3 * unit test for qtdemux
5 * Copyright (C) <2016> Edward Hervey <edward@centricular.com>
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., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 #include <glib/gprintf.h>
25 #include <gst/check/gstharness.h>
31 GstClockTime expected_time;
34 static GstPadProbeReturn
35 qtdemux_probe (GstPad * pad, GstPadProbeInfo * info, CommonTestData * data)
37 if (GST_IS_EVENT (GST_PAD_PROBE_INFO_DATA (info))) {
38 GstEvent *ev = GST_PAD_PROBE_INFO_EVENT (info);
40 switch (GST_EVENT_TYPE (ev)) {
41 case GST_EVENT_SEGMENT:
43 const GstSegment *segment;
44 gst_event_parse_segment (ev, &segment);
45 fail_unless (GST_CLOCK_TIME_IS_VALID (segment->format));
46 fail_unless (GST_CLOCK_TIME_IS_VALID (segment->start));
47 fail_unless (GST_CLOCK_TIME_IS_VALID (segment->base));
48 fail_unless (GST_CLOCK_TIME_IS_VALID (segment->time));
49 fail_unless (GST_CLOCK_TIME_IS_VALID (segment->position));
57 return GST_PAD_PROBE_OK;
58 } else if (GST_IS_BUFFER (GST_PAD_PROBE_INFO_DATA (info))) {
59 GstBuffer *buf = GST_PAD_PROBE_INFO_BUFFER (info);
61 fail_unless_equals_int (gst_buffer_get_size (buf), data->expected_size);
62 fail_unless_equals_uint64 (GST_BUFFER_PTS (buf), data->expected_time);
65 return GST_PAD_PROBE_DROP;
69 qtdemux_pad_added_cb (GstElement * element, GstPad * pad, CommonTestData * data)
72 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_DATA_DOWNSTREAM,
73 (GstPadProbeCallback) qtdemux_probe, data, NULL);
76 GST_START_TEST (test_qtdemux_fuzzed0)
80 guchar *fuzzed_qtdemux;
81 gsize fuzzed_qtdemux_len;
83 /* The goal of this test is to check that qtdemux can properly handle
84 * a stream that does not contain any stsd entries, by correctly identifying
85 * the case and erroring out appropriately.
88 h = gst_harness_new_parse ("qtdemux");
89 gst_harness_set_src_caps_str (h, "video/quicktime");
93 ("AAAAIGZ0eXBtcDQyAAAAAG1wNDJtcDQxaXNvbWlzbzIAAAAIZnJlZQAAAMltZGF0AAAADGdCwAyV"
94 "oQkgHhEI1AAAAARozjyAAAAAIWW4AA5///wRRQAfHAxwABAJkxWTk6xWuuuupaupa6668AAAABJB"
95 "4CBX8Zd3d3d3d3d3eJ7E8ZAAAABWQeBAO/wpFAYoDFAYoDFAYkeKAzx4+gAA+kcPHBQGePPHF6jj"
96 "HP0Qdj/og7H/SHY/6jsf9R2P+o7H/Udj/qOx/1HY/6jsf9R2P+o7H/Udj/qOx/1HY/AAAAAGQeBg"
97 "O8IwAAAABkHggDvCMAAAA1dtb292AAAAbG12aGQAAAAA1lbpxdZW6cYAAAfQAAAH0AABAAABAAAA"
98 "AAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAA"
99 "AAAAAAAAAAAAAAAAAAACAAACpnRyYWsAAABcdGtoZAAAAAfWVunF1lbpxgAAAAEAAAAAAAAH0AAA"
100 "AAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAEAAAAAAAQAAAAEA"
101 "AAAAACRlZHRzAAAAHGVsc3QAAIAAAAAAAQAAB9AAAAAAAAEAAAAAAeFtZGlhAAAAIG1kaGQAAAAA"
102 "1lbpxdZW6cYAAAH0AAAB9FXEAAAAAAAtaGRscgAAAAAAAAAAdmlkZUAAAAAAAAAAAAAAAFZpZGVv"
103 "SGFuZGxlcgAAAAGMbWluZgAAABR2bWhkAAAAAQAAAAAAAAAAAAAAJGRpbmYAAAAcZHJlZgAAAAAA"
104 "AAABAAAADHVybCAAAAABAAABTHN0YmwAAADAc3RzZAAAAAAAAAAAAAAAsGF2YzEAAAAAAAAAAQAA"
105 "AAAAAAAZAAAAAAAAAAAAQABAAEgAAABIAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
106 "AAAAAAAAAAAY//8AAAAjYXZjQwFCwAz/4QAMZ0LADJWhCSAeEQjUAQAEaM48gAAAABRidHJ0AAAA"
107 "AAAAAAAAAAYIAAAAE2NvbHJuY2x4AAYAAQAGAAAAABBwYXNwAAAAAQAAAAEAAAAYc3R0cwAAAAAA"
108 "AAABAAAABQAAAAAAAAAUc3RzcwAAAAAAAAABAAAAAQAAABxzdHNjAAAAAAAAAAEAAAABAAAABQAA"
109 "AAEAAAAoc3RzegAAAAAAAAAAAAAAAQAAAAAAAAAWAAAAWgAAAAoAAAAKAAAAFHN0Y28AAAAAAAAA"
110 "AQAAADAAAAA9dWR0YQAAADVtZXRhAAAAAAAAACFoZGxyAAAAAG1obJJtZGlyAAAAAAAAAAAAAAAA"
111 "AAAAAAhpbHN0AAAAPXVkdGEAAAA1bWV0YQAAAAAAAAAhaGRscgAAAABtaGxybWRpcgAAAAAAAAAA"
112 "AAAAAAAAAAAIaWxzdA==", &fuzzed_qtdemux_len);
114 buf = gst_buffer_new_and_alloc (fuzzed_qtdemux_len);
115 gst_buffer_fill (buf, 0, fuzzed_qtdemux, fuzzed_qtdemux_len);
116 fail_unless_equals_int (gst_harness_push (h, buf), GST_FLOW_OK);
118 fail_unless (gst_harness_buffers_received (h) == 0);
120 g_free (fuzzed_qtdemux);
121 gst_harness_teardown (h);
126 GST_START_TEST (test_qtdemux_input_gap)
130 CommonTestData data = { 0, };
137 /* The goal of this test is to check that qtdemux can properly handle
138 * fragmented input from dashdemux, with gaps in it.
143 * - The offset is set on buffers, it corresponds to the offset
144 * within the current fragment.
145 * - Buffer of the beginning of a fragment has the PTS set, others
147 * - By extension, the beginning of a fragment also has an offset
151 qtdemux = gst_element_factory_make ("qtdemux", NULL);
152 gst_element_set_state (qtdemux, GST_STATE_PLAYING);
153 sinkpad = gst_element_get_static_pad (qtdemux, "sink");
155 /* We'll want to know when the source pad is added */
156 g_signal_connect (qtdemux, "pad-added", (GCallback) qtdemux_pad_added_cb,
159 /* Send the initial STREAM_START and segment (TIME) event */
160 event = gst_event_new_stream_start ("TEST");
161 GST_DEBUG ("Pushing stream-start event");
162 fail_unless (gst_pad_send_event (sinkpad, event) == TRUE);
163 gst_segment_init (&segment, GST_FORMAT_TIME);
164 event = gst_event_new_segment (&segment);
165 GST_DEBUG ("Pushing segment event");
166 fail_unless (gst_pad_send_event (sinkpad, event) == TRUE);
168 /* Feed the init buffer, should create the source pad */
169 inbuf = gst_buffer_new_and_alloc (init_mp4_len);
170 gst_buffer_fill (inbuf, 0, init_mp4, init_mp4_len);
171 GST_BUFFER_PTS (inbuf) = 0;
172 GST_BUFFER_OFFSET (inbuf) = 0;
173 GST_DEBUG ("Pushing header buffer");
174 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
176 /* Now send the trun of the first fragment */
177 inbuf = gst_buffer_new_and_alloc (seg_1_moof_size);
178 gst_buffer_fill (inbuf, 0, seg_1_m4f, seg_1_moof_size);
179 GST_BUFFER_PTS (inbuf) = 0;
180 GST_BUFFER_OFFSET (inbuf) = 0;
181 /* We are simulating that this fragment can happen at any point */
182 GST_BUFFER_FLAG_SET (inbuf, GST_BUFFER_FLAG_DISCONT);
183 GST_DEBUG ("Pushing trun buffer");
184 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
185 fail_if (data.srcpad == NULL);
187 /* We are now ready to send some buffers with gaps */
188 offset = seg_1_sample_0_offset;
191 GST_DEBUG ("Pushing gap'ed buffers");
192 for (i = 0; i < 129; i++) {
193 /* Let's send one every 3 */
195 GST_DEBUG ("Pushing buffer #%d offset:%" G_GUINT32_FORMAT, i, offset);
196 inbuf = gst_buffer_new_and_alloc (seg_1_sample_sizes[i]);
197 gst_buffer_fill (inbuf, 0, seg_1_m4f + offset, seg_1_sample_sizes[i]);
198 GST_BUFFER_OFFSET (inbuf) = offset;
199 GST_BUFFER_FLAG_SET (inbuf, GST_BUFFER_FLAG_DISCONT);
201 gst_util_uint64_scale (pts, GST_SECOND, seg_1_timescale);
202 data.expected_size = seg_1_sample_sizes[i];
203 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
205 /* Finally move offset forward */
206 offset += seg_1_sample_sizes[i];
207 pts += seg_1_sample_duration;
210 gst_object_unref (sinkpad);
211 gst_element_set_state (qtdemux, GST_STATE_NULL);
212 gst_object_unref (qtdemux);
221 GstEventType *expected_events;
224 guint expected_num_srcpad;
228 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
231 GST_STATIC_CAPS_ANY);
234 _sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
236 gst_event_unref (event);
241 _sink_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
243 gst_buffer_unref (buffer);
247 static GstPadProbeReturn
248 qtdemux_block_for_reconfig (GstPad * pad, GstPadProbeInfo * info,
249 ReconfigTestData * data)
251 fail_unless (data->pending_pad);
252 fail_unless (data->pending_pad == pad);
254 GST_DEBUG_OBJECT (pad, "Unblock pad");
256 if (gst_pad_is_linked (data->sinkpad)) {
257 GstPad *peer = gst_pad_get_peer (data->sinkpad);
259 gst_pad_unlink (peer, data->sinkpad);
262 fail_unless (gst_pad_link (data->pending_pad, data->sinkpad) ==
264 data->pending_pad = NULL;
266 return GST_PAD_PROBE_REMOVE;
269 static GstPadProbeReturn
270 qtdemux_probe_for_reconfig (GstPad * pad, GstPadProbeInfo * info,
271 ReconfigTestData * data)
273 GstEvent *event = GST_PAD_PROBE_INFO_EVENT (info);
274 GstEventType expected;
276 if (data->step < data->total_step) {
277 expected = data->expected_events[data->step];
279 expected = GST_EVENT_UNKNOWN;
282 GST_DEBUG ("Got event %p %s", event, GST_EVENT_TYPE_NAME (event));
284 fail_unless (GST_EVENT_TYPE (event) == expected,
285 "Received unexpected event: %s (expected: %s)",
286 GST_EVENT_TYPE_NAME (event), gst_event_type_get_name (expected));
289 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS && data->step < data->total_step) {
290 /* If current EOS is for draining, there should be pending srcpad */
291 fail_unless (data->pending_pad != NULL);
294 return GST_PAD_PROBE_OK;
298 qtdemux_pad_added_cb_for_reconfig (GstElement * element, GstPad * pad,
299 ReconfigTestData * data)
303 fail_unless (data->num_srcpad <= data->expected_num_srcpad);
304 fail_unless (data->pending_pad == NULL);
306 GST_DEBUG_OBJECT (pad, "New pad added");
308 data->pending_pad = pad;
309 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
310 (GstPadProbeCallback) qtdemux_block_for_reconfig, data, NULL);
312 if (!data->sinkpad) {
313 GstPad *sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
315 gst_pad_set_event_function (sinkpad, _sink_event);
316 gst_pad_set_chain_function (sinkpad, _sink_chain);
318 gst_pad_add_probe (sinkpad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
319 (GstPadProbeCallback) qtdemux_probe_for_reconfig, data, NULL);
320 gst_pad_set_active (sinkpad, TRUE);
321 data->sinkpad = sinkpad;
325 GST_START_TEST (test_qtdemux_duplicated_moov)
329 ReconfigTestData data = { 0, };
333 GstEventType expected[] = {
334 GST_EVENT_STREAM_START,
342 data.expected_events = expected;
343 data.expected_num_srcpad = 1;
344 data.total_step = G_N_ELEMENTS (expected);
346 /* The goal of this test is to check that qtdemux can properly handle
347 * duplicated moov without redundant events and pad exposing
350 * - Push events stream-start and segment to qtdemux
351 * - Push init and media data
352 * - Push the same init and media data again
355 * - Expose srcpad only once
356 * - No additional downstream events when the second init and media data is
360 qtdemux = gst_element_factory_make ("qtdemux", NULL);
361 gst_element_set_state (qtdemux, GST_STATE_PLAYING);
362 sinkpad = gst_element_get_static_pad (qtdemux, "sink");
364 /* We'll want to know when the source pad is added */
365 g_signal_connect (qtdemux, "pad-added", (GCallback)
366 qtdemux_pad_added_cb_for_reconfig, &data);
368 /* Send the initial STREAM_START and segment (TIME) event */
369 event = gst_event_new_stream_start ("TEST");
370 GST_DEBUG ("Pushing stream-start event");
371 fail_unless (gst_pad_send_event (sinkpad, event) == TRUE);
372 gst_segment_init (&segment, GST_FORMAT_TIME);
373 event = gst_event_new_segment (&segment);
374 GST_DEBUG ("Pushing segment event");
375 fail_unless (gst_pad_send_event (sinkpad, event) == TRUE);
377 /* Feed the init buffer, should create the source pad */
378 inbuf = gst_buffer_new_and_alloc (init_mp4_len);
379 gst_buffer_fill (inbuf, 0, init_mp4, init_mp4_len);
380 GST_BUFFER_PTS (inbuf) = 0;
381 GST_BUFFER_OFFSET (inbuf) = 0;
382 GST_DEBUG ("Pushing moov buffer");
383 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
384 fail_if (data.sinkpad == NULL);
385 fail_unless_equals_int (data.num_srcpad, 1);
387 /* Now send the moof and mdat of the first fragment */
388 inbuf = gst_buffer_new_and_alloc (seg_1_m4f_len);
389 gst_buffer_fill (inbuf, 0, seg_1_m4f, seg_1_m4f_len);
390 GST_BUFFER_PTS (inbuf) = 0;
391 GST_BUFFER_OFFSET (inbuf) = 0;
392 GST_DEBUG ("Pushing moof and mdat buffer");
393 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
395 /* Resend the init, moof and mdat, no additional event and pad are expected */
396 inbuf = gst_buffer_new_and_alloc (init_mp4_len);
397 gst_buffer_fill (inbuf, 0, init_mp4, init_mp4_len);
398 GST_BUFFER_PTS (inbuf) = 0;
399 GST_BUFFER_OFFSET (inbuf) = 0;
400 GST_BUFFER_FLAG_SET (inbuf, GST_BUFFER_FLAG_DISCONT);
401 GST_DEBUG ("Pushing moov buffer again");
402 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
403 fail_if (data.sinkpad == NULL);
404 fail_unless_equals_int (data.num_srcpad, 1);
406 inbuf = gst_buffer_new_and_alloc (seg_1_m4f_len);
407 gst_buffer_fill (inbuf, 0, seg_1_m4f, seg_1_m4f_len);
408 GST_BUFFER_PTS (inbuf) = 0;
409 GST_BUFFER_OFFSET (inbuf) = init_mp4_len;
410 GST_DEBUG ("Pushing moof and mdat buffer again");
411 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
412 fail_unless (gst_pad_send_event (sinkpad, gst_event_new_eos ()) == TRUE);
413 fail_unless_equals_int (data.step, data.total_step);
414 fail_unless (data.pending_pad == NULL);
416 gst_object_unref (sinkpad);
417 gst_pad_set_active (data.sinkpad, FALSE);
418 gst_object_unref (data.sinkpad);
419 gst_element_set_state (qtdemux, GST_STATE_NULL);
420 gst_object_unref (qtdemux);
425 GST_START_TEST (test_qtdemux_stream_change)
429 ReconfigTestData data = { 0, };
433 const gchar *upstream_id;
434 const gchar *stream_id = NULL;
435 gchar *expected_stream_id = NULL;
437 GstEventType expected[] = {
439 GST_EVENT_STREAM_START,
444 /* 2nd group (track-id change without upstream stream-start) */
446 GST_EVENT_STREAM_START,
451 /* 3rd group (no track-id change with upstream stream-start) */
453 GST_EVENT_STREAM_START,
458 /* last group (track-id change with upstream stream-start) */
460 GST_EVENT_STREAM_START,
468 data.expected_events = expected;
469 data.expected_num_srcpad = 4;
470 data.total_step = G_N_ELEMENTS (expected);
472 /* The goal of this test is to check that qtdemux can properly handle
473 * stream change regardless of track-id change.
474 * This test is simulating DASH bitrate switching (for both playbin and plabyin3)
475 * and period-change for playbin3
477 * NOTE: During bitrate switching in DASH, track-id might be changed
478 * NOTE: stream change with new stream-start to qtdemux is playbin3 specific behaviour,
479 * because playbin configures new demux per period and existing demux never ever get
480 * new stream-start again.
484 * - Push events stream-start and segment to qtdemux
485 * - Push init and media data to qtdemux
487 * - Push different (track-id change) init and media data to qtdemux
488 * without new downstream sticky events to qtdemux
490 * - Push events stream-start and segment to qtdemux again
491 * - Push the init and media data which are the same as GROUP 2
493 * - Push events stream-start and segment to qtdemux again
494 * - Push different (track-id change) init and media data to qtdemux
497 * - Demux exposes srcpad four times, per test GROUP, regardless of track-id change
498 * - Whenever exposing new pads, downstream sticky events should be detected
502 qtdemux = gst_element_factory_make ("qtdemux", NULL);
503 gst_element_set_state (qtdemux, GST_STATE_PLAYING);
504 sinkpad = gst_element_get_static_pad (qtdemux, "sink");
506 /* We'll want to know when the source pad is added */
507 g_signal_connect (qtdemux, "pad-added", (GCallback)
508 qtdemux_pad_added_cb_for_reconfig, &data);
514 /* Send the initial STREAM_START and segment (TIME) event */
515 upstream_id = "TEST-GROUP-1";
517 expected_stream_id = g_strdup_printf ("%s/%03u", upstream_id, track_id);
518 event = gst_event_new_stream_start (upstream_id);
519 GST_DEBUG ("Pushing stream-start event");
520 fail_unless (gst_pad_send_event (sinkpad, event) == TRUE);
521 gst_segment_init (&segment, GST_FORMAT_TIME);
522 event = gst_event_new_segment (&segment);
523 GST_DEBUG ("Pushing segment event");
524 fail_unless (gst_pad_send_event (sinkpad, event) == TRUE);
526 /* Feed the init buffer, should create the source pad */
527 inbuf = gst_buffer_new_and_alloc (init_mp4_len);
528 gst_buffer_fill (inbuf, 0, init_mp4, init_mp4_len);
529 GST_BUFFER_PTS (inbuf) = 0;
530 GST_BUFFER_OFFSET (inbuf) = 0;
531 GST_DEBUG ("Pushing moov buffer");
532 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
533 fail_if (data.sinkpad == NULL);
534 fail_unless_equals_int (data.num_srcpad, 1);
536 /* Check stream-id */
537 event = gst_pad_get_sticky_event (data.sinkpad, GST_EVENT_STREAM_START, 0);
538 fail_unless (event != NULL);
539 gst_event_parse_stream_start (event, &stream_id);
540 fail_unless_equals_string (stream_id, expected_stream_id);
541 g_free (expected_stream_id);
542 gst_event_unref (event);
544 /* Now send the moof and mdat of the first fragment */
545 inbuf = gst_buffer_new_and_alloc (seg_1_m4f_len);
546 gst_buffer_fill (inbuf, 0, seg_1_m4f, seg_1_m4f_len);
547 GST_BUFFER_PTS (inbuf) = 0;
548 GST_BUFFER_OFFSET (inbuf) = init_mp4_len;
549 GST_DEBUG ("Pushing moof and mdat buffer");
550 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
556 * - track-id change without new upstream stream-start event
558 /* Resend the init */
559 inbuf = gst_buffer_new_and_alloc (BBB_32k_init_mp4_len);
560 gst_buffer_fill (inbuf, 0, BBB_32k_init_mp4, BBB_32k_init_mp4_len);
561 GST_BUFFER_PTS (inbuf) = 0;
562 GST_BUFFER_OFFSET (inbuf) = 0;
563 GST_BUFFER_FLAG_SET (inbuf, GST_BUFFER_FLAG_DISCONT);
564 GST_DEBUG ("Pushing moov buffer again");
565 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
566 fail_if (data.sinkpad == NULL);
567 /* new srcpad should be exposed */
568 fail_unless_equals_int (data.num_srcpad, 2);
570 /* Check stream-id */
571 upstream_id = "TEST-GROUP-1"; /* upstream-id does not changed from GROUP 1 */
572 track_id = 1; /* track-id is changed from 2 to 1 */
573 expected_stream_id = g_strdup_printf ("%s/%03u", upstream_id, track_id);
574 event = gst_pad_get_sticky_event (data.sinkpad, GST_EVENT_STREAM_START, 0);
575 fail_unless (event != NULL);
576 gst_event_parse_stream_start (event, &stream_id);
577 fail_unless_equals_string (stream_id, expected_stream_id);
578 g_free (expected_stream_id);
579 gst_event_unref (event);
581 /* push the moof and mdat again */
582 inbuf = gst_buffer_new_and_alloc (BBB_32k_1_mp4_len);
583 gst_buffer_fill (inbuf, 0, BBB_32k_1_mp4, BBB_32k_1_mp4_len);
584 GST_BUFFER_PTS (inbuf) = 0;
585 GST_BUFFER_OFFSET (inbuf) = BBB_32k_init_mp4_len;
586 GST_DEBUG ("Pushing moof and mdat buffer");
587 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
592 * - Push new stream-start and segment to qtdemux
593 * - Reuse init and media data of GROUP 2 (no track-id change)
595 /* Send STREAM_START and segment (TIME) event */
596 upstream_id = "TEST-GROUP-3";
598 expected_stream_id = g_strdup_printf ("%s/%03u", upstream_id, track_id);
599 event = gst_event_new_stream_start (upstream_id);
600 GST_DEBUG ("Pushing stream-start event");
601 fail_unless (gst_pad_send_event (sinkpad, event) == TRUE);
602 gst_segment_init (&segment, GST_FORMAT_TIME);
603 event = gst_event_new_segment (&segment);
604 GST_DEBUG ("Pushing segment event");
605 fail_unless (gst_pad_send_event (sinkpad, event) == TRUE);
607 /* Resend the init */
608 inbuf = gst_buffer_new_and_alloc (BBB_32k_init_mp4_len);
609 gst_buffer_fill (inbuf, 0, BBB_32k_init_mp4, BBB_32k_init_mp4_len);
610 GST_BUFFER_PTS (inbuf) = 0;
611 GST_BUFFER_OFFSET (inbuf) = 0;
612 GST_BUFFER_FLAG_SET (inbuf, GST_BUFFER_FLAG_DISCONT);
613 GST_DEBUG ("Pushing moov buffer again");
614 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
615 fail_if (data.sinkpad == NULL);
616 /* new srcpad should be exposed */
617 fail_unless_equals_int (data.num_srcpad, 3);
619 /* Check stream-id */
620 event = gst_pad_get_sticky_event (data.sinkpad, GST_EVENT_STREAM_START, 0);
621 fail_unless (event != NULL);
622 gst_event_parse_stream_start (event, &stream_id);
623 fail_unless_equals_string (stream_id, expected_stream_id);
624 g_free (expected_stream_id);
625 gst_event_unref (event);
627 /* push the moof and mdat again */
628 inbuf = gst_buffer_new_and_alloc (BBB_32k_1_mp4_len);
629 gst_buffer_fill (inbuf, 0, BBB_32k_1_mp4, BBB_32k_1_mp4_len);
630 GST_BUFFER_PTS (inbuf) = 0;
631 GST_BUFFER_OFFSET (inbuf) = BBB_32k_init_mp4_len;
632 GST_DEBUG ("Pushing moof and mdat buffer");
633 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
638 * - Push new stream-start and segment to qtdemux
639 * - track-id change from 1 to 2
641 /* Send STREAM_START and segment (TIME) event */
642 upstream_id = "TEST-GROUP-4";
644 expected_stream_id = g_strdup_printf ("%s/%03u", upstream_id, track_id);
645 event = gst_event_new_stream_start (upstream_id);
646 GST_DEBUG ("Pushing stream-start event");
647 fail_unless (gst_pad_send_event (sinkpad, event) == TRUE);
648 gst_segment_init (&segment, GST_FORMAT_TIME);
649 event = gst_event_new_segment (&segment);
650 GST_DEBUG ("Pushing segment event");
651 fail_unless (gst_pad_send_event (sinkpad, event) == TRUE);
653 /* Resend the init */
654 inbuf = gst_buffer_new_and_alloc (init_mp4_len);
655 gst_buffer_fill (inbuf, 0, init_mp4, init_mp4_len);
656 GST_BUFFER_PTS (inbuf) = 0;
657 GST_BUFFER_OFFSET (inbuf) = 0;
658 GST_BUFFER_FLAG_SET (inbuf, GST_BUFFER_FLAG_DISCONT);
659 GST_DEBUG ("Pushing moov buffer again");
660 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
661 fail_if (data.sinkpad == NULL);
662 /* new srcpad should be exposed */
663 fail_unless_equals_int (data.num_srcpad, 4);
665 /* Check stream-id */
666 event = gst_pad_get_sticky_event (data.sinkpad, GST_EVENT_STREAM_START, 0);
667 fail_unless (event != NULL);
668 gst_event_parse_stream_start (event, &stream_id);
669 fail_unless_equals_string (stream_id, expected_stream_id);
670 g_free (expected_stream_id);
671 gst_event_unref (event);
673 /* push the moof and mdat again */
674 inbuf = gst_buffer_new_and_alloc (seg_1_m4f_len);
675 gst_buffer_fill (inbuf, 0, seg_1_m4f, seg_1_m4f_len);
676 GST_BUFFER_PTS (inbuf) = 0;
677 GST_BUFFER_OFFSET (inbuf) = init_mp4_len;
678 GST_DEBUG ("Pushing moof and mdat buffer again");
679 fail_unless (gst_pad_chain (sinkpad, inbuf) == GST_FLOW_OK);
680 fail_unless (gst_pad_send_event (sinkpad, gst_event_new_eos ()) == TRUE);
681 fail_unless_equals_int (data.step, data.total_step);
682 fail_unless (data.pending_pad == NULL);
684 gst_object_unref (sinkpad);
685 gst_pad_set_active (data.sinkpad, FALSE);
686 gst_object_unref (data.sinkpad);
687 gst_element_set_state (qtdemux, GST_STATE_NULL);
688 gst_object_unref (qtdemux);
696 Suite *s = suite_create ("qtdemux");
697 TCase *tc_chain = tcase_create ("general");
699 suite_add_tcase (s, tc_chain);
700 tcase_add_test (tc_chain, test_qtdemux_fuzzed0);
701 tcase_add_test (tc_chain, test_qtdemux_input_gap);
702 tcase_add_test (tc_chain, test_qtdemux_duplicated_moov);
703 tcase_add_test (tc_chain, test_qtdemux_stream_change);
708 GST_CHECK_MAIN (qtdemux)