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