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