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 #include "codechal_hw.h"
37 
38 namespace decode
39 {
40     class Av1BasicFeatureG12 : public DecodeBasicFeature
41     {
42     public:
43         //!
44         //! \brief  Av1BasicFeatureG12 constructor
45         //!
Av1BasicFeatureG12(DecodeAllocator * allocator,void * hwInterface,PMOS_INTERFACE osInterface)46         Av1BasicFeatureG12(DecodeAllocator *allocator, void *hwInterface, PMOS_INTERFACE osInterface) :
47             DecodeBasicFeature(allocator, hwInterface ? ((CodechalHwInterface*)hwInterface)->m_hwInterfaceNext : nullptr, osInterface)
48         {
49             if (osInterface != nullptr)
50             {
51                 m_osInterface = osInterface;
52             }
53             m_hwInterface = (CodechalHwInterface*)hwInterface;
54         };
55 
56         //!
57         //! \brief  Av1BasicFeatureG12 deconstructor
58         //!
59         virtual ~Av1BasicFeatureG12();
60 
61         //!
62         //! \brief  Initialize av1 basic feature CodechalSetting
63         //! \return MOS_STATUS
64         //!         MOS_STATUS_SUCCESS if success, else fail reason
65         //!
66         virtual MOS_STATUS Init(void *setting) override;
67 
68         //!
69         //! \brief  Update av1 decodeParams
70         //! \return MOS_STATUS
71         //!         MOS_STATUS_SUCCESS if success, else fail reason
72         //!
73         virtual MOS_STATUS Update(void *params) override;
74 
75         //!
76         //! \brief  Detect conformance conflict and do error concealment
77         //! \return MOS_STATUS
78         //!         MOS_STATUS_SUCCESS if success, else fail reason
79         //!
80         MOS_STATUS ErrorDetectAndConceal();
81 
82         //!
83         //! \brief    Initialize one of AV1 Decode frame context buffers with default values
84         //! \param    [in] ctxBuffer
85         //!           Pointer to frame context buffer
86         //! \param    [in] index
87         //!           flag to indicate the coeff CDF table index
88         //! \return   MOS_STATUS
89         //!           MOS_STATUS_SUCCESS if success, else fail reason
90         //!
91         MOS_STATUS InitDefaultFrameContextBuffer(
92             uint16_t              *ctxBuffer,
93             uint8_t               index);
94 
95         //!
96         //! \brief    Initialize CDF tables for one Syntax Element
97         //! \details  Initialize CDF tables for one Syntax Element according to its CDF table layout and the initialization buffer
98         //! \param    [in] ctxBuffer
99         //!           Pointer to frame context buffer
100         //! \param    [in] SyntaxElement
101         //!           CDF table layout info and the initialization buffer for this syntax element
102         //! \return   MOS_STATUS
103         //!           MOS_STATUS_SUCCESS if success, else fail reason
104         //!
105         MOS_STATUS SyntaxElementCdfTableInit(
106             uint16_t                    *ctxBuffer,
107             SyntaxElementCdfTableLayout SyntaxElement);
108 
109         //!
110         //! \brief    Update default cdfTable buffers
111         //! \details  Update default cdfTable buffers for AV1 decoder
112         //! \param    [in] cmdBuffer
113         //!           Command buffer to hold HW commands
114         //! \return   MOS_STATUS
115         //!           MOS_STATUS_SUCCESS if success, else fail reason
116         //!
117         virtual MOS_STATUS UpdateDefaultCdfTable();
118 
119         // Parameters passed from application
120         uint16_t                        m_frameWidthAlignedMinBlk  = 0;            //!< Picture Width aligned to minBlock
121         uint16_t                        m_frameHeightAlignedMinBlk = 0;            //!< Picture Height aligned to minBlock
122         uint8_t                         m_av1DepthIndicator        = 0;            //!< Indicate it is 8/10/12 bit AV1
123         CodecAv1PicParams               *m_av1PicParams            = nullptr;      //!< Pointer to AV1 picture parameter
124         CodecAv1SegmentsParams          *m_segmentParams           = nullptr;      //!< Pointer to AV1 segments parameter
125         CodecAv1TileParams              *m_av1TileParams           = nullptr;      //!< Pointer to AV1 tiles parameter
126 
127         PMOS_BUFFER                     m_defaultCdfBuffers[4]     = {};           //!< 4 default frame contexts per base_qindex
128         PMOS_BUFFER                     m_defaultCdfBufferInUse    = nullptr;      //!< default cdf table used base on current base_qindex
129         uint8_t                         m_curCoeffCdfQCtx          = 0;            //!< Coeff CDF Q context ID for current frame
130         static const uint32_t           m_cdfMaxNumBytes           = 15104;        //!< Max number of bytes for CDF tables buffer, which equals to 236*64 (236 Cache Lines)
131         static const uint32_t           av1DefaultCdfTableNum      = 4;            //!< Number of inited cdf table
132                                                                                    //for Internal buffer upating
133         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.
134 
135         Av1ReferenceFramesG12           m_refFrames;                               //!< Reference frames
136         Av1DecodeTileG12                m_tileCoding;                              //!< Tile coding
137         std::vector<uint32_t>           m_refFrameIndexList;                       //!< Reference frame index list
138         RefrenceAssociatedBuffer<Av1RefAssociatedBufs, Av1TempBufferOpInfG12, Av1BasicFeatureG12> m_tempBuffers; //!< Reference associated buffers
139 
140         InternalTargets                 m_internalTarget;                          //!< Internal decode out surface
141         FilmGrainProcParams            *m_filmGrainProcParams       = nullptr;     //!< Film grain processing params
142         bool                            m_frameCompletedFlag        = false;
143         bool                            m_filmGrainEnabled          = false;       //!< Per-frame film grain enable flag
144         bool                            m_usingDummyWl              = false;       //!< Indicate using dummy workload flag
145         PMOS_SURFACE                    m_destSurfaceForDummyWL     = nullptr;     //!< Internal Dummy dest surface
146         bool                            m_singleKernelPerfFlag      = true;        //!< Defaut to capture whole kernel execution timing for perf
147         PMOS_SURFACE                    m_fgInternalSurf            = nullptr;     //!< Internal film grain surface for AVP+FilmGrain+SFC case
148         MOS_SURFACE                     m_fgOutputSurf              = {};          //!< Film Grain output surface from App
149 
150     protected:
151         virtual MOS_STATUS SetRequiredBitstreamSize(uint32_t requiredSize) override;
152         MOS_STATUS SetPictureStructs(CodechalDecodeParams *decodeParams);
153         MOS_STATUS SetTileStructs();
154         MOS_STATUS SetSegmentData(CodecAv1PicParams &picParams);
155         MOS_STATUS GetDecodeTargetFormat(MOS_FORMAT &format);
156 
157         //!
158         //! \brief    Calculate global motion params
159         //! \return   MOS_STATUS
160         //!           MOS_STATUS_SUCCESS if success, else fail reason
161         //!
162         MOS_STATUS CalculateGlobalMotionParams();
163 
164         MhwVdboxAvpInterface *m_avpInterface = nullptr;
165         PMOS_INTERFACE        m_osInterface  = nullptr;
166         CodechalHwInterface  *m_hwInterface  = nullptr;
167 
168     MEDIA_CLASS_DEFINE_END(decode__Av1BasicFeatureG12)
169     };
170 
171 }  // namespace decode
172 
173 #endif  // !__DECODE_AV1_BASIC_FEATURE_G12_H__
174