From 6227a6118e803561877b6a8ccbe023c6e53ec5e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 31 Jul 2009 23:28:12 +0100 Subject: [PATCH] check: add basic unit test for flvdemux In particular, test re-use of flvdemux in both pull and push mode (see #583030). --- tests/check/Makefile.am | 1 + tests/check/elements/.gitignore | 1 + tests/check/elements/flvdemux.c | 184 ++++++++++++++++++++++++++++++++ tests/files/Makefile.am | 1 + tests/files/pcm16sine.flv | Bin 0 -> 4459 bytes 5 files changed, 187 insertions(+) create mode 100644 tests/check/elements/flvdemux.c create mode 100644 tests/files/pcm16sine.flv diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 350a26d7e2..faff1f094f 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -100,6 +100,7 @@ check_PROGRAMS = \ elements/avisubtitle \ elements/deinterleave \ elements/equalizer \ + elements/flvdemux \ elements/icydemux \ elements/id3demux \ elements/interleave \ diff --git a/tests/check/elements/.gitignore b/tests/check/elements/.gitignore index 7a3e4a2ec0..e6dde233fb 100644 --- a/tests/check/elements/.gitignore +++ b/tests/check/elements/.gitignore @@ -21,6 +21,7 @@ cmmlenc deinterleave equalizer gdkpixbufsink +flvdemux icydemux id3demux id3v2mux diff --git a/tests/check/elements/flvdemux.c b/tests/check/elements/flvdemux.c new file mode 100644 index 0000000000..2fe8ab3f8c --- /dev/null +++ b/tests/check/elements/flvdemux.c @@ -0,0 +1,184 @@ +/* GStreamer unit tests for flvdemux + * + * Copyright (C) 2009 Tim-Philipp Müller + * + * 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., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include + +#include + +static void +pad_added_cb (GstElement * flvdemux, GstPad * pad, GstBin * pipeline) +{ + GstElement *sink; + + sink = gst_bin_get_by_name (pipeline, "fakesink"); + fail_unless (gst_element_link (flvdemux, sink)); + gst_object_unref (sink); + + gst_element_set_state (sink, GST_STATE_PAUSED); +} + +static GstBusSyncReply +error_cb (GstBus * bus, GstMessage * msg, gpointer user_data) +{ + if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) { + const gchar *file = (const gchar *) user_data; + GError *err = NULL; + gchar *dbg = NULL; + + gst_message_parse_error (msg, &err, &dbg); + g_error ("ERROR for %s: %s\n%s\n", file, err->message, dbg); + } + + return GST_BUS_PASS; +} + +static void +handoff_cb (GstElement * element, GstBuffer * buf, GstPad * pad, + gint * p_counter) +{ + *p_counter += 1; + GST_LOG ("counter = %d", *p_counter); + + fail_unless (GST_BUFFER_CAPS (buf) != NULL); +} + +static void +process_file (const gchar * file, gboolean push_mode, gint repeat, + gint num_buffers) +{ + GstElement *src, *sep, *sink, *flvdemux, *pipeline; + GstBus *bus; + gchar *path; + gint counter; + + pipeline = gst_pipeline_new ("pipeline"); + fail_unless (pipeline != NULL, "Failed to create pipeline!"); + + bus = gst_element_get_bus (pipeline); + + /* kids, don't use a sync handler for this at home, really; we do because + * we just want to abort and nothing else */ + gst_bus_set_sync_handler (bus, error_cb, (gpointer) file); + + src = gst_element_factory_make ("filesrc", "filesrc"); + fail_unless (src != NULL, "Failed to create 'filesrc' element!"); + + if (push_mode) { + sep = gst_element_factory_make ("queue", "queue"); + fail_unless (sep != NULL, "Failed to create 'queue' element"); + } else { + sep = gst_element_factory_make ("identity", "identity"); + fail_unless (sep != NULL, "Failed to create 'identity' element"); + } + + flvdemux = gst_element_factory_make ("flvdemux", "flvdemux"); + fail_unless (flvdemux != NULL, "Failed to create 'flvdemux' element!"); + + sink = gst_element_factory_make ("fakesink", "fakesink"); + fail_unless (sink != NULL, "Failed to create 'fakesink' element!"); + + g_object_set (sink, "signal-handoffs", TRUE, NULL); + g_signal_connect (sink, "handoff", G_CALLBACK (handoff_cb), &counter); + + gst_bin_add_many (GST_BIN (pipeline), src, sep, flvdemux, sink, NULL); + + fail_unless (gst_element_link (src, sep)); + fail_unless (gst_element_link (sep, flvdemux)); + + /* can't link flvdemux and sink yet, do that later */ + g_signal_connect (flvdemux, "pad-added", G_CALLBACK (pad_added_cb), pipeline); + + path = g_build_filename (GST_TEST_FILES_PATH, file, NULL); + GST_LOG ("processing file '%s'", path); + g_object_set (src, "location", path, NULL); + + do { + GstStateChangeReturn state_ret; + GstMessage *msg; + + GST_LOG ("repeat=%d", repeat); + + counter = 0; + + state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED); + fail_unless (state_ret != GST_STATE_CHANGE_FAILURE); + + if (state_ret == GST_STATE_CHANGE_ASYNC) { + GST_LOG ("waiting for pipeline to reach PAUSED state"); + state_ret = gst_element_get_state (pipeline, NULL, NULL, -1); + fail_unless_equals_int (state_ret, GST_STATE_CHANGE_SUCCESS); + } + + GST_LOG ("PAUSED, let's read all of it"); + + state_ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); + fail_unless (state_ret != GST_STATE_CHANGE_FAILURE); + + msg = gst_bus_poll (bus, GST_MESSAGE_EOS, -1); + fail_unless (msg != NULL, "Expected EOS message on bus! (%s)", file); + + gst_message_unref (msg); + + if (num_buffers >= 0) { + fail_unless_equals_int (counter, num_buffers); + } + + fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL), + GST_STATE_CHANGE_SUCCESS); + + --repeat; + } while (repeat > 0); + + gst_object_unref (bus); + gst_object_unref (pipeline); + + g_free (path); +} + +GST_START_TEST (test_reuse_pull) +{ + process_file ("pcm16sine.flv", FALSE, 3, 129); + gst_task_cleanup_all (); +} + +GST_END_TEST; + +GST_START_TEST (test_reuse_push) +{ + process_file ("pcm16sine.flv", TRUE, 3, 129); + gst_task_cleanup_all (); +} + +GST_END_TEST; + +static Suite * +flvdemux_suite (void) +{ + Suite *s = suite_create ("flvdemux"); + TCase *tc_chain = tcase_create ("general"); + + suite_add_tcase (s, tc_chain); + tcase_add_test (tc_chain, test_reuse_push); + tcase_add_test (tc_chain, test_reuse_pull); + + return s; +} + +GST_CHECK_MAIN (flvdemux) diff --git a/tests/files/Makefile.am b/tests/files/Makefile.am index 4f3d3a433e..73ab4f2d51 100644 --- a/tests/files/Makefile.am +++ b/tests/files/Makefile.am @@ -5,6 +5,7 @@ EXTRA_DIST = \ id3-407349-2.tag \ id3-447000-wcop.tag \ id3-577468-unsynced-tag.tag \ + pcm16sine.flv \ test-cert.pem \ test-key.pem diff --git a/tests/files/pcm16sine.flv b/tests/files/pcm16sine.flv new file mode 100644 index 0000000000000000000000000000000000000000..2925a2aaf290ea78b54f6767564d21173c910b39 GIT binary patch literal 4459 zcmZYC2|U#4AHeY^caD~HN*N5@jtwErJRx!uE0SZ3nIdAPUG4t=rP^#8mDRz_IA&at zXgbg(DkZx`rIJcfM4_}whh%^Je$UHqAM<+k>f=3+XP)28cV1>3Tzx0V0RScv|G;Db z!bbilZZbeQdXpP3j$_Y><0ugz3%-jYehedi}EW^Roml3rk zo)-&LNAC`g-b5_r$$;q&vEdBoEs=~RrVLXnYjbmJ6UO%@CRXG_MiX0)J~Z(NtO$jA zRi@^KnM6;ad#X;R!H$L2rnq0W(6BLB@o^>YyPRv>%UApO;-2BZcb!(S3kP>C?(VQ8 z-XcEkJpNLCF0XLpDf!QNR&jT8f`gma;XdGh)>q$qnFsE&F54Z-RutOc9<;Q@bipEL zL)`5dv$dXR{;oFW6Nm&Xrs8?v^`)mD_k+D|os2e($GFeCAJNcKmso@Q#;VlwLuF@9 z;(o3~<5*QeZ7%MMBz;-aGP6av?-RBOG6a_dxH}3hL`fNTS-1y@n{!U(cNF3tbKFC^ z{mhrMxK~zQxgvif;ntYT5D8dDjT4(yo*8%G9@Sm_PVZCFH{3tS1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