import ext/codecparsers instead of git submodule
[profile/ivi/gstreamer-vaapi.git] / ext / codecparsers / gst-libs / gst / codecparsers / gsth264parser.h
1 /* Gstreamer
2  * Copyright (C) <2011> Intel Corporation
3  * Copyright (C) <2011> Collabora Ltd.
4  * Copyright (C) <2011> Thibault Saunier <thibault.saunier@collabora.com>
5  *
6  * Some bits C-c,C-v'ed and s/4/3 from h264parse and videoparsers/h264parse.c:
7  *    Copyright (C) <2010> Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
8  *    Copyright (C) <2010> Collabora Multimedia
9  *    Copyright (C) <2010> Nokia Corporation
10  *
11  *    (C) 2005 Michal Benes <michal.benes@itonis.tv>
12  *    (C) 2008 Wim Taymans <wim.taymans@gmail.com>
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Library General Public
16  * License as published by the Free Software Foundation; either
17  * version 2 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22  * Library General Public License for more details.
23  *
24  * You should have received a copy of the GNU Library General Public
25  * License along with this library; if not, write to the
26  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
27  * Boston, MA 02110-1301, USA.
28  */
29
30 #ifndef __GST_H264_PARSER_H__
31 #define __GST_H264_PARSER_H__
32
33 #ifndef GST_USE_UNSTABLE_API
34 #warning "The H.264 parsing library is unstable API and may change in future."
35 #warning "You can define GST_USE_UNSTABLE_API to avoid this warning."
36 #endif
37
38 #include <gst/gst.h>
39
40 G_BEGIN_DECLS
41
42 #define GST_H264_MAX_SPS_COUNT   32
43 #define GST_H264_MAX_PPS_COUNT   256
44
45 #define GST_H264_IS_P_SLICE(slice)  (((slice)->type % 5) == GST_H264_P_SLICE)
46 #define GST_H264_IS_B_SLICE(slice)  (((slice)->type % 5) == GST_H264_B_SLICE)
47 #define GST_H264_IS_I_SLICE(slice)  (((slice)->type % 5) == GST_H264_I_SLICE)
48 #define GST_H264_IS_SP_SLICE(slice) (((slice)->type % 5) == GST_H264_SP_SLICE)
49 #define GST_H264_IS_SI_SLICE(slice) (((slice)->type % 5) == GST_H264_SI_SLICE)
50
51 /**
52  * GstH264NalUnitType:
53  * @GST_H264_NAL_UNKNOWN: Unknown nal type
54  * @GST_H264_NAL_SLICE: Slice nal
55  * @GST_H264_NAL_SLICE_DPA: DPA slice nal
56  * @GST_H264_NAL_SLICE_DPB: DPB slice nal
57  * @GST_H264_NAL_SLICE_DPC: DPC slice nal
58  * @GST_H264_NAL_SLICE_IDR: DPR slice nal
59  * @GST_H264_NAL_SEI: Supplemental enhancement information (SEI) nal unit
60  * @GST_H264_NAL_SPS: Sequence parameter set (SPS) nal unit
61  * @GST_H264_NAL_PPS: Picture parameter set (PPS) nal unit
62  * @GST_H264_NAL_AU_DELIMITER: Access unit (AU) delimiter nal unit
63  * @GST_H264_NAL_SEQ_END: End of sequence nal unit
64  * @GST_H264_NAL_STREAM_END: End of stream nal unit
65  * @GST_H264_NAL_FILLER_DATA: Filler data nal lunit
66  *
67  * Indicates the type of H264 Nal Units
68  */
69 typedef enum
70 {
71   GST_H264_NAL_UNKNOWN      = 0,
72   GST_H264_NAL_SLICE        = 1,
73   GST_H264_NAL_SLICE_DPA    = 2,
74   GST_H264_NAL_SLICE_DPB    = 3,
75   GST_H264_NAL_SLICE_DPC    = 4,
76   GST_H264_NAL_SLICE_IDR    = 5,
77   GST_H264_NAL_SEI          = 6,
78   GST_H264_NAL_SPS          = 7,
79   GST_H264_NAL_PPS          = 8,
80   GST_H264_NAL_AU_DELIMITER = 9,
81   GST_H264_NAL_SEQ_END      = 10,
82   GST_H264_NAL_STREAM_END   = 11,
83   GST_H264_NAL_FILLER_DATA  = 12
84 } GstH264NalUnitType;
85
86 /**
87  * GstH264ParserResult:
88  * @GST_H264_PARSER_OK: The parsing succeded
89  * @GST_H264_PARSER_BROKEN_DATA: The data to parse is broken
90  * @GST_H264_PARSER_BROKEN_LINK: The link to structure needed for the parsing couldn't be found
91  * @GST_H264_PARSER_ERROR: An error accured when parsing
92  * @GST_H264_PARSER_NO_NAL: No nal found during the parsing
93  * @GST_H264_PARSER_NO_NAL_END: Start of the nal found, but not the end.
94  *
95  * The result of parsing H264 data.
96  */
97 typedef enum
98 {
99   GST_H264_PARSER_OK,
100   GST_H264_PARSER_BROKEN_DATA,
101   GST_H264_PARSER_BROKEN_LINK,
102   GST_H264_PARSER_ERROR,
103   GST_H264_PARSER_NO_NAL,
104   GST_H264_PARSER_NO_NAL_END
105 } GstH264ParserResult;
106
107 /**
108  * GstH264SEIPayloadType:
109  * @GST_H264_SEI_BUF_PERIOD: Buffering Period SEI Message
110  * @GST_H264_SEI_PIC_TIMING: Picture Timing SEI Message
111  * ...
112  *
113  * The type of SEI message.
114  */
115 typedef enum
116 {
117   GST_H264_SEI_BUF_PERIOD = 0,
118   GST_H264_SEI_PIC_TIMING = 1
119       /* and more...  */
120 } GstH264SEIPayloadType;
121
122 /**
123  * GstH264SEIPicStructType:
124  * @GST_H264_SEI_PIC_STRUCT_FRAME: Picture is a frame
125  * @GST_H264_SEI_PIC_STRUCT_TOP_FIELD: Top field of frame
126  * @GST_H264_SEI_PIC_STRUCT_BOTTOM_FIELD: Botom field of frame
127  * @GST_H264_SEI_PIC_STRUCT_TOP_BOTTOM: Top bottom field of frame
128  * @GST_H264_SEI_PIC_STRUCT_BOTTOM_TOP: bottom top field of frame
129  * @GST_H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP: top bottom top field of frame
130  * @GST_H264_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM: bottom top bottom field of frame
131  * @GST_H264_SEI_PIC_STRUCT_FRAME_DOUBLING: indicates that the frame should
132  *  be displayed two times consecutively
133  * @GST_H264_SEI_PIC_STRUCT_FRAME_TRIPLING: indicates that the frame should be
134  *  displayed three times consecutively
135  *
136  * SEI pic_struct type
137  */
138 typedef enum
139 {
140   GST_H264_SEI_PIC_STRUCT_FRAME             = 0,
141   GST_H264_SEI_PIC_STRUCT_TOP_FIELD         = 1,
142   GST_H264_SEI_PIC_STRUCT_BOTTOM_FIELD      = 2,
143   GST_H264_SEI_PIC_STRUCT_TOP_BOTTOM        = 3,
144   GST_H264_SEI_PIC_STRUCT_BOTTOM_TOP        = 4,
145   GST_H264_SEI_PIC_STRUCT_TOP_BOTTOM_TOP    = 5,
146   GST_H264_SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM = 6,
147   GST_H264_SEI_PIC_STRUCT_FRAME_DOUBLING    = 7,
148   GST_H264_SEI_PIC_STRUCT_FRAME_TRIPLING    = 8
149 } GstH264SEIPicStructType;
150
151 /**
152  * GstH264SliceType:
153  *
154  * Type of Picture slice
155  */
156
157 typedef enum
158 {
159   GST_H264_P_SLICE    = 0,
160   GST_H264_B_SLICE    = 1,
161   GST_H264_I_SLICE    = 2,
162   GST_H264_SP_SLICE   = 3,
163   GST_H264_SI_SLICE   = 4,
164   GST_H264_S_P_SLICE  = 5,
165   GST_H264_S_B_SLICE  = 6,
166   GST_H264_S_I_SLICE  = 7,
167   GST_H264_S_SP_SLICE = 8,
168   GST_H264_S_SI_SLICE = 9
169 } GstH264SliceType;
170
171 typedef struct _GstH264NalParser              GstH264NalParser;
172
173 typedef struct _GstH264NalUnit                GstH264NalUnit;
174
175 typedef struct _GstH264SPS                    GstH264SPS;
176 typedef struct _GstH264PPS                    GstH264PPS;
177 typedef struct _GstH264HRDParams              GstH264HRDParams;
178 typedef struct _GstH264VUIParams              GstH264VUIParams;
179
180 typedef struct _GstH264RefPicListModification GstH264RefPicListModification;
181 typedef struct _GstH264DecRefPicMarking       GstH264DecRefPicMarking;
182 typedef struct _GstH264RefPicMarking          GstH264RefPicMarking;
183 typedef struct _GstH264PredWeightTable        GstH264PredWeightTable;
184 typedef struct _GstH264SliceHdr               GstH264SliceHdr;
185
186 typedef struct _GstH264ClockTimestamp         GstH264ClockTimestamp;
187 typedef struct _GstH264PicTiming              GstH264PicTiming;
188 typedef struct _GstH264BufferingPeriod        GstH264BufferingPeriod;
189 typedef struct _GstH264SEIMessage             GstH264SEIMessage;
190
191 /**
192  * GstH264NalUnit:
193  * @ref_idc: not equal to 0 specifies that the content of the NAL unit contains a sequence
194  *  parameter set, a sequence * parameter set extension, a subset sequence parameter set, a
195  *  picture parameter set, a slice of a reference picture, a slice data partition of a
196  *  reference picture, or a prefix NAL unit preceding a slice of a reference picture.
197  * @type: A #GstH264NalUnitType
198  * @idr_pic_flag: calculated idr_pic_flag
199  * @size: The size of the nal unit starting from @offset
200  * @offset: The offset of the actual start of the nal unit
201  * @sc_offset:The offset of the start code of the nal unit
202  * @valid: If the nal unit is valid, which mean it has
203  * already been parsed
204  * @data: The data from which the Nalu has been parsed
205  *
206  * Structure defining the Nal unit headers
207  */
208 struct _GstH264NalUnit
209 {
210   guint16 ref_idc;
211   guint16 type;
212
213   /* calculated values */
214   guint8 idr_pic_flag;
215   guint size;
216   guint offset;
217   guint sc_offset;
218   gboolean valid;
219
220   guint8 *data;
221 };
222
223 /**
224  * GstH264HRDParams:
225  * @cpb_cnt_minus1: plus 1 specifies the number of alternative
226  *    CPB specifications in the bitstream
227  * @bit_rate_scale: specifies the maximum input bit rate of the
228  * SchedSelIdx-th CPB
229  * @cpb_size_scale: specifies the CPB size of the SchedSelIdx-th CPB
230  * @guint32 bit_rate_value_minus1: specifies the maximum input bit rate for the
231  * SchedSelIdx-th CPB
232  * @cpb_size_value_minus1: is used together with cpb_size_scale to specify the
233  * SchedSelIdx-th CPB size
234  * @cbr_flag: Specifies if running in itermediate bitrate mode or constant
235  * @initial_cpb_removal_delay_length_minus1: specifies the length in bits of
236  * the cpb_removal_delay syntax element
237  * @cpb_removal_delay_length_minus1: specifies the length in bits of the
238  * dpb_output_delay syntax element
239  * @dpb_output_delay_length_minus1: >0 specifies the length in bits of the time_offset syntax element.
240  * =0 specifies that the time_offset syntax element is not present
241  * @time_offset_length: Length of the time offset
242  *
243  * Defines the HRD parameters
244  */
245 struct _GstH264HRDParams
246 {
247   guint8 cpb_cnt_minus1;
248   guint8 bit_rate_scale;
249   guint8 cpb_size_scale;
250
251   guint32 bit_rate_value_minus1[32];
252   guint32 cpb_size_value_minus1[32];
253   guint8 cbr_flag[32];
254
255   guint8 initial_cpb_removal_delay_length_minus1;
256   guint8 cpb_removal_delay_length_minus1;
257   guint8 dpb_output_delay_length_minus1;
258   guint8 time_offset_length;
259 };
260
261 /**
262  * GstH264VUIParams:
263  * @aspect_ratio_info_present_flag: %TRUE specifies that aspect_ratio_idc is present.
264  *  %FALSE specifies that aspect_ratio_idc is not present
265  * @aspect_ratio_idc specifies the value of the sample aspect ratio of the luma samples
266  * @sar_width indicates the horizontal size of the sample aspect ratio
267  * @sar_height indicates the vertical size of the sample aspect ratio
268  * @overscan_info_present_flag: %TRUE overscan_appropriate_flag is present %FALSE otherwize
269  * @overscan_appropriate_flag: %TRUE indicates that the cropped decoded pictures
270  *  output are suitable for display using overscan. %FALSE the cropped decoded pictures
271  *  output contain visually important information
272  * @video_signal_type_present_flag: %TRUE specifies that video_format, video_full_range_flag and
273  *  colour_description_present_flag are present.
274  * @video_format: indicates the representation of the picture
275  * @video_full_range_flag: indicates the black level and range of the luma and chroma signals
276  * @colour_description_present_flag: %TRUE specifies that colour_primaries,
277  *  transfer_characteristics and matrix_coefficients are present
278  * @colour_primaries: indicates the chromaticity coordinates of the source primaries
279  * @transfer_characteristics: indicates the opto-electronic transfer characteristic
280  * @matrix_coefficients: describes the matrix coefficients used in deriving luma and chroma signals
281  * @chroma_loc_info_present_flag: %TRUE specifies that chroma_sample_loc_type_top_field and
282  *  chroma_sample_loc_type_bottom_field are present, %FALSE otherwize
283  * @chroma_sample_loc_type_top_field: specify the location of chroma for top field
284  * @chroma_sample_loc_type_bottom_field specify the location of chroma for bottom field
285  * @timing_info_present_flag: %TRUE specifies that num_units_in_tick,
286  *  time_scale and fixed_frame_rate_flag are present in the bitstream
287  * @num_units_in_tick: is the number of time units of a clock operating at the frequency time_scale Hz
288  * time_scale: is the number of time units that pass in one second
289  * @fixed_frame_rate_flag: %TRUE indicates that the temporal distance between the HRD output times
290  *  of any two consecutive pictures in output order is constrained as specified in the spec, %FALSE
291  *  otherwize.
292  * @nal_hrd_parameters_present_flag: %TRUE if nal hrd parameters present in the bitstream
293  * @vcl_hrd_parameters_present_flag: %TRUE if nal vlc hrd parameters present in the bitstream
294  * @low_delay_hrd_flag: specifies the HRD operational mode
295  * @pic_struct_present_flag: %TRUE specifies that picture timing SEI messages are present or not
296  * @bitstream_restriction_flag: %TRUE specifies that the following coded video sequence bitstream restriction
297  * parameters are present
298  * @motion_vectors_over_pic_boundaries_flag: %FALSE indicates that no sample outside the
299  *  picture boundaries and no sample at a fractional sample position, %TRUE indicates that one or more
300  *  samples outside picture boundaries may be used in inter prediction
301  * @max_bytes_per_pic_denom: indicates a number of bytes not exceeded by the sum of the sizes of
302  *  the VCL NAL units associated with any coded picture in the coded video sequence.
303  * @max_bits_per_mb_denom: indicates the maximum number of coded bits of macroblock_layer
304  * @log2_max_mv_length_horizontal: indicate the maximum absolute value of a decoded horizontal
305  * motion vector component
306  * @log2_max_mv_length_vertical: indicate the maximum absolute value of a decoded vertical
307  *  motion vector component
308  * @num_reorder_frames: indicates the maximum number of frames, complementary field pairs,
309  *  or non-paired fields that precede any frame,
310  * @max_dec_frame_buffering: specifies the required size of the HRD decoded picture buffer in
311  *  units of frame buffers.
312  *
313  * The structure representing the VUI parameters.
314  */
315 struct _GstH264VUIParams
316 {
317   guint8 aspect_ratio_info_present_flag;
318   guint8 aspect_ratio_idc;
319   /* if aspect_ratio_idc == 255 */
320   guint16 sar_width;
321   guint16 sar_height;
322
323   guint8 overscan_info_present_flag;
324   /* if overscan_info_present_flag */
325   guint8 overscan_appropriate_flag;
326
327   guint8 video_signal_type_present_flag;
328   guint8 video_format;
329   guint8 video_full_range_flag;
330   guint8 colour_description_present_flag;
331   guint8 colour_primaries;
332   guint8 transfer_characteristics;
333   guint8 matrix_coefficients;
334
335   guint8 chroma_loc_info_present_flag;
336   guint8 chroma_sample_loc_type_top_field;
337   guint8 chroma_sample_loc_type_bottom_field;
338
339   guint8 timing_info_present_flag;
340   /* if timing_info_present_flag */
341   guint32 num_units_in_tick;
342   guint32 time_scale;
343   guint8 fixed_frame_rate_flag;
344
345   guint8 nal_hrd_parameters_present_flag;
346   /* if nal_hrd_parameters_present_flag */
347   GstH264HRDParams nal_hrd_parameters;
348
349   guint8 vcl_hrd_parameters_present_flag;
350   /* if nal_hrd_parameters_present_flag */
351   GstH264HRDParams vcl_hrd_parameters;
352
353   guint8 low_delay_hrd_flag;
354   guint8 pic_struct_present_flag;
355
356   guint8 bitstream_restriction_flag;
357   /*  if bitstream_restriction_flag */
358   guint8 motion_vectors_over_pic_boundaries_flag;
359   guint32 max_bytes_per_pic_denom;
360   guint32 max_bits_per_mb_denom;
361   guint32 log2_max_mv_length_horizontal;
362   guint32 log2_max_mv_length_vertical;
363   guint32 num_reorder_frames;
364   guint32 max_dec_frame_buffering;
365
366   /* calculated values */
367   guint par_n;
368   guint par_d;
369 };
370
371 /**
372  * GstH264SPS:
373  * @id: The ID of the sequence parameter set
374  * @profile_idc: indicate the profile to which the coded video sequence conforms
375  *
376  * H264 Sequence Parameter Set (SPS)
377  */
378 struct _GstH264SPS
379 {
380   gint id;
381
382   guint8 profile_idc;
383   guint8 constraint_set0_flag;
384   guint8 constraint_set1_flag;
385   guint8 constraint_set2_flag;
386   guint8 constraint_set3_flag;
387   guint8 level_idc;
388
389   guint8 chroma_format_idc;
390   guint8 separate_colour_plane_flag;
391   guint8 bit_depth_luma_minus8;
392   guint8 bit_depth_chroma_minus8;
393   guint8 qpprime_y_zero_transform_bypass_flag;
394
395   guint8 scaling_matrix_present_flag;
396   guint8 scaling_lists_4x4[6][16];
397   guint8 scaling_lists_8x8[6][64];
398
399   guint8 log2_max_frame_num_minus4;
400   guint8 pic_order_cnt_type;
401
402   /* if pic_order_cnt_type == 0 */
403   guint8 log2_max_pic_order_cnt_lsb_minus4;
404
405   /* else if pic_order_cnt_type == 1 */
406   guint8 delta_pic_order_always_zero_flag;
407   gint32 offset_for_non_ref_pic;
408   gint32 offset_for_top_to_bottom_field;
409   guint8 num_ref_frames_in_pic_order_cnt_cycle;
410   gint32 offset_for_ref_frame[255];
411
412   guint32 num_ref_frames;
413   guint8 gaps_in_frame_num_value_allowed_flag;
414   guint32 pic_width_in_mbs_minus1;
415   guint32 pic_height_in_map_units_minus1;
416   guint8 frame_mbs_only_flag;
417
418   guint8 mb_adaptive_frame_field_flag;
419
420   guint8 direct_8x8_inference_flag;
421
422   guint8 frame_cropping_flag;
423
424   /* if frame_cropping_flag */
425   guint32 frame_crop_left_offset;
426   guint32 frame_crop_right_offset;
427   guint32 frame_crop_top_offset;
428   guint32 frame_crop_bottom_offset;
429
430   guint8 vui_parameters_present_flag;
431   /* if vui_parameters_present_flag */
432  GstH264VUIParams vui_parameters;
433
434   /* calculated values */
435   guint8 chroma_array_type;
436   guint32 max_frame_num;
437   gint width, height;
438   gint fps_num, fps_den;
439   gboolean valid;
440 };
441
442 /**
443  * GstH264PPS:
444  *
445  * H264 Picture Parameter Set
446  */
447 struct _GstH264PPS
448 {
449   gint id;
450
451   GstH264SPS *sequence;
452
453   guint8 entropy_coding_mode_flag;
454   guint8 pic_order_present_flag;
455
456   guint32 num_slice_groups_minus1;
457
458   /* if num_slice_groups_minus1 > 0 */
459   guint8 slice_group_map_type;
460   /* and if slice_group_map_type == 0 */
461   guint32 run_length_minus1[8];
462   /* or if slice_group_map_type == 2 */
463   guint32 top_left[8];
464   guint32 bottom_right[8];
465   /* or if slice_group_map_type == (3, 4, 5) */
466   guint8 slice_group_change_direction_flag;
467   guint32 slice_group_change_rate_minus1;
468   /* or if slice_group_map_type == 6 */
469   guint32 pic_size_in_map_units_minus1;
470   guint8 *slice_group_id;
471
472   guint8 num_ref_idx_l0_active_minus1;
473   guint8 num_ref_idx_l1_active_minus1;
474   guint8 weighted_pred_flag;
475   guint8 weighted_bipred_idc;
476   gint8 pic_init_qp_minus26;
477   gint8 pic_init_qs_minus26;
478   gint8 chroma_qp_index_offset;
479   guint8 deblocking_filter_control_present_flag;
480   guint8 constrained_intra_pred_flag;
481   guint8 redundant_pic_cnt_present_flag;
482
483   guint8 transform_8x8_mode_flag;
484
485   guint8 scaling_lists_4x4[6][16];
486   guint8 scaling_lists_8x8[6][64];
487
488   guint8 second_chroma_qp_index_offset;
489
490   gboolean valid;
491 };
492
493 struct _GstH264RefPicListModification
494 {
495   guint8 modification_of_pic_nums_idc;
496   union
497   {
498     /* if modification_of_pic_nums_idc == 0 || 1 */
499     guint32 abs_diff_pic_num_minus1;
500     /* if modification_of_pic_nums_idc == 2 */
501     guint32 long_term_pic_num;
502   } value;
503 };
504
505 struct _GstH264PredWeightTable
506 {
507   guint8 luma_log2_weight_denom;
508   guint8 chroma_log2_weight_denom;
509
510   gint16 luma_weight_l0[32];
511   gint8 luma_offset_l0[32];
512
513   /* if seq->ChromaArrayType != 0 */
514   gint16 chroma_weight_l0[32][2];
515   gint8 chroma_offset_l0[32][2];
516
517   /* if slice->slice_type % 5 == 1 */
518   gint16 luma_weight_l1[32];
519   gint8 luma_offset_l1[32];
520
521   /* and if seq->ChromaArrayType != 0 */
522   gint16 chroma_weight_l1[32][2];
523   gint8 chroma_offset_l1[32][2];
524 };
525
526 struct _GstH264RefPicMarking
527 {
528   guint8 memory_management_control_operation;
529
530   guint32 difference_of_pic_nums_minus1;
531   guint32 long_term_pic_num;
532   guint32 long_term_frame_idx;
533   guint32 max_long_term_frame_idx_plus1;
534 };
535
536 struct _GstH264DecRefPicMarking
537 {
538   /* if slice->nal_unit.IdrPicFlag */
539   guint8 no_output_of_prior_pics_flag;
540   guint8 long_term_reference_flag;
541
542   guint8 adaptive_ref_pic_marking_mode_flag;
543   GstH264RefPicMarking ref_pic_marking[10];
544   guint8 n_ref_pic_marking;
545 };
546
547
548 struct _GstH264SliceHdr
549 {
550   guint32 first_mb_in_slice;
551   guint32 type;
552   GstH264PPS *pps;
553
554   /* if seq->separate_colour_plane_flag */
555   guint8 colour_plane_id;
556
557   guint16 frame_num;
558
559   guint8 field_pic_flag;
560   guint8 bottom_field_flag;
561
562   /* if nal_unit.type == 5 */
563   guint16 idr_pic_id;
564
565   /* if seq->pic_order_cnt_type == 0 */
566   guint16 pic_order_cnt_lsb;
567   /* if seq->pic_order_present_flag && !field_pic_flag */
568   gint32 delta_pic_order_cnt_bottom;
569
570   gint32 delta_pic_order_cnt[2];
571   guint8 redundant_pic_cnt;
572
573   /* if slice_type == B_SLICE */
574   guint8 direct_spatial_mv_pred_flag;
575
576   guint8 num_ref_idx_l0_active_minus1;
577   guint8 num_ref_idx_l1_active_minus1;
578
579   guint8 ref_pic_list_modification_flag_l0;
580   guint8 n_ref_pic_list_modification_l0;
581   GstH264RefPicListModification ref_pic_list_modification_l0[32];
582   guint8 ref_pic_list_modification_flag_l1;
583   guint8 n_ref_pic_list_modification_l1;
584   GstH264RefPicListModification ref_pic_list_modification_l1[32];
585
586   GstH264PredWeightTable pred_weight_table;
587   /* if nal_unit.ref_idc != 0 */
588   GstH264DecRefPicMarking dec_ref_pic_marking;
589
590   guint8 cabac_init_idc;
591   gint8 slice_qp_delta;
592   gint8 slice_qs_delta;
593
594   guint8 disable_deblocking_filter_idc;
595   gint8 slice_alpha_c0_offset_div2;
596   gint8 slice_beta_offset_div2;
597
598   guint16 slice_group_change_cycle;
599
600   /* calculated values */
601   guint32 max_pic_num;
602   gboolean valid;
603
604   /* Size of the slice_header() in bits */
605   guint header_size;
606
607   /* Number of emulation prevention bytes (EPB) in this slice_header() */
608   guint n_emulation_prevention_bytes;
609 };
610
611
612 struct _GstH264ClockTimestamp
613 {
614   guint8 ct_type;
615   guint8 nuit_field_based_flag;
616   guint8 counting_type;
617   guint8 discontinuity_flag;
618   guint8 cnt_dropped_flag;
619   guint8 n_frames;
620
621   guint8 seconds_flag;
622   guint8 seconds_value;
623
624   guint8 minutes_flag;
625   guint8 minutes_value;
626
627   guint8 hours_flag;
628   guint8 hours_value;
629
630   guint32 time_offset;
631 };
632
633 struct _GstH264PicTiming
634 {
635   guint32 cpb_removal_delay;
636   guint32 dpb_output_delay;
637
638   guint8 pic_struct_present_flag;
639   /* if pic_struct_present_flag */
640   guint8 pic_struct;
641
642   guint8 clock_timestamp_flag[3];
643   GstH264ClockTimestamp clock_timestamp[3];
644 };
645
646 struct _GstH264BufferingPeriod
647 {
648   GstH264SPS *sps;
649
650   /* seq->vui_parameters->nal_hrd_parameters_present_flag */
651   guint8 nal_initial_cpb_removal_delay[32];
652   guint8 nal_initial_cpb_removal_delay_offset[32];
653
654   /* seq->vui_parameters->vcl_hrd_parameters_present_flag */
655   guint8 vcl_initial_cpb_removal_delay[32];
656   guint8 vcl_initial_cpb_removal_delay_offset[32];
657 };
658
659 struct _GstH264SEIMessage
660 {
661   GstH264SEIPayloadType payloadType;
662
663   union {
664     GstH264BufferingPeriod buffering_period;
665     GstH264PicTiming pic_timing;
666     /* ... could implement more */
667   } payload;
668 };
669
670 /**
671  * GstH264NalParser:
672  *
673  * H264 NAL Parser (opaque structure).
674  */
675 struct _GstH264NalParser
676 {
677   /*< private >*/
678   GstH264SPS sps[GST_H264_MAX_SPS_COUNT];
679   GstH264PPS pps[GST_H264_MAX_PPS_COUNT];
680   GstH264SPS *last_sps;
681   GstH264PPS *last_pps;
682 };
683
684 GstH264NalParser *gst_h264_nal_parser_new             (void);
685
686 GstH264ParserResult gst_h264_parser_identify_nalu     (GstH264NalParser *nalparser,
687                                                        const guint8 *data, guint offset,
688                                                        gsize size, GstH264NalUnit *nalu);
689
690 GstH264ParserResult gst_h264_parser_identify_nalu_unchecked (GstH264NalParser *nalparser,
691                                                        const guint8 *data, guint offset,
692                                                        gsize size, GstH264NalUnit *nalu);
693
694 GstH264ParserResult gst_h264_parser_identify_nalu_avc (GstH264NalParser *nalparser, const guint8 *data,
695                                                        guint offset, gsize size, guint8 nal_length_size,
696                                                        GstH264NalUnit *nalu);
697
698 GstH264ParserResult gst_h264_parser_parse_nal         (GstH264NalParser *nalparser,
699                                                        GstH264NalUnit *nalu);
700
701 GstH264ParserResult gst_h264_parser_parse_slice_hdr   (GstH264NalParser *nalparser, GstH264NalUnit *nalu,
702                                                        GstH264SliceHdr *slice, gboolean parse_pred_weight_table,
703                                                        gboolean parse_dec_ref_pic_marking);
704
705 GstH264ParserResult gst_h264_parser_parse_sps         (GstH264NalParser *nalparser, GstH264NalUnit *nalu,
706                                                        GstH264SPS *sps, gboolean parse_vui_params);
707
708 GstH264ParserResult gst_h264_parser_parse_pps         (GstH264NalParser *nalparser,
709                                                        GstH264NalUnit *nalu, GstH264PPS *pps);
710
711 GstH264ParserResult gst_h264_parser_parse_sei         (GstH264NalParser *nalparser,
712                                                        GstH264NalUnit *nalu, GstH264SEIMessage *sei);
713
714 void gst_h264_nal_parser_free                         (GstH264NalParser *nalparser);
715
716 GstH264ParserResult gst_h264_parse_sps                (GstH264NalUnit *nalu,
717                                                        GstH264SPS *sps, gboolean parse_vui_params);
718
719 GstH264ParserResult gst_h264_parse_pps                (GstH264NalParser *nalparser,
720                                                        GstH264NalUnit *nalu, GstH264PPS *pps);
721
722 G_END_DECLS
723 #endif