Debian Codegraph @

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

raw
1 /*
2 * Copyright (c) 2016-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_hevc.h
24 //! \brief Defines encode HEVC types and macros shared by CodecHal, MHW, and DDI layer
25 //! \details Applies to HEVC encode only. Should not contain any DDI specific code.
26 //!
27 #ifndef __CODEC_DEF_ENCODE_HEVC_H__
28 #define __CODEC_DEF_ENCODE_HEVC_H__
29
30 #include "codec_def_common_hevc.h"
31 #include "codec_def_common_encode.h"
32
33 // HEVC
34 #define CODEC_MAX_NUM_REF_FRAME_HEVC 15
35 #define CODEC_NUM_REF_FRAME_HEVC_WP 3 // number of reference frames used for weighted prediction
36 #define CODEC_HEVC_MAX_QP 51
37 #define CODEC_HEVC_MIN_QP_LP 10
38 #define CODEC_HEVC_MIN_QP1 1
39 #define HEVC_NUM_MAX_TILE_ROW 22
40 #define HEVC_NUM_MAX_TILE_COLUMN 20
41 #define CODECHAL_HEVC_MAX_NUM_SLICES_LVL_6 600
42 #define CODECHAL_HEVC_MAX_NUM_SLICES_LVL_5 200
43 #define CODECHAL_MAX_CUR_NUM_REF_FRAME_HEVC 8
44 #define CODECHAL_NUM_INTERNAL_NV12_RT_HEVC 16
45 #define CODECHAL_ENCODE_HEVC_MAX_NUM_ROI 16
46 #define CODECHAL_HEVC_FRAME_HEADER_SIZE 8192
47 #define CODECHAL_HEVC_MAX_LCU_SIZE_G10 64
48 #define CODECHAL_ENCODE_RECYCLED_BUFFER_NUM 6
49 #define CODECHAL_ENCODE_HEVC_MIN_STREAM_BUFFER_ALIGNMENT 4096
50 #define CODECHAL_ENCODE_HEVC_MI_COPY_MEM_MEM_CMD_ALIGNMENT 4
51
52 #define CODECHAL_HEVC_BRC_MAX_QUALITY_LAYER 16
53 #define CODECHAL_HEVC_BRC_MAX_TEMPORAL_LAYER 3
54 #define CODECHAL_HEVC_MAX_BSTRUCTRUE_GOP_SIZE 16
55 #define CODECHAL_HEVC_MAX_BSTRUCTRUE_REF_NUM 8
56 #define CODECHAL_HEVC_NUM_MODE_MV_COSTS 171
57
58 #define CODECHAL_HEVC_VDENC_MIN_TILE_WIDTH_SIZE 256
59 #define CODECHAL_HEVC_VDENC_MIN_TILE_HEIGHT_SIZE 128
60 #define CODECHAL_HEVC_SAO_STRMOUT_SIZE_PERLCU 16
61 #define CODECHAL_HEVC_VDENC_STATS_SIZE 1216
62 #define HEVC_BRC_PAK_STATISTCS_SIZE 32
63
64 #define CODECHAL_VDENC_HEVC_BRC_HUC_STATUS_REENCODE_MASK (1<<31)
65 #define CODECHAL_VDENC_HEVC_BRC_HISTORY_BUF_SIZE 964
66
67 #define CODECHAL_HEVC_I_SLICE 2
68 #define CODECHAL_HEVC_P_SLICE 1
69 #define CODECHAL_HEVC_B_SLICE 0
70 #define CODECHAL_HEVC_NUM_SLICE_TYPES 3
71
72 // HEVC VDENC
73 #define ENCODE_HEVC_VDENC_NUM_MAX_SLICES 70
74 #define ENCODE_VDENC_HEVC_MAX_STREAMINROI_G10 3
75 #define ENCODE_VDENC_HEVC_MAX_ROI_NUMBER_G10 8
76 #define ENCODE_VDENC_HEVC_MAX_DIRTYRECT_G10 256
77 #define ENCODE_VDENC_HEVC_ROI_BLOCKSIZE_G10 2 // 0:8x8, 1:16x16, 2:32x32, 3:64x64
78 #define ENCODE_VDENC_HEVC_MIN_ROI_DELTA_QP_G10 -8
79 #define ENCODE_VDENC_HEVC_MAX_ROI_DELTA_QP_G10 7 // Max delta QP for VDEnc ROI
80 #define ENCODE_VDENC_HEVC_PADDING_DW_SIZE 8
81 #define CODECHAL_ENCODE_HEVC_MAX_NUM_DIRTYRECT 16
82
83 #define ENCODE_HEVC_MAX_16K_PIC_WIDTH 16384
84 #define ENCODE_HEVC_MAX_16K_PIC_HEIGHT 16384
85 #define CODECHAL_ENCODE_HEVC_NUM_MAX_VDENC_L0_REF_G10 3 // multiref, hevc vdenc
86 #define CODECHAL_ENCODE_HEVC_NUM_MAX_VDENC_L1_REF_G10 3 // multiref, hevc vdenc
87
88 // HEVC DP
89 #define ENCODE_DP_HEVC_NUM_MAX_VME_L0_REF_G9 3
90 #define ENCODE_DP_HEVC_NUM_MAX_VME_L1_REF_G9 1
91 #define ENCODE_DP_HEVC_MAX_NUM_ROI 16
92 #define ENCODE_DP_HEVC_ROI_BLOCK_SIZE 1 //From DDI, 0:8x8, 1:16x16, 2:32x32, 3:64x64
93 #define ENCODE_DP_HEVC_ROI_BLOCK_Width 16
94 #define ENCODE_DP_HEVC_ROI_BLOCK_HEIGHT 16
95
96 //!
97 //! \enum HEVC_BRC_FRAME_TYPE
98 //! \brief HEVC BRC frame type
99 //!
100 enum HEVC_BRC_FRAME_TYPE
101 {
102 HEVC_BRC_FRAME_TYPE_P_OR_LB = 0,
103 HEVC_BRC_FRAME_TYPE_B = 1,
104 HEVC_BRC_FRAME_TYPE_I = 2,
105 HEVC_BRC_FRAME_TYPE_B1 = 3,
106 HEVC_BRC_FRAME_TYPE_B2 = 4,
107 HEVC_BRC_FRAME_TYPE_INVALID
108 };
109
110 typedef enum
111 {
112 ENCODE_HEVC_BIT_DEPTH_8 = 0,
113 ENCODE_HEVC_BIT_DEPTH_10 = 1,
114 ENCODE_HEVC_BIT_DEPTH_12 = 2,
115 ENCODE_HEVC_BIT_DEPTH_16 = 3,
116 } ENCODE_HEVC_BIT_DEPTH;
117
118 //!
119 //! \enum HEVC_NAL_UNIT_TYPE
120 //! \brief HEVC NAL unit type
121 //!
122 typedef enum
123 {
124 HEVC_NAL_UT_TRAIL_N = 0x00, //!< Coded slice segment of a non-TSA, non-STSA trailing picture - slice_segment_layer_rbsp, VLC
125 HEVC_NAL_UT_TRAIL_R = 0x01, //!< Coded slice segment of a non-TSA, non-STSA trailing picture - slice_segment_layer_rbsp, VLC
126 HEVC_NAL_UT_TSA_N = 0x02, //!< Coded slice segment of a TSA picture - slice_segment_layer_rbsp, VLC
127 HEVC_NAL_UT_TSA_R = 0x03, //!< Coded slice segment of a TSA picture - slice_segment_layer_rbsp, VLC
128 HEVC_NAL_UT_STSA_N = 0x04, //!< Coded slice of an STSA picture - slice_layer_rbsp, VLC
129 HEVC_NAL_UT_STSA_R = 0x05, //!< Coded slice of an STSA picture - slice_layer_rbsp, VLC
130 HEVC_NAL_UT_RADL_N = 0x06, //!< Coded slice of an RADL picture - slice_layer_rbsp, VLC
131 HEVC_NAL_UT_RADL_R = 0x07, //!< Coded slice of an RADL picture - slice_layer_rbsp, VLC
132 HEVC_NAL_UT_RASL_N = 0x08, //!< Coded slice of an RASL picture - slice_layer_rbsp, VLC
133 HEVC_NAL_UT_RASL_R = 0x09, //!< Coded slice of an RASL picture - slice_layer_rbsp, VLC
134 /* 0x0a..0x0f - Reserved */
135 HEVC_NAL_UT_BLA_W_LP = 0x10, //!< Coded slice segment of an BLA picture - slice_segment_layer_rbsp, VLC
136 HEVC_NAL_UT_BLA_W_DLP = 0x11, //!< Coded slice segment of an BLA picture - slice_segment_layer_rbsp, VLC
137 HEVC_NAL_UT_BLA_N_LP = 0x12, //!< Coded slice segment of an BLA picture - slice_segment_layer_rbsp, VLC
138 HEVC_NAL_UT_IDR_W_DLP = 0x13, //!< Coded slice segment of an IDR picture - slice_segment_layer_rbsp, VLC
139 HEVC_NAL_UT_IDR_N_LP = 0x14, //!< Coded slice segment of an IDR picture - slice_segment_layer_rbsp, VLC
140 HEVC_NAL_UT_CRA = 0x15, //!< Coded slice segment of an CRA picture - slice_segment_layer_rbsp, VLC
141 HEVC_NAL_UT_RSV_IRAP_VCL23 = 0x17, //!< Reserved IRAP VCL NAL unit type
142 /* 0x16..0x1f - Reserved */
143 HEVC_NAL_UT_VPS = 0x20, //!< Video parameter set - video_parameter_set_rbsp, non-VLC
144 HEVC_NAL_UT_SPS = 0x21, //!< Sequence parameter set - seq_parameter_set_rbsp, non-VLC
145 HEVC_NAL_UT_PPS = 0x22, //!< Picture parameter set - pic_parameter_set_rbsp, non-VLC
146 HEVC_NAL_UT_AUD = 0x23, //!< Access unit delimiter - access_unit_delimiter_rbsp, non-VLC
147 HEVC_NAL_UT_EOS = 0x24, //!< End of sequence - end_of_seq_rbsp, non-VLC
148 HEVC_NAL_UT_EOB = 0x25, //!< End of bitsteam - end_of_bitsteam_rbsp, non-VLC
149 HEVC_NAL_UT_FD = 0x26, //!< Filler data - filler_data_rbsp, non-VLC
150 HEVC_NAL_UT_PREFIX_SEI = 0x27, //!< Supplemental enhancement information (SEI) - sei_rbsp, non_VLC
151 HEVC_NAL_UT_SUFFIX_SEI = 0x28, //!< Supplemental enhancement information (SEI) - sei_rbsp, non_VLC
152
153 //this should be the last element of this enum
154 //chagne this value if NAL unit type increased
155 HEVC_MAX_NAL_UNIT_TYPE = 0x3f,
156 } HEVC_NAL_UNIT_TYPE;
157
158 typedef struct _CODEC_FRAMERATE
159 {
160 uint32_t Numerator;
161 uint32_t Denominator;
162 }CODEC_FRAMERATE;
163
164 /*! \brief Provides the picture-level parameters of a compressed picture for HEVC decoding.
165 *
166 * The framework is expected to only send a sequence parameter compressed buffer for the first picture(first Execute() call) in a sequence, associated with a RAP(IDR, CRA, BLA) picture.
167 */
168 typedef struct _CODEC_HEVC_ENCODE_SEQUENCE_PARAMS
169 {
170 /*! \brief Plus 1 specifies the width of each encoded picture in units of minimum coding block size.
171 *
172 * The encoded picture width in units of luma samples equals (wFrameWidthInMinCbMinus1 + 1) * (1 << (log2_min_coding_block_size_minus3 + 3))
173 * Programming Note: HW requres surface allocation Y offset of chroma plain to be multiple of 32 pixels. And HEVC spec requires frame resolution to be multiple of minimal CU (could be 8 pixels) horizontally and vertically. Framework needs to pad accordingly. If source resolution is different from what is actually encoded (padding happens), cropping information should be provided in the SPS header accordingly.
174 */
175 uint16_t wFrameWidthInMinCbMinus1;
176 /*! \brief Plus 1 specifies the height of each encoded picture in units of minimum coding block size.
177 *
178 * The encoded picture height in units of luma samples equals (wFrameHeightInMinCbMinus1 + 1) * (1 << (log2_min_coding_block_size_minus3 + 3))
179 */
180 uint16_t wFrameHeightInMinCbMinus1;
181 uint8_t general_profile_idc; //!< Same as HEVC syntax element
182 /*! \brief Equal to syntax element general_level_idc / 3
183 *
184 * Value range of general_level_idc is 30 times [1, 2, 2.1, 3, 3.1, 4, 4.1, 5, 5.1, 5.2, 6, 6.1, 6.2].
185 * Programming Note: HW requres surface allocation Y offset of chroma plain to be multiple of 32 pixels. And HEVC spec requires frame resolution to be multiple of minimal CU (could be 8 pixels) horizontally and vertically. Framework needs to pad accordingly. If source resolution is different from what is actually encoded (padding happens), cropping information should be provided in the SPS header accordingly.
186 */
187 uint8_t Level;
188 uint8_t general_tier_flag; //!< Same as HEVC syntax element
189
190 uint16_t GopPicSize; //!< Distance between IRAP pictures.
191 /*! \brief Distance between anchor frames (I or P).
192 *
193 * Here, P may also means low delay B (GPB) frames.
194 * Programming Note: GopPicSize > GopRefDist should be ensured by application. It is required by BRC.
195 */
196 uint8_t GopRefDist;
197 uint8_t GopOptFlag : 2;
198 uint8_t : 6;
199
200 uint8_t TargetUsage;
201 /*! \brief Specifies rate control method.
202 *
203 * \n 1: CBR
204 * \n 2: VBR
205 * \n 3: CQP, if set, internal BRC, multi-pass and panic mode will be disabled
206 * \n 4: AVBR, if set, HRD compliance is not guaranteed. Buffering period SEI and picture timing SEI messages are not necessary for AVBR.
207 * \n 5: QVBR
208 * \n 6: Reserved
209 * \n 7: Reserved
210 * \n 8: VCM, defined for video converencing
211 * \n 9: ICQ
212 * \n Programming note: Define the minimum value as indicated above for AVBR accuracy & convergence, clamp any value that is less than the minimum value to the minimum value. Define the maximum value for AVBR accuracy as 100 (10%) and for AVBR convergence as 500, clamp any value that is greater than the maximum value to the maximum value. The maximum & minimum value may be adjusted when necessary. If bResetBRC is set to 1 for a non-I picture, driver shall not insert SPS into bitstream. Driver needs to calculate the maximum allowed frame size per profile/level for all RateControlMethod except CQP, and use the calculated value to program kernel for non AVBR modes; for AVBR mode, driver needs to clamp the upper bound of UserMaxFrameSize to the calculated value and use the clamped UserMaxFrameSize to program kernel. If IWD_VBR is set, driver programs it the same as VBR except not to enable panic mode.
213 */
214 uint8_t RateControlMethod;
215 uint32_t TargetBitRate; //!< Target bit rate Kbit per second
216 uint32_t MaxBitRate; //!< Maximum bit rate Kbit per second
217 /*! \brief Minimun bit rate Kbit per second.
218 *
219 * This is used in VBR control. For CBR control, this field is ignored.
220 */
221 uint32_t MinBitRate;
222 CODEC_FRAMERATE FrameRate; //!< Actual frame rate is the decimal derivative of FrameRate.Numerator / FrameRate.Denominator.
223 uint32_t InitVBVBufferFullnessInBit; //!< Initial VBV buffer fullness in bits.
224 /*! \brief VBV buffer size in bit unit.
225 *
226 * The HEVC spec defines a max coded picture buffer size for each level.
227 */
228 uint32_t VBVBufferSizeInBit;
229
230 union
231 {
232 struct
233 {
234 /*! \brief Indicate if a BRC reset is desired to set a new bit rate or frame rate.
235 *
236 * This setting is only valid if RateControlMethod is AVBR or VBR and the current picture is an I picture. If the frame resolution is changed, it should be set with IDR picture. It should not be set when RateControlMethod is CBR or CQP. The following table indicates which BRC parameters can be changed via a BRC reset.
237 *
238 * \n BRC Parameters Changes allowed via reset
239 * \n Profile & Level Yes
240 * \n UserMaxFrameSize Yes
241 * \n InitVBVBufferFullnessInBit No
242 * \n TargetBitRate Yes
243 * \n VBVBufferSizeInBit No
244 * \n MaxBitRate Yes
245 * \n FramesPer100Sec * No
246 * \n RateControlMethod No
247 * \n GopPicSize No
248 * \n GopRefDist No
249 * \n GopOptFlag Yes
250 * \n FrameWidth No
251 * \n FrameHeight No
252 * \n AVBRAccuracy No
253 * \n AVBRConvergence No
254 * \n Note: when resolution (FrameWidth and/or FrameHeight) changes, framework should re-start a new bit stream and not using BRC reset.
255 */
256 uint32_t bResetBRC : 1;
257 /*! \brief Indicates the global search options.
258 *
259 * It is only valid if EnhancedEncInput is reported as a capability.
260 * \n - 0 : Default - option internally selected based on target usage
261 * \n - 1 : Long - SHME enabled
262 * \n - 2 : Medium - HME only enabled, SHME disabled
263 * \n - 3 : Short - SHME/HME disabled
264 */
265 uint32_t GlobalSearch : 2;
266
267 /*! \brief Indicates the local search options.
268 *
269 * It is only valid if EnhancedEncInput is reported as a capability.
270 * \n - 0 : Default - option internally selected based on target usage
271 * \n - 1 : Tiny – MaxLenSP = 4, Reference Window = 24x24 SP = Spiral
272 * \n - 2 : Small – MaxLenSP = 9, Reference Window = 28x28 SP = Spiral
273 * \n - 3 : Square – MaxLenSP = 16, Reference Window = 32x32 SP = Spiral
274 * \n - 4 : Diamond – MaxLenSP = 16, Reference Window = 48x40 SP = Diamond
275 * \n - 5 : Large Diamond – MaxLenSP = 30, Reference Window = 48x40 SP = Diamond
276 * \n - 6 : Exhaustive – MaxLenSP = 57, Reference Window = 48x40 SP = Spiral
277 * \n - 7 : Heavy Horizontal – MaxLenSP = 57, Reference Window = 64x32 SP = Spiral
278 * \n - 8 : Heavy Vertical – MaxLenSP = 57, Reference Window = 32x64 SP = Spiral
279 */
280 uint32_t LocalSearch : 4;
281 /*! \brief Indicates the EarlySkip control.
282 *
283 * It is only valid if EnhancedEncInput is reported as a capability.
284 * \n - 0 : Default, decided internally
285 * \n - 1 : EarlySkip enabled
286 * \n - 2 : EarlySkip disabled
287 */
288 uint32_t EarlySkip : 2;
289 /*! \brief Indicates that MB BRC is enabled.
290 *
291 * It is only valid if MBBRCSupport is reported as a capability. Currently MB BRC can be applied to all bit rate control methods except CQP.
292 * \n - 0 : Default, decided internally based on target usage.
293 * \n - 1 : MB BRC enabled.
294 * \n - 2 : MB BRC disabled.
295 * \n - Other values are reserved.
296 */
297 uint32_t MBBRC : 4;
298 /*! \brief Indicates that Parallel BRC is enabled.
299 *
300 * It is only valid if ParallelBRC is reported as a capability.
301 * \n - 0 : no parallel BRC required.
302 * \n - 1 : request parallel BRC.
303 */
304 uint32_t ParallelBRC : 1;
305 /*! \brief Indicates that Dynamic Slice Size Control is enabled.
306 *
307 * It is only valid if SliceByteSizeControl is reported as a capability. When enabled, the slice information that app provides will be applied as "supper slice". It means that GPU may further split the slice region that slice control data specifies into finer slice segments based on slice size upper limit (MaxSliceSize). GPU will duplicate the slice header bit stream for each splitted slice segments while updating the necessary fields such as slice_segment_address.
308 */
309 uint32_t SliceSizeControl : 1;
310 /*! \brief Specifies input source format
311 *
312 * \n 0: YUV420
313 * \n 1: YUV422
314 * \n 2: YUV444
315 * \n 3: RGB
316 * \n Note1: Encoder cannot do up-sampling. For example, if source format is YUV422, the encoder can generates bit stream of 420 or 422 only. It cannot generate YUV444 format. But it may generates RGB format.
317 * Note2: For RGB, the actual input source format is also determined by flag DisplayFormatSwizzle (formats below is in MSB->LSB order).
318 * \n - If DisplayFromatSwizzle is 0, and 8b intut is specified the format is A8B8G8R8, if 10 bit is specified the format is A2B10G10R10
319 * \n - If DisplayFromatSwizzle is 0, and 8b intut is specified the format is A8R8G8B8, if 10 bit is specified the format is A2R10G10B10
320 */
321 uint32_t SourceFormat : 2;
322 /*! \brief Specifies input source bit depth.
323 *
324 * \n 0: 8b
325 * \n 1: 10b
326 * \n 2: 12b
327 * \n 3: 16b
328 * \n Note: Encoder cannot do up-sampling. For example, if source bit depth is 10b, the encoder can generates bit stream of 8b or 10b only, and that it cannot generate 12b format. It is subjected to the limit set by MaxEncodedBitDepth.
329 */
330 uint32_t SourceBitDepth : 2;
331 /*! \brief Enable QP Adjustment at CQP mode.
332 *
333 * \n - 0 : no QP adjustment.
334 * \n - 1 : enable QP adjustment.
335 * \n Note: Basically ENC may define fine-tune QP adjustment based on motion search result, which is similar as MBBRC for BRC mode. With BRC modes, this flag should be set to 0.
336 */
337 uint32_t QpAdjustment : 1;
338 /*! \brief Indicates ROI[] value is in delta QP.
339 *
340 * It is valid only when parameter NumROI is greater than 0 and either ROIDeltaQPSupport or ROIBRCPriorityLevelSupport equals to 1.
341 * \n - 0 : ROI[] value is in priority.
342 * \n - 1 : ROI[] value is in delta QP.
343 * \n Note: ROIValueInDeltaQP must be set to 1 for CQP. Currently only ROIValueInDeltaQP equal 1 is validated.
344 */
345 uint32_t ROIValueInDeltaQP : 1;
346 /*! \brief Indicates block level absolute QP value is provided.
347 *
348 * \n - 0 : block level absolute QP value is not provided.
349 * \n - 1 : block level absolute QP value is provided.
350 */
351 uint32_t BlockQPforNonRectROI : 1;
352 /*! \brief Enables tile based encoding.
353 *
354 * \n - 0 : tile based encoding disabled.
355 * \n - 1 : tile based encoding enabled.
356 */
357 uint32_t EnableTileBasedEncode : 1;
358 /*! \brief Indicates if BRC can use larger P/B frame size than UserMaxPBFrameSize
359 *
360 * \n - 0 : BRC can not use larger P/B frame size than UserMaxPBFrameSize.
361 * \n - 1 : BRC can use larger P/B frame size than UserMaxPBFrameSize.
362 */
363 uint32_t bAutoMaxPBFrameSizeForSceneChange : 1;
364 /*! \brief Enables streaming buffer in LLC
365 *
366 * \n - 0 : streaming buffer by LLC is disabled.
367 * \n - 1 : streaming buffer by LLC is enabled.
368 */
369 uint32_t EnableStreamingBufferLLC : 1;
370 /*! \brief Enables streaming buffer in DDR
371 *
372 * \n - 0 : streaming buffer by DDR is disabled.
373 * \n - 1 : streaming buffer by DDR is enabled.
374 */
375 uint32_t EnableStreamingBufferDDR : 1;
376
377 /*! \brief Low Delay Mode
378 *
379 * \n - 0 : Random Access B.
380 * \n - 1 : Low delay encoding with P or LDB.
381 */
382 uint32_t LowDelayMode : 1;
383
384 /*! \brief Disable HRD conformance
385 *
386 * \n - 0 : HRD conformance is enabled.
387 * \n - 1 : HRD conformance is disabled (aka no panic mode).
388 */
389 uint32_t DisableHRDConformance : 1;
390
391 /*! \brief Hierarchical Mini GOP
392 *
393 * \n - 0 : Flat GOP (No Hierarchical Mini GOP).
394 * \n - 1 : Hierarchical Mini GOP.
395 */
396 uint32_t HierarchicalFlag : 1;
397
398 /*! \brief Indicates if FastPass is enabled.
399 *
400 * \n - 0 : no FastPass.
401 * \n - 1 : enable FastPass if FastPassSupport in CAP is 1.
402 */
403 uint32_t EnableFastPass : 1;
404
405 /*! \brief Indicates if current encodin gis lookahead pass.
406 *
407 * \n - 0 : the current encoding is in the actual encoding pass, and one of the BRC modes (CBR, VBR, etc.) should be selected.
408 * \n - 1 : the current encoding is in the lookahead pass.
409 * \n Valid only when LookAheadAnalysisSupport in CAP is on and LookAheadDepth > 0.
410 */
411 uint32_t bLookAheadPhase : 1;
412
413 uint32_t ReservedBits : 1;
414 };
415 uint32_t SeqFlags;
416 };
417
418 /*! \brief Framework defined maximum frame size in bytes for I frames.
419 *
420 * Applicable for all RateControlMethod values except CQP; guarantees that the compressed frame size will be less than this value. If UserMaxPBFrameSize equals 0, UserMaxIFrameSize will be used for all frame types. Maximum allowed frame size per profile/level will be calculated in driver and be used when UserMaxIFrameSize and UserMaxPBFrameSize are both set to 0.
421 */
422 uint32_t UserMaxIFrameSize;
423 /*! \brief Framework defined maximum frame size in bytes for P & B frames.
424 *
425 * Applicable for all RateControlMethod values except CQP; guarantees that the compressed frame size will be less than this value. If UserMaxPBFrameSize equals 0, UserMaxIFrameSize will be used for all frame types. Maximum allowed frame size per profile/level will be calculated in driver and be used when UserMaxIFrameSize and UserMaxPBFrameSize are both set to 0.
426 */
427 uint32_t UserMaxPBFrameSize;
428 /*! \brief For Constant Rate Factor BRC method, it indicates the measure of quality.
429 *
430 * The range is from 1 – 51, with 1 being the best quality.
431 */
432 uint8_t ICQQualityFactor;
433
434 /*! \brief Specigy session that IPU and GPU communicate on.
435 *
436 * It is for streaming buffer.
437 */
438 uint8_t StreamBufferSessionID;
439
440 uint8_t maxAdaptiveMiniGopSize;
441
442 union
443 {
444 struct
445 {
446 uint8_t ClosedGop : 1; // [0..1]
447 uint8_t StrictGop : 1; // [0..1]
448 uint8_t AdaptiveGop : 1; // [0..1]
449 uint8_t ReservedBits : 5; // [0]
450 } fields;
451 uint8_t value;
452 } GopFlags;
453
454 /*! \brief Number of B frames per level in BGOP (between each two consecutive anchor frames).
455 *
456 * \n NumOfBInGop[0] – regular B, or no reference to other B frames.
457 * \n NumOfBInGop[1] – B1, reference to only I, P or regular B frames.
458 * \n NumOfBInGop[2] – B2, references include B1.
459 * \n Invalid when ParallelBRC is disabled (value 0).
460 */
461 uint32_t NumOfBInGop[3]; // depricated
462
463 union
464 {
465 struct
466 {
467 /*! \brief Same as syntax element.
468 *
469 * When the scaling_list_enable_flag is set to disable, the scaling matrix is still sent to the PAK, and with all entries programmed to the same value of 16.
470 */
471 uint32_t scaling_list_enable_flag : 1;
472 uint32_t sps_temporal_mvp_enable_flag : 1; //!< Same as HEVC syntax element
473 uint32_t strong_intra_smoothing_enable_flag : 1; //!< Same as HEVC syntax element
474 uint32_t amp_enabled_flag : 1; //!< Same as HEVC syntax element
475 /*! \brief Same as syntax element sample_adaptive_offset_enabled_flag.
476 *
477 * Programming notes: must be 0 on SKL
478 */
479 uint32_t SAO_enabled_flag : 1;
480 /*! \brief Same as syntax element.
481 *
482 * Programming note: must be 0 on SKL.
483 */
484 uint32_t pcm_enabled_flag : 1;
485 uint32_t pcm_loop_filter_disable_flag : 1; //!< Same as HEVC syntax element
486 uint32_t reserved : 1;
487 uint32_t chroma_format_idc : 2; //!< Same as HEVC syntax element
488 uint32_t separate_colour_plane_flag : 1; //!< Same as HEVC syntax element
489 uint32_t palette_mode_enabled_flag : 1;
490 uint32_t RGBEncodingEnable : 1;
491 uint32_t PrimaryChannelForRGBEncoding : 2;
492 uint32_t SecondaryChannelForRGBEncoding : 2;
493 uint32_t RGBInputStudioRange : 1;
494 uint32_t ConvertedYUVStudioRange : 1;
495 uint32_t : 13; // [0]
496 };
497 uint32_t EncodeTools;
498 };
499
500 /*! \brief Specifies the maximum size of a coding block
501 *
502 * Corresponds to HEVC spec variable Log2CtbSize - 3. The full value range is [0..3], inclusive.
503 * Programming note: On SKL, must be set at 2.
504 */
505 uint8_t log2_max_coding_block_size_minus3;
506 /*! \brief Specifies the minimum size of a coding block.
507 *
508 * Corresponds to HEVC spec variable Log2MinCbSize - 3. The full value range is [0..3], inclusive.
509 * Programming note: On SKL, must be set at 0.
510 */
511 uint8_t log2_min_coding_block_size_minus3;
512 /*! \brief Specifies the maximum size of a transform unit.
513 *
514 * Corresponds to HEVC spec variable Log2MaxTrafoSize - 2. The value range is [0..3], inclusive.
515 * Programming note: On SKL, must be set to 3 to indicate 32x32.
516 */
517 uint8_t log2_max_transform_block_size_minus2;
518 /*! \brief Specifies the minimum size of a transform unit.
519 *
520 * Corresponds to HEVC spec variable Log2MinTrafoSize - 2. The value range is [0..3], inclusive.
521 * Programming note: On SKL, must be set to 0 to indicate 4x4.
522 */
523 uint8_t log2_min_transform_block_size_minus2;
524 /*! \brief Same as HEVC syntax element.
525 *
526 * Programming note: On SKL, must be set to 2.
527 */
528 uint8_t max_transform_hierarchy_depth_intra;
529 /*! \brief Same as HEVC syntax element.
530 *
531 * Programming note: On SKL, must be set to 2.
532 */
533 uint8_t max_transform_hierarchy_depth_inter;
534 /*! \brief Specifies the minimum size of I_PCM coding blocks.
535 *
536 * Corresponds to HEVC spec variable Log2MinIpcmCbSizeY.
537 */
538 uint8_t log2_min_PCM_cb_size_minus3;
539 /*! \brief Specifies the maximum size of I_PCM coding blocks.
540 *
541 * Corresponds to HEVC spec variable Log2MaxIpcmCbSizeY.
542 */
543 uint8_t log2_max_PCM_cb_size_minus3;
544 uint8_t bit_depth_luma_minus8; //!< Same as HEVC syntax element
545 uint8_t bit_depth_chroma_minus8; //!< Same as HEVC syntax element
546 uint8_t pcm_sample_bit_depth_luma_minus1; //!< Same as HEVC syntax element
547 uint8_t pcm_sample_bit_depth_chroma_minus1; //!< Same as HEVC syntax element
548
549 uint8_t bVideoSurveillance;
550
551 /*! \brief This flag is used for compatibility between various DDIs.
552 *
553 * Do NOT proram a kernel or otherwise make decisions based on this value. Instead use the flag inside CODEC_HEVC_ENCODE_PICTURE_PARAMS.
554 */
555 uint8_t bScreenContent;
556
557 /*! \brief Indicates the uncompressed input color space
558 *
559 * Valid only when input is ARGB format.
560 */
561 ENCODE_INPUT_COLORSPACE InputColorSpace;
562
563 /*! \brief Provides a hint to encoder about the scenario for the encoding session.
564 *
565 * BRC algorithm may tune differently based on this info.
566 */
567 ENCODE_SCENARIO ScenarioInfo;
568
569 ENCODE_CONTENT contentInfo;
570
571 /*! \brief Indicates the tolerance the application has to variations in the frame size.
572 *
573 * It affects the BRC algorithm used, but may or may not have an effect based on the combination of other BRC parameters. Only valid when the driver reports support for FrameSizeToleranceSupport.
574 */
575 ENCODE_FRAMESIZE_TOLERANCE FrameSizeTolerance;
576
577
578 uint16_t SlidingWindowSize;
579 uint32_t MaxBitRatePerSlidingWindow;
580 uint32_t MinBitRatePerSlidingWindow;
581
582 /*! \brief Indicates number of frames to lookahead.
583 *
584 * Range is [0~127]. Default is 0 which means lookahead disabled. Valid only when LookaheadBRCSupport is 1. When not 0, application should send LOOKAHEADDATA to driver.
585 */
586 uint8_t LookaheadDepth;
587
588 /*! \brief Indicates minimal and maximal IDR distances used for adaptive GOP decision.
589 *
590 * Applicable for LookAhead phase only.
591 */
592 uint16_t MinAdaptiveGopPicSize;
593 uint16_t MaxAdaptiveGopPicSize;
594
595 uint32_t motion_vector_resolution_control_idc;
596 uint32_t intra_boundary_filtering_disabled_flag;
597 uint8_t palette_max_size;
598 uint8_t delta_palette_max_predictor_size;
599 uint8_t FullPassCodecType; // [0..4]
600 uint8_t FastPassRatio;
601 uint8_t FastPassDsType; // [0..1]
602 uint8_t long_term_ref_pics_present_flag;
603 } CODEC_HEVC_ENCODE_SEQUENCE_PARAMS, *PCODEC_HEVC_ENCODE_SEQUENCE_PARAMS;
604
605 /*! \brief Provides the picture-level parameters of a compressed picture for HEVC decoding.
606 */
607 typedef struct _CODEC_HEVC_ENCODE_PICTURE_PARAMS
608 {
609 /*! \brief Specifies the uncompressed source surface of the frame for the current picture to be encode.
610 *
611 * The PicFlags regarding reference usage are expected to be valid at this time.
612 */
613 CODEC_PICTURE CurrOriginalPic;
614 /*! \brief Specifies the uncompressed surface of the reconstructed frame for the current encoded picture.
615 *
616 * The PicFlags regarding reference usage are expected to be valid at this time.
617 * The recon surface may be of different format and different bit depth from that of source.
618 * The framework needs to specify it through chroma_format_idc and bit_depth_luma_minus8
619 * and bit_depth_chroma_minus8 in SPS data structure.
620 */
621 CODEC_PICTURE CurrReconstructedPic;
622 /*! \brief Specifies the collocated reference picture’s index into the RefFrameList[].
623 *
624 * Application should generate collocated_ref_idx from collocated_from_l0_flag value per slice. When the HEVC syntax element slice_temporal_mvp_enable_flag takes value 0, CollocatedRefPicIndex should take value 0xFF.
625 */
626 uint8_t CollocatedRefPicIndex;
627 /*! \brief Each entry of the list specifies the frame index of the reference pictures.
628 *
629 * The value of FrameIdx specifies the index of RefFrameList structure. And valid value range is [0..14, 0x7F]. Invalid entries are indicated by setting PicFlags to PICTURE_INVALID.
630 * RefFrameList[] should include all the reference pictures in DPB, which means either the picture is referred by current picture or future pictures, it should have a valid entry in it.
631 */
632 CODEC_PICTURE RefFrameList[CODEC_MAX_NUM_REF_FRAME_HEVC];
633 int32_t CurrPicOrderCnt; //!< Picture Order Count value of current picture.
634 /*! \brief Picture Order Count values of reference pictures corresponding to the entries of RefFrameList[].
635 *
636 * For invalid entries of RefFrameList[], its RefFramePOCList value can be ignored.
637 */
638 int32_t RefFramePOCList[CODEC_MAX_NUM_REF_FRAME_HEVC];
639
640 /*! \brief Specifies picture coding type.
641 *
642 * \n 1: I picture
643 * \n 2: P picture
644 * \n 3: B picture
645 * \n 4: B1 picutre
646 * \n 5: B2 picture
647 * \n For B1 and B2 explanation refer to NumOfBInGop[]
648 */
649 uint8_t CodingType;
650
651 /*! \brief Specifies picture coding type.
652 *
653 * Store pic coding type specified through DDI to retain pyramid level information. CodingType is updated to I/P/B when parsing slice-level parameters
654 */
655 uint8_t ppsCodingType;
656
657 uint8_t HierarchLevelPlus1;
658 uint16_t NumSlices;
659
660 union
661 {
662 struct
663 {
664 uint32_t tiles_enabled_flag : 1; //!< Same as HEVC syntax element
665 uint32_t entropy_coding_sync_enabled_flag : 1; //!< Same as HEVC syntax element
666 /*! \brief Same as HEVC syntax element.
667 *
668 * Programming note: On SKL, must be set to 0.
669 */
670 uint32_t sign_data_hiding_flag : 1;
671 /*! \brief Same as HEVC syntax element.
672 *
673 * Programming note: On SKL, must be set to 0.
674 */
675 uint32_t constrained_intra_pred_flag : 1;
676 /*! \brief Same as HEVC syntax element.
677 *
678 * Programming note: On SKL, must be set to 0.
679 */
680 uint32_t transform_skip_enabled_flag : 1;
681 uint32_t transquant_bypass_enabled_flag : 1; //!< Same as HEVC syntax element
682 uint32_t cu_qp_delta_enabled_flag : 1; //!< Same as HEVC syntax element
683 uint32_t weighted_pred_flag : 1; //!< Same as HEVC syntax element
684 uint32_t weighted_bipred_flag : 1; //!< Same as HEVC syntax element
685 uint32_t loop_filter_across_slices_flag : 1; //!< Same as HEVC syntax element of seq_loop_filter_across_slices_enabled_flag
686 uint32_t loop_filter_across_tiles_flag : 1; //!< Same as HEVC syntax element
687 /*! \brief A combination of HEVC syntax element of sps_scaling_list_data_present_flag and pps_scaling_list_data_present_flag.
688 *
689 * If the value is 1, application will send a quantization matrix (scaling list) buffer to DDI. Otherwise not. If scaling_list_enable_flag is 0. This flag should also be 0.
690 */
691 uint32_t scaling_list_data_present_flag : 1;
692 uint32_t dependent_slice_segments_enabled_flag : 1; //!< Same as HEVC syntax element
693 uint32_t bLastPicInSeq : 1;
694 uint32_t bLastPicInStream : 1;
695 uint32_t bUseRawPicForRef : 1;
696 uint32_t bEmulationByteInsertion : 1;
697 uint32_t BRCPrecision : 2;
698 /*! \brief Specifies that slice level reporting may be requested for this frame.
699 *
700 * If this flag is set, then slice level parameter reporting will be set up for this frame. Only valid if SliceLevelReportSupport is reported as a capability, else this flag is ignored.
701 */
702 uint32_t bEnableSliceLevelReport : 1;
703 /*! \brief Specifies whether intra refresh is enabled in colum/row, or disabled.
704 *
705 * It applies to P picture only (not valid with IBP) and is effective only when RollingIntraRefresh capability is set..
706 * \n - 0: disabled
707 * \n - 1: enabled in colum
708 * \n - 2: enabled in row
709 * \n Programming Note: When RollingIntraRefresh is used, there are some restrictions the application must obey.
710 * \n - No B frames.
711 * \n - No multiple references.
712 * \n Additionally the driver will disable Multiple Prediction (MultiPred). This is to simplify the kernel when ensuring inter serach doesn’t refer to illegal regions.
713 */
714 uint32_t bEnableRollingIntraRefresh : 2;
715 /*! \brief Same as HEVC syntax element
716 *
717 */
718 uint32_t no_output_of_prior_pics_flag : 1;
719 /*! \brief Requests GPU to determine weighted prediction factors.
720 *
721 * Is valid when either weighted_pred_flag or weighted_bipred_flag is turned on.
722 * In this case, the following parameters in slice control data structure shall be ignored: luma_log2_weight_denom, delta_chroma_log2_weight_denom, luma_offset[2][15], delta_luma_weight[2][15], chroma_offset[2][15][2], and delta_chroma_weight[2][15][2].
723 */
724 uint32_t bEnableGPUWeightedPrediction : 1;
725 /*! \brief Indicates that the allocated source buffer format is a swizzle format from display.
726 *
727 * Framework still allocates the buffer as a standard FOURCC format. The swizzled format will be reported as supported for the encoder configuration during capability reporting.
728 * \n Source/Raw Allocated Buffer Format, DisplayFormatSwizzle, Layout Format in Buffer
729 * \n - YUY2, 0, YUY2
730 * \n - YUY2, 1, 2YUY (Y0U0Y1V0)
731 * \n - AYUV, 0, AYUV
732 * \n - AYUV, 1, YUXV
733 */
734 uint32_t bDisplayFormatSwizzle : 1;
735 uint32_t deblocking_filter_override_enabled_flag : 1;
736 uint32_t pps_deblocking_filter_disabled_flag : 1;
737 uint32_t bEnableCTULevelReport : 1; // [0..1]
738 uint32_t bEnablePartialFrameUpdate : 1;
739 uint32_t bEnableSaliencyEncode : 1;
740 uint32_t reservedbits : 2;
741 };
742 uint32_t PicFlags;
743 };
744
745 char QpY; //!< QpY = pic_init_qp_minus26 + 26
746 uint8_t diff_cu_qp_delta_depth; //!< Same as HEVC syntax element
747 char pps_cb_qp_offset; //!< Same as HEVC syntax element
748 char pps_cr_qp_offset; //!< Same as HEVC syntax element
749 uint8_t num_tile_columns_minus1; //!< Same as HEVC syntax element
750 uint8_t num_tile_rows_minus1; //!< Same as HEVC syntax element
751 /*! \brief Same as HEVC syntax elements of column_width_minus1 + 1 in PPS of HEVC bitstreams.
752 *
753 * Driver expected to calculate the size of last column from frame resolution.
754 */
755 uint16_t tile_column_width[20];
756 /*! \brief Same as HEVC syntax elements of row_height_minus1 + 1 in PPS of HEVC bitstreams.
757 *
758 * Driver expected to calculate the size of last row from frame resolution.
759 */
760 uint16_t tile_row_height[22];
761 /*! \brief Same as HEVC syntax element.
762 *
763 * Programming note: On SKL, must be set to 0.
764 */
765 uint8_t log2_parallel_merge_level_minus2;
766 uint8_t num_ref_idx_l0_default_active_minus1; //!< Same as HEVC syntax element
767 uint8_t num_ref_idx_l1_default_active_minus1; //!< Same as HEVC syntax element
768 /*! \brief Specifies the CTU bit size limit based on spec requirement, or other value for special purpose.
769 *
770 * If the value is set 0, no bit size limit is checked.
771 */
772 uint32_t LcuMaxBitsizeAllowed;
773 /*! \brief Indicates the column or row location in block unit which is dictated by IntraRefreshBlockUnitSize from encoding capability.
774 *
775 * Ignored if bEnableRollingIntraRefresh is 0.
776 * If IntraInsertionSize is equal or larger than the LCU size (CTB), IntraInsertionLocation has to be aligned with LCU boundaries. Otherwise, IntraInsertionLocation could have an offset of integer multiple of the block unit size from LCU boundary and must make sure that IntraInsertionLocation + IntraInsertionSize -1 would reside in the same LCU region.
777 */
778 uint16_t IntraInsertionLocation;
779 /*! \brief Indicates the number of columns or rows in block unit which is dictated by IntraRefreshBlockUnitSize from encoding capability.
780 *
781 * Ignored if bEnableRollingIntraRefresh is 0.
782 * If IntraInsertionSize is equal or larger than the LCU size (CTB), it has to be multiple of LCU size. Otherwise, it can only be integer multiple of the block unit size (equal or smaller than LCU).
783 * When RateControlMode takes VCM mode. IntraInsertionSize defines the number of LCUs to be turn into Intra LCUs when bEnableRollingIntraRefresh is 1.
784 */
785 uint16_t IntraInsertionSize;
786 /*! \brief Indicates the Qp difference for inserted intra columns or rows.
787 *
788 * Framework can use this to adjust intra Qp based on bitrate & max frame size. It is ignored if bEnableRollingIntraRefresh is 0. Value range [-8..7]. Driver will clamp it if out of range.
789 */
790 char QpDeltaForInsertedIntra;
791 /*! \brief Arbitrary number set by the host decoder to use as a tag in the status report feedback data.
792 *
793 * The value should not equal 0, and should be different in each call to Execute.
794 */
795 uint32_t StatusReportFeedbackNumber;
796
797 /*! \brief Same as HEVC syntax element
798 *
799 */
800 uint8_t slice_pic_parameter_set_id;
801 /*! \brief Same as HEVC syntax element
802 *
803 */
804 uint8_t nal_unit_type;
805 bool bUsedAsRef;
806
807 /*! \brief Slice byte size upper limit.
808 *
809 * Used when SliceSizeControl is enabled. Currently only valid for VDENC.
810 */
811 uint32_t MaxSliceSizeInBytes;
812
813 /*! \brief Number of Region Of Interest (ROI).
814 *
815 * Value range is 0 to 16 inclusively. If no ROI to be set, this value shall be set to 0.
816 */
817 uint8_t NumROI;
818 /*! \brief Defines ROI settings.
819 *
820 * Value entries are ROI[0] up to ROI[NumROI – 1], inclusively, if NumROI > 0. And it can be ignored otherwise.
821 */
822 CODEC_ROI ROI[CODECHAL_ENCODE_HEVC_MAX_NUM_ROI];
823 /*! \brief Distinct delta QP values assigned to the ROI
824 *
825 * Value entries are distinct and within [MinDeltaQp..MaxDeltaQp].
826 */
827 int8_t ROIDistinctDeltaQp[CODECHAL_ENCODE_HEVC_MAX_NUM_ROI];
828 uint32_t RollingIntraReferenceLocation[16];
829 /*! \brief Dictates the value of delta QP for any ROI should be within [MinDeltaQp..MaxDeltaQp]
830 *
831 * Applies only to BRC case.
832 */
833 char MaxDeltaQp;
834 /*! \brief Dictates the value of delta QP for any ROI should be within [MinDeltaQp..MaxDeltaQp]
835 *
836 * Applies only to BRC case.
837 */
838 char MinDeltaQp;
839
840 union
841 {
842 struct
843 {
844 uint32_t EnableCustomRoudingIntra : 1;
845 uint32_t RoundingOffsetIntra : 7;
846 uint32_t EnableCustomRoudingInter : 1;
847 uint32_t RoundingOffsetInter : 7;
848 uint32_t reservedbits : 16;
849 } fields;
850
851 uint32_t value;
852 } CustomRoundingOffsetsParams;
853
854 /*! \brief Specifies skip frames.
855 *
856 * 0: Encode as normal, no skip.
857 * 1: One or more frames were skipped prior to the current frame, encode the current frame as normal. The driver will pass the NumSkipFrames and SizeSkipFrames to BRC for adjustment.
858 */
859 uint8_t SkipFrameFlag;
860 /*! \brief The number of frames skipped prior to the current frame.
861 *
862 * Valid when SkipFlag = 1.
863 */
864 uint8_t NumSkipFrames;
865 /*! \brief Differs in meaning based on value of SkipFrameFlag
866 *
867 * SkipFrameFlag = 1, the size of the skipped frames in bits.
868 * Note: Currently kernel only supports 16 bits for SizeSkipFrames.
869 */
870 uint32_t SizeSkipFrames;
871
872 uint8_t BRCMaxQp; //!< Specifies the maximum Qp to be used for BRC.
873 /*! \brief Specifies the minimum Qp to be used for BRC.
874 *
875 * BRCMaxQp and BRCMinQp may be set at a per frame type (I, P, B) granularity.
876 * BRCMaxQp and BRCMinQp should be set to zero if Qp control is not desired.
877 * If non-zero min/max QP is passed for I-frame, it will be used for I, P and B frames.
878 * If non-zero min/max QP is passed for P-frame also, then P and B frame will be updated to this. I-frame remains unchanged.
879 * If non-zero min/max QP is passed for B-frame also, then B-frame will be updated to this. I and P frame remains unchanged.
880 * If new QP values are passed in between the sequence, then it will be updated for that frame-type and any other frame types that are not explicitly set. Eg. if min/max QP for P-frame was passed separately, and an update for I-frame is received, then only I-frame values are updated. P and B will continue to use old values. But, if P-frame and B-frame were never explicitly set then updating I-frame will also update P and B.
881 * If the application wants to keep the current non-zero min/max QP settings, then min/max QP should be set to zero, so the driver will not change previously set values and continue to use them.
882 * Min QP is expected to be less than or equal to Max QP. Driver clamps max QP to [1, 51] and min QP to [1, max QP]. Zero QP is not used.
883 * Only single PAK pass is supported plus the IPCM pass. Panic mode is disabled. This is because min/maxQP requirement conflicts with the HRD compliancy requirement, so the HRD compliancy restriction is relaxed.
884 */
885 uint8_t BRCMinQp;
886
887 /*! \brief Indicates that an HMEOffset will be sent by the application in HMEOffset for each reference.
888 *
889 * This offset will be added to the co-located (0, 0) location before HME search is performed. This is only valid if HMEOffsetSupport is reported as supported as a capability, else this flag is ignored.
890 */
891 uint8_t bEnableHMEOffset;
892 /*! \brief Specifies the HME offsets.
893 *
894 * Curently the supported range is -128 to +127, programmed in 4x downscaled HME precision, not the original size. HMEOffset[i][j] where:
895 * \n - i – RefFrameList Index
896 * \n - j – 0 = x, 1 = y Coordinates
897 * \n So for example, HMEOffset[i] specifies the (x, y) offset corresponding to the ith entry in RefFrameList.
898 * Programming Note: The HME offset must be a multiple of 4x4 to align to the 4x4 HME block, so the driver must align the application supplied value.
899 */
900 int16_t HMEOffset[15][2];
901
902 /*! \brief Number of dirty rectangles.
903 *
904 * If no dirty rectangle to be set, this value shall be set to 0. Encoder does not have number of dirty rectangle limitation.
905 */
906 uint8_t NumDirtyRects;
907 /*! \brief Buffer containing an array of NumDirtyRects number of dirty rectangle elements
908 *
909 * It’s framework's responsibility to ensure that the content in non-dirty rectangle region is the same as previous frame.
910 */
911 PCODEC_ROI pDirtyRect;
912 /*! \brief Number of moving rectangles.
913 *
914 * If no moving rectangle to be set, this value shall be set to 0.
915 */
916 uint8_t NumMoveRects;
917 //MOVE_RECT *pMoveRect; \\!< Buffer containing an array of NumMoveRects number of moving rectangle elements.
918
919 /*! \brief Provides a hint to encoder about the content for the encoding session.
920 *
921 * Hint is of the format CODEC_CONTENT.
922 */
923 uint32_t bScreenContent;
924
925 uint16_t LcuMaxBitsizeAllowedHigh16b;
926 uint32_t TargetFrameSize;
927
928 /*! \brief Picture parameter, Same as syntax element.
929 *
930 */
931 uint32_t pps_curr_pic_ref_enabled_flag;
932 uint32_t residual_adaptive_colour_transform_enabled_flag;
933 uint32_t pps_slice_act_qp_offsets_present_flag;
934 uint8_t PredictorPaletteSize;
935 uint16_t PredictorPaletteEntries[3][128];
936 char pps_act_y_qp_offset_plus5;
937 char pps_act_cb_qp_offset_plus5;
938 char pps_act_cr_qp_offset_plus3;
939
940 /*! \brief Source down scaling ratio for look ahead pass.
941 *
942 * when bLookAheadPhase == 1, this parameter indicates the source down scaling ratio for look ahead pass. Otherwise, the parameter should be ignored.
943 * (X16Minus1_X + 1) is the numerator of the horizontal downscaling ratio over 16.
944 * (X16Minus1_Y + 1) is the numerator of the vertical downscaling ratio over 16.
945 */
946 union
947 {
948 struct
949 {
950 uint8_t X16Minus1_X : 4;
951 uint8_t X16Minus1_Y : 4;
952 } fields;
953 uint8_t value;
954 } DownScaleRatio;
955
956 uint8_t QpModulationStrength;
957
958 /*! \brief StatusReportEnable
959 *
960 * Request features to be enabled at status report.
961 * FrameStats: FRAME_STATS_INFO enabled in ENCODE_QUERY_STATUS_PARAMS.
962 * BlockStats: BLOCK_STATS_INFO enabled in ENCODE_QUERY_STATUS_PARAMS.
963 */
964 union
965 {
966 struct
967 {
968 uint16_t FrameStats : 1;
969 uint16_t BlockStats : 1;
970 uint16_t reserved : 14;
971 } fields;
972 uint16_t value;
973 } StatusReportEnable;
974
975 /*! \brief quality information report enable flags.
976 */
977 union
978 {
979 struct
980 {
981 uint8_t enable_frame : 1;
982 uint8_t reserved : 7;
983 } fields;
984 uint8_t value;
985 } QualityInfoSupportFlags;
986
987 uint8_t AdaptiveTUEnabled;
988 } CODEC_HEVC_ENCODE_PICTURE_PARAMS, *PCODEC_HEVC_ENCODE_PICTURE_PARAMS;
989
990 /*! \brief Slice-level parameters of a compressed picture for HEVC encoding.
991 */
992 typedef struct _CODEC_HEVC_ENCODE_SLICE_PARAMS
993 {
994 /*! \brief Same as HEVC syntax element.
995 *
996 * For first slice in the picture, slice_segment_address shall be set to 0.
997 */
998 uint32_t slice_segment_address;
999 uint32_t NumLCUsInSlice; //!< Specifies the number of LCUs in the current slice.
1000 /*! \brief Specifies the surfaces of reference pictures.
1001 *
1002 * The value of FrameIdx specifies the index of RefFrameList structure, PicFlags has no meaning.
1003 * RefPicIdx[0][15] corresponds to reference list 0 and RefPicIdx[1][15] corresponds to reference list 1.
1004 * Each list may contain duplicated reference picture indexes. Same as RefFrameList[] from picture parameter data structure, the bPicEntry of invalid entries should take value 0xFF.
1005 * Must be same across all slices.
1006 */
1007 CODEC_PICTURE RefPicList[2][CODEC_MAX_NUM_REF_FRAME_HEVC];
1008 /*! \brief Same as HEVC syntax element.
1009 *
1010 * If num_ref_idx_active_override_flag == 0, host encoder shall set their values with num_ref_idx_l0_default_minus1.
1011 * Must be same across all slices.
1012 */
1013 uint8_t num_ref_idx_l0_active_minus1;
1014 /*! \brief Same as HEVC syntax element.
1015 *
1016 * If num_ref_idx_active_override_flag == 0, host encoder shall set their values with num_ref_idx_l1_default_minus1.
1017 * Must be same across all slices.
1018 */
1019 uint8_t num_ref_idx_l1_active_minus1;
1020
1021 union
1022 {
1023 struct
1024 {
1025 uint32_t bLastSliceOfPic : 1; //!< Specifies if current slice is the last slice of picture.
1026 uint32_t dependent_slice_segment_flag : 1; //!< Same as HEVC syntax element
1027 uint32_t slice_temporal_mvp_enable_flag : 1; //!< Same as HEVC syntax element
1028 /*! \brief Same as HEVC syntax element.
1029 *
1030 * HEVC has three slice types, B, P, and I slices, and their corresponding values are 0, 1, and 2.
1031 */
1032 uint32_t slice_type : 2;
1033 uint32_t slice_sao_luma_flag : 1; //!< Same as HEVC syntax element
1034 uint32_t slice_sao_chroma_flag : 1; //!< Same as HEVC syntax element
1035 /*! \brief Same as HEVC syntax element.
1036 *
1037 * Programming note: On SKL, must be 0.
1038 */
1039 uint32_t mvd_l1_zero_flag : 1;
1040 uint32_t cabac_init_flag : 1; //!< Same as HEVC syntax element
1041 /*! \brief Same as HEVC syntax element.
1042 *
1043 * Affects the decoding process accordingly if it appears in slice header of the bitstream. Otherwise, host encode should set it to be the value of pic_disable_deblocking_filter_flag in picture parameter set bit stream.
1044 */
1045 uint32_t slice_deblocking_filter_disable_flag : 1;
1046 uint32_t collocated_from_l0_flag : 1; //!< Same as HEVC syntax element
1047 uint32_t : 21;
1048 };
1049 uint32_t SliceFlags;
1050 };
1051
1052 /*! \brief Same as HEVC syntax element.
1053 *
1054 * Must be the same across all slices.
1055 */
1056 char slice_qp_delta;
1057 char slice_cb_qp_offset; //!< Same as HEVC syntax element, [-12..12]
1058 char slice_cr_qp_offset; //!< Same as HEVC syntax element, [-12..12]
1059 char beta_offset_div2; //!< Same as HEVC syntax element
1060 char tc_offset_div2; //!< Same as HEVC syntax element
1061 /*! \brief Same as HEVC syntax element.
1062 *
1063 * Specifies the base 2 logarithm of the denominator for all luma weighting factors. Value range: 0 to 7, inclusive.
1064 */
1065 uint8_t luma_log2_weight_denom;
1066 /*! \brief Same as HEVC syntax element.
1067 *
1068 * Framework is expected to ensure that the spec variable ChromaLog2WeightDenom, which is luma_log2_weight_denom plus delta_chroma_log2_weight_denom, specifies the base 2 logarithm of the denominator for all chroma weighting factors, with value range: 0 to 7, inclusive.
1069 */
1070 char delta_chroma_log2_weight_denom;
1071 /*! \brief Specifies the additive offsets applied to the luma prediction values for list 0 and list 1.
1072 *
1073 * Its values correspond to HEVC syntax elements luma_offset_l0, and luma_offset_l1. In luma_offset[i][j]:
1074 * \n - i equal to 0 is for reference picture list 0, equal to 1 is for reference picture list 1.
1075 * \n - j is for reference list index [0..14].
1076 * \n Value range: [-128..127], inclusive. When luma_weight_l0_flag or luma_weight_l1_flag take value 0, corresponding luma_offset should be set 0.
1077 */
1078 char luma_offset[2][CODEC_MAX_NUM_REF_FRAME_HEVC];
1079 /*! \brief Specifies the difference of the weighting factor applied to the luma prediction value for list 0/1 prediction using RefPicList.
1080 *
1081 * Corresponds to syntax element delta_luma_weight_l0, and delta_luma_weight_l1. In delta_luma_weight[i][j]:
1082 * \n - i equal to 0 is for reference picture list 0, equal to 1 is for reference picture list 1.
1083 * \n - j is for reference list index [0..14].
1084 * \n Value range: [-127..128], inclusive. When luma_weight_l0_flag or luma_weight_l1_flag take value 0, corresponding delta_luma_weight should be set 0.
1085 */
1086 char delta_luma_weight[2][CODEC_MAX_NUM_REF_FRAME_HEVC];
1087 /*! \brief Corresponds to HEVC spec variable ChromaOffsetL0 and ChromaOffsetL1.
1088 *
1089 * In chroma_offset[i][j][k]:
1090 * \n - i equal to 0 is for reference picture list 0, equal to 1 is for reference picture list 1.
1091 * \n - j is for reference list index [0..14].
1092 * \n - k equal to 0 is for Cb, and equal to 1 is for Cr.
1093 * \n Value range: [-128..127], inclusive. When chroma_weight_l0_flag or chroma_weight_l1_flag take value 0, corresponding chroma_offset should be set 0.
1094 */
1095 char chroma_offset[2][CODEC_MAX_NUM_REF_FRAME_HEVC][2];
1096 /*! \brief Specifies the difference of the weighting factor applied to the chroma prediction values for list 0/1 prediction using RefPicList.
1097 *
1098 * Corresponds to HEVC syntax elements delta_chroma_weight_l0 and delta_chroma_weight_l1. In delta_chroma_weight[i][j][k]:
1099 * \n - i equal to 0 is for reference picture list 0, equal to 1 is for reference picture list 1.
1100 * \n - j is for reference list index [0..14].
1101 * \n - k equal to 0 is for Cb, and equal to 1 is for Cr.
1102 * \n Value range: [-127..128], inclusive. When chroma_weight_l0_flag or chroma_weight_l1_flag take value 0, corresponding delta_chroma_weight should be set 0.
1103 */
1104 char delta_chroma_weight[2][CODEC_MAX_NUM_REF_FRAME_HEVC][2];
1105
1106 /*! \brief Specifies the maximum number of merging MVP candidates supported in the slice.
1107 *
1108 * Corresponds to HEVC spec variable MaxNumMergeCand.
1109 */
1110 uint8_t MaxNumMergeCand;
1111 /*! \brief ????
1112 *
1113 * ????
1114 */
1115 uint16_t slice_id;
1116 /*! \brief ????
1117 *
1118 * ????
1119 */
1120 uint16_t BitLengthSliceHeaderStartingPortion;
1121 /*! \brief ????
1122 *
1123 * ????
1124 */
1125 uint32_t SliceHeaderByteOffset;
1126 /*! \brief ????
1127 *
1128 * ????
1129 */
1130 uint32_t SliceQpDeltaBitOffset;
1131 /*! \brief Bit offset of syntax element pred_weight_table() in slice segment header.
1132 *
1133 * It aligns with the starting position of the current packed slice header. It is used when encoder prefers to override the weighted prediction parameters passed in from DDI.
1134 */
1135 uint32_t PredWeightTableBitOffset;
1136 /*! \brief Bit length of syntax element pred_weight_table() in slice segment header.
1137 *
1138 * It is used when encoder prefers to override the weighted prediction parameters passed in from DDI.
1139 */
1140 uint32_t PredWeightTableBitLength;
1141 /*! \brief Bit offset of syntax element slice_sao_luma_flag in slice segment header.
1142 *
1143 * It aligns with the starting position of the current packed slice header. BRC kernel may use it to update the slice_sao_luma_flag and slice_sao_chroma_flag values. The value is invalid if SAO_enabled_flag is false.
1144 */
1145 uint32_t SliceSAOFlagBitOffset;
1146 } CODEC_HEVC_ENCODE_SLICE_PARAMS, *PCODEC_HEVC_ENCODE_SLICE_PARAMS;
1147
1148 //!
1149 //! \struct CodecEncodeHevcFeiPicParams
1150 //! \brief Codec encode HEVC FEI pic params
1151 //!
1152 struct CodecEncodeHevcFeiPicParams
1153 {
1154 MOS_RESOURCE resCTBCtrl; // input CTB control buffer
1155 MOS_RESOURCE resCTBCmd; // ENC CTB cmd output buffer or PAK CTB cmd input buffer
1156 MOS_RESOURCE resCURecord; // ENC CU record output buffer or PAK CU record input buffer
1157 MOS_RESOURCE resMVPredictor; // input external MV predictor surface
1158 MOS_RESOURCE resCTBQp; // input QP per CTB surface
1159 MOS_RESOURCE resDistortion; // ENC or ENC_PAK Distortion output surface
1160
1161 uint32_t NumMVPredictorsL0;
1162 uint32_t NumMVPredictorsL1;
1163
1164 bool bCTBCmdCuRecordEnable;
1165 bool bDistortionEnable;
1166
1167 /** \brief control parameters */
1168 uint32_t SearchPath;
1169 uint32_t LenSP;
1170 uint32_t MultiPredL0;
1171 uint32_t MultiPredL1;
1172 uint32_t SubPelMode;
1173 uint32_t MVPredictorInput;
1174
1175 bool AdaptiveSearch;
1176 bool bPerBlockQP;
1177 bool bPerCTBInput;
1178 bool bColocatedCTBDistortion;
1179 bool bForceLCUSplit;
1180 bool bEnableCU64Check;
1181 bool bEnableCU64AmpCheck;
1182 bool bCU64SkipCheckOnly;
1183
1184 uint32_t RefWidth;
1185 uint32_t RefHeight;
1186 uint32_t SearchWindow;
1187 uint32_t MaxNumIMESearchCenter;
1188 uint32_t FastIntraMode;
1189 uint32_t NumConcurrentEncFramePartition;
1190
1191 /** \brief add for mutlple pass pak */
1192 uint32_t dwMaxFrameSize;
1193 uint32_t dwNumPasses; //number of QPs
1194 uint8_t *pDeltaQp; //list of detla QPs
1195 };
1196
1197 //!
1198 //! \struct CodecEncodeHevcSSHParams
1199 //! \brief Codec encode HEVC Slice Header params
1200 //!
1201 struct CodecEncodeHevcSliceHeaderParams
1202 {
1203 uint8_t log2_max_pic_order_cnt_lsb_minus4; //Hevc slice header packer use
1204 uint8_t num_long_term_pics;
1205 struct LongTermRef
1206 {
1207 uint8_t used_by_curr_pic_lt_flag : 1;
1208 uint8_t delta_poc_msb_present_flag : 1;
1209 uint32_t poc_lsb_lt;
1210 uint32_t delta_poc_msb_cycle_lt;
1211 } lt[8];
1212 uint8_t lists_modification_present_flag;
1213 uint8_t ref_pic_list_modification_flag_lx[2];
1214 uint8_t list_entry_lx[2][16];
1215 uint8_t num_negative_pics;
1216 uint8_t num_positive_pics;
1217 uint16_t delta_poc_minus1[2][16];
1218 bool used_by_curr_pic_flag[2][16];
1219 };
1220
1221 //!
1222 //! \struct HEVC_TILE_STATS_INFO
1223 //! \brief HEVC tiles states info
1224 //!
1225 struct HEVC_TILE_STATS_INFO
1226 {
1227 uint32_t uiTileSizeRecord = 0;
1228 uint32_t uiHevcPakStatistics = 0;
1229 uint32_t uiVdencStatistics = 0;
1230 uint32_t uiHevcSliceStreamout = 0;
1231 };
1232 using PHEVC_TILE_STATS_INFO = HEVC_TILE_STATS_INFO*;
1233
1234 typedef enum
1235 {
1236 HEVC_CHROMA_FORMAT_MONOCHROME = 0,
1237 HEVC_CHROMA_FORMAT_YUV420 = 1,
1238 HEVC_CHROMA_FORMAT_YUV422 = 2,
1239 HEVC_CHROMA_FORMAT_YUV444 = 3
1240 } HEVC_CHROMA_FORMAT_IDC;
1241
1242 inline uint32_t CodecHalHevcEncode_GetBitstreamBufferSize(
1243 uint32_t frameWidth,
1244 uint32_t frameHeight,
1245 uint8_t chromaFormat,
1246 bool is10Bits)
1247 {
1248 // 4:2:0 uncompression buffer size
1249
1250 frameHeight = (frameHeight * 3) / (is10Bits ? 1 : 2);
1251
1252 if (chromaFormat == HEVC_CHROMA_FORMAT_YUV422)
1253 {
1254 frameWidth = (frameWidth * 8) / 6; //4:2:2 v.s 4:2:0
1255 }
1256 else if (chromaFormat == HEVC_CHROMA_FORMAT_YUV444)
1257 {
1258 frameWidth = (frameWidth * 12) / 6; //4:4:4 v.s 4:2:0
1259 }
1260
1261 return frameWidth * frameHeight;
1262 }
1263
1264 #endif // __CODEC_DEF_ENCODE_HEVC_H__