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     codec_def_encode_vp9.h
24 //! \brief    Defines encode VP9 types and macros shared by CodecHal, MHW, and DDI layer
25 //! \details  Applies to VP9 encode only. Should not contain any DDI specific code.
26 //!
27 #ifndef __CODEC_DEF_ENCODE_VP9_H__
28 #define __CODEC_DEF_ENCODE_VP9_H__
29 
30 #include "codec_def_common.h"
31 #include "codec_def_common_encode.h"
32 #include "codec_def_common_vp9.h"
33 
34 #define CODECHAL_ENCODE_VP9_MAX_NAL_UNIT_TYPE       1 // only support one NAL unit for uncompressed header
35 #define CODECHAL_ENCODE_VP9_MAX_NUM_TEMPORAL_LAYERS 8
36 #define ENCODE_VP9_NUM_MAX_L0_REF                   3
37 #define VP9_MAX_COEFF_PARTITIONS                    4
38 #define VP9_HYBRIDPAK_PER_MB_DATA_SIZE              816
39 #define VP9_HYBRIDPAK_PER_MB_MV_DATA_SIZE           64
40 #define CODECHAL_ENCODE_VP9_FRAME_HEADER_SIZE       4096
41 
42 typedef enum
43 {
44     VP9_ENCODED_CHROMA_FORMAT_YUV420 = 0,
45     VP9_ENCODED_CHROMA_FORMAT_YUV422 = 1,
46     VP9_ENCODED_CHROMA_FORMAT_YUV444 = 2
47 } VP9_ENCODED_CHROMA_FORMAT;
48 
49 typedef enum
50 {
51     VP9_ENCODED_BIT_DEPTH_8 = 0,
52     VP9_ENCODED_BIT_DEPTH_10 = 1,
53     VP9_ENCODED_BIT_DEPTH_12 = 2
54 } VP9_ENCODED_BIT_DEPTH;
55 
56 typedef struct _CODEC_VP9_ENCODE_SEG_PARAMS
57 {
58     union
59     {
60         struct
61         {
62             uint8_t       SegmentReferenceEnabled : 1;
63             uint8_t       SegmentReference        : 2;
64             uint8_t       SegmentSkipped          : 1;
65             uint8_t       ReservedField3          : 4;
66         } fields;
67         uint8_t           value;
68 
69     } SegmentFlags;
70 
71     char                SegmentLFLevelDelta;
72     int16_t             SegmentQIndexDelta;
73 
74 } CODEC_VP9_ENCODE_SEG_PARAMS, *PCODEC_VP9_ENCODE_SEG_PARAMS;
75 
76 typedef struct _CODEC_VP9_ENCODE_SEGMENT_PARAMS
77 {
78     CODEC_VP9_ENCODE_SEG_PARAMS SegData[8];
79 
80 } CODEC_VP9_ENCODE_SEGMENT_PARAMS, *PCODEC_VP9_ENCODE_SEGMENT_PARAMS;
81 
82 typedef struct _CODEC_VP9_ENCODE_SEQUENCE_PARAMS
83 {
84     uint16_t       wMaxFrameWidth;
85     uint16_t       wMaxFrameHeight;
86     uint16_t       GopPicSize;
87     uint8_t        TargetUsage;
88     uint8_t        RateControlMethod;
89     uint32_t       TargetBitRate[CODECHAL_ENCODE_VP9_MAX_NUM_TEMPORAL_LAYERS];
90     uint32_t       MaxBitRate;
91     uint32_t       MinBitRate;
92     uint32_t       InitVBVBufferFullnessInBit;
93     uint32_t       VBVBufferSizeInBit;
94     uint32_t       OptimalVBVBufferLevelInBit;
95     uint32_t       UpperVBVBufferLevelThresholdInBit;
96     uint32_t       LowerVBVBufferLevelThresholdInBit;
97 
98     union
99     {
100         struct
101         {
102             uint32_t bResetBRC                  : 1;
103             uint32_t bNoFrameHeaderInsertion    : 1;
104             uint32_t bUseRawReconRef            : 1;
105             uint32_t MBBRC                      : 4; // This is not to be set for VP9 VDEnc (G10+), this is removed from DDI, only here to support legacy KBL DP
106             uint32_t EnableDynamicScaling       : 1;
107             uint32_t SourceFormat               : 2;
108             uint32_t SourceBitDepth             : 2;
109             uint32_t EncodedFormat              : 2;
110             uint32_t EncodedBitDepth            : 2;
111             uint32_t DisplayFormatSwizzle       : 1;
112             uint32_t bReserved                  : 15;
113         } fields;
114 
115         uint32_t value;
116     } SeqFlags;
117 
118     uint32_t     UserMaxFrameSize;
119     uint16_t     reserved2;
120     uint16_t     reserved3;
121     FRAME_RATE   FrameRate[CODECHAL_ENCODE_VP9_MAX_NUM_TEMPORAL_LAYERS];
122     uint8_t      NumTemporalLayersMinus1;
123     uint8_t      ICQQualityFactor;
124 
125     ENCODE_INPUT_COLORSPACE         InputColorSpace;
126     ENCODE_SCENARIO                 ScenarioInfo;
127     ENCODE_CONTENT                  ContentInfo;
128     ENCODE_FRAMESIZE_TOLERANCE      FrameSizeTolerance;
129 
130 } CODEC_VP9_ENCODE_SEQUENCE_PARAMS, *PCODEC_VP9_ENCODE_SEQUENCE_PARAMS;
131 
132 typedef struct _CODEC_VP9_ENCODE_PIC_PARAMS
133 {
134     uint16_t            SrcFrameHeightMinus1;
135     uint16_t            SrcFrameWidthMinus1;
136     uint16_t            DstFrameHeightMinus1;
137     uint16_t            DstFrameWidthMinus1;
138 
139     CODEC_PICTURE       CurrOriginalPic;
140     CODEC_PICTURE       CurrReconstructedPic;
141     CODEC_PICTURE       RefFrameList[8];
142 
143     union
144     {
145         struct
146         {
147             uint32_t    frame_type                      : 1;
148             uint32_t    show_frame                      : 1;
149             uint32_t    error_resilient_mode            : 1;
150             uint32_t    intra_only                      : 1;
151             uint32_t    allow_high_precision_mv         : 1;
152             uint32_t    mcomp_filter_type               : 3;
153             uint32_t    frame_parallel_decoding_mode    : 1;
154             uint32_t    segmentation_enabled            : 1;
155             uint32_t    segmentation_temporal_update    : 1;
156             uint32_t    segmentation_update_map         : 1;
157             uint32_t    reset_frame_context             : 2;
158             uint32_t    refresh_frame_context           : 1;
159             uint32_t    frame_context_idx               : 2;
160             uint32_t    LosslessFlag                    : 1;
161             uint32_t    comp_prediction_mode            : 2;
162             uint32_t    super_frame                     : 1;
163             uint32_t    seg_id_block_size               : 2;
164             uint32_t    seg_update_data                 : 1;
165             uint32_t    reserved                        : 8;
166         } fields;
167 
168         uint32_t value;
169     } PicFlags;
170 
171     union
172     {
173         struct
174         {
175             uint32_t    LastRefIdx                      : 3;
176             uint32_t    LastRefSignBias                 : 1;
177             uint32_t    GoldenRefIdx                    : 3;
178             uint32_t    GoldenRefSignBias               : 1;
179             uint32_t    AltRefIdx                       : 3;
180             uint32_t    AltRefSignBias                  : 1;
181 
182             uint32_t    ref_frame_ctrl_l0               : 3;
183             uint32_t    ref_frame_ctrl_l1               : 3;
184 
185             uint32_t    refresh_frame_flags             : 8;
186             uint32_t    reserved2                       : 6;
187         } fields;
188 
189         uint32_t value;
190     } RefFlags;
191 
192     uint8_t         LumaACQIndex;
193     char            LumaDCQIndexDelta;
194     char            ChromaACQIndexDelta;
195     char            ChromaDCQIndexDelta;
196 
197     uint8_t         filter_level;    // This is not to be set for VP9 VDEnc (G10+), this is removed from DDI, only here to support legacy KBL DP
198     uint8_t         sharpness_level; // This is not to be set for VP9 VDEnc (G10+), this is removed from DDI, only here to support legacy KBL DP
199 
200     char            LFRefDelta[4];   // This is not to be set for VP9 VDEnc (G10+), this is removed from DDI, only here to support legacy KBL DP
201     char            LFModeDelta[2];  // This is not to be set for VP9 VDEnc (G10+), this is removed from DDI, only here to support legacy KBL DP
202 
203     uint16_t        BitOffsetForLFRefDelta;
204     uint16_t        BitOffsetForLFModeDelta;
205     uint16_t        BitOffsetForLFLevel;
206     uint16_t        BitOffsetForQIndex;
207     uint16_t        BitOffsetForFirstPartitionSize;
208     uint16_t        BitOffsetForSegmentation;
209     uint16_t        BitSizeForSegmentation;
210 
211     uint8_t         log2_tile_rows;
212     uint8_t         log2_tile_columns;
213 
214     uint8_t         temporal_id;
215 
216     uint32_t        StatusReportFeedbackNumber;
217 
218     // Skip Frames
219     uint8_t         SkipFrameFlag;    // [0..2]
220     uint8_t         NumSkipFrames;
221     uint32_t        SizeSkipFrames;
222 } CODEC_VP9_ENCODE_PIC_PARAMS, *PCODEC_VP9_ENCODE_PIC_PARAMS;
223 #endif
224