1 /*
2 * Copyright (c) 2019-2023, 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.h
24 //! \brief    Defines the common interface for decode av1 basic feature
25 //!
26 #ifndef __DECODE_AV1_BASIC_FEATURE_H__
27 #define __DECODE_AV1_BASIC_FEATURE_H__
28 
29 #include "decode_basic_feature.h"
30 #include "codec_def_decode_av1.h"
31 #include "decode_av1_reference_frames.h"
32 #include "decode_av1_temporal_buffers.h"
33 #include "decode_av1_tile_coding.h"
34 #include "mhw_vdbox_avp_itf.h"
35 #include "decode_internal_target.h"
36 
37 namespace decode
38 {
39     class Av1BasicFeature : public DecodeBasicFeature
40     {
41     public:
42         //!
43         //! \brief  Av1BasicFeature constructor
44         //!
Av1BasicFeature(DecodeAllocator * allocator,void * hwInterface,PMOS_INTERFACE osInterface)45         Av1BasicFeature(DecodeAllocator *allocator, void *hwInterface, PMOS_INTERFACE osInterface) :
46             DecodeBasicFeature(allocator, hwInterface, osInterface)
47         {
48             if (osInterface != nullptr)
49             {
50                 m_osInterface = osInterface;
51             }
52         };
53 
54         //!
55         //! \brief  Av1BasicFeature deconstructor
56         //!
57         virtual ~Av1BasicFeature();
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         virtual 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_defaultCdfBuffers[4]     = {};           //!< 4 default frame contexts per base_qindex
126         PMOS_BUFFER                     m_defaultCdfBufferInUse    = nullptr;      //!< default cdf table used base on current base_qindex
127         uint8_t                         m_curCoeffCdfQCtx          = 0;            //!< Coeff CDF Q context ID for current frame
128         static const uint32_t           m_cdfMaxNumBytes           = 15104;        //!< Max number of bytes for CDF tables buffer, which equals to 236*64 (236 Cache Lines)
129         static const uint32_t           av1DefaultCdfTableNum      = 4;            //!< Number of inited cdf table
130                                                                                    //for Internal buffer upating
131         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.
132 
133         Av1ReferenceFrames              m_refFrames;                               //!< Reference frames
134         Av1DecodeTile                   m_tileCoding;                              //!< Tile coding
135         std::vector<uint32_t>           m_refFrameIndexList;                       //!< Reference frame index list
136         RefrenceAssociatedBuffer<Av1RefAssociatedBufs, Av1TempBufferOpInf, Av1BasicFeature> m_tempBuffers; //!< Reference associated buffers
137 
138         InternalTargets                 m_internalTarget;                          //!< Internal decode out surface
139         FilmGrainProcParams            *m_filmGrainProcParams       = nullptr;     //!< Film grain processing params
140         bool                            m_frameCompletedFlag        = false;
141         bool                            m_filmGrainEnabled          = false;       //!< Per-frame film grain enable flag
142         bool                            m_usingDummyWl              = false;       //!< Indicate using dummy workload flag
143         PMOS_SURFACE                    m_destSurfaceForDummyWL     = nullptr;     //!< Internal Dummy dest surface
144         bool                            m_singleKernelPerfFlag      = true;        //!< Defaut to capture whole kernel execution timing for perf
145         PMOS_SURFACE                    m_fgInternalSurf            = nullptr;     //!< Internal film grain surface for AVP+FilmGrain+SFC case
146         MOS_SURFACE                     m_fgOutputSurf              = {};          //!< Film Grain output surface from App
147 #if (_DEBUG || _RELEASE_INTERNAL)
148         MOS_SURFACE m_fgOutputSurfList[DecodeBasicFeature::m_maxFrameIndex] = {};  //!< Brief film grain applied surfaces
149 #endif
150 
151     protected:
152         virtual MOS_STATUS SetRequiredBitstreamSize(uint32_t requiredSize) override;
153         MOS_STATUS SetPictureStructs(CodechalDecodeParams *decodeParams);
154         MOS_STATUS SetTileStructs();
155         MOS_STATUS SetSegmentData(CodecAv1PicParams &picParams);
156         MOS_STATUS GetDecodeTargetFormat(MOS_FORMAT &format);
157         virtual MOS_STATUS CheckProfileAndSubsampling();
158         MOS_STATUS CheckBitdepth();
159         //!
160         //! \brief    Calculate global motion params
161         //! \return   MOS_STATUS
162         //!           MOS_STATUS_SUCCESS if success, else fail reason
163         //!
164         MOS_STATUS CalculateGlobalMotionParams();
165 
166         std::shared_ptr<mhw::vdbox::avp::Itf> m_avpItf = nullptr;
167         PMOS_INTERFACE m_osInterface = nullptr;
168 
169     MEDIA_CLASS_DEFINE_END(decode__Av1BasicFeature)
170     };
171 
172 }  // namespace decode
173 
174 #endif  // !__DECODE_AV1_BASIC_FEATURE_H__
175