Debian Codegraph @

media_driver/linux/common/codec/ddi/media_ddi_encode_av1.h

raw
1 /*
2 * Copyright (c) 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 //!
24 //! \file media_ddi_encode_av1.h
25 //! \brief Defines class for DDI media av1 encode
26 //!
27
28 #ifndef __MEDIA_LIBVA_ENCODER_AV1_H__
29 #define __MEDIA_LIBVA_ENCODER_AV1_H__
30
31 #define TILE_GROUP_NUM_INCREMENT 8
32
33 #include "media_ddi_encode_base.h"
34 #include "codec_def_encode_av1.h"
35 #include "codec_def_encode_vp9.h"
36
37 //!
38 //! \class DdiEncodeAV1
39 //! \brief Ddi encode AV1
40 //!
41 class DdiEncodeAV1 : public DdiEncodeBase
42 {
43 public:
44 //!
45 //! \brief Constructor
46 //!
47 DdiEncodeAV1(){};
48
49 //!
50 //! \brief Destructor
51 //!
52 ~DdiEncodeAV1();
53
54 //!
55 //! \brief Initialize Encode Context and CodecHal Setting for AV1
56 //!
57 //! \param [out] codecHalSettings
58 //! Pointer to CodecHalSetting *
59 //!
60 //! \return VAStatus
61 //! VA_STATUS_SUCCESS if successs, else fail reason
62 //!
63 VAStatus ContextInitialize(CodechalSetting *codecHalSettings) override;
64
65 //!
66 //! \brief Parse buffer to the server.
67 //!
68 //! \param [in] ctx
69 //! Pointer to VADriverContextP
70 //! \param [in] context
71 //! VA context ID
72 //! \param [in] buffers
73 //! Pointer to VABufferID
74 //! \parsm [in] numBuffers
75 //! Number of buffers
76 //!
77 //! \return VAStatus
78 //! VA_STATUS_SUCCESS if success, else fail reason
79 //!
80 VAStatus RenderPicture(
81 VADriverContextP ctx,
82 VAContextID context,
83 VABufferID *buffers,
84 int32_t numBuffers) override;
85
86 protected:
87 //!
88 //! \brief Reset Encode Context At Frame Level
89 //!
90 //! \return VAStatus
91 //! VA_STATUS_SUCCESS if success, else fail reason
92 //!
93 VAStatus ResetAtFrameLevel() override;
94
95 //!
96 //! \brief Encode in CodecHal for Hevc
97 //!
98 //! \param [in] numSlices
99 //! Number of slice data structures
100 //!
101 //! \return VAStatus
102 //! VA_STATUS_SUCCESS if success, else fail reason
103 //!
104 VAStatus EncodeInCodecHal(uint32_t numSlices) override;
105
106 //!
107 //! \brief Parse Picture Parameter buffer to Encode Context
108 //!
109 //! \param [in] mediaCtx
110 //! Pointer to DDI_MEDIA_CONTEXT
111 //! \param [in] ptr
112 //! Pointer to Picture Parameter buffer
113 //!
114 //! \return VAStatus
115 //! VA_STATUS_SUCCESS if success, else fail reason
116 //!
117 VAStatus ParsePicParams(DDI_MEDIA_CONTEXT *mediaCtx, void *ptr) override;
118
119 //!
120 //! \brief Parse Sequence Parameter buffer to Encode Context
121 //!
122 //! \param [in] ptr
123 //! Pointer to Sequence Parameter buffer
124 //!
125 //! \return VAStatus
126 //! VA_STATUS_SUCCESS if success, else fail reason
127 //!
128 VAStatus ParseSeqParams(void *ptr);
129
130 //!
131 //! \brief Parse Slice Parameter buffer to Encode Context
132 //!
133 //! \param [in] mediaCtx
134 //! Pointer to DDI_MEDIA_CONTEXT
135 //! \param [in] ptr
136 //! Pointer to Slice Parameter buffer
137 //! \param [in] numSlices
138 //! Number of slice
139 //!
140 //! \return VAStatus
141 //! VA_STATUS_SUCCESS if success, else fail reason
142 //!
143 VAStatus ParseTileGroupParams(void *ptr, uint32_t numTileGroupParams);
144
145 //!
146 //! \brief Parse Packed Header Parameter buffer to Encode Context
147 //!
148 //! \param [in] ptr
149 //! Pointer to Packed Header Parameter buffer
150 //!
151 //! return VAStatus
152 //! VA_STATUS_SUCCESS if success, else fail reason
153 //!
154 VAStatus ParsePackedHeaderParams(void *ptr);
155
156 //!
157 //! \brief Parse Packed Header Data buffer to Encode Context
158 //!
159 //! \param [in] ptr
160 //! Pointer to Packed Header Data buffer
161 //!
162 //! return VAStatus
163 //! VA_STATUS_SUCCESS if success, else fail reason
164 //!
165 VAStatus ParsePackedHeaderData(void *ptr);
166
167 //!
168 //! \brief Parse Misc Parameter buffer to Encode Context
169 //!
170 //! \param [in] ptr
171 //! Pointer to Misc Parameter buffer
172 //!
173 //! \return VAStatus
174 //! VA_STATUS_SUCCESS if success, else fail reason
175 //!
176 VAStatus ParseMiscParams(void *ptr);
177
178 //!
179 //! \brief Parse Segment Map Parameter buffer to Encode Context
180 //!
181 //! \param [in] buf
182 //! Pointer to Segment Map Parameter buffer
183 //!
184 //! \return VAStatus
185 //! VA_STATUS_SUCCESS if success, else fail reason
186 //!
187 VAStatus ParseSegMapParams(void *ptr);
188
189 uint32_t getSequenceParameterBufferSize() override;
190
191 uint32_t getPictureParameterBufferSize() override;
192
193 uint32_t getSliceParameterBufferSize() override;
194
195 private:
196 //!
197 //! \brief Setup Codec Picture for AV1
198 //!
199 //! \param [in] mediaCtx
200 //! Pointer to DDI_MEDIA_CONTEXT
201 //! \param [in] rtTbl
202 //! Pointer to DDI_CODEC_RENDER_TARGET_TABLE
203 //! \param [in] surfaceID
204 //! VASurface index
205 //! \param [in] picReference
206 //! Reference picture flag
207 //! \param [out] codecHalPic
208 //! Pointer to CODEC_PICTURE
209 //!
210 //! \return void
211 //!
212 void SetupCodecPicture(
213 DDI_MEDIA_CONTEXT *mediaCtx,
214 DDI_CODEC_RENDER_TARGET_TABLE *rtTbl,
215 CODEC_PICTURE *codecHalPic,
216 VASurfaceID surfaceID,
217 bool picReference);
218
219 //!
220 //! \brief Parse Misc Param VBV Data buffer to Encode Context
221 //!
222 //! \param [in] data
223 //! Pointer to Misc Param VBV Data buffer
224 //!
225 //! \return VAStatus
226 //! VA_STATUS_SUCCESS if success, else fail reason
227 //!
228 VAStatus ParseMiscParamVBV(void *data);
229
230 //!
231 //! \brief Parse Misc Param FrameRate Data buffer to Encode Context
232 //!
233 //! \param [in] data
234 //! Pointer to Misc Param FR Data buffer
235 //!
236 //! \return VAStatus
237 //! VA_STATUS_SUCCESS if success, else fail reason
238 //!
239 VAStatus ParseMiscParamFR(void *data);
240
241 //!
242 //! \brief Parse Misc Param RateControl Data buffer to Encode Context
243 //!
244 //! \param [in] data
245 //! Pointer to Misc Param RC Data buffer
246 //!
247 //! \return VAStatus
248 //! VA_STATUS_SUCCESS if success, else fail reason
249 //!
250 VAStatus ParseMiscParamRC(void *data);
251
252 //!
253 //! \brief Parse Misc Param Enc Quality to Encode Context
254 //!
255 //! \param [in] data
256 //! Pointer to Misc Param Private Data buffer
257 //!
258 //! \return VAStatus
259 //! VA_STATUS_SUCCESS if success, else fail reason
260 //!
261 VAStatus ParseMiscParamEncQuality(void *data);
262
263 //!
264 //! \brief Parse Misc Parameter Temporal Layer Params buffer to Encode Context
265 //!
266 //! \param [in] data
267 //! Pointer to Misc Parameter Temporal Layer Params buffer
268 //!
269 //! \return VAStatus
270 //! VA_STATUS_SUCCESS if success, else fail reason
271 //!
272 VAStatus ParseMiscParamTemporalLayerParams(void *data);
273
274 //!
275 //! \brief Parse Misc Param Buffer Quality Level to Encode Context
276 //!
277 //! \param [in] data
278 //! Pointer to Misc Param Buffer Quality Level
279 //!
280 //! \return VAStatus
281 //! VA_STATUS_SUCCESS if success, else fail reason
282 //!
283 VAStatus ParseMiscParamQualityLevel(void *data);
284
285 //!
286 //! \brief Parse Misc Param Max Frame Size to Encode Context
287 //!
288 //! \param [in] data
289 //! Pointer to Misc Param Buffer Max Frame Size
290 //!
291 //! \return VAStatus
292 //! VA_STATUS_SUCCESS if success, else fail reason
293 //!
294 VAStatus ParseMiscParamMaxFrameSize(void *data);
295
296 //!
297 //! \brief Setup Codec Picture for AV1
298 //!
299 //! \param [in] picParams
300 //! Pointer to picture parameters
301 //! \param [in] platform
302 //! Pointer to platform
303 //!
304 //! \return VAStatus
305 //! VA_STATUS_SUCCESS if success, else fail reason
306 //!
307 VAStatus CheckCDEF(const VAEncPictureParameterBufferAV1 *picParams,
308 PRODUCT_FAMILY platform);
309
310 VAStatus CheckTile(const VAEncPictureParameterBufferAV1 *picParams);
311
312 //!
313 //! \brief Check whether swizzle needed
314 //!
315 //! \param [in] rawSurface
316 //! Pointer of Raw Surface
317 //!
318 //! \return bool, true if need, otherwise false
319 //!
320 inline bool NeedDisplayFormatSwizzle(DDI_MEDIA_SURFACE *rawSurface)
321 {
322 if (Media_Format_A8R8G8B8 == rawSurface->format ||
323 Media_Format_X8R8G8B8 == rawSurface->format ||
324 Media_Format_B10G10R10A2 == rawSurface->format)
325 {
326 return true;
327 }
328
329 return false;
330 }
331 uint32_t savedTargetBit[ENCODE_AV1_MAX_NUM_TEMPORAL_LAYERS] = { 0 };
332 uint32_t savedFrameRate[ENCODE_AV1_MAX_NUM_TEMPORAL_LAYERS] = { 0 };
333 uint32_t savedMaxBitRate[ENCODE_AV1_MAX_NUM_TEMPORAL_LAYERS] = { 0 };
334 uint32_t savedQualityFactor = 0;
335
336 uint32_t allocatedTileNum = 0;
337 bool m_isSegParamsChanged = false;
338 };
339 #endif //__MEDIA_LIBVA_ENCODER_AV1_H__