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