xref: /aosp_15_r20/external/intel-media-driver/media_driver/agnostic/common/codec/hal/codechal_decode_vc1.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
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 //!
24 //! \file     codechal_decode_vc1.h
25 //! \brief    Defines the decode interface extension for VC1.
26 //! \details  Defines all types, macros, and functions required by CodecHal for VC1 decoding.
27 //!           Definitions are not externally facing.
28 //!
29 
30 #ifndef __CODECHAL_DECODER_VC1_H__
31 #define __CODECHAL_DECODER_VC1_H__
32 
33 #include "codechal_decoder.h"
34 
35 //!
36 //! \def CODECHAL_DECODE_VC1_UNEQUAL_FIELD_WA_SURFACES
37 //! Unequal Field Surface max index
38 //!
39 #define CODECHAL_DECODE_VC1_UNEQUAL_FIELD_WA_SURFACES   4
40 
41 //!
42 //! \def CODECHAL_DECODE_VC1_NUM_SYNC_TAGS
43 //! Sync Tags Number for StateHeap Settings
44 //!
45 #define CODECHAL_DECODE_VC1_NUM_SYNC_TAGS               36
46 
47 //!
48 //! \def CODECHAL_DECODE_VC1_INITIAL_DSH_SIZE
49 //! Initial Dsh Size for StateHeap Settings
50 //!
51 #define CODECHAL_DECODE_VC1_INITIAL_DSH_SIZE            (MHW_PAGE_SIZE * 2)
52 
53 //!
54 //! \def CODECHAL_DECODE_VC1_FAST_CHROMA_MV
55 //! Fast Chroma Mv calculation
56 //!
57 #define CODECHAL_DECODE_VC1_FAST_CHROMA_MV(cmv)         ((cmv) - ((cmv) % 2))
58 
59 //!
60 //! \def CODECHAL_DECODE_VC1_CHROMA_MV
61 //! Chroma Mv calculation
62 //!
63 #define CODECHAL_DECODE_VC1_CHROMA_MV(lmv)              (((lmv) + CODECHAL_DECODE_VC1_RndTb[(lmv) & 3]) >> 1)
64 
65 //!
66 //! \def CODECHAL_DECODE_VC1_BITSTRM_BUF_LEN
67 //! Bitstream Buffer Length
68 //!
69 #define CODECHAL_DECODE_VC1_BITSTRM_BUF_LEN             8
70 
71 //!
72 //! \def CODECHAL_DECODE_VC1_STUFFING_BYTES
73 //!
74 #define CODECHAL_DECODE_VC1_STUFFING_BYTES              64
75 
76 //!
77 //! \def CODECHAL_DECODE_VC1_SC_PREFIX_LENGTH
78 //! Sc prefix lengith
79 //!
80 #define CODECHAL_DECODE_VC1_SC_PREFIX_LENGTH            3
81 
82 //!
83 //! \struct CODECHAL_VC1_VLD_SLICE_RECORD
84 //! VC1 slice record
85 //!
86 typedef struct _CODECHAL_VC1_VLD_SLICE_RECORD
87 {
88     uint32_t   dwSkip;
89     uint32_t   dwOffset;
90     uint32_t   dwLength;
91     uint32_t   dwSliceYOffset;
92     uint32_t   dwNextSliceYOffset;
93 } CODECHAL_VC1_VLD_SLICE_RECORD, *PCODECHAL_VC1_VLD_SLICE_RECORD;
94 
95 //!
96 //! \enum CODECHAL_DECODE_VC1_BINDING_TABLE_OFFSET_OLP
97 //! VC1 OLP Binding Table Offset
98 //!
99 typedef enum _CODECHAL_DECODE_VC1_BINDING_TABLE_OFFSET_OLP
100 {
101     CODECHAL_DECODE_VC1_OLP_SRC_Y = 0,
102     CODECHAL_DECODE_VC1_OLP_SRC_UV = 1,
103     CODECHAL_DECODE_VC1_OLP_DST_Y = 3,
104     CODECHAL_DECODE_VC1_OLP_DST_UV = 4,
105     CODECHAL_DECODE_VC1_OLP_NUM_SURFACES = 6
106 }CODECHAL_DECODE_VC1_BINDING_TABLE_OFFSET_OLP;
107 
108 //!
109 //! \enum CODECHAL_DECODE_VC1_DMV_INDEX
110 //! VC1 DMV index
111 //!
112 typedef enum _CODECHAL_DECODE_VC1_DMV_INDEX
113 {
114     CODECHAL_DECODE_VC1_DMV_EVEN = 0,
115     CODECHAL_DECODE_VC1_DMV_ODD = 1,
116     CODECHAL_DECODE_VC1_DMV_MAX = 2
117 }CODECHAL_DECODE_VC1_DMV_INDEX;
118 
119 //!
120 //! \struct _CODECHAL_DECODE_VC1_I_LUMA_BLOCKS
121 //! \brief  Define Look Up Table Structure for Luma Polarity of Interlaced Picture
122 //!
123 typedef struct _CODECHAL_DECODE_VC1_I_LUMA_BLOCKS
124 {
125     uint8_t u8NumSamePolarity;
126     union
127     {
128         uint8_t u8Polarity;
129         uint8_t u8MvIndex0;
130     };
131     uint8_t u8MvIndex1;
132     uint8_t u8MvIndex2;
133     uint8_t u8MvIndex3;
134 }CODECHAL_DECODE_VC1_I_LUMA_BLOCKS;
135 
136 //!
137 //! \struct _CODECHAL_DECODE_VC1_P_LUMA_BLOCKS
138 //! \brief  Define Look Up Table for Luma Inter-coded Blocks of Progressive Picture
139 //!
140 typedef struct _CODECHAL_DECODE_VC1_P_LUMA_BLOCKS
141 {
142     uint8_t u8NumIntercodedBlocks;
143     uint8_t u8MvIndex1;
144     uint8_t u8MvIndex2;
145     uint8_t u8MvIndex3;
146 }CODECHAL_DECODE_VC1_P_LUMA_BLOCKS;
147 
148 //!
149 //! \struct _CODECHAL_DECODE_VC1_BITSTREAM
150 //! \brief  Define variables for VC1 bitstream
151 //!
152 typedef struct _CODECHAL_DECODE_VC1_BITSTREAM
153 {
154     uint8_t*    pOriginalBitBuffer;                                   // pointer to the original capsuted bitstream
155     uint8_t*    pOriginalBufferEnd;                                   // pointer to the end of the original uncapsuted bitstream
156     uint32_t    u32ZeroNum;                                           // number of continuous zeros before the current bype.
157     uint32_t    u32ProcessedBitNum;                                   // number of bits being processed from initiation
158     uint8_t     CacheBuffer[CODECHAL_DECODE_VC1_BITSTRM_BUF_LEN + 4]; // cache buffer of uncapsuted raw bitstream
159     uint32_t*   pu32Cache;                                            // pointer to the cache buffer
160     uint32_t*   pu32CacheEnd;                                         // pointer to the updating end of the cache buffer
161     uint32_t*   pu32CacheDataEnd;                                     // pointer to the last valid uint32_t of the cache buffer
162     int32_t     iBitOffset;                                           // offset = 32 is the MSB, offset = 1 is the LSB.
163     int32_t     iBitOffsetEnd;                                        // bit offset of the last valid uint32_t
164     bool        bIsEBDU;                                              // 1 if it is EBDU and emulation prevention bytes are present.
165 } CODECHAL_DECODE_VC1_BITSTREAM, *PCODECHAL_DECODE_VC1_BITSTREAM;
166 
167 //!
168 //! \struct _CODECHAL_DECODE_VC1_OLP_PARAMS
169 //! \brief  Define variables of VC1 Olp params for hw cmd
170 //!
171 typedef struct _CODECHAL_DECODE_VC1_OLP_PARAMS
172 {
173     PMOS_COMMAND_BUFFER         pCmdBuffer;
174     PMHW_PIPE_CONTROL_PARAMS    pPipeControlParams;
175     PMHW_STATE_BASE_ADDR_PARAMS pStateBaseAddrParams;
176     PMHW_VFE_PARAMS             pVfeParams;
177     PMHW_CURBE_LOAD_PARAMS      pCurbeLoadParams;
178     PMHW_ID_LOAD_PARAMS         pIdLoadParams;
179 }CODECHAL_DECODE_VC1_OLP_PARAMS, *PCODECHAL_DECODE_VC1_OLP_PARAMS;
180 
181 //!
182 //! \struct _CODECHAL_DECODE_VC1_OLP_STATIC_DATA
183 //! \brief  Define VC1 OLP Static Data
184 //!
185 typedef struct _CODECHAL_DECODE_VC1_OLP_STATIC_DATA
186 {
187     // uint32_t 0
188     union
189     {
190         struct
191         {
192             uint32_t   Reserved;
193         };
194         struct
195         {
196             uint32_t   Value;
197         };
198     } DW0;
199 
200     // uint32_t 1
201     union
202     {
203         struct
204         {
205             uint32_t   BlockWidth                      : 16;   // in byte
206             uint32_t   BlockHeight                     : 16;   // in byte
207         };
208         struct
209         {
210             uint32_t   Value;
211         };
212     } DW1;
213 
214     // uint32_t 2
215     union
216     {
217         struct
218         {
219             uint32_t   Profile                         : 1;
220             uint32_t   RangeExpansionFlag              : 1;    // Simple & Main Profile only
221             uint32_t   PictureUpsamplingFlag           : 2;    // 2:H, 3:V
222             uint32_t                                   : 1;
223             uint32_t   InterlaceFieldFlag              : 1;
224             uint32_t                                   : 2;
225             uint32_t   RangeMapUV                      : 3;
226             uint32_t   RangeMapUVFlag                  : 1;
227             uint32_t   RangeMapY                       : 3;
228             uint32_t   RangeMapYFlag                   : 1;
229             uint32_t                                   : 4;
230             uint32_t   ComponentFlag                   : 1;
231             uint32_t                                   : 11;
232         };
233         struct
234         {
235             uint32_t   Value;
236         };
237     } DW2;
238 
239     // uint32_t 3
240     union
241     {
242         struct
243         {
244             uint32_t   Reserved;
245         };
246         struct
247         {
248             uint32_t   Value;
249         };
250     } DW3;
251 
252     // uint32_t 4
253     union
254     {
255         struct
256         {
257             uint32_t   SourceDataBindingIndex;
258         };
259         struct
260         {
261             uint32_t   Value;
262         };
263     } DW4;
264 
265     // uint32_t 5
266     union
267     {
268         struct
269         {
270             uint32_t   DestDataBindingIndex;
271         };
272         struct
273         {
274             uint32_t   Value;
275         };
276     } DW5;
277 
278     // uint32_t 6
279     union
280     {
281         struct
282         {
283             uint32_t   Reserved;
284         };
285         struct
286         {
287             uint32_t   Value;
288         };
289     } DW6;
290 
291     // uint32_t 7
292     union
293     {
294         struct
295         {
296             uint32_t   Reserved;
297         };
298         struct
299         {
300             uint32_t   Value;
301         };
302     } DW7;
303 
304 } CODECHAL_DECODE_VC1_OLP_STATIC_DATA, *PCODECHAL_DECODE_VC1_OLP_STATIC_DATA;
305 
306 //!
307 //! \def CODECHAL_DECODE_VC1_CURBE_SIZE_OLP
308 //! VC1 Curbe Size for Olp
309 //!
310 #define CODECHAL_DECODE_VC1_CURBE_SIZE_OLP          (sizeof(CODECHAL_DECODE_VC1_OLP_STATIC_DATA))
311 
312 //!
313 //! \struct _CODECHAL_DECODE_VC1_KERNEL_HEADER_CM
314 //! \brief Define VC1 Kernel Header CM
315 //!
316 typedef struct _CODECHAL_DECODE_VC1_KERNEL_HEADER_CM {
317     int nKernelCount;
318 
319     CODECHAL_KERNEL_HEADER OLP;
320     CODECHAL_KERNEL_HEADER IC;
321 } CODECHAL_DECODE_VC1_KERNEL_HEADER_CM, *PCODECHAL_DECODE_VC1_KERNEL_HEADER_CM;
322 
323 //*------------------------------------------------------------------------------
324 //* Codec Definitions
325 //*------------------------------------------------------------------------------
326 
327 //!
328 //! \class CodechalDecodeVc1
329 //! \brief This class defines the member fields, functions etc used by VC1 decoder.
330 //!
331 class CodechalDecodeVc1 : public CodechalDecode
332 {
333 public:
334     //!
335     //! \brief    Constructor
336     //! \param    [in] hwInterface
337     //!           Hardware interface
338     //! \param    [in] debugInterface
339     //!           Debug interface
340     //! \param    [in] standardInfo
341     //!           The information of decode standard for this instance
342     //!
343     CodechalDecodeVc1(
344         CodechalHwInterface   *hwInterface,
345         CodechalDebugInterface* debugInterface,
346         PCODECHAL_STANDARD_INFO standardInfo);
347 
348     //!
349     //! \brief    Copy constructor
350     //!
351     CodechalDecodeVc1(const CodechalDecodeVc1&) = delete;
352 
353     //!
354     //! \brief    Copy assignment operator
355     //!
356     CodechalDecodeVc1& operator=(const CodechalDecodeVc1&) = delete;
357 
358     //!
359     //! \brief    Destructor
360     //!
361     ~CodechalDecodeVc1();
362 
363     //!
364     //! \brief    Allocate and initialize VC1 decoder standard
365     //! \param    [in] settings
366     //!           Pointer to CodechalSetting
367     //! \return   MOS_STATUS
368     //!           MOS_STATUS_SUCCESS if success, else fail reason
369     //!
370     MOS_STATUS  AllocateStandard(
371         CodechalSetting *          settings) override;
372 
373     //!
374     //! \brief  Set states for each frame to prepare for VC1 decode
375     //! \return MOS_STATUS
376     //!         MOS_STATUS_SUCCESS if success, else fail reason
377     //!
378     MOS_STATUS  SetFrameStates() override;
379 
380     //!
381     //! \brief    VC1 decoder state level function
382     //! \details  State level function for VC1 decoder
383     //! \return   MOS_STATUS
384     //!           MOS_STATUS_SUCCESS if success, else fail reason
385     //!
386     MOS_STATUS  DecodeStateLevel() override;
387 
388     //!
389     //! \brief    VC1 decoder primitive level function
390     //! \details  Primitive level function for GEN specific VC1 decoder
391     //! \return   MOS_STATUS
392     //!           MOS_STATUS_SUCCESS if success, else fail reason
393     //!
394     MOS_STATUS  DecodePrimitiveLevel() override;
395 
396     MOS_STATUS  InitMmcState() override;
397 
398     //!
399     //! \brief    VC1 decoder primitive level function for VLD mode
400     //! \details  Primitive level function for GEN specific VC1 decoder for VLD mode
401     //! \return   MOS_STATUS
402     //!           MOS_STATUS_SUCCESS if success, else fail reason
403     //!
404     virtual  MOS_STATUS  DecodePrimitiveLevelVLD();
405 
406     //!
407     //! \brief    VC1 decoder primitive level function for IT mode
408     //! \details  Primitive level function for GEN specific VC1 decoder for IT mode
409     //! \return   MOS_STATUS
410     //!           MOS_STATUS_SUCCESS if success, else fail reason
411     //!
412     virtual MOS_STATUS  DecodePrimitiveLevelIT();
413 
414     // no downsampling
415 
416     //!
417     //! \brief    Allocate resources for VC1 decoder
418     //! \details  Allocate resources for VC1 decoder
419     //! \return   MOS_STATUS
420     //!           MOS_STATUS_SUCCESS if success, else fail reason
421     //!
422     virtual MOS_STATUS AllocateResources();
423 
424     //!
425     //! \brief    Set GEN specific Curbe data for VC1 OLP
426     //! \details  Configure Curbe data for VC1 OLP Y / UV component
427     //! \return   MOS_STATUS
428     //!           MOS_STATUS_SUCCESS if success, else fail reason
429     //!
430     virtual MOS_STATUS SetCurbeOlp();
431 
432     //!
433     //! \brief    Update VC1 Kernel State
434     //! \details  Get Decode Kernel and Update Kernel State
435     //! \return   MOS_STATUS
436     //!           MOS_STATUS_SUCCESS if success, else fail reason
437     //!
438     virtual MOS_STATUS UpdateVc1KernelState();
439 
440     virtual MOS_STATUS AddVc1OlpCmd(
441         PCODECHAL_DECODE_VC1_OLP_PARAMS vc1OlpParams);
442 
443     //!
444     //! \brief    Return if Olp needed
445     //! \details  Return value of member bOlpNeeded
446     //! \return   bool
447     //!           true if Olp needed, else false
448     //!
IsOlpNeeded()449     bool IsOlpNeeded() { return m_olpNeeded; };
450 
451     PCODEC_VC1_PIC_PARAMS m_vc1PicParams = nullptr;                           //!< VC1 Picture Params
452     MOS_SURFACE           m_destSurface;                                      //!< Pointer to MOS_SURFACE of render surface
453     PMOS_RESOURCE         m_presReferences[CODEC_MAX_NUM_REF_FRAME_NON_AVC];  //!< Reference Resources Handle list
454     bool                  m_deblockingEnabled   = false;                      //!< Indicator of deblocking enabling
455     bool                  m_unequalFieldWaInUse = false;                      //!< Indicator of Unequal Field WA
456 
457 protected:
458     //!
459     //! \brief    Construct VC1 decode bitstream buffer
460     //! \details  For WaVC1ShortFormat. Construct VC1 decode bistream buffer by
461     //            adding a stuffing byte ahead of frame bitstream data. It's for
462     //            simple & main profile short format only.
463     //! \return   MOS_STATUS
464     //!           MOS_STATUS_SUCCESS if success, else fail reason
465     //!
466     MOS_STATUS ConstructBistreamBuffer();
467 
468     //!
469     //! \brief    Handle VC1 skipped frame
470     //! \details  For skipped frame, use reference frame instead
471     //! \return   MOS_STATUS
472     //!           MOS_STATUS_SUCCESS if success, else fail reason
473     //!
474     virtual MOS_STATUS HandleSkipFrame();
475 
476     //!
477     //! \brief    Initialize Unequal Field Surface
478     //! \details  Initialize Unequal Field Surface for VC1 decoder
479     //! \param    [in] refListIdx
480     //!           Index for pic in RefList
481     //! \param    [in] nullHwInUse
482     //!           Indicate if null HW is in use or not
483     //! \return   MOS_STATUS
484     //!           MOS_STATUS_SUCCESS if success, else fail reason
485     //!
486     MOS_STATUS InitializeUnequalFieldSurface(
487         uint8_t                     refListIdx,
488         bool                        nullHwInUse);
489 
490     //!
491     //! \brief    Formats destination surface for VC1 decoder
492     //! \details  Formats the destination surface, in the pack case the UV surface
493     //            is moved to be adjacent to the UV surface such that NV12
494     //            formatting is maintained when the surface is returned to SW,
495     //            in the unpack case the UV surface is moved to be 32 - pixel rows
496     //            away from the Y surface so that during decoding HW will not
497     //            overwrite the UV surface
498     //! \param    [in] srcSurface
499     //!           Source Surface
500     //! \param    [in] dstSurface
501     //!           Destiny Surface
502     //! \param    [in] pack
503     //!           Indicate pack case or unpack case
504     //! \param    [in] nullHwInUse
505     //!           Indicate if null HW is in use or not
506     //! \return   MOS_STATUS
507     //!           MOS_STATUS_SUCCESS if success, else fail reason
508     //!
509     MOS_STATUS FormatUnequalFieldPicture(
510         MOS_SURFACE                 srcSurface,
511         MOS_SURFACE                 dstSurface,
512         bool                        pack,
513         bool                        nullHwInUse);
514 
515     //!
516     //! \brief    Parse Picture Header for VC1 decoder
517     //! \details  Parse Picture Header in bitstream for VC1 decoder
518     //! \return   MOS_STATUS
519     //!           MOS_STATUS_SUCCESS if success, else fail reason
520     //!
521     MOS_STATUS ParsePictureHeader();
522 
523     //!
524     //! \brief    Parse Picture Header for VC1 decoder Advanced profile
525     //! \details  Parse Picture Header in bitstream for VC1 decoder Advaced profile
526     //! \return   MOS_STATUS
527     //!           MOS_STATUS_SUCCESS if success, else fail reason
528     //!
529     MOS_STATUS ParsePictureHeaderAdvanced();
530 
531     //!
532     //! \brief    Parse Picture Header for VC1 decoder Simple profile
533     //! \details  Parse Picture Header in bitstream for VC1 decoder Simple profile
534     //! \return   MOS_STATUS
535     //!           MOS_STATUS_SUCCESS if success, else fail reason
536     //!
537     MOS_STATUS ParsePictureHeaderMainSimple();
538 
539     //!
540     //! \brief    Initialise bitstream for VC1 decoder
541     //! \details  Initialise members' value of bitstream struct for VC1 decoder
542     //! \param    [in] buffer
543     //!           Original bitstream buffer
544     //! \param    [in] length
545     //!           Original bitstream length
546     //! \param    [in] isEBDU
547     //!           Indicate if it is EBDU
548     //! \return   MOS_STATUS
549     //!           MOS_STATUS_SUCCESS if success, else fail reason
550     //!
551     MOS_STATUS InitialiseBitstream(
552         uint8_t*                           buffer,
553         uint32_t                           length,
554         bool                               isEBDU);
555 
556     //!
557     //! \brief    Parse bitplane for VC1 decoder
558     //! \details  Parse bitplane according to bitplane mode for VC1 decoder
559     //! \return   MOS_STATUS
560     //!           MOS_STATUS_SUCCESS if success, else fail reason
561     //!
562     MOS_STATUS ParseBitplane();
563 
564     //!
565     //! \brief    Parse bitplane in Norm2 Mode for VC1 decoder
566     //! \details  Parse bitplane in Norm2 Mode for VC1 decoder
567     //! \return   MOS_STATUS
568     //!           MOS_STATUS_SUCCESS if success, else fail reason
569     //!
570     MOS_STATUS BitplaneNorm2Mode();
571 
572     //!
573     //! \brief    Parse bitplane in Norm6 Mode for VC1 decoder
574     //! \details  Parse bitplane in Norm6 Mode for VC1 decoder
575     //! \return   MOS_STATUS
576     //!           MOS_STATUS_SUCCESS if success, else fail reason
577     //!
578     MOS_STATUS BitplaneNorm6Mode();
579 
580     //!
581     //! \brief    Parse bitplane in Rowskip Mode for VC1 decoder
582     //! \details  Parse bitplane in Rowskip Mode for VC1 decoder
583     //! \return   MOS_STATUS
584     //!           MOS_STATUS_SUCCESS if success, else fail reason
585     //!
586     MOS_STATUS BitplaneRowskipMode();
587 
588     //!
589     //! \brief    Parse bitplane in Colskip Mode for VC1 decoder
590     //! \details  Parse bitplane in Colskip Mode for VC1 decoder
591     //! \return   MOS_STATUS
592     //!           MOS_STATUS_SUCCESS if success, else fail reason
593     //!
594     MOS_STATUS BitplaneColskipMode();
595 
596     //!
597     //! \brief    Parse bitplane quantization for VC1 decoder
598     //! \details  Parse bitplane quantization for VC1 decoder
599     //! \return   MOS_STATUS
600     //!           MOS_STATUS_SUCCESS if success, else fail reason
601     //!
602     MOS_STATUS ParseVopDquant();
603 
604     //!
605     //! \brief    Parse Mv Range for VC1 decoder
606     //! \details  Parse Mv Range for VC1 decoder
607     //! \return   MOS_STATUS
608     //!           MOS_STATUS_SUCCESS if success, else fail reason
609     //!
610     MOS_STATUS ParseMvRange();
611 
612     //!
613     //! \brief    Parse Progressive Mv Mode for VC1 decoder
614     //! \details  Parse Progressive Mv Mode for VC1 decoder
615     //! \param    [in] mvModeTable[]
616     //!           const MV Mode Table
617     //! \param    [out] mvMode
618     //!           pointer to Mv Mode
619     //! \return   MOS_STATUS
620     //!           MOS_STATUS_SUCCESS if success, else fail reason
621     //!
622     MOS_STATUS ParseProgressiveMvMode(
623         const uint32_t                     mvModeTable[],
624         uint32_t*                          mvMode);
625 
626     //!
627     //! \brief    Parse Interlace Mv Mode for VC1 decoder
628     //! \details  Parse Interlace Mv Mode for VC1 decoder
629     //! \param    [in] isPPicture
630     //!           indicate if it is P picture
631     //! \param    [out] mvmode
632     //!           pointer to Mv Mode
633     //! \return   MOS_STATUS
634     //!           MOS_STATUS_SUCCESS if success, else fail reason
635     //!
636     MOS_STATUS ParseInterlaceMVMode(
637         bool                               isPPicture,
638         uint32_t*                          mvmode);
639 
640     //!
641     //! \brief    Parse I Picture Layer for VC1 decoder
642     //! \details  Parse I Picture Layer for VC1 decoder advanced profile
643     //! \return   MOS_STATUS
644     //!           MOS_STATUS_SUCCESS if success, else fail reason
645     //!
646     MOS_STATUS ParsePictureLayerIAdvanced();
647 
648     //!
649     //! \brief    Parse P Picture Layer for VC1 decoder
650     //! \details  Parse P Picture Layer for VC1 decoder advanced profile
651     //! \return   MOS_STATUS
652     //!           MOS_STATUS_SUCCESS if success, else fail reason
653     //!
654     MOS_STATUS ParsePictureLayerPAdvanced();
655 
656     //!
657     //! \brief    Parse B Picture Layer for VC1 decoder
658     //! \details  Parse B Picture Layer for VC1 decoder advanced profile
659     //! \return   MOS_STATUS
660     //!           MOS_STATUS_SUCCESS if success, else fail reason
661     //!
662     MOS_STATUS ParsePictureLayerBAdvanced();
663 
664     //!
665     //! \brief    Parse P Field Picture Layer for VC1 decoder
666     //! \details  Parse P Field Picture Layer for VC1 decoder advanced profile
667     //! \return   MOS_STATUS
668     //!           MOS_STATUS_SUCCESS if success, else fail reason
669     //!
670     MOS_STATUS ParseFieldPictureLayerPAdvanced();
671 
672     //!
673     //! \brief    Parse B Field Picture Layer for VC1 decoder
674     //! \details  Parse B Field Picture Layer for VC1 decoder advanced profile
675     //! \return   MOS_STATUS
676     //!           MOS_STATUS_SUCCESS if success, else fail reason
677     //!
678     MOS_STATUS ParseFieldPictureLayerBAdvanced();
679 
680     //!
681     //! \brief    Get Macroblock Offset for VC1 decoder
682     //! \details  Get Macroblock Offset for VC1 decoder slice params
683     //! \return   MOS_STATUS
684     //!           MOS_STATUS_SUCCESS if success, else fail reason
685     //!
686     MOS_STATUS GetSliceMbDataOffset();
687 
688     //!
689     //! \brief    Perform Olp for VC1 decoder
690     //! \details  Perform Olp for VC1 decoder
691     //! \return   MOS_STATUS
692     //!           MOS_STATUS_SUCCESS if success, else fail reason
693     //!
694     MOS_STATUS PerformVc1Olp();
695 
696     //!
697     //! \brief    Initializes the VC1 OLP state
698     //! \details  Initializes the VC1 OLP state based on parameters saved in InitInterface
699     //!           command buffer or indirect state
700     //! \return   MOS_STATUS
701     //!           MOS_STATUS_SUCCESS if success, else fail reason
702     //!
703     MOS_STATUS InitKernelStateVc1Olp();
704 
705     //!
706     //! \brief    Pack Motion Vectors in Macro Block State
707     //! \param    [in] vc1MbState
708     //!           Pointer to Vc1 Macro Block State
709     //! \param    [in] mv
710     //!           Pointer to Motion Vector
711     //! \param    [out] packedLumaMvs
712     //!           Pointer to Packed Luma Motion Vectors
713     //! \param    [out] packedChromaMv
714     //!           Pointer to Packed Chroma Motion Vectors
715     //! \return   void
716     //!
717     virtual void PackMotionVectors(
718         PMHW_VDBOX_VC1_MB_STATE vc1MbState,
719         int16_t                 *mv,
720         int16_t                 *packedLumaMvs,
721         int16_t                 *packedChromaMv);
722 
723     // Parameters passed by application
724     uint16_t                m_picWidthInMb         = 0;        //!< Picture Width in MB width count
725     uint16_t                m_picHeightInMb        = 0;        //!< Picture Height in MB height count
726     bool                    m_intelEntrypointInUse = false;    //!< Indicator of using a Intel-specific entrypoint.
727     bool                    m_shortFormatInUse     = false;    //!< Short format slice data
728     bool                    m_vc1OddFrameHeight    = false;    //!< VC1 Odd Frame Height
729     uint32_t                m_dataSize             = 0;        //!< Size of the data contained in presDataBuffer
730     uint32_t                m_dataOffset           = 0;        //!< Offset of the data contained in presDataBuffer
731     uint32_t                m_numSlices            = 0;        //!< [VLD mode] Number of slices to be decoded
732     uint32_t                m_numMacroblocks       = 0;        //!< [IT mode] Number of MBs to be decoded
733     uint32_t                m_numMacroblocksUv     = 0;        //!< [IT mode] Number of UV MBs to be decoded
734     PCODEC_VC1_SLICE_PARAMS m_vc1SliceParams       = nullptr;  //!< VC1 Slice Params
735     PCODEC_VC1_MB_PARAMS    m_vc1MbParams          = nullptr;  //!< VC1 Macro Block Params
736     MOS_SURFACE             m_deblockSurface;                  //!< Deblock Surface
737     MOS_RESOURCE            m_resDataBuffer;                   //!< Handle of residual difference surface
738     MOS_RESOURCE            m_resBitplaneBuffer;               //!< Handle of Bitplane buffer
739     uint8_t *               m_deblockDataBuffer = nullptr;     //!< Pointer to the deblock data
740 
741     // Internally maintained
742     MOS_RESOURCE                   m_resMfdDeblockingFilterRowStoreScratchBuffer;        //!< Handle of MFD Deblocking Filter Row Store Scratch data surface
743     MOS_RESOURCE                   m_resBsdMpcRowStoreScratchBuffer;                     //!< Handle of BSD/MPC Row Store Scratch data surface
744     MOS_RESOURCE                   m_resVc1BsdMvData[CODECHAL_DECODE_VC1_DMV_MAX];       //!< Handle of VC1 BSD MV Data
745     PCODECHAL_VC1_VLD_SLICE_RECORD m_vldSliceRecord = nullptr;                           //!< [VLD mode] Slice record
746     uint32_t                       m_numVldSliceRecord = 0;
747     PCODEC_REF_LIST                m_vc1RefList[CODECHAL_NUM_UNCOMPRESSED_SURFACE_VC1];  //!< VC1 Reference List
748     MOS_RESOURCE                   m_resSyncObject;                                      //!< Handle of Sync Object
749     MOS_RESOURCE                   m_resPrivateBistreamBuffer;                           //!< Handle of Private Bistream Buffer
750     uint32_t                       m_privateBistreamBufferSize = 0;                      //!< Size of Private Bistream Buffer
751     CODECHAL_DECODE_VC1_BITSTREAM  m_bitstream;                                          //!< VC1 Bitstream
752     // PCODECHAL_DECODE_VC1_BITSTREAM  pBitstream;                                     //!< Pointer to Bitstream
753 
754     uint16_t m_prevAnchorPictureTff     = 0;      //!< Previous Anchor Picture Top Field First(TFF)
755     bool     m_prevEvenAnchorPictureIsP = false;  //!< Indicator of Previous Even Anchor Picture P frame
756     bool     m_prevOddAnchorPictureIsP  = false;  //!< Indicator of Previous Odd Anchor Picture P frame
757     uint16_t m_referenceDistance        = 0;      //!< REFDIST.
758 
759     // OLP related
760     MHW_KERNEL_STATE m_olpKernelState;                      //!< Olp Kernel State
761     uint8_t *        m_olpKernelBase            = nullptr;  //!< Pointer to Kernel Base Address
762     uint32_t         m_olpKernelSize            = 0;        //!< Olp Kernel Size
763     bool             m_olpNeeded                = false;    //!< Indicator if Olp Needed
764     uint16_t         m_olpPicWidthInMb          = 0;        //!< Width of Olp Pic in Macro block
765     uint16_t         m_olpPicHeightInMb         = 0;        //!< Height of Olp Pic in Macro block
766     uint32_t         m_olpCurbeStaticDataLength = 0;        //!< Olp Curbe Static Data Length
767     uint32_t         m_olpDshSize               = 0;        //!< Olp DSH Size
768 
769     // IT mode related
770     MHW_BATCH_BUFFER m_itObjectBatchBuffer;  //!< IT mode Object Batch Buffer
771     uint8_t          m_fieldPolarity = 0;    //!< Field Polarity Offset
772 
773     MOS_SURFACE m_unequalFieldSurface[CODECHAL_DECODE_VC1_UNEQUAL_FIELD_WA_SURFACES];     //!< Handle of Unequal Field Surface
774     uint8_t     m_unequalFieldRefListIdx[CODECHAL_DECODE_VC1_UNEQUAL_FIELD_WA_SURFACES];  //!< Reference list of Unequal Field Surface
775     uint8_t     m_unequalFieldSurfaceForBType = 0;                                        //!< Unequal Field Surface Index for B frame
776     uint8_t     m_currUnequalFieldSurface     = 0;                                        //!< Current Unequal Field Surface Index
777 
778     // HuC copy related
779     bool         m_huCCopyInUse;                    //!< a sync flag used when huc copy and decoder run in the different VDBOX
780     MOS_RESOURCE m_resSyncObjectWaContextInUse;     //!< signals on the video WA context
781     MOS_RESOURCE m_resSyncObjectVideoContextInUse;  //!< signals on the video context
782 
783 private:
784     //!
785     //! \brief    Wrapper function to read bits from VC1 bitstream
786     //! \param    [in] bitsRead
787     //!           Number of bits to be read
788     //! \param    [out] value
789     //!           VC1 bitstream status, EOS if reaching end of stream, else bitstream value
790     //! \return   MOS_STATUS
791     //!           MOS_STATUS_SUCCESS if success, else fail reason
792     //!
793     MOS_STATUS GetBits(uint32_t bitsRead, uint32_t &value);
794 
795     //!
796     //! \brief    Wrapper function to get VLC from VC1 bitstream according to VLC Table
797     //! \param    [in] table
798     //!           Pointer to VLC Table
799     //! \param    [out] value
800     //!           VC1 bitstream status, EOS if reaching end of stream, else bitstream value
801     //! \return   MOS_STATUS
802     //!           MOS_STATUS_SUCCESS if success, else fail reason
803     //!
804     MOS_STATUS GetVLC(const uint32_t* table, uint32_t & value);
805 
806     //!
807     //! \brief    Wrapper function to skip words from VC1 bitstream
808     //! \param    [in] dwordNumber
809     //!           Number of Dword to be skipped
810     //! \param    [out] value
811     //!           VC1 bitstream status, EOS if reaching end of stream, else bitstream value
812     //! \return   MOS_STATUS
813     //!           MOS_STATUS_SUCCESS if success, else fail reason
814     //!
815     MOS_STATUS SkipWords(uint32_t dwordNumber, uint32_t & value);
816 
817     //!
818     //! \brief    Wrapper function to skip bits from VC1 bitstream
819     //! \param    [in] bits
820     //!           Number of bits to be skipped
821     //! \param    [out] value
822     //!           VC1 bitstream status, EOS if reaching end of stream, else bitstream value
823     //! \return   MOS_STATUS
824     //!           MOS_STATUS_SUCCESS if success, else fail reason
825     //!
826     MOS_STATUS SkipBits(uint32_t bits, uint32_t & value);
827 
828     //!
829     //! \brief    Read bits from VC1 bitstream
830     //! \param    [in] bitsRead
831     //!           Number of bits to be read
832     //! \return   uint32_t
833     //!           EOS if reaching end of stream, else bitstream value
834     //!
835     uint32_t GetBits(uint32_t bitsRead);
836 
837     //!
838     //! \brief    Update VC1 bitstream memeber value
839     //! \return   uint32_t
840     //!           EOS if reaching end of stream, else bitstream value
841     //!
842     uint32_t UpdateBitstreamBuffer();
843 
844     //!
845     //! \brief    Get VLC from VC1 bitstream according to VLC Table
846     //! \param    [in] table
847     //!           Pointer to VLC Table
848     //! \return   uint32_t
849     //!           EOS if reaching end of stream, else bitstream value
850     //!
851     uint32_t GetVLC(const uint32_t *table);
852 
853     //!
854     //! \brief    Read bits from VC1 bitstream and don't update bitstream pointer
855     //! \param    [in] bitsRead
856     //!           Number of bits to be read
857     //! \return   uint32_t
858     //!           EOS if reaching end of stream, else bitstream value
859     //!
860     uint32_t PeekBits(uint32_t bitsRead);
861 
862     //!
863     //! \brief    Skip bits from VC1 bitstream
864     //! \param    [in] bits
865     //!           Number of bits to be skipped
866     //! \return   uint32_t
867     //!           EOS if reaching end of stream, else bitstream value
868     //!
869     uint32_t SkipBits(uint32_t bitsRead);
870 
871     //!
872     //! \brief    Pack Chroma/Luma Motion Vectors for Interlaced frame
873     //! \param    [in] fieldSelect
874     //!           Field Select Index
875     //! \param    [in] currentField
876     //!           Current Filed Indicator
877     //! \param    [in] fastUVMotionCompensation
878     //!           Fast UV Motion Compensation Indicator
879     //! \param    [out] lmv
880     //!           Pointer to Adjusted Luma Motion Vectors
881     //! \param    [out] cmv
882     //!           Pointer to Adjusted Chroma Motion Vectors
883     //! \return   void
884     //!
885     uint8_t PackMotionVectorsChroma4MvI(
886         uint16_t    fieldSelect,
887         uint16_t    currentField,
888         bool        fastUVMotionCompensation,
889         int16_t      *lmv,
890         int16_t      *cmv);
891 
892     //!
893     //! \brief    Pack Chroma/Luma Motion Vectors for Picture frame
894     //! \param    [in] intraFlags
895     //!           Intra Flag Index
896     //! \param    [out] lmv
897     //!           Pointer to Adjusted Luma Motion Vectors
898     //! \param    [out] cmv
899     //!           Pointer to Adjusted Chroma Motion Vectors
900     //! \return   void
901     //!
902     void PackMotionVectorsChroma4MvP(uint16_t intraFlags, int16_t *lmv, int16_t *cmv);
903 
904     //!
905     //! \brief    Find Median for 3 Motion Vectors
906     //! \param    [in] mv#
907     //!           Motion Vectors
908     //! \return   int16_t
909     //!           return median for 3 Motion Vectors
910     //!
911     int16_t PackMotionVectorsMedian3(int16_t mv1, int16_t mv2, int16_t mv3);
912     //!
913     //! \brief    Find Median for 4 Motion Vectors
914     //! \param    [in] mv#
915     //!           Motion Vectors
916     //! \return   int16_t
917     //!           return median for 4 Motion Vectors
918     //!
919     int16_t PackMotionVectorsMedian4(int16_t mv1, int16_t mv2, int16_t mv3, int16_t mv4);
920 
921 #if USE_CODECHAL_DEBUG_TOOL
922     MOS_STATUS DumpPicParams(
923         PCODEC_VC1_PIC_PARAMS vc1PicParams);
924 
925     MOS_STATUS DumpSliceParams(
926         PCODEC_VC1_SLICE_PARAMS sliceControl);
927 
928     MOS_STATUS DumpMbParams(
929         PCODEC_VC1_MB_PARAMS mbParams);
930 #endif
931 };
932 
933 #endif  // __CODECHAL_DECODER_VC1_H__
934