Debian Codegraph @

media_common/agnostic/common/codec/shared/codec_def_decode_av1.h

raw
1 /*
2 * Copyright (c) 2017-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 codec_def_decode_av1.h
24 //! \brief Defines decode AV1 types and macros shared by CodecHal, MHW, and DDI layer
25 //! \details Applies to AV1 decode only. Should not contain any DDI specific code.
26 //!
27 #ifndef __CODEC_DEF_DECODE_AV1_H__
28 #define __CODEC_DEF_DECODE_AV1_H__
29
30 #include "codec_def_common_av1.h"
31
32 #define CODECHAL_MAX_DPB_NUM_AV1 127 // Maximum number of uncompressed decoded buffers that driver supports for non-LST mode
33 #define CODEC_NUM_REF_AV1_TEMP_BUFFERS 8
34 #define CODEC_NUM_AV1_SECOND_BB 64
35 #define CODEC_NUM_AV1_TEMP_BUFFERS (CODEC_NUM_REF_AV1_TEMP_BUFFERS + 1) //!< Temp buffers number
36 #define CODECHAL_MAX_DPB_NUM_LST_AV1 255 // Maximum number of uncompressed decoded buffers that driver supports with LST support
37
38 // AV1 parameters definition
39
40 //!
41 //! \struct CodecAv1FilmGrainParams
42 //! \brief Define the film grain parameters for AV1
43 //!
44 struct CodecAv1FilmGrainParams
45 {
46 union
47 {
48 struct
49 {
50 uint32_t m_applyGrain : 1; //!< apply Grain flag
51 uint32_t m_chromaScalingFromLuma : 1; //!< chroma scaling from luma
52 uint32_t m_grainScalingMinus8 : 2; //!< Grain scaling minus 8
53 uint32_t m_arCoeffLag : 2; //!< AR Coeff lag
54 uint32_t m_arCoeffShiftMinus6 : 2; //!< AR coeff shift minus 6
55 uint32_t m_grainScaleShift : 2; //!< grain scale shift
56 uint32_t m_overlapFlag : 1; //!< overlap flag
57 uint32_t m_clipToRestrictedRange : 1; //!< clip to restricted range flag
58 uint32_t m_reservedBits : 20; //!< reserved bits
59 } m_fields;
60 uint32_t m_value; //!< film grain info flag value
61 } m_filmGrainInfoFlags;
62
63 uint16_t m_randomSeed; //!< random seed
64 uint8_t m_numYPoints; //!< num Y points, range [0..14]
65 uint8_t m_pointYValue[14]; //!< point Y value array
66 uint8_t m_pointYScaling[14]; //!< point Y scaling array
67 uint8_t m_numCbPoints; //!< num Cb Points, range [0..10]
68 uint8_t m_pointCbValue[10]; //!< point Cb Value
69 uint8_t m_pointCbScaling[10]; //!< point Cb Scaling
70 uint8_t m_numCrPoints; //!< num Cr Points, range [0..10]
71 uint8_t m_pointCrValue[10]; //!< point Cr Value
72 uint8_t m_pointCrScaling[10]; //!< point Cr Scaling
73 int8_t m_arCoeffsY[24]; //!< ar coeffs for Y, range [-128..127]
74 int8_t m_arCoeffsCb[25]; //!< ar coeffs for Cb, range [-128..127]
75 int8_t m_arCoeffsCr[25]; //!< ar coeffs for Cr, range [-128..127]
76 uint8_t m_cbMult; //!< cb multipler
77 uint8_t m_cbLumaMult; //!< cb Luma Multipler
78 uint16_t m_cbOffset; //!< cb offset, range [0..512]
79 uint8_t m_crMult; //!< Cr multipler
80 uint8_t m_crLumaMult; //!< Cr Luma Multipler
81 uint16_t m_crOffset; //!< Cr Offset, range [0..512]
82 uint32_t m_reservedDws[4]; //!< reserved DWs
83 };
84
85 //!
86 //! \struct CodecAv1PicParams
87 //! \brief Define AV1 picture parameters
88 //!
89 struct CodecAv1PicParams
90 {
91 CODEC_PICTURE m_currPic;
92 CODEC_PICTURE m_currDisplayPic;
93 uint8_t m_profile; // [0..2]
94 uint8_t m_anchorFrameInsertion;
95 uint8_t m_anchorFrameNum;
96 PMOS_SURFACE m_anchorFrameList;
97
98 // sequence info
99 uint8_t m_orderHintBitsMinus1; // [0..7]
100 uint8_t m_bitDepthIdx; // [0..2]
101 uint8_t m_matrixCoefficients; // [0..14]
102 uint8_t m_reserved8b;
103
104 union
105 {
106 struct
107 {
108 uint32_t m_stillPicture : 1;
109 uint32_t m_use128x128Superblock : 1;
110 uint32_t m_enableFilterIntra : 1;
111 uint32_t m_enableIntraEdgeFilter : 1;
112
113 // read_compound_tools
114 uint32_t m_enableInterintraCompound : 1; // [0..1]
115 uint32_t m_enableMaskedCompound : 1; // [0..1]
116
117 uint32_t m_enableDualFilter : 1;
118 uint32_t m_enableOrderHint : 1;
119 uint32_t m_enableJntComp : 1;
120 uint32_t m_enableCdef : 1;
121 uint32_t m_reserved3b : 3;
122
123 uint32_t m_monoChrome : 1;
124 uint32_t m_colorRange : 1;
125 uint32_t m_subsamplingX : 1;
126 uint32_t m_subsamplingY : 1;
127 uint32_t m_chromaSamplePosition : 1;
128 uint32_t m_filmGrainParamsPresent : 1;
129 uint32_t m_reservedSeqInfoBits : 13;
130 } m_fields;
131 uint32_t m_value;
132 } m_seqInfoFlags;
133
134 // frame info
135 union
136 {
137 struct
138 {
139 uint32_t m_frameType : 2;
140 uint32_t m_showFrame : 1;
141 uint32_t m_showableFrame : 1;
142 uint32_t m_errorResilientMode : 1;
143 uint32_t m_disableCdfUpdate : 1;
144 uint32_t m_allowScreenContentTools : 1; // [0..1]
145 uint32_t m_forceIntegerMv : 1; // [0..1]
146 uint32_t m_allowIntrabc : 1;
147 uint32_t m_useSuperres : 1;
148 uint32_t m_allowHighPrecisionMv : 1;
149 uint32_t m_isMotionModeSwitchable : 1;
150 uint32_t m_useRefFrameMvs : 1;
151 uint32_t m_disableFrameEndUpdateCdf : 1;
152 uint32_t m_uniformTileSpacingFlag : 1;
153 uint32_t m_allowWarpedMotion : 1;
154 uint32_t m_largeScaleTile : 1;
155 uint32_t m_reservedPicInfoBits : 15;
156 } m_fields;
157 uint32_t m_value;
158 } m_picInfoFlags;
159
160 uint16_t m_frameWidthMinus1; // [0..65535] //!< Super-Res downscaled resolution
161 uint16_t m_frameHeightMinus1; // [0..65535] //!< Super-Res downscaled resolution
162
163 CODEC_PICTURE m_refFrameMap[8];
164 uint8_t m_refFrameIdx[7]; // [0..7]
165 uint8_t m_primaryRefFrame; // [0..7]
166
167 uint16_t m_outputFrameWidthInTilesMinus1; // [0..65535]
168 uint16_t m_outputFrameHeightInTilesMinus1; // [0..65535]
169 uint32_t m_reserved32b2;
170
171 // deblocking filter
172 uint8_t m_filterLevel[2]; // [0..63]
173 uint8_t m_filterLevelU; // [0..63]
174 uint8_t m_filterLevelV; // [0..63]
175 union
176 {
177 struct
178 {
179 uint8_t m_sharpnessLevel : 3; // [0..7]
180 uint8_t m_modeRefDeltaEnabled : 1;
181 uint8_t m_modeRefDeltaUpdate : 1;
182 uint8_t m_reservedField : 3; // [0]
183 } m_fields;
184 uint8_t m_value;
185 } m_loopFilterInfoFlags;
186
187 uint8_t m_orderHint;
188 uint8_t m_superresScaleDenominator; // [9..16]
189 uint8_t m_interpFilter; // [0..9]
190
191 int8_t m_refDeltas[8]; // [-64..63]
192 int8_t m_modeDeltas[2]; // [-64..63]
193
194 // quantization
195 uint16_t m_baseQindex; // [0..255]
196 int8_t m_yDcDeltaQ; // [-64..63]
197 int8_t m_uDcDeltaQ; // [-64..63]
198 int8_t m_uAcDeltaQ; // [-64..63]
199 int8_t m_vDcDeltaQ; // [-64..63]
200 int8_t m_vAcDeltaQ; // [-64..63]
201 uint8_t m_reserved8b2;
202
203 // quantization_matrix
204 union
205 {
206 struct
207 {
208 uint16_t m_usingQmatrix : 1;
209 // valid only when using_qmatrix is 1.
210 uint16_t m_qmY : 4; // [0..15]
211 uint16_t m_qmU : 4; // [0..15]
212 uint16_t m_qmV : 4; // [0..15]
213 uint16_t m_reservedField : 3; // [0]
214 } m_fields;
215 uint16_t m_value;
216 } m_qMatrixFlags;
217
218 union
219 {
220 struct
221 {
222 // delta_q parameters
223 uint32_t m_deltaQPresentFlag : 1; // [0..1]
224 uint32_t m_log2DeltaQRes : 2; // [0..3]
225
226 // delta_lf parameters
227 uint32_t m_deltaLfPresentFlag : 1; // [0..1]
228 uint32_t m_log2DeltaLfRes : 2; // [0..3]
229 uint32_t m_deltaLfMulti : 1; // [0..1]
230
231 // read_tx_mode
232 uint32_t m_txMode : 2; // [0..3]
233
234 // read_frame_reference_mode
235 uint32_t m_referenceMode : 2; // [0..3] will be replaced by reference_select
236 uint32_t m_reducedTxSetUsed : 1; // [0..1]
237
238 // tiles
239 uint32_t m_skipModePresent : 1; // [0..1]
240 uint32_t m_reservedField : 19; // [0]
241 } m_fields;
242 uint32_t m_value;
243 } m_modeControlFlags;
244
245 CodecAv1SegmentsParams m_av1SegData; //!< segment data
246
247 uint8_t m_tileCols;
248 uint16_t m_widthInSbsMinus1[64]; //!< note: 64 not 63
249 uint8_t m_tileRows;
250 uint16_t m_heightInSbsMinus1[64];
251
252 uint16_t m_tileCountMinus1;
253 uint16_t m_contextUpdateTileId;
254
255 // CDEF
256 uint8_t m_cdefDampingMinus3; // [0..3]
257 uint8_t m_cdefBits; // [0..3]
258 uint8_t m_cdefYStrengths[8]; // [0..63]
259 uint8_t m_cdefUvStrengths[8]; // [0..63]
260
261 union
262 {
263 struct
264 {
265 uint16_t m_yframeRestorationType : 2; // [0..3]
266 uint16_t m_cbframeRestorationType : 2; // [0..3]
267 uint16_t m_crframeRestorationType : 2; // [0..3]
268 uint16_t m_lrUnitShift : 2; // [0..2]
269 uint16_t m_lrUvShift : 1; // [0..1]
270 uint16_t m_reservedField : 7; // [0]
271 } m_fields;
272 uint16_t m_value;
273 } m_loopRestorationFlags;
274
275 // global motion
276 CodecAv1WarpedMotionParams m_wm[7];
277 CodecAv1FilmGrainParams m_filmGrainParams;
278
279 uint32_t m_bsBytesInBuffer;
280 uint32_t m_statusReportFeedbackNumber;
281
282 // Below are parameters for driver internal use only, not corresponding to any DDI parameter
283 bool m_losslessMode; //!< frame lossless mode
284 uint16_t m_superResUpscaledWidthMinus1; //!< Super-Res upscaled width, [0..65535]
285 uint16_t m_superResUpscaledHeightMinus1; //!< Super-Res upscaled height, [0..65535]
286 uint8_t m_activeRefBitMaskMfmv[7]; //!< active reference bitmask for Motion Field Projection, [0]: LAST_FRAME, [6]: ALTREF
287 uint8_t m_refFrameSide[8]; //!< ref_frame_side for each reference
288 };
289
290 struct CodecAv1TileParams
291 {
292 uint32_t m_bsTileDataLocation;
293 uint32_t m_bsTileBytesInBuffer;
294 uint16_t m_badBSBufferChopping;
295 uint16_t m_tileRow;
296 uint16_t m_tileColumn;
297 uint16_t m_tileIndex;
298 uint16_t m_reserved16b;
299 uint16_t m_startTileIdx;
300 uint16_t m_endTileIdx;
301 uint16_t m_tile_idx_in_tile_list;
302 CODEC_PICTURE m_anchorFrameIdx;
303 uint32_t m_bsTilePayloadSizeInBytes;
304 };
305
306
307 struct Av1SharedBuf
308 {
309 PMOS_BUFFER buffer = nullptr;
310 int refCnt = 0;
311 };
312
313 struct Av1RefAssociatedBufs
314 {
315 PMOS_BUFFER mvBuf = nullptr;
316 Av1SharedBuf *segIdBuf = nullptr;
317 Av1SharedBuf segIdWriteBuf;
318 Av1SharedBuf *initCdfBuf = nullptr;
319 Av1SharedBuf bwdAdaptCdfBuf;
320 Av1SharedBuf defaultCdfBuf;
321 bool disableFrmEndUpdateCdf = false;
322 };
323
324 enum
325 {
326 av1ChromaFormatMonochrome = 0,
327 av1ChromaFormatYuv420 = 1,
328 av1ChromaFormatYuv422 = 2,
329 av1ChromaFormatYuv444 = 3,
330 };
331
332 #endif // __CODEC_DEF_DECODE_AV1_H__
333