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;
103 /* expected sample duration */
104 guint expected_sample_duration_n;
105 guint expected_sample_duration_d;
107 /* for avg bitrate calculation */
109 guint64 total_duration;
112 /* dts of last_buf */
113 GstClockTime last_dts;
114 guint64 sample_offset;
116 /* This is compensate for CTTS */
117 GstClockTime dts_adjustment;
119 /* store the first timestamp for comparing with other streams and
120 * know if there are late streams */
121 /* subjected to dts adjustment */
122 GstClockTime first_ts;
123 GstClockTime first_dts;
125 /* all the atom and chunk book-keeping is delegated here
126 * unowned/uncounted reference, parent MOOV owns */
129 SampleTableEntry *trak_ste;
130 /* fragmented support */
131 /* meta data book-keeping delegated here */
133 /* fragment buffers */
134 ATOM_ARRAY (GstBuffer *) fragment_buffers;
135 /* running fragment duration */
136 gint64 fragment_duration;
137 /* optional fragment index book-keeping */
140 /* Set when tags are received, cleared when written to moov */
141 gboolean tags_changed;
145 /* if nothing is set, it won't be called */
146 GstQTPadPrepareBufferFunc prepare_buf_func;
147 GstQTPadSetCapsFunc set_caps;
148 GstQTPadCreateEmptyBufferFunc create_empty_buffer;
151 GstVideoTimeCode *first_tc;
152 GstClockTime first_pts;
155 /* for keeping track in pre-fill mode */
158 GstAdapter *raw_audio_adapter;
159 guint64 raw_audio_adapter_offset;
160 GstClockTime raw_audio_adapter_pts;
163 typedef enum _GstQTMuxState
165 GST_QT_MUX_STATE_NONE,
166 GST_QT_MUX_STATE_STARTED,
167 GST_QT_MUX_STATE_DATA,
171 typedef enum _GstQtMuxMode {
172 GST_QT_MUX_MODE_MOOV_AT_END,
173 GST_QT_MUX_MODE_FRAGMENTED,
174 GST_QT_MUX_MODE_FRAGMENTED_STREAMABLE,
175 GST_QT_MUX_MODE_FAST_START,
176 GST_QT_MUX_MODE_ROBUST_RECORDING,
177 GST_QT_MUX_MODE_ROBUST_RECORDING_PREFILL,
185 GstCollectPads *collect;
191 /* Mux mode, inferred from property
192 * set in gst_qt_mux_start_file() */
193 GstQtMuxMode mux_mode;
195 /* size of header (prefix, atoms (ftyp, possibly moov, mdat header)) */
197 /* accumulated size of raw media data (not including mdat header) */
199 /* position of the moov (for fragmented mode) or reserved moov atom
200 * area (for robust-muxing mode) */
202 /* position of mdat atom header (for later updating of size) in
203 * moov-at-end, fragmented and robust-muxing modes */
206 /* keep track of the largest chunk to fine-tune brands */
207 GstClockTime longest_chunk;
209 /* Earliest timestamp across all pads/traks
210 * (unadjusted incoming PTS) */
211 GstClockTime first_ts;
212 /* Last DTS across all pads (= duration) */
213 GstClockTime last_dts;
215 /* Last pad we used for writing the current chunk */
216 GstQTPad *current_pad;
217 guint64 current_chunk_size;
218 GstClockTime current_chunk_duration;
219 guint64 current_chunk_offset;
221 /* atom helper objects */
222 AtomsContext *context;
225 GSList *extra_atoms; /* list of extra top-level atoms (e.g. UUID for xmp)
226 * Stored as AtomInfo structs */
228 /* Set when tags are received, cleared when written to moov */
229 gboolean tags_changed;
231 /* fragmented file index */
235 FILE *fast_start_file;
238 FILE *moov_recov_file;
240 /* fragment sequence */
241 guint32 fragment_sequence;
245 guint32 trak_timescale;
246 AtomsTreeFlavor flavor;
249 #ifndef GST_REMOVE_DEPRECATED
252 gchar *fast_start_file_path;
253 gchar *moov_recov_file_path;
254 guint32 fragment_duration;
255 /* Whether or not to work in 'streamable' mode and not
256 * seek to rewrite headers - only valid for fragmented
260 /* Requested target maximum duration */
261 GstClockTime reserved_max_duration;
262 /* Estimate of remaining reserved header space (in ns of recording) */
263 GstClockTime reserved_duration_remaining;
264 /* Multiplier for conversion from reserved_max_duration to bytes */
265 guint reserved_bytes_per_sec_per_trak;
267 guint64 interleave_bytes;
268 GstClockTime interleave_time;
269 gboolean interleave_bytes_set, interleave_time_set;
271 GstClockTime max_raw_audio_drift;
273 /* Reserved minimum MOOV size in bytes
274 * This is converted from reserved_max_duration
275 * using the bytes/trak/sec estimate */
276 guint32 reserved_moov_size;
277 /* Basic size of the moov (static headers + tags) */
278 guint32 base_moov_size;
279 /* Size of the most recently generated moov header */
280 guint32 last_moov_size;
281 /* True if the first moov in the ping-pong buffers
282 * is the active one. See gst_qt_mux_robust_recording_rewrite_moov() */
283 gboolean reserved_moov_first_active;
285 /* Tracking of periodic MOOV updates */
286 GstClockTime last_moov_update;
287 GstClockTime reserved_moov_update_period;
288 GstClockTime muxed_since_last_update;
290 gboolean reserved_prefill;
292 /* for request pad naming */
293 guint video_pads, audio_pads, subtitle_pads, caption_pads;
296 struct _GstQTMuxClass
298 GstElementClass parent_class;
300 GstQTMuxFormat format;
303 /* type register helper struct */
304 typedef struct _GstQTMuxClassParams
306 GstQTMuxFormatProp *prop;
308 GstCaps *video_sink_caps;
309 GstCaps *audio_sink_caps;
310 GstCaps *subtitle_sink_caps;
311 GstCaps *caption_sink_caps;
312 } GstQTMuxClassParams;
314 #define GST_QT_MUX_PARAMS_QDATA g_quark_from_static_string("qt-mux-params")
316 GType gst_qt_mux_get_type (void);
317 gboolean gst_qt_mux_register (GstPlugin * plugin);
319 /* FIXME: ideally classification tag should be added and
320 * registered in gstreamer core gsttaglist
322 * this tag is a string in the format: entityfourcc://table_num/content
323 * FIXME Shouldn't we add a field for 'language'?
325 #define GST_TAG_3GP_CLASSIFICATION "classification"
329 #endif /* __GST_QT_MUX_H__ */