Debian Codegraph @

media_softlet/linux/common/codec/ddi/dec/ddi_decode_base_specific.h

raw
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_base_specific.h
24 //! \brief Defines base class for DDI media decode.
25 //!
26
27 #ifndef _DDI_DECODE_BASE_SPECIFIC_H_
28 #define _DDI_DECODE_BASE_SPECIFIC_H_
29
30 #include <stdint.h>
31 #include <va/va.h>
32 #include "ddi_codec_base_specific.h"
33 #include "decode_pipeline_adapter.h"
34 #include "ddi_libva_decoder_specific.h"
35 #include "media_capstable_specific.h"
36
37 namespace decode
38 {
39
40 //!
41 //! \class DdiDecodeBase
42 //! \brief Ddi decode base
43 //!
44 class DdiDecodeBase : public codec::DdiCodecBase
45 {
46 public:
47 //!
48 //! \brief Constructor
49 //!
50 DdiDecodeBase();
51
52 //!
53 //! \brief Destructor
54 //!
55 virtual ~DdiDecodeBase()
56 {
57 MOS_FreeMemory(m_ddiDecodeAttr);
58 m_ddiDecodeAttr = nullptr;
59 MOS_Delete(m_codechalSettings);
60 m_codechalSettings = nullptr;
61 #ifdef _DECODE_PROCESSING_SUPPORTED
62 MOS_FreeMemory(m_procBuf);
63 m_procBuf = nullptr;
64 #endif
65 }
66
67 //! \brief the type conversion to get the DDI_DECODE_CONTEXT
68 inline operator DDI_DECODE_CONTEXT *()
69 {
70 return m_decodeCtx;
71 }
72
73 //!
74 //! \brief Free the allocated resource related with the decode context
75 //! \details Free the private resource related with the decode context.
76 //! For example: DecodeParams, CodecHal and so on.
77 //!
78 //! \param [in] ctx
79 //! VADriverContextP
80 //!
81 virtual void DestroyContext(VADriverContextP ctx) = 0;
82
83 //!
84 //! \brief Get ready to decoding process for a target surface
85 //! \details It begins the decoding process for a specified target surface
86 //!
87 //! \param [in] ctx
88 //! VADriverContextP
89 //! \param [in] context
90 //! Already created context for the decoding process
91 //! \param [in] renderTarget
92 //! Specified target surface
93 //!
94 //! \return VAStatus
95 //! VA_STATUS_SUCCESS if success, else fail reason
96 //!
97 virtual VAStatus BeginPicture(
98 VADriverContextP ctx,
99 VAContextID context,
100 VASurfaceID renderTarget);
101
102 //!
103 //! \brief Send required buffers to decoding process
104 //! \details It sends needed buffers by the decoding to the driver
105 //!
106 //! \param [in] ctx
107 //! VADriverContextP
108 //! \param [in] context
109 //! Already created context for the decoding process
110 //! \param [in] buffers
111 //! Pointer to the buffer array
112 //! \param [in] numBuffers
113 //! Number of buffers in above array
114 //!
115 //! \return VAStatus
116 //! VA_STATUS_SUCCESS if success, else fail reason
117 //!
118 virtual VAStatus RenderPicture(
119 VADriverContextP ctx,
120 VAContextID context,
121 VABufferID *buffers,
122 int32_t numBuffers) = 0;
123
124 //!
125 //! \brief Init Params setting of EndPicture Function
126 //! \details The function is used to init EndPicture params
127 //!
128 //! \param [in] ctx
129 //! VADriverContextP
130 //! \param [in] context
131 //! Already created context for the process
132 //!
133 //! \return VAStatus
134 //! VA_STATUS_SUCCESS if success
135 //!
136 virtual VAStatus InitDecodeParams(
137 VADriverContextP ctx,
138 VAContextID context);
139
140 //!
141 //! \brief Get decode format
142 //! \details The function is used to get decode format
143 //!
144 //! \return MOS_FORMAT
145 //! VA_STATUS_SUCCESS if success
146 //!
147 virtual MOS_FORMAT GetFormat();
148
149 //!
150 //! \brief Set common decode param setting for each codec
151 //! \details Set common decode param setting for each decode class
152 //!
153 //! \return VAStatus
154 //! VA_STATUS_SUCCESS if success
155 //!
156 virtual VAStatus SetDecodeParams();
157
158 //!
159 //! \brief Make the end of rendering for a picture
160 //! \details The driver will flush/submit the decoding processing.
161 //! This call is non-blocking. The app can start another
162 //! Begin/Render/End sequence on a different render target
163 //!
164 //! \param [in] ctx
165 //! VADriverContextP
166 //! \param [in] context
167 //! Already created context for the process
168 //!
169 //! \return VAStatus
170 //! VA_STATUS_SUCCESS if success, else fail reason
171 //!
172 virtual VAStatus EndPicture(
173 VADriverContextP ctx,
174 VAContextID context);
175
176 //!
177 //! \brief the first step of Initializing internal structure of DdiDecodeBase
178 //! \details Initialize and allocate the internal structur of DdiDecodeBase. This
179 //! is the first step.
180 //! \param [in] linuxConfAttr
181 //! the config attr related with the linux caps
182 //! \return VAStatus
183 //! VA_STATUS_SUCCESS if success, else fail reason
184
185 VAStatus BasicInit(ConfigLinux *configItem);
186 //!
187 //! \brief the second step of Initializing internal structure of DdiDecodeBase
188 //! \details Initialize the internal structure of DdiDecodeBase base on
189 //! input width/height. It is step two
190 //!
191 //! \param [in] picWidth
192 //! int32_t
193 //! \param [in] picHeight
194 //! int32_t
195 //!
196 virtual void ContextInit(
197 int32_t picWidth,
198 int32_t picHeight) = 0;
199
200 //!
201 //! \brief Initialize the back-end CodecHal of DdiDecodeBase
202 //! \details Initialize the back-end CodecHal of DdiDecodeBase base on
203 //! the codec attribute. This is the third step of DdiMediDecode context
204 //! initialiazation.
205 //!
206 //! \param [in] mediaCtx
207 //! DDI_MEDIA_CONTEXT * type
208 //! \param [in] ptr
209 //! extra data
210 //! \return VAStatus
211 //! VA_STATUS_SUCCESS if success, else fail reason
212 virtual VAStatus CodecHalInit(
213 DDI_MEDIA_CONTEXT *mediaCtx,
214 void *ptr) = 0;
215
216 //!
217 //! \brief Get bit stream buffer index
218 //! \details Get bit stream buffer index
219 //!
220 //! \param [in] bufMgr
221 //! DDI_CODEC_COM_BUFFER_MGR *bufMgr
222 //! \param [in] buf
223 //! DDI_MEDIA_BUFFER *buf
224 //! \return i
225 //! buffer index
226 virtual int32_t GetBitstreamBufIndexFromBuffer(
227 DDI_CODEC_COM_BUFFER_MGR *bufMgr,
228 DDI_MEDIA_BUFFER *buf);
229
230 //!
231 //! \brief Allocate slice control buffer
232 //! \details Allocate slice control buffer
233 //!
234 //! \param [in] buf
235 //! DDI_MEDIA_BUFFER *buf
236 //! \return VAStatus
237 //!
238 virtual VAStatus AllocSliceControlBuffer(
239 DDI_MEDIA_BUFFER *buf) = 0;
240
241 //!
242 //! \brief Allocate Bs buffer
243 //! \details Allocate Bs buffer
244 //!
245 //! \param [in] bufMgr
246 //! DDI_CODEC_COM_BUFFER_MGR *bufMgr
247 //! \param [in] buf
248 //! DDI_MEDIA_BUFFER *buf
249 //! \return VAStatus
250 //!
251 virtual VAStatus AllocBsBuffer(
252 DDI_CODEC_COM_BUFFER_MGR *bufMgr,
253 DDI_MEDIA_BUFFER *buf);
254
255 //!
256 //! \brief Get Picture parameter size
257 //! \details Get Picture parameter size for each decoder
258 //!
259 //! \param [in] bufMgr
260 //! DDI_CODEC_COM_BUFFER_MGR *bufMgr
261 //! \return uint8_t*
262 //!
263 virtual uint8_t* GetPicParamBuf(
264 DDI_CODEC_COM_BUFFER_MGR *bufMgr)
265 {
266 return (uint8_t*)bufMgr;
267 }
268
269 //!
270 //! \brief Create buffer in ddi decode context
271 //! \details Create related decode buffer in ddi decode base class
272 //!
273 //! \param [in] type
274 //! VABufferType type
275 //! \param [in] size
276 //! uint32_t size
277 //! \param [in] numElements
278 //! uint32_t numElements
279 //! \param [in] data
280 //! void data
281 //! \param [in] bufId
282 //! VABufferID bufId
283 //!
284 virtual VAStatus CreateBuffer(
285 VABufferType type,
286 uint32_t size,
287 uint32_t numElements,
288 void *data,
289 VABufferID *bufId);
290
291 //!
292 //! \brief if it is range extention
293 //!
294 //! \return true or false
295 //!
296 virtual bool IsRextProfile()
297 {
298 return false;
299 }
300
301 //! \brief Combine the Bitstream Before decoding execution
302 //! \details Help to refine and combine the decoded input bitstream if
303 //! required. It is decided by the flag of IsSliceOverSize.
304 //! \param [in] mediaCtx
305 //! DDI_MEDIA_CONTEXT * type
306 //!
307 //! \return VAStatus
308 //! VA_STATUS_SUCCESS if success, else fail reason
309 //!
310 VAStatus DecodeCombineBitstream(DDI_MEDIA_CONTEXT *mediaCtx);
311
312 //!
313 //! \brief Check if the resolution is valid for a given decode config
314 //!
315 //! \param [in] configItem
316 //! Pointer to ConfigLinux
317 //!
318 //! \param [in] width
319 //! Specify the width for checking
320 //!
321 //! \param [in] height
322 //! Specify the height for checking
323 //!
324 //! \return VAStatus
325 //! VA_STATUS_SUCCESS if the resolution is supported
326 //! VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED if the resolution isn't valid
327 //!
328 VAStatus CheckDecodeResolution(
329 ConfigLinux *configItem,
330 uint32_t width,
331 uint32_t height);
332
333 //!
334 //! \brief Gets the decode standard
335 //! \return The decode standard \see m_standard
336 //!
337 uint32_t GetStandard() { return m_codechalSettings ? m_codechalSettings->standard : CODECHAL_UNDEFINED; }
338
339
340 //! \brief the referred DDI_DECODE_CONTEXT object
341 //! \details This is allocated when creating one new instance. As it is
342 //! referred by other component, it should be free explicitly
343 //! outside of the instance.
344 DDI_DECODE_CONTEXT *m_decodeCtx = nullptr;
345
346 protected:
347 //! \brief the decode_config_attr related with Decode_CONTEXT
348 ConfigLinux *m_ddiDecodeAttr = nullptr;
349
350 //! \brief decoded picture buffer flag
351 bool m_withDpb = true;
352
353 //!
354 //! \brief return the Buffer offset for sliceGroup
355 //! \details return the Base offset for one given slice_data buffer.
356 //! It can be applied under the following two scenarios:
357 //! Multiple slice parameters are included in one slice_param_buf
358 //! Only one slice parameter is in one slice_param_buf.
359 //!
360 //! \param [in] sliceGroup
361 //! the index of slice_parameter group
362 //!
363 //! \return return the base offset
364 //!
365 uint32_t GetBsBufOffset(int32_t sliceGroup);
366
367 //! \brief Parse the processing buffer if needed.
368 //! \details Helps to parse the Video-post processing buffer for Decoding
369 //!
370 //! \param [in] mediaCtx
371 //! DDI_MEDIA_CONTEXT * type
372 //! \param [in] bufAddr
373 //! the address of passed buf
374 //!
375 //! \return VAStatus
376 //! VA_STATUS_SUCCESS if success, else fail reason
377 //!
378 VAStatus ParseProcessingBuffer(
379 DDI_MEDIA_CONTEXT *mediaCtx,
380 void *bufAddr);
381
382 //!
383 //! \brief Create the back-end CodecHal of DdiDecodeBase
384 //! \details Create the back-end CodecHal of DdiDecodeBase base on
385 //! the codec attribute. This is one common function, which is called by CreateCodecHal.
386 //!
387 //! \param [in] mediaCtx
388 //! DDI_MEDIA_CONTEXT * type
389 //! \param [in] ptr
390 //! extra data
391 //! \param [in] standardInfo
392 //! CODECHAL_STANDARD_INFO *
393 //!
394 //! \return VAStatus
395 //! VA_STATUS_SUCCESS if success, else fail reason
396
397 VAStatus CreateCodecHal(
398 DDI_MEDIA_CONTEXT *mediaCtx,
399 void *ptr,
400 _CODECHAL_STANDARD_INFO *standardInfo);
401
402 //!
403 //! \brief Get dummy reference from DPB
404 //! \details Get dummy reference from DPB for error concealment
405 //!
406 //! \param [in] decodeCtx
407 //! DDI_DECODE_CONTEXT * type
408 //!
409 //! \return void
410 void GetDummyReferenceFromDPB(
411 DDI_DECODE_CONTEXT *decodeCtx);
412
413 //!
414 //! \brief Report decode mode
415 //! \details Report decode mode to UFKEY_INTERNAL
416 //!
417 //! \param [in] wMode
418 //! CODECHAL_MODE
419 //!
420 //! \return void
421 void ReportDecodeMode(
422 uint16_t wMode);
423
424 //! \brief Use EU path to do the scaling
425 //! \details When VD+SFC are not supported, it will call into VPhal to do scaling
426 //!
427 //! \param [in] ctx
428 //! VADriverContextP * type
429 //! \param [in] context
430 //! Already created context for the process
431 //!
432 //! \return VAStatus
433 //! VA_STATUS_SUCCESS if success, else fail reason
434 VAStatus ExtraDownScaling(
435 VADriverContextP ctx,
436 VAContextID context);
437
438 //! \brief Init dummy reference
439 //! \details Init dummy reference for decode
440 //!
441 //! \param [in/out] decoder
442 //! Codechal decoder
443 //!
444 //! \return VAStatus
445 //! VA_STATUS_SUCCESS if success, else fail reason
446 VAStatus InitDummyReference(CodechalDecode& decoder);
447
448 //! \brief Init dummy reference
449 //! \details Init dummy reference for decode
450 //!
451 //! \param [in/out] decoder
452 //! DecodePipelineAdapter decoder
453 //!
454 //! \return VAStatus
455 //! VA_STATUS_SUCCESS if success, else fail reason
456 VAStatus InitDummyReference(DecodePipelineAdapter& decoder);
457
458 //! \brief the type of decode base class
459 MOS_SURFACE m_destSurface; //!<Destination Surface structure
460 uint32_t m_groupIndex; //!<global Group
461 uint16_t m_picWidthInMB; //!<Picture Width in MB width count
462 uint16_t m_picHeightInMB; //!<Picture Height in MB height count
463 uint32_t m_width; //!<Picture Width
464 uint32_t m_height; //!<Picture Height
465 bool m_streamOutEnabled; //!<Stream Out enable flag
466 uint32_t m_sliceParamBufNum; //!<Slice parameter Buffer Number
467 uint32_t m_sliceCtrlBufNum; //!<Slice control Buffer Number
468 uint32_t m_decProcessingType; //!<Decode Processing type
469 CodechalSetting *m_codechalSettings = nullptr; //!<Codechal Settings
470 static const uint32_t m_decDefaultMaxWidth = 4096;
471 static const uint32_t m_decDefaultMaxHeight = 4096;
472
473 #ifdef _DECODE_PROCESSING_SUPPORTED
474 bool m_requireInputRegion = false;
475 VAProcPipelineParameterBuffer *m_procBuf = nullptr; //!< Process parameters for vp sfc input
476 #endif
477 MEDIA_CLASS_DEFINE_END(decode__DdiDecodeBase)
478 };
479
480 } // namespace decode
481 #endif /* _DDI_DECODE_BASE_SPECIFIC_H_ */