Debian Codegraph @

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