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.
75 * Note: the start code prefix can contain an arbitrary number of leading
76 * zeros. The driver will skip them for emulation prevention bytes insertion,
81 * \brief Packed Sequence Parameter Set (SPS).
83 * The corresponding packed header data buffer shall contain the
84 * complete seq_parameter_set_rbsp() syntax element.
86 * Note: packed \c nal_unit_type shall be equal to 7.
88 VAEncPackedHeaderH264_SPS = VAEncPackedHeaderSequence,
90 * \brief Packed Picture Parameter Set (PPS).
92 * The corresponding packed header data buffer shall contain the
93 * complete pic_parameter_set_rbsp() syntax element.
95 * Note: packed \c nal_unit_type shall be equal to 8.
97 VAEncPackedHeaderH264_PPS = VAEncPackedHeaderPicture,
99 * \brief Packed slice header.
101 * The corresponding packed header data buffer shall contain the
102 * \c slice_header() syntax element only, along with any start
103 * code prefix and NAL unit type preceeding it. i.e. this means
104 * that the buffer does not contain any of the \c slice_data() or
105 * the \c rbsp_slice_trailing_bits().
107 * Note: packed \c nal_unit_type shall be equal to 1 (non-IDR
108 * picture), or 5 (IDR picture).
110 VAEncPackedHeaderH264_Slice = VAEncPackedHeaderSlice,
112 * \brief Packed Supplemental Enhancement Information (SEI).
114 * The corresponding packed header data buffer shall contain the
115 * complete sei_rbsp() syntax element, thus including several
116 * sei_message() elements if necessary.
118 * Note: packed \c nal_unit_type shall be equal to 6.
120 VAEncPackedHeaderH264_SEI = (VAEncPackedHeaderMiscMask | 1),
121 } VAEncPackedHeaderTypeH264;
124 * \brief Sequence parameter for H.264 encoding in main & high profiles.
126 * This structure holds information for \c seq_parameter_set_data() as
127 * defined by the H.264 specification.
129 * If packed sequence headers mode is used, i.e. if the encoding
130 * pipeline was configured with the #VA_ENC_PACKED_HEADER_SEQUENCE
131 * flag, then the driver expects two more buffers to be provided to
132 * the same \c vaRenderPicture() as this buffer:
133 * - a #VAEncPackedHeaderParameterBuffer with type set to
134 * VAEncPackedHeaderType::VAEncPackedHeaderSequence ;
135 * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
138 * If \c seq_scaling_matrix_present_flag is set to \c 1, then a
139 * #VAIQMatrixBufferH264 buffer shall also be provided within the same
140 * \c vaRenderPicture() call as this sequence parameter buffer.
142 typedef struct _VAEncSequenceParameterBufferH264 {
143 /** \brief Same as the H.264 bitstream syntax element. */
144 unsigned char seq_parameter_set_id;
145 /** \brief Same as the H.264 bitstream syntax element. */
146 unsigned char level_idc;
147 /** \brief Period between I frames. */
148 unsigned int intra_period;
149 /** \brief Period between IDR frames. */
150 unsigned int intra_idr_period;
151 /** \brief Period between I/P frames. */
152 unsigned int ip_period;
154 * \brief Initial bitrate set for this sequence in CBR or VBR modes.
156 * This field represents the initial bitrate value for this
157 * sequence if CBR or VBR mode is used, i.e. if the encoder
158 * pipeline was created with a #VAConfigAttribRateControl
159 * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR.
161 * The bitrate can be modified later on through
162 * #VAEncMiscParameterRateControl buffers.
164 unsigned int bits_per_second;
165 /** \brief Same as the H.264 bitstream syntax element. */
166 unsigned int max_num_ref_frames;
167 /** \brief Picture width in macroblocks. */
168 unsigned short picture_width_in_mbs;
169 /** \brief Picture height in macroblocks. */
170 unsigned short picture_height_in_mbs;
174 /** \brief Same as the H.264 bitstream syntax element. */
175 unsigned int chroma_format_idc : 2;
176 /** \brief Same as the H.264 bitstream syntax element. */
177 unsigned int frame_mbs_only_flag : 1;
178 /** \brief Same as the H.264 bitstream syntax element. */
179 unsigned int mb_adaptive_frame_field_flag : 1;
180 /** \brief Same as the H.264 bitstream syntax element. */
181 unsigned int seq_scaling_matrix_present_flag : 1;
182 /** \brief Same as the H.264 bitstream syntax element. */
183 unsigned int direct_8x8_inference_flag : 1;
184 /** \brief Same as the H.264 bitstream syntax element. */
185 unsigned int log2_max_frame_num_minus4 : 4;
186 /** \brief Same as the H.264 bitstream syntax element. */
187 unsigned int pic_order_cnt_type : 2;
188 /** \brief Same as the H.264 bitstream syntax element. */
189 unsigned int log2_max_pic_order_cnt_lsb_minus4 : 4;
190 /** \brief Same as the H.264 bitstream syntax element. */
191 unsigned int delta_pic_order_always_zero_flag : 1;
196 /** \brief Same as the H.264 bitstream syntax element. */
197 unsigned char bit_depth_luma_minus8;
198 /** \brief Same as the H.264 bitstream syntax element. */
199 unsigned char bit_depth_chroma_minus8;
201 /** if pic_order_cnt_type == 1 */
203 /** \brief Same as the H.264 bitstream syntax element. */
204 unsigned char num_ref_frames_in_pic_order_cnt_cycle;
205 /** \brief Same as the H.264 bitstream syntax element. */
206 int offset_for_non_ref_pic;
207 /** \brief Same as the H.264 bitstream syntax element. */
208 int offset_for_top_to_bottom_field;
209 /** \brief Same as the H.264 bitstream syntax element. */
210 int offset_for_ref_frame[256];
213 /** @name Cropping (optional) */
215 /** \brief Same as the H.264 bitstream syntax element. */
216 unsigned char frame_cropping_flag;
217 /** \brief Same as the H.264 bitstream syntax element. */
218 unsigned int frame_crop_left_offset;
219 /** \brief Same as the H.264 bitstream syntax element. */
220 unsigned int frame_crop_right_offset;
221 /** \brief Same as the H.264 bitstream syntax element. */
222 unsigned int frame_crop_top_offset;
223 /** \brief Same as the H.264 bitstream syntax element. */
224 unsigned int frame_crop_bottom_offset;
227 /** @name VUI parameters (optional) */
229 /** \brief Same as the H.264 bitstream syntax element. */
230 unsigned char vui_parameters_present_flag;
233 /** \brief Same as the H.264 bitstream syntax element. */
234 unsigned int aspect_ratio_info_present_flag : 1;
235 /** \brief Same as the H.264 bitstream syntax element. */
236 unsigned int timing_info_present_flag : 1;
237 /** \brief Same as the H.264 bitstream syntax element. */
238 unsigned int bitstream_restriction_flag : 1;
239 /** \brief Range: 0 to 16, inclusive. */
240 unsigned int log2_max_mv_length_horizontal : 5;
241 /** \brief Range: 0 to 16, inclusive. */
242 unsigned int log2_max_mv_length_vertical : 5;
246 /** \brief Same as the H.264 bitstream syntax element. */
247 unsigned char aspect_ratio_idc;
248 /** \brief Same as the H.264 bitstream syntax element. */
249 unsigned int sar_width;
250 /** \brief Same as the H.264 bitstream syntax element. */
251 unsigned int sar_height;
252 /** \brief Same as the H.264 bitstream syntax element. */
253 unsigned int num_units_in_tick;
254 /** \brief Same as the H.264 bitstream syntax element. */
255 unsigned int time_scale;
257 } VAEncSequenceParameterBufferH264;
260 * \brief Picture parameter for H.264 encoding in main & high profiles.
262 * This structure holds information for \c pic_parameter_set_rbsp() as
263 * defined by the H.264 specification.
265 * If packed picture headers mode is used, i.e. if the encoding
266 * pipeline was configured with the #VA_ENC_PACKED_HEADER_PICTURE
267 * flag, then the driver expects two more buffers to be provided to
268 * the same \c vaRenderPicture() as this buffer:
269 * - a #VAEncPackedHeaderParameterBuffer with type set to
270 * VAEncPackedHeaderType::VAEncPackedHeaderPicture ;
271 * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
274 * If \c pic_scaling_matrix_present_flag is set to \c 1, then a
275 * #VAIQMatrixBufferH264 buffer shall also be provided within the same
276 * \c vaRenderPicture() call as this picture parameter buffer.
278 typedef struct _VAEncPictureParameterBufferH264 {
280 * \brief Information about the picture to be encoded.
282 * See #VAPictureH264 for further description of each field.
283 * Note that CurrPic.picture_id represents the reconstructed
284 * (decoded) picture. User provides a scratch VA surface ID here.
286 VAPictureH264 CurrPic;
288 * \brief Decoded Picture Buffer (DPB).
290 * This array represents the list of reconstructed (decoded)
291 * frames used as reference. It is important to keep track of
292 * reconstructed frames so that they can be used later on as
293 * reference for P or B-frames encoding.
295 VAPictureH264 ReferenceFrames[16];
297 * \brief Output encoded bitstream.
299 * \ref coded_buf has type #VAEncCodedBufferType. It should be
300 * large enough to hold the compressed NAL slice and possibly SPS
303 VABufferID coded_buf;
305 /** \brief The picture parameter set referred to in the slice header. */
306 unsigned char pic_parameter_set_id;
307 /** \brief The active sequence parameter set. Range: 0 to 31, inclusive. */
308 unsigned char seq_parameter_set_id;
311 * \brief OR'd flags describing whether the picture is the last one or not.
313 * This fields holds 0 if the picture to be encoded is not the last
314 * one in the stream or sequence. Otherwise, it is a combination of
315 * \ref H264_LAST_PICTURE_EOSEQ or \ref H264_LAST_PICTURE_EOSTREAM.
317 unsigned char last_picture;
319 /** \brief The picture identifier.
320 * Range: 0 to \f$2^{log2\_max\_frame\_num\_minus4 + 4} - 1\f$, inclusive.
322 unsigned short frame_num;
324 /** \brief \c pic_init_qp_minus26 + 26. */
325 unsigned char pic_init_qp;
326 /** \brief Maximum reference index for reference picture list 0.
327 * Range: 0 to 31, inclusive.
329 unsigned char num_ref_idx_l0_active_minus1;
330 /** \brief Maximum reference index for reference picture list 1.
331 * Range: 0 to 31, inclusive.
333 unsigned char num_ref_idx_l1_active_minus1;
335 /** \brief Range: -12 to 12, inclusive. */
336 signed char chroma_qp_index_offset;
337 /** \brief Range: -12 to 12, inclusive. */
338 signed char second_chroma_qp_index_offset;
342 /** \brief Is picture an IDR picture? */
343 unsigned int idr_pic_flag : 1;
344 /** \brief Is picture a reference picture? */
345 unsigned int reference_pic_flag : 2;
346 /** \brief Selects CAVLC (0) or CABAC (1) entropy coding mode. */
347 unsigned int entropy_coding_mode_flag : 1;
348 /** \brief Is weighted prediction applied to P slices? */
349 unsigned int weighted_pred_flag : 1;
350 /** \brief Range: 0 to 2, inclusive. */
351 unsigned int weighted_bipred_idc : 2;
352 /** \brief Same as the H.264 bitstream syntax element. */
353 unsigned int constrained_intra_pred_flag : 1;
354 /** \brief Same as the H.264 bitstream syntax element. */
355 unsigned int transform_8x8_mode_flag : 1;
356 /** \brief Same as the H.264 bitstream syntax element. */
357 unsigned int deblocking_filter_control_present_flag : 1;
358 /** \brief Same as the H.264 bitstream syntax element. */
359 unsigned int redundant_pic_cnt_present_flag : 1;
360 /** \brief Same as the H.264 bitstream syntax element. */
361 unsigned int pic_order_present_flag : 1;
362 /** \brief Same as the H.264 bitstream syntax element. */
363 unsigned int pic_scaling_matrix_present_flag : 1;
367 } VAEncPictureParameterBufferH264;
370 * \brief Slice parameter for H.264 encoding in main & high profiles.
372 * This structure holds information for \c
373 * slice_layer_without_partitioning_rbsp() as defined by the H.264
376 * If packed slice headers mode is used, i.e. if the encoding
377 * pipeline was configured with the #VA_ENC_PACKED_HEADER_SLICE
378 * flag, then the driver expects two more buffers to be provided to
379 * the same \c vaRenderPicture() as this buffer:
380 * - a #VAEncPackedHeaderParameterBuffer with type set to
381 * VAEncPackedHeaderType::VAEncPackedHeaderSlice ;
382 * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
385 * If per-macroblock encoder configuration is needed, \c macroblock_info
386 * references a buffer of type #VAEncMacroblockParameterBufferH264. This
387 * buffer is not passed to vaRenderPicture(). i.e. it is not destroyed
388 * by subsequent calls to vaRenderPicture() and then can be re-used
389 * without re-allocating the whole buffer.
391 typedef struct _VAEncSliceParameterBufferH264 {
392 /** \brief Starting MB address for this slice. */
393 unsigned int macroblock_address;
394 /** \brief Number of macroblocks in this slice. */
395 unsigned int num_macroblocks;
397 * \brief Per-MB encoder configuration buffer, or \c VA_INVALID_ID.
399 * If per-MB encoder configuration is needed, then \ref macroblock_info
400 * references a buffer of type #VAEncMacroblockParameterBufferH264
401 * (\c VAEncMacroblockParameterBufferType). Otherwise, buffer id
402 * is set to \c VA_INVALID_ID and per-MB configuration is derived
403 * from this slice parameter.
405 * The \c macroblock_info buffer must hold \ref num_macroblocks
408 VABufferID macroblock_info;
409 /** \brief Slice type.
410 * Range: 0..2, 5..7, i.e. no switching slices.
412 unsigned char slice_type;
413 /** \brief Same as the H.264 bitstream syntax element. */
414 unsigned char pic_parameter_set_id;
415 /** \brief Same as the H.264 bitstream syntax element. */
416 unsigned short idr_pic_id;
418 /** @name If pic_order_cnt_type == 0 */
420 /** \brief The picture order count modulo MaxPicOrderCntLsb. */
421 unsigned short pic_order_cnt_lsb;
422 /** \brief Valid if \c pic_order_present_flag and this is a bottom field. */
423 int delta_pic_order_cnt_bottom;
425 /** @name If pic_order_cnt_type == 1 && !delta_pic_order_always_zero_flag */
427 /** \brief [0]: top, [1]: bottom. */
428 int delta_pic_order_cnt[2];
431 /** @name If slice_type == B */
433 unsigned char direct_spatial_mv_pred_flag;
436 /** @name If slice_type == P */
438 /** \brief Specifies if
439 * \ref _VAEncPictureParameterBufferH264::num_ref_idx_l0_active_minus1 or
440 * \ref _VAEncPictureParameterBufferH264::num_ref_idx_l1_active_minus1 are
441 * overriden by the values for this slice.
443 unsigned char num_ref_idx_active_override_flag;
444 /** \brief Maximum reference index for reference picture list 0.
445 * Range: 0 to 31, inclusive.
447 unsigned char num_ref_idx_l0_active_minus1;
448 /** \brief Maximum reference index for reference picture list 1.
449 * Range: 0 to 31, inclusive.
451 unsigned char num_ref_idx_l1_active_minus1;
452 /** \brief Reference picture list 0 (for P slices). */
453 VAPictureH264 RefPicList0[32];
454 /** \brief Reference picture list 1 (for B slices). */
455 VAPictureH264 RefPicList1[32];
458 /** @name pred_weight_table() */
460 /** \brief Same as the H.264 bitstream syntax element. */
461 unsigned char luma_log2_weight_denom;
462 /** \brief Same as the H.264 bitstream syntax element. */
463 unsigned char chroma_log2_weight_denom;
464 /** \brief Same as the H.264 bitstream syntax element. */
465 unsigned char luma_weight_l0_flag;
466 /** \brief Same as the H.264 bitstream syntax element. */
467 signed short luma_weight_l0[32];
468 /** \brief Same as the H.264 bitstream syntax element. */
469 signed short luma_offset_l0[32];
470 /** \brief Same as the H.264 bitstream syntax element. */
471 unsigned char chroma_weight_l0_flag;
472 /** \brief Same as the H.264 bitstream syntax element. */
473 signed short chroma_weight_l0[32][2];
474 /** \brief Same as the H.264 bitstream syntax element. */
475 signed short chroma_offset_l0[32][2];
476 /** \brief Same as the H.264 bitstream syntax element. */
477 unsigned char luma_weight_l1_flag;
478 /** \brief Same as the H.264 bitstream syntax element. */
479 signed short luma_weight_l1[32];
480 /** \brief Same as the H.264 bitstream syntax element. */
481 signed short luma_offset_l1[32];
482 /** \brief Same as the H.264 bitstream syntax element. */
483 unsigned char chroma_weight_l1_flag;
484 /** \brief Same as the H.264 bitstream syntax element. */
485 signed short chroma_weight_l1[32][2];
486 /** \brief Same as the H.264 bitstream syntax element. */
487 signed short chroma_offset_l1[32][2];
490 /** \brief Range: 0 to 2, inclusive. */
491 unsigned char cabac_init_idc;
492 /** \brief Same as the H.264 bitstream syntax element. */
493 signed char slice_qp_delta;
494 /** @name If deblocking_filter_control_present_flag */
496 /** \brief Range: 0 to 2, inclusive. */
497 unsigned char disable_deblocking_filter_idc;
498 /** \brief Same as the H.264 bitstream syntax element. */
499 signed char slice_alpha_c0_offset_div2;
500 /** \brief Same as the H.264 bitstream syntax element. */
501 signed char slice_beta_offset_div2;
503 } VAEncSliceParameterBufferH264;
506 * @name Macroblock neighbour availability bits
508 * \anchor api_enc_h264_mb_pred_avail_bits
509 * Definitions for macroblock neighbour availability bits used in
510 * intra prediction mode (non MBAFF only).
514 /** \brief References macroblock in the top-left corner. */
515 #define VA_MB_PRED_AVAIL_TOP_LEFT (1 << 2)
516 /** \brief References macroblock above the current macroblock. */
517 #define VA_MB_PRED_AVAIL_TOP (1 << 4)
518 /** \brief References macroblock in the top-right corner. */
519 #define VA_MB_PRED_AVAIL_TOP_RIGHT (1 << 3)
520 /** \brief References macroblock on the left of the current macroblock. */
521 #define VA_MB_PRED_AVAIL_LEFT (1 << 6)
525 * \brief Macroblock parameter for H.264 encoding in main & high profiles.
527 * This structure holds per-macroblock information. The buffer must be
528 * allocated with as many elements (macroblocks) as necessary to fit
529 * the slice to be encoded. Besides, the per-macroblock records must
530 * be written in a strict raster order and with no gap. i.e. every
531 * macroblock, regardless of its type, shall have an entry.
533 typedef struct _VAEncMacroblockParameterBufferH264 {
535 * \brief Quantization parameter.
537 * Requested quantization parameter. Range: 0 to 51, inclusive.
538 * If \ref qp is set to 0xff, then the actual value is derived
539 * from the slice-level value: \c pic_init_qp + \c slice_qp_delta.
544 /** @name Data for intra macroblock */
549 * \brief Flag specified to override MB neighbour
550 * availability bits from VME stage.
552 * This flag specifies that macroblock neighbour
553 * availability bits from the VME stage are overriden
554 * by the \ref pred_avail_flags hereunder.
556 unsigned int pred_avail_override_flag : 1;
558 * \brief Bitwise representation of which macroblocks
559 * are available for intra prediction.
561 * If the slice is intra-coded, this field represents
562 * the macroblocks available for intra prediction.
563 * See \ref api_enc_h264_mb_pred_avail_bits
564 * "macroblock neighbour availability" bit definitions.
566 unsigned int pred_avail_flags : 8;
572 /** @name Data for inter macroblock */
581 } VAEncMacroblockParameterBufferH264;
589 #endif /* VA_ENC_H264_H */