xref: /aosp_15_r20/external/intel-media-driver/media_driver/linux/common/codec/ddi/media_ddi_decode_av1.h (revision ba62d9d3abf0e404f2022b4cd7a85e107f48596f)
1 /*
2 * Copyright (c) 2017-2021, 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_av1.h
24 //! \brief    Defines DdiDecodeAV1 class for AV1 decode
25 //!
26 
27 #ifndef __MEDIA_DDI_DECODER_AV1_H__
28 #define __MEDIA_DDI_DECODER_AV1_H__
29 
30 #include <va/va.h>
31 #include "media_ddi_decode_base.h"
32 #include "codec_def_decode_av1.h"
33 
34 #define DECODE_ID_AV1                       "VIDEO_DEC_AV1"
35 #define MAX_ANCHOR_FRAME_NUM_AV1            128
36 
37 //!
38 //! \class  DdiDecodeAV1
39 //! \brief  Ddi decode AV1
40 //!
41 
42 typedef struct _DDI_CODEC_BUFFER_PARAM_AV1
43 {
44     // one picture buffer
45     VADecPictureParameterBufferAV1               PicParamAV1;
46 
47     VASliceParameterBufferAV1                *pVASliceParameterBufferAV1;
48 } DDI_CODEC_BUFFER_PARAM_AV1;
49 
50 class DdiDecodeAV1 : public DdiMediaDecode
51 {
52 public:
53     //!
54     //! \brief Constructor
55     //!
DdiDecodeAV1(DDI_DECODE_CONFIG_ATTR * ddiDecodeAttr)56     DdiDecodeAV1(DDI_DECODE_CONFIG_ATTR *ddiDecodeAttr) : DdiMediaDecode(ddiDecodeAttr)
57     {
58         MOS_ZeroMemory(&outputSurface, sizeof(outputSurface));
59     };
60 
61     //!
62     //! \brief Destructor
63     //!
~DdiDecodeAV1()64     virtual ~DdiDecodeAV1() {};
65 
66     // inherited virtual functions
67     virtual void DestroyContext(
68         VADriverContextP ctx) override;
69 
70     virtual VAStatus RenderPicture(
71         VADriverContextP ctx,
72         VAContextID      context,
73         VABufferID       *buffers,
74         int32_t          numBuffers) override;
75 
76     virtual VAStatus InitDecodeParams(
77         VADriverContextP ctx,
78         VAContextID      context) override;
79 
80     virtual VAStatus SetDecodeParams() override;
81 
82     virtual MOS_FORMAT GetFormat() override;
83 
84     /*virtual VAStatus EndPicture(
85     VADriverContextP ctx,
86     VAContextID      context) override;*/
87 
88     virtual void ContextInit(
89         int32_t picWidth,
90         int32_t picHeight) override;
91 
92     virtual VAStatus CodecHalInit(
93         DDI_MEDIA_CONTEXT *mediaCtx,
94         void              *ptr) override;
95 
96     virtual VAStatus AllocSliceControlBuffer(
97         DDI_MEDIA_BUFFER       *buf) override;
98 
99     virtual uint8_t* GetPicParamBuf(
100         DDI_CODEC_COM_BUFFER_MGR     *bufMgr) override;
101 
102 private:
103     //!
104     //! \brief   ParseSliceParam for AV1
105     //! \details parse the sliceParam info required by AV1 decoding for
106     //!          each slice
107     //!
108     //! \param   [in] *mediaCtx
109     //!          DDI_MEDIA_CONTEXT
110     //! \param   [in] *slcParam
111     //!          VASliceParameterBufferAV1
112     //! \param   [in] numTile
113     //!
114     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
115     //!          else fail reason
116     VAStatus ParseTileParams(
117         DDI_MEDIA_CONTEXT             *mediaCtx,
118         VASliceParameterBufferAV1     *slcParam,
119         uint32_t                      numTiles);
120 
121     //! \brief   ParsePicParam for AV1
122     //! \details parse the PicParam info required by AV1 decoding
123     //!
124     //! \param   [in] *mediaCtx
125     //!          DDI_MEDIA_CONTEXT
126     //! \param   [in] *qMatrix
127     //!          VAIQMatrixBufferH264
128     //!
129     //! \return   VAStatus
130     //!           VA_STATUS_SUCCESS if success, else fail reason
131     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
132     //!          else fail reason
133     VAStatus ParsePicParams(
134         DDI_MEDIA_CONTEXT *mediaCtx,
135         VADecPictureParameterBufferAV1 *picParam);
136 
137     VAStatus ParseAv1SegFilterLevel(
138         DDI_MEDIA_CONTEXT *mediaCtx,
139         VADecPictureParameterBufferAV1 *picParam);
140 
141     VAStatus Av1LoopFilterFrameInit(
142         DDI_MEDIA_CONTEXT *mediaCtx,
143         VADecPictureParameterBufferAV1 *picParam,
144         int defaultFiltLvl,
145         int defaultFiltLvlR,
146         int plane);
147 
148     uint32_t Av1GetQindex(
149         CodecAv1SegmentsParams *segInfo,
150         uint32_t segment_id,
151         uint8_t base_qindex);
152 
153     int Av1Clamp(int value, int low, int high);
154 
155     //! \brief   Init Resource buffer for AV1
156     //! \details Initialize and allocate the Resource buffer for AV1
157     //!
158     //! \return  VA_STATUS_SUCCESS is returned if it is parsed successfully.
159     //!          else fail reason
160     VAStatus InitResourceBuffer();
161 
162     //! \brief   Free Resource buffer for AV1
163     //!
164     void FreeResourceBuffer();
165 
166     //! \brief   film grain output surface
167     PDDI_MEDIA_SURFACE filmGrainOutSurface = nullptr;
168     //! \brief   film grain output surface structure
169     MOS_SURFACE outputSurface;
170 
171     MOS_SURFACE anchorFrameList[MAX_ANCHOR_FRAME_NUM_AV1];
172     VASurfaceID anchorFrameListVA[MAX_ANCHOR_FRAME_NUM_AV1] = {0};
173 };
174 
175 #endif /* _MEDIA_DDI_DECODE_AV1_H */
176