1 /* Quicktime muxer plugin for GStreamer
2 * Copyright (C) 2008-2010 Thiago Santos <thiagoss@embedded.ufcg.edu.br>
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.
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.
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.
20 * Unless otherwise indicated, Source Code is licensed under MIT license.
21 * See further explanation attached in License Statement (distributed in the file
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:
31 * The above copyright notice and this permission notice shall be included in all
32 * copies or substantial portions of the Software.
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
43 #ifndef __GST_QT_MUX_H__
44 #define __GST_QT_MUX_H__
47 #include <gst/base/gstcollectpads.h>
51 #include "atomsrecovery.h"
52 #include "gstqtmuxmap.h"
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))
64 typedef struct _GstQTMux GstQTMux;
65 typedef struct _GstQTMuxClass GstQTMuxClass;
66 typedef struct _GstQTPad GstQTPad;
69 * GstQTPadPrepareBufferFunc
71 * Receives a buffer (takes ref) and returns a new buffer that should
72 * replace the passed one.
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)
78 typedef GstBuffer * (*GstQTPadPrepareBufferFunc) (GstQTPad * pad,
79 GstBuffer * buf, GstQTMux * qtmux);
81 typedef gboolean (*GstQTPadSetCapsFunc) (GstQTPad * pad, GstCaps * caps);
82 typedef GstBuffer * (*GstQTPadCreateEmptyBufferFunc) (GstQTPad * pad, gint64 duration);
84 #define QTMUX_NO_OF_TS 10
88 GstCollectData collect; /* we extend the CollectData */
90 /* fourcc id of stream */
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 */
96 /* make sync table entry */
98 /* if it is a sparse stream
99 * (meaning we can't use PTS differences to compute duration) */
102 guint32 avg_bitrate, max_bitrate;
104 /* for avg bitrate calculation */
106 guint64 total_duration;
109 /* dts of last_buf */
110 GstClockTime last_dts;
112 /* This is compensate for CTTS */
113 GstClockTime dts_adjustment;
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;
123 /* all the atom and chunk book-keeping is delegated here
124 * unowned/uncounted reference, parent MOOV owns */
126 SampleTableEntry *trak_ste;
127 /* fragmented support */
128 /* meta data book-keeping delegated here */
130 /* fragment buffers */
131 ATOM_ARRAY (GstBuffer *) fragment_buffers;
132 /* running fragment duration */
133 gint64 fragment_duration;
134 /* optional fragment index book-keeping */
137 /* Set when tags are received, cleared when written to moov */
138 gboolean tags_changed;
142 /* if nothing is set, it won't be called */
143 GstQTPadPrepareBufferFunc prepare_buf_func;
144 GstQTPadSetCapsFunc set_caps;
145 GstQTPadCreateEmptyBufferFunc create_empty_buffer;
148 typedef enum _GstQTMuxState
150 GST_QT_MUX_STATE_NONE,
151 GST_QT_MUX_STATE_STARTED,
152 GST_QT_MUX_STATE_DATA,
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
169 GstCollectPads *collect;
175 /* Mux mode, inferred from property
176 * set in gst_qt_mux_start_file() */
177 GstQtMuxMode mux_mode;
179 /* size of header (prefix, atoms (ftyp, possibly moov, mdat header)) */
181 /* accumulated size of raw media data (not including mdat header) */
183 /* position of the moov (for fragmented mode) or reserved moov atom
184 * area (for robust-muxing mode) */
186 /* position of mdat atom header (for later updating of size) in
187 * moov-at-end, fragmented and robust-muxing modes */
190 /* keep track of the largest chunk to fine-tune brands */
191 GstClockTime longest_chunk;
193 /* Earliest timestamp across all pads/traks */
194 GstClockTime first_ts;
195 /* Last DTS across all pads (= duration) */
196 GstClockTime last_dts;
198 /* atom helper objects */
199 AtomsContext *context;
202 GSList *extra_atoms; /* list of extra top-level atoms (e.g. UUID for xmp)
203 * Stored as AtomInfo structs */
205 /* Set when tags are received, cleared when written to moov */
206 gboolean tags_changed;
209 /* fragmented file index */
213 FILE *fast_start_file;
216 FILE *moov_recov_file;
218 /* fragment sequence */
219 guint32 fragment_sequence;
223 guint32 trak_timescale;
224 AtomsTreeFlavor flavor;
227 #ifndef GST_REMOVE_DEPRECATED
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
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;
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;
257 /* Tracking of periodic MOOV updates */
258 GstClockTime last_moov_update;
259 GstClockTime reserved_moov_update_period;
260 GstClockTime muxed_since_last_update;
262 /* for request pad naming */
263 guint video_pads, audio_pads, subtitle_pads;
265 #ifdef TIZEN_FEATURE_GST_MUX_ENHANCEMENT
266 guint expected_trailer_size;
267 guint audio_expected_trailer_size;
268 guint video_expected_trailer_size;
269 #endif /* TIZEN_FEATURE_GST_MUX_ENHANCEMENT */
272 struct _GstQTMuxClass
274 GstElementClass parent_class;
276 GstQTMuxFormat format;
279 /* type register helper struct */
280 typedef struct _GstQTMuxClassParams
282 GstQTMuxFormatProp *prop;
284 GstCaps *video_sink_caps;
285 GstCaps *audio_sink_caps;
286 GstCaps *subtitle_sink_caps;
287 } GstQTMuxClassParams;
289 #define GST_QT_MUX_PARAMS_QDATA g_quark_from_static_string("qt-mux-params")
291 GType gst_qt_mux_get_type (void);
292 gboolean gst_qt_mux_register (GstPlugin * plugin);
294 /* FIXME: ideally classification tag should be added and
295 * registered in gstreamer core gsttaglist
297 * this tag is a string in the format: entityfourcc://table_num/content
298 * FIXME Shouldn't we add a field for 'language'?
300 #define GST_TAG_3GP_CLASSIFICATION "classification"
304 #endif /* __GST_QT_MUX_H__ */