qtdemux: fix crash when qtdemux dispose (free spherical_metadata)
[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 #ifdef TIZEN_FEATURE_QTDEMUX_MODIFICATION
57 typedef struct _QtDemuxSphericalMetadata QtDemuxSphericalMetadata;
58 #endif
59
60 struct _GstQTDemux {
61   GstElement element;
62
63   /* pads */
64   GstPad *sinkpad;
65
66   QtDemuxStream *streams[GST_QTDEMUX_MAX_STREAMS];
67   gint     n_streams;
68   gint     n_video_streams;
69   gint     n_audio_streams;
70   gint     n_sub_streams;
71
72   GstFlowCombiner *flowcombiner;
73
74   gboolean have_group_id;
75   guint group_id;
76
77   guint  major_brand;
78   GstBuffer *comp_brands;
79   GNode *moov_node;
80   GNode *moov_node_compressed;
81
82   guint32 timescale;
83   GstClockTime duration;
84
85   gboolean fragmented;
86   gboolean fragmented_seek_pending;
87   guint64 moof_offset;
88
89   gint state;
90
91   gboolean pullbased;
92   gboolean posted_redirect;
93
94   /* push based variables */
95   guint neededbytes;
96   guint todrop;
97   GstAdapter *adapter;
98   GstBuffer *mdatbuffer;
99   guint64 mdatleft;
100   /* When restoring the mdat to the adatpter, this buffer
101    * stores any trailing data that was after the last atom parsed as it
102    * has to be restored later along with the correct offset. Used in
103    * fragmented scenario where mdat/moof are one after the other
104    * in any order.
105    *
106    * Check https://bugzilla.gnome.org/show_bug.cgi?id=710623 */
107   GstBuffer *restoredata_buffer;
108   guint64 restoredata_offset;
109
110   guint64 offset;
111   /* offset of the mdat atom */
112   guint64 mdatoffset;
113   guint64 first_mdat;
114   gboolean got_moov;
115   guint64 last_moov_offset;
116   guint header_size;
117
118   GstTagList *tag_list;
119
120   /* configured playback region */
121   GstSegment segment;
122   GstEvent *pending_newsegment;
123   gboolean upstream_format_is_time; /* qtdemux received upstream
124                                      * newsegment in TIME format which likely
125                                      * means that upstream is driving the pipeline
126                                      * (adaptive demuxers / dlna) */
127   gint64 seek_offset;
128   gint64 push_seek_start;
129   gint64 push_seek_stop;
130
131 #if 0
132   /* gst index support */
133   GstIndex *element_index;
134   gint index_id;
135 #endif
136
137   gboolean upstream_seekable;
138   gint64 upstream_size;
139
140   /* MSS streams have a single media that is unspecified at the atoms, so
141    * upstream provides it at the caps */
142   GstCaps *media_caps;
143   gboolean exposed;
144   gboolean mss_mode; /* flag to indicate that we're working with a smoothstreaming fragment
145                       * Mss doesn't have 'moov' or any information about the streams format,
146                       * requiring qtdemux to expose and create the streams */
147   guint64 fragment_start;
148   guint64 fragment_start_offset;
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 #ifdef TIZEN_FEATURE_QTDEMUX_MODIFICATION
156   QtDemuxSphericalMetadata *spherical_metadata;
157 #endif
158 };
159
160 struct _GstQTDemuxClass {
161   GstElementClass parent_class;
162 };
163
164 GType gst_qtdemux_get_type (void);
165
166 G_END_DECLS
167
168 #endif /* __GST_QTDEMUX_H__ */