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 IDR frames. */
115 unsigned int intra_idr_period;
116 /** \brief Period between I/P frames. */
117 unsigned int ip_period;
119 * \brief Initial bitrate set for this sequence in CBR or VBR modes.
121 * This field represents the initial bitrate value for this
122 * sequence if CBR or VBR mode is used, i.e. if the encoder
123 * pipeline was created with a #VAConfigAttribRateControl
124 * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR.
126 * The bitrate can be modified later on through
127 * #VAEncMiscParameterRateControl buffers.
129 unsigned int bits_per_second;
130 /** \brief Same as the H.264 bitstream syntax element. */
131 unsigned int max_num_ref_frames;
132 /** \brief Picture width in macroblocks. */
133 unsigned short picture_width_in_mbs;
134 /** \brief Picture height in macroblocks. */
135 unsigned short picture_height_in_mbs;
139 /** \brief Same as the H.264 bitstream syntax element. */
140 unsigned int chroma_format_idc : 2;
141 /** \brief Same as the H.264 bitstream syntax element. */
142 unsigned int frame_mbs_only_flag : 1;
143 /** \brief Same as the H.264 bitstream syntax element. */
144 unsigned int mb_adaptive_frame_field_flag : 1;
145 /** \brief Same as the H.264 bitstream syntax element. */
146 unsigned int seq_scaling_matrix_present_flag : 1;
147 /** \brief Same as the H.264 bitstream syntax element. */
148 unsigned int direct_8x8_inference_flag : 1;
149 /** \brief Same as the H.264 bitstream syntax element. */
150 unsigned int log2_max_frame_num_minus4 : 4;
151 /** \brief Same as the H.264 bitstream syntax element. */
152 unsigned int pic_order_cnt_type : 2;
153 /** \brief Same as the H.264 bitstream syntax element. */
154 unsigned int log2_max_pic_order_cnt_lsb_minus4 : 4;
155 /** \brief Same as the H.264 bitstream syntax element. */
156 unsigned int delta_pic_order_always_zero_flag : 1;
161 /** \brief Same as the H.264 bitstream syntax element. */
162 unsigned char bit_depth_luma_minus8;
163 /** \brief Same as the H.264 bitstream syntax element. */
164 unsigned char bit_depth_chroma_minus8;
166 /** if pic_order_cnt_type == 1 */
168 /** \brief Same as the H.264 bitstream syntax element. */
169 unsigned char num_ref_frames_in_pic_order_cnt_cycle;
170 /** \brief Same as the H.264 bitstream syntax element. */
171 int offset_for_non_ref_pic;
172 /** \brief Same as the H.264 bitstream syntax element. */
173 int offset_for_top_to_bottom_field;
174 /** \brief Same as the H.264 bitstream syntax element. */
175 int offset_for_ref_frame[256];
178 /** @name Cropping (optional) */
180 /** \brief Same as the H.264 bitstream syntax element. */
181 unsigned char frame_cropping_flag;
182 /** \brief Same as the H.264 bitstream syntax element. */
183 unsigned int frame_crop_left_offset;
184 /** \brief Same as the H.264 bitstream syntax element. */
185 unsigned int frame_crop_right_offset;
186 /** \brief Same as the H.264 bitstream syntax element. */
187 unsigned int frame_crop_top_offset;
188 /** \brief Same as the H.264 bitstream syntax element. */
189 unsigned int frame_crop_bottom_offset;
192 /** @name VUI parameters (optional) */
194 /** \brief Same as the H.264 bitstream syntax element. */
195 unsigned char vui_parameters_present_flag;
198 /** \brief Same as the H.264 bitstream syntax element. */
199 unsigned int timing_info_present_flag : 1;
200 /** \brief Same as the H.264 bitstream syntax element. */
201 unsigned int bitstream_restriction_flag : 1;
202 /** \brief Range: 0 to 16, inclusive. */
203 unsigned int log2_max_mv_length_horizontal : 5;
204 /** \brief Range: 0 to 16, inclusive. */
205 unsigned int log2_max_mv_length_vertical : 5;
209 /** \brief Same as the H.264 bitstream syntax element. */
210 unsigned int num_units_in_tick;
211 /** \brief Same as the H.264 bitstream syntax element. */
212 unsigned int time_scale;
214 } VAEncSequenceParameterBufferH264;
217 * \brief Picture parameter for H.264 encoding in main & high profiles.
219 * This structure holds information for \c pic_parameter_set_rbsp() as
220 * defined by the H.264 specification.
222 * If packed picture headers mode is used, i.e. if the encoding
223 * pipeline was configured with the #VA_ENC_PACKED_HEADER_PICTURE
224 * flag, then the driver expects two more buffers to be provided to
225 * the same \c vaRenderPicture() as this buffer:
226 * - a #VAEncPackedHeaderParameterBuffer with type set to
227 * VAEncPackedHeaderType::VAEncPackedHeaderPicture ;
228 * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
231 * If \c pic_scaling_matrix_present_flag is set to \c 1, then a
232 * #VAIQMatrixBufferH264 buffer shall also be provided within the same
233 * \c vaRenderPicture() call as this picture parameter buffer.
235 typedef struct _VAEncPictureParameterBufferH264 {
237 * \brief Information about the picture to be encoded.
239 * See #VAPictureH264 for further description of each field.
240 * Note that CurrPic.picture_id represents the reconstructed
241 * (decoded) picture. User provides a scratch VA surface ID here.
243 VAPictureH264 CurrPic;
245 * \brief Decoded Picture Buffer (DPB).
247 * This array represents the list of reconstructed (decoded)
248 * frames used as reference. It is important to keep track of
249 * reconstructed frames so that they can be used later on as
250 * reference for P or B-frames encoding.
252 VAPictureH264 ReferenceFrames[16];
254 * \brief Output encoded bitstream.
256 * \ref coded_buf has type #VAEncCodedBufferType. It should be
257 * large enough to hold the compressed NAL slice and possibly SPS
260 VABufferID coded_buf;
262 /** \brief The picture parameter set referred to in the slice header. */
263 unsigned char pic_parameter_set_id;
264 /** \brief The active sequence parameter set. Range: 0 to 31, inclusive. */
265 unsigned char seq_parameter_set_id;
268 * \brief OR'd flags describing whether the picture is the last one or not.
270 * This fields holds 0 if the picture to be encoded is not the last
271 * one in the stream or sequence. Otherwise, it is a combination of
272 * \ref H264_LAST_PICTURE_EOSEQ or \ref H264_LAST_PICTURE_EOSTREAM.
274 unsigned char last_picture;
276 /** \brief The picture identifier.
277 * Range: 0 to \f$2^{log2\_max\_frame\_num\_minus4 + 4} - 1\f$, inclusive.
279 unsigned short frame_num;
281 /** \brief \c pic_init_qp_minus26 + 26. */
282 unsigned char pic_init_qp;
283 /** \brief Maximum reference index for reference picture list 0.
284 * Range: 0 to 31, inclusive.
286 unsigned char num_ref_idx_l0_active_minus1;
287 /** \brief Maximum reference index for reference picture list 1.
288 * Range: 0 to 31, inclusive.
290 unsigned char num_ref_idx_l1_active_minus1;
292 /** \brief Range: -12 to 12, inclusive. */
293 signed char chroma_qp_index_offset;
294 /** \brief Range: -12 to 12, inclusive. */
295 signed char second_chroma_qp_index_offset;
299 /** \brief Is picture an IDR picture? */
300 unsigned int idr_pic_flag : 1;
301 /** \brief Is picture a reference picture? */
302 unsigned int reference_pic_flag : 2;
303 /** \brief Selects CAVLC (0) or CABAC (1) entropy coding mode. */
304 unsigned int entropy_coding_mode_flag : 1;
305 /** \brief Is weighted prediction applied to P slices? */
306 unsigned int weighted_pred_flag : 1;
307 /** \brief Range: 0 to 2, inclusive. */
308 unsigned int weighted_bipred_idc : 2;
309 /** \brief Same as the H.264 bitstream syntax element. */
310 unsigned int constrained_intra_pred_flag : 1;
311 /** \brief Same as the H.264 bitstream syntax element. */
312 unsigned int transform_8x8_mode_flag : 1;
313 /** \brief Same as the H.264 bitstream syntax element. */
314 unsigned int deblocking_filter_control_present_flag : 1;
315 /** \brief Same as the H.264 bitstream syntax element. */
316 unsigned int redundant_pic_cnt_present_flag : 1;
317 /** \brief Same as the H.264 bitstream syntax element. */
318 unsigned int pic_order_present_flag : 1;
319 /** \brief Same as the H.264 bitstream syntax element. */
320 unsigned int pic_scaling_matrix_present_flag : 1;
324 } VAEncPictureParameterBufferH264;
327 * \brief Slice parameter for H.264 encoding in main & high profiles.
329 * This structure holds information for \c
330 * slice_layer_without_partitioning_rbsp() as defined by the H.264
333 * If packed slice headers mode is used, i.e. if the encoding
334 * pipeline was configured with the #VA_ENC_PACKED_HEADER_SLICE
335 * flag, then the driver expects two more buffers to be provided to
336 * the same \c vaRenderPicture() as this buffer:
337 * - a #VAEncPackedHeaderParameterBuffer with type set to
338 * VAEncPackedHeaderType::VAEncPackedHeaderSlice ;
339 * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
342 * If per-macroblock encoder configuration is needed, \c macroblock_info
343 * references a buffer of type #VAEncMacroblockParameterBufferH264. This
344 * buffer is not passed to vaRenderPicture(). i.e. it is not destroyed
345 * by subsequent calls to vaRenderPicture() and then can be re-used
346 * without re-allocating the whole buffer.
348 typedef struct _VAEncSliceParameterBufferH264 {
349 /** \brief Starting MB address for this slice. */
350 unsigned int macroblock_address;
352 * \brief Per-MB encoder configuration buffer, or \c VA_INVALID_ID.
354 * If per-MB encoder configuration is needed, then \ref macroblock_info
355 * references a buffer of type #VAEncMacroblockParameterBufferH264
356 * (\c VAEncMacroblockParameterBufferType). Otherwise, buffer id
357 * is set to \c VA_INVALID_ID and per-MB configuration is derived
358 * from this slice parameter.
360 * The \c macroblock_info buffer must hold \ref num_macroblocks
363 VABufferID macroblock_info;
364 /** \brief Number of macroblocks in this slice. */
365 unsigned int num_macroblocks;
366 /** \brief Slice type.
367 * Range: 0..2, 5..7, i.e. no switching slices.
369 unsigned char slice_type;
370 /** \brief Same as the H.264 bitstream syntax element. */
371 unsigned char pic_parameter_set_id;
372 /** \brief Same as the H.264 bitstream syntax element. */
373 unsigned short idr_pic_id;
375 /** @name If pic_order_cnt_type == 0 */
377 /** \brief The picture order count modulo MaxPicOrderCntLsb. */
378 unsigned short pic_order_cnt_lsb;
379 /** \brief Valid if \c pic_order_present_flag and this is a bottom field. */
380 int delta_pic_order_cnt_bottom;
382 /** @name If pic_order_cnt_type == 1 && !delta_pic_order_always_zero_flag */
384 /** \brief [0]: top, [1]: bottom. */
385 int delta_pic_order_cnt[2];
388 /** @name If slice_type == B */
390 unsigned char direct_spatial_mv_pred_flag;
393 /** @name If slice_type == P */
395 /** \brief Specifies if
396 * \ref _VAEncPictureParameterBufferH264::num_ref_idx_l0_active_minus1 or
397 * \ref _VAEncPictureParameterBufferH264::num_ref_idx_l1_active_minus1 are
398 * overriden by the values for this slice.
400 unsigned char num_ref_idx_active_override_flag;
401 /** \brief Maximum reference index for reference picture list 0.
402 * Range: 0 to 31, inclusive.
404 unsigned char num_ref_idx_l0_active_minus1;
405 /** \brief Maximum reference index for reference picture list 1.
406 * Range: 0 to 31, inclusive.
408 unsigned char num_ref_idx_l1_active_minus1;
409 /** \brief Reference picture list 0 (for P slices). */
410 VAPictureH264 RefPicList0[32];
411 /** \brief Reference picture list 1 (for B slices). */
412 VAPictureH264 RefPicList1[32];
415 /** @name ref_pic_list_modification() */
417 /** \brief Same as the H.264 bitstream syntax element. */
418 unsigned char ref_pic_list_modification_flag_l0;
419 /** \brief Same as the H.264 bitstream syntax element. */
420 unsigned char ref_pic_list_modification_flag_l1;
421 /** \brief Same as the H.264 bitstream syntax element. */
422 unsigned char modification_of_pic_nums_idc_l0[32];
423 /** \brief Same as the H.264 bitstream syntax element. */
424 unsigned char modification_of_pic_nums_idc_l1[32];
425 /** \brief List 0 values for each \c modification_of_pic_nums_idc_l0. */
427 * - If \c modification_of_pic_nums_idc == 0 or 1:
428 * - \c modification_of_pic_nums_value is \c abs_diff_pic_num_minus1
429 * - If \c modification_of_pic_nums_idc == 2:
430 * - \c modification_of_pic_nums_value is \c long_term_pic_num
432 unsigned int modification_of_pic_nums_value_l0[32];
433 /** \brief Same as \c modification_of_pic_nums_value_l0 but for list 1. */
434 unsigned int modification_of_pic_nums_value_l1[32];
437 /** @name pred_weight_table() */
439 /** \brief Same as the H.264 bitstream syntax element. */
440 unsigned char luma_log2_weight_denom;
441 /** \brief Same as the H.264 bitstream syntax element. */
442 unsigned char chroma_log2_weight_denom;
443 /** \brief Same as the H.264 bitstream syntax element. */
444 unsigned char luma_weight_l0_flag;
445 /** \brief Same as the H.264 bitstream syntax element. */
446 signed short luma_weight_l0[32];
447 /** \brief Same as the H.264 bitstream syntax element. */
448 signed short luma_offset_l0[32];
449 /** \brief Same as the H.264 bitstream syntax element. */
450 unsigned char chroma_weight_l0_flag;
451 /** \brief Same as the H.264 bitstream syntax element. */
452 signed short chroma_weight_l0[32][2];
453 /** \brief Same as the H.264 bitstream syntax element. */
454 signed short chroma_offset_l0[32][2];
455 /** \brief Same as the H.264 bitstream syntax element. */
456 unsigned char luma_weight_l1_flag;
457 /** \brief Same as the H.264 bitstream syntax element. */
458 signed short luma_weight_l1[32];
459 /** \brief Same as the H.264 bitstream syntax element. */
460 signed short luma_offset_l1[32];
461 /** \brief Same as the H.264 bitstream syntax element. */
462 unsigned char chroma_weight_l1_flag;
463 /** \brief Same as the H.264 bitstream syntax element. */
464 signed short chroma_weight_l1[32][2];
465 /** \brief Same as the H.264 bitstream syntax element. */
466 signed short chroma_offset_l1[32][2];
469 /** @name dec_ref_pic_marking() */
471 /** \brief Same as the H.264 bitstream syntax element. */
472 unsigned char no_output_of_prior_pics_flag;
473 /** \brief Same as the H.264 bitstream syntax element. */
474 unsigned char long_term_reference_flag;
475 /** \brief Same as the H.264 bitstream syntax element. */
476 unsigned char adaptive_ref_pic_marking_mode_flag;
477 /** \brief Same as the \c memory_management_control_operation syntax element. */
478 unsigned char mmco[32];
480 * \brief Values for each \c memory_management_control_operation.
483 * - \c mmco_value[0] is \c difference_of_pic_nums_minus1
484 * - \c mmco_value[1] is not used
486 * - \c mmco_value[0] is \c long_term_pic_num
487 * - \c mmco_value[1] is not used
489 * - \c mmco_value[0] is \c difference_of_pic_nums_minus1
490 * - \c mmco_value[1] is \c long_term_frame_idx
492 * - \c mmco_value[0] is \c max_long_term_frame_idx_plus1
493 * - \c mmco_value[1] is not used
495 * - \c mmco_value[0] is \c long_term_frame_idx
496 * - \c mmco_value[1] is not used
498 unsigned int mmco_value[32][2];
501 /** \brief Range: 0 to 2, inclusive. */
502 unsigned char cabac_init_idc;
503 /** \brief Same as the H.264 bitstream syntax element. */
504 signed char slice_qp_delta;
505 /** @name If deblocking_filter_control_present_flag */
507 /** \brief Range: 0 to 2, inclusive. */
508 unsigned char disable_deblocking_filter_idc;
509 /** \brief Same as the H.264 bitstream syntax element. */
510 signed char slice_alpha_c0_offset_div2;
511 /** \brief Same as the H.264 bitstream syntax element. */
512 signed char slice_beta_offset_div2;
514 } VAEncSliceParameterBufferH264;
517 * @name Macroblock neighbour availability bits
519 * \anchor api_enc_h264_mb_pred_avail_bits
520 * Definitions for macroblock neighbour availability bits used in
521 * intra prediction mode (non MBAFF only).
525 /** \brief References macroblock in the top-left corner. */
526 #define VA_MB_PRED_AVAIL_TOP_LEFT (1 << 2)
527 /** \brief References macroblock above the current macroblock. */
528 #define VA_MB_PRED_AVAIL_TOP (1 << 4)
529 /** \brief References macroblock in the top-right corner. */
530 #define VA_MB_PRED_AVAIL_TOP_RIGHT (1 << 3)
531 /** \brief References macroblock on the left of the current macroblock. */
532 #define VA_MB_PRED_AVAIL_LEFT (1 << 6)
536 * \brief Macroblock parameter for H.264 encoding in main & high profiles.
538 * This structure holds per-macroblock information. The buffer must be
539 * allocated with as many elements (macroblocks) as necessary to fit
540 * the slice to be encoded. Besides, the per-macroblock records must
541 * be written in a strict raster order and with no gap. i.e. every
542 * macroblock, regardless of its type, shall have an entry.
544 typedef struct _VAEncMacroblockParameterBufferH264 {
546 * \brief Quantization parameter.
548 * Requested quantization parameter. Range: 0 to 51, inclusive.
549 * If \ref qp is set to 0xff, then the actual value is derived
550 * from the slice-level value: \c pic_init_qp + \c slice_qp_delta.
555 /** @name Data for intra macroblock */
560 * \brief Flag specified to override MB neighbour
561 * availability bits from VME stage.
563 * This flag specifies that macroblock neighbour
564 * availability bits from the VME stage are overriden
565 * by the \ref pred_avail_flags hereunder.
567 unsigned int pred_avail_override_flag : 1;
569 * \brief Bitwise representation of which macroblocks
570 * are available for intra prediction.
572 * If the slice is intra-coded, this field represents
573 * the macroblocks available for intra prediction.
574 * See \ref api_enc_h264_mb_pred_avail_bits
575 * "macroblock neighbour availability" bit definitions.
577 unsigned int pred_avail_flags : 8;
583 /** @name Data for inter macroblock */
592 } VAEncMacroblockParameterBufferH264;
600 #endif /* VA_ENC_H264_H */