• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_av1_specific.h
24 //! \brief    Defines DdiDecodeAv1 class for AV1 decode
25 //!
26 
27 #ifndef __DDI_DECODE_AV1_SPECIFIC_H__
28 #define __DDI_DECODE_AV1_SPECIFIC_H__
29 
30 #include "ddi_decode_base_specific.h"
31 
32 #define DECODE_ID_AV1             "VIDEO_DEC_AV1"
33 #define MAX_ANCHOR_FRAME_NUM_AV1  128
34 
35 namespace decode
36 {
37 
38 //!
39 //! \class  DdiDecodeAv1
40 //! \brief  Ddi Decode AV1
41 //!
42 
43 typedef struct _DDI_DECODE_BUFFER_PARAM_AV1
44 {
45     // one picture buffer
46     VADecPictureParameterBufferAV1 PicParamAV1;
47     VASliceParameterBufferAV1     *pVASliceParameterBufferAV1;
48 } DDI_DECODE_BUFFER_PARAM_AV1;
49 
50 class DdiDecodeAv1 : public DdiDecodeBase
51 {
52 public:
53     //!
54     //! \brief Constructor
55     //!
DdiDecodeAv1()56     DdiDecodeAv1() : DdiDecodeBase()
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     void FreeResource();
167 
168     //! \brief   film grain output surface
169     PDDI_MEDIA_SURFACE filmGrainOutSurface = nullptr;
170     //! \brief   film grain output surface structure
171     MOS_SURFACE outputSurface;
172 
173     MOS_SURFACE anchorFrameList[MAX_ANCHOR_FRAME_NUM_AV1];
174     VASurfaceID anchorFrameListVA[MAX_ANCHOR_FRAME_NUM_AV1] = {0};
175 
176     MEDIA_CLASS_DEFINE_END(decode__DdiDecodeAv1)
177 };
178 } // namespace decode
179 
180 #endif /* __DDI_DECODE_AV1_SPECIFIC_H__ */
181