qtdemux: Add/Fix comments on the various structure variables
[platform/upstream/gst-plugins-good.git] / gst / isomp4 / gstqtmux.h
1 /* Quicktime muxer plugin for GStreamer
2  * Copyright (C) 2008-2010 Thiago Santos <thiagoss@embedded.ufcg.edu.br>
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  * Unless otherwise indicated, Source Code is licensed under MIT license.
21  * See further explanation attached in License Statement (distributed in the file
22  * LICENSE).
23  *
24  * Permission is hereby granted, free of charge, to any person obtaining a copy of
25  * this software and associated documentation files (the "Software"), to deal in
26  * the Software without restriction, including without limitation the rights to
27  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
28  * of the Software, and to permit persons to whom the Software is furnished to do
29  * so, subject to the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be included in all
32  * copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
37  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
39  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
40  * SOFTWARE.
41  */
42
43 #ifndef __GST_QT_MUX_H__
44 #define __GST_QT_MUX_H__
45
46 #include <gst/gst.h>
47 #include <gst/base/gstcollectpads.h>
48
49 #include "fourcc.h"
50 #include "atoms.h"
51 #include "atomsrecovery.h"
52 #include "gstqtmuxmap.h"
53
54 G_BEGIN_DECLS
55
56 #define GST_TYPE_QT_MUX (gst_qt_mux_get_type())
57 #define GST_QT_MUX(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_QT_MUX, GstQTMux))
58 #define GST_QT_MUX_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_QT_MUX, GstQTMux))
59 #define GST_IS_QT_MUX(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_QT_MUX))
60 #define GST_IS_QT_MUX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_QT_MUX))
61 #define GST_QT_MUX_CAST(obj) ((GstQTMux*)(obj))
62
63
64 typedef struct _GstQTMux GstQTMux;
65 typedef struct _GstQTMuxClass GstQTMuxClass;
66 typedef struct _GstQTPad GstQTPad;
67
68 /*
69  * GstQTPadPrepareBufferFunc
70  *
71  * Receives a buffer (takes ref) and returns a new buffer that should
72  * replace the passed one.
73  *
74  * Useful for when the pad/datatype needs some manipulation before
75  * being muxed. (Originally added for image/x-jpc support, for which buffers
76  * need to be wrapped into a isom box)
77  */
78 typedef GstBuffer * (*GstQTPadPrepareBufferFunc) (GstQTPad * pad,
79     GstBuffer * buf, GstQTMux * qtmux);
80
81 typedef gboolean (*GstQTPadSetCapsFunc) (GstQTPad * pad, GstCaps * caps);
82 typedef GstBuffer * (*GstQTPadCreateEmptyBufferFunc) (GstQTPad * pad, gint64 duration);
83
84 #define QTMUX_NO_OF_TS   10
85
86 struct _GstQTPad
87 {
88   GstCollectData collect;       /* we extend the CollectData */
89
90   /* fourcc id of stream */
91   guint32 fourcc;
92   /* whether using format that have out of order buffers */
93   gboolean is_out_of_order;
94   /* if not 0, track with constant sized samples, e.g. raw audio */
95   guint sample_size;
96   /* make sync table entry */
97   gboolean sync;
98   /* if it is a sparse stream
99    * (meaning we can't use PTS differences to compute duration) */
100   gboolean sparse;
101   /* bitrates */
102   guint32 avg_bitrate, max_bitrate;
103
104   /* for avg bitrate calculation */
105   guint64 total_bytes;
106   guint64 total_duration;
107
108   GstBuffer *last_buf;
109   /* dts of last_buf */
110   GstClockTime last_dts;
111
112   /* This is compensate for CTTS */
113   GstClockTime dts_adjustment;
114
115   /* store the first timestamp for comparing with other streams and
116    * know if there are late streams */
117   GstClockTime first_ts;
118   GstClockTime first_dts;
119
120   guint buf_head;
121   guint buf_tail;
122
123   /* all the atom and chunk book-keeping is delegated here
124    * unowned/uncounted reference, parent MOOV owns */
125   AtomTRAK *trak;
126   SampleTableEntry *trak_ste;
127   /* fragmented support */
128   /* meta data book-keeping delegated here */
129   AtomTRAF *traf;
130   /* fragment buffers */
131   ATOM_ARRAY (GstBuffer *) fragment_buffers;
132   /* running fragment duration */
133   gint64 fragment_duration;
134   /* optional fragment index book-keeping */
135   AtomTFRA *tfra;
136
137   /* Set when tags are received, cleared when written to moov */
138   gboolean tags_changed;
139
140   GstTagList *tags;
141
142   /* if nothing is set, it won't be called */
143   GstQTPadPrepareBufferFunc prepare_buf_func;
144   GstQTPadSetCapsFunc set_caps;
145   GstQTPadCreateEmptyBufferFunc create_empty_buffer;
146 };
147
148 typedef enum _GstQTMuxState
149 {
150   GST_QT_MUX_STATE_NONE,
151   GST_QT_MUX_STATE_STARTED,
152   GST_QT_MUX_STATE_DATA,
153   GST_QT_MUX_STATE_EOS
154 } GstQTMuxState;
155
156 typedef enum _GstQtMuxMode {
157     GST_QT_MUX_MODE_MOOV_AT_END,
158     GST_QT_MUX_MODE_FRAGMENTED,
159     GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE,
160     GST_QT_MUX_MODE_FAST_START,
161     GST_QT_MUX_MODE_ROBUST_RECORDING
162 } GstQtMuxMode;
163
164 struct _GstQTMux
165 {
166   GstElement element;
167
168   GstPad *srcpad;
169   GstCollectPads *collect;
170   GSList *sinkpads;
171
172   /* state */
173   GstQTMuxState state;
174
175   /* Mux mode, inferred from property
176    * set in gst_qt_mux_start_file() */
177   GstQtMuxMode mux_mode;
178
179   /* size of header (prefix, atoms (ftyp, possibly moov, mdat header)) */
180   guint64 header_size;
181   /* accumulated size of raw media data (not including mdat header) */
182   guint64 mdat_size;
183   /* position of the moov (for fragmented mode) or reserved moov atom
184    * area (for robust-muxing mode) */
185   guint64 moov_pos;
186   /* position of mdat atom header (for later updating of size) in
187    * moov-at-end, fragmented and robust-muxing modes */
188   guint64 mdat_pos;
189
190   /* keep track of the largest chunk to fine-tune brands */
191   GstClockTime longest_chunk;
192
193   /* Earliest timestamp across all pads/traks */
194   GstClockTime first_ts;
195   /* Last DTS across all pads (= duration) */
196   GstClockTime last_dts;
197
198   /* atom helper objects */
199   AtomsContext *context;
200   AtomFTYP *ftyp;
201   AtomMOOV *moov;
202   GSList *extra_atoms; /* list of extra top-level atoms (e.g. UUID for xmp)
203                         * Stored as AtomInfo structs */
204
205   /* Set when tags are received, cleared when written to moov */
206   gboolean tags_changed;
207
208
209   /* fragmented file index */
210   AtomMFRA *mfra;
211
212   /* fast start */
213   FILE *fast_start_file;
214
215   /* moov recovery */
216   FILE *moov_recov_file;
217
218   /* fragment sequence */
219   guint32 fragment_sequence;
220
221   /* properties */
222   guint32 timescale;
223   guint32 trak_timescale;
224   AtomsTreeFlavor flavor;
225   gboolean fast_start;
226   gboolean guess_pts;
227 #ifndef GST_REMOVE_DEPRECATED
228   gint dts_method;
229 #endif
230   gchar *fast_start_file_path;
231   gchar *moov_recov_file_path;
232   guint32 fragment_duration;
233   /* Whether or not to work in 'streamable' mode and not
234    * seek to rewrite headers - only valid for fragmented
235    * mode. */
236   gboolean streamable;
237
238   /* Requested target maximum duration */
239   GstClockTime reserved_max_duration;
240   /* Estimate of remaining reserved header space (in ns of recording) */
241   GstClockTime reserved_duration_remaining;
242   /* Multiplier for conversion from reserved_max_duration to bytes */
243   guint reserved_bytes_per_sec_per_trak;
244
245   /* Reserved minimum MOOV size in bytes
246    * This is converted from reserved_max_duration
247    * using the bytes/trak/sec estimate */
248   guint32 reserved_moov_size;
249   /* Basic size of the moov (static headers + tags) */
250   guint32 base_moov_size;
251   /* Size of the most recently generated moov header */
252   guint32 last_moov_size;
253   /* True if the first moov in the ping-pong buffers
254    * is the active one. See gst_qt_mux_robust_recording_rewrite_moov() */
255   gboolean reserved_moov_first_active;
256
257   /* Tracking of periodic MOOV updates */
258   GstClockTime last_moov_update;
259   GstClockTime reserved_moov_update_period;
260   GstClockTime muxed_since_last_update;
261
262   /* for request pad naming */
263   guint video_pads, audio_pads, subtitle_pads;
264 };
265
266 struct _GstQTMuxClass
267 {
268   GstElementClass parent_class;
269
270   GstQTMuxFormat format;
271 };
272
273 /* type register helper struct */
274 typedef struct _GstQTMuxClassParams
275 {
276   GstQTMuxFormatProp *prop;
277   GstCaps *src_caps;
278   GstCaps *video_sink_caps;
279   GstCaps *audio_sink_caps;
280   GstCaps *subtitle_sink_caps;
281 } GstQTMuxClassParams;
282
283 #define GST_QT_MUX_PARAMS_QDATA g_quark_from_static_string("qt-mux-params")
284
285 GType gst_qt_mux_get_type (void);
286 gboolean gst_qt_mux_register (GstPlugin * plugin);
287
288 /* FIXME: ideally classification tag should be added and
289  * registered in gstreamer core gsttaglist
290  *
291  * this tag is a string in the format: entityfourcc://table_num/content
292  * FIXME Shouldn't we add a field for 'language'?
293  */
294 #define GST_TAG_3GP_CLASSIFICATION "classification"
295
296 G_END_DECLS
297
298 #endif /* __GST_QT_MUX_H__ */