1 /* GStreamer H.264 Parser
2  * Copyright (C) <2010> Collabora ltd
3  * Copyright (C) <2010> Nokia Corporation
4  * Copyright (C) <2011> Intel Corporation
5  *
6  * Copyright (C) <2010> Mark Nauwelaerts <mark.nauwelaerts@collabora.co.uk>
7  * Copyright (C) <2011> Thibault Saunier <thibault.saunier@collabora.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Library General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Library General Public License for more details.
18  *
19  * You should have received a copy of the GNU Library General Public
20  * License along with this library; if not, write to the
21  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22  * Boston, MA 02110-1301, USA.
23  */
24 
25 #ifndef __GST_H264_PARSE_H__
26 #define __GST_H264_PARSE_H__
27 
28 #include <gst/gst.h>
29 #include <gst/base/gstbaseparse.h>
30 #include <gst/codecparsers/gsth264parser.h>
31 #include <gst/video/video.h>
32 
33 G_BEGIN_DECLS
34 
35 typedef struct _H264Params H264Params;
36 
37 #define GST_TYPE_H264_PARSE \
38   (gst_h264_parse_get_type())
39 #define GST_H264_PARSE(obj) \
40   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_H264_PARSE,GstH264Parse))
41 #define GST_H264_PARSE_CLASS(klass) \
42   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_H264_PARSE,GstH264ParseClass))
43 #define GST_IS_H264_PARSE(obj) \
44   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_H264_PARSE))
45 #define GST_IS_H264_PARSE_CLASS(klass) \
46   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_H264_PARSE))
47 
48 GType gst_h264_parse_get_type (void);
49 
50 typedef struct _GstH264Parse GstH264Parse;
51 typedef struct _GstH264ParseClass GstH264ParseClass;
52 
53 struct _GstH264Parse
54 {
55   GstBaseParse baseparse;
56 
57   /* stream */
58   gint width, height;
59   gint fps_num, fps_den;
60   gint upstream_par_n, upstream_par_d;
61   gint parsed_par_n, parsed_par_d;
62   gint parsed_fps_n, parsed_fps_d;
63   /* current codec_data in output caps, if any */
64   GstBuffer *codec_data;
65   /* input codec_data, if any */
66   GstBuffer *codec_data_in;
67   guint nal_length_size;
68   gboolean packetized;
69   gboolean split_packetized;
70   gboolean transform;
71 
72   /* state */
73   GstH264NalParser *nalparser;
74   guint state;
75   guint in_align;
76   guint align;
77   guint format;
78   gint current_off;
79   /* True if input format and alignment match negotiated output */
80   gboolean can_passthrough;
81 
82   GstClockTime last_report;
83   gboolean push_codec;
84   /* The following variables have a meaning in context of "have
85    * SPS/PPS to push downstream", e.g. to update caps */
86   gboolean have_sps;
87   gboolean have_pps;
88 
89   /* per frame sps/pps check for periodic push codec decision */
90   gboolean have_sps_in_frame;
91   gboolean have_pps_in_frame;
92 
93   gboolean sent_codec_tag;
94 
95   /* collected SPS and PPS NALUs */
96   GstBuffer *sps_nals[GST_H264_MAX_SPS_COUNT];
97   GstBuffer *pps_nals[GST_H264_MAX_PPS_COUNT];
98 
99   /* collected SEI timestamps */
100   guint num_clock_timestamp;
101   GstH264ClockTimestamp clock_timestamp[3];
102 
103   /* Infos we need to keep track of */
104   guint32 sei_cpb_removal_delay;
105   guint8 sei_pic_struct;
106   guint8 sei_pic_struct_pres_flag;
107   guint field_pic_flag;
108 
109   /* cached timestamps */
110   /* (trying to) track upstream dts and interpolate */
111   GstClockTime dts;
112   /* dts at start of last buffering period */
113   GstClockTime ts_trn_nb;
114   gboolean do_ts;
115 
116   gboolean discont;
117 
118   /* frame parsing */
119   /*guint last_nal_pos;*/
120   /*guint next_sc_pos;*/
121   gint idr_pos, sei_pos;
122   gboolean update_caps;
123   GstAdapter *frame_out;
124   gboolean keyframe;
125   gboolean header;
126   gboolean frame_start;
127   /* AU state */
128   gboolean picture_start;
129 
130   /* props */
131   gint interval;
132 
133   GstClockTime pending_key_unit_ts;
134   GstEvent *force_key_unit_event;
135 
136   /* Stereo / multiview info */
137   GstVideoMultiviewMode multiview_mode;
138   GstVideoMultiviewFlags multiview_flags;
139   gboolean first_in_bundle;
140 
141   /* For insertion of AU Delimiter */
142   gboolean aud_needed;
143   gboolean aud_insert;
144 
145   /* pending closed captions */
146   guint8 closedcaptions[96];
147   guint closedcaptions_size;
148   GstVideoCaptionType closedcaptions_type;
149 };
150 
151 struct _GstH264ParseClass
152 {
153   GstBaseParseClass parent_class;
154 };
155 
156 G_END_DECLS
157 #endif
158