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 #include <stdint.h>
40 #include <va/va_enc.h>
41 
42 /**
43  * \defgroup api_enc_h264 H.264 encoding API
44  *
45  * @{
46  */
47 
48 /**
49  * @name Picture flags
50  *
51  * Those flags flags are meant to signal when a picture marks the end
52  * of a sequence, a stream, or even both at once.
53  *
54  * @{
55  */
56 /**
57  * \brief Marks the last picture in the sequence.
58  *
59  * i.e. the driver appends \c end_of_seq() NAL unit to the encoded frame.
60  */
61 #define H264_LAST_PICTURE_EOSEQ     VA_ENC_LAST_PICTURE_EOSEQ
62 /**
63  * \brief Marks the last picture in the stream.
64  *
65  * i.e. the driver appends \c end_of_stream() NAL unit to the encoded frame.
66  */
67 #define H264_LAST_PICTURE_EOSTREAM  VA_ENC_LAST_PICTURE_EOSTREAM
68 /**@}*/
69 
70 /**
71  * \brief Packed header types specific to H.264 encoding.
72  *
73  * Types of packed headers generally used for H.264 encoding. Each
74  * associated packed header data buffer shall contain the start code
75  * prefix 0x000001 followed by the complete NAL unit, thus also
76  * including the \c nal_unit_type.
77  *
78  * Note: the start code prefix can contain an arbitrary number of leading
79  * zeros. The driver will skip them for emulation prevention bytes insertion,
80  * if necessary.
81  */
82 typedef enum {
83     /**
84      * \brief Packed Sequence Parameter Set (SPS).
85      *
86      * The corresponding packed header data buffer shall contain the
87      * complete seq_parameter_set_rbsp() syntax element.
88      *
89      * Note: packed \c nal_unit_type shall be equal to 7.
90      */
91     VAEncPackedHeaderH264_SPS   = VAEncPackedHeaderSequence,
92     /**
93      * \brief Packed Picture Parameter Set (PPS).
94      *
95      * The corresponding packed header data buffer shall contain the
96      * complete pic_parameter_set_rbsp() syntax element.
97      *
98      * Note: packed \c nal_unit_type shall be equal to 8.
99      */
100     VAEncPackedHeaderH264_PPS   = VAEncPackedHeaderPicture,
101     /**
102      * \brief Packed slice header.
103      *
104      * The corresponding packed header data buffer shall contain the
105      * \c slice_header() syntax element only, along with any start
106      * code prefix and NAL unit type preceeding it. i.e. this means
107      * that the buffer does not contain any of the \c slice_data() or
108      * the \c rbsp_slice_trailing_bits().
109      *
110      * Note: packed \c nal_unit_type shall be equal to 1 (non-IDR
111      * picture), or 5 (IDR picture).
112      */
113     VAEncPackedHeaderH264_Slice = VAEncPackedHeaderSlice,
114     /**
115      * \brief Packed Supplemental Enhancement Information (SEI).
116      *
117      * The corresponding packed header data buffer shall contain the
118      * complete sei_rbsp() syntax element, thus including several
119      * sei_message() elements if necessary.
120      *
121      * Note: packed \c nal_unit_type shall be equal to 6.
122      */
123     VAEncPackedHeaderH264_SEI   = (VAEncPackedHeaderMiscMask | 1),
124 } VAEncPackedHeaderTypeH264;
125 
126 /**
127  * \brief Sequence parameter for H.264 encoding in baseline, main & high
128  * profiles.
129  *
130  * This structure holds information for \c seq_parameter_set_data() as
131  * defined by the H.264 specification.
132  *
133  * If packed sequence headers mode is used, i.e. if the encoding
134  * pipeline was configured with the #VA_ENC_PACKED_HEADER_SEQUENCE
135  * flag, then the driver expects two more buffers to be provided to
136  * the same \c vaRenderPicture() as this buffer:
137  * - a #VAEncPackedHeaderParameterBuffer with type set to
138  *   VAEncPackedHeaderType::VAEncPackedHeaderSequence ;
139  * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
140  *   header data.
141  *
142  * If \c seq_scaling_matrix_present_flag is set to \c 1, then a
143  * #VAIQMatrixBufferH264 buffer shall also be provided within the same
144  * \c vaRenderPicture() call as this sequence parameter buffer.
145  */
146 typedef struct _VAEncSequenceParameterBufferH264 {
147     /** \brief Same as the H.264 bitstream syntax element. */
148     unsigned char   seq_parameter_set_id;
149     /** \brief Same as the H.264 bitstream syntax element. */
150     unsigned char   level_idc;
151     /** \brief Period between I frames. */
152     unsigned int    intra_period;
153     /** \brief Period between IDR frames. */
154     unsigned int    intra_idr_period;
155     /** \brief Period between I/P frames. */
156     unsigned int    ip_period;
157     /**
158      * \brief Initial bitrate set for this sequence in CBR or VBR modes.
159      *
160      * This field represents the initial bitrate value for this
161      * sequence if CBR or VBR mode is used, i.e. if the encoder
162      * pipeline was created with a #VAConfigAttribRateControl
163      * attribute set to either \ref VA_RC_CBR or \ref VA_RC_VBR.
164      *
165      * The bitrate can be modified later on through
166      * #VAEncMiscParameterRateControl buffers.
167      */
168     unsigned int    bits_per_second;
169     /** \brief Same as the H.264 bitstream syntax element. */
170     unsigned int    max_num_ref_frames;
171     /** \brief Picture width in macroblocks. */
172     unsigned short  picture_width_in_mbs;
173     /** \brief Picture height in macroblocks. */
174     unsigned short  picture_height_in_mbs;
175 
176     union {
177         struct {
178             /** \brief Same as the H.264 bitstream syntax element. */
179             unsigned int chroma_format_idc                      : 2;
180             /** \brief Same as the H.264 bitstream syntax element. */
181             unsigned int frame_mbs_only_flag                    : 1;
182             /** \brief Same as the H.264 bitstream syntax element. */
183             unsigned int mb_adaptive_frame_field_flag           : 1;
184             /** \brief Same as the H.264 bitstream syntax element. */
185             unsigned int seq_scaling_matrix_present_flag        : 1;
186             /** \brief Same as the H.264 bitstream syntax element. */
187             unsigned int direct_8x8_inference_flag              : 1;
188             /** \brief Same as the H.264 bitstream syntax element. */
189             unsigned int log2_max_frame_num_minus4              : 4;
190             /** \brief Same as the H.264 bitstream syntax element. */
191             unsigned int pic_order_cnt_type                     : 2;
192             /** \brief Same as the H.264 bitstream syntax element. */
193             unsigned int log2_max_pic_order_cnt_lsb_minus4      : 4;
194             /** \brief Same as the H.264 bitstream syntax element. */
195             unsigned int delta_pic_order_always_zero_flag       : 1;
196         } bits;
197         unsigned int value;
198     } seq_fields;
199 
200     /** \brief Same as the H.264 bitstream syntax element. */
201     unsigned char   bit_depth_luma_minus8;
202     /** \brief Same as the H.264 bitstream syntax element. */
203     unsigned char   bit_depth_chroma_minus8;
204 
205     /** if pic_order_cnt_type == 1 */
206     /**@{*/
207     /** \brief Same as the H.264 bitstream syntax element. */
208     unsigned char   num_ref_frames_in_pic_order_cnt_cycle;
209     /** \brief Same as the H.264 bitstream syntax element. */
210     int             offset_for_non_ref_pic;
211     /** \brief Same as the H.264 bitstream syntax element. */
212     int             offset_for_top_to_bottom_field;
213     /** \brief Same as the H.264 bitstream syntax element. */
214     int             offset_for_ref_frame[256];
215     /**@}*/
216 
217     /** @name Cropping (optional) */
218     /**@{*/
219     /** \brief Same as the H.264 bitstream syntax element. */
220     unsigned char   frame_cropping_flag;
221     /** \brief Same as the H.264 bitstream syntax element. */
222     unsigned int    frame_crop_left_offset;
223     /** \brief Same as the H.264 bitstream syntax element. */
224     unsigned int    frame_crop_right_offset;
225     /** \brief Same as the H.264 bitstream syntax element. */
226     unsigned int    frame_crop_top_offset;
227     /** \brief Same as the H.264 bitstream syntax element. */
228     unsigned int    frame_crop_bottom_offset;
229     /**@}*/
230 
231     /** @name VUI parameters (optional) */
232     /**@{*/
233     /** \brief Same as the H.264 bitstream syntax element. */
234     unsigned char   vui_parameters_present_flag;
235     union {
236         struct {
237             /** \brief Same as the H.264 bitstream syntax element. */
238             unsigned int aspect_ratio_info_present_flag         : 1;
239             /** \brief Same as the H.264 bitstream syntax element. */
240             unsigned int timing_info_present_flag               : 1;
241             /** \brief Same as the H.264 bitstream syntax element. */
242             unsigned int bitstream_restriction_flag             : 1;
243             /** \brief Range: 0 to 16, inclusive. */
244             unsigned int log2_max_mv_length_horizontal          : 5;
245             /** \brief Range: 0 to 16, inclusive. */
246             unsigned int log2_max_mv_length_vertical            : 5;
247         } bits;
248         unsigned int value;
249     } vui_fields;
250     /** \brief Same as the H.264 bitstream syntax element. */
251     unsigned char   aspect_ratio_idc;
252     /** \brief Same as the H.264 bitstream syntax element. */
253     unsigned int    sar_width;
254     /** \brief Same as the H.264 bitstream syntax element. */
255     unsigned int    sar_height;
256     /** \brief Same as the H.264 bitstream syntax element. */
257     unsigned int    num_units_in_tick;
258     /** \brief Same as the H.264 bitstream syntax element. */
259     unsigned int    time_scale;
260     /**@}*/
261 } VAEncSequenceParameterBufferH264;
262 
263 /**
264  * \brief Picture parameter for H.264 encoding in baseline, main & high
265  * profiles.
266  *
267  * This structure holds information for \c pic_parameter_set_rbsp() as
268  * defined by the H.264 specification.
269  *
270  * If packed picture headers mode is used, i.e. if the encoding
271  * pipeline was configured with the #VA_ENC_PACKED_HEADER_PICTURE
272  * flag, then the driver expects two more buffers to be provided to
273  * the same \c vaRenderPicture() as this buffer:
274  * - a #VAEncPackedHeaderParameterBuffer with type set to
275  *   VAEncPackedHeaderType::VAEncPackedHeaderPicture ;
276  * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
277  *   header data.
278  *
279  * If \c pic_scaling_matrix_present_flag is set to \c 1, then a
280  * #VAIQMatrixBufferH264 buffer shall also be provided within the same
281  * \c vaRenderPicture() call as this picture parameter buffer.
282  */
283 typedef struct _VAEncPictureParameterBufferH264 {
284     /**
285      * \brief Information about the picture to be encoded.
286      *
287      * See #VAPictureH264 for further description of each field.
288      * Note that CurrPic.picture_id represents the reconstructed
289      * (decoded) picture. User provides a scratch VA surface ID here.
290      */
291     VAPictureH264   CurrPic;
292     /**
293      * \brief Decoded Picture Buffer (DPB).
294      *
295      * This array represents the list of reconstructed (decoded)
296      * frames used as reference. It is important to keep track of
297      * reconstructed frames so that they can be used later on as
298      * reference for P or B-frames encoding.
299      */
300     VAPictureH264   ReferenceFrames[16];
301     /**
302      * \brief Output encoded bitstream.
303      *
304      * \ref coded_buf has type #VAEncCodedBufferType. It should be
305      * large enough to hold the compressed NAL slice and possibly SPS
306      * and PPS NAL units.
307      */
308     VABufferID      coded_buf;
309 
310     /** \brief The picture parameter set referred to in the slice header. */
311     unsigned char   pic_parameter_set_id;
312     /** \brief The active sequence parameter set. Range: 0 to 31, inclusive. */
313     unsigned char   seq_parameter_set_id;
314 
315     /**
316      * \brief OR'd flags describing whether the picture is the last one or not.
317      *
318      * This fields holds 0 if the picture to be encoded is not the last
319      * one in the stream or sequence. Otherwise, it is a combination of
320      * \ref H264_LAST_PICTURE_EOSEQ or \ref H264_LAST_PICTURE_EOSTREAM.
321      */
322     unsigned char   last_picture;
323 
324     /** \brief The picture identifier.
325      *   Range: 0 to \f$2^{log2\_max\_frame\_num\_minus4 + 4} - 1\f$, inclusive.
326      */
327     unsigned short  frame_num;
328 
329     /** \brief \c pic_init_qp_minus26 + 26. */
330     unsigned char   pic_init_qp;
331     /** \brief Maximum reference index for reference picture list 0.
332      *   Range: 0 to 31, inclusive.
333      */
334     unsigned char   num_ref_idx_l0_active_minus1;
335     /** \brief Maximum reference index for reference picture list 1.
336      *  Range: 0 to 31, inclusive.
337      */
338     unsigned char   num_ref_idx_l1_active_minus1;
339 
340     /** \brief Range: -12 to 12, inclusive. */
341     signed char     chroma_qp_index_offset;
342     /** \brief Range: -12 to 12, inclusive. */
343     signed char     second_chroma_qp_index_offset;
344 
345     union {
346         struct {
347             /** \brief Is picture an IDR picture? */
348             unsigned int idr_pic_flag                           : 1;
349             /** \brief Is picture a reference picture? */
350             unsigned int reference_pic_flag                     : 2;
351             /** \brief Selects CAVLC (0) or CABAC (1) entropy coding mode. */
352             unsigned int entropy_coding_mode_flag               : 1;
353             /** \brief Is weighted prediction applied to P slices? */
354             unsigned int weighted_pred_flag                     : 1;
355             /** \brief Range: 0 to 2, inclusive. */
356             unsigned int weighted_bipred_idc                    : 2;
357             /** \brief Same as the H.264 bitstream syntax element. */
358             unsigned int constrained_intra_pred_flag            : 1;
359             /** \brief Same as the H.264 bitstream syntax element. */
360             unsigned int transform_8x8_mode_flag                : 1;
361             /** \brief Same as the H.264 bitstream syntax element. */
362             unsigned int deblocking_filter_control_present_flag : 1;
363             /** \brief Same as the H.264 bitstream syntax element. */
364             unsigned int redundant_pic_cnt_present_flag         : 1;
365             /** \brief Same as the H.264 bitstream syntax element. */
366             unsigned int pic_order_present_flag                 : 1;
367             /** \brief Same as the H.264 bitstream syntax element. */
368             unsigned int pic_scaling_matrix_present_flag        : 1;
369         } bits;
370         unsigned int value;
371     } pic_fields;
372 } VAEncPictureParameterBufferH264;
373 
374 /**
375  * \brief Slice parameter for H.264 encoding in baseline, main & high profiles.
376  *
377  * This structure holds information for \c
378  * slice_layer_without_partitioning_rbsp() as defined by the H.264
379  * specification.
380  *
381  * If packed slice headers mode is used, i.e. if the encoding
382  * pipeline was configured with the #VA_ENC_PACKED_HEADER_SLICE
383  * flag, then the driver expects two more buffers to be provided to
384  * the same \c vaRenderPicture() as this buffer:
385  * - a #VAEncPackedHeaderParameterBuffer with type set to
386  *   VAEncPackedHeaderType::VAEncPackedHeaderSlice ;
387  * - a #VAEncPackedHeaderDataBuffer which holds the actual packed
388  *   header data.
389  *
390  * If per-macroblock encoder configuration is needed, \c macroblock_info
391  * references a buffer of type #VAEncMacroblockParameterBufferH264. This
392  * buffer is not passed to vaRenderPicture(). i.e. it is not destroyed
393  * by subsequent calls to vaRenderPicture() and then can be re-used
394  * without re-allocating the whole buffer.
395  */
396 typedef struct _VAEncSliceParameterBufferH264 {
397     /** \brief Starting MB address for this slice. */
398     unsigned int    macroblock_address;
399     /** \brief Number of macroblocks in this slice. */
400     unsigned int    num_macroblocks;
401     /**
402      * \brief Per-MB encoder configuration buffer, or \c VA_INVALID_ID.
403      *
404      * If per-MB encoder configuration is needed, then \ref macroblock_info
405      * references a buffer of type #VAEncMacroblockParameterBufferH264
406      * (\c VAEncMacroblockParameterBufferType). Otherwise, buffer id
407      * is set to \c VA_INVALID_ID and per-MB configuration is derived
408      * from this slice parameter.
409      *
410      * The \c macroblock_info buffer must hold \ref num_macroblocks
411      * elements.
412      */
413     VABufferID      macroblock_info;
414     /** \brief Slice type.
415      *  Range: 0..2, 5..7, i.e. no switching slices.
416      */
417     unsigned char   slice_type;
418     /** \brief Same as the H.264 bitstream syntax element. */
419     unsigned char   pic_parameter_set_id;
420     /** \brief Same as the H.264 bitstream syntax element. */
421     unsigned short  idr_pic_id;
422 
423     /** @name If pic_order_cnt_type == 0 */
424     /**@{*/
425     /** \brief The picture order count modulo MaxPicOrderCntLsb. */
426     unsigned short  pic_order_cnt_lsb;
427     /** \brief Valid if \c pic_order_present_flag and this is a bottom field. */
428     int             delta_pic_order_cnt_bottom;
429     /**@}*/
430     /** @name If pic_order_cnt_type == 1 && !delta_pic_order_always_zero_flag */
431     /**@{*/
432     /** \brief [0]: top, [1]: bottom. */
433     int             delta_pic_order_cnt[2];
434     /**@}*/
435 
436     /** @name If slice_type == B */
437     /**@{*/
438     unsigned char   direct_spatial_mv_pred_flag;
439     /**@}*/
440 
441     /** @name If slice_type == P */
442     /**@{*/
443     /** \brief Specifies if
444      * \ref _VAEncPictureParameterBufferH264::num_ref_idx_l0_active_minus1 or
445      * \ref _VAEncPictureParameterBufferH264::num_ref_idx_l1_active_minus1 are
446      * overriden by the values for this slice.
447      */
448     unsigned char   num_ref_idx_active_override_flag;
449     /** \brief Maximum reference index for reference picture list 0.
450      *  Range: 0 to 31, inclusive.
451      */
452     unsigned char   num_ref_idx_l0_active_minus1;
453     /** \brief Maximum reference index for reference picture list 1.
454      *  Range: 0 to 31, inclusive.
455      */
456     unsigned char   num_ref_idx_l1_active_minus1;
457     /** \brief Reference picture list 0 (for P slices). */
458     VAPictureH264   RefPicList0[32];
459     /** \brief Reference picture list 1 (for B slices). */
460     VAPictureH264   RefPicList1[32];
461     /**@}*/
462 
463     /** @name pred_weight_table() */
464     /**@{*/
465     /** \brief Same as the H.264 bitstream syntax element. */
466     unsigned char   luma_log2_weight_denom;
467     /** \brief Same as the H.264 bitstream syntax element. */
468     unsigned char   chroma_log2_weight_denom;
469     /** \brief Same as the H.264 bitstream syntax element. */
470     unsigned char   luma_weight_l0_flag;
471     /** \brief Same as the H.264 bitstream syntax element. */
472     signed short    luma_weight_l0[32];
473     /** \brief Same as the H.264 bitstream syntax element. */
474     signed short    luma_offset_l0[32];
475     /** \brief Same as the H.264 bitstream syntax element. */
476     unsigned char   chroma_weight_l0_flag;
477     /** \brief Same as the H.264 bitstream syntax element. */
478     signed short    chroma_weight_l0[32][2];
479     /** \brief Same as the H.264 bitstream syntax element. */
480     signed short    chroma_offset_l0[32][2];
481     /** \brief Same as the H.264 bitstream syntax element. */
482     unsigned char   luma_weight_l1_flag;
483     /** \brief Same as the H.264 bitstream syntax element. */
484     signed short    luma_weight_l1[32];
485     /** \brief Same as the H.264 bitstream syntax element. */
486     signed short    luma_offset_l1[32];
487     /** \brief Same as the H.264 bitstream syntax element. */
488     unsigned char   chroma_weight_l1_flag;
489     /** \brief Same as the H.264 bitstream syntax element. */
490     signed short    chroma_weight_l1[32][2];
491     /** \brief Same as the H.264 bitstream syntax element. */
492     signed short    chroma_offset_l1[32][2];
493     /**@}*/
494 
495     /** \brief Range: 0 to 2, inclusive. */
496     unsigned char   cabac_init_idc;
497     /** \brief Same as the H.264 bitstream syntax element. */
498     signed char     slice_qp_delta;
499     /** @name If deblocking_filter_control_present_flag */
500     /**@{*/
501     /** \brief Range: 0 to 2, inclusive. */
502     unsigned char   disable_deblocking_filter_idc;
503     /** \brief Same as the H.264 bitstream syntax element. */
504     signed char     slice_alpha_c0_offset_div2;
505     /** \brief Same as the H.264 bitstream syntax element. */
506     signed char     slice_beta_offset_div2;
507     /**@}*/
508 } VAEncSliceParameterBufferH264;
509 
510 /**
511  * @name Macroblock neighbour availability bits
512  *
513  * \anchor api_enc_h264_mb_pred_avail_bits
514  * Definitions for macroblock neighbour availability bits used in
515  * intra prediction mode (non MBAFF only).
516  *
517  * @{
518  */
519 /** \brief References macroblock in the top-left corner. */
520 #define VA_MB_PRED_AVAIL_TOP_LEFT         (1 << 2)
521 /** \brief References macroblock above the current macroblock. */
522 #define VA_MB_PRED_AVAIL_TOP              (1 << 4)
523 /** \brief References macroblock in the top-right corner. */
524 #define VA_MB_PRED_AVAIL_TOP_RIGHT        (1 << 3)
525 /** \brief References macroblock on the left of the current macroblock. */
526 #define VA_MB_PRED_AVAIL_LEFT             (1 << 6)
527 /**@}*/
528 
529 /**
530  * \brief Macroblock parameter for H.264 encoding in baseline, main & high
531  * profiles.
532  *
533  * This structure holds per-macroblock information. The buffer must be
534  * allocated with as many elements (macroblocks) as necessary to fit
535  * the slice to be encoded. Besides, the per-macroblock records must
536  * be written in a strict raster order and with no gap. i.e. every
537  * macroblock, regardless of its type, shall have an entry.
538  */
539 typedef struct _VAEncMacroblockParameterBufferH264 {
540     /**
541      * \brief Quantization parameter.
542      *
543      * Requested quantization parameter. Range: 0 to 51, inclusive.
544      * If \ref qp is set to 0xff, then the actual value is derived
545      * from the slice-level value: \c pic_init_qp + \c slice_qp_delta.
546      */
547     unsigned char   qp;
548 
549     union {
550         /** @name Data for intra macroblock */
551         /**@{*/
552         struct {
553             union {
554                 /**
555                  * \brief Flag specified to override MB neighbour
556                  * availability bits from VME stage.
557                  *
558                  * This flag specifies that macroblock neighbour
559                  * availability bits from the VME stage are overriden
560                  * by the \ref pred_avail_flags hereunder.
561                  */
562                 unsigned int    pred_avail_override_flag        : 1;
563                 /**
564                  * \brief Bitwise representation of which macroblocks
565                  * are available for intra prediction.
566                  *
567                  * If the slice is intra-coded, this field represents
568                  * the macroblocks available for intra prediction.
569                  * See \ref api_enc_h264_mb_pred_avail_bits
570                  * "macroblock neighbour availability" bit definitions.
571                  */
572                 unsigned int    pred_avail_flags                : 8;
573             } bits;
574             unsigned int value;
575         } intra_fields;
576         /**@}*/
577 
578         /** @name Data for inter macroblock */
579         /**@{*/
580         struct {
581             union {
582             } bits;
583             unsigned int value;
584         } inter_fields;
585         /**@}*/
586     } info;
587 } VAEncMacroblockParameterBufferH264;
588 
589 /**
590  * \brief H.264 Mutiview Coding(MVC) Sequence Parameter Buffer
591  *
592  */
593 typedef struct _VAEncSequenceParameterBufferH264_MVC {
594     /** brief Basic common sequence parameter */
595     VAEncSequenceParameterBufferH264 base;
596 
597     /** brief Plus 1 specify the max number of views
598      * coded in the video sequence
599      */
600     uint16_t num_views_minus1;
601 
602     /** brief Specify the view information in all layers */
603     struct H264SPSExtMVCViewInfo{
604         /** \brief The current view identifier. */
605         uint16_t view_id;
606         /** \brief Specifies the number of view components for inter-view
607          * prediction in the initialized RefPicList0 in decoding
608          * anchor views.
609          */
610         uint8_t  num_anchor_refs_l0;
611         /** \brief Specifies the view_id for inter-view prediction in
612          * the initialized RefPicList0 in decoding anchor views.
613          */
614         uint16_t anchor_ref_l0[15];
615         /** \brief Specifies the number of view components for inter-view
616          * prediction in the initialized RefPicList1 in decoding
617          * anchor views
618          */
619         uint8_t  num_anchor_refs_l1;
620         /** \brief Specifies the view_id for inter-view prediction in
621          * the initialized RefPicList1 in decoding anchor views.
622          */
623         uint16_t anchor_ref_l1[15];
624         /** \brief Specifies the number of view components for inter-view
625          * prediction in the initialized RefPicList0 in decoding
626          * non-anchor views.
627          */
628         uint8_t  num_non_anchor_refs_l0;
629         /** \brief Specifies the view_id for inter-view prediction in
630          * the initialized RefPicList0 in decoding non-anchor views.
631          */
632         uint16_t non_anchor_ref_l0[15];
633         /** \brief Specifies the number of view components for inter-view
634          * prediction in the initialized RefPicList1 in decoding
635          * non-anchor view.
636          */
637         uint8_t  num_non_anchor_refs_l1;
638         /** \brief Specifies the view_id for inter-view prediction in
639          * the initialized RefPicList1 in decoding non-anchor views.
640          */
641         uint16_t non_anchor_ref_l1[15];
642     }* view_list;
643 
644     /** brief Plus 1 specifies the number of level values
645      * signalled for the coded video sequence
646      */
647     uint8_t num_level_values_signalled_minus1;
648 
649     /** brief Level values operation for a set of the operation
650      * points in the current sequence
651      */
652     struct H264SPSExtMVCLevelValue {
653         /** \brief Specifies the level value signalled for the coded video sequence */
654         uint8_t level_idc;
655 
656         /** \brief Plus 1 specifies the number of operation points to
657          *  which the level indicated by level_idc applies
658          */
659         uint16_t num_applicable_ops_minus1;
660 
661         /** \brief Represent the specific operation to the view in the video sequence */
662         struct H264SPSExtMVCLevelValueOps {
663             /** \brief Specify a temporal identifier for the NAL unit */
664             uint8_t   temporal_id;
665             /** \brief Specify the number of the views whose level value will be modified */
666             uint16_t  num_target_views_minus1;
667             /** \brief Specify the views whose level value will be modified */
668             uint16_t* target_view_id_list;
669             /** \brief Specify the number of views whose level value can be modified */
670             uint16_t  num_views_minus1;
671         }* level_value_ops_list;
672 
673     }* level_value_list;
674 
675 } VAEncSequenceParameterBufferH264_MVC;
676 
677 /**
678  * \brief H.264 Multiview Coding(MVC) Picture Parameter Buffer
679  *
680  */
681 typedef struct _VAEncPictureParameterBufferH264_MVC
682 {
683     /** brief Basic common picture parameter */
684     VAEncPictureParameterBufferH264 base;
685 
686     /** brief Specifes the view id for current picture */
687     uint16_t view_id;
688 
689     /** brief Specifes whether the picture is one anchor picture */
690     uint8_t  anchor_pic_flag;
691 
692     /** brief Specifes whether inter view reference frame
693      * is used to encode current picture.
694      */
695     uint8_t  inter_view_flag;
696 } VAEncPictureParameterBufferH264_MVC;
697 
698 typedef struct _VAEncQpBufferH264 {
699     /*
700      * \brief This structure holds luma Qp per 16x16 macroblock. Buffer size shall be
701      * sufficient to fit the slice or frame to be encoded depending on if it is a slice level
702      * or frame level encoding.
703      */
704     unsigned char qp_y;
705 } VAEncQpBufferH264;
706 
707 /** \brief Bitstream writer attribute types specific to H.264 encoding. */
708 typedef enum {
709     /**
710      * \brief Flag: specifies whether to insert emulation prevention
711      * bytes (integer).
712      */
713     VAEncBitstreamAttribEmulationPreventionH264 = (
714         VAEncBitstreamAttribMiscMask | 1),
715 } VAEncBitstreamAttribTypeH264;
716 
717 
718 /**
719  * \brief Allocates a new H.264 bitstream writer.
720  *
721  * Allocates a new bitstream writer. By default, libva allocates and
722  * maintains its own buffer. However, the user can pass down his own
723  * buffer with the \c VAEncBitstreamAttribBuffer attribute, along with
724  * the size of that buffer with the \c VAEncBitstreamAttribBufferSize
725  * attribute.
726  *
727  * By default, emulation prevention bytes are not inserted. However,
728  * the user can still request emulation prevention by setting the
729  * \c VAEncBitstreamAttribEmulationPreventionH264 attribute to 1.
730  *
731  * @param[in] attribs       the optional attributes, or NULL
732  * @param[in] num_attribs   the number of attributes available in \c attribs
733  * @return a new #VAEncBitstream, or NULL if an error occurred
734  */
735 VAEncBitstream *
736 va_enc_bitstream_h264_new(
737     VAEncBitstreamAttrib *attribs,
738     unsigned int          num_attribs
739 );
740 
741 /**
742  * \brief Destroys an H.264 bitstream writer.
743  *
744  * @param[in] bs            the bitstream writer to destroy
745  */
746 void
747 va_enc_bitstream_h264_destroy(VAEncBitstream *bs);
748 
749 /**
750  * \brief Writes an unsigned integer as \c ue(v).
751  *
752  * Writes a 32-bit unsigned int value by following \c ue(v) from the
753  * H.264 specification.
754  *
755  * @param[in] bs            the bitstream writer
756  * @param[in] value         the unsigned int value
757  * @return the number of bits written, or a negative value to indicate an error
758  */
759 int
760 va_enc_bitstream_h264_write_ue(VAEncBitstream *bs, unsigned int value);
761 
762 /**
763  * \brief Writes a signed integer as \c se(v).
764  *
765  * Writes a 32-bit signed int value by following \c se(v) from the
766  * H.264 specification.
767  *
768  * @param[in] bs            the bitstream writer
769  * @param[in] value         the signed int value
770  * @return the number of bits written, or a negative value to indicate an error
771  */
772 int
773 va_enc_bitstream_h264_write_se(VAEncBitstream *bs, int value);
774 
775 /**
776  * \brief Helper function to write trailing bits into the bitstream.
777  *
778  * @param[in] bs            the bitstream writer
779  * @return the number of bits written, or a negative value to indicate an error
780  */
781 int
782 va_enc_bitstream_h264_write_trailing_bits(VAEncBitstream *bs);
783 
784 /**@}*/
785 
786 #ifdef __cplusplus
787 }
788 #endif
789 
790 #endif /* VA_ENC_H264_H */
791