qtdemux: Forward upstream time-format segment without mapping
[platform/upstream/gst-plugins-good.git] / gst / isomp4 / qtdemux.h
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20
21 #ifndef __GST_QTDEMUX_H__
22 #define __GST_QTDEMUX_H__
23
24 #include <gst/gst.h>
25 #include <gst/base/gstadapter.h>
26 #include <gst/base/gstflowcombiner.h>
27 #include "gstisoff.h"
28
29 G_BEGIN_DECLS
30
31 #define GST_TYPE_QTDEMUX \
32   (gst_qtdemux_get_type())
33 #define GST_QTDEMUX(obj) \
34   (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_QTDEMUX,GstQTDemux))
35 #define GST_QTDEMUX_CLASS(klass) \
36   (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_QTDEMUX,GstQTDemuxClass))
37 #define GST_IS_QTDEMUX(obj) \
38   (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_QTDEMUX))
39 #define GST_IS_QTDEMUX_CLASS(klass) \
40   (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_QTDEMUX))
41
42 #define GST_QTDEMUX_CAST(obj) ((GstQTDemux *)(obj))
43
44 /* qtdemux produces these for atoms it cannot parse */
45 #define GST_QT_DEMUX_PRIVATE_TAG "private-qt-tag"
46 #define GST_QT_DEMUX_CLASSIFICATION_TAG "classification"
47
48 typedef struct _GstQTDemux GstQTDemux;
49 typedef struct _GstQTDemuxClass GstQTDemuxClass;
50 typedef struct _QtDemuxStream QtDemuxStream;
51
52 enum QtDemuxState
53 {
54   QTDEMUX_STATE_INITIAL,        /* Initial state (haven't got the header yet) */
55   QTDEMUX_STATE_HEADER,         /* Parsing the header */
56   QTDEMUX_STATE_MOVIE,          /* Parsing/Playing the media data */
57   QTDEMUX_STATE_BUFFER_MDAT     /* Buffering the mdat atom */
58 };
59
60 struct _GstQTDemux {
61   GstElement element;
62
63   /* Global state */
64   enum QtDemuxState state;
65
66   /* static sink pad */
67   GstPad *sinkpad;
68
69   /* TRUE if pull-based */
70   gboolean pullbased;
71
72   gboolean posted_redirect;
73
74   /* Protect pad exposing from flush event */
75   GMutex expose_lock;
76
77   /* list of QtDemuxStream */
78   GList *active_streams;
79   GList *old_streams;
80
81   gint     n_streams;
82   gint     n_video_streams;
83   gint     n_audio_streams;
84   gint     n_sub_streams;
85
86   GstFlowCombiner *flowcombiner;
87
88   /* Incoming stream group-id to set on downstream STREAM_START events.
89    * If upstream doesn't contain one, a global one will be generated */
90   gboolean have_group_id;
91   guint group_id;
92
93   guint  major_brand;
94   GstBuffer *comp_brands;
95
96   /* [moov] header.
97    * FIXME : This is discarded just after it's created. Just move it
98    * to a temporary variable ? */
99   GNode *moov_node;
100
101   /* FIXME : This is never freed. It is only assigned once. memleak ? */
102   GNode *moov_node_compressed;
103
104   /* Set to TRUE when the [moov] header has been fully parsed */
105   gboolean got_moov;
106
107   /* Global timescale for the incoming stream. Use the QTTIME macros
108    * to convert values to/from GstClockTime */
109   guint32 timescale;
110
111   /* Global duration (in global timescale). Use QTTIME macros to get GstClockTime */
112   guint64 duration;
113
114   /* Total size of header atoms. Used to calculate fallback overall bitrate */
115   guint header_size;
116
117   GstTagList *tag_list;
118
119   /* configured playback region */
120   GstSegment segment;
121
122   /* If a segment event needs to be pushed */
123   gboolean need_segment;
124
125   guint32 segment_seqnum;
126
127   /* flag to indicate that we're working with a smoothstreaming fragment
128    * Mss doesn't have 'moov' or any information about the streams format,
129    * requiring qtdemux to expose and create the streams */
130   gboolean mss_mode;
131
132   /* Set to TRUE if the incoming stream is either a MSS stream or
133    * a Fragmented MP4 (containing the [mvex] atom in the header) */
134   gboolean fragmented;
135
136   /* PULL-BASED only : If TRUE there is a pending seek */
137   gboolean fragmented_seek_pending;
138
139   /* PULL-BASED : offset of first [moof] or of fragment to seek to
140    * PUSH-BASED : offset of latest [moof] */
141   guint64 moof_offset;
142
143   /* MSS streams have a single media that is unspecified at the atoms, so
144    * upstream provides it at the caps */
145   GstCaps *media_caps;
146
147   /* Set to TRUE when all streams have been exposed */
148   gboolean exposed;
149
150   gint64 chapters_track_id;
151
152   /* protection support */
153   GPtrArray *protection_system_ids; /* Holds identifiers of all content protection systems for all tracks */
154   GQueue protection_event_queue; /* holds copy of upstream protection events */
155   guint64 cenc_aux_info_offset;
156   guint8 *cenc_aux_info_sizes;
157   guint32 cenc_aux_sample_count;
158   gchar *preferred_protection_system_id;
159
160   /* Whether the parent bin is streams-aware, meaning we can
161    * add/remove streams at any point in time */
162   gboolean streams_aware;
163
164   /*
165    * ALL VARIABLES BELOW ARE ONLY USED IN PUSH-BASED MODE
166    */
167   GstAdapter *adapter;
168   guint neededbytes;
169   guint todrop;
170   /* Used to store data if [mdat] is before the headers */
171   GstBuffer *mdatbuffer;
172   /* Amount of bytes left to read in the current [mdat] */
173   guint64 mdatleft, mdatsize;
174
175   /* When restoring the mdat to the adapter, this buffer stores any
176    * trailing data that was after the last atom parsed as it has to be
177    * restored later along with the correct offset. Used in fragmented
178    * scenario where mdat/moof are one after the other in any order.
179    *
180    * Check https://bugzilla.gnome.org/show_bug.cgi?id=710623 */
181   GstBuffer *restoredata_buffer;
182   guint64 restoredata_offset;
183
184   /* The current offset in bytes from upstream.
185    * Note: While it makes complete sense when we are PULL-BASED (pulling
186    * in BYTES from upstream) and PUSH-BASED with a BYTE SEGMENT (receiving
187    * buffers with actual offsets), it is undefined in PUSH-BASED with a
188    * TIME SEGMENT */
189   guint64 offset;
190
191   /* offset of the mdat atom */
192   guint64 mdatoffset;
193   /* Offset of the first mdat */
194   guint64 first_mdat;
195   /* offset of last [moov] seen */
196   guint64 last_moov_offset;
197
198   /* If TRUE, qtdemux received upstream newsegment in TIME format
199    * which likely means that upstream is driving the pipeline (such as
200    * adaptive demuxers or dlna sources) */
201   gboolean upstream_format_is_time;
202
203   /* Seqnum of the seek event sent upstream.  Will be used to
204    * detect incoming FLUSH events corresponding to that */
205   guint32 offset_seek_seqnum;
206
207   /* UPSTREAM BYTE: Requested upstream byte seek offset.
208    * Currently it is only used to check if an incoming BYTE SEGMENT
209    * corresponds to a seek event that was sent upstream */
210   gint64 seek_offset;
211
212   /* UPSTREAM BYTE: Requested start/stop TIME values from
213    * downstream.
214    * Used to set on the downstream segment once the corresponding upstream
215    * BYTE SEEK has succeeded */
216   gint64 push_seek_start;
217   gint64 push_seek_stop;
218
219 #if 0
220   /* gst index support */
221   GstIndex *element_index;
222   gint index_id;
223 #endif
224
225   /* Whether upstream is seekable in BYTES */
226   gboolean upstream_seekable;
227   /* UPSTREAM BYTE: Size of upstream content.
228    * Note : This is only computed once ! If upstream grows in the meantime
229    * it will not be updated */
230   gint64 upstream_size;
231
232   /* UPSTREAM TIME : Contains the PTS (if any) of the
233    * buffer that contains a [moof] header. Will be used to establish
234    * the actual PTS of the samples contained within that fragment. */
235   guint64 fragment_start;
236   /* UPSTREAM TIME : The offset in bytes of the [moof]
237    * header start.
238    * Note : This is not computed from the GST_BUFFER_OFFSET field */
239   guint64 fragment_start_offset;
240 };
241
242 struct _GstQTDemuxClass {
243   GstElementClass parent_class;
244 };
245
246 GType gst_qtdemux_get_type (void);
247
248 G_END_DECLS
249
250 #endif /* __GST_QTDEMUX_H__ */