2 * Copyright (c) 2007-2017 Intel Corporation. All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * The above copyright notice and this permission notice (including the
13 * next paragraph) shall be included in all copies or substantial portions
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
19 * IN NO EVENT SHALL INTEL AND/OR ITS SUPPLIERS BE LIABLE FOR
20 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * \brief The FEI encoding H264 special API
41 * \defgroup api_fei_h264 H.264 FEI encoding API
46 /** \brief FEI frame level control buffer for H.264 */
47 typedef struct _VAEncMiscParameterFEIFrameControlH264
49 uint32_t function; /* one of the VAConfigAttribFEIFunctionType values */
50 /** \brief MB (16x16) control input buffer. It is valid only when (mb_input | mb_size_ctrl)
51 * is set to 1. The data in this buffer correspond to the input source. 16x16 MB is in raster scan order,
52 * each MB control data structure is defined by VAEncFEIMBControlH264.
53 * Buffer size shall not be less than the number of 16x16 blocks multiplied by
54 * sizeof(VAEncFEIMBControlH264).
55 * Note: if mb_qp is set, VAEncQPBufferH264 is expected.
58 /** \brief distortion output of MB ENC or ENC_PAK.
59 * Each 16x16 block has one distortion data with VAEncFEIDistortionH264 layout
60 * Buffer size shall not be less than the number of 16x16 blocks multiplied by
61 * sizeof(VAEncFEIDistortionH264).
63 VABufferID distortion;
64 /** \brief MVs data output of MB ENC.
65 * Each 16x16 block has one MVs data with layout VAMotionVector
66 * Buffer size shall not be less than the number of 16x16 blocks multiplied by
67 * sizeof(VAMotionVector) * 16.
70 /** \brief MBCode data output of MB ENC.
71 * Each 16x16 block has one MB Code data with layout VAEncFEIMBCodeH264
72 * Buffer size shall not be less than the number of 16x16 blocks multiplied by
73 * sizeof(VAEncFEIMBCodeH264).
75 VABufferID mb_code_data;
76 /** \brief QP input buffer with layout VAEncQPBufferH264. It is valid only when mb_qp is set to 1.
77 * The data in this buffer correspond to the input source.
78 * One QP per 16x16 block in raster scan order, each QP is a signed char (8-bit) value.
81 /** \brief MV predictor. It is valid only when mv_predictor_enable is set to 1.
82 * Each 16x16 block has one or more pair of motion vectors and the corresponding
83 * reference indexes as defined by VAEncFEIMVPredictorH264. 16x16 block is in raster scan order.
84 * Buffer size shall not be less than the number of 16x16 blocks multiplied by
85 * sizeof(VAEncFEIMVPredictorH264). */
86 VABufferID mv_predictor;
88 /** \brief number of MV predictors. It must not be greater than maximum supported MV predictor. */
89 uint32_t num_mv_predictors_l0 : 16;
90 uint32_t num_mv_predictors_l1 : 16;
92 /** \brief motion search method definition
93 * 0: default value, diamond search
97 uint32_t search_path : 8;
98 /** \brief maximum number of Search Units, valid range is [1, 63]
99 * 0 is treated as 1. reference search locations are grouped in a predefined pattern,
100 * and all locations within the same group must be either all are chosen or all are skipped.
101 * These predefined groups are called search unit (SU).*/
103 uint32_t reserved0 : 16;
104 /** \brief defines the bit-mask for disabling sub-partition
105 * The lower 4 bits are for the major partitions (sub-macroblock) and the higher 3 bits for minor partitions (with sub-partition for 4x(8x8) sub-macroblocks.
106 * xxxxxx1 : 16x16 sub-macroblock disabled
107 * xxxxx1x : 2x(16x8) sub-macroblock within 16x16 disabled
108 * xxxx1xx : 2x(8x16) sub-macroblock within 16x16 disabled
109 * xxx1xxx : 1x(8x8) sub-partition for 4x(8x8) within 16x16 disabled
110 * xx1xxxx : 2x(8x4) sub-partition for 4x(8x8) within 16x16 disabled
111 * x1xxxxx : 2x(4x8) sub-partition for 4x(8x8) within 16x16 disabled
112 * 1xxxxxx : 4x(4x4) sub-partition for 4x(8x8) within 16x16 disabled
114 * 0000000 : default value */
115 uint32_t sub_mb_part_mask : 7;
116 /** specifies which Luma Intra partition is enabled/disabled for intra mode decision.
117 * xxxx1: luma_intra_16x16 disabled
118 * xxx1x: luma_intra_8x8 disabled
119 * xx1xx: luma_intra_4x4 disabled
120 * xx111: intra prediction is disabled */
121 uint32_t intra_part_mask : 5;
122 /** when set to 1, neighbor MV will be used as predictor; when set to 0, no neighbor MV will be used as predictor.*/
123 uint32_t multi_pred_l0 : 1;
124 /** when set to 1, neighbor MV will be used as predictor; when set to 0, no neighbor MV will be used as predictor.*/
125 uint32_t multi_pred_l1 : 1;
126 /**defines the half/quarter pel modes. The mode is inclusive, ie., higher precision mode samples lower precision locations.
127 * 00b: integer mode searching
128 * 01b: half-pel mode searching
130 * 11b: quarter-pel mode searching */
131 uint32_t sub_pel_mode : 2;
132 /** specifies distortion measure adjustments used for the inter motion search SAD comparison.
134 * 10b: Haar transform adjusted*/
135 uint32_t inter_sad : 2;
136 /** specifies distortion measure adjustments used for the intra motion search SAD comparison.
138 * 10b: Haar transform adjusted*/
139 uint32_t intra_sad : 2;
140 /** specifies if the output distortion is the raw distortion or cost adjusted distortion.
141 * 0: Raw Distortion without Cost
142 * 1: Distortion with added Cost */
143 uint32_t distortion_type : 1;
144 /** when set to 1, enables the additional calls on Fraction & Bidirectional Refinement*/
145 uint32_t repartition_check_enable : 1;
146 /** defines whether adaptive searching is enabled for IME(Integer Motion Estimation).
149 uint32_t adaptive_search : 1;
150 /** enables using the motion vector as an extra predictor provided by the host. If it is set,
151 * host needs to provide a buffer with motion vectors and the associated reference index for
152 * each 16x16 block as defined . The host can call processing function to get motion vectors and use as predictor.
153 * 0: MV predictor disabled
154 * 1: MV predictor enabled */
155 uint32_t mv_predictor_enable : 1;
156 /** enables using the QP buffer to set the QP for each block*/
158 /** enable mb_ctrl buffer to handle MB*/
159 uint32_t mb_input : 1;
160 /** when this flag is set, mb_ctrl must be set too and a buffer with per MB input
161 * needs to be provided and MaxSizeInWord and */
162 uint32_t mb_size_ctrl : 1;
163 /** when this flag is set, extra distortion between the current MB and co-located MB is provided.
164 * Extra distortion output has performance impact, set it only when it is needed.*/
165 uint32_t colocated_mb_distortion : 1;
166 uint32_t reserved1 : 4;
168 /** \brief motion search window(ref_width * ref_height) */
169 uint32_t ref_width : 8;
170 uint32_t ref_height : 8;
171 /** \brief predefined motion search windows. If selected, len_sp, window(ref_width * ref_eight)
172 * and search_path setting are ignored.
173 * 0: not use predefined search window
174 * 1: Tiny, len_sp=4, 24x24 window and diamond search
175 * 2: Small, len_sp=9, 28x28 window and diamond search
176 * 3: Diamond, len_sp=16, 48x40 window and diamond search
177 * 4: Large Diamond, len_sp=32, 48x40 window and diamond search
178 * 5: Exhaustive, len_sp=48, 48x40 window and full search
179 * 6: Extend Diamond, len_sp=16, 64x40 window and diamond search
180 * 7: Extend Large Diamond, len_sp=32, 64x40 window and diamond search
181 * 8: Extend Exhaustive, len_sp=48, 64x40 window and full search
183 uint32_t search_window : 4;
184 uint32_t reserved2 : 12;
186 /** \brief max frame size control with multi passes QP setting */
187 uint32_t max_frame_size;
188 /** \brief number of passes, every pass has different QP */
190 /** \brief delta QP list for every pass */
192 uint32_t reserved3[VA_PADDING_LOW];
193 } VAEncMiscParameterFEIFrameControlH264;
195 /** \brief FEI MB level control data structure */
196 typedef struct _VAEncFEIMBControlH264
198 /** \brief when set, correposndent MB is coded as intra */
199 uint32_t force_to_intra : 1;
200 /** \brief when set, correposndent MB is coded as skip */
201 uint32_t force_to_skip : 1;
202 /** \brief specifies whether this macroblock should be coded as a non-skipped macroblock. */
203 uint32_t force_to_nonskip : 1;
204 uint32_t enable_direct_bias_adjustment : 1;
205 uint32_t enable_motion_bias_adjustment : 1;
206 uint32_t ext_mv_cost_scaling_factor : 3;
207 uint32_t reserved0 : 24;
213 uint32_t reserved3 : 16;
214 /** \brief when mb_size_ctrl is set, size here is used to budget accumulatively. Set to 0xFF if don't care. */
215 uint32_t target_size_in_word : 8;
216 /** \brief specifies the max size of each MB */
217 uint32_t max_size_in_word : 8;
218 } VAEncFEIMBControlH264;
221 /** \brief Application can use this definition as reference to allocate the buffer
222 * based on MaxNumPredictor returned from attribute VAConfigAttribFEIMVPredictors query.
224 typedef struct _VAEncFEIMVPredictorH264
226 /** \brief Reference index corresponding to the entry of RefPicList0 & RefPicList1 in VAEncSliceParameterBufferH264.
227 * Note that RefPicList0 & RefPicList1 needs to be the same for all slices.
228 * ref_idx_l0_x : index to RefPicList0; ref_idx_l1_x : index to RefPicList1; x : 0 - MaxNumPredictor.
231 uint8_t ref_idx_l0 : 4;
232 uint8_t ref_idx_l1 : 4;
233 } ref_idx[4]; /* index is predictor number */
235 /** \brief MV. MaxNumPredictor must be the returned value from attribute VAConfigAttribFEIMVPredictors query.
236 * Even application doesn't use the maximum predictors, the VAFEIMVPredictorH264 structure size
237 * has to be defined as maximum so each MB can be at a fixed location.
238 * Note that 0x8000 must be used for correspondent intra block.
240 VAMotionVector mv[4]; /* MaxNumPredictor is 4 */
241 } VAEncFEIMVPredictorH264;
243 /** \brief FEI output */
245 * Motion vector output is per 4x4 block. For each 4x4 block there is a pair of MVs
246 * for RefPicList0 and RefPicList1 and each MV is 4 bytes including horizontal and vertical directions.
247 * Depending on Subblock partition, for the shape that is not 4x4, the MV is replicated
248 * so each 4x4 block has a pair of MVs. The 16x16 block has 32 MVs (128 bytes).
249 * 0x8000 is used for correspondent intra block. The 16x16 block is in raster scan order,
250 * within the 16x16 block, each 4x4 block MV is ordered as below in memory.
251 * The buffer size shall be greater than or equal to the number of 16x16 blocks multiplied by 128 bytes.
252 * Note that, when separate ENC and PAK is enabled, the exact layout of this buffer is needed for PAK input.
253 * App can reuse this buffer, or copy to a different buffer as PAK input.
254 * Layout is defined as Generic motion vector data structure VAMotionVector
256 * -----------------------------------------
258 * -----------------------------------------
260 * -----------------------------------------
261 * | 9 | 10 | 13 | 14 |
262 * -----------------------------------------
263 * | 11 | 12 | 15 | 16 |
264 * -----------------------------------------
267 /** \brief VAEncFEIMBCodeH264 defines the data structure for VAEncFEIMBCodeBufferType per 16x16 MB block.
268 * it is output buffer of ENC and ENC_PAK modes, it's also input buffer of PAK mode.
269 * The 16x16 block is in raster scan order. Buffer size shall not be less than the number of 16x16 blocks
270 * multiplied by sizeof(VAEncFEIMBCodeH264). Note that, when separate ENC and PAK is enabled,
271 * the exact layout of this buffer is needed for PAK input. App can reuse this buffer,
272 * or copy to a different buffer as PAK input, reserved elements must not be modified when used as PAK input.
274 typedef struct _VAEncFEIMBCodeH264
277 uint32_t reserved0[3];
280 uint32_t inter_mb_mode : 2;
281 uint32_t mb_skip_flag : 1;
282 uint32_t reserved1 : 1;
283 uint32_t intra_mb_mode : 2;
284 uint32_t reserved2 : 1;
285 uint32_t field_mb_polarity_flag : 1;
286 uint32_t mb_type : 5;
287 uint32_t intra_mb_flag : 1;
288 uint32_t field_mb_flag : 1;
289 uint32_t transform8x8_flag : 1;
290 uint32_t reserved3 : 1;
291 uint32_t dc_block_coded_cr_flag : 1;
292 uint32_t dc_block_coded_cb_flag : 1;
293 uint32_t dc_block_coded_y_flag : 1;
294 uint32_t reserved4 : 12;
297 uint32_t horz_origin : 8;
298 uint32_t vert_origin : 8;
302 uint32_t cbp_cb : 16;
303 uint32_t cbp_cr : 16;
306 uint32_t qp_prime_y : 8;
307 uint32_t reserved5 : 17;
308 uint32_t mb_skip_conv_disable : 1;
309 uint32_t is_last_mb : 1;
310 uint32_t enable_coefficient_clamp : 1;
311 uint32_t direct8x8_pattern : 4;
319 uint32_t luma_intra_pred_modes0 : 16;
320 uint32_t luma_intra_pred_modes1 : 16;
322 uint32_t luma_intra_pred_modes2 : 16;
323 uint32_t luma_intra_pred_modes3 : 16;
325 uint32_t chroma_intra_pred_mode : 2;
326 uint32_t intra_pred_avail_flag : 5;
327 uint32_t intra_pred_avail_flagF : 1;
328 uint32_t reserved6 : 24;
334 uint32_t sub_mb_shapes : 8;
335 uint32_t sub_mb_pred_modes : 8;
336 uint32_t reserved7 : 16;
338 uint32_t ref_idx_l0_0 : 8;
339 uint32_t ref_idx_l0_1 : 8;
340 uint32_t ref_idx_l0_2 : 8;
341 uint32_t ref_idx_l0_3 : 8;
343 uint32_t ref_idx_l1_0 : 8;
344 uint32_t ref_idx_l1_1 : 8;
345 uint32_t ref_idx_l1_2 : 8;
346 uint32_t ref_idx_l1_3 : 8;
351 uint32_t reserved8 : 16;
352 uint32_t target_size_in_word : 8;
353 uint32_t max_size_in_word : 8;
356 uint32_t reserved9[4];
360 } VAEncFEIMBCodeH264; // 64 bytes
362 /** \brief VAEncFEIDistortionH264 defines the data structure for VAEncFEIDistortionBufferType per 16x16 MB block.
363 * It is output buffer of ENC and ENC_PAK modes, The 16x16 block is in raster scan order.
364 * Buffer size shall not be less than the number of 16x16 blocks multiple by sizeof(VAEncFEIDistortionH264).
366 typedef struct _VAEncFEIDistortionH264 {
367 /** \brief Inter-prediction-distortion associated with motion vector i (co-located with subblock_4x4_i).
368 * Its meaning is determined by sub-shape. It must be zero if the corresponding sub-shape is not chosen.
370 uint16_t inter_distortion[16];
371 uint32_t best_inter_distortion : 16;
372 uint32_t best_intra_distortion : 16;
373 uint32_t colocated_mb_distortion : 16;
374 uint32_t reserved0 : 16;
375 uint32_t reserved1[2];
376 } VAEncFEIDistortionH264; // 48 bytes
378 /** \brief Motion Vector and Statistics frame level controls.
379 * VAStatsStatisticsParameterBufferType for H264 16x16 block
381 typedef struct _VAStatsStatisticsParameterH264
383 VAStatsStatisticsParameter stats_params;
385 uint32_t frame_qp : 8;
386 /** \brief length of search path */
388 /** \brief motion search method definition
389 * 0: default value, diamond search
393 uint32_t search_path : 8;
394 uint32_t reserved0 : 8;
396 uint32_t sub_mb_part_mask : 7;
397 /** \brief sub pixel mode definition
398 * 00b: integer mode searching
399 * 01b: half-pel mode searching
401 * 11b: quarter-pel mode searching
403 uint32_t sub_pel_mode : 2;
404 /** \brief distortion measure adjustment for inter search SAD comparison
407 * 10b: Haar transform adjusted
410 uint32_t inter_sad : 2;
411 /** \brief distortion measure adjustment for intra search SAD comparison
414 * 10b: Haar transform adjusted
417 uint32_t intra_sad : 2;
418 uint32_t adaptive_search : 1;
419 /** \brief indicate if future or/and past MV in mv_predictor buffer is valid.
420 * 0: MV predictor disabled
421 * 1: MV predictor enabled for past reference
422 * 2: MV predictor enabled for future reference
423 * 3: MV predictor enabled for both past and future references
425 uint32_t mv_predictor_ctrl : 3;
427 /** \brief forward transform enable
429 * 1: enable, needs frame_qp or mb_qp input for transform
431 uint32_t ft_enable : 1;
432 /** \brief luma intra mode partition mask
433 * xxxx1: luma_intra_16x16 disabled
434 * xxx1x: luma_intra_8x8 disabled
435 * xx1xx: luma_intra_4x4 disabled
436 * xx111: intra prediction is disabled
438 uint32_t intra_part_mask : 5;
439 uint32_t reserved1 : 8;
441 /** \brief motion search window(ref_width * ref_height) */
442 uint32_t ref_width : 8;
443 uint32_t ref_height : 8;
444 /** \brief predefined motion search windows. If selected, len_sp, window(ref_width * ref_eight)
445 * and search_path setting are ignored.
446 * 0: not use predefined search window
447 * 1: Tiny, len_sp=4, 24x24 window and diamond search
448 * 2: Small, len_sp=9, 28x28 window and diamond search
449 * 3: Diamond, len_sp=16, 48x40 window and diamond search
450 * 4: Large Diamond, len_sp=32, 48x40 window and diamond search
451 * 5: Exhaustive, len_sp=48, 48x40 window and full search
452 * 6: Extend Diamond, len_sp=16, 64x40 window and diamond search
453 * 7: Extend Large Diamond, len_sp=32, 64x40 window and diamond search
454 * 8: Extend Exhaustive, len_sp=48, 64x40 window and full search
456 uint32_t search_window : 4;
457 uint32_t reserved2 : 12;
459 /** \brief MVOutput. When set to 1, MV output is NOT provided */
460 uint32_t disable_mv_output : 1;
461 /** \brief StatisticsOutput. When set to 1, Statistics output is NOT provided. */
462 uint32_t disable_statistics_output : 1;
463 /** \brief block 8x8 data enabling in statistics output */
464 uint32_t enable_8x8_statistics : 1;
465 uint32_t reserved3 : 29;
466 uint32_t reserved4[2];
467 } VAStatsStatisticsParameterH264;
469 /** \brief VAStatsStatisticsH264. H264 Statistics buffer layout for VAStatsStatisticsBufferType
470 * and VAStatsStatisticsBottomFieldBufferType(for interlaced only).
471 * Statistics output is per 16x16 block. Data structure per 16x16 block is defined below.
472 * The 16x16 block is in raster scan order. The buffer size shall be greater than or equal to
473 * the number of 16x16 blocks multiplied by sizeof(VAStatsStatisticsH264).
475 typedef struct _VAStatsStatisticsH264
477 /** \brief past reference */
478 uint32_t best_inter_distortion0 : 16;
479 uint32_t inter_mode0 : 16;
481 /** \brief future reference */
482 uint32_t best_inter_distortion1 : 16;
483 uint32_t inter_mode1 : 16;
485 uint32_t best_intra_distortion : 16;
486 uint32_t intra_mode : 16;
488 uint32_t num_non_zero_coef : 16;
489 uint32_t reserved0 : 16;
493 /** \brief DWORD 5 flat info **/
494 uint32_t mb_is_flat : 1;
495 uint32_t reserved1 : 31;
497 /** \brief DWORD 6 variance for block16x16**/
498 uint32_t variance_16x16;
499 /** \brief DWORD 7 ~ 10, variance for block8x8 **/
500 uint32_t variance_8x8[4];
502 /** \brief DWORD 11 pixel_average for block16x16 **/
503 uint32_t pixel_average_16x16;
504 /** \brief DWORD 12 ~ 15, pixel_average for block8x8 **/
505 uint32_t pixel_average_8x8[4];
506 } VAStatsStatisticsH264; // 64 bytes
513 #endif /* VA_FEI_H264_H */