Debian Codegraph @

media_driver/agnostic/common/codec/hal/codechal_decode_avc.h

raw
1 /*
2 * Copyright (c) 2011-2017, 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 codechal_decode_avc.h
24 //! \brief Defines the decode interface extension for AVC.
25 //! \details Defines all types, macros, and functions required by CodecHal for AVC decoding.
26 //! Definitions are not externally facing.
27 //!
28
29 #ifndef __CODECHAL_DECODER_AVC_H__
30 #define __CODECHAL_DECODER_AVC_H__
31
32 #include "codechal.h"
33 #include "codechal_decoder.h"
34 #include "codechal_decode_sfc_avc.h"
35
36 //!
37 //! \def CODECHAL_DECODE_AVC_MONOPIC_CHROMA_DEFAULT
38 //! default chroma value for mono picture
39 //!
40 #define CODECHAL_DECODE_AVC_MONOPIC_CHROMA_DEFAULT 0x80
41
42 //!
43 //! \def CODECHAL_DECODE_AVC_INVALID_FRAME_IDX
44 //! invalid value for invalid frame index
45 //!
46 #define CODECHAL_DECODE_AVC_INVALID_FRAME_IDX 0xFF
47
48 //!
49 //! \def CODECHAL_DECODE_AVC_INVALID_REFPIC_VALUE
50 //! invalid value for invalid ref frame index
51 //!
52 #define CODECHAL_DECODE_AVC_INVALID_REFPIC_VALUE 0x80
53
54 //!
55 //! \def CODECHAL_DECODE_AVC_MAX_NUM_MVC_VIEWS
56 //! max mvc views
57 //!
58 #define CODECHAL_DECODE_AVC_MAX_NUM_MVC_VIEWS 16
59
60 typedef class CodechalDecodeAvc *PCODECHAL_DECODE_AVC_STATE;
61
62 //!
63 //! \class CodechalDecodeAvc
64 //! \brief This class defines the member fields, functions etc used by AVC decoder.
65 //!
66 class CodechalDecodeAvc : public CodechalDecode
67 {
68 public:
69
70 //!
71 //! \brief Define params for AVC picture decoding
72 //!
73 struct PIC_MHW_PARAMS
74 {
75 MHW_VDBOX_PIPE_MODE_SELECT_PARAMS PipeModeSelectParams;
76 MHW_VDBOX_SURFACE_PARAMS SurfaceParams;
77 MHW_VDBOX_PIPE_BUF_ADDR_PARAMS PipeBufAddrParams;
78 MHW_VDBOX_IND_OBJ_BASE_ADDR_PARAMS IndObjBaseAddrParams;
79 MHW_VDBOX_BSP_BUF_BASE_ADDR_PARAMS BspBufBaseAddrParams;
80 MHW_VDBOX_QM_PARAMS QmParams;
81 MHW_VDBOX_PIC_ID_PARAMS PicIdParams;
82 MHW_VDBOX_AVC_IMG_PARAMS ImgParams;
83 MHW_VDBOX_AVC_DIRECTMODE_PARAMS AvcDirectmodeParams;
84 };
85
86 //!
87 //! \brief Constructor
88 //! \param [in] hwInterface
89 //! Hardware interface
90 //! \param [in] debugInterface
91 //! Debug interface
92 //! \param [in] standardInfo
93 //! The information of decode standard for this instance
94 //!
95 CodechalDecodeAvc(
96 CodechalHwInterface *hwInterface,
97 CodechalDebugInterface* debugInterface,
98 PCODECHAL_STANDARD_INFO standardInfo);
99
100 //!
101 //! \brief Copy constructor
102 //!
103 CodechalDecodeAvc(const CodechalDecodeAvc&) = delete;
104
105 //!
106 //! \brief Copy assignment operator
107 //!
108 CodechalDecodeAvc& operator=(const CodechalDecodeAvc&) = delete;
109
110 //!
111 //! \brief Destructor
112 //!
113 ~CodechalDecodeAvc();
114
115 //!
116 //! \brief Allocate and initialize AVC decoder standard
117 //! \param [in] settings
118 //! Pointer to CodechalSetting
119 //! \return MOS_STATUS
120 //! MOS_STATUS_SUCCESS if success, else fail reason
121 //!
122 MOS_STATUS AllocateStandard(
123 CodechalSetting * settings) override;
124
125 //!
126 //! \brief Set states for each frame to prepare for AVC decode
127 //! \return MOS_STATUS
128 //! MOS_STATUS_SUCCESS if success, else fail reason
129 //!
130 MOS_STATUS SetFrameStates() override;
131
132 //!
133 //! \brief AVC decoder state level function
134 //! \details State level function for AVC decoder
135 //!
136 //! \return MOS_STATUS
137 //! MOS_STATUS_SUCCESS if success, else fail reason
138 //!
139 MOS_STATUS DecodeStateLevel() override;
140
141 //!
142 //! \brief AVC decoder primitive level function
143 //! \details Primitive level function for GEN specific AVC decoder
144 //!
145 //! \return MOS_STATUS
146 //! MOS_STATUS_SUCCESS if success, else fail reason
147 //!
148 MOS_STATUS DecodePrimitiveLevel() override;
149
150 //!
151 //! \brief AVC decoder downsampling calc function
152 //! \details calc downsample param for GEN specific AVC decoder
153 //!
154 //! \return MOS_STATUS
155 //! MOS_STATUS_SUCCESS if success, else fail reason
156 //!
157 MOS_STATUS CalcDownsamplingParams(
158 void *picParams,
159 uint32_t *refSurfWidth,
160 uint32_t *refSurfHeight,
161 MOS_FORMAT *format,
162 uint8_t *frameIdx) override;
163
164 //!
165 //! \brief Allocate fixed sized resources
166 //! \details Allocate fixed sized resources AVC decode driver
167 //! \return MOS_STATUS
168 //! MOS_STATUS_SUCCESS if success, else fail reason
169 //!
170 MOS_STATUS AllocateResourcesFixedSizes();
171
172 //!
173 //! \brief Allocate variable sized resources
174 //! \details Allocate variable sized resources in AVC decode driver
175 //! \return MOS_STATUS
176 //! MOS_STATUS_SUCCESS if success, else fail reason
177 //!
178 MOS_STATUS AllocateResourcesVariableSizes();
179
180 //!
181 //! \brief Allocate invalid ref buffer
182 //! \details Allocate invalid ref buffer in AVC decode driver
183 //! \return MOS_STATUS
184 //! MOS_STATUS_SUCCESS if success, else fail reason
185 //!
186 MOS_STATUS AllocateInvalidRefBuffer();
187
188 //!
189 //! \brief Set Picture Struct
190 //! \details Set Picture Struct in AVC decode driver
191 //! \return MOS_STATUS
192 //! MOS_STATUS_SUCCESS if success, else fail reason
193 //!
194 MOS_STATUS SetPictureStructs();
195
196 //!
197 //! \brief Set and Alloc Dmv Buffer
198 //! \details Set and Alloc Dmv Buffer in AVC decode driver
199 //!
200 //! \param [in] avcMVBufList
201 //! Pointer to MV Buf List
202 //! \param [in] usedForRef
203 //! indicate it is used for ref
204 //! \param [in] frameIdx
205 //! frame idx
206 //! \param [in] avcDmvBufferSize
207 //! Dmv Bufer Size
208 //! \param [out] dmvIdx
209 //! Dmv Index
210 //! \param [out] avcDmvBuffers
211 //! Dmv Buffers
212 //!
213 //! \return MOS_STATUS
214 //! MOS_STATUS_SUCCESS if success, else fail reason
215 //!
216 MOS_STATUS SetAndAllocateDmvBufferIndex(
217 PCODEC_AVC_DMV_LIST avcMVBufList,
218 bool usedForRef,
219 uint8_t frameIdx,
220 uint32_t avcDmvBufferSize,
221 uint8_t *dmvIdx,
222 MOS_RESOURCE *avcDmvBuffers);
223
224 //!
225 //! \brief Set and Alloc Dmv Buffer
226 //! \details Set and Alloc Dmv Buffer in AVC decode driver
227 //!
228 //! \param [in] frameIdx
229 //! frame idx
230 //! \param [in] avcDmvBufferSize
231 //! Dmv Bufer Size
232 //! \param [out] dmvIdx
233 //! Dmv Index
234 //! \param [out] avcDmvBuffers
235 //! Dmv Buffers
236 //!
237 //! \return MOS_STATUS
238 //! MOS_STATUS_SUCCESS if success, else fail reason
239 //!
240 MOS_STATUS SetAndAllocateDmvBufferIndexMismatched(
241 uint8_t frameIdx,
242 uint32_t avcDmvBufferSize,
243 uint8_t *dmvIdx,
244 MOS_RESOURCE *avcDmvBuffers);
245
246 //!
247 //! \brief Init Mvc Dummy Dmv Buffer
248 //! \details Init Mvc Dummy Dmv Buffer in AVC decode driver
249 //!
250 //! \param [in] mvcWaDummyDmvBuf
251 //! Pointer to Mvc Wa Dummy Dmv Buf
252 //! \param [in] size
253 //! Dmv Bufer Size
254 //! \param [out] mvcDummyDmvBuffer
255 //! Pointer to Mvc Dummy Dmv Buffer Resource
256 //!
257 //! \return MOS_STATUS
258 //! MOS_STATUS_SUCCESS if success, else fail reason
259 //!
260 MOS_STATUS InitMvcDummyDmvBuffer(
261 uint32_t *mvcWaDummyDmvBuf,
262 uint32_t size,
263 PMOS_RESOURCE mvcDummyDmvBuffer);
264
265 //!
266 //! \brief Initialize AVC picture HW parameters
267 //! \details Initialize picture parameters for GEN specific AVC decoder
268 //!
269 //! \param [in] picMhwParams
270 //! Pointer to PIC_MHW_PARAMS
271 //!
272 //! \return MOS_STATUS
273 //! MOS_STATUS_SUCCESS if success, else fail reason
274 //!
275 virtual MOS_STATUS InitPicMhwParams(
276 PIC_MHW_PARAMS *picMhwParams);
277
278 //!
279 //! \brief Add picture commands
280 //! \details Add picture commands for GEN specific AVC decoder
281 //!
282 //! \param [in] cmdBuf
283 //! Pointer to PMOS_COMMAND_BUFFER
284 //! \param [in] picMhwParams
285 //! Pointer to PIC_MHW_PARAMS
286 //!
287 //! \return MOS_STATUS
288 //! MOS_STATUS_SUCCESS if success, else fail reason
289 //!
290 virtual MOS_STATUS AddPictureCmds(
291 PMOS_COMMAND_BUFFER cmdBuf,
292 PIC_MHW_PARAMS *picMhwParams);
293
294 //!
295 //! \brief Parse AVC slice parameters
296 //! \details Parse slice parameters for GEN specific AVC decoder
297 //!
298 //! \param [in] cmdBuf
299 //! Pointer to PMOS_COMMAND_BUFFER
300 //!
301 //! \return MOS_STATUS
302 //! MOS_STATUS_SUCCESS if success, else fail reason
303 //!
304 MOS_STATUS ParseSlice(
305 PMOS_COMMAND_BUFFER cmdBuf);
306
307 //!
308 //! \brief Send Slice Command
309 //! \details Send Slice Command in AVC decode driver
310 //!
311 //! \param [in] avcSliceState
312 //! Pointer to AVC Slice State
313 //! \param [out] cmdBuffer
314 //! Pointer to Command buffer
315 //!
316 //! \return MOS_STATUS
317 //! MOS_STATUS_SUCCESS if success, else fail reason
318 //!
319 MOS_STATUS SendSlice(
320 PMHW_VDBOX_AVC_SLICE_STATE avcSliceState,
321 PMOS_COMMAND_BUFFER cmdBuffer);
322
323 //!
324 //! \brief Constrcut Mono Picture
325 //! \details Constrcut Mono Picture in AVC decode driver, Write 0x80 in the chroma plane for Monochrome clips
326 //! \param [in] surface
327 //! Pointer to the decode output surface
328 //! \return MOS_STATUS
329 //! MOS_STATUS_SUCCESS if success, else fail reason
330 //!
331 virtual MOS_STATUS FormatAvcMonoPicture(PMOS_SURFACE surface);
332
333 //!
334 //! \brief Set frame store Id for avc codec.
335 //! \details
336 //! \param [in] frameIdx
337 //! frame index
338 //! \return MOS_STATUS
339 //! MOS_STATUS_SUCCESS if success, else fail reason
340 //!
341 MOS_STATUS SetFrameStoreIds(uint8_t frameIdx);
342
343 MOS_STATUS InitMmcState() override;
344
345 //!
346 //! \brief Initialize Sfc state for AVC decode
347 //!
348 //! \return MOS_STATUS
349 //! MOS_STATUS_SUCCESS if success, else fail reason
350 //!
351 virtual MOS_STATUS InitSfcState();
352
353 #if USE_CODECHAL_DEBUG_TOOL
354 MOS_STATUS DumpMvcExtPicParams(
355 PCODEC_MVC_EXT_PIC_PARAMS mvcExtPicParams);
356
357 MOS_STATUS DumpPicParams(
358 PCODEC_AVC_PIC_PARAMS picParams);
359
360 MOS_STATUS DumpSliceParams(
361 PCODEC_AVC_SLICE_PARAMS sliceParams,
362 uint32_t numSlices);
363
364 MOS_STATUS DumpIQParams(
365 PCODEC_AVC_IQ_MATRIX_PARAMS matrixData);
366 #endif
367
368 protected:
369 //!
370 //! \brief Indicates whether or not the SFC is inuse
371 //! \return If SFC is inuse
372 //!
373 bool IsSfcInUse(CodechalSetting * codecHalSettings) override
374 {
375 return (codecHalSettings->downsamplingHinted && (MEDIA_IS_SKU(m_skuTable, FtrSFCPipe) && !MEDIA_IS_SKU(m_skuTable, FtrDisableVDBox2SFC)));
376 }
377
378 public:
379 // Parameters passed by application
380 uint16_t m_picWidthInMb; //!< Picture Width in MB
381 uint16_t m_picHeightInMb; //!< Picture Height in MB
382 uint16_t m_picWidthInMbLastMaxAlloced; //!< Max Picture Width in MB used for buffer allocation in past frames
383 uint16_t m_picHeightInMbLastMaxAlloced; //!< Max Picture Height in MB used for buffer allocation in past frames
384 uint32_t m_dataSize; //!< Data size
385 uint32_t m_dataOffset; //!< Date offset
386 uint32_t m_numSlices; //!< Num of slices
387 uint32_t m_avcDmvBufferSize; //!< DMV Buffer Size
388 uint8_t m_avcMvBufferIndex; //!< MV Buffer Index
389 uint16_t m_bsdMpcRowStoreScratchBufferPicWidthInMb; //!< Bsd Mpc RowStore Scratch Buffer Pic Width in MB
390 uint16_t m_mfdIntraRowStoreScratchBufferPicWidthInMb; //!< Mfd Intra RowStore Scratch Buffer Pic Width in MB
391 uint16_t m_mprRowStoreScratchBufferPicWidthInMb; //!< Mpr RowStore Scratch Buffer Pic Width in MB
392 uint8_t m_firstFieldIdxList[CODECHAL_DECODE_AVC_MAX_NUM_MVC_VIEWS]; //!< First Field Index List
393 uint32_t m_refSurfaceNum; //!< Number of reference frame surface
394
395 bool m_isSecondField; //!< Indicate it is second field
396 bool m_intelEntrypointInUse; //!< Indicate it is Intel-specific Format
397 bool m_shortFormatInUse; //!< Indicate it is Short Format
398 bool m_picIdRemappingInUse; //!< Indicate PicId Remapping are in use
399 bool m_deblockingEnabled; //!< Indicate Deblocking is enabled
400 bool m_fullFrameData; //!< Indicate it is a full frame
401
402 #ifdef _DECODE_PROCESSING_SUPPORTED
403 CodechalAvcSfcState *m_sfcState = nullptr; //!< Avc Sfc State
404 #endif
405
406 CODEC_PICTURE m_currPic; //!< Current Picture Struct
407 CODEC_AVC_FRAME_STORE_ID m_avcFrameStoreId[CODEC_AVC_MAX_NUM_REF_FRAME]; //!< Avc Frame Store ID
408 CODEC_AVC_DMV_LIST m_avcDmvList[CODEC_AVC_NUM_DMV_BUFFERS]; //!< Avc Dmv List
409 CODEC_PIC_ID m_avcPicIdx[CODEC_AVC_MAX_NUM_REF_FRAME]; //!< Avc Pic Index
410
411 PCODEC_REF_LIST m_avcRefList[CODEC_AVC_NUM_UNCOMPRESSED_SURFACE]; //!< Pointer to AVC Ref List
412 PCODEC_AVC_PIC_PARAMS m_avcPicParams; //!< Pointer to AVC picture parameter
413 PCODEC_MVC_EXT_PIC_PARAMS m_mvcExtPicParams; //!< Pointer to MVC ext picture parameter
414 PCODEC_AVC_SLICE_PARAMS m_avcSliceParams; //!< Pointer to AVC slice parameter
415 PCODEC_AVC_IQ_MATRIX_PARAMS m_avcIqMatrixParams; //!< Pointer to AVC IQ matrix parameter
416 PCODECHAL_VLD_SLICE_RECORD m_vldSliceRecord;
417
418 MOS_RESOURCE m_resDataBuffer; //!< Handle of Data Buffer
419 MOS_RESOURCE m_resMonoPictureChromaBuffer; //!< Handle of MonoPicture's default Chroma data surface
420 MOS_RESOURCE m_resMfdIntraRowStoreScratchBuffer; //!< Handle of MFD Intra Row Store Scratch data surface
421 MOS_RESOURCE m_resMfdDeblockingFilterRowStoreScratchBuffer; //!< Handle of MFD Deblocking Filter Row Store Scratch data surface
422 MOS_RESOURCE m_resBsdMpcRowStoreScratchBuffer; //!< Handle of BSD/MPC Row Store Scratch data surface
423 MOS_RESOURCE m_resMprRowStoreScratchBuffer; //!< Handle of MPR Row Store Scratch data surface
424 MOS_RESOURCE m_resAvcDmvBuffers[CODEC_AVC_NUM_UNCOMPRESSED_SURFACE]; //!< Handle of Dmv Buffers, only used CODEC_AVC_NUM_DMV_BUFFERS normally
425 MOS_RESOURCE m_resInvalidRefBuffer; //!< Handle of Invalid Ref Buffer
426 MOS_RESOURCE m_resMvcDummyDmvBuffer[2]; //!< Handle of Mvc Dummy Dmv Buffer
427 MOS_SURFACE m_destSurface; //!< Handle of Dest data surface
428 PMOS_SURFACE m_refFrameSurface; //!< Handle of reference frame surface
429 PMOS_RESOURCE m_presReferences[CODEC_AVC_MAX_NUM_REF_FRAME]; //!< Pointer to Handle of Reference Frames
430 MOS_RESOURCE m_resSyncObjectWaContextInUse; //!< signals on the video WA context
431 MOS_RESOURCE m_resSyncObjectVideoContextInUse; //!< signals on the video context
432 };
433 #endif // __CODECHAL_DECODER_AVC_H__