2 * Copyright (c) 2007-2011 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 H.264 encoding API
29 * This file contains the \ref api_enc_h264 "H.264 encoding API".
40 * \defgroup api_enc_h264 H.264 encoding API
48 * Those flags flags are meant to signal when a picture marks the end
49 * of a sequence, a stream, or even both at once.
54 * \brief Marks the last picture in the sequence.
56 * i.e. the driver appends \c end_of_seq() NAL unit to the encoded frame.
58 #define H264_LAST_PICTURE_EOSEQ 0x01
60 * \brief Marks the last picture in the stream.
62 * i.e. the driver appends \c end_of_stream() NAL unit to the encoded frame.
64 #define H264_LAST_PICTURE_EOSTREAM 0x02
68 * \brief Sequence parameter for H.264 encoding in main & high profiles.
70 * This structure holds information for \c seq_parameter_set_data() as
71 * defined by the H.264 specification.
73 * If packed sequence headers mode is used, i.e. if the encoding
74 * pipeline was configured with the #VA_ENC_PACKED_HEADER_SEQUENCE
75 * flag, then the driver expects two more buffers to be provided to
76 * the same \c vaRenderPicture() as this buffer:
77 * - a #VAEncPackedHeaderParameterBuffer with type set to
78 * VAEncPackedHeaderType::VAEncPackedHeaderSequence ;
79 * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
82 * If \c seq_scaling_matrix_present_flag is set to \c 1, then a
83 * #VAIQMatrixBufferH264 buffer shall also be provided within the same
84 * \c vaRenderPicture() call as this sequence parameter buffer.
86 typedef struct _VAEncSequenceParameterBufferH264 {
87 /** \brief Same as the H.264 bitstream syntax element. */
88 unsigned char seq_parameter_set_id;
89 /** \brief XXX: implied by VA config. */
90 unsigned char profile_idc;
91 /** \brief Same as the H.264 bitstream syntax element. */
92 unsigned char level_idc;
93 /** \brief Period between I frames. */
94 unsigned int intra_period;
95 /** \brief Period between I/P frames. */
96 unsigned int ip_period;
98 * \brief Initial bitrate set for this sequence in CBR or VBR modes.
100 * This field represents the initial bitrate value for this
101 * sequence if CBR or VBR mode is used, i.e. if the encoder
102 * pipeline was created with a #VAConfigAttribRateControl
103 * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR.
105 * The bitrate can be modified later on through
106 * #VAEncMiscParameterRateControl buffers.
108 unsigned int bits_per_second;
109 /** \brief Same as the H.264 bitstream syntax element. */
110 unsigned int max_num_ref_frames;
111 /** \brief Picture width in macroblocks. */
112 unsigned short picture_width_in_mbs;
113 /** \brief Picture height in macroblocks. */
114 unsigned short picture_height_in_mbs;
118 /** \brief Same as the H.264 bitstream syntax element. */
119 unsigned int chroma_format_idc : 2;
120 /** \brief Same as the H.264 bitstream syntax element. */
121 unsigned int frame_mbs_only_flag : 1;
122 /** \brief Same as the H.264 bitstream syntax element. */
123 unsigned int mb_adaptive_frame_field_flag : 1;
124 /** \brief Same as the H.264 bitstream syntax element. */
125 unsigned int seq_scaling_matrix_present_flag : 1;
126 /** \brief Same as the H.264 bitstream syntax element. */
127 unsigned int direct_8x8_inference_flag : 1;
128 /** \brief Same as the H.264 bitstream syntax element. */
129 unsigned int log2_max_frame_num_minus4 : 4;
130 /** \brief Same as the H.264 bitstream syntax element. */
131 unsigned int pic_order_cnt_type : 2;
132 /** \brief Same as the H.264 bitstream syntax element. */
133 unsigned int log2_max_pic_order_cnt_lsb_minus4 : 4;
134 /** \brief Same as the H.264 bitstream syntax element. */
135 unsigned int delta_pic_order_always_zero_flag : 1;
140 /** \brief Same as the H.264 bitstream syntax element. */
141 unsigned char bit_depth_luma_minus8;
142 /** \brief Same as the H.264 bitstream syntax element. */
143 unsigned char bit_depth_chroma_minus8;
145 /** if pic_order_cnt_type == 1 */
147 /** \brief Same as the H.264 bitstream syntax element. */
148 unsigned char num_ref_frames_in_pic_order_cnt_cycle;
149 /** \brief Same as the H.264 bitstream syntax element. */
150 int offset_for_non_ref_pic;
151 /** \brief Same as the H.264 bitstream syntax element. */
152 int offset_for_top_to_bottom_field;
153 /** \brief Same as the H.264 bitstream syntax element. */
154 int offset_for_ref_frame[256];
157 /** @name Cropping (optional) */
159 /** \brief Same as the H.264 bitstream syntax element. */
160 unsigned char frame_cropping_flag;
161 /** \brief Same as the H.264 bitstream syntax element. */
162 unsigned int frame_crop_left_offset;
163 /** \brief Same as the H.264 bitstream syntax element. */
164 unsigned int frame_crop_right_offset;
165 /** \brief Same as the H.264 bitstream syntax element. */
166 unsigned int frame_crop_top_offset;
167 /** \brief Same as the H.264 bitstream syntax element. */
168 unsigned int frame_crop_bottom_offset;
171 /** @name VUI parameters (optional) */
173 /** \brief Same as the H.264 bitstream syntax element. */
174 unsigned char vui_parameters_present_flag;
177 /** \brief Same as the H.264 bitstream syntax element. */
178 unsigned int timing_info_present_flag : 1;
179 /** \brief Same as the H.264 bitstream syntax element. */
180 unsigned int bitstream_restriction_flag : 1;
181 /** \brief Range: 0 to 16, inclusive. */
182 unsigned int log2_max_mv_length_horizontal : 5;
183 /** \brief Range: 0 to 16, inclusive. */
184 unsigned int log2_max_mv_length_vertical : 5;
188 /** \brief Same as the H.264 bitstream syntax element. */
189 unsigned int num_units_in_tick;
190 /** \brief Same as the H.264 bitstream syntax element. */
191 unsigned int time_scale;
193 } VAEncSequenceParameterBufferH264;
196 * \brief Picture parameter for H.264 encoding in main & high profiles.
198 * This structure holds information for \c pic_parameter_set_rbsp() as
199 * defined by the H.264 specification.
201 * If packed picture headers mode is used, i.e. if the encoding
202 * pipeline was configured with the #VA_ENC_PACKED_HEADER_PICTURE
203 * flag, then the driver expects two more buffers to be provided to
204 * the same \c vaRenderPicture() as this buffer:
205 * - a #VAEncPackedHeaderParameterBuffer with type set to
206 * VAEncPackedHeaderType::VAEncPackedHeaderPicture ;
207 * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
210 * If \c pic_scaling_matrix_present_flag is set to \c 1, then a
211 * #VAIQMatrixBufferH264 buffer shall also be provided within the same
212 * \c vaRenderPicture() call as this picture parameter buffer.
214 typedef struct _VAEncPictureParameterBufferH264 {
215 /** \brief Information about the picture to be encoded. */
216 VAPictureH264 CurrPic;
217 /** \brief Decoded Picture Buffer (DPB).
218 * XXX: is this really used?
220 VAPictureH264 ReferenceFrames[16];
222 * \brief Output encoded bitstream.
224 * \ref coded_buf has type #VAEncCodedBufferType. It should be
225 * large enough to hold the compressed NAL slice and possibly SPS
228 VABufferID coded_buf;
230 /** \brief The picture parameter set referred to in the slice header. */
231 unsigned char pic_parameter_set_id;
232 /** \brief The active sequence parameter set. Range: 0 to 31, inclusive. */
233 unsigned char seq_parameter_set_id;
236 * \brief OR'd flags describing whether the picture is the last one or not.
238 * This fields holds 0 if the picture to be encoded is not the last
239 * one in the stream or sequence. Otherwise, it is a combination of
240 * \ref H264_LAST_PICTURE_EOSEQ or \ref H264_LAST_PICTURE_EOSTREAM.
242 unsigned char last_picture;
244 /** \brief The picture identifier.
245 * Range: 0 to \f$2^{log2\_max\_frame\_num\_minus4 + 4} - 1\f$, inclusive.
247 unsigned short frame_num; /* (0..65535) */
249 /** \brief \c pic_init_qp_minus26 + 26. */
250 unsigned char pic_init_qp;
251 /** \brief Maximum reference index for reference picture list 0.
252 * Range: 0 to 31, inclusive.
254 unsigned char num_ref_idx_l0_active_minus1;
255 /** \brief Maximum reference index for reference picture list 1.
256 * Range: 0 to 31, inclusive.
258 unsigned char num_ref_idx_l1_active_minus1;
260 /** \brief Range: -12 to 12, inclusive. */
261 signed char chroma_qp_index_offset;
262 /** \brief Range: -12 to 12, inclusive. */
263 signed char second_chroma_qp_index_offset;
267 /** \brief Is picture an IDR picture? */
268 unsigned int idr_pic_flag : 1;
269 /** \brief Is picture a reference picture? */
270 unsigned int reference_pic_flag : 2;
271 /** \brief Selects CAVLC (0) or CABAC (1) entropy coding mode. */
272 unsigned int entropy_coding_mode_flag : 1;
273 /** \brief Is weighted prediction applied to P slices? */
274 unsigned int weighted_pred_flag : 1;
275 /** \brief Range: 0 to 2, inclusive. */
276 unsigned int weighted_bipred_idc : 2;
277 /** \brief Same as the H.264 bitstream syntax element. */
278 unsigned int constrained_intra_pred_flag : 1;
279 /** \brief Same as the H.264 bitstream syntax element. */
280 unsigned int transform_8x8_mode_flag : 1;
281 /** \brief Same as the H.264 bitstream syntax element. */
282 unsigned int deblocking_filter_control_present_flag : 1;
283 /** \brief Same as the H.264 bitstream syntax element. */
284 unsigned int redundant_pic_cnt_present_flag : 1;
285 /** \brief Same as the H.264 bitstream syntax element. */
286 unsigned int pic_order_present_flag : 1;
287 /** \brief Same as the H.264 bitstream syntax element. */
288 unsigned int pic_scaling_matrix_present_flag : 1;
292 } VAEncPictureParameterBufferH264;
295 * \brief Slice parameter for H.264 encoding in main & high profiles.
297 * This structure holds information for \c
298 * slice_layer_without_partitioning_rbsp() as defined by the H.264
301 * If packed slice headers mode is used, i.e. if the encoding
302 * pipeline was configured with the #VA_ENC_PACKED_HEADER_SLICE
303 * flag, then the driver expects two more buffers to be provided to
304 * the same \c vaRenderPicture() as this buffer:
305 * - a #VAEncPackedHeaderParameterBuffer with type set to
306 * VAEncPackedHeaderType::VAEncPackedHeaderSlice ;
307 * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
310 * If per-macroblock encoder configuration is needed, \c macroblock_info
311 * references a buffer of type #VAEncMacroblockParameterBufferH264. This
312 * buffer is not passed to vaRenderPicture(). i.e. it is not destroyed
313 * by subsequent calls to vaRenderPicture() and then can be re-used
314 * without re-allocating the whole buffer.
316 typedef struct _VAEncSliceParameterBufferH264 {
317 /** \brief Starting MB address for this slice. */
318 unsigned int macroblock_address;
320 * \brief Per-MB encoder configuration buffer, or \c VA_INVALID_ID.
322 * If per-MB encoder configuration is needed, then \ref macroblock_info
323 * references a buffer of type #VAEncMacroblockParameterBufferH264
324 * (\c VAEncMacroblockParameterBufferType). Otherwise, buffer id
325 * is set to \c VA_INVALID_ID and per-MB configuration is derived
326 * from this slice parameter.
328 * The \c macroblock_info buffer must hold \ref num_macroblocks
331 VABufferID macroblock_info;
332 /** \brief Number of macroblocks in this slice. */
333 unsigned int num_macroblocks;
334 /** \brief Slice type.
335 * Range: 0..2, 5..7, i.e. no switching slices.
337 unsigned char slice_type;
338 /** \brief Same as the H.264 bitstream syntax element. */
339 unsigned char pic_parameter_set_id;
340 /** \brief Same as the H.264 bitstream syntax element. */
341 unsigned short idr_pic_id;
343 /** @name If pic_order_cnt_type == 0 */
345 /** \brief The picture order count modulo MaxPicOrderCntLsb. */
346 unsigned short pic_order_cnt_lsb;
347 /** \brief Valid if \c pic_order_present_flag and this is a bottom field. */
348 int delta_pic_order_cnt_bottom;
350 /** @name If pic_order_cnt_type == 1 && !delta_pic_order_always_zero_flag */
352 /** \brief [0]: top, [1]: bottom. */
353 int delta_pic_order_cnt[2];
356 /** @name If slice_type == B */
358 unsigned char direct_spatial_mv_pred_flag;
361 /** @name If slice_type == P */
363 /** \brief Specifies if
364 * \ref _VAEncPictureParameterBufferH264::num_ref_idx_l0_active_minus1 or
365 * \ref _VAEncPictureParameterBufferH264::num_ref_idx_l1_active_minus1 are
366 * overriden by the values for this slice.
368 unsigned char num_ref_idx_active_override_flag;
369 /** \brief Maximum reference index for reference picture list 0.
370 * Range: 0 to 31, inclusive.
372 unsigned char num_ref_idx_l0_active_minus1;
373 /** \brief Maximum reference index for reference picture list 1.
374 * Range: 0 to 31, inclusive.
376 unsigned char num_ref_idx_l1_active_minus1;
377 /** \brief XXX: is this really used? */
378 VAPictureH264 RefPicList0[32];
379 /** \brief XXX: is this really used? */
380 VAPictureH264 RefPicList1[32];
383 /** @name ref_pic_list_modification() */
385 /** \brief Same as the H.264 bitstream syntax element. */
386 unsigned char ref_pic_list_modification_flag_l0;
387 /** \brief Same as the H.264 bitstream syntax element. */
388 unsigned char ref_pic_list_modification_flag_l1;
389 /** \brief Same as the H.264 bitstream syntax element. */
390 unsigned char modification_of_pic_nums_idc_l0[32];
391 /** \brief Same as the H.264 bitstream syntax element. */
392 unsigned char modification_of_pic_nums_idc_l1[32];
393 /** \brief List 0 values for each \c modification_of_pic_nums_idc_l0. */
395 * - If \c modification_of_pic_nums_idc == 0 or 1:
396 * - \c modification_of_pic_nums_value is \c abs_diff_pic_num_minus1
397 * - If \c modification_of_pic_nums_idc == 2:
398 * - \c modification_of_pic_nums_value is \c long_term_pic_num
400 unsigned int modification_of_pic_nums_value_l0[32];
401 /** \brief Same as \c modification_of_pic_nums_value_l0 but for list 1. */
402 unsigned int modification_of_pic_nums_value_l1[32];
405 /** @name pred_weight_table() */
407 /** \brief Same as the H.264 bitstream syntax element. */
408 unsigned char luma_log2_weight_denom;
409 /** \brief Same as the H.264 bitstream syntax element. */
410 unsigned char chroma_log2_weight_denom;
411 /** \brief Same as the H.264 bitstream syntax element. */
412 unsigned char luma_weight_l0_flag;
413 /** \brief Same as the H.264 bitstream syntax element. */
414 signed short luma_weight_l0[32];
415 /** \brief Same as the H.264 bitstream syntax element. */
416 signed short luma_offset_l0[32];
417 /** \brief Same as the H.264 bitstream syntax element. */
418 unsigned char chroma_weight_l0_flag;
419 /** \brief Same as the H.264 bitstream syntax element. */
420 signed short chroma_weight_l0[32][2];
421 /** \brief Same as the H.264 bitstream syntax element. */
422 signed short chroma_offset_l0[32][2];
423 /** \brief Same as the H.264 bitstream syntax element. */
424 unsigned char luma_weight_l1_flag;
425 /** \brief Same as the H.264 bitstream syntax element. */
426 signed short luma_weight_l1[32];
427 /** \brief Same as the H.264 bitstream syntax element. */
428 signed short luma_offset_l1[32];
429 /** \brief Same as the H.264 bitstream syntax element. */
430 unsigned char chroma_weight_l1_flag;
431 /** \brief Same as the H.264 bitstream syntax element. */
432 signed short chroma_weight_l1[32][2];
433 /** \brief Same as the H.264 bitstream syntax element. */
434 signed short chroma_offset_l1[32][2];
437 /** @name dec_ref_pic_marking() */
439 /** \brief Same as the H.264 bitstream syntax element. */
440 unsigned char no_output_of_prior_pics_flag;
441 /** \brief Same as the H.264 bitstream syntax element. */
442 unsigned char long_term_reference_flag;
443 /** \brief Same as the H.264 bitstream syntax element. */
444 unsigned char adaptive_ref_pic_marking_mode_flag;
445 /** \brief Same as the \c memory_management_control_operation syntax element. */
446 unsigned char mmco[32];
448 * \brief Values for each \c memory_management_control_operation.
451 * - \c mmco_value[0] is \c difference_of_pic_nums_minus1
452 * - \c mmco_value[1] is not used
454 * - \c mmco_value[0] is \c long_term_pic_num
455 * - \c mmco_value[1] is not used
457 * - \c mmco_value[0] is \c difference_of_pic_nums_minus1
458 * - \c mmco_value[1] is \c long_term_frame_idx
460 * - \c mmco_value[0] is \c max_long_term_frame_idx_plus1
461 * - \c mmco_value[1] is not used
463 * - \c mmco_value[0] is \c long_term_frame_idx
464 * - \c mmco_value[1] is not used
466 unsigned int mmco_value[32][2];
469 /** \brief Range: 0 to 2, inclusive. */
470 unsigned char cabac_init_idc;
471 /** \brief Same as the H.264 bitstream syntax element. */
472 signed char slice_qp_delta;
473 /** @name If deblocking_filter_control_present_flag */
475 /** \brief Range: 0 to 2, inclusive. */
476 unsigned char disable_deblocking_filter_idc;
477 /** \brief Same as the H.264 bitstream syntax element. */
478 signed char slice_alpha_c0_offset_div2;
479 /** \brief Same as the H.264 bitstream syntax element. */
480 signed char slice_beta_offset_div2;
482 } VAEncSliceParameterBufferH264;
485 * @name Macroblock neighbour availability bits
487 * \anchor api_enc_h264_mb_pred_avail_bits
488 * Definitions for macroblock neighbour availability bits used in
489 * intra prediction mode (non MBAFF only).
493 /** \brief References macroblock in the top-left corner. */
494 #define VA_MB_PRED_AVAIL_TOP_LEFT (1 << 2)
495 /** \brief References macroblock above the current macroblock. */
496 #define VA_MB_PRED_AVAIL_TOP (1 << 4)
497 /** \brief References macroblock in the top-right corner. */
498 #define VA_MB_PRED_AVAIL_TOP_RIGHT (1 << 3)
499 /** \brief References macroblock on the left of the current macroblock. */
500 #define VA_MB_PRED_AVAIL_LEFT (1 << 6)
504 * \brief Macroblock parameter for H.264 encoding in main & high profiles.
506 * This structure holds per-macroblock information. The buffer must be
507 * allocated with as many elements (macroblocks) as necessary to fit
508 * the slice to be encoded. Besides, the per-macroblock records must
509 * be written in a strict raster order and with no gap. i.e. every
510 * macroblock, regardless of its type, shall have an entry.
512 typedef struct _VAEncMacroblockParameterBufferH264 {
514 * \brief Quantization parameter.
516 * Requested quantization parameter. Range: 0 to 51, inclusive.
517 * If \ref qp is set to 0xff, then the actual value is derived
518 * from the slice-level value: \c pic_init_qp + \c slice_qp_delta.
523 /** @name Data for intra macroblock */
528 * \brief Flag specified to override MB neighbour
529 * availability bits from VME stage.
531 * This flag specifies that macroblock neighbour
532 * availability bits from the VME stage are overriden
533 * by the \ref pred_avail_flags hereunder.
535 unsigned int pred_avail_override_flag : 1;
537 * \brief Bitwise representation of which macroblocks
538 * are available for intra prediction.
540 * If the slice is intra-coded, this field represents
541 * the macroblocks available for intra prediction.
542 * See \ref api_enc_h264_mb_pred_avail_bits
543 * "macroblock neighbour availability" bit definitions.
545 unsigned int pred_avail_flags : 8;
551 /** @name Data for inter macroblock */
560 } VAEncMacroblockParameterBufferH264;
568 #endif /* VA_ENC_H264_H */