documentation: fixed a heap o' typos
[platform/upstream/gstreamer.git] / gst / mpegtsdemux / mpegtsbase.h
1 /*
2  * mpegtsbase.h - GStreamer MPEG transport stream base class
3  * Copyright (C) 2009 Edward Hervey <edward.hervey@collabora.co.uk>
4  *               2007 Alessandro Decina
5  * Copyright (C) 2011, Hewlett-Packard Development Company, L.P.
6  *  Author: Youness Alaoui <youness.alaoui@collabora.co.uk>, Collabora Ltd.
7  *  Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
8  *
9  * Authors:
10  *   Alessandro Decina <alessandro@nnva.org>
11  *   Edward Hervey <edward.hervey@collabora.co.uk>
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Library General Public
15  * License as published by the Free Software Foundation; either
16  * version 2 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21  * Library General Public License for more details.
22  *
23  * You should have received a copy of the GNU Library General Public
24  * License along with this library; if not, write to the
25  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
26  * Boston, MA 02110-1301, USA.
27  */
28
29
30 #ifndef GST_MPEG_TS_BASE_H
31 #define GST_MPEG_TS_BASE_H
32
33 #include <gst/gst.h>
34 #include "mpegtspacketizer.h"
35
36 G_BEGIN_DECLS
37
38 #define GST_TYPE_MPEGTS_BASE \
39   (mpegts_base_get_type())
40 #define GST_MPEGTS_BASE(obj) \
41   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MPEGTS_BASE,MpegTSBase))
42 #define GST_MPEGTS_BASE_CLASS(klass) \
43   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MPEGTS_BASE,MpegTSBaseClass))
44 #define GST_IS_MPEGTS_BASE(obj) \
45   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MPEGTS_BASE))
46 #define GST_IS_MPEGTS_BASE_CLASS(klass) \
47   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MPEGTS_BASE))
48 #define GST_MPEGTS_BASE_GET_CLASS(obj) \
49   (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_MPEGTS_BASE, MpegTSBaseClass))
50
51 #define MPEG_TS_BASE_PACKETIZER(b) (((MpegTSBase*)b)->packetizer)
52
53 typedef struct _MpegTSBase MpegTSBase;
54 typedef struct _MpegTSBaseClass MpegTSBaseClass;
55 typedef struct _MpegTSBaseStream MpegTSBaseStream;
56 typedef struct _MpegTSBaseProgram MpegTSBaseProgram;
57
58 struct _MpegTSBaseStream
59 {
60   guint16             pid;
61   guint8              stream_type;
62
63   /* Content of the registration descriptor (if present) */
64   guint32             registration_id;
65
66   GstMpegtsPMTStream *stream;
67   GstStream          *stream_object;
68   gchar              *stream_id;
69 };
70
71 struct _MpegTSBaseProgram
72 {
73   gint                program_number;
74   guint16             pmt_pid;
75   guint16             pcr_pid;
76
77   /* Content of the registration descriptor (if present) */
78   guint32             registration_id;
79
80   GstMpegtsSection   *section;
81   const GstMpegtsPMT *pmt;
82
83   MpegTSBaseStream  **streams;
84   GList              *stream_list;
85   gint                patcount;
86
87   GstStreamCollection *collection;
88
89   /* Pending Tags for the program */
90   GstTagList *tags;
91   guint event_id;
92
93   /* TRUE if the program is currently being used */
94   gboolean active;
95   /* TRUE if this is the first program created */
96   gboolean initial_program;
97 };
98
99 typedef enum {
100   /* PULL MODE */
101   BASE_MODE_SCANNING,           /* Looking for PAT/PMT */
102   BASE_MODE_SEEKING,            /* Seeking */
103   BASE_MODE_STREAMING,          /* Normal mode (pushing out data) */
104
105   /* PUSH MODE */
106   BASE_MODE_PUSHING
107 } MpegTSBaseMode;
108
109 struct _MpegTSBase {
110   GstElement element;
111
112   GstPad *sinkpad;
113
114   /* pull-based behaviour */
115   MpegTSBaseMode mode;
116
117   /* Current pull offset (also set by seek handler) */
118   guint64       seek_offset;
119
120   /* Cached packetsize */
121   guint16       packetsize;
122
123   /* the following vars must be protected with the OBJECT_LOCK as they can be
124    * accessed from the application thread and the streaming thread */
125   GHashTable *programs;
126
127   GPtrArray  *pat;
128   MpegTSPacketizer2 *packetizer;
129
130   /* arrays that say whether a pid is a known psi pid or a pes pid */
131   /* Use MPEGTS_BIT_* to set/unset/check the values */
132   guint8 *known_psi;
133   guint8 *is_pes;
134
135   gboolean disposed;
136
137   /* size of the MpegTSBaseProgram structure, can be overridden
138    * by subclasses if they have their own MpegTSBaseProgram subclasses. */
139   gsize program_size;
140
141   /* size of the MpegTSBaseStream structure, can be overridden
142    * by subclasses if they have their own MpegTSBaseStream subclasses */
143   gsize stream_size;
144
145   /* Whether we saw a PAT yet */
146   gboolean seen_pat;
147
148   /* Upstream segment */
149   GstSegment segment;
150
151   /* Downstream segment, for use by sub-classes */
152   GstSegment out_segment;
153
154   /* Last received seek event seqnum (default GST_SEQNUM_INVALID) */
155   guint last_seek_seqnum;
156
157   /* Whether to parse private section or not */
158   gboolean parse_private_sections;
159
160   /* Whether to push data and/or sections to subclasses */
161   gboolean push_data;
162   gboolean push_section;
163
164   /* Whether the parent bin is streams-aware, meaning we can
165    * add/remove streams at any point in time */
166   gboolean streams_aware;
167 };
168
169 struct _MpegTSBaseClass {
170   GstElementClass parent_class;
171
172   /* Virtual methods */
173   void (*reset) (MpegTSBase *base);
174   GstFlowReturn (*push) (MpegTSBase *base, MpegTSPacketizerPacket *packet, GstMpegtsSection * section);
175   void (*inspect_packet) (MpegTSBase *base, MpegTSPacketizerPacket *packet);
176   /* takes ownership of @event */
177   gboolean (*push_event) (MpegTSBase *base, GstEvent * event);
178
179   /* program_started gets called when program's pmt arrives for first time */
180   void (*program_started) (MpegTSBase *base, MpegTSBaseProgram *program);
181   /* program_stopped gets called when pat no longer has program's pmt */
182   void (*program_stopped) (MpegTSBase *base, MpegTSBaseProgram *program);
183   void (*update_program) (MpegTSBase *base, MpegTSBaseProgram *program);
184   /* Whether mpegtbase can deactivate/free a program or whether the subclass will do it
185    * If the subclass responds TRUE, it should call mpegts_base_deactivate_and_free_program()
186    * when it wants to remove it */
187   gboolean (*can_remove_program) (MpegTSBase *base, MpegTSBaseProgram *program);
188
189   /* stream_added is called whenever a new stream has been identified */
190   gboolean (*stream_added) (MpegTSBase *base, MpegTSBaseStream *stream, MpegTSBaseProgram *program);
191   /* stream_removed is called whenever a stream is no longer referenced */
192   void (*stream_removed) (MpegTSBase *base, MpegTSBaseStream *stream);
193
194   /* find_timestamps is called to find PCR */
195   GstFlowReturn (*find_timestamps) (MpegTSBase * base, guint64 initoff, guint64 *offset);
196
197   /* seek is called to wait for seeking */
198   GstFlowReturn (*seek) (MpegTSBase * base, GstEvent * event);
199
200   /* Drain all currently pending data */
201   GstFlowReturn (*drain) (MpegTSBase * base);
202
203   /* flush all streams
204    * The hard inicator is used to flush completely on FLUSH_STOP events
205    * or partially in pull mode seeks of tsdemux */
206   void (*flush) (MpegTSBase * base, gboolean hard);
207
208   /* Notifies subclasses input buffer has been handled */
209   GstFlowReturn (*input_done) (MpegTSBase *base, GstBuffer *buffer);
210
211   /* signals */
212   void (*pat_info) (GstStructure *pat);
213   void (*pmt_info) (GstStructure *pmt);
214   void (*nit_info) (GstStructure *nit);
215   void (*sdt_info) (GstStructure *sdt);
216   void (*eit_info) (GstStructure *eit);
217
218   /* takes ownership of @query */
219   gboolean (*sink_query) (MpegTSBase *base, GstQuery * query);
220 };
221
222 #define MPEGTS_BIT_SET(field, offs)    ((field)[(offs) >> 3] |=  (1 << ((offs) & 0x7)))
223 #define MPEGTS_BIT_UNSET(field, offs)  ((field)[(offs) >> 3] &= ~(1 << ((offs) & 0x7)))
224 #define MPEGTS_BIT_IS_SET(field, offs) ((field)[(offs) >> 3] &   (1 << ((offs) & 0x7)))
225
226 G_GNUC_INTERNAL GType mpegts_base_get_type(void);
227
228 G_GNUC_INTERNAL MpegTSBaseProgram *mpegts_base_get_program (MpegTSBase * base, gint program_number);
229 G_GNUC_INTERNAL MpegTSBaseProgram *mpegts_base_add_program (MpegTSBase * base, gint program_number, guint16 pmt_pid);
230
231 G_GNUC_INTERNAL const GstMpegtsDescriptor *mpegts_get_descriptor_from_stream (MpegTSBaseStream * stream, guint8 tag);
232 G_GNUC_INTERNAL const GstMpegtsDescriptor *mpegts_get_descriptor_from_program (MpegTSBaseProgram * program, guint8 tag);
233
234 G_GNUC_INTERNAL gboolean
235 mpegts_base_handle_seek_event(MpegTSBase * base, GstPad * pad, GstEvent * event);
236
237 G_GNUC_INTERNAL gboolean gst_mpegtsbase_plugin_init (GstPlugin * plugin);
238
239 G_GNUC_INTERNAL void mpegts_base_deactivate_and_free_program (MpegTSBase *base, MpegTSBaseProgram *program);
240
241 G_END_DECLS
242
243 #endif /* GST_MPEG_TS_BASE_H */