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.
10 * Alessandro Decina <alessandro@nnva.org>
11 * Edward Hervey <edward.hervey@collabora.co.uk>
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.
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.
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.
30 #ifndef GST_MPEG_TS_BASE_H
31 #define GST_MPEG_TS_BASE_H
34 #include "mpegtspacketizer.h"
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))
51 #define MPEG_TS_BASE_PACKETIZER(b) (((MpegTSBase*)b)->packetizer)
53 typedef struct _MpegTSBase MpegTSBase;
54 typedef struct _MpegTSBaseClass MpegTSBaseClass;
55 typedef struct _MpegTSBaseStream MpegTSBaseStream;
56 typedef struct _MpegTSBaseProgram MpegTSBaseProgram;
58 struct _MpegTSBaseStream
63 /* Content of the registration descriptor (if present) */
64 guint32 registration_id;
66 GstMpegtsPMTStream *stream;
67 GstStream *stream_object;
71 struct _MpegTSBaseProgram
77 /* Content of the registration descriptor (if present) */
78 guint32 registration_id;
80 GstMpegtsSection *section;
81 const GstMpegtsPMT *pmt;
83 MpegTSBaseStream **streams;
87 GstStreamCollection *collection;
89 /* Pending Tags for the program */
93 /* TRUE if the program is currently being used */
95 /* TRUE if this is the first program created */
96 gboolean initial_program;
101 BASE_MODE_SCANNING, /* Looking for PAT/PMT */
102 BASE_MODE_SEEKING, /* Seeking */
103 BASE_MODE_STREAMING, /* Normal mode (pushing out data) */
114 /* pull-based behaviour */
117 /* Current pull offset (also set by seek handler) */
120 /* Cached packetsize */
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;
128 MpegTSPacketizer2 *packetizer;
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 */
137 /* size of the MpegTSBaseProgram structure, can be overridden
138 * by subclasses if they have their own MpegTSBaseProgram subclasses. */
141 /* size of the MpegTSBaseStream structure, can be overridden
142 * by subclasses if they have their own MpegTSBaseStream subclasses */
145 /* Whether we saw a PAT yet */
148 /* Upstream segment */
151 /* Downstream segment, for use by sub-classes */
152 GstSegment out_segment;
154 /* Last received seek event seqnum (default GST_SEQNUM_INVALID) */
155 guint last_seek_seqnum;
157 /* Whether to parse private section or not */
158 gboolean parse_private_sections;
160 /* Whether to push data and/or sections to subclasses */
162 gboolean push_section;
164 /* Whether the parent bin is streams-aware, meaning we can
165 * add/remove streams at any point in time */
166 gboolean streams_aware;
169 struct _MpegTSBaseClass {
170 GstElementClass parent_class;
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);
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);
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);
194 /* find_timestamps is called to find PCR */
195 GstFlowReturn (*find_timestamps) (MpegTSBase * base, guint64 initoff, guint64 *offset);
197 /* seek is called to wait for seeking */
198 GstFlowReturn (*seek) (MpegTSBase * base, GstEvent * event);
200 /* Drain all currently pending data */
201 GstFlowReturn (*drain) (MpegTSBase * base);
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);
208 /* Notifies subclasses input buffer has been handled */
209 GstFlowReturn (*input_done) (MpegTSBase *base, GstBuffer *buffer);
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);
218 /* takes ownership of @query */
219 gboolean (*sink_query) (MpegTSBase *base, GstQuery * query);
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)))
226 G_GNUC_INTERNAL GType mpegts_base_get_type(void);
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);
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);
234 G_GNUC_INTERNAL gboolean
235 mpegts_base_handle_seek_event(MpegTSBase * base, GstPad * pad, GstEvent * event);
237 G_GNUC_INTERNAL gboolean gst_mpegtsbase_plugin_init (GstPlugin * plugin);
239 G_GNUC_INTERNAL void mpegts_base_deactivate_and_free_program (MpegTSBase *base, MpegTSBaseProgram *program);
243 #endif /* GST_MPEG_TS_BASE_H */