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