Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/GStreamer/gst-plugins-good.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Schmidt <jan@centricular.com>2015-02-06 17:41:49 +0300
committerJan Schmidt <jan@centricular.com>2015-02-06 19:58:30 +0300
commit8ceb58122e4e5ca4e9a64a2b3b36b5978de2f58b (patch)
tree356b2a3392283775e370ab8ccfbbc4f4ed89cc5d /tests/check/elements
parenteb975ce88069fad7cad7657a846268b5305f239e (diff)
splitmux: Add unit test for file splitting
Add a unit test for file splitting, and fix the leaks in the splitmuxsink it found
Diffstat (limited to 'tests/check/elements')
-rw-r--r--tests/check/elements/splitmux.c103
1 files changed, 95 insertions, 8 deletions
diff --git a/tests/check/elements/splitmux.c b/tests/check/elements/splitmux.c
index acdf97042..16e2b4312 100644
--- a/tests/check/elements/splitmux.c
+++ b/tests/check/elements/splitmux.c
@@ -52,16 +52,37 @@ tempdir_cleanup (void)
d = g_dir_open (tmpdir, 0, NULL);
fail_if (d == NULL);
- while ((f = g_dir_read_name (d)) != NULL)
- fail_if (g_remove (f) != 0);
+ 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);
+ 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 GstMessage *
run_pipeline (GstElement * pipeline)
{
@@ -77,12 +98,27 @@ run_pipeline (GstElement * pipeline)
return msg;
}
-GST_START_TEST (test_splitmuxsrc)
+static void
+dump_error (GstMessage * msg)
+{
+ GError *err = NULL;
+ gchar *dbg_info;
+
+ fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
+
+ 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 void
+test_playback (const gchar * in_pattern)
{
GstMessage *msg;
GstElement *pipeline;
GstElement *fakesink;
- gchar *in_pattern;
gchar *uri;
pipeline = gst_element_factory_make ("playbin", NULL);
@@ -92,20 +128,70 @@ GST_START_TEST (test_splitmuxsrc)
fail_if (fakesink == NULL);
g_object_set (G_OBJECT (pipeline), "video-sink", fakesink, NULL);
- in_pattern = g_build_filename (GST_TEST_FILES_PATH, "splitvideo*.ogg", NULL);
uri = g_strdup_printf ("splitmux://%s", in_pattern);
- g_free (in_pattern);
g_object_set (G_OBJECT (pipeline), "uri", uri, NULL);
g_free (uri);
msg = run_pipeline (pipeline);
- fail_if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
+ 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_splitmuxsrc)
+{
+ gchar *in_pattern =
+ g_build_filename (GST_TEST_FILES_PATH, "splitvideo*.ogg", NULL);
+ test_playback (in_pattern);
+ g_free (in_pattern);
+}
+
+GST_END_TEST;
+
+GST_START_TEST (test_splitmuxsink)
+{
+ GstMessage *msg;
+ GstElement *pipeline;
+ GstElement *sink;
+ 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);
+ 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);
+ 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);
+ g_free (in_pattern);
+}
+
GST_END_TEST;
static Suite *
@@ -119,6 +205,7 @@ splitmux_suite (void)
tcase_add_checked_fixture (tc_chain, tempdir_setup, tempdir_cleanup);
tcase_add_test (tc_chain, test_splitmuxsrc);
+ tcase_add_test (tc_chain, test_splitmuxsink);
return s;
}