Send seek event to baseparse when aacparse seek failed in push mode
[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 #ifdef TIZEN_FEATURE_QTDEMUX_MODIFICATION
61 typedef struct _QtDemuxSphericalMetadata QtDemuxSphericalMetadata;
62 #endif
63
64 struct _GstQTDemux {
65   GstElement element;
66
67   /* Global state */
68   enum QtDemuxState state;
69
70   /* static sink pad */
71   GstPad *sinkpad;
72
73   /* TRUE if pull-based */
74   gboolean pullbased;
75
76   gboolean posted_redirect;
77
78   /* Protect pad exposing from flush event */
79   GMutex expose_lock;
80
81   /* list of QtDemuxStream */
82   GPtrArray *active_streams;
83   GPtrArray *old_streams;
84
85   gint     n_video_streams;
86   gint     n_audio_streams;
87   gint     n_sub_streams;
88
89   GstFlowCombiner *flowcombiner;
90
91   /* Incoming stream group-id to set on downstream STREAM_START events.
92    * If upstream doesn't contain one, a global one will be generated */
93   gboolean have_group_id;
94   guint group_id;
95
96   guint  major_brand;
97   GstBuffer *comp_brands;
98
99   /* [moov] header.
100    * FIXME : This is discarded just after it's created. Just move it
101    * to a temporary variable ? */
102   GNode *moov_node;
103
104   /* FIXME : This is never freed. It is only assigned once. memleak ? */
105   GNode *moov_node_compressed;
106
107   /* Set to TRUE when the [moov] header has been fully parsed */
108   gboolean got_moov;
109
110   /* Global timescale for the incoming stream. Use the QTTIME macros
111    * to convert values to/from GstClockTime */
112   guint32 timescale;
113
114   /* Global duration (in global timescale). Use QTTIME macros to get GstClockTime */
115   guint64 duration;
116
117   /* Total size of header atoms. Used to calculate fallback overall bitrate */
118   guint header_size;
119
120   GstTagList *tag_list;
121
122   /* configured playback region */
123   GstSegment segment;
124
125   /* PUSH-BASED only: If the initial segment event, or a segment consequence of
126    * a seek or incoming TIME segment from upstream needs to be pushed. This
127    * variable is used instead of pushing the event directly because at that
128    * point we may not have yet emitted the srcpads. */
129   gboolean need_segment;
130
131   guint32 segment_seqnum;
132
133   /* flag to indicate that we're working with a smoothstreaming fragment
134    * Mss doesn't have 'moov' or any information about the streams format,
135    * requiring qtdemux to expose and create the streams */
136   gboolean mss_mode;
137
138   /* Set to TRUE if the incoming stream is either a MSS stream or
139    * a Fragmented MP4 (containing the [mvex] atom in the header) */
140   gboolean fragmented;
141
142   /* PULL-BASED only : If TRUE there is a pending seek */
143   gboolean fragmented_seek_pending;
144
145   /* PULL-BASED : offset of first [moof] or of fragment to seek to
146    * PUSH-BASED : offset of latest [moof] */
147   guint64 moof_offset;
148
149   /* MSS streams have a single media that is unspecified at the atoms, so
150    * upstream provides it at the caps */
151   GstCaps *media_caps;
152
153   /* Set to TRUE when all streams have been exposed */
154   gboolean exposed;
155
156   gint64 chapters_track_id;
157
158   /* protection support */
159   GPtrArray *protection_system_ids; /* Holds identifiers of all content protection systems for all tracks */
160   GQueue protection_event_queue; /* holds copy of upstream protection events */
161   guint64 cenc_aux_info_offset;
162   guint8 *cenc_aux_info_sizes;
163   guint32 cenc_aux_sample_count;
164   gchar *preferred_protection_system_id;
165
166   /* Whether the parent bin is streams-aware, meaning we can
167    * add/remove streams at any point in time */
168   gboolean streams_aware;
169
170   /*
171    * ALL VARIABLES BELOW ARE ONLY USED IN PUSH-BASED MODE
172    */
173   GstAdapter *adapter;
174   guint neededbytes;
175   guint todrop;
176   /* Used to store data if [mdat] is before the headers */
177   GstBuffer *mdatbuffer;
178   /* Amount of bytes left to read in the current [mdat] */
179   guint64 mdatleft, mdatsize;
180
181   /* When restoring the mdat to the adapter, this buffer stores any
182    * trailing data that was after the last atom parsed as it has to be
183    * restored later along with the correct offset. Used in fragmented
184    * scenario where mdat/moof are one after the other in any order.
185    *
186    * Check https://bugzilla.gnome.org/show_bug.cgi?id=710623 */
187   GstBuffer *restoredata_buffer;
188   guint64 restoredata_offset;
189
190   /* The current offset in bytes from upstream.
191    * Note: While it makes complete sense when we are PULL-BASED (pulling
192    * in BYTES from upstream) and PUSH-BASED with a BYTE SEGMENT (receiving
193    * buffers with actual offsets), it is undefined in PUSH-BASED with a
194    * TIME SEGMENT */
195   guint64 offset;
196
197   /* offset of the mdat atom */
198   guint64 mdatoffset;
199   /* Offset of the first mdat */
200   guint64 first_mdat;
201   /* offset of last [moov] seen */
202   guint64 last_moov_offset;
203
204   /* If TRUE, qtdemux received upstream newsegment in TIME format
205    * which likely means that upstream is driving the pipeline (such as
206    * adaptive demuxers or dlna sources) */
207   gboolean upstream_format_is_time;
208
209   /* Seqnum of the seek event sent upstream.  Will be used to
210    * detect incoming FLUSH events corresponding to that */
211   guint32 offset_seek_seqnum;
212
213   /* UPSTREAM BYTE: Requested upstream byte seek offset.
214    * Currently it is only used to check if an incoming BYTE SEGMENT
215    * corresponds to a seek event that was sent upstream */
216   gint64 seek_offset;
217
218   /* UPSTREAM BYTE: Requested start/stop TIME values from
219    * downstream.
220    * Used to set on the downstream segment once the corresponding upstream
221    * BYTE SEEK has succeeded */
222   gint64 push_seek_start;
223   gint64 push_seek_stop;
224
225 #if 0
226   /* gst index support */
227   GstIndex *element_index;
228   gint index_id;
229 #endif
230
231   /* Whether upstream is seekable in BYTES */
232   gboolean upstream_seekable;
233   /* UPSTREAM BYTE: Size of upstream content.
234    * Note : This is only computed once ! If upstream grows in the meantime
235    * it will not be updated */
236   gint64 upstream_size;
237
238   /* UPSTREAM TIME : Contains the PTS (if any) of the
239    * buffer that contains a [moof] header. Will be used to establish
240    * the actual PTS of the samples contained within that fragment. */
241   guint64 fragment_start;
242   /* UPSTREAM TIME : The offset in bytes of the [moof]
243    * header start.
244    * Note : This is not computed from the GST_BUFFER_OFFSET field */
245   guint64 fragment_start_offset;
246
247   /* These two fields are used to perform an implicit seek when a fragmented
248    * file whose first tfdt is not zero. This way if the first fragment starts
249    * at 1 hour, the user does not have to wait 1 hour or perform a manual seek
250    * for the image to move and the sound to play.
251    *
252    * This implicit seek is only done if the first parsed fragment has a non-zero
253    * decode base time and a seek has not been received previously, hence these
254    * fields. */
255   gboolean received_seek;
256   gboolean first_moof_already_parsed;
257 #ifdef TIZEN_FEATURE_QTDEMUX_MODIFICATION
258   QtDemuxSphericalMetadata *spherical_metadata;
259 #endif  
260 };
261
262 struct _GstQTDemuxClass {
263   GstElementClass parent_class;
264 };
265
266 GType gst_qtdemux_get_type (void);
267
268 G_END_DECLS
269
270 #endif /* __GST_QTDEMUX_H__ */