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 Packed header types specific to H.264 encoding.
70 * Types of packed headers generally used for H.264 encoding. Each
71 * associated packed header data buffer shall contain the start code
72 * prefix 0x000001 followed by the complete NAL unit, thus also
73 * including the \c nal_unit_type.
77 * \brief Packed Supplemental Enhancement Information (SEI).
79 * The corresponding packed header data buffer shall contain the
80 * complete sei_rbsp() syntax element, thus including several
81 * sei_message() elements if necessary.
83 * Note: packed \c nal_unit_type shall be equal to 6.
85 VAEncPackedHeaderH264_SEI = (VAEncPackedHeaderMiscMask | 1),
86 } VAEncPackedHeaderTypeH264;
89 * \brief Sequence parameter for H.264 encoding in main & high profiles.
91 * This structure holds information for \c seq_parameter_set_data() as
92 * defined by the H.264 specification.
94 * If packed sequence headers mode is used, i.e. if the encoding
95 * pipeline was configured with the #VA_ENC_PACKED_HEADER_SEQUENCE
96 * flag, then the driver expects two more buffers to be provided to
97 * the same \c vaRenderPicture() as this buffer:
98 * - a #VAEncPackedHeaderParameterBuffer with type set to
99 * VAEncPackedHeaderType::VAEncPackedHeaderSequence ;
100 * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
103 * If \c seq_scaling_matrix_present_flag is set to \c 1, then a
104 * #VAIQMatrixBufferH264 buffer shall also be provided within the same
105 * \c vaRenderPicture() call as this sequence parameter buffer.
107 typedef struct _VAEncSequenceParameterBufferH264 {
108 /** \brief Same as the H.264 bitstream syntax element. */
109 unsigned char seq_parameter_set_id;
110 /** \brief Same as the H.264 bitstream syntax element. */
111 unsigned char level_idc;
112 /** \brief Period between I frames. */
113 unsigned int intra_period;
114 /** \brief Period between I/P frames. */
115 unsigned int ip_period;
117 * \brief Initial bitrate set for this sequence in CBR or VBR modes.
119 * This field represents the initial bitrate value for this
120 * sequence if CBR or VBR mode is used, i.e. if the encoder
121 * pipeline was created with a #VAConfigAttribRateControl
122 * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR.
124 * The bitrate can be modified later on through
125 * #VAEncMiscParameterRateControl buffers.
127 unsigned int bits_per_second;
128 /** \brief Same as the H.264 bitstream syntax element. */
129 unsigned int max_num_ref_frames;
130 /** \brief Picture width in macroblocks. */
131 unsigned short picture_width_in_mbs;
132 /** \brief Picture height in macroblocks. */
133 unsigned short picture_height_in_mbs;
137 /** \brief Same as the H.264 bitstream syntax element. */
138 unsigned int chroma_format_idc : 2;
139 /** \brief Same as the H.264 bitstream syntax element. */
140 unsigned int frame_mbs_only_flag : 1;
141 /** \brief Same as the H.264 bitstream syntax element. */
142 unsigned int mb_adaptive_frame_field_flag : 1;
143 /** \brief Same as the H.264 bitstream syntax element. */
144 unsigned int seq_scaling_matrix_present_flag : 1;
145 /** \brief Same as the H.264 bitstream syntax element. */
146 unsigned int direct_8x8_inference_flag : 1;
147 /** \brief Same as the H.264 bitstream syntax element. */
148 unsigned int log2_max_frame_num_minus4 : 4;
149 /** \brief Same as the H.264 bitstream syntax element. */
150 unsigned int pic_order_cnt_type : 2;
151 /** \brief Same as the H.264 bitstream syntax element. */
152 unsigned int log2_max_pic_order_cnt_lsb_minus4 : 4;
153 /** \brief Same as the H.264 bitstream syntax element. */
154 unsigned int delta_pic_order_always_zero_flag : 1;
159 /** \brief Same as the H.264 bitstream syntax element. */
160 unsigned char bit_depth_luma_minus8;
161 /** \brief Same as the H.264 bitstream syntax element. */
162 unsigned char bit_depth_chroma_minus8;
164 /** if pic_order_cnt_type == 1 */
166 /** \brief Same as the H.264 bitstream syntax element. */
167 unsigned char num_ref_frames_in_pic_order_cnt_cycle;
168 /** \brief Same as the H.264 bitstream syntax element. */
169 int offset_for_non_ref_pic;
170 /** \brief Same as the H.264 bitstream syntax element. */
171 int offset_for_top_to_bottom_field;
172 /** \brief Same as the H.264 bitstream syntax element. */
173 int offset_for_ref_frame[256];
176 /** @name Cropping (optional) */
178 /** \brief Same as the H.264 bitstream syntax element. */
179 unsigned char frame_cropping_flag;
180 /** \brief Same as the H.264 bitstream syntax element. */
181 unsigned int frame_crop_left_offset;
182 /** \brief Same as the H.264 bitstream syntax element. */
183 unsigned int frame_crop_right_offset;
184 /** \brief Same as the H.264 bitstream syntax element. */
185 unsigned int frame_crop_top_offset;
186 /** \brief Same as the H.264 bitstream syntax element. */
187 unsigned int frame_crop_bottom_offset;
190 /** @name VUI parameters (optional) */
192 /** \brief Same as the H.264 bitstream syntax element. */
193 unsigned char vui_parameters_present_flag;
196 /** \brief Same as the H.264 bitstream syntax element. */
197 unsigned int timing_info_present_flag : 1;
198 /** \brief Same as the H.264 bitstream syntax element. */
199 unsigned int bitstream_restriction_flag : 1;
200 /** \brief Range: 0 to 16, inclusive. */
201 unsigned int log2_max_mv_length_horizontal : 5;
202 /** \brief Range: 0 to 16, inclusive. */
203 unsigned int log2_max_mv_length_vertical : 5;
207 /** \brief Same as the H.264 bitstream syntax element. */
208 unsigned int num_units_in_tick;
209 /** \brief Same as the H.264 bitstream syntax element. */
210 unsigned int time_scale;
212 } VAEncSequenceParameterBufferH264;
215 * \brief Picture parameter for H.264 encoding in main & high profiles.
217 * This structure holds information for \c pic_parameter_set_rbsp() as
218 * defined by the H.264 specification.
220 * If packed picture headers mode is used, i.e. if the encoding
221 * pipeline was configured with the #VA_ENC_PACKED_HEADER_PICTURE
222 * flag, then the driver expects two more buffers to be provided to
223 * the same \c vaRenderPicture() as this buffer:
224 * - a #VAEncPackedHeaderParameterBuffer with type set to
225 * VAEncPackedHeaderType::VAEncPackedHeaderPicture ;
226 * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
229 * If \c pic_scaling_matrix_present_flag is set to \c 1, then a
230 * #VAIQMatrixBufferH264 buffer shall also be provided within the same
231 * \c vaRenderPicture() call as this picture parameter buffer.
233 typedef struct _VAEncPictureParameterBufferH264 {
234 /** \brief Information about the picture to be encoded. */
235 VAPictureH264 CurrPic;
236 /** \brief Decoded Picture Buffer (DPB).
237 * XXX: is this really used?
239 VAPictureH264 ReferenceFrames[16];
241 * \brief Output encoded bitstream.
243 * \ref coded_buf has type #VAEncCodedBufferType. It should be
244 * large enough to hold the compressed NAL slice and possibly SPS
247 VABufferID coded_buf;
249 /** \brief The picture parameter set referred to in the slice header. */
250 unsigned char pic_parameter_set_id;
251 /** \brief The active sequence parameter set. Range: 0 to 31, inclusive. */
252 unsigned char seq_parameter_set_id;
255 * \brief OR'd flags describing whether the picture is the last one or not.
257 * This fields holds 0 if the picture to be encoded is not the last
258 * one in the stream or sequence. Otherwise, it is a combination of
259 * \ref H264_LAST_PICTURE_EOSEQ or \ref H264_LAST_PICTURE_EOSTREAM.
261 unsigned char last_picture;
263 /** \brief The picture identifier.
264 * Range: 0 to \f$2^{log2\_max\_frame\_num\_minus4 + 4} - 1\f$, inclusive.
266 unsigned short frame_num;
268 /** \brief \c pic_init_qp_minus26 + 26. */
269 unsigned char pic_init_qp;
270 /** \brief Maximum reference index for reference picture list 0.
271 * Range: 0 to 31, inclusive.
273 unsigned char num_ref_idx_l0_active_minus1;
274 /** \brief Maximum reference index for reference picture list 1.
275 * Range: 0 to 31, inclusive.
277 unsigned char num_ref_idx_l1_active_minus1;
279 /** \brief Range: -12 to 12, inclusive. */
280 signed char chroma_qp_index_offset;
281 /** \brief Range: -12 to 12, inclusive. */
282 signed char second_chroma_qp_index_offset;
286 /** \brief Is picture an IDR picture? */
287 unsigned int idr_pic_flag : 1;
288 /** \brief Is picture a reference picture? */
289 unsigned int reference_pic_flag : 2;
290 /** \brief Selects CAVLC (0) or CABAC (1) entropy coding mode. */
291 unsigned int entropy_coding_mode_flag : 1;
292 /** \brief Is weighted prediction applied to P slices? */
293 unsigned int weighted_pred_flag : 1;
294 /** \brief Range: 0 to 2, inclusive. */
295 unsigned int weighted_bipred_idc : 2;
296 /** \brief Same as the H.264 bitstream syntax element. */
297 unsigned int constrained_intra_pred_flag : 1;
298 /** \brief Same as the H.264 bitstream syntax element. */
299 unsigned int transform_8x8_mode_flag : 1;
300 /** \brief Same as the H.264 bitstream syntax element. */
301 unsigned int deblocking_filter_control_present_flag : 1;
302 /** \brief Same as the H.264 bitstream syntax element. */
303 unsigned int redundant_pic_cnt_present_flag : 1;
304 /** \brief Same as the H.264 bitstream syntax element. */
305 unsigned int pic_order_present_flag : 1;
306 /** \brief Same as the H.264 bitstream syntax element. */
307 unsigned int pic_scaling_matrix_present_flag : 1;
311 } VAEncPictureParameterBufferH264;
314 * \brief Slice parameter for H.264 encoding in main & high profiles.
316 * This structure holds information for \c
317 * slice_layer_without_partitioning_rbsp() as defined by the H.264
320 * If packed slice headers mode is used, i.e. if the encoding
321 * pipeline was configured with the #VA_ENC_PACKED_HEADER_SLICE
322 * flag, then the driver expects two more buffers to be provided to
323 * the same \c vaRenderPicture() as this buffer:
324 * - a #VAEncPackedHeaderParameterBuffer with type set to
325 * VAEncPackedHeaderType::VAEncPackedHeaderSlice ;
326 * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
329 * If per-macroblock encoder configuration is needed, \c macroblock_info
330 * references a buffer of type #VAEncMacroblockParameterBufferH264. This
331 * buffer is not passed to vaRenderPicture(). i.e. it is not destroyed
332 * by subsequent calls to vaRenderPicture() and then can be re-used
333 * without re-allocating the whole buffer.
335 typedef struct _VAEncSliceParameterBufferH264 {
336 /** \brief Starting MB address for this slice. */
337 unsigned int macroblock_address;
339 * \brief Per-MB encoder configuration buffer, or \c VA_INVALID_ID.
341 * If per-MB encoder configuration is needed, then \ref macroblock_info
342 * references a buffer of type #VAEncMacroblockParameterBufferH264
343 * (\c VAEncMacroblockParameterBufferType). Otherwise, buffer id
344 * is set to \c VA_INVALID_ID and per-MB configuration is derived
345 * from this slice parameter.
347 * The \c macroblock_info buffer must hold \ref num_macroblocks
350 VABufferID macroblock_info;
351 /** \brief Number of macroblocks in this slice. */
352 unsigned int num_macroblocks;
353 /** \brief Slice type.
354 * Range: 0..2, 5..7, i.e. no switching slices.
356 unsigned char slice_type;
357 /** \brief Same as the H.264 bitstream syntax element. */
358 unsigned char pic_parameter_set_id;
359 /** \brief Same as the H.264 bitstream syntax element. */
360 unsigned short idr_pic_id;
362 /** @name If pic_order_cnt_type == 0 */
364 /** \brief The picture order count modulo MaxPicOrderCntLsb. */
365 unsigned short pic_order_cnt_lsb;
366 /** \brief Valid if \c pic_order_present_flag and this is a bottom field. */
367 int delta_pic_order_cnt_bottom;
369 /** @name If pic_order_cnt_type == 1 && !delta_pic_order_always_zero_flag */
371 /** \brief [0]: top, [1]: bottom. */
372 int delta_pic_order_cnt[2];
375 /** @name If slice_type == B */
377 unsigned char direct_spatial_mv_pred_flag;
380 /** @name If slice_type == P */
382 /** \brief Specifies if
383 * \ref _VAEncPictureParameterBufferH264::num_ref_idx_l0_active_minus1 or
384 * \ref _VAEncPictureParameterBufferH264::num_ref_idx_l1_active_minus1 are
385 * overriden by the values for this slice.
387 unsigned char num_ref_idx_active_override_flag;
388 /** \brief Maximum reference index for reference picture list 0.
389 * Range: 0 to 31, inclusive.
391 unsigned char num_ref_idx_l0_active_minus1;
392 /** \brief Maximum reference index for reference picture list 1.
393 * Range: 0 to 31, inclusive.
395 unsigned char num_ref_idx_l1_active_minus1;
396 /** \brief XXX: is this really used? */
397 VAPictureH264 RefPicList0[32];
398 /** \brief XXX: is this really used? */
399 VAPictureH264 RefPicList1[32];
402 /** @name ref_pic_list_modification() */
404 /** \brief Same as the H.264 bitstream syntax element. */
405 unsigned char ref_pic_list_modification_flag_l0;
406 /** \brief Same as the H.264 bitstream syntax element. */
407 unsigned char ref_pic_list_modification_flag_l1;
408 /** \brief Same as the H.264 bitstream syntax element. */
409 unsigned char modification_of_pic_nums_idc_l0[32];
410 /** \brief Same as the H.264 bitstream syntax element. */
411 unsigned char modification_of_pic_nums_idc_l1[32];
412 /** \brief List 0 values for each \c modification_of_pic_nums_idc_l0. */
414 * - If \c modification_of_pic_nums_idc == 0 or 1:
415 * - \c modification_of_pic_nums_value is \c abs_diff_pic_num_minus1
416 * - If \c modification_of_pic_nums_idc == 2:
417 * - \c modification_of_pic_nums_value is \c long_term_pic_num
419 unsigned int modification_of_pic_nums_value_l0[32];
420 /** \brief Same as \c modification_of_pic_nums_value_l0 but for list 1. */
421 unsigned int modification_of_pic_nums_value_l1[32];
424 /** @name pred_weight_table() */
426 /** \brief Same as the H.264 bitstream syntax element. */
427 unsigned char luma_log2_weight_denom;
428 /** \brief Same as the H.264 bitstream syntax element. */
429 unsigned char chroma_log2_weight_denom;
430 /** \brief Same as the H.264 bitstream syntax element. */
431 unsigned char luma_weight_l0_flag;
432 /** \brief Same as the H.264 bitstream syntax element. */
433 signed short luma_weight_l0[32];
434 /** \brief Same as the H.264 bitstream syntax element. */
435 signed short luma_offset_l0[32];
436 /** \brief Same as the H.264 bitstream syntax element. */
437 unsigned char chroma_weight_l0_flag;
438 /** \brief Same as the H.264 bitstream syntax element. */
439 signed short chroma_weight_l0[32][2];
440 /** \brief Same as the H.264 bitstream syntax element. */
441 signed short chroma_offset_l0[32][2];
442 /** \brief Same as the H.264 bitstream syntax element. */
443 unsigned char luma_weight_l1_flag;
444 /** \brief Same as the H.264 bitstream syntax element. */
445 signed short luma_weight_l1[32];
446 /** \brief Same as the H.264 bitstream syntax element. */
447 signed short luma_offset_l1[32];
448 /** \brief Same as the H.264 bitstream syntax element. */
449 unsigned char chroma_weight_l1_flag;
450 /** \brief Same as the H.264 bitstream syntax element. */
451 signed short chroma_weight_l1[32][2];
452 /** \brief Same as the H.264 bitstream syntax element. */
453 signed short chroma_offset_l1[32][2];
456 /** @name dec_ref_pic_marking() */
458 /** \brief Same as the H.264 bitstream syntax element. */
459 unsigned char no_output_of_prior_pics_flag;
460 /** \brief Same as the H.264 bitstream syntax element. */
461 unsigned char long_term_reference_flag;
462 /** \brief Same as the H.264 bitstream syntax element. */
463 unsigned char adaptive_ref_pic_marking_mode_flag;
464 /** \brief Same as the \c memory_management_control_operation syntax element. */
465 unsigned char mmco[32];
467 * \brief Values for each \c memory_management_control_operation.
470 * - \c mmco_value[0] is \c difference_of_pic_nums_minus1
471 * - \c mmco_value[1] is not used
473 * - \c mmco_value[0] is \c long_term_pic_num
474 * - \c mmco_value[1] is not used
476 * - \c mmco_value[0] is \c difference_of_pic_nums_minus1
477 * - \c mmco_value[1] is \c long_term_frame_idx
479 * - \c mmco_value[0] is \c max_long_term_frame_idx_plus1
480 * - \c mmco_value[1] is not used
482 * - \c mmco_value[0] is \c long_term_frame_idx
483 * - \c mmco_value[1] is not used
485 unsigned int mmco_value[32][2];
488 /** \brief Range: 0 to 2, inclusive. */
489 unsigned char cabac_init_idc;
490 /** \brief Same as the H.264 bitstream syntax element. */
491 signed char slice_qp_delta;
492 /** @name If deblocking_filter_control_present_flag */
494 /** \brief Range: 0 to 2, inclusive. */
495 unsigned char disable_deblocking_filter_idc;
496 /** \brief Same as the H.264 bitstream syntax element. */
497 signed char slice_alpha_c0_offset_div2;
498 /** \brief Same as the H.264 bitstream syntax element. */
499 signed char slice_beta_offset_div2;
501 } VAEncSliceParameterBufferH264;
504 * @name Macroblock neighbour availability bits
506 * \anchor api_enc_h264_mb_pred_avail_bits
507 * Definitions for macroblock neighbour availability bits used in
508 * intra prediction mode (non MBAFF only).
512 /** \brief References macroblock in the top-left corner. */
513 #define VA_MB_PRED_AVAIL_TOP_LEFT (1 << 2)
514 /** \brief References macroblock above the current macroblock. */
515 #define VA_MB_PRED_AVAIL_TOP (1 << 4)
516 /** \brief References macroblock in the top-right corner. */
517 #define VA_MB_PRED_AVAIL_TOP_RIGHT (1 << 3)
518 /** \brief References macroblock on the left of the current macroblock. */
519 #define VA_MB_PRED_AVAIL_LEFT (1 << 6)
523 * \brief Macroblock parameter for H.264 encoding in main & high profiles.
525 * This structure holds per-macroblock information. The buffer must be
526 * allocated with as many elements (macroblocks) as necessary to fit
527 * the slice to be encoded. Besides, the per-macroblock records must
528 * be written in a strict raster order and with no gap. i.e. every
529 * macroblock, regardless of its type, shall have an entry.
531 typedef struct _VAEncMacroblockParameterBufferH264 {
533 * \brief Quantization parameter.
535 * Requested quantization parameter. Range: 0 to 51, inclusive.
536 * If \ref qp is set to 0xff, then the actual value is derived
537 * from the slice-level value: \c pic_init_qp + \c slice_qp_delta.
542 /** @name Data for intra macroblock */
547 * \brief Flag specified to override MB neighbour
548 * availability bits from VME stage.
550 * This flag specifies that macroblock neighbour
551 * availability bits from the VME stage are overriden
552 * by the \ref pred_avail_flags hereunder.
554 unsigned int pred_avail_override_flag : 1;
556 * \brief Bitwise representation of which macroblocks
557 * are available for intra prediction.
559 * If the slice is intra-coded, this field represents
560 * the macroblocks available for intra prediction.
561 * See \ref api_enc_h264_mb_pred_avail_bits
562 * "macroblock neighbour availability" bit definitions.
564 unsigned int pred_avail_flags : 8;
570 /** @name Data for inter macroblock */
579 } VAEncMacroblockParameterBufferH264;
587 #endif /* VA_ENC_H264_H */