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