1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
|
/* GStreamer unit test for splitmuxsrc/sink elements
*
* Copyright (C) 2007 David A. Schleef <ds@schleef.org>
* Copyright (C) 2015 Jan Schmidt <jan@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <glib/gstdio.h>
#include <unistd.h>
#include <gst/check/gstcheck.h>
#include <gst/app/app.h>
#include <stdlib.h>
#include <unistd.h>
gchar *tmpdir = NULL;
GstClockTime first_ts;
GstClockTime last_ts;
gdouble current_rate;
static void
tempdir_setup (void)
{
const gchar *systmp = g_get_tmp_dir ();
tmpdir = g_build_filename (systmp, "splitmux-test-XXXXXX", NULL);
/* Rewrites tmpdir template input: */
tmpdir = g_mkdtemp (tmpdir);
}
static void
tempdir_cleanup (void)
{
GDir *d;
const gchar *f;
fail_if (tmpdir == NULL);
d = g_dir_open (tmpdir, 0, NULL);
fail_if (d == NULL);
while ((f = g_dir_read_name (d)) != NULL) {
gchar *fname = g_build_filename (tmpdir, f, NULL);
fail_if (g_remove (fname) != 0, "Failed to remove tmp file %s", fname);
g_free (fname);
}
g_dir_close (d);
fail_if (g_remove (tmpdir) != 0, "Failed to delete tmpdir %s", tmpdir);
g_free (tmpdir);
tmpdir = NULL;
}
static guint
count_files (const gchar * target)
{
GDir *d;
const gchar *f;
guint ret = 0;
d = g_dir_open (target, 0, NULL);
fail_if (d == NULL);
while ((f = g_dir_read_name (d)) != NULL)
ret++;
g_dir_close (d);
return ret;
}
static void
dump_error (GstMessage * msg)
{
GError *err = NULL;
gchar *dbg_info;
fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
gst_message_parse_error (msg, &err, &dbg_info);
g_printerr ("ERROR from element %s: %s\n",
GST_OBJECT_NAME (msg->src), err->message);
g_printerr ("Debugging info: %s\n", (dbg_info) ? dbg_info : "none");
g_error_free (err);
g_free (dbg_info);
}
static GstMessage *
run_pipeline (GstElement * pipeline)
{
GstBus *bus = gst_element_get_bus (GST_ELEMENT (pipeline));
GstMessage *msg;
gst_element_set_state (pipeline, GST_STATE_PLAYING);
msg = gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (bus);
if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR)
dump_error (msg);
return msg;
}
static void
seek_pipeline (GstElement * pipeline, gdouble rate, GstClockTime start,
GstClockTime end)
{
/* Pause the pipeline, seek to the desired range / rate, wait for PAUSED again, then
* clear the tracking vars for start_ts / end_ts */
gst_element_set_state (pipeline, GST_STATE_PAUSED);
gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
/* specific end time not implemented: */
fail_unless (end == GST_CLOCK_TIME_NONE);
gst_element_seek (pipeline, rate, GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE, GST_SEEK_TYPE_SET, start,
GST_SEEK_TYPE_END, 0);
/* Wait for the pipeline to preroll again */
gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
GST_LOG ("Seeked pipeline. Rate %f time range %" GST_TIME_FORMAT " to %"
GST_TIME_FORMAT, rate, GST_TIME_ARGS (start), GST_TIME_ARGS (end));
/* Clear tracking variables now that the seek is complete */
first_ts = last_ts = GST_CLOCK_TIME_NONE;
current_rate = rate;
};
static void
receive_handoff (GstElement * object G_GNUC_UNUSED, GstBuffer * buf,
GstPad * arg1 G_GNUC_UNUSED, gpointer user_data G_GNUC_UNUSED)
{
GstClockTime start = GST_BUFFER_TIMESTAMP (buf);
GstClockTime end = start;
if (GST_BUFFER_DURATION_IS_VALID (buf))
end += GST_BUFFER_DURATION (buf);
GST_LOG ("Got buffer %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT,
GST_TIME_ARGS (start), GST_TIME_ARGS (end));
/* Check time is moving in the right direction */
if (current_rate > 0) {
if (GST_CLOCK_TIME_IS_VALID (first_ts))
fail_unless (start >= first_ts,
"Timestamps went backward during forward play, %" GST_TIME_FORMAT
" < %" GST_TIME_FORMAT, GST_TIME_ARGS (start),
GST_TIME_ARGS (first_ts));
if (GST_CLOCK_TIME_IS_VALID (last_ts))
fail_unless (end >= last_ts,
"Timestamps went backward during forward play, %" GST_TIME_FORMAT
" < %" GST_TIME_FORMAT, GST_TIME_ARGS (end), GST_TIME_ARGS (last_ts));
} else {
fail_unless (start <= first_ts,
"Timestamps went forward during reverse play, %" GST_TIME_FORMAT " > %"
GST_TIME_FORMAT, GST_TIME_ARGS (start), GST_TIME_ARGS (first_ts));
fail_unless (end <= last_ts,
"Timestamps went forward during reverse play, %" GST_TIME_FORMAT " > %"
GST_TIME_FORMAT, GST_TIME_ARGS (end), GST_TIME_ARGS (last_ts));
}
/* update the range of timestamps we've encountered */
if (!GST_CLOCK_TIME_IS_VALID (first_ts) || start < first_ts)
first_ts = start;
if (!GST_CLOCK_TIME_IS_VALID (last_ts) || end > last_ts)
last_ts = end;
}
static void
test_playback (const gchar * in_pattern, GstClockTime exp_first_time,
GstClockTime exp_last_time)
{
GstMessage *msg;
GstElement *pipeline;
GstElement *fakesink;
gchar *uri;
pipeline = gst_element_factory_make ("playbin", NULL);
fail_if (pipeline == NULL);
fakesink = gst_element_factory_make ("fakesink", NULL);
fail_if (fakesink == NULL);
g_object_set (G_OBJECT (pipeline), "video-sink", fakesink, NULL);
uri = g_strdup_printf ("splitmux://%s", in_pattern);
g_object_set (G_OBJECT (pipeline), "uri", uri, NULL);
g_free (uri);
g_signal_connect (fakesink, "handoff", (GCallback) receive_handoff, NULL);
g_object_set (G_OBJECT (fakesink), "signal-handoffs", TRUE, NULL);
/* test forwards */
seek_pipeline (pipeline, 1.0, 0, -1);
fail_unless (first_ts == GST_CLOCK_TIME_NONE);
msg = run_pipeline (pipeline);
fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
gst_message_unref (msg);
/* Check we saw the entire range of values */
fail_unless (first_ts == exp_first_time,
"Expected start of playback range 0, got %" GST_TIME_FORMAT,
GST_TIME_ARGS (first_ts));
fail_unless (last_ts == exp_last_time,
"Expected end of playback range 3s, got %" GST_TIME_FORMAT,
GST_TIME_ARGS (last_ts));
/* Test backwards */
seek_pipeline (pipeline, -1.0, 0, -1);
msg = run_pipeline (pipeline);
fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
gst_message_unref (msg);
/* Check we saw the entire range of values */
fail_unless (first_ts == exp_first_time,
"Expected start of playback range %" GST_TIME_FORMAT
", got %" GST_TIME_FORMAT, GST_TIME_ARGS (exp_first_time),
GST_TIME_ARGS (first_ts));
fail_unless (last_ts == exp_last_time,
"Expected end of playback range %" GST_TIME_FORMAT
", got %" GST_TIME_FORMAT, GST_TIME_ARGS (exp_last_time),
GST_TIME_ARGS (last_ts));
gst_object_unref (pipeline);
}
GST_START_TEST (test_splitmuxsrc)
{
gchar *in_pattern =
g_build_filename (GST_TEST_FILES_PATH, "splitvideo*.ogg", NULL);
test_playback (in_pattern, 0, 3 * GST_SECOND);
g_free (in_pattern);
}
GST_END_TEST;
static gchar **
src_format_location_cb (GstElement * splitmuxsrc, gpointer user_data)
{
gchar **result = g_malloc0_n (4, sizeof (gchar *));
result[0] = g_build_filename (GST_TEST_FILES_PATH, "splitvideo00.ogg", NULL);
result[1] = g_build_filename (GST_TEST_FILES_PATH, "splitvideo01.ogg", NULL);
result[2] = g_build_filename (GST_TEST_FILES_PATH, "splitvideo02.ogg", NULL);
return result;
}
GST_START_TEST (test_splitmuxsrc_format_location)
{
GstMessage *msg;
GstElement *pipeline;
GstElement *src;
GError *error = NULL;
pipeline = gst_parse_launch ("splitmuxsrc name=splitsrc ! decodebin "
"! fakesink", &error);
g_assert_no_error (error);
fail_if (pipeline == NULL);
src = gst_bin_get_by_name (GST_BIN (pipeline), "splitsrc");
g_signal_connect (src, "format-location",
(GCallback) src_format_location_cb, NULL);
g_object_unref (src);
msg = run_pipeline (pipeline);
if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR)
dump_error (msg);
fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
gst_message_unref (msg);
gst_object_unref (pipeline);
}
GST_END_TEST;
static gchar *
check_format_location (GstElement * object,
guint fragment_id, GstSample * first_sample)
{
GstBuffer *buf = gst_sample_get_buffer (first_sample);
/* Must have a buffer */
fail_if (buf == NULL);
GST_LOG ("New file - first buffer %" GST_TIME_FORMAT,
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
return NULL;
}
GST_START_TEST (test_splitmuxsink)
{
GstMessage *msg;
GstElement *pipeline;
GstElement *sink;
GstPad *splitmux_sink_pad;
GstPad *enc_src_pad;
gchar *dest_pattern;
guint count;
gchar *in_pattern;
/* This pipeline has a small time cutoff - it should start a new file
* every GOP, ie 1 second */
pipeline =
gst_parse_launch
("videotestsrc num-buffers=15 ! video/x-raw,width=80,height=64,framerate=5/1 ! videoconvert !"
" queue ! theoraenc keyframe-force=5 ! splitmuxsink name=splitsink "
" max-size-time=1000000 max-size-bytes=1000000 muxer=oggmux", NULL);
fail_if (pipeline == NULL);
sink = gst_bin_get_by_name (GST_BIN (pipeline), "splitsink");
fail_if (sink == NULL);
g_signal_connect (sink, "format-location-full",
(GCallback) check_format_location, NULL);
dest_pattern = g_build_filename (tmpdir, "out%05d.ogg", NULL);
g_object_set (G_OBJECT (sink), "location", dest_pattern, NULL);
g_free (dest_pattern);
g_object_unref (sink);
msg = run_pipeline (pipeline);
if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR)
dump_error (msg);
fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
gst_message_unref (msg);
/* unlink manually and relase request pad to ensure that we *can* do that
* - https://bugzilla.gnome.org/show_bug.cgi?id=753622 */
sink = gst_bin_get_by_name (GST_BIN (pipeline), "splitsink");
fail_if (sink == NULL);
splitmux_sink_pad = gst_element_get_static_pad (sink, "video");
fail_if (splitmux_sink_pad == NULL);
enc_src_pad = gst_pad_get_peer (splitmux_sink_pad);
fail_if (enc_src_pad == NULL);
fail_unless (gst_pad_unlink (enc_src_pad, splitmux_sink_pad));
gst_object_unref (enc_src_pad);
gst_element_release_request_pad (sink, splitmux_sink_pad);
gst_object_unref (splitmux_sink_pad);
/* at this point the pad must be releaased - try to find it again to verify */
splitmux_sink_pad = gst_element_get_static_pad (sink, "video");
fail_if (splitmux_sink_pad != NULL);
g_object_unref (sink);
gst_object_unref (pipeline);
count = count_files (tmpdir);
fail_unless (count == 3, "Expected 3 output files, got %d", count);
in_pattern = g_build_filename (tmpdir, "out*.ogg", NULL);
test_playback (in_pattern, 0, 3 * GST_SECOND);
g_free (in_pattern);
}
GST_END_TEST;
static GstPadProbeReturn
intercept_stream_start (GstPad * pad, GstPadProbeInfo * info,
gpointer user_data)
{
GstEvent *event = gst_pad_probe_info_get_event (info);
if (GST_EVENT_TYPE (event) == GST_EVENT_STREAM_START) {
GstStreamFlags flags;
event = gst_event_make_writable (event);
gst_event_parse_stream_flags (event, &flags);
gst_event_set_stream_flags (event, flags | GST_STREAM_FLAG_SPARSE);
GST_PAD_PROBE_INFO_DATA (info) = event;
}
return GST_PAD_PROBE_OK;
}
static GstFlowReturn
new_sample_verify_continuous_timestamps (GstAppSink * appsink,
gpointer user_data)
{
GstSample *sample;
GstBuffer *buffer;
GstClockTime *prev_ts = user_data;
GstClockTime new_ts;
sample = gst_app_sink_pull_sample (appsink);
buffer = gst_sample_get_buffer (sample);
new_ts = GST_BUFFER_PTS (buffer);
if (GST_CLOCK_TIME_IS_VALID (*prev_ts)) {
fail_unless (*prev_ts < new_ts,
"%s: prev_ts (%" GST_TIME_FORMAT ") >= new_ts (%" GST_TIME_FORMAT ")",
GST_OBJECT_NAME (appsink), GST_TIME_ARGS (*prev_ts),
GST_TIME_ARGS (new_ts));
}
*prev_ts = new_ts;
gst_sample_unref (sample);
return GST_FLOW_OK;
}
static GstFlowReturn
new_sample_verify_1sec_offset (GstAppSink * appsink, gpointer user_data)
{
GstSample *sample;
GstBuffer *buffer;
GstClockTime *prev_ts = user_data;
GstClockTime new_ts;
sample = gst_app_sink_pull_sample (appsink);
buffer = gst_sample_get_buffer (sample);
new_ts = GST_BUFFER_PTS (buffer);
if (GST_CLOCK_TIME_IS_VALID (*prev_ts)) {
fail_unless (new_ts > (*prev_ts + 900 * GST_MSECOND),
"%s: prev_ts (%" GST_TIME_FORMAT ") + 0.9s >= new_ts (%"
GST_TIME_FORMAT ")", GST_OBJECT_NAME (appsink),
GST_TIME_ARGS (*prev_ts), GST_TIME_ARGS (new_ts));
}
*prev_ts = new_ts;
gst_sample_unref (sample);
return GST_FLOW_OK;
}
/* https://bugzilla.gnome.org/show_bug.cgi?id=761086 */
GST_START_TEST (test_splitmuxsrc_sparse_streams)
{
GstElement *pipeline;
GstElement *element;
gchar *dest_pattern;
GstElement *appsrc;
GstPad *appsrc_src;
GstBus *bus;
GstMessage *msg;
gint i;
/* generate files */
/* in this test, we have 5sec of data with files split at 1sec intervals */
pipeline =
gst_parse_launch
("videotestsrc num-buffers=75 !"
" video/x-raw,width=80,height=64,framerate=15/1 !"
" theoraenc keyframe-force=5 ! splitmuxsink name=splitsink"
" max-size-time=1000000000 muxer=matroskamux"
" audiotestsrc num-buffers=100 samplesperbuffer=1024 !"
" audio/x-raw,rate=20000 ! vorbisenc ! splitsink.audio_%u"
" appsrc name=appsrc format=time caps=text/x-raw,format=utf8 !"
" splitsink.subtitle_%u", NULL);
fail_if (pipeline == NULL);
element = gst_bin_get_by_name (GST_BIN (pipeline), "splitsink");
fail_if (element == NULL);
dest_pattern = g_build_filename (tmpdir, "out%05d.ogg", NULL);
g_object_set (G_OBJECT (element), "location", dest_pattern, NULL);
g_clear_pointer (&dest_pattern, g_free);
g_clear_object (&element);
appsrc = gst_bin_get_by_name (GST_BIN (pipeline), "appsrc");
fail_if (appsrc == NULL);
/* add the SPARSE flag on the stream-start event of the subtitle stream */
appsrc_src = gst_element_get_static_pad (appsrc, "src");
fail_if (appsrc_src == NULL);
gst_pad_add_probe (appsrc_src, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
intercept_stream_start, NULL, NULL);
g_clear_object (&appsrc_src);
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
gst_element_set_state (pipeline, GST_STATE_PLAYING);
/* push subtitles, one per second, starting from t=100ms */
for (i = 0; i < 5; i++) {
GstBuffer *buffer = gst_buffer_new_allocate (NULL, 5, NULL);
GstMapInfo info;
gst_buffer_map (buffer, &info, GST_MAP_WRITE);
strcpy ((char *) info.data, "test");
gst_buffer_unmap (buffer, &info);
GST_BUFFER_PTS (buffer) = i * GST_SECOND + 100 * GST_MSECOND;
GST_BUFFER_DTS (buffer) = GST_BUFFER_PTS (buffer);
fail_if (gst_app_src_push_buffer (GST_APP_SRC (appsrc), buffer)
!= GST_FLOW_OK);
}
fail_if (gst_app_src_end_of_stream (GST_APP_SRC (appsrc)) != GST_FLOW_OK);
msg = gst_bus_timed_pop_filtered (bus, 5 * GST_SECOND, GST_MESSAGE_EOS);
g_clear_pointer (&msg, gst_message_unref);
gst_element_set_state (pipeline, GST_STATE_NULL);
g_clear_object (&appsrc);
g_clear_object (&bus);
g_clear_object (&pipeline);
/* read and verify */
pipeline =
gst_parse_launch
("splitmuxsrc name=splitsrc"
" splitsrc. ! theoradec ! appsink name=vsink sync=false emit-signals=true"
" splitsrc. ! vorbisdec ! appsink name=asink sync=false emit-signals=true"
" splitsrc. ! text/x-raw ! appsink name=tsink sync=false emit-signals=true",
NULL);
fail_if (pipeline == NULL);
element = gst_bin_get_by_name (GST_BIN (pipeline), "splitsrc");
fail_if (element == NULL);
dest_pattern = g_build_filename (tmpdir, "out*.ogg", NULL);
g_object_set (G_OBJECT (element), "location", dest_pattern, NULL);
g_clear_pointer (&dest_pattern, g_free);
g_clear_object (&element);
{
GstClockTime vsink_prev_ts = GST_CLOCK_TIME_NONE;
GstClockTime asink_prev_ts = GST_CLOCK_TIME_NONE;
GstClockTime tsink_prev_ts = GST_CLOCK_TIME_NONE;
/* verify that timestamps are continuously increasing for audio + video.
* if we hit bug 761086, timestamps will jump about -900ms after switching
* to a new part, because this is the difference between the last subtitle
* pts and the last audio/video pts */
element = gst_bin_get_by_name (GST_BIN (pipeline), "vsink");
g_signal_connect (element, "new-sample",
(GCallback) new_sample_verify_continuous_timestamps, &vsink_prev_ts);
g_clear_object (&element);
element = gst_bin_get_by_name (GST_BIN (pipeline), "asink");
g_signal_connect (element, "new-sample",
(GCallback) new_sample_verify_continuous_timestamps, &asink_prev_ts);
g_clear_object (&element);
/* also verify that subtitle timestamps are increasing by about 1s.
* if we hit bug 761086, timestamps will increase by exactly 100ms instead,
* because this is the relative difference between a part's start time
* (remember a new part starts every 1sec) and the subtitle's pts in that
* part, which will be added to the max_ts of the previous part, which
* equals the last subtitle's pts (and should not!) */
element = gst_bin_get_by_name (GST_BIN (pipeline), "tsink");
g_signal_connect (element, "new-sample",
(GCallback) new_sample_verify_1sec_offset, &tsink_prev_ts);
g_clear_object (&element);
msg = run_pipeline (pipeline);
}
if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR)
dump_error (msg);
fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
g_clear_pointer (&msg, gst_message_unref);
g_clear_object (&pipeline);
}
GST_END_TEST;
struct CapsChangeData
{
guint count;
GstElement *cf;
};
static GstPadProbeReturn
switch_caps (GstPad * pad, GstPadProbeInfo * info, gpointer user_data)
{
struct CapsChangeData *data = (struct CapsChangeData *) (user_data);
if (data->count == 4) {
GST_INFO ("Saw 5 buffers to the encoder. Switching caps");
gst_util_set_object_arg (G_OBJECT (data->cf), "caps",
"video/x-raw,width=160,height=128,framerate=10/1");
}
data->count++;
return GST_PAD_PROBE_OK;
}
GST_START_TEST (test_splitmuxsrc_caps_change)
{
GstMessage *msg;
GstElement *pipeline;
GstElement *sink;
GstElement *cf;
GstPad *sinkpad;
gchar *dest_pattern;
guint count;
gchar *in_pattern;
struct CapsChangeData data;
/* This test creates a new file only by changing the caps, which
* qtmux will reject (for now - if qtmux starts supporting caps
* changes, this test will break and need fixing/disabling */
pipeline =
gst_parse_launch
("videotestsrc num-buffers=10 !"
" capsfilter name=c caps=video/x-raw,width=80,height=64,framerate=10/1 !"
" jpegenc ! splitmuxsink name=splitsink muxer=qtmux", NULL);
fail_if (pipeline == NULL);
sink = gst_bin_get_by_name (GST_BIN (pipeline), "splitsink");
fail_if (sink == NULL);
g_signal_connect (sink, "format-location-full",
(GCallback) check_format_location, NULL);
dest_pattern = g_build_filename (tmpdir, "out%05d.mp4", NULL);
g_object_set (G_OBJECT (sink), "location", dest_pattern, NULL);
g_free (dest_pattern);
g_object_unref (sink);
cf = gst_bin_get_by_name (GST_BIN (pipeline), "c");
sinkpad = gst_element_get_static_pad (cf, "sink");
data.cf = cf;
data.count = 0;
gst_pad_add_probe (sinkpad, GST_PAD_PROBE_TYPE_BUFFER,
switch_caps, &data, NULL);
gst_object_unref (sinkpad);
gst_object_unref (cf);
msg = run_pipeline (pipeline);
if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR)
dump_error (msg);
fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
gst_message_unref (msg);
gst_object_unref (pipeline);
count = count_files (tmpdir);
fail_unless (count == 2, "Expected 2 output files, got %d", count);
in_pattern = g_build_filename (tmpdir, "out*.mp4", NULL);
test_playback (in_pattern, 0, GST_SECOND);
g_free (in_pattern);
}
GST_END_TEST;
/* For verifying bug https://bugzilla.gnome.org/show_bug.cgi?id=762893 */
GST_START_TEST (test_splitmuxsink_reuse_simple)
{
GstElement *sink;
GstPad *pad;
sink = gst_element_factory_make ("splitmuxsink", NULL);
pad = gst_element_get_request_pad (sink, "video");
fail_unless (pad != NULL);
g_object_set (sink, "location", "/dev/null", NULL);
fail_unless (gst_element_set_state (sink,
GST_STATE_PLAYING) == GST_STATE_CHANGE_ASYNC);
fail_unless (gst_element_set_state (sink,
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
fail_unless (gst_element_set_state (sink,
GST_STATE_PLAYING) == GST_STATE_CHANGE_ASYNC);
fail_unless (gst_element_set_state (sink,
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
gst_element_release_request_pad (sink, pad);
gst_object_unref (pad);
gst_object_unref (sink);
}
GST_END_TEST;
static Suite *
splitmux_suite (void)
{
Suite *s = suite_create ("splitmux");
TCase *tc_chain = tcase_create ("general");
TCase *tc_chain_basic = tcase_create ("basic");
TCase *tc_chain_complex = tcase_create ("complex");
TCase *tc_chain_caps_change = tcase_create ("caps_change");
gboolean have_theora, have_ogg, have_vorbis, have_matroska, have_qtmux,
have_jpeg;
/* we assume that if encoder/muxer are there, decoder/demuxer will be a well */
have_theora = gst_registry_check_feature_version (gst_registry_get (),
"theoraenc", GST_VERSION_MAJOR, GST_VERSION_MINOR, 0);
have_ogg = gst_registry_check_feature_version (gst_registry_get (),
"oggmux", GST_VERSION_MAJOR, GST_VERSION_MINOR, 0);
have_vorbis = gst_registry_check_feature_version (gst_registry_get (),
"vorbisenc", GST_VERSION_MAJOR, GST_VERSION_MINOR, 0);
have_matroska = gst_registry_check_feature_version (gst_registry_get (),
"matroskamux", GST_VERSION_MAJOR, GST_VERSION_MINOR, 0);
have_qtmux = gst_registry_check_feature_version (gst_registry_get (),
"qtmux", GST_VERSION_MAJOR, GST_VERSION_MINOR, 0);
have_jpeg = gst_registry_check_feature_version (gst_registry_get (),
"jpegenc", GST_VERSION_MAJOR, GST_VERSION_MINOR, 0);
suite_add_tcase (s, tc_chain);
suite_add_tcase (s, tc_chain_basic);
suite_add_tcase (s, tc_chain_complex);
suite_add_tcase (s, tc_chain_caps_change);
tcase_add_test (tc_chain_basic, test_splitmuxsink_reuse_simple);
if (have_theora && have_ogg) {
tcase_add_checked_fixture (tc_chain, tempdir_setup, tempdir_cleanup);
tcase_add_test (tc_chain, test_splitmuxsrc);
tcase_add_test (tc_chain, test_splitmuxsrc_format_location);
tcase_add_test (tc_chain, test_splitmuxsink);
if (have_matroska && have_vorbis) {
tcase_add_checked_fixture (tc_chain_complex, tempdir_setup,
tempdir_cleanup);
tcase_add_test (tc_chain_complex, test_splitmuxsrc_sparse_streams);
} else {
GST_INFO ("Skipping tests, missing plugins: matroska and/or vorbis");
}
} else {
GST_INFO ("Skipping tests, missing plugins: theora and/or ogg");
}
if (have_qtmux && have_jpeg) {
tcase_add_checked_fixture (tc_chain_caps_change, tempdir_setup,
tempdir_cleanup);
tcase_add_test (tc_chain_caps_change, test_splitmuxsrc_caps_change);
} else {
GST_INFO ("Skipping tests, missing plugins: jpegenc or mp4mux");
}
return s;
}
GST_CHECK_MAIN (splitmux);
|