1 /* Quicktime muxer plugin for GStreamer
2 * Copyright (C) 2008 Thiago Sousa Santos <thiagoss@embedded.ufcg.edu.br>
3 * Copyright (C) 2008 Mark Nauwelaerts <mnauw@users.sf.net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 * Unless otherwise indicated, Source Code is licensed under MIT license.
22 * See further explanation attached in License Statement (distributed in the file
25 * Permission is hereby granted, free of charge, to any person obtaining a copy of
26 * this software and associated documentation files (the "Software"), to deal in
27 * the Software without restriction, including without limitation the rights to
28 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
29 * of the Software, and to permit persons to whom the Software is furnished to do
30 * so, subject to the following conditions:
32 * The above copyright notice and this permission notice shall be included in all
33 * copies or substantial portions of the Software.
35 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
38 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
39 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
40 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
47 * @short_description: Muxer for quicktime(.mov) files
51 * This element merges streams (audio and video) into qt(.mov) files.
53 * <title>Example pipelines</title>
56 * gst-launch v4l2src num-buffers=500 ! video/x-raw-yuv,width=320,height=240 ! ffmpegcolorspace ! qtmux ! filesink location=video.mov
58 * Records a video stream captured from a v4l2 device and muxes it into a qt file.
62 * Last reviewed on 2008-08-27
73 #include <glib/gstdio.h>
76 #include <gst/base/gstcollectpads.h>
78 #include <sys/types.h>
80 #include <io.h> /* lseek, open, close, read */
82 #define lseek _lseeki64
93 GST_DEBUG_CATEGORY_STATIC (gst_qt_mux_debug);
94 #define GST_CAT_DEFAULT gst_qt_mux_debug
96 /* QTMux signals and args */
107 PROP_MOVIE_TIMESCALE,
111 PROP_FAST_START_TEMP_FILE
114 /* some spare for header size as well */
115 #define MDAT_LARGE_FILE_LIMIT ((guint64) 1024 * 1024 * 1024 * 2)
117 #define DEFAULT_LARGE_FILE FALSE
118 #define DEFAULT_MOVIE_TIMESCALE 1000
119 #define DEFAULT_DO_CTTS FALSE
120 #define DEFAULT_FAST_START FALSE
121 #define DEFAULT_FAST_START_TEMP_FILE NULL
123 static void gst_qt_mux_finalize (GObject * object);
125 static GstStateChangeReturn gst_qt_mux_change_state (GstElement * element,
126 GstStateChange transition);
128 /* property functions */
129 static void gst_qt_mux_set_property (GObject * object,
130 guint prop_id, const GValue * value, GParamSpec * pspec);
131 static void gst_qt_mux_get_property (GObject * object,
132 guint prop_id, GValue * value, GParamSpec * pspec);
135 static GstPad *gst_qt_mux_request_new_pad (GstElement * element,
136 GstPadTemplate * templ, const gchar * name);
137 static void gst_qt_mux_release_pad (GstElement * element, GstPad * pad);
140 static gboolean gst_qt_mux_sink_event (GstPad * pad, GstEvent * event);
142 static GstFlowReturn gst_qt_mux_collected (GstCollectPads * pads,
144 static GstFlowReturn gst_qt_mux_add_buffer (GstQTMux * qtmux, GstQTPad * pad,
147 static GstElementClass *parent_class = NULL;
150 gst_qt_mux_base_init (gpointer g_class)
152 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
153 GstQTMuxClass *klass = (GstQTMuxClass *) g_class;
154 GstQTMuxClassParams *params;
155 GstElementDetails details;
156 GstPadTemplate *videosinktempl, *audiosinktempl, *srctempl;
159 (GstQTMuxClassParams *) g_type_get_qdata (G_OBJECT_CLASS_TYPE (g_class),
160 GST_QT_MUX_PARAMS_QDATA);
161 g_assert (params != NULL);
163 /* construct the element details struct */
164 details.longname = g_strdup_printf ("%s Muxer", params->prop->long_name);
165 details.klass = g_strdup ("Codec/Muxer");
166 details.description =
167 g_strdup_printf ("Multiplex audio and video into a %s file",
168 params->prop->long_name);
169 details.author = "Thiago Sousa Santos <thiagoss@embedded.ufcg.edu.br>";
170 gst_element_class_set_details (element_class, &details);
171 g_free (details.longname);
172 g_free (details.klass);
173 g_free (details.description);
176 srctempl = gst_pad_template_new ("src", GST_PAD_SRC,
177 GST_PAD_ALWAYS, params->src_caps);
178 gst_element_class_add_pad_template (element_class, srctempl);
180 if (params->audio_sink_caps) {
181 audiosinktempl = gst_pad_template_new ("audio_%d",
182 GST_PAD_SINK, GST_PAD_REQUEST, params->audio_sink_caps);
183 gst_element_class_add_pad_template (element_class, audiosinktempl);
186 if (params->video_sink_caps) {
187 videosinktempl = gst_pad_template_new ("video_%d",
188 GST_PAD_SINK, GST_PAD_REQUEST, params->video_sink_caps);
189 gst_element_class_add_pad_template (element_class, videosinktempl);
192 klass->format = params->prop->format;
196 gst_qt_mux_class_init (GstQTMuxClass * klass)
198 GObjectClass *gobject_class;
199 GstElementClass *gstelement_class;
201 gobject_class = (GObjectClass *) klass;
202 gstelement_class = (GstElementClass *) klass;
204 parent_class = g_type_class_peek_parent (klass);
206 gobject_class->finalize = gst_qt_mux_finalize;
207 gobject_class->get_property = gst_qt_mux_get_property;
208 gobject_class->set_property = gst_qt_mux_set_property;
210 g_object_class_install_property (gobject_class, PROP_LARGE_FILE,
211 g_param_spec_boolean ("large-file", "Support for large files",
212 "Uses 64bits to some fields instead of 32bits, "
213 "providing support for large files",
214 DEFAULT_LARGE_FILE, G_PARAM_READWRITE));
215 g_object_class_install_property (gobject_class, PROP_MOVIE_TIMESCALE,
216 g_param_spec_uint ("movie-timescale", "Movie timescale",
217 "Timescale to use in the movie (units per second)",
218 1, G_MAXUINT32, DEFAULT_MOVIE_TIMESCALE,
219 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
220 g_object_class_install_property (gobject_class, PROP_DO_CTTS,
221 g_param_spec_boolean ("presentation-time",
222 "Include presentation-time info",
223 "Calculate and include presentation/composition time (in addition to decoding time)"
224 " (use with caution)", DEFAULT_DO_CTTS,
225 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
226 g_object_class_install_property (gobject_class, PROP_FAST_START,
227 g_param_spec_boolean ("faststart", "Format file to faststart",
228 "If the file should be formated for faststart (headers first). ",
229 DEFAULT_FAST_START, G_PARAM_READWRITE));
230 g_object_class_install_property (gobject_class, PROP_FAST_START_TEMP_FILE,
231 g_param_spec_string ("faststart-file", "File to use for storing buffers",
232 "File that will be used temporarily to store data from the stream when "
233 "creating a faststart file. If null a filepath will be created automatically",
234 DEFAULT_FAST_START_TEMP_FILE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
236 gstelement_class->request_new_pad =
237 GST_DEBUG_FUNCPTR (gst_qt_mux_request_new_pad);
238 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_qt_mux_change_state);
239 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_qt_mux_release_pad);
243 gst_qt_mux_pad_reset (GstQTPad * qtpad)
246 qtpad->is_out_of_order = FALSE;
247 qtpad->have_dts = FALSE;
248 qtpad->sample_size = 0;
253 gst_buffer_replace (&qtpad->last_buf, NULL);
255 /* reference owned elsewhere */
260 * Takes GstQTMux back to its initial state
263 gst_qt_mux_reset (GstQTMux * qtmux, gboolean alloc)
267 qtmux->state = GST_QT_MUX_STATE_NONE;
268 qtmux->header_size = 0;
269 qtmux->mdat_size = 0;
273 atom_ftyp_free (qtmux->ftyp);
277 atom_moov_free (qtmux->moov);
280 if (qtmux->fast_start_file) {
281 fclose (qtmux->fast_start_file);
282 qtmux->fast_start_file = NULL;
284 gst_tag_setter_reset_tags (GST_TAG_SETTER (qtmux));
287 for (walk = qtmux->collect->data; walk; walk = g_slist_next (walk)) {
288 GstQTPad *qtpad = (GstQTPad *) walk->data;
289 gst_qt_mux_pad_reset (qtpad);
291 /* hm, moov_free above yanked the traks away from us,
292 * so do not free, but do clear */
297 qtmux->moov = atom_moov_new (qtmux->context);
298 /* ensure all is as nice and fresh as request_new_pad would provide it */
299 for (walk = qtmux->collect->data; walk; walk = g_slist_next (walk)) {
300 GstQTPad *qtpad = (GstQTPad *) walk->data;
302 qtpad->trak = atom_trak_new (qtmux->context);
303 atom_moov_add_trak (qtmux->moov, qtpad->trak);
309 gst_qt_mux_init (GstQTMux * qtmux, GstQTMuxClass * qtmux_klass)
311 GstElementClass *klass = GST_ELEMENT_CLASS (qtmux_klass);
312 GstPadTemplate *templ;
315 templ = gst_element_class_get_pad_template (klass, "src");
316 qtmux->srcpad = gst_pad_new_from_template (templ, "src");
317 caps = gst_caps_copy (gst_pad_get_pad_template_caps (qtmux->srcpad));
318 gst_pad_set_caps (qtmux->srcpad, caps);
319 gst_caps_unref (caps);
320 gst_pad_use_fixed_caps (qtmux->srcpad);
321 gst_element_add_pad (GST_ELEMENT (qtmux), qtmux->srcpad);
323 qtmux->collect = gst_collect_pads_new ();
324 gst_collect_pads_set_function (qtmux->collect,
325 (GstCollectPadsFunction) GST_DEBUG_FUNCPTR (gst_qt_mux_collected), qtmux);
327 /* properties set to default upon construction */
329 /* always need this */
331 atoms_context_new (gst_qt_mux_map_format_to_flavor (qtmux_klass->format));
333 /* internals to initial state */
334 gst_qt_mux_reset (qtmux, TRUE);
339 gst_qt_mux_finalize (GObject * object)
341 GstQTMux *qtmux = GST_QT_MUX_CAST (object);
343 gst_qt_mux_reset (qtmux, FALSE);
345 if (qtmux->fast_start_file_path)
346 g_free (qtmux->fast_start_file_path);
348 atoms_context_free (qtmux->context);
349 gst_object_unref (qtmux->collect);
351 G_OBJECT_CLASS (parent_class)->finalize (object);
355 gst_qt_mux_add_mp4_tag (GstQTMux * qtmux, const GstTagList * list,
356 const char *tag, const char *tag2, guint32 fourcc)
358 switch (gst_tag_get_type (tag)) {
364 if (!gst_tag_list_get_string (list, tag, &str) || !str)
366 GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s",
367 GST_FOURCC_ARGS (fourcc), str);
368 atom_moov_add_str_tag (qtmux->moov, fourcc, str);
377 if (!gst_tag_list_get_double (list, tag, &value))
379 GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %u",
380 GST_FOURCC_ARGS (fourcc), (gint) value);
381 atom_moov_add_uint_tag (qtmux->moov, fourcc, 21, (gint) value);
384 /* paired unsigned integers */
390 if (!gst_tag_list_get_uint (list, tag, &value) ||
391 !gst_tag_list_get_uint (list, tag2, &count))
393 GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %u/%u",
394 GST_FOURCC_ARGS (fourcc), value, count);
395 atom_moov_add_uint_tag (qtmux->moov, fourcc, 0,
396 value << 16 | (count & 0xFFFF));
400 g_assert_not_reached ();
406 gst_qt_mux_add_mp4_date (GstQTMux * qtmux, const GstTagList * list,
407 const char *tag, const char *tag2, guint32 fourcc)
415 g_return_if_fail (gst_tag_get_type (tag) == GST_TYPE_DATE);
417 if (!gst_tag_list_get_date (list, tag, &date) || !date)
420 year = g_date_get_year (date);
421 month = g_date_get_month (date);
422 day = g_date_get_day (date);
424 if (year == G_DATE_BAD_YEAR && month == G_DATE_BAD_MONTH &&
425 day == G_DATE_BAD_DAY) {
426 GST_WARNING_OBJECT (qtmux, "invalid date in tag");
430 str = g_strdup_printf ("%u-%u-%u", year, month, day);
431 GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s",
432 GST_FOURCC_ARGS (fourcc), str);
433 atom_moov_add_str_tag (qtmux->moov, fourcc, str);
437 gst_qt_mux_add_mp4_cover (GstQTMux * qtmux, const GstTagList * list,
438 const char *tag, const char *tag2, guint32 fourcc)
440 GValue value = { 0, };
443 GstStructure *structure;
446 g_return_if_fail (gst_tag_get_type (tag) == GST_TYPE_BUFFER);
448 if (!gst_tag_list_copy_value (&value, list, tag))
451 buf = gst_value_get_buffer (&value);
455 caps = gst_buffer_get_caps (buf);
457 GST_WARNING_OBJECT (qtmux, "preview image without caps");
461 GST_DEBUG_OBJECT (qtmux, "preview image caps %" GST_PTR_FORMAT, caps);
463 structure = gst_caps_get_structure (caps, 0);
464 if (gst_structure_has_name (structure, "image/jpeg"))
466 else if (gst_structure_has_name (structure, "image/png"))
468 gst_caps_unref (caps);
471 GST_WARNING_OBJECT (qtmux, "preview image format not supported");
475 GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT
476 " -> image size %d", GST_FOURCC_ARGS (fourcc), GST_BUFFER_SIZE (buf));
477 atom_moov_add_tag (qtmux->moov, fourcc, flags, GST_BUFFER_DATA (buf),
478 GST_BUFFER_SIZE (buf));
480 g_value_unset (&value);
484 gst_qt_mux_add_3gp_str (GstQTMux * qtmux, const GstTagList * list,
485 const char *tag, const char *tag2, guint32 fourcc)
490 g_return_if_fail (gst_tag_get_type (tag) == G_TYPE_STRING);
491 g_return_if_fail (!tag2 || gst_tag_get_type (tag2) == G_TYPE_UINT);
493 if (!gst_tag_list_get_string (list, tag, &str) || !str)
497 if (!gst_tag_list_get_uint (list, tag2, &number))
501 GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s",
502 GST_FOURCC_ARGS (fourcc), str);
503 atom_moov_add_3gp_str_tag (qtmux->moov, fourcc, str);
505 GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s/%d",
506 GST_FOURCC_ARGS (fourcc), str, number);
507 atom_moov_add_3gp_str_int_tag (qtmux->moov, fourcc, str, number);
514 gst_qt_mux_add_3gp_date (GstQTMux * qtmux, const GstTagList * list,
515 const char *tag, const char *tag2, guint32 fourcc)
520 g_return_if_fail (gst_tag_get_type (tag) == GST_TYPE_DATE);
522 if (!gst_tag_list_get_date (list, tag, &date) || !date)
525 year = g_date_get_year (date);
527 if (year == G_DATE_BAD_YEAR) {
528 GST_WARNING_OBJECT (qtmux, "invalid date in tag");
532 GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %d",
533 GST_FOURCC_ARGS (fourcc), year);
534 atom_moov_add_3gp_uint_tag (qtmux->moov, fourcc, year);
538 gst_qt_mux_add_3gp_location (GstQTMux * qtmux, const GstTagList * list,
539 const char *tag, const char *tag2, guint32 fourcc)
541 gdouble latitude = -360, longitude = -360, altitude = 0;
542 gchar *location = NULL;
543 guint8 *data, *ddata;
544 gint size = 0, len = 0;
545 gboolean ret = FALSE;
547 g_return_if_fail (strcmp (tag, GST_TAG_GEO_LOCATION_NAME) == 0);
549 ret = gst_tag_list_get_string (list, tag, &location);
550 ret |= gst_tag_list_get_double (list, GST_TAG_GEO_LOCATION_LONGITUDE,
552 ret |= gst_tag_list_get_double (list, GST_TAG_GEO_LOCATION_LATITUDE,
554 ret |= gst_tag_list_get_double (list, GST_TAG_GEO_LOCATION_ELEVATION,
561 len = strlen (location);
564 /* role + (long, lat, alt) + body + notes */
565 size += 1 + 3 * 4 + 1 + 1;
567 data = ddata = g_malloc (size);
570 GST_WRITE_UINT16_BE (data, language_code (GST_QT_MUX_DEFAULT_TAG_LANGUAGE));
573 memcpy (data + 2, location, len);
574 GST_WRITE_UINT8 (data + 2 + len, 0);
577 GST_WRITE_UINT8 (data, 0);
579 GST_WRITE_UINT32_BE (data + 1, (guint32) (longitude * 65536.0));
580 GST_WRITE_UINT32_BE (data + 5, (guint32) (latitude * 65536.0));
581 GST_WRITE_UINT32_BE (data + 9, (guint32) (altitude * 65536.0));
582 /* neither astronomical body nor notes */
583 GST_WRITE_UINT16_BE (data + 13, 0);
585 GST_DEBUG_OBJECT (qtmux, "Adding tag 'loci'");
586 atom_moov_add_3gp_tag (qtmux->moov, fourcc, ddata, size);
591 gst_qt_mux_add_3gp_keywords (GstQTMux * qtmux, const GstTagList * list,
592 const char *tag, const char *tag2, guint32 fourcc)
594 gchar *keywords = NULL;
595 guint8 *data, *ddata;
599 g_return_if_fail (strcmp (tag, GST_TAG_KEYWORDS) == 0);
601 if (!gst_tag_list_get_string (list, tag, &keywords) || !keywords)
604 kwds = g_strsplit (keywords, ",", 0);
607 for (i = 0; kwds[i]; i++) {
608 /* size byte + null-terminator */
609 size += strlen (kwds[i]) + 1 + 1;
612 /* language tag + count + keywords */
615 data = ddata = g_malloc (size);
618 GST_WRITE_UINT16_BE (data, language_code (GST_QT_MUX_DEFAULT_TAG_LANGUAGE));
620 GST_WRITE_UINT8 (data + 2, i);
623 for (i = 0; kwds[i]; ++i) {
624 gint len = strlen (kwds[i]);
626 GST_DEBUG_OBJECT (qtmux, "Adding tag %" GST_FOURCC_FORMAT " -> %s",
627 GST_FOURCC_ARGS (fourcc), kwds[i]);
629 GST_WRITE_UINT8 (data, len + 1);
630 memcpy (data + 1, kwds[i], len + 1);
636 atom_moov_add_3gp_tag (qtmux->moov, fourcc, ddata, size);
641 typedef void (*GstQTMuxAddTagFunc) (GstQTMux * mux, const GstTagList * list,
642 const char *tag, const char *tag2, guint32 fourcc);
645 * Struct to record mappings from gstreamer tags to fourcc codes
647 typedef struct _GstTagToFourcc
651 const gchar *gsttag2;
652 const GstQTMuxAddTagFunc func;
655 /* tag list tags to fourcc matching */
656 static const GstTagToFourcc tag_matches_mp4[] = {
657 {FOURCC__alb, GST_TAG_ALBUM, NULL, gst_qt_mux_add_mp4_tag},
658 {FOURCC__ART, GST_TAG_ARTIST, NULL, gst_qt_mux_add_mp4_tag},
659 {FOURCC__cmt, GST_TAG_COMMENT, NULL, gst_qt_mux_add_mp4_tag},
660 {FOURCC__wrt, GST_TAG_COMPOSER, NULL, gst_qt_mux_add_mp4_tag},
661 {FOURCC__gen, GST_TAG_GENRE, NULL, gst_qt_mux_add_mp4_tag},
662 {FOURCC__nam, GST_TAG_TITLE, NULL, gst_qt_mux_add_mp4_tag},
663 {FOURCC__des, GST_TAG_DESCRIPTION, NULL, gst_qt_mux_add_mp4_tag},
664 {FOURCC__too, GST_TAG_ENCODER, NULL, gst_qt_mux_add_mp4_tag},
665 {FOURCC_cprt, GST_TAG_COPYRIGHT, NULL, gst_qt_mux_add_mp4_tag},
666 {FOURCC_keyw, GST_TAG_KEYWORDS, NULL, gst_qt_mux_add_mp4_tag},
667 {FOURCC__day, GST_TAG_DATE, NULL, gst_qt_mux_add_mp4_date},
668 {FOURCC_tmpo, GST_TAG_BEATS_PER_MINUTE, NULL, gst_qt_mux_add_mp4_tag},
669 {FOURCC_trkn, GST_TAG_TRACK_NUMBER, GST_TAG_TRACK_COUNT,
670 gst_qt_mux_add_mp4_tag},
671 {FOURCC_disk, GST_TAG_ALBUM_VOLUME_NUMBER, GST_TAG_ALBUM_VOLUME_COUNT,
672 gst_qt_mux_add_mp4_tag},
673 {FOURCC_covr, GST_TAG_PREVIEW_IMAGE, NULL, gst_qt_mux_add_mp4_cover},
677 static const GstTagToFourcc tag_matches_3gp[] = {
678 {FOURCC_titl, GST_TAG_TITLE, NULL, gst_qt_mux_add_3gp_str},
679 {FOURCC_dscp, GST_TAG_DESCRIPTION, NULL, gst_qt_mux_add_3gp_str},
680 {FOURCC_cprt, GST_TAG_COPYRIGHT, NULL, gst_qt_mux_add_3gp_str},
681 {FOURCC_perf, GST_TAG_ARTIST, NULL, gst_qt_mux_add_3gp_str},
682 {FOURCC_auth, GST_TAG_COMPOSER, NULL, gst_qt_mux_add_3gp_str},
683 {FOURCC_gnre, GST_TAG_GENRE, NULL, gst_qt_mux_add_3gp_str},
684 {FOURCC_kywd, GST_TAG_KEYWORDS, NULL, gst_qt_mux_add_3gp_keywords},
685 {FOURCC_yrrc, GST_TAG_DATE, NULL, gst_qt_mux_add_3gp_date},
686 {FOURCC_albm, GST_TAG_ALBUM, GST_TAG_TRACK_NUMBER, gst_qt_mux_add_3gp_str},
687 {FOURCC_loci, GST_TAG_GEO_LOCATION_NAME, NULL, gst_qt_mux_add_3gp_location},
691 /* qtdemux produces these for atoms it cannot parse */
692 #define GST_QT_DEMUX_PRIVATE_TAG "private-qt-tag"
695 gst_qt_mux_add_metadata_tags (GstQTMux * qtmux, const GstTagList * list)
697 GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
700 const gchar *tag, *tag2;
701 const GstTagToFourcc *tag_matches;
703 switch (qtmux_klass->format) {
704 case GST_QT_MUX_FORMAT_3GP:
705 tag_matches = tag_matches_3gp;
707 case GST_QT_MUX_FORMAT_MJ2:
711 /* sort of iTunes style for mp4 and QT (?) */
712 tag_matches = tag_matches_mp4;
719 for (i = 0; tag_matches[i].fourcc; i++) {
720 fourcc = tag_matches[i].fourcc;
721 tag = tag_matches[i].gsttag;
722 tag2 = tag_matches[i].gsttag2;
724 g_assert (tag_matches[i].func);
725 tag_matches[i].func (qtmux, list, tag, tag2, fourcc);
728 /* add unparsed blobs if present */
729 if (gst_tag_exists (GST_QT_DEMUX_PRIVATE_TAG)) {
732 num_tags = gst_tag_list_get_tag_size (list, GST_QT_DEMUX_PRIVATE_TAG);
733 for (i = 0; i < num_tags; ++i) {
736 GstCaps *caps = NULL;
738 val = gst_tag_list_get_value_index (list, GST_QT_DEMUX_PRIVATE_TAG, i);
739 buf = (GstBuffer *) gst_value_get_mini_object (val);
741 if (buf && (caps = gst_buffer_get_caps (buf))) {
743 const gchar *style = NULL;
745 GST_DEBUG_OBJECT (qtmux, "Found private tag %d/%d; size %d, caps %"
746 GST_PTR_FORMAT, i, num_tags, GST_BUFFER_SIZE (buf), caps);
747 s = gst_caps_get_structure (caps, 0);
748 if (s && (style = gst_structure_get_string (s, "style"))) {
749 /* try to prevent some style tag ending up into another variant
750 * (todo: make into a list if more cases) */
751 if ((strcmp (style, "itunes") == 0 &&
752 qtmux_klass->format == GST_QT_MUX_FORMAT_MP4) ||
753 (strcmp (style, "iso") == 0 &&
754 qtmux_klass->format == GST_QT_MUX_FORMAT_3GP)) {
755 GST_DEBUG_OBJECT (qtmux, "Adding private tag");
756 atom_moov_add_blob_tag (qtmux->moov, GST_BUFFER_DATA (buf),
757 GST_BUFFER_SIZE (buf));
760 gst_caps_unref (caps);
769 * Gets the tagsetter iface taglist and puts the known tags
770 * into the output stream
773 gst_qt_mux_setup_metadata (GstQTMux * qtmux)
775 const GstTagList *tags;
777 tags = gst_tag_setter_get_tag_list (GST_TAG_SETTER (qtmux));
779 GST_LOG_OBJECT (qtmux, "tags: %" GST_PTR_FORMAT, tags);
781 if (tags && !gst_tag_list_is_empty (tags)) {
782 GST_DEBUG_OBJECT (qtmux, "Formatting tags");
783 gst_qt_mux_add_metadata_tags (qtmux, tags);
785 GST_DEBUG_OBJECT (qtmux, "No tags received");
790 gst_qt_mux_send_buffer (GstQTMux * qtmux, GstBuffer * buf, guint64 * offset,
797 g_return_val_if_fail (buf != NULL, GST_FLOW_ERROR);
799 data = GST_BUFFER_DATA (buf);
800 size = GST_BUFFER_SIZE (buf);
802 GST_LOG_OBJECT (qtmux, "sending buffer size %d", size);
804 if (mind_fast && qtmux->fast_start_file) {
807 GST_LOG_OBJECT (qtmux, "to temporary file");
808 ret = fwrite (data, sizeof (guint8), size, qtmux->fast_start_file);
809 gst_buffer_unref (buf);
815 GST_LOG_OBJECT (qtmux, "downstream");
817 gst_buffer_set_caps (buf, GST_PAD_CAPS (qtmux->srcpad));
818 res = gst_pad_push (qtmux->srcpad, buf);
821 if (G_LIKELY (offset))
829 GST_ELEMENT_ERROR (qtmux, RESOURCE, WRITE,
830 ("Failed to write to temporary file"), GST_ERROR_SYSTEM);
831 return GST_FLOW_ERROR;
836 gst_qt_mux_send_buffered_data (GstQTMux * qtmux, guint64 * offset)
838 GstFlowReturn ret = GST_FLOW_OK;
839 GstBuffer *buf = NULL;
841 if (fflush (qtmux->fast_start_file))
845 if (fseeko (qtmux->fast_start_file, (off_t) 0, SEEK_SET) != 0)
847 #elif defined (G_OS_UNIX) || defined (G_OS_WIN32)
848 if (lseek (fileno (qtmux->fast_start_file), (off_t) 0,
849 SEEK_SET) == (off_t) - 1)
852 if (fseek (qtmux->fast_start_file, (long) 0, SEEK_SET) != 0)
856 /* hm, this could all take a really really long time,
857 * but there may not be another way to get moov atom first
858 * (somehow optimize copy?) */
859 GST_DEBUG_OBJECT (qtmux, "Sending buffered data");
860 while (ret == GST_FLOW_OK) {
862 const int bufsize = 4096;
864 buf = gst_buffer_new_and_alloc (bufsize);
865 r = fread (GST_BUFFER_DATA (buf), sizeof (guint8), bufsize,
866 qtmux->fast_start_file);
869 GST_BUFFER_SIZE (buf) = r;
870 GST_LOG_OBJECT (qtmux, "Pushing buffered buffer of size %d", r);
871 ret = gst_qt_mux_send_buffer (qtmux, buf, offset, FALSE);
875 gst_buffer_unref (buf);
878 /* best cleaning up effort, eat possible error */
879 fclose (qtmux->fast_start_file);
880 qtmux->fast_start_file = NULL;
882 /* FIXME maybe delete temporary file, or let the system handle that ? */
889 GST_ELEMENT_ERROR (qtmux, RESOURCE, WRITE,
890 ("Failed to flush temporary file"), GST_ERROR_SYSTEM);
891 ret = GST_FLOW_ERROR;
896 GST_ELEMENT_ERROR (qtmux, RESOURCE, SEEK,
897 ("Failed to seek temporary file"), GST_ERROR_SYSTEM);
898 ret = GST_FLOW_ERROR;
904 * Sends the initial mdat atom fields (size fields and fourcc type),
905 * the subsequent buffers are considered part of it's data.
906 * As we can't predict the amount of data that we are going to place in mdat
907 * we need to record the position of the size field in the stream so we can
908 * seek back to it later and update when the streams have finished.
911 gst_qt_mux_send_mdat_header (GstQTMux * qtmux, guint64 * off, guint64 size,
919 GST_DEBUG_OBJECT (qtmux, "Sending mdat's atom header, "
920 "size %" G_GUINT64_FORMAT, size);
922 node_header = g_malloc0 (sizeof (Atom));
923 node_header->type = FOURCC_mdat;
925 /* use extended size */
926 node_header->size = 1;
927 node_header->extended_size = 0;
929 node_header->extended_size = size + 16;
931 node_header->size = size + 8;
935 if (atom_copy_data (node_header, &data, &size, &offset) == 0)
936 goto serialize_error;
938 buf = gst_buffer_new ();
939 GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data;
940 GST_BUFFER_SIZE (buf) = offset;
942 g_free (node_header);
944 GST_LOG_OBJECT (qtmux, "Pushing mdat start");
945 return gst_qt_mux_send_buffer (qtmux, buf, off, FALSE);
950 GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
951 ("Failed to serialize ftyp"));
952 return GST_FLOW_ERROR;
957 * We get the position of the mdat size field, seek back to it
958 * and overwrite with the real value
961 gst_qt_mux_update_mdat_size (GstQTMux * qtmux, guint64 mdat_pos,
962 guint64 mdat_size, guint64 * offset)
968 large_file = (mdat_size > MDAT_LARGE_FILE_LIMIT);
973 /* seek and rewrite the header */
974 event = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES,
975 mdat_pos, GST_CLOCK_TIME_NONE, 0);
976 gst_pad_push_event (qtmux->srcpad, event);
979 buf = gst_buffer_new_and_alloc (sizeof (guint64));
980 GST_WRITE_UINT64_BE (GST_BUFFER_DATA (buf), mdat_size + 16);
984 buf = gst_buffer_new_and_alloc (16);
985 data = GST_BUFFER_DATA (buf);
986 GST_WRITE_UINT32_BE (data, 8);
987 GST_WRITE_UINT32_LE (data + 4, FOURCC_free);
988 GST_WRITE_UINT32_BE (data + 8, mdat_size + 8);
989 GST_WRITE_UINT32_LE (data + 12, FOURCC_mdat);
992 return gst_qt_mux_send_buffer (qtmux, buf, offset, FALSE);
996 gst_qt_mux_send_ftyp (GstQTMux * qtmux, guint64 * off)
999 guint64 size = 0, offset = 0;
1000 guint8 *data = NULL;
1002 GST_DEBUG_OBJECT (qtmux, "Sending ftyp atom");
1004 if (!atom_ftyp_copy_data (qtmux->ftyp, &data, &size, &offset))
1005 goto serialize_error;
1007 buf = gst_buffer_new ();
1008 GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data;
1009 GST_BUFFER_SIZE (buf) = offset;
1011 GST_LOG_OBJECT (qtmux, "Pushing ftyp");
1012 return gst_qt_mux_send_buffer (qtmux, buf, off, FALSE);
1017 GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
1018 ("Failed to serialize ftyp"));
1019 return GST_FLOW_ERROR;
1023 static GstFlowReturn
1024 gst_qt_mux_prepare_and_send_ftyp (GstQTMux * qtmux)
1026 GstFlowReturn ret = GST_FLOW_OK;
1027 GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
1028 guint32 major, version;
1032 GST_DEBUG_OBJECT (qtmux, "Preparing to send ftyp atom");
1034 /* init and send context and ftyp based on current property state */
1036 atom_ftyp_free (qtmux->ftyp);
1037 gst_qt_mux_map_format_to_header (qtmux_klass->format, &prefix, &major,
1038 &version, &comp, qtmux->moov);
1039 qtmux->ftyp = atom_ftyp_new (qtmux->context, major, version, comp);
1043 ret = gst_qt_mux_send_buffer (qtmux, prefix, &qtmux->header_size, FALSE);
1044 if (ret != GST_FLOW_OK)
1047 return gst_qt_mux_send_ftyp (qtmux, &qtmux->header_size);
1050 static GstFlowReturn
1051 gst_qt_mux_start_file (GstQTMux * qtmux)
1053 GstFlowReturn ret = GST_FLOW_OK;
1055 GST_DEBUG_OBJECT (qtmux, "starting file");
1057 /* let downstream know we think in BYTES and expect to do seeking later on */
1058 gst_pad_push_event (qtmux->srcpad,
1059 gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0));
1062 * send mdat header if already needed, and mark position for later update.
1063 * We don't send ftyp now if we are on fast start mode, because we can
1064 * better fine tune using the information we gather to create the whole moov
1067 if (qtmux->fast_start) {
1068 GST_OBJECT_LOCK (qtmux);
1069 qtmux->fast_start_file = g_fopen (qtmux->fast_start_file_path, "wb+");
1070 if (!qtmux->fast_start_file)
1072 GST_OBJECT_UNLOCK (qtmux);
1074 /* send a dummy buffer for preroll */
1075 ret = gst_qt_mux_send_buffer (qtmux, gst_buffer_new (), NULL, FALSE);
1076 if (ret != GST_FLOW_OK)
1080 ret = gst_qt_mux_prepare_and_send_ftyp (qtmux);
1081 if (ret != GST_FLOW_OK) {
1085 /* extended to ensure some spare space */
1086 qtmux->mdat_pos = qtmux->header_size;
1087 ret = gst_qt_mux_send_mdat_header (qtmux, &qtmux->header_size, 0, TRUE);
1096 GST_ELEMENT_ERROR (qtmux, RESOURCE, OPEN_READ_WRITE,
1097 (("Could not open temporary file \"%s\""), qtmux->fast_start_file_path),
1099 GST_OBJECT_UNLOCK (qtmux);
1100 return GST_FLOW_ERROR;
1104 static GstFlowReturn
1105 gst_qt_mux_stop_file (GstQTMux * qtmux)
1107 gboolean ret = GST_FLOW_OK;
1108 GstBuffer *buffer = NULL;
1109 guint64 offset = 0, size = 0;
1112 gboolean large_file;
1115 GST_DEBUG_OBJECT (qtmux, "Updating remaining values and sending last data");
1117 /* pushing last buffers for each pad */
1118 for (walk = qtmux->collect->data; walk; walk = g_slist_next (walk)) {
1119 GstCollectData *cdata = (GstCollectData *) walk->data;
1120 GstQTPad *qtpad = (GstQTPad *) cdata;
1122 /* send last buffer */
1123 GST_DEBUG_OBJECT (qtmux, "Sending the last buffer for pad %s",
1124 GST_PAD_NAME (qtpad->collect.pad));
1125 ret = gst_qt_mux_add_buffer (qtmux, qtpad, NULL);
1126 if (ret != GST_FLOW_OK)
1127 GST_DEBUG_OBJECT (qtmux, "Failed to send last buffer for %s, "
1128 "flow return: %s", GST_PAD_NAME (qtpad->collect.pad),
1129 gst_flow_get_name (ret));
1132 GST_OBJECT_LOCK (qtmux);
1133 timescale = qtmux->timescale;
1134 large_file = qtmux->large_file;
1135 GST_OBJECT_UNLOCK (qtmux);
1137 /* inform lower layers of our property wishes, and determine duration.
1138 * Let moov take care of this using its list of traks;
1139 * so that released pads are also included */
1140 GST_DEBUG_OBJECT (qtmux, "Large file support: %d", large_file);
1141 GST_DEBUG_OBJECT (qtmux, "Updating timescale to %" G_GUINT32_FORMAT,
1143 atom_moov_update_timescale (qtmux->moov, timescale);
1144 atom_moov_set_64bits (qtmux->moov, large_file);
1145 atom_moov_update_duration (qtmux->moov);
1147 /* tags into file metadata */
1148 gst_qt_mux_setup_metadata (qtmux);
1150 large_file = (qtmux->mdat_size > MDAT_LARGE_FILE_LIMIT);
1151 /* if faststart, update the offset of the atoms in the movie with the offset
1152 * that the movie headers before mdat will cause.
1153 * Also, send the ftyp */
1154 if (qtmux->fast_start_file) {
1155 GstFlowReturn flow_ret;
1158 flow_ret = gst_qt_mux_prepare_and_send_ftyp (qtmux);
1159 if (flow_ret != GST_FLOW_OK) {
1162 /* copy into NULL to obtain size */
1163 if (!atom_moov_copy_data (qtmux->moov, NULL, &size, &offset))
1164 goto serialize_error;
1165 GST_DEBUG_OBJECT (qtmux, "calculated moov atom size %" G_GUINT64_FORMAT,
1167 offset += qtmux->header_size + (large_file ? 16 : 8);
1169 offset = qtmux->header_size;
1170 atom_moov_chunks_add_offset (qtmux->moov, offset);
1172 /* serialize moov */
1175 GST_LOG_OBJECT (qtmux, "Copying movie header into buffer");
1176 ret = atom_moov_copy_data (qtmux->moov, &data, &size, &offset);
1178 goto serialize_error;
1180 buffer = gst_buffer_new ();
1181 GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer) = data;
1182 GST_BUFFER_SIZE (buffer) = offset;
1183 /* note: as of this point, we no longer care about tracking written data size,
1184 * since there is no more use for it anyway */
1185 GST_DEBUG_OBJECT (qtmux, "Pushing movie atoms");
1186 gst_qt_mux_send_buffer (qtmux, buffer, NULL, FALSE);
1188 /* if needed, send mdat atom and move buffered data into it */
1189 if (qtmux->fast_start_file) {
1190 /* mdat size = accumulated (buffered data) + mdat atom header */
1191 ret = gst_qt_mux_send_mdat_header (qtmux, NULL, qtmux->mdat_size,
1193 if (ret != GST_FLOW_OK)
1195 ret = gst_qt_mux_send_buffered_data (qtmux, NULL);
1196 if (ret != GST_FLOW_OK)
1199 /* mdata needs update iff not using faststart */
1200 GST_DEBUG_OBJECT (qtmux, "updating mdata size");
1201 ret = gst_qt_mux_update_mdat_size (qtmux, qtmux->mdat_pos,
1202 qtmux->mdat_size, NULL);
1203 /* note; no seeking back to the end of file is done,
1204 * since we longer write anything anyway */
1212 gst_buffer_unref (buffer);
1213 GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
1214 ("Failed to serialize moov"));
1215 return GST_FLOW_ERROR;
1219 GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL), ("Failed to send ftyp"));
1220 return GST_FLOW_ERROR;
1225 * Here we push the buffer and update the tables in the track atoms
1227 static GstFlowReturn
1228 gst_qt_mux_add_buffer (GstQTMux * qtmux, GstQTPad * pad, GstBuffer * buf)
1230 GstBuffer *last_buf = NULL;
1231 GstClockTime duration;
1232 guint nsamples, sample_size;
1233 guint64 scaled_duration, chunk_offset;
1235 gint64 pts_offset = 0;
1236 gboolean sync = FALSE, do_pts = FALSE;
1239 goto not_negotiated;
1241 last_buf = pad->last_buf;
1242 if (last_buf == NULL) {
1243 #ifndef GST_DISABLE_GST_DEBUG
1245 GST_DEBUG_OBJECT (qtmux, "Pad %s has no previous buffer stored and "
1246 "received NULL buffer, doing nothing",
1247 GST_PAD_NAME (pad->collect.pad));
1249 GST_LOG_OBJECT (qtmux,
1250 "Pad %s has no previous buffer stored, storing now",
1251 GST_PAD_NAME (pad->collect.pad));
1254 pad->last_buf = buf;
1257 gst_buffer_ref (last_buf);
1259 /* fall back to duration if:
1261 * - this format has out of order buffers (e.g. MPEG-4),
1262 * - lack of valid time forces fall back */
1263 if (buf == NULL || pad->is_out_of_order ||
1264 !GST_BUFFER_TIMESTAMP_IS_VALID (last_buf) ||
1265 !GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
1266 if (!GST_BUFFER_DURATION_IS_VALID (last_buf)) {
1267 /* be forgiving for some possibly last upstream flushed buffer */
1270 GST_WARNING_OBJECT (qtmux, "no duration for last buffer");
1271 /* iso spec recommends some small value, try 0 */
1274 duration = GST_BUFFER_DURATION (last_buf);
1277 duration = GST_BUFFER_TIMESTAMP (buf) - GST_BUFFER_TIMESTAMP (last_buf);
1280 gst_buffer_replace (&pad->last_buf, buf);
1282 last_dts = gst_util_uint64_scale (pad->last_dts,
1283 atom_trak_get_timescale (pad->trak), GST_SECOND);
1285 /* raw audio has many samples per buffer (= chunk) */
1286 if (pad->sample_size) {
1287 sample_size = pad->sample_size;
1288 if (GST_BUFFER_SIZE (last_buf) % sample_size != 0)
1289 goto fragmented_sample;
1290 /* note: qt raw audio storage warps it implicitly into a timewise
1291 * perfect stream, discarding buffer times */
1292 nsamples = GST_BUFFER_SIZE (last_buf) / sample_size;
1293 duration = GST_BUFFER_DURATION (last_buf) / nsamples;
1294 /* timescale = samplerate */
1295 scaled_duration = 1;
1296 pad->last_dts += duration * nsamples;
1299 sample_size = GST_BUFFER_SIZE (last_buf);
1300 if (pad->have_dts) {
1302 pad->last_dts = GST_BUFFER_OFFSET_END (last_buf);
1303 if ((gint64) (pad->last_dts) < 0) {
1304 scaled_dts = -gst_util_uint64_scale (-pad->last_dts,
1305 atom_trak_get_timescale (pad->trak), GST_SECOND);
1307 scaled_dts = gst_util_uint64_scale (pad->last_dts,
1308 atom_trak_get_timescale (pad->trak), GST_SECOND);
1310 scaled_duration = scaled_dts - last_dts;
1311 last_dts = scaled_dts;
1313 /* first convert intended timestamp (in GstClockTime resolution) to
1314 * trak timescale, then derive delta;
1315 * this ensures sums of (scale)delta add up to converted timestamp,
1316 * which only deviates at most 1/scale from timestamp itself */
1317 scaled_duration = gst_util_uint64_scale (pad->last_dts + duration,
1318 atom_trak_get_timescale (pad->trak), GST_SECOND) - last_dts;
1319 pad->last_dts += duration;
1322 chunk_offset = qtmux->mdat_size;
1324 GST_LOG_OBJECT (qtmux,
1325 "Pad (%s) dts updated to %" GST_TIME_FORMAT,
1326 GST_PAD_NAME (pad->collect.pad), GST_TIME_ARGS (pad->last_dts));
1327 GST_LOG_OBJECT (qtmux,
1328 "Adding %d samples to track, duration: %" G_GUINT64_FORMAT
1329 " size: %" G_GUINT32_FORMAT " chunk offset: %" G_GUINT64_FORMAT,
1330 nsamples, scaled_duration, sample_size, chunk_offset);
1332 /* might be a sync sample */
1334 !GST_BUFFER_FLAG_IS_SET (last_buf, GST_BUFFER_FLAG_DELTA_UNIT)) {
1335 GST_LOG_OBJECT (qtmux, "Adding new sync sample entry for track of pad %s",
1336 GST_PAD_NAME (pad->collect.pad));
1340 /* optionally calculate ctts entry values
1341 * (if composition-time expected different from decoding-time) */
1342 /* really not recommended:
1343 * - decoder typically takes care of dts/pts issues
1344 * - in case of out-of-order, dts may only be determined as above
1345 * (e.g. sum of duration), which may be totally different from
1346 * buffer timestamps in case of multiple segment, non-perfect streams
1347 * (and just perhaps maybe with some luck segment_to_running_time
1348 * or segment_to_media_time might get near to it) */
1349 if ((pad->have_dts || qtmux->guess_pts) && pad->is_out_of_order) {
1352 pts = gst_util_uint64_scale (GST_BUFFER_TIMESTAMP (last_buf),
1353 atom_trak_get_timescale (pad->trak), GST_SECOND);
1354 pts_offset = (gint64) (pts - last_dts);
1356 GST_LOG_OBJECT (qtmux, "Adding ctts entry for pad %s: %" G_GINT64_FORMAT,
1357 GST_PAD_NAME (pad->collect.pad), pts_offset);
1360 /* now we go and register this buffer/sample all over */
1361 /* note that a new chunk is started each time (not fancy but works) */
1362 atom_trak_add_samples (pad->trak, nsamples, scaled_duration, sample_size,
1363 chunk_offset, sync, do_pts, pts_offset);
1366 gst_buffer_unref (buf);
1368 return gst_qt_mux_send_buffer (qtmux, last_buf, &qtmux->mdat_size, TRUE);
1374 gst_buffer_unref (buf);
1375 gst_buffer_unref (last_buf);
1376 return GST_FLOW_ERROR;
1380 GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
1381 ("Received buffer without timestamp/duration."));
1386 GST_ELEMENT_ERROR (qtmux, STREAM, MUX, (NULL),
1387 ("Audio buffer contains fragmented sample."));
1392 GST_ELEMENT_ERROR (qtmux, CORE, NEGOTIATION, (NULL),
1393 ("format wasn't negotiated before buffer flow on pad %s",
1394 GST_PAD_NAME (pad->collect.pad)));
1395 gst_buffer_unref (buf);
1396 return GST_FLOW_NOT_NEGOTIATED;
1400 static GstFlowReturn
1401 gst_qt_mux_collected (GstCollectPads * pads, gpointer user_data)
1403 GstFlowReturn ret = GST_FLOW_OK;
1404 GstQTMux *qtmux = GST_QT_MUX_CAST (user_data);
1406 GstQTPad *best_pad = NULL;
1407 GstClockTime time, best_time = GST_CLOCK_TIME_NONE;
1410 if (G_UNLIKELY (qtmux->state == GST_QT_MUX_STATE_STARTED)) {
1411 if ((ret = gst_qt_mux_start_file (qtmux)) != GST_FLOW_OK)
1414 qtmux->state = GST_QT_MUX_STATE_DATA;
1417 if (G_UNLIKELY (qtmux->state == GST_QT_MUX_STATE_EOS))
1418 return GST_FLOW_UNEXPECTED;
1420 /* select the best buffer */
1421 walk = qtmux->collect->data;
1424 GstCollectData *data;
1426 data = (GstCollectData *) walk->data;
1427 pad = (GstQTPad *) data;
1429 walk = g_slist_next (walk);
1431 buf = gst_collect_pads_peek (pads, data);
1433 GST_LOG_OBJECT (qtmux, "Pad %s has no buffers",
1434 GST_PAD_NAME (pad->collect.pad));
1437 time = GST_BUFFER_TIMESTAMP (buf);
1438 gst_buffer_unref (buf);
1440 if (best_pad == NULL || !GST_CLOCK_TIME_IS_VALID (time) ||
1441 (GST_CLOCK_TIME_IS_VALID (best_time) && time < best_time)) {
1447 if (best_pad != NULL) {
1448 GST_LOG_OBJECT (qtmux, "selected pad %s with time %" GST_TIME_FORMAT,
1449 GST_PAD_NAME (best_pad->collect.pad), GST_TIME_ARGS (best_time));
1450 buf = gst_collect_pads_pop (pads, &best_pad->collect);
1451 ret = gst_qt_mux_add_buffer (qtmux, best_pad, buf);
1453 ret = gst_qt_mux_stop_file (qtmux);
1454 if (ret == GST_FLOW_OK) {
1455 gst_pad_push_event (qtmux->srcpad, gst_event_new_eos ());
1456 ret = GST_FLOW_UNEXPECTED;
1458 qtmux->state = GST_QT_MUX_STATE_EOS;
1465 gst_qt_mux_audio_sink_set_caps (GstPad * pad, GstCaps * caps)
1467 GstQTMux *qtmux = GST_QT_MUX_CAST (gst_pad_get_parent (pad));
1468 GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
1469 GstQTPad *qtpad = NULL;
1470 GstStructure *structure;
1471 const gchar *mimetype;
1472 gint rate, channels;
1473 const GValue *value = NULL;
1474 const GstBuffer *codec_data = NULL;
1475 GstQTMuxFormat format;
1476 AudioSampleEntry entry = { 0, };
1477 AtomInfo *ext_atom = NULL;
1478 gint constant_size = 0;
1480 /* find stream data */
1481 qtpad = (GstQTPad *) gst_pad_get_element_private (pad);
1484 /* does not go well to renegotiate stream mid-way */
1486 goto refuse_renegotiation;
1488 GST_DEBUG_OBJECT (qtmux, "%s:%s, caps=%" GST_PTR_FORMAT,
1489 GST_DEBUG_PAD_NAME (pad), caps);
1491 format = qtmux_klass->format;
1492 structure = gst_caps_get_structure (caps, 0);
1493 mimetype = gst_structure_get_name (structure);
1496 if (!gst_structure_get_int (structure, "channels", &channels) ||
1497 !gst_structure_get_int (structure, "rate", &rate)) {
1502 value = gst_structure_get_value (structure, "codec_data");
1504 codec_data = gst_value_get_buffer (value);
1506 qtpad->is_out_of_order = FALSE;
1507 qtpad->have_dts = FALSE;
1509 /* set common properties */
1510 entry.sample_rate = rate;
1511 entry.channels = channels;
1513 entry.sample_size = 16;
1514 /* this is the typical compressed case */
1515 if (format == GST_QT_MUX_FORMAT_QT) {
1517 entry.compression_id = -2;
1520 /* now map onto a fourcc, and some extra properties */
1521 if (strcmp (mimetype, "audio/mpeg") == 0) {
1522 gint mpegversion = 0;
1525 gst_structure_get_int (structure, "mpegversion", &mpegversion);
1526 switch (mpegversion) {
1528 gst_structure_get_int (structure, "layer", &layer);
1532 /* note: QuickTime player does not like mp3 either way in iso/mp4 */
1533 if (format == GST_QT_MUX_FORMAT_QT)
1534 entry.fourcc = FOURCC__mp3;
1536 entry.fourcc = FOURCC_mp4a;
1538 build_esds_extension (qtpad->trak, ESDS_OBJECT_TYPE_MPEG1_P3,
1539 ESDS_STREAM_TYPE_AUDIO, codec_data);
1541 entry.samples_per_packet = 1152;
1542 entry.bytes_per_sample = 2;
1548 entry.fourcc = FOURCC_mp4a;
1549 if (!codec_data || GST_BUFFER_SIZE (codec_data) < 2)
1550 GST_WARNING_OBJECT (qtmux, "no (valid) codec_data for AAC audio");
1552 guint8 profile = GST_READ_UINT8 (GST_BUFFER_DATA (codec_data));
1554 /* warn if not Low Complexity profile */
1557 GST_WARNING_OBJECT (qtmux,
1558 "non-LC AAC may not run well on (Apple) QuickTime/iTunes");
1560 if (format == GST_QT_MUX_FORMAT_QT)
1561 ext_atom = build_mov_aac_extension (qtpad->trak, codec_data);
1564 build_esds_extension (qtpad->trak, ESDS_OBJECT_TYPE_MPEG4_P3,
1565 ESDS_STREAM_TYPE_AUDIO, codec_data);
1570 } else if (strcmp (mimetype, "audio/AMR") == 0) {
1571 entry.fourcc = FOURCC_samr;
1572 entry.sample_size = 16;
1573 entry.samples_per_packet = 160;
1574 entry.bytes_per_sample = 2;
1575 ext_atom = build_amr_extension ();
1576 } else if (strcmp (mimetype, "audio/AMR-WB") == 0) {
1577 entry.fourcc = FOURCC_sawb;
1578 entry.sample_size = 16;
1579 entry.samples_per_packet = 320;
1580 entry.bytes_per_sample = 2;
1581 ext_atom = build_amr_extension ();
1582 } else if (strcmp (mimetype, "audio/x-raw-int") == 0) {
1588 if (!gst_structure_get_int (structure, "width", &width) ||
1589 !gst_structure_get_int (structure, "depth", &depth) ||
1590 !gst_structure_get_boolean (structure, "signed", &sign)) {
1591 GST_DEBUG_OBJECT (qtmux, "broken caps, width/depth/signed field missing");
1596 endianness = G_BYTE_ORDER;
1597 } else if (!gst_structure_get_boolean (structure,
1598 "endianness", &endianness)) {
1599 GST_DEBUG_OBJECT (qtmux, "broken caps, endianness field missing");
1603 /* spec has no place for a distinction in these */
1604 if (width != depth) {
1605 GST_DEBUG_OBJECT (qtmux, "width must be same as depth!");
1610 if (endianness == G_LITTLE_ENDIAN)
1611 entry.fourcc = FOURCC_sowt;
1612 else if (endianness == G_BIG_ENDIAN)
1613 entry.fourcc = FOURCC_twos;
1614 /* maximum backward compatibility; only new version for > 16 bit */
1617 /* not compressed in any case */
1618 entry.compression_id = 0;
1619 /* QT spec says: max at 16 bit even if sample size were actually larger,
1620 * however, most players (e.g. QuickTime!) seem to disagree, so ... */
1621 entry.sample_size = depth;
1622 entry.bytes_per_sample = depth / 8;
1623 entry.samples_per_packet = 1;
1624 entry.bytes_per_packet = depth / 8;
1625 entry.bytes_per_frame = entry.bytes_per_packet * channels;
1627 if (width == 8 && depth == 8) {
1628 /* fall back to old 8-bit version */
1629 entry.fourcc = FOURCC_raw_;
1631 entry.compression_id = 0;
1632 entry.sample_size = 8;
1634 GST_DEBUG_OBJECT (qtmux, "non 8-bit PCM must be signed");
1638 constant_size = (depth / 8) * channels;
1639 } else if (strcmp (mimetype, "audio/x-alaw") == 0) {
1640 entry.fourcc = FOURCC_alaw;
1641 entry.samples_per_packet = 1023;
1642 entry.bytes_per_sample = 2;
1643 } else if (strcmp (mimetype, "audio/x-mulaw") == 0) {
1644 entry.fourcc = FOURCC_ulaw;
1645 entry.samples_per_packet = 1023;
1646 entry.bytes_per_sample = 2;
1652 /* ok, set the pad info accordingly */
1653 qtpad->fourcc = entry.fourcc;
1654 qtpad->sample_size = constant_size;
1655 atom_trak_set_audio_type (qtpad->trak, qtmux->context, &entry,
1656 entry.sample_rate, ext_atom, constant_size);
1658 gst_object_unref (qtmux);
1664 GST_WARNING_OBJECT (qtmux, "pad %s refused caps %" GST_PTR_FORMAT,
1665 GST_PAD_NAME (pad), caps);
1666 gst_object_unref (qtmux);
1669 refuse_renegotiation:
1671 GST_WARNING_OBJECT (qtmux,
1672 "pad %s refused renegotiation to %" GST_PTR_FORMAT,
1673 GST_PAD_NAME (pad), caps);
1674 gst_object_unref (qtmux);
1679 /* scale rate up or down by factor of 10 to fit into [1000,10000] interval */
1681 adjust_rate (guint64 rate)
1683 while (rate >= 10000)
1689 return (guint32) rate;
1693 gst_qt_mux_video_sink_set_caps (GstPad * pad, GstCaps * caps)
1695 GstQTMux *qtmux = GST_QT_MUX_CAST (gst_pad_get_parent (pad));
1696 GstQTMuxClass *qtmux_klass = (GstQTMuxClass *) (G_OBJECT_GET_CLASS (qtmux));
1697 GstQTPad *qtpad = NULL;
1698 GstStructure *structure;
1699 const gchar *mimetype;
1700 gint width, height, depth = -1;
1701 gint framerate_num, framerate_den;
1703 const GValue *value = NULL;
1704 const GstBuffer *codec_data = NULL;
1705 VisualSampleEntry entry = { 0, };
1706 GstQTMuxFormat format;
1707 AtomInfo *ext_atom = NULL;
1708 gboolean sync = FALSE;
1709 int par_num, par_den;
1711 /* find stream data */
1712 qtpad = (GstQTPad *) gst_pad_get_element_private (pad);
1715 /* does not go well to renegotiate stream mid-way */
1717 goto refuse_renegotiation;
1719 GST_DEBUG_OBJECT (qtmux, "%s:%s, caps=%" GST_PTR_FORMAT,
1720 GST_DEBUG_PAD_NAME (pad), caps);
1722 format = qtmux_klass->format;
1723 structure = gst_caps_get_structure (caps, 0);
1724 mimetype = gst_structure_get_name (structure);
1726 /* required parts */
1727 if (!gst_structure_get_int (structure, "width", &width) ||
1728 !gst_structure_get_int (structure, "height", &height))
1733 /* works as a default timebase */
1734 framerate_num = 10000;
1736 gst_structure_get_fraction (structure, "framerate", &framerate_num,
1738 gst_structure_get_int (structure, "depth", &depth);
1739 value = gst_structure_get_value (structure, "codec_data");
1741 codec_data = gst_value_get_buffer (value);
1745 gst_structure_get_fraction (structure, "pixel-aspect-ratio", &par_num,
1748 qtpad->is_out_of_order = FALSE;
1750 /* bring frame numerator into a range that ensures both reasonable resolution
1751 * as well as a fair duration */
1752 rate = adjust_rate (framerate_num);
1753 GST_DEBUG_OBJECT (qtmux, "Rate of video track selected: %" G_GUINT32_FORMAT,
1756 /* set common properties */
1757 entry.width = width;
1758 entry.height = height;
1759 entry.par_n = par_num;
1760 entry.par_d = par_den;
1761 /* should be OK according to qt and iso spec, override if really needed */
1762 entry.color_table_id = -1;
1763 entry.frame_count = 1;
1766 /* sync entries by default */
1769 /* now map onto a fourcc, and some extra properties */
1770 if (strcmp (mimetype, "video/x-raw-rgb") == 0) {
1773 entry.fourcc = FOURCC_raw_;
1774 gst_structure_get_int (structure, "bpp", &bpp);
1777 } else if (strcmp (mimetype, "video/x-raw-yuv") == 0) {
1781 gst_structure_get_fourcc (structure, "format", &format);
1783 case GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y'):
1786 entry.fourcc = FOURCC_2vuy;
1787 entry.depth = depth;
1790 } else if (strcmp (mimetype, "video/x-h263") == 0) {
1791 if (format == GST_QT_MUX_FORMAT_QT)
1792 entry.fourcc = FOURCC_h263;
1794 entry.fourcc = FOURCC_s263;
1795 ext_atom = build_h263_extension ();
1796 } else if (strcmp (mimetype, "video/x-divx") == 0 ||
1797 strcmp (mimetype, "video/mpeg") == 0) {
1800 if (strcmp (mimetype, "video/x-divx") == 0) {
1801 gst_structure_get_int (structure, "divxversion", &version);
1802 version = version == 5 ? 1 : 0;
1804 gst_structure_get_int (structure, "mpegversion", &version);
1805 version = version == 4 ? 1 : 0;
1808 entry.fourcc = FOURCC_mp4v;
1810 build_esds_extension (qtpad->trak, ESDS_OBJECT_TYPE_MPEG4_P2,
1811 ESDS_STREAM_TYPE_VISUAL, codec_data);
1813 GST_WARNING_OBJECT (qtmux, "no codec_data for MPEG4 video; "
1814 "output might not play in Apple QuickTime (try global-headers?)");
1816 } else if (strcmp (mimetype, "video/x-h264") == 0) {
1817 entry.fourcc = FOURCC_avc1;
1818 qtpad->is_out_of_order = TRUE;
1820 GST_WARNING_OBJECT (qtmux, "no codec_data in h264 caps");
1821 ext_atom = build_codec_data_extension (FOURCC_avcC, codec_data);
1822 } else if (strcmp (mimetype, "video/x-dv") == 0) {
1824 gboolean pal = TRUE;
1827 if (framerate_num != 25 || framerate_den != 1)
1829 gst_structure_get_int (structure, "dvversion", &version);
1830 /* fall back to typical one */
1836 entry.fourcc = GST_MAKE_FOURCC ('d', 'v', 'c', 'p');
1838 entry.fourcc = GST_MAKE_FOURCC ('d', 'v', 'c', ' ');
1842 entry.fourcc = GST_MAKE_FOURCC ('d', 'v', '5', 'p');
1844 entry.fourcc = GST_MAKE_FOURCC ('d', 'v', '5', 'n');
1847 GST_WARNING_OBJECT (qtmux, "unrecognized dv version");
1850 } else if (strcmp (mimetype, "image/jpeg") == 0) {
1851 entry.fourcc = FOURCC_jpeg;
1853 } else if (strcmp (mimetype, "image/x-j2c") == 0) {
1856 entry.fourcc = FOURCC_mjp2;
1858 if (!gst_structure_get_fourcc (structure, "fourcc", &fourcc) ||
1860 build_jp2h_extension (qtpad->trak, width, height, fourcc))) {
1861 GST_DEBUG_OBJECT (qtmux, "missing or invalid fourcc in jp2 caps");
1864 } else if (strcmp (mimetype, "video/x-qt-part") == 0) {
1867 gst_structure_get_fourcc (structure, "format", &fourcc);
1868 entry.fourcc = fourcc;
1869 qtpad->is_out_of_order = TRUE;
1870 qtpad->have_dts = TRUE;
1871 } else if (strcmp (mimetype, "video/x-mp4-part") == 0) {
1874 gst_structure_get_fourcc (structure, "format", &fourcc);
1875 entry.fourcc = fourcc;
1876 qtpad->is_out_of_order = TRUE;
1877 qtpad->have_dts = TRUE;
1883 /* ok, set the pad info accordingly */
1884 qtpad->fourcc = entry.fourcc;
1886 atom_trak_set_video_type (qtpad->trak, qtmux->context, &entry, rate,
1889 gst_object_unref (qtmux);
1895 GST_WARNING_OBJECT (qtmux, "pad %s refused caps %" GST_PTR_FORMAT,
1896 GST_PAD_NAME (pad), caps);
1897 gst_object_unref (qtmux);
1900 refuse_renegotiation:
1902 GST_WARNING_OBJECT (qtmux,
1903 "pad %s refused renegotiation to %" GST_PTR_FORMAT " from %"
1904 GST_PTR_FORMAT, GST_PAD_NAME (pad), caps, GST_PAD_CAPS (pad));
1905 gst_object_unref (qtmux);
1911 gst_qt_mux_sink_event (GstPad * pad, GstEvent * event)
1916 qtmux = GST_QT_MUX_CAST (gst_pad_get_parent (pad));
1917 switch (GST_EVENT_TYPE (event)) {
1918 case GST_EVENT_TAG:{
1920 GstTagSetter *setter = GST_TAG_SETTER (qtmux);
1921 const GstTagMergeMode mode = gst_tag_setter_get_tag_merge_mode (setter);
1923 GST_DEBUG_OBJECT (qtmux, "received tag event");
1924 gst_event_parse_tag (event, &list);
1925 gst_tag_setter_merge_tags (setter, list, mode);
1932 ret = qtmux->collect_event (pad, event);
1933 gst_object_unref (qtmux);
1939 gst_qt_mux_release_pad (GstElement * element, GstPad * pad)
1941 GstQTMux *mux = GST_QT_MUX_CAST (element);
1943 /* let GstCollectPads complain if it is some unknown pad */
1944 if (gst_collect_pads_remove_pad (mux->collect, pad))
1945 gst_element_remove_pad (element, pad);
1949 gst_qt_mux_request_new_pad (GstElement * element,
1950 GstPadTemplate * templ, const gchar * name)
1952 GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
1953 GstQTMux *qtmux = GST_QT_MUX_CAST (element);
1954 GstQTPad *collect_pad;
1958 GST_DEBUG_OBJECT (qtmux, "Requested pad: %s", GST_STR_NULL (name));
1960 if (qtmux->state != GST_QT_MUX_STATE_NONE) {
1961 GST_WARNING_OBJECT (qtmux, "Not providing request pad after stream start.");
1965 if (templ == gst_element_class_get_pad_template (klass, "audio_%d")) {
1967 } else if (templ == gst_element_class_get_pad_template (klass, "video_%d")) {
1970 GST_WARNING_OBJECT (qtmux, "This is not our template!");
1974 /* add pad to collections */
1975 newpad = gst_pad_new_from_template (templ, name);
1976 collect_pad = (GstQTPad *)
1977 gst_collect_pads_add_pad_full (qtmux->collect, newpad, sizeof (GstQTPad),
1978 (GstCollectDataDestroyNotify) (gst_qt_mux_pad_reset));
1980 gst_qt_mux_pad_reset (collect_pad);
1981 collect_pad->trak = atom_trak_new (qtmux->context);
1982 atom_moov_add_trak (qtmux->moov, collect_pad->trak);
1984 /* set up pad functions */
1986 gst_pad_set_setcaps_function (newpad,
1987 GST_DEBUG_FUNCPTR (gst_qt_mux_audio_sink_set_caps));
1989 gst_pad_set_setcaps_function (newpad,
1990 GST_DEBUG_FUNCPTR (gst_qt_mux_video_sink_set_caps));
1992 /* FIXME: hacked way to override/extend the event function of
1993 * GstCollectPads; because it sets its own event function giving the
1994 * element no access to events.
1996 qtmux->collect_event = (GstPadEventFunction) GST_PAD_EVENTFUNC (newpad);
1997 gst_pad_set_event_function (newpad,
1998 GST_DEBUG_FUNCPTR (gst_qt_mux_sink_event));
2000 gst_pad_set_active (newpad, TRUE);
2001 gst_element_add_pad (element, newpad);
2007 gst_qt_mux_get_property (GObject * object,
2008 guint prop_id, GValue * value, GParamSpec * pspec)
2010 GstQTMux *qtmux = GST_QT_MUX_CAST (object);
2012 GST_OBJECT_LOCK (qtmux);
2014 case PROP_LARGE_FILE:
2015 g_value_set_boolean (value, qtmux->large_file);
2017 case PROP_MOVIE_TIMESCALE:
2018 g_value_set_uint (value, qtmux->timescale);
2021 g_value_set_boolean (value, qtmux->guess_pts);
2023 case PROP_FAST_START:
2024 g_value_set_boolean (value, qtmux->fast_start);
2026 case PROP_FAST_START_TEMP_FILE:
2027 g_value_set_string (value, qtmux->fast_start_file_path);
2030 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2033 GST_OBJECT_UNLOCK (qtmux);
2037 gst_qt_mux_generate_fast_start_file_path (GstQTMux * qtmux)
2041 if (qtmux->fast_start_file_path) {
2042 g_free (qtmux->fast_start_file_path);
2043 qtmux->fast_start_file_path = NULL;
2046 tmp = g_strdup_printf ("%s%d", "qtmux", g_random_int ());
2047 qtmux->fast_start_file_path = g_build_filename (g_get_tmp_dir (), tmp, NULL);
2052 gst_qt_mux_set_property (GObject * object,
2053 guint prop_id, const GValue * value, GParamSpec * pspec)
2055 GstQTMux *qtmux = GST_QT_MUX_CAST (object);
2057 GST_OBJECT_LOCK (qtmux);
2059 case PROP_LARGE_FILE:
2060 qtmux->large_file = g_value_get_boolean (value);
2062 case PROP_MOVIE_TIMESCALE:
2063 qtmux->timescale = g_value_get_uint (value);
2066 qtmux->guess_pts = g_value_get_boolean (value);
2068 case PROP_FAST_START:
2069 qtmux->fast_start = g_value_get_boolean (value);
2071 case PROP_FAST_START_TEMP_FILE:
2072 if (qtmux->fast_start_file_path) {
2073 g_free (qtmux->fast_start_file_path);
2075 qtmux->fast_start_file_path = g_value_dup_string (value);
2076 /* NULL means to generate a random one */
2077 if (!qtmux->fast_start_file_path) {
2078 gst_qt_mux_generate_fast_start_file_path (qtmux);
2082 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2085 GST_OBJECT_UNLOCK (qtmux);
2088 static GstStateChangeReturn
2089 gst_qt_mux_change_state (GstElement * element, GstStateChange transition)
2091 GstStateChangeReturn ret;
2092 GstQTMux *qtmux = GST_QT_MUX_CAST (element);
2094 switch (transition) {
2095 case GST_STATE_CHANGE_NULL_TO_READY:
2097 case GST_STATE_CHANGE_READY_TO_PAUSED:
2098 gst_collect_pads_start (qtmux->collect);
2099 qtmux->state = GST_QT_MUX_STATE_STARTED;
2101 case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
2103 case GST_STATE_CHANGE_PAUSED_TO_READY:
2104 gst_collect_pads_stop (qtmux->collect);
2110 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
2112 switch (transition) {
2113 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
2115 case GST_STATE_CHANGE_PAUSED_TO_READY:
2116 gst_qt_mux_reset (qtmux, TRUE);
2118 case GST_STATE_CHANGE_READY_TO_NULL:
2129 gst_qt_mux_register (GstPlugin * plugin)
2131 GTypeInfo typeinfo = {
2132 sizeof (GstQTMuxClass),
2133 (GBaseInitFunc) gst_qt_mux_base_init,
2135 (GClassInitFunc) gst_qt_mux_class_init,
2140 (GInstanceInitFunc) gst_qt_mux_init,
2142 static const GInterfaceInfo tag_setter_info = {
2146 GstQTMuxFormat format;
2147 GstQTMuxClassParams *params;
2150 GST_LOG ("Registering muxers");
2153 GstQTMuxFormatProp *prop;
2155 prop = &gst_qt_mux_format_list[i];
2156 format = prop->format;
2157 if (format == GST_QT_MUX_FORMAT_NONE)
2160 /* create a cache for these properties */
2161 params = g_new0 (GstQTMuxClassParams, 1);
2162 params->prop = prop;
2163 params->src_caps = gst_static_caps_get (&prop->src_caps);
2164 params->video_sink_caps = gst_static_caps_get (&prop->video_sink_caps);
2165 params->audio_sink_caps = gst_static_caps_get (&prop->audio_sink_caps);
2167 /* create the type now */
2168 type = g_type_register_static (GST_TYPE_ELEMENT, prop->type_name, &typeinfo,
2170 g_type_set_qdata (type, GST_QT_MUX_PARAMS_QDATA, (gpointer) params);
2171 g_type_add_interface_static (type, GST_TYPE_TAG_SETTER, &tag_setter_info);
2173 if (!gst_element_register (plugin, prop->name, GST_RANK_PRIMARY, type))
2179 GST_LOG ("Finished registering muxers");
2185 gst_qt_mux_plugin_init (GstPlugin * plugin)
2187 GST_DEBUG_CATEGORY_INIT (gst_qt_mux_debug, "qtmux", 0, "QT Muxer");
2189 return gst_qt_mux_register (plugin);
2192 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
2195 "Quicktime Muxer plugin",
2196 gst_qt_mux_plugin_init, VERSION, "LGPL", "gsoc2008 package",
2197 "embedded.ufcg.edu.br")