OSDN Git Service

API: h264 encode: remove dec_ref_pic_marking().
[android-x86/hardware-intel-common-libva.git] / va / va_enc_h264.h
1 /*
2  * Copyright (c) 2007-2011 Intel Corporation. All Rights Reserved.
3  *
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:
11  *
12  * The above copyright notice and this permission notice (including the
13  * next paragraph) shall be included in all copies or substantial portions
14  * of the Software.
15  *
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.
23  */
24
25 /**
26  * \file va_enc_h264.h
27  * \brief The H.264 encoding API
28  *
29  * This file contains the \ref api_enc_h264 "H.264 encoding API".
30  */
31
32 #ifndef VA_ENC_H264_H
33 #define VA_ENC_H264_H
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 /**
40  * \defgroup api_enc_h264 H.264 encoding API
41  *
42  * @{
43  */
44
45 /**
46  * @name Picture flags
47  *
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.
50  *
51  * @{
52  */
53 /**
54  * \brief Marks the last picture in the sequence.
55  *
56  * i.e. the driver appends \c end_of_seq() NAL unit to the encoded frame.
57  */
58 #define H264_LAST_PICTURE_EOSEQ     0x01
59 /**
60  * \brief Marks the last picture in the stream.
61  *
62  * i.e. the driver appends \c end_of_stream() NAL unit to the encoded frame.
63  */
64 #define H264_LAST_PICTURE_EOSTREAM  0x02
65 /**@}*/
66
67 /**
68  * \brief Packed header types specific to H.264 encoding.
69  *
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.
74  */
75 typedef enum {
76     /**
77      * \brief Packed Supplemental Enhancement Information (SEI).
78      *
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.
82      *
83      * Note: packed \c nal_unit_type shall be equal to 6.
84      */
85     VAEncPackedHeaderH264_SEI = (VAEncPackedHeaderMiscMask | 1),
86 } VAEncPackedHeaderTypeH264;
87
88 /**
89  * \brief Sequence parameter for H.264 encoding in main & high profiles.
90  *
91  * This structure holds information for \c seq_parameter_set_data() as
92  * defined by the H.264 specification.
93  *
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
101  *   header data.
102  *
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.
106  */
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;
118     /**
119      * \brief Initial bitrate set for this sequence in CBR or VBR modes.
120      *
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.
125      *
126      * The bitrate can be modified later on through
127      * #VAEncMiscParameterRateControl buffers.
128      */
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;
136
137     union {
138         struct {
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;
157         } bits;
158         unsigned int value;
159     } seq_fields;
160
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;
165
166     /** if pic_order_cnt_type == 1 */
167     /**@{*/
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];
176     /**@}*/
177
178     /** @name Cropping (optional) */
179     /**@{*/
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;
190     /**@}*/
191
192     /** @name VUI parameters (optional) */
193     /**@{*/
194     /** \brief Same as the H.264 bitstream syntax element. */
195     unsigned char   vui_parameters_present_flag;
196     union {
197         struct {
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;
206         } bits;
207         unsigned int value;
208     } vui_fields;
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;
213     /**@}*/
214 } VAEncSequenceParameterBufferH264;
215
216 /**
217  * \brief Picture parameter for H.264 encoding in main & high profiles.
218  *
219  * This structure holds information for \c pic_parameter_set_rbsp() as
220  * defined by the H.264 specification.
221  *
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
229  *   header data.
230  *
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.
234  */
235 typedef struct _VAEncPictureParameterBufferH264 {
236     /**
237      * \brief Information about the picture to be encoded.
238      *
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.
242      */
243     VAPictureH264   CurrPic;
244     /**
245      * \brief Decoded Picture Buffer (DPB).
246      *
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.
251      */
252     VAPictureH264   ReferenceFrames[16];
253     /**
254      * \brief Output encoded bitstream.
255      *
256      * \ref coded_buf has type #VAEncCodedBufferType. It should be
257      * large enough to hold the compressed NAL slice and possibly SPS
258      * and PPS NAL units.
259      */
260     VABufferID      coded_buf;
261
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;
266
267     /**
268      * \brief OR'd flags describing whether the picture is the last one or not.
269      *
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.
273      */
274     unsigned char   last_picture;
275
276     /** \brief The picture identifier.
277      *   Range: 0 to \f$2^{log2\_max\_frame\_num\_minus4 + 4} - 1\f$, inclusive.
278      */
279     unsigned short  frame_num;
280
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.
285      */
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.
289      */
290     unsigned char   num_ref_idx_l1_active_minus1;
291
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;
296
297     union {
298         struct {
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;
321         } bits;
322         unsigned int value;
323     } pic_fields;
324 } VAEncPictureParameterBufferH264;
325
326 /**
327  * \brief Slice parameter for H.264 encoding in main & high profiles.
328  *
329  * This structure holds information for \c
330  * slice_layer_without_partitioning_rbsp() as defined by the H.264
331  * specification.
332  *
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
340  *   header data.
341  *
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.
347  */
348 typedef struct _VAEncSliceParameterBufferH264 {
349     /** \brief Starting MB address for this slice. */
350     unsigned int    macroblock_address;
351     /**
352      * \brief Per-MB encoder configuration buffer, or \c VA_INVALID_ID.
353      *
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.
359      *
360      * The \c macroblock_info buffer must hold \ref num_macroblocks
361      * elements.
362      */
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.
368      */
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;
374
375     /** @name If pic_order_cnt_type == 0 */
376     /**@{*/
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;
381     /**@}*/
382     /** @name If pic_order_cnt_type == 1 && !delta_pic_order_always_zero_flag */
383     /**@{*/
384     /** \brief [0]: top, [1]: bottom. */
385     int             delta_pic_order_cnt[2];
386     /**@}*/
387
388     /** @name If slice_type == B */
389     /**@{*/
390     unsigned char   direct_spatial_mv_pred_flag;
391     /**@}*/
392
393     /** @name If slice_type == P */
394     /**@{*/
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.
399      */
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.
403      */
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.
407      */
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];
413     /**@}*/
414
415     /** @name pred_weight_table() */
416     /**@{*/
417     /** \brief Same as the H.264 bitstream syntax element. */
418     unsigned char   luma_log2_weight_denom;
419     /** \brief Same as the H.264 bitstream syntax element. */
420     unsigned char   chroma_log2_weight_denom;
421     /** \brief Same as the H.264 bitstream syntax element. */
422     unsigned char   luma_weight_l0_flag;
423     /** \brief Same as the H.264 bitstream syntax element. */
424     signed short    luma_weight_l0[32];
425     /** \brief Same as the H.264 bitstream syntax element. */
426     signed short    luma_offset_l0[32];
427     /** \brief Same as the H.264 bitstream syntax element. */
428     unsigned char   chroma_weight_l0_flag;
429     /** \brief Same as the H.264 bitstream syntax element. */
430     signed short    chroma_weight_l0[32][2];
431     /** \brief Same as the H.264 bitstream syntax element. */
432     signed short    chroma_offset_l0[32][2];
433     /** \brief Same as the H.264 bitstream syntax element. */
434     unsigned char   luma_weight_l1_flag;
435     /** \brief Same as the H.264 bitstream syntax element. */
436     signed short    luma_weight_l1[32];
437     /** \brief Same as the H.264 bitstream syntax element. */
438     signed short    luma_offset_l1[32];
439     /** \brief Same as the H.264 bitstream syntax element. */
440     unsigned char   chroma_weight_l1_flag;
441     /** \brief Same as the H.264 bitstream syntax element. */
442     signed short    chroma_weight_l1[32][2];
443     /** \brief Same as the H.264 bitstream syntax element. */
444     signed short    chroma_offset_l1[32][2];
445     /**@}*/
446
447     /** \brief Range: 0 to 2, inclusive. */
448     unsigned char   cabac_init_idc;
449     /** \brief Same as the H.264 bitstream syntax element. */
450     signed char     slice_qp_delta;
451     /** @name If deblocking_filter_control_present_flag */
452     /**@{*/
453     /** \brief Range: 0 to 2, inclusive. */
454     unsigned char   disable_deblocking_filter_idc;
455     /** \brief Same as the H.264 bitstream syntax element. */
456     signed char     slice_alpha_c0_offset_div2;
457     /** \brief Same as the H.264 bitstream syntax element. */
458     signed char     slice_beta_offset_div2;
459     /**@}*/
460 } VAEncSliceParameterBufferH264;
461
462 /**
463  * @name Macroblock neighbour availability bits
464  *
465  * \anchor api_enc_h264_mb_pred_avail_bits
466  * Definitions for macroblock neighbour availability bits used in
467  * intra prediction mode (non MBAFF only).
468  *
469  * @{
470  */
471 /** \brief References macroblock in the top-left corner. */
472 #define VA_MB_PRED_AVAIL_TOP_LEFT         (1 << 2)
473 /** \brief References macroblock above the current macroblock. */
474 #define VA_MB_PRED_AVAIL_TOP              (1 << 4)
475 /** \brief References macroblock in the top-right corner. */
476 #define VA_MB_PRED_AVAIL_TOP_RIGHT        (1 << 3)
477 /** \brief References macroblock on the left of the current macroblock. */
478 #define VA_MB_PRED_AVAIL_LEFT             (1 << 6)
479 /**@}*/
480
481 /**
482  * \brief Macroblock parameter for H.264 encoding in main & high profiles.
483  *
484  * This structure holds per-macroblock information. The buffer must be
485  * allocated with as many elements (macroblocks) as necessary to fit
486  * the slice to be encoded. Besides, the per-macroblock records must
487  * be written in a strict raster order and with no gap. i.e. every
488  * macroblock, regardless of its type, shall have an entry.
489  */
490 typedef struct _VAEncMacroblockParameterBufferH264 {
491     /**
492      * \brief Quantization parameter.
493      *
494      * Requested quantization parameter. Range: 0 to 51, inclusive.
495      * If \ref qp is set to 0xff, then the actual value is derived
496      * from the slice-level value: \c pic_init_qp + \c slice_qp_delta.
497      */
498     unsigned char   qp;
499
500     union {
501         /** @name Data for intra macroblock */
502         /**@{*/
503         struct {
504             union {
505                 /**
506                  * \brief Flag specified to override MB neighbour
507                  * availability bits from VME stage.
508                  *
509                  * This flag specifies that macroblock neighbour
510                  * availability bits from the VME stage are overriden
511                  * by the \ref pred_avail_flags hereunder.
512                  */
513                 unsigned int    pred_avail_override_flag        : 1;
514                 /**
515                  * \brief Bitwise representation of which macroblocks
516                  * are available for intra prediction.
517                  *
518                  * If the slice is intra-coded, this field represents
519                  * the macroblocks available for intra prediction.
520                  * See \ref api_enc_h264_mb_pred_avail_bits
521                  * "macroblock neighbour availability" bit definitions.
522                  */
523                 unsigned int    pred_avail_flags                : 8;
524             } bits;
525             unsigned int value;
526         } intra_fields;
527         /**@}*/
528
529         /** @name Data for inter macroblock */
530         /**@{*/
531         struct {
532             union {
533             } bits;
534             unsigned int value;
535         } inter_fields;
536         /**@}*/
537     } info;
538 } VAEncMacroblockParameterBufferH264;
539
540 /**@}*/
541
542 #ifdef __cplusplus
543 }
544 #endif
545
546 #endif /* VA_ENC_H264_H */