xref: /aosp_15_r20/external/intel-media-driver/media_common/agnostic/common/codec/shared/codec_def_decode.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2018-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     codec_def_decoder.h
24 //! \brief    Defines the decode interface for CodecHal.
25 //! \details  The decode interface is further sub-divided by standard, this file is for the base interface which is shared by all decode standards.
26 //!
27 
28 #ifndef __CODEC_DEF_DECODE_H__
29 #define __CODEC_DEF_DECODE_H__
30 
31 #include "mos_os.h"
32 #include "codec_def_decode_jpeg.h"
33 
34 #define HISTOGRAM_BINCOUNT 256
35 
36 struct CencDecodeShareBuf;
37 
38 //!
39 //! \struct FilmGrainProcParams
40 //! \brief Define the film grain processing parameters
41 //!
42 struct FilmGrainProcParams
43 {
44     PMOS_SURFACE m_inputSurface;
45     PMOS_SURFACE m_outputSurface;
46 };
47 
48 //!
49 //! \struct CodecRectangle
50 //! \brief Parameters to describe a surface region
51 //!
52 struct CodecRectangle
53 {
54     uint32_t m_x;
55     uint32_t m_y;
56     uint32_t m_width;
57     uint32_t m_height;
58 };
59 
60 //!
61 //! \struct DecodeProcessingParams
62 //! \brief Parameters needed for the processing of the decode render target.
63 //!
64 struct DecodeProcessingParams
65 {
66     // Input
67     PMOS_SURFACE   m_inputSurface;
68     CodecRectangle m_inputSurfaceRegion;
69     uint32_t       m_inputColorStandard;
70     uint32_t       m_inputColorRange;
71     uint32_t       m_chromaSitingType;
72 
73     // Output
74     PMOS_SURFACE   m_outputSurface;
75     CodecRectangle m_outputSurfaceRegion;
76     uint32_t       m_outputColorStandard;
77 
78     PMOS_SURFACE   m_histogramSurface;
79 
80     // Processing state
81     uint32_t       m_rotationState;
82     uint32_t       m_blendState;
83     uint32_t       m_mirrorState;
84     bool           m_isSourceSurfAllocated;
85     bool           m_isReferenceOnlyPattern;
86 
87     CODECHAL_SCALING_MODE m_scalingMode;
88 };
89 
90 //!
91 //! \struct CodechalDecodeParams
92 //! \brief  Parameters passed in via Execute() to perform decoding.
93 //!
94 struct CodechalDecodeParams
95 {
96     //! \brief Decode render target
97     PMOS_SURFACE            m_destSurface = nullptr;
98     //! \brief Reference frame surface
99     PMOS_SURFACE            m_refFrameSurface = nullptr;
100     //! \brief [VC1] Deblocked output of OLP
101     PMOS_SURFACE            m_deblockSurface = nullptr;
102     //! \brief Resource containing the bitstream (VLD mode) or residual difference (IT mode) data
103     PMOS_RESOURCE           m_dataBuffer = nullptr;
104     //! \brief [VC1] Resource containing the bitplane data
105     PMOS_RESOURCE           m_bitplaneBuffer = nullptr;
106     //! \brief [VP8 & VP9] resource containing coefficient probability data
107     PMOS_RESOURCE           m_coefProbBuffer = nullptr;
108     //! \brief [VP8 & VP9] resource containing the last reference surface which was not registered.
109     PMOS_RESOURCE           m_presNoneRegLastRefFrame = nullptr;
110     //! \brief [VP8 & VP9] resource containing the golden reference surface which was not registered.
111     PMOS_RESOURCE           m_presNoneRegGoldenRefFrame = nullptr;
112     //! \brief [VP8 & VP9] resource containing the alt reference surface which was not registered.
113     PMOS_RESOURCE           m_presNoneRegAltRefFrame = nullptr;
114     //! \brief [VC1 IT] Deblock data
115     //!    For advanced profile P frames, this data should be formated as an array of 6 bytes for each MB:
116     //!        Byte0: ILDBControlDataforY0
117     //!        Byte1: ILDBControlDataforY1
118     //!        Byte2: ILDBControlDataforY2
119     //!        Byte3: ILDBControlDataforY3
120     //!        Byte4: ILDBControlDataforCb
121     //!        Byte5: ILDBControlDataforCr
122     uint8_t                 *m_deblockData = nullptr;
123 
124     //! \brief [Codecs (HEVC & VP9)] Bitstream buffer data
125     uint8_t                 *m_bitStreamBufData = nullptr;
126     //! \brief Size of the data contained in m_dataBuffer
127     uint32_t                m_dataSize = 0;
128     //! \brief Offset of the data contained in presDataBuffer
129     uint32_t                m_dataOffset = 0;
130     //! \brief [VLD mode] Number of slices to be decoded
131     uint32_t                m_numSlices = 0;
132     //! \brief [IT mode] Number of MBs to be decoded
133     uint32_t                m_numMacroblocks = 0;
134     //! \brief [VC1] size of the data contained in m_bitplaneBuffer
135     uint32_t                m_vc1BitplaneSize = 0;
136     //! \brief [VP8 & VP9] Size of the data contained in m_coefProbBuffer
137     uint32_t                m_coefProbSize = 0;
138     //! \brief [VC1 IT] Size of the data contained in m_deblockData
139     uint32_t                m_deblockDataSize = 0;
140     //! \brief Number of reference frame surface
141     uint32_t                m_refSurfaceNum = 0;
142 
143     //! \brief Indicates whether or not stream out information should be returned to the DDI
144     bool                    m_streamOutEnabled = false;
145     //! \brief Resource to contain the stream out output from HW
146     PMOS_RESOURCE           m_externalStreamOutBuffer = nullptr;
147 
148     //! \brief [CENC Decode] Status reporting number associated with the current frame.
149     uint16_t                m_cencDecodeStatusReportNum = 0;
150     CencDecodeShareBuf      *m_cencBuf = nullptr;
151 
152     //! \brief Picture level parameters to be used for decoding
153     void                    *m_picParams = nullptr;
154     //! \brief Additional picture level parameters to be used for decoding.
155     //!      In certain cases additional parameters are needed to supplement m_picParams (MVC, etc).
156     void                    *m_extPicParams = nullptr;
157     //! \brief Picture Level parameters for HEVC advanced feature
158     void                    *m_advPicParams = nullptr;
159     //! \brief [VLD mode] Slice level parameters to be used for decoding
160     void                    *m_sliceParams = nullptr;
161     //!< [VLD LF mode] Intel long format
162     void                    *m_subsetParams = nullptr;
163     //! \brief Additional slice level parameters to be used for decoding.
164     //!      In certain cases additional parameters are needed to supplement m_sliceParams (MVC, etc).
165     void                    *m_extSliceParams = nullptr;
166     //! \brief Inverse quant matrix data
167     void                    *m_iqMatrixBuffer = nullptr;
168     //! \brief [IT mode] MB level parameters to be used for decoding
169     void                    *m_macroblockParams = nullptr;
170     //!\brief size of data contained in m_iqMatrixBuffer
171     uint32_t                m_iqMatrixSize = 0;
172     //! \brief reference parameters to be used for decoding
173     void                    *m_refParams = nullptr;
174     //! \brief tile info parameters to be used for decoding
175     void                    *m_tileParams = nullptr;
176 
177     //! \brief Reference count used for downsampling, If non-zero enables downsampling of the render target.
178     uint32_t                m_refFrameCnt = 0;
179 #ifdef _DECODE_PROCESSING_SUPPORTED
180     //! \brief Parameters used for processing the decode render target, if invalid, decode render target processing will not be used.
181     void                    *m_procParams = nullptr;
182 #endif
183 
184     //! \brief Parameters used for film grain process
185     FilmGrainProcParams     m_filmGrainProcParams;
186 
187     //! \brief [Predication] Resource for predication
188     PMOS_RESOURCE           m_presPredication = nullptr;
189     //! \brief [Predication] Offset for Predication resource
190     uint64_t                m_predicationResOffset = 0;
191     //! \brief [Predication] Predication mode
192     bool                    m_predicationNotEqualZero = false;
193 
194     //! \brief [Predication] Indicates whether or not Predication is enabled
195     bool                    m_predicationEnabled = false;
196     //! \brief [Predication] Temp buffer for Predication
197     PMOS_RESOURCE           *m_tempPredicationBuffer = nullptr;
198 
199     //! \brief [JPEG] Huffman table data
200     void                    *m_huffmanTable = nullptr;
201     //! \brief [JPEG] Describes the layout of the decode render target
202     CodecDecodeJpegImageLayout m_outputSurfLayout = {{0}};
203     // JPEG incomplete bitstream flag
204     bool                    m_scanIncomplete = false;
205 
206     //! \brief [AVC] Indicates whethe or not PicId remapping is in use
207     bool                    m_picIdRemappingInUse = false;
208 
209     // MPEG2 Specific Parameters
210     //! \brief [MPEG2] MPEG2 I slice concealment mode
211     uint32_t                m_mpeg2ISliceConcealmentMode = 0;
212     //! \brief [MPEG2] MPEG2 P/B slice concealment mode
213     uint32_t                m_mpeg2PBSliceConcealmentMode = 0;
214     //! \brief [MPEG2] MPEG2 P/B Slice Predicted BiDir Motion Type Override
215     uint32_t                m_mpeg2PBSlicePredBiDirMVTypeOverride = 0;
216     //! \brief [MPEG2] MPEG2 P/B Slice Predicted Motion Vector Override
217     uint32_t                m_mpeg2PBSlicePredMVOverride = 0;
218 
219     //! \brief [VP8] Indicates whether or not the driver is expected to parse parameters from the frame header
220     bool                    m_bitstreamLockingInUse = false;
221     //! \brief [VP8] Indicates whether or not the bitstream buffer may be directly locked to perform header parsing.
222     bool                    m_bitstreamLockable = false;
223 
224     //! \brief [SetMarker] Indicates whether or not SetMarker is enabled
225     bool                    m_setMarkerEnabled = false;
226     //! \brief [SetMarker] Resource for SetMarker
227     PMOS_RESOURCE           m_presSetMarker = nullptr;
228     //! \brief [SetMarker] Number Timestamp for SetMarker
229     uint32_t                setMarkerNumTs = 0;
230     //! \brief [CENC Decode] Indicates if it's a full frame
231     bool                    m_bFullFrameData = false;
232     //! \brief MSDK event handling
233     HANDLE                  m_gpuAppTaskEvent;
234     //! \brief execution call index in multiple execution call mode
235     uint32_t                m_executeCallIndex = 0;
236     //! \brief [Decode Histogram] Input buffer to hold decode histogram
237     MOS_SURFACE             m_histogramSurface = {};
238 };
239 
240 typedef enum _CODECHAL_DUMMY_REFERENCE_STATUS
241 {
242     CODECHAL_DUMMY_REFERENCE_INVALID,
243     CODECHAL_DUMMY_REFERENCE_DPB,
244     CODECHAL_DUMMY_REFERENCE_DEST_SURFACE,
245     CODECHAL_DUMMY_REFERENCE_ALLOCATED
246 } CODECHAL_DUMMY_REFERENCE_STATUS;
247 
248 //!
249 //! \class CodechalDecodeRestoreData
250 //! \brief This class restore the data when destory, used as temporal storage and restore automatically.
251 //!
252 template   <typename T>
253 class CodechalDecodeRestoreData
254 {
255 public:
256     //!
257     //! \brief    Constructor
258     //!
CodechalDecodeRestoreData(T * mem)259     CodechalDecodeRestoreData(T *mem):
260         m_mem(mem)
261     {
262         if (m_mem != nullptr)
263         {
264             m_restoreValue = *mem;
265         }
266     }
267     //!
268     //! \brief    Constructor
269     //!
CodechalDecodeRestoreData(T * mem,T restoreValue)270     CodechalDecodeRestoreData(T *mem, T restoreValue):
271         m_mem(mem)
272     {
273         if (m_mem != nullptr)
274         {
275             m_restoreValue = restoreValue;
276         }
277     }
278 
279     //!
280     //! \brief    Destructor
281     //!
~CodechalDecodeRestoreData()282     ~CodechalDecodeRestoreData()
283     {
284         if (m_mem != nullptr)
285         {
286             *m_mem = m_restoreValue;
287         }
288     }
289 
290 private:
291     T * m_mem = nullptr;          //!< Point to the memory need to be restored when this class destroy
292     T m_restoreValue = {};   //!< The value to be restored to memory when this class destroy
293 };
294 #endif  // __CODEC_DEF_DECODE_H__
295