xref: /aosp_15_r20/external/intel-media-driver/media_driver/linux/common/codec/ddi/media_ddi_decode_avc.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 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     media_ddi_decode_avc.h
24 //! \brief    Defines DdiDecodeAvc class for Avc decode
25 //!
26 
27 #ifndef __MEDIA_DDI_DECODER_AVC_H__
28 #define __MEDIA_DDI_DECODER_AVC_H__
29 
30 #include <va/va.h>
31 #include "media_ddi_decode_base.h"
32 
33 //!
34 //! \class  DdiDecodeAVC
35 //! \brief  Ddi decode AVC
36 //!
37 class DdiDecodeAVC : public DdiMediaDecode
38 {
39 public:
40     //!
41     //! \brief Constructor
42     //!
DdiDecodeAVC(DDI_DECODE_CONFIG_ATTR * ddiDecodeAttr)43     DdiDecodeAVC(DDI_DECODE_CONFIG_ATTR *ddiDecodeAttr) : DdiMediaDecode(ddiDecodeAttr){};
44 
45     //!
46     //! \brief Destructor
47     //!
~DdiDecodeAVC()48     virtual ~DdiDecodeAVC(){};
49 
50     // inherited virtual function
51     virtual void DestroyContext(
52         VADriverContextP ctx) override;
53 
54     virtual VAStatus RenderPicture(
55         VADriverContextP ctx,
56         VAContextID      context,
57         VABufferID       *buffers,
58         int32_t          numBuffers) override;
59 
60     virtual VAStatus SetDecodeParams() override;
61 
62     virtual void ContextInit(
63         int32_t picWidth,
64         int32_t picHeight) override;
65 
66     virtual VAStatus CodecHalInit(
67         DDI_MEDIA_CONTEXT *mediaCtx,
68         void              *ptr) override;
69 
70     virtual VAStatus AllocSliceControlBuffer(
71         DDI_MEDIA_BUFFER       *buf) override;
72 
73     virtual uint8_t* GetPicParamBuf(
74     DDI_CODEC_COM_BUFFER_MGR    *bufMgr) override;
75 
76 private:
77     //!
78     //! \brief   ParaSliceParam for Avc
79     //! \details parse the sliceParam info required by Avc decoding for
80     //!          each slice
81     //!
82     //! \param   [in] *mediaCtx
83     //!          DDI_MEDIA_CONTEXT
84     //! \param   [in] *slcParam
85     //!          VASliceParameterBufferH264
86     //! \param   [in] numSlices
87     //!             uint32_t
88     //!
89     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
90     //!          else fail reason
91     VAStatus ParseSliceParams(
92         DDI_MEDIA_CONTEXT           *mediaCtx,
93         VASliceParameterBufferH264  *slcParam,
94         uint32_t                     numSlices);
95 
96     //!
97     //! \brief   ParaQMatrixParam for Avc
98     //! \details parse the IQMatrix info required by Avc decoding
99     //!
100     //! \param   [in] *mediaCtx
101     //!          DDI_MEDIA_CONTEXT
102     //! \param   [in] *matrix
103     //!          VAIQMatrixBufferH264
104     //!
105     //! \param   [in] numSlices
106     //!          int32_t
107     //!
108     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
109     //!          else fail reason
110     VAStatus ParseIQMatrix(
111         DDI_MEDIA_CONTEXT    *mediaCtx,
112         VAIQMatrixBufferH264 *matrix);
113 
114     //! \brief   ParsePicParam for Avc
115     //! \details parse the PicParam info required by Avc decoding
116     //!
117     //! \param   [in] *mediaCtx
118     //!          DDI_MEDIA_CONTEXT
119     //! \param   [in] picParam
120     //!          VAPictureParameterBufferH264
121     //!
122     //! \param   [in] numSlices
123     //!          int32_t
124     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
125     //!          else fail reason
126     VAStatus ParsePicParams(
127         DDI_MEDIA_CONTEXT            *mediaCtx,
128         VAPictureParameterBufferH264 *picParam);
129 
130     //! \brief   Alloc SliceParam content for Avc
131     //! \details Alloc/resize SlicePram content for AVC decoding
132     //!
133     //! \param   [in] numSlices
134     //!          uint32_t the required number of slices
135     //!
136     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
137     //!          else fail reason
138     VAStatus AllocSliceParamContext(
139         uint32_t numSlices);
140 
141     //! \brief   Init resource buffer for AVC
142     //! \details Initialize and allocate the resource buffer for AVC
143     //!
144     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
145     //!          else fail reason
146     VAStatus InitResourceBuffer();
147 
148     //! \brief   Free Resource buffer for AVC
149     //!
150     void FreeResourceBuffer();
151 
152     //!
153     //! \brief    Get Slice Reference Index
154     //! \details  To change the value of  sliceParams->RefPicList[][].FrameIdx
155     //!           from the frame itself  to the index in picParams->RefFrameList
156     //!
157     //! \param    [in] picReference
158     //!           Pointer to CODEC_PICTURE
159     //! \param    [in] slcReference
160     //!           Pointer to CODEC_PICTURE
161     //!
162     //! \return   void
163     //!
164     void GetSlcRefIdx(CODEC_PICTURE *picReference, CODEC_PICTURE *slcReference);
165 
166     //!
167     //! \brief    Setup Codec Picture for AVC
168     //!
169     //! \param    [in] mediaCtx
170     //!           Pointer to DDI_MEDIA_CONTEXT
171     //! \param    [in] rtTbl
172     //!           Pointer to DDI_CODEC_RENDER_TARGET_TABLE
173     //! \param    [in] vaPic
174     //!           H264 VAPicture structure
175     //! \param    [in] fieldPicFlag
176     //!           Field picture flag
177     //! \param    [in] picReference
178     //!           Reference picture flag
179     //! \param    [in] sliceReference
180     //!           Reference slice flag
181     //! \param    [out] codecHalPic
182     //!           Pointer to CODEC_PICTURE
183     //!
184     //! \return   void
185     //!
186     void SetupCodecPicture(
187         DDI_MEDIA_CONTEXT                   *mediaCtx,
188         DDI_CODEC_RENDER_TARGET_TABLE       *rtTbl,
189         CODEC_PICTURE                       *codecHalPic,
190         VAPictureH264                       vaPic,
191         bool                                fieldPicFlag,
192         bool                                picReference,
193         bool                                sliceReference);
194 };
195 
196 #endif /* _MEDIA_DDI_DECODE_AVC_H */
197