Debian Codegraph @

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

raw
1 /*
2 * Copyright (c) 2019-2024, 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_encode_av1.h
24 //! \brief Defines encode AV1 types and macros shared by CodecHal, MHW, and DDI layer
25 //! \details Applies to AV1 encode only. Should not contain any DDI specific code.
26 //!
27 #ifndef __CODEC_DEF_ENCODE_AV1_H__
28 #define __CODEC_DEF_ENCODE_AV1_H__
29
30 #include "codec_def_common_av1.h"
31 #include "codec_def_common_encode.h"
32 #include "codec_def_encode_avc.h"
33 #include "codec_def_encode.h"
34
35 #define CODECHAL_AV1_FRAME_HEADER_SIZE 8192
36 #define CODECHAL_ENCODE_AV1_PAK_INSERT_UNCOMPRESSED_HEADER 80
37 #define CODEC_AV1_NUM_REF_FRAMES 8
38 #define CODEC_AV1_NUM_REFL0P_FRAMES 3
39 #define CODEC_AV1_NUM_REFL0B_FRAMES 2
40 #define CODEC_AV1_NUM_REFL1B_FRAMES 1
41 #define CODEC_AV1_NUM_UNCOMPRESSED_SURFACE 127 // Maximum number of uncompressed decoded buffers that driver supports
42 #define ENCODE_VDENC_AV1_MAX_DIRTYRECT 16
43 #define ENCODE_VDENC_AV1_MAX_MOVERECT 16
44 #define ENCODE_AV1_MAX_NUM_TEMPORAL_LAYERS 8
45 #define ENCODE_VDENC_AV1_MAX_TILE_GROUP_NUM 128
46 #define ENCODE_MIM_SEGID_BLOCK_SIZE 32
47 #define ENCODE_AV1_MIN_ICQ_QUALITYFACTOR 0
48 #define ENCODE_AV1_MAX_ICQ_QUALITYFACTOR 255
49 #define ENCODE_AV1_ORDER_HINT_SIZE 256
50 // for VAConfigAttribValEncAV1Ext2.tx_mode_support
51 #define AV1_TX_MODE_ONLY_4X4_SUPPORTED 0x01
52 #define AV1_TX_MODE_LARGEST_SUPPORTED 0x02
53 #define AV1_TX_MODE_SELECT_SUPPORTED 0x04
54 #define AV1_MAX_NUM_OF_BATCH_BUFFER 5
55 #define AV1_MAX_NUM_OF_SEGMENTS 8
56 constexpr uint32_t TILE_SIZE_BYTES = 4;
57 const uint8_t OBU_LEB128_SIZE = 4;
58 const uint8_t LEB128_BYTE_MASK = 0x7f;
59 const uint8_t av1CuReordSize = 32;
60 static const uint32_t codechalEncodeModeAv1 = CODECHAL_ENCODE_MODE_AV1; // codechal encode mode AV1
61
62 enum {
63 AV1_Y_DC,
64 AV1_U_DC,
65 AV1_U_AC,
66 AV1_V_DC,
67 AV1_V_AC,
68 AV1_NUM_COEFF_QUANTIZERS
69 };
70
71 typedef enum
72 {
73 AVP_CHROMA_FORMAT_MONOCHROME = 0,
74 AVP_CHROMA_FORMAT_YUV420 = 1,
75 AVP_CHROMA_FORMAT_YUV422 = 2,
76 AVP_CHROMA_FORMAT_YUV444 = 3
77 } AVP_CHROMA_FORMAT_IDC;
78
79 typedef enum
80 {
81 SEQUENCE_HEADER_OBU = 0,
82 TEMPORAL_DELIMITER_OBU = 1,
83 PADDING_OBU = 2,
84 META_DATA_OBU = 3,
85 FRAME_HEADER_OBU = 4,
86 FRAME_OBU = 5,
87 TILE_GROUP_OBU = 6,
88 TILE_LIST_OBU = 7,
89 REDUNDANT_FRAME_HEADER_OBU = 8,
90 MAX_NUM_OBU_TYPES = 9
91 } AV1_OBU_TYPES;
92
93 typedef enum
94 {
95 AV1_ENCODED_BIT_DEPTH_8 = 0,
96 AV1_ENCODED_BIT_DEPTH_10 = 1
97 } AV1_ENCODED_BIT_DEPTH;
98
99 typedef enum //VDEnc Frame Types
100 {
101 AV1_I_FRAME = 0, // I (Intra)
102 AV1_P_FRAME = 1, // P (Inter/Pred)
103 AV1_B_FRAME = 2, // B (BiPred/Random Access)
104 AV1_GPB_FRAME = 3, // B (GPB/LowDelay)
105 } VDEncFrameType;
106
107 enum TABLE_A1_COLS_INDEX
108 {
109 MAX_PIC_SIZE_INDEX = 0,
110 MAX_H_SIZE_INDEX,
111 MAX_V_SIZE_INDEX,
112 MAX_DISPLAY_RATE_INDEX,
113 MAX_DECODE_RATE_INDEX,
114 TABLE_A1_COLS_NUM,
115 };
116
117 enum TABLE_A2_COLS_INDEX
118 {
119 MAX_HEADER_RATE_INDEX = 0,
120 MAIN_BPS_INDEX,
121 HIGH_BPS_INDEX,
122 MAIN_CR_INDEX,
123 HIGH_CR_INDEX,
124 MAX_TILES_INDEX,
125 MAX_TILE_COLS_INDEX,
126 TABLE_A2_COLS_NUM,
127 };
128 const uint64_t TableA1[][TABLE_A1_COLS_NUM] =
129 {
130 // Level |MaxPicSize | MaxHSize | MaxVSize | MaxDiaplayRate | MaxDecodeRate
131 /* 2.0 */ {147456, 2048, 1152, 4423680, 5529600},
132 /* 2.1 */ {278784, 2816, 1584, 8363520, 10454400},
133 /* 3.0 */ {665856, 4352, 2448, 19975680, 24969600},
134 /* 3.1 */ {1065024, 5504, 3096, 31950720, 39938400},
135 /* 4.0 */ {2359296, 6144, 3456, 70778880, 77856768},
136 /* 4.1 */ {2359296, 6144, 3456, 141557760, 155713536},
137 /* 5.0 */ {8912896, 8192, 4352, 267386880, 273705200},
138 /* 5.1 */ {8912896, 8192, 4352, 534773760, 547430400},
139 /* 5.2 */ {8912896, 8192, 4352, 1069547520, 1094860800},
140 /* 5.3 */ {8912896, 8192, 4352, 1069547520, 1176502272},
141 /* 6.0 */ {35651584, 16384, 8704, 1069547520, 1176502272},
142 /* 6.1 */ {35651584, 16384, 8704, 2139095040, 2189721600},
143 /* 6.2 */ {35651584, 16384, 8704, 4278190080, 4379443200},
144 /* 6.3 */ {35651584, 16384, 8704, 4278190080, 4706009088},
145 };
146 const uint32_t TableA2[][TABLE_A2_COLS_NUM] =
147 {
148 // Level | MaxHeaderRate | Mainbps | Highbps | MainCR | HighCR | MaxTiles | MaxTileCols
149 /* 2.0 */ {150, 1500000, 0, 2, 0, 8, 4},
150 /* 2.1 */ {150, 3000000, 0, 2, 0, 8, 4},
151 /* 3.0 */ {150, 6000000, 0, 2, 0, 16, 6},
152 /* 3.1 */ {150, 10000000, 0, 2, 0, 16, 6},
153 /* 4.0 */ {300, 12000000, 30000000, 4, 4, 32, 8},
154 /* 4.1 */ {300, 20000000, 50000000, 4, 4, 32, 8},
155 /* 5.0 */ {300, 30000000, 100000000, 6, 4, 64, 8},
156 /* 5.1 */ {300, 40000000, 160000000, 8, 4, 64, 8},
157 /* 5.2 */ {300, 60000000, 240000000, 8, 4, 64, 8},
158 /* 5.3 */ {300, 60000000, 240000000, 8, 4, 64, 8},
159 /* 6.0 */ {300, 60000000, 240000000, 8, 4, 128, 16},
160 /* 6.1 */ {300, 100000000, 480000000, 8, 4, 128, 16},
161 /* 6.2 */ {300, 160000000, 800000000, 8, 4, 128, 16},
162 /* 6.3 */ {300, 160000000, 800000000, 8, 4, 128, 16},
163 };
164 const uint32_t RdMultLUT[2][256] =
165 {
166 {58, 234, 234, 297, 366, 443, 528,
167 528, 619, 718, 825, 938, 1059, 1188, 1323, 1323, 1466, 1617, 1774,
168 1939, 2112, 2291, 2478, 2478, 2673, 2874, 3083, 3300, 3523, 3754,
169 3754, 3993, 4238, 4491, 4752, 5019, 5294, 5294, 5577, 5866, 6163,
170 6468, 6779, 6779, 7098, 7425, 7758, 8099, 8448, 8448, 8803, 9166,
171 9537, 9914, 10299, 10299, 10692, 11091, 11498, 11913, 11913, 12334,
172 12763, 13200, 13643, 14094, 14094, 14553, 15018, 15491, 15972,
173 15972, 16459, 16954, 17457, 17966, 17966, 18483, 19008, 19539,
174 20078, 20078, 20625, 21178, 21739, 22308, 22308, 22883, 23466,
175 24057, 24057, 24654, 25259, 25872, 26491, 26491, 27753, 28394,
176 29700, 31034, 31713, 33091, 33792, 35214, 35937, 37403, 38148,
177 39658, 40425, 41979, 42768, 44366, 45177, 46819, 47652, 49338,
178 50193, 51054, 52800, 53683, 55473, 57291, 59139, 61017, 62923,
179 65838, 67818, 69828, 71866, 73934, 76032, 78158, 80314, 82500,
180 84714, 86958, 89232, 91534, 95043, 98618, 101038, 104723, 108474,
181 111012, 114873, 118800, 121454, 125491, 128219, 132366, 135168,
182 139425, 145203, 149614, 154091, 158634, 163243, 167918, 172659,
183 177466, 182339, 187278, 193966, 199059, 205953, 211200, 216513,
184 223699, 229166, 234699, 242179, 249777, 257491, 265323, 271274,
185 279312, 287466, 295738, 304128, 312634, 321258, 330000, 338858,
186 350097, 359219, 368459, 380174, 389678, 399300, 411491, 423866,
187 433898, 446603, 459492, 472563, 485818, 499257, 512878, 526683,
188 540672, 554843, 572091, 586666, 604398, 619377, 637593, 656073,
189 674817, 693825, 713097, 732633, 755758, 779243, 799659, 827291,
190 851854, 876777, 905699, 935091, 964953, 999108, 1029966, 1065243,
191 1105137, 1145763, 1187123, 1229217, 1276366, 1328814, 1382318,
192 1436878, 1501866, 1568292, 1636154, 1715472, 1796666, 1884993,
193 1986218, 2090091, 2202291, 2323258, 2459457, 2605713, 2768923,
194 2943658, 3137291, 3344091, 3579194, 3829774, 4104334, 4420548,
195 4756843, 5140138, 5565354, 6026254, 6544618},
196 {4, 19, 23, 39, 52, 66, 92, 111, 143, 180, 220, 265, 314, 367,
197 424, 506, 573, 644, 745, 825, 939, 1060, 1155, 1289, 1394, 1541,
198 1695, 1856, 1982, 2156, 2338, 2527, 2723, 2926, 3084, 3300, 3524,
199 3755, 3993, 4239, 4492, 4686, 4952, 5225, 5506, 5794, 6089, 6315,
200 6623, 6938, 7261, 7591, 7843, 8186, 8536, 8894, 9167, 9537, 9915,
201 10300, 10593, 10991, 11396, 11705, 12123, 12441, 12872, 13310, 13644,
202 14095, 14438, 14902, 15373, 15731, 16215, 16583, 17080, 17457, 17967,
203 18354, 18876, 19273, 19674, 20215, 20625, 21179, 21599, 22023, 22595,
204 23029, 23614, 24057, 24505, 25108, 25565, 26026, 26961, 28073, 29044,
205 30031, 31204, 32227, 33266, 34322, 35575, 36667, 37775, 38900, 40041,
206 41199, 42373, 43564, 44771, 45995, 47235, 48492, 49765, 51055, 52361,
207 53684, 55023, 57063, 58907, 61017, 63164, 65104, 67321, 69323, 71610,
208 73675, 76032, 78159, 80315, 82775, 84994, 87241, 89518, 92115, 95044,
209 98318, 101648, 104724, 108160, 111651, 114873, 118141, 121789, 125153,
210 128563, 132019, 135873, 140141, 144839, 149245, 153716, 158254, 163244,
211 167919, 172660, 177467, 181931, 188108, 193967, 199487, 205519, 211640,
212 217852, 223700, 229625, 236093, 243123, 250256, 257978, 265324, 272273,
213 279818, 287467, 296260, 304656, 313706, 322345, 331101, 339974, 350097,
214 359794, 370205, 380175, 390875, 401117, 412721, 424490, 435793, 447884,
215 459492, 472564, 485819, 499257, 512879, 526684, 541376, 556985, 572092,
216 587400, 604399, 621640, 639123, 656073, 675604, 694623, 714715, 735094,
217 756591, 779244, 802230, 827292, 852739, 878571, 907523, 936018, 966835,
218 999108, 1032884, 1068210, 1106144, 1145764, 1187124, 1232404, 1279614,
219 1331023, 1384571, 1441473, 1503040, 1568292, 1639831, 1716726, 1799234,
220 1888939, 1986219, 2090092, 2205134, 2329100, 2465467, 2610352, 2772111,
221 2946945, 3140684, 3349346, 3581006, 3831649, 4112097, 4424575, 4763110,
222 5142310, 5567614, 4289813442, 4290334454}
223 };
224
225 //DDI version 0.20
226 typedef struct _CODEC_AV1_ENCODE_SEQUENCE_PARAMS
227 {
228 uint8_t seq_profile; // [0]
229 uint8_t seq_level_idx; // [0..23, 31]
230 uint16_t GopPicSize;
231 uint8_t TargetUsage;
232 uint8_t RateControlMethod;
233 uint8_t GopRefDist;
234 uint8_t GopOptFlag : 2;
235 uint8_t reserved6b : 6;
236 uint32_t TargetBitRate[8]; // One per temporal layer
237 uint32_t MaxBitRate;
238 uint32_t MinBitRate;
239 uint32_t InitVBVBufferFullnessInBit;
240 uint32_t VBVBufferSizeInBit;
241 uint32_t OptimalVBVBufferLevelInBit;
242 uint32_t UpperVBVBufferLevelThresholdInBit;
243 uint32_t LowerVBVBufferLevelThresholdInBit;
244
245 union
246 {
247 struct
248 {
249 uint32_t ResetBRC : 1;
250 uint32_t StillPicture : 1;
251 uint32_t UseRawReconRef : 1;
252 uint32_t DisplayFormatSwizzle : 1; //[0]
253 uint32_t bLookAheadPhase : 1;
254 uint32_t HierarchicalFlag : 1;
255 uint32_t RGBInputStudioRange : 1; // [0, 1]
256 uint32_t ConvertedYUVStudioRange : 1; // [0, 1]
257 uint32_t EnableFastPass : 1; // [0, 1]
258 uint32_t LADsRatio : 2; // [0..2]
259 uint32_t Reserved0 : 21;
260 } fields;
261 uint32_t value;
262 } SeqFlags;
263
264 uint32_t UserMaxIFrameSize;
265 uint32_t UserMaxPBFrameSize;
266 FRAMERATE FrameRate[8]; // One per temporal layer
267 uint8_t NumTemporalLayersMinus1;
268 uint8_t ICQQualityFactor; // [0..255], with 0 being the best quality
269
270 ENCODE_INPUT_COLORSPACE InputColorSpace;
271 ENCODE_SCENARIO ScenarioInfo;
272 ENCODE_CONTENT ContentInfo;
273 ENCODE_FRAMESIZE_TOLERANCE FrameSizeTolerance;
274 uint16_t SlidingWindowSize;
275 uint32_t MaxBitRatePerSlidingWindow;
276 uint32_t MinBitRatePerSlidingWindow;
277
278 union
279 {
280 struct
281 {
282 uint32_t enable_order_hint : 1;
283 uint32_t enable_superres : 1;
284 uint32_t enable_cdef : 1;
285 uint32_t enable_restoration : 1;
286 uint32_t enable_warped_motion : 1; //[0]
287 uint32_t enable_filter_intra : 1;
288 uint32_t enable_intra_edge_filter : 1;
289 uint32_t enable_interintra_compound : 1;
290 uint32_t enable_masked_compound : 1;
291 uint32_t enable_dual_filter : 1;
292 uint32_t enable_jnt_comp : 1;
293 uint32_t enable_ref_frame_mvs : 1;
294 uint32_t Reserved3 : 20;
295 } fields;
296 uint32_t value;
297 } CodingToolFlags;
298
299 uint8_t order_hint_bits_minus_1; // [0..7]
300 union
301 {
302 uint8_t LookaheadDepth; // [0..100]
303 uint8_t TargetFrameSizeConfidence; // [0..100]
304 };
305
306 uint8_t Reserved8b2;
307 uint8_t Reserved8b3;
308 uint32_t Reserved32b[16];
309 } CODEC_AV1_ENCODE_SEQUENCE_PARAMS, *PCODEC_AV1_ENCODE_SEQUENCE_PARAMS;
310
311 struct CODEC_Intel_Seg_AV1
312 {
313 union
314 {
315 struct
316 {
317 uint8_t segmentation_enabled : 1;
318 uint8_t SegmentNumber : 4; //[0..8]
319 uint8_t update_map : 1;
320 uint8_t temporal_update : 1;
321 uint8_t Reserved0 : 1;
322 } fields;
323 uint8_t value;
324 } SegmentFlags;
325
326 int16_t feature_data[8][8];
327 uint8_t feature_mask[8];
328 uint32_t Reserved1[4];
329 };
330
331 struct CODEC_Warped_Motion_Params_AV1
332 {
333 uint32_t wmtype;
334 int32_t wmmat[8];
335 int8_t invalid;
336 };
337
338 struct CODEC_Ref_Frame_Ctrl_AV1
339 {
340 union
341 {
342 struct
343 {
344 uint32_t search_idx0 : 3;
345 uint32_t search_idx1 : 3;
346 uint32_t search_idx2 : 3;
347 uint32_t search_idx3 : 3;
348 uint32_t search_idx4 : 3;
349 uint32_t search_idx5 : 3;
350 uint32_t search_idx6 : 3;
351 uint32_t ReservedField : 11; //[0]
352 } fields;
353 uint32_t value;
354 } RefFrameCtrl;
355 };
356
357 /*! \brief Provides the picture-level parameters of a compressed picture for AV1 decoding.
358 */
359 typedef struct _CODEC_AV1_ENCODE_PICTURE_PARAMS
360 {
361 uint16_t frame_width_minus1; // [15..2^16-1]
362 uint16_t frame_height_minus1; // [15..2^16-1]
363 uint8_t NumTileGroupsMinus1; // [0..255]
364 uint8_t Reserved8b; // [0]
365 CODEC_PICTURE CurrOriginalPic; // [0..127]
366 CODEC_PICTURE CurrReconstructedPic; // [0..11]
367 CODEC_PICTURE RefFrameList [8]; // [0..11, 0xFF]
368 uint8_t ref_frame_idx[7]; // [0..6]
369 uint8_t HierarchLevelPlus1;
370 uint8_t primary_ref_frame; // [0..7]
371 uint8_t AdaptiveTUEnabled;
372 uint8_t Reserved8b4;
373 uint8_t order_hint;
374
375 CODEC_Ref_Frame_Ctrl_AV1 ref_frame_ctrl_l0;
376 CODEC_Ref_Frame_Ctrl_AV1 ref_frame_ctrl_l1;
377
378 union
379 {
380 struct
381 {
382 uint32_t frame_type : 2; // [0..3]
383 uint32_t error_resilient_mode : 1; // [0..1]
384 uint32_t disable_cdf_update : 1; // [0..1]
385 uint32_t use_superres : 1; // [0..1]
386 uint32_t allow_high_precision_mv : 1; // [0..1]
387 uint32_t use_ref_frame_mvs : 1; // [0..1]
388 uint32_t disable_frame_end_update_cdf : 1; // [0..1]
389 uint32_t reduced_tx_set_used : 1; // [0..1]
390 uint32_t reserved1b : 1; // [0..1]
391 uint32_t SegIdBlockSize : 2; // [0..3]
392 uint32_t EnableFrameOBU : 1;
393 uint32_t DisableFrameRecon : 1;
394 uint32_t LongTermReference : 1;
395 uint32_t allow_intrabc : 1;
396 uint32_t PaletteModeEnable : 1;
397 uint32_t EnableDeltaQP : 1;
398 uint32_t Reserved2 : 14;
399 } fields;
400 uint32_t value;
401 } PicFlags;
402
403 // deblocking filter
404 uint8_t filter_level[2]; // [0..63]
405 uint8_t filter_level_u; // [0..63]
406 uint8_t filter_level_v; // [0..63]
407
408 union
409 {
410 struct
411 {
412 uint8_t sharpness_level : 3; // [0..7]
413 uint8_t mode_ref_delta_enabled : 1;
414 uint8_t mode_ref_delta_update : 1;
415 uint8_t Reserved3 : 3; // [0]
416 } fields;
417 uint8_t value;
418 } cLoopFilterInfoFlags;
419
420 uint8_t superres_scale_denominator; // [9..16]
421 uint8_t interp_filter; // [0..9]
422 uint8_t Reserved4; // [0]
423 int8_t ref_deltas[8]; // [-63..63]
424 int8_t mode_deltas[2]; // [-63..63]
425
426 // quantization
427 uint16_t base_qindex; // [0..255]
428 int8_t y_dc_delta_q; // [-15..15]
429 int8_t u_dc_delta_q; // [-63..63]
430 int8_t u_ac_delta_q; // [-63..63]
431 int8_t v_dc_delta_q; // [-63..63]
432 int8_t v_ac_delta_q; // [-63..63]
433 uint8_t MinBaseQIndex; // [1..255]
434 uint8_t MaxBaseQIndex; // [1..255]
435 uint8_t Reserved5; // [0]
436
437 // quantization_matrix
438 union {
439 struct {
440 uint16_t using_qmatrix : 1; // verify if supported
441
442 // valid only when using_qmatrix is 1.
443 uint16_t qm_y : 4; // [0..15]
444 uint16_t qm_u : 4; // [0..15]
445 uint16_t qm_v : 4; // [0..15]
446 uint16_t Reserved6 : 3; // [0]
447 } fields;
448 uint16_t value;
449 } wQMatrixFlags;
450
451 uint16_t Reserved7; // [0]
452
453 union
454 {
455 struct
456 {
457 // delta_q parameters
458 uint32_t delta_q_present_flag : 1; // [0..1]
459 uint32_t log2_delta_q_res : 2; // [0..3]
460
461 // delta_lf parameters
462 uint32_t delta_lf_present_flag : 1; // [0..1]
463 uint32_t log2_delta_lf_res : 2; // [0..3]
464 uint32_t delta_lf_multi : 1; // [0..1]
465
466 // read_tx_mode
467 uint32_t tx_mode : 2; // [0..3]
468
469 // read_frame_reference_mode
470 uint32_t reference_mode : 2; // [0..3]
471 uint32_t reduced_tx_set_used : 1; // [0..1]
472
473 uint32_t skip_mode_present : 1; // [0..1]
474 uint32_t Reserved8 : 19; // [0]
475 } fields;
476 uint32_t value;
477 } dwModeControlFlags;
478
479 CODEC_Intel_Seg_AV1 stAV1Segments;
480 uint16_t tile_cols;
481 uint16_t width_in_sbs_minus_1[63];
482 uint16_t tile_rows;
483 uint16_t height_in_sbs_minus_1[63];
484 uint8_t context_update_tile_id; // [0..127]
485 uint8_t temporal_id;
486
487 // CDEF
488 uint8_t cdef_damping_minus_3; // [0..3]
489 uint8_t cdef_bits; // [0..3]
490 uint8_t cdef_y_strengths[8]; // [0..63]
491 uint8_t cdef_uv_strengths[8]; // [0..63]
492
493 union
494 {
495 struct
496 {
497 uint16_t yframe_restoration_type : 2; // [0..3]
498 uint16_t cbframe_restoration_type : 2; // [0..3]
499 uint16_t crframe_restoration_type : 2; // [0..3]
500 uint16_t lr_unit_shift : 2; // [0..2]
501 uint16_t lr_uv_shift : 1; // [0..1]
502 uint16_t Reserved9 : 7; // [0]
503 } fields;
504 uint16_t value;
505 } LoopRestorationFlags;
506
507 // global motion
508 CODEC_Warped_Motion_Params_AV1 wm[7];
509
510 uint32_t QIndexBitOffset;
511 uint32_t SegmentationBitOffset;
512 uint32_t LoopFilterParamsBitOffset;
513 uint32_t CDEFParamsBitOffset;
514 uint8_t CDEFParamsSizeInBits;
515 uint8_t reserved8bits0;
516 uint16_t FrameHdrOBUSizeInBits;
517 uint32_t FrameHdrOBUSizeByteOffset;
518 uint32_t StatusReportFeedbackNumber;
519
520 // Tile Group OBU header
521 union
522 {
523 struct
524 {
525 uint8_t obu_extension_flag : 1; // [0..1]
526 uint8_t obu_has_size_field : 1; // [0..1]
527 uint8_t temporal_id : 3; // [0..7]
528 uint8_t spatial_id : 2; // [0..3]
529 uint8_t ReservedField : 1; // [0]
530 } fields;
531 uint8_t value;
532 } TileGroupOBUHdrInfo; //DDI 0.06
533
534 uint8_t reserved8bs1; // [0]
535 uint8_t reserved8bs2; // [0]
536 // Skip Frames
537 uint8_t NumSkipFrames;
538 int32_t FrameSizeReducedInBytes;
539
540 uint16_t NumDirtyRects;
541 ENCODE_RECT *pDirtyRect;
542 uint16_t NumMoveRects;
543 MOVE_RECT *pMoveRect;
544 uint32_t InputType;
545 uint32_t TargetFrameSize;
546 uint8_t QpModulationStrength;
547
548 /*! \brief quality information report enable flags.
549 */
550 union
551 {
552 struct
553 {
554 uint8_t enable_frame : 1;
555 uint8_t enable_block : 1;
556 uint8_t reserved : 6;
557 } fields;
558 uint8_t value;
559 } QualityInfoSupportFlags;
560 uint8_t reserved8b[2];
561
562 union
563 {
564 void *pBlkQualityInfo;
565 uint32_t Reserved9[2];
566 };
567
568 uint32_t Reserved10[12];
569 } CODEC_AV1_ENCODE_PICTURE_PARAMS, *PCODEC_AV1_ENCODE_PICTURE_PARAMS;
570
571 /*! \brief Slice-level parameters of a compressed picture for AV1 encoding.
572 */
573 typedef struct _CODEC_AV1_ENCODE_TILE_GROUP_PARAMS
574 {
575 uint8_t TileGroupStart;
576 uint8_t TileGroupEnd;
577 uint16_t Reserved16b;
578 uint32_t Reserved32b[9];
579 } CODEC_AV1_ENCODE_TILE_GROUP_PARAMS, *PCODEC_AV1_ENCODE_TILE_GROUP_PARAMS;
580
581 typedef struct _CODEC_AV1_ENCODE_PACKEDHEADER_DATA
582 {
583 uint8_t *pData;
584 uint32_t BufferSize;
585 uint32_t DataLength;
586 uint32_t DataOffset;
587 uint32_t SkipEmulationByteCount;
588 uint32_t Reserved;
589 } CODEC_AV1ENCODE_PACKEDHEADER_DATA, *PCODEC_AV1ENCODE_PACKEDHEADER_DATA;
590
591 #define MAX_BSTRUCTURE_GOP_SIZE 16
592 #define MAX_BSTRUCTURE_REF_NUM 8
593 #define MAX_TLEVEL 16
594 #define AV1_NUM_OF_REF_LF_DELTAS 8
595 #define AV1_NUM_OF_MODE_LF_DELTAS 2
596 #define AV1_NUM_OF_DUAL_CTX 2
597 struct EncodeAv1Par
598 {
599
600 /* Configurable parameters */
601 uint32_t NumFrames;
602 uint32_t GopRefDist;
603 uint32_t GopOptFlag;
604 uint32_t Width;
605 uint32_t Height;
606 uint32_t FrameRateNom;
607 uint32_t FrameRateDeNom;
608 uint32_t EncMode;
609 uint32_t NumP;
610
611 uint32_t Profile;
612 uint32_t InternalBitDepth;
613 uint32_t InputBitDepth;
614 uint32_t OutputBitDepth;
615 uint32_t ChromaFormatIDC;
616 uint32_t InputFileFormat;
617 uint32_t AdaptiveRounding;
618 uint32_t ColorSpace;
619 uint32_t DisableCdfUpdate;
620 uint32_t EnableSeg;
621 uint32_t SegMapUpdateCycle;
622 uint32_t SegTemporalUpdate;
623 uint32_t BaseKeyFrameQP;
624 uint32_t BasePFrameQP;
625 uint32_t KeyFrameQP[8]; /* Fixed QP for K frame, all segments */
626 uint32_t PFrameQP[8]; /* Fixed QP for P frame, all segments */
627 int32_t KeyCTQPDelta[AV1_NUM_COEFF_QUANTIZERS]; // Key frame QP deltas for coefficient type [YAC, UDC, UAC]
628 int32_t PCTQPDelta[AV1_NUM_COEFF_QUANTIZERS]; //P frame QP deltas for coefficient type [YAC, UDC, UAC]
629 uint32_t BaseLoopFilterLevel[2]; /* Loop filter level, all segments */
630 uint32_t SegLoopFilterLevel[2][8]; /* Loop filter level, all segments */
631 int32_t RefTypeLFDelta[AV1_NUM_OF_REF_LF_DELTAS]; // Loop filter level delta for ref types
632 int32_t MBTypeLFDelta[AV1_NUM_OF_MODE_LF_DELTAS]; // Look filter level delta for MB types
633 int32_t SegmentRef[8]; //Fixed reference per segment: -1 = not fixed
634 uint32_t SegmentSkip[8]; //Segment skip flag, per segment.
635 uint32_t SegmentGlobalMV[8]; //Segment global MV flag, per segment.
636 uint32_t NumTileCols;
637 uint32_t NumTileRows;
638 uint32_t UniformSpacingFlag;
639 uint32_t TileWidths[av1MaxTileColumn];
640 uint32_t TileHeights[av1MaxTileColumn];
641 uint32_t Log2TileCols;
642 uint32_t Log2TileRows;
643 uint32_t LoopFilterAcrossTiles;
644 uint32_t NumTileGroup;
645 uint32_t MaxNumTileCols;
646 uint32_t MaxNumTileRows;
647 uint32_t MinNumTileCols;
648 uint32_t MinNumTileRows;
649 uint32_t TxMode;
650 uint32_t IntraOnly;
651 uint32_t McMode;
652 uint32_t AllowHpMv;
653 uint32_t CompPredMode;
654 uint32_t FrameParallel;
655 uint32_t ContextUpdateTileId;
656
657 //RDO
658 uint32_t RdoEnable;
659 //intra prediction control
660 uint32_t KeyIntraPrediction;
661 uint32_t PIntraPrediction;
662
663 //adaptive deadzone
664 uint32_t AdaptiveDeadZoneEnable;
665
666 //VDEnc Mode
667 uint32_t VDEncSpeedMode;
668
669 //Super Resolution
670 uint32_t EnableSuperResolution;
671 uint32_t SuperresScaleDenominator;
672 uint32_t SuperresUsePreScaleRef;
673 uint32_t SuperresStartFrame;
674 uint32_t SuperresEndFrame;
675
676 uint32_t FrameIdNumbersPresentFlag;
677 int32_t GroupTileHeaderNumBytes;
678
679 uint32_t LoopFilterLevelFormulaType;
680 uint32_t DoSwapInRef1List;
681 uint32_t PrimaryRefFrameSelection;
682
683 uint32_t UsingQmatrix;
684 uint32_t QMatrixY;
685 uint32_t QMatrixU;
686 uint32_t QMatrixV;
687
688 //Ref ctrl
689 uint32_t RefCtrl;
690
691 bool AdditionalFWDAlphaSearchEnable;
692 bool AdditionalFWDBetaSearchEnable;
693
694 uint32_t EnableStatistics;
695 uint32_t RDOQEnable;
696 uint32_t CDEFMode;
697 uint32_t LRMode;
698 uint32_t LRFilterTypeY;
699 uint32_t LRFilterTypeU;
700 uint32_t LRFilterTypeV;
701 uint32_t EnableCDEFSearchForRandEnc;
702 uint32_t EnableLRSearchForRandEnc;
703
704 uint32_t CDEFYStrength[8];
705 uint32_t CDEFUVStrength[8];
706 uint32_t CDEFBits;
707 uint32_t UseDefaultCDEFStrengths;
708
709 // StreamIn
710 uint32_t StreamInEnable;
711 uint32_t StreamInSegEnable;
712 uint32_t StreamInMaxCuSize;
713 uint32_t StreamInMaxTuSize;
714 uint32_t StreamInNumImePredictors;
715 uint32_t StreamInNumMergeCandidateCu8x8;
716 uint32_t StreamInNumMergeCandidateCu16x16;
717 uint32_t StreamInNumMergeCandidateCu32x32;
718 uint32_t StreamInNumMergeCandidateCu64x64;
719
720 //B Frame Coding Structure
721 uint32_t BGOPSize;
722 int32_t IntraPeriod;
723 uint32_t PerBFramePOC[MAX_BSTRUCTURE_GOP_SIZE];
724 uint32_t PerBFrameQPOffset[MAX_BSTRUCTURE_GOP_SIZE];
725 double PerBFrameLambdaQPOffset[MAX_BSTRUCTURE_GOP_SIZE];
726 uint32_t PerBFrameRoundingInter[MAX_BSTRUCTURE_GOP_SIZE];
727 uint32_t PerBFrameRoundingIntra[MAX_BSTRUCTURE_GOP_SIZE];
728 double PerBFrameQPFactor[MAX_BSTRUCTURE_GOP_SIZE];
729 uint32_t PerBFrameTemporalID[MAX_BSTRUCTURE_GOP_SIZE];
730 uint32_t PerBFrameNumRefPicsActiveL0[MAX_BSTRUCTURE_GOP_SIZE];
731 uint32_t PerBFrameNumRefPicsActiveL1[MAX_BSTRUCTURE_GOP_SIZE];
732 uint32_t PerBFrameNumRefPics[MAX_BSTRUCTURE_GOP_SIZE];
733 int32_t PerBFrameRefPics[MAX_BSTRUCTURE_GOP_SIZE * MAX_BSTRUCTURE_REF_NUM];
734 uint32_t PerBFrameEnableCurrPicInL1[MAX_BSTRUCTURE_GOP_SIZE];
735
736 };
737
738 struct MetadataAV1PostFeature
739 {
740 struct
741 {
742 uint64_t RowCount;
743 uint64_t ColCount;
744 uint64_t RowHeights[64];
745 uint64_t ColWidths[64];
746 uint64_t ContextUpdateTileId;
747 } tilePartition;
748
749 struct
750 {
751 uint64_t CompoundPredictionType;
752 struct
753 {
754 uint64_t LoopFilterLevel[2];
755 uint64_t LoopFilterLevelU;
756 uint64_t LoopFilterLevelV;
757 uint64_t LoopFilterSharpnessLevel;
758 uint64_t LoopFilterDeltaEnabled;
759 uint64_t UpdateRefDelta;
760 int64_t RefDeltas[8];
761 uint64_t UpdateModeDelta;
762 int64_t ModeDeltas[2];
763 } LoopFilter;
764 struct
765 {
766 uint64_t DeltaLFPresent;
767 uint64_t DeltaLFMulti;
768 uint64_t DeltaLFRes;
769 } LoopFilterDelta;
770 struct
771 {
772 uint64_t BaseQIndex;
773 int64_t YDCDeltaQ;
774 int64_t UDCDeltaQ;
775 int64_t UACDeltaQ;
776 int64_t VDCDeltaQ;
777 int64_t VACDeltaQ;
778 uint64_t UsingQMatrix;
779 uint64_t QMY;
780 uint64_t QMU;
781 uint64_t QMV;
782 } Quantization;
783 struct
784 {
785 uint64_t DeltaQPresent;
786 uint64_t DeltaQRes;
787 } QuantizationDelta;
788 struct
789 {
790 uint64_t CdefBits;
791 uint64_t CdefDampingMinus3;
792 uint64_t CdefYPriStrength[8];
793 uint64_t CdefUVPriStrength[8];
794 uint64_t CdefYSecStrength[8];
795 uint64_t CdefUVSecStrength[8];
796 } CDEF;
797 struct
798 {
799 uint64_t UpdateMap;
800 uint64_t TemporalUpdate;
801 uint64_t UpdateData;
802 uint64_t NumSegments;
803 struct
804 {
805 uint64_t EnabledFeatures;
806 int64_t FeatureValue[8];
807 } SegmentsData[8];
808 } SegmentationConfig;
809 uint64_t PrimaryRefFrame;
810 uint64_t ReferenceIndices[7];
811 } postFeature;
812 };
813
814 struct AV1MetaDataOffset
815 {
816 //tile partition
817 uint32_t dwRowCount = 0;
818 uint32_t dwColCount = 0;
819 uint32_t dwRowHeights = 0;
820 uint32_t dwColWidths = 0;
821 uint32_t dwContextUpdateTileId = 0;
822 //post feature
823 uint32_t dwCompoundPredictionType = 0;
824 uint32_t dwLoopFilter = 0;
825 uint32_t dwLoopFilterDelta = 0;
826 uint32_t dwQuantization = 0;
827 uint32_t dwQuantizationDelta = 0;
828 uint32_t dwCDEF = 0;
829 uint32_t dwSegmentationConfig = 0;
830 uint32_t dwPrimaryRefFrame = 0;
831 uint32_t dwReferenceIndices = 0;
832 //loop filter
833 uint32_t dwLoopFilterLevel = 0;
834 uint32_t dwLoopFilterLevelU = 0;
835 uint32_t dwLoopFilterLevelV = 0;
836 uint32_t dwLoopFilterSharpnessLevel = 0;
837 uint32_t dwLoopFilterDeltaEnabled = 0;
838 uint32_t dwUpdateRefDelta = 0;
839 uint32_t dwRefDeltas = 0;
840 uint32_t dwUpdateModeDelta = 0;
841 uint32_t dwModeDeltas = 0;
842 //loop filter delta
843 uint32_t dwDeltaLFPresent = 0;
844 uint32_t dwDeltaLFMulti = 0;
845 uint32_t dwDeltaLFRes = 0;
846 //Quantization
847 uint32_t dwBaseQIndex = 0;
848 uint32_t dwYDCDeltaQ = 0;
849 uint32_t dwUDCDeltaQ = 0;
850 uint32_t dwUACDeltaQ = 0;
851 uint32_t dwVDCDeltaQ = 0;
852 uint32_t dwVACDeltaQ = 0;
853 uint32_t dwUsingQMatrix = 0;
854 uint32_t dwQMY = 0;
855 uint32_t dwQMU = 0;
856 uint32_t dwQMV = 0;
857 //QuantizationDelta
858 uint32_t dwDeltaQPresent = 0;
859 uint32_t dwDeltaQRes = 0;
860 //CDEF
861 uint32_t dwCdefBits = 0;
862 uint32_t dwCdefDampingMinus3 = 0;
863 uint32_t dwCdefYPriStrength = 0;
864 uint32_t dwCdefUVPriStrength = 0;
865 uint32_t dwCdefYSecStrength = 0;
866 uint32_t dwCdefUVSecStrength = 0;
867 //SegmentationConfig
868 uint32_t dwUpdateMap = 0;
869 uint32_t dwTemporalUpdate = 0;
870 uint32_t dwUpdateData = 0;
871 uint32_t dwNumSegments = 0;
872 uint32_t dwSegmentsData = 0;
873 //dwSegmentsData
874 uint32_t dwEnabledFeatures = 0;
875 uint32_t dwFeatureValue = 0;
876 uint32_t dwSegmentsDataSize = 0;
877 };
878
879 struct EncoderParamsAV1 : EncoderParams
880 {
881 uint32_t segmentMapDataSize = 0; //!< [AV1] size of data in segment map buffer
882 uint8_t *pSegmentMap = nullptr; //!< [AV1] pointer to segment map buffer from DDI
883 AV1MetaDataOffset AV1metaDataOffset = {}; //!< [AV1] AV1 Specific metadata offset
884 };
885
886 enum RoundingMethod
887 {
888 fixedRounding = 0,
889 adaptiveRounding,
890 lookUpTableRounding = 3
891 };
892 #endif // __CODEC_DEF_ENCODE_AV1_H__