xref: /aosp_15_r20/external/libva/va/va_enc_av1.h (revision 54e60f844a168e9a219354de272cd517ee8cd4b7)
1 /*
2  * Copyright (c) 2021 Intel Corporation. All Rights Reserved.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the
6  * "Software"), to deal in the Software without restriction, including
7  * without limitation the rights to use, copy, modify, merge, publish,
8  * distribute, sub license, and/or sell copies of the Software, and to
9  * permit persons to whom the Software is furnished to do so, subject to
10  * the following conditions:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19  * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR
20  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 /**
26  * \file va_enc_av1.h
27  * \brief AV1 encoding API
28  *
29  * This file contains the \ref api_enc_av1 "AV1 encoding API".
30  *
31  */
32 
33 #ifndef VA_ENC_AV1_H
34 #define VA_ENC_AV1_H
35 
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39 
40 #include <stdint.h>
41 
42 /**
43  * \defgroup api_enc_av1 AV1 encoding API
44  *
45  * This AV1 encoding API supports 8-bit/10bit 420 format only.
46  *
47  * @{
48  */
49 
50 /** \brief Attribute value for VAConfigAttribEncAV1.
51  *
52  * This attribute decribes the supported features of an AV1
53  * encoder configuration.
54  *
55  * All of the field values in this attribute are VA_FEATURE_* values,
56  * indicating support for the corresponding feature.
57  *
58  */
59 typedef union _VAConfigAttribValEncAV1 {
60     struct {
61         /**
62          * \brief Use 128x128 superblock.
63          *
64          * Allows setting use_128x128_superblock in the SPS.
65          */
66         uint32_t support_128x128_superblock     : 2;
67         /**
68          * \brief Intra  filter.
69          * Allows setting enable_filter_intra in the SPS.
70          */
71         uint32_t support_filter_intra           : 2;
72         /**
73          * \brief  Intra edge filter.
74          * Allows setting enable_intra_edge_filter in the SPS.
75          */
76         uint32_t support_intra_edge_filter      : 2;
77         /**
78          * \brief  Interintra compound.
79          * Allows setting enable_interintra_compound in the SPS.
80          */
81         uint32_t support_interintra_compound    : 2;
82         /**
83          * \brief  Masked compound.
84          * Allows setting enable_masked_compound in the SPS.
85          */
86         uint32_t support_masked_compound        : 2;
87         /**
88          * \brief  Warped motion.
89          * Allows setting enable_warped_motion in the SPS.
90          */
91         uint32_t support_warped_motion          : 2;
92         /**
93          * \brief  Palette mode.
94          * Allows setting palette_mode in the PPS.
95          */
96         uint32_t support_palette_mode           : 2;
97         /**
98          * \brief  Dual filter.
99          * Allows setting enable_dual_filter in the SPS.
100          */
101         uint32_t support_dual_filter            : 2;
102         /**
103          * \brief  Jnt compound.
104          * Allows setting enable_jnt_comp in the SPS.
105          */
106         uint32_t support_jnt_comp               : 2;
107         /**
108          * \brief  Refrence frame mvs.
109          * Allows setting enable_ref_frame_mvs in the SPS.
110          */
111         uint32_t support_ref_frame_mvs          : 2;
112         /**
113          * \brief  Super resolution.
114          * Allows setting enable_superres in the SPS.
115          */
116         uint32_t support_superres               : 2;
117         /**
118          * \brief  Restoration.
119          * Allows setting enable_restoration in the SPS.
120          */
121         uint32_t support_restoration            : 2;
122         /**
123          * \brief  Allow intraBC.
124          * Allows setting allow_intrabc in the PPS.
125          */
126         uint32_t support_allow_intrabc          : 2;
127         /**
128          * \brief  Cdef channel strength.
129          * Allows setting cdef_y_strengths and cdef_uv_strengths in PPS.
130          */
131         uint32_t support_cdef_channel_strength  : 2;
132         /** \brief Reserved bits for future, must be zero. */
133         uint32_t reserved                       : 4;
134     } bits;
135     uint32_t value;
136 } VAConfigAttribValEncAV1;
137 
138 /** \brief Attribute value for VAConfigAttribEncAV1Ext1. */
139 typedef union _VAConfigAttribValEncAV1Ext1 {
140     struct {
141         /**
142          * \brief Fields indicate which types of interpolation filter are supported.
143          * (interpolation_filter & 0x01) == 1: eight_tap filter is supported, 0: not.
144          * (interpolation_filter & 0x02) == 1: eight_tap_smooth filter is supported, 0: not.
145          * (interpolation_filter & 0x04) == 1: eight_sharp filter is supported, 0: not.
146          * (interpolation_filter & 0x08) == 1: bilinear filter is supported, 0: not.
147          * (interpolation_filter & 0x10) == 1: switchable filter is supported, 0: not.
148          */
149         uint32_t interpolation_filter          : 5;
150         /**
151          * \brief Min segmentId block size accepted.
152          * Application need to send seg_id_block_size in PPS equal or larger than this value.
153          */
154         uint32_t min_segid_block_size_accepted : 8;
155         /**
156          * \brief Type of segment feature supported.
157          * (segment_feature_support & 0x01) == 1: SEG_LVL_ALT_Q is supported, 0: not.
158          * (segment_feature_support & 0x02) == 1: SEG_LVL_ALT_LF_Y_V is supported, 0: not.
159          * (segment_feature_support & 0x04) == 1: SEG_LVL_ALT_LF_Y_H is supported, 0: not.
160          * (segment_feature_support & 0x08) == 1: SEG_LVL_ALT_LF_U is supported, 0: not.
161          * (segment_feature_support & 0x10) == 1: SEG_LVL_ALT_LF_V is supported, 0: not.
162          * (segment_feature_support & 0x20) == 1: SEG_LVL_REF_FRAME is supported, 0: not.
163          * (segment_feature_support & 0x40) == 1: SEG_LVL_SKIP is supported, 0: not.
164          * (segment_feature_support & 0x80) == 1: SEG_LVL_GLOBALMV is supported, 0: not.
165          */
166         uint32_t segment_feature_support       : 8;
167         /** \brief Reserved bits for future, must be zero. */
168         uint32_t reserved                      : 11;
169     } bits;
170     uint32_t value;
171 } VAConfigAttribValEncAV1Ext1;
172 
173 /** \brief Attribute value for VAConfigAttribEncAV1Ext2. */
174 typedef union _VAConfigAttribValEncAV1Ext2 {
175     struct {
176         /**
177         * \brief Tile size bytes minus1.
178         * Specify the number of bytes needed to code tile size supported.
179         * This value need to be set in frame header obu.
180         */
181         uint32_t tile_size_bytes_minus1        : 2;
182         /**
183         * \brief Tile size bytes minus1.
184         * Specify the fixed number of bytes needed to code syntax obu_size.
185         */
186         uint32_t obu_size_bytes_minus1         : 2;
187         /**
188          * \brief tx_mode supported.
189          * (tx_mode_support & 0x01) == 1: ONLY_4X4 is supported, 0: not.
190          * (tx_mode_support & 0x02) == 1: TX_MODE_LARGEST is supported, 0: not.
191          * (tx_mode_support & 0x04) == 1: TX_MODE_SELECT is supported, 0: not.
192          */
193         uint32_t tx_mode_support               : 3;
194         /**
195          * \brief Max tile num minus1.
196          * Specify the max number of tile supported by driver.
197          */
198         uint32_t max_tile_num_minus1           : 13;
199         /** \brief Reserved bits for future, must be zero. */
200         uint32_t reserved                      : 12;
201     } bits;
202     uint32_t value;
203 } VAConfigAttribValEncAV1Ext2;
204 
205 /**
206  * \brief Packed header types specific to AV1 encoding.
207  *
208  * Types of packed headers generally used for AV1 encoding.
209  *
210  */
211 typedef enum {
212     /**
213      * \brief Packed Sequence Parameter Set (SPS).
214      *
215      * The corresponding packed header data buffer shall contain the
216      * complete sequence_header_obu() syntax element.
217      *
218      */
219     VAEncPackedHeaderAV1_SPS = VAEncPackedHeaderSequence,
220     /**
221      * \brief Packed Picture Parameter Set (PPS).
222      *
223      * The corresponding packed header data buffer shall contain the
224      * complete frame_header_obu() syntax element.
225      *
226      */
227     VAEncPackedHeaderAV1_PPS = VAEncPackedHeaderPicture,
228 } VAEncPackedHeaderTypeAV1;
229 
230 /**
231  * \brief AV1 Encoding Sequence Parameter Buffer Structure.
232  *
233  * This structure conveys sequence level parameters.
234  *
235  */
236 typedef struct  _VAEncSequenceParameterBufferAV1 {
237     /** \brief AV1 profile setting.
238      *  value range [0..2].
239      */
240     uint8_t     seq_profile;
241 
242     /** \brief Level Setting of current operation point.
243      *  value range [0..23].
244      */
245     uint8_t     seq_level_idx;
246 
247     /** \brief Tier Setting of current operation point.
248      *  value range [0..1].
249      */
250     uint8_t     seq_tier;
251 
252     /** \brief Indicates whether or not the encoding is in dyadic hierarchical GOP structure.
253      *  value range [0..1].
254      */
255     uint8_t     hierarchical_flag;
256 
257     /** \brief Period between intra_only frames. */
258     uint32_t    intra_period;
259 
260     /** \brief Period between I/P frames.
261      *  For hierarchical structure, this is the anchor frame distance.
262      */
263     uint32_t    ip_period;
264 
265     /* \brief RC related fields. RC modes are set with VAConfigAttribRateControl. */
266     /* For AV1, CBR implies HRD conformance and VBR implies no HRD conformance. */
267 
268     /**
269      * \brief Initial bitrate set for this sequence in CBR or VBR modes.
270      *
271      * This field represents the initial bitrate value for CBR mode or
272      * initial max bitrate value for VBR mode in this sequence.
273      * i.e. if the encoder pipeline was created with a #VAConfigAttribRateControl
274      * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR.
275      *
276      * The bitrate can be modified later on through
277      * #VAEncMiscParameterRateControl buffers.
278      */
279     uint32_t    bits_per_second;
280 
281     union {
282         struct {
283             /** \brief Still picture encoding, no inter frame referencing. */
284             uint32_t    still_picture                               : 1;
285             /** \brief Force using 128x128 or 64x64 Supper block */
286             uint32_t    use_128x128_superblock                      : 1;
287             /** \brief Corresponds to AV1 syntax element of the same name. */
288             uint32_t    enable_filter_intra                         : 1;
289             /** \brief Corresponds to AV1 syntax element of the same name. */
290             uint32_t    enable_intra_edge_filter                    : 1;
291             /** \brief Corresponds to AV1 syntax element of the same name. */
292             uint32_t    enable_interintra_compound                  : 1;
293             /** \brief Corresponds to AV1 syntax element of the same name. */
294             uint32_t    enable_masked_compound                      : 1;
295             /** \brief Corresponds to AV1 syntax element of the same name. */
296             uint32_t    enable_warped_motion                        : 1;
297             /** \brief Corresponds to AV1 syntax element of the same name. */
298             uint32_t    enable_dual_filter                          : 1;
299             /** \brief Corresponds to AV1 syntax element of the same name. */
300             uint32_t    enable_order_hint                           : 1;
301             /** \brief Corresponds to AV1 syntax element of the same name. */
302             uint32_t    enable_jnt_comp                             : 1;
303             /** \brief Corresponds to AV1 syntax element of the same name. */
304             uint32_t    enable_ref_frame_mvs                        : 1;
305             /** \brief Corresponds to AV1 syntax element of the same name. */
306             uint32_t    enable_superres                             : 1;
307             /** \brief Corresponds to AV1 syntax element of the same name. */
308             uint32_t    enable_cdef                                 : 1;
309             /** \brief Corresponds to AV1 syntax element of the same name. */
310             uint32_t    enable_restoration                          : 1;
311             /** \brief Sepcify number of bits for every channel(Y, U or V). */
312             uint32_t    bit_depth_minus8                            : 3;
313             /** \brief Corresponds to AV1 syntax element of the same name. */
314             uint32_t    subsampling_x                               : 1;
315             /** \brief Corresponds to AV1 syntax element of the same name. */
316             uint32_t    subsampling_y                               : 1;
317             /** \brief Corresponds to AV1 syntax element of the same name. */
318             uint32_t    mono_chrome                                 : 1;
319             /** \brief Reserved bytes for future use, must be zero. */
320             uint32_t    reserved_bits                               : 12;
321         } bits;
322         uint32_t value;
323     } seq_fields;
324 
325     /** \brief Corresponds to AV1 syntax element of the same name.
326      *  value range [0..7].
327      */
328     uint8_t     order_hint_bits_minus_1;
329 
330     /** \brief Reserved bytes for future use, must be zero */
331     uint32_t                va_reserved[VA_PADDING_HIGH];
332 } VAEncSequenceParameterBufferAV1;
333 
334 #define VA_AV1_MAX_SEGMENTS    8
335 #define VA_AV1_SEG_LVL_MAX     8
336 
337 /**
338  * \brief Segment parameters
339  */
340 typedef struct _VAEncSegParamAV1 {
341     union {
342         struct {
343             /** \brief Indicates if segmentation is enabled in the current frame.
344              *  If disabled, all the below parameters in the structure should
345              *  be set to 0, and ignored by driver.
346              */
347             uint8_t     segmentation_enabled            : 1;
348 
349             /**
350              *  When segmentation_enabled equals 1 and segment_number > 0,
351              *  this parameter equals 1 indicates the segmentation map may
352              *  come from application, and that "Segment map data buffer"
353              *  should be provided with populated segment_id. If equals 0,
354              *  segmentation map should be inherited from a reference frame
355              *  (specified by \c primary_ref_frame). When segmentation_enabled or
356              *  segment_number equals 0, this parameter should be set to 0
357              *  and ignored by driver.
358              */
359             uint8_t     segmentation_update_map         : 1;
360             /**
361              * When segmentation_update_map equals 1, this parameter equaling 1
362              * indicates segment id per block will be determined either from
363              * reference frame or from app. Equaling 0 means segment id per block
364              * will come from app. When segmentation_temporal_update equals 0,
365              * this parameter should be set to 0 and ignored by driver.
366             */
367             uint8_t     segmentation_temporal_update    : 1;
368             /** \brief Reserved bytes for future use, must be zero. */
369             uint8_t     reserved                        : 5;
370 
371         } bits;
372         uint8_t value;
373     } seg_flags;
374 
375     /**
376      *  If segmentation_enabled equals 1, this parameter indicates
377      *  the number of segments conveyed through VAAPI. In this case,
378      *  if segment_number equals 0, it will force the driver to determine
379      *  how many segments would be created as well as the segmentation map
380      *  to be generated. Also the driver shall write the segmentation_params()
381      *  syntax in the uncompressed header at \c bit_offset_segmentation (back-annotation).
382      *  In application, the rest parameters in this structure should be all
383      *  set to 0 and ignored by driver. And app should NOT send the
384      *  "Segment map data buffer". In packed uncompressed header
385      *  bitstream, app should write syntax element segmentation_enabled
386      *  as 0 and segmentation_params() should be only 1-bit-long.
387      *  If segment_number > 0, and segmentation_update_map = 1, app should provide
388      *  the "Segment map data buffer" and populate the rest of the
389      *  current data structure. And that underline encoder would honor
390      *  the segmentation parameters feature_data[0..segment_number-1][]
391      *  and feature_mask[0..segment_number-1], etc.
392      *  Value range [0..8].
393      */
394     uint8_t      segment_number;
395 
396     /** \brief segment parameters.
397      *  feature_data[][] is equivalent to variable FeatureData[][] in spec,
398      *  which is after clip3() operation.
399      *  Clip3(x, y, z) = (z<x)? x : ((z > y)? y : z);
400      *  The limit is defined in Segmentation_Feature_Max[ SEG_LVL_MAX ] = {
401      *  255, MAX_LOOP_FILTER, MAX_LOOP_FILTER, MAX_LOOP_FILTER,
402      *  MAX_LOOP_FILTER, 7, 0, 0 }
403      */
404     int16_t     feature_data[VA_AV1_MAX_SEGMENTS][VA_AV1_SEG_LVL_MAX];
405 
406     /** \brief Bit field to indicate each feature is enabled or not per
407      *  segment_id. Each bit is the feature_id.
408      */
409     uint8_t     feature_mask[VA_AV1_MAX_SEGMENTS];
410 
411     /** \brief Reserved bytes for future use, must be zero. */
412     uint32_t                va_reserved[VA_PADDING_LOW];
413 } VAEncSegParamAV1;
414 
415 /**
416  * \brief Segment map data buffer.
417  *
418  * This buffer is optional depending on the value of av1_segments.segmentation_enabled.
419  * If av1_segments.segmentation_enabled in the picture parameters equals 1,
420  * and RateControlMethod is not CQP and this surface is not provided by App,
421  * the encoder will determine the per block segmentation map. In this case,
422  * App should not provide the segmentation parameter data structure
423  * in frame header as well. If av1_segments.segmentation_enabled equals 1
424  * and the segmentation map buffer is provided, app should embed the
425  * segmentation info in frame header, populate the VAEncSegParamAV1 structure with
426  * #VAEncMacroblockMapBufferType and the driver as well as the underline encoder
427  * should honor what is given by the app.
428  */
429 typedef struct _VAEncSegMapBufferAV1 {
430     /** \brief Segment map data size. */
431     uint32_t    segmentMapDataSize;
432 
433     /**
434      * \brief Segment map.
435      * Size of this map is indicated by \ref segmentMapDataSize and each element
436      * in this map contains the segment id of a particular block.
437      * The element is indexed by raster scan order.
438      * The value of each entry should be in the range [0..7], inclusive.
439      */
440     uint8_t    *pSegmentMap;
441 } VAEncSegMapBufferAV1;
442 
443 typedef enum {
444     /** \brief Identity transformation, 0-parameter. */
445     VAAV1EncTransformationIdentity           = 0,
446     /** \brief Translational motion, 2-parameter. */
447     VAAV1EncTransformationTranslation        = 1,
448     /** \brief Simplified affine with rotation + zoom only, 4-parameter. */
449     VAAV1EncTransformationRotzoom            = 2,
450     /** \brief Affine, 6-parameter. */
451     VAAV1EncTransformationAffine             = 3,
452     /** \brief Transformation count. */
453     VAAV1EncTransformationCount
454 } VAEncTransformationTypeAV1;
455 
456 typedef struct _VAEncWarpedMotionParamsAV1 {
457 
458     /** \brief Specify the type of warped motion. */
459     VAEncTransformationTypeAV1  wmtype;
460 
461     /** \brief Specify warp motion parameters.
462      *  wm.wmmat[] corresponds to gm_params[][] in spec.
463      *  Details in AV1 spec section 5.9.24 or refer to libaom code
464      *  https://aomedia.googlesource.com/aom/+/refs/heads/master/av1/decoder/decodeframe.c.
465      */
466     int32_t                 wmmat[8];
467 
468     /** \brief Valid or invalid on affine set. */
469     uint8_t                 invalid;
470 
471     /** \brief Reserved bytes for future use, must be zero. */
472     uint32_t                va_reserved[VA_PADDING_LOW];
473 
474 } VAEncWarpedMotionParamsAV1;
475 
476 /**
477  * \brief Reference frame control.
478  *
479  * Suggest which frame to be used as reference along with preferred search order.
480  *
481  * search_idx#: index into ref_frame_idx[] to indicate that frame will be included
482  * in the reference list if value in range [1..7]. Invalid when value is 0.
483  * The order of the search_idx# indicates the preferred search order.
484  *
485  */
486 typedef union {
487     struct {
488         /**
489          * \brief Value used as index into ref_frame_idx[] to indicate that frame
490          * will be included in the reference list.
491          * valid value range: [1..7], invalid when value is 0.
492          */
493         uint32_t search_idx0 : 3;
494         /**
495          * \brief Value used as index into ref_frame_idx[] to indicate that frame
496          * will be included in the reference list.
497          * valid value range: [1..7], invalid when value is 0.
498          */
499         uint32_t search_idx1 : 3;
500         /**
501          * \brief Value used as index into ref_frame_idx[] to indicate that frame
502          * will be included in the reference list.
503          * valid value range: [1..7], invalid when value is 0.
504          */
505         uint32_t search_idx2 : 3;
506         /**
507          * \brief Value used as index into ref_frame_idx[] to indicate that frame
508          * will be included in the reference list.
509          * valid value range: [1..7], invalid when value is 0.
510          */
511         uint32_t search_idx3 : 3;
512         /**
513          * \brief Value used as index into ref_frame_idx[] to indicate that frame
514          * will be included in the reference list.
515          * valid value range: [1..7], invalid when value is 0.
516          */
517         uint32_t search_idx4 : 3;
518         /**
519          * \brief Value used as index into ref_frame_idx[] to indicate that frame
520          * will be included in the reference list.
521          * valid value range: [1..7], invalid when value is 0.
522          */
523         uint32_t search_idx5 : 3;
524         /**
525          * \brief Value used as index into ref_frame_idx[] to indicate that frame
526          * will be included in the reference list.
527          * valid value range: [1..7], invalid when value is 0.
528          */
529         uint32_t search_idx6 : 3;
530 
531         /** \brief Reserved bytes for future use, must be zero. */
532         uint32_t Reserved    : 11;
533     } fields;
534     uint32_t value;
535 } VARefFrameCtrlAV1;
536 
537 /**
538  * \brief AV1 Encoding Picture Parameter Buffer Structure.
539  *
540  * This structure conveys picture level parameters.
541  *
542  */
543 typedef struct  _VAEncPictureParameterBufferAV1 {
544     /** \brief AV1 encoder may support SupRes and dynamic scaling function.
545      *  For SupRes, underline encoder is responsible to do downscaling.
546      *  For dynamic scaling, app should provide the scaled raw source.
547      */
548     /** \brief Raw source frame width in pixels. */
549     uint16_t    frame_width_minus_1;
550     /** \brief Raw source frame height in pixels. */
551     uint16_t    frame_height_minus_1;
552 
553     /** \brief Surface to store reconstructed frame, not used for enc only case. */
554     VASurfaceID reconstructed_frame;
555 
556     /** \brief Buffer to store coded data. */
557     VABufferID  coded_buf;
558 
559     /** \brief Reference frame buffers.
560      *  Each entry of the array specifies the surface index of the picture
561      *  that is referred by current picture or will be referred by any future
562      *  picture. The valid entries take value from 0 to 127, inclusive.
563      *  Non-valid entries, those do not point to pictures which are referred
564      *  by current picture or future pictures, should take value 0xFF.
565      *  Other values are not allowed.
566      *
567      *  Application should update this array based on the refreshing
568      *  information expected.
569      */
570     VASurfaceID reference_frames[8];
571 
572     /** \brief Reference index list.
573      *  Contains a list of indices into refernce_frames[].
574      *  Indice with refernce frames range: [LAST_FRAME - LAST_FRAME,
575      *  LAST2_FRAME - LAST_FRAME, ..., ALTREF2_FRAME - LAST_FRAME].
576      *  #define LAST_FRAME 1
577      *  #define LAST2_FRAME 2
578      *  #define LAST3_FRAME 3
579      *  #define GOLDEN_FRAME 4
580      *  #define BWDREF_FRAME 5
581      *  #define ALTREF_FRAME 6
582      *  #define ALTREF2_FRAME 7
583      *  value range [0..7].
584      */
585     uint8_t     ref_frame_idx[7];
586 
587     /** \brief When hierarchical_level_plus1 > 0, hierarchical_level_plus1-1 indicates
588      *  the current frame's level. If VAEncMiscParameterTemporalLayerStructure
589      *  is valid (number_of_layers >0), hierarchical_level_plus1 shouldn't larger than number_of_layers.
590      */
591     uint8_t     hierarchical_level_plus1;
592 
593     /** \brief primary reference frame.
594      *  Index into reference_frames[]
595      *  segment id map, context table, etc. come from the reference
596      *  frame pointed by this index.
597      *  value range [0..7].
598      */
599     uint8_t     primary_ref_frame;
600 
601     /** \brief Corresponds to AV1 syntax element of the same name. */
602     uint8_t     order_hint;
603 
604     /** \brief Corresponds to AV1 syntax element of the same name. */
605     uint8_t     refresh_frame_flags;
606 
607     /** \brief Reserved bytes for future use, must be zero. */
608     uint8_t     reserved8bits1;
609 
610     /** \brief Suggest which frames to be used as references.
611      *  see struct #VARefFrameCtrl for details.
612      */
613     VARefFrameCtrlAV1     ref_frame_ctrl_l0;
614     VARefFrameCtrlAV1     ref_frame_ctrl_l1;
615 
616     union {
617         struct {
618             /** \brief frame type.
619              *  0:  key_frame.
620              *  1:  inter_frame.
621              *  2:  intra_only frame.
622              *  3:  switch_frame (app needs to set error_resilient_mode = 1,
623              *      refresh_frame_flags, etc approperately.).
624              */
625             uint32_t    frame_type                      : 2;
626             /** \brief Corresponds to AV1 syntax element of the same name. */
627             uint32_t    error_resilient_mode            : 1;
628             /** \brief Corresponds to AV1 syntax element of the same name. */
629             uint32_t    disable_cdf_update              : 1;
630             /** \brief Corresponds to AV1 syntax element of the same name. */
631             uint32_t    use_superres                    : 1;
632             /** \brief Corresponds to AV1 syntax element of the same name. */
633             uint32_t    allow_high_precision_mv         : 1;
634             /** \brief Corresponds to AV1 syntax element of the same name. */
635             uint32_t    use_ref_frame_mvs               : 1;
636             /** \brief Corresponds to AV1 syntax element of the same name. */
637             uint32_t    disable_frame_end_update_cdf    : 1;
638             /** \brief Corresponds to AV1 syntax element of the same name. */
639             uint32_t    reduced_tx_set                  : 1;
640 
641             /** \brief For single tile group, app may choose to use one frame obu
642              *  to replace one frame header obu + one tile group obu.
643              *  Invalid if num_tile_groups_minus1 > 0.
644              */
645             uint32_t    enable_frame_obu                : 1;
646 
647             /** \brief Indicate the current frame will be used as a long term reference. */
648             uint32_t    long_term_reference             : 1;
649             /** \brief If the encoded frame will not be referred by other frames,
650              * its recon may not be generated in order to save memory bandwidth.
651              */
652             uint32_t    disable_frame_recon             : 1;
653             /** \brief Corresponds to AV1 syntax element of the same name. */
654             uint32_t    allow_intrabc                   : 1;
655             /** \brief Equal to 1 indicates that intra blocks may use palette encoding.
656              * Otherwise disable palette encoding.
657              */
658             uint32_t    palette_mode_enable             : 1;
659             /** \brief Corresponds to AV1 syntax element of the same name. */
660             uint32_t    allow_screen_content_tools      : 1;
661             /** \brief Corresponds to AV1 syntax element of the same name. */
662             uint32_t    force_integer_mv                : 1;
663             /** \brief Reserved bytes for future use, must be zero. */
664             uint32_t    reserved                        : 16;
665         } bits;
666         uint32_t value;
667     } picture_flags;
668 
669     /** \brief Block size for each Segment ID in Segment Map.
670      *  0: 16x16 block size, default value;
671      *  1: 32x32 block size;
672      *  2: 64x64 block size;
673      *  3: 8x8 block size.
674      */
675     uint8_t     seg_id_block_size;
676 
677     /** \brief Number of tile groups minus 1.
678      *  value range [0..255].
679      */
680     uint8_t     num_tile_groups_minus1;
681 
682     /** \brief Temporal id of the frame.*/
683     uint8_t     temporal_id;
684 
685     /** \brief Deblock filter parameters.
686      *  value range [0..63].
687      */
688     uint8_t     filter_level[2];
689     uint8_t     filter_level_u;
690     uint8_t     filter_level_v;
691 
692     union {
693         struct {
694             /** \brief Sharpness level for deblock filter.
695              *  value range [0..7].
696              */
697             uint8_t     sharpness_level                 : 3;
698             uint8_t     mode_ref_delta_enabled          : 1;
699             uint8_t     mode_ref_delta_update           : 1;
700             /** \brief Reserved bytes for future use, must be zero. */
701             uint8_t     reserved                        : 3;
702         } bits;
703         uint8_t    value;
704     } loop_filter_flags;
705 
706     /** \brief Super resolution scale denominator.
707      *  value range [9..16].
708      */
709     uint8_t     superres_scale_denominator;
710     /** \brief Corresponds to AV1 syntax element of the same name. */
711     uint8_t     interpolation_filter;
712 
713     /** \brief Loop filter ref deltas.
714      *  value range [-63..63].
715      */
716     int8_t      ref_deltas[8];
717 
718     /** \brief Loop filter mode deltas.
719      *  value range [-63..63].
720      */
721     int8_t      mode_deltas[2];
722 
723     /** \brief Quantization params. */
724     uint8_t     base_qindex;
725     int8_t      y_dc_delta_q;
726     int8_t      u_dc_delta_q;
727     int8_t      u_ac_delta_q;
728     int8_t      v_dc_delta_q;
729     int8_t      v_ac_delta_q;
730 
731     /** \brief Min value for base q index for BRC.
732      *  value range [1..255].
733      */
734     uint8_t     min_base_qindex;
735 
736     /** \brief Max value for base q index for BRC.
737      *  value range [1..255].
738      */
739     uint8_t     max_base_qindex;
740 
741     /** \brief Quantization matrix. */
742     union {
743         struct {
744             /** \brief Corresponds to AV1 syntax element of the same name. */
745             uint16_t    using_qmatrix                   : 1;
746             /** \brief Following parameters only valid when using_qmatrix == 1. */
747             uint16_t    qm_y                            : 4;
748             /** \brief Corresponds to AV1 syntax element of the same name. */
749             uint16_t    qm_u                            : 4;
750             /** \brief Corresponds to AV1 syntax element of the same name. */
751             uint16_t    qm_v                            : 4;
752             /** \brief Reserved bytes for future use, must be zero. */
753             uint16_t    reserved                        : 3;
754         } bits;
755         uint16_t    value;
756     } qmatrix_flags;
757 
758     /** \brief Reserved bytes for future use, must be zero. */
759     uint16_t reserved16bits1;
760 
761     union {
762         struct {
763             /** \brief Specify whether quantizer index delta values are present.
764              *  value range [0..1]. */
765             uint32_t    delta_q_present                 : 1;
766             /** \brief Corresponds to AV1 syntax element of the same name.
767              *  value range [0..3]. */
768             uint32_t    delta_q_res                     : 2;
769 
770             /** \brief Specify whether loop filter delta values are present.
771              *  value range [0..1]. */
772             uint32_t    delta_lf_present                : 1;
773             /** \brief Corresponds to AV1 syntax element of the same name.
774              *  value range [0..3]. */
775             uint32_t    delta_lf_res                    : 2;
776             /** \brief Corresponds to AV1 syntax element of the same name.
777              *  value range [0..1]. */
778             uint32_t    delta_lf_multi                  : 1;
779 
780             /** \brief Corresponds to AV1 syntax element of the same name.
781              *  0: ONLY_4X4;
782              *  1: TX_MODE_LARGEST;
783              *  2: TX_MODE_SELECT;
784              *  3: Invalid.
785              */
786             uint32_t    tx_mode                         : 2;
787 
788             /** \brief Indicates whether to use single or compound reference prediction.
789              *  0: SINGLE_REFERENCE;
790              *  1: COMPOUND_REFERENCE;
791              *  2: REFERENCE_MODE_SELECT.
792              *  3: Invalid.
793              *
794              *  Value 2 means driver make decision to use single reference or compound reference.
795              */
796             uint32_t    reference_mode                  : 2;
797             /** \brief Corresponds to AV1 syntax element of the same name.
798              *  value range [0..1].
799              */
800             uint32_t    skip_mode_present               : 1;
801             /** \brief Reserved bytes for future use, must be zero. */
802             uint32_t    reserved                        : 20;
803         } bits;
804         uint32_t    value;
805     } mode_control_flags;
806 
807     /** \brief Segmentation parameters. */
808     VAEncSegParamAV1    segments;
809 
810     /** \brief Number of tile columns. */
811     uint8_t     tile_cols;
812     /** \brief Number of tile rows. */
813     uint8_t     tile_rows;
814 
815     /** \brief Reserved bytes for future use, must be zero. */
816     uint16_t    reserved16bits2;
817 
818     /** \brief The last tile column or row size needs to be derived. */
819     uint16_t    width_in_sbs_minus_1[63];
820     uint16_t    height_in_sbs_minus_1[63];
821 
822     /** \brief specify which tile to use for the CDF update.
823      *  value range [0..127]*/
824     uint16_t     context_update_tile_id;
825 
826     /** \brief Corresponds to AV1 syntax element of the same name.
827      *  value range [0..3].
828      */
829     uint8_t     cdef_damping_minus_3;
830     /** \brief Corresponds to AV1 syntax element of the same name.
831      *  value range [0..3].
832      */
833     uint8_t     cdef_bits;
834     /** \brief CDEF Y strengths.
835      *  value range [0..63]*/
836     uint8_t     cdef_y_strengths[8];
837     /** \brief CDEF UV strengths.
838      *  value range [0..63]*/
839     uint8_t     cdef_uv_strengths[8];
840 
841     union {
842         struct {
843             /** \brief Restoration type for Y frame.
844              *  value range [0..3].
845              */
846             uint16_t    yframe_restoration_type         : 2;
847             /** \brief Restoration type for Cb frame.
848              *  value range [0..3].
849              */
850             uint16_t    cbframe_restoration_type        : 2;
851             /** \brief Restoration type for Cr frame.
852              *  value range [0..3].
853              */
854             uint16_t    crframe_restoration_type        : 2;
855             /** \brief Corresponds to AV1 syntax element of the same name.
856              *  value range [0..2].
857              */
858             uint16_t    lr_unit_shift                   : 2;
859             /** \brief Corresponds to AV1 syntax element of the same name.
860              *  value range [0..1].
861              */
862             uint16_t    lr_uv_shift                     : 1;
863             /** \brief Reserved bytes for future use, must be zero. */
864             uint16_t    reserved                        : 7;
865         } bits;
866         uint16_t    value;
867     } loop_restoration_flags;
868 
869     /** \brief Global motion. */
870     VAEncWarpedMotionParamsAV1    wm[7];
871 
872     /**
873      *  Offset in bits for syntax base_q_idx in packed frame header bit stream
874      *  from the start of the packed header data.
875      *  In BRC mode, this parameter should be set and driver will update base_q_idx in
876      *  uncompressed header according to this offset.
877      *  In CQP mode, this parameter should be set to 0 and ignored by driver.
878      */
879     uint32_t    bit_offset_qindex;
880     /**
881      *  Offset in bits for syntax segmentation_enabled of frame header OBU
882      *  in packed frame header bit stream from the start of the packed header data.
883      *  Valid only in auto segmentation mode. Other than that, this parameter
884      *  should be set to 0 and ignored by driver.
885      */
886     uint32_t    bit_offset_segmentation;
887     /**
888      *  Offset in bits for syntax loop_filter_params() in packed frame
889      *  header bit stream from the start of the packed header data.
890      *  In BRC mode, this parameter should be set and driver will update filter params
891      *  in packed frame header according to this offset.
892      *  In CQP mode, this parameter should be set to 0 and ignored by driver.
893      */
894     uint32_t    bit_offset_loopfilter_params;
895     /**
896      *  In BRC mode, underline encoder should generate the approperiate
897      *  CDEF values and write back into uncompressed header. And app
898      *  should provide default CDEF values in packed header. This parameter
899      *  should point to the starting bit of cdef_params() syntax structure
900      *  in packed header.
901      *  In CQP mode, this parameter should be set to 0 and ignored by driver.
902      */
903     uint32_t    bit_offset_cdef_params;
904     /**
905      *  In BRC mode, this parameter indicates the actual bit usage of
906      *  cdef_params() syntax structure in packed uncompressed header.
907      *  In CQP mode, this parameter should be set to 0 and ignored by driver.
908      */
909     uint32_t    size_in_bits_cdef_params;
910 
911     /**
912      *  Offset in bytes for syntax obu_size of frame header OBU in packed
913      *  frame header bit stream from the start of the packed header. The frame
914      *  header OBU size depends on the encoded tile sizes. It applies to both
915      *  Frame Header OBU and Frame OBU if obu_size needs to be updated by
916      *  underline encoder. Otherwise, app can set it to 0 and ignored by driver.
917      *
918      *  In BRC mode, obu_size needs to be updated and this parameter should be set.
919      *  In CQP mode, obu_size needs to be updated if \c enable_frame_obu == 1. Otherwise
920      *  this parameter should be set to 0 and ignored by driver.
921      */
922     uint32_t    byte_offset_frame_hdr_obu_size;
923 
924     /**
925      * Frame header OBU bit stream size in bits. The frame header obu packed bit
926      * stream contains an obu header, a 4-byte long obu_size field, frame_header_obu()
927      * syntax chain, and a trailing bit if not inside a frame obu. If \c enable_frame_obu == 1,
928      * the value should include and up to the last bit of frame_header_obu() and
929      * excluding the bits generated by byte_alignment(). If \c enable_frame_obu == 0,
930      * the value should include and up to the trailing bit at the end of the frame
931      * header obu. The size will be used by encoder to calculate the final frame
932      * header size after bit shifting due to auto segmentation.
933      * In CQP mode, this parameter should be set to 0 and ignored by driver.
934      */
935     uint32_t    size_in_bits_frame_hdr_obu;
936 
937     /** \brief Tile Group OBU header */
938     union {
939         struct {
940             /** \brief Corresponds to AV1 syntax element of the same name.
941              *  value range [0..1].
942              */
943             uint8_t     obu_extension_flag              : 1;
944             /** \brief Corresponds to AV1 syntax element of the same name.
945              *  value range [0..1].
946              */
947             uint8_t     obu_has_size_field              : 1;
948             /** \brief Corresponds to AV1 syntax element of the same name.
949              *  value range [0..7].
950              */
951             uint8_t     temporal_id                     : 3;
952             /** \brief Corresponds to AV1 syntax element of the same name.
953              *  value range [0..2].
954              */
955             uint8_t     spatial_id                      : 2;
956             /** \brief Reserved bytes for future use, must be zero. */
957             uint8_t     reserved                        : 1;
958         } bits;
959         uint8_t     value;
960     } tile_group_obu_hdr_info;
961 
962     /** \brief The number of frames skipped prior to the current frame.
963      *  It includes only the skipped frames that were not counted before.
964      *  App may generate the "show_existing_frame" short frame header OBUs
965      *  and send to driver with the next frame. Default value 0.
966      */
967     uint8_t     number_skip_frames;
968 
969     /** \brief Reserved bytes for future use, must be zero. */
970     uint16_t    reserved16bits3;
971 
972     /** \brief Indicates the application forced frame size change in bytes.
973      * When the value is positive, the frame size is reduced. Otherwise, the frame
974      * size increases. The parameter can be used when application skips frames with
975      * setting of NumSkipFrames. And application can also use it for other scenarios
976      * such as inserting "show_existing_frame" at very end of the sequence.
977      */
978     int32_t    skip_frames_reduced_size;
979 
980     /** \brief Reserved bytes for future use, must be zero. */
981     uint32_t    va_reserved[VA_PADDING_HIGH];
982 } VAEncPictureParameterBufferAV1;
983 
984 /**
985  * \brief Tile Group Buffer.
986  */
987 typedef struct _VAEncTileGroupBufferAV1 {
988     /** \brief Tile group start location.
989      *  The position of the first tile in current tile group
990      *  in raster scan order across the frame.
991      *  value range [0..127].
992      */
993     uint8_t  tg_start;
994     /** \brief Tile group end location.
995      *  The position of the last tile in current tile group
996      *  in raster scan order across the frame.
997      *  value range [0..127].
998      */
999     uint8_t  tg_end;
1000 
1001     /** \brief Reserved bytes for future use, must be zero. */
1002     uint32_t                va_reserved[VA_PADDING_LOW];
1003 } VAEncTileGroupBufferAV1;
1004 
1005 /**@}*/
1006 
1007 #ifdef __cplusplus
1008 }
1009 #endif
1010 
1011 #endif /* VA_ENC_AV1_H */
1012