1 /*
2 * Copyright (c) 2021-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_vvc_basic_feature.h
24 //! \brief    Defines the common interface for decode vvc basic feature
25 //!
26 #ifndef __DECODE_VVC_BASIC_FEATURE_H__
27 #define __DECODE_VVC_BASIC_FEATURE_H__
28 
29 #include "decode_basic_feature.h"
30 #include "codec_def_decode_vvc.h"
31 #include "codec_def_common_vvc.h"
32 #include "decode_vvc_reference_frames.h"
33 #include "decode_vvc_mv_buffers.h"
34 #include "mhw_vdbox_vvcp_itf.h"
35 #include "decode_internal_target.h"
36 
37 namespace decode
38 {
39     class VvcBasicFeature : public DecodeBasicFeature
40     {
41     public:
42         //!
43         //! \brief  VvcBasicFeature constructor
44         //!
VvcBasicFeature(DecodeAllocator * allocator,CodechalHwInterfaceNext * hwInterface,PMOS_INTERFACE osInterface)45         VvcBasicFeature(DecodeAllocator *allocator, CodechalHwInterfaceNext *hwInterface, PMOS_INTERFACE osInterface) : DecodeBasicFeature(allocator, hwInterface, osInterface)
46         {
47             m_hwInterface = hwInterface;
48             if (osInterface != nullptr)
49             {
50                 m_osInterface = osInterface;
51             }
52             if (hwInterface != nullptr)
53             {
54                 m_vvcpItf = std::static_pointer_cast<mhw::vdbox::vvcp::Itf>(m_hwInterface->GetVvcpInterfaceNext());
55             }
56             MOS_ZeroMemory(m_scalingListArray, sizeof(CodecVvcQmData) * 8);
57             MOS_ZeroMemory(m_tileRow, sizeof(TileRowDesc) * 440);
58             MOS_ZeroMemory(m_tileCol, sizeof(TileColDesc) * 20);
59             MOS_ZeroMemory(m_sliceDesc, sizeof(SliceDescriptor) * 600);
60             MOS_ZeroMemory(m_alfApsArray, sizeof(CodecVvcAlfData) * 8);
61             MOS_ZeroMemory(m_lmcsApsArray, sizeof(CodecVvcLmcsData) * 4);
62             MOS_ZeroMemory(m_lmcsReshaperInfo, sizeof(ApsLmcsReshapeInfo) * 4);
63         };
64 
65         //!
66         //! \brief  VvcBasicFeature deconstructor
67         //!
68         virtual ~VvcBasicFeature();
69 
70         //!
71         //! \brief  Initialize vvc basic feature CodechalSetting
72         //! \return MOS_STATUS
73         //!         MOS_STATUS_SUCCESS if success, else fail reason
74         //!
75         virtual MOS_STATUS Init(void *setting) override;
76 
77         //!
78         //! \brief  Update vvc decodeParams
79         //! \return MOS_STATUS
80         //!         MOS_STATUS_SUCCESS if success, else fail reason
81         //!
82         virtual MOS_STATUS Update(void *params) override;
83 
84         //!
85         //! \brief  Update APS
86         //! \return MOS_STATUS
87         //!         MOS_STATUS_SUCCESS if success, else fail reason
88         //!
89         MOS_STATUS UpdateAPS(void *params);
90 
91         //!
92         //! \brief  Check if ALF params are out of valid range
93         //! \param    [in] alfData
94         //!           Pointer to an ALF data structure
95         //! \return MOS_STATUS
96         //!         MOS_STATUS_SUCCESS if success, else fail reason
97         //!
98         MOS_STATUS CheckAlfRange(CodecVvcAlfData* alfData);
99 
100         //!
101         //! \brief  Detect conformance conflict and do error concealment
102         //! \return MOS_STATUS
103         //!         MOS_STATUS_SUCCESS if success, else fail reason
104         //!
105         MOS_STATUS ErrorDetectAndConceal();
106 
107         //!
108         //! \brief  Detect slice duplication and reorder and do error concealment for long format decoding
109         //! \return MOS_STATUS
110         //!         MOS_STATUS_SUCCESS if success, else fail reason
111         //!
112         MOS_STATUS SliceErrorHandlingLF();
113 
114         //!
115         //! \brief    Get subpic Index from Subpic ID
116         //! \param    [in] subPicId
117         //!           Subpic ID value
118         //! \return   MOS_STATUS
119         //!           MOS_STATUS_SUCCESS if success, else fail reason
120         //!
121         int16_t GetSubPicIdxFromSubPicId(uint16_t subPicId);
122 
123         MOS_STATUS UpdateNumRefForList();  //Update Correct NumRefForList
124 
125         // Parameters passed from application
126         uint16_t                        m_frameWidthAlignedMinBlk  = 0;            //!< Picture Width aligned to minBlock
127         uint16_t                        m_frameHeightAlignedMinBlk = 0;            //!< Picture Height aligned to minBlock
128         uint8_t                         m_vvcDepthIndicator        = 0;            //!< Indicate it is 8/10/12 bit VVC
129         uint8_t                         m_numRefForList0           = 0;
130         uint8_t                         m_numRefForList1           = 0;
131         CodecVvcPicParams               *m_vvcPicParams            = nullptr;      //!< Pointer to VVC picture parameter
132         CodecVvcSliceParams             *m_vvcSliceParams          = nullptr;      //!< Pointer to VVC slice parameter
133         CodecVvcSubpicParam             *m_subPicParams            = nullptr;      //!< Pointer to VVC SubPic Parameter
134         CodecVvcSliceStructure          *m_sliceStructParams       = nullptr;      //!< Pointer to Slice Structure parameter
135         CodecVvcRplStructure            *m_rplParams               = nullptr;      //!< Pointer to RPL parameter
136         CodecVvcTileParam               *m_tileParams              = nullptr;      //!< pointer to Tile Parameter
137 
138         //Internal parameters
139         //APS buffer arrays
140         CodecVvcAlfData                 m_alfApsArray[8];                          //!< 8 internal ALF APS arrays
141         CodecVvcLmcsData                m_lmcsApsArray[4];                         //!< 4 internal LMCS APS arrays
142         CodecVvcQmData                  m_scalingListArray[8];                     //!< 8 internal Scaling List arrays
143         ApsLmcsReshapeInfo              m_lmcsReshaperInfo[4];                     //!< 4 internal LMCS reshaper info
144         uint8_t                         m_lmcsReshaperReady = 0;                   //!< bit0 corresponds to Lmcs0
145         uint8_t                         m_activeAlfMask = 0;                       //!< valid flags for each ALF table
146         uint8_t                         m_activeLmcsMask = 0;                      //!< valid flags for each LMCS table
147         uint8_t                         m_activeScalingListMask = 0;               //!< valid flags for each scaling list table
148         uint8_t                         m_concealAlfMask = 0;                      //!< out-of-range flag for each ALF table
149         uint8_t                         m_numAlf = 0;                              //!< Accumulated valid ALF number
150         uint8_t                         m_numLmcs = 0;                             //!< Accumulated valid LMCS number
151         uint8_t                         m_numScalingList = 0;                      //!< Accumulated valid scaling list number
152 
153         //Picture
154         uint16_t                        m_picWidthInCtu = 0;
155         uint16_t                        m_picHeightInCtu = 0;
156 
157         //Tile structure
158         uint16_t                        m_tileCols = 0;
159         uint16_t                        m_tileRows = 0;
160         uint16_t                        m_maxTileWidth = 0;
161         TileRowDesc                     m_tileRow[440];
162         TileColDesc                     m_tileCol[20];
163 
164         //Sub-Pic Structure
165         uint16_t                        m_sliceIdxInPicScanOrder[600];             //!< Internal buffer to store global slice scan order in picture
166 
167         //Slice structure
168         int16_t                         m_curSlice = 0;                            //!< Current slice index
169         SliceDescriptor                 m_sliceDesc[600];
170         std::vector<int16_t>            m_sliceIdxInOrder;                         //!< Valid slice index in order with duplicated slice removed and reordered slices reversed
171 
172         //DPB+RPL
173         VvcReferenceFrames              m_refFrames;                               //!< Reference frames
174         std::vector<uint32_t>           m_refFrameIndexList;                       //!< Reference frame index list
175         RefrenceAssociatedBuffer<MOS_BUFFER, VvcMvBufferOpInf, VvcBasicFeature>
176                                         m_mvBuffers;                               //!< Reference associated buffers
177 
178         bool                            m_frameCompletedFlag        = false;       //!< Command packet preparation done for the whole frame
179         bool                            m_shortFormatInUse          = false;       //!< flag to indicate if short format in use
180 
181         CodechalHwInterfaceNext         *m_hwInterface              = nullptr;
182 
183     protected:
184         virtual MOS_STATUS SetRequiredBitstreamSize(uint32_t requiredSize) override;
185         //!
186         //! \brief    Reconstruct picture partition, including slice/tile/subpic
187         //! \return   MOS_STATUS
188         //!           MOS_STATUS_SUCCESS if success, else fail reason
189         //!
190         MOS_STATUS ReconstructPartition(CodechalDecodeParams *decodeParams);
191         MOS_STATUS ReconstructSlice();
192         MOS_STATUS ReconstructTile();
193         MOS_STATUS SetSubPicStruct();
194         int16_t GetSubpicWidthInTile(uint16_t startCtu, uint16_t endCtu, int16_t &startTile, int16_t &endTile);
195         int16_t GetSubpicHeightInTile(uint16_t startCtu, uint16_t endCtu, int16_t &startTile, int16_t &endTile);
196 
197         MOS_STATUS SetPictureStructs(CodechalDecodeParams *decodeParams);
198         virtual MOS_STATUS CheckProfileCaps();
199 
200         std::shared_ptr<mhw::vdbox::vvcp::Itf> m_vvcpItf     = nullptr;
201         PMOS_INTERFACE                         m_osInterface = nullptr;
202 
203     MEDIA_CLASS_DEFINE_END(decode__VvcBasicFeature)
204     };
205 
206 }  // namespace decode
207 
208 #endif  // !__DECODE_VVC_BASIC_FEATURE_H__
209