Debian Codegraph @

media_softlet/linux/common/codec/ddi/enc/ddi_encode_av1_specific.h

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