qtdemux: Apply qtdemux debug category to gstisoff
[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 #define GST_QTDEMUX_MAX_STREAMS         32
49
50 typedef struct _GstQTDemux GstQTDemux;
51 typedef struct _GstQTDemuxClass GstQTDemuxClass;
52 typedef struct _QtDemuxStream QtDemuxStream;
53
54 enum QtDemuxState
55 {
56   QTDEMUX_STATE_INITIAL,        /* Initial state (haven't got the header yet) */
57   QTDEMUX_STATE_HEADER,         /* Parsing the header */
58   QTDEMUX_STATE_MOVIE,          /* Parsing/Playing the media data */
59   QTDEMUX_STATE_BUFFER_MDAT     /* Buffering the mdat atom */
60 };
61
62 struct _GstQTDemux {
63   GstElement element;
64
65   /* Global state */
66   enum QtDemuxState state;
67
68   /* static sink pad */
69   GstPad *sinkpad;
70
71   /* TRUE if pull-based */
72   gboolean pullbased;
73
74   gboolean posted_redirect;
75
76   QtDemuxStream *streams[GST_QTDEMUX_MAX_STREAMS];
77   gint     n_streams;
78   gint     n_video_streams;
79   gint     n_audio_streams;
80   gint     n_sub_streams;
81
82   GstFlowCombiner *flowcombiner;
83
84   /* Incoming stream group-id to set on downstream STREAM_START events.
85    * If upstream doesn't contain one, a global one will be generated */
86   gboolean have_group_id;
87   guint group_id;
88
89   guint  major_brand;
90   GstBuffer *comp_brands;
91
92   /* [moov] header.
93    * FIXME : This is discarded just after it's created. Just move it
94    * to a temporary variable ? */
95   GNode *moov_node;
96
97   /* FIXME : This is never freed. It is only assigned once. memleak ? */
98   GNode *moov_node_compressed;
99
100   /* Set to TRUE when the [moov] header has been fully parsed */
101   gboolean got_moov;
102
103   /* Global timescale for the incoming stream. Use the QTTIME macros
104    * to convert values to/from GstClockTime */
105   guint32 timescale;
106
107   /* Global duration (in global timescale). Use QTTIME macros to get GstClockTime */
108   guint64 duration;
109
110   /* Total size of header atoms. Used to calculate fallback overall bitrate */
111   guint header_size;
112
113   GstTagList *tag_list;
114
115   /* configured playback region */
116   GstSegment segment;
117
118   /* The SEGMENT_EVENT from upstream *OR* generated from segment (above) */
119   GstEvent *pending_newsegment;
120
121   guint32 segment_seqnum;
122
123   /* flag to indicate that we're working with a smoothstreaming fragment
124    * Mss doesn't have 'moov' or any information about the streams format,
125    * requiring qtdemux to expose and create the streams */
126   gboolean mss_mode;
127
128   /* Set to TRUE if the incoming stream is either a MSS stream or
129    * a Fragmented MP4 (containing the [mvex] atom in the header) */
130   gboolean fragmented;
131
132   /* PULL-BASED only : If TRUE there is a pending seek */
133   gboolean fragmented_seek_pending;
134
135   /* PULL-BASED : offset of first [moof] or of fragment to seek to
136    * PUSH-BASED : offset of latest [moof] */
137   guint64 moof_offset;
138
139   /* MSS streams have a single media that is unspecified at the atoms, so
140    * upstream provides it at the caps */
141   GstCaps *media_caps;
142
143   /* Set to TRUE when all streams have been exposed */
144   gboolean exposed;
145     
146   gint64 chapters_track_id;
147
148   /* protection support */
149   GPtrArray *protection_system_ids; /* Holds identifiers of all content protection systems for all tracks */
150   GQueue protection_event_queue; /* holds copy of upstream protection events */
151   guint64 cenc_aux_info_offset;
152   guint8 *cenc_aux_info_sizes;
153   guint32 cenc_aux_sample_count;
154
155
156   /*
157    * ALL VARIABLES BELOW ARE ONLY USED IN PUSH-BASED MODE 
158    */
159   GstAdapter *adapter;
160   guint neededbytes;
161   guint todrop;
162   /* Used to store data if [mdat] is before the headers */
163   GstBuffer *mdatbuffer;
164   /* Amount of bytes left to read in the current [mdat] */
165   guint64 mdatleft, mdatsize;
166
167   /* When restoring the mdat to the adapter, this buffer stores any
168    * trailing data that was after the last atom parsed as it has to be
169    * restored later along with the correct offset. Used in fragmented
170    * scenario where mdat/moof are one after the other in any order.
171    *
172    * Check https://bugzilla.gnome.org/show_bug.cgi?id=710623 */
173   GstBuffer *restoredata_buffer;
174   guint64 restoredata_offset;
175
176   /* The current offset in bytes from upstream.
177    * Note: While it makes complete sense when we are PULL-BASED (pulling
178    * in BYTES from upstream) and PUSH-BASED with a BYTE SEGMENT (receiving
179    * buffers with actual offsets), it is undefined in PUSH-BASED with a
180    * TIME SEGMENT */
181   guint64 offset;
182
183   /* offset of the mdat atom */
184   guint64 mdatoffset;
185   /* Offset of the first mdat */
186   guint64 first_mdat;
187   /* offset of last [moov] seen */
188   guint64 last_moov_offset;
189
190   /* If TRUE, qtdemux received upstream newsegment in TIME format
191    * which likely means that upstream is driving the pipeline (such as
192    * adaptive demuxers or dlna sources) */
193   gboolean upstream_format_is_time;
194
195   /* Seqnum of the seek event sent upstream.  Will be used to
196    * detect incoming FLUSH events corresponding to that */
197   guint32 offset_seek_seqnum;
198
199   /* UPSTREAM BYTE: Requested upstream byte seek offset.
200    * Currently it is only used to check if an incoming BYTE SEGMENT
201    * corresponds to a seek event that was sent upstream */
202   gint64 seek_offset;
203
204   /* UPSTREAM BYTE: Requested start/stop TIME values from
205    * downstream.
206    * Used to set on the downstream segment once the corresponding upstream
207    * BYTE SEEK has succeeded */
208   gint64 push_seek_start;
209   gint64 push_seek_stop;
210
211 #if 0
212   /* gst index support */
213   GstIndex *element_index;
214   gint index_id;
215 #endif
216
217   /* Whether upstream is seekable in BYTES */
218   gboolean upstream_seekable;
219   /* UPSTREAM BYTE: Size of upstream content.
220    * Note : This is only computed once ! If upstream grows in the meantime
221    * it will not be updated */
222   gint64 upstream_size;
223
224   /* UPSTREAM TIME : Contains the PTS (if any) of the
225    * buffer that contains a [moof] header. Will be used to establish
226    * the actual PTS of the samples contained within that fragment. */
227   guint64 fragment_start;
228   /* UPSTREAM TIME : The offset in bytes of the [moof]
229    * header start.
230    * Note : This is not computed from the GST_BUFFER_OFFSET field */
231   guint64 fragment_start_offset;
232 };
233
234 struct _GstQTDemuxClass {
235   GstElementClass parent_class;
236 };
237
238 GType gst_qtdemux_get_type (void);
239
240 G_END_DECLS
241
242 #endif /* __GST_QTDEMUX_H__ */