xref: /aosp_15_r20/external/intel-media-driver/media_driver/linux/common/codec/ddi/media_ddi_decode_mpeg2.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2015-2018, 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_decode_mpeg2.h
25 //! \brief    Defines DdiDecodeMPEG2 class for MPEG2 decode
26 //!
27 
28 #ifndef __MEDIA_DDI_DECODER_MPEG2_H__
29 #define __MEDIA_DDI_DECODER_MPEG2_H__
30 
31 #include <va/va.h>
32 #include "media_ddi_decode_base.h"
33 
34 //!
35 //! \class  DdiDecodeMPEG2
36 //! \brief  Ddi decode MPEG2
37 //!
38 class DdiDecodeMPEG2 : public DdiMediaDecode
39 {
40 public:
41     //!
42     //! \brief Constructor
43     //!
DdiDecodeMPEG2(DDI_DECODE_CONFIG_ATTR * ddiDecodeAttr)44     DdiDecodeMPEG2(DDI_DECODE_CONFIG_ATTR *ddiDecodeAttr) : DdiMediaDecode(ddiDecodeAttr){m_withDpb = false;};
45 
46     //!
47     //! \brief Destructor
48     //!
~DdiDecodeMPEG2()49     virtual ~DdiDecodeMPEG2(){};
50 
51     // inherited virtual functions
52     virtual void DestroyContext(
53         VADriverContextP ctx) override;
54 
55     virtual VAStatus RenderPicture(
56         VADriverContextP ctx,
57         VAContextID      context,
58         VABufferID       *buffers,
59         int32_t          num_buffers) override;
60 
61     virtual VAStatus SetDecodeParams() override;
62 
63     virtual void ContextInit(
64         int32_t picWidth,
65         int32_t picHeight) override;
66 
67     virtual VAStatus CodecHalInit(
68         DDI_MEDIA_CONTEXT *mediaCtx,
69         void              *ptr) override;
70 
71     virtual VAStatus AllocSliceControlBuffer(
72         DDI_MEDIA_BUFFER       *buf) override;
73 
74     virtual uint8_t* GetPicParamBuf(
75         DDI_CODEC_COM_BUFFER_MGR     *bufMgr) override;
76 
77 private:
78     //!
79     //! \brief   ParaSliceParam for MPEG2
80     //! \details parse the sliceParam info required by MPEG2 decoding for
81     //!          each slice
82     //!
83     //! \param   [in] *mediaCtx
84     //!          DDI_MEDIA_CONTEXT
85     //! \param   [in] *slcParam
86     //!          VASliceParameterBufferMPEG2
87     //! \param   [in] numSlices
88     //!             uint32_t
89     //!
90     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
91     //!          else fail reason
92     VAStatus ParseSliceParams(
93         DDI_MEDIA_CONTEXT            *mediaCtx,
94         VASliceParameterBufferMPEG2  *slcParam,
95         uint32_t                      numSlices);
96 
97     //!
98     //! \brief   ParseIQMatrixParam for MPEG2
99     //! \details parse the QMatrix info required by MPEG2 decoding
100     //!
101     //! \param   [in] *mediaCtx
102     //!          DDI_MEDIA_CONTEXT
103     //! \param   [in] *qMatrix
104     //!          VAIQMatrixBufferMPEG2
105     //!
106     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
107     //!          else fail reason
108     VAStatus ParseIQMatrix(
109         DDI_MEDIA_CONTEXT     *mediaCtx,
110         VAIQMatrixBufferMPEG2 *matrix);
111 
112     //! \brief   ParsePicParam for MPEG2
113     //! \details parse the PicParam info required by MPEG2 decoding
114     //!
115     //! \param   [in] *mediaCtx
116     //!          DDI_MEDIA_CONTEXT
117     //! \param   [in] *qMatrix
118     //!          VAIQMatrixBufferH264
119     //!
120     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
121     //!          else fail reason
122     VAStatus ParsePicParams(
123         DDI_MEDIA_CONTEXT             *mediaCtx,
124         VAPictureParameterBufferMPEG2 *picParam);
125 
126     //! \brief   Alloc SliceParam content for MPEG2
127     //! \details Alloc/resize SlicePram content for MPEG2 decoding
128     //!
129     //! \param   [in] numSlices
130     //!          uint32_t the required number of slices
131     //!
132     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
133     //!          else fail reason
134     VAStatus AllocSliceParamContext(
135         uint32_t numSlices);
136 
137     //!
138     //! \brief   Parse and Refine the number of MBs for MPEG2
139     //! \details parse and Refine the number of MBs for each slices
140     //!          This helps to fix the issue passed from upper middleware.
141     //!
142     //! \param   [in] numSlices
143     //!             int32_t
144     void ParseNumMbsForSlice(int32_t numSlices);
145 
146     //! \brief   Init Resource buffer for MPEG2
147     //! \details Initialize and allocate the Resource buffer for MPEG2
148     //!
149     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
150     //!          else fail reason
151     VAStatus InitResourceBuffer();
152 
153     //! \brief   Free Resource buffer for MPEG2
154     //!
155     void FreeResourceBuffer();
156 };
157 
158 #endif /* _MEDIA_DDI_DECODE_MPEG2_H */
159