2020-04-03 07:49:25 +00:00
|
|
|
/* GStreamer unit test for splitmuxsink elements
|
2014-07-31 14:07:53 +00:00
|
|
|
*
|
|
|
|
* 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 <gst/check/gstcheck.h>
|
2017-02-23 10:11:15 +00:00
|
|
|
#include <gst/app/app.h>
|
2020-04-03 04:45:56 +00:00
|
|
|
#include <gst/video/video.h>
|
2014-07-31 14:07:53 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
gchar *tmpdir = NULL;
|
2017-03-03 13:34:44 +00:00
|
|
|
GstClockTime first_ts;
|
|
|
|
GstClockTime last_ts;
|
|
|
|
gdouble current_rate;
|
2014-07-31 14:07:53 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2015-02-06 14:41:49 +00:00
|
|
|
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);
|
|
|
|
}
|
2014-07-31 14:07:53 +00:00
|
|
|
g_dir_close (d);
|
|
|
|
|
2015-02-06 14:41:49 +00:00
|
|
|
fail_if (g_remove (tmpdir) != 0, "Failed to delete tmpdir %s", tmpdir);
|
2014-07-31 14:07:53 +00:00
|
|
|
|
|
|
|
g_free (tmpdir);
|
|
|
|
tmpdir = NULL;
|
|
|
|
}
|
|
|
|
|
2015-02-06 14:41:49 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-03-03 13:34:44 +00:00
|
|
|
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);
|
|
|
|
}
|
2015-02-06 14:41:49 +00:00
|
|
|
|
2014-07-31 14:07:53 +00:00
|
|
|
static GstMessage *
|
2024-04-29 14:33:35 +00:00
|
|
|
run_pipeline (GstElement * pipeline, guint num_fragments_expected,
|
|
|
|
const GstClockTime * fragment_offsets,
|
|
|
|
const GstClockTime * fragment_durations)
|
2014-07-31 14:07:53 +00:00
|
|
|
{
|
|
|
|
GstBus *bus = gst_element_get_bus (GST_ELEMENT (pipeline));
|
|
|
|
GstMessage *msg;
|
2024-04-29 14:33:35 +00:00
|
|
|
guint fragment_number = 0;
|
2014-07-31 14:07:53 +00:00
|
|
|
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
2024-04-29 14:33:35 +00:00
|
|
|
do {
|
|
|
|
msg =
|
|
|
|
gst_bus_poll (bus,
|
|
|
|
GST_MESSAGE_EOS | GST_MESSAGE_ERROR | GST_MESSAGE_ELEMENT, -1);
|
|
|
|
if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS
|
|
|
|
|| GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (num_fragments_expected != 0) {
|
|
|
|
// Handle element message
|
|
|
|
const GstStructure *s = gst_message_get_structure (msg);
|
|
|
|
if (gst_structure_has_name (s, "splitmuxsrc-fragment-info") ||
|
|
|
|
gst_structure_has_name (s, "splitmuxsink-fragment-closed")) {
|
|
|
|
GstClockTime fragment_offset, fragment_duration;
|
|
|
|
fail_unless (gst_structure_get_clock_time (s, "fragment-offset",
|
|
|
|
&fragment_offset));
|
|
|
|
fail_unless (gst_structure_get_clock_time (s, "fragment-duration",
|
|
|
|
&fragment_duration));
|
|
|
|
if (fragment_offsets != NULL) {
|
|
|
|
fail_unless (fragment_offsets[fragment_number] == fragment_offset,
|
|
|
|
"Expected offset %" GST_TIME_FORMAT
|
|
|
|
" for fragment %u. Got offset %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (fragment_offsets[fragment_number]),
|
|
|
|
fragment_number, GST_TIME_ARGS (fragment_offset));
|
|
|
|
}
|
|
|
|
if (fragment_durations != NULL) {
|
|
|
|
fail_unless (fragment_durations[fragment_number] == fragment_duration,
|
|
|
|
"Expected duration %" GST_TIME_FORMAT
|
|
|
|
" for fragment %u. Got duration %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (fragment_durations[fragment_number]),
|
|
|
|
fragment_number, GST_TIME_ARGS (fragment_duration));
|
|
|
|
}
|
|
|
|
fragment_number++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gst_message_unref (msg);
|
|
|
|
} while (TRUE);
|
|
|
|
|
2014-07-31 14:07:53 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
|
|
|
|
|
|
|
gst_object_unref (bus);
|
|
|
|
|
2017-03-03 13:34:44 +00:00
|
|
|
if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR)
|
|
|
|
dump_error (msg);
|
2024-04-29 14:33:35 +00:00
|
|
|
else if (num_fragments_expected != 0) {
|
|
|
|
// Success. Check we got the expected number of fragment messages
|
|
|
|
fail_unless (fragment_number == num_fragments_expected);
|
|
|
|
}
|
2017-03-03 13:34:44 +00:00
|
|
|
|
2014-07-31 14:07:53 +00:00
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
2015-02-06 14:41:49 +00:00
|
|
|
static void
|
2017-03-03 13:34:44 +00:00
|
|
|
seek_pipeline (GstElement * pipeline, gdouble rate, GstClockTime start,
|
|
|
|
GstClockTime end)
|
2015-02-06 14:41:49 +00:00
|
|
|
{
|
2017-03-03 13:34:44 +00:00
|
|
|
/* 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);
|
2015-02-06 14:41:49 +00:00
|
|
|
|
2017-03-03 13:34:44 +00:00
|
|
|
/* specific end time not implemented: */
|
|
|
|
fail_unless (end == GST_CLOCK_TIME_NONE);
|
2015-02-06 14:41:49 +00:00
|
|
|
|
2017-03-03 13:34:44 +00:00
|
|
|
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);
|
2015-02-16 02:45:24 +00:00
|
|
|
|
2017-03-03 13:34:44 +00:00
|
|
|
/* 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;
|
|
|
|
};
|
|
|
|
|
2020-02-20 15:14:11 +00:00
|
|
|
static GstFlowReturn
|
2020-04-20 10:43:57 +00:00
|
|
|
receive_sample (GstAppSink * appsink, gpointer user_data)
|
2017-03-03 13:34:44 +00:00
|
|
|
{
|
2020-02-20 15:14:11 +00:00
|
|
|
GstSample *sample;
|
|
|
|
GstSegment *seg;
|
|
|
|
GstBuffer *buf;
|
|
|
|
GstClockTime start;
|
|
|
|
GstClockTime end;
|
|
|
|
|
|
|
|
g_signal_emit_by_name (appsink, "pull-sample", &sample);
|
|
|
|
fail_unless (sample != NULL);
|
|
|
|
|
|
|
|
seg = gst_sample_get_segment (sample);
|
|
|
|
fail_unless (seg != NULL);
|
|
|
|
|
|
|
|
buf = gst_sample_get_buffer (sample);
|
|
|
|
fail_unless (buf != NULL);
|
|
|
|
|
|
|
|
GST_LOG ("Got buffer %" GST_PTR_FORMAT, buf);
|
|
|
|
|
|
|
|
start = GST_BUFFER_PTS (buf);
|
|
|
|
end = start;
|
2017-03-03 13:34:44 +00:00
|
|
|
|
2020-02-20 15:14:11 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (start))
|
|
|
|
start = gst_segment_to_stream_time (seg, GST_FORMAT_TIME, start);
|
2017-03-03 13:34:44 +00:00
|
|
|
|
2020-02-20 15:14:11 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (end)) {
|
|
|
|
if (GST_BUFFER_DURATION_IS_VALID (buf))
|
|
|
|
end += GST_BUFFER_DURATION (buf);
|
|
|
|
|
|
|
|
end = gst_segment_to_stream_time (seg, GST_FORMAT_TIME, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG ("Got buffer stream time %" GST_TIME_FORMAT " to %" GST_TIME_FORMAT,
|
2017-03-03 13:34:44 +00:00
|
|
|
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;
|
2020-02-20 15:14:11 +00:00
|
|
|
|
|
|
|
gst_sample_unref (sample);
|
|
|
|
|
2020-04-20 10:43:57 +00:00
|
|
|
if (user_data) {
|
|
|
|
guint *num_frame = (guint *) user_data;
|
|
|
|
|
|
|
|
*num_frame = *num_frame + 1;
|
|
|
|
}
|
|
|
|
|
2020-02-20 15:14:11 +00:00
|
|
|
return GST_FLOW_OK;
|
2015-02-06 14:41:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-03-14 04:48:08 +00:00
|
|
|
test_playback (const gchar * in_pattern, GstClockTime exp_first_time,
|
2024-04-29 14:33:35 +00:00
|
|
|
GstClockTime exp_last_time, gboolean test_reverse,
|
|
|
|
guint num_fragments_expected, const GstClockTime * fragment_offsets,
|
|
|
|
const GstClockTime * fragment_durations)
|
2014-07-31 14:07:53 +00:00
|
|
|
{
|
|
|
|
GstMessage *msg;
|
|
|
|
GstElement *pipeline;
|
2020-02-20 15:14:11 +00:00
|
|
|
GstElement *appsink;
|
2017-06-13 14:42:55 +00:00
|
|
|
GstElement *fakesink2;
|
2020-02-20 15:14:11 +00:00
|
|
|
GstAppSinkCallbacks callbacks = { NULL };
|
2014-07-31 14:07:53 +00:00
|
|
|
gchar *uri;
|
|
|
|
|
2020-02-20 15:14:11 +00:00
|
|
|
GST_DEBUG ("Playing back files matching %s", in_pattern);
|
|
|
|
|
2014-07-31 14:07:53 +00:00
|
|
|
pipeline = gst_element_factory_make ("playbin", NULL);
|
|
|
|
fail_if (pipeline == NULL);
|
|
|
|
|
2020-02-20 15:14:11 +00:00
|
|
|
appsink = gst_element_factory_make ("appsink", NULL);
|
|
|
|
fail_if (appsink == NULL);
|
2020-03-23 13:18:54 +00:00
|
|
|
g_object_set (G_OBJECT (appsink), "sync", FALSE, NULL);
|
|
|
|
|
2020-02-20 15:14:11 +00:00
|
|
|
g_object_set (G_OBJECT (pipeline), "video-sink", appsink, NULL);
|
2017-06-13 14:42:55 +00:00
|
|
|
fakesink2 = gst_element_factory_make ("fakesink", NULL);
|
|
|
|
fail_if (fakesink2 == NULL);
|
|
|
|
g_object_set (G_OBJECT (pipeline), "audio-sink", fakesink2, NULL);
|
2014-07-31 14:07:53 +00:00
|
|
|
|
|
|
|
uri = g_strdup_printf ("splitmux://%s", in_pattern);
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (pipeline), "uri", uri, NULL);
|
|
|
|
g_free (uri);
|
|
|
|
|
2020-02-20 15:14:11 +00:00
|
|
|
callbacks.new_sample = receive_sample;
|
|
|
|
gst_app_sink_set_callbacks (GST_APP_SINK (appsink), &callbacks, NULL, NULL);
|
2017-03-03 13:34:44 +00:00
|
|
|
|
|
|
|
/* test forwards */
|
|
|
|
seek_pipeline (pipeline, 1.0, 0, -1);
|
|
|
|
fail_unless (first_ts == GST_CLOCK_TIME_NONE);
|
2024-04-29 14:33:35 +00:00
|
|
|
msg =
|
|
|
|
run_pipeline (pipeline, num_fragments_expected, fragment_offsets,
|
|
|
|
fragment_durations);
|
2017-03-03 13:34:44 +00:00
|
|
|
fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
|
|
|
|
gst_message_unref (msg);
|
2014-07-31 14:07:53 +00:00
|
|
|
|
2017-03-03 13:34:44 +00:00
|
|
|
/* Check we saw the entire range of values */
|
2017-11-24 05:56:03 +00:00
|
|
|
fail_unless (first_ts == exp_first_time,
|
2020-02-20 15:14:11 +00:00
|
|
|
"Expected start of playback range %" GST_TIME_FORMAT ", got %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (exp_first_time),
|
2017-03-03 13:34:44 +00:00
|
|
|
GST_TIME_ARGS (first_ts));
|
2017-11-24 05:56:03 +00:00
|
|
|
fail_unless (last_ts == exp_last_time,
|
2020-02-20 15:14:11 +00:00
|
|
|
"Expected end of playback range %" GST_TIME_FORMAT ", got %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (exp_last_time), GST_TIME_ARGS (last_ts));
|
2017-03-03 13:34:44 +00:00
|
|
|
|
2019-05-25 12:08:05 +00:00
|
|
|
if (test_reverse) {
|
|
|
|
/* Test backwards */
|
|
|
|
seek_pipeline (pipeline, -1.0, 0, -1);
|
2024-04-29 14:33:35 +00:00
|
|
|
msg =
|
|
|
|
run_pipeline (pipeline, num_fragments_expected, fragment_offsets,
|
|
|
|
fragment_durations);
|
2019-05-25 12:08:05 +00:00
|
|
|
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));
|
|
|
|
}
|
2017-03-03 13:34:44 +00:00
|
|
|
|
2015-02-06 13:19:36 +00:00
|
|
|
gst_object_unref (pipeline);
|
2014-07-31 14:07:53 +00:00
|
|
|
}
|
|
|
|
|
2020-12-11 16:28:56 +00:00
|
|
|
struct splitmux_location_state
|
|
|
|
{
|
|
|
|
GstElement *splitmuxsink;
|
|
|
|
gboolean got_format_location;
|
|
|
|
gboolean fragment_opened;
|
|
|
|
gchar *current_location;
|
|
|
|
};
|
|
|
|
|
2016-11-17 12:40:27 +00:00
|
|
|
static gchar *
|
|
|
|
check_format_location (GstElement * object,
|
2020-12-11 16:28:56 +00:00
|
|
|
guint fragment_id, GstSample * first_sample,
|
|
|
|
struct splitmux_location_state *location_state)
|
2016-11-17 12:40:27 +00:00
|
|
|
{
|
|
|
|
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)));
|
|
|
|
|
2020-12-11 16:28:56 +00:00
|
|
|
if (location_state) {
|
|
|
|
fail_unless (location_state->got_format_location == FALSE,
|
|
|
|
"Got format-location signal twice without an intervening splitmuxsink-fragment-closed");
|
|
|
|
location_state->got_format_location = TRUE;
|
|
|
|
}
|
|
|
|
|
2016-11-17 12:40:27 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-12-11 16:28:56 +00:00
|
|
|
static GstBusSyncReply
|
|
|
|
bus_sync_handler (GstBus * bus, GstMessage * message,
|
|
|
|
struct splitmux_location_state *location_state)
|
|
|
|
{
|
|
|
|
switch (message->type) {
|
|
|
|
case GST_MESSAGE_ELEMENT:
|
|
|
|
{
|
|
|
|
const GstStructure *s = gst_message_get_structure (message);
|
|
|
|
if (message->src == GST_OBJECT_CAST (location_state->splitmuxsink)) {
|
|
|
|
if (gst_structure_has_name (s, "splitmuxsink-fragment-opened")) {
|
|
|
|
const gchar *location = gst_structure_get_string (s, "location");
|
|
|
|
fail_unless (location != NULL);
|
|
|
|
fail_unless (location_state->got_format_location == TRUE,
|
|
|
|
"Failed to get format-location before fragment start");
|
|
|
|
fail_unless (location_state->fragment_opened == FALSE);
|
|
|
|
location_state->fragment_opened = TRUE;
|
|
|
|
|
|
|
|
/* The location must be different to last time */
|
|
|
|
fail_unless (location_state->current_location == NULL
|
|
|
|
|| !g_str_equal (location_state->current_location, location));
|
|
|
|
g_free (location_state->current_location);
|
|
|
|
location_state->current_location = g_strdup (location);
|
|
|
|
|
|
|
|
} else if (gst_structure_has_name (s, "splitmuxsink-fragment-closed")) {
|
|
|
|
fail_unless (location_state->got_format_location == TRUE);
|
|
|
|
fail_unless (location_state->fragment_opened == TRUE);
|
|
|
|
location_state->got_format_location = FALSE; /* We need another format-location before the next open */
|
|
|
|
location_state->fragment_opened = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_BUS_PASS;
|
|
|
|
}
|
|
|
|
|
2015-02-06 14:41:49 +00:00
|
|
|
GST_START_TEST (test_splitmuxsink)
|
|
|
|
{
|
|
|
|
GstMessage *msg;
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *sink;
|
2015-10-24 21:57:38 +00:00
|
|
|
GstPad *splitmux_sink_pad;
|
|
|
|
GstPad *enc_src_pad;
|
2015-02-06 14:41:49 +00:00
|
|
|
gchar *dest_pattern;
|
|
|
|
guint count;
|
|
|
|
gchar *in_pattern;
|
2020-12-11 16:28:56 +00:00
|
|
|
struct splitmux_location_state location_state = { NULL, FALSE, FALSE, NULL };
|
|
|
|
GstBus *bus;
|
2015-02-06 14:41:49 +00:00
|
|
|
|
|
|
|
/* 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);
|
2020-12-11 16:28:56 +00:00
|
|
|
location_state.splitmuxsink = sink =
|
|
|
|
gst_bin_get_by_name (GST_BIN (pipeline), "splitsink");
|
2015-02-06 14:41:49 +00:00
|
|
|
fail_if (sink == NULL);
|
2016-11-17 12:40:27 +00:00
|
|
|
g_signal_connect (sink, "format-location-full",
|
2020-12-11 16:28:56 +00:00
|
|
|
(GCallback) check_format_location, &location_state);
|
|
|
|
|
2015-02-06 14:41:49 +00:00
|
|
|
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);
|
|
|
|
|
2020-12-11 16:28:56 +00:00
|
|
|
bus = gst_element_get_bus (pipeline);
|
|
|
|
gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler,
|
|
|
|
&location_state, NULL);
|
|
|
|
gst_object_unref (bus);
|
|
|
|
|
2024-04-29 14:33:35 +00:00
|
|
|
GstClockTime offsets[] = { 0, GST_SECOND, 2 * GST_SECOND };
|
|
|
|
GstClockTime durations[] = { GST_SECOND, GST_SECOND, GST_SECOND };
|
|
|
|
msg = run_pipeline (pipeline, 3, offsets, durations);
|
2015-02-06 14:41:49 +00:00
|
|
|
|
2020-12-11 16:28:56 +00:00
|
|
|
/* Clean up the location state */
|
|
|
|
g_free (location_state.current_location);
|
|
|
|
|
2015-02-06 14:41:49 +00:00
|
|
|
if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR)
|
|
|
|
dump_error (msg);
|
|
|
|
fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
|
|
|
|
gst_message_unref (msg);
|
2015-10-24 21:57:38 +00:00
|
|
|
|
2019-09-02 12:27:35 +00:00
|
|
|
/* unlink manually and release request pad to ensure that we *can* do that
|
2015-10-24 21:57:38 +00:00
|
|
|
* - 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);
|
2019-09-02 12:27:35 +00:00
|
|
|
/* at this point the pad must be released - try to find it again to verify */
|
2015-10-24 21:57:38 +00:00
|
|
|
splitmux_sink_pad = gst_element_get_static_pad (sink, "video");
|
|
|
|
fail_if (splitmux_sink_pad != NULL);
|
|
|
|
g_object_unref (sink);
|
|
|
|
|
2015-02-06 14:41:49 +00:00
|
|
|
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);
|
2024-04-29 14:33:35 +00:00
|
|
|
test_playback (in_pattern, 0, 3 * GST_SECOND, TRUE, 3, offsets, durations);
|
2019-05-25 12:08:05 +00:00
|
|
|
g_free (in_pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2021-07-07 14:12:52 +00:00
|
|
|
GST_START_TEST (test_splitmuxsink_clean_failure)
|
|
|
|
{
|
|
|
|
GstMessage *msg;
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *sink, *fakesink;
|
|
|
|
|
|
|
|
/* This pipeline has a small time cutoff - it should start a new file
|
|
|
|
* every GOP, ie 1 second */
|
|
|
|
pipeline =
|
|
|
|
gst_parse_launch
|
|
|
|
("videotestsrc horizontal-speed=2 is-live=true ! 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);
|
|
|
|
|
|
|
|
fakesink = gst_element_factory_make ("fakesink", "fakesink-fail");
|
|
|
|
fail_if (fakesink == NULL);
|
|
|
|
|
|
|
|
/* Trigger an error on READY->PAUSED */
|
|
|
|
g_object_set (fakesink, "state-error", 2, NULL);
|
|
|
|
g_object_set (sink, "sink", fakesink, NULL);
|
|
|
|
gst_object_unref (sink);
|
|
|
|
|
2024-04-29 14:33:35 +00:00
|
|
|
msg = run_pipeline (pipeline, 0, NULL, NULL);
|
2021-07-07 14:12:52 +00:00
|
|
|
|
|
|
|
fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
|
|
|
|
gst_message_unref (msg);
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (pipeline,
|
|
|
|
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
gst_object_unref (pipeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2019-05-25 12:08:05 +00:00
|
|
|
GST_START_TEST (test_splitmuxsink_multivid)
|
|
|
|
{
|
|
|
|
GstMessage *msg;
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *sink;
|
|
|
|
gchar *dest_pattern;
|
|
|
|
guint count;
|
|
|
|
gchar *in_pattern;
|
|
|
|
|
|
|
|
/* This pipeline should start a new file every GOP, ie 1 second,
|
2019-09-02 12:27:35 +00:00
|
|
|
* driven by the primary video stream and with 2 auxiliary video streams */
|
2019-05-25 12:08:05 +00:00
|
|
|
pipeline =
|
|
|
|
gst_parse_launch
|
|
|
|
("splitmuxsink name=splitsink "
|
|
|
|
" max-size-time=1000000 max-size-bytes=1000000 muxer=qtmux "
|
|
|
|
"videotestsrc num-buffers=15 ! video/x-raw,width=80,height=64,framerate=5/1 ! videoconvert !"
|
|
|
|
" queue ! vp8enc keyframe-max-dist=5 ! splitsink.video "
|
|
|
|
"videotestsrc num-buffers=15 pattern=snow ! video/x-raw,width=80,height=64,framerate=5/1 ! videoconvert !"
|
|
|
|
" queue ! vp8enc keyframe-max-dist=6 ! splitsink.video_aux_0 "
|
|
|
|
"videotestsrc num-buffers=15 pattern=ball ! video/x-raw,width=80,height=64,framerate=5/1 ! videoconvert !"
|
|
|
|
" queue ! vp8enc keyframe-max-dist=8 ! splitsink.video_aux_1 ", 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.m4v", NULL);
|
|
|
|
g_object_set (G_OBJECT (sink), "location", dest_pattern, NULL);
|
|
|
|
g_free (dest_pattern);
|
|
|
|
g_object_unref (sink);
|
|
|
|
|
2024-04-29 14:33:35 +00:00
|
|
|
GstClockTime offsets[] = { 0, GST_SECOND, 2 * GST_SECOND };
|
|
|
|
GstClockTime durations[] = { GST_SECOND, GST_SECOND, GST_SECOND };
|
|
|
|
msg = run_pipeline (pipeline, 3, offsets, durations);
|
2019-05-25 12:08:05 +00:00
|
|
|
|
|
|
|
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 == 3, "Expected 3 output files, got %d", count);
|
|
|
|
|
|
|
|
in_pattern = g_build_filename (tmpdir, "out*.m4v", NULL);
|
|
|
|
/* FIXME: Reverse playback works poorly with multiple video streams
|
|
|
|
* in qtdemux (at least, maybe other demuxers) at the time this was
|
|
|
|
* written, and causes test failures like buffers being output
|
|
|
|
* multiple times by qtdemux as it loops through GOPs. Disable that
|
|
|
|
* for now */
|
2024-04-29 14:33:35 +00:00
|
|
|
test_playback (in_pattern, 0, 3 * GST_SECOND, FALSE, 3, offsets, durations);
|
2015-02-06 14:41:49 +00:00
|
|
|
g_free (in_pattern);
|
|
|
|
}
|
|
|
|
|
2014-07-31 14:07:53 +00:00
|
|
|
GST_END_TEST;
|
|
|
|
|
2017-06-13 14:42:55 +00:00
|
|
|
GST_START_TEST (test_splitmuxsink_async)
|
|
|
|
{
|
|
|
|
GstMessage *msg;
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *sink;
|
|
|
|
GstPad *splitmux_sink_pad;
|
|
|
|
GstPad *enc_src_pad;
|
|
|
|
gchar *dest_pattern;
|
|
|
|
guint count;
|
|
|
|
gchar *in_pattern;
|
|
|
|
|
|
|
|
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=1000000000 async-finalize=true "
|
|
|
|
" muxer-factory=matroskamux audiotestsrc num-buffers=15 samplesperbuffer=9600 ! "
|
|
|
|
" audio/x-raw,rate=48000 ! splitsink.audio_%u", 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, "matroska%05d.mkv", NULL);
|
|
|
|
g_object_set (G_OBJECT (sink), "location", dest_pattern, NULL);
|
|
|
|
g_free (dest_pattern);
|
|
|
|
g_object_unref (sink);
|
|
|
|
|
2024-04-29 14:33:35 +00:00
|
|
|
GstClockTime offsets[] = { 0, GST_SECOND, 2 * GST_SECOND };
|
|
|
|
GstClockTime durations[] = { GST_SECOND, GST_SECOND, GST_SECOND };
|
|
|
|
msg = run_pipeline (pipeline, 3, offsets, durations);
|
2017-06-13 14:42:55 +00:00
|
|
|
|
|
|
|
if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR)
|
|
|
|
dump_error (msg);
|
|
|
|
fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS);
|
|
|
|
gst_message_unref (msg);
|
|
|
|
|
2019-09-02 12:27:35 +00:00
|
|
|
/* unlink manually and release request pad to ensure that we *can* do that
|
2017-06-13 14:42:55 +00:00
|
|
|
* - 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);
|
2019-09-02 12:27:35 +00:00
|
|
|
/* at this point the pad must be released - try to find it again to verify */
|
2017-06-13 14:42:55 +00:00
|
|
|
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, "matroska*.mkv", NULL);
|
2024-04-29 14:33:35 +00:00
|
|
|
test_playback (in_pattern, 0, 3 * GST_SECOND, TRUE, 3, offsets, durations);
|
2017-06-13 14:42:55 +00:00
|
|
|
g_free (in_pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2016-03-01 02:40:03 +00:00
|
|
|
/* 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);
|
2021-04-20 20:08:23 +00:00
|
|
|
pad = gst_element_request_pad_simple (sink, "video");
|
2016-03-01 02:40:03 +00:00
|
|
|
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;
|
|
|
|
|
2019-07-31 06:17:36 +00:00
|
|
|
GST_START_TEST (test_splitmuxsink_muxer_pad_map)
|
|
|
|
{
|
|
|
|
GstElement *sink, *muxer;
|
|
|
|
GstPad *muxpad;
|
|
|
|
GstPad *pad1 = NULL, *pad2 = NULL;
|
|
|
|
GstStructure *pad_map;
|
|
|
|
|
|
|
|
pad_map = gst_structure_new ("x-pad-map",
|
|
|
|
"video", G_TYPE_STRING, "video_100",
|
|
|
|
"audio_0", G_TYPE_STRING, "audio_101", NULL);
|
|
|
|
|
|
|
|
muxer = gst_element_factory_make ("qtmux", NULL);
|
|
|
|
fail_if (muxer == NULL);
|
|
|
|
sink = gst_element_factory_make ("splitmuxsink", NULL);
|
|
|
|
fail_if (sink == NULL);
|
|
|
|
|
|
|
|
g_object_set (sink, "muxer", muxer, "muxer-pad-map", pad_map, NULL);
|
|
|
|
gst_structure_free (pad_map);
|
|
|
|
|
2021-04-20 20:08:23 +00:00
|
|
|
pad1 = gst_element_request_pad_simple (sink, "video");
|
2019-07-31 06:17:36 +00:00
|
|
|
fail_unless (g_str_equal ("video", GST_PAD_NAME (pad1)));
|
|
|
|
muxpad = gst_element_get_static_pad (muxer, "video_100");
|
|
|
|
fail_unless (muxpad != NULL);
|
|
|
|
gst_object_unref (muxpad);
|
|
|
|
|
2021-04-20 20:08:23 +00:00
|
|
|
pad2 = gst_element_request_pad_simple (sink, "audio_0");
|
2019-07-31 06:17:36 +00:00
|
|
|
fail_unless (g_str_equal ("audio_0", GST_PAD_NAME (pad2)));
|
|
|
|
muxpad = gst_element_get_static_pad (muxer, "audio_101");
|
|
|
|
fail_unless (muxpad != NULL);
|
|
|
|
gst_object_unref (muxpad);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
gst_element_release_request_pad (sink, pad1);
|
|
|
|
gst_object_unref (pad1);
|
|
|
|
gst_element_release_request_pad (sink, pad2);
|
|
|
|
gst_object_unref (pad2);
|
|
|
|
gst_object_unref (sink);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2022-04-13 16:19:51 +00:00
|
|
|
static void
|
|
|
|
run_eos_pipeline (guint num_video_buf, guint num_audio_buf,
|
|
|
|
gboolean configure_audio)
|
|
|
|
{
|
|
|
|
GstMessage *msg;
|
|
|
|
GstElement *pipeline;
|
|
|
|
gchar *dest_pattern;
|
|
|
|
gchar *pipeline_str;
|
|
|
|
gchar *audio_branch = NULL;
|
|
|
|
|
|
|
|
dest_pattern = g_build_filename (tmpdir, "out%05d.mp4", NULL);
|
|
|
|
|
|
|
|
if (configure_audio) {
|
|
|
|
audio_branch = g_strdup_printf ("audiotestsrc num-buffers=%d ! "
|
|
|
|
"splitsink.audio_0", num_audio_buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
pipeline_str = g_strdup_printf ("splitmuxsink name=splitsink location=%s "
|
|
|
|
"muxer-factory=qtmux videotestsrc num-buffers=%d ! jpegenc ! splitsink. "
|
|
|
|
"%s", dest_pattern, num_video_buf, audio_branch ? audio_branch : "");
|
|
|
|
pipeline = gst_parse_launch (pipeline_str, NULL);
|
|
|
|
g_free (dest_pattern);
|
|
|
|
g_free (audio_branch);
|
|
|
|
g_free (pipeline_str);
|
|
|
|
|
|
|
|
fail_if (pipeline == NULL);
|
|
|
|
|
2024-04-29 14:33:35 +00:00
|
|
|
msg = run_pipeline (pipeline, 0, NULL, NULL);
|
2022-04-13 16:19:51 +00:00
|
|
|
|
|
|
|
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_START_TEST (test_splitmuxsink_eos_without_buffer)
|
|
|
|
{
|
|
|
|
/* below pipelines will create non-playable files but at least we should not
|
|
|
|
* crash */
|
|
|
|
run_eos_pipeline (0, 0, FALSE);
|
|
|
|
run_eos_pipeline (0, 0, TRUE);
|
|
|
|
run_eos_pipeline (1, 0, TRUE);
|
|
|
|
run_eos_pipeline (0, 1, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2020-04-03 04:45:56 +00:00
|
|
|
static GstPadProbeReturn
|
|
|
|
count_upstrea_fku (GstPad * pad, GstPadProbeInfo * info,
|
|
|
|
guint * upstream_fku_count)
|
|
|
|
{
|
|
|
|
GstEvent *event = GST_PAD_PROBE_INFO_EVENT (info);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_CUSTOM_UPSTREAM:
|
|
|
|
if (gst_video_event_is_force_key_unit (event))
|
|
|
|
*upstream_fku_count += 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GST_PAD_PROBE_OK;
|
|
|
|
}
|
|
|
|
|
2020-03-12 11:34:47 +00:00
|
|
|
static void
|
|
|
|
splitmuxsink_split_by_keyframe (gboolean send_keyframe_request,
|
|
|
|
guint max_size_time_sec, guint encoder_key_interval_sec)
|
|
|
|
{
|
|
|
|
GstMessage *msg;
|
|
|
|
GstElement *pipeline;
|
|
|
|
GstElement *sink;
|
2020-04-03 04:45:56 +00:00
|
|
|
GstElement *enc;
|
|
|
|
GstPad *srcpad;
|
2020-03-12 11:34:47 +00:00
|
|
|
gchar *pipeline_str;
|
|
|
|
gchar *dest_pattern;
|
|
|
|
guint count;
|
|
|
|
guint expected_count;
|
|
|
|
gchar *in_pattern;
|
2020-04-03 04:45:56 +00:00
|
|
|
guint upstream_fku_count = 0;
|
|
|
|
guint expected_fku_count;
|
2020-03-12 11:34:47 +00:00
|
|
|
|
|
|
|
pipeline_str = g_strdup_printf ("splitmuxsink name=splitsink "
|
|
|
|
"max-size-time=%" G_GUINT64_FORMAT
|
|
|
|
" send-keyframe-requests=%s muxer=qtmux "
|
|
|
|
"videotestsrc num-buffers=30 ! video/x-raw,width=80,height=64,framerate=5/1 "
|
2020-04-03 04:45:56 +00:00
|
|
|
"! videoconvert ! queue ! vp8enc name=enc keyframe-max-dist=%d ! splitsink.video ",
|
2020-03-12 11:34:47 +00:00
|
|
|
max_size_time_sec * GST_SECOND, send_keyframe_request ? "true" : "false",
|
|
|
|
encoder_key_interval_sec * 5);
|
|
|
|
|
|
|
|
pipeline = gst_parse_launch (pipeline_str, NULL);
|
|
|
|
g_free (pipeline_str);
|
|
|
|
|
|
|
|
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.m4v", NULL);
|
|
|
|
g_object_set (G_OBJECT (sink), "location", dest_pattern, NULL);
|
|
|
|
g_free (dest_pattern);
|
|
|
|
g_object_unref (sink);
|
|
|
|
|
2020-04-03 04:45:56 +00:00
|
|
|
enc = gst_bin_get_by_name (GST_BIN (pipeline), "enc");
|
|
|
|
fail_if (enc == NULL);
|
|
|
|
srcpad = gst_element_get_static_pad (enc, "src");
|
|
|
|
fail_if (srcpad == NULL);
|
|
|
|
|
|
|
|
gst_pad_add_probe (srcpad, GST_PAD_PROBE_TYPE_EVENT_UPSTREAM,
|
|
|
|
(GstPadProbeCallback) count_upstrea_fku, &upstream_fku_count, NULL);
|
|
|
|
gst_object_unref (srcpad);
|
|
|
|
gst_object_unref (enc);
|
|
|
|
|
2024-04-29 14:33:35 +00:00
|
|
|
msg = run_pipeline (pipeline, 0, 0, NULL);
|
2020-03-12 11:34:47 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
expected_count = 6 / max_size_time_sec;
|
|
|
|
fail_unless (count == expected_count,
|
|
|
|
"Expected %d output files, got %d", expected_count, count);
|
|
|
|
|
2020-04-03 04:45:56 +00:00
|
|
|
if (!send_keyframe_request) {
|
|
|
|
expected_fku_count = 0;
|
|
|
|
} else {
|
|
|
|
expected_fku_count = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_INFO ("Upstream force keyunit event count %d", upstream_fku_count);
|
|
|
|
|
|
|
|
fail_unless (upstream_fku_count == expected_fku_count,
|
|
|
|
"Expected upstream force keyunit event count %d, got %d",
|
|
|
|
expected_fku_count, upstream_fku_count);
|
|
|
|
|
2020-03-12 11:34:47 +00:00
|
|
|
in_pattern = g_build_filename (tmpdir, "out*.m4v", NULL);
|
|
|
|
/* FIXME: Reverse playback works poorly with multiple video streams
|
|
|
|
* in qtdemux (at least, maybe other demuxers) at the time this was
|
|
|
|
* written, and causes test failures like buffers being output
|
|
|
|
* multiple times by qtdemux as it loops through GOPs. Disable that
|
|
|
|
* for now */
|
2024-04-29 14:33:35 +00:00
|
|
|
test_playback (in_pattern, 0, 6 * GST_SECOND, FALSE, 0, NULL, NULL);
|
2020-03-12 11:34:47 +00:00
|
|
|
g_free (in_pattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_splitmuxsink_without_keyframe_request)
|
|
|
|
{
|
|
|
|
/* This encoding option is intended to produce keyframe per 1 seconds
|
|
|
|
* but splitmuxsink will split file per 2 second without keyframe request */
|
|
|
|
splitmuxsink_split_by_keyframe (FALSE, 2, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_splitmuxsink_keyframe_request)
|
|
|
|
{
|
|
|
|
/* This encoding option is intended to produce keyframe per 2 seconds
|
|
|
|
* and splitmuxsink will request keyframe per 2 seconds as well.
|
|
|
|
* This should produce 2 seconds long files */
|
|
|
|
splitmuxsink_split_by_keyframe (TRUE, 2, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_splitmuxsink_keyframe_request_more)
|
|
|
|
{
|
|
|
|
/* This encoding option is intended to produce keyframe per 2 seconds
|
|
|
|
* but splitmuxsink will request keyframe per 1 second. This should produce
|
|
|
|
* 1 second long files */
|
|
|
|
splitmuxsink_split_by_keyframe (TRUE, 1, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
|
|
|
GST_START_TEST (test_splitmuxsink_keyframe_request_less)
|
|
|
|
{
|
|
|
|
/* This encoding option is intended to produce keyframe per 1 second
|
|
|
|
* but splitmuxsink will request keyframe per 2 seconds. This should produce
|
|
|
|
* 2 seconds long files */
|
|
|
|
splitmuxsink_split_by_keyframe (TRUE, 2, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
2019-07-31 06:17:36 +00:00
|
|
|
|
2014-07-31 14:07:53 +00:00
|
|
|
static Suite *
|
2020-04-03 07:49:25 +00:00
|
|
|
splitmuxsink_suite (void)
|
2014-07-31 14:07:53 +00:00
|
|
|
{
|
2020-04-03 07:49:25 +00:00
|
|
|
Suite *s = suite_create ("splitmuxsink");
|
2014-07-31 14:07:53 +00:00
|
|
|
TCase *tc_chain = tcase_create ("general");
|
2016-03-01 02:40:03 +00:00
|
|
|
TCase *tc_chain_basic = tcase_create ("basic");
|
2017-02-23 10:11:15 +00:00
|
|
|
TCase *tc_chain_complex = tcase_create ("complex");
|
2015-04-07 13:53:19 +00:00
|
|
|
TCase *tc_chain_mp4_jpeg = tcase_create ("caps_change");
|
2020-04-20 10:43:57 +00:00
|
|
|
TCase *tc_chain_keyframe_request = tcase_create ("keyframe_request");
|
2017-11-24 05:56:03 +00:00
|
|
|
gboolean have_theora, have_ogg, have_vorbis, have_matroska, have_qtmux,
|
2020-04-20 10:43:57 +00:00
|
|
|
have_jpeg, have_vp8;
|
2016-06-21 16:51:38 +00:00
|
|
|
|
|
|
|
/* 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);
|
2017-02-23 10:11:15 +00:00
|
|
|
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);
|
2017-11-24 05:56:03 +00:00
|
|
|
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);
|
2019-05-25 12:08:05 +00:00
|
|
|
have_vp8 = gst_registry_check_feature_version (gst_registry_get (),
|
|
|
|
"vp8enc", GST_VERSION_MAJOR, GST_VERSION_MINOR, 0);
|
2014-07-31 14:07:53 +00:00
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
2016-03-01 02:40:03 +00:00
|
|
|
suite_add_tcase (s, tc_chain_basic);
|
2017-02-23 10:11:15 +00:00
|
|
|
suite_add_tcase (s, tc_chain_complex);
|
2015-04-07 13:53:19 +00:00
|
|
|
suite_add_tcase (s, tc_chain_mp4_jpeg);
|
2020-04-20 10:43:57 +00:00
|
|
|
suite_add_tcase (s, tc_chain_keyframe_request);
|
2014-07-31 14:07:53 +00:00
|
|
|
|
2016-03-01 02:40:03 +00:00
|
|
|
tcase_add_test (tc_chain_basic, test_splitmuxsink_reuse_simple);
|
2014-07-31 14:07:53 +00:00
|
|
|
|
2016-06-21 16:51:38 +00:00
|
|
|
if (have_theora && have_ogg) {
|
|
|
|
tcase_add_checked_fixture (tc_chain, tempdir_setup, tempdir_cleanup);
|
|
|
|
|
|
|
|
tcase_add_test (tc_chain, test_splitmuxsink);
|
2021-07-07 14:12:52 +00:00
|
|
|
tcase_add_test (tc_chain, test_splitmuxsink_clean_failure);
|
2017-02-23 10:11:15 +00:00
|
|
|
|
|
|
|
if (have_matroska && have_vorbis) {
|
|
|
|
tcase_add_checked_fixture (tc_chain_complex, tempdir_setup,
|
|
|
|
tempdir_cleanup);
|
|
|
|
|
2017-06-13 14:42:55 +00:00
|
|
|
tcase_add_test (tc_chain, test_splitmuxsink_async);
|
2017-02-23 10:11:15 +00:00
|
|
|
} else {
|
|
|
|
GST_INFO ("Skipping tests, missing plugins: matroska and/or vorbis");
|
|
|
|
}
|
2016-06-21 16:51:38 +00:00
|
|
|
} else {
|
|
|
|
GST_INFO ("Skipping tests, missing plugins: theora and/or ogg");
|
|
|
|
}
|
2014-07-31 14:07:53 +00:00
|
|
|
|
2017-11-24 05:56:03 +00:00
|
|
|
|
|
|
|
if (have_qtmux && have_jpeg) {
|
2015-04-07 13:53:19 +00:00
|
|
|
tcase_add_checked_fixture (tc_chain_mp4_jpeg, tempdir_setup,
|
2017-11-24 05:56:03 +00:00
|
|
|
tempdir_cleanup);
|
2019-07-31 06:17:36 +00:00
|
|
|
tcase_add_test (tc_chain_mp4_jpeg, test_splitmuxsink_muxer_pad_map);
|
2022-04-13 16:19:51 +00:00
|
|
|
tcase_add_test (tc_chain_mp4_jpeg, test_splitmuxsink_eos_without_buffer);
|
2017-11-24 05:56:03 +00:00
|
|
|
} else {
|
|
|
|
GST_INFO ("Skipping tests, missing plugins: jpegenc or mp4mux");
|
|
|
|
}
|
2019-05-25 12:08:05 +00:00
|
|
|
|
|
|
|
if (have_qtmux && have_vp8) {
|
2020-04-20 10:43:57 +00:00
|
|
|
tcase_add_checked_fixture (tc_chain_keyframe_request, tempdir_setup,
|
|
|
|
tempdir_cleanup);
|
|
|
|
tcase_add_test (tc_chain_keyframe_request, test_splitmuxsink_multivid);
|
|
|
|
tcase_add_test (tc_chain_keyframe_request,
|
|
|
|
test_splitmuxsink_without_keyframe_request);
|
|
|
|
tcase_add_test (tc_chain_keyframe_request,
|
|
|
|
test_splitmuxsink_keyframe_request);
|
|
|
|
tcase_add_test (tc_chain_keyframe_request,
|
|
|
|
test_splitmuxsink_keyframe_request_more);
|
|
|
|
tcase_add_test (tc_chain_keyframe_request,
|
|
|
|
test_splitmuxsink_keyframe_request_less);
|
2019-05-25 12:08:05 +00:00
|
|
|
} else {
|
|
|
|
GST_INFO ("Skipping tests, missing plugins: vp8enc or mp4mux");
|
|
|
|
}
|
2020-03-12 11:34:47 +00:00
|
|
|
|
2014-07-31 14:07:53 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2020-04-03 07:49:25 +00:00
|
|
|
GST_CHECK_MAIN (splitmuxsink);
|