5 * Copyright (C) <2008> Mark Nauwelaerts <mnauw@users.sf.net>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
31 #include <glib/gstdio.h>
33 #include <gst/check/gstcheck.h>
34 #include <gst/pbutils/encoding-profile.h>
36 /* For ease of programming we use globals to keep refs for our floating
37 * src and sink pads we create; otherwise we always have to do get_pad,
38 * get_peer, and then remove references in every test function */
39 static GstPad *mysrcpad, *mysinkpad;
41 #define AUDIO_CAPS_STRING "audio/mpeg, " \
42 "mpegversion = (int) 1, " \
44 "channels = (int) 2, " \
47 #define AUDIO_AAC_CAPS_STRING "audio/mpeg, " \
48 "mpegversion=(int)4, " \
51 "stream-format=(string)raw, " \
53 "base-profile=(string)lc, " \
54 "profile=(string)lc, " \
55 "codec_data=(buffer)1208"
57 #define VIDEO_CAPS_STRING "video/mpeg, " \
58 "mpegversion = (int) 4, " \
59 "systemstream = (boolean) false, " \
60 "width = (int) 384, " \
61 "height = (int) 288, " \
62 "framerate = (fraction) 25/1"
64 #define VIDEO_CAPS_H264_STRING "video/x-h264, " \
67 "framerate=(fraction)30/1, " \
68 "pixel-aspect-ratio=(fraction)1/1, " \
69 "codec_data=(buffer)01640014ffe1001867640014a" \
70 "cd94141fb0110000003001773594000f14299600" \
72 "stream-format=(string)avc, " \
73 "alignment=(string)au, " \
75 "profile=(string)high"
77 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
80 GST_STATIC_CAPS ("video/quicktime"));
81 static GstStaticPadTemplate srcvideotemplate = GST_STATIC_PAD_TEMPLATE ("src",
84 GST_STATIC_CAPS (VIDEO_CAPS_STRING));
86 static GstStaticPadTemplate srcvideoh264template =
87 GST_STATIC_PAD_TEMPLATE ("src",
90 GST_STATIC_CAPS (VIDEO_CAPS_H264_STRING));
92 static GstStaticPadTemplate srcaudiotemplate = GST_STATIC_PAD_TEMPLATE ("src",
95 GST_STATIC_CAPS (AUDIO_CAPS_STRING));
97 static GstStaticPadTemplate srcaudioaactemplate =
98 GST_STATIC_PAD_TEMPLATE ("src",
101 GST_STATIC_CAPS (AUDIO_AAC_CAPS_STRING));
103 /* setup and teardown needs some special handling for muxer */
105 setup_src_pad (GstElement * element,
106 GstStaticPadTemplate * template, GstCaps * caps, const gchar * sinkname)
108 GstPad *srcpad, *sinkpad;
110 GST_DEBUG_OBJECT (element, "setting up sending pad");
112 srcpad = gst_pad_new_from_static_template (template, "src");
113 fail_if (srcpad == NULL, "Could not create a srcpad");
114 ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
116 if (!(sinkpad = gst_element_get_static_pad (element, sinkname)))
117 sinkpad = gst_element_get_request_pad (element, sinkname);
118 fail_if (sinkpad == NULL, "Could not get sink pad from %s",
119 GST_ELEMENT_NAME (element));
120 /* references are owned by: 1) us, 2) qtmux, 3) collect pads */
121 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 3);
123 fail_unless (gst_pad_set_caps (srcpad, caps));
124 fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK,
125 "Could not link source and %s sink pads", GST_ELEMENT_NAME (element));
126 gst_object_unref (sinkpad); /* because we got it higher up */
128 /* references are owned by: 1) qtmux, 2) collect pads */
129 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2);
135 teardown_src_pad (GstPad * srcpad)
139 /* clean up floating src pad */
140 sinkpad = gst_pad_get_peer (srcpad);
141 fail_if (sinkpad == NULL);
142 /* pad refs held by 1) qtmux 2) collectpads and 3) us (through _get_peer) */
143 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 3);
145 gst_pad_unlink (srcpad, sinkpad);
147 /* after unlinking, pad refs still held by
148 * 1) qtmux and 2) collectpads and 3) us (through _get_peer) */
149 ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 3);
150 gst_object_unref (sinkpad);
151 /* one more ref is held by element itself */
153 /* pad refs held by creator */
154 ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
155 gst_object_unref (srcpad);
159 setup_qtmux (GstStaticPadTemplate * srctemplate, const gchar * sinkname)
163 GST_DEBUG ("setup_qtmux");
164 qtmux = gst_check_setup_element ("qtmux");
165 mysrcpad = setup_src_pad (qtmux, srctemplate, NULL, sinkname);
166 mysinkpad = gst_check_setup_sink_pad (qtmux, &sinktemplate);
167 gst_pad_set_active (mysrcpad, TRUE);
168 gst_pad_set_active (mysinkpad, TRUE);
174 cleanup_qtmux (GstElement * qtmux, const gchar * sinkname)
176 GST_DEBUG ("cleanup_qtmux");
177 gst_element_set_state (qtmux, GST_STATE_NULL);
179 gst_pad_set_active (mysrcpad, FALSE);
180 gst_pad_set_active (mysinkpad, FALSE);
181 teardown_src_pad (mysrcpad);
182 gst_check_teardown_sink_pad (qtmux);
183 gst_check_teardown_element (qtmux);
187 check_qtmux_pad (GstStaticPadTemplate * srctemplate, const gchar * sinkname,
191 GstBuffer *inbuffer, *outbuffer;
195 guint8 data0[12] = "\000\000\000\024ftypqt ";
196 guint8 data1[8] = "\000\000\000\001mdat";
197 guint8 data2[4] = "moov";
200 qtmux = setup_qtmux (srctemplate, sinkname);
201 g_object_set (qtmux, "dts-method", dts_method, NULL);
202 fail_unless (gst_element_set_state (qtmux,
203 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
204 "could not set to playing");
206 /* ensure segment (format) properly setup */
207 gst_segment_init (&segment, GST_FORMAT_TIME);
208 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_segment (&segment)));
210 inbuffer = gst_buffer_new_and_alloc (1);
211 caps = gst_caps_copy (gst_pad_get_pad_template_caps (mysrcpad));
212 gst_pad_set_caps (mysrcpad, caps);
213 gst_caps_unref (caps);
214 GST_BUFFER_TIMESTAMP (inbuffer) = 0;
215 GST_BUFFER_DURATION (inbuffer) = 40 * GST_MSECOND;
216 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
217 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
219 /* send eos to have moov written */
220 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()) == TRUE);
222 num_buffers = g_list_length (buffers);
223 /* at least expect ftyp, mdat header, buffer chunk and moov */
224 fail_unless (num_buffers >= 4);
226 /* clean up first to clear any pending refs in sticky caps */
227 cleanup_qtmux (qtmux, sinkname);
229 for (i = 0; i < num_buffers; ++i) {
230 outbuffer = GST_BUFFER (buffers->data);
231 fail_if (outbuffer == NULL);
232 buffers = g_list_remove (buffers, outbuffer);
238 fail_unless (gst_buffer_get_size (outbuffer) >= 20);
239 fail_unless (gst_buffer_memcmp (outbuffer, 0, data0,
240 sizeof (data0)) == 0);
241 fail_unless (gst_buffer_memcmp (outbuffer, 16, data0 + 8, 4) == 0);
244 case 1: /* mdat header */
245 fail_unless (gst_buffer_get_size (outbuffer) == 16);
246 fail_unless (gst_buffer_memcmp (outbuffer, 0, data1, sizeof (data1))
249 case 2: /* buffer we put in */
250 fail_unless (gst_buffer_get_size (outbuffer) == 1);
253 fail_unless (gst_buffer_get_size (outbuffer) > 8);
254 fail_unless (gst_buffer_memcmp (outbuffer, 4, data2,
255 sizeof (data2)) == 0);
261 ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
262 gst_buffer_unref (outbuffer);
266 g_list_free (buffers);
271 check_qtmux_pad_fragmented (GstStaticPadTemplate * srctemplate,
272 const gchar * sinkname, guint32 dts_method, gboolean streamable)
275 GstBuffer *inbuffer, *outbuffer;
279 guint8 data0[12] = "\000\000\000\024ftypqt ";
280 guint8 data1[4] = "mdat";
281 guint8 data2[4] = "moov";
282 guint8 data3[4] = "moof";
283 guint8 data4[4] = "mfra";
286 qtmux = setup_qtmux (srctemplate, sinkname);
287 g_object_set (qtmux, "dts-method", dts_method, NULL);
288 g_object_set (qtmux, "fragment-duration", 2000, NULL);
289 g_object_set (qtmux, "streamable", streamable, NULL);
290 fail_unless (gst_element_set_state (qtmux,
291 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
292 "could not set to playing");
294 /* ensure segment (format) properly setup */
295 gst_segment_init (&segment, GST_FORMAT_TIME);
296 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_segment (&segment)));
298 inbuffer = gst_buffer_new_and_alloc (1);
299 caps = gst_caps_copy (gst_pad_get_pad_template_caps (mysrcpad));
300 gst_pad_set_caps (mysrcpad, caps);
301 gst_caps_unref (caps);
302 GST_BUFFER_TIMESTAMP (inbuffer) = 0;
303 GST_BUFFER_DURATION (inbuffer) = 40 * GST_MSECOND;
304 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
305 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
307 /* send eos to have all written */
308 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()) == TRUE);
310 num_buffers = g_list_length (buffers);
311 /* at least expect ftyp, moov, moof, mdat header, buffer chunk
312 * and optionally mfra */
313 fail_unless (num_buffers >= 5);
315 /* clean up first to clear any pending refs in sticky caps */
316 cleanup_qtmux (qtmux, sinkname);
318 for (i = 0; i < num_buffers; ++i) {
319 outbuffer = GST_BUFFER (buffers->data);
320 fail_if (outbuffer == NULL);
321 buffers = g_list_remove (buffers, outbuffer);
327 fail_unless (gst_buffer_get_size (outbuffer) >= 20);
328 fail_unless (gst_buffer_memcmp (outbuffer, 0, data0,
329 sizeof (data0)) == 0);
330 fail_unless (gst_buffer_memcmp (outbuffer, 16, data0 + 8, 4) == 0);
334 fail_unless (gst_buffer_get_size (outbuffer) > 8);
335 fail_unless (gst_buffer_memcmp (outbuffer, 4, data2,
336 sizeof (data2)) == 0);
339 fail_unless (gst_buffer_get_size (outbuffer) > 8);
340 fail_unless (gst_buffer_memcmp (outbuffer, 4, data3,
341 sizeof (data3)) == 0);
343 case 3: /* mdat header */
344 fail_unless (gst_buffer_get_size (outbuffer) == 8);
345 fail_unless (gst_buffer_memcmp (outbuffer, 4, data1,
346 sizeof (data1)) == 0);
348 case 4: /* buffer we put in */
349 fail_unless (gst_buffer_get_size (outbuffer) == 1);
352 fail_unless (gst_buffer_get_size (outbuffer) > 8);
353 fail_unless (gst_buffer_memcmp (outbuffer, 4, data4,
354 sizeof (data4)) == 0);
360 ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
361 gst_buffer_unref (outbuffer);
365 g_list_free (buffers);
371 GST_START_TEST (test_video_pad_dd)
373 check_qtmux_pad (&srcvideotemplate, "video_%u", 0);
378 GST_START_TEST (test_audio_pad_dd)
380 check_qtmux_pad (&srcaudiotemplate, "audio_%u", 0);
386 GST_START_TEST (test_video_pad_frag_dd)
388 check_qtmux_pad_fragmented (&srcvideotemplate, "video_%u", 0, FALSE);
393 GST_START_TEST (test_audio_pad_frag_dd)
395 check_qtmux_pad_fragmented (&srcaudiotemplate, "audio_%u", 0, FALSE);
401 GST_START_TEST (test_video_pad_frag_dd_streamable)
403 check_qtmux_pad_fragmented (&srcvideotemplate, "video_%u", 0, TRUE);
409 GST_START_TEST (test_audio_pad_frag_dd_streamable)
411 check_qtmux_pad_fragmented (&srcaudiotemplate, "audio_%u", 0, TRUE);
416 /* dts-method reorder */
418 GST_START_TEST (test_video_pad_reorder)
420 check_qtmux_pad (&srcvideotemplate, "video_%u", 1);
425 GST_START_TEST (test_audio_pad_reorder)
427 check_qtmux_pad (&srcaudiotemplate, "audio_%u", 1);
433 GST_START_TEST (test_video_pad_frag_reorder)
435 check_qtmux_pad_fragmented (&srcvideotemplate, "video_%u", 1, FALSE);
440 GST_START_TEST (test_audio_pad_frag_reorder)
442 check_qtmux_pad_fragmented (&srcaudiotemplate, "audio_%u", 1, FALSE);
448 GST_START_TEST (test_video_pad_frag_reorder_streamable)
450 check_qtmux_pad_fragmented (&srcvideotemplate, "video_%u", 1, TRUE);
456 GST_START_TEST (test_audio_pad_frag_reorder_streamable)
458 check_qtmux_pad_fragmented (&srcaudiotemplate, "audio_%u", 1, TRUE);
465 GST_START_TEST (test_video_pad_asc)
467 check_qtmux_pad (&srcvideotemplate, "video_%u", 2);
472 GST_START_TEST (test_audio_pad_asc)
474 check_qtmux_pad (&srcaudiotemplate, "audio_%u", 2);
480 GST_START_TEST (test_video_pad_frag_asc)
482 check_qtmux_pad_fragmented (&srcvideotemplate, "video_%u", 2, FALSE);
487 GST_START_TEST (test_audio_pad_frag_asc)
489 check_qtmux_pad_fragmented (&srcaudiotemplate, "audio_%u", 2, FALSE);
495 GST_START_TEST (test_video_pad_frag_asc_streamable)
497 check_qtmux_pad_fragmented (&srcvideotemplate, "video_%u", 2, TRUE);
503 GST_START_TEST (test_audio_pad_frag_asc_streamable)
505 check_qtmux_pad_fragmented (&srcaudiotemplate, "audio_%u", 2, TRUE);
510 GST_START_TEST (test_reuse)
512 GstElement *qtmux = setup_qtmux (&srcvideotemplate, "video_%u");
517 gst_element_set_state (qtmux, GST_STATE_PLAYING);
518 gst_element_set_state (qtmux, GST_STATE_NULL);
519 gst_element_set_state (qtmux, GST_STATE_PLAYING);
520 gst_pad_set_active (mysrcpad, TRUE);
521 gst_pad_set_active (mysinkpad, TRUE);
523 /* ensure segment (format) properly setup */
524 gst_segment_init (&segment, GST_FORMAT_TIME);
525 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_segment (&segment)));
527 inbuffer = gst_buffer_new_and_alloc (1);
528 fail_unless (inbuffer != NULL);
529 caps = gst_caps_copy (gst_pad_get_pad_template_caps (mysrcpad));
530 gst_pad_set_caps (mysrcpad, caps);
531 gst_caps_unref (caps);
532 GST_BUFFER_TIMESTAMP (inbuffer) = 0;
533 GST_BUFFER_DURATION (inbuffer) = 40 * GST_MSECOND;
534 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
535 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
537 /* send eos to have all written */
538 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()) == TRUE);
540 cleanup_qtmux (qtmux, "video_%u");
545 static GstEncodingContainerProfile *
546 create_qtmux_profile (const gchar * variant)
548 GstEncodingContainerProfile *cprof;
551 if (variant == NULL) {
552 caps = gst_caps_new_empty_simple ("video/quicktime");
554 caps = gst_caps_new_simple ("video/quicktime",
555 "variant", G_TYPE_STRING, variant, NULL);
558 cprof = gst_encoding_container_profile_new ("Name", "blah", caps, NULL);
559 gst_caps_unref (caps);
561 caps = gst_caps_new_simple ("audio/x-raw",
562 "format", G_TYPE_STRING, "S16BE",
563 "channels", G_TYPE_INT, 2, "rate", G_TYPE_INT, 44100, NULL);
564 gst_encoding_container_profile_add_profile (cprof,
565 GST_ENCODING_PROFILE (gst_encoding_audio_profile_new (caps, NULL, NULL,
567 gst_caps_unref (caps);
572 GST_START_TEST (test_encodebin_qtmux)
574 GstEncodingContainerProfile *cprof;
578 enc = gst_element_factory_make ("encodebin", NULL);
582 /* Make sure encodebin finds a muxer for a profile with a variant field .. */
583 cprof = create_qtmux_profile ("apple");
584 g_object_set (enc, "profile", cprof, NULL);
585 gst_encoding_profile_unref (cprof);
587 /* should have created a pad after setting the profile */
588 pad = gst_element_get_static_pad (enc, "audio_0");
589 fail_unless (pad != NULL);
590 gst_object_unref (pad);
591 gst_object_unref (enc);
593 /* ... and for a profile without a variant field */
594 enc = gst_element_factory_make ("encodebin", NULL);
595 cprof = create_qtmux_profile (NULL);
596 g_object_set (enc, "profile", cprof, NULL);
597 gst_encoding_profile_unref (cprof);
599 /* should have created a pad after setting the profile */
600 pad = gst_element_get_static_pad (enc, "audio_0");
601 fail_unless (pad != NULL);
602 gst_object_unref (pad);
603 gst_object_unref (enc);
608 /* Fake mp3 encoder for test */
609 typedef GstElement TestMp3Enc;
610 typedef GstElementClass TestMp3EncClass;
612 static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
615 GST_STATIC_CAPS ("audio/mpeg, mpegversion=1, layer=[1,3]")
618 static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink",
621 GST_STATIC_CAPS ("audio/x-raw")
624 static GType test_mp3_enc_get_type (void);
626 G_DEFINE_TYPE (TestMp3Enc, test_mp3_enc, GST_TYPE_ELEMENT);
629 test_mp3_enc_class_init (TestMp3EncClass * klass)
631 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
633 gst_element_class_add_pad_template (element_class,
634 gst_static_pad_template_get (&sink_template));
635 gst_element_class_add_pad_template (element_class,
636 gst_static_pad_template_get (&src_template));
638 gst_element_class_set_details_simple (element_class, "MPEG1 Audio Encoder",
639 "Codec/Encoder/Audio", "Pretends to encode mp3", "Foo Bar <foo@bar.com>");
643 test_mp3_enc_init (TestMp3Enc * mp3enc)
647 pad = gst_pad_new_from_static_template (&sink_template, "sink");
648 gst_element_add_pad (mp3enc, pad);
650 pad = gst_pad_new_from_static_template (&src_template, "src");
651 gst_element_add_pad (mp3enc, pad);
655 plugin_init (GstPlugin * plugin)
657 return gst_element_register (plugin, "testmp3enc", GST_RANK_NONE,
658 test_mp3_enc_get_type ());
661 static GstEncodingContainerProfile *
662 create_mp4mux_profile (void)
664 GstEncodingContainerProfile *cprof;
667 caps = gst_caps_new_simple ("video/quicktime",
668 "variant", G_TYPE_STRING, "iso", NULL);
670 cprof = gst_encoding_container_profile_new ("Name", "blah", caps, NULL);
671 gst_caps_unref (caps);
673 caps = gst_caps_new_simple ("audio/mpeg", "mpegversion", G_TYPE_INT, 1,
674 "layer", G_TYPE_INT, 3, "channels", G_TYPE_INT, 2, "rate", G_TYPE_INT,
676 gst_encoding_container_profile_add_profile (cprof,
677 GST_ENCODING_PROFILE (gst_encoding_audio_profile_new (caps, NULL, NULL,
679 gst_caps_unref (caps);
684 GST_START_TEST (test_encodebin_mp4mux)
686 GstEncodingContainerProfile *cprof;
687 GstPluginFeature *feature;
688 GstElement *enc, *mux;
691 /* need a fake mp3 encoder because mp4 only accepts encoded formats */
692 gst_plugin_register_static (GST_VERSION_MAJOR, GST_VERSION_MINOR,
693 "fakemp3enc", "fakemp3enc", plugin_init, VERSION, "LGPL",
694 "gst-plugins-good", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
696 feature = gst_registry_find_feature (gst_registry_get (), "testmp3enc",
697 GST_TYPE_ELEMENT_FACTORY);
698 gst_plugin_feature_set_rank (feature, GST_RANK_PRIMARY + 100);
700 enc = gst_element_factory_make ("encodebin", NULL);
704 /* Make sure encodebin finds mp4mux even though qtmux outputs a superset */
705 cprof = create_mp4mux_profile ();
706 g_object_set (enc, "profile", cprof, NULL);
707 gst_encoding_profile_unref (cprof);
709 /* should have created a pad after setting the profile */
710 pad = gst_element_get_static_pad (enc, "audio_0");
711 fail_unless (pad != NULL);
712 gst_object_unref (pad);
714 mux = gst_bin_get_by_interface (GST_BIN (enc), GST_TYPE_TAG_SETTER);
715 fail_unless (mux != NULL);
717 GstElementFactory *f = gst_element_get_factory (mux);
719 /* make sure we got mp4mux for variant=iso */
720 GST_INFO ("muxer: %s", G_OBJECT_TYPE_NAME (mux));
721 fail_unless_equals_string (GST_OBJECT_NAME (f), "mp4mux");
723 gst_object_unref (mux);
724 gst_object_unref (enc);
726 gst_plugin_feature_set_rank (feature, GST_RANK_NONE);
727 gst_object_unref (feature);
733 extract_tags (const gchar * location, GstTagList ** taglist)
738 GstElement *pipeline =
739 gst_parse_launch ("filesrc name=src ! qtdemux ! fakesink", NULL);
741 src = gst_bin_get_by_name (GST_BIN (pipeline), "src");
742 g_object_set (src, "location", location, NULL);
744 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
745 fail_unless (gst_element_set_state (pipeline, GST_STATE_PLAYING)
746 != GST_STATE_CHANGE_FAILURE);
748 if (*taglist == NULL) {
749 *taglist = gst_tag_list_new_empty ();
753 GstMessage *msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE,
754 GST_MESSAGE_TAG | GST_MESSAGE_ERROR | GST_MESSAGE_EOS);
756 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS) {
757 gst_message_unref (msg);
759 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
761 gst_message_unref (msg);
763 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_TAG) {
766 gst_message_parse_tag (msg, &tags);
767 gst_tag_list_insert (*taglist, tags, GST_TAG_MERGE_REPLACE);
768 gst_tag_list_free (tags);
770 gst_message_unref (msg);
773 gst_object_unref (bus);
774 gst_element_set_state (pipeline, GST_STATE_NULL);
775 gst_object_unref (src);
776 gst_object_unref (pipeline);
781 test_average_bitrate_custom (const gchar * elementname,
782 GstStaticPadTemplate * tmpl, const gchar * sinkpadname)
786 GstElement *filesink;
790 gint bytes[] = { 16, 22, 12 };
791 gint64 durations[] = { GST_SECOND * 3, GST_SECOND * 5, GST_SECOND * 2 };
792 gint64 total_bytes = 0;
793 GstClockTime total_duration = 0;
796 location = g_strdup_printf ("%s/%s-%d", g_get_tmp_dir (), "qtmuxtest",
798 GST_INFO ("Using location %s for bitrate test", location);
799 qtmux = gst_check_setup_element (elementname);
800 filesink = gst_element_factory_make ("filesink", NULL);
801 g_object_set (filesink, "location", location, NULL);
802 gst_element_link (qtmux, filesink);
803 mysrcpad = setup_src_pad (qtmux, tmpl, NULL, sinkpadname);
804 fail_unless (mysrcpad != NULL);
805 gst_pad_set_active (mysrcpad, TRUE);
807 fail_unless (gst_element_set_state (filesink,
808 GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
809 "could not set filesink to playing");
810 fail_unless (gst_element_set_state (qtmux,
811 GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
812 "could not set to playing");
814 /* ensure segment (format) properly setup */
815 gst_segment_init (&segment, GST_FORMAT_TIME);
816 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_segment (&segment)));
818 for (i = 0; i < 3; i++) {
819 inbuffer = gst_buffer_new_and_alloc (bytes[i]);
820 caps = gst_caps_copy (gst_pad_get_pad_template_caps (mysrcpad));
821 gst_pad_set_caps (mysrcpad, caps);
822 gst_caps_unref (caps);
823 GST_BUFFER_TIMESTAMP (inbuffer) = total_duration;
824 GST_BUFFER_DURATION (inbuffer) = (GstClockTime) durations[i];
825 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
827 total_bytes += gst_buffer_get_size (inbuffer);
828 total_duration += GST_BUFFER_DURATION (inbuffer);
829 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
832 /* send eos to have moov written */
833 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()) == TRUE);
835 gst_element_set_state (qtmux, GST_STATE_NULL);
836 gst_element_set_state (filesink, GST_STATE_NULL);
838 gst_pad_set_active (mysrcpad, FALSE);
839 teardown_src_pad (mysrcpad);
840 gst_object_unref (filesink);
841 gst_check_teardown_element (qtmux);
843 /* check the bitrate tag */
845 GstTagList *taglist = NULL;
849 fail_unless (extract_tags (location, &taglist));
851 fail_unless (gst_tag_list_get_uint (taglist, GST_TAG_BITRATE, &bitrate));
854 (guint) gst_util_uint64_scale_round ((guint64) total_bytes,
855 (guint64) 8 * GST_SECOND, (guint64) total_duration);
856 fail_unless (bitrate == expected);
857 gst_tag_list_free (taglist);
865 GST_START_TEST (test_average_bitrate)
867 test_average_bitrate_custom ("mp4mux", &srcaudioaactemplate, "audio_%u");
868 test_average_bitrate_custom ("mp4mux", &srcvideoh264template, "video_%u");
870 test_average_bitrate_custom ("qtmux", &srcaudioaactemplate, "audio_%u");
871 test_average_bitrate_custom ("qtmux", &srcvideoh264template, "video_%u");
880 Suite *s = suite_create ("qtmux");
881 TCase *tc_chain = tcase_create ("general");
883 suite_add_tcase (s, tc_chain);
884 tcase_add_test (tc_chain, test_video_pad_dd);
885 tcase_add_test (tc_chain, test_audio_pad_dd);
886 tcase_add_test (tc_chain, test_video_pad_frag_dd);
887 tcase_add_test (tc_chain, test_audio_pad_frag_dd);
888 tcase_add_test (tc_chain, test_video_pad_frag_dd_streamable);
889 tcase_add_test (tc_chain, test_audio_pad_frag_dd_streamable);
891 tcase_add_test (tc_chain, test_video_pad_reorder);
892 tcase_add_test (tc_chain, test_audio_pad_reorder);
893 tcase_add_test (tc_chain, test_video_pad_frag_reorder);
894 tcase_add_test (tc_chain, test_audio_pad_frag_reorder);
895 tcase_add_test (tc_chain, test_video_pad_frag_reorder_streamable);
896 tcase_add_test (tc_chain, test_audio_pad_frag_reorder_streamable);
898 tcase_add_test (tc_chain, test_video_pad_asc);
899 tcase_add_test (tc_chain, test_audio_pad_asc);
900 tcase_add_test (tc_chain, test_video_pad_frag_asc);
901 tcase_add_test (tc_chain, test_audio_pad_frag_asc);
902 tcase_add_test (tc_chain, test_video_pad_frag_asc_streamable);
903 tcase_add_test (tc_chain, test_audio_pad_frag_asc_streamable);
905 tcase_add_test (tc_chain, test_average_bitrate);
907 tcase_add_test (tc_chain, test_reuse);
908 tcase_add_test (tc_chain, test_encodebin_qtmux);
909 tcase_add_test (tc_chain, test_encodebin_mp4mux);
914 GST_CHECK_MAIN (qtmux)