1 /*
2 * Copyright (c) 2019-2021, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22 //!
23 //! \file     decode_av1_basic_feature_g12.h
24 //! \brief    Defines the common interface for decode av1 basic feature g12
25 //!
26 #ifndef __DECODE_AV1_BASIC_FEATURE_G12_H__
27 #define __DECODE_AV1_BASIC_FEATURE_G12_H__
28 
29 #include "decode_basic_feature.h"
30 #include "codec_def_decode_av1.h"
31 #include "decode_av1_reference_frames_g12.h"
32 #include "decode_av1_temporal_buffers_g12.h"
33 #include "decode_av1_tile_coding_g12.h"
34 #include "mhw_vdbox_avp_interface.h"
35 #include "decode_internal_target.h"
36 
37 namespace decode
38 {
39     class Av1BasicFeatureG12 : public DecodeBasicFeature
40     {
41     public:
42         //!
43         //! \brief  Av1BasicFeatureG12 constructor
44         //!
Av1BasicFeatureG12(DecodeAllocator * allocator,CodechalHwInterface * hwInterface)45         Av1BasicFeatureG12(DecodeAllocator *allocator, CodechalHwInterface *hwInterface) :
46                          DecodeBasicFeature(allocator, hwInterface)
47         {
48             if (hwInterface != nullptr)
49             {
50                 m_osInterface  = hwInterface->GetOsInterface();
51             }
52         };
53 
54         //!
55         //! \brief  Av1BasicFeatureG12 deconstructor
56         //!
57         virtual ~Av1BasicFeatureG12();
58 
59         //!
60         //! \brief  Initialize av1 basic feature CodechalSetting
61         //! \return MOS_STATUS
62         //!         MOS_STATUS_SUCCESS if success, else fail reason
63         //!
64         virtual MOS_STATUS Init(void *setting) override;
65 
66         //!
67         //! \brief  Update av1 decodeParams
68         //! \return MOS_STATUS
69         //!         MOS_STATUS_SUCCESS if success, else fail reason
70         //!
71         virtual MOS_STATUS Update(void *params) override;
72 
73         //!
74         //! \brief  Detect conformance conflict and do error concealment
75         //! \return MOS_STATUS
76         //!         MOS_STATUS_SUCCESS if success, else fail reason
77         //!
78         MOS_STATUS ErrorDetectAndConceal();
79 
80         //!
81         //! \brief    Initialize one of AV1 Decode frame context buffers with default values
82         //! \param    [in] ctxBuffer
83         //!           Pointer to frame context buffer
84         //! \param    [in] index
85         //!           flag to indicate the coeff CDF table index
86         //! \return   MOS_STATUS
87         //!           MOS_STATUS_SUCCESS if success, else fail reason
88         //!
89         MOS_STATUS InitDefaultFrameContextBuffer(
90             uint16_t              *ctxBuffer,
91             uint8_t               index);
92 
93         //!
94         //! \brief    Initialize CDF tables for one Syntax Element
95         //! \details  Initialize CDF tables for one Syntax Element according to its CDF table layout and the initialization buffer
96         //! \param    [in] ctxBuffer
97         //!           Pointer to frame context buffer
98         //! \param    [in] SyntaxElement
99         //!           CDF table layout info and the initialization buffer for this syntax element
100         //! \return   MOS_STATUS
101         //!           MOS_STATUS_SUCCESS if success, else fail reason
102         //!
103         MOS_STATUS SyntaxElementCdfTableInit(
104             uint16_t                    *ctxBuffer,
105             SyntaxElementCdfTableLayout SyntaxElement);
106 
107         //!
108         //! \brief    Update default cdfTable buffers
109         //! \details  Update default cdfTable buffers for AV1 decoder
110         //! \param    [in] cmdBuffer
111         //!           Command buffer to hold HW commands
112         //! \return   MOS_STATUS
113         //!           MOS_STATUS_SUCCESS if success, else fail reason
114         //!
115         virtual MOS_STATUS UpdateDefaultCdfTable();
116 
117         // Parameters passed from application
118         uint16_t                        m_frameWidthAlignedMinBlk  = 0;            //!< Picture Width aligned to minBlock
119         uint16_t                        m_frameHeightAlignedMinBlk = 0;            //!< Picture Height aligned to minBlock
120         uint8_t                         m_av1DepthIndicator        = 0;            //!< Indicate it is 8/10/12 bit AV1
121         CodecAv1PicParams               *m_av1PicParams            = nullptr;      //!< Pointer to AV1 picture parameter
122         CodecAv1SegmentsParams          *m_segmentParams           = nullptr;      //!< Pointer to AV1 segments parameter
123         CodecAv1TileParams              *m_av1TileParams           = nullptr;      //!< Pointer to AV1 tiles parameter
124 
125         PMOS_BUFFER                     m_tmpCdfBuffers[4]         = {};           //!< 4 temporal cdf table buffers for later use.
126         PMOS_BUFFER                     m_defaultCdfBuffers[4]     = {};           //!< 4 default frame contexts per base_qindex
127         PMOS_BUFFER                     m_defaultCdfBufferInUse    = nullptr;      //!< default cdf table used base on current base_qindex
128         uint8_t                         m_curCoeffCdfQCtx          = 0;            //!< Coeff CDF Q context ID for current frame
129         static const uint32_t           m_cdfMaxNumBytes           = 15104;        //!< Max number of bytes for CDF tables buffer, which equals to 236*64 (236 Cache Lines)
130         static const uint32_t           av1DefaultCdfTableNum      = 4;            //!< Number of inited cdf table
131                                                                                    //for Internal buffer upating
132         bool                            m_defaultFcInitialized     = false;        //!< default Frame context initialized flag. default frame context should be initialized only once, and set this flag to 1 once initialized.
133 
134         Av1ReferenceFramesG12           m_refFrames;                               //!< Reference frames
135         Av1DecodeTileG12                m_tileCoding;                              //!< Tile coding
136         std::vector<uint32_t>           m_refFrameIndexList;                       //!< Reference frame index list
137         RefrenceAssociatedBuffer<Av1RefAssociatedBufs, Av1TempBufferOpInfG12, Av1BasicFeatureG12> m_tempBuffers; //!< Reference associated buffers
138 
139         InternalTargets                 m_internalTarget;                          //!< Internal decode out surface
140         FilmGrainProcParams            *m_filmGrainProcParams       = nullptr;     //!< Film grain processing params
141         bool                            m_frameCompletedFlag        = false;
142         bool                            m_filmGrainEnabled          = false;       //!< Per-frame film grain enable flag
143         bool                            m_usingDummyWl              = false;       //!< Indicate using dummy workload flag
144         PMOS_SURFACE                    m_destSurfaceForDummyWL     = nullptr;     //!< Internal Dummy dest surface
145         bool                            m_singleKernelPerfFlag      = true;        //!< Defaut to capture whole kernel execution timing for perf
146         PMOS_SURFACE                    m_fgInternalSurf            = nullptr;     //!< Internal film grain surface for AVP+FilmGrain+SFC case
147         MOS_SURFACE                     m_fgOutputSurf              = {};          //!< Film Grain output surface from App
148 
149     protected:
150         virtual MOS_STATUS SetRequiredBitstreamSize(uint32_t requiredSize) override;
151         MOS_STATUS SetPictureStructs(CodechalDecodeParams *decodeParams);
152         MOS_STATUS SetTileStructs();
153         MOS_STATUS SetSegmentData(CodecAv1PicParams &picParams);
154         MOS_STATUS GetDecodeTargetFormat(MOS_FORMAT &format);
155 
156         //!
157         //! \brief    Calculate global motion params
158         //! \return   MOS_STATUS
159         //!           MOS_STATUS_SUCCESS if success, else fail reason
160         //!
161         MOS_STATUS CalculateGlobalMotionParams();
162 
163         MhwVdboxAvpInterface *m_avpInterface = nullptr;
164         PMOS_INTERFACE        m_osInterface  = nullptr;
165     };
166 
167 }  // namespace decode
168 
169 #endif  // !__DECODE_AV1_BASIC_FEATURE_G12_H__
170