diff options
author | Russell King <rmk@arm.linux.org.uk> | 2015-06-12 14:03:18 +0100 |
---|---|---|
committer | Russell King <rmk@arm.linux.org.uk> | 2015-06-12 16:23:01 +0100 |
commit | 84cda34f20299e644f1c19e74bd3b7d921483b1a (patch) | |
tree | c8d6338e0c3400977fb2faefcc8bae7ad91bb7df /tests | |
parent | a1728ec7c6a657d6af12cd40d4ddf1ee19a8332b (diff) |
Convert gst-plugins-base to stand-alone gst-plugins-xvbo package
We want to be a stand-alone package to support the xvboimagesink
plugin, so we don't want to replicate most of gst-plugins-base code
here. Delete mode of it, and rename ourselves appropriately.
Signed-off-by: Russell King <rmk@arm.linux.org.uk>
Diffstat (limited to 'tests')
133 files changed, 0 insertions, 34807 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am deleted file mode 100644 index b5c677c0..00000000 --- a/tests/Makefile.am +++ /dev/null @@ -1,27 +0,0 @@ -if BUILD_EXAMPLES -SUBDIRS_EXAMPLES = examples -else -SUBDIRS_EXAMPLES = -endif - -if HAVE_GST_CHECK -SUBDIRS_CHECK = check -else -SUBDIRS_CHECK = -endif - -if USE_X -SUBDIRS_ICLES = icles -else -SUBDIRS_ICLES = -endif - -SUBDIRS = \ - $(SUBDIRS_CHECK) \ - $(SUBDIRS_EXAMPLES) \ - $(SUBDIRS_ICLES) - -DIST_SUBDIRS = \ - check \ - examples \ - icles diff --git a/tests/check/.gitignore b/tests/check/.gitignore deleted file mode 100644 index 9af31302..00000000 --- a/tests/check/.gitignore +++ /dev/null @@ -1 +0,0 @@ -test-registry.* diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am deleted file mode 100644 index 78099541..00000000 --- a/tests/check/Makefile.am +++ /dev/null @@ -1,362 +0,0 @@ -include $(top_srcdir)/common/check.mak - -CHECK_REGISTRY = $(top_builddir)/tests/check/test-registry.reg - -REGISTRY_ENVIRONMENT = \ - GST_REGISTRY=$(CHECK_REGISTRY) - -TESTS_ENVIRONMENT = \ - CK_DEFAULT_TIMEOUT=120 \ - STATE_IGNORE_ELEMENTS="$(STATE_IGNORE_ELEMENTS)" \ - $(REGISTRY_ENVIRONMENT) \ - GST_PLUGIN_SYSTEM_PATH= \ - GST_PLUGIN_PATH=$(top_builddir)/gst:$(top_builddir)/sys:$(top_builddir)/ext:$(GST_PLUGINS_DIR) - -# ths core dumps of some machines have PIDs appended -CLEANFILES = core.* test-registry.* - -clean-local: clean-local-check - -$(CHECK_REGISTRY): - $(TESTS_ENVIRONMENT) - -# elements to ignore for the state tests -STATE_IGNORE_ELEMENTS = cdio cdparanoiasrc libvisual_ alsasrc alsamixer alsasink - -TESTS = $(check_PROGRAMS) - -if USE_ALSA -check_alsa = elements/alsa -else -check_alsa = -endif - -if USE_GNOME_VFS -check_gnomevfs = elements/gnomevfssink -else -check_gnomevfs = -endif - -if USE_GIO -check_gio = pipelines/gio -else -check_gio = -endif - -if USE_LIBVISUAL -check_libvisual = elements/libvisual -else -check_libvisual = -endif - -if USE_OGG -check_ogg = pipelines/oggmux -else -check_ogg = -endif - -if USE_PANGO -check_pango = elements/textoverlay -else -check_pango = -endif - -if USE_VORBIS -check_vorbis = elements/vorbisdec pipelines/vorbisenc pipelines/vorbisdec \ - elements/vorbistag -else -check_vorbis = -endif - -if USE_THEORA -check_theora = pipelines/theoraenc -else -check_theora = -endif - -if USE_PLUGIN_SUBPARSE -check_subparse = elements/subparse -else -check_subparse = -endif - -check_PROGRAMS = \ - $(check_alsa) \ - $(check_gnomevfs) \ - $(check_gio) \ - $(check_ogg) \ - $(check_pango) \ - $(check_vorbis) \ - $(check_theora) \ - elements/adder \ - elements/appsink \ - elements/audioconvert \ - elements/audiorate \ - elements/audioresample \ - elements/audiotestsrc \ - elements/decodebin \ - elements/decodebin2 \ - elements/ffmpegcolorspace \ - elements/gdpdepay \ - elements/gdppay \ - elements/multifdsink \ - elements/playbin \ - elements/playbin2 \ - $(check_subparse) \ - elements/videorate \ - elements/videoscale \ - elements/videotestsrc \ - elements/volume \ - generic/clock-selection \ - generic/states \ - gst/typefindfunctions \ - libs/audio \ - libs/cddabasesrc \ - libs/fft \ - libs/mixer \ - libs/navigation \ - libs/netbuffer \ - libs/pbutils \ - libs/rtp \ - libs/tag \ - libs/video \ - pipelines/simple-launch-lines \ - pipelines/streamheader \ - pipelines/basetime - -# TORTURE_TO_FIX = \ -# elements/adder - -# ffmpegcolorspace takes too long, so disabled for now -VALGRIND_TO_FIX = \ - elements/ffmpegcolorspace \ - libs/video - -# these tests don't even pass -noinst_PROGRAMS = $(check_libvisual) - -AM_CFLAGS = $(GST_CFLAGS) $(GST_CHECK_CFLAGS) -LDADD = $(GST_LIBS) $(GST_CHECK_LIBS) - -# valgrind testing -VALGRIND_TESTS_DISABLE = $(VALGRIND_TO_FIX) - -SUPPRESSIONS = $(top_srcdir)/common/gst.supp $(srcdir)/gst-plugins-base.supp - -libs_audio_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(GST_BASE_CFLAGS) \ - $(AM_CFLAGS) - -libs_audio_LDADD = \ - $(top_builddir)/gst-libs/gst/audio/libgstaudio-@GST_MAJORMINOR@.la \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la \ - $(GST_BASE_LIBS) \ - $(LDADD) - -libs_cddabasesrc_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(GST_BASE_CFLAGS) \ - $(AM_CFLAGS) - -libs_cddabasesrc_LDADD = \ - $(top_builddir)/gst-libs/gst/cdda/libgstcdda-@GST_MAJORMINOR@.la \ - $(top_builddir)/gst-libs/gst/tag/libgsttag-@GST_MAJORMINOR@.la \ - $(GST_BASE_LIBS) \ - $(LDADD) - -libs_fft_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(GST_BASE_CFLAGS) \ - $(AM_CFLAGS) - -libs_fft_LDADD = \ - $(top_builddir)/gst-libs/gst/fft/libgstfft-@GST_MAJORMINOR@.la \ - $(GST_BASE_LIBS) \ - $(LDADD) - -libs_mixer_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(GST_BASE_CFLAGS) \ - $(AM_CFLAGS) - -libs_mixer_LDADD = \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la \ - $(GST_BASE_LIBS) \ - $(LDADD) - -libs_navigation_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(GST_BASE_CFLAGS) \ - $(AM_CFLAGS) - -libs_navigation_LDADD = \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la \ - $(GST_BASE_LIBS) \ - $(LDADD) - -libs_netbuffer_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(AM_CFLAGS) -libs_netbuffer_LDADD = \ - $(top_builddir)/gst-libs/gst/netbuffer/libgstnetbuffer-@GST_MAJORMINOR@.la \ - $(LDADD) - -libs_rtp_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(AM_CFLAGS) -libs_rtp_LDADD = \ - $(top_builddir)/gst-libs/gst/rtp/libgstrtp-@GST_MAJORMINOR@.la $(LDADD) - -libs_tag_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(AM_CFLAGS) -libs_tag_LDADD = \ - $(top_builddir)/gst-libs/gst/tag/libgsttag-@GST_MAJORMINOR@.la $(LDADD) - -libs_pbutils_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(AM_CFLAGS) -libs_pbutils_LDADD = \ - $(top_builddir)/gst-libs/gst/pbutils/libgstpbutils-@GST_MAJORMINOR@.la $(LDADD) - -elements_appsink_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(AM_CFLAGS) - -elements_appsink_LDADD = \ - $(top_builddir)/gst-libs/gst/app/libgstapp-@GST_MAJORMINOR@.la \ - $(LDADD) - -elements_alsa_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(AM_CFLAGS) - -elements_alsa_LDADD = \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la \ - $(LDADD) - -elements_audioconvert_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(GST_BASE_CFLAGS) \ - $(AM_CFLAGS) - -elements_audioconvert_LDADD = \ - $(top_builddir)/gst-libs/gst/audio/libgstaudio-@GST_MAJORMINOR@.la \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la \ - $(GST_BASE_LIBS) \ - $(LDADD) - -elements_audiorate_LDADD = $(LDADD) -elements_audiorate_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(CFLAGS) $(AM_CFLAGS) - -elements_libvisual_LDADD = $(LDADD) -elements_libvisual_CFLAGS = $(CFLAGS) $(AM_CFLAGS) - -elements_gdpdepay_LDADD = $(GST_GDP_LIBS) $(LDADD) -elements_gdppay_LDADD = $(GST_GDP_LIBS) $(LDADD) - -elements_playbin_LDADD = $(GST_BASE_LIBS) $(LDADD) -elements_playbin_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS) - -elements_playbin2_LDADD = $(GST_BASE_LIBS) $(LDADD) -elements_playbin2_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS) - -elements_decodebin_LDADD = $(GST_BASE_LIBS) $(LDADD) -elements_decodebin_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS) - -elements_decodebin2_LDADD = $(GST_BASE_LIBS) $(LDADD) -elements_decodebin2_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS) - -elements_subparse_LDADD = $(LDADD) -elements_subparse_CFLAGS = $(CFLAGS) $(AM_CFLAGS) - -elements_audioresample_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(GST_BASE_CFLAGS) \ - $(AM_CFLAGS) - -elements_audioresample_LDADD = \ - $(top_builddir)/gst-libs/gst/audio/libgstaudio-@GST_MAJORMINOR@.la \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la \ - $(GST_BASE_LIBS) \ - $(LDADD) - -elements_textoverlay_LDADD = $(GST_BASE_LIBS) $(LDADD) -elements_textoverlay_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS) - -elements_volume_LDADD = \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la \ - $(GST_PLUGINS_BASE_LIBS) \ - $(GST_CONTROLLER_LIBS) \ - $(GST_BASE_LIBS) \ - $(LDADD) - -elements_volume_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(GST_CONTROLLER_CFLAGS) \ - $(GST_BASE_CFLAGS) \ - $(AM_CFLAGS) - -elements_vorbisdec_LDADD = \ - $(LDADD) \ - $(VORBIS_LIBS) - -elements_vorbisdec_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(AM_CFLAGS) \ - $(VORBIS_CFLAGS) \ - $(CFLAGS) - -elements_vorbistag_LDADD = \ - $(LDADD) \ - $(VORBIS_LIBS) - -elements_vorbistag_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(AM_CFLAGS) \ - $(VORBIS_CFLAGS) \ - $(CFLAGS) - -gst_typefindfunctions_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS) -gst_typefindfunctions_LDADD = $(GST_BASE_LIBS) $(LDADD) - -libs_video_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(GST_BASE_CFLAGS) \ - $(AM_CFLAGS) - -libs_video_LDADD = \ - $(top_builddir)/gst-libs/gst/video/libgstvideo-@GST_MAJORMINOR@.la \ - $(GST_BASE_LIBS) \ - $(LDADD) - -pipelines_gio_CFLAGS = $(GIO_CFLAGS) $(AM_CFLAGS) -pipelines_gio_LDADD = $(GIO_LIBS) $(LDADD) - -pipelines_vorbisenc_CFLAGS = \ - $(GST_PLUGINS_BASE_CFLAGS) \ - $(AM_CFLAGS) - -# this seemingly useless CFLAGS line is here only to avoid -# vorbisdec.$(OBJEXT) by triggering creation of pipelines_vorbisdec.$(OBJEXT) -# instead -pipelines_vorbisdec_CFLAGS = $(AM_CFLAGS) - -pipelines_oggmux_LDADD = $(LDADD) $(OGG_LIBS) -pipelines_oggmux_CFLAGS = $(AM_CFLAGS) $(OGG_CFLAGS) - -pipelines_theoraenc_CFLAGS = $(AM_CFLAGS) $(THEORA_CFLAGS) -pipelines_theoraenc_LDADD = $(LDADD) $(THEORA_LIBS) - -pipelines_simple_launch_lines_CFLAGS = \ - $(GST_BASE_CFLAGS) \ - $(AM_CFLAGS) - -pipelines_simple_launch_lines_LDADD = \ - $(top_builddir)/gst-libs/gst/audio/libgstaudio-@GST_MAJORMINOR@.la \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la \ - $(GST_BASE_LIBS) \ - $(LDADD) - -EXTRA_DIST = gst-plugins-base.supp diff --git a/tests/check/elements/.gitignore b/tests/check/elements/.gitignore deleted file mode 100644 index 00ab7d17..00000000 --- a/tests/check/elements/.gitignore +++ /dev/null @@ -1,27 +0,0 @@ -.dirstamp -adder -alsa -appsink -audioconvert -audiorate -audioresample -audiotestsrc -decodebin -decodebin2 -gdpdepay -gdppay -gnomevfssink -libvisual -multifdsink -videorate -videotestsrc -volume -vorbisdec -typefindfunctions -textoverlay -ffmpegcolorspace -videoscale -vorbistag -playbin -playbin2 -subparse diff --git a/tests/check/elements/adder.c b/tests/check/elements/adder.c deleted file mode 100644 index db0e79ac..00000000 --- a/tests/check/elements/adder.c +++ /dev/null @@ -1,889 +0,0 @@ -/* GStreamer - * - * unit test for adder - * - * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#ifdef HAVE_VALGRIND -# include <valgrind/valgrind.h> -#endif - -#include <unistd.h> - -#include <gst/check/gstcheck.h> -#include <gst/check/gstconsistencychecker.h> - -static GMainLoop *main_loop; - -static void -message_received (GstBus * bus, GstMessage * message, GstPipeline * bin) -{ - GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT, - GST_MESSAGE_SRC (message), message); - - switch (message->type) { - case GST_MESSAGE_EOS: - g_main_loop_quit (main_loop); - break; - case GST_MESSAGE_WARNING:{ - GError *gerror; - gchar *debug; - - gst_message_parse_warning (message, &gerror, &debug); - gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); - g_error_free (gerror); - g_free (debug); - break; - } - case GST_MESSAGE_ERROR:{ - GError *gerror; - gchar *debug; - - gst_message_parse_error (message, &gerror, &debug); - gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); - g_error_free (gerror); - g_free (debug); - g_main_loop_quit (main_loop); - break; - } - default: - break; - } -} - - -static GstFormat format = GST_FORMAT_UNDEFINED; -static gint64 position = -1; - -static void -test_event_message_received (GstBus * bus, GstMessage * message, - GstPipeline * bin) -{ - GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT, - GST_MESSAGE_SRC (message), message); - - switch (message->type) { - case GST_MESSAGE_SEGMENT_DONE: - gst_message_parse_segment_done (message, &format, &position); - GST_INFO ("received segment_done : %" G_GINT64_FORMAT, position); - g_main_loop_quit (main_loop); - break; - default: - g_assert_not_reached (); - break; - } -} - - -GST_START_TEST (test_event) -{ - GstElement *bin, *src1, *src2, *adder, *sink; - GstBus *bus; - GstEvent *seek_event; - gboolean res; - GstPad *srcpad; - GstStreamConsistency *consist; - - GST_INFO ("preparing test"); - - /* build pipeline */ - bin = gst_pipeline_new ("pipeline"); - bus = gst_element_get_bus (bin); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - - /* FIXME, fakesrc with default setting will produce 0 sized - * buffers and incompatible caps for adder that will make - * adder EOS and error out */ - src1 = gst_element_factory_make ("audiotestsrc", "src1"); - g_object_set (src1, "wave", 4, NULL); /* silence */ - src2 = gst_element_factory_make ("audiotestsrc", "src2"); - g_object_set (src2, "wave", 4, NULL); /* silence */ - adder = gst_element_factory_make ("adder", "adder"); - sink = gst_element_factory_make ("fakesink", "sink"); - gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL); - - res = gst_element_link (src1, adder); - fail_unless (res == TRUE, NULL); - res = gst_element_link (src2, adder); - fail_unless (res == TRUE, NULL); - res = gst_element_link (adder, sink); - fail_unless (res == TRUE, NULL); - - srcpad = gst_element_get_static_pad (adder, "src"); - consist = gst_consistency_checker_new (srcpad); - gst_object_unref (srcpad); - - seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME, - GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH, - GST_SEEK_TYPE_SET, (GstClockTime) 0, - GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND); - - format = GST_FORMAT_UNDEFINED; - position = -1; - - main_loop = g_main_loop_new (NULL, FALSE); - g_signal_connect (bus, "message::segment-done", - (GCallback) test_event_message_received, bin); - g_signal_connect (bus, "message::error", (GCallback) message_received, bin); - g_signal_connect (bus, "message::warning", (GCallback) message_received, bin); - g_signal_connect (bus, "message::eos", (GCallback) message_received, bin); - - GST_INFO ("starting test"); - - /* prepare playing */ - res = gst_element_set_state (bin, GST_STATE_PAUSED); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* wait for completion */ - res = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - res = gst_element_send_event (bin, seek_event); - fail_unless (res == TRUE, NULL); - - /* run pipeline */ - res = gst_element_set_state (bin, GST_STATE_PLAYING); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - g_main_loop_run (main_loop); - - res = gst_element_set_state (bin, GST_STATE_NULL); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - fail_unless (position == 2 * GST_SECOND, NULL); - - /* cleanup */ - g_main_loop_unref (main_loop); - gst_consistency_checker_free (consist); - gst_object_unref (G_OBJECT (bus)); - gst_object_unref (G_OBJECT (bin)); -} - -GST_END_TEST; - -static guint play_count = 0; -static GstEvent *play_seek_event = NULL; - -static void -test_play_twice_message_received (GstBus * bus, GstMessage * message, - GstPipeline * bin) -{ - gboolean res; - - GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT, - GST_MESSAGE_SRC (message), message); - - switch (message->type) { - case GST_MESSAGE_SEGMENT_DONE: - play_count++; - if (play_count == 1) { - res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* prepare playing again */ - res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* wait for completion */ - res = - gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, - GST_CLOCK_TIME_NONE); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - res = gst_element_send_event (GST_ELEMENT (bin), - gst_event_ref (play_seek_event)); - fail_unless (res == TRUE, NULL); - - res = gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - } else { - g_main_loop_quit (main_loop); - } - break; - default: - g_assert_not_reached (); - break; - } -} - - -GST_START_TEST (test_play_twice) -{ - GstElement *bin, *src1, *src2, *adder, *sink; - GstBus *bus; - gboolean res; - GstPad *srcpad; - GstStreamConsistency *consist; - - GST_INFO ("preparing test"); - - /* build pipeline */ - bin = gst_pipeline_new ("pipeline"); - bus = gst_element_get_bus (bin); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - - src1 = gst_element_factory_make ("audiotestsrc", "src1"); - g_object_set (src1, "wave", 4, NULL); /* silence */ - src2 = gst_element_factory_make ("audiotestsrc", "src2"); - g_object_set (src2, "wave", 4, NULL); /* silence */ - adder = gst_element_factory_make ("adder", "adder"); - sink = gst_element_factory_make ("fakesink", "sink"); - gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL); - - res = gst_element_link (src1, adder); - fail_unless (res == TRUE, NULL); - res = gst_element_link (src2, adder); - fail_unless (res == TRUE, NULL); - res = gst_element_link (adder, sink); - fail_unless (res == TRUE, NULL); - - srcpad = gst_element_get_static_pad (adder, "src"); - consist = gst_consistency_checker_new (srcpad); - gst_object_unref (srcpad); - - play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME, - GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH, - GST_SEEK_TYPE_SET, (GstClockTime) 0, - GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND); - - play_count = 0; - - main_loop = g_main_loop_new (NULL, FALSE); - g_signal_connect (bus, "message::segment-done", - (GCallback) test_play_twice_message_received, bin); - g_signal_connect (bus, "message::error", (GCallback) message_received, bin); - g_signal_connect (bus, "message::warning", (GCallback) message_received, bin); - g_signal_connect (bus, "message::eos", (GCallback) message_received, bin); - - GST_INFO ("starting test"); - - /* prepare playing */ - res = gst_element_set_state (bin, GST_STATE_PAUSED); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* wait for completion */ - res = - gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, - GST_CLOCK_TIME_NONE); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - res = gst_element_send_event (bin, gst_event_ref (play_seek_event)); - fail_unless (res == TRUE, NULL); - - GST_INFO ("seeked"); - - /* run pipeline */ - res = gst_element_set_state (bin, GST_STATE_PLAYING); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - g_main_loop_run (main_loop); - - res = gst_element_set_state (bin, GST_STATE_NULL); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - fail_unless (play_count == 2, NULL); - - /* cleanup */ - g_main_loop_unref (main_loop); - gst_consistency_checker_free (consist); - gst_event_ref (play_seek_event); - gst_object_unref (G_OBJECT (bus)); - gst_object_unref (G_OBJECT (bin)); -} - -GST_END_TEST; - -GST_START_TEST (test_play_twice_then_add_and_play_again) -{ - GstElement *bin, *src1, *src2, *src3, *adder, *sink; - GstBus *bus; - gboolean res; - gint i; - GstPad *srcpad; - GstStreamConsistency *consist; - - GST_INFO ("preparing test"); - - /* build pipeline */ - bin = gst_pipeline_new ("pipeline"); - bus = gst_element_get_bus (bin); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - - src1 = gst_element_factory_make ("audiotestsrc", "src1"); - g_object_set (src1, "wave", 4, NULL); /* silence */ - src2 = gst_element_factory_make ("audiotestsrc", "src2"); - g_object_set (src2, "wave", 4, NULL); /* silence */ - adder = gst_element_factory_make ("adder", "adder"); - sink = gst_element_factory_make ("fakesink", "sink"); - gst_bin_add_many (GST_BIN (bin), src1, src2, adder, sink, NULL); - - srcpad = gst_element_get_static_pad (adder, "src"); - consist = gst_consistency_checker_new (srcpad); - gst_object_unref (srcpad); - - res = gst_element_link (src1, adder); - fail_unless (res == TRUE, NULL); - res = gst_element_link (src2, adder); - fail_unless (res == TRUE, NULL); - res = gst_element_link (adder, sink); - fail_unless (res == TRUE, NULL); - - play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME, - GST_SEEK_FLAG_SEGMENT | GST_SEEK_FLAG_FLUSH, - GST_SEEK_TYPE_SET, (GstClockTime) 0, - GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND); - - main_loop = g_main_loop_new (NULL, FALSE); - g_signal_connect (bus, "message::segment-done", - (GCallback) test_play_twice_message_received, bin); - g_signal_connect (bus, "message::error", (GCallback) message_received, bin); - g_signal_connect (bus, "message::warning", (GCallback) message_received, bin); - g_signal_connect (bus, "message::eos", (GCallback) message_received, bin); - - /* run it twice */ - for (i = 0; i < 2; i++) { - play_count = 0; - - GST_INFO ("starting test-loop %d", i); - - /* prepare playing */ - res = gst_element_set_state (bin, GST_STATE_PAUSED); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* wait for completion */ - res = - gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, - GST_CLOCK_TIME_NONE); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - res = gst_element_send_event (bin, gst_event_ref (play_seek_event)); - fail_unless (res == TRUE, NULL); - - GST_INFO ("seeked"); - - /* run pipeline */ - res = gst_element_set_state (bin, GST_STATE_PLAYING); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - g_main_loop_run (main_loop); - - res = gst_element_set_state (bin, GST_STATE_READY); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - fail_unless (play_count == 2, NULL); - - /* plug another source */ - if (i == 0) { - src3 = gst_element_factory_make ("audiotestsrc", "src3"); - g_object_set (src3, "wave", 4, NULL); /* silence */ - gst_bin_add (GST_BIN (bin), src3); - - res = gst_element_link (src3, adder); - fail_unless (res == TRUE, NULL); - } - - gst_consistency_checker_reset (consist); - } - - res = gst_element_set_state (bin, GST_STATE_NULL); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* cleanup */ - g_main_loop_unref (main_loop); - gst_event_ref (play_seek_event); - gst_consistency_checker_free (consist); - gst_object_unref (G_OBJECT (bus)); - gst_object_unref (G_OBJECT (bin)); -} - -GST_END_TEST; - - -static void -test_live_seeking_eos_message_received (GstBus * bus, GstMessage * message, - GstPipeline * bin) -{ - GST_INFO ("bus message from \"%" GST_PTR_FORMAT "\": %" GST_PTR_FORMAT, - GST_MESSAGE_SRC (message), message); - - switch (message->type) { - case GST_MESSAGE_EOS: - g_main_loop_quit (main_loop); - break; - default: - g_assert_not_reached (); - break; - } -} - - -/* test failing seeks on live-sources */ -GST_START_TEST (test_live_seeking) -{ - GstElement *bin, *src1, *src2, *ac1, *ac2, *adder, *sink; - GstBus *bus; - gboolean res; - GstPad *srcpad; - gint i; - GstStreamConsistency *consist; - - GST_INFO ("preparing test"); - main_loop = NULL; - play_seek_event = NULL; - - /* build pipeline */ - bin = gst_pipeline_new ("pipeline"); - bus = gst_element_get_bus (bin); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - - /* normal audiosources behave differently than audiotestsrc */ -#if 0 - src1 = gst_element_factory_make ("audiotestsrc", "src1"); - g_object_set (src1, "wave", 4, "is-live", TRUE, NULL); /* silence */ -#else - src1 = gst_element_factory_make ("alsasrc", "src1"); - if (!src1) { - GST_INFO ("no audiosrc, skipping"); - goto cleanup; - } - /* Test that the audio source can get to paused, else skip */ - res = gst_element_set_state (src1, GST_STATE_PAUSED); - (void) gst_element_set_state (src1, GST_STATE_NULL); - gst_object_unref (src1); - - if (res == GST_STATE_CHANGE_FAILURE) - goto cleanup; - src1 = gst_element_factory_make ("alsasrc", "src1"); - - /* live sources ignore seeks, force eos after 2 sec (4 buffers half second - * each) - don't use autoaudiosrc, as then we can't set anything here */ - g_object_set (src1, "num-buffers", 4, "blocksize", 44100, NULL); -#endif - ac1 = gst_element_factory_make ("audioconvert", "ac1"); - src2 = gst_element_factory_make ("audiotestsrc", "src2"); - g_object_set (src2, "wave", 4, NULL); /* silence */ - ac2 = gst_element_factory_make ("audioconvert", "ac2"); - adder = gst_element_factory_make ("adder", "adder"); - sink = gst_element_factory_make ("fakesink", "sink"); - gst_bin_add_many (GST_BIN (bin), src1, ac1, src2, ac2, adder, sink, NULL); - - res = gst_element_link (src1, ac1); - fail_unless (res == TRUE, NULL); - res = gst_element_link (ac1, adder); - fail_unless (res == TRUE, NULL); - res = gst_element_link (src2, ac2); - fail_unless (res == TRUE, NULL); - res = gst_element_link (ac2, adder); - fail_unless (res == TRUE, NULL); - res = gst_element_link (adder, sink); - fail_unless (res == TRUE, NULL); - - play_seek_event = gst_event_new_seek (1.0, GST_FORMAT_TIME, - GST_SEEK_FLAG_FLUSH, - GST_SEEK_TYPE_SET, (GstClockTime) 0, - GST_SEEK_TYPE_SET, (GstClockTime) 2 * GST_SECOND); - - main_loop = g_main_loop_new (NULL, FALSE); - g_signal_connect (bus, "message::error", (GCallback) message_received, bin); - g_signal_connect (bus, "message::warning", (GCallback) message_received, bin); - g_signal_connect (bus, "message::eos", - (GCallback) test_live_seeking_eos_message_received, bin); - - srcpad = gst_element_get_static_pad (adder, "src"); - consist = gst_consistency_checker_new (srcpad); - gst_object_unref (srcpad); - - GST_INFO ("starting test"); - - /* run it twice */ - for (i = 0; i < 2; i++) { - - GST_INFO ("starting test-loop %d", i); - - /* prepare playing */ - res = gst_element_set_state (bin, GST_STATE_PAUSED); - fail_unless (res != GST_STATE_CHANGE_FAILURE); - - /* wait for completion */ - res = - gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, - GST_CLOCK_TIME_NONE); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - res = gst_element_send_event (bin, gst_event_ref (play_seek_event)); -#if 1 - fail_unless (res == TRUE, NULL); -#else - /* adder is picky, if a single seek fails it totaly fails */ - fail_unless (res == FALSE, NULL); -#endif - - GST_INFO ("seeked"); - - /* run pipeline */ - res = gst_element_set_state (bin, GST_STATE_PLAYING); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - GST_INFO ("playing"); - - g_main_loop_run (main_loop); - - res = gst_element_set_state (bin, GST_STATE_NULL); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - gst_consistency_checker_reset (consist); - } - - /* cleanup */ -cleanup: - GST_INFO ("cleaning up"); - if (main_loop) - g_main_loop_unref (main_loop); - if (play_seek_event) - gst_event_unref (play_seek_event); - gst_object_unref (G_OBJECT (bus)); - gst_object_unref (G_OBJECT (bin)); -} - -GST_END_TEST; - -/* check if adding pads work as expected */ -GST_START_TEST (test_add_pad) -{ - GstElement *bin, *src1, *src2, *adder, *sink; - GstBus *bus; - GstPad *srcpad; - GstStreamConsistency *consist; - gboolean res; - - GST_INFO ("preparing test"); - - /* build pipeline */ - bin = gst_pipeline_new ("pipeline"); - bus = gst_element_get_bus (bin); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - - src1 = gst_element_factory_make ("audiotestsrc", "src1"); - g_object_set (src1, "num-buffers", 4, NULL); - g_object_set (src1, "wave", 4, NULL); /* silence */ - src2 = gst_element_factory_make ("audiotestsrc", "src2"); - /* one buffer less, we connect with 1 buffer of delay */ - g_object_set (src2, "num-buffers", 3, NULL); - g_object_set (src2, "wave", 4, NULL); /* silence */ - adder = gst_element_factory_make ("adder", "adder"); - sink = gst_element_factory_make ("fakesink", "sink"); - gst_bin_add_many (GST_BIN (bin), src1, adder, sink, NULL); - - res = gst_element_link (src1, adder); - fail_unless (res == TRUE, NULL); - res = gst_element_link (adder, sink); - fail_unless (res == TRUE, NULL); - - srcpad = gst_element_get_static_pad (adder, "src"); - consist = gst_consistency_checker_new (srcpad); - gst_object_unref (srcpad); - - main_loop = g_main_loop_new (NULL, FALSE); - g_signal_connect (bus, "message::segment-done", (GCallback) message_received, - bin); - g_signal_connect (bus, "message::error", (GCallback) message_received, bin); - g_signal_connect (bus, "message::warning", (GCallback) message_received, bin); - g_signal_connect (bus, "message::eos", (GCallback) message_received, bin); - - GST_INFO ("starting test"); - - /* prepare playing */ - res = gst_element_set_state (bin, GST_STATE_PAUSED); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* wait for completion */ - res = - gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, - GST_CLOCK_TIME_NONE); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* add other element */ - gst_bin_add_many (GST_BIN (bin), src2, NULL); - - /* now link the second element */ - res = gst_element_link (src2, adder); - fail_unless (res == TRUE, NULL); - - /* set to PAUSED as well */ - res = gst_element_set_state (src2, GST_STATE_PAUSED); - - /* now play all */ - res = gst_element_set_state (bin, GST_STATE_PLAYING); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - g_main_loop_run (main_loop); - - res = gst_element_set_state (bin, GST_STATE_NULL); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* cleanup */ - g_main_loop_unref (main_loop); - gst_object_unref (G_OBJECT (bus)); - gst_object_unref (G_OBJECT (bin)); -} - -GST_END_TEST; - -/* check if removing pads work as expected */ -GST_START_TEST (test_remove_pad) -{ - GstElement *bin, *src, *adder, *sink; - GstBus *bus; - GstPad *pad, *srcpad; - gboolean res; - GstStreamConsistency *consist; - - GST_INFO ("preparing test"); - - /* build pipeline */ - bin = gst_pipeline_new ("pipeline"); - bus = gst_element_get_bus (bin); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - - src = gst_element_factory_make ("audiotestsrc", "src"); - g_object_set (src, "num-buffers", 4, NULL); - g_object_set (src, "wave", 4, NULL); - adder = gst_element_factory_make ("adder", "adder"); - sink = gst_element_factory_make ("fakesink", "sink"); - gst_bin_add_many (GST_BIN (bin), src, adder, sink, NULL); - - res = gst_element_link (src, adder); - fail_unless (res == TRUE, NULL); - res = gst_element_link (adder, sink); - fail_unless (res == TRUE, NULL); - - /* create an unconnected sinkpad in adder */ - pad = gst_element_get_request_pad (adder, "sink%d"); - fail_if (pad == NULL, NULL); - - srcpad = gst_element_get_static_pad (adder, "src"); - consist = gst_consistency_checker_new (srcpad); - gst_object_unref (srcpad); - - main_loop = g_main_loop_new (NULL, FALSE); - g_signal_connect (bus, "message::segment-done", (GCallback) message_received, - bin); - g_signal_connect (bus, "message::error", (GCallback) message_received, bin); - g_signal_connect (bus, "message::warning", (GCallback) message_received, bin); - g_signal_connect (bus, "message::eos", (GCallback) message_received, bin); - - GST_INFO ("starting test"); - - /* prepare playing, this will not preroll as adder is waiting - * on the unconnected sinkpad. */ - res = gst_element_set_state (bin, GST_STATE_PAUSED); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* wait for completion for one second, will return ASYNC */ - res = gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, GST_SECOND); - fail_unless (res == GST_STATE_CHANGE_ASYNC, NULL); - - /* get rid of the pad now, adder should stop waiting on it and - * continue the preroll */ - gst_element_release_request_pad (adder, pad); - gst_object_unref (pad); - - /* wait for completion, should work now */ - res = - gst_element_get_state (GST_ELEMENT (bin), NULL, NULL, - GST_CLOCK_TIME_NONE); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* now play all */ - res = gst_element_set_state (bin, GST_STATE_PLAYING); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - g_main_loop_run (main_loop); - - res = gst_element_set_state (bin, GST_STATE_NULL); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* cleanup */ - g_main_loop_unref (main_loop); - gst_object_unref (G_OBJECT (bus)); - gst_object_unref (G_OBJECT (bin)); -} - -GST_END_TEST; - - -static GstBuffer *handoff_buffer = NULL; -static void -handoff_buffer_cb (GstElement * fakesink, GstBuffer * buffer, GstPad * pad, - gpointer user_data) -{ - GST_DEBUG ("got buffer %p", buffer); - gst_buffer_replace (&handoff_buffer, buffer); -} - -/* check if clipping works as expected */ -GST_START_TEST (test_clip) -{ - GstElement *bin, *adder, *sink; - GstBus *bus; - GstPad *sinkpad; - gboolean res; - GstFlowReturn ret; - GstEvent *event; - GstBuffer *buffer; - GstCaps *caps; - - GST_INFO ("preparing test"); - - /* build pipeline */ - bin = gst_pipeline_new ("pipeline"); - bus = gst_element_get_bus (bin); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - - g_signal_connect (bus, "message::error", (GCallback) message_received, bin); - g_signal_connect (bus, "message::warning", (GCallback) message_received, bin); - g_signal_connect (bus, "message::eos", (GCallback) message_received, bin); - - /* just an adder and a fakesink */ - adder = gst_element_factory_make ("adder", "adder"); - sink = gst_element_factory_make ("fakesink", "sink"); - g_object_set (sink, "signal-handoffs", TRUE, NULL); - g_signal_connect (sink, "handoff", (GCallback) handoff_buffer_cb, NULL); - gst_bin_add_many (GST_BIN (bin), adder, sink, NULL); - - res = gst_element_link (adder, sink); - fail_unless (res == TRUE, NULL); - - /* set to playing */ - res = gst_element_set_state (bin, GST_STATE_PLAYING); - fail_unless (res != GST_STATE_CHANGE_FAILURE, NULL); - - /* create an unconnected sinkpad in adder, should also automatically activate - * the pad */ - sinkpad = gst_element_get_request_pad (adder, "sink%d"); - fail_if (sinkpad == NULL, NULL); - - /* send segment to adder */ - event = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, - GST_SECOND, 2 * GST_SECOND, 0); - gst_pad_send_event (sinkpad, event); - - caps = gst_caps_new_simple ("audio/x-raw-int", - "rate", G_TYPE_INT, 44100, - "channels", G_TYPE_INT, 2, - "endianness", G_TYPE_INT, G_BYTE_ORDER, - "width", G_TYPE_INT, 16, - "depth", G_TYPE_INT, 16, "signed", G_TYPE_BOOLEAN, TRUE, NULL); - - /* should be clipped and ok */ - buffer = gst_buffer_new_and_alloc (44100); - GST_BUFFER_TIMESTAMP (buffer) = 0; - GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND; - gst_buffer_set_caps (buffer, caps); - GST_DEBUG ("pushing buffer %p", buffer); - ret = gst_pad_chain (sinkpad, buffer); - fail_unless (ret == GST_FLOW_OK); - fail_unless (handoff_buffer == NULL); - - /* should be partially clipped */ - buffer = gst_buffer_new_and_alloc (44100); - GST_BUFFER_TIMESTAMP (buffer) = 900 * GST_MSECOND; - GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND; - gst_buffer_set_caps (buffer, caps); - GST_DEBUG ("pushing buffer %p", buffer); - ret = gst_pad_chain (sinkpad, buffer); - fail_unless (ret == GST_FLOW_OK); - fail_unless (handoff_buffer != NULL); - gst_buffer_replace (&handoff_buffer, NULL); - - /* should not be clipped */ - buffer = gst_buffer_new_and_alloc (44100); - GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND; - GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND; - gst_buffer_set_caps (buffer, caps); - GST_DEBUG ("pushing buffer %p", buffer); - ret = gst_pad_chain (sinkpad, buffer); - fail_unless (ret == GST_FLOW_OK); - fail_unless (handoff_buffer != NULL); - gst_buffer_replace (&handoff_buffer, NULL); - - /* should be clipped and ok */ - buffer = gst_buffer_new_and_alloc (44100); - GST_BUFFER_TIMESTAMP (buffer) = 2 * GST_SECOND; - GST_BUFFER_DURATION (buffer) = 250 * GST_MSECOND; - gst_buffer_set_caps (buffer, caps); - GST_DEBUG ("pushing buffer %p", buffer); - ret = gst_pad_chain (sinkpad, buffer); - fail_unless (ret == GST_FLOW_OK); - fail_unless (handoff_buffer == NULL); - - -} - -GST_END_TEST; - -static Suite * -adder_suite (void) -{ - Suite *s = suite_create ("adder"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_event); - tcase_add_test (tc_chain, test_play_twice); - tcase_add_test (tc_chain, test_play_twice_then_add_and_play_again); - tcase_add_test (tc_chain, test_live_seeking); - tcase_add_test (tc_chain, test_add_pad); - tcase_add_test (tc_chain, test_remove_pad); - tcase_add_test (tc_chain, test_clip); - - /* Use a longer timeout */ -#ifdef HAVE_VALGRIND - if (RUNNING_ON_VALGRIND) { - tcase_set_timeout (tc_chain, 5 * 60); - } else -#endif - { - /* this is shorter than the default 60 seconds?! (tpm) */ - /* tcase_set_timeout (tc_chain, 6); */ - } - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = adder_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/elements/alsa.c b/tests/check/elements/alsa.c deleted file mode 100644 index ddd95c73..00000000 --- a/tests/check/elements/alsa.c +++ /dev/null @@ -1,134 +0,0 @@ -/* GStreamer - * - * unit test for alsa elements - * - * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> - * - * 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 <unistd.h> - -#include <gst/check/gstcheck.h> -#include <gst/interfaces/propertyprobe.h> -#include <gst/interfaces/mixer.h> - -/* just a simple test that runs device probing on - * an alsasrc, alsasink and alsamixer instance */ - -GST_START_TEST (test_device_property_probe) -{ - const gchar *elements[] = { "alsasink", "alsasrc", "alsamixer" }; - gint n; - - for (n = 0; n < G_N_ELEMENTS (elements); ++n) { - GstPropertyProbe *probe; - GValueArray *arr; - GstElement *element; - gint i; - - element = gst_element_factory_make (elements[n], elements[n]); - fail_unless (element != NULL); - - probe = GST_PROPERTY_PROBE (element); - fail_unless (probe != NULL); - - arr = gst_property_probe_probe_and_get_values_name (probe, "device"); - if (arr) { - for (i = 0; i < arr->n_values; ++i) { - const gchar *device; - GValue *val; - - val = g_value_array_get_nth (arr, i); - fail_unless (val != NULL); - fail_unless (G_VALUE_HOLDS_STRING (val)); - - device = g_value_get_string (val); - fail_unless (device != NULL); - GST_LOG_OBJECT (element, "device[%d] = %s", i, device); - } - g_value_array_free (arr); - } else { - GST_LOG_OBJECT (element, "no devices found"); - } - - gst_object_unref (element); - } -} - -GST_END_TEST; - -GST_START_TEST (test_alsa_mixer_track) -{ - GstStateChangeReturn state_ret; - GstElement *mixer; - GList *tracks, *l; - - mixer = gst_element_factory_make ("alsamixer", "alsamixer"); - fail_unless (mixer != NULL, "Failed to create 'alsamixer' element!"); - - state_ret = gst_element_set_state (mixer, GST_STATE_READY); - if (state_ret != GST_STATE_CHANGE_SUCCESS) { - gst_object_unref (mixer); - return; - } - - GST_LOG ("opened alsamixer"); - fail_unless (GST_IS_MIXER (mixer), "is not a GstMixer?!"); - - tracks = (GList *) gst_mixer_list_tracks (GST_MIXER (mixer)); - for (l = tracks; l != NULL; l = l->next) { - GstMixerTrack *track; - gchar *ulabel = NULL, *label = NULL; - - track = GST_MIXER_TRACK (l->data); - g_object_get (track, "label", &label, "untranslated-label", &ulabel, NULL); - fail_unless (label == NULL || g_utf8_validate (label, -1, NULL)); - if (ulabel != NULL) { - gchar *p; - - for (p = ulabel; p != NULL && *p != '\0'; ++p) { - fail_unless (g_ascii_isprint (*p), - "untranslated label '%s' not printable ASCII", ulabel); - } - } - GST_DEBUG ("%s: %s", GST_STR_NULL (ulabel), GST_STR_NULL (label)); - g_free (label); - g_free (ulabel); - } - - fail_unless_equals_int (gst_element_set_state (mixer, GST_STATE_NULL), - GST_STATE_CHANGE_SUCCESS); - - gst_object_unref (mixer); -} - -GST_END_TEST; - -static Suite * -alsa_suite (void) -{ - Suite *s = suite_create ("alsa"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_device_property_probe); - tcase_add_test (tc_chain, test_alsa_mixer_track); - - return s; -} - -GST_CHECK_MAIN (alsa) diff --git a/tests/check/elements/appsink.c b/tests/check/elements/appsink.c deleted file mode 100644 index f8bc68d4..00000000 --- a/tests/check/elements/appsink.c +++ /dev/null @@ -1,357 +0,0 @@ -/* GStreamer - * - * Copyright (C) 2009, Axis Communications AB, LUND, SWEDEN - * - * 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 <gst/check/gstcheck.h> -#include <gst/app/gstappsink.h> - -gint global_testdata; - -static GstPad *mysrcpad; - -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("application/x-gst-check") - ); - -static GstElement * -setup_appsink (void) -{ - GstElement *appsink; - - GST_DEBUG ("setup_appsink"); - appsink = gst_check_setup_element ("appsink"); - mysrcpad = gst_check_setup_src_pad (appsink, &srctemplate, NULL); - - return appsink; -} - -static void -cleanup_appsink (GstElement * appsink) -{ - GST_DEBUG ("cleanup_appsink"); - - gst_check_teardown_src_pad (appsink); - gst_check_teardown_element (appsink); -} - -/* This function does an operation to it's indata argument and returns it. - * The exact operation performed doesn't matter. Currently it multiplies with - * two, but it could do anything. The idea is to use the function to verify - * that the code calling it gets run. */ -gint -operate_on_data (gint indata) -{ - return indata * 2; -} - -void -notify_test_function (gpointer userdata) -{ - global_testdata = operate_on_data (GPOINTER_TO_INT (userdata)); -} - -static GstFlowReturn -callback_function (GstAppSink * appsink, gpointer callback_data) -{ - global_testdata = operate_on_data (*((gint *) callback_data)); - - return GST_FLOW_OK; -} - -void -notify_function (gpointer callback_data) -{ - global_testdata = operate_on_data (*((gint *) callback_data)); -} - -GST_START_TEST (test_non_clients) -{ - GstElement *sink; - GstBuffer *buffer; - GstCaps *caps; - - sink = setup_appsink (); - - ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC); - - caps = gst_caps_from_string ("application/x-gst-check"); - buffer = gst_buffer_new_and_alloc (4); - gst_buffer_set_caps (buffer, caps); - gst_caps_unref (caps); - fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); - - GST_DEBUG ("cleaning up appsink"); - ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); - cleanup_appsink (sink); -} - -GST_END_TEST; - -/* Verifies that the handoff callback gets run one time when passing a buffer */ -GST_START_TEST (test_handoff_callback) -{ - GstElement *sink; - GstBuffer *buffer; - GstCaps *caps; - gint testdata; - GstAppSinkCallbacks callbacks = { NULL }; - - sink = setup_appsink (); - - global_testdata = 0; - testdata = 5; /* Arbitrary value */ - - callbacks.new_buffer = callback_function; - - gst_app_sink_set_callbacks (GST_APP_SINK (sink), &callbacks, &testdata, NULL); - - ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC); - - caps = gst_caps_from_string ("application/x-gst-check"); - buffer = gst_buffer_new_and_alloc (4); - gst_buffer_set_caps (buffer, caps); - gst_caps_unref (caps); - /* Pushing a buffer should run our callback */ - fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); - - testdata = operate_on_data (testdata); - - /* If both test_data & global_testdata have been operated on, we're happy. */ - fail_unless (testdata == global_testdata); - - GST_DEBUG ("cleaning up appsink"); - ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); - cleanup_appsink (sink); -} - -GST_END_TEST; - -/* Verifies that the notify function gets executed when the sink is destroyed */ -GST_START_TEST (test_notify0) -{ - GstElement *sink; - gint testdata; - GstAppSinkCallbacks callbacks = { NULL }; - - sink = gst_element_factory_make ("appsink", NULL); - - global_testdata = 0; - testdata = 17; /* Arbitrary value */ - - gst_app_sink_set_callbacks (GST_APP_SINK (sink), &callbacks, - &testdata, (*notify_function)); - - GST_DEBUG ("cleaning up appsink"); - /* Destroying sink should call our notify_function */ - gst_object_unref (sink); - - testdata = operate_on_data (testdata); - - /* If both test_data & global_testdata have been operated on, we're happy. */ - fail_unless (testdata == global_testdata); -} - -GST_END_TEST; - - -/* Verifies that the notify function gets executed when - * gst_app_sink_set_callbacks () gets called */ -GST_START_TEST (test_notify1) -{ - GstElement *sink; - gint testdata; - GstAppSinkCallbacks callbacks = { NULL }; - - sink = gst_element_factory_make ("appsink", NULL); - - global_testdata = 0; - testdata = 42; /* Arbitrary value */ - - gst_app_sink_set_callbacks (GST_APP_SINK (sink), &callbacks, - &testdata, (*notify_function)); - /* Setting new callbacks should trigger the destroy of the old data */ - gst_app_sink_set_callbacks (GST_APP_SINK (sink), &callbacks, &testdata, NULL); - - testdata = operate_on_data (testdata); - - /* If both test_data & global_testdata have been operated on, we're happy. */ - fail_unless (testdata == global_testdata); - - GST_DEBUG ("cleaning up appsink"); - gst_object_unref (sink); -} - -GST_END_TEST; - -static GstBufferList *mylist; -static GstCaps *mycaps; - -static GstBufferList * -create_buffer_list (void) -{ - GstBufferListIterator *it; - GstBuffer *buffer; - - mylist = gst_buffer_list_new (); - fail_if (mylist == NULL); - - mycaps = gst_caps_from_string ("application/x-gst-check"); - fail_if (mycaps == NULL); - - it = gst_buffer_list_iterate (mylist); - fail_if (it == NULL); - - gst_buffer_list_iterator_add_group (it); - - buffer = gst_buffer_new_and_alloc (sizeof (gint)); - *(gint *) GST_BUFFER_DATA (buffer) = 1; - gst_buffer_set_caps (buffer, mycaps); - gst_buffer_list_iterator_add (it, buffer); - - gst_buffer_list_iterator_add_group (it); - - buffer = gst_buffer_new_and_alloc (sizeof (gint)); - *(gint *) GST_BUFFER_DATA (buffer) = 2; - gst_buffer_set_caps (buffer, mycaps); - gst_buffer_list_iterator_add (it, buffer); - - buffer = gst_buffer_new_and_alloc (sizeof (gint)); - *(gint *) GST_BUFFER_DATA (buffer) = 4; - gst_buffer_set_caps (buffer, mycaps); - gst_buffer_list_iterator_add (it, buffer); - - gst_buffer_list_iterator_free (it); - - return mylist; -} - -static void -check_buffer_list (GstBufferList * list) -{ - GstBufferListIterator *it; - GstBuffer *buf; - GstCaps *caps; - - fail_unless (list == mylist); - fail_unless (gst_buffer_list_n_groups (list) == 2); - - it = gst_buffer_list_iterate (list); - fail_if (it == NULL); - - fail_unless (gst_buffer_list_iterator_next_group (it)); - fail_unless (gst_buffer_list_iterator_n_buffers (it) == 1); - buf = gst_buffer_list_iterator_next (it); - fail_if (buf == NULL); - fail_unless (*(gint *) GST_BUFFER_DATA (buf) == 1); - caps = gst_buffer_get_caps (buf); - fail_unless (caps == mycaps); - fail_unless (gst_caps_is_equal (caps, mycaps)); - gst_caps_unref (caps); - - fail_unless (gst_buffer_list_iterator_next_group (it)); - fail_unless (gst_buffer_list_iterator_n_buffers (it) == 2); - buf = gst_buffer_list_iterator_next (it); - fail_if (buf == NULL); - fail_unless (*(gint *) GST_BUFFER_DATA (buf) == 2); - caps = gst_buffer_get_caps (buf); - fail_unless (caps == mycaps); - gst_caps_unref (caps); - - buf = gst_buffer_list_iterator_next (it); - fail_if (buf == NULL); - fail_unless (*(gint *) GST_BUFFER_DATA (buf) == 4); - caps = gst_buffer_get_caps (buf); - fail_unless (caps == mycaps); - gst_caps_unref (caps); - - gst_buffer_list_iterator_free (it); -} - -static GstFlowReturn -callback_function_buffer_list (GstAppSink * appsink, gpointer callback_data) -{ - GstBufferList *list; - - list = gst_app_sink_pull_buffer_list (appsink); - fail_unless (GST_IS_BUFFER_LIST (list)); - - check_buffer_list (list); - - gst_buffer_list_unref (list); - - return GST_FLOW_OK; -} - -GST_START_TEST (test_buffer_list) -{ - GstElement *sink; - GstBufferList *list; - GstAppSinkCallbacks callbacks = { NULL }; - - sink = setup_appsink (); - - callbacks.new_buffer_list = callback_function_buffer_list; - - gst_app_sink_set_callbacks (GST_APP_SINK (sink), &callbacks, NULL, NULL); - - ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC); - - list = create_buffer_list (); - fail_unless (gst_pad_push_list (mysrcpad, list) == GST_FLOW_OK); - - ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); - cleanup_appsink (sink); -} - -GST_END_TEST; - -static Suite * -appsink_suite (void) -{ - Suite *s = suite_create ("appsink"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_non_clients); - tcase_add_test (tc_chain, test_handoff_callback); - tcase_add_test (tc_chain, test_notify0); - tcase_add_test (tc_chain, test_notify1); - tcase_add_test (tc_chain, test_buffer_list); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = appsink_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/elements/audioconvert.c b/tests/check/elements/audioconvert.c deleted file mode 100644 index 58c69dd8..00000000 --- a/tests/check/elements/audioconvert.c +++ /dev/null @@ -1,1741 +0,0 @@ -/* GStreamer - * - * unit test for audioconvert - * - * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org> - * Copyright (C) <2007> Tim-Philipp Müller <tim centricular net> - * - * 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 <unistd.h> - -#include <gst/floatcast/floatcast.h> -#include <gst/check/gstcheck.h> -#include <gst/audio/multichannel.h> - -/* For ease of programming we use globals to keep refs for our floating - * src and sink pads we create; otherwise we always have to do get_pad, - * get_peer, and then remove references in every test function */ -static GstPad *mysrcpad, *mysinkpad; - -#define CONVERT_CAPS_TEMPLATE_STRING \ - "audio/x-raw-float, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, MAX ], " \ - "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \ - "width = (int) { 32, 64 };" \ - "audio/x-raw-int, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, MAX ], " \ - "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \ - "width = (int) 32, " \ - "depth = (int) [ 1, 32 ], " \ - "signed = (boolean) { true, false }; " \ - "audio/x-raw-int, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, MAX ], " \ - "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \ - "width = (int) 24, " \ - "depth = (int) [ 1, 24 ], " \ - "signed = (boolean) { true, false }; " \ - "audio/x-raw-int, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, MAX ], " \ - "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \ - "width = (int) 16, " \ - "depth = (int) [ 1, 16 ], " \ - "signed = (boolean) { true, false }; " \ - "audio/x-raw-int, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, MAX ], " \ - "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \ - "width = (int) 8, " \ - "depth = (int) [ 1, 8 ], " \ - "signed = (boolean) { true, false } " - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (CONVERT_CAPS_TEMPLATE_STRING) - ); -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (CONVERT_CAPS_TEMPLATE_STRING) - ); - -/* takes over reference for outcaps */ -static GstElement * -setup_audioconvert (GstCaps * outcaps) -{ - GstElement *audioconvert; - - GST_DEBUG ("setup_audioconvert with caps %" GST_PTR_FORMAT, outcaps); - audioconvert = gst_check_setup_element ("audioconvert"); - g_object_set (G_OBJECT (audioconvert), "dithering", 0, NULL); - g_object_set (G_OBJECT (audioconvert), "noise-shaping", 0, NULL); - mysrcpad = gst_check_setup_src_pad (audioconvert, &srctemplate, NULL); - mysinkpad = gst_check_setup_sink_pad (audioconvert, &sinktemplate, NULL); - /* this installs a getcaps func that will always return the caps we set - * later */ - gst_pad_use_fixed_caps (mysinkpad); - gst_pad_set_caps (mysinkpad, outcaps); - gst_caps_unref (outcaps); - outcaps = gst_pad_get_negotiated_caps (mysinkpad); - fail_unless (gst_caps_is_fixed (outcaps)); - gst_caps_unref (outcaps); - - gst_pad_set_active (mysrcpad, TRUE); - gst_pad_set_active (mysinkpad, TRUE); - - return audioconvert; -} - -static void -cleanup_audioconvert (GstElement * audioconvert) -{ - GST_DEBUG ("cleanup_audioconvert"); - - gst_pad_set_active (mysrcpad, FALSE); - gst_pad_set_active (mysinkpad, FALSE); - gst_check_teardown_src_pad (audioconvert); - gst_check_teardown_sink_pad (audioconvert); - gst_check_teardown_element (audioconvert); -} - -/* returns a newly allocated caps */ -static GstCaps * -get_int_caps (guint channels, gchar * endianness, guint width, - guint depth, gboolean signedness) -{ - GstCaps *caps; - gchar *string; - - string = g_strdup_printf ("audio/x-raw-int, " - "rate = (int) 44100, " - "channels = (int) %d, " - "endianness = (int) %s, " - "width = (int) %d, " - "depth = (int) %d, " - "signed = (boolean) %s ", - channels, endianness, width, depth, signedness ? "true" : "false"); - GST_DEBUG ("creating caps from %s", string); - caps = gst_caps_from_string (string); - g_free (string); - fail_unless (caps != NULL); - GST_DEBUG ("returning caps %p", caps); - return caps; -} - -/* returns a newly allocated caps */ -static GstCaps * -get_float_caps (guint channels, gchar * endianness, guint width) -{ - GstCaps *caps; - gchar *string; - - string = g_strdup_printf ("audio/x-raw-float, " - "rate = (int) 44100, " - "channels = (int) %d, " - "endianness = (int) %s, " - "width = (int) %d ", channels, endianness, width); - GST_DEBUG ("creating caps from %s", string); - caps = gst_caps_from_string (string); - g_free (string); - fail_unless (caps != NULL); - GST_DEBUG ("returning caps %p", caps); - return caps; -} - -/* Copied from vorbis; the particular values used don't matter */ -static GstAudioChannelPosition channelpositions[][6] = { - { /* Mono */ - GST_AUDIO_CHANNEL_POSITION_FRONT_MONO}, - { /* Stereo */ - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, - { /* Stereo + Centre */ - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT}, - { /* Quadraphonic */ - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_REAR_LEFT, - GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT, - }, - { /* Stereo + Centre + rear stereo */ - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_REAR_LEFT, - GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT, - }, - { /* Full 5.1 Surround */ - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_REAR_LEFT, - GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT, - GST_AUDIO_CHANNEL_POSITION_LFE, - } -}; - -/* these are a bunch of random positions, they are mostly just - * different from the ones above, don't use elsewhere */ -static GstAudioChannelPosition mixed_up_positions[][6] = { - { - GST_AUDIO_CHANNEL_POSITION_FRONT_MONO}, - { - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, - { - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT}, - { - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT, - GST_AUDIO_CHANNEL_POSITION_REAR_LEFT, - }, - { - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_REAR_LEFT, - GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT, - }, - { - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT, - GST_AUDIO_CHANNEL_POSITION_REAR_LEFT, - GST_AUDIO_CHANNEL_POSITION_LFE, - } -}; - -/* we get this when recording from a soundcard with lots of input channels */ -static GstAudioChannelPosition undefined_positions[][15] = { - { - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE}, - { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE} -}; - -static void -set_channel_positions (GstCaps * caps, int channels, - GstAudioChannelPosition * channelpositions) -{ - GValue chanpos = { 0 }; - GValue pos = { 0 }; - GstStructure *structure = gst_caps_get_structure (caps, 0); - int c; - - g_value_init (&chanpos, GST_TYPE_ARRAY); - g_value_init (&pos, GST_TYPE_AUDIO_CHANNEL_POSITION); - - for (c = 0; c < channels; c++) { - g_value_set_enum (&pos, channelpositions[c]); - gst_value_array_append_value (&chanpos, &pos); - } - g_value_unset (&pos); - - gst_structure_set_value (structure, "channel-positions", &chanpos); - g_value_unset (&chanpos); -} - -/* For channels > 2, caps have to have channel positions. This adds some simple - * ones. Only implemented for channels between 1 and 6. - */ -static GstCaps * -get_float_mc_caps (guint channels, gchar * endianness, guint width, - gboolean mixed_up_layout) -{ - GstCaps *caps = get_float_caps (channels, endianness, width); - - if (channels <= 6) { - if (mixed_up_layout) - set_channel_positions (caps, channels, mixed_up_positions[channels - 1]); - else - set_channel_positions (caps, channels, channelpositions[channels - 1]); - } - - return caps; -} - -static GstCaps * -get_int_mc_caps (guint channels, gchar * endianness, guint width, - guint depth, gboolean signedness, gboolean mixed_up_layout) -{ - GstCaps *caps = get_int_caps (channels, endianness, width, depth, signedness); - - if (channels <= 6) { - if (mixed_up_layout) - set_channel_positions (caps, channels, mixed_up_positions[channels - 1]); - else - set_channel_positions (caps, channels, channelpositions[channels - 1]); - } - - return caps; -} - -/* eats the refs to the caps */ -static void -verify_convert (const gchar * which, void *in, int inlength, - GstCaps * incaps, void *out, int outlength, GstCaps * outcaps, - GstFlowReturn expected_flow) -{ - GstBuffer *inbuffer, *outbuffer; - GstElement *audioconvert; - - GST_DEBUG ("verifying conversion %s", which); - GST_DEBUG ("incaps: %" GST_PTR_FORMAT, incaps); - GST_DEBUG ("outcaps: %" GST_PTR_FORMAT, outcaps); - ASSERT_CAPS_REFCOUNT (incaps, "incaps", 1); - ASSERT_CAPS_REFCOUNT (outcaps, "outcaps", 1); - audioconvert = setup_audioconvert (outcaps); - ASSERT_CAPS_REFCOUNT (outcaps, "outcaps", 1); - - fail_unless (gst_element_set_state (audioconvert, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - GST_DEBUG ("Creating buffer of %d bytes", inlength); - inbuffer = gst_buffer_new_and_alloc (inlength); - memcpy (GST_BUFFER_DATA (inbuffer), in, inlength); - gst_buffer_set_caps (inbuffer, incaps); - ASSERT_CAPS_REFCOUNT (incaps, "incaps", 2); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference ... */ - GST_DEBUG ("push it"); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), expected_flow); - GST_DEBUG ("pushed it"); - - if (expected_flow != GST_FLOW_OK) - goto done; - - /* ... and puts a new buffer on the global list */ - fail_unless (g_list_length (buffers) == 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), outlength); - - if (memcmp (GST_BUFFER_DATA (outbuffer), out, outlength) != 0) { - g_print ("\nInput data:\n"); - gst_util_dump_mem (in, inlength); - g_print ("\nConverted data:\n"); - gst_util_dump_mem (GST_BUFFER_DATA (outbuffer), outlength); - g_print ("\nExpected data:\n"); - gst_util_dump_mem (out, outlength); - } - fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, outlength) == 0, - "failed converting %s", which); - - /* make sure that the channel positions are not lost */ - { - GstStructure *in_s, *out_s; - gint out_chans; - - in_s = gst_caps_get_structure (incaps, 0); - out_s = gst_caps_get_structure (GST_BUFFER_CAPS (outbuffer), 0); - fail_unless (gst_structure_get_int (out_s, "channels", &out_chans)); - - /* positions for 1 and 2 channels are implicit if not provided */ - if (out_chans > 2 && gst_structure_has_field (in_s, "channel-positions")) { - if (!gst_structure_has_field (out_s, "channel-positions")) { - g_error ("Channel layout got lost somewhere:\n\nIns : %s\nOuts: %s\n", - gst_structure_to_string (in_s), gst_structure_to_string (out_s)); - } - } - } - - buffers = g_list_remove (buffers, outbuffer); - gst_buffer_unref (outbuffer); - -done: - fail_unless (gst_element_set_state (audioconvert, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); - /* cleanup */ - GST_DEBUG ("cleanup audioconvert"); - cleanup_audioconvert (audioconvert); - GST_DEBUG ("cleanup, unref incaps"); - ASSERT_CAPS_REFCOUNT (incaps, "incaps", 1); - gst_caps_unref (incaps); -} - - -#define RUN_CONVERSION(which, inarray, in_get_caps, outarray, out_get_caps) \ - verify_convert (which, inarray, sizeof (inarray), \ - in_get_caps, outarray, sizeof (outarray), out_get_caps, GST_FLOW_OK) - -#define RUN_CONVERSION_TO_FAIL(which, inarray, in_caps, outarray, out_caps) \ - verify_convert (which, inarray, sizeof (inarray), \ - in_caps, outarray, sizeof (outarray), out_caps, GST_FLOW_NOT_NEGOTIATED) - - -GST_START_TEST (test_int16) -{ - /* stereo to mono */ - { - gint16 in[] = { 16384, -256, 1024, 1024 }; - gint16 out[] = { 8064, 1024 }; - - RUN_CONVERSION ("int16 stereo to mono", - in, get_int_caps (2, "BYTE_ORDER", 16, 16, TRUE), - out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)); - } - /* mono to stereo */ - { - gint16 in[] = { 512, 1024 }; - gint16 out[] = { 512, 512, 1024, 1024 }; - - RUN_CONVERSION ("int16 mono to stereo", - in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE), - out, get_int_caps (2, "BYTE_ORDER", 16, 16, TRUE)); - } - /* signed -> unsigned */ - { - gint16 in[] = { 0, -32767, 32767, -32768 }; - guint16 out[] = { 32768, 1, 65535, 0 }; - - RUN_CONVERSION ("int16 signed to unsigned", - in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE), - out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE)); - RUN_CONVERSION ("int16 unsigned to signed", - out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE), - in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)); - } -} - -GST_END_TEST; - - -GST_START_TEST (test_float32) -{ - /* stereo to mono */ - { - gfloat in[] = { 0.6, -0.0078125, 0.03125, 0.03125 }; - gfloat out[] = { 0.29609375, 0.03125 }; - - RUN_CONVERSION ("float32 stereo to mono", - in, get_float_caps (2, "BYTE_ORDER", 32), - out, get_float_caps (1, "BYTE_ORDER", 32)); - } - /* mono to stereo */ - { - gfloat in[] = { 0.015625, 0.03125 }; - gfloat out[] = { 0.015625, 0.015625, 0.03125, 0.03125 }; - - RUN_CONVERSION ("float32 mono to stereo", - in, get_float_caps (1, "BYTE_ORDER", 32), - out, get_float_caps (2, "BYTE_ORDER", 32)); - } -} - -GST_END_TEST; - - -GST_START_TEST (test_int_conversion) -{ - /* 8 <-> 16 signed */ - /* NOTE: if audioconvert was doing dithering we'd have a problem */ - { - gint8 in[] = { 0, 1, 2, 127, -127 }; - gint16 out[] = { 0, 256, 512, 32512, -32512 }; - - RUN_CONVERSION ("int 8bit to 16bit signed", - in, get_int_caps (1, "BYTE_ORDER", 8, 8, TRUE), - out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE) - ); - RUN_CONVERSION ("int 16bit signed to 8bit", - out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE), - in, get_int_caps (1, "BYTE_ORDER", 8, 8, TRUE) - ); - } - /* 16 -> 8 signed */ - { - gint16 in[] = { 0, 127, 128, 256, 256 + 127, 256 + 128 }; - gint8 out[] = { 0, 0, 1, 1, 1, 2 }; - - RUN_CONVERSION ("16 bit to 8 signed", - in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE), - out, get_int_caps (1, "BYTE_ORDER", 8, 8, TRUE) - ); - } - /* 8 unsigned <-> 16 signed */ - /* NOTE: if audioconvert was doing dithering we'd have a problem */ - { - guint8 in[] = { 128, 129, 130, 255, 1 }; - gint16 out[] = { 0, 256, 512, 32512, -32512 }; - GstCaps *incaps, *outcaps; - - /* exploded for easier valgrinding */ - incaps = get_int_caps (1, "BYTE_ORDER", 8, 8, FALSE); - outcaps = get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE); - GST_DEBUG ("incaps: %" GST_PTR_FORMAT, incaps); - GST_DEBUG ("outcaps: %" GST_PTR_FORMAT, outcaps); - RUN_CONVERSION ("8 unsigned to 16 signed", in, incaps, out, outcaps); - RUN_CONVERSION ("16 signed to 8 unsigned", out, get_int_caps (1, - "BYTE_ORDER", 16, 16, TRUE), in, get_int_caps (1, "BYTE_ORDER", 8, - 8, FALSE) - ); - } - /* 8 <-> 24 signed */ - /* NOTE: if audioconvert was doing dithering we'd have a problem */ - { - gint8 in[] = { 0, 1, 127 }; - guint8 out[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x7f }; - /* out has the bytes in little-endian, so that's how they should be - * interpreted during conversion */ - - RUN_CONVERSION ("8 to 24 signed", in, get_int_caps (1, "BYTE_ORDER", 8, 8, - TRUE), out, get_int_caps (1, "LITTLE_ENDIAN", 24, 24, TRUE) - ); - RUN_CONVERSION ("24 signed to 8", out, get_int_caps (1, "LITTLE_ENDIAN", 24, - 24, TRUE), in, get_int_caps (1, "BYTE_ORDER", 8, 8, TRUE) - ); - } - - /* 16 bit signed <-> unsigned */ - { - gint16 in[] = { 0, 128, -128 }; - guint16 out[] = { 32768, 32896, 32640 }; - RUN_CONVERSION ("16 signed to 16 unsigned", - in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE), - out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE) - ); - RUN_CONVERSION ("16 unsigned to 16 signed", - out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE), - in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE) - ); - } - - /* 16 bit signed <-> 8 in 16 bit signed */ - /* NOTE: if audioconvert was doing dithering we'd have a problem */ - { - gint16 in[] = { 0, 64 << 8, -64 << 8 }; - gint16 out[] = { 0, 64, -64 }; - RUN_CONVERSION ("16 signed to 8 in 16 signed", - in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE), - out, get_int_caps (1, "BYTE_ORDER", 16, 8, TRUE) - ); - RUN_CONVERSION ("8 in 16 signed to 16 signed", - out, get_int_caps (1, "BYTE_ORDER", 16, 8, TRUE), - in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE) - ); - } - - /* 16 bit unsigned <-> 8 in 16 bit unsigned */ - /* NOTE: if audioconvert was doing dithering we'd have a problem */ - { - guint16 in[] = { 1 << 15, (1 << 15) - (64 << 8), (1 << 15) + (64 << 8) }; - guint16 out[] = { 1 << 7, (1 << 7) - 64, (1 << 7) + 64 }; - RUN_CONVERSION ("16 unsigned to 8 in 16 unsigned", - in, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE), - out, get_int_caps (1, "BYTE_ORDER", 16, 8, FALSE) - ); - RUN_CONVERSION ("8 in 16 unsigned to 16 unsigned", - out, get_int_caps (1, "BYTE_ORDER", 16, 8, FALSE), - in, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE) - ); - } - - /* 32 bit signed -> 16 bit signed for rounding check */ - /* NOTE: if audioconvert was doing dithering we'd have a problem */ - { - gint32 in[] = { 0, G_MININT32, G_MAXINT32, - (32 << 16), (32 << 16) + (1 << 15), (32 << 16) - (1 << 15), - (32 << 16) + (2 << 15), (32 << 16) - (2 << 15), - (-32 << 16) + (1 << 15), (-32 << 16) - (1 << 15), - (-32 << 16) + (2 << 15), (-32 << 16) - (2 << 15), - (-32 << 16) - }; - gint16 out[] = { 0, G_MININT16, G_MAXINT16, - 32, 33, 32, - 33, 31, - -31, -32, - -31, -33, - -32 - }; - RUN_CONVERSION ("32 signed to 16 signed for rounding", - in, get_int_caps (1, "BYTE_ORDER", 32, 32, TRUE), - out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE) - ); - } - - /* 32 bit signed -> 16 bit unsigned for rounding check */ - /* NOTE: if audioconvert was doing dithering we'd have a problem */ - { - gint32 in[] = { 0, G_MININT32, G_MAXINT32, - (32 << 16), (32 << 16) + (1 << 15), (32 << 16) - (1 << 15), - (32 << 16) + (2 << 15), (32 << 16) - (2 << 15), - (-32 << 16) + (1 << 15), (-32 << 16) - (1 << 15), - (-32 << 16) + (2 << 15), (-32 << 16) - (2 << 15), - (-32 << 16) - }; - guint16 out[] = { (1 << 15), 0, G_MAXUINT16, - (1 << 15) + 32, (1 << 15) + 33, (1 << 15) + 32, - (1 << 15) + 33, (1 << 15) + 31, - (1 << 15) - 31, (1 << 15) - 32, - (1 << 15) - 31, (1 << 15) - 33, - (1 << 15) - 32 - }; - RUN_CONVERSION ("32 signed to 16 unsigned for rounding", - in, get_int_caps (1, "BYTE_ORDER", 32, 32, TRUE), - out, get_int_caps (1, "BYTE_ORDER", 16, 16, FALSE) - ); - } -} - -GST_END_TEST; - -GST_START_TEST (test_float_conversion) -{ - /* 32 float <-> 16 signed */ - /* NOTE: if audioconvert was doing dithering we'd have a problem */ - { - gfloat in_le[] = - { GFLOAT_TO_LE (0.0), GFLOAT_TO_LE (1.0), GFLOAT_TO_LE (-1.0), - GFLOAT_TO_LE (0.5), GFLOAT_TO_LE (-0.5), GFLOAT_TO_LE (1.1), - GFLOAT_TO_LE (-1.1) - }; - gfloat in_be[] = - { GFLOAT_TO_BE (0.0), GFLOAT_TO_BE (1.0), GFLOAT_TO_BE (-1.0), - GFLOAT_TO_BE (0.5), GFLOAT_TO_BE (-0.5), GFLOAT_TO_BE (1.1), - GFLOAT_TO_BE (-1.1) - }; - gint16 out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 }; - - /* only one direction conversion, the other direction does - * not produce exactly the same as the input due to floating - * point rounding errors etc. */ - RUN_CONVERSION ("32 float le to 16 signed", - in_le, get_float_caps (1, "LITTLE_ENDIAN", 32), - out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)); - RUN_CONVERSION ("32 float be to 16 signed", - in_be, get_float_caps (1, "BIG_ENDIAN", 32), - out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)); - } - - { - gint16 in[] = { 0, -32768, 16384, -16384 }; - gfloat out[] = { 0.0, -1.0, 0.5, -0.5 }; - - RUN_CONVERSION ("16 signed to 32 float", - in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE), - out, get_float_caps (1, "BYTE_ORDER", 32)); - } - - /* 64 float <-> 16 signed */ - /* NOTE: if audioconvert was doing dithering we'd have a problem */ - { - gdouble in_le[] = - { GDOUBLE_TO_LE (0.0), GDOUBLE_TO_LE (1.0), GDOUBLE_TO_LE (-1.0), - GDOUBLE_TO_LE (0.5), GDOUBLE_TO_LE (-0.5), GDOUBLE_TO_LE (1.1), - GDOUBLE_TO_LE (-1.1) - }; - gdouble in_be[] = - { GDOUBLE_TO_BE (0.0), GDOUBLE_TO_BE (1.0), GDOUBLE_TO_BE (-1.0), - GDOUBLE_TO_BE (0.5), GDOUBLE_TO_BE (-0.5), GDOUBLE_TO_BE (1.1), - GDOUBLE_TO_BE (-1.1) - }; - gint16 out[] = { 0, 32767, -32768, 16384, -16384, 32767, -32768 }; - - /* only one direction conversion, the other direction does - * not produce exactly the same as the input due to floating - * point rounding errors etc. */ - RUN_CONVERSION ("64 float LE to 16 signed", - in_le, get_float_caps (1, "LITTLE_ENDIAN", 64), - out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)); - RUN_CONVERSION ("64 float BE to 16 signed", - in_be, get_float_caps (1, "BIG_ENDIAN", 64), - out, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE)); - } - { - gint16 in[] = { 0, -32768, 16384, -16384 }; - gdouble out[] = { 0.0, - (gdouble) (-32768L << 16) / 2147483647.0, /* ~ -1.0 */ - (gdouble) (16384L << 16) / 2147483647.0, /* ~ 0.5 */ - (gdouble) (-16384L << 16) / 2147483647.0, /* ~ -0.5 */ - }; - - RUN_CONVERSION ("16 signed to 64 float", - in, get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE), - out, get_float_caps (1, "BYTE_ORDER", 64)); - } - { - gint32 in[] = { 0, (-1L << 31), (1L << 30), (-1L << 30) }; - gdouble out[] = { 0.0, - (gdouble) (-1L << 31) / 2147483647.0, /* ~ -1.0 */ - (gdouble) (1L << 30) / 2147483647.0, /* ~ 0.5 */ - (gdouble) (-1L << 30) / 2147483647.0, /* ~ -0.5 */ - }; - - RUN_CONVERSION ("32 signed to 64 float", - in, get_int_caps (1, "BYTE_ORDER", 32, 32, TRUE), - out, get_float_caps (1, "BYTE_ORDER", 64)); - } - - /* 64-bit float <-> 32-bit float */ - { - gdouble in[] = { 0.0, 1.0, -1.0, 0.5, -0.5 }; - gfloat out[] = { 0.0, 1.0, -1.0, 0.5, -0.5 }; - - RUN_CONVERSION ("64 float to 32 float", - in, get_float_caps (1, "BYTE_ORDER", 64), - out, get_float_caps (1, "BYTE_ORDER", 32)); - - RUN_CONVERSION ("32 float to 64 float", - out, get_float_caps (1, "BYTE_ORDER", 32), - in, get_float_caps (1, "BYTE_ORDER", 64)); - } - - /* 32-bit float little endian <-> big endian */ - { - gfloat le[] = { GFLOAT_TO_LE (0.0), GFLOAT_TO_LE (1.0), GFLOAT_TO_LE (-1.0), - GFLOAT_TO_LE (0.5), GFLOAT_TO_LE (-0.5) - }; - gfloat be[] = { GFLOAT_TO_BE (0.0), GFLOAT_TO_BE (1.0), GFLOAT_TO_BE (-1.0), - GFLOAT_TO_BE (0.5), GFLOAT_TO_BE (-0.5) - }; - - RUN_CONVERSION ("32 float LE to BE", - le, get_float_caps (1, "LITTLE_ENDIAN", 32), - be, get_float_caps (1, "BIG_ENDIAN", 32)); - - RUN_CONVERSION ("32 float BE to LE", - be, get_float_caps (1, "BIG_ENDIAN", 32), - le, get_float_caps (1, "LITTLE_ENDIAN", 32)); - } - - /* 64-bit float little endian <-> big endian */ - { - gdouble le[] = - { GDOUBLE_TO_LE (0.0), GDOUBLE_TO_LE (1.0), GDOUBLE_TO_LE (-1.0), - GDOUBLE_TO_LE (0.5), GDOUBLE_TO_LE (-0.5) - }; - gdouble be[] = - { GDOUBLE_TO_BE (0.0), GDOUBLE_TO_BE (1.0), GDOUBLE_TO_BE (-1.0), - GDOUBLE_TO_BE (0.5), GDOUBLE_TO_BE (-0.5) - }; - - RUN_CONVERSION ("64 float LE to BE", - le, get_float_caps (1, "LITTLE_ENDIAN", 64), - be, get_float_caps (1, "BIG_ENDIAN", 64)); - - RUN_CONVERSION ("64 float BE to LE", - be, get_float_caps (1, "BIG_ENDIAN", 64), - le, get_float_caps (1, "LITTLE_ENDIAN", 64)); - } -} - -GST_END_TEST; - - -GST_START_TEST (test_multichannel_conversion) -{ - { - gfloat in[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; - gfloat out[] = { 0.0, 0.0 }; - - RUN_CONVERSION ("3 channels to 1", in, get_float_mc_caps (3, - "BYTE_ORDER", 32, FALSE), out, get_float_caps (1, "BYTE_ORDER", - 32)); - RUN_CONVERSION ("1 channels to 3", out, get_float_caps (1, - "BYTE_ORDER", 32), in, get_float_mc_caps (3, "BYTE_ORDER", - 32, TRUE)); - } - - { - gint16 in[] = { 0, 0, 0, 0, 0, 0 }; - gint16 out[] = { 0, 0 }; - - RUN_CONVERSION ("3 channels to 1", in, get_int_mc_caps (3, - "BYTE_ORDER", 16, 16, TRUE, FALSE), out, get_int_caps (1, - "BYTE_ORDER", 16, 16, TRUE)); - RUN_CONVERSION ("1 channels to 3", out, get_int_caps (1, "BYTE_ORDER", 16, - 16, TRUE), in, get_int_mc_caps (3, "BYTE_ORDER", 16, 16, TRUE, - TRUE)); - } - - { - gint16 in[] = { 1, 2 }; - gint16 out[] = { 1, 1, 2, 2 }; - GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[1] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO }; - GstAudioChannelPosition out_layout[2] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT - }; - - set_channel_positions (in_caps, 1, in_layout); - set_channel_positions (out_caps, 2, out_layout); - - RUN_CONVERSION ("1 channels to 2 with standard layout", in, - in_caps, out, out_caps); - } - - { - gint16 in[] = { 1, 2 }; - gint16 out[] = { 1, 1, 2, 2 }; - GstCaps *in_caps = get_int_caps (1, "BYTE_ORDER", 16, 16, TRUE); - GstCaps *out_caps = get_int_caps (2, "BYTE_ORDER", 16, 16, TRUE); - - RUN_CONVERSION ("1 channels to 2 with standard layout and no positions set", - in, gst_caps_copy (in_caps), out, gst_caps_copy (out_caps)); - - RUN_CONVERSION ("2 channels to 1 with standard layout and no positions set", - out, out_caps, in, in_caps); - } - - { - gint16 in[] = { 1, 2 }; - gint16 out[] = { 1, 0, 2, 0 }; - GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[1] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT }; - GstAudioChannelPosition out_layout[2] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT - }; - - set_channel_positions (in_caps, 1, in_layout); - set_channel_positions (out_caps, 2, out_layout); - - RUN_CONVERSION ("1 channels to 2 with non-standard layout", in, - in_caps, out, out_caps); - } - - { - gint16 in[] = { 1, 2, 3, 4 }; - gint16 out[] = { 2, 4 }; - GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[2] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT - }; - GstAudioChannelPosition out_layout[1] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER }; - - set_channel_positions (in_caps, 2, in_layout); - set_channel_positions (out_caps, 1, out_layout); - - RUN_CONVERSION ("2 channels to 1 with non-standard layout", in, - in_caps, out, out_caps); - } - - { - gint16 in[] = { 1, 2, 3, 4 }; - gint16 out[] = { 2, 4 }; - GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[2] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT - }; - GstAudioChannelPosition out_layout[1] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO }; - - set_channel_positions (in_caps, 2, in_layout); - set_channel_positions (out_caps, 1, out_layout); - - RUN_CONVERSION ("2 channels to 1 with standard layout", in, - in_caps, out, out_caps); - } - - { - gint16 in[] = { 1, 2, 3, 4 }; - gint16 out[] = { 1, 3 }; - GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[2] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_REAR_CENTER - }; - GstAudioChannelPosition out_layout[1] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO }; - - set_channel_positions (in_caps, 2, in_layout); - set_channel_positions (out_caps, 1, out_layout); - - RUN_CONVERSION ("2 channels to 1 with non-standard layout", in, - in_caps, out, out_caps); - } - - { - gint16 in[] = { 1, 2, 3, 4 }; - gint16 out[] = { 1, 3 }; - GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[2] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_REAR_LEFT - }; - GstAudioChannelPosition out_layout[1] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO }; - - set_channel_positions (in_caps, 2, in_layout); - set_channel_positions (out_caps, 1, out_layout); - - RUN_CONVERSION ("2 channels to 1 with non-standard layout", in, - in_caps, out, out_caps); - } - { - gint16 in[] = { 4, 5, 4, 2, 2, 1 }; - gint16 out[] = { 3, 3 }; - GstCaps *in_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_caps (2, "BYTE_ORDER", 16, 16, TRUE); - - RUN_CONVERSION ("5.1 to 2 channels", in, in_caps, out, out_caps); - } - { - gint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - gint16 out[] = { 0, 0 }; - GstCaps *in_caps = get_int_mc_caps (11, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[11] = { - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_REAR_CENTER, - GST_AUDIO_CHANNEL_POSITION_REAR_LEFT, - GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT, - GST_AUDIO_CHANNEL_POSITION_LFE, - GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER, - GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT, - GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT, - }; - - set_channel_positions (in_caps, 11, in_layout); - - RUN_CONVERSION ("11 channels to 2", in, - gst_caps_copy (in_caps), out, gst_caps_copy (out_caps)); - RUN_CONVERSION ("2 channels to 11", out, out_caps, in, in_caps); - } - -} - -GST_END_TEST; - -/* for testing channel remapping with 8 channels */ -static GstAudioChannelPosition n8chan_pos_remap_in[8] = { - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_REAR_LEFT, - GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT, - GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_LFE, - GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT, - GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT -}; -static GstAudioChannelPosition n8chan_pos_remap_out[8] = { - GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT, - GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT, - GST_AUDIO_CHANNEL_POSITION_REAR_LEFT, - GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT, - GST_AUDIO_CHANNEL_POSITION_LFE -}; - -GST_START_TEST (test_channel_remapping) -{ - /* float */ - { - gfloat in[] = { 0.0, 1.0, -0.5 }; - gfloat out[] = { -0.5, 1.0, 0.0 }; - GstCaps *in_caps = get_float_mc_caps (3, "BYTE_ORDER", 32, FALSE); - GstCaps *out_caps = get_float_mc_caps (3, "BYTE_ORDER", 32, TRUE); - - RUN_CONVERSION ("3 channels layout remapping float", in, in_caps, - out, out_caps); - } - - /* int */ - { - guint16 in[] = { 0, 65535, 0x9999 }; - guint16 out[] = { 0x9999, 65535, 0 }; - GstCaps *in_caps = get_int_mc_caps (3, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_int_mc_caps (3, "BYTE_ORDER", 16, 16, FALSE, TRUE); - - RUN_CONVERSION ("3 channels layout remapping int", in, in_caps, - out, out_caps); - } - - /* int with 8 channels (= largest number allowed with channel positions) */ - { - guint16 in[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; - guint16 out[] = { 4, 0, 1, 6, 7, 2, 3, 5 }; - GstCaps *in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, TRUE); - - set_channel_positions (in_caps, 8, n8chan_pos_remap_in); - set_channel_positions (out_caps, 8, n8chan_pos_remap_out); - - RUN_CONVERSION ("8 channels layout remapping int", in, in_caps, - out, out_caps); - } - - /* int16 to int32 with 8 channels (= largest number allowed with channel positions) */ - { - guint16 in[] = { 0, 1, 2, 3, 4, 5, 6, 7 }; - guint32 out[] = - { 4 << 16, 0, 1 << 16, 6 << 16, 7 << 16, 2 << 16, 3 << 16, 5 << 16 }; - GstCaps *in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_int_mc_caps (8, "BYTE_ORDER", 32, 32, FALSE, TRUE); - - set_channel_positions (in_caps, 8, n8chan_pos_remap_in); - set_channel_positions (out_caps, 8, n8chan_pos_remap_out); - - RUN_CONVERSION ("8 channels layout remapping int16 --> int32", in, in_caps, - out, out_caps); - - in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, FALSE); - out_caps = get_int_mc_caps (8, "BYTE_ORDER", 32, 32, FALSE, TRUE); - set_channel_positions (in_caps, 8, n8chan_pos_remap_in); - set_channel_positions (out_caps, 8, n8chan_pos_remap_out); - RUN_CONVERSION ("8 channels layout remapping int16 <-- int32", out, - out_caps, in, in_caps); - } - - /* float to gint16 with 3 channels */ - { - gfloat in[] = { 100.0 / G_MAXINT16, 0.0, -100.0 / G_MAXINT16 }; - gint16 out[] = { -100, 0, 100 }; - GstCaps *in_caps = get_float_mc_caps (3, "BYTE_ORDER", 32, TRUE); - GstCaps *out_caps = get_int_mc_caps (3, "BYTE_ORDER", 16, 16, TRUE, FALSE); - - RUN_CONVERSION ("3 channels layout remapping float32 --> int16", in, - in_caps, out, out_caps); - } - - /* gint16 to gint16 with 2 channels and non-standard layout */ - { - gint16 in[] = { 1, 2, 3, 4 }; - gint16 out[] = { 1, 2, 2, 4 }; - GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[2] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_LFE - }; - GstAudioChannelPosition out_layout[2] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT - }; - - set_channel_positions (in_caps, 2, in_layout); - set_channel_positions (out_caps, 2, out_layout); - - RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in, - in_caps, out, out_caps); - } - - /* gint16 to gint16 with 2 channels and non-standard layout */ - { - gint16 in[] = { 1, 2, 3, 4 }; - gint16 out[] = { 2, 1, 4, 3 }; - GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[2] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT - }; - GstAudioChannelPosition out_layout[2] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT - }; - - set_channel_positions (in_caps, 2, in_layout); - set_channel_positions (out_caps, 2, out_layout); - - RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in, - in_caps, out, out_caps); - } - - /* gint16 to gint16 with 2 channels and non-standard layout */ - { - gint16 in[] = { 1, 2, 3, 4 }; - gint16 out[] = { 1, 1, 3, 3 }; - GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[2] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_REAR_CENTER - }; - GstAudioChannelPosition out_layout[2] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT - }; - - set_channel_positions (in_caps, 2, in_layout); - set_channel_positions (out_caps, 2, out_layout); - - RUN_CONVERSION ("2 channels layout remapping int16 --> int16", in, - in_caps, out, out_caps); - } - - /* gint16 to gint16 with 1 channel and non-standard layout */ - { - gint16 in[] = { 1, 2, 3, 4 }; - gint16 out[] = { 0, 0, 0, 0 }; - GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[1] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT }; - GstAudioChannelPosition out_layout[1] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT }; - - set_channel_positions (in_caps, 1, in_layout); - set_channel_positions (out_caps, 1, out_layout); - - RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in, - in_caps, out, out_caps); - } - - /* gint16 to gint16 with 1 channel and non-standard layout */ - { - gint16 in[] = { 1, 2, 3, 4 }; - gint16 out[] = { 1, 2, 3, 4 }; - GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[1] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO }; - GstAudioChannelPosition out_layout[1] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER }; - - set_channel_positions (in_caps, 1, in_layout); - set_channel_positions (out_caps, 1, out_layout); - - RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in, - in_caps, out, out_caps); - } - - /* gint16 to gint16 with 1 channel and non-standard layout */ - { - gint16 in[] = { 1, 2, 3, 4 }; - gint16 out[] = { 1, 2, 3, 4 }; - GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstAudioChannelPosition in_layout[1] = - { GST_AUDIO_CHANNEL_POSITION_FRONT_MONO }; - GstAudioChannelPosition out_layout[1] = - { GST_AUDIO_CHANNEL_POSITION_REAR_LEFT }; - - set_channel_positions (in_caps, 1, in_layout); - set_channel_positions (out_caps, 1, out_layout); - - RUN_CONVERSION ("1 channels layout remapping int16 --> int16", in, - in_caps, out, out_caps); - } -} - -GST_END_TEST; - -GST_START_TEST (test_caps_negotiation) -{ - GstElement *src, *ac1, *ac2, *ac3, *sink; - GstElement *pipeline; - GstPad *ac3_src; - GstCaps *caps1, *caps2; - - pipeline = gst_pipeline_new ("test"); - - /* create elements */ - src = gst_element_factory_make ("audiotestsrc", "src"); - ac1 = gst_element_factory_make ("audioconvert", "ac1"); - ac2 = gst_element_factory_make ("audioconvert", "ac2"); - ac3 = gst_element_factory_make ("audioconvert", "ac3"); - sink = gst_element_factory_make ("fakesink", "sink"); - ac3_src = gst_element_get_static_pad (ac3, "src"); - - /* test with 2 audioconvert elements */ - gst_bin_add_many (GST_BIN (pipeline), src, ac1, ac3, sink, NULL); - gst_element_link_many (src, ac1, ac3, sink, NULL); - - /* Set to PAUSED and wait for PREROLL */ - fail_if (gst_element_set_state (pipeline, GST_STATE_PAUSED) == - GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline to PAUSED"); - fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) != - GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline to PAUSED"); - - caps1 = gst_pad_get_caps (ac3_src); - fail_if (caps1 == NULL, "gst_pad_get_caps returned NULL"); - GST_DEBUG ("Caps size 1 : %d", gst_caps_get_size (caps1)); - - fail_if (gst_element_set_state (pipeline, GST_STATE_READY) == - GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to READY"); - fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) != - GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to READY"); - - /* test with 3 audioconvert elements */ - gst_element_unlink (ac1, ac3); - gst_bin_add (GST_BIN (pipeline), ac2); - gst_element_link_many (ac1, ac2, ac3, NULL); - - fail_if (gst_element_set_state (pipeline, GST_STATE_PAUSED) == - GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to PAUSED"); - fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) != - GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to PAUSED"); - - caps2 = gst_pad_get_caps (ac3_src); - - fail_if (caps2 == NULL, "gst_pad_get_caps returned NULL"); - GST_DEBUG ("Caps size 2 : %d", gst_caps_get_size (caps2)); - fail_unless (gst_caps_get_size (caps1) == gst_caps_get_size (caps2)); - - gst_caps_unref (caps1); - gst_caps_unref (caps2); - - fail_if (gst_element_set_state (pipeline, GST_STATE_NULL) == - GST_STATE_CHANGE_FAILURE, "Failed to set test pipeline back to NULL"); - fail_if (gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE) != - GST_STATE_CHANGE_SUCCESS, "Failed to set test pipeline back to NULL"); - - gst_object_unref (ac3_src); - gst_object_unref (pipeline); -} - -GST_END_TEST; - -GST_START_TEST (test_convert_undefined_multichannel) -{ - /* (A) CONVERSION FROM 'WORSE' TO 'BETTER' FORMAT */ - - /* 1 channel, NONE positions, int8 => int16 */ - { - guint16 out[] = { 0x2000 }; - guint8 in[] = { 0x20 }; - GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 8, 8, FALSE, FALSE); - - set_channel_positions (out_caps, 1, undefined_positions[1 - 1]); - set_channel_positions (in_caps, 1, undefined_positions[1 - 1]); - - RUN_CONVERSION ("1 channel, undefined layout, identity conversion, " - "int8 => int16", in, in_caps, out, out_caps); - } - - /* 2 channels, NONE positions, int8 => int16 */ - { - guint16 out[] = { 0x8000, 0x2000 }; - guint8 in[] = { 0x80, 0x20 }; - GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 8, 8, FALSE, FALSE); - - set_channel_positions (out_caps, 2, undefined_positions[2 - 1]); - set_channel_positions (in_caps, 2, undefined_positions[2 - 1]); - - RUN_CONVERSION ("2 channels, undefined layout, identity conversion, " - "int8 => int16", in, in_caps, out, out_caps); - } - - /* 6 channels, NONE positions, int8 => int16 */ - { - guint16 out[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 }; - guint8 in[] = { 0x00, 0x20, 0x80, 0x20, 0x00, 0xff }; - GstCaps *out_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *in_caps = get_int_mc_caps (6, "BYTE_ORDER", 8, 8, FALSE, FALSE); - - set_channel_positions (out_caps, 6, undefined_positions[6 - 1]); - set_channel_positions (in_caps, 6, undefined_positions[6 - 1]); - - RUN_CONVERSION ("6 channels, undefined layout, identity conversion, " - "int8 => int16", in, in_caps, out, out_caps); - } - - /* 9 channels, NONE positions, int8 => int16 */ - { - guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, - 0x0000, 0xff00, 0x0000 - }; - guint8 in[] = { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00 }; - GstCaps *out_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 8, 8, FALSE, FALSE); - - set_channel_positions (out_caps, 9, undefined_positions[9 - 1]); - set_channel_positions (in_caps, 9, undefined_positions[9 - 1]); - - RUN_CONVERSION ("9 channels, undefined layout, identity conversion, " - "int8 => int16", in, in_caps, out, out_caps); - } - - /* 15 channels, NONE positions, int8 => int16 */ - { - guint16 out[] = - { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00, - 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, 0x0000 - }; - guint8 in[] = - { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00, 0xff, 0x00, - 0x20, 0x80, 0x20, 0x00 - }; - GstCaps *out_caps = - get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 8, 8, FALSE, FALSE); - - set_channel_positions (out_caps, 15, undefined_positions[15 - 1]); - set_channel_positions (in_caps, 15, undefined_positions[15 - 1]); - - RUN_CONVERSION ("15 channels, undefined layout, identity conversion, " - "int8 => int16", in, in_caps, out, out_caps); - } - - /* (B) CONVERSION FROM 'BETTER' TO 'WORSE' FORMAT */ - - /* 1 channel, NONE positions, int16 => int8 */ - { - guint16 in[] = { 0x2000 }; - guint8 out[] = { 0x20 }; - GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 8, 8, FALSE, FALSE); - - set_channel_positions (out_caps, 1, undefined_positions[1 - 1]); - set_channel_positions (in_caps, 1, undefined_positions[1 - 1]); - - RUN_CONVERSION ("1 channel, undefined layout, identity conversion, " - "int16 => int8", in, in_caps, out, out_caps); - } - - /* 2 channels, NONE positions, int16 => int8 */ - { - guint16 in[] = { 0x8000, 0x2000 }; - guint8 out[] = { 0x80, 0x20 }; - GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 8, 8, FALSE, FALSE); - - set_channel_positions (out_caps, 2, undefined_positions[2 - 1]); - set_channel_positions (in_caps, 2, undefined_positions[2 - 1]); - - RUN_CONVERSION ("2 channels, undefined layout, identity conversion, " - "int16 => int8", in, in_caps, out, out_caps); - } - - /* 6 channels, NONE positions, int16 => int8 */ - { - guint16 in[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 }; - guint8 out[] = { 0x00, 0x20, 0x80, 0x20, 0x00, 0xff }; - GstCaps *in_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_int_mc_caps (6, "BYTE_ORDER", 8, 8, FALSE, FALSE); - - set_channel_positions (out_caps, 6, undefined_positions[6 - 1]); - set_channel_positions (in_caps, 6, undefined_positions[6 - 1]); - - RUN_CONVERSION ("6 channels, undefined layout, identity conversion, " - "int16 => int8", in, in_caps, out, out_caps); - } - - /* 9 channels, NONE positions, int16 => int8 */ - { - guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, - 0x0000, 0xff00, 0x0000 - }; - guint8 out[] = { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00 }; - GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_int_mc_caps (9, "BYTE_ORDER", 8, 8, FALSE, FALSE); - - set_channel_positions (out_caps, 9, undefined_positions[9 - 1]); - set_channel_positions (in_caps, 9, undefined_positions[9 - 1]); - - RUN_CONVERSION ("9 channels, undefined layout, identity conversion, " - "int16 => int8", in, in_caps, out, out_caps); - } - - /* 15 channels, NONE positions, int16 => int8 */ - { - guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, - 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, - 0x0000 - }; - guint8 out[] = - { 0x00, 0xff, 0x00, 0x20, 0x80, 0x20, 0x00, 0xff, 0x00, 0xff, 0x00, - 0x20, 0x80, 0x20, 0x00 - }; - GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_int_mc_caps (15, "BYTE_ORDER", 8, 8, FALSE, FALSE); - - set_channel_positions (out_caps, 15, undefined_positions[15 - 1]); - set_channel_positions (in_caps, 15, undefined_positions[15 - 1]); - - RUN_CONVERSION ("15 channels, undefined layout, identity conversion, " - "int16 => int8", in, in_caps, out, out_caps); - } - - - /* (C) NO CONVERSION, SAME FORMAT */ - - /* 1 channel, NONE positions, int16 => int16 */ - { - guint16 in[] = { 0x2000 }; - guint16 out[] = { 0x2000 }; - GstCaps *in_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_int_mc_caps (1, "BYTE_ORDER", 16, 16, FALSE, FALSE); - - set_channel_positions (out_caps, 1, undefined_positions[1 - 1]); - set_channel_positions (in_caps, 1, undefined_positions[1 - 1]); - - RUN_CONVERSION ("1 channel, undefined layout, identity conversion, " - "int16 => int16", in, in_caps, out, out_caps); - } - - /* 2 channels, NONE positions, int16 => int16 */ - { - guint16 in[] = { 0x8000, 0x2000 }; - guint16 out[] = { 0x8000, 0x2000 }; - GstCaps *in_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, FALSE, FALSE); - - set_channel_positions (out_caps, 2, undefined_positions[2 - 1]); - set_channel_positions (in_caps, 2, undefined_positions[2 - 1]); - - RUN_CONVERSION ("2 channels, undefined layout, identity conversion, " - "int16 => int16", in, in_caps, out, out_caps); - } - - /* 6 channels, NONE positions, int16 => int16 */ - { - guint16 in[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 }; - guint16 out[] = { 0x0000, 0x2000, 0x8000, 0x2000, 0x0000, 0xff00 }; - GstCaps *in_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_int_mc_caps (6, "BYTE_ORDER", 16, 16, FALSE, FALSE); - - set_channel_positions (out_caps, 6, undefined_positions[6 - 1]); - set_channel_positions (in_caps, 6, undefined_positions[6 - 1]); - - RUN_CONVERSION ("6 channels, undefined layout, identity conversion, " - "int16 => int16", in, in_caps, out, out_caps); - } - - /* 9 channels, NONE positions, int16 => int16 */ - { - guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, - 0x0000, 0xff00, 0x0000 - }; - guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, - 0x0000, 0xff00, 0x0000 - }; - GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE); - - set_channel_positions (out_caps, 9, undefined_positions[9 - 1]); - set_channel_positions (in_caps, 9, undefined_positions[9 - 1]); - - RUN_CONVERSION ("9 channels, undefined layout, identity conversion, " - "int16 => int16", in, in_caps, out, out_caps); - } - - /* 15 channels, NONE positions, int16 => int16 */ - { - guint16 in[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, - 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, - 0x0000 - }; - guint16 out[] = { 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, - 0x0000, 0xff00, 0x0000, 0xff00, 0x0000, 0x2000, 0x8000, 0x2000, - 0x0000 - }; - GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = - get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE); - - set_channel_positions (out_caps, 15, undefined_positions[15 - 1]); - set_channel_positions (in_caps, 15, undefined_positions[15 - 1]); - - RUN_CONVERSION ("15 channels, undefined layout, identity conversion, " - "int16 => int16", in, in_caps, out, out_caps); - } - - - /* (C) int16 => float */ - - /* 9 channels, NONE positions, int16 => float */ - { - guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000, - 0x0000, 0x8000, 0x0000 - }; - gfloat out[] = { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0 }; - GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_float_mc_caps (9, "BYTE_ORDER", 32, FALSE); - - set_channel_positions (out_caps, 9, undefined_positions[9 - 1]); - set_channel_positions (in_caps, 9, undefined_positions[9 - 1]); - - RUN_CONVERSION ("9 channels, undefined layout, identity conversion, " - "int16 => float", in, in_caps, out, out_caps); - } - - /* 15 channels, NONE positions, int16 => float */ - { - guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000, - 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000, - 0x0000 - }; - gfloat out[] = - { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 0.0, -1.0, 0.0, 0.0, - 0.0, -1.0 - }; - GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_float_mc_caps (15, "BYTE_ORDER", 32, FALSE); - - set_channel_positions (out_caps, 15, undefined_positions[15 - 1]); - set_channel_positions (in_caps, 15, undefined_positions[15 - 1]); - - RUN_CONVERSION ("15 channels, undefined layout, identity conversion, " - "int16 => float", in, in_caps, out, out_caps); - } - - - /* 9 channels, NONE positions, int16 => float (same as above, but no - * position on output caps to see if audioconvert transforms correctly) */ - { - guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000, - 0x0000, 0x8000, 0x0000 - }; - gfloat out[] = { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0 }; - GstCaps *in_caps = get_int_mc_caps (9, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_float_mc_caps (9, "BYTE_ORDER", 32, FALSE); - - //set_channel_positions (out_caps, 9, undefined_positions[9 - 1]); - set_channel_positions (in_caps, 9, undefined_positions[9 - 1]); - - RUN_CONVERSION ("9 channels, undefined layout, identity conversion, " - "int16 => float", in, in_caps, out, out_caps); - } - - /* 15 channels, NONE positions, int16 => float (same as above, but no - * position on output caps to see if audioconvert transforms correctly) */ - { - guint16 in[] = { 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000, - 0x0000, 0x8000, 0x0000, 0x8000, 0x0000, 0x8000, 0x8000, 0x8000, - 0x0000 - }; - gfloat out[] = - { -1.0, 0.0, -1.0, 0.0, 0.0, 0.0, -1.0, 0.0, -1.0, 0.0, -1.0, 0.0, 0.0, - 0.0, -1.0 - }; - GstCaps *in_caps = get_int_mc_caps (15, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_float_mc_caps (15, "BYTE_ORDER", 32, FALSE); - - //set_channel_positions (out_caps, 9, undefined_positions[9 - 1]); - set_channel_positions (in_caps, 15, undefined_positions[15 - 1]); - - RUN_CONVERSION ("15 channels, undefined layout, identity conversion, " - "int16 => float", in, in_caps, out, out_caps); - } - - /* 8 channels, NONE positions => 2 channels: should fail, no mixing allowed */ - { - guint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - gfloat out[] = { -1.0, -1.0 }; - GstCaps *in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, FALSE, FALSE); - GstCaps *out_caps = get_float_mc_caps (2, "BYTE_ORDER", 32, FALSE); - - set_channel_positions (in_caps, 8, undefined_positions[8 - 1]); - - RUN_CONVERSION_TO_FAIL ("8 channels with layout => 2 channels", - in, in_caps, out, out_caps); - } - - /* 8 channels, with positions => 2 channels (makes sure channel-position - * fields are removed properly in some cases in ::transform_caps, so we - * don't up with caps with 2 channels and 8 channel positions) */ - { - GstAudioChannelPosition layout8ch[] = { - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_REAR_LEFT, - GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT, - GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - GST_AUDIO_CHANNEL_POSITION_LFE, - GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT, - GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT - }; - gint16 in[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - gint16 out[] = { 0, 0 }; - GstCaps *in_caps = get_int_mc_caps (8, "BYTE_ORDER", 16, 16, TRUE, FALSE); - GstCaps *out_caps = get_int_mc_caps (2, "BYTE_ORDER", 16, 16, TRUE, FALSE); - - set_channel_positions (in_caps, 8, layout8ch); - - RUN_CONVERSION ("8 channels with layout => 2 channels", - in, in_caps, out, out_caps); - } -} - -GST_END_TEST; - -static Suite * -audioconvert_suite (void) -{ - Suite *s = suite_create ("audioconvert"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_int16); - tcase_add_test (tc_chain, test_float32); - tcase_add_test (tc_chain, test_int_conversion); - tcase_add_test (tc_chain, test_float_conversion); - tcase_add_test (tc_chain, test_multichannel_conversion); - tcase_add_test (tc_chain, test_channel_remapping); - tcase_add_test (tc_chain, test_caps_negotiation); - tcase_add_test (tc_chain, test_convert_undefined_multichannel); - - return s; -} - -GST_CHECK_MAIN (audioconvert); diff --git a/tests/check/elements/audiorate.c b/tests/check/elements/audiorate.c deleted file mode 100644 index 75654dd5..00000000 --- a/tests/check/elements/audiorate.c +++ /dev/null @@ -1,469 +0,0 @@ -/* GStreamer unit tests for audiorate - * - * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <gst/check/gstcheck.h> - -/* helper element to insert additional buffers overlapping with previous ones */ -static gdouble injector_inject_probability = 0.0; - -typedef GstElement TestInjector; -typedef GstElementClass TestInjectorClass; - -GST_BOILERPLATE (TestInjector, test_injector, GstElement, GST_TYPE_ELEMENT); - -#define INJECTOR_CAPS \ - "audio/x-raw-float, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, 8 ], " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 32;" \ - "audio/x-raw-int, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, 8 ], " \ - "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " \ - "width = (int) { 8, 16, 32 }, " \ - "depth = (int) [ 1, 32 ], " \ - "signed = (boolean) { true, false }" - -static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (INJECTOR_CAPS)); - -static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (INJECTOR_CAPS)); - -static void -test_injector_base_init (gpointer g_class) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_template)); -} - -static void -test_injector_class_init (TestInjectorClass * klass) -{ - /* nothing to do here */ -} - -static GstFlowReturn -test_injector_chain (GstPad * pad, GstBuffer * buf) -{ - GstFlowReturn ret; - GstPad *srcpad; - - srcpad = - gst_element_get_static_pad (GST_ELEMENT (GST_PAD_PARENT (pad)), "src"); - - /* since we're increasing timestamp/offsets, push this one first */ - GST_LOG (" passing buffer [t=%" GST_TIME_FORMAT "-%" GST_TIME_FORMAT - "], offset=%" G_GINT64_FORMAT ", offset_end=%" G_GINT64_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf)), - GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf)); - - gst_buffer_ref (buf); - - ret = gst_pad_push (srcpad, buf); - - if (g_random_double () < injector_inject_probability) { - GstBuffer *ibuf; - - ibuf = gst_buffer_copy (buf); - - if (GST_BUFFER_OFFSET_IS_VALID (buf) && - GST_BUFFER_OFFSET_END_IS_VALID (buf)) { - guint64 delta; - - delta = GST_BUFFER_OFFSET_END (buf) - GST_BUFFER_OFFSET (buf); - GST_BUFFER_OFFSET (ibuf) += delta / 4; - GST_BUFFER_OFFSET_END (ibuf) += delta / 4; - } else { - GST_BUFFER_OFFSET (ibuf) = GST_BUFFER_OFFSET_NONE; - GST_BUFFER_OFFSET_END (ibuf) = GST_BUFFER_OFFSET_NONE; - } - - if (GST_BUFFER_TIMESTAMP_IS_VALID (buf) && - GST_BUFFER_DURATION_IS_VALID (buf)) { - GstClockTime delta; - - delta = GST_BUFFER_DURATION (buf); - GST_BUFFER_TIMESTAMP (ibuf) += delta / 4; - } else { - GST_BUFFER_TIMESTAMP (ibuf) = GST_CLOCK_TIME_NONE; - GST_BUFFER_DURATION (ibuf) = GST_CLOCK_TIME_NONE; - } - - if (GST_BUFFER_TIMESTAMP_IS_VALID (ibuf) || - GST_BUFFER_OFFSET_IS_VALID (ibuf)) { - GST_LOG ("injecting buffer [t=%" GST_TIME_FORMAT "-%" GST_TIME_FORMAT - "], offset=%" G_GINT64_FORMAT ", offset_end=%" G_GINT64_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (ibuf)), - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (ibuf) + - GST_BUFFER_DURATION (ibuf)), GST_BUFFER_OFFSET (ibuf), - GST_BUFFER_OFFSET_END (ibuf)); - - if (gst_pad_push (srcpad, ibuf) != GST_FLOW_OK) { - /* ignore return value */ - } - } else { - GST_WARNING ("couldn't inject buffer, no incoming timestamps or offsets"); - gst_buffer_unref (ibuf); - } - } - - gst_buffer_unref (buf); - - return ret; -} - -static void -test_injector_init (TestInjector * injector, TestInjectorClass * klass) -{ - GstPad *pad; - - pad = gst_pad_new_from_static_template (&sink_template, "sink"); - gst_pad_set_chain_function (pad, test_injector_chain); - gst_pad_set_getcaps_function (pad, gst_pad_proxy_getcaps); - gst_pad_set_setcaps_function (pad, gst_pad_proxy_setcaps); - gst_element_add_pad (GST_ELEMENT (injector), pad); - - pad = gst_pad_new_from_static_template (&src_template, "src"); - gst_pad_set_getcaps_function (pad, gst_pad_proxy_getcaps); - gst_pad_set_setcaps_function (pad, gst_pad_proxy_setcaps); - gst_element_add_pad (GST_ELEMENT (injector), pad); -} - -static gboolean -probe_cb (GstPad * pad, GstBuffer * buf, gdouble * drop_probability) -{ - if (g_random_double () < *drop_probability) { - GST_LOG ("dropping buffer [t=%" GST_TIME_FORMAT "-%" GST_TIME_FORMAT "], " - "offset=%" G_GINT64_FORMAT ", offset_end=%" G_GINT64_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf)), - GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf)); - return FALSE; /* drop buffer */ - } - - return TRUE; /* don't drop buffer */ -} - -static void -got_buf (GstElement * fakesink, GstBuffer * buf, GstPad * pad, GList ** p_bufs) -{ - *p_bufs = g_list_append (*p_bufs, gst_buffer_ref (buf)); -} - -static void -do_perfect_stream_test (guint rate, guint width, gdouble drop_probability, - gdouble inject_probability) -{ - GstElement *pipe, *src, *conv, *filter, *injector, *audiorate, *sink; - GstMessage *msg; - GstCaps *caps; - GstPad *srcpad; - GList *l, *bufs = NULL; - GstClockTime next_time = GST_CLOCK_TIME_NONE; - guint64 next_offset = GST_BUFFER_OFFSET_NONE; - - caps = gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, - rate, "width", G_TYPE_INT, width, NULL); - - GST_INFO ("-------- drop=%.0f%% caps = %" GST_PTR_FORMAT " ---------- ", - drop_probability * 100.0, caps); - - g_assert (drop_probability >= 0.0 && drop_probability <= 1.0); - g_assert (inject_probability >= 0.0 && inject_probability <= 1.0); - g_assert (width > 0 && (width % 8) == 0); - - pipe = gst_pipeline_new ("pipeline"); - fail_unless (pipe != NULL); - - src = gst_element_factory_make ("audiotestsrc", "audiotestsrc"); - fail_unless (src != NULL); - - g_object_set (src, "num-buffers", 100, NULL); - - conv = gst_element_factory_make ("audioconvert", "audioconvert"); - fail_unless (conv != NULL); - - filter = gst_element_factory_make ("capsfilter", "capsfilter"); - fail_unless (filter != NULL); - - g_object_set (filter, "caps", caps, NULL); - - injector_inject_probability = inject_probability; - - injector = GST_ELEMENT (g_object_new (test_injector_get_type (), NULL)); - - srcpad = gst_element_get_static_pad (injector, "src"); - fail_unless (srcpad != NULL); - gst_pad_add_buffer_probe (srcpad, G_CALLBACK (probe_cb), &drop_probability); - gst_object_unref (srcpad); - - audiorate = gst_element_factory_make ("audiorate", "audiorate"); - fail_unless (audiorate != NULL); - - sink = gst_element_factory_make ("fakesink", "fakesink"); - fail_unless (sink != NULL); - - g_object_set (sink, "signal-handoffs", TRUE, NULL); - - g_signal_connect (sink, "handoff", G_CALLBACK (got_buf), &bufs); - - gst_bin_add_many (GST_BIN (pipe), src, conv, filter, injector, audiorate, - sink, NULL); - gst_element_link_many (src, conv, filter, injector, audiorate, sink, NULL); - - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PLAYING), - GST_STATE_CHANGE_ASYNC); - - fail_unless_equals_int (gst_element_get_state (pipe, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - msg = gst_bus_poll (GST_ELEMENT_BUS (pipe), - GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1); - fail_unless_equals_string (GST_MESSAGE_TYPE_NAME (msg), "eos"); - - for (l = bufs; l != NULL; l = l->next) { - GstBuffer *buf = GST_BUFFER (l->data); - guint num_samples; - - fail_unless (GST_BUFFER_TIMESTAMP_IS_VALID (buf)); - fail_unless (GST_BUFFER_DURATION_IS_VALID (buf)); - fail_unless (GST_BUFFER_OFFSET_IS_VALID (buf)); - fail_unless (GST_BUFFER_OFFSET_END_IS_VALID (buf)); - - GST_LOG ("buffer: ts=%" GST_TIME_FORMAT ", end_ts=%" GST_TIME_FORMAT - " off=%" G_GINT64_FORMAT ", end_off=%" G_GINT64_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf)), - GST_BUFFER_OFFSET (buf), GST_BUFFER_OFFSET_END (buf)); - - if (GST_CLOCK_TIME_IS_VALID (next_time)) { - fail_unless_equals_uint64 (next_time, GST_BUFFER_TIMESTAMP (buf)); - } - if (next_offset != GST_BUFFER_OFFSET_NONE) { - fail_unless_equals_uint64 (next_offset, GST_BUFFER_OFFSET (buf)); - } - - /* check buffer size for sanity */ - fail_unless_equals_int (GST_BUFFER_SIZE (buf) % (width / 8), 0); - - /* check there is actually as much data as there should be */ - num_samples = GST_BUFFER_OFFSET_END (buf) - GST_BUFFER_OFFSET (buf); - fail_unless_equals_int (GST_BUFFER_SIZE (buf), num_samples * (width / 8)); - - next_time = GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf); - next_offset = GST_BUFFER_OFFSET_END (buf); - } - - gst_message_unref (msg); - gst_element_set_state (pipe, GST_STATE_NULL); - gst_object_unref (pipe); - - g_list_foreach (bufs, (GFunc) gst_mini_object_unref, NULL); - g_list_free (bufs); - - gst_caps_unref (caps); -} - -static const guint rates[] = { 8000, 11025, 16000, 22050, 32000, 44100, - 48000, 3333, 33333, 66666, 9999 -}; - -GST_START_TEST (test_perfect_stream_drop0) -{ - guint i; - - for (i = 0; i < G_N_ELEMENTS (rates); ++i) { - do_perfect_stream_test (rates[i], 8, 0.0, 0.0); - do_perfect_stream_test (rates[i], 16, 0.0, 0.0); - } -} - -GST_END_TEST; - -GST_START_TEST (test_perfect_stream_drop10) -{ - guint i; - - for (i = 0; i < G_N_ELEMENTS (rates); ++i) { - do_perfect_stream_test (rates[i], 8, 0.10, 0.0); - do_perfect_stream_test (rates[i], 16, 0.10, 0.0); - } -} - -GST_END_TEST; - -GST_START_TEST (test_perfect_stream_drop50) -{ - guint i; - - for (i = 0; i < G_N_ELEMENTS (rates); ++i) { - do_perfect_stream_test (rates[i], 8, 0.50, 0.0); - do_perfect_stream_test (rates[i], 16, 0.50, 0.0); - } -} - -GST_END_TEST; - -GST_START_TEST (test_perfect_stream_drop90) -{ - guint i; - - for (i = 0; i < G_N_ELEMENTS (rates); ++i) { - do_perfect_stream_test (rates[i], 8, 0.90, 0.0); - do_perfect_stream_test (rates[i], 16, 0.90, 0.0); - } -} - -GST_END_TEST; - -GST_START_TEST (test_perfect_stream_inject10) -{ - guint i; - - for (i = 0; i < G_N_ELEMENTS (rates); ++i) { - do_perfect_stream_test (rates[i], 8, 0.0, 0.10); - do_perfect_stream_test (rates[i], 16, 0.0, 0.10); - } -} - -GST_END_TEST; - -GST_START_TEST (test_perfect_stream_inject90) -{ - guint i; - - for (i = 0; i < G_N_ELEMENTS (rates); ++i) { - do_perfect_stream_test (rates[i], 8, 0.0, 0.90); - do_perfect_stream_test (rates[i], 16, 0.0, 0.90); - } -} - -GST_END_TEST; - -GST_START_TEST (test_perfect_stream_drop45_inject25) -{ - guint i; - - for (i = 0; i < G_N_ELEMENTS (rates); ++i) { - do_perfect_stream_test (rates[i], 8, 0.45, 0.25); - do_perfect_stream_test (rates[i], 16, 0.45, 0.25); - } -} - -GST_END_TEST; - -/* TODO: also do all tests with channels=1 and channels=2 */ - -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-raw-float,channels=1,rate=44100,width=32") - ); - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-raw-float,channels=1,rate=44100,width=32") - ); - -GST_START_TEST (test_large_discont) -{ - GstElement *audiorate; - GstCaps *caps; - GstPad *srcpad, *sinkpad; - GstBuffer *buf; - - audiorate = gst_check_setup_element ("audiorate"); - caps = gst_caps_new_simple ("audio/x-raw-float", - "channels", G_TYPE_INT, 1, - "rate", G_TYPE_INT, 44100, "width", G_TYPE_INT, 32, NULL); - - srcpad = gst_check_setup_src_pad (audiorate, &srctemplate, caps); - sinkpad = gst_check_setup_sink_pad (audiorate, &sinktemplate, caps); - - gst_pad_set_active (srcpad, TRUE); - gst_pad_set_active (sinkpad, TRUE); - - fail_unless (gst_element_set_state (audiorate, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "failed to set audiorate playing"); - - buf = gst_buffer_new_and_alloc (4); - gst_buffer_set_caps (buf, caps); - GST_BUFFER_TIMESTAMP (buf) = 0; - gst_pad_push (srcpad, buf); - - fail_unless_equals_int (g_list_length (buffers), 1); - - buf = gst_buffer_new_and_alloc (4); - gst_buffer_set_caps (buf, caps); - GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND; - gst_pad_push (srcpad, buf); - /* Now we should have 3 more buffers: the one we injected, plus _two_ filler - * buffers, because the gap is > 1 second (but less than 2 seconds) */ - fail_unless_equals_int (g_list_length (buffers), 4); - - gst_element_set_state (audiorate, GST_STATE_NULL); - gst_caps_unref (caps); - - gst_check_teardown_sink_pad (audiorate); - gst_check_teardown_src_pad (audiorate); - - gst_object_unref (audiorate); -} - -GST_END_TEST; - -static Suite * -audiorate_suite (void) -{ - Suite *s = suite_create ("audiorate"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - - tcase_add_test (tc_chain, test_perfect_stream_drop0); - tcase_add_test (tc_chain, test_perfect_stream_drop10); - tcase_add_test (tc_chain, test_perfect_stream_drop50); - tcase_add_test (tc_chain, test_perfect_stream_drop90); - tcase_add_test (tc_chain, test_perfect_stream_inject10); - tcase_add_test (tc_chain, test_perfect_stream_inject90); - tcase_add_test (tc_chain, test_perfect_stream_drop45_inject25); - tcase_add_test (tc_chain, test_large_discont); - - return s; -} - -GST_CHECK_MAIN (audiorate); diff --git a/tests/check/elements/audioresample.c b/tests/check/elements/audioresample.c deleted file mode 100644 index 4a67a9e0..00000000 --- a/tests/check/elements/audioresample.c +++ /dev/null @@ -1,926 +0,0 @@ -/* GStreamer - * - * unit test for audioresample, based on the audioresample unit test - * - * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org> - * Copyright (C) <2006> Tim-Philipp Müller <tim at centricular net> - * - * 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 <unistd.h> - -#include <gst/check/gstcheck.h> - -#include <gst/audio/audio.h> - -/* For ease of programming we use globals to keep refs for our floating - * src and sink pads we create; otherwise we always have to do get_pad, - * get_peer, and then remove references in every test function */ -static GstPad *mysrcpad, *mysinkpad; - -#define RESAMPLE_CAPS_FLOAT \ - "audio/x-raw-float, " \ - "channels = (int) [ 1, MAX ], " \ - "rate = (int) [ 1, MAX ], " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) { 32, 64 }" - -#define RESAMPLE_CAPS_INT \ - "audio/x-raw-int, " \ - "channels = (int) [ 1, MAX ], " \ - "rate = (int) [ 1, MAX ], " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 16, " \ - "depth = (int) 16, " \ - "signed = (bool) TRUE" - -#define RESAMPLE_CAPS_TEMPLATE_STRING \ - RESAMPLE_CAPS_FLOAT " ; " \ - RESAMPLE_CAPS_INT - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING) - ); -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (RESAMPLE_CAPS_TEMPLATE_STRING) - ); - -static GstElement * -setup_audioresample (int channels, int inrate, int outrate, int width, - gboolean fp) -{ - GstElement *audioresample; - GstCaps *caps; - GstStructure *structure; - - GST_DEBUG ("setup_audioresample"); - audioresample = gst_check_setup_element ("audioresample"); - - if (fp) - caps = gst_caps_from_string (RESAMPLE_CAPS_FLOAT); - else - caps = gst_caps_from_string (RESAMPLE_CAPS_INT); - structure = gst_caps_get_structure (caps, 0); - gst_structure_set (structure, "channels", G_TYPE_INT, channels, - "rate", G_TYPE_INT, inrate, "width", G_TYPE_INT, width, NULL); - if (!fp) - gst_structure_set (structure, "depth", G_TYPE_INT, width, NULL); - fail_unless (gst_caps_is_fixed (caps)); - - fail_unless (gst_element_set_state (audioresample, - GST_STATE_PAUSED) == GST_STATE_CHANGE_SUCCESS, - "could not set to paused"); - - mysrcpad = gst_check_setup_src_pad (audioresample, &srctemplate, caps); - gst_pad_set_caps (mysrcpad, caps); - gst_caps_unref (caps); - - if (fp) - caps = gst_caps_from_string (RESAMPLE_CAPS_FLOAT); - else - caps = gst_caps_from_string (RESAMPLE_CAPS_INT); - structure = gst_caps_get_structure (caps, 0); - gst_structure_set (structure, "channels", G_TYPE_INT, channels, - "rate", G_TYPE_INT, outrate, "width", G_TYPE_INT, width, NULL); - if (!fp) - gst_structure_set (structure, "depth", G_TYPE_INT, width, NULL); - fail_unless (gst_caps_is_fixed (caps)); - - mysinkpad = gst_check_setup_sink_pad (audioresample, &sinktemplate, caps); - /* this installs a getcaps func that will always return the caps we set - * later */ - gst_pad_set_caps (mysinkpad, caps); - gst_pad_use_fixed_caps (mysinkpad); - - gst_pad_set_active (mysinkpad, TRUE); - gst_pad_set_active (mysrcpad, TRUE); - - gst_caps_unref (caps); - - return audioresample; -} - -static void -cleanup_audioresample (GstElement * audioresample) -{ - GST_DEBUG ("cleanup_audioresample"); - - fail_unless (gst_element_set_state (audioresample, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to NULL"); - - gst_pad_set_active (mysrcpad, FALSE); - gst_pad_set_active (mysinkpad, FALSE); - gst_check_teardown_src_pad (audioresample); - gst_check_teardown_sink_pad (audioresample); - gst_check_teardown_element (audioresample); - gst_check_drop_buffers (); -} - -static void -fail_unless_perfect_stream (void) -{ - guint64 timestamp = 0L, duration = 0L; - guint64 offset = 0L, offset_end = 0L; - - GList *l; - GstBuffer *buffer; - - for (l = buffers; l; l = l->next) { - buffer = GST_BUFFER (l->data); - ASSERT_BUFFER_REFCOUNT (buffer, "buffer", 1); - GST_DEBUG ("buffer timestamp %" G_GUINT64_FORMAT ", duration %" - G_GUINT64_FORMAT " offset %" G_GUINT64_FORMAT " offset_end %" - G_GUINT64_FORMAT, - GST_BUFFER_TIMESTAMP (buffer), - GST_BUFFER_DURATION (buffer), - GST_BUFFER_OFFSET (buffer), GST_BUFFER_OFFSET_END (buffer)); - - fail_unless_equals_uint64 (timestamp, GST_BUFFER_TIMESTAMP (buffer)); - fail_unless_equals_uint64 (offset, GST_BUFFER_OFFSET (buffer)); - duration = GST_BUFFER_DURATION (buffer); - offset_end = GST_BUFFER_OFFSET_END (buffer); - - timestamp += duration; - offset = offset_end; - gst_buffer_unref (buffer); - } - g_list_free (buffers); - buffers = NULL; -} - -/* this tests that the output is a perfect stream if the input is */ -static void -test_perfect_stream_instance (int inrate, int outrate, int samples, - int numbuffers) -{ - GstElement *audioresample; - GstBuffer *inbuffer, *outbuffer; - GstCaps *caps; - guint64 offset = 0; - - int i, j; - gint16 *p; - - audioresample = setup_audioresample (2, inrate, outrate, 16, FALSE); - caps = gst_pad_get_negotiated_caps (mysrcpad); - fail_unless (gst_caps_is_fixed (caps)); - - fail_unless (gst_element_set_state (audioresample, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - for (j = 1; j <= numbuffers; ++j) { - - inbuffer = gst_buffer_new_and_alloc (samples * 4); - GST_BUFFER_DURATION (inbuffer) = GST_FRAMES_TO_CLOCK_TIME (samples, inrate); - GST_BUFFER_TIMESTAMP (inbuffer) = GST_BUFFER_DURATION (inbuffer) * (j - 1); - GST_BUFFER_OFFSET (inbuffer) = offset; - offset += samples; - GST_BUFFER_OFFSET_END (inbuffer) = offset; - - gst_buffer_set_caps (inbuffer, caps); - - p = (gint16 *) GST_BUFFER_DATA (inbuffer); - - /* create a 16 bit signed ramp */ - for (i = 0; i < samples; ++i) { - *p = -32767 + i * (65535 / samples); - ++p; - *p = -32767 + i * (65535 / samples); - ++p; - } - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being collected on the global buffer list */ - fail_unless_equals_int (g_list_length (buffers), j); - } - - /* FIXME: we should make audioresample handle eos by flushing out the last - * samples, which will give us one more, small, buffer */ - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); - - fail_unless_perfect_stream (); - - /* cleanup */ - gst_caps_unref (caps); - cleanup_audioresample (audioresample); -} - - -/* make sure that outgoing buffers are contiguous in timestamp/duration and - * offset/offsetend - */ -GST_START_TEST (test_perfect_stream) -{ - /* integral scalings */ - test_perfect_stream_instance (48000, 24000, 500, 20); - test_perfect_stream_instance (48000, 12000, 500, 20); - test_perfect_stream_instance (12000, 24000, 500, 20); - test_perfect_stream_instance (12000, 48000, 500, 20); - - /* non-integral scalings */ - test_perfect_stream_instance (44100, 8000, 500, 20); - test_perfect_stream_instance (8000, 44100, 500, 20); - - /* wacky scalings */ - test_perfect_stream_instance (12345, 54321, 500, 20); - test_perfect_stream_instance (101, 99, 500, 20); -} - -GST_END_TEST; - -/* this tests that the output is a correct discontinuous stream - * if the input is; ie input drops in time come out the same way */ -static void -test_discont_stream_instance (int inrate, int outrate, int samples, - int numbuffers) -{ - GstElement *audioresample; - GstBuffer *inbuffer, *outbuffer; - GstCaps *caps; - GstClockTime ints; - - int i, j; - gint16 *p; - - GST_DEBUG ("inrate:%d outrate:%d samples:%d numbuffers:%d", - inrate, outrate, samples, numbuffers); - - audioresample = setup_audioresample (2, inrate, outrate, 16, FALSE); - caps = gst_pad_get_negotiated_caps (mysrcpad); - fail_unless (gst_caps_is_fixed (caps)); - - fail_unless (gst_element_set_state (audioresample, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - for (j = 1; j <= numbuffers; ++j) { - - inbuffer = gst_buffer_new_and_alloc (samples * 4); - GST_BUFFER_DURATION (inbuffer) = samples * GST_SECOND / inrate; - /* "drop" half the buffers */ - ints = GST_BUFFER_DURATION (inbuffer) * 2 * (j - 1); - GST_BUFFER_TIMESTAMP (inbuffer) = ints; - GST_BUFFER_OFFSET (inbuffer) = (j - 1) * 2 * samples; - GST_BUFFER_OFFSET_END (inbuffer) = j * 2 * samples + samples; - - gst_buffer_set_caps (inbuffer, caps); - - p = (gint16 *) GST_BUFFER_DATA (inbuffer); - - /* create a 16 bit signed ramp */ - for (i = 0; i < samples; ++i) { - *p = -32767 + i * (65535 / samples); - ++p; - *p = -32767 + i * (65535 / samples); - ++p; - } - - GST_DEBUG ("Sending Buffer time:%" G_GUINT64_FORMAT " duration:%" - G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%" - G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (inbuffer), - GST_BUFFER_DURATION (inbuffer), GST_BUFFER_IS_DISCONT (inbuffer), - GST_BUFFER_OFFSET (inbuffer), GST_BUFFER_OFFSET_END (inbuffer)); - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - /* check if the timestamp of the pushed buffer matches the incoming one */ - outbuffer = g_list_nth_data (buffers, g_list_length (buffers) - 1); - fail_if (outbuffer == NULL); - fail_unless_equals_uint64 (ints, GST_BUFFER_TIMESTAMP (outbuffer)); - GST_DEBUG ("Got Buffer time:%" G_GUINT64_FORMAT " duration:%" - G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%" - G_GUINT64_FORMAT, GST_BUFFER_TIMESTAMP (outbuffer), - GST_BUFFER_DURATION (outbuffer), GST_BUFFER_IS_DISCONT (outbuffer), - GST_BUFFER_OFFSET (outbuffer), GST_BUFFER_OFFSET_END (outbuffer)); - if (j > 1) { - fail_unless (GST_BUFFER_IS_DISCONT (outbuffer), - "expected discont for buffer #%d", j); - } - } - - /* cleanup */ - gst_caps_unref (caps); - cleanup_audioresample (audioresample); -} - -GST_START_TEST (test_discont_stream) -{ - /* integral scalings */ - test_discont_stream_instance (48000, 24000, 500, 20); - test_discont_stream_instance (48000, 12000, 500, 20); - test_discont_stream_instance (12000, 24000, 500, 20); - test_discont_stream_instance (12000, 48000, 500, 20); - - /* non-integral scalings */ - test_discont_stream_instance (44100, 8000, 500, 20); - test_discont_stream_instance (8000, 44100, 500, 20); - - /* wacky scalings */ - test_discont_stream_instance (12345, 54321, 500, 20); - test_discont_stream_instance (101, 99, 500, 20); -} - -GST_END_TEST; - - - -GST_START_TEST (test_reuse) -{ - GstElement *audioresample; - GstEvent *newseg; - GstBuffer *inbuffer; - GstCaps *caps; - - audioresample = setup_audioresample (1, 9343, 48000, 16, FALSE); - caps = gst_pad_get_negotiated_caps (mysrcpad); - fail_unless (gst_caps_is_fixed (caps)); - - fail_unless (gst_element_set_state (audioresample, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0); - fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE); - - inbuffer = gst_buffer_new_and_alloc (9343 * 4); - memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer)); - GST_BUFFER_DURATION (inbuffer) = GST_SECOND; - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - GST_BUFFER_OFFSET (inbuffer) = 0; - gst_buffer_set_caps (inbuffer, caps); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - /* ... but it ends up being collected on the global buffer list */ - fail_unless_equals_int (g_list_length (buffers), 1); - - /* now reset and try again ... */ - fail_unless (gst_element_set_state (audioresample, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to NULL"); - - fail_unless (gst_element_set_state (audioresample, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0); - fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE); - - inbuffer = gst_buffer_new_and_alloc (9343 * 4); - memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer)); - GST_BUFFER_DURATION (inbuffer) = GST_SECOND; - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - GST_BUFFER_OFFSET (inbuffer) = 0; - gst_buffer_set_caps (inbuffer, caps); - - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - /* ... it also ends up being collected on the global buffer list. If we - * now have more than 2 buffers, then audioresample probably didn't clean - * up its internal buffer properly and tried to push the remaining samples - * when it got the second NEWSEGMENT event */ - fail_unless_equals_int (g_list_length (buffers), 2); - - cleanup_audioresample (audioresample); - gst_caps_unref (caps); -} - -GST_END_TEST; - -GST_START_TEST (test_shutdown) -{ - GstElement *pipeline, *src, *cf1, *ar, *cf2, *sink; - GstCaps *caps; - guint i; - - /* create pipeline, force audioresample to actually resample */ - pipeline = gst_pipeline_new (NULL); - - src = gst_check_setup_element ("audiotestsrc"); - cf1 = gst_check_setup_element ("capsfilter"); - ar = gst_check_setup_element ("audioresample"); - cf2 = gst_check_setup_element ("capsfilter"); - g_object_set (cf2, "name", "capsfilter2", NULL); - sink = gst_check_setup_element ("fakesink"); - - caps = - gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, 11025, NULL); - g_object_set (cf1, "caps", caps, NULL); - gst_caps_unref (caps); - - caps = - gst_caps_new_simple ("audio/x-raw-int", "rate", G_TYPE_INT, 48000, NULL); - g_object_set (cf2, "caps", caps, NULL); - gst_caps_unref (caps); - - /* don't want to sync against the clock, the more throughput the better */ - g_object_set (src, "is-live", FALSE, NULL); - g_object_set (sink, "sync", FALSE, NULL); - - gst_bin_add_many (GST_BIN (pipeline), src, cf1, ar, cf2, sink, NULL); - fail_if (!gst_element_link_many (src, cf1, ar, cf2, sink, NULL)); - - /* now, wait until pipeline is running and then shut it down again; repeat */ - for (i = 0; i < 20; ++i) { - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gst_element_get_state (pipeline, NULL, NULL, -1); - gst_element_set_state (pipeline, GST_STATE_PLAYING); - g_usleep (100); - gst_element_set_state (pipeline, GST_STATE_NULL); - } - - gst_object_unref (pipeline); -} - -GST_END_TEST; - -static GstFlowReturn -live_switch_alloc_only_48000 (GstPad * pad, guint64 offset, - guint size, GstCaps * caps, GstBuffer ** buf) -{ - GstStructure *structure; - gint rate; - gint channels; - GstCaps *desired; - - structure = gst_caps_get_structure (caps, 0); - fail_unless (gst_structure_get_int (structure, "rate", &rate)); - fail_unless (gst_structure_get_int (structure, "channels", &channels)); - - if (rate < 48000) - return GST_FLOW_NOT_NEGOTIATED; - - desired = gst_caps_copy (caps); - gst_caps_set_simple (desired, "rate", G_TYPE_INT, 48000, NULL); - - *buf = gst_buffer_new_and_alloc (channels * 48000); - gst_buffer_set_caps (*buf, desired); - gst_caps_unref (desired); - - return GST_FLOW_OK; -} - -static GstCaps * -live_switch_get_sink_caps (GstPad * pad) -{ - GstCaps *result; - - result = gst_caps_copy (GST_PAD_CAPS (pad)); - - gst_caps_set_simple (result, - "rate", GST_TYPE_INT_RANGE, 48000, G_MAXINT, NULL); - - return result; -} - -static void -live_switch_push (int rate, GstCaps * caps) -{ - GstBuffer *inbuffer; - GstCaps *desired; - GList *l; - - desired = gst_caps_copy (caps); - gst_caps_set_simple (desired, "rate", G_TYPE_INT, rate, NULL); - gst_pad_set_caps (mysrcpad, desired); - - fail_unless (gst_pad_alloc_buffer_and_set_caps (mysrcpad, - GST_BUFFER_OFFSET_NONE, rate * 4, desired, &inbuffer) == GST_FLOW_OK); - - /* When the basetransform hits the non-configured case it always - * returns a buffer with exactly the same caps as we requested so the actual - * renegotiation (if needed) will be done in the _chain*/ - fail_unless (inbuffer != NULL); - GST_DEBUG ("desired: %" GST_PTR_FORMAT ".... got: %" GST_PTR_FORMAT, - desired, GST_BUFFER_CAPS (inbuffer)); - fail_unless (gst_caps_is_equal (desired, GST_BUFFER_CAPS (inbuffer))); - - memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer)); - GST_BUFFER_DURATION (inbuffer) = GST_SECOND; - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - GST_BUFFER_OFFSET (inbuffer) = 0; - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - /* ... but it ends up being collected on the global buffer list */ - fail_unless_equals_int (g_list_length (buffers), 1); - - for (l = buffers; l; l = l->next) { - GstBuffer *buffer = GST_BUFFER (l->data); - - gst_buffer_unref (buffer); - } - - g_list_free (buffers); - buffers = NULL; - - gst_caps_unref (desired); -} - -GST_START_TEST (test_live_switch) -{ - GstElement *audioresample; - GstEvent *newseg; - GstCaps *caps; - - audioresample = setup_audioresample (4, 48000, 48000, 16, FALSE); - - /* Let the sinkpad act like something that can only handle things of - * rate 48000- and can only allocate buffers for that rate, but if someone - * tries to get a buffer with a rate higher then 48000 tries to renegotiate - * */ - gst_pad_set_bufferalloc_function (mysinkpad, live_switch_alloc_only_48000); - gst_pad_set_getcaps_function (mysinkpad, live_switch_get_sink_caps); - - gst_pad_use_fixed_caps (mysrcpad); - - caps = gst_pad_get_negotiated_caps (mysrcpad); - fail_unless (gst_caps_is_fixed (caps)); - - fail_unless (gst_element_set_state (audioresample, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - newseg = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, 0); - fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE); - - /* downstream can provide the requested rate, a buffer alloc will be passed - * on */ - live_switch_push (48000, caps); - - /* Downstream can never accept this rate, buffer alloc isn't passed on */ - live_switch_push (40000, caps); - - /* Downstream can provide the requested rate but will re-negotiate */ - live_switch_push (50000, caps); - - cleanup_audioresample (audioresample); - gst_caps_unref (caps); -} - -GST_END_TEST; - -#ifndef GST_DISABLE_PARSE - -static GMainLoop *loop; -static gint messages = 0; - -static void -element_message_cb (GstBus * bus, GstMessage * message, gpointer user_data) -{ - gchar *s; - - s = gst_structure_to_string (gst_message_get_structure (message)); - GST_DEBUG ("Received message: %s", s); - g_free (s); - - messages++; -} - -static void -eos_message_cb (GstBus * bus, GstMessage * message, gpointer user_data) -{ - GST_DEBUG ("Received eos"); - g_main_loop_quit (loop); -} - -static void -test_pipeline (gint width, gboolean fp, gint inrate, gint outrate, gint quality) -{ - GstElement *pipeline; - GstBus *bus; - GError *error = NULL; - gchar *pipe_str; - - pipe_str = - g_strdup_printf - ("audiotestsrc num-buffers=10 ! audioconvert ! audio/x-raw-%s,rate=%d,width=%d,channels=2 ! audioresample quality=%d ! audio/x-raw-%s,rate=%d,width=%d ! identity check-imperfect-timestamp=TRUE ! fakesink", - (fp) ? "float" : "int", inrate, width, quality, (fp) ? "float" : "int", - outrate, width); - - pipeline = gst_parse_launch (pipe_str, &error); - fail_unless (pipeline != NULL, "Error parsing pipeline: %s", - error ? error->message : "(invalid error)"); - g_free (pipe_str); - - bus = gst_element_get_bus (pipeline); - fail_if (bus == NULL); - gst_bus_add_signal_watch (bus); - g_signal_connect (bus, "message::element", (GCallback) element_message_cb, - NULL); - g_signal_connect (bus, "message::eos", (GCallback) eos_message_cb, NULL); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - /* run until we receive EOS */ - loop = g_main_loop_new (NULL, FALSE); - - g_main_loop_run (loop); - - g_main_loop_unref (loop); - loop = NULL; - - gst_element_set_state (pipeline, GST_STATE_NULL); - - fail_if (messages > 0, "Received imperfect timestamp messages"); - gst_object_unref (pipeline); -} - -GST_START_TEST (test_pipelines) -{ - gint quality; - - /* Test qualities 0, 5 and 10 */ - for (quality = 0; quality < 11; quality += 5) { - GST_DEBUG ("Checking with quality %d", quality); - - test_pipeline (8, FALSE, 44100, 48000, quality); - test_pipeline (8, FALSE, 48000, 44100, quality); - - test_pipeline (16, FALSE, 44100, 48000, quality); - test_pipeline (16, FALSE, 48000, 44100, quality); - - test_pipeline (24, FALSE, 44100, 48000, quality); - test_pipeline (24, FALSE, 48000, 44100, quality); - - test_pipeline (32, FALSE, 44100, 48000, quality); - test_pipeline (32, FALSE, 48000, 44100, quality); - - test_pipeline (32, TRUE, 44100, 48000, quality); - test_pipeline (32, TRUE, 48000, 44100, quality); - - test_pipeline (64, TRUE, 44100, 48000, quality); - test_pipeline (64, TRUE, 48000, 44100, quality); - } -} - -GST_END_TEST; - -GST_START_TEST (test_preference_passthrough) -{ - GstStateChangeReturn ret; - GstElement *pipeline, *src; - GstStructure *s; - GstMessage *msg; - GstCaps *caps; - GstPad *pad; - GstBus *bus; - GError *error = NULL; - gint rate = 0; - - pipeline = gst_parse_launch ("audiotestsrc num-buffers=1 name=src ! " - "audioresample ! audio/x-raw-int,channels=1,width=16,depth=16," - "endianness=BYTE_ORDER,signed=true,rate=8000 ! " - "fakesink can-activate-pull=false", &error); - fail_unless (pipeline != NULL, "Error parsing pipeline: %s", - error ? error->message : "(invalid error)"); - - ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); - fail_unless_equals_int (ret, GST_STATE_CHANGE_ASYNC); - - /* run until we receive EOS */ - bus = gst_element_get_bus (pipeline); - fail_if (bus == NULL); - msg = gst_bus_timed_pop_filtered (bus, -1, GST_MESSAGE_EOS); - gst_message_unref (msg); - gst_object_unref (bus); - - src = gst_bin_get_by_name (GST_BIN (pipeline), "src"); - fail_unless (src != NULL); - pad = gst_element_get_static_pad (src, "src"); - fail_unless (pad != NULL); - caps = gst_pad_get_negotiated_caps (pad); - GST_LOG ("negotiated audiotestsrc caps: %" GST_PTR_FORMAT, caps); - fail_unless (caps != NULL); - s = gst_caps_get_structure (caps, 0); - fail_unless (gst_structure_get_int (s, "rate", &rate)); - /* there's no need to resample, audiotestsrc supports any rate, so make - * sure audioresample provided upstream with the right caps to negotiate - * this correctly */ - fail_unless_equals_int (rate, 8000); - gst_caps_unref (caps); - gst_object_unref (pad); - gst_object_unref (src); - - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); -} - -GST_END_TEST; - -#endif - -static void -_message_cb (GstBus * bus, GstMessage * message, gpointer user_data) -{ - GMainLoop *loop = user_data; - - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_ERROR: - case GST_MESSAGE_WARNING: - g_assert_not_reached (); - break; - case GST_MESSAGE_EOS: - g_main_loop_quit (loop); - break; - default: - break; - } -} - -typedef struct -{ - guint64 latency; - GstClockTime in_ts; - - GstClockTime next_out_ts; - guint64 next_out_off; - - guint64 in_buffer_count, out_buffer_count; -} TimestampDriftCtx; - -void -fakesink_handoff_cb (GstElement * object, GstBuffer * buffer, GstPad * pad, - gpointer user_data) -{ - TimestampDriftCtx *ctx = user_data; - - ctx->out_buffer_count++; - if (ctx->latency == GST_CLOCK_TIME_NONE) { - ctx->latency = 1000 - GST_BUFFER_SIZE (buffer) / 8; - } - - /* Check if we have a perfectly timestampped stream */ - if (ctx->next_out_ts != GST_CLOCK_TIME_NONE) - fail_unless (ctx->next_out_ts == GST_BUFFER_TIMESTAMP (buffer), - "expected timestamp %" GST_TIME_FORMAT " got timestamp %" - GST_TIME_FORMAT, GST_TIME_ARGS (ctx->next_out_ts), - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer))); - - /* Check if we have a perfectly offsetted stream */ - fail_unless (GST_BUFFER_OFFSET_END (buffer) == - GST_BUFFER_OFFSET (buffer) + GST_BUFFER_SIZE (buffer) / 8, - "expected offset end %" G_GUINT64_FORMAT " got offset end %" - G_GUINT64_FORMAT, - GST_BUFFER_OFFSET (buffer) + GST_BUFFER_SIZE (buffer) / 8, - GST_BUFFER_OFFSET_END (buffer)); - if (ctx->next_out_off != GST_BUFFER_OFFSET_NONE) { - fail_unless (GST_BUFFER_OFFSET (buffer) == ctx->next_out_off, - "expected offset %" G_GUINT64_FORMAT " got offset %" G_GUINT64_FORMAT, - ctx->next_out_off, GST_BUFFER_OFFSET (buffer)); - } - - if (ctx->in_buffer_count != ctx->out_buffer_count) { - GST_INFO ("timestamp %" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer))); - } - - if (ctx->in_ts != GST_CLOCK_TIME_NONE && ctx->in_buffer_count > 1 - && ctx->in_buffer_count == ctx->out_buffer_count) { - fail_unless (GST_BUFFER_TIMESTAMP (buffer) == - ctx->in_ts - gst_util_uint64_scale_round (ctx->latency, GST_SECOND, - 4096), - "expected output timestamp %" GST_TIME_FORMAT " (%" G_GUINT64_FORMAT - ") got output timestamp %" GST_TIME_FORMAT " (%" G_GUINT64_FORMAT ")", - GST_TIME_ARGS (ctx->in_ts - gst_util_uint64_scale_round (ctx->latency, - GST_SECOND, 4096)), - ctx->in_ts - gst_util_uint64_scale_round (ctx->latency, GST_SECOND, - 4096), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)), - GST_BUFFER_TIMESTAMP (buffer)); - } - - ctx->next_out_ts = - GST_BUFFER_TIMESTAMP (buffer) + GST_BUFFER_DURATION (buffer); - ctx->next_out_off = GST_BUFFER_OFFSET_END (buffer); -} - -void -identity_handoff_cb (GstElement * object, GstBuffer * buffer, - gpointer user_data) -{ - TimestampDriftCtx *ctx = user_data; - - ctx->in_ts = GST_BUFFER_TIMESTAMP (buffer); - ctx->in_buffer_count++; -} - -GST_START_TEST (test_timestamp_drift) -{ - TimestampDriftCtx ctx = - { GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE, GST_CLOCK_TIME_NONE, - GST_BUFFER_OFFSET_NONE, 0, 0 - }; - GstElement *pipeline; - GstElement *audiotestsrc, *capsfilter1, *identity, *audioresample, - *capsfilter2, *fakesink; - GstBus *bus; - GMainLoop *loop; - GstCaps *caps; - - pipeline = gst_pipeline_new ("pipeline"); - fail_unless (pipeline != NULL); - - audiotestsrc = gst_element_factory_make ("audiotestsrc", "src"); - fail_unless (audiotestsrc != NULL); - g_object_set (G_OBJECT (audiotestsrc), "num-buffers", 10000, - "samplesperbuffer", 4000, NULL); - - capsfilter1 = gst_element_factory_make ("capsfilter", "capsfilter1"); - fail_unless (capsfilter1 != NULL); - caps = - gst_caps_from_string - ("audio/x-raw-float, channels=1, width=64, rate=16384"); - g_object_set (G_OBJECT (capsfilter1), "caps", caps, NULL); - gst_caps_unref (caps); - - identity = gst_element_factory_make ("identity", "identity"); - fail_unless (identity != NULL); - g_object_set (G_OBJECT (identity), "sync", FALSE, "signal-handoffs", TRUE, - NULL); - g_signal_connect (identity, "handoff", (GCallback) identity_handoff_cb, &ctx); - - audioresample = gst_element_factory_make ("audioresample", "resample"); - fail_unless (audioresample != NULL); - capsfilter2 = gst_element_factory_make ("capsfilter", "capsfilter2"); - fail_unless (capsfilter2 != NULL); - caps = - gst_caps_from_string - ("audio/x-raw-float, channels=1, width=64, rate=4096"); - g_object_set (G_OBJECT (capsfilter2), "caps", caps, NULL); - gst_caps_unref (caps); - - fakesink = gst_element_factory_make ("fakesink", "sink"); - fail_unless (fakesink != NULL); - g_object_set (G_OBJECT (fakesink), "sync", FALSE, "async", FALSE, - "signal-handoffs", TRUE, NULL); - g_signal_connect (fakesink, "handoff", (GCallback) fakesink_handoff_cb, &ctx); - - - gst_bin_add_many (GST_BIN (pipeline), audiotestsrc, capsfilter1, identity, - audioresample, capsfilter2, fakesink, NULL); - fail_unless (gst_element_link_many (audiotestsrc, capsfilter1, identity, - audioresample, capsfilter2, fakesink, NULL)); - - loop = g_main_loop_new (NULL, FALSE); - - bus = gst_element_get_bus (pipeline); - gst_bus_add_signal_watch (bus); - g_signal_connect (bus, "message", (GCallback) _message_cb, loop); - - fail_unless (gst_element_set_state (pipeline, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS); - g_main_loop_run (loop); - - fail_unless (gst_element_set_state (pipeline, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS); - g_main_loop_unref (loop); - gst_object_unref (pipeline); - -} GST_END_TEST; - -static Suite * -audioresample_suite (void) -{ - Suite *s = suite_create ("audioresample"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_perfect_stream); - tcase_add_test (tc_chain, test_discont_stream); - tcase_add_test (tc_chain, test_reuse); - tcase_add_test (tc_chain, test_shutdown); - tcase_add_test (tc_chain, test_live_switch); - tcase_add_test (tc_chain, test_timestamp_drift); - -#ifndef GST_DISABLE_PARSE - tcase_set_timeout (tc_chain, 360); - tcase_add_test (tc_chain, test_pipelines); - tcase_add_test (tc_chain, test_preference_passthrough); -#endif - - return s; -} - -GST_CHECK_MAIN (audioresample); diff --git a/tests/check/elements/audiotestsrc.c b/tests/check/elements/audiotestsrc.c deleted file mode 100644 index cd2dec64..00000000 --- a/tests/check/elements/audiotestsrc.c +++ /dev/null @@ -1,143 +0,0 @@ -/* GStreamer - * - * unit test for audiotestsrc - * - * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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 <unistd.h> - -#include <gst/check/gstcheck.h> - -/* For ease of programming we use globals to keep refs for our floating - * src and sink pads we create; otherwise we always have to do get_pad, - * get_peer, and then remove references in every test function */ -static GstPad *mysinkpad; - - -#define CAPS_TEMPLATE_STRING \ - "audio/x-raw-int, " \ - "channels = (int) 1, " \ - "rate = (int) [ 1, MAX ], " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 16, " \ - "depth = (int) 16, " \ - "signed = (bool) TRUE" - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (CAPS_TEMPLATE_STRING) - ); - -static GstElement * -setup_audiotestsrc (void) -{ - GstElement *audiotestsrc; - - GST_DEBUG ("setup_audiotestsrc"); - audiotestsrc = gst_check_setup_element ("audiotestsrc"); - mysinkpad = gst_check_setup_sink_pad (audiotestsrc, &sinktemplate, NULL); - gst_pad_set_active (mysinkpad, TRUE); - - return audiotestsrc; -} - -static void -cleanup_audiotestsrc (GstElement * audiotestsrc) -{ - GST_DEBUG ("cleanup_audiotestsrc"); - - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - - gst_pad_set_active (mysinkpad, FALSE); - gst_check_teardown_sink_pad (audiotestsrc); - gst_check_teardown_element (audiotestsrc); -} - -GST_START_TEST (test_all_waves) -{ - GstElement *audiotestsrc; - GObjectClass *oclass; - GParamSpec *property; - GEnumValue *values; - guint j = 0; - - audiotestsrc = setup_audiotestsrc (); - oclass = G_OBJECT_GET_CLASS (audiotestsrc); - property = g_object_class_find_property (oclass, "wave"); - fail_unless (G_IS_PARAM_SPEC_ENUM (property)); - values = G_ENUM_CLASS (g_type_class_ref (property->value_type))->values; - - - while (values[j].value_name) { - GST_DEBUG_OBJECT (audiotestsrc, "testing wave %s", values[j].value_name); - - fail_unless (gst_element_set_state (audiotestsrc, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - g_mutex_lock (check_mutex); - while (g_list_length (buffers) < 10) - g_cond_wait (check_cond, check_mutex); - g_mutex_unlock (check_mutex); - - gst_element_set_state (audiotestsrc, GST_STATE_READY); - - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ++j; - } - - /* cleanup */ - cleanup_audiotestsrc (audiotestsrc); -} - -GST_END_TEST; - -static Suite * -audiotestsrc_suite (void) -{ - Suite *s = suite_create ("audiotestsrc"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_all_waves); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = audiotestsrc_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/elements/decodebin.c b/tests/check/elements/decodebin.c deleted file mode 100644 index eb6f38a4..00000000 --- a/tests/check/elements/decodebin.c +++ /dev/null @@ -1,200 +0,0 @@ -/* GStreamer unit tests for decodebin - * - * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <gst/check/gstcheck.h> -#include <unistd.h> - -static const gchar dummytext[] = - "Quick Brown Fox Jumps over a Lazy Frog Quick Brown " - "Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick " - "Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog " - "Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy " - "Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a " - "Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps " - "over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox " - "jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown " - "Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick " - "Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog " - "Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy " - "Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a " - "Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps " - "over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox "; - -static void -src_handoff_cb (GstElement * src, GstBuffer * buf, GstPad * pad, gpointer data) -{ - GST_BUFFER_DATA (buf) = (guint8 *) dummytext; - GST_BUFFER_SIZE (buf) = sizeof (dummytext); - GST_BUFFER_OFFSET (buf) = 0; - GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY); -} - -static void -decodebin_new_decoded_pad_cb (GstElement * decodebin, GstPad * pad, - gboolean last, gboolean * p_flag) -{ - /* we should not be reached */ - fail_unless (decodebin == NULL, "new-decoded-pad should not be emitted"); -} - -/* make sure that decodebin errors out instead of creating a new decoded pad - * if the entire stream is a plain text file */ -GST_START_TEST (test_text_plain_streams) -{ - GstElement *pipe, *src, *decodebin; - GstMessage *msg; - - pipe = gst_pipeline_new (NULL); - fail_unless (pipe != NULL, "failed to create pipeline"); - - src = gst_element_factory_make ("fakesrc", "src"); - fail_unless (src != NULL, "Failed to create fakesrc element"); - - g_object_set (src, "signal-handoffs", TRUE, NULL); - g_object_set (src, "num-buffers", 1, NULL); - g_object_set (src, "can-activate-pull", FALSE, NULL); - g_signal_connect (src, "handoff", G_CALLBACK (src_handoff_cb), NULL); - - decodebin = gst_element_factory_make ("decodebin", "decodebin"); - fail_unless (decodebin != NULL, "Failed to create decodebin element"); - - g_signal_connect (decodebin, "new-decoded-pad", - G_CALLBACK (decodebin_new_decoded_pad_cb), NULL); - - fail_unless (gst_bin_add (GST_BIN (pipe), src)); - fail_unless (gst_bin_add (GST_BIN (pipe), decodebin)); - fail_unless (gst_element_link (src, decodebin), "can't link src<->decodebin"); - - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - /* it's push-based, so should be async */ - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - - /* it should error out at some point */ - msg = gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, -1); - fail_unless (msg != NULL); - fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR); - gst_message_unref (msg); - - gst_element_set_state (pipe, GST_STATE_NULL); - gst_object_unref (pipe); -} - -GST_END_TEST; - -static void -new_decoded_pad_plug_fakesink_cb (GstElement * decodebin, GstPad * srcpad, - gboolean last, GstElement * pipeline) -{ - GstElement *sink; - GstPad *sinkpad; - - sink = gst_element_factory_make ("fakesink", "sink"); - fail_unless (sink != NULL, "Failed to create fakesink element"); - - gst_bin_add (GST_BIN (pipeline), sink); - - sinkpad = gst_element_get_static_pad (sink, "sink"); - fail_unless_equals_int (gst_pad_link (srcpad, sinkpad), GST_PAD_LINK_OK); - gst_object_unref (sinkpad); - - gst_element_set_state (sink, GST_STATE_PLAYING); -} - -GST_START_TEST (test_reuse_without_decoders) -{ - GstElement *pipe, *src, *decodebin, *sink; - - pipe = gst_pipeline_new (NULL); - fail_unless (pipe != NULL, "failed to create pipeline"); - - src = gst_element_factory_make ("audiotestsrc", "src"); - fail_unless (src != NULL, "Failed to create audiotestsrc element"); - - decodebin = gst_element_factory_make ("decodebin", "decodebin"); - fail_unless (decodebin != NULL, "Failed to create decodebin element"); - - g_signal_connect (decodebin, "new-decoded-pad", - G_CALLBACK (new_decoded_pad_plug_fakesink_cb), pipe); - - fail_unless (gst_bin_add (GST_BIN (pipe), src)); - fail_unless (gst_bin_add (GST_BIN (pipe), decodebin)); - fail_unless (gst_element_link (src, decodebin), "can't link src<->decodebin"); - - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - /* it's push-based, so should be async */ - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - - /* wait for state change to complete */ - fail_unless_equals_int (gst_element_get_state (pipe, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - /* there shouldn't be any errors */ - fail_if (gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, 0) != NULL); - - /* reset */ - gst_element_set_state (pipe, GST_STATE_NULL); - - sink = gst_bin_get_by_name (GST_BIN (pipe), "sink"); - gst_bin_remove (GST_BIN (pipe), sink); - gst_object_unref (sink); - - GST_LOG ("second try"); - - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - /* it's push-based, so should be async */ - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - - /* wait for state change to complete */ - fail_unless_equals_int (gst_element_get_state (pipe, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - /* there shouldn't be any errors */ - fail_if (gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, 0) != NULL); - - gst_element_set_state (pipe, GST_STATE_NULL); - gst_object_unref (pipe); -} - -GST_END_TEST; - -static Suite * -decodebin_suite (void) -{ - Suite *s = suite_create ("decodebin"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_text_plain_streams); - tcase_add_test (tc_chain, test_reuse_without_decoders); - - return s; -} - -GST_CHECK_MAIN (decodebin); diff --git a/tests/check/elements/decodebin2.c b/tests/check/elements/decodebin2.c deleted file mode 100644 index 84cf4054..00000000 --- a/tests/check/elements/decodebin2.c +++ /dev/null @@ -1,203 +0,0 @@ -/* GStreamer unit tests for decodebin2 - * - * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <gst/check/gstcheck.h> -#include <unistd.h> - -static const gchar dummytext[] = - "Quick Brown Fox Jumps over a Lazy Frog Quick Brown " - "Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick " - "Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog " - "Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy " - "Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a " - "Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps " - "over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox " - "jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown " - "Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick " - "Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog " - "Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy " - "Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a " - "Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps " - "over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox "; - -static void -src_handoff_cb (GstElement * src, GstBuffer * buf, GstPad * pad, gpointer data) -{ - GST_BUFFER_DATA (buf) = (guint8 *) dummytext; - GST_BUFFER_SIZE (buf) = sizeof (dummytext); - GST_BUFFER_OFFSET (buf) = 0; - GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY); -} - -static void -decodebin_new_decoded_pad_cb (GstElement * decodebin, GstPad * pad, - gboolean last, gboolean * p_flag) -{ - /* we should not be reached */ - fail_unless (decodebin == NULL, "new-decoded-pad should not be emitted"); -} - -/* make sure that decodebin errors out instead of creating a new decoded pad - * if the entire stream is a plain text file */ -GST_START_TEST (test_text_plain_streams) -{ - GstElement *pipe, *src, *decodebin; - GstMessage *msg; - - pipe = gst_pipeline_new (NULL); - fail_unless (pipe != NULL, "failed to create pipeline"); - - src = gst_element_factory_make ("fakesrc", "src"); - fail_unless (src != NULL, "Failed to create fakesrc element"); - - g_object_set (src, "signal-handoffs", TRUE, NULL); - g_object_set (src, "num-buffers", 1, NULL); - g_object_set (src, "can-activate-pull", FALSE, NULL); - g_signal_connect (src, "handoff", G_CALLBACK (src_handoff_cb), NULL); - - decodebin = gst_element_factory_make ("decodebin2", "decodebin"); - fail_unless (decodebin != NULL, "Failed to create decodebin element"); - - g_signal_connect (decodebin, "new-decoded-pad", - G_CALLBACK (decodebin_new_decoded_pad_cb), NULL); - - fail_unless (gst_bin_add (GST_BIN (pipe), src)); - fail_unless (gst_bin_add (GST_BIN (pipe), decodebin)); - fail_unless (gst_element_link (src, decodebin), "can't link src<->decodebin"); - - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - /* it's push-based, so should be async */ - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - - /* it should error out at some point */ - msg = gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, -1); - fail_unless (msg != NULL); - fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR); - gst_message_unref (msg); - - gst_element_set_state (pipe, GST_STATE_NULL); - gst_object_unref (pipe); -} - -GST_END_TEST; - -static void -new_decoded_pad_plug_fakesink_cb (GstElement * decodebin, GstPad * srcpad, - gboolean last, GstElement * pipeline) -{ - GstElement *sink; - GstPad *sinkpad; - - GST_LOG ("Linking fakesink"); - - sink = gst_element_factory_make ("fakesink", "sink"); - fail_unless (sink != NULL, "Failed to create fakesink element"); - - gst_bin_add (GST_BIN (pipeline), sink); - - sinkpad = gst_element_get_static_pad (sink, "sink"); - fail_unless_equals_int (gst_pad_link (srcpad, sinkpad), GST_PAD_LINK_OK); - gst_object_unref (sinkpad); - - gst_element_set_state (sink, GST_STATE_PLAYING); -} - -GST_START_TEST (test_reuse_without_decoders) -{ - GstElement *pipe, *src, *decodebin, *sink; - - pipe = gst_pipeline_new (NULL); - fail_unless (pipe != NULL, "failed to create pipeline"); - - src = gst_element_factory_make ("audiotestsrc", "src"); - fail_unless (src != NULL, "Failed to create audiotestsrc element"); - - decodebin = gst_element_factory_make ("decodebin2", "decodebin"); - fail_unless (decodebin != NULL, "Failed to create decodebin element"); - - g_signal_connect (decodebin, "new-decoded-pad", - G_CALLBACK (new_decoded_pad_plug_fakesink_cb), pipe); - - fail_unless (gst_bin_add (GST_BIN (pipe), src)); - fail_unless (gst_bin_add (GST_BIN (pipe), decodebin)); - fail_unless (gst_element_link (src, decodebin), "can't link src<->decodebin"); - - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - /* it's push-based, so should be async */ - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - - /* wait for state change to complete */ - fail_unless_equals_int (gst_element_get_state (pipe, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - /* there shouldn't be any errors */ - fail_if (gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, 0) != NULL); - - /* reset */ - gst_element_set_state (pipe, GST_STATE_READY); - - sink = gst_bin_get_by_name (GST_BIN (pipe), "sink"); - gst_bin_remove (GST_BIN (pipe), sink); - gst_element_set_state (sink, GST_STATE_NULL); - gst_object_unref (sink); - - GST_LOG ("second try"); - - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - /* it's push-based, so should be async */ - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - - /* wait for state change to complete */ - fail_unless_equals_int (gst_element_get_state (pipe, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - /* there shouldn't be any errors */ - fail_if (gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, 0) != NULL); - - gst_element_set_state (pipe, GST_STATE_NULL); - gst_object_unref (pipe); -} - -GST_END_TEST; - -static Suite * -decodebin2_suite (void) -{ - Suite *s = suite_create ("decodebin2"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_text_plain_streams); - tcase_add_test (tc_chain, test_reuse_without_decoders); - - return s; -} - -GST_CHECK_MAIN (decodebin2); diff --git a/tests/check/elements/ffmpegcolorspace.c b/tests/check/elements/ffmpegcolorspace.c deleted file mode 100644 index 60179c61..00000000 --- a/tests/check/elements/ffmpegcolorspace.c +++ /dev/null @@ -1,439 +0,0 @@ -/* GStreamer - * - * unit test for ffmpegcolorspace - * - * Copyright (C) <2006> Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#ifdef HAVE_VALGRIND -# include <valgrind/valgrind.h> -#endif - -#include <unistd.h> - -#include <gst/check/gstcheck.h> - -typedef struct _RGBFormat -{ - const gchar *nick; - guint bpp, depth; - guint32 red_mask, green_mask, blue_mask, alpha_mask; - guint endianness; -} RGBFormat; - -typedef struct _RGBConversion -{ - RGBFormat from_fmt; - RGBFormat to_fmt; - GstCaps *from_caps; - GstCaps *to_caps; -} RGBConversion; - -static GstCaps * -rgb_format_to_caps (RGBFormat * fmt) -{ - GstCaps *caps; - - g_assert (fmt != NULL); - g_assert (fmt->endianness != 0); - - caps = gst_caps_new_simple ("video/x-raw-rgb", - "bpp", G_TYPE_INT, fmt->bpp, - "depth", G_TYPE_INT, fmt->depth, - "red_mask", G_TYPE_INT, fmt->red_mask, - "green_mask", G_TYPE_INT, fmt->green_mask, - "blue_mask", G_TYPE_INT, fmt->blue_mask, - "width", G_TYPE_INT, 16, "height", G_TYPE_INT, 16, - "endianness", G_TYPE_INT, fmt->endianness, - "framerate", GST_TYPE_FRACTION, 1, 1, NULL); - - fail_unless (fmt->alpha_mask == 0 || fmt->bpp == 32); - - if (fmt->alpha_mask != 0) { - gst_structure_set (gst_caps_get_structure (caps, 0), - "alpha_mask", G_TYPE_INT, fmt->alpha_mask, NULL); - } - - return caps; -} - -static GList * -create_rgb_conversions (void) -{ - const RGBFormat rgb_formats[] = { - { - "RGBA", 32, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, 0}, { - "ARGB", 32, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000, 0}, { - "BGRA", 32, 32, 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff, 0}, { - "ABGR", 32, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, 0}, { - "RGBx", 32, 24, 0xff000000, 0x00ff0000, 0x0000ff00, 0x00000000, 0}, { - "xRGB", 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000, 0}, { - "BGRx", 32, 24, 0x0000ff00, 0x00ff0000, 0xff000000, 0x00000000, 0}, { - "xBGR", 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000, 0}, { - "RGB ", 24, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000, 0}, { - "BGR ", 24, 24, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000, 0}, { - "RGB565", 16, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000, 0}, { - "xRGB1555", 16, 15, 0x00007c00, 0x000003e0, 0x0000001f, 0x0000000, 0} - }; - const struct - { - guint from_endianness, to_endianness; - } end_arr[4] = { - { - G_LITTLE_ENDIAN, G_LITTLE_ENDIAN}, { - G_BIG_ENDIAN, G_LITTLE_ENDIAN}, { - G_LITTLE_ENDIAN, G_BIG_ENDIAN}, { - G_BIG_ENDIAN, G_BIG_ENDIAN} - }; - GList *conversions = NULL; - guint from_fmt, to_fmt; - - for (from_fmt = 0; from_fmt < G_N_ELEMENTS (rgb_formats); ++from_fmt) { - for (to_fmt = 0; to_fmt < G_N_ELEMENTS (rgb_formats); ++to_fmt) { - guint i; - - for (i = 0; i < 4; ++i) { - RGBConversion *conversion; - - conversion = g_new0 (RGBConversion, 1); - conversion->from_fmt = rgb_formats[from_fmt]; - conversion->to_fmt = rgb_formats[to_fmt]; - conversion->from_fmt.endianness = end_arr[i].from_endianness; - conversion->to_fmt.endianness = end_arr[i].to_endianness; - conversion->from_caps = rgb_format_to_caps (&conversion->from_fmt); - conversion->to_caps = rgb_format_to_caps (&conversion->to_fmt); - conversions = g_list_prepend (conversions, conversion); - } - } - } - - return g_list_reverse (conversions); -} - -static void -rgb_conversion_free (RGBConversion * conv) -{ - gst_caps_unref (conv->from_caps); - gst_caps_unref (conv->to_caps); - memset (conv, 0x99, sizeof (RGBConversion)); - g_free (conv); -} - -static guint32 -right_shift_colour (guint32 mask, guint32 pixel) -{ - if (mask == 0) - return 0; - - pixel = pixel & mask; - while ((mask & 0x01) == 0) { - mask = mask >> 1; - pixel = pixel >> 1; - } - - return pixel; -} - -static guint8 -fix_expected_colour (guint32 col_mask, guint8 col_expected) -{ - guint32 mask; - gint last = g_bit_nth_msf (col_mask, -1); - gint first = g_bit_nth_lsf (col_mask, -1); - - mask = 1 << (last - first + 1); - mask -= 1; - - g_assert (col_expected == 0x00 || col_expected == 0xff); - - /* this only works because we only check for all-bits-set or no-bits-set */ - return col_expected & mask; -} - -static void -check_rgb_buf (const guint8 * pixels, guint32 r_mask, guint32 g_mask, - guint32 b_mask, guint32 a_mask, guint8 r_expected, guint8 g_expected, - guint8 b_expected, guint endianness, guint bpp, guint depth) -{ - guint32 pixel, red, green, blue, alpha; - - switch (bpp) { - case 32:{ - if (endianness == G_LITTLE_ENDIAN) - pixel = GST_READ_UINT32_LE (pixels); - else - pixel = GST_READ_UINT32_BE (pixels); - break; - } - case 24:{ - if (endianness == G_BIG_ENDIAN) { - pixel = (GST_READ_UINT8 (pixels) << 16) | - (GST_READ_UINT8 (pixels + 1) << 8) | - (GST_READ_UINT8 (pixels + 2) << 0); - } else { - pixel = (GST_READ_UINT8 (pixels + 2) << 16) | - (GST_READ_UINT8 (pixels + 1) << 8) | - (GST_READ_UINT8 (pixels + 0) << 0); - } - break; - } - case 16:{ - if (endianness == G_LITTLE_ENDIAN) - pixel = GST_READ_UINT16_LE (pixels); - else - pixel = GST_READ_UINT16_BE (pixels); - break; - } - default: - g_return_if_reached (); - } - - red = right_shift_colour (r_mask, pixel); - green = right_shift_colour (g_mask, pixel); - blue = right_shift_colour (b_mask, pixel); - alpha = right_shift_colour (a_mask, pixel); - - /* can't enable this by default, valgrind will complain about accessing - * uninitialised memory for the depth=24,bpp=32 formats ... */ - /* GST_LOG ("pixels: 0x%02x 0x%02x 0x%02x 0x%02x => pixel = 0x%08x", - pixels[0], (guint) pixels[1], pixels[2], pixels[3], pixel); */ - - /* fix up the mask (for rgb15/16) */ - if (bpp == 16) { - r_expected = fix_expected_colour (r_mask, r_expected); - g_expected = fix_expected_colour (g_mask, g_expected); - b_expected = fix_expected_colour (b_mask, b_expected); - } - - fail_unless (red == r_expected, "RED: expected 0x%02x, found 0x%02x " - "Bytes: 0x%02x 0x%02x 0x%02x 0x%02x Pixel: 0x%08x", r_expected, red, - pixels[0], pixels[1], pixels[2], pixels[3], pixel); - fail_unless (green == g_expected, "GREEN: expected 0x%02x, found 0x%02x " - "Bytes: 0x%02x 0x%02x 0x%02x 0x%02x Pixel: 0x%08x", g_expected, green, - pixels[0], pixels[1], pixels[2], pixels[3], pixel); - fail_unless (blue == b_expected, "BLUE: expected 0x%02x, found 0x%02x " - "Bytes: 0x%02x 0x%02x 0x%02x 0x%02x Pixel: 0x%08x", b_expected, blue, - pixels[0], pixels[1], pixels[2], pixels[3], pixel); - -// FIXME: fix alpha check -// fail_unless (a_mask == 0 || alpha != 0); /* better than nothing */ -} - -static void -got_buf_cb (GstElement * sink, GstBuffer * new_buf, GstPad * pad, - GstBuffer ** p_old_buf) -{ - gst_buffer_replace (p_old_buf, new_buf); -} - -/* Note: lots of this code here is also in the videotestsrc.c unit test */ -GST_START_TEST (test_rgb_to_rgb) -{ - const struct - { - const gchar *pattern_name; - gint pattern_enum; - guint8 r_expected; - guint8 g_expected; - guint8 b_expected; - } test_patterns[] = { - { - "white", 3, 0xff, 0xff, 0xff}, { - "red", 4, 0xff, 0x00, 0x00}, { - "green", 5, 0x00, 0xff, 0x00}, { - "blue", 6, 0x00, 0x00, 0xff}, { - "black", 2, 0x00, 0x00, 0x00} - }; - GstElement *pipeline, *src, *filter1, *csp, *filter2, *sink; - const GstCaps *template_caps; - GstBuffer *buf = NULL; - GstPad *srcpad; - GList *conversions, *l; - gint p; - - /* test check function */ - fail_unless (right_shift_colour (0x00ff0000, 0x11223344) == 0x22); - - pipeline = gst_pipeline_new ("pipeline"); - src = gst_check_setup_element ("videotestsrc"); - filter1 = gst_check_setup_element ("capsfilter"); - csp = gst_check_setup_element ("ffmpegcolorspace"); - filter2 = gst_element_factory_make ("capsfilter", "to_filter"); - sink = gst_check_setup_element ("fakesink"); - - gst_bin_add_many (GST_BIN (pipeline), src, filter1, csp, filter2, sink, NULL); - - fail_unless (gst_element_link (src, filter1)); - fail_unless (gst_element_link (filter1, csp)); - fail_unless (gst_element_link (csp, filter2)); - fail_unless (gst_element_link (filter2, sink)); - - srcpad = gst_element_get_static_pad (src, "src"); - template_caps = gst_pad_get_pad_template_caps (srcpad); - gst_object_unref (srcpad); - - g_object_set (sink, "signal-handoffs", TRUE, NULL); - g_signal_connect (sink, "preroll-handoff", G_CALLBACK (got_buf_cb), &buf); - - GST_LOG ("videotestsrc src template caps: %" GST_PTR_FORMAT, template_caps); - - conversions = create_rgb_conversions (); - - for (l = conversions; l != NULL; l = l->next) { - RGBConversion *conv = (RGBConversion *) l->data; - - /* does videotestsrc support the from_caps? */ - if (!gst_caps_is_subset (conv->from_caps, template_caps)) { - GST_DEBUG ("videotestsrc doesn't support from_caps %" GST_PTR_FORMAT, - conv->from_caps); - continue; - } - - /* caps are supported, let's run some tests then ... */ - for (p = 0; p < G_N_ELEMENTS (test_patterns); ++p) { - GstStateChangeReturn state_ret; - RGBFormat *from = &conv->from_fmt; - RGBFormat *to = &conv->to_fmt; - - /* trick compiler into thinking from is used, might throw warning - * otherwise if the debugging system is disabled */ - fail_unless (from != NULL); - - gst_element_set_state (pipeline, GST_STATE_NULL); - - g_object_set (src, "pattern", test_patterns[p].pattern_enum, NULL); - - GST_INFO ("%5s %u/%u %08x %08x %08x %08x %u => " - "%5s %u/%u %08x %08x %08x %08x %u, pattern=%s", - from->nick, from->bpp, from->depth, from->red_mask, - from->green_mask, from->blue_mask, from->alpha_mask, - from->endianness, to->nick, to->bpp, to->depth, to->red_mask, - to->green_mask, to->blue_mask, to->alpha_mask, to->endianness, - test_patterns[p].pattern_name); - - /* now get videotestsrc to produce a buffer with the given caps */ - g_object_set (filter1, "caps", conv->from_caps, NULL); - - /* ... and force ffmpegcolorspace to convert to our target caps */ - g_object_set (filter2, "caps", conv->to_caps, NULL); - - state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED); - if (state_ret == GST_STATE_CHANGE_FAILURE) { - GstMessage *msg; - GError *err = NULL; - - msg = gst_bus_poll (GST_ELEMENT_BUS (pipeline), GST_MESSAGE_ERROR, 0); - fail_if (msg == NULL, "expected ERROR message on the bus"); - fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR); - gst_message_parse_error (msg, &err, NULL); - fail_unless (err != NULL); - if (msg->src == GST_OBJECT_CAST (src) && - err->code == GST_STREAM_ERROR_FORMAT) { - GST_DEBUG ("ffmpegcolorspace does not support this conversion"); - gst_message_unref (msg); - g_error_free (err); - continue; - } - fail_unless (state_ret != GST_STATE_CHANGE_FAILURE, - "pipeline _set_state() to PAUSED failed: %s", err->message); - } - - state_ret = gst_element_get_state (pipeline, NULL, NULL, -1); - fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS, - "pipeline failed going to PAUSED state"); - - state_ret = gst_element_set_state (pipeline, GST_STATE_NULL); - fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS); - - fail_unless (buf != NULL); - - /* check buffer caps */ - { - GstStructure *s; - gint v; - - fail_unless (GST_BUFFER_CAPS (buf) != NULL); - s = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0); - fail_unless (gst_structure_get_int (s, "bpp", &v)); - fail_unless_equals_int (v, to->bpp); - fail_unless (gst_structure_get_int (s, "depth", &v)); - fail_unless_equals_int (v, to->depth); - fail_unless (gst_structure_get_int (s, "red_mask", &v)); - fail_unless_equals_int (v, to->red_mask); - fail_unless (gst_structure_get_int (s, "green_mask", &v)); - fail_unless_equals_int (v, to->green_mask); - fail_unless (gst_structure_get_int (s, "blue_mask", &v)); - fail_unless_equals_int (v, to->blue_mask); - /* there mustn't be an alpha_mask if there's no alpha component */ - if (to->depth == 32) { - fail_unless (gst_structure_get_int (s, "alpha_mask", &v)); - fail_unless_equals_int (v, to->alpha_mask); - } else { - fail_unless (gst_structure_get_value (s, "alpha_mask") == NULL); - } - } - - /* now check the top-left pixel */ - check_rgb_buf (GST_BUFFER_DATA (buf), to->red_mask, - to->green_mask, to->blue_mask, to->alpha_mask, - test_patterns[p].r_expected, test_patterns[p].g_expected, - test_patterns[p].b_expected, to->endianness, to->bpp, to->depth); - - gst_buffer_unref (buf); - buf = NULL; - } - } - - g_list_foreach (conversions, (GFunc) rgb_conversion_free, NULL); - g_list_free (conversions); - - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); -} - -GST_END_TEST; - -static Suite * -ffmpegcolorspace_suite (void) -{ - Suite *s = suite_create ("ffmpegcolorspace"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - -#ifdef HAVE_VALGRIND - if (RUNNING_ON_VALGRIND) { - /* otherwise valgrind errors out when liboil probes CPU extensions - * during which it causes SIGILLs etc. to be fired */ - g_setenv ("OIL_CPU_FLAGS", "0", 0); - /* test_rgb_formats takes a bit longer, so increase timeout */ - tcase_set_timeout (tc_chain, 10 * 60); - } -#endif - - /* FIXME: add tests for YUV <=> YUV and YUV <=> RGB */ - tcase_add_test (tc_chain, test_rgb_to_rgb); - - return s; -} - -GST_CHECK_MAIN (ffmpegcolorspace); diff --git a/tests/check/elements/gdpdepay.c b/tests/check/elements/gdpdepay.c deleted file mode 100644 index 60bc1aed..00000000 --- a/tests/check/elements/gdpdepay.c +++ /dev/null @@ -1,428 +0,0 @@ -/* GStreamer - * - * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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 "config.h" -#include <string.h> -#include <unistd.h> - -#include <gst/check/gstcheck.h> -#include <gst/dataprotocol/dataprotocol.h> - -/* For ease of programming we use globals to keep refs for our floating - * src and sink pads we create; otherwise we always have to do get_pad, - * get_peer, and then remove references in every test function */ -static GstPad *mysrcpad, *mysinkpad, *myshsinkpad; - -#define AUDIO_CAPS_TEMPLATE_STRING \ - "audio/x-raw-int, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, 8 ], " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) {8, 16}, " \ - "depth = (int) {8, 16}, " \ - "signed = (boolean) true" - -#define AUDIO_CAPS_STRING \ - "audio/x-raw-int, " \ - "rate = (int) 1000, " \ - "channels = (int) 2, " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 16, " \ - "depth = (int) 16, " \ - "signed = (boolean) true" - - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (AUDIO_CAPS_TEMPLATE_STRING) - ); -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("application/x-gdp") - ); - -/* takes over reference for outcaps */ -static GstElement * -setup_gdpdepay (void) -{ - GstElement *gdpdepay; - - GST_DEBUG ("setup_gdpdepay"); - gdpdepay = gst_check_setup_element ("gdpdepay"); - mysrcpad = gst_check_setup_src_pad (gdpdepay, &srctemplate, NULL); - mysinkpad = gst_check_setup_sink_pad (gdpdepay, &sinktemplate, NULL); - gst_pad_set_active (mysrcpad, TRUE); - gst_pad_set_active (mysinkpad, TRUE); - - return gdpdepay; -} - -static void -cleanup_gdpdepay (GstElement * gdpdepay) -{ - GST_DEBUG ("cleanup_gdpdepay"); - - gst_pad_set_active (mysrcpad, FALSE); - if (mysinkpad) - gst_pad_set_active (mysinkpad, FALSE); - if (myshsinkpad) - gst_pad_set_active (myshsinkpad, FALSE); - gst_check_teardown_src_pad (gdpdepay); - gst_check_teardown_sink_pad (gdpdepay); - gst_check_teardown_element (gdpdepay); - mysinkpad = NULL; - myshsinkpad = NULL; -} - -static void -gdpdepay_push_per_byte (gchar * reason, guint8 * bytes, guint length) -{ - int i; - GstBuffer *inbuffer; - - for (i = 0; i < length; ++i) { - inbuffer = gst_buffer_new_and_alloc (1); - GST_BUFFER_DATA (inbuffer)[0] = bytes[i]; - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK, - "%s: failed pushing byte buffer", reason); - } -} - -GST_START_TEST (test_audio_per_byte) -{ - GstCaps *caps; - GstPad *srcpad; - GstElement *gdpdepay; - GstBuffer *buffer, *outbuffer; - guint8 *header, *payload; - guint len; - GstDPPacketizer *pk; - - pk = gst_dp_packetizer_new (GST_DP_VERSION_1_0); - - gdpdepay = setup_gdpdepay (); - srcpad = gst_element_get_static_pad (gdpdepay, "src"); - - fail_unless (gst_element_set_state (gdpdepay, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - caps = gst_pad_get_caps (srcpad); - fail_unless (gst_caps_is_any (caps)); - gst_caps_unref (caps); - fail_if (gst_pad_get_negotiated_caps (srcpad)); - - /* create caps and buffer packets and push them */ - caps = gst_caps_from_string (AUDIO_CAPS_STRING); - fail_unless (pk->packet_from_caps (caps, 0, &len, &header, &payload)); - gst_caps_unref (caps); - gdpdepay_push_per_byte ("caps header", header, len); - fail_unless_equals_int (g_list_length (buffers), 0); - gdpdepay_push_per_byte ("caps payload", payload, - gst_dp_header_payload_length (header)); - fail_unless_equals_int (g_list_length (buffers), 0); - caps = gst_pad_get_caps (srcpad); - fail_if (gst_caps_is_any (caps)); - gst_caps_unref (caps); - - g_free (header); - g_free (payload); - - buffer = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (buffer), "f00d", 4); - GST_BUFFER_TIMESTAMP (buffer) = GST_SECOND; - GST_BUFFER_DURATION (buffer) = GST_SECOND / 10; - fail_unless (pk->header_from_buffer (buffer, 0, &len, &header)); - gdpdepay_push_per_byte ("buffer header", header, len); - fail_unless_equals_int (g_list_length (buffers), 0); - gdpdepay_push_per_byte ("buffer payload", GST_BUFFER_DATA (buffer), - gst_dp_header_payload_length (header)); - g_free (header); - gst_buffer_unref (buffer); - - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (outbuffer), GST_SECOND); - fail_unless_equals_uint64 (GST_BUFFER_DURATION (outbuffer), GST_SECOND / 10); - - buffers = g_list_remove (buffers, outbuffer); - gst_buffer_unref (outbuffer); - - fail_unless (gst_element_set_state (gdpdepay, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); - - ASSERT_OBJECT_REFCOUNT (gdpdepay, "gdpdepay", 1); - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - gst_object_unref (srcpad); - cleanup_gdpdepay (gdpdepay); - - gst_dp_packetizer_free (pk); -} - -GST_END_TEST; - -GST_START_TEST (test_audio_in_one_buffer) -{ - GstCaps *caps; - GstPad *srcpad; - GstElement *gdpdepay; - GstBuffer *buffer, *inbuffer; - guint8 *caps_header, *caps_payload, *buf_header; - guint header_len, payload_len; - guint i; - GstDPPacketizer *pk; - - pk = gst_dp_packetizer_new (GST_DP_VERSION_1_0); - - gdpdepay = setup_gdpdepay (); - srcpad = gst_element_get_static_pad (gdpdepay, "src"); - - fail_unless (gst_element_set_state (gdpdepay, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - /* make sure no caps are set yet */ - caps = gst_pad_get_caps (srcpad); - fail_unless (gst_caps_is_any (caps)); - gst_caps_unref (caps); - fail_if (gst_pad_get_negotiated_caps (srcpad)); - - /* create caps and buffer packets and push them as one buffer */ - caps = gst_caps_from_string (AUDIO_CAPS_STRING); - fail_unless (pk->packet_from_caps (caps, 0, &header_len, &caps_header, - &caps_payload)); - - buffer = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (buffer), "f00d", 4); - fail_unless (pk->header_from_buffer (buffer, 0, &header_len, &buf_header)); - - payload_len = gst_dp_header_payload_length (caps_header); - - inbuffer = gst_buffer_new_and_alloc (2 * GST_DP_HEADER_LENGTH + - payload_len + GST_BUFFER_SIZE (buffer)); - memcpy (GST_BUFFER_DATA (inbuffer), caps_header, GST_DP_HEADER_LENGTH); - i = GST_DP_HEADER_LENGTH; - memcpy (GST_BUFFER_DATA (inbuffer) + i, caps_payload, payload_len); - i += payload_len; - memcpy (GST_BUFFER_DATA (inbuffer) + i, buf_header, GST_DP_HEADER_LENGTH); - i += GST_DP_HEADER_LENGTH; - memcpy (GST_BUFFER_DATA (inbuffer) + i, GST_BUFFER_DATA (buffer), - GST_BUFFER_SIZE (buffer)); - - gst_caps_unref (caps); - gst_buffer_unref (buffer); - - g_free (caps_header); - g_free (caps_payload); - g_free (buf_header); - - /* now push it */ - gst_pad_push (mysrcpad, inbuffer); - - /* the buffer is still queued */ - fail_unless_equals_int (g_list_length (buffers), 1); - - fail_unless (gst_element_set_state (gdpdepay, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); - - gst_object_unref (srcpad); - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ASSERT_OBJECT_REFCOUNT (gdpdepay, "gdpdepay", 1); - cleanup_gdpdepay (gdpdepay); - - gst_dp_packetizer_free (pk); -} - -GST_END_TEST; - -static GstStaticPadTemplate shsinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("application/x-gst-test-streamheader") - ); - -static GstElement * -setup_gdpdepay_streamheader (void) -{ - GstElement *gdpdepay; - - GST_DEBUG ("setup_gdpdepay"); - gdpdepay = gst_check_setup_element ("gdpdepay"); - mysrcpad = gst_check_setup_src_pad (gdpdepay, &srctemplate, NULL); - myshsinkpad = gst_check_setup_sink_pad (gdpdepay, &shsinktemplate, NULL); - gst_pad_set_active (mysrcpad, TRUE); - gst_pad_set_active (myshsinkpad, TRUE); - - return gdpdepay; -} - -/* this tests deserialization of a GDP stream where the serialized caps - * have a streamheader set */ -GST_START_TEST (test_streamheader) -{ - GstCaps *caps, *padcaps; - GstPad *srcpad; - GstElement *gdpdepay; - GstBuffer *buffer, *inbuffer, *outbuffer, *shbuffer; - guint8 *caps_header, *caps_payload, *buf_header; - guint header_len, payload_len; - guint i; - GstStructure *structure; - GValue array = { 0 }; - GValue value = { 0 }; - GstDPPacketizer *pk; - - pk = gst_dp_packetizer_new (GST_DP_VERSION_1_0); - - gdpdepay = setup_gdpdepay_streamheader (); - srcpad = gst_element_get_static_pad (gdpdepay, "src"); - ASSERT_OBJECT_REFCOUNT (gdpdepay, "gdpdepay", 1); - - fail_unless (gst_element_set_state (gdpdepay, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - /* make sure no caps are set yet */ - caps = gst_pad_get_caps (srcpad); - fail_unless (gst_caps_is_any (caps)); - gst_caps_unref (caps); - fail_if (gst_pad_get_negotiated_caps (srcpad)); - - /* create a streamheader buffer and the caps containing it */ - caps = gst_caps_from_string ("application/x-gst-test-streamheader"); - structure = gst_caps_get_structure (caps, 0); - buffer = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (buffer), "f00d", 4); - GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS); - g_value_init (&array, GST_TYPE_ARRAY); - g_value_init (&value, GST_TYPE_BUFFER); - shbuffer = gst_buffer_copy (buffer); - gst_value_set_buffer (&value, shbuffer); - gst_buffer_unref (shbuffer); - gst_value_array_append_value (&array, &value); - g_value_unset (&value); - gst_structure_set_value (structure, "streamheader", &array); - g_value_unset (&array); - - gst_buffer_set_caps (buffer, caps); - - /* create GDP packets for the caps and the buffer, and put them in one - * GDP buffer */ - fail_unless (pk->packet_from_caps (caps, 0, &header_len, &caps_header, - &caps_payload)); - - fail_unless (pk->header_from_buffer (buffer, 0, &header_len, &buf_header)); - - payload_len = gst_dp_header_payload_length (caps_header); - - inbuffer = gst_buffer_new_and_alloc (2 * GST_DP_HEADER_LENGTH + - payload_len + GST_BUFFER_SIZE (buffer)); - memcpy (GST_BUFFER_DATA (inbuffer), caps_header, GST_DP_HEADER_LENGTH); - i = GST_DP_HEADER_LENGTH; - memcpy (GST_BUFFER_DATA (inbuffer) + i, caps_payload, payload_len); - i += payload_len; - memcpy (GST_BUFFER_DATA (inbuffer) + i, buf_header, GST_DP_HEADER_LENGTH); - i += GST_DP_HEADER_LENGTH; - memcpy (GST_BUFFER_DATA (inbuffer) + i, GST_BUFFER_DATA (buffer), - GST_BUFFER_SIZE (buffer)); - - gst_caps_unref (caps); - gst_buffer_unref (buffer); - - g_free (caps_header); - g_free (caps_payload); - g_free (buf_header); - - /* now push it */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_pad_push (mysrcpad, inbuffer); - - /* our only output buffer is the streamheader buffer */ - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); - fail_unless (GST_BUFFER_FLAG_IS_SET (outbuffer, GST_BUFFER_FLAG_IN_CAPS)); - - padcaps = gst_pad_get_negotiated_caps (myshsinkpad); - caps = gst_buffer_get_caps (outbuffer); - fail_if (caps == NULL); - fail_if (padcaps == NULL); - GST_DEBUG ("caps: %" GST_PTR_FORMAT ", padcaps: %" GST_PTR_FORMAT, caps, - padcaps); - fail_unless (gst_caps_is_equal (padcaps, caps)); - - /* FIXME: get streamheader, compare data with buffer */ - gst_buffer_unref (outbuffer); - gst_caps_unref (padcaps); - gst_caps_unref (caps); - - /* clean up */ - fail_unless (gst_element_set_state (gdpdepay, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); - - gst_object_unref (srcpad); - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ASSERT_OBJECT_REFCOUNT (gdpdepay, "gdpdepay", 1); - cleanup_gdpdepay (gdpdepay); - - gst_dp_packetizer_free (pk); -} - -GST_END_TEST; - -static Suite * -gdpdepay_suite (void) -{ - Suite *s = suite_create ("gdpdepay"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_audio_per_byte); - tcase_add_test (tc_chain, test_audio_in_one_buffer); - tcase_add_test (tc_chain, test_streamheader); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = gdpdepay_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/elements/gdppay.c b/tests/check/elements/gdppay.c deleted file mode 100644 index 267b266d..00000000 --- a/tests/check/elements/gdppay.c +++ /dev/null @@ -1,581 +0,0 @@ -/* GStreamer - * - * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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 <string.h> -#include <unistd.h> - -#include <gst/check/gstcheck.h> -#include <gst/dataprotocol/dataprotocol.h> - -/* For ease of programming we use globals to keep refs for our floating - * src and sink pads we create; otherwise we always have to do get_pad, - * get_peer, and then remove references in every test function */ -static GstPad *mysrcpad, *myshsrcpad, *mysinkpad; - -#define AUDIO_CAPS_TEMPLATE_STRING \ - "audio/x-raw-int, " \ - "rate = (int) [ 1, MAX ], " \ - "channels = (int) [ 1, 8 ], " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) {8, 16}, " \ - "depth = (int) {8, 16}, " \ - "signed = (boolean) true" - -#define AUDIO_CAPS_STRING \ - "audio/x-raw-int, " \ - "rate = (int) 1000, " \ - "channels = (int) 2, " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 16, " \ - "depth = (int) 16, " \ - "signed = (boolean) true" - - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("application/x-gdp") - ); -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (AUDIO_CAPS_TEMPLATE_STRING) - ); - -/* takes over reference for outcaps */ -static GstElement * -setup_gdppay (void) -{ - GstElement *gdppay; - - GST_DEBUG ("setup_gdppay"); - gdppay = gst_check_setup_element ("gdppay"); - mysrcpad = gst_check_setup_src_pad (gdppay, &srctemplate, NULL); - mysinkpad = gst_check_setup_sink_pad (gdppay, &sinktemplate, NULL); - gst_pad_set_active (mysrcpad, TRUE); - gst_pad_set_active (mysinkpad, TRUE); - - return gdppay; -} - -static void -cleanup_gdppay (GstElement * gdppay) -{ - GST_DEBUG ("cleanup_gdppay"); - - if (mysrcpad) - gst_pad_set_active (mysrcpad, FALSE); - if (myshsrcpad) - gst_pad_set_active (myshsrcpad, FALSE); - gst_pad_set_active (mysinkpad, FALSE); - gst_check_teardown_src_pad (gdppay); - gst_check_teardown_sink_pad (gdppay); - gst_check_teardown_element (gdppay); - mysrcpad = NULL; - myshsrcpad = NULL; -} - -GST_START_TEST (test_audio) -{ - GstCaps *caps; - GstElement *gdppay; - GstBuffer *inbuffer, *outbuffer; - GstEvent *event; - gchar *caps_string; - gint length; - - gdppay = setup_gdppay (); - - fail_unless (gst_element_set_state (gdppay, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - GST_DEBUG ("new segment"); - event = - gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, GST_SECOND, 0); - fail_unless (gst_pad_push_event (mysrcpad, event)); - - /* no buffer should be pushed yet, waiting for caps */ - fail_unless_equals_int (g_list_length (buffers), 0); - - GST_DEBUG ("first buffer"); - inbuffer = gst_buffer_new_and_alloc (4); - caps = gst_caps_from_string (AUDIO_CAPS_STRING); - gst_buffer_set_caps (inbuffer, caps); - caps_string = gst_caps_to_string (caps); - - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - /* we should have three buffers now */ - fail_unless_equals_int (g_list_length (buffers), 3); - - /* first buffer is the serialized new_segment event; - * the element also holds a ref to it */ - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2); - gst_buffer_unref (outbuffer); - - /* second buffer is the serialized caps; - * the element also holds a ref to it */ - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2); - length = GST_DP_HEADER_LENGTH + (strlen (caps_string) + 1); - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); - gst_buffer_unref (outbuffer); - - /* the third buffer is the GDP buffer for our pushed buffer */ - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); - length = GST_DP_HEADER_LENGTH + 4; - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); - gst_buffer_unref (outbuffer); - - /* second buffer */ - GST_DEBUG ("second buffer"); - inbuffer = gst_buffer_new_and_alloc (4); - gst_buffer_set_caps (inbuffer, caps); - - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); - - /* the third output buffer is data */ - length = GST_DP_HEADER_LENGTH + 4; - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); - gst_buffer_unref (outbuffer); - - /* a third buffer without caps set explicitly; should work */ - GST_DEBUG ("Creating third buffer, no caps set"); - inbuffer = gst_buffer_new_and_alloc (4); - - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); - - /* the fourth output buffer is data */ - length = GST_DP_HEADER_LENGTH + 4; - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); - gst_buffer_unref (outbuffer); - - - fail_unless (gst_element_set_state (gdppay, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); - - gst_caps_unref (caps); - g_free (caps_string); - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ASSERT_OBJECT_REFCOUNT (gdppay, "gdppay", 1); - cleanup_gdppay (gdppay); -} - -GST_END_TEST; - -static GstStaticPadTemplate shsrctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("application/x-gst-test-streamheader") - ); - - -static GstElement * -setup_gdppay_streamheader (void) -{ - GstElement *gdppay; - - GST_DEBUG ("setup_gdppay"); - gdppay = gst_check_setup_element ("gdppay"); - myshsrcpad = gst_check_setup_src_pad (gdppay, &shsrctemplate, NULL); - mysinkpad = gst_check_setup_sink_pad (gdppay, &sinktemplate, NULL); - gst_pad_set_active (myshsrcpad, TRUE); - gst_pad_set_active (mysinkpad, TRUE); - - return gdppay; -} - -/* this test serializes a stream that already has a streamheader of its own. - * the streamheader should then be serialized and put on the GDP stream's - * streamheader */ -GST_START_TEST (test_streamheader) -{ - GstCaps *caps, *sinkcaps; - GstElement *gdppay; - GstBuffer *inbuffer, *outbuffer, *shbuffer; - GstEvent *event; - gchar *caps_string; - gint length; - GstStructure *structure; - GValue array = { 0 }; - GValue value = { 0 }; - const GValue *sh; - GArray *shbuffers; - - - gdppay = setup_gdppay_streamheader (); - - fail_unless (gst_element_set_state (gdppay, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - GST_DEBUG ("new segment"); - event = - gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, GST_SECOND, 0); - fail_unless (gst_pad_push_event (myshsrcpad, event)); - - /* no buffer should be pushed yet, still waiting for caps */ - fail_unless_equals_int (g_list_length (buffers), 0); - - GST_DEBUG ("first buffer"); - inbuffer = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (inbuffer), "head", 4); - caps = gst_caps_from_string ("application/x-gst-test-streamheader"); - structure = gst_caps_get_structure (caps, 0); - GST_BUFFER_FLAG_SET (inbuffer, GST_BUFFER_FLAG_IN_CAPS); - g_value_init (&array, GST_TYPE_ARRAY); - g_value_init (&value, GST_TYPE_BUFFER); - shbuffer = gst_buffer_copy (inbuffer); - gst_value_set_buffer (&value, shbuffer); - gst_buffer_unref (shbuffer); - gst_value_array_append_value (&array, &value); - g_value_unset (&value); - gst_structure_set_value (structure, "streamheader", &array); - g_value_unset (&array); - caps_string = gst_caps_to_string (caps); - - gst_buffer_set_caps (inbuffer, caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference */ - fail_unless (gst_pad_push (myshsrcpad, inbuffer) == GST_FLOW_OK); - - /* we should have three buffers now */ - fail_unless_equals_int (g_list_length (buffers), 3); - - /* our sink pad should now have GDP caps with a streamheader that includes - * GDP wrappings of our streamheader */ - sinkcaps = gst_pad_get_negotiated_caps (mysinkpad); - structure = gst_caps_get_structure (sinkcaps, 0); - fail_unless_equals_string ((gchar *) gst_structure_get_name (structure), - "application/x-gdp"); - fail_unless (gst_structure_has_field (structure, "streamheader")); - sh = gst_structure_get_value (structure, "streamheader"); - fail_unless (G_VALUE_TYPE (sh) == GST_TYPE_ARRAY); - shbuffers = g_value_peek_pointer (sh); - /* a serialized new_segment, a serialized caps, and serialization of our - * incoming streamheader */ - fail_unless_equals_int (shbuffers->len, 3); - - gst_caps_unref (sinkcaps); - - /* first buffer is the serialized new_segment event; - * the element also holds a ref to it */ - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2); - gst_buffer_unref (outbuffer); - - /* second buffer is the serialized caps; - * the element also holds a ref to it */ - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2); - length = GST_DP_HEADER_LENGTH + (strlen (caps_string) + 1); - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); - gst_buffer_unref (outbuffer); - - /* the third buffer is the GDP buffer for our pushed buffer */ - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); - length = GST_DP_HEADER_LENGTH + 4; - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); - gst_buffer_unref (outbuffer); - - /* second buffer */ - GST_DEBUG ("second buffer"); - inbuffer = gst_buffer_new_and_alloc (4); - gst_buffer_set_caps (inbuffer, caps); - - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference */ - fail_unless (gst_pad_push (myshsrcpad, inbuffer) == GST_FLOW_OK); - - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); - - /* the third output buffer is data */ - length = GST_DP_HEADER_LENGTH + 4; - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); - gst_buffer_unref (outbuffer); - - /* a third buffer without caps set explicitly; should work */ - GST_DEBUG ("Creating third buffer, no caps set"); - inbuffer = gst_buffer_new_and_alloc (4); - - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference */ - fail_unless (gst_pad_push (myshsrcpad, inbuffer) == GST_FLOW_OK); - - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); - - /* the fourth output buffer is data */ - length = GST_DP_HEADER_LENGTH + 4; - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); - gst_buffer_unref (outbuffer); - - - fail_unless (gst_element_set_state (gdppay, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); - - gst_caps_unref (caps); - g_free (caps_string); - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ASSERT_OBJECT_REFCOUNT (gdppay, "gdppay", 1); - cleanup_gdppay (gdppay); -} - -GST_END_TEST; - - -GST_START_TEST (test_first_no_caps) -{ - GstElement *gdppay; - GstBuffer *inbuffer; - - gdppay = setup_gdppay (); - - fail_unless (gst_element_set_state (gdppay, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - GST_DEBUG ("first buffer"); - inbuffer = gst_buffer_new_and_alloc (4); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing should trigger an error */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_NOT_NEGOTIATED); - - fail_unless_equals_int (g_list_length (buffers), 0); - - fail_unless (gst_element_set_state (gdppay, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); - - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ASSERT_OBJECT_REFCOUNT (gdppay, "gdppay", 1); - cleanup_gdppay (gdppay); -} - -GST_END_TEST; - -/* element should still work if no new_segment is sent before the first - * buffer */ -GST_START_TEST (test_first_no_new_segment) -{ - GstElement *gdppay; - GstBuffer *inbuffer; - GstCaps *caps; - - gdppay = setup_gdppay (); - - fail_unless (gst_element_set_state (gdppay, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - GST_DEBUG ("first buffer"); - inbuffer = gst_buffer_new_and_alloc (4); - caps = gst_caps_from_string (AUDIO_CAPS_STRING); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - /* we should have three buffers now; - * one for an "invented" new segment, one for GDP caps, and one with our - * buffer */ - fail_unless_equals_int (g_list_length (buffers), 3); - - fail_unless (gst_element_set_state (gdppay, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); - - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ASSERT_OBJECT_REFCOUNT (gdppay, "gdppay", 1); - cleanup_gdppay (gdppay); -} - -GST_END_TEST; - -GST_START_TEST (test_crc) -{ - GstCaps *caps; - GstElement *gdppay; - GstBuffer *inbuffer, *outbuffer; - GstEvent *event; - gchar *caps_string; - gint length; - guint16 crc_calculated, crc_read; - - gdppay = setup_gdppay (); - g_object_set (gdppay, "crc-header", TRUE, NULL); - - fail_unless (gst_element_set_state (gdppay, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - GST_DEBUG ("new segment"); - event = - gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, GST_SECOND, 0); - fail_unless (gst_pad_push_event (mysrcpad, event)); - - /* no buffer should be pushed yet, waiting for caps */ - fail_unless_equals_int (g_list_length (buffers), 0); - - GST_DEBUG ("first buffer"); - inbuffer = gst_buffer_new_and_alloc (4); - caps = gst_caps_from_string (AUDIO_CAPS_STRING); - gst_buffer_set_caps (inbuffer, caps); - caps_string = gst_caps_to_string (caps); - - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - - /* we should have three buffers now */ - fail_unless_equals_int (g_list_length (buffers), 3); - - /* first buffer is the serialized new_segment event; - * the element also holds a ref to it */ - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2); - - /* verify the header checksum */ - /* CRC's start at 58 in the header */ - crc_calculated = gst_dp_crc (GST_BUFFER_DATA (outbuffer), 58); - crc_read = GST_READ_UINT16_BE (GST_BUFFER_DATA (outbuffer) + 58); - fail_unless_equals_int (crc_calculated, crc_read); - - /* change a byte in the header and verify that the checksum now fails */ - GST_BUFFER_DATA (outbuffer)[0] = 0xff; - crc_calculated = gst_dp_crc (GST_BUFFER_DATA (outbuffer), 58); - fail_if (crc_calculated == crc_read, - "Introducing a byte error in the header should make the checksum fail"); - - gst_buffer_unref (outbuffer); - - /* second buffer is the serialized caps; - * the element also holds a ref to it */ - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2); - length = GST_DP_HEADER_LENGTH + (strlen (caps_string) + 1); - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); - gst_buffer_unref (outbuffer); - - /* the third buffer is the GDP buffer for our pushed buffer */ - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - buffers = g_list_remove (buffers, outbuffer); - ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); - length = GST_DP_HEADER_LENGTH + 4; - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); - gst_buffer_unref (outbuffer); - - fail_unless (gst_element_set_state (gdppay, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null"); - - gst_caps_unref (caps); - g_free (caps_string); - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ASSERT_OBJECT_REFCOUNT (gdppay, "gdppay", 1); - cleanup_gdppay (gdppay); -} - -GST_END_TEST; - - -static Suite * -gdppay_suite (void) -{ - Suite *s = suite_create ("gdppay"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_audio); - tcase_add_test (tc_chain, test_first_no_caps); - tcase_add_test (tc_chain, test_first_no_new_segment); - tcase_add_test (tc_chain, test_streamheader); - tcase_add_test (tc_chain, test_crc); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = gdppay_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/elements/gnomevfssink.c b/tests/check/elements/gnomevfssink.c deleted file mode 100644 index f0cf64d4..00000000 --- a/tests/check/elements/gnomevfssink.c +++ /dev/null @@ -1,319 +0,0 @@ -/* GStreamer unit test for the gnomevfssink element - * - * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org> - * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdio.h> - -#include <glib.h> -#include <glib/gstdio.h> - -#ifdef HAVE_UNISTD_H -#include <unistd.h> /* for close() */ -#endif - -#include <gst/check/gstcheck.h> - -static GstPad *mysrcpad; - -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS_ANY); - -static GstElement * -setup_gnomevfssink (void) -{ - GstElement *gnomevfssink; - - GST_DEBUG ("setup_gnomevfssink"); - gnomevfssink = gst_check_setup_element ("gnomevfssink"); - mysrcpad = gst_check_setup_src_pad (gnomevfssink, &srctemplate, NULL); - gst_pad_set_active (mysrcpad, TRUE); - return gnomevfssink; -} - -static void -cleanup_gnomevfssink (GstElement * gnomevfssink) -{ - gst_pad_set_active (mysrcpad, FALSE); - gst_check_teardown_src_pad (gnomevfssink); - gst_check_teardown_element (gnomevfssink); -} - -#if 0 -/* this queries via the element vfunc, which is currently not implemented */ -#define CHECK_QUERY_POSITION(gnomevfssink,format,position) \ - G_STMT_START { \ - GstFormat fmt = format; \ - gint64 pos; \ - fail_unless (gst_element_query_position (gnomevfssink, &fmt, &pos)); \ - fail_unless_equals_int (pos, position); \ - } G_STMT_END -#else -#define CHECK_QUERY_POSITION(gnomevfssink,format,position) \ - G_STMT_START { \ - GstFormat fmt = format; \ - GstPad *pad; \ - gint64 pos; \ - pad = gst_element_get_static_pad (gnomevfssink, "sink"); \ - fail_unless (gst_pad_query_position (pad, &fmt, &pos)); \ - fail_unless_equals_int (pos, position); \ - gst_object_unref (pad); \ - } G_STMT_END -#endif - -#define PUSH_BYTES(num_bytes) \ - G_STMT_START { \ - GstBuffer *buf = gst_buffer_new_and_alloc(num_bytes); \ - GRand *rand = g_rand_new_with_seed (num_bytes); \ - guint i; \ - for (i = 0; i < num_bytes; ++i) \ - GST_BUFFER_DATA(buf)[i] = (g_rand_int (rand) >> 24) & 0xff; \ - fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK); \ - g_rand_free (rand); \ - } G_STMT_END - -/* TODO: we don't check that the data is actually written to the right - * position after a seek */ -GST_START_TEST (test_seeking) -{ - const gchar *tmpdir; - GstElement *gnomevfssink; - gchar *tmp_fn; - gint fd; - - tmpdir = g_get_tmp_dir (); - if (tmpdir == NULL) - return; - - /* this is just silly, but gcc warns if we try to use tpmnam() */ - tmp_fn = - g_build_filename (tmpdir, "gstreamer-gnomevfssink-test-XXXXXX", NULL); - fd = g_mkstemp (tmp_fn); - if (fd < 0) { - GST_ERROR ("can't create temp file %s: %s", tmp_fn, g_strerror (errno)); - g_free (tmp_fn); - return; - } - /* don't want the file, just a filename (hence silly, see above) */ - close (fd); - g_remove (tmp_fn); - - gnomevfssink = setup_gnomevfssink (); - - GST_LOG ("using temp file '%s'", tmp_fn); - g_object_set (gnomevfssink, "location", tmp_fn, NULL); - - fail_unless_equals_int (gst_element_set_state (gnomevfssink, - GST_STATE_PLAYING), GST_STATE_CHANGE_ASYNC); - -#if 0 - /* Test that gnomevfssink is seekable with a file fd */ - /* gnomevfssink doesn't implement seekable query at the moment */ - GstQuery *seeking_query; - gboolean seekable; - - fail_unless ((seeking_query = gst_query_new_seeking (GST_FORMAT_BYTES)) - != NULL); - fail_unless (gst_element_query (gnomevfssink, seeking_query) == TRUE); - gst_query_parse_seeking (seeking_query, NULL, &seekable, NULL, NULL); - fail_unless (seekable == TRUE); - gst_query_unref (seeking_query); -#endif - - fail_unless (gst_pad_push_event (mysrcpad, - gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_BYTES, 0, -1, 0))); - - CHECK_QUERY_POSITION (gnomevfssink, GST_FORMAT_BYTES, 0); - - /* push buffer with size 0 and NULL data */ - PUSH_BYTES (0); - CHECK_QUERY_POSITION (gnomevfssink, GST_FORMAT_BYTES, 0); - - PUSH_BYTES (1); - CHECK_QUERY_POSITION (gnomevfssink, GST_FORMAT_BYTES, 1); - - PUSH_BYTES (99); - CHECK_QUERY_POSITION (gnomevfssink, GST_FORMAT_BYTES, 100); - - PUSH_BYTES (8800); - CHECK_QUERY_POSITION (gnomevfssink, GST_FORMAT_BYTES, 8900); - - if (gst_pad_push_event (mysrcpad, - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_BYTES, 8800, -1, - 0))) { - GST_LOG ("seek ok"); - /* make sure that that new position is reported immediately */ - CHECK_QUERY_POSITION (gnomevfssink, GST_FORMAT_BYTES, 8800); - PUSH_BYTES (1); - CHECK_QUERY_POSITION (gnomevfssink, GST_FORMAT_BYTES, 8801); - PUSH_BYTES (9256); - CHECK_QUERY_POSITION (gnomevfssink, GST_FORMAT_BYTES, 18057); - } else { - GST_INFO ("seeking not supported for tempfile?!"); - } - - fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ())); - - fail_unless_equals_int (gst_element_set_state (gnomevfssink, GST_STATE_NULL), - GST_STATE_CHANGE_SUCCESS); - - /* cleanup */ - cleanup_gnomevfssink (gnomevfssink); - - /* check that we wrote data to the right position after the seek */ - { - gchar *data = NULL; - gsize len; - - fail_unless (g_file_get_contents (tmp_fn, &data, &len, NULL), - "Failed to read in newly-created file '%s'", tmp_fn); - fail_unless_equals_int (len, 18057); - { - /* we wrote 9256 bytes at position 8801 */ - GRand *rand = g_rand_new_with_seed (9256); - guint i; - - for (i = 0; i < 9256; ++i) { - guint8 byte_written = *(((guint8 *) data) + 8801 + i); - - fail_unless_equals_int (byte_written, g_rand_int (rand) >> 24); - } - g_rand_free (rand); - } - g_free (data); - } - - /* remove file */ - g_remove (tmp_fn); - g_free (tmp_fn); -} - -GST_END_TEST; - -GST_START_TEST (test_coverage) -{ - GstElement *gnomevfssink; - gchar *location; - GstBus *bus; - GstMessage *message; - - gnomevfssink = setup_gnomevfssink (); - bus = gst_bus_new (); - - gst_element_set_bus (gnomevfssink, bus); - - g_object_set (gnomevfssink, "location", "/i/do/not/exist", NULL); - g_object_get (gnomevfssink, "location", &location, NULL); - fail_unless_equals_string (location, "/i/do/not/exist"); - g_free (location); - - fail_unless_equals_int (gst_element_set_state (gnomevfssink, - GST_STATE_PLAYING), GST_STATE_CHANGE_FAILURE); - - /* a state change and an error */ - fail_if ((message = gst_bus_pop (bus)) == NULL); - fail_unless_message_error (message, RESOURCE, OPEN_WRITE); - gst_message_unref (message); - - g_object_set (gnomevfssink, "location", NULL, NULL); - g_object_get (gnomevfssink, "location", &location, NULL); - fail_if (location); - - /* cleanup */ - gst_element_set_bus (gnomevfssink, NULL); - gst_object_unref (GST_OBJECT (bus)); - cleanup_gnomevfssink (gnomevfssink); -} - -GST_END_TEST; - -GST_START_TEST (test_uri_interface) -{ - GstElement *gnomevfssink; - gchar *location; - GstBus *bus; - - gnomevfssink = setup_gnomevfssink (); - bus = gst_bus_new (); - - gst_element_set_bus (gnomevfssink, bus); - - g_object_set (G_OBJECT (gnomevfssink), "location", "/i/do/not/exist", NULL); - g_object_get (G_OBJECT (gnomevfssink), "location", &location, NULL); - fail_unless_equals_string (location, "/i/do/not/exist"); - g_free (location); - - location = (gchar *) gst_uri_handler_get_uri (GST_URI_HANDLER (gnomevfssink)); - fail_unless_equals_string (location, "file://%2Fi%2Fdo%2Fnot%2Fexist"); - - /* should accept file:///foo/bar URIs */ - fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (gnomevfssink), - "file:///foo/bar")); - location = (gchar *) gst_uri_handler_get_uri (GST_URI_HANDLER (gnomevfssink)); - fail_unless_equals_string (location, "file://%2Ffoo%2Fbar"); - g_object_get (G_OBJECT (gnomevfssink), "location", &location, NULL); - fail_unless_equals_string (location, "/foo/bar"); - g_free (location); - - /* should accept file://localhost/foo/bar URIs */ - fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (gnomevfssink), - "file://localhost/foo/baz")); - location = (gchar *) gst_uri_handler_get_uri (GST_URI_HANDLER (gnomevfssink)); - fail_unless_equals_string (location, "file://%2Ffoo%2Fbaz"); - g_object_get (G_OBJECT (gnomevfssink), "location", &location, NULL); - fail_unless_equals_string (location, "/foo/baz"); - g_free (location); - - /* should fail with other hostnames */ - fail_if (gst_uri_handler_set_uri (GST_URI_HANDLER (gnomevfssink), - "file://hostname/foo/foo")); - - /* cleanup */ - gst_element_set_bus (gnomevfssink, NULL); - gst_object_unref (GST_OBJECT (bus)); - cleanup_gnomevfssink (gnomevfssink); -} - -GST_END_TEST; - -static Suite * -gnomevfssink_suite (void) -{ - Suite *s = suite_create ("gnomevfssink"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - - /* FIXME: these two tests fail right now because of uri/location stuff */ - if (0) { - tcase_add_test (tc_chain, test_coverage); - tcase_add_test (tc_chain, test_uri_interface); - } - tcase_add_test (tc_chain, test_seeking); - - return s; -} - -GST_CHECK_MAIN (gnomevfssink); diff --git a/tests/check/elements/libvisual.c b/tests/check/elements/libvisual.c deleted file mode 100644 index 0f950060..00000000 --- a/tests/check/elements/libvisual.c +++ /dev/null @@ -1,118 +0,0 @@ -/* GStreamer unit test for libvisual plugin - * - * Copyright (C) 2007 Tim-Philipp Müller <tim at centricular net> - * - * 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 <gst/check/gstcheck.h> - -static gboolean -filter_func (GstPluginFeature * feature, gpointer user_data) -{ - return (g_str_has_prefix (GST_PLUGIN_FEATURE_NAME (feature), "libvisual_")); -} - -static void -test_shutdown_for_factory (const gchar * factory_name) -{ - GstElement *pipeline, *src, *q, *ac, *vis, *cf, *q2, *sink; - GstCaps *caps; - guint i; - - pipeline = gst_pipeline_new (NULL); - - src = gst_check_setup_element ("audiotestsrc"); - q = gst_check_setup_element ("queue"); - ac = gst_check_setup_element ("audioconvert"); - - GST_INFO ("Using %s", factory_name); - vis = gst_check_setup_element (factory_name); - - cf = gst_check_setup_element ("capsfilter"); - caps = gst_caps_new_simple ("video/x-raw-rgb", "width", G_TYPE_INT, 320, - "height", G_TYPE_INT, 240, "framerate", GST_TYPE_FRACTION, 15, 1, NULL); - g_object_set (cf, "caps", caps, NULL); - gst_caps_unref (caps); - - q2 = gst_check_setup_element ("queue"); - gst_object_set_name (GST_OBJECT (q2), "queue2"); - sink = gst_check_setup_element ("fakesink"); - - /* don't want to sync against the clock, the more throughput the better */ - g_object_set (src, "is-live", FALSE, NULL); - g_object_set (sink, "sync", FALSE, NULL); - - gst_bin_add_many (GST_BIN (pipeline), src, q, ac, vis, cf, q2, sink, NULL); - fail_if (!gst_element_link_many (src, q, ac, vis, cf, q2, sink, NULL)); - - /* now, wait until pipeline is running and then shut it down again; repeat; - * this makes sure we can shut down cleanly while stuff is going on in the - * chain function */ - for (i = 0; i < 50; ++i) { - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gst_element_get_state (pipeline, NULL, NULL, -1); - gst_element_set_state (pipeline, GST_STATE_PLAYING); - g_usleep (100); - gst_element_set_state (pipeline, GST_STATE_NULL); - } - - gst_object_unref (pipeline); -} - -GST_START_TEST (test_shutdown) -{ - const gchar *factory_to_test; - - factory_to_test = g_getenv ("LIBVISUAL_UNIT_TEST_FACTORY"); - - if (factory_to_test == NULL) { - GList *list, *l; - - list = gst_default_registry_feature_filter (filter_func, FALSE, NULL); - if (list == NULL) { - g_print ("No libvisual plugins installed.\n"); - return; - } - for (l = list; l != NULL; l = l->next) { - test_shutdown_for_factory (GST_PLUGIN_FEATURE_NAME (l->data)); - } - gst_plugin_feature_list_free (list); - } else { - test_shutdown_for_factory (factory_to_test); - } -} - -GST_END_TEST; - -static Suite * -libvisual_suite (void) -{ - Suite *s = suite_create ("libvisual"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - - /* set one manually, since we're currently built as uninst program with - * the default timeout of 3 seconds, which is way too short */ - tcase_set_timeout (tc_chain, 30); - - tcase_add_test (tc_chain, test_shutdown); - - return s; -} - -GST_CHECK_MAIN (libvisual); diff --git a/tests/check/elements/multifdsink.c b/tests/check/elements/multifdsink.c deleted file mode 100644 index a45230bf..00000000 --- a/tests/check/elements/multifdsink.c +++ /dev/null @@ -1,881 +0,0 @@ -/* GStreamer - * - * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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 <unistd.h> -#include <sys/ioctl.h> -#ifdef HAVE_FIONREAD_IN_SYS_FILIO -#include <sys/filio.h> -#endif - -#include <gst/check/gstcheck.h> - -static GstPad *mysrcpad; - -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("application/x-gst-check") - ); - -static GstElement * -setup_multifdsink (void) -{ - GstElement *multifdsink; - - GST_DEBUG ("setup_multifdsink"); - multifdsink = gst_check_setup_element ("multifdsink"); - mysrcpad = gst_check_setup_src_pad (multifdsink, &srctemplate, NULL); - - return multifdsink; -} - -static void -cleanup_multifdsink (GstElement * multifdsink) -{ - GST_DEBUG ("cleanup_multifdsink"); - - gst_check_teardown_src_pad (multifdsink); - gst_check_teardown_element (multifdsink); -} - -static void -wait_bytes_served (GstElement * sink, guint64 bytes) -{ - guint64 bytes_served = 0; - - while (bytes_served != bytes) { - g_object_get (sink, "bytes-served", &bytes_served, NULL); - } -} - -/* FIXME: possibly racy, since if it would write, we may not get it - * immediately ? */ -#define fail_if_can_read(msg,fd) \ -G_STMT_START { \ - long avail; \ -\ - fail_if (ioctl (fd, FIONREAD, &avail) < 0, "%s: could not ioctl", msg); \ - fail_if (avail > 0, "%s: has bytes available to read"); \ -} G_STMT_END; - - -GST_START_TEST (test_no_clients) -{ - GstElement *sink; - GstBuffer *buffer; - GstCaps *caps; - - sink = setup_multifdsink (); - - ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC); - - caps = gst_caps_from_string ("application/x-gst-check"); - buffer = gst_buffer_new_and_alloc (4); - gst_buffer_set_caps (buffer, caps); - gst_caps_unref (caps); - fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); - - GST_DEBUG ("cleaning up multifdsink"); - ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); - cleanup_multifdsink (sink); -} - -GST_END_TEST; - -GST_START_TEST (test_add_client) -{ - GstElement *sink; - GstBuffer *buffer; - GstCaps *caps; - int pfd[2]; - gchar data[4]; - - sink = setup_multifdsink (); - - fail_if (pipe (pfd) == -1); - - ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC); - - /* add the client */ - g_signal_emit_by_name (sink, "add", pfd[1]); - - caps = gst_caps_from_string ("application/x-gst-check"); - GST_DEBUG ("Created test caps %p %" GST_PTR_FORMAT, caps, caps); - buffer = gst_buffer_new_and_alloc (4); - gst_buffer_set_caps (buffer, caps); - ASSERT_CAPS_REFCOUNT (caps, "caps", 2); - memcpy (GST_BUFFER_DATA (buffer), "dead", 4); - fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); - - GST_DEBUG ("reading"); - fail_if (read (pfd[0], data, 4) < 4); - fail_unless (strncmp (data, "dead", 4) == 0); - wait_bytes_served (sink, 4); - - GST_DEBUG ("cleaning up multifdsink"); - ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); - cleanup_multifdsink (sink); - - ASSERT_CAPS_REFCOUNT (caps, "caps", 1); - gst_caps_unref (caps); -} - -GST_END_TEST; - -#define fail_unless_read(msg,fd,size,ref) \ -G_STMT_START { \ - char data[size + 1]; \ - int nbytes; \ -\ - GST_DEBUG ("%s: reading %d bytes", msg, size); \ - nbytes = read (fd, data, size); \ - data[size] = 0; \ - GST_DEBUG ("%s: read %d bytes", msg, nbytes); \ - fail_if (nbytes < size); \ - fail_unless (memcmp (data, ref, size) == 0, \ - "data read '%s' differs from '%s'", data, ref); \ -} G_STMT_END; - -/* from the given two data buffers, create two streamheader buffers and - * some caps that match it, and store them in the given pointers - * returns one ref to each of the buffers and the caps */ -static void -gst_multifdsink_create_streamheader (const gchar * data1, - const gchar * data2, GstBuffer ** hbuf1, GstBuffer ** hbuf2, - GstCaps ** caps) -{ - GstBuffer *buf; - GValue array = { 0 }; - GValue value = { 0 }; - GstStructure *structure; - guint size1 = strlen (data1); - guint size2 = strlen (data2); - - fail_if (hbuf1 == NULL); - fail_if (hbuf2 == NULL); - fail_if (caps == NULL); - - /* create caps with streamheader, set the caps, and push the IN_CAPS - * buffers */ - *hbuf1 = gst_buffer_new_and_alloc (size1); - GST_BUFFER_FLAG_SET (*hbuf1, GST_BUFFER_FLAG_IN_CAPS); - memcpy (GST_BUFFER_DATA (*hbuf1), data1, size1); - *hbuf2 = gst_buffer_new_and_alloc (size2); - GST_BUFFER_FLAG_SET (*hbuf2, GST_BUFFER_FLAG_IN_CAPS); - memcpy (GST_BUFFER_DATA (*hbuf2), data2, size2); - /* we want to keep them around for the tests */ - gst_buffer_ref (*hbuf1); - gst_buffer_ref (*hbuf2); - - g_value_init (&array, GST_TYPE_ARRAY); - - g_value_init (&value, GST_TYPE_BUFFER); - /* we take a copy, set it on the array (which refs it), then unref our copy */ - buf = gst_buffer_copy (*hbuf1); - gst_value_set_buffer (&value, buf); - ASSERT_BUFFER_REFCOUNT (buf, "copied buffer", 2); - gst_buffer_unref (buf); - gst_value_array_append_value (&array, &value); - g_value_unset (&value); - - g_value_init (&value, GST_TYPE_BUFFER); - buf = gst_buffer_copy (*hbuf2); - gst_value_set_buffer (&value, buf); - ASSERT_BUFFER_REFCOUNT (buf, "copied buffer", 2); - gst_buffer_unref (buf); - gst_value_array_append_value (&array, &value); - g_value_unset (&value); - - *caps = gst_caps_from_string ("application/x-gst-check"); - structure = gst_caps_get_structure (*caps, 0); - - gst_structure_set_value (structure, "streamheader", &array); - g_value_unset (&array); - ASSERT_CAPS_REFCOUNT (*caps, "streamheader caps", 1); - - /* set our streamheadery caps on the buffers */ - gst_buffer_set_caps (*hbuf1, *caps); - gst_buffer_set_caps (*hbuf2, *caps); - ASSERT_CAPS_REFCOUNT (*caps, "streamheader caps", 3); - - GST_DEBUG ("created streamheader caps %p %" GST_PTR_FORMAT, *caps, *caps); -} - - -/* this test: - * - adds a first client - * - sets streamheader caps on the pad - * - pushes the IN_CAPS buffers - * - pushes a buffer - * - verifies that the client received all the data correctly, and did not - * get multiple copies of the streamheader - * - adds a second client - * - verifies that this second client receives the streamheader caps too, plus - * - the new buffer - */ -GST_START_TEST (test_streamheader) -{ - GstElement *sink; - GstBuffer *hbuf1, *hbuf2, *buf; - GstCaps *caps; - int pfd1[2], pfd2[2]; - - sink = setup_multifdsink (); - - fail_if (pipe (pfd1) == -1); - fail_if (pipe (pfd2) == -1); - - ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC); - - /* add the first client */ - g_signal_emit_by_name (sink, "add", pfd1[1]); - - /* create caps with streamheader, set the caps, and push the IN_CAPS - * buffers */ - gst_multifdsink_create_streamheader ("babe", "deadbeef", &hbuf1, &hbuf2, - &caps); - fail_unless (gst_pad_set_caps (mysrcpad, caps)); - /* one is ours, two on the buffers, and one now on the pad */ - ASSERT_CAPS_REFCOUNT (caps, "caps", 4); - - fail_unless (gst_pad_push (mysrcpad, hbuf1) == GST_FLOW_OK); - fail_unless (gst_pad_push (mysrcpad, hbuf2) == GST_FLOW_OK); - - //FIXME: - //fail_if_can_read ("first client", pfd1[0]); - - /* push a non-IN_CAPS buffer, this should trigger the client receiving the - * first three buffers */ - buf = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (buf), "f00d", 4); - gst_pad_push (mysrcpad, buf); - - fail_unless_read ("first client", pfd1[0], 4, "babe"); - fail_unless_read ("first client", pfd1[0], 8, "deadbeef"); - fail_unless_read ("first client", pfd1[0], 4, "f00d"); - wait_bytes_served (sink, 16); - - /* now add the second client */ - g_signal_emit_by_name (sink, "add", pfd2[1]); - //FIXME: - //fail_if_can_read ("second client", pfd2[0]); - - /* now push another buffer, which will trigger streamheader for second - * client */ - buf = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (buf), "deaf", 4); - gst_pad_push (mysrcpad, buf); - - fail_unless_read ("first client", pfd1[0], 4, "deaf"); - - fail_unless_read ("second client", pfd2[0], 4, "babe"); - fail_unless_read ("second client", pfd2[0], 8, "deadbeef"); - /* we missed the f00d buffer */ - fail_unless_read ("second client", pfd2[0], 4, "deaf"); - wait_bytes_served (sink, 36); - - GST_DEBUG ("cleaning up multifdsink"); - - g_signal_emit_by_name (sink, "remove", pfd1[1]); - g_signal_emit_by_name (sink, "remove", pfd2[1]); - - ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); - cleanup_multifdsink (sink); - - ASSERT_BUFFER_REFCOUNT (hbuf1, "hbuf1", 1); - ASSERT_BUFFER_REFCOUNT (hbuf2, "hbuf2", 1); - gst_buffer_unref (hbuf1); - gst_buffer_unref (hbuf2); - - ASSERT_CAPS_REFCOUNT (caps, "caps", 1); - gst_caps_unref (caps); -} - -GST_END_TEST; - -/* this tests changing of streamheaders - * - set streamheader caps on the pad - * - pushes the IN_CAPS buffers - * - pushes a buffer - * - add a first client - * - verifies that this first client receives the first streamheader caps, - * plus a new buffer - * - change streamheader caps - * - verify that the first client receives the new streamheader buffers as well - */ -GST_START_TEST (test_change_streamheader) -{ - GstElement *sink; - GstBuffer *hbuf1, *hbuf2, *buf; - GstCaps *caps; - int pfd1[2], pfd2[2]; - - sink = setup_multifdsink (); - - fail_if (pipe (pfd1) == -1); - fail_if (pipe (pfd2) == -1); - - ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC); - - /* create caps with streamheader, set the caps, and push the IN_CAPS - * buffers */ - gst_multifdsink_create_streamheader ("first", "header", &hbuf1, &hbuf2, - &caps); - fail_unless (gst_pad_set_caps (mysrcpad, caps)); - /* one is ours, two on the buffers, and one now on the pad */ - ASSERT_CAPS_REFCOUNT (caps, "caps", 4); - - /* one to hold for the test and one to give away */ - ASSERT_BUFFER_REFCOUNT (hbuf1, "hbuf1", 2); - ASSERT_BUFFER_REFCOUNT (hbuf2, "hbuf2", 2); - - fail_unless (gst_pad_push (mysrcpad, hbuf1) == GST_FLOW_OK); - fail_unless (gst_pad_push (mysrcpad, hbuf2) == GST_FLOW_OK); - - /* add the first client */ - g_signal_emit_by_name (sink, "add", pfd1[1]); - - /* verify this hasn't triggered a write yet */ - /* FIXME: possibly racy, since if it would write, we may not get it - * immediately ? */ - //fail_if_can_read ("first client, no buffer", pfd1[0]); - - /* now push a buffer and read */ - buf = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (buf), "f00d", 4); - gst_pad_push (mysrcpad, buf); - - fail_unless_read ("change: first client", pfd1[0], 5, "first"); - fail_unless_read ("change: first client", pfd1[0], 6, "header"); - fail_unless_read ("change: first client", pfd1[0], 4, "f00d"); - //wait_bytes_served (sink, 16); - - /* now add the second client */ - g_signal_emit_by_name (sink, "add", pfd2[1]); - //fail_if_can_read ("second client, no buffer", pfd2[0]); - - /* change the streamheader */ - - /* before we change, multifdsink still has a list of the old streamheaders */ - ASSERT_BUFFER_REFCOUNT (hbuf1, "hbuf1", 2); - ASSERT_BUFFER_REFCOUNT (hbuf2, "hbuf2", 2); - gst_buffer_unref (hbuf1); - gst_buffer_unref (hbuf2); - - /* drop our ref to the previous caps */ - gst_caps_unref (caps); - - gst_multifdsink_create_streamheader ("second", "header", &hbuf1, &hbuf2, - &caps); - fail_unless (gst_pad_set_caps (mysrcpad, caps)); - /* one to hold for the test and one to give away */ - ASSERT_BUFFER_REFCOUNT (hbuf1, "hbuf1", 2); - ASSERT_BUFFER_REFCOUNT (hbuf2, "hbuf2", 2); - - fail_unless (gst_pad_push (mysrcpad, hbuf1) == GST_FLOW_OK); - fail_unless (gst_pad_push (mysrcpad, hbuf2) == GST_FLOW_OK); - - /* verify neither client has new data available to read */ - //fail_if_can_read ("first client, changed streamheader", pfd1[0]); - //fail_if_can_read ("second client, changed streamheader", pfd2[0]); - - /* now push another buffer, which will trigger streamheader for second - * client, but should also send new streamheaders to first client */ - buf = gst_buffer_new_and_alloc (8); - memcpy (GST_BUFFER_DATA (buf), "deadbabe", 8); - gst_pad_push (mysrcpad, buf); - - fail_unless_read ("first client", pfd1[0], 6, "second"); - fail_unless_read ("first client", pfd1[0], 6, "header"); - fail_unless_read ("first client", pfd1[0], 8, "deadbabe"); - - /* new streamheader data */ - fail_unless_read ("second client", pfd2[0], 6, "second"); - fail_unless_read ("second client", pfd2[0], 6, "header"); - /* we missed the f00d buffer */ - fail_unless_read ("second client", pfd2[0], 8, "deadbabe"); - //wait_bytes_served (sink, 36); - - GST_DEBUG ("cleaning up multifdsink"); - g_signal_emit_by_name (sink, "remove", pfd1[1]); - g_signal_emit_by_name (sink, "remove", pfd2[1]); - ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); - - /* setting to NULL should have cleared the streamheader */ - ASSERT_BUFFER_REFCOUNT (hbuf1, "hbuf1", 1); - ASSERT_BUFFER_REFCOUNT (hbuf2, "hbuf2", 1); - gst_buffer_unref (hbuf1); - gst_buffer_unref (hbuf2); - cleanup_multifdsink (sink); - - ASSERT_CAPS_REFCOUNT (caps, "caps", 1); - gst_caps_unref (caps); -} - -GST_END_TEST; - -/* keep 100 bytes and burst 80 bytes to clients */ -GST_START_TEST (test_burst_client_bytes) -{ - GstElement *sink; - GstBuffer *buffer; - GstCaps *caps; - int pfd1[2]; - int pfd2[2]; - int pfd3[2]; - gchar data[16]; - gint i; - guint buffers_queued; - - sink = setup_multifdsink (); - /* make sure we keep at least 100 bytes at all times */ - g_object_set (sink, "bytes-min", 100, NULL); - g_object_set (sink, "sync-method", 3, NULL); /* 3 = burst */ - g_object_set (sink, "burst-unit", 3, NULL); /* 3 = bytes */ - g_object_set (sink, "burst-value", (guint64) 80, NULL); - - fail_if (pipe (pfd1) == -1); - fail_if (pipe (pfd2) == -1); - fail_if (pipe (pfd3) == -1); - - ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC); - - caps = gst_caps_from_string ("application/x-gst-check"); - GST_DEBUG ("Created test caps %p %" GST_PTR_FORMAT, caps, caps); - - /* push buffers in, 9 * 16 bytes = 144 bytes */ - for (i = 0; i < 9; i++) { - gchar *data; - - buffer = gst_buffer_new_and_alloc (16); - gst_buffer_set_caps (buffer, caps); - - /* copy some id */ - data = (gchar *) GST_BUFFER_DATA (buffer); - g_snprintf (data, 16, "deadbee%08x", i); - - fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); - } - - /* check that at least 7 buffers (112 bytes) are in the queue */ - g_object_get (sink, "buffers-queued", &buffers_queued, NULL); - fail_if (buffers_queued != 7); - - /* now add the clients */ - g_signal_emit_by_name (sink, "add", pfd1[1]); - g_signal_emit_by_name (sink, "add_full", pfd2[1], 3, - 3, (guint64) 50, 3, (guint64) 200); - g_signal_emit_by_name (sink, "add_full", pfd3[1], 3, - 3, (guint64) 50, 3, (guint64) 50); - - /* push last buffer to make client fds ready for reading */ - for (i = 9; i < 10; i++) { - gchar *data; - - buffer = gst_buffer_new_and_alloc (16); - gst_buffer_set_caps (buffer, caps); - - /* copy some id */ - data = (gchar *) GST_BUFFER_DATA (buffer); - g_snprintf (data, 16, "deadbee%08x", i); - - fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); - } - - /* now we should only read the last 5 buffers (5 * 16 = 80 bytes) */ - GST_DEBUG ("Reading from client 1"); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000005", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000006", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000007", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000008", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000009", 16) == 0); - - /* second client only bursts 50 bytes = 4 buffers (we get 4 buffers since - * the max alows it) */ - GST_DEBUG ("Reading from client 2"); - fail_if (read (pfd2[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000006", 16) == 0); - fail_if (read (pfd2[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000007", 16) == 0); - fail_if (read (pfd2[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000008", 16) == 0); - fail_if (read (pfd2[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000009", 16) == 0); - - /* third client only bursts 50 bytes = 4 buffers, we can't send - * more than 50 bytes so we only get 3 buffers (48 bytes). */ - GST_DEBUG ("Reading from client 3"); - fail_if (read (pfd3[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000007", 16) == 0); - fail_if (read (pfd3[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000008", 16) == 0); - fail_if (read (pfd3[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000009", 16) == 0); - - GST_DEBUG ("cleaning up multifdsink"); - ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); - cleanup_multifdsink (sink); - - ASSERT_CAPS_REFCOUNT (caps, "caps", 1); - gst_caps_unref (caps); -} - -GST_END_TEST; - -/* keep 100 bytes and burst 80 bytes to clients */ -GST_START_TEST (test_burst_client_bytes_keyframe) -{ - GstElement *sink; - GstBuffer *buffer; - GstCaps *caps; - int pfd1[2]; - int pfd2[2]; - int pfd3[2]; - gchar data[16]; - gint i; - guint buffers_queued; - - sink = setup_multifdsink (); - /* make sure we keep at least 100 bytes at all times */ - g_object_set (sink, "bytes-min", 100, NULL); - g_object_set (sink, "sync-method", 4, NULL); /* 3 = burst_keyframe */ - g_object_set (sink, "burst-unit", 3, NULL); /* 3 = bytes */ - g_object_set (sink, "burst-value", (guint64) 80, NULL); - - fail_if (pipe (pfd1) == -1); - fail_if (pipe (pfd2) == -1); - fail_if (pipe (pfd3) == -1); - - ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC); - - caps = gst_caps_from_string ("application/x-gst-check"); - GST_DEBUG ("Created test caps %p %" GST_PTR_FORMAT, caps, caps); - - /* push buffers in, 9 * 16 bytes = 144 bytes */ - for (i = 0; i < 9; i++) { - gchar *data; - - buffer = gst_buffer_new_and_alloc (16); - gst_buffer_set_caps (buffer, caps); - - /* mark most buffers as delta */ - if (i != 0 && i != 4 && i != 8) - GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT); - - /* copy some id */ - data = (gchar *) GST_BUFFER_DATA (buffer); - g_snprintf (data, 16, "deadbee%08x", i); - - fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); - } - - /* check that at least 7 buffers (112 bytes) are in the queue */ - g_object_get (sink, "buffers-queued", &buffers_queued, NULL); - fail_if (buffers_queued != 7); - - /* now add the clients */ - g_signal_emit_by_name (sink, "add", pfd1[1]); - g_signal_emit_by_name (sink, "add_full", pfd2[1], 4, - 3, (guint64) 50, 3, (guint64) 90); - g_signal_emit_by_name (sink, "add_full", pfd3[1], 4, - 3, (guint64) 50, 3, (guint64) 50); - - /* push last buffer to make client fds ready for reading */ - for (i = 9; i < 10; i++) { - gchar *data; - - buffer = gst_buffer_new_and_alloc (16); - gst_buffer_set_caps (buffer, caps); - GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT); - - /* copy some id */ - data = (gchar *) GST_BUFFER_DATA (buffer); - g_snprintf (data, 16, "deadbee%08x", i); - - fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); - } - - /* now we should only read the last 6 buffers (min 5 * 16 = 80 bytes), - * keyframe at buffer 4 */ - GST_DEBUG ("Reading from client 1"); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000004", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000005", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000006", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000007", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000008", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000009", 16) == 0); - - /* second client only bursts 50 bytes = 4 buffers, there is - * no keyframe above min and below max, so get one below min */ - GST_DEBUG ("Reading from client 2"); - fail_if (read (pfd2[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000008", 16) == 0); - fail_if (read (pfd2[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000009", 16) == 0); - - /* third client only bursts 50 bytes = 4 buffers, we can't send - * more than 50 bytes so we only get 2 buffers (32 bytes). */ - GST_DEBUG ("Reading from client 3"); - fail_if (read (pfd3[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000008", 16) == 0); - fail_if (read (pfd3[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000009", 16) == 0); - - GST_DEBUG ("cleaning up multifdsink"); - ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); - cleanup_multifdsink (sink); - - ASSERT_CAPS_REFCOUNT (caps, "caps", 1); - gst_caps_unref (caps); -} - -GST_END_TEST; - -/* keep 100 bytes and burst 80 bytes to clients */ -GST_START_TEST (test_burst_client_bytes_with_keyframe) -{ - GstElement *sink; - GstBuffer *buffer; - GstCaps *caps; - int pfd1[2]; - int pfd2[2]; - int pfd3[2]; - gchar data[16]; - gint i; - guint buffers_queued; - - sink = setup_multifdsink (); - /* make sure we keep at least 100 bytes at all times */ - g_object_set (sink, "bytes-min", 100, NULL); - g_object_set (sink, "sync-method", 5, NULL); /* 3 = burst_with_keyframe */ - g_object_set (sink, "burst-unit", 3, NULL); /* 3 = bytes */ - g_object_set (sink, "burst-value", (guint64) 80, NULL); - - fail_if (pipe (pfd1) == -1); - fail_if (pipe (pfd2) == -1); - fail_if (pipe (pfd3) == -1); - - ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC); - - caps = gst_caps_from_string ("application/x-gst-check"); - GST_DEBUG ("Created test caps %p %" GST_PTR_FORMAT, caps, caps); - - /* push buffers in, 9 * 16 bytes = 144 bytes */ - for (i = 0; i < 9; i++) { - gchar *data; - - buffer = gst_buffer_new_and_alloc (16); - gst_buffer_set_caps (buffer, caps); - - /* mark most buffers as delta */ - if (i != 0 && i != 4 && i != 8) - GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT); - - /* copy some id */ - data = (gchar *) GST_BUFFER_DATA (buffer); - g_snprintf (data, 16, "deadbee%08x", i); - - fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); - } - - /* check that at least 7 buffers (112 bytes) are in the queue */ - g_object_get (sink, "buffers-queued", &buffers_queued, NULL); - fail_if (buffers_queued != 7); - - /* now add the clients */ - g_signal_emit_by_name (sink, "add", pfd1[1]); - g_signal_emit_by_name (sink, "add_full", pfd2[1], 5, - 3, (guint64) 50, 3, (guint64) 90); - g_signal_emit_by_name (sink, "add_full", pfd3[1], 5, - 3, (guint64) 50, 3, (guint64) 50); - - /* push last buffer to make client fds ready for reading */ - for (i = 9; i < 10; i++) { - gchar *data; - - buffer = gst_buffer_new_and_alloc (16); - gst_buffer_set_caps (buffer, caps); - GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT); - - /* copy some id */ - data = (gchar *) GST_BUFFER_DATA (buffer); - g_snprintf (data, 16, "deadbee%08x", i); - - fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); - } - - /* now we should only read the last 6 buffers (min 5 * 16 = 80 bytes), - * keyframe at buffer 4 */ - GST_DEBUG ("Reading from client 1"); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000004", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000005", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000006", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000007", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000008", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000009", 16) == 0); - - /* second client only bursts 50 bytes = 4 buffers, there is - * no keyframe above min and below max, so send min */ - GST_DEBUG ("Reading from client 2"); - fail_if (read (pfd2[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000006", 16) == 0); - fail_if (read (pfd2[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000007", 16) == 0); - fail_if (read (pfd2[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000008", 16) == 0); - fail_if (read (pfd2[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000009", 16) == 0); - - /* third client only bursts 50 bytes = 4 buffers, we can't send - * more than 50 bytes so we only get 3 buffers (48 bytes). */ - GST_DEBUG ("Reading from client 3"); - fail_if (read (pfd3[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000007", 16) == 0); - fail_if (read (pfd3[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000008", 16) == 0); - fail_if (read (pfd3[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000009", 16) == 0); - - GST_DEBUG ("cleaning up multifdsink"); - ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); - cleanup_multifdsink (sink); - - ASSERT_CAPS_REFCOUNT (caps, "caps", 1); - gst_caps_unref (caps); -} - -GST_END_TEST; - -/* Check that we can get data when multifdsink is configured in next-keyframe - * mode */ -GST_START_TEST (test_client_next_keyframe) -{ - GstElement *sink; - GstBuffer *buffer; - GstCaps *caps; - int pfd1[2]; - gchar data[16]; - gint i; - - sink = setup_multifdsink (); - g_object_set (sink, "sync-method", 1, NULL); /* 1 = next-keyframe */ - - fail_if (pipe (pfd1) == -1); - - ASSERT_SET_STATE (sink, GST_STATE_PLAYING, GST_STATE_CHANGE_ASYNC); - - caps = gst_caps_from_string ("application/x-gst-check"); - GST_DEBUG ("Created test caps %p %" GST_PTR_FORMAT, caps, caps); - - /* now add our client */ - g_signal_emit_by_name (sink, "add", pfd1[1]); - - /* push buffers in: keyframe, then non-keyframe */ - for (i = 0; i < 2; i++) { - gchar *data; - - buffer = gst_buffer_new_and_alloc (16); - gst_buffer_set_caps (buffer, caps); - - /* copy some id */ - data = (gchar *) GST_BUFFER_DATA (buffer); - g_snprintf (data, 16, "deadbee%08x", i); - if (i > 0) - GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT); - - fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); - } - - /* now we should be able to read some data */ - GST_DEBUG ("Reading from client 1"); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000000", 16) == 0); - fail_if (read (pfd1[0], data, 16) < 16); - fail_unless (strncmp (data, "deadbee00000001", 16) == 0); - - GST_DEBUG ("cleaning up multifdsink"); - ASSERT_SET_STATE (sink, GST_STATE_NULL, GST_STATE_CHANGE_SUCCESS); - cleanup_multifdsink (sink); - - ASSERT_CAPS_REFCOUNT (caps, "caps", 1); - gst_caps_unref (caps); -} - -GST_END_TEST; - -/* FIXME: add test simulating chained oggs where: - * sync-method is burst-on-connect - * (when multifdsink actually does burst-on-connect based on byte size, not - "last keyframe" which any frame for audio :)) - * an old client still needs to read from before the new streamheaders - * a new client gets the new streamheaders - */ -static Suite * -multifdsink_suite (void) -{ - Suite *s = suite_create ("multifdsink"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_no_clients); - tcase_add_test (tc_chain, test_add_client); - tcase_add_test (tc_chain, test_streamheader); - tcase_add_test (tc_chain, test_change_streamheader); - tcase_add_test (tc_chain, test_burst_client_bytes); - tcase_add_test (tc_chain, test_burst_client_bytes_keyframe); - tcase_add_test (tc_chain, test_burst_client_bytes_with_keyframe); - tcase_add_test (tc_chain, test_client_next_keyframe); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = multifdsink_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/elements/playbin.c b/tests/check/elements/playbin.c deleted file mode 100644 index f285df40..00000000 --- a/tests/check/elements/playbin.c +++ /dev/null @@ -1,652 +0,0 @@ -/* GStreamer unit tests for playbin - * - * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <gst/check/gstcheck.h> -#include <gst/base/gstpushsrc.h> -#include <unistd.h> - -#ifndef GST_DISABLE_REGISTRY - -static GType gst_red_video_src_get_type (void); -static GType gst_codec_src_get_type (void); - -#define DEFINE_TEST(func) \ - static void func (void); \ - \ - GST_START_TEST(func ## _decodebin1) \ - { g_unsetenv("USE_DECODEBIN2"); func(); } \ - GST_END_TEST; \ - \ - GST_START_TEST(func ## _decodebin2) \ - { g_setenv("USE_DECODEBIN2", "1", TRUE); func(); } \ - GST_END_TEST; - -DEFINE_TEST (test_sink_usage_video_only_stream); - -/* make sure the audio sink is not touched for video-only streams */ -static void -test_sink_usage_video_only_stream (void) -{ - GstElement *playbin, *fakevideosink, *fakeaudiosink; - GstState cur_state, pending_state; - - fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, - gst_red_video_src_get_type ())); - - playbin = gst_element_factory_make ("playbin", "playbin"); - fail_unless (playbin != NULL, "Failed to create playbin element"); - - fakevideosink = gst_element_factory_make ("fakesink", "fakevideosink"); - fail_unless (fakevideosink != NULL, "Failed to create fakevideosink element"); - - fakeaudiosink = gst_element_factory_make ("fakesink", "fakeaudiosink"); - fail_unless (fakeaudiosink != NULL, "Failed to create fakeaudiosink element"); - - /* video-only stream, audiosink will error out in null => ready if used */ - g_object_set (fakeaudiosink, "state-error", 1, NULL); - - g_object_set (playbin, "video-sink", fakevideosink, NULL); - g_object_set (playbin, "audio-sink", fakeaudiosink, NULL); - - g_object_set (playbin, "uri", "redvideo://", NULL); - - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - fail_unless_equals_int (gst_element_get_state (playbin, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - fail_unless_equals_int (gst_element_get_state (fakeaudiosink, &cur_state, - &pending_state, 0), GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (cur_state, GST_STATE_NULL); - fail_unless_equals_int (pending_state, GST_STATE_VOID_PENDING); - - { - GValueArray *stream_info = NULL; - - g_object_get (playbin, "stream-info-value-array", &stream_info, NULL); - fail_unless (stream_info != NULL); - fail_unless_equals_int (stream_info->n_values, 1); - g_value_array_free (stream_info); - } - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -/* this tests async error handling when setting up the subbin */ -DEFINE_TEST (test_suburi_error_unknowntype); - -static void -test_suburi_error_unknowntype (void) -{ - GstElement *playbin, *fakesink; - - fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, - gst_red_video_src_get_type ())); - - playbin = gst_element_factory_make ("playbin", "playbin"); - fail_unless (playbin != NULL, "Failed to create playbin element"); - - fakesink = gst_element_factory_make ("fakesink", "fakesink"); - fail_unless (fakesink != NULL, "Failed to create fakesink element"); - ASSERT_OBJECT_REFCOUNT (fakesink, "fakesink after creation", 1); - - g_object_set (playbin, "video-sink", fakesink, NULL); - - /* suburi file format unknown: playbin should just ignore the suburi and - * preroll normally (if /dev/zero does not exist, this test should behave - * the same as test_suburi_error_invalidfile() */ - g_object_set (playbin, "uri", "redvideo://", NULL); - g_object_set (playbin, "suburi", "file:///dev/zero", NULL); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - fail_unless_equals_int (gst_element_get_state (playbin, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -DEFINE_TEST (test_suburi_error_invalidfile); - -static void -test_suburi_error_invalidfile (void) -{ - GstElement *playbin, *fakesink; - - fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, - gst_red_video_src_get_type ())); - - playbin = gst_element_factory_make ("playbin", "playbin"); - fail_unless (playbin != NULL, "Failed to create playbin element"); - - fakesink = gst_element_factory_make ("fakesink", "fakesink"); - fail_unless (fakesink != NULL, "Failed to create fakesink element"); - ASSERT_OBJECT_REFCOUNT (fakesink, "fakesink after creation", 1); - - g_object_set (playbin, "video-sink", fakesink, NULL); - - /* suburi file does not exist: playbin should just ignore the suburi and - * preroll normally */ - g_object_set (playbin, "uri", "redvideo://", NULL); - g_object_set (playbin, "suburi", "file:///foo/bar/803129999/32x9ax1", NULL); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - fail_unless_equals_int (gst_element_get_state (playbin, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -DEFINE_TEST (test_suburi_error_wrongproto); - -static void -test_suburi_error_wrongproto (void) -{ - GstElement *playbin, *fakesink; - - fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, - gst_red_video_src_get_type ())); - - playbin = gst_element_factory_make ("playbin", "playbin"); - fail_unless (playbin != NULL, "Failed to create playbin element"); - - fakesink = gst_element_factory_make ("fakesink", "fakesink"); - fail_unless (fakesink != NULL, "Failed to create fakesink element"); - ASSERT_OBJECT_REFCOUNT (fakesink, "fakesink after creation", 1); - - g_object_set (playbin, "video-sink", fakesink, NULL); - - /* wrong protocol for suburi: playbin should just ignore the suburi and - * preroll normally */ - g_object_set (playbin, "uri", "redvideo://", NULL); - g_object_set (playbin, "suburi", "nosuchproto://foo.bar:80", NULL); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - fail_unless_equals_int (gst_element_get_state (playbin, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -static GstElement * -create_playbin (const gchar * uri) -{ - GstElement *playbin, *fakesink1, *fakesink2; - - playbin = gst_element_factory_make ("playbin", "playbin"); - fail_unless (playbin != NULL, "Failed to create playbin element"); - - fakesink1 = gst_element_factory_make ("fakesink", NULL); - fail_unless (fakesink1 != NULL, "Failed to create fakesink element #1"); - - fakesink2 = gst_element_factory_make ("fakesink", NULL); - fail_unless (fakesink2 != NULL, "Failed to create fakesink element #2"); - - /* make them behave like normal sinks, even if not needed for the test */ - g_object_set (fakesink1, "sync", TRUE, NULL); - g_object_set (fakesink2, "sync", TRUE, NULL); - - g_object_set (playbin, "video-sink", fakesink1, NULL); - g_object_set (playbin, "audio-sink", fakesink2, NULL); - - g_object_set (playbin, "uri", uri, NULL); - - return playbin; -} - -DEFINE_TEST (test_missing_urisource_handler); - -static void -test_missing_urisource_handler (void) -{ - GstStructure *s; - GstMessage *msg; - GstElement *playbin; - GError *err = NULL; - GstBus *bus; - - playbin = create_playbin ("chocchipcookie://withahint.of/cinnamon"); - - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_FAILURE); - - /* there should be at least a missing-plugin message on the bus now and an - * error message; the missing-plugin message should be first */ - bus = gst_element_get_bus (playbin); - - msg = gst_bus_poll (bus, GST_MESSAGE_ELEMENT | GST_MESSAGE_ERROR, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "detail"), - "chocchipcookie"); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisource"); - gst_message_unref (msg); - - msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ERROR); - - /* make sure the error is a CORE MISSING_PLUGIN one */ - gst_message_parse_error (msg, &err, NULL); - fail_unless (err != NULL); - fail_unless (err->domain == GST_CORE_ERROR, "error has wrong error domain " - "%s instead of core-error-quark", g_quark_to_string (err->domain)); - fail_unless (err->code == GST_CORE_ERROR_MISSING_PLUGIN, "error has wrong " - "code %u instead of GST_CORE_ERROR_MISSING_PLUGIN", err->code); - g_error_free (err); - gst_message_unref (msg); - gst_object_unref (bus); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -DEFINE_TEST (test_missing_suburisource_handler); - -static void -test_missing_suburisource_handler (void) -{ - GstStructure *s; - GstMessage *msg; - GstElement *playbin; - GError *err = NULL; - GstBus *bus; - - playbin = create_playbin ("file:///does/not/exis.t"); - - g_object_set (playbin, "suburi", "cookie://withahint.of/cinnamon", NULL); - - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_FAILURE); - - /* there should be at least a missing-plugin message on the bus now and an - * error message; the missing-plugin message should be first */ - bus = gst_element_get_bus (playbin); - - msg = gst_bus_poll (bus, GST_MESSAGE_ELEMENT | GST_MESSAGE_ERROR, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "detail"), "cookie"); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisource"); - gst_message_unref (msg); - - msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ERROR); - - /* make sure the error is a CORE MISSING_PLUGIN one */ - gst_message_parse_error (msg, &err, NULL); - fail_unless (err != NULL); - fail_unless (err->domain == GST_CORE_ERROR, "error has wrong error domain " - "%s instead of core-error-quark", g_quark_to_string (err->domain)); - fail_unless (err->code == GST_CORE_ERROR_MISSING_PLUGIN, "error has wrong " - "code %u instead of GST_CORE_ERROR_MISSING_PLUGIN", err->code); - g_error_free (err); - gst_message_unref (msg); - gst_object_unref (bus); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -DEFINE_TEST (test_missing_primary_decoder); - -static void -test_missing_primary_decoder (void) -{ - GstStructure *s; - GstMessage *msg; - GstElement *playbin; - GError *err = NULL; - GstBus *bus; - gchar *use_decodebin2 = getenv ("USE_DECODEBIN2"); - gboolean decodebin2 = use_decodebin2 != NULL && *use_decodebin2 == '1'; - - fail_unless (gst_element_register (NULL, "codecsrc", GST_RANK_PRIMARY, - gst_codec_src_get_type ())); - - playbin = create_playbin ("codec://"); - - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - - /* there should soon be at least a missing-plugin message on the bus and an - * error message; the missing-plugin message should be first */ - bus = gst_element_get_bus (playbin); - - msg = gst_bus_poll (bus, GST_MESSAGE_ELEMENT | GST_MESSAGE_ERROR, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "decoder"); - fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS)); - gst_message_unref (msg); - - msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ERROR); - - /* make sure the error is a STREAM CODEC_NOT_FOUND one */ - gst_message_parse_error (msg, &err, NULL); - fail_unless (err != NULL); - if (decodebin2) { - fail_unless (err->domain == GST_CORE_ERROR, "error has wrong error domain " - "%s instead of core-error-quark", g_quark_to_string (err->domain)); - fail_unless (err->code == GST_CORE_ERROR_MISSING_PLUGIN, "error has wrong " - "code %u instead of GST_RESOURCE_ERROR_MISSING_PLUGIN", err->code); - } else { - fail_unless (err->domain == GST_STREAM_ERROR, - "error has wrong error domain " "%s instead of stream-error-quark", - g_quark_to_string (err->domain)); - fail_unless (err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND, - "error has wrong " - "code %u instead of GST_STREAM_ERROR_CODEC_NOT_FOUND", err->code); - } - g_error_free (err); - gst_message_unref (msg); - gst_object_unref (bus); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -/*** redvideo:// source ***/ - -static GstURIType -gst_red_video_src_uri_get_type (void) -{ - return GST_URI_SRC; -} - -static gchar ** -gst_red_video_src_uri_get_protocols (void) -{ - static gchar *protocols[] = { "redvideo", NULL }; - - return protocols; -} - -static const gchar * -gst_red_video_src_uri_get_uri (GstURIHandler * handler) -{ - return "redvideo://"; -} - -static gboolean -gst_red_video_src_uri_set_uri (GstURIHandler * handler, const gchar * uri) -{ - return (uri != NULL && g_str_has_prefix (uri, "redvideo:")); -} - -static void -gst_red_video_src_uri_handler_init (gpointer g_iface, gpointer iface_data) -{ - GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; - - iface->get_type = gst_red_video_src_uri_get_type; - iface->get_protocols = gst_red_video_src_uri_get_protocols; - iface->get_uri = gst_red_video_src_uri_get_uri; - iface->set_uri = gst_red_video_src_uri_set_uri; -} - -static void -gst_red_video_src_init_type (GType type) -{ - static const GInterfaceInfo uri_hdlr_info = { - gst_red_video_src_uri_handler_init, NULL, NULL - }; - - g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &uri_hdlr_info); -} - -typedef GstPushSrc GstRedVideoSrc; -typedef GstPushSrcClass GstRedVideoSrcClass; - -GST_BOILERPLATE_FULL (GstRedVideoSrc, gst_red_video_src, GstPushSrc, - GST_TYPE_PUSH_SRC, gst_red_video_src_init_type); - -static void -gst_red_video_src_base_init (gpointer klass) -{ - static const GstElementDetails details = - GST_ELEMENT_DETAILS ("Red Video Src", "Source/Video", "yep", "me"); - static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-raw-yuv, format=(fourcc)I420") - ); - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_templ)); - gst_element_class_set_details (element_class, &details); -} - -static GstFlowReturn -gst_red_video_src_create (GstPushSrc * src, GstBuffer ** p_buf) -{ - GstBuffer *buf; - GstCaps *caps; - guint8 *data; - guint w = 64, h = 64; - guint size; - - size = w * h * 3 / 2; - buf = gst_buffer_new_and_alloc (size); - data = GST_BUFFER_DATA (buf); - memset (data, 76, w * h); - memset (data + (w * h), 85, (w * h) / 4); - memset (data + (w * h) + ((w * h) / 4), 255, (w * h) / 4); - - caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC, - GST_MAKE_FOURCC ('I', '4', '2', '0'), "width", G_TYPE_INT, w, "height", - G_TYPE_INT, h, "framerate", GST_TYPE_FRACTION, 1, 1, NULL); - gst_buffer_set_caps (buf, caps); - gst_caps_unref (caps); - - *p_buf = buf; - return GST_FLOW_OK; -} - -static void -gst_red_video_src_class_init (GstRedVideoSrcClass * klass) -{ - GstPushSrcClass *pushsrc_class = GST_PUSH_SRC_CLASS (klass); - - pushsrc_class->create = gst_red_video_src_create; -} - -static void -gst_red_video_src_init (GstRedVideoSrc * src, GstRedVideoSrcClass * klass) -{ -} - -/*** codec:// source ***/ - -static GstURIType -gst_codec_src_uri_get_type (void) -{ - return GST_URI_SRC; -} - -static gchar ** -gst_codec_src_uri_get_protocols (void) -{ - static gchar *protocols[] = { "codec", NULL }; - - return protocols; -} - -static const gchar * -gst_codec_src_uri_get_uri (GstURIHandler * handler) -{ - return "codec://"; -} - -static gboolean -gst_codec_src_uri_set_uri (GstURIHandler * handler, const gchar * uri) -{ - return (uri != NULL && g_str_has_prefix (uri, "codec:")); -} - -static void -gst_codec_src_uri_handler_init (gpointer g_iface, gpointer iface_data) -{ - GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; - - iface->get_type = gst_codec_src_uri_get_type; - iface->get_protocols = gst_codec_src_uri_get_protocols; - iface->get_uri = gst_codec_src_uri_get_uri; - iface->set_uri = gst_codec_src_uri_set_uri; -} - -static void -gst_codec_src_init_type (GType type) -{ - static const GInterfaceInfo uri_hdlr_info = { - gst_codec_src_uri_handler_init, NULL, NULL - }; - - g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &uri_hdlr_info); -} - -#undef parent_class -#define parent_class codec_src_parent_class - -typedef GstPushSrc GstCodecSrc; -typedef GstPushSrcClass GstCodecSrcClass; - -GST_BOILERPLATE_FULL (GstCodecSrc, gst_codec_src, GstPushSrc, - GST_TYPE_PUSH_SRC, gst_codec_src_init_type); - -static void -gst_codec_src_base_init (gpointer klass) -{ - static const GstElementDetails details = - GST_ELEMENT_DETAILS ("Codec Src", "Source/Video", "yep", "me"); - static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, GST_PAD_ALWAYS, - GST_STATIC_CAPS ("application/x-codec") - ); - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_templ)); - gst_element_class_set_details (element_class, &details); -} - -static GstFlowReturn -gst_codec_src_create (GstPushSrc * src, GstBuffer ** p_buf) -{ - GstBuffer *buf; - GstCaps *caps; - - buf = gst_buffer_new_and_alloc (20); - memset (GST_BUFFER_DATA (buf), 0, GST_BUFFER_SIZE (buf)); - - caps = gst_caps_new_simple ("application/x-codec", NULL); - gst_buffer_set_caps (buf, caps); - gst_caps_unref (caps); - - *p_buf = buf; - return GST_FLOW_OK; -} - -static void -gst_codec_src_class_init (GstCodecSrcClass * klass) -{ - GstPushSrcClass *pushsrc_class = GST_PUSH_SRC_CLASS (klass); - - pushsrc_class->create = gst_codec_src_create; -} - -static void -gst_codec_src_init (GstCodecSrc * src, GstCodecSrcClass * klass) -{ -} - -#endif /* GST_DISABLE_REGISTRY */ - - -static Suite * -playbin_suite (void) -{ - Suite *s = suite_create ("playbin"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - -#ifndef GST_DISABLE_REGISTRY - /* with the old decodebin */ - tcase_add_test (tc_chain, test_sink_usage_video_only_stream_decodebin1); - tcase_add_test (tc_chain, test_suburi_error_wrongproto_decodebin1); - tcase_add_test (tc_chain, test_suburi_error_invalidfile_decodebin1); - tcase_add_test (tc_chain, test_suburi_error_unknowntype_decodebin1); - tcase_add_test (tc_chain, test_missing_urisource_handler_decodebin1); - tcase_add_test (tc_chain, test_missing_suburisource_handler_decodebin1); - tcase_add_test (tc_chain, test_missing_primary_decoder_decodebin1); - - /* and again with decodebin2 */ - tcase_add_test (tc_chain, test_missing_primary_decoder_decodebin2); - tcase_add_test (tc_chain, test_sink_usage_video_only_stream_decodebin2); - tcase_add_test (tc_chain, test_suburi_error_wrongproto_decodebin2); - tcase_add_test (tc_chain, test_suburi_error_invalidfile_decodebin2); - tcase_add_test (tc_chain, test_suburi_error_unknowntype_decodebin2); - tcase_add_test (tc_chain, test_missing_urisource_handler_decodebin2); - tcase_add_test (tc_chain, test_missing_suburisource_handler_decodebin2); - - /* one day we might also want to have the following checks: - * tcase_add_test (tc_chain, test_missing_secondary_decoder_one_fatal); - * tcase_add_test (tc_chain, test_missing_secondary_decoder_two_fatal); - * tcase_add_test (tc_chain, test_missing_secondary_decoder_two_with_preroll); - */ -#endif - - return s; -} - -GST_CHECK_MAIN (playbin); diff --git a/tests/check/elements/playbin2.c b/tests/check/elements/playbin2.c deleted file mode 100644 index a90dc84b..00000000 --- a/tests/check/elements/playbin2.c +++ /dev/null @@ -1,712 +0,0 @@ -/* GStreamer unit tests for playbin2 - * - * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <gst/check/gstcheck.h> -#include <gst/base/gstpushsrc.h> -#include <unistd.h> - -#ifndef GST_DISABLE_REGISTRY - -static GType gst_red_video_src_get_type (void); -static GType gst_codec_src_get_type (void); - -/* make sure the audio sink is not touched for video-only streams */ -GST_START_TEST (test_sink_usage_video_only_stream) -{ - GstElement *playbin, *fakevideosink, *fakeaudiosink; - GstState cur_state, pending_state; - GstElement *source; - GstBuffer *last_frame; - gint nstreams; - - fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, - gst_red_video_src_get_type ())); - - playbin = gst_element_factory_make ("playbin2", "playbin2"); - fail_unless (playbin != NULL, "Failed to create playbin element"); - - fakevideosink = gst_element_factory_make ("fakesink", "fakevideosink"); - fail_unless (fakevideosink != NULL, "Failed to create fakevideosink element"); - - fakeaudiosink = gst_element_factory_make ("fakesink", "fakeaudiosink"); - fail_unless (fakeaudiosink != NULL, "Failed to create fakeaudiosink element"); - - /* video-only stream, audiosink will error out in null => ready if used */ - g_object_set (fakeaudiosink, "state-error", 1, NULL); - - g_object_set (playbin, "video-sink", fakevideosink, NULL); - g_object_set (playbin, "audio-sink", fakeaudiosink, NULL); - - g_object_set (playbin, "uri", "redvideo://", NULL); - - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - fail_unless_equals_int (gst_element_get_state (playbin, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - fail_unless_equals_int (gst_element_get_state (fakeaudiosink, &cur_state, - &pending_state, 0), GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (cur_state, GST_STATE_NULL); - fail_unless_equals_int (pending_state, GST_STATE_VOID_PENDING); - - g_object_get (playbin, "n-video", &nstreams, NULL); - fail_unless_equals_int (nstreams, 1); - - g_object_get (playbin, "n-audio", &nstreams, NULL); - fail_unless_equals_int (nstreams, 0); - - g_object_get (playbin, "n-text", &nstreams, NULL); - fail_unless_equals_int (nstreams, 0); - - g_object_get (playbin, "source", &source, NULL); - fail_unless (G_TYPE_FROM_INSTANCE (source) == gst_red_video_src_get_type ()); - gst_object_unref (source); - - g_object_get (playbin, "frame", &last_frame, NULL); - fail_unless (GST_IS_BUFFER (last_frame)); - gst_buffer_unref (last_frame); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -GST_END_TEST; - -/* this tests async error handling when setting up the subbin */ -GST_START_TEST (test_suburi_error_unknowntype) -{ - GstElement *playbin, *fakesink; - - fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, - gst_red_video_src_get_type ())); - - playbin = gst_element_factory_make ("playbin2", "playbin2"); - fail_unless (playbin != NULL, "Failed to create playbin element"); - - fakesink = gst_element_factory_make ("fakesink", "fakesink"); - fail_unless (fakesink != NULL, "Failed to create fakesink element"); - ASSERT_OBJECT_REFCOUNT (fakesink, "fakesink after creation", 1); - - g_object_set (playbin, "video-sink", fakesink, NULL); - - /* suburi file format unknown: playbin should just ignore the suburi and - * preroll normally (if /dev/zero does not exist, this test should behave - * the same as test_suburi_error_invalidfile() */ - g_object_set (playbin, "uri", "redvideo://", NULL); - g_object_set (playbin, "suburi", "file:///dev/zero", NULL); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - fail_unless_equals_int (gst_element_get_state (playbin, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -GST_END_TEST; - -GST_START_TEST (test_suburi_error_invalidfile) -{ - GstElement *playbin, *fakesink; - - fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, - gst_red_video_src_get_type ())); - - playbin = gst_element_factory_make ("playbin2", "playbin2"); - fail_unless (playbin != NULL, "Failed to create playbin element"); - - fakesink = gst_element_factory_make ("fakesink", "fakesink"); - fail_unless (fakesink != NULL, "Failed to create fakesink element"); - ASSERT_OBJECT_REFCOUNT (fakesink, "fakesink after creation", 1); - - g_object_set (playbin, "video-sink", fakesink, NULL); - - /* suburi file does not exist: playbin should just ignore the suburi and - * preroll normally */ - g_object_set (playbin, "uri", "redvideo://", NULL); - g_object_set (playbin, "suburi", "file:///foo/bar/803129999/32x9ax1", NULL); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - fail_unless_equals_int (gst_element_get_state (playbin, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -GST_END_TEST; - -GST_START_TEST (test_suburi_error_wrongproto) -{ - GstElement *playbin, *fakesink; - - fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, - gst_red_video_src_get_type ())); - - playbin = gst_element_factory_make ("playbin2", "playbin2"); - fail_unless (playbin != NULL, "Failed to create playbin element"); - - fakesink = gst_element_factory_make ("fakesink", "fakesink"); - fail_unless (fakesink != NULL, "Failed to create fakesink element"); - ASSERT_OBJECT_REFCOUNT (fakesink, "fakesink after creation", 1); - - g_object_set (playbin, "video-sink", fakesink, NULL); - - /* wrong protocol for suburi: playbin should just ignore the suburi and - * preroll normally */ - g_object_set (playbin, "uri", "redvideo://", NULL); - g_object_set (playbin, "suburi", "nosuchproto://foo.bar:80", NULL); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - fail_unless_equals_int (gst_element_get_state (playbin, NULL, NULL, -1), - GST_STATE_CHANGE_SUCCESS); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -GST_END_TEST; - -static GstElement * -create_playbin (const gchar * uri) -{ - GstElement *playbin, *fakesink1, *fakesink2; - - playbin = gst_element_factory_make ("playbin2", "playbin2"); - fail_unless (playbin != NULL, "Failed to create playbin element"); - - fakesink1 = gst_element_factory_make ("fakesink", NULL); - fail_unless (fakesink1 != NULL, "Failed to create fakesink element #1"); - - fakesink2 = gst_element_factory_make ("fakesink", NULL); - fail_unless (fakesink2 != NULL, "Failed to create fakesink element #2"); - - /* make them behave like normal sinks, even if not needed for the test */ - g_object_set (fakesink1, "sync", TRUE, NULL); - g_object_set (fakesink2, "sync", TRUE, NULL); - - g_object_set (playbin, "video-sink", fakesink1, NULL); - g_object_set (playbin, "audio-sink", fakesink2, NULL); - - g_object_set (playbin, "uri", uri, NULL); - - return playbin; -} - -GST_START_TEST (test_missing_urisource_handler) -{ - GstStructure *s; - GstMessage *msg; - GstElement *playbin; - GError *err = NULL; - GstBus *bus; - - playbin = create_playbin ("chocchipcookie://withahint.of/cinnamon"); - - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_FAILURE); - - /* there should be at least a missing-plugin message on the bus now and an - * error message; the missing-plugin message should be first */ - bus = gst_element_get_bus (playbin); - - msg = gst_bus_poll (bus, GST_MESSAGE_ELEMENT | GST_MESSAGE_ERROR, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "detail"), - "chocchipcookie"); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisource"); - gst_message_unref (msg); - - msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ERROR); - - /* make sure the error is a CORE MISSING_PLUGIN one */ - gst_message_parse_error (msg, &err, NULL); - fail_unless (err != NULL); - fail_unless (err->domain == GST_CORE_ERROR, "error has wrong error domain " - "%s instead of core-error-quark", g_quark_to_string (err->domain)); - fail_unless (err->code == GST_CORE_ERROR_MISSING_PLUGIN, "error has wrong " - "code %u instead of GST_CORE_ERROR_MISSING_PLUGIN", err->code); - g_error_free (err); - gst_message_unref (msg); - gst_object_unref (bus); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -GST_END_TEST; - -GST_START_TEST (test_missing_suburisource_handler) -{ - GstStructure *s; - GstMessage *msg; - GstElement *playbin; - GError *err = NULL; - GstBus *bus; - - playbin = create_playbin ("file:///does/not/exis.t"); - - g_object_set (playbin, "suburi", "cookie://withahint.of/cinnamon", NULL); - - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_FAILURE); - - /* there should be at least a missing-plugin message on the bus now and an - * error message; the missing-plugin message should be first */ - bus = gst_element_get_bus (playbin); - - msg = gst_bus_poll (bus, GST_MESSAGE_ELEMENT | GST_MESSAGE_ERROR, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "detail"), "cookie"); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisource"); - gst_message_unref (msg); - - msg = gst_bus_poll (bus, GST_MESSAGE_WARNING, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_WARNING); - - /* make sure the *warning* is a CORE MISSING_PLUGIN one */ - gst_message_parse_warning (msg, &err, NULL); - fail_unless (err != NULL); - fail_unless (err->domain == GST_CORE_ERROR, "error has wrong error domain " - "%s instead of core-error-quark", g_quark_to_string (err->domain)); - fail_unless (err->code == GST_CORE_ERROR_MISSING_PLUGIN, "error has wrong " - "code %u instead of GST_CORE_ERROR_MISSING_PLUGIN", err->code); - g_error_free (err); - gst_message_unref (msg); - - msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ERROR); - - /* make sure the error is a RESOURCE NOT_FOUND one */ - gst_message_parse_error (msg, &err, NULL); - fail_unless (err != NULL); - fail_unless (err->domain == GST_RESOURCE_ERROR, - "error has wrong error domain " "%s instead of resource-error-quark", - g_quark_to_string (err->domain)); - fail_unless (err->code == GST_RESOURCE_ERROR_NOT_FOUND, - "error has wrong " "code %u instead of GST_RESOURCE_ERROR_NOT_FOUND", - err->code); - g_error_free (err); - gst_message_unref (msg); - - gst_object_unref (bus); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -GST_END_TEST; - -GST_START_TEST (test_missing_primary_decoder) -{ - GstStructure *s; - GstMessage *msg; - GstElement *playbin; - GError *err = NULL; - GstBus *bus; - - fail_unless (gst_element_register (NULL, "codecsrc", GST_RANK_PRIMARY, - gst_codec_src_get_type ())); - - playbin = create_playbin ("codec://"); - - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_READY), - GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - - /* there should soon be at least a missing-plugin message on the bus and an - * error message; the missing-plugin message should be first */ - bus = gst_element_get_bus (playbin); - - msg = gst_bus_poll (bus, GST_MESSAGE_ELEMENT | GST_MESSAGE_ERROR, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "decoder"); - fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS)); - gst_message_unref (msg); - - msg = gst_bus_poll (bus, GST_MESSAGE_WARNING, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_WARNING); - - /* make sure the *warning* is a STREAM CODEC_NOT_FOUND one */ - gst_message_parse_warning (msg, &err, NULL); - fail_unless (err != NULL); - fail_unless (err->domain == GST_STREAM_ERROR, "error has wrong error domain " - "%s instead of stream-error-quark", g_quark_to_string (err->domain)); - fail_unless (err->code == GST_STREAM_ERROR_CODEC_NOT_FOUND, "error has wrong " - "code %u instead of GST_STREAM_ERROR_CODEC_NOT_FOUND", err->code); - g_error_free (err); - gst_message_unref (msg); - - msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, -1); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ERROR); - - /* make sure the error is a CORE MISSING_PLUGIN one */ - gst_message_parse_error (msg, &err, NULL); - fail_unless (err != NULL); - fail_unless (err->domain == GST_CORE_ERROR, "error has wrong error domain " - "%s instead of core-error-quark", g_quark_to_string (err->domain)); - fail_unless (err->code == GST_CORE_ERROR_MISSING_PLUGIN, "error has wrong " - "code %u instead of GST_CORE_ERROR_MISSING_PLUGIN", err->code); - g_error_free (err); - gst_message_unref (msg); - - gst_object_unref (bus); - - gst_element_set_state (playbin, GST_STATE_NULL); - gst_object_unref (playbin); -} - -GST_END_TEST; - -GST_START_TEST (test_refcount) -{ - GstElement *playbin, *audiosink, *videosink, *vis; - - fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, - gst_red_video_src_get_type ())); - - playbin = gst_element_factory_make ("playbin2", NULL); - audiosink = gst_element_factory_make ("fakesink", "myaudiosink"); - videosink = gst_element_factory_make ("fakesink", "myvideosink"); - vis = gst_element_factory_make ("identity", "myvis"); - - /* ref because we need them after we unref playbin2 */ - gst_object_ref (audiosink); - gst_object_ref (videosink); - gst_object_ref (vis); - - /* Sinks have floating ref only, setting the properties takes ownership. */ - g_object_set (playbin, - "audio-sink", audiosink, - "video-sink", videosink, - "vis-plugin", vis, "flags", 0x01 | 0x02 | 0x08, NULL); - - g_object_set (playbin, "uri", "redvideo://", NULL); - //"uri", "file:///home/wim/data/cdda.ogg", NULL); - - ASSERT_OBJECT_REFCOUNT (playbin, "playbin", 1); - - /* we have two refs now, one from ourselves and one from playbin2 */ - ASSERT_OBJECT_REFCOUNT (audiosink, "myaudiosink", 2); - ASSERT_OBJECT_REFCOUNT (videosink, "myvideosink", 2); - ASSERT_OBJECT_REFCOUNT (vis, "myvis", 2); - - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_PAUSED), - GST_STATE_CHANGE_ASYNC); - fail_unless_equals_int (gst_element_get_state (playbin, NULL, NULL, - GST_CLOCK_TIME_NONE), GST_STATE_CHANGE_SUCCESS); - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_NULL), - GST_STATE_CHANGE_SUCCESS); - - ASSERT_OBJECT_REFCOUNT (playbin, "playbin", 1); - /* refcount of our elements is undefined, playbin2 might keep additional refs - * because it cached the elements in bins */ - gst_object_unref (playbin); - - /* now we are back to our refs */ - ASSERT_OBJECT_REFCOUNT (audiosink, "myaudiosink", 1); - ASSERT_OBJECT_REFCOUNT (videosink, "myvideosink", 1); - ASSERT_OBJECT_REFCOUNT (vis, "myvis", 1); - - gst_object_unref (audiosink); - gst_object_unref (videosink); - gst_object_unref (vis); -} - -GST_END_TEST; - -/*** redvideo:// source ***/ - -static GstURIType -gst_red_video_src_uri_get_type (void) -{ - return GST_URI_SRC; -} - -static gchar ** -gst_red_video_src_uri_get_protocols (void) -{ - static gchar *protocols[] = { "redvideo", NULL }; - - return protocols; -} - -static const gchar * -gst_red_video_src_uri_get_uri (GstURIHandler * handler) -{ - return "redvideo://"; -} - -static gboolean -gst_red_video_src_uri_set_uri (GstURIHandler * handler, const gchar * uri) -{ - return (uri != NULL && g_str_has_prefix (uri, "redvideo:")); -} - -static void -gst_red_video_src_uri_handler_init (gpointer g_iface, gpointer iface_data) -{ - GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; - - iface->get_type = gst_red_video_src_uri_get_type; - iface->get_protocols = gst_red_video_src_uri_get_protocols; - iface->get_uri = gst_red_video_src_uri_get_uri; - iface->set_uri = gst_red_video_src_uri_set_uri; -} - -static void -gst_red_video_src_init_type (GType type) -{ - static const GInterfaceInfo uri_hdlr_info = { - gst_red_video_src_uri_handler_init, NULL, NULL - }; - - g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &uri_hdlr_info); -} - -typedef GstPushSrc GstRedVideoSrc; -typedef GstPushSrcClass GstRedVideoSrcClass; - -GST_BOILERPLATE_FULL (GstRedVideoSrc, gst_red_video_src, GstPushSrc, - GST_TYPE_PUSH_SRC, gst_red_video_src_init_type); - -static void -gst_red_video_src_base_init (gpointer klass) -{ - static const GstElementDetails details = - GST_ELEMENT_DETAILS ("Red Video Src", "Source/Video", "yep", "me"); - static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-raw-yuv, format=(fourcc)I420") - ); - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_templ)); - gst_element_class_set_details (element_class, &details); -} - -static GstFlowReturn -gst_red_video_src_create (GstPushSrc * src, GstBuffer ** p_buf) -{ - GstBuffer *buf; - GstCaps *caps; - guint8 *data; - guint w = 64, h = 64; - guint size; - - size = w * h * 3 / 2; - buf = gst_buffer_new_and_alloc (size); - data = GST_BUFFER_DATA (buf); - memset (data, 76, w * h); - memset (data + (w * h), 85, (w * h) / 4); - memset (data + (w * h) + ((w * h) / 4), 255, (w * h) / 4); - - caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC, - GST_MAKE_FOURCC ('I', '4', '2', '0'), "width", G_TYPE_INT, w, "height", - G_TYPE_INT, h, "framerate", GST_TYPE_FRACTION, 1, 1, NULL); - gst_buffer_set_caps (buf, caps); - gst_caps_unref (caps); - - *p_buf = buf; - return GST_FLOW_OK; -} - -static void -gst_red_video_src_class_init (GstRedVideoSrcClass * klass) -{ - GstPushSrcClass *pushsrc_class = GST_PUSH_SRC_CLASS (klass); - - pushsrc_class->create = gst_red_video_src_create; -} - -static void -gst_red_video_src_init (GstRedVideoSrc * src, GstRedVideoSrcClass * klass) -{ -} - -/*** codec:// source ***/ - -static GstURIType -gst_codec_src_uri_get_type (void) -{ - return GST_URI_SRC; -} - -static gchar ** -gst_codec_src_uri_get_protocols (void) -{ - static gchar *protocols[] = { "codec", NULL }; - - return protocols; -} - -static const gchar * -gst_codec_src_uri_get_uri (GstURIHandler * handler) -{ - return "codec://"; -} - -static gboolean -gst_codec_src_uri_set_uri (GstURIHandler * handler, const gchar * uri) -{ - return (uri != NULL && g_str_has_prefix (uri, "codec:")); -} - -static void -gst_codec_src_uri_handler_init (gpointer g_iface, gpointer iface_data) -{ - GstURIHandlerInterface *iface = (GstURIHandlerInterface *) g_iface; - - iface->get_type = gst_codec_src_uri_get_type; - iface->get_protocols = gst_codec_src_uri_get_protocols; - iface->get_uri = gst_codec_src_uri_get_uri; - iface->set_uri = gst_codec_src_uri_set_uri; -} - -static void -gst_codec_src_init_type (GType type) -{ - static const GInterfaceInfo uri_hdlr_info = { - gst_codec_src_uri_handler_init, NULL, NULL - }; - - g_type_add_interface_static (type, GST_TYPE_URI_HANDLER, &uri_hdlr_info); -} - -#undef parent_class -#define parent_class codec_src_parent_class - -typedef GstPushSrc GstCodecSrc; -typedef GstPushSrcClass GstCodecSrcClass; - -GST_BOILERPLATE_FULL (GstCodecSrc, gst_codec_src, GstPushSrc, - GST_TYPE_PUSH_SRC, gst_codec_src_init_type); - -static void -gst_codec_src_base_init (gpointer klass) -{ - static const GstElementDetails details = - GST_ELEMENT_DETAILS ("Codec Src", "Source/Video", "yep", "me"); - static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, GST_PAD_ALWAYS, - GST_STATIC_CAPS ("application/x-codec") - ); - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&src_templ)); - gst_element_class_set_details (element_class, &details); -} - -static GstFlowReturn -gst_codec_src_create (GstPushSrc * src, GstBuffer ** p_buf) -{ - GstBuffer *buf; - GstCaps *caps; - - buf = gst_buffer_new_and_alloc (20); - memset (GST_BUFFER_DATA (buf), 0, GST_BUFFER_SIZE (buf)); - - caps = gst_caps_new_simple ("application/x-codec", NULL); - gst_buffer_set_caps (buf, caps); - gst_caps_unref (caps); - - *p_buf = buf; - return GST_FLOW_OK; -} - -static void -gst_codec_src_class_init (GstCodecSrcClass * klass) -{ - GstPushSrcClass *pushsrc_class = GST_PUSH_SRC_CLASS (klass); - - pushsrc_class->create = gst_codec_src_create; -} - -static void -gst_codec_src_init (GstCodecSrc * src, GstCodecSrcClass * klass) -{ -} - -#endif /* GST_DISABLE_REGISTRY */ - - -static Suite * -playbin2_suite (void) -{ - Suite *s = suite_create ("playbin2"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - -#ifndef GST_DISABLE_REGISTRY - tcase_add_test (tc_chain, test_sink_usage_video_only_stream); - tcase_add_test (tc_chain, test_suburi_error_wrongproto); - tcase_add_test (tc_chain, test_suburi_error_invalidfile); - tcase_add_test (tc_chain, test_suburi_error_unknowntype); - tcase_add_test (tc_chain, test_missing_urisource_handler); - tcase_add_test (tc_chain, test_missing_suburisource_handler); - tcase_add_test (tc_chain, test_missing_primary_decoder); - tcase_add_test (tc_chain, test_refcount); - - /* one day we might also want to have the following checks: - * tcase_add_test (tc_chain, test_missing_secondary_decoder_one_fatal); - * tcase_add_test (tc_chain, test_missing_secondary_decoder_two_fatal); - * tcase_add_test (tc_chain, test_missing_secondary_decoder_two_with_preroll); - */ -#endif - - return s; -} - -GST_CHECK_MAIN (playbin2); diff --git a/tests/check/elements/subparse.c b/tests/check/elements/subparse.c deleted file mode 100644 index 884140b9..00000000 --- a/tests/check/elements/subparse.c +++ /dev/null @@ -1,719 +0,0 @@ -/* GStreamer unit tests for subparse - * Copyright (C) 2006-2008 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <gst/check/gstcheck.h> - -#include <string.h> - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("text/plain; text/x-pango-markup") - ); -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("ANY") - ); - -static GstElement *subparse; -static GstPad *mysrcpad, *mysinkpad; - -static GstBuffer * -buffer_from_static_string (const gchar * s) -{ - GstBuffer *buf; - - buf = gst_buffer_new (); - GST_BUFFER_DATA (buf) = (guint8 *) s; - GST_BUFFER_SIZE (buf) = strlen (s); - GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY); - - return buf; -} - -typedef struct -{ - const gchar *in; - GstClockTime from_ts; - GstClockTime to_ts; - const gchar *out; -} SubParseInputChunk; - -static SubParseInputChunk srt_input[] = { - { - "1\n00:00:01,000 --> 00:00:02,000\nOne\n\n", - 1 * GST_SECOND, 2 * GST_SECOND, "One"}, { - "2\n00:00:02,000 --> 00:00:03,000\nTwo\n\n", - 2 * GST_SECOND, 3 * GST_SECOND, "Two"}, { - "3\n00:00:03,000 --> 00:00:04,000\nThree\n\n", - 3 * GST_SECOND, 4 * GST_SECOND, "Three"}, { - "4\n00:00:04,000 --> 00:00:05,000\nFour\n\n", - 4 * GST_SECOND, 5 * GST_SECOND, "Four"}, { - "5\n00:00:05,000 --> 00:00:06,000\nFive\n\n", - 5 * GST_SECOND, 6 * GST_SECOND, "Five"}, { - /* markup should be preserved */ - "6\n00:00:06,000 --> 00:00:07,000\n<i>Six</i>\n\n", - 6 * GST_SECOND, 7 * GST_SECOND, "<i>Six</i>"}, { - /* open markup tags should be closed */ - "7\n00:00:07,000 --> 00:00:08,000\n<i>Seven\n\n", - 7 * GST_SECOND, 8 * GST_SECOND, "<i>Seven</i>"}, { - /* open markup tags should be closed (II) */ - "8\n00:00:08,000 --> 00:00:09,000\n<b><i>Eight\n\n", - 8 * GST_SECOND, 9 * GST_SECOND, "<b><i>Eight</i></b>"}, { - /* broken markup should be fixed */ - "9\n00:00:09,000 --> 00:00:10,000\n</b>\n\n", - 9 * GST_SECOND, 10 * GST_SECOND, ""}, { - "10\n00:00:10,000 --> 00:00:11,000\n</b></i>\n\n", - 10 * GST_SECOND, 11 * GST_SECOND, ""}, { - "11\n00:00:11,000 --> 00:00:12,000\n<i>xyz</b></i>\n\n", - 11 * GST_SECOND, 12 * GST_SECOND, "<i>xyz</i>"}, { - "12\n00:00:12,000 --> 00:00:13,000\n<i>xyz</b>\n\n", - 12 * GST_SECOND, 13 * GST_SECOND, "<i>xyz</i>"}, { - /* skip a few chunk numbers here, the numbers shouldn't matter */ - "24\n00:01:00,000 --> 00:02:00,000\nYep, still here\n\n", - 60 * GST_SECOND, 120 * GST_SECOND, "Yep, still here"}, { - /* make sure stuff is escaped properly, but allowed markup stays intact */ - "25\n00:03:00,000 --> 00:04:00,000\ngave <i>Rock & Roll</i> to\n\n", - 180 * GST_SECOND, 240 * GST_SECOND, "gave <i>Rock & Roll</i> to"}, { - "26\n00:04:00,000 --> 00:05:00,000\n<i>Rock & Roll</i>\n\n", - 240 * GST_SECOND, 300 * GST_SECOND, "<i>Rock & Roll</i>"}, { - "27\n00:06:00,000 --> 00:08:00,000\nRock & Roll\n\n", - 360 * GST_SECOND, 480 * GST_SECOND, "Rock & Roll"}, { - "28\n00:10:00,000 --> 00:11:00,000\n" - "<font \"#0000FF\"><joj>This is </xxx>in blue but <5</font>\n\n", - 600 * GST_SECOND, 660 * GST_SECOND, "This is in blue but <5"} -}; - -/* starts with chunk number 0 (not exactly according to spec) */ -static SubParseInputChunk srt_input0[] = { - { - "0\n00:00:01,000 --> 00:00:02,000\nOne\n\n", - 1 * GST_SECOND, 2 * GST_SECOND, "One"}, { - "1\n00:00:02,000 --> 00:00:03,000\nTwo\n\n", - 2 * GST_SECOND, 3 * GST_SECOND, "Two"}, { - "2\n00:00:03,000 --> 00:00:04,000\nThree\n\n", - 3 * GST_SECOND, 4 * GST_SECOND, "Three"} -}; - -/* has spaces instead of doubled zeroes (not exactly according to spec) */ -static SubParseInputChunk srt_input1[] = { - { - "1\n 0: 0:26, 26 --> 0: 0:28, 17\nI cant see.\n\n", - 26 * GST_SECOND + 26 * GST_MSECOND, - 28 * GST_SECOND + 17 * GST_MSECOND, "I cant see."}, - { - "2\n 0: 0:30, 30 --> 0: 0:33, 22\nI really cant see.\n\n", - 30 * GST_SECOND + 30 * GST_MSECOND, - 33 * GST_SECOND + 22 * GST_MSECOND, "I really cant see."}, - { - "3\n 0: 0:40, 40 --> 0: 0:44, 44\nI still cant see anything.\n\n", - 40 * GST_SECOND + 40 * GST_MSECOND, - 44 * GST_SECOND + 44 * GST_MSECOND, "I still cant see anything."} -}; - -/* has UTF-8 BOM at the start */ -static SubParseInputChunk srt_input2[] = { - { - "\xef\xbb\xbf" "1\n00:00:00,000 --> 00:00:03,50\nJust testing.\n\n", - 0, 3 * GST_SECOND + 50 * GST_MSECOND, "Just testing."} -}; - -/* starts with chunk number 0 and has less than three digits after the comma - * and a few extra spaces before the arrow or at the end of the line */ -static SubParseInputChunk srt_input3[] = { - { - "0\n00:00:01,0 --> 00:00:02,0\nOne\n\n", - 1000 * GST_MSECOND, 2000 * GST_MSECOND, "One"}, { - "1\n00:00:02,5 --> 00:00:03, 5 \nTwo\n\n", - 2500 * GST_MSECOND, 3005 * GST_MSECOND, "Two"}, { - "2\n00:00:03, 9 --> 00:00:04,0 \nThree\n\n", - 3090 * GST_MSECOND, 4000 * GST_MSECOND, "Three"} -}; - -static void -setup_subparse (void) -{ - subparse = gst_check_setup_element ("subparse"); - - mysrcpad = gst_check_setup_src_pad (subparse, &srctemplate, NULL); - mysinkpad = gst_check_setup_sink_pad (subparse, &sinktemplate, NULL); - - gst_pad_set_active (mysrcpad, TRUE); - gst_pad_set_active (mysinkpad, TRUE); - - fail_unless_equals_int (gst_element_set_state (subparse, GST_STATE_PLAYING), - GST_STATE_CHANGE_SUCCESS); -} - -static void -teardown_subparse (void) -{ - GST_DEBUG ("cleaning up"); - - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - - gst_pad_set_active (mysrcpad, FALSE); - gst_pad_set_active (mysinkpad, FALSE); - gst_check_teardown_sink_pad (subparse); - gst_check_teardown_src_pad (subparse); - gst_check_teardown_element (subparse); - subparse = NULL; - mysrcpad = NULL; - mysinkpad = NULL; -} - -static void -test_srt_do_test (SubParseInputChunk * input, guint start_idx, guint num) -{ - guint n; - - GST_LOG ("srt test: start_idx = %u, num = %u", start_idx, num); - - setup_subparse (); - - for (n = start_idx; n < start_idx + num; ++n) { - GstBuffer *buf; - - buf = buffer_from_static_string (input[n].in); - fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK); - } - - gst_pad_push_event (mysrcpad, gst_event_new_eos ()); - - fail_unless_equals_int (g_list_length (buffers), num); - - for (n = start_idx; n < start_idx + num; ++n) { - const GstStructure *buffer_caps_struct; - GstBuffer *buf; - gchar *out; - guint out_size; - - buf = g_list_nth_data (buffers, n - start_idx); - fail_unless (buf != NULL); - fail_unless (GST_BUFFER_TIMESTAMP_IS_VALID (buf), NULL); - fail_unless (GST_BUFFER_DURATION_IS_VALID (buf), NULL); - fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buf), input[n].from_ts); - fail_unless_equals_uint64 (GST_BUFFER_DURATION (buf), - input[n].to_ts - input[n].from_ts); - out = (gchar *) GST_BUFFER_DATA (buf); - out_size = GST_BUFFER_SIZE (buf); - /* shouldn't have trailing newline characters */ - fail_if (out_size > 0 && out[out_size - 1] == '\n'); - /* shouldn't include NUL-terminator in data size */ - fail_if (out_size > 0 && out[out_size - 1] == '\0'); - /* but should still have a NUL-terminator behind the declared data */ - fail_unless_equals_int (out[out_size], '\0'); - /* make sure out string matches expected string */ - fail_unless_equals_string (out, input[n].out); - /* check caps */ - fail_unless (GST_BUFFER_CAPS (buf) != NULL); - buffer_caps_struct = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0); - fail_unless_equals_string (gst_structure_get_name (buffer_caps_struct), - "text/x-pango-markup"); - } - - teardown_subparse (); -} - -GST_START_TEST (test_srt) -{ - test_srt_do_test (srt_input, 0, G_N_ELEMENTS (srt_input)); - - /* make sure everything works fine if we don't start with chunk 1 */ - test_srt_do_test (srt_input, 1, G_N_ELEMENTS (srt_input) - 1); - test_srt_do_test (srt_input, 2, G_N_ELEMENTS (srt_input) - 2); - test_srt_do_test (srt_input, 3, G_N_ELEMENTS (srt_input) - 3); - test_srt_do_test (srt_input, 4, G_N_ELEMENTS (srt_input) - 4); - - /* try with empty input, immediate EOS */ - test_srt_do_test (srt_input, 5, G_N_ELEMENTS (srt_input) - 5); - - /* try with chunk number 0 (which is not exactly according to spec) */ - test_srt_do_test (srt_input0, 0, G_N_ELEMENTS (srt_input0)); - - /* try with spaces instead of doubled zeroes (which is not exactly according to spec) */ - test_srt_do_test (srt_input1, 0, G_N_ELEMENTS (srt_input1)); - - /* try with UTF-8 BOM at the start */ - test_srt_do_test (srt_input1, 0, G_N_ELEMENTS (srt_input2)); - - /* try with fewer than three post-comma digits, and some extra spaces */ - test_srt_do_test (srt_input3, 0, G_N_ELEMENTS (srt_input3)); -} - -GST_END_TEST; - -static void -do_test (SubParseInputChunk * input, guint num, const gchar * media_type) -{ - guint n; - - setup_subparse (); - - for (n = 0; n < num; ++n) { - GstBuffer *buf; - - buf = buffer_from_static_string (input[n].in); - fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK); - } - - gst_pad_push_event (mysrcpad, gst_event_new_eos ()); - - fail_unless_equals_int (g_list_length (buffers), num); - - for (n = 0; n < num; ++n) { - const GstStructure *buffer_caps_struct; - GstBuffer *buf; - gchar *out; - guint out_size; - - buf = g_list_nth_data (buffers, n); - fail_unless (buf != NULL); - - /* check timestamp */ - fail_unless (GST_BUFFER_TIMESTAMP_IS_VALID (buf), NULL); - fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buf), input[n].from_ts); - - /* might not be able to put a duration on the last buffer */ - if (input[n].to_ts != GST_CLOCK_TIME_NONE) { - /* check duration */ - fail_unless (GST_BUFFER_DURATION_IS_VALID (buf), NULL); - fail_unless_equals_uint64 (GST_BUFFER_DURATION (buf), - input[n].to_ts - input[n].from_ts); - } - - out = (gchar *) GST_BUFFER_DATA (buf); - out_size = GST_BUFFER_SIZE (buf); - /* shouldn't have trailing newline characters */ - fail_if (out_size > 0 && out[out_size - 1] == '\n'); - /* shouldn't include NUL-terminator in data size */ - fail_if (out_size > 0 && out[out_size - 1] == '\0'); - /* but should still have a NUL-terminator behind the declared data */ - fail_unless_equals_int (out[out_size], '\0'); - /* make sure out string matches expected string */ - fail_unless_equals_string (out, input[n].out); - /* check caps */ - fail_unless (GST_BUFFER_CAPS (buf) != NULL); - buffer_caps_struct = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0); - fail_unless_equals_string (gst_structure_get_name (buffer_caps_struct), - media_type); - } - - teardown_subparse (); -} - -static void -test_tmplayer_do_test (SubParseInputChunk * input, guint num) -{ - do_test (input, num, "text/plain"); -} - -static void -test_microdvd_do_test (SubParseInputChunk * input, guint num) -{ - do_test (input, num, "text/x-pango-markup"); -} - -GST_START_TEST (test_tmplayer_multiline) -{ - static SubParseInputChunk tmplayer_multiline_input[] = { - { - "00:00:10,1=This is the Earth at a time\n" - "00:00:10,2=when the dinosaurs roamed...\n" "00:00:13,1=\n", - 10 * GST_SECOND, 13 * GST_SECOND, - "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { - "00:00:14,1=a lush and fertile planet.\n" "00:00:16,1=\n", - 14 * GST_SECOND, 16 * GST_SECOND, - "a lush and fertile planet."} - }; - - test_tmplayer_do_test (tmplayer_multiline_input, - G_N_ELEMENTS (tmplayer_multiline_input)); -} - -GST_END_TEST; - -GST_START_TEST (test_tmplayer_multiline_with_bogus_lines) -{ - static SubParseInputChunk tmplayer_multiline_b_input[] = { - { - "00:00:10,1=This is the Earth at a time\n" - "Yooboo wabahablablahuguug bogus line hello test 1-2-3-4\n" - "00:00:10,2=when the dinosaurs roamed...\n" "00:00:13,1=\n", - 10 * GST_SECOND, 13 * GST_SECOND, - "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { - "00:00:14,1=a lush and fertile planet.\n" "00:00:16,1=\n", - 14 * GST_SECOND, 16 * GST_SECOND, - "a lush and fertile planet."} - }; - - test_tmplayer_do_test (tmplayer_multiline_b_input, - G_N_ELEMENTS (tmplayer_multiline_b_input)); -} - -GST_END_TEST; - -GST_START_TEST (test_tmplayer_style1) -{ - static SubParseInputChunk tmplayer_style1_input[] = { - { - "00:00:10:This is the Earth at a time|when the dinosaurs roamed...\n" - "00:00:13:\n", - 10 * GST_SECOND, 13 * GST_SECOND, - "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { - "00:00:14:a lush and fertile planet.\n" "00:00:16:\n", - 14 * GST_SECOND, 16 * GST_SECOND, - "a lush and fertile planet."} - }; - - test_tmplayer_do_test (tmplayer_style1_input, - G_N_ELEMENTS (tmplayer_style1_input)); -} - -GST_END_TEST; - -GST_START_TEST (test_tmplayer_style2) -{ - static SubParseInputChunk tmplayer_style2_input[] = { - { - "00:00:10=This is the Earth at a time|when the dinosaurs roamed...\n" - "00:00:13=\n", - 10 * GST_SECOND, 13 * GST_SECOND, - "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { - "00:00:14=a lush and fertile planet.\n" "00:00:16=\n", - 14 * GST_SECOND, 16 * GST_SECOND, - "a lush and fertile planet."} - }; - - test_tmplayer_do_test (tmplayer_style2_input, - G_N_ELEMENTS (tmplayer_style2_input)); -} - -GST_END_TEST; - -GST_START_TEST (test_tmplayer_style3) -{ - static SubParseInputChunk tmplayer_style3_input[] = { - { - "0:00:10:This is the Earth at a time|when the dinosaurs roamed...\n" - "0:00:13:\n", - 10 * GST_SECOND, 13 * GST_SECOND, - "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { - "0:00:14:a lush and fertile planet.\n" "0:00:16:\n", - 14 * GST_SECOND, 16 * GST_SECOND, - "a lush and fertile planet."} - }; - - test_tmplayer_do_test (tmplayer_style3_input, - G_N_ELEMENTS (tmplayer_style3_input)); -} - -GST_END_TEST; - -/* also tests the max_duration stuff (see second-last chunk which is supposed - * to be clipped to 5s duration) */ -GST_START_TEST (test_tmplayer_style3b) -{ - static SubParseInputChunk tmplayer_style3b_input[] = { - { - "0:00:10:This is the Earth at a time|when the dinosaurs roamed...\n", - 10 * GST_SECOND, 14 * GST_SECOND, - "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { - "0:00:14:a lush and fertile planet.\n", - 14 * GST_SECOND, 16 * GST_SECOND, - "a lush and fertile planet."}, { - "0:00:16:And they liked it a lot.\n", - 16 * GST_SECOND, (16 + 5) * GST_SECOND, "And they liked it a lot."}, { - "0:00:30:Last line.", - 30 * GST_SECOND, GST_CLOCK_TIME_NONE, "Last line."} - }; - - test_tmplayer_do_test (tmplayer_style3b_input, - G_N_ELEMENTS (tmplayer_style3b_input)); -} - -GST_END_TEST; - -GST_START_TEST (test_tmplayer_style4) -{ - static SubParseInputChunk tmplayer_style4_input[] = { - { - "0:00:10=This is the Earth at a time|when the dinosaurs roamed...\n" - "0:00:13=\n", - 10 * GST_SECOND, 13 * GST_SECOND, - "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { - "0:00:14=a lush and fertile planet.\n" "0:00:16=\n", - 14 * GST_SECOND, 16 * GST_SECOND, - "a lush and fertile planet."} - }; - - test_tmplayer_do_test (tmplayer_style4_input, - G_N_ELEMENTS (tmplayer_style4_input)); -} - -GST_END_TEST; - -GST_START_TEST (test_tmplayer_style4_with_bogus_lines) -{ - static SubParseInputChunk tmplayer_style4b_input[] = { - { - "0:00:10=This is the Earth at a time|when the dinosaurs roamed...\n" - "# This is a bogus line with a comment and should just be skipped\n" - "0:00:13=\n", - 10 * GST_SECOND, 13 * GST_SECOND, - "This is the Earth at a time\nwhen the dinosaurs roamed..."}, { - "0:00:14=a lush and fertile planet.\n" - " \n" - "0:00:16=\n", - 14 * GST_SECOND, 16 * GST_SECOND, - "a lush and fertile planet."} - }; - - test_tmplayer_do_test (tmplayer_style4b_input, - G_N_ELEMENTS (tmplayer_style4b_input)); -} - -GST_END_TEST; - -GST_START_TEST (test_microdvd_with_italics) -{ - static SubParseInputChunk microdvd_italics[] = { - { - "{1}{1}25.000 movie info: XVID 608x256 25.0fps 699.0 MB|" - "/SubEdit b.4060(http://subedit.com.pl)/\n" - "{100}{200}/italics/|not italics\n", - 4 * GST_SECOND, 8 * GST_SECOND, - "<span style=\"italic\">italics</span>\n" "<span>not italics</span>"} - }; - - test_microdvd_do_test (microdvd_italics, G_N_ELEMENTS (microdvd_italics)); -} - -GST_END_TEST; - -GST_START_TEST (test_microdvd_with_fps) -{ - static SubParseInputChunk microdvd_input[] = { - { - "{1}{1}12.500\n{100}{200}- Hi, Eddie.|- Hiya, Scotty.\n", - 8 * GST_SECOND, 16 * GST_SECOND, - "<span>- Hi, Eddie.</span>\n<span>- Hiya, Scotty.</span>"}, { - "{1250}{1350}- Cold enough for you?|- Well, I'm only faintly alive. " - "It's 25 below\n", - 100 * GST_SECOND, 108 * GST_SECOND, - "<span>- Cold enough for you?</span>\n" - "<span>- Well, I'm only faintly alive. It's 25 below</span>"} - }; - - test_microdvd_do_test (microdvd_input, G_N_ELEMENTS (microdvd_input)); - - /* and the same with ',' instead of '.' as floating point divider */ - microdvd_input[0].in = - "{1}{1}12,500\n{100}{200}- Hi, Eddie.|- Hiya, Scotty.\n"; - test_microdvd_do_test (microdvd_input, G_N_ELEMENTS (microdvd_input)); -} - -GST_END_TEST; - -GST_START_TEST (test_mpl2) -{ - SubParseInputChunk mpl2_input[] = { - { - "[123][456] This is the Earth at a time|when the dinosaurs roamed\n", - (123 * GST_SECOND) / 10, (456 * GST_SECOND) / 10, - "This is the Earth at a time\nwhen the dinosaurs roamed"}, { - "[1234][5678]a lush and fertile planet.\n", - (1234 * GST_SECOND) / 10, (5678 * GST_SECOND) / 10, - "a lush and fertile planet."}, { - "[12345][27890] /Italic|Normal\n", - (12345 * GST_SECOND) / 10, (27890 * GST_SECOND) / 10, - "<i>Italic</i>\nNormal"}, { - "[32345][37890]/Italic|/Italic\n", - (32345 * GST_SECOND) / 10, (37890 * GST_SECOND) / 10, - "<i>Italic</i>\n<i>Italic</i>"}, { - "[42345][47890] Normal|/Italic", - (42345 * GST_SECOND) / 10, (47890 * GST_SECOND) / 10, - "Normal\n<i>Italic</i>"} - }; - - do_test (mpl2_input, G_N_ELEMENTS (mpl2_input), "text/x-pango-markup"); -} - -GST_END_TEST; - -GST_START_TEST (test_subviewer) -{ - SubParseInputChunk subviewer_input[] = { - { - "[INFORMATION]\n" - "[TITLE]xxxxxxxxxx\n" - "[AUTHOR]xxxxxxxx\n" - "[SOURCE]xxxxxxxxxxxxxxxx\n" - "[FILEPATH]\n" - "[DELAY]0\n" - "[COMMENT]\n" - "[END INFORMATION]\n" - "[SUBTITLE]\n" - "[COLF]&HFFFFFF,[STYLE]bd,[SIZE]18,[FONT]Arial\n" - "00:00:41.00,00:00:44.40\n" - "The Age of Gods was closing.\n" - "Eternity had come to an end.\n" - "\n", 41 * GST_SECOND, 44 * GST_SECOND + 40 * GST_MSECOND, - "The Age of Gods was closing.\nEternity had come to an end."}, { - "00:00:55.00,00:00:58.40\n" - "The heavens shook as the armies\n" - "of Falis, God of Light...\n\n", 55 * GST_SECOND, - 58 * GST_SECOND + 40 * GST_MSECOND, - "The heavens shook as the armies\nof Falis, God of Light..."} - }; - - do_test (subviewer_input, G_N_ELEMENTS (subviewer_input), "text/plain"); -} - -GST_END_TEST; - -GST_START_TEST (test_subviewer2) -{ - SubParseInputChunk subviewer2_input[] = { - { - "[INFORMATION]\n" - "[TITLE]xxxxxxxxxx\n" - "[AUTHOR]xxxxxxxxxx\n" - "[SOURCE]xxxxxxxxxx\n" - "[PRG]\n" - "[FILEPATH]\n" - "[DELAY]0\n" - "[CD TRACK]0\n" - "[COMMENT]\n" - "[END INFORMATION]\n" - "[SUBTITLE]\n" - "[COLF]&H00FFFF,[STYLE]no,[SIZE]12,[FONT]Courier New\n" - "00:00:07.00,00:00:11.91\n" - "THERE IS A PLACE ON EARTH WHERE IT[br]IS STILL THE MORNING OF LIFE...\n\n", - 7 * GST_SECOND, 11 * GST_SECOND + 91 * GST_MSECOND, - "THERE IS A PLACE ON EARTH WHERE IT\nIS STILL THE MORNING OF LIFE..."}, { - "00:00:12.48,00:00:15.17\n" - "AND THE GREAT HERDS RUN FREE.[br]SO WHAT?!\n\n", - 12 * GST_SECOND + 48 * GST_MSECOND, - 15 * GST_SECOND + 17 * GST_MSECOND, - "AND THE GREAT HERDS RUN FREE.\nSO WHAT?!"} - }; - - do_test (subviewer2_input, G_N_ELEMENTS (subviewer2_input), "text/plain"); -} - -GST_END_TEST; - -GST_START_TEST (test_dks) -{ - SubParseInputChunk dks_input[] = { - { - "[00:00:07]THERE IS A PLACE ON EARTH WHERE IT[br]IS STILL THE MORNING OF LIFE...\n[00:00:12]\n", - 7 * GST_SECOND, 12 * GST_SECOND, - "THERE IS A PLACE ON EARTH WHERE IT\nIS STILL THE MORNING OF LIFE..."}, { - "[00:00:13]AND THE GREAT HERDS RUN FREE.[br]SO WHAT?!\n[00:00:15]\n", - 13 * GST_SECOND, 15 * GST_SECOND, - "AND THE GREAT HERDS RUN FREE.\nSO WHAT?!"} - }; - - do_test (dks_input, G_N_ELEMENTS (dks_input), "text/plain"); -} - -GST_END_TEST; - -#ifndef GST_DISABLE_XML -GST_START_TEST (test_sami) -{ - SubParseInputChunk sami_input[] = { - {"<SAMI>\n" - "<HEAD>\n" - " <TITLE>Subtitle</TITLE>\n" - " <STYLE TYPE=\"text/css\">\n" - " <!--\n" - " P {margin-left:8pt; margin-right:8pt; margin-bottom:2pt; margin-top:2pt; text-align:center; font-size:12pt; font-weight:normal; color:black;}\n" - " .CC {Name:English; lang:en-AU; SAMIType:CC;}\n" - " #STDPrn {Name:Standard Print;}\n" - " #LargePrn {Name:Large Print; font-size:24pt;}\n" - " #SmallPrn {Name:Small Print; font-size:16pt;}\n" - " -->\n" - " </Style>\n" - "</HEAD>\n" - "<BODY>\n" - " <SYNC Start=1000>\n" - " <P Class=CC>\n" - " This is a comment.<br>\n" - " This is a second comment.\n", - 1000 * GST_MSECOND, 2000 * GST_MSECOND, - "This is a comment.\nThis is a second comment."}, - {" <SYNC Start=2000>\n" - " <P Class=CC>\n" - " This is a third comment.<br>\n" - " This is a fourth comment.\n" "</BODY>\n" "</SAMI>\n", - 2000 * GST_MSECOND, GST_CLOCK_TIME_NONE, - "This is a third comment.\nThis is a fourth comment."} - }; - - do_test (sami_input, G_N_ELEMENTS (sami_input), "text/x-pango-markup"); -} - -GST_END_TEST; -#endif - -/* TODO: - * - add/modify tests so that lines aren't dogfed to the parsers in complete - * lines or sets of complete lines, but rather in random chunks - */ - -static Suite * -subparse_suite (void) -{ - Suite *s = suite_create ("subparse"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - - tcase_add_test (tc_chain, test_srt); - tcase_add_test (tc_chain, test_tmplayer_multiline); - tcase_add_test (tc_chain, test_tmplayer_multiline_with_bogus_lines); - tcase_add_test (tc_chain, test_tmplayer_style1); - tcase_add_test (tc_chain, test_tmplayer_style2); - tcase_add_test (tc_chain, test_tmplayer_style3); - tcase_add_test (tc_chain, test_tmplayer_style3b); - tcase_add_test (tc_chain, test_tmplayer_style4); - tcase_add_test (tc_chain, test_tmplayer_style4_with_bogus_lines); - tcase_add_test (tc_chain, test_microdvd_with_fps); - tcase_add_test (tc_chain, test_microdvd_with_italics); - tcase_add_test (tc_chain, test_mpl2); - tcase_add_test (tc_chain, test_subviewer); - tcase_add_test (tc_chain, test_subviewer2); - tcase_add_test (tc_chain, test_dks); -#ifndef GST_DISABLE_XML - tcase_add_test (tc_chain, test_sami); -#endif - return s; -} - -GST_CHECK_MAIN (subparse); diff --git a/tests/check/elements/textoverlay.c b/tests/check/elements/textoverlay.c deleted file mode 100644 index 63dd31d5..00000000 --- a/tests/check/elements/textoverlay.c +++ /dev/null @@ -1,751 +0,0 @@ -/* GStreamer unit tests for textoverlay - * - * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> - * - * 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 <unistd.h> - -#include <gst/check/gstcheck.h> - -#define I420_Y_ROWSTRIDE(width) (GST_ROUND_UP_4(width)) -#define I420_U_ROWSTRIDE(width) (GST_ROUND_UP_8(width)/2) -#define I420_V_ROWSTRIDE(width) ((GST_ROUND_UP_8(I420_Y_ROWSTRIDE(width)))/2) - -#define I420_Y_OFFSET(w,h) (0) -#define I420_U_OFFSET(w,h) (I420_Y_OFFSET(w,h)+(I420_Y_ROWSTRIDE(w)*GST_ROUND_UP_2(h))) -#define I420_V_OFFSET(w,h) (I420_U_OFFSET(w,h)+(I420_U_ROWSTRIDE(w)*GST_ROUND_UP_2(h)/2)) - -#define I420_SIZE(w,h) (I420_V_OFFSET(w,h)+(I420_V_ROWSTRIDE(w)*GST_ROUND_UP_2(h)/2)) - -#define WIDTH 240 -#define HEIGHT 120 - -/* For ease of programming we use globals to keep refs for our floating - * src and sink pads we create; otherwise we always have to do get_pad, - * get_peer, and then remove references in every test function */ -static GstPad *myvideosrcpad, *mytextsrcpad, *mysinkpad; - -#define VIDEO_CAPS_STRING \ - "video/x-raw-yuv, " \ - "format = (fourcc) I420, " \ - "framerate = (fraction) 1/1, " \ - "width = (int) 240, " \ - "height = (int) 120" - -#define VIDEO_CAPS_TEMPLATE_STRING \ - "video/x-raw-yuv, " \ - "format = (fourcc) I420" - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (VIDEO_CAPS_TEMPLATE_STRING) - ); -static GstStaticPadTemplate text_srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("text/plain") - ); - -static GstStaticPadTemplate video_srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (VIDEO_CAPS_TEMPLATE_STRING) - ); - -/* much like gst_check_setup_src_pad(), but with possibility to give a hint - * which sink template of the element to use, if there are multiple ones */ -static GstPad * -notgst_check_setup_src_pad2 (GstElement * element, - GstStaticPadTemplate * template, GstCaps * caps, - const gchar * sink_template_name) -{ - GstPad *srcpad, *sinkpad; - - if (sink_template_name == NULL) - sink_template_name = "sink"; - - /* sending pad */ - srcpad = gst_pad_new_from_static_template (template, "src"); - GST_DEBUG_OBJECT (element, "setting up sending pad %p", srcpad); - fail_if (srcpad == NULL, "Could not create a srcpad"); - ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1); - - if (!(sinkpad = gst_element_get_static_pad (element, sink_template_name))) - sinkpad = gst_element_get_request_pad (element, sink_template_name); - fail_if (sinkpad == NULL, "Could not get sink pad from %s", - GST_ELEMENT_NAME (element)); - ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2); - if (caps) - fail_unless (gst_pad_set_caps (srcpad, caps)); - fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK, - "Could not link source and %s sink pads", GST_ELEMENT_NAME (element)); - gst_object_unref (sinkpad); /* because we got it higher up */ - ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 1); - - return srcpad; -} - -static void -notgst_check_teardown_src_pad2 (GstElement * element, - const gchar * sink_template_name) -{ - GstPad *srcpad, *sinkpad; - - if (sink_template_name == NULL) - sink_template_name = "sink"; - - /* clean up floating src pad */ - if (!(sinkpad = gst_element_get_static_pad (element, sink_template_name))) - sinkpad = gst_element_get_request_pad (element, sink_template_name); - ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2); - srcpad = gst_pad_get_peer (sinkpad); - - gst_pad_unlink (srcpad, sinkpad); - - /* caps could have been set, make sure they get unset */ - gst_pad_set_caps (srcpad, NULL); - - /* pad refs held by both creator and this function (through _get) */ - ASSERT_OBJECT_REFCOUNT (sinkpad, "element sinkpad", 2); - gst_object_unref (sinkpad); - /* one more ref is held by element itself */ - - /* pad refs held by both creator and this function (through _get_peer) */ - ASSERT_OBJECT_REFCOUNT (srcpad, "check srcpad", 2); - gst_object_unref (srcpad); - gst_object_unref (srcpad); -} - -static GstElement * -setup_textoverlay (gboolean video_only_no_text) -{ - GstElement *textoverlay; - - GST_DEBUG ("setup_textoverlay"); - textoverlay = gst_check_setup_element ("textoverlay"); - mysinkpad = gst_check_setup_sink_pad (textoverlay, &sinktemplate, NULL); - myvideosrcpad = - notgst_check_setup_src_pad2 (textoverlay, &video_srctemplate, NULL, - "video_sink"); - - if (!video_only_no_text) { - mytextsrcpad = - notgst_check_setup_src_pad2 (textoverlay, &text_srctemplate, NULL, - "text_sink"); - gst_pad_set_active (mytextsrcpad, TRUE); - } else { - mytextsrcpad = NULL; - } - - gst_pad_set_active (myvideosrcpad, TRUE); - gst_pad_set_active (mysinkpad, TRUE); - - return textoverlay; -} - -static gboolean -buffer_is_all_black (GstBuffer * buf) -{ - GstStructure *s; - gint x, y, w, h; - - fail_unless (buf != NULL); - fail_unless (GST_BUFFER_CAPS (buf) != NULL); - s = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0); - fail_unless (s != NULL); - fail_unless (gst_structure_get_int (s, "width", &w)); - fail_unless (gst_structure_get_int (s, "height", &h)); - - for (y = 0; y < h; ++y) { - guint8 *data = GST_BUFFER_DATA (buf) + (y * GST_ROUND_UP_4 (w)); - - for (x = 0; x < w; ++x) { - if (data[x] != 0x00) { - GST_LOG ("non-black pixel at (x,y) %d,%d", x, y); - return FALSE; - } - } - } - - return TRUE; -} - -static GstBuffer * -create_black_buffer (const gchar * caps_string) -{ - GstStructure *s; - GstBuffer *buffer; - GstCaps *caps; - gint w, h, size; - - fail_unless (caps_string != NULL); - - caps = gst_caps_from_string (caps_string); - fail_unless (caps != NULL); - fail_unless (gst_caps_is_fixed (caps)); - - s = gst_caps_get_structure (caps, 0); - fail_unless (gst_structure_get_int (s, "width", &w)); - fail_unless (gst_structure_get_int (s, "height", &h)); - - GST_LOG ("creating buffer (%dx%d)", w, h); - size = I420_SIZE (w, h); - buffer = gst_buffer_new_and_alloc (size); - /* we're only checking the Y plane later, so just zero it all out, - * even if it's not the blackest black there is */ - memset (GST_BUFFER_DATA (buffer), 0, size); - - gst_buffer_set_caps (buffer, caps); - gst_caps_unref (caps); - - /* double check to make sure it's been created right */ - fail_unless (buffer_is_all_black (buffer)); - - return buffer; -} - -static GstBuffer * -create_text_buffer (const gchar * txt, GstClockTime ts, GstClockTime duration) -{ - GstBuffer *buffer; - GstCaps *caps; - guint txt_len; - - fail_unless (txt != NULL); - - txt_len = strlen (txt); - - buffer = gst_buffer_new_and_alloc (txt_len); - memcpy (GST_BUFFER_DATA (buffer), txt, txt_len); - - GST_BUFFER_TIMESTAMP (buffer) = ts; - GST_BUFFER_DURATION (buffer) = duration; - - caps = gst_caps_new_simple ("text/plain", NULL); - gst_buffer_set_caps (buffer, caps); - gst_caps_unref (caps); - - return buffer; -} - -static void -cleanup_textoverlay (GstElement * textoverlay) -{ - GST_DEBUG ("cleanup_textoverlay"); - - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - - gst_element_set_state (textoverlay, GST_STATE_NULL); - gst_element_get_state (textoverlay, NULL, NULL, GST_CLOCK_TIME_NONE); - gst_pad_set_active (myvideosrcpad, FALSE); - gst_pad_set_active (mysinkpad, FALSE); - notgst_check_teardown_src_pad2 (textoverlay, "video_sink"); - if (mytextsrcpad) { - notgst_check_teardown_src_pad2 (textoverlay, "text_sink"); - } - gst_check_teardown_sink_pad (textoverlay); - gst_check_teardown_element (textoverlay); -} - -GST_START_TEST (test_video_passthrough) -{ - GstElement *textoverlay; - GstBuffer *inbuffer; - - textoverlay = setup_textoverlay (TRUE); - fail_unless (gst_element_set_state (textoverlay, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = create_black_buffer (VIDEO_CAPS_STRING); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* ========== (1) video buffer without timestamp => should be dropped ==== */ - - /* take additional ref to keep it alive */ - gst_buffer_ref (inbuffer); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 2); - - /* pushing gives away one of the two references we have ... */ - fail_unless (gst_pad_push (myvideosrcpad, inbuffer) == GST_FLOW_OK); - - /* should have been discarded as out-of-segment since it has no timestamp */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 0); - - /* ========== (2) buffer with 0 timestamp => simple passthrough ========== */ - - /* now try again, this time with timestamp (segment defaults to 0 start) */ - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - GST_BUFFER_DURATION (inbuffer) = GST_CLOCK_TIME_NONE; - - /* take additional ref to keep it alive */ - gst_buffer_ref (inbuffer); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 2); - - /* pushing gives away one of the two references we have ... */ - fail_unless (gst_pad_push (myvideosrcpad, inbuffer) == GST_FLOW_OK); - - /* text pad is not linked, timestamp is in segment, no static text to - * render, should have gone through right away without modification */ - fail_unless_equals_int (g_list_length (buffers), 1); - fail_unless (GST_BUFFER_CAST (buffers->data) == inbuffer); - fail_unless (buffer_is_all_black (inbuffer)); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 2); - - /* and clean up */ - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* ========== (3) buffer with 0 timestamp and no duration, with the - * segment starting from 1sec => should be discarded */ - - gst_pad_push_event (myvideosrcpad, - gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 1 * GST_SECOND, - -1, 0)); - - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - GST_BUFFER_DURATION (inbuffer) = GST_CLOCK_TIME_NONE; - - /* take additional ref to keep it alive */ - gst_buffer_ref (inbuffer); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 2); - - /* pushing gives away one of the two references we have ... */ - fail_unless (gst_pad_push (myvideosrcpad, inbuffer) == GST_FLOW_OK); - - /* should have been discarded as out-of-segment */ - fail_unless_equals_int (g_list_length (buffers), 0); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* ========== (4) buffer with 0 timestamp and small defined duration, with - * segment starting from 1sec => should be discarded */ - - gst_pad_push_event (myvideosrcpad, - gst_event_new_new_segment (FALSE, 1.0, 1 * GST_FORMAT_TIME, GST_SECOND, - -1, 0)); - - GST_BUFFER_DURATION (inbuffer) = GST_SECOND / 10; - - /* take additional ref to keep it alive */ - gst_buffer_ref (inbuffer); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 2); - - /* pushing gives away one of the two references we have ... */ - fail_unless (gst_pad_push (myvideosrcpad, inbuffer) == GST_FLOW_OK); - - /* should have been discareded as out-of-segment since it has no timestamp */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 0); - - /* ========== (5) buffer partially overlapping into the segment => should - * be pushed through, but with adjusted stamp values */ - - gst_pad_push_event (myvideosrcpad, - gst_event_new_new_segment (FALSE, 1.0, 1 * GST_FORMAT_TIME, GST_SECOND, - -1, 0)); - - GST_BUFFER_TIMESTAMP (inbuffer) = GST_SECOND / 4; - GST_BUFFER_DURATION (inbuffer) = GST_SECOND; - - /* take additional ref to keep it alive */ - gst_buffer_ref (inbuffer); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 2); - - /* pushing gives away one of the two references we have ... */ - fail_unless (gst_pad_push (myvideosrcpad, inbuffer) == GST_FLOW_OK); - - /* should be the parent for a new subbuffer for the stamp fix-up */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 2); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_unless (GST_BUFFER_CAST (buffers->data) != inbuffer); - fail_unless (GST_BUFFER_TIMESTAMP (GST_BUFFER_CAST (buffers->data)) == - GST_SECOND); - fail_unless (GST_BUFFER_DURATION (GST_BUFFER_CAST (buffers->data)) == - (GST_SECOND / 4)); - fail_unless (buffer_is_all_black (GST_BUFFER_CAST (buffers->data))); - /* and clean up */ - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* cleanup */ - cleanup_textoverlay (textoverlay); - gst_buffer_unref (inbuffer); -} - -GST_END_TEST; - -GST_START_TEST (test_video_render_static_text) -{ - GstElement *textoverlay; - GstBuffer *inbuffer; - - textoverlay = setup_textoverlay (TRUE); - - /* set static text to render */ - g_object_set (textoverlay, "text", "XLX", NULL); - - fail_unless (gst_element_set_state (textoverlay, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = create_black_buffer (VIDEO_CAPS_STRING); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - GST_BUFFER_DURATION (inbuffer) = GST_SECOND / 10; - - /* take additional ref to keep it alive */ - gst_buffer_ref (inbuffer); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 2); - - /* pushing gives away one of the two references we have ... */ - fail_unless (gst_pad_push (myvideosrcpad, inbuffer) == GST_FLOW_OK); - - /* should have been dropped in favour of a new writable buffer */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_unless (GST_BUFFER_CAST (buffers->data) != inbuffer); - - /* there should be text rendered */ - fail_unless (buffer_is_all_black (GST_BUFFER_CAST (buffers->data)) == FALSE); - - fail_unless (GST_BUFFER_TIMESTAMP (GST_BUFFER_CAST (buffers->data)) == 0); - fail_unless (GST_BUFFER_DURATION (GST_BUFFER_CAST (buffers->data)) == - (GST_SECOND / 10)); - - /* and clean up */ - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* cleanup */ - cleanup_textoverlay (textoverlay); - gst_buffer_unref (inbuffer); -} - -GST_END_TEST; - -static gpointer -test_video_waits_for_text_send_text_newsegment_thread (gpointer data) -{ - g_usleep (1 * G_USEC_PER_SEC); - - /* send an update newsegment; the video buffer should now be pushed through - * even though there is no text buffer queued at the moment */ - GST_INFO ("Sending newsegment update on text pad"); - gst_pad_push_event (mytextsrcpad, - gst_event_new_new_segment (TRUE, 1.0, GST_FORMAT_TIME, - 35 * GST_SECOND, -1, 35 * GST_SECOND)); - - return NULL; -} - -static gpointer -test_video_waits_for_text_shutdown_element (gpointer data) -{ - g_usleep (1 * G_USEC_PER_SEC); - - GST_INFO ("Trying to shut down textoverlay element ..."); - /* set to NULL state to make sure we can shut it down while it's - * blocking in the video chain function waiting for a text buffer */ - gst_element_set_state (GST_ELEMENT (data), GST_STATE_NULL); - GST_INFO ("Done."); - - return NULL; -} - -GST_START_TEST (test_video_waits_for_text) -{ - GstElement *textoverlay; - GstBuffer *inbuffer, *tbuf; - GThread *thread; - - textoverlay = setup_textoverlay (FALSE); - - fail_unless (gst_element_set_state (textoverlay, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - tbuf = create_text_buffer ("XLX", 1 * GST_SECOND, 5 * GST_SECOND); - gst_buffer_ref (tbuf); - ASSERT_BUFFER_REFCOUNT (tbuf, "tbuf", 2); - - GST_LOG ("pushing text buffer"); - fail_unless (gst_pad_push (mytextsrcpad, tbuf) == GST_FLOW_OK); - - /* it should be stuck in textoverlay until it gets a text buffer or a - * newsegment event that indicates it's not needed any longer */ - fail_unless_equals_int (g_list_length (buffers), 0); - - inbuffer = create_black_buffer (VIDEO_CAPS_STRING); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - GST_BUFFER_DURATION (inbuffer) = GST_SECOND / 2; - - /* take additional ref to keep it alive */ - gst_buffer_ref (inbuffer); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 2); - - /* pushing gives away one of the two references we have ... */ - GST_LOG ("pushing video buffer 1"); - fail_unless (gst_pad_push (myvideosrcpad, inbuffer) == GST_FLOW_OK); - - /* video buffer should have gone through untainted, since the text is later */ - fail_unless_equals_int (g_list_length (buffers), 1); - - /* text should still be stuck in textoverlay */ - ASSERT_BUFFER_REFCOUNT (tbuf, "tbuf", 2); - - /* there should be no text rendered */ - fail_unless (buffer_is_all_black (GST_BUFFER_CAST (buffers->data))); - - /* now, another video buffer */ - inbuffer = gst_buffer_make_metadata_writable (inbuffer); - GST_BUFFER_TIMESTAMP (inbuffer) = GST_SECOND; - GST_BUFFER_DURATION (inbuffer) = GST_SECOND / 2; - - /* pushing gives away one of the two references we have ... */ - GST_LOG ("pushing video buffer 2"); - gst_buffer_ref (inbuffer); - fail_unless (gst_pad_push (myvideosrcpad, inbuffer) == GST_FLOW_OK); - - /* video buffer should have gone right away, with text rendered on it */ - fail_unless_equals_int (g_list_length (buffers), 2); - - /* text should still be stuck in textoverlay */ - ASSERT_BUFFER_REFCOUNT (tbuf, "tbuf", 2); - - /* there should be text rendered */ - fail_unless (buffer_is_all_black (GST_BUFFER_CAST (buffers->next->data)) == - FALSE); - - /* a third video buffer */ - inbuffer = gst_buffer_make_metadata_writable (inbuffer); - GST_BUFFER_TIMESTAMP (inbuffer) = 30 * GST_SECOND; - GST_BUFFER_DURATION (inbuffer) = GST_SECOND / 2; - - /* video buffer #3: should not go through, it should discard the current - * text buffer as too old and then wait for the next text buffer (or a - * newsegment event to arrive); we spawn a background thread to send such - * a newsegment event after a second or so so we get back control */ - thread = - g_thread_create (test_video_waits_for_text_send_text_newsegment_thread, - NULL, FALSE, NULL); - fail_unless (thread != NULL); - - GST_LOG ("pushing video buffer 3"); - gst_buffer_ref (inbuffer); - fail_unless (gst_pad_push (myvideosrcpad, inbuffer) == GST_FLOW_OK); - - /* but the text should no longer be stuck in textoverlay */ - ASSERT_BUFFER_REFCOUNT (tbuf, "tbuf", 1); - - /* video buffer should have gone through after newsegment event */ - fail_unless_equals_int (g_list_length (buffers), 3); - - /* ... and there should not be any text rendered on it */ - fail_unless (buffer_is_all_black (GST_BUFFER_CAST (buffers->next->next-> - data))); - - /* a fourth video buffer */ - inbuffer = gst_buffer_make_metadata_writable (inbuffer); - GST_BUFFER_TIMESTAMP (inbuffer) = 35 * GST_SECOND; - GST_BUFFER_DURATION (inbuffer) = GST_SECOND; - - /* video buffer #4: should not go through, it should wait for the next - * text buffer (or a newsegment event) to arrive; we spawn a background - * thread to shut down the element while it's waiting to make sure that - * works ok */ - thread = g_thread_create (test_video_waits_for_text_shutdown_element, - textoverlay, FALSE, NULL); - fail_unless (thread != NULL); - - GST_LOG ("pushing video buffer 4"); - gst_buffer_ref (inbuffer); - fail_unless (gst_pad_push (myvideosrcpad, inbuffer) == GST_FLOW_WRONG_STATE); - - /* and clean up */ - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* cleanup */ - cleanup_textoverlay (textoverlay); - gst_buffer_unref (inbuffer); - - /* give up our ref, textoverlay should've cleared its queued buffer by now */ - ASSERT_BUFFER_REFCOUNT (tbuf, "tbuf", 1); - gst_buffer_unref (tbuf); -} - -GST_END_TEST; - -static gpointer -test_render_continuity_push_video_buffers_thread (gpointer data) -{ - /* push video buffers at 1fps */ - guint frame_count = 0; - - do { - GstBuffer *vbuf; - - vbuf = create_black_buffer (VIDEO_CAPS_STRING); - ASSERT_BUFFER_REFCOUNT (vbuf, "vbuf", 1); - - GST_BUFFER_TIMESTAMP (vbuf) = frame_count * GST_SECOND; - GST_BUFFER_DURATION (vbuf) = GST_SECOND; - - /* pushing gives away one of the two references we have ... */ - GST_LOG ("pushing video buffer %u @ %" GST_TIME_FORMAT, frame_count, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (vbuf))); - fail_unless (gst_pad_push (myvideosrcpad, vbuf) == GST_FLOW_OK); - - ++frame_count; - } while (frame_count < 15); - - return NULL; -} - - -GST_START_TEST (test_render_continuity) -{ - GThread *thread; - GstElement *textoverlay; - GstBuffer *tbuf; - - textoverlay = setup_textoverlay (FALSE); - - fail_unless (gst_element_set_state (textoverlay, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - thread = g_thread_create (test_render_continuity_push_video_buffers_thread, - NULL, FALSE, NULL); - fail_unless (thread != NULL); - - tbuf = create_text_buffer ("XLX", 2 * GST_SECOND, GST_SECOND); - GST_LOG ("pushing text buffer @ %" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (tbuf))); - fail_unless (gst_pad_push (mytextsrcpad, tbuf) == GST_FLOW_OK); - - tbuf = create_text_buffer ("XLX", 3 * GST_SECOND, 2 * GST_SECOND); - GST_LOG ("pushing text buffer @ %" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (tbuf))); - fail_unless (gst_pad_push (mytextsrcpad, tbuf) == GST_FLOW_OK); - - tbuf = create_text_buffer ("XLX", 7 * GST_SECOND, GST_SECOND); - GST_LOG ("pushing text buffer @ %" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (tbuf))); - fail_unless (gst_pad_push (mytextsrcpad, tbuf) == GST_FLOW_OK); - - tbuf = create_text_buffer ("XLX", 8 * GST_SECOND, GST_SECOND); - GST_LOG ("pushing text buffer @ %" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (tbuf))); - fail_unless (gst_pad_push (mytextsrcpad, tbuf) == GST_FLOW_OK); - - tbuf = create_text_buffer ("XLX", 9 * GST_SECOND, GST_SECOND); - GST_LOG ("pushing text buffer @ %" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (tbuf))); - fail_unless (gst_pad_push (mytextsrcpad, tbuf) == GST_FLOW_OK); - - tbuf = create_text_buffer ("XLX", 10 * GST_SECOND, 30 * GST_SECOND); - GST_LOG ("pushing text buffer @ %" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (tbuf))); - fail_unless (gst_pad_push (mytextsrcpad, tbuf) == GST_FLOW_OK); - - GST_LOG ("give the other thread some time to push through the remaining" - "video buffers"); - g_usleep (G_USEC_PER_SEC); - GST_LOG ("done"); - - /* we should have 15 buffers each with one second length now */ - fail_unless_equals_int (g_list_length (buffers), 15); - - /* buffers 0 + 1 should be black */ - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, 0)))); - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, 1)))); - - /* buffers 2 - 4 should have text */ - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, - 2))) == FALSE); - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, - 3))) == FALSE); - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, - 4))) == FALSE); - - /* buffers 5 + 6 should be black */ - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, 5)))); - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, 6)))); - - /* buffers 7 - last should have text */ - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, - 7))) == FALSE); - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, - 8))) == FALSE); - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, - 9))) == FALSE); - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, - 10))) == FALSE); - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, - 11))) == FALSE); - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, - 12))) == FALSE); - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, - 13))) == FALSE); - fail_unless (buffer_is_all_black (GST_BUFFER (g_list_nth_data (buffers, - 14))) == FALSE); - - /* and clean up */ - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - - /* cleanup */ - cleanup_textoverlay (textoverlay); -} - -GST_END_TEST; - -static Suite * -textoverlay_suite (void) -{ - Suite *s = suite_create ("textoverlay"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - - tcase_add_test (tc_chain, test_video_passthrough); - tcase_add_test (tc_chain, test_video_render_static_text); - tcase_add_test (tc_chain, test_render_continuity); - tcase_add_test (tc_chain, test_video_waits_for_text); - - return s; -} - -GST_CHECK_MAIN (textoverlay); diff --git a/tests/check/elements/videorate.c b/tests/check/elements/videorate.c deleted file mode 100644 index 010ee775..00000000 --- a/tests/check/elements/videorate.c +++ /dev/null @@ -1,783 +0,0 @@ -/* GStreamer - * - * unit test for videorate - * - * Copyright (C) 2006 Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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 <unistd.h> - -#include <gst/check/gstcheck.h> - -/* For ease of programming we use globals to keep refs for our floating - * src and sink pads we create; otherwise we always have to do get_pad, - * get_peer, and then remove references in every test function */ -static GstPad *mysrcpad, *mysinkpad; - - -#define VIDEO_CAPS_TEMPLATE_STRING \ - "video/x-raw-yuv" - -#define VIDEO_CAPS_STRING \ - "video/x-raw-yuv, " \ - "width = (int) 320, " \ - "height = (int) 240, " \ - "framerate = (fraction) 25/1 , " \ - "format = (fourcc) I420" - -#define VIDEO_CAPS_NO_FRAMERATE_STRING \ - "video/x-raw-yuv, " \ - "width = (int) 320, " \ - "height = (int) 240, " \ - "format = (fourcc) I420" - -#define VIDEO_CAPS_NEWSIZE_STRING \ - "video/x-raw-yuv, " \ - "width = (int) 240, " \ - "height = (int) 120, " \ - "framerate = (fraction) 25/1 , " \ - "format = (fourcc) I420" - -#define VIDEO_CAPS_UNUSUAL_FRAMERATE \ - "video/x-raw-yuv, " \ - "width = (int) 240, " \ - "height = (int) 120, " \ - "framerate = (fraction) 999/7 , " \ - "format = (fourcc) I420" - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (VIDEO_CAPS_TEMPLATE_STRING) - ); -static GstStaticPadTemplate downstreamsinktemplate = -GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (VIDEO_CAPS_STRING) - ); -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (VIDEO_CAPS_TEMPLATE_STRING) - ); - -static void -assert_videorate_stats (GstElement * videorate, gchar * reason, - guint64 xin, guint64 xout, guint64 xdropped, guint64 xduplicated) -{ - guint64 in, out, dropped, duplicated; - - g_object_get (videorate, "in", &in, "out", &out, "drop", &dropped, - "duplicate", &duplicated, NULL); -#define _assert_equals_uint64(a, b) \ -G_STMT_START { \ - guint64 first = a; \ - guint64 second = b; \ - fail_unless(first == second, \ - "%s: '" #a "' (%" G_GUINT64_FORMAT ") is not equal to " \ - "expected '" #a"' (%" G_GUINT64_FORMAT ")", reason, first, second); \ -} G_STMT_END; - - - _assert_equals_uint64 (in, xin); - _assert_equals_uint64 (out, xout); - _assert_equals_uint64 (dropped, xdropped); - _assert_equals_uint64 (duplicated, xduplicated); -} - -static GstElement * -setup_videorate_full (GstStaticPadTemplate * srctemplate, - GstStaticPadTemplate * sinktemplate) -{ - GstElement *videorate; - - GST_DEBUG ("setup_videorate"); - videorate = gst_check_setup_element ("videorate"); - mysrcpad = gst_check_setup_src_pad (videorate, srctemplate, NULL); - mysinkpad = gst_check_setup_sink_pad (videorate, sinktemplate, NULL); - gst_pad_set_active (mysrcpad, TRUE); - gst_pad_set_active (mysinkpad, TRUE); - - return videorate; -} - -static GstElement * -setup_videorate (void) -{ - return setup_videorate_full (&srctemplate, &sinktemplate); -} - -static void -cleanup_videorate (GstElement * videorate) -{ - GST_DEBUG ("cleanup_videorate"); - - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - - gst_element_set_state (videorate, GST_STATE_NULL); - gst_element_get_state (videorate, NULL, NULL, GST_CLOCK_TIME_NONE); - gst_pad_set_active (mysrcpad, FALSE); - gst_pad_set_active (mysinkpad, FALSE); - gst_check_teardown_src_pad (videorate); - gst_check_teardown_sink_pad (videorate); - gst_check_teardown_element (videorate); -} - -GST_START_TEST (test_one) -{ - GstElement *videorate; - GstBuffer *inbuffer; - GstCaps *caps; - - videorate = setup_videorate (); - fail_unless (gst_element_set_state (videorate, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (4); - memset (GST_BUFFER_DATA (inbuffer), 0, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - gst_buffer_set_caps (inbuffer, caps); - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... and it is now stuck inside videorate */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 0); - - /* cleanup */ - cleanup_videorate (videorate); -} - -GST_END_TEST; - -GST_START_TEST (test_more) -{ - GstElement *videorate; - GstBuffer *first, *second, *third, *outbuffer; - GList *l; - GstCaps *caps; - GRand *rand; - - videorate = setup_videorate (); - fail_unless (gst_element_set_state (videorate, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - assert_videorate_stats (videorate, "creation", 0, 0, 0, 0); - - rand = g_rand_new (); - - /* first buffer */ - first = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (first) = 0; - /* it shouldn't matter what the offsets are, videorate produces perfect - streams */ - GST_BUFFER_OFFSET (first) = g_rand_int (rand); - GST_BUFFER_OFFSET_END (first) = g_rand_int (rand); - memset (GST_BUFFER_DATA (first), 1, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - gst_buffer_set_caps (first, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (first, "first", 1); - gst_buffer_ref (first); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, first) == GST_FLOW_OK); - /* ... and it is now stuck inside videorate */ - ASSERT_BUFFER_REFCOUNT (first, "first", 2); - fail_unless_equals_int (g_list_length (buffers), 0); - assert_videorate_stats (videorate, "first buffer", 1, 0, 0, 0); - - /* second buffer; inbetween second and third output frame's timestamp */ - second = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (second) = GST_SECOND * 3 / 50; - GST_BUFFER_OFFSET (first) = g_rand_int (rand); - GST_BUFFER_OFFSET_END (first) = g_rand_int (rand); - memset (GST_BUFFER_DATA (second), 2, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - gst_buffer_set_caps (second, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (second, "second", 1); - gst_buffer_ref (second); - - /* pushing gives away one of my references ... */ - fail_unless (gst_pad_push (mysrcpad, second) == GST_FLOW_OK); - /* ... and it is now stuck inside videorate */ - ASSERT_BUFFER_REFCOUNT (second, "second", 2); - - /* ... and the first one is pushed out, with timestamp 0 */ - fail_unless_equals_int (g_list_length (buffers), 1); - assert_videorate_stats (videorate, "second buffer", 2, 1, 0, 0); - ASSERT_BUFFER_REFCOUNT (first, "first", 2); - - outbuffer = buffers->data; - fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (outbuffer), 0); - - /* third buffer */ - third = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (third) = GST_SECOND * 12 / 50; - GST_BUFFER_OFFSET (first) = g_rand_int (rand); - GST_BUFFER_OFFSET_END (first) = g_rand_int (rand); - memset (GST_BUFFER_DATA (third), 3, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - gst_buffer_set_caps (third, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (third, "third", 1); - gst_buffer_ref (third); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, third) == GST_FLOW_OK); - /* ... and it is now stuck inside videorate */ - ASSERT_BUFFER_REFCOUNT (third, "third", 2); - - /* submitting the third buffer has triggered flushing of three more frames */ - assert_videorate_stats (videorate, "third buffer", 3, 4, 0, 2); - - /* check timestamp and source correctness */ - l = buffers; - fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), 0); - fail_unless_equals_int (GST_BUFFER_DATA (l->data)[0], 1); - fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 0); - fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 1); - - l = g_list_next (l); - fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), GST_SECOND / 25); - fail_unless_equals_int (GST_BUFFER_DATA (l->data)[0], 2); - fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 1); - fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 2); - - l = g_list_next (l); - fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), - GST_SECOND * 2 / 25); - fail_unless_equals_int (GST_BUFFER_DATA (l->data)[0], 2); - fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 2); - fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 3); - - l = g_list_next (l); - fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), - GST_SECOND * 3 / 25); - fail_unless_equals_int (GST_BUFFER_DATA (l->data)[0], 2); - fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 3); - fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 4); - - fail_unless_equals_int (g_list_length (buffers), 4); - /* one held by us, three held by each output frame taken from the second */ - ASSERT_BUFFER_REFCOUNT (second, "second", 4); - - /* now send EOS */ - fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ())); - - /* submitting eos should flush out two more frames for tick 8 and 10 */ - /* FIXME: right now it only flushes out one, so out is 5 instead of 6 ! */ - assert_videorate_stats (videorate, "eos", 3, 5, 0, 2); - fail_unless_equals_int (g_list_length (buffers), 5); - - /* cleanup */ - g_rand_free (rand); - gst_buffer_unref (first); - gst_buffer_unref (second); - gst_buffer_unref (third); - cleanup_videorate (videorate); -} - -GST_END_TEST; - -/* frames at 1, 0, 2 -> second one should be ignored */ -GST_START_TEST (test_wrong_order_from_zero) -{ - GstElement *videorate; - GstBuffer *first, *second, *third, *outbuffer; - GstCaps *caps; - - videorate = setup_videorate (); - fail_unless (gst_element_set_state (videorate, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - assert_videorate_stats (videorate, "start", 0, 0, 0, 0); - - /* first buffer */ - first = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (first) = GST_SECOND; - memset (GST_BUFFER_DATA (first), 0, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - gst_buffer_set_caps (first, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (first, "first", 1); - gst_buffer_ref (first); - - GST_DEBUG ("pushing first buffer"); - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, first) == GST_FLOW_OK); - /* ... and it is now stuck inside videorate */ - ASSERT_BUFFER_REFCOUNT (first, "first", 2); - fail_unless_equals_int (g_list_length (buffers), 0); - assert_videorate_stats (videorate, "first", 1, 0, 0, 0); - - /* second buffer */ - second = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (second) = 0; - memset (GST_BUFFER_DATA (second), 0, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - gst_buffer_set_caps (second, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (second, "second", 1); - gst_buffer_ref (second); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, second) == GST_FLOW_OK); - /* ... and it is now dropped because it is too old */ - ASSERT_BUFFER_REFCOUNT (second, "second", 1); - fail_unless_equals_int (g_list_length (buffers), 0); - - /* ... and the first one is still there */ - assert_videorate_stats (videorate, "second", 2, 0, 1, 0); - ASSERT_BUFFER_REFCOUNT (first, "first", 2); - - /* third buffer */ - third = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (third) = 2 * GST_SECOND; - memset (GST_BUFFER_DATA (third), 0, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - gst_buffer_set_caps (third, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (third, "third", 1); - gst_buffer_ref (third); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, third) == GST_FLOW_OK); - /* ... and it is now stuck inside videorate */ - ASSERT_BUFFER_REFCOUNT (third, "third", 2); - - /* and now the first one should be pushed once and dupped 24 + 13 times, to - * reach the half point between 1 s (first) and 2 s (third) */ - fail_unless_equals_int (g_list_length (buffers), 38); - ASSERT_BUFFER_REFCOUNT (first, "first", 39); - ASSERT_BUFFER_REFCOUNT (second, "second", 1); - ASSERT_BUFFER_REFCOUNT (third, "third", 2); - assert_videorate_stats (videorate, "third", 3, 38, 1, 37); - - /* verify last buffer */ - outbuffer = g_list_last (buffers)->data; - fail_unless (GST_IS_BUFFER (outbuffer)); - fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (outbuffer), - GST_SECOND * 37 / 25); - - /* cleanup */ - gst_buffer_unref (first); - gst_buffer_unref (second); - gst_buffer_unref (third); - cleanup_videorate (videorate); -} - -GST_END_TEST; - -/* send frames with 0, 1, 2, 0 seconds */ -GST_START_TEST (test_wrong_order) -{ - GstElement *videorate; - GstBuffer *first, *second, *third, *fourth, *outbuffer; - GstCaps *caps; - - videorate = setup_videorate (); - fail_unless (gst_element_set_state (videorate, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - assert_videorate_stats (videorate, "start", 0, 0, 0, 0); - - /* first buffer */ - first = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (first) = 0; - memset (GST_BUFFER_DATA (first), 0, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - gst_buffer_set_caps (first, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (first, "first", 1); - gst_buffer_ref (first); - - GST_DEBUG ("pushing first buffer"); - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, first) == GST_FLOW_OK); - /* ... and it is now stuck inside videorate */ - ASSERT_BUFFER_REFCOUNT (first, "first", 2); - fail_unless_equals_int (g_list_length (buffers), 0); - assert_videorate_stats (videorate, "first", 1, 0, 0, 0); - - /* second buffer */ - second = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (second) = GST_SECOND; - memset (GST_BUFFER_DATA (second), 0, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - gst_buffer_set_caps (second, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (second, "second", 1); - gst_buffer_ref (second); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, second) == GST_FLOW_OK); - /* ... and it is now stuck inside videorate */ - ASSERT_BUFFER_REFCOUNT (second, "second", 2); - /* and it created 13 output buffers as copies of the first frame */ - fail_unless_equals_int (g_list_length (buffers), 13); - assert_videorate_stats (videorate, "second", 2, 13, 0, 12); - ASSERT_BUFFER_REFCOUNT (first, "first", 14); - - /* third buffer */ - third = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (third) = 2 * GST_SECOND; - memset (GST_BUFFER_DATA (third), 0, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - gst_buffer_set_caps (third, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (third, "third", 1); - gst_buffer_ref (third); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, third) == GST_FLOW_OK); - /* ... and it is now stuck inside videorate */ - ASSERT_BUFFER_REFCOUNT (third, "third", 2); - - /* submitting a frame with 2 seconds triggers output of 25 more frames */ - fail_unless_equals_int (g_list_length (buffers), 38); - ASSERT_BUFFER_REFCOUNT (first, "first", 14); - ASSERT_BUFFER_REFCOUNT (second, "second", 26); - /* three frames submitted; two of them output as is, and 36 duplicated */ - assert_videorate_stats (videorate, "third", 3, 38, 0, 36); - - /* fourth buffer */ - fourth = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (fourth) = 0; - memset (GST_BUFFER_DATA (fourth), 0, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - gst_buffer_set_caps (fourth, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (fourth, "fourth", 1); - gst_buffer_ref (fourth); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, fourth) == GST_FLOW_OK); - /* ... and it is dropped */ - ASSERT_BUFFER_REFCOUNT (fourth, "fourth", 1); - - fail_unless_equals_int (g_list_length (buffers), 38); - ASSERT_BUFFER_REFCOUNT (first, "first", 14); - ASSERT_BUFFER_REFCOUNT (second, "second", 26); - assert_videorate_stats (videorate, "fourth", 4, 38, 1, 36); - - /* verify last buffer */ - outbuffer = g_list_last (buffers)->data; - fail_unless (GST_IS_BUFFER (outbuffer)); - fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (outbuffer), - GST_SECOND * 37 / 25); - - - /* cleanup */ - gst_buffer_unref (first); - gst_buffer_unref (second); - gst_buffer_unref (third); - gst_buffer_unref (fourth); - cleanup_videorate (videorate); -} - -GST_END_TEST; - - -/* if no framerate is negotiated, we should not be able to push a buffer */ -GST_START_TEST (test_no_framerate) -{ - GstElement *videorate; - GstBuffer *inbuffer; - GstCaps *caps; - - videorate = setup_videorate (); - fail_unless (gst_element_set_state (videorate, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (4); - memset (GST_BUFFER_DATA (inbuffer), 0, 4); - caps = gst_caps_from_string (VIDEO_CAPS_NO_FRAMERATE_STRING); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* take a ref so we can later check refcount */ - gst_buffer_ref (inbuffer); - - /* no framerate is negotiated so pushing should fail */ - fail_if (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_unref (inbuffer); - fail_unless_equals_int (g_list_length (buffers), 0); - - /* cleanup */ - cleanup_videorate (videorate); -} - -GST_END_TEST; - -/* This test outputs 2 buffers of same dimensions (320x240), then 1 buffer of - * differing dimensions (240x120), and then another buffer of previous - * dimensions (320x240) and checks that the 3 buffers output as a result have - * correct caps (first 2 with 320x240 and 3rd with 240x120). - */ -GST_START_TEST (test_changing_size) -{ - GstElement *videorate; - GstBuffer *first; - GstBuffer *second; - GstBuffer *third; - GstBuffer *fourth; - GstBuffer *fifth; - GstBuffer *outbuf; - GstEvent *newsegment; - GstCaps *caps, *caps_newsize; - - videorate = setup_videorate (); - fail_unless (gst_element_set_state (videorate, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - newsegment = gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME, 0, -1, - 0); - fail_unless (gst_pad_push_event (mysrcpad, newsegment) == TRUE); - - first = gst_buffer_new_and_alloc (4); - memset (GST_BUFFER_DATA (first), 0, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - GST_BUFFER_TIMESTAMP (first) = 0; - gst_buffer_set_caps (first, caps); - - GST_DEBUG ("pushing first buffer"); - fail_unless (gst_pad_push (mysrcpad, first) == GST_FLOW_OK); - - /* second buffer */ - second = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (second) = GST_SECOND / 25; - memset (GST_BUFFER_DATA (second), 0, 4); - gst_buffer_set_caps (second, caps); - - fail_unless (gst_pad_push (mysrcpad, second) == GST_FLOW_OK); - fail_unless_equals_int (g_list_length (buffers), 1); - outbuf = buffers->data; - /* first buffer should be output here */ - fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (outbuf), caps)); - fail_unless (GST_BUFFER_TIMESTAMP (outbuf) == 0); - - /* third buffer with new size */ - third = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (third) = 2 * GST_SECOND / 25; - memset (GST_BUFFER_DATA (third), 0, 4); - caps_newsize = gst_caps_from_string (VIDEO_CAPS_NEWSIZE_STRING); - gst_buffer_set_caps (third, caps_newsize); - - fail_unless (gst_pad_push (mysrcpad, third) == GST_FLOW_OK); - /* new caps flushed the internal state, no new output yet */ - fail_unless_equals_int (g_list_length (buffers), 1); - outbuf = g_list_last (buffers)->data; - /* first buffer should be output here */ - fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (outbuf), caps)); - fail_unless (GST_BUFFER_TIMESTAMP (outbuf) == 0); - - /* fourth buffer with original size */ - fourth = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (fourth) = 3 * GST_SECOND / 25; - memset (GST_BUFFER_DATA (fourth), 0, 4); - gst_buffer_set_caps (fourth, caps); - - fail_unless (gst_pad_push (mysrcpad, fourth) == GST_FLOW_OK); - fail_unless_equals_int (g_list_length (buffers), 1); - - /* fifth buffer with original size */ - fifth = gst_buffer_new_and_alloc (4); - GST_BUFFER_TIMESTAMP (fifth) = 4 * GST_SECOND / 25; - memset (GST_BUFFER_DATA (fifth), 0, 4); - gst_buffer_set_caps (fifth, caps); - - fail_unless (gst_pad_push (mysrcpad, fifth) == GST_FLOW_OK); - /* all four missing buffers here, dups of fourth buffer */ - fail_unless_equals_int (g_list_length (buffers), 4); - outbuf = g_list_last (buffers)->data; - /* third buffer should be output here */ - fail_unless (GST_BUFFER_TIMESTAMP (outbuf) == 3 * GST_SECOND / 25); - fail_unless (gst_caps_is_equal (GST_BUFFER_CAPS (outbuf), caps)); - - gst_caps_unref (caps); - gst_caps_unref (caps_newsize); - cleanup_videorate (videorate); -} - -GST_END_TEST; - -GST_START_TEST (test_non_ok_flow) -{ - GstElement *videorate; - GstClockTime ts; - GstBuffer *buf; - GstCaps *caps; - - videorate = setup_videorate (); - fail_unless (gst_element_set_state (videorate, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - buf = gst_buffer_new_and_alloc (4); - memset (GST_BUFFER_DATA (buf), 0, 4); - caps = gst_caps_from_string (VIDEO_CAPS_STRING); - gst_buffer_set_caps (buf, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (buf, "inbuffer", 1); - - /* push a few 'normal' buffers */ - for (ts = 0; ts < 100 * GST_SECOND; ts += GST_SECOND / 33) { - GstBuffer *inbuf; - - inbuf = gst_buffer_copy (buf); - GST_BUFFER_TIMESTAMP (inbuf) = ts; - - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuf), GST_FLOW_OK); - } - - /* we should have buffers according to the output framerate of 25/1 */ - fail_unless_equals_int (g_list_length (buffers), 100 * 25); - - /* now deactivate pad so we get a WRONG_STATE flow return */ - gst_pad_set_active (mysinkpad, FALSE); - - /* push buffer on deactivated pad */ - fail_unless (gst_buffer_is_metadata_writable (buf)); - GST_BUFFER_TIMESTAMP (buf) = ts; - - /* pushing gives away our reference */ - fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_WRONG_STATE); - - /* cleanup */ - cleanup_videorate (videorate); -} - -GST_END_TEST; - -GST_START_TEST (test_upstream_caps_nego) -{ - GstElement *videorate; - GstPad *videorate_pad; - GstCaps *expected_caps; - GstCaps *caps; - GstStructure *structure; - - videorate = setup_videorate_full (&srctemplate, &downstreamsinktemplate); - fail_unless (gst_element_set_state (videorate, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - videorate_pad = gst_element_get_pad (videorate, "sink"); - caps = gst_pad_get_caps (videorate_pad); - - /* assemble the expected caps */ - structure = gst_structure_from_string (VIDEO_CAPS_STRING, NULL); - expected_caps = gst_caps_new_empty (); - gst_caps_append_structure (expected_caps, structure); - structure = gst_structure_copy (structure); - gst_structure_set (structure, "framerate", GST_TYPE_FRACTION_RANGE, - 0, 1, G_MAXINT, 1, NULL); - gst_caps_append_structure (expected_caps, structure); - - fail_unless (gst_caps_is_equal (expected_caps, caps)); - gst_caps_unref (caps); - gst_caps_unref (expected_caps); - gst_object_unref (videorate_pad); - - /* cleanup */ - cleanup_videorate (videorate); -} - -GST_END_TEST; - - -GST_START_TEST (test_selected_caps) -{ - GstElement *videorate; - GstElement *pipeline; - GstBus *bus; - GstMessage *msg; - - GstPad *videorate_pad; - GstCaps *caps = NULL; - GstCaps *expected_caps = NULL; - - pipeline = gst_parse_launch ("videotestsrc num-buffers=1 ! " - "! identity ! videorate name=videorate0 ! " VIDEO_CAPS_UNUSUAL_FRAMERATE - " ! fakesink", NULL); - fail_if (pipeline == NULL); - videorate = gst_bin_get_by_name (GST_BIN (pipeline), "videorate0"); - fail_if (videorate == NULL); - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - - fail_if (gst_element_set_state (pipeline, - GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE, - "could not set to playing"); - - msg = gst_bus_timed_pop_filtered (bus, GST_CLOCK_TIME_NONE, - GST_MESSAGE_EOS | GST_MESSAGE_ERROR); - fail_if (msg == NULL || GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR); - - videorate_pad = gst_element_get_pad (videorate, "sink"); - g_object_get (videorate_pad, "caps", &caps, NULL); - expected_caps = gst_caps_from_string (VIDEO_CAPS_UNUSUAL_FRAMERATE); - - fail_unless (gst_caps_is_equal (expected_caps, caps)); - - /* cleanup */ - gst_object_unref (bus); - gst_message_unref (msg); - gst_caps_unref (caps); - gst_caps_unref (expected_caps); - gst_object_unref (videorate_pad); - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE); - gst_object_unref (pipeline); -} - -GST_END_TEST; - -static Suite * -videorate_suite (void) -{ - Suite *s = suite_create ("videorate"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_one); - tcase_add_test (tc_chain, test_more); - tcase_add_test (tc_chain, test_wrong_order_from_zero); - tcase_add_test (tc_chain, test_wrong_order); - tcase_add_test (tc_chain, test_no_framerate); - tcase_add_test (tc_chain, test_changing_size); - tcase_add_test (tc_chain, test_non_ok_flow); - tcase_add_test (tc_chain, test_upstream_caps_nego); - tcase_add_test (tc_chain, test_selected_caps); - - return s; -} - -GST_CHECK_MAIN (videorate) diff --git a/tests/check/elements/videoscale.c b/tests/check/elements/videoscale.c deleted file mode 100644 index 35e9c06d..00000000 --- a/tests/check/elements/videoscale.c +++ /dev/null @@ -1,361 +0,0 @@ -/* GStreamer - * - * unit test for videoscale - * - * Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk> - * - * 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 <gst/check/gstcheck.h> -#include <string.h> - -static GstCaps ** -videoscale_get_allowed_caps (void) -{ - GstElement *scale = gst_element_factory_make ("videoscale", "scale"); - GstPadTemplate *templ; - GstCaps *caps, **ret; - GstStructure *s; - gint i, n; - - templ = - gst_element_class_get_pad_template (GST_ELEMENT_GET_CLASS (scale), - "sink"); - fail_unless (templ != NULL); - - caps = gst_pad_template_get_caps (templ); - - n = gst_caps_get_size (caps); - ret = g_new0 (GstCaps *, n + 1); - - for (i = 0; i < n; i++) { - s = gst_caps_get_structure (caps, i); - ret[i] = gst_caps_new_empty (); - gst_caps_append_structure (ret[i], gst_structure_copy (s)); - } - - gst_object_unref (scale); - - return ret; -} - -typedef struct -{ - GMainLoop *loop; - gboolean eos; -} OnMessageUserData; - -static void -on_message_cb (GstBus * bus, GstMessage * message, gpointer user_data) -{ - OnMessageUserData *d = user_data; - - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_ERROR: - case GST_MESSAGE_WARNING: - g_assert_not_reached (); - break; - case GST_MESSAGE_EOS: - g_main_loop_quit (d->loop); - d->eos = TRUE; - break; - default: - break; - } -} - -static void -on_sink_handoff (GstElement * element, GstBuffer * buffer, GstPad * pad, - gpointer user_data) -{ - guint *n_buffers = user_data; - - *n_buffers = *n_buffers + 1; -} - -static void -run_test (const GstCaps * caps, gint src_width, gint src_height, - gint dest_width, gint dest_height, gint method, - GCallback src_handoff, gpointer src_handoff_user_data, - GCallback sink_handoff, gpointer sink_handoff_user_data) -{ - GstElement *pipeline; - GstElement *src, *capsfilter1, *identity, *scale, *capsfilter2, *sink; - GstBus *bus; - GMainLoop *loop; - GstCaps *copy; - guint n_buffers = 0; - OnMessageUserData omud = { NULL, }; - - pipeline = gst_element_factory_make ("pipeline", "pipeline"); - fail_unless (pipeline != NULL); - - src = gst_element_factory_make ("videotestsrc", "src"); - fail_unless (src != NULL); - g_object_set (G_OBJECT (src), "num-buffers", 5, NULL); - - capsfilter1 = gst_element_factory_make ("capsfilter", "filter1"); - fail_unless (capsfilter1 != NULL); - copy = gst_caps_copy (caps); - gst_caps_set_simple (copy, "width", G_TYPE_INT, src_width, "height", - G_TYPE_INT, src_height, "framerate", GST_TYPE_FRACTION, 30, 1, NULL); - g_object_set (G_OBJECT (capsfilter1), "caps", copy, NULL); - gst_caps_unref (copy); - - identity = gst_element_factory_make ("identity", "identity"); - fail_unless (identity != NULL); - if (src_handoff) { - g_object_set (G_OBJECT (identity), "signal-handoffs", TRUE, NULL); - g_signal_connect (identity, "handoff", G_CALLBACK (src_handoff), - src_handoff_user_data); - } - - scale = gst_element_factory_make ("videoscale", "scale"); - fail_unless (scale != NULL); - g_object_set (G_OBJECT (scale), "method", method, NULL); - - capsfilter2 = gst_element_factory_make ("capsfilter", "filter2"); - fail_unless (capsfilter2 != NULL); - copy = gst_caps_copy (caps); - gst_caps_set_simple (copy, "width", G_TYPE_INT, dest_width, "height", - G_TYPE_INT, dest_height, NULL); - g_object_set (G_OBJECT (capsfilter2), "caps", copy, NULL); - gst_caps_unref (copy); - - sink = gst_element_factory_make ("fakesink", "sink"); - fail_unless (sink != NULL); - g_object_set (G_OBJECT (sink), "signal-handoffs", TRUE, "async", FALSE, NULL); - g_signal_connect (sink, "handoff", G_CALLBACK (on_sink_handoff), &n_buffers); - if (sink_handoff) { - g_signal_connect (sink, "handoff", G_CALLBACK (sink_handoff), - sink_handoff_user_data); - } - - gst_bin_add_many (GST_BIN (pipeline), src, capsfilter1, identity, scale, - capsfilter2, sink, NULL); - fail_unless (gst_element_link_many (src, capsfilter1, identity, scale, - capsfilter2, sink, NULL)); - - loop = g_main_loop_new (NULL, FALSE); - - bus = gst_element_get_bus (pipeline); - fail_unless (bus != NULL); - gst_bus_add_signal_watch (bus); - - omud.loop = loop; - omud.eos = FALSE; - - g_signal_connect (bus, "message", (GCallback) on_message_cb, &omud); - - gst_object_unref (bus); - - fail_unless (gst_element_set_state (pipeline, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS); - - g_main_loop_run (loop); - - fail_unless (gst_element_set_state (pipeline, - GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS); - - fail_unless (omud.eos == TRUE); - fail_unless (n_buffers == 5); - - gst_object_unref (pipeline); - g_main_loop_unref (loop); -} - -static void -on_sink_handoff_passthrough (GstElement * element, GstBuffer * buffer, - GstPad * pad, gpointer user_data) -{ - GList **list = user_data; - - *list = g_list_prepend (*list, gst_buffer_ref (buffer)); -} - -static void -on_src_handoff_passthrough (GstElement * element, GstBuffer * buffer, - gpointer user_data) -{ - GList **list = user_data; - - *list = g_list_prepend (*list, gst_buffer_ref (buffer)); -} - -GST_START_TEST (test_passthrough) -{ - GList *l1, *l2, *src_buffers = NULL, *sink_buffers = NULL; - GstCaps **allowed_caps = NULL, **p; - gint method; - static const gint src_width = 640, src_height = 480; - static const gint dest_width = 640, dest_height = 480; - - p = allowed_caps = videoscale_get_allowed_caps (); - - while (*p) { - GstCaps *caps = *p; - - for (method = 0; method < 3; method++) { - GST_DEBUG ("Running test for caps '%" GST_PTR_FORMAT "'" - " from %dx%u to %dx%d with method %d", caps, src_width, src_height, - dest_width, dest_height, method); - run_test (caps, src_width, src_height, - dest_width, dest_height, method, - G_CALLBACK (on_src_handoff_passthrough), &src_buffers, - G_CALLBACK (on_sink_handoff_passthrough), &sink_buffers); - - fail_unless (src_buffers && sink_buffers); - fail_unless_equals_int (g_list_length (src_buffers), - g_list_length (sink_buffers)); - - for (l1 = src_buffers, l2 = sink_buffers; l1 && l2; - l1 = l1->next, l2 = l2->next) { - GstBuffer *a = l1->data; - GstBuffer *b = l2->data; - - fail_unless_equals_int (GST_BUFFER_SIZE (a), GST_BUFFER_SIZE (b)); - fail_unless (GST_BUFFER_DATA (a) == GST_BUFFER_DATA (b)); - - gst_buffer_unref (a); - gst_buffer_unref (b); - } - g_list_free (src_buffers); - src_buffers = NULL; - g_list_free (sink_buffers); - sink_buffers = NULL; - } - - gst_caps_unref (caps); - p++; - } - g_free (allowed_caps); -} - -GST_END_TEST; - -#define CREATE_TEST(name,method,src_width,src_height,dest_width,dest_height) \ -GST_START_TEST (name) \ -{ \ - GstCaps **allowed_caps = NULL, **p; \ - \ - p = allowed_caps = videoscale_get_allowed_caps (); \ - \ - while (*p) { \ - GstCaps *caps = *p; \ - \ - GST_DEBUG ("Running test for caps '%" GST_PTR_FORMAT "'" \ - " from %dx%u to %dx%d with method %d", caps, src_width, src_height, \ - dest_width, dest_height, method); \ - run_test (caps, src_width, src_height, \ - dest_width, dest_height, method, \ - NULL, NULL, NULL, NULL); \ - \ - gst_caps_unref (caps); \ - p++; \ - } \ - g_free (allowed_caps); \ -} \ -\ -GST_END_TEST; - -CREATE_TEST (test_downscale_640x480_320x240_method_0, 0, 640, 480, 320, 240); -CREATE_TEST (test_downscale_640x480_320x240_method_1, 1, 640, 480, 320, 240); -CREATE_TEST (test_downscale_640x480_320x240_method_2, 2, 640, 480, 320, 240); -CREATE_TEST (test_upscale_320x240_640x480_method_0, 0, 320, 240, 640, 480); -CREATE_TEST (test_upscale_320x240_640x480_method_1, 1, 320, 240, 640, 480); -CREATE_TEST (test_upscale_320x240_640x480_method_2, 2, 320, 240, 640, 480); -CREATE_TEST (test_downscale_640x480_1x1_method_0, 0, 640, 480, 1, 1); -CREATE_TEST (test_downscale_640x480_1x1_method_1, 1, 640, 480, 1, 1); -CREATE_TEST (test_downscale_640x480_1x1_method_2, 2, 640, 480, 1, 1); -CREATE_TEST (test_upscale_1x1_640x480_method_0, 0, 1, 1, 640, 480); -CREATE_TEST (test_upscale_1x1_640x480_method_1, 1, 1, 1, 640, 480); -CREATE_TEST (test_upscale_1x1_640x480_method_2, 2, 1, 1, 640, 480); -CREATE_TEST (test_downscale_641x481_111x30_method_0, 0, 641, 481, 111, 30); -CREATE_TEST (test_downscale_641x481_111x30_method_1, 1, 641, 481, 111, 30); -CREATE_TEST (test_downscale_641x481_111x30_method_2, 2, 641, 481, 111, 30); -CREATE_TEST (test_upscale_111x30_641x481_method_0, 0, 111, 30, 641, 481); -CREATE_TEST (test_upscale_111x30_641x481_method_1, 1, 111, 30, 641, 481); -CREATE_TEST (test_upscale_111x30_641x481_method_2, 2, 111, 30, 641, 481); -CREATE_TEST (test_downscale_641x481_30x111_method_0, 0, 641, 481, 30, 111); -CREATE_TEST (test_downscale_641x481_30x111_method_1, 1, 641, 481, 30, 111); -CREATE_TEST (test_downscale_641x481_30x111_method_2, 2, 641, 481, 30, 111); -CREATE_TEST (test_upscale_30x111_641x481_method_0, 0, 30, 111, 641, 481); -CREATE_TEST (test_upscale_30x111_641x481_method_1, 1, 30, 111, 641, 481); -CREATE_TEST (test_upscale_30x111_641x481_method_2, 2, 30, 111, 641, 481); -CREATE_TEST (test_downscale_640x480_320x1_method_0, 0, 640, 480, 320, 1); -CREATE_TEST (test_downscale_640x480_320x1_method_1, 1, 640, 480, 320, 1); -CREATE_TEST (test_downscale_640x480_320x1_method_2, 2, 640, 480, 320, 1); -CREATE_TEST (test_upscale_320x1_640x480_method_0, 0, 320, 1, 640, 480); -CREATE_TEST (test_upscale_320x1_640x480_method_1, 1, 320, 1, 640, 480); -CREATE_TEST (test_upscale_320x1_640x480_method_2, 2, 320, 1, 640, 480); -CREATE_TEST (test_downscale_640x480_1x240_method_0, 0, 640, 480, 1, 240); -CREATE_TEST (test_downscale_640x480_1x240_method_1, 1, 640, 480, 1, 240); -CREATE_TEST (test_downscale_640x480_1x240_method_2, 2, 640, 480, 1, 240); -CREATE_TEST (test_upscale_1x240_640x480_method_0, 0, 1, 240, 640, 480); -CREATE_TEST (test_upscale_1x240_640x480_method_1, 1, 1, 240, 640, 480); -CREATE_TEST (test_upscale_1x240_640x480_method_2, 2, 1, 240, 640, 480); - -static Suite * -videoscale_suite (void) -{ - Suite *s = suite_create ("videoscale"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_set_timeout (tc_chain, 180); - tcase_add_test (tc_chain, test_passthrough); - tcase_add_test (tc_chain, test_downscale_640x480_320x240_method_0); - tcase_add_test (tc_chain, test_downscale_640x480_320x240_method_1); - tcase_add_test (tc_chain, test_downscale_640x480_320x240_method_2); - tcase_add_test (tc_chain, test_upscale_320x240_640x480_method_0); - tcase_add_test (tc_chain, test_upscale_320x240_640x480_method_1); - tcase_add_test (tc_chain, test_upscale_320x240_640x480_method_2); - tcase_add_test (tc_chain, test_downscale_640x480_1x1_method_0); - tcase_add_test (tc_chain, test_downscale_640x480_1x1_method_1); - tcase_add_test (tc_chain, test_downscale_640x480_1x1_method_2); - tcase_add_test (tc_chain, test_upscale_1x1_640x480_method_0); - tcase_add_test (tc_chain, test_upscale_1x1_640x480_method_1); - tcase_add_test (tc_chain, test_upscale_1x1_640x480_method_2); - tcase_add_test (tc_chain, test_downscale_641x481_111x30_method_0); - tcase_add_test (tc_chain, test_downscale_641x481_111x30_method_1); - tcase_add_test (tc_chain, test_downscale_641x481_111x30_method_2); - tcase_add_test (tc_chain, test_upscale_111x30_641x481_method_0); - tcase_add_test (tc_chain, test_upscale_111x30_641x481_method_1); - tcase_add_test (tc_chain, test_upscale_111x30_641x481_method_2); - tcase_add_test (tc_chain, test_downscale_641x481_30x111_method_0); - tcase_add_test (tc_chain, test_downscale_641x481_30x111_method_1); - tcase_add_test (tc_chain, test_downscale_641x481_30x111_method_2); - tcase_add_test (tc_chain, test_upscale_30x111_641x481_method_0); - tcase_add_test (tc_chain, test_upscale_30x111_641x481_method_1); - tcase_add_test (tc_chain, test_upscale_30x111_641x481_method_2); - tcase_add_test (tc_chain, test_downscale_640x480_320x1_method_0); - tcase_add_test (tc_chain, test_downscale_640x480_320x1_method_1); - tcase_add_test (tc_chain, test_downscale_640x480_320x1_method_2); - tcase_add_test (tc_chain, test_upscale_320x1_640x480_method_0); - tcase_add_test (tc_chain, test_upscale_320x1_640x480_method_1); - tcase_add_test (tc_chain, test_upscale_320x1_640x480_method_2); - tcase_add_test (tc_chain, test_downscale_640x480_1x240_method_0); - tcase_add_test (tc_chain, test_downscale_640x480_1x240_method_1); - tcase_add_test (tc_chain, test_downscale_640x480_1x240_method_2); - tcase_add_test (tc_chain, test_upscale_1x240_640x480_method_0); - tcase_add_test (tc_chain, test_upscale_1x240_640x480_method_1); - tcase_add_test (tc_chain, test_upscale_1x240_640x480_method_2); - - return s; -} - -GST_CHECK_MAIN (videoscale); diff --git a/tests/check/elements/videotestsrc.c b/tests/check/elements/videotestsrc.c deleted file mode 100644 index 827c5b31..00000000 --- a/tests/check/elements/videotestsrc.c +++ /dev/null @@ -1,447 +0,0 @@ -/* GStreamer - * - * unit test for videotestsrc - * - * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org> - * Copyright (C) <2006> Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#ifdef HAVE_VALGRIND -# include <valgrind/valgrind.h> -#endif - -#include <unistd.h> - -#include <gst/check/gstcheck.h> - -/* For ease of programming we use globals to keep refs for our floating - * src and sink pads we create; otherwise we always have to do get_pad, - * get_peer, and then remove references in every test function */ -static GstPad *mysinkpad; - - -#define CAPS_TEMPLATE_STRING \ - "video/x-raw-yuv, " \ - "format = (fourcc) Y422, " \ - "width = (int) [ 1, MAX ], " \ - "height = (int) [ 1, MAX ], " \ - "framerate = (fraction) [ 0/1, MAX ]" - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (CAPS_TEMPLATE_STRING) - ); - -static GstElement * -setup_videotestsrc (void) -{ - GstElement *videotestsrc; - - GST_DEBUG ("setup_videotestsrc"); - videotestsrc = gst_check_setup_element ("videotestsrc"); - mysinkpad = gst_check_setup_sink_pad (videotestsrc, &sinktemplate, NULL); - gst_pad_set_active (mysinkpad, TRUE); - - return videotestsrc; -} - -static void -cleanup_videotestsrc (GstElement * videotestsrc) -{ - GST_DEBUG ("cleanup_videotestsrc"); - - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - - gst_pad_set_active (mysinkpad, FALSE); - gst_check_teardown_sink_pad (videotestsrc); - gst_check_teardown_element (videotestsrc); -} - -GST_START_TEST (test_all_patterns) -{ - GstElement *videotestsrc; - GObjectClass *oclass; - GParamSpec *property; - GEnumValue *values; - guint j = 0; - - videotestsrc = setup_videotestsrc (); - oclass = G_OBJECT_GET_CLASS (videotestsrc); - property = g_object_class_find_property (oclass, "pattern"); - fail_unless (G_IS_PARAM_SPEC_ENUM (property)); - values = G_ENUM_CLASS (g_type_class_ref (property->value_type))->values; - - - while (values[j].value_name) { - GST_DEBUG_OBJECT (videotestsrc, "testing pattern %s", values[j].value_name); - - fail_unless (gst_element_set_state (videotestsrc, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - g_mutex_lock (check_mutex); - while (g_list_length (buffers) < 10) { - GST_DEBUG_OBJECT (videotestsrc, "Waiting for more buffers"); - g_cond_wait (check_cond, check_mutex); - } - g_mutex_unlock (check_mutex); - - - gst_element_set_state (videotestsrc, GST_STATE_READY); - - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - ++j; - } - - /* cleanup */ - cleanup_videotestsrc (videotestsrc); -} - -GST_END_TEST; - -static guint32 -right_shift_colour (guint32 mask, guint32 pixel) -{ - if (mask == 0) - return 0; - - pixel = pixel & mask; - while ((mask & 0x01) == 0) { - mask = mask >> 1; - pixel = pixel >> 1; - } - - return pixel; -} - -static guint8 -fix_expected_colour (guint32 col_mask, guint8 col_expected) -{ - guint32 mask; - gint last = g_bit_nth_msf (col_mask, -1); - gint first = g_bit_nth_lsf (col_mask, -1); - - mask = 1 << (last - first + 1); - mask -= 1; - - g_assert (col_expected == 0x00 || col_expected == 0xff); - - /* this only works because we only check for all-bits-set or no-bits-set */ - return col_expected & mask; -} - -static void -check_rgb_buf (const guint8 * pixels, guint32 r_mask, guint32 g_mask, - guint32 b_mask, guint32 a_mask, guint8 r_expected, guint8 g_expected, - guint8 b_expected, guint endianness, guint bpp, guint depth) -{ - guint32 pixel, red, green, blue, alpha; - - switch (bpp) { - case 32:{ - if (endianness == G_LITTLE_ENDIAN) - pixel = GST_READ_UINT32_LE (pixels); - else - pixel = GST_READ_UINT32_BE (pixels); - break; - } - case 24:{ - if (endianness == G_BIG_ENDIAN) { - pixel = (GST_READ_UINT8 (pixels) << 16) | - (GST_READ_UINT8 (pixels + 1) << 8) | - (GST_READ_UINT8 (pixels + 2) << 0); - } else { - pixel = (GST_READ_UINT8 (pixels + 2) << 16) | - (GST_READ_UINT8 (pixels + 1) << 8) | - (GST_READ_UINT8 (pixels + 0) << 0); - } - break; - } - case 16:{ - if (endianness == G_LITTLE_ENDIAN) - pixel = GST_READ_UINT16_LE (pixels); - else - pixel = GST_READ_UINT16_BE (pixels); - break; - } - default: - g_return_if_reached (); - } - - red = right_shift_colour (r_mask, pixel); - green = right_shift_colour (g_mask, pixel); - blue = right_shift_colour (b_mask, pixel); - alpha = right_shift_colour (a_mask, pixel); - - /* can't enable this by default, valgrind will complain about accessing - * uninitialised memory for the depth=24,bpp=32 formats ... */ - /* GST_LOG ("pixels: 0x%02x 0x%02x 0x%02x 0x%02x => pixel = 0x%08x", - pixels[0], (guint) pixels[1], pixels[2], pixels[3], pixel); */ - - /* fix up the mask (for rgb15/16) */ - if (bpp == 16) { - r_expected = fix_expected_colour (r_mask, r_expected); - g_expected = fix_expected_colour (g_mask, g_expected); - b_expected = fix_expected_colour (b_mask, b_expected); - } - - fail_unless (red == r_expected, "RED: expected 0x%02x, found 0x%02x", - r_expected, red); - fail_unless (green == g_expected, "GREEN: expected 0x%02x, found 0x%02x", - g_expected, green); - fail_unless (blue == b_expected, "BLUE: expected 0x%02x, found 0x%02x", - b_expected, blue); - - fail_unless (a_mask == 0 || alpha != 0); /* better than nothing */ -} - -static void -got_buf_cb (GstElement * sink, GstBuffer * new_buf, GstPad * pad, - GstBuffer ** p_old_buf) -{ - gst_buffer_replace (p_old_buf, new_buf); -} - -/* tests the positioning of pixels within the various RGB pixel layouts */ -GST_START_TEST (test_rgb_formats) -{ - const struct - { - const gchar *pattern_name; - gint pattern_enum; - guint8 r_expected; - guint8 g_expected; - guint8 b_expected; - } test_patterns[] = { - { - "white", 3, 0xff, 0xff, 0xff}, { - "red", 4, 0xff, 0x00, 0x00}, { - "green", 5, 0x00, 0xff, 0x00}, { - "blue", 6, 0x00, 0x00, 0xff}, { - "black", 2, 0x00, 0x00, 0x00} - }; - const struct - { - const gchar *nick; - guint bpp, depth; - guint32 red_mask, green_mask, blue_mask, alpha_mask; - } rgb_formats[] = { - { - "RGBA", 32, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff}, { - "ARGB", 32, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000}, { - "BGRA", 32, 32, 0x0000ff00, 0x00ff0000, 0xff000000, 0x000000ff}, { - "ABGR", 32, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000}, { - "RGBx", 32, 24, 0xff000000, 0x00ff0000, 0x0000ff00, 0x00000000}, { - "xRGB", 32, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000}, { - "BGRx", 32, 24, 0x0000ff00, 0x00ff0000, 0xff000000, 0x00000000}, { - "xBGR", 32, 24, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000}, { - "RGB ", 24, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000}, { - "BGR ", 24, 24, 0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000}, { - "RGB565", 16, 16, 0x0000f800, 0x000007e0, 0x0000001f, 0x00000000}, { - "xRGB1555", 16, 15, 0x00007c00, 0x000003e0, 0x0000001f, 0x0000000} - }; - GstElement *pipeline, *src, *filter, *sink; - const GstCaps *template_caps; - GstBuffer *buf = NULL; - GstPad *srcpad; - gint p, i, e; - - /* test check function */ - fail_unless (right_shift_colour (0x00ff0000, 0x11223344) == 0x22); - - pipeline = gst_pipeline_new ("pipeline"); - src = gst_check_setup_element ("videotestsrc"); - filter = gst_check_setup_element ("capsfilter"); - sink = gst_check_setup_element ("fakesink"); - - gst_bin_add_many (GST_BIN (pipeline), src, filter, sink, NULL); - - fail_unless (gst_element_link (src, filter)); - fail_unless (gst_element_link (filter, sink)); - - srcpad = gst_element_get_static_pad (src, "src"); - template_caps = gst_pad_get_pad_template_caps (srcpad); - gst_object_unref (srcpad); - - g_object_set (sink, "signal-handoffs", TRUE, NULL); - g_signal_connect (sink, "preroll-handoff", G_CALLBACK (got_buf_cb), &buf); - - GST_LOG ("videotestsrc src template caps: %" GST_PTR_FORMAT, template_caps); - - for (i = 0; i < G_N_ELEMENTS (rgb_formats); ++i) { - for (e = 0; e < 2; ++e) { - guint endianness; - GstCaps *caps; - - if (e == 0) { - endianness = G_BYTE_ORDER; - } else { - endianness = - (G_BYTE_ORDER == G_BIG_ENDIAN) ? G_LITTLE_ENDIAN : G_BIG_ENDIAN; - } - - caps = gst_caps_new_simple ("video/x-raw-rgb", - "bpp", G_TYPE_INT, rgb_formats[i].bpp, - "depth", G_TYPE_INT, rgb_formats[i].depth, - "red_mask", G_TYPE_INT, rgb_formats[i].red_mask, - "green_mask", G_TYPE_INT, rgb_formats[i].green_mask, - "blue_mask", G_TYPE_INT, rgb_formats[i].blue_mask, - "width", G_TYPE_INT, 16, "height", G_TYPE_INT, 16, - "endianness", G_TYPE_INT, endianness, - "framerate", GST_TYPE_FRACTION, 1, 1, NULL); - - fail_unless (rgb_formats[i].alpha_mask == 0 || rgb_formats[i].bpp == 32); - - if (rgb_formats[i].alpha_mask != 0) { - gst_structure_set (gst_caps_get_structure (caps, 0), - "alpha_mask", G_TYPE_INT, rgb_formats[i].alpha_mask, NULL); - } - - if (gst_caps_is_subset (caps, template_caps)) { - - /* caps are supported, let's run some tests then ... */ - for (p = 0; p < G_N_ELEMENTS (test_patterns); ++p) { - GstStateChangeReturn state_ret; - - g_object_set (src, "pattern", test_patterns[p].pattern_enum, NULL); - - GST_INFO ("%5s %u/%u %08x %08x %08x %08x %u, pattern=%s", - rgb_formats[i].nick, rgb_formats[i].bpp, rgb_formats[i].depth, - rgb_formats[i].red_mask, rgb_formats[i].green_mask, - rgb_formats[i].blue_mask, rgb_formats[i].alpha_mask, endianness, - test_patterns[p].pattern_name); - - /* now get videotestsrc to produce a buffer with the given caps */ - g_object_set (filter, "caps", caps, NULL); - - state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED); - fail_unless (state_ret != GST_STATE_CHANGE_FAILURE, - "pipeline _set_state() to PAUSED failed"); - state_ret = gst_element_get_state (pipeline, NULL, NULL, -1); - fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS, - "pipeline failed going to PAUSED state"); - - state_ret = gst_element_set_state (pipeline, GST_STATE_NULL); - fail_unless (state_ret == GST_STATE_CHANGE_SUCCESS); - - fail_unless (buf != NULL); - - /* check buffer caps */ - { - GstStructure *s; - gint v; - - fail_unless (GST_BUFFER_CAPS (buf) != NULL); - - s = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0); - fail_unless (gst_structure_get_int (s, "bpp", &v)); - fail_unless_equals_int (v, rgb_formats[i].bpp); - fail_unless (gst_structure_get_int (s, "depth", &v)); - fail_unless_equals_int (v, rgb_formats[i].depth); - fail_unless (gst_structure_get_int (s, "red_mask", &v)); - fail_unless_equals_int (v, rgb_formats[i].red_mask); - fail_unless (gst_structure_get_int (s, "green_mask", &v)); - fail_unless_equals_int (v, rgb_formats[i].green_mask); - fail_unless (gst_structure_get_int (s, "blue_mask", &v)); - fail_unless_equals_int (v, rgb_formats[i].blue_mask); - /* there mustn't be an alpha_mask if there's no alpha component */ - if (rgb_formats[i].depth == 32) { - fail_unless (gst_structure_get_int (s, "alpha_mask", &v)); - fail_unless_equals_int (v, rgb_formats[i].alpha_mask); - } else { - fail_unless (gst_structure_get_value (s, "alpha_mask") == NULL); - } - } - - - /* now check the first pixel */ - check_rgb_buf (GST_BUFFER_DATA (buf), rgb_formats[i].red_mask, - rgb_formats[i].green_mask, rgb_formats[i].blue_mask, - rgb_formats[i].alpha_mask, test_patterns[p].r_expected, - test_patterns[p].g_expected, test_patterns[p].b_expected, - endianness, rgb_formats[i].bpp, rgb_formats[i].depth); - - gst_buffer_unref (buf); - buf = NULL; - } - - } else { - GST_INFO ("videotestsrc doesn't support format %" GST_PTR_FORMAT, caps); - } - - gst_caps_unref (caps); - } - } - - gst_object_unref (pipeline); -} - -GST_END_TEST; - - -/* FIXME: add tests for YUV formats */ - -static Suite * -videotestsrc_suite (void) -{ - Suite *s = suite_create ("videotestsrc"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - -#ifdef HAVE_VALGRIND - if (RUNNING_ON_VALGRIND) { - /* otherwise valgrind errors out when liboil probes CPU extensions - * during which it causes SIGILLs etc. to be fired */ - g_setenv ("OIL_CPU_FLAGS", "0", 0); - /* test_rgb_formats takes a bit longer, so increase timeout */ - tcase_set_timeout (tc_chain, 5 * 60); - } -#endif - - tcase_add_test (tc_chain, test_all_patterns); - tcase_add_test (tc_chain, test_rgb_formats); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = videotestsrc_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/elements/volume.c b/tests/check/elements/volume.c deleted file mode 100644 index d59a96f3..00000000 --- a/tests/check/elements/volume.c +++ /dev/null @@ -1,1525 +0,0 @@ -/* GStreamer - * - * unit test for volume - * - * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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 <unistd.h> - -#include <gst/base/gstbasetransform.h> -#include <gst/check/gstcheck.h> -#include <gst/controller/gstcontroller.h> -#include <gst/interfaces/streamvolume.h> - -/* For ease of programming we use globals to keep refs for our floating - * src and sink pads we create; otherwise we always have to do get_pad, - * get_peer, and then remove references in every test function */ -static GstPad *mysrcpad, *mysinkpad; - - -#define VOLUME_CAPS_TEMPLATE_STRING \ - "audio/x-raw-int, " \ - "channels = (int) [ 1, MAX ], " \ - "rate = (int) [ 1, MAX ], " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) { 8, 16, 24, 32 }, " \ - "depth = (int) { 8, 16, 24, 32 }, " \ - "signed = (bool) TRUE; " \ - "audio/x-raw-float, " \ - "channels = (int) [ 1, MAX ], " \ - "rate = (int) [ 1, MAX ], " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) { 32, 64 }" \ - -#define VOLUME_CAPS_STRING_S8 \ - "audio/x-raw-int, " \ - "channels = (int) 1, " \ - "rate = (int) 44100, " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 8, " \ - "depth = (int) 8, " \ - "signed = (bool) TRUE" - -#define VOLUME_CAPS_STRING_S16 \ - "audio/x-raw-int, " \ - "channels = (int) 1, " \ - "rate = (int) 44100, " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 16, " \ - "depth = (int) 16, " \ - "signed = (bool) TRUE" - -#define VOLUME_CAPS_STRING_S24 \ - "audio/x-raw-int, " \ - "channels = (int) 1, " \ - "rate = (int) 44100, " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 24, " \ - "depth = (int) 24, " \ - "signed = (bool) TRUE" - -#define VOLUME_CAPS_STRING_S32 \ - "audio/x-raw-int, " \ - "channels = (int) 1, " \ - "rate = (int) 44100, " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 32, " \ - "depth = (int) 32, " \ - "signed = (bool) TRUE" - -#define VOLUME_CAPS_STRING_F32 \ - "audio/x-raw-float, " \ - "channels = (int) 1, " \ - "rate = (int) 44100, " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 32" - -#define VOLUME_CAPS_STRING_F64 \ - "audio/x-raw-float, " \ - "channels = (int) 1, " \ - "rate = (int) 44100, " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 64" - -#define VOLUME_WRONG_CAPS_STRING \ - "audio/x-raw-int, " \ - "channels = (int) 1, " \ - "rate = (int) 44100, " \ - "endianness = (int) BYTE_ORDER, " \ - "width = (int) 16, " \ - "depth = (int) 16, " \ - "signed = (bool) FALSE" - - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (VOLUME_CAPS_TEMPLATE_STRING) - ); -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (VOLUME_CAPS_TEMPLATE_STRING) - ); - -static GstElement * -setup_volume (void) -{ - GstElement *volume; - - GST_DEBUG ("setup_volume"); - volume = gst_check_setup_element ("volume"); - mysrcpad = gst_check_setup_src_pad (volume, &srctemplate, NULL); - mysinkpad = gst_check_setup_sink_pad (volume, &sinktemplate, NULL); - gst_pad_set_active (mysrcpad, TRUE); - gst_pad_set_active (mysinkpad, TRUE); - - return volume; -} - -static void -cleanup_volume (GstElement * volume) -{ - GST_DEBUG ("cleanup_volume"); - - g_list_foreach (buffers, (GFunc) gst_mini_object_unref, NULL); - g_list_free (buffers); - buffers = NULL; - - gst_pad_set_active (mysrcpad, FALSE); - gst_pad_set_active (mysinkpad, FALSE); - gst_check_teardown_src_pad (volume); - gst_check_teardown_sink_pad (volume); - gst_check_teardown_element (volume); -} - -GST_START_TEST (test_get_set) -{ - GstElement *volume = gst_element_factory_make ("volume", NULL); - gdouble val; - - fail_unless (volume != NULL); - g_object_get (G_OBJECT (volume), "volume", &val, NULL); - fail_unless (val == 1.0); - fail_unless (val == gst_stream_volume_get_volume (GST_STREAM_VOLUME (volume), - GST_STREAM_VOLUME_FORMAT_LINEAR)); - - g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); - g_object_get (G_OBJECT (volume), "volume", &val, NULL); - fail_unless (val == 0.5); - fail_unless (val == gst_stream_volume_get_volume (GST_STREAM_VOLUME (volume), - GST_STREAM_VOLUME_FORMAT_LINEAR)); - - gst_stream_volume_set_volume (GST_STREAM_VOLUME (volume), - GST_STREAM_VOLUME_FORMAT_LINEAR, 1.0); - g_object_get (G_OBJECT (volume), "volume", &val, NULL); - fail_unless (val == 1.0); - fail_unless (val == gst_stream_volume_get_volume (GST_STREAM_VOLUME (volume), - GST_STREAM_VOLUME_FORMAT_LINEAR)); - - gst_object_unref (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_unity_s8) -{ - GstElement *volume; - GstBuffer *inbuffer, *outbuffer; - GstCaps *caps; - gint8 in[2] = { 64, -16 }; - gint8 *res; - - volume = setup_volume (); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (2); - memcpy (GST_BUFFER_DATA (inbuffer), in, 2); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint8 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 2) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_half_s8) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gint8 in[2] = { 64, -16 }; - gint8 out[2] = { 32, -8 }; - gint8 *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (2); - memcpy (GST_BUFFER_DATA (inbuffer), in, 2); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 2) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint8 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], - res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 2) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_double_s8) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gint8 in[2] = { 64, -16 }; - gint8 out[2] = { 127, -32 }; /* notice the clamped sample */ - gint8 *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (2); - memcpy (GST_BUFFER_DATA (inbuffer), in, 2); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 2) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint8 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], - res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 2) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_mute_s8) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gint8 in[2] = { 64, -16 }; - gint8 out[2] = { 0, 0 }; - gint8 *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "mute", TRUE, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (2); - memcpy (GST_BUFFER_DATA (inbuffer), in, 2); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 2) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint8 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], - res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 2) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_unity_s16) -{ - GstElement *volume; - GstBuffer *inbuffer, *outbuffer; - GstCaps *caps; - gint16 in[2] = { 16384, -256 }; - gint16 *res; - - volume = setup_volume (); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (inbuffer), in, 4); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint16 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_half_s16) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gint16 in[2] = { 16384, -256 }; - gint16 out[2] = { 8192, -128 }; - gint16 *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (inbuffer), in, 4); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint16 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], - res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_double_s16) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gint16 in[2] = { 16384, -256 }; - gint16 out[2] = { 32767, -512 }; /* notice the clamped sample */ - gint16 *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (inbuffer), in, 4); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint16 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], - res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - - -GST_START_TEST (test_mute_s16) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gint16 in[2] = { 16384, -256 }; - gint16 out[2] = { 0, 0 }; - gint16 *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "mute", TRUE, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (inbuffer), in, 4); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint16 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], - res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -#if (G_BYTE_ORDER == G_LITTLE_ENDIAN) -#define get_unaligned_i24(_x) ( (((guint8*)_x)[0]) | ((((guint8*)_x)[1]) << 8) | ((((gint8*)_x)[2]) << 16) ) -#define write_unaligned_u24(_x,samp) do { (((guint8*)_x)[0]) = samp & 0xFF; (((guint8*)_x)[1]) = (samp >> 8) & 0xFF; (((guint8*)_x)[2]) = (samp >> 16) & 0xFF; } while (0) -#else /* BIG ENDIAN */ -#define get_unaligned_i24(_x) ( (((guint8*)_x)[2]) | ((((guint8*)_x)[1]) << 8) | ((((gint8*)_x)[0]) << 16) ) -#define write_unaligned_u24(_x,samp) do { (((guint8*)_x)[0]) = (samp >> 16) & 0xFF; (((guint8*)_x)[1]) = (samp >> 8) & 0xFF; (((guint8*)_x)[2]) = samp & 0xFF; } while (0) -#endif - -GST_START_TEST (test_unity_s24) -{ - GstElement *volume; - GstBuffer *inbuffer, *outbuffer; - GstCaps *caps; - gint32 in_32[2] = { 4194304, -4096 }; - guint8 in[6]; - guint8 *res; - gint32 res_32[2]; - - - write_unaligned_u24 (in, in_32[0]); - write_unaligned_u24 (in + 3, in_32[1]); - - volume = setup_volume (); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (6); - memcpy (GST_BUFFER_DATA (inbuffer), in, 6); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = GST_BUFFER_DATA (outbuffer); - - res_32[0] = get_unaligned_i24 (res); - res_32[1] = get_unaligned_i24 ((res + 3)); - - GST_INFO ("expected %+5d %+5d real %+5d %+5d", in_32[0], in_32[1], res_32[0], - res_32[1]); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 6) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_half_s24) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gint32 in_32[2] = { 4194304, -4096 }; - guint8 in[6]; - guint8 *res; - gint32 res_32[2]; - gint32 out_32[2] = { 2097152, -2048 }; - - write_unaligned_u24 (in, in_32[0]); - write_unaligned_u24 (in + 3, in_32[1]); - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (6); - memcpy (GST_BUFFER_DATA (inbuffer), in, 6); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 6) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = GST_BUFFER_DATA (outbuffer); - - res_32[0] = get_unaligned_i24 (res); - res_32[1] = get_unaligned_i24 ((res + 3)); - - GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1], - res_32[0], res_32[1]); - fail_unless (memcmp (res_32, out_32, 8) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_double_s24) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gint32 in_32[2] = { 4194304, -4096 }; - guint8 in[6]; - guint8 *res; - gint32 res_32[2]; - gint32 out_32[2] = { 8388607, -8192 }; /* notice the clamped sample */ - - write_unaligned_u24 (in, in_32[0]); - write_unaligned_u24 (in + 3, in_32[1]); - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (6); - memcpy (GST_BUFFER_DATA (inbuffer), in, 6); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 6) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = GST_BUFFER_DATA (outbuffer); - - res_32[0] = get_unaligned_i24 (res); - res_32[1] = get_unaligned_i24 ((res + 3)); - - GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1], - res_32[0], res_32[1]); - fail_unless (memcmp (res_32, out_32, 8) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - - -GST_START_TEST (test_mute_s24) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gint32 in_32[2] = { 4194304, -4096 }; - guint8 in[6]; - guint8 *res; - gint32 res_32[2]; - gint32 out_32[2] = { 0, 0 }; /* notice the clamped sample */ - - write_unaligned_u24 (in, in_32[0]); - write_unaligned_u24 (in + 3, in_32[1]); - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "mute", TRUE, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (6); - memcpy (GST_BUFFER_DATA (inbuffer), in, 6); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 6) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - - res = GST_BUFFER_DATA (outbuffer); - - res_32[0] = get_unaligned_i24 (res); - res_32[1] = get_unaligned_i24 ((res + 3)); - - GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1], - res_32[0], res_32[1]); - fail_unless (memcmp (res_32, out_32, 8) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_unity_s32) -{ - GstElement *volume; - GstBuffer *inbuffer, *outbuffer; - GstCaps *caps; - gint32 in[2] = { 1073741824, -65536 }; - gint32 *res; - - volume = setup_volume (); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (8); - memcpy (GST_BUFFER_DATA (inbuffer), in, 8); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint32 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_half_s32) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gint32 in[2] = { 1073741824, -65536 }; - gint32 out[2] = { 536870912, -32768 }; - gint32 *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (8); - memcpy (GST_BUFFER_DATA (inbuffer), in, 8); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint32 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], - res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_double_s32) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gint32 in[2] = { 1073741824, -65536 }; - gint32 out[2] = { 2147483647, -131072 }; /* notice the clamped sample */ - gint32 *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (8); - memcpy (GST_BUFFER_DATA (inbuffer), in, 8); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint32 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], - res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - - -GST_START_TEST (test_mute_s32) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gint32 in[2] = { 1073741824, -65536 }; - gint32 out[2] = { 0, 0 }; - gint32 *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "mute", TRUE, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (8); - memcpy (GST_BUFFER_DATA (inbuffer), in, 8); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint32 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], - res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_unity_f32) -{ - GstElement *volume; - GstBuffer *inbuffer, *outbuffer; - GstCaps *caps; - gfloat in[2] = { 0.75, -0.25 }; - gfloat *res; - - volume = setup_volume (); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (8); - memcpy (GST_BUFFER_DATA (inbuffer), in, 8); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gfloat *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", in[0], in[1], res[0], - res[1]); - fail_unless_equals_float (res[0], in[0]); - fail_unless_equals_float (res[1], in[1]); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_half_f32) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gfloat in[2] = { 0.75, -0.25 }; - gfloat out[2] = { 0.375, -0.125 }; - gfloat *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (8); - memcpy (GST_BUFFER_DATA (inbuffer), in, 8); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gfloat *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1], - res[0], res[1]); - fail_unless_equals_float (res[0], out[0]); - fail_unless_equals_float (res[1], out[1]); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_double_f32) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gfloat in[2] = { 0.75, -0.25 }; - gfloat out[2] = { 1.5, -0.5 }; /* nothing is clamped */ - gfloat *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (8); - memcpy (GST_BUFFER_DATA (inbuffer), in, 8); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gfloat *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1], - res[0], res[1]); - fail_unless_equals_float (res[0], out[0]); - fail_unless_equals_float (res[1], out[1]); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - - -GST_START_TEST (test_mute_f32) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gfloat in[2] = { 0.75, -0.25 }; - gfloat out[2] = { 0, 0 }; - gfloat *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "mute", TRUE, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (8); - memcpy (GST_BUFFER_DATA (inbuffer), in, 8); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gfloat *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1], - res[0], res[1]); - fail_unless_equals_float (res[0], out[0]); - fail_unless_equals_float (res[1], out[1]); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_unity_f64) -{ - GstElement *volume; - GstBuffer *inbuffer, *outbuffer; - GstCaps *caps; - gdouble in[2] = { 0.75, -0.25 }; - gdouble *res; - - volume = setup_volume (); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (16); - memcpy (GST_BUFFER_DATA (inbuffer), in, 16); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gdouble *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", in[0], in[1], res[0], - res[1]); - fail_unless_equals_float (res[0], in[0]); - fail_unless_equals_float (res[1], in[1]); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_half_f64) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gdouble in[2] = { 0.75, -0.25 }; - gdouble out[2] = { 0.375, -0.125 }; - gdouble *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (16); - memcpy (GST_BUFFER_DATA (inbuffer), in, 16); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 16) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gdouble *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1], - res[0], res[1]); - fail_unless_equals_float (res[0], out[0]); - fail_unless_equals_float (res[1], out[1]); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_double_f64) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gdouble in[2] = { 0.75, -0.25 }; - gdouble out[2] = { 1.5, -0.5 }; /* nothing is clamped */ - gdouble *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (16); - memcpy (GST_BUFFER_DATA (inbuffer), in, 16); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 16) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gdouble *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1], - res[0], res[1]); - fail_unless_equals_float (res[0], out[0]); - fail_unless_equals_float (res[1], out[1]); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - - -GST_START_TEST (test_mute_f64) -{ - GstElement *volume; - GstBuffer *inbuffer; - GstBuffer *outbuffer; - GstCaps *caps; - gdouble in[2] = { 0.75, -0.25 }; - gdouble out[2] = { 0, 0 }; - gdouble *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "mute", TRUE, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (16); - memcpy (GST_BUFFER_DATA (inbuffer), in, 16); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 16) == 0); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - /* FIXME: reffing the inbuffer should make the transformation not be - * inplace - gst_buffer_ref (inbuffer); - */ - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being modified inplace and - * collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gdouble *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1], - res[0], res[1]); - fail_unless_equals_float (res[0], out[0]); - fail_unless_equals_float (res[1], out[1]); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_wrong_caps) -{ - GstElement *volume; - GstBuffer *inbuffer; - gint16 in[2] = { 16384, -256 }; - GstBus *bus; - GstMessage *message; - GstCaps *caps; - - volume = setup_volume (); - bus = gst_bus_new (); - - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (inbuffer), in, 4); - caps = gst_caps_from_string (VOLUME_WRONG_CAPS_STRING); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_ref (inbuffer); - - /* set a bus here so we avoid getting state change messages */ - gst_element_set_bus (volume, bus); - - /* pushing gives an error because it can't negotiate with wrong caps */ - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), - GST_FLOW_NOT_NEGOTIATED); - /* ... and the buffer would have been lost if we didn't ref it ourselves */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_unref (inbuffer); - fail_unless_equals_int (g_list_length (buffers), 0); - - /* volume_set_caps should not have been called since basetransform caught - * the negotiation problem */ - fail_if ((message = gst_bus_pop (bus)) != NULL); - - /* cleanup */ - gst_element_set_bus (volume, NULL); - gst_object_unref (GST_OBJECT (bus)); - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_passthrough) -{ - GstElement *volume; - GstBuffer *inbuffer, *outbuffer; - GstCaps *caps; - gint16 in[2] = { 16384, -256 }; - gint16 *res; - - volume = setup_volume (); - g_object_set (G_OBJECT (volume), "volume", 1.0, NULL); - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (inbuffer), in, 4); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16); - gst_buffer_set_caps (inbuffer, caps); - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint16 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0); - - /* cleanup */ - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_controller_usability) -{ - GstInterpolationControlSource *csource; - GstController *c; - GstElement *volume; - GValue value = { 0, }; - - /* note: the volume element should init the controller library for us */ - volume = setup_volume (); - - c = gst_controller_new (G_OBJECT (volume), "volume", NULL); - - fail_unless (GST_IS_CONTROLLER (c)); - - /* this shouldn't crash, whether this mode is implemented or not */ - csource = gst_interpolation_control_source_new (); - gst_interpolation_control_source_set_interpolation_mode (csource, - GST_INTERPOLATE_CUBIC); - gst_controller_set_control_source (c, "volume", GST_CONTROL_SOURCE (csource)); - g_object_unref (csource); - - g_value_init (&value, G_TYPE_DOUBLE); - g_value_set_double (&value, 0.0); - gst_interpolation_control_source_set (csource, 0 * GST_SECOND, &value); - g_value_set_double (&value, 1.0); - gst_interpolation_control_source_set (csource, 5 * GST_SECOND, &value); - g_value_set_double (&value, 0.0); - gst_interpolation_control_source_set (csource, 10 * GST_SECOND, &value); - g_value_unset (&value); - - g_object_unref (c); - - cleanup_volume (volume); -} - -GST_END_TEST; - -GST_START_TEST (test_controller_processing) -{ - GstInterpolationControlSource *csource; - GstController *c; - GstElement *volume; - GstBuffer *inbuffer, *outbuffer; - GstCaps *caps; - gint16 in[2] = { 16384, -256 }; - gint16 *res; - - volume = setup_volume (); - - c = gst_controller_new (G_OBJECT (volume), "volume", NULL); - - fail_unless (GST_IS_CONTROLLER (c)); - - csource = gst_interpolation_control_source_new (); - gst_interpolation_control_source_set_interpolation_mode (csource, - GST_INTERPOLATE_CUBIC); - gst_controller_set_control_source (c, "volume", GST_CONTROL_SOURCE (csource)); - g_object_unref (csource); - - fail_unless (gst_element_set_state (volume, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (4); - memcpy (GST_BUFFER_DATA (inbuffer), in, 4); - caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16); - gst_buffer_set_caps (inbuffer, caps); - GST_BUFFER_TIMESTAMP (inbuffer) = 0; - gst_caps_unref (caps); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... but it ends up being collected on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - fail_unless_equals_int (g_list_length (buffers), 1); - fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); - fail_unless (inbuffer == outbuffer); - res = (gint16 *) GST_BUFFER_DATA (outbuffer); - GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]); - fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0); - - g_object_unref (c); - - cleanup_volume (volume); -} - -GST_END_TEST; - -static Suite * -volume_suite (void) -{ - Suite *s = suite_create ("volume"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_get_set); - tcase_add_test (tc_chain, test_unity_s8); - tcase_add_test (tc_chain, test_half_s8); - tcase_add_test (tc_chain, test_double_s8); - tcase_add_test (tc_chain, test_mute_s8); - tcase_add_test (tc_chain, test_unity_s16); - tcase_add_test (tc_chain, test_half_s16); - tcase_add_test (tc_chain, test_double_s16); - tcase_add_test (tc_chain, test_mute_s16); - tcase_add_test (tc_chain, test_unity_s24); - tcase_add_test (tc_chain, test_half_s24); - tcase_add_test (tc_chain, test_double_s24); - tcase_add_test (tc_chain, test_mute_s24); - tcase_add_test (tc_chain, test_unity_s32); - tcase_add_test (tc_chain, test_half_s32); - tcase_add_test (tc_chain, test_double_s32); - tcase_add_test (tc_chain, test_mute_s32); - tcase_add_test (tc_chain, test_unity_f32); - tcase_add_test (tc_chain, test_half_f32); - tcase_add_test (tc_chain, test_double_f32); - tcase_add_test (tc_chain, test_mute_f32); - tcase_add_test (tc_chain, test_unity_f64); - tcase_add_test (tc_chain, test_half_f64); - tcase_add_test (tc_chain, test_double_f64); - tcase_add_test (tc_chain, test_mute_f64); - tcase_add_test (tc_chain, test_wrong_caps); - tcase_add_test (tc_chain, test_passthrough); - tcase_add_test (tc_chain, test_controller_usability); - tcase_add_test (tc_chain, test_controller_processing); - - return s; -} - -GST_CHECK_MAIN (volume) diff --git a/tests/check/elements/vorbisdec.c b/tests/check/elements/vorbisdec.c deleted file mode 100644 index 587fd199..00000000 --- a/tests/check/elements/vorbisdec.c +++ /dev/null @@ -1,354 +0,0 @@ -/* GStreamer - * - * unit test for vorbisdec - * - * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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 <unistd.h> - -#include <gst/check/gstcheck.h> - -#include <vorbis/codec.h> -#include <vorbis/vorbisenc.h> - -/* For ease of programming we use globals to keep refs for our floating - * src and sink pads we create; otherwise we always have to do get_pad, - * get_peer, and then remove references in every test function */ -static GstPad *mysrcpad, *mysinkpad; - -/* a valid first header packet */ -static guchar identification_header[30] = { - 1, /* packet_type */ - 'v', 'o', 'r', 'b', 'i', 's', - 0, 0, 0, 0, /* vorbis_version */ - 2, /* audio_channels */ - 0x44, 0xac, 0, 0, /* sample_rate */ - 0xff, 0xff, 0xff, 0xff, /* bitrate_maximum */ - 0x00, 0xee, 0x02, 0x00, /* bitrate_nominal */ - 0xff, 0xff, 0xff, 0xff, /* bitrate_minimum */ - 0xb8, /* blocksize_0, blocksize_1 */ - 0x01, /* framing_flag */ -}; - -static guchar comment_header[] = { - 3, /* packet_type */ - 'v', 'o', 'r', 'b', 'i', 's', - 2, 0, 0, 0, /* vendor_length */ - 'm', 'e', - 1, 0, 0, 0, /* user_comment_list_length */ - 9, 0, 0, 0, /* length comment[0] */ - 'A', 'R', 'T', 'I', 'S', 'T', '=', 'm', 'e', - 0x01, /* framing bit */ -}; - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS_ANY); -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS_ANY); - -static GstElement * -setup_vorbisdec (void) -{ - GstElement *vorbisdec; - - GST_DEBUG ("setup_vorbisdec"); - vorbisdec = gst_check_setup_element ("vorbisdec"); - mysrcpad = gst_check_setup_src_pad (vorbisdec, &srctemplate, NULL); - mysinkpad = gst_check_setup_sink_pad (vorbisdec, &sinktemplate, NULL); - gst_pad_set_active (mysrcpad, TRUE); - gst_pad_set_active (mysinkpad, TRUE); - - return vorbisdec; -} - -static void -cleanup_vorbisdec (GstElement * vorbisdec) -{ - GST_DEBUG ("cleanup_vorbisdec"); - gst_element_set_state (vorbisdec, GST_STATE_NULL); - - gst_pad_set_active (mysrcpad, FALSE); - gst_pad_set_active (mysinkpad, FALSE); - gst_check_teardown_src_pad (vorbisdec); - gst_check_teardown_sink_pad (vorbisdec); - gst_check_teardown_element (vorbisdec); -} - -GST_START_TEST (test_empty_identification_header) -{ - GstElement *vorbisdec; - GstBuffer *inbuffer; - GstBus *bus; - GstMessage *message; - - vorbisdec = setup_vorbisdec (); - bus = gst_bus_new (); - - fail_unless (gst_element_set_state (vorbisdec, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - - inbuffer = gst_buffer_new_and_alloc (0); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - - /* set a bus here so we avoid getting state change messages */ - gst_element_set_bus (vorbisdec, bus); - - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_ERROR); - /* ... but it ends up being collected on the global buffer list */ - fail_unless_equals_int (g_list_length (buffers), 0); - - fail_if ((message = gst_bus_pop (bus)) == NULL); - fail_unless_message_error (message, STREAM, DECODE); - gst_message_unref (message); - gst_element_set_bus (vorbisdec, NULL); - - /* cleanup */ - gst_object_unref (GST_OBJECT (bus)); - cleanup_vorbisdec (vorbisdec); -} - -GST_END_TEST; - -/* FIXME: also tests comment header */ -GST_START_TEST (test_identification_header) -{ - GstElement *vorbisdec; - GstBuffer *inbuffer; - GstBus *bus; - GstMessage *message; - GstTagList *tag_list; - gchar *artist; - - vorbisdec = setup_vorbisdec (); - fail_unless (gst_element_set_state (vorbisdec, - GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, - "could not set to playing"); - bus = gst_bus_new (); - - inbuffer = gst_buffer_new_and_alloc (30); - memcpy (GST_BUFFER_DATA (inbuffer), identification_header, 30); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_ref (inbuffer); - - gst_element_set_bus (vorbisdec, bus); - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... and nothing ends up on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_unref (inbuffer); - fail_unless (g_list_length (buffers) == 0); - fail_if ((message = gst_bus_pop (bus)) != NULL); - - inbuffer = gst_buffer_new_and_alloc (sizeof (comment_header)); - memcpy (GST_BUFFER_DATA (inbuffer), comment_header, sizeof (comment_header)); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_ref (inbuffer); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... and nothing ends up on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_unref (inbuffer); - fail_unless (g_list_length (buffers) == 0); - /* there's a tag message waiting */ - fail_if ((message = gst_bus_pop (bus)) == NULL); - gst_message_parse_tag (message, &tag_list); - fail_unless_equals_int (gst_tag_list_get_tag_size (tag_list, GST_TAG_ARTIST), - 1); - fail_unless (gst_tag_list_get_string (tag_list, GST_TAG_ARTIST, &artist)); - fail_unless_equals_string (artist, "me"); - g_free (artist); - fail_unless_equals_int (gst_tag_list_get_tag_size (tag_list, "album"), 0); - gst_tag_list_free (tag_list); - gst_message_unref (message); - - /* cleanup */ - gst_bus_set_flushing (bus, TRUE); - gst_element_set_bus (vorbisdec, NULL); - gst_object_unref (GST_OBJECT (bus)); - cleanup_vorbisdec (vorbisdec); -} - -GST_END_TEST; - -static vorbis_comment vc; -static vorbis_dsp_state vd; -static vorbis_info vi; -static vorbis_block vb; - -static GstBuffer * -_create_codebook_header_buffer (void) -{ - GstBuffer *buffer; - ogg_packet header; - ogg_packet header_comm; - ogg_packet header_code; - - vorbis_info_init (&vi); - vorbis_encode_setup_vbr (&vi, 1, 44000, 0.5); - vorbis_encode_setup_init (&vi); - vorbis_analysis_init (&vd, &vi); - vorbis_block_init (&vd, &vb); - vorbis_comment_init (&vc); - vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code); - - buffer = gst_buffer_new_and_alloc (header_code.bytes); - memcpy (GST_BUFFER_DATA (buffer), header_code.packet, header_code.bytes); - - return buffer; -} - -static GstBuffer * -_create_audio_buffer (void) -{ - GstBuffer *buffer; - ogg_packet packet; - float **vorbis_buffer; - gint i; - - vorbis_buffer = vorbis_analysis_buffer (&vd, 44100); - for (i = 0; i < 44100 * 1; ++i) - vorbis_buffer[0][i] = 0.0; - vorbis_analysis_wrote (&vd, 44100); - vorbis_analysis_blockout (&vd, &vb); - vorbis_analysis (&vb, NULL); - vorbis_bitrate_addblock (&vb); - vorbis_bitrate_flushpacket (&vd, &packet); - buffer = gst_buffer_new_and_alloc (packet.bytes); - memcpy (GST_BUFFER_DATA (buffer), packet.packet, packet.bytes); - - vorbis_comment_clear (&vc); - vorbis_block_clear (&vb); - vorbis_dsp_clear (&vd); - vorbis_info_clear (&vi); - - return buffer; -} - -GST_START_TEST (test_empty_vorbis_packet) -{ - GstElement *vorbisdec; - GstBuffer *inbuffer; - GstMessage *message; - GstBus *bus; - - vorbisdec = setup_vorbisdec (); - fail_unless_equals_int (gst_element_set_state (vorbisdec, GST_STATE_PLAYING), - GST_STATE_CHANGE_SUCCESS); - - bus = gst_bus_new (); - - inbuffer = gst_buffer_new_and_alloc (30); - memcpy (GST_BUFFER_DATA (inbuffer), identification_header, 30); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_ref (inbuffer); - - gst_element_set_bus (vorbisdec, bus); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... and nothing ends up on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_unref (inbuffer); - fail_unless (g_list_length (buffers) == 0); - fail_if ((message = gst_bus_pop (bus)) != NULL); - - inbuffer = gst_buffer_new_and_alloc (sizeof (comment_header)); - memcpy (GST_BUFFER_DATA (inbuffer), comment_header, sizeof (comment_header)); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_ref (inbuffer); - - /* pushing gives away my reference ... */ - fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); - /* ... and nothing ends up on the global buffer list */ - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_unref (inbuffer); - fail_unless (g_list_length (buffers) == 0); - - /* send minimal codebook header and audio packers */ - inbuffer = _create_codebook_header_buffer (); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - - /* now send an empty vorbis packet, which should just be skipped */ - inbuffer = gst_buffer_new_and_alloc (0); - gst_buffer_ref (inbuffer); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_unref (inbuffer); - fail_unless (g_list_length (buffers) == 0); - - /* create and push an encoded audio packet */ - inbuffer = _create_audio_buffer (); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - - /* now send another empty vorbis packet, which should just be skipped */ - inbuffer = gst_buffer_new_and_alloc (0); - gst_buffer_ref (inbuffer); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); - gst_buffer_unref (inbuffer); - - /* make sure there's no error on the bus */ - message = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0); - fail_if (message != NULL); - - /* cleanup */ - gst_bus_set_flushing (bus, TRUE); - gst_element_set_bus (vorbisdec, NULL); - gst_object_unref (GST_OBJECT (bus)); - cleanup_vorbisdec (vorbisdec); -} - -GST_END_TEST; - -static Suite * -vorbisdec_suite (void) -{ - Suite *s = suite_create ("vorbisdec"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_empty_identification_header); - tcase_add_test (tc_chain, test_identification_header); - tcase_add_test (tc_chain, test_empty_vorbis_packet); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = vorbisdec_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/elements/vorbistag.c b/tests/check/elements/vorbistag.c deleted file mode 100644 index 4b20d6d7..00000000 --- a/tests/check/elements/vorbistag.c +++ /dev/null @@ -1,409 +0,0 @@ -/* GStreamer - * - * unit test for vorbisdec - * - * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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 <unistd.h> -#include <glib.h> - -#include <vorbis/codec.h> -#include <vorbis/vorbisenc.h> - -#include <gst/gsttagsetter.h> -#include <gst/check/gstcheck.h> - -/* a valid first header packet */ -static guchar identification_header[30] = { - 1, /* packet_type */ - 'v', 'o', 'r', 'b', 'i', 's', - 0, 0, 0, 0, /* vorbis_version */ - 2, /* audio_channels */ - 0x44, 0xac, 0, 0, /* sample_rate */ - 0xff, 0xff, 0xff, 0xff, /* bitrate_maximum */ - 0x00, 0xee, 0x02, 0x00, /* bitrate_nominal */ - 0xff, 0xff, 0xff, 0xff, /* bitrate_minimum */ - 0xb8, /* blocksize_0, blocksize_1 */ - 0x01 /* framing_flag */ -}; - -static guchar artist_comment_header[] = { - 3, /* packet_type */ - 'v', 'o', 'r', 'b', 'i', 's', - 2, 0, 0, 0, /* vendor_length */ - 'm', 'e', - 1, 0, 0, 0, /* user_comment_list_length */ - 9, 0, 0, 0, /* length comment[0] */ - 'A', 'R', 'T', 'I', 'S', 'T', '=', 'm', 'e', - 0x01, /* framing bit */ -}; - -static guchar title_comment_header[] = { - 3, /* packet_type */ - 'v', 'o', 'r', 'b', 'i', 's', - 2, 0, 0, 0, /* vendor_length */ - 'm', 'e', - 1, 0, 0, 0, /* user_comment_list_length */ - 12, 0, 0, 0, /* length comment[0] */ - 'T', 'I', 'T', 'L', 'E', '=', 'f', 'o', 'o', 'b', 'a', 'r', - 0x01, /* framing bit */ -}; - -static guchar empty_comment_header[] = { - 3, /* packet_type */ - 'v', 'o', 'r', 'b', 'i', 's', - 2, 0, 0, 0, /* vendor_length */ - 'm', 'e', - 0, 0, 0, 0, /* user_comment_list_length */ - 0x01, /* framing bit */ -}; - - -static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS_ANY); -static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS_ANY); - -static GstPad *mysrcpad, *mysinkpad; -static GAsyncQueue *pending_buffers; -static gulong id; - - -static GstElement * -setup_vorbistag (void) -{ - GstElement *vorbistag; - - GST_DEBUG ("setup_vorbistag"); - vorbistag = gst_check_setup_element ("vorbistag"); - mysrcpad = gst_check_setup_src_pad (vorbistag, &srctemplate, NULL); - mysinkpad = gst_check_setup_sink_pad (vorbistag, &sinktemplate, NULL); - gst_pad_set_active (mysrcpad, TRUE); - gst_pad_set_active (mysinkpad, TRUE); - - return vorbistag; -} - -static void -cleanup_vorbistag (GstElement * vorbistag) -{ - GST_DEBUG ("cleanup_vorbistag"); - gst_element_set_state (vorbistag, GST_STATE_NULL); - - gst_pad_set_active (mysrcpad, FALSE); - gst_pad_set_active (mysinkpad, FALSE); - gst_check_teardown_src_pad (vorbistag); - gst_check_teardown_sink_pad (vorbistag); - gst_check_teardown_element (vorbistag); -} - - -static gboolean -buffer_probe (GstPad * pad, GstBuffer * buffer, gpointer unused) -{ - g_async_queue_push (pending_buffers, gst_buffer_ref (buffer)); - return TRUE; -} - -static void -start_pipeline (GstElement * element) -{ - id = gst_pad_add_buffer_probe (mysinkpad, G_CALLBACK (buffer_probe), NULL); - - pending_buffers = g_async_queue_new (); - gst_element_set_state (element, GST_STATE_PLAYING); -} - -static GstBuffer * -get_buffer (void) -{ - return GST_BUFFER (g_async_queue_pop (pending_buffers)); -} - -static void -stop_pipeline (GstElement * element) -{ - GstBuffer *buf; - - while ((buf = g_async_queue_try_pop (pending_buffers))) - gst_buffer_unref (buf); - - gst_pad_remove_buffer_probe (mysinkpad, (guint) id); - id = 0; - - gst_element_set_state (element, GST_STATE_NULL); - - while ((buf = g_async_queue_try_pop (pending_buffers))) - gst_buffer_unref (buf); - - g_async_queue_unref (pending_buffers); - pending_buffers = NULL; -} - -static vorbis_comment vc; -static vorbis_dsp_state vd; -static vorbis_info vi; -static vorbis_block vb; - -static GstBuffer * -_create_codebook_header_buffer (void) -{ - GstBuffer *buffer; - ogg_packet header; - ogg_packet header_comm; - ogg_packet header_code; - - vorbis_info_init (&vi); - vorbis_encode_setup_vbr (&vi, 1, 44000, 0.5); - vorbis_encode_setup_init (&vi); - vorbis_analysis_init (&vd, &vi); - vorbis_block_init (&vd, &vb); - vorbis_comment_init (&vc); - vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code); - - buffer = gst_buffer_new_and_alloc (header_code.bytes); - memcpy (GST_BUFFER_DATA (buffer), header_code.packet, header_code.bytes); - - return buffer; -} - -static GstBuffer * -_create_audio_buffer (void) -{ - GstBuffer *buffer; - ogg_packet packet; - float **vorbis_buffer; - - vorbis_buffer = vorbis_analysis_buffer (&vd, 0); - vorbis_analysis_wrote (&vd, 0); - vorbis_analysis_blockout (&vd, &vb); - vorbis_analysis (&vb, NULL); - vorbis_bitrate_addblock (&vb); - vorbis_bitrate_flushpacket (&vd, &packet); - buffer = gst_buffer_new_and_alloc (packet.bytes); - memcpy (GST_BUFFER_DATA (buffer), packet.packet, packet.bytes); - - vorbis_comment_clear (&vc); - vorbis_block_clear (&vb); - vorbis_dsp_clear (&vd); - vorbis_info_clear (&vi); - - return buffer; -} - - -GST_START_TEST (test_empty_tags_set) -{ - GstTagList *tags; - GstElement *vorbistag; - GstBuffer *inbuffer, *outbuffer; - - vorbistag = setup_vorbistag (); - - tags = gst_tag_list_new (); - gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_TITLE, "foobar", NULL); - gst_tag_setter_merge_tags (GST_TAG_SETTER (vorbistag), tags, - GST_TAG_MERGE_REPLACE); - gst_tag_setter_set_tag_merge_mode (GST_TAG_SETTER (vorbistag), - GST_TAG_MERGE_KEEP_ALL); - gst_tag_list_free (tags); - - start_pipeline (vorbistag); - - /* send identification header */ - inbuffer = gst_buffer_new_and_alloc (sizeof (identification_header)); - memcpy (GST_BUFFER_DATA (inbuffer), identification_header, - sizeof (identification_header)); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - - /* send empty comment buffer */ - inbuffer = gst_buffer_new_and_alloc (sizeof (empty_comment_header)); - memcpy (GST_BUFFER_DATA (inbuffer), empty_comment_header, - sizeof (empty_comment_header)); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - - /* send minimal codebook header and audio packers */ - inbuffer = _create_codebook_header_buffer (); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - inbuffer = _create_audio_buffer (); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - - - /* check identification header is unchanged */ - outbuffer = get_buffer (); - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), - sizeof (identification_header)); - fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer), - identification_header, sizeof (identification_header)), 0); - gst_buffer_unref (outbuffer); - - /* check comment header is correct */ - outbuffer = get_buffer (); - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), - sizeof (title_comment_header)); - fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer), - title_comment_header, sizeof (title_comment_header)), 0); - gst_buffer_unref (outbuffer); - - stop_pipeline (vorbistag); - cleanup_vorbistag (vorbistag); -} - -GST_END_TEST; - - -GST_START_TEST (test_filled_tags_unset) -{ - GstTagList *tags; - GstElement *vorbistag; - GstBuffer *inbuffer, *outbuffer; - - vorbistag = setup_vorbistag (); - - tags = gst_tag_list_new (); - gst_tag_setter_merge_tags (GST_TAG_SETTER (vorbistag), tags, - GST_TAG_MERGE_REPLACE); - gst_tag_setter_set_tag_merge_mode (GST_TAG_SETTER (vorbistag), - GST_TAG_MERGE_KEEP_ALL); - gst_tag_list_free (tags); - - start_pipeline (vorbistag); - - /* send identification header */ - inbuffer = gst_buffer_new_and_alloc (sizeof (identification_header)); - memcpy (GST_BUFFER_DATA (inbuffer), identification_header, - sizeof (identification_header)); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - - /* send empty comment buffer */ - inbuffer = gst_buffer_new_and_alloc (sizeof (title_comment_header)); - memcpy (GST_BUFFER_DATA (inbuffer), title_comment_header, - sizeof (title_comment_header)); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - - /* send minimal codebook header and audio packers */ - inbuffer = _create_codebook_header_buffer (); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - inbuffer = _create_audio_buffer (); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - - - /* check identification header is unchanged */ - outbuffer = get_buffer (); - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), - sizeof (identification_header)); - fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer), - identification_header, sizeof (identification_header)), 0); - gst_buffer_unref (outbuffer); - - /* check comment header is correct */ - outbuffer = get_buffer (); - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), - sizeof (empty_comment_header)); - fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer), - empty_comment_header, sizeof (empty_comment_header)), 0); - gst_buffer_unref (outbuffer); - - stop_pipeline (vorbistag); - cleanup_vorbistag (vorbistag); -} - -GST_END_TEST; - - -GST_START_TEST (test_filled_tags_change) -{ - GstTagList *tags; - GstElement *vorbistag; - GstBuffer *inbuffer, *outbuffer; - - vorbistag = setup_vorbistag (); - - tags = gst_tag_list_new (); - gst_tag_list_add (tags, GST_TAG_MERGE_REPLACE, GST_TAG_TITLE, "foobar", NULL); - gst_tag_setter_merge_tags (GST_TAG_SETTER (vorbistag), tags, - GST_TAG_MERGE_REPLACE); - gst_tag_setter_set_tag_merge_mode (GST_TAG_SETTER (vorbistag), - GST_TAG_MERGE_KEEP_ALL); - gst_tag_list_free (tags); - - start_pipeline (vorbistag); - - /* send identification header */ - inbuffer = gst_buffer_new_and_alloc (sizeof (identification_header)); - memcpy (GST_BUFFER_DATA (inbuffer), identification_header, - sizeof (identification_header)); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - - /* send empty comment buffer */ - inbuffer = gst_buffer_new_and_alloc (sizeof (artist_comment_header)); - memcpy (GST_BUFFER_DATA (inbuffer), artist_comment_header, - sizeof (artist_comment_header)); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - - /* send minimal codebook header and audio packers */ - inbuffer = _create_codebook_header_buffer (); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - inbuffer = _create_audio_buffer (); - fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); - - - /* check identification header is unchanged */ - outbuffer = get_buffer (); - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), - sizeof (identification_header)); - fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer), - identification_header, sizeof (identification_header)), 0); - gst_buffer_unref (outbuffer); - - /* check comment header is correct */ - outbuffer = get_buffer (); - fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), - sizeof (title_comment_header)); - fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer), - title_comment_header, sizeof (title_comment_header)), 0); - gst_buffer_unref (outbuffer); - - stop_pipeline (vorbistag); - cleanup_vorbistag (vorbistag); -} - -GST_END_TEST; - - - -static Suite * -vorbistag_suite (void) -{ - Suite *s = suite_create ("vorbistag"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_empty_tags_set); - tcase_add_test (tc_chain, test_filled_tags_unset); - tcase_add_test (tc_chain, test_filled_tags_change); - - return s; -} - -GST_CHECK_MAIN (vorbistag) diff --git a/tests/check/generic/.gitignore b/tests/check/generic/.gitignore deleted file mode 100644 index 0d69de1f..00000000 --- a/tests/check/generic/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -.dirstamp -clock-selection -states diff --git a/tests/check/generic/clock-selection.c b/tests/check/generic/clock-selection.c deleted file mode 100644 index 8e332f81..00000000 --- a/tests/check/generic/clock-selection.c +++ /dev/null @@ -1,72 +0,0 @@ -/* GStreamer - * - * unit test for clock selection - * - * Copyright (C) <2005> Wim Taymans <wim at fluendo dot 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <unistd.h> - -#include <gst/check/gstcheck.h> - -GST_START_TEST (test_add) -{ - GstElement *pipeline; - GstStateChangeReturn ret; - - pipeline = gst_pipeline_new ("pipeline"); - fail_unless (pipeline != NULL, "could not create pipeline"); - - ret = gst_element_set_state (pipeline, GST_STATE_READY); - fail_unless (ret == GST_STATE_CHANGE_SUCCESS, "could not set to READY"); - - /* cleanup */ - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); -} - -GST_END_TEST; - -static Suite * -volume_suite (void) -{ - Suite *s = suite_create ("clocks"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_add); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = volume_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/generic/states.c b/tests/check/generic/states.c deleted file mode 100644 index c6ebd6b1..00000000 --- a/tests/check/generic/states.c +++ /dev/null @@ -1,222 +0,0 @@ -/* GStreamer - * - * unit test for state changes on all elements - * - * Copyright (C) <2005> Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <unistd.h> - -#include <gst/check/gstcheck.h> - -static GList *elements = NULL; - -static void -setup (void) -{ - GList *features, *f; - GList *plugins, *p; - gchar **ignorelist = NULL; - const gchar *STATE_IGNORE_ELEMENTS = NULL; - - GST_DEBUG ("getting elements for package %s", PACKAGE); - STATE_IGNORE_ELEMENTS = g_getenv ("STATE_IGNORE_ELEMENTS"); - if (STATE_IGNORE_ELEMENTS) { - GST_DEBUG ("Will ignore element factories: '%s'", STATE_IGNORE_ELEMENTS); - ignorelist = g_strsplit (STATE_IGNORE_ELEMENTS, " ", 0); - } - - plugins = gst_registry_get_plugin_list (gst_registry_get_default ()); - - for (p = plugins; p; p = p->next) { - GstPlugin *plugin = p->data; - - if (strcmp (gst_plugin_get_source (plugin), PACKAGE) != 0) - continue; - - features = - gst_registry_get_feature_list_by_plugin (gst_registry_get_default (), - gst_plugin_get_name (plugin)); - - for (f = features; f; f = f->next) { - GstPluginFeature *feature = f->data; - const gchar *name = gst_plugin_feature_get_name (feature); - gboolean ignore = FALSE; - - if (!GST_IS_ELEMENT_FACTORY (feature)) - continue; - - if (ignorelist) { - gchar **s; - - for (s = ignorelist; s && *s; ++s) { - if (g_str_has_prefix (name, *s)) { - GST_DEBUG ("ignoring element %s", name); - ignore = TRUE; - } - } - if (ignore) - continue; - } - - GST_DEBUG ("adding element %s", name); - elements = g_list_prepend (elements, (gpointer) g_strdup (name)); - } - gst_plugin_feature_list_free (features); - } - gst_plugin_list_free (plugins); - g_strfreev (ignorelist); -} - -static void -teardown (void) -{ - GList *e; - - for (e = elements; e; e = e->next) { - g_free (e->data); - } - g_list_free (elements); - elements = NULL; -} - - -GST_START_TEST (test_state_changes_up_and_down_seq) -{ - GstElement *element; - GList *e; - - for (e = elements; e; e = e->next) { - const gchar *name = e->data; - - GST_DEBUG ("testing element %s", name); - element = gst_element_factory_make (name, name); - fail_if (element == NULL, "Could not make element from factory %s", name); - - if (GST_IS_PIPELINE (element)) { - GST_DEBUG ("element %s is a pipeline", name); - } - - gst_element_set_state (element, GST_STATE_READY); - gst_element_set_state (element, GST_STATE_PAUSED); - gst_element_set_state (element, GST_STATE_PLAYING); - gst_element_set_state (element, GST_STATE_PAUSED); - gst_element_set_state (element, GST_STATE_READY); - gst_element_set_state (element, GST_STATE_NULL); - gst_element_set_state (element, GST_STATE_PAUSED); - gst_element_set_state (element, GST_STATE_READY); - gst_element_set_state (element, GST_STATE_PLAYING); - gst_element_set_state (element, GST_STATE_PAUSED); - gst_element_set_state (element, GST_STATE_NULL); - gst_object_unref (GST_OBJECT (element)); - } -} - -GST_END_TEST; - -GST_START_TEST (test_state_changes_up_seq) -{ - GstElement *element; - GList *e; - - for (e = elements; e; e = e->next) { - const gchar *name = e->data; - - GST_DEBUG ("testing element %s", name); - element = gst_element_factory_make (name, name); - fail_if (element == NULL, "Could not make element from factory %s", name); - - if (GST_IS_PIPELINE (element)) { - GST_DEBUG ("element %s is a pipeline", name); - } - - gst_element_set_state (element, GST_STATE_READY); - - gst_element_set_state (element, GST_STATE_PAUSED); - gst_element_set_state (element, GST_STATE_READY); - - gst_element_set_state (element, GST_STATE_PAUSED); - gst_element_set_state (element, GST_STATE_PLAYING); - gst_element_set_state (element, GST_STATE_PAUSED); - gst_element_set_state (element, GST_STATE_READY); - - gst_element_set_state (element, GST_STATE_NULL); - gst_object_unref (GST_OBJECT (element)); - } -} - -GST_END_TEST; - -GST_START_TEST (test_state_changes_down_seq) -{ - GstElement *element; - GList *e; - - for (e = elements; e; e = e->next) { - const gchar *name = e->data; - - GST_DEBUG ("testing element %s", name); - element = gst_element_factory_make (name, name); - fail_if (element == NULL, "Could not make element from factory %s", name); - - if (GST_IS_PIPELINE (element)) { - GST_DEBUG ("element %s is a pipeline", name); - } - - gst_element_set_state (element, GST_STATE_READY); - gst_element_set_state (element, GST_STATE_PAUSED); - gst_element_set_state (element, GST_STATE_PLAYING); - - gst_element_set_state (element, GST_STATE_PAUSED); - gst_element_set_state (element, GST_STATE_PLAYING); - - gst_element_set_state (element, GST_STATE_PAUSED); - gst_element_set_state (element, GST_STATE_READY); - gst_element_set_state (element, GST_STATE_PAUSED); - gst_element_set_state (element, GST_STATE_PLAYING); - - gst_element_set_state (element, GST_STATE_PAUSED); - gst_element_set_state (element, GST_STATE_READY); - gst_element_set_state (element, GST_STATE_NULL); - gst_object_unref (GST_OBJECT (element)); - } -} - -GST_END_TEST; - - -static Suite * -states_suite (void) -{ - Suite *s = suite_create ("states"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_checked_fixture (tc_chain, setup, teardown); - tcase_add_test (tc_chain, test_state_changes_up_and_down_seq); - tcase_add_test (tc_chain, test_state_changes_up_seq); - tcase_add_test (tc_chain, test_state_changes_down_seq); - - return s; -} - -GST_CHECK_MAIN (states); diff --git a/tests/check/gst-plugins-base.supp b/tests/check/gst-plugins-base.supp deleted file mode 100644 index 113b3f2e..00000000 --- a/tests/check/gst-plugins-base.supp +++ /dev/null @@ -1,397 +0,0 @@ -# A suppression for an old bug in libtheora (fixed in more recent versions, -# but some of our buildslaves still have this) -{ - <Leaky libtheora> - Memcheck:Leak - fun:realloc - fun:oggpackB_write - fun:EncodeData - obj:/usr/lib/libtheora.so* - fun:theora_encode_YUVin -} - -# Suppression for pango on ubuntu edgy/x86 and textoverlay test -{ - <pango> - Memcheck:Param - access(pathname) - fun:access - fun:pango_config_key_get - fun:pango_find_map -} - -{ - <suppression for a singleton in GIO that can't be cleaned up> - Memcheck:Leak - fun:realloc - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - fun:g_type_create_instance - fun:g_object_constructor - fun:g_object_newv - fun:g_object_new_valist - fun:g_object_new - fun:get_default_vfs - fun:g_once_impl - fun:g_vfs_get_default -} - -{ - <suppression for a singleton in GIO that can't be cleaned up> - Memcheck:Leak - fun:malloc - obj:* - obj:* - obj:* - obj:* - fun:g_type_create_instance - fun:g_object_constructor - fun:g_object_newv - fun:g_object_new_valist - fun:g_object_new - fun:get_default_vfs - fun:g_once_impl - fun:g_vfs_get_default -} - -{ - <ALSA unitialised access> - Memcheck:Cond - obj:/usr/lib/libasound.so.* - fun:snd_pcm_hw_params_set_buffer_time_near -} - -{ - <ALSA unitialized access> - Memcheck:Cond - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - fun:snd_pcm_hw_params_set_buffer_time_near -} - -{ - <One time init in ALSA> - Memcheck:Leak - fun:malloc - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - fun:gst_alsa_device_property_probe_get_values -} - -{ - <One time init in ALSA> - Memcheck:Leak - fun:calloc - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - fun:snd_config_hook_load - obj:* - obj:/usr/lib/libasound.so.* - fun:snd_config_searcha_hooks - fun:snd_config_searchva_hooks - obj:/usr/lib/libasound.so.* - fun:snd_config_search_definition - obj:/usr/lib/libasound.so.* - fun:gst_alsa_device_property_probe_get_values -} - -{ - <One time init in ALSA> - Memcheck:Leak - fun:calloc - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:/usr/lib/libasound.so.* - fun:snd_config_searcha_hooks - fun:snd_config_searchva_hooks - obj:/usr/lib/libasound.so.* - fun:snd_config_search_definition - obj:/usr/lib/libasound.so.* - fun:gst_alsa_device_property_probe_get_values -} - -{ - <One time init in ALSA> - Memcheck:Leak - fun:calloc - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:/usr/lib/libasound.so.* - fun:snd_config_searcha_hooks - fun:snd_config_searchva_hooks - obj:/usr/lib/libasound.so.* - fun:snd_config_search_definition - obj:/usr/lib/libasound.so.* - fun:gst_alsa_device_property_probe_get_values -} - -{ - <One time init in ALSA> - Memcheck:Leak - fun:calloc - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:* - obj:/usr/lib/libasound.so.* - fun:snd_config_searcha_hooks - fun:snd_config_searchva_hooks - obj:/usr/lib/libasound.so.* - fun:snd_config_search_definition - obj:/usr/lib/libasound.so.* - fun:gst_alsa_device_property_probe_get_values -} - -{ - <One time init in ALSA> - Memcheck:Leak - fun:malloc - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - fun:snd_hctl_open - fun:snd_mixer_attach -} - -{ - <Pulseaudio ALSA plugin initialisation> - Memcheck:Leak - fun:calloc - fun:pa_xmalloc0 - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - fun:pa_proplist_sets - fun:pa_context_new_with_proplist - fun:pa_context_new - obj:/usr/lib/alsa-lib/libasound_module_pcm_pulse.so -} - -{ - <Pulseaudio ALSA plugin initialisation> - Memcheck:Leak - fun:calloc - fun:pa_xmalloc0 - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - fun:pa_mainloop_dispatch - obj:/usr/lib/alsa-lib/libasound_module_pcm_pulse.so -} - -{ - <Pulseaudio ALSA plugin initialisation> - Memcheck:Leak - fun:calloc - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - fun:snd_config_hook_load - obj:/usr/lib/alsa-lib/libasound_module_ctl_pulse.so -} - -{ - <Pulseaudio ALSA plugin initialisation> - Memcheck:Leak - fun:calloc - fun:pa_xmalloc0 - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - fun:pa_proplist_sets - fun:pa_context_new_with_proplist - fun:pa_context_new - obj:/usr/lib/alsa-lib/libasound_module_ctl_pulse.so -} - -{ - <Pulseaudio ALSA plugin initialisation> - Memcheck:Leak - fun:calloc - fun:pa_xmalloc0 - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - fun:pa_mainloop_dispatch - obj:/usr/lib/alsa-lib/libasound_module_ctl_pulse.so -} - -{ - <Pulseaudio ALSA plugin initialisation> - Memcheck:Leak - fun:calloc - fun:pa_xmalloc0 - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - fun:pa_mainloop_dispatch - obj:/usr/lib/alsa-lib/libasound_module_ctl_pulse.so -} - -{ - <Pulseaudio ALSA plugin initialisation> - Memcheck:Leak - fun:calloc - fun:pa_xmalloc0 - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - fun:pa_mainloop_dispatch - obj:/usr/lib/alsa-lib/libasound_module_ctl_pulse.so -} - -{ - <Pulseaudio ALSA plugin initialisation> - Memcheck:Leak - fun:calloc - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - fun:snd_config_hook_load - obj:/usr/lib/alsa-lib/libasound_module_pcm_pulse.so -} - -{ - <Pulseaudio ALSA plugin initialisation> - Memcheck:Leak - fun:calloc - fun:pa_xmalloc0 - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - fun:pa_mainloop_dispatch - obj:/usr/lib/alsa-lib/libasound_module_pcm_pulse.so -} - -{ - <Pulseaudio ALSA plugin initialisation> - Memcheck:Leak - fun:calloc - fun:pa_xmalloc0 - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - obj:/usr/lib/libpulse.so.* - fun:pa_mainloop_dispatch - obj:/usr/lib/alsa-lib/libasound_module_pcm_pulse.so -} - -{ - <One time ALSA init> - Memcheck:Leak - fun:malloc - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - obj:/usr/lib/libasound.so.* - fun:gst_alsasrc_open -} - -{ - <Fontconfig init> - Memcheck:Leak - fun:malloc - obj:/usr/lib/libfontconfig.so.* - obj:/usr/lib/libfontconfig.so.* - obj:/usr/lib/libfontconfig.so.* - obj:/usr/lib/libfontconfig.so.* - obj:/usr/lib/libexpat.so.* - obj:/usr/lib/libexpat.so.* - obj:/usr/lib/libexpat.so.* - obj:/usr/lib/libexpat.so.* - fun:XML_ParseBuffer - fun:FcConfigParseAndLoad -} - -{ - <Fontconfig init> - Memcheck:Leak - fun:realloc - obj:/usr/lib/libfontconfig.so.* - obj:/usr/lib/libfontconfig.so.* - obj:/usr/lib/libfontconfig.so.* - obj:/usr/lib/libfontconfig.so.* - fun:FcDefaultSubstitute -} - -{ - <Fontconfig init> - Memcheck:Leak - fun:realloc - obj:/usr/lib/libfontconfig.so.* - obj:/usr/lib/libfontconfig.so.* - fun:FcConfigSubstituteWithPat -} - -{ - <Fontconfig init> - Memcheck:Leak - fun:realloc - obj:/usr/lib/libfontconfig.so.* - obj:/usr/lib/libfontconfig.so.* - obj:/usr/lib/libfontconfig.so.* - fun:FcFontRenderPrepare -} diff --git a/tests/check/gst/.gitignore b/tests/check/gst/.gitignore deleted file mode 100644 index b4690418..00000000 --- a/tests/check/gst/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -typefindfunctions -.dirstamp diff --git a/tests/check/gst/typefindfunctions.c b/tests/check/gst/typefindfunctions.c deleted file mode 100644 index 08d3f1bc..00000000 --- a/tests/check/gst/typefindfunctions.c +++ /dev/null @@ -1,125 +0,0 @@ -/* GStreamer unit tests for the -base typefind functions - * - * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <gst/check/gstcheck.h> -#include <gst/base/gsttypefindhelper.h> - -GST_START_TEST (test_quicktime_mpeg4video) -{ - /* quicktime redirect file which starts with what could also be interpreted - * as an MPEG-4 video object layer start code */ - const guint8 qt_redirect_396042[] = - { 0x00, 0x00, 0x01, 0x22, 0x6d, 0x6f, 0x6f, 0x76, 0x00, 0x00, 0x01, 0x1a, - 0x72, 0x6d, 0x72, 0x61, 0x00, 0x00, 0x00, 0x86, 0x72, 0x6d, 0x64, 0x61, - 0x00, 0x00, 0x00, 0x54, 0x72, 0x64, 0x72, 0x66, 0x00, 0x00, 0x00, 0x00, - 0x75, 0x72, 0x6c, 0x20, 0x00, 0x00, 0x00, 0x40, 0x68, 0x74, 0x74, 0x70, - 0x3a, 0x2f, 0x2f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, 0x71, 0x74, - 0x76, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, - 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x6a, 0x61, 0x6e, 0x2f, 0x6a, - 0x34, 0x37, 0x64, 0x35, 0x32, 0x6f, 0x6f, 0x2f, 0x71, 0x74, 0x37, 0x72, - 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x2e, 0x6d, 0x6f, 0x76, 0x00, - 0x00, 0x00, 0x00, 0x10, 0x72, 0x6d, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x0a, 0xf0, 0x00, 0x00, 0x00, 0x1a, 0x72, 0x6d, 0x76, 0x63, - 0x00, 0x00, 0x00, 0x00, 0x71, 0x74, 0x69, 0x6d, 0x06, 0x50, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8c, 0x72, 0x6d, - 0x64, 0x61, 0x00, 0x00, 0x00, 0x5a, 0x72, 0x64, 0x72, 0x66, 0x00, 0x00, - 0x00, 0x00, 0x75, 0x72, 0x6c, 0x20, 0x00, 0x00, 0x00, 0x46, 0x68, 0x74, - 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6d, 0x2e, - 0x71, 0x74, 0x76, 0x2e, 0x61, 0x70, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, - 0x6d, 0x2f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x2f, 0x6a, 0x61, 0x6e, - 0x2f, 0x6a, 0x34, 0x37, 0x64, 0x35, 0x32, 0x6f, 0x6f, 0x2f, 0x38, 0x38, - 0x34, 0x38, 0x31, 0x32, 0x35, 0x5f, 0x32, 0x5f, 0x33, 0x35, 0x30, 0x5f, - 0x72, 0x65, 0x66, 0x2e, 0x6d, 0x6f, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10, - 0x72, 0x6d, 0x64, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, 0xf0, - 0x00, 0x00, 0x00, 0x1a, 0x72, 0x6d, 0x76, 0x63, 0x00, 0x00, 0x00, 0x00, - 0x71, 0x74, 0x69, 0x6d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00 - }; - GstTypeFindProbability prob; - const gchar *type; - GstBuffer *buf; - GstCaps *caps = NULL; - - buf = gst_buffer_new (); - GST_BUFFER_DATA (buf) = (guint8 *) qt_redirect_396042; - GST_BUFFER_SIZE (buf) = sizeof (qt_redirect_396042); - GST_BUFFER_OFFSET (buf) = 0; - - caps = gst_type_find_helper_for_buffer (NULL, buf, &prob); - fail_unless (caps != NULL); - GST_LOG ("Found type: %" GST_PTR_FORMAT, caps); - - type = gst_structure_get_name (gst_caps_get_structure (caps, 0)); - fail_unless_equals_string (type, "video/quicktime"); - fail_unless (prob > GST_TYPE_FIND_MINIMUM && prob <= GST_TYPE_FIND_MAXIMUM); - - gst_buffer_unref (buf); - gst_caps_unref (caps); -} - -GST_END_TEST; - -GST_START_TEST (test_broken_flac_in_ogg) -{ - const guint8 flac_id_packet[4] = { 'f', 'L', 'a', 'C' }; - GstTypeFindProbability prob; - const gchar *type; - GstBuffer *buf; - GstCaps *caps = NULL; - - buf = gst_buffer_new (); - GST_BUFFER_DATA (buf) = (guint8 *) flac_id_packet; - GST_BUFFER_SIZE (buf) = sizeof (flac_id_packet); - GST_BUFFER_OFFSET (buf) = 0; - - caps = gst_type_find_helper_for_buffer (NULL, buf, &prob); - fail_unless (caps != NULL); - GST_LOG ("Found type: %" GST_PTR_FORMAT, caps); - - type = gst_structure_get_name (gst_caps_get_structure (caps, 0)); - fail_unless_equals_string (type, "audio/x-flac"); - fail_unless (prob > GST_TYPE_FIND_MINIMUM && prob <= GST_TYPE_FIND_MAXIMUM); - - gst_buffer_unref (buf); - gst_caps_unref (caps); - -} - -GST_END_TEST; - -static Suite * -typefindfunctions_suite (void) -{ - Suite *s = suite_create ("typefindfunctions"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - - tcase_add_test (tc_chain, test_quicktime_mpeg4video); - tcase_add_test (tc_chain, test_broken_flac_in_ogg); - - return s; -} - -GST_CHECK_MAIN (typefindfunctions); diff --git a/tests/check/libs/.gitignore b/tests/check/libs/.gitignore deleted file mode 100644 index cd372588..00000000 --- a/tests/check/libs/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -.dirstamp -audio -cddabasesrc -fft -mixer -navigation -netbuffer -pbutils -rtp -tag -utils -video - diff --git a/tests/check/libs/audio.c b/tests/check/libs/audio.c deleted file mode 100644 index f5fab570..00000000 --- a/tests/check/libs/audio.c +++ /dev/null @@ -1,559 +0,0 @@ -/* GStreamer - * - * unit tests for audio support library - * - * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/check/gstcheck.h> - -#include <gst/audio/audio.h> -#include <gst/audio/multichannel.h> -#include <string.h> - -static gboolean -structure_contains_channel_positions (const GstStructure * s) -{ - return (gst_structure_get_value (s, "channel-positions") != NULL); -} - -#if 0 -static gboolean -fixed_caps_have_channel_positions (const GstCaps * caps) -{ - GstStructure *s; - - fail_unless (caps != NULL); - - s = gst_caps_get_structure (caps, 0); - fail_unless (s != NULL); - - return structure_contains_channel_positions (s); -} -#endif - -GST_START_TEST (test_multichannel_checks) -{ - GstAudioChannelPosition pos_2_mixed[2] = { - GST_AUDIO_CHANNEL_POSITION_FRONT_MONO, - GST_AUDIO_CHANNEL_POSITION_NONE - }; - GstAudioChannelPosition pos_2_none[2] = { - GST_AUDIO_CHANNEL_POSITION_NONE, - GST_AUDIO_CHANNEL_POSITION_NONE - }; - GstAudioChannelPosition pos_2_flr[2] = { - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT - }; - GstAudioChannelPosition pos_2_frr[2] = { - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT - }; - GstStructure *s; - - s = gst_structure_new ("audio/x-raw-int", "channels", G_TYPE_INT, 2, NULL); - - /* check if the audio channel position checks work */ - fail_if (gst_audio_check_channel_positions (pos_2_mixed, 2)); - fail_unless (gst_audio_check_channel_positions (pos_2_none, 2)); - fail_unless (gst_audio_check_channel_positions (pos_2_flr, 2)); - fail_if (gst_audio_check_channel_positions (pos_2_frr, 2)); - - /* this should not work and issue a warning: FRONT_MONO + NONE */ - _gst_check_expecting_log = TRUE; - gst_audio_set_channel_positions (s, pos_2_mixed); - _gst_check_expecting_log = FALSE; - fail_if (structure_contains_channel_positions (s)); - - /* this should work: NONE + NONE */ - gst_audio_set_channel_positions (s, pos_2_none); - fail_unless (structure_contains_channel_positions (s)); - gst_structure_remove_field (s, "channel-positions"); - - /* this should also work: FRONT_LEFT + FRONT_RIGHT */ - gst_audio_set_channel_positions (s, pos_2_flr); - fail_unless (structure_contains_channel_positions (s)); - gst_structure_remove_field (s, "channel-positions"); - - /* this should not work and issue a warning: FRONT_RIGHT twice */ - _gst_check_expecting_log = TRUE; - gst_audio_set_channel_positions (s, pos_2_frr); - _gst_check_expecting_log = FALSE; - -/* FIXME: did I misunderstand _set_structure_channel_positions_list? */ -#if 0 - /* this should not work and issue a warning: FRONT_RIGHT twice */ - _gst_check_expecting_log = TRUE; - gst_audio_set_structure_channel_positions_list (s, pos_2_frr, 2); - _gst_check_expecting_log = FALSE; - - /* this should not work and issue a warning: FRONT_MONO + NONE */ - _gst_check_expecting_log = TRUE; - gst_audio_set_structure_channel_positions_list (s, pos_2_mixed, 2); - _gst_check_expecting_log = FALSE; - - /* this should not work either (channel count mismatch) */ - _gst_check_expecting_log = TRUE; - gst_audio_set_structure_channel_positions_list (s, pos_2_none, 44); - _gst_check_expecting_log = FALSE; - fail_if (structure_contains_channel_positions (s)); -#endif - - gst_structure_free (s); -} - -GST_END_TEST; - -GST_START_TEST (test_buffer_clipping_time) -{ - GstSegment s; - - GstBuffer *buf; - - GstBuffer *ret; - - guint8 *data; - - /* Clip start and end */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_TIME); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 4 * GST_SECOND, - 8 * GST_SECOND, 4 * GST_SECOND); - - GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND; - GST_BUFFER_DURATION (buf) = 10 * GST_SECOND; - GST_BUFFER_OFFSET (buf) = 200; - GST_BUFFER_OFFSET_END (buf) = 1200; - - ret = gst_audio_buffer_clip (buf, &s, 100, 1); - fail_unless (ret != NULL); - - fail_unless (GST_BUFFER_TIMESTAMP (ret) == 4 * GST_SECOND); - fail_unless (GST_BUFFER_DURATION (ret) == 4 * GST_SECOND); - fail_unless (GST_BUFFER_OFFSET (ret) == 400); - fail_unless (GST_BUFFER_OFFSET_END (ret) == 800); - fail_unless (GST_BUFFER_DATA (ret) == data + 200); - fail_unless (GST_BUFFER_SIZE (ret) == 400); - - gst_buffer_unref (ret); - - /* Clip only start */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_TIME); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 4 * GST_SECOND, - 12 * GST_SECOND, 4 * GST_SECOND); - - GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND; - GST_BUFFER_DURATION (buf) = 10 * GST_SECOND; - GST_BUFFER_OFFSET (buf) = 200; - GST_BUFFER_OFFSET_END (buf) = 1200; - - ret = gst_audio_buffer_clip (buf, &s, 100, 1); - fail_unless (ret != NULL); - - fail_unless (GST_BUFFER_TIMESTAMP (ret) == 4 * GST_SECOND); - fail_unless (GST_BUFFER_DURATION (ret) == 8 * GST_SECOND); - fail_unless (GST_BUFFER_OFFSET (ret) == 400); - fail_unless (GST_BUFFER_OFFSET_END (ret) == 1200); - fail_unless (GST_BUFFER_DATA (ret) == data + 200); - fail_unless (GST_BUFFER_SIZE (ret) == 800); - - gst_buffer_unref (ret); - - /* Clip only stop */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_TIME); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 2 * GST_SECOND, - 10 * GST_SECOND, 2 * GST_SECOND); - - GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND; - GST_BUFFER_DURATION (buf) = 10 * GST_SECOND; - GST_BUFFER_OFFSET (buf) = 200; - GST_BUFFER_OFFSET_END (buf) = 1200; - - ret = gst_audio_buffer_clip (buf, &s, 100, 1); - fail_unless (ret != NULL); - - fail_unless (GST_BUFFER_TIMESTAMP (ret) == 2 * GST_SECOND); - fail_unless (GST_BUFFER_DURATION (ret) == 8 * GST_SECOND); - fail_unless (GST_BUFFER_OFFSET (ret) == 200); - fail_unless (GST_BUFFER_OFFSET_END (ret) == 1000); - fail_unless (GST_BUFFER_DATA (ret) == data); - fail_unless (GST_BUFFER_SIZE (ret) == 800); - - gst_buffer_unref (ret); - - /* Buffer outside segment */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_TIME); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 12 * GST_SECOND, - 20 * GST_SECOND, 12 * GST_SECOND); - - GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND; - GST_BUFFER_DURATION (buf) = 10 * GST_SECOND; - GST_BUFFER_OFFSET (buf) = 200; - GST_BUFFER_OFFSET_END (buf) = 1200; - - ret = gst_audio_buffer_clip (buf, &s, 100, 1); - fail_unless (ret == NULL); - - /* Clip start and end but don't touch duration and offset_end */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_TIME); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 4 * GST_SECOND, - 8 * GST_SECOND, 4 * GST_SECOND); - - GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND; - GST_BUFFER_DURATION (buf) = GST_CLOCK_TIME_NONE; - GST_BUFFER_OFFSET (buf) = 200; - GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_NONE; - - ret = gst_audio_buffer_clip (buf, &s, 100, 1); - fail_unless (ret != NULL); - - fail_unless (GST_BUFFER_TIMESTAMP (ret) == 4 * GST_SECOND); - fail_unless (GST_BUFFER_DURATION (ret) == GST_CLOCK_TIME_NONE); - fail_unless (GST_BUFFER_OFFSET (ret) == 400); - fail_unless (GST_BUFFER_OFFSET_END (ret) == GST_BUFFER_OFFSET_NONE); - fail_unless (GST_BUFFER_DATA (ret) == data + 200); - fail_unless (GST_BUFFER_SIZE (ret) == 400); - - gst_buffer_unref (ret); - - /* If the buffer has no timestamp it should assert() - * FIXME: check if return value is the same as the input buffer. - * probably can't be done because the assert() does a SIGABRT. - */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_TIME); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 0 * GST_SECOND, - 10 * GST_SECOND, 0 * GST_SECOND); - - GST_BUFFER_TIMESTAMP (buf) = GST_CLOCK_TIME_NONE; - GST_BUFFER_DURATION (buf) = GST_CLOCK_TIME_NONE; - GST_BUFFER_OFFSET (buf) = GST_BUFFER_OFFSET_NONE; - GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_NONE; - - ret = gst_audio_buffer_clip (buf, &s, 100, 1); - fail_unless (ret == buf); - - gst_buffer_unref (buf); - - /* If the format is not TIME or DEFAULT it should assert() - * FIXME: check if return value is the same as the input buffer. - * probably can't be done because the assert() does a SIGABRT. - */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_PERCENT); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_PERCENT, 0, 10, 0); - - GST_BUFFER_TIMESTAMP (buf) = 0 * GST_SECOND; - GST_BUFFER_DURATION (buf) = 0; - GST_BUFFER_OFFSET (buf) = GST_BUFFER_OFFSET_NONE; - GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_NONE; - - ASSERT_CRITICAL (ret = gst_audio_buffer_clip (buf, &s, 100, 1)); - - gst_buffer_unref (buf); - -} - -GST_END_TEST; - -GST_START_TEST (test_buffer_clipping_samples) -{ - GstSegment s; - - GstBuffer *buf; - - GstBuffer *ret; - - guint8 *data; - - /* Clip start and end */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_DEFAULT); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 400, - 800, 400); - - GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND; - GST_BUFFER_DURATION (buf) = 10 * GST_SECOND; - GST_BUFFER_OFFSET (buf) = 200; - GST_BUFFER_OFFSET_END (buf) = 1200; - - ret = gst_audio_buffer_clip (buf, &s, 100, 1); - fail_unless (ret != NULL); - - fail_unless (GST_BUFFER_TIMESTAMP (ret) == 4 * GST_SECOND); - fail_unless (GST_BUFFER_DURATION (ret) == 4 * GST_SECOND); - fail_unless (GST_BUFFER_OFFSET (ret) == 400); - fail_unless (GST_BUFFER_OFFSET_END (ret) == 800); - fail_unless (GST_BUFFER_DATA (ret) == data + 200); - fail_unless (GST_BUFFER_SIZE (ret) == 400); - - gst_buffer_unref (ret); - - /* Clip only start */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_DEFAULT); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 400, - 1200, 400); - - GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND; - GST_BUFFER_DURATION (buf) = 10 * GST_SECOND; - GST_BUFFER_OFFSET (buf) = 200; - GST_BUFFER_OFFSET_END (buf) = 1200; - - ret = gst_audio_buffer_clip (buf, &s, 100, 1); - fail_unless (ret != NULL); - - fail_unless (GST_BUFFER_TIMESTAMP (ret) == 4 * GST_SECOND); - fail_unless (GST_BUFFER_DURATION (ret) == 8 * GST_SECOND); - fail_unless (GST_BUFFER_OFFSET (ret) == 400); - fail_unless (GST_BUFFER_OFFSET_END (ret) == 1200); - fail_unless (GST_BUFFER_DATA (ret) == data + 200); - fail_unless (GST_BUFFER_SIZE (ret) == 800); - - gst_buffer_unref (ret); - - /* Clip only stop */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_DEFAULT); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 200, - 1000, 200); - - GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND; - GST_BUFFER_DURATION (buf) = 10 * GST_SECOND; - GST_BUFFER_OFFSET (buf) = 200; - GST_BUFFER_OFFSET_END (buf) = 1200; - - ret = gst_audio_buffer_clip (buf, &s, 100, 1); - fail_unless (ret != NULL); - - fail_unless (GST_BUFFER_TIMESTAMP (ret) == 2 * GST_SECOND); - fail_unless (GST_BUFFER_DURATION (ret) == 8 * GST_SECOND); - fail_unless (GST_BUFFER_OFFSET (ret) == 200); - fail_unless (GST_BUFFER_OFFSET_END (ret) == 1000); - fail_unless (GST_BUFFER_DATA (ret) == data); - fail_unless (GST_BUFFER_SIZE (ret) == 800); - - gst_buffer_unref (ret); - - /* Buffer outside segment */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_DEFAULT); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 1200, - 2000, 1200); - - GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND; - GST_BUFFER_DURATION (buf) = 10 * GST_SECOND; - GST_BUFFER_OFFSET (buf) = 200; - GST_BUFFER_OFFSET_END (buf) = 1200; - - ret = gst_audio_buffer_clip (buf, &s, 100, 1); - fail_unless (ret == NULL); - - /* Clip start and end but don't touch duration and offset_end */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_DEFAULT); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 400, - 800, 400); - - GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND; - GST_BUFFER_DURATION (buf) = GST_CLOCK_TIME_NONE; - GST_BUFFER_OFFSET (buf) = 200; - GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_NONE; - - ret = gst_audio_buffer_clip (buf, &s, 100, 1); - fail_unless (ret != NULL); - - fail_unless (GST_BUFFER_TIMESTAMP (ret) == 4 * GST_SECOND); - fail_unless (GST_BUFFER_DURATION (ret) == GST_CLOCK_TIME_NONE); - fail_unless (GST_BUFFER_OFFSET (ret) == 400); - fail_unless (GST_BUFFER_OFFSET_END (ret) == GST_BUFFER_OFFSET_NONE); - fail_unless (GST_BUFFER_DATA (ret) == data + 200); - fail_unless (GST_BUFFER_SIZE (ret) == 400); - - gst_buffer_unref (ret); - - /* If the buffer has no offset it should assert() - * FIXME: check if return value is the same as the input buffer. - * probably can't be done because the assert() does a SIGABRT. - */ - buf = gst_buffer_new (); - data = (guint8 *) g_malloc (1000); - GST_BUFFER_SIZE (buf) = 1000; - GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; - - gst_segment_init (&s, GST_FORMAT_DEFAULT); - gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 0, 10, 0); - - GST_BUFFER_TIMESTAMP (buf) = 0 * GST_SECOND; - GST_BUFFER_DURATION (buf) = GST_CLOCK_TIME_NONE; - GST_BUFFER_OFFSET (buf) = GST_BUFFER_OFFSET_NONE; - GST_BUFFER_OFFSET_END (buf) = GST_BUFFER_OFFSET_NONE; - - ASSERT_CRITICAL (ret = gst_audio_buffer_clip (buf, &s, 100, 1)); - - gst_buffer_unref (buf); -} - -GST_END_TEST; - -static void -init_value_to_channel_layout (GValue * val, GstAudioChannelPosition pos1, - GstAudioChannelPosition pos2) -{ - GValue pos = { 0, }; - - g_value_init (val, GST_TYPE_ARRAY); - g_value_init (&pos, GST_TYPE_AUDIO_CHANNEL_POSITION); - g_value_set_enum (&pos, pos1); - gst_value_array_append_value (val, &pos); - g_value_set_enum (&pos, pos2); - gst_value_array_append_value (val, &pos); - g_value_unset (&pos); -} - -GST_START_TEST (test_channel_layout_value_intersect) -{ - GValue layout = { 0, }; - GValue list = { 0, }; - GValue res = { 0, }; - - g_value_init (&list, GST_TYPE_LIST); - init_value_to_channel_layout (&layout, GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT); - gst_value_list_append_value (&list, &layout); - g_value_unset (&layout); - init_value_to_channel_layout (&layout, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT); - gst_value_list_append_value (&list, &layout); - g_value_unset (&layout); - - init_value_to_channel_layout (&layout, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT); - - /* we should get the second layout in the list, as it matches the input */ - fail_unless (gst_value_intersect (&res, &layout, &list)); - g_value_unset (&layout); - fail_unless (GST_VALUE_HOLDS_ARRAY (&res)); - fail_unless_equals_int (gst_value_array_get_size (&res), 2); - fail_unless_equals_int (g_value_get_enum (gst_value_array_get_value (&res, - 0)), GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT); - fail_unless_equals_int (g_value_get_enum (gst_value_array_get_value (&res, - 1)), GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT); - g_value_unset (&res); - - /* this (with rear position) should not yield any results */ - init_value_to_channel_layout (&layout, GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT); - fail_if (gst_value_intersect (&res, &layout, &list)); - g_value_unset (&layout); - - g_value_unset (&list); -} - -GST_END_TEST; - -static Suite * -audio_suite (void) -{ - Suite *s = suite_create ("audio support library"); - - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_multichannel_checks); - tcase_add_test (tc_chain, test_buffer_clipping_time); - tcase_add_test (tc_chain, test_buffer_clipping_samples); - tcase_add_test (tc_chain, test_channel_layout_value_intersect); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = audio_suite (); - - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/libs/cddabasesrc.c b/tests/check/libs/cddabasesrc.c deleted file mode 100644 index 33685d81..00000000 --- a/tests/check/libs/cddabasesrc.c +++ /dev/null @@ -1,518 +0,0 @@ -/* GStreamer - * - * unit test for cddabasesrc - * - * Copyright (C) <2005> Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -/* TODO: - * - test different modes (when seeking to tracks in track mode, buffer - * timestamps should start from 0, when seeking to tracks in disc mode, - * buffer timestamps should increment, etc.) - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <unistd.h> - -#include <gst/check/gstcheck.h> -#include <gst/check/gstbufferstraw.h> - -#include <gst/cdda/gstcddabasesrc.h> -#include <string.h> - -#define CD_FRAMESIZE_RAW 2352 - -#define GST_TYPE_CD_FOO_SRC (gst_cd_foo_src_get_type()) -#define GST_CD_FOO_SRC(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CD_FOO_SRC,GstCdFooSrc)) -#define GST_CD_FOO_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CD_FOO_SRC,GstCdFooSrcClass)) -#define GST_IS_CD_FOO_SRC(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CD_FOO_SRC)) -#define GST_IS_CD_FOO_SRC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CD_FOO_SRC)) -#define GST_CD_FOO_SRC_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_CDDA_BASAE_SRC, GstCdFooSrcClass)) - -typedef struct _GstCdFooSrc GstCdFooSrc; -typedef struct _GstCdFooSrcClass GstCdFooSrcClass; - - -/* Neue Heimat (CD 2) */ -static GstCddaBaseSrcTrack nh_cd2_tracks[] = { - {TRUE, 1, 0, 20664, NULL,}, - {TRUE, 2, 20665, 52377, NULL,}, - {TRUE, 3, 52378, 84100, NULL,}, - {TRUE, 4, 84101, 105401, NULL,}, - {TRUE, 5, 105402, 123060, NULL,}, - {TRUE, 6, 123061, 146497, NULL,}, - {TRUE, 7, 146498, 175693, NULL,}, - {TRUE, 8, 175694, 203272, NULL,}, - {TRUE, 9, 203273, 217909, NULL,}, - {TRUE, 10, 217910, 240938, NULL,}, - {TRUE, 11, 240939, 256169, NULL,}, - {TRUE, 12, 256170, 282237, NULL,}, - {TRUE, 13, 282238, 307606, NULL,}, - {TRUE, 14, 307607, 337245, NULL,} -}; - -/* Offspring - Smash */ -static GstCddaBaseSrcTrack offspring_tracks[] = { - {TRUE, 1, 0, 1924, NULL,}, - {TRUE, 2, 1925, 12947, NULL,}, - {TRUE, 3, 12948, 29739, NULL,}, - {TRUE, 4, 29740, 47202, NULL,}, - {TRUE, 5, 47203, 63134, NULL,}, - {TRUE, 6, 63135, 77954, NULL,}, - {TRUE, 7, 77955, 92789, NULL,}, - {TRUE, 8, 92790, 112127, NULL,}, - {TRUE, 9, 112128, 124372, NULL,}, - {TRUE, 10, 124373, 133574, NULL,}, - {TRUE, 11, 133575, 143484, NULL,}, - {TRUE, 12, 143485, 149279, NULL,}, - {TRUE, 13, 149280, 162357, NULL,}, - {TRUE, 14, 162358, 210372, NULL,} -}; - -/* this matches the sample TOC from the DiscIDCalculation - * page in the Musicbrainz wiki. It's a tricky one because - * it's got a data track as well. */ -static GstCddaBaseSrcTrack mb_sample_tracks[] = { - {TRUE, 1, 0, 18640, NULL,}, - {TRUE, 2, 18641, 34666, NULL,}, - {TRUE, 3, 34667, 56349, NULL,}, - {TRUE, 4, 56350, 77005, NULL,}, - {TRUE, 5, 77006, 106093, NULL,}, - {TRUE, 6, 106094, 125728, NULL,}, - {TRUE, 7, 125729, 149784, NULL,}, - {TRUE, 8, 149785, 168884, NULL,}, - {TRUE, 9, 168885, 185909, NULL,}, - {TRUE, 10, 185910, 205828, NULL,}, - {TRUE, 11, 205829, 230141, NULL,}, - {TRUE, 12, 230142, 246658, NULL,}, - {TRUE, 13, 246659, 265613, NULL,}, - {TRUE, 14, 265614, 289478, NULL,}, - {FALSE, 15, 289479, 325731, NULL,} -}; - -/* Nicola Conte - Other Directions (also - * tricky due to the extra data track) */ -static GstCddaBaseSrcTrack nconte_odir_tracks[] = { - {TRUE, 1, 0, 17852, NULL,}, - {TRUE, 2, 17853, 39956, NULL,}, - {TRUE, 3, 39957, 68449, NULL,}, - {TRUE, 4, 68450, 88725, NULL,}, - {TRUE, 5, 88726, 106413, NULL,}, - {TRUE, 6, 106414, 131966, NULL,}, - {TRUE, 7, 131967, 152372, NULL,}, - {TRUE, 8, 152373, 168602, NULL,}, - {TRUE, 9, 168603, 190348, NULL,}, - {TRUE, 10, 190349, 209044, NULL,}, - {TRUE, 11, 209045, 235586, NULL,}, - {TRUE, 12, 235587, 253830, NULL,}, - {TRUE, 13, 253831, 272213, NULL,}, - {FALSE, 14, 272214, 332849, NULL,} -}; - -/* Pink Martini - Sympathique (11 track version) */ -static GstCddaBaseSrcTrack pm_symp_tracks[] = { - {TRUE, 1, 0, 21667, NULL,}, - {TRUE, 2, 21668, 49576, NULL,}, - {TRUE, 3, 49577, 62397, NULL,}, - {TRUE, 4, 62398, 81087, NULL,}, - {TRUE, 5, 81088, 106595, NULL,}, - {TRUE, 6, 106596, 122012, NULL,}, - {TRUE, 7, 122013, 138469, NULL,}, - {TRUE, 8, 138470, 157306, NULL,}, - {TRUE, 9, 157307, 179635, NULL,}, - {TRUE, 10, 179636, 203673, NULL,}, - {TRUE, 11, 203674, 213645, NULL,} -}; - -#define NUM_TEST_DISCS 5 - -struct _test_disc -{ - GstCddaBaseSrcTrack *tracks; - guint num_tracks; - guint32 cddb_discid; - const gchar *musicbrainz_discid; -}; - -/* FIXME: now we just need to find out how to treat - * data tracks for the cddb id calculation .... */ -static struct _test_disc test_discs[NUM_TEST_DISCS] = { - {nh_cd2_tracks, G_N_ELEMENTS (nh_cd2_tracks), 0xae11900e, - NULL}, - {mb_sample_tracks, G_N_ELEMENTS (mb_sample_tracks), 0x00000000, - "MUtMmKN402WPj3_VFsgUelxpc8U-"}, - {offspring_tracks, G_N_ELEMENTS (offspring_tracks), 0xc20af40e, - "ahg7JUcfR3vCYBphSDIogOOWrr0-"}, - {nconte_odir_tracks, G_N_ELEMENTS (nconte_odir_tracks), 0x00000000, - /* hKx_PejjG47X161ND_Sh0HyqaS0- according to libmusicbrainz, but that's - * wrong according to the wiki docs (or not?) (neither discid is listed) */ - "fboaOQtfqwENv8WyXa9tRyvyUbQ-"}, - {pm_symp_tracks, G_N_ELEMENTS (pm_symp_tracks), 0xa00b200b, - "iP0DOLdr4vt_IfKSIXoRUR.q_Wc-"} -}; - -struct _GstCdFooSrc -{ - GstCddaBaseSrc cddabasesrc; - - struct _test_disc *cur_test; - guint cur_disc; -}; - -struct _GstCdFooSrcClass -{ - GstCddaBaseSrcClass parent_class; -}; - -GST_BOILERPLATE (GstCdFooSrc, gst_cd_foo_src, GstCddaBaseSrc, - GST_TYPE_CDDA_BASE_SRC); - -static GstBuffer *gst_cd_foo_src_read_sector (GstCddaBaseSrc * src, - gint sector); -static gboolean gst_cd_foo_src_open (GstCddaBaseSrc * src, - const gchar * device); -static void gst_cd_foo_src_close (GstCddaBaseSrc * src); - -static const GstElementDetails cdfoo_details = -GST_ELEMENT_DETAILS ("CD Audio (cdda) Source, FooBar", - "Source/File", - "Read audio from CD", - "Foo Bar <foo@bar.com>"); - -static void -gst_cd_foo_src_base_init (gpointer g_class) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_set_details (element_class, &cdfoo_details); -} - -static void -gst_cd_foo_src_init (GstCdFooSrc * src, GstCdFooSrcClass * klass) -{ - src->cur_disc = 0; -} - -static void -gst_cd_foo_src_class_init (GstCdFooSrcClass * klass) -{ - GstCddaBaseSrcClass *cddabasesrc_class = GST_CDDA_BASE_SRC_CLASS (klass); - - cddabasesrc_class->open = gst_cd_foo_src_open; - cddabasesrc_class->close = gst_cd_foo_src_close; - cddabasesrc_class->read_sector = gst_cd_foo_src_read_sector; -} - -static gboolean -gst_cd_foo_src_open (GstCddaBaseSrc * cddabasesrc, const gchar * device) -{ - GstCddaBaseSrcTrack *tracks; - GstCdFooSrc *src; - gint i; - - src = GST_CD_FOO_SRC (cddabasesrc); - - /* if this fails, the test is wrong */ - g_assert (src->cur_disc < NUM_TEST_DISCS); - - src->cur_test = &test_discs[src->cur_disc]; - - /* add tracks */ - tracks = src->cur_test->tracks; - for (i = 0; i < src->cur_test->num_tracks; ++i) { - gst_cdda_base_src_add_track (GST_CDDA_BASE_SRC (src), &tracks[i]); - } - - return TRUE; -} - -static void -gst_cd_foo_src_close (GstCddaBaseSrc * cddabasesrc) -{ - GstCdFooSrc *src = GST_CD_FOO_SRC (cddabasesrc); - - if (src->cur_test->cddb_discid != 0) { - g_assert (cddabasesrc->discid == src->cur_test->cddb_discid); - } - - if (src->cur_test->musicbrainz_discid != NULL) { - g_assert (g_str_equal (cddabasesrc->mb_discid, - src->cur_test->musicbrainz_discid)); - } -} - -static GstBuffer * -gst_cd_foo_src_read_sector (GstCddaBaseSrc * cddabasesrc, gint sector) -{ - GstBuffer *buf; - - buf = gst_buffer_new_and_alloc (CD_FRAMESIZE_RAW); - memset (GST_BUFFER_DATA (buf), 0, CD_FRAMESIZE_RAW); - - return buf; -} - -static inline gboolean -tag_list_has_tag (GstTagList * list, const gchar * tag, GType type) -{ - const GValue *val = gst_tag_list_get_value_index (list, tag, 0); - - if (val == NULL) { - GST_LOG ("no tag '%s' in taglist %" GST_PTR_FORMAT, tag, list); - return FALSE; - } - - if (!G_VALUE_HOLDS (val, type)) { - GST_LOG ("tag '%s' in taglist %" GST_PTR_FORMAT " is not of type %s", - tag, list, g_type_name (type)); - return FALSE; - } - - return TRUE; -} - -static void -test_uri_parse (const gchar * uri, const gchar * device, gint track) -{ - GstElement *foosrc; - gchar *set_device = NULL; - gint set_track = 0; - - foosrc = gst_element_factory_make ("cdfoosrc", "cdfoosrc"); - fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc), uri) == TRUE, - "couldn't set uri %s", uri); - g_object_get (foosrc, "device", &set_device, "track", &set_track, NULL); - fail_unless (set_device != NULL); - fail_unless (strcmp (set_device, device) == 0, - "device set was %s, expected %s", set_device, device); - fail_unless (set_track == track, "track set was %d, expected %d", set_track, - track); - g_free (set_device); - gst_object_unref (foosrc); -} - -GST_START_TEST (test_discid_calculations) -{ - GstElement *foosrc, *pipeline, *sink; - gint i; - - fail_unless (gst_element_register (NULL, "cdfoosrc", GST_RANK_SECONDARY, - GST_TYPE_CD_FOO_SRC)); - - pipeline = gst_pipeline_new ("pipeline"); - - sink = gst_element_factory_make ("fakesink", "sink"); - fail_unless (sink != NULL, "couldn't create fakesink"); - - foosrc = gst_element_factory_make ("cdfoosrc", "cdfoosrc"); - fail_unless (foosrc != NULL, "couldn't create cdfoosrc"); - - gst_bin_add (GST_BIN (pipeline), foosrc); - gst_bin_add (GST_BIN (pipeline), sink); - fail_unless (gst_element_link (foosrc, sink)); - - for (i = 0; i < G_N_ELEMENTS (test_discs); ++i) { - GstTagList *tags = NULL; - GstMessage *msg; - - GST_LOG ("Testing disc layout %u ...", i); - GST_CD_FOO_SRC (foosrc)->cur_disc = i; - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - msg = - gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipeline), - GST_CLOCK_TIME_NONE, GST_MESSAGE_TAG); - gst_message_parse_tag (msg, &tags); - fail_unless (tags != NULL); - fail_unless (tag_list_has_tag (tags, "track-count", G_TYPE_UINT)); - fail_unless (tag_list_has_tag (tags, "track-number", G_TYPE_UINT)); - fail_unless (tag_list_has_tag (tags, "duration", G_TYPE_UINT64)); - fail_unless (tag_list_has_tag (tags, "discid", G_TYPE_STRING)); - fail_unless (tag_list_has_tag (tags, "discid-full", G_TYPE_STRING)); - fail_unless (tag_list_has_tag (tags, "musicbrainz-discid", G_TYPE_STRING)); - fail_unless (tag_list_has_tag (tags, "musicbrainz-discid-full", - G_TYPE_STRING)); - gst_tag_list_free (tags); - gst_message_unref (msg); - - msg = - gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipeline), - GST_CLOCK_TIME_NONE, GST_MESSAGE_ASYNC_DONE); - gst_message_unref (msg); - - gst_element_set_state (pipeline, GST_STATE_NULL); - } - - gst_object_unref (pipeline); - - gst_task_cleanup_all (); -} - -GST_END_TEST; - -GST_START_TEST (test_buffer_timestamps) -{ - GstElement *foosrc, *pipeline, *fakesink; - GstClockTime prev_ts, prev_duration, ts; - GstPad *sinkpad; - gint i; - - fail_unless (gst_element_register (NULL, "cdfoosrc", GST_RANK_SECONDARY, - GST_TYPE_CD_FOO_SRC)); - - pipeline = gst_pipeline_new ("pipeline"); - foosrc = gst_element_factory_make ("cdfoosrc", "cdfoosrc"); - fakesink = gst_element_factory_make ("fakesink", "fakesink"); - gst_bin_add_many (GST_BIN (pipeline), foosrc, fakesink, NULL); - fail_unless (gst_element_link (foosrc, fakesink)); - sinkpad = gst_element_get_static_pad (fakesink, "sink"); - - GST_CD_FOO_SRC (foosrc)->cur_disc = 0; - - gst_buffer_straw_start_pipeline (pipeline, sinkpad); - - prev_ts = GST_CLOCK_TIME_NONE; - prev_duration = GST_CLOCK_TIME_NONE; - - for (i = 0; i < 100; ++i) { - GstBuffer *buf; - - buf = gst_buffer_straw_get_buffer (pipeline, sinkpad); - GST_LOG ("buffer, ts=%" GST_TIME_FORMAT ", dur=%" GST_TIME_FORMAT, - GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)), - GST_TIME_ARGS (GST_BUFFER_DURATION (buf))); - ts = GST_BUFFER_TIMESTAMP (buf); - fail_unless (GST_CLOCK_TIME_IS_VALID (ts)); - fail_unless (GST_BUFFER_DURATION_IS_VALID (buf)); - if (i > 0) { - fail_unless (GST_CLOCK_TIME_IS_VALID (prev_ts)); - fail_unless (GST_CLOCK_TIME_IS_VALID (prev_duration)); - fail_unless ((prev_ts + prev_duration) == ts); - } - prev_ts = ts; - prev_duration = GST_BUFFER_DURATION (buf); - gst_buffer_unref (buf); - } - - gst_buffer_straw_stop_pipeline (pipeline, sinkpad); - - gst_task_cleanup_all (); - gst_object_unref (pipeline); - gst_object_unref (sinkpad); -} - -GST_END_TEST; - -GST_START_TEST (test_uri_parsing) -{ - GstElement *foosrc; - - fail_unless (gst_element_register (NULL, "cdfoosrc", GST_RANK_SECONDARY, - GST_TYPE_CD_FOO_SRC)); - - /* wrong protocol */ - foosrc = gst_element_factory_make ("cdfoosrc", "cdfoosrc"); - fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc), - "x://") == FALSE); - fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc), - "cddaq://") == FALSE); - - /* cdda://track */ - test_uri_parse ("cdda://", "/dev/cdrom", 1); - test_uri_parse ("cdda://2", "/dev/cdrom", 2); - test_uri_parse ("cdda://47", "/dev/cdrom", 47); - fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc), - "cdda://-1") == FALSE); - fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc), - "cdda://what") == FALSE); - - /* cdda://device#track */ - test_uri_parse ("cdda:///dev/hdb#1", "/dev/hdb", 1); - test_uri_parse ("cdda://anything#8", "anything", 8); - fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc), - "cdda:///dev/hdb#nonsense") == FALSE); - fail_unless (gst_uri_handler_set_uri (GST_URI_HANDLER (foosrc), - "cdda:///dev/hdb#-2") == FALSE); - - /* cdda://track#device (device should be ignored - FIXME 0.11) */ - test_uri_parse ("cdda://8#/dev/hdb", "/dev/cdrom", 8); - - gst_object_unref (foosrc); -} - -GST_END_TEST; - -GST_START_TEST (test_properties) -{ - GstElement *foosrc; - gchar *device; - guint track; - - fail_unless (gst_element_register (NULL, "cdfoosrc", GST_RANK_SECONDARY, - GST_TYPE_CD_FOO_SRC)); - - foosrc = gst_element_factory_make ("cdfoosrc", "cdfoosrc"); - - g_object_set (foosrc, "device", "/dev/cdrom", NULL); - g_object_get (foosrc, "device", &device, "track", &track, NULL); - fail_unless (g_str_equal (device, "/dev/cdrom")); - fail_unless_equals_int (track, 1); - g_free (device); - - g_object_set (foosrc, "device", "/dev/cdrom1", "track", 17, NULL); - g_object_get (foosrc, "device", &device, "track", &track, NULL); - fail_unless (g_str_equal (device, "/dev/cdrom1")); - fail_unless_equals_int (track, 17); - g_free (device); - - g_object_set (foosrc, "track", 17, "device", "/dev/cdrom1", NULL); - g_object_get (foosrc, "device", &device, "track", &track, NULL); - fail_unless (g_str_equal (device, "/dev/cdrom1")); - fail_unless_equals_int (track, 17); - g_free (device); - - g_object_set (foosrc, "track", 12, NULL); - g_object_get (foosrc, "device", &device, "track", &track, NULL); - fail_unless (g_str_equal (device, "/dev/cdrom1")); - fail_unless_equals_int (track, 12); - g_free (device); - - gst_object_unref (foosrc); -} - -GST_END_TEST; - -static Suite * -cddabasesrc_suite (void) -{ - Suite *s = suite_create ("cddabasesrc"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_discid_calculations); - tcase_add_test (tc_chain, test_buffer_timestamps); - tcase_add_test (tc_chain, test_uri_parsing); - tcase_add_test (tc_chain, test_properties); - - return s; -} - -GST_CHECK_MAIN (cddabasesrc) diff --git a/tests/check/libs/fft.c b/tests/check/libs/fft.c deleted file mode 100644 index bcaf967e..00000000 --- a/tests/check/libs/fft.c +++ /dev/null @@ -1,563 +0,0 @@ -/* GStreamer - * - * unit test for FFT library - * - * Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/check/gstcheck.h> - -#include <gst/fft/gstfft.h> -#include <gst/fft/gstffts16.h> -#include <gst/fft/gstffts32.h> -#include <gst/fft/gstfftf32.h> -#include <gst/fft/gstfftf64.h> - -GST_START_TEST (test_next_fast_length) -{ - fail_unless_equals_int (gst_fft_next_fast_length (13), 16); - fail_unless_equals_int (gst_fft_next_fast_length (30), 30); - fail_unless_equals_int (gst_fft_next_fast_length (31), 32); - fail_unless_equals_int (gst_fft_next_fast_length (1), 2); -} - -GST_END_TEST; - -GST_START_TEST (test_s16_0hz) -{ - gint i; - gint16 *in; - GstFFTS16Complex *out; - GstFFTS16 *ctx; - - in = g_new (gint16, 2048); - out = g_new (GstFFTS16Complex, 1025); - ctx = gst_fft_s16_new (2048, FALSE); - - for (i = 0; i < 2048; i++) - in[i] = G_MAXINT16; - - gst_fft_s16_window (ctx, in, GST_FFT_WINDOW_HAMMING); - gst_fft_s16_fft (ctx, in, out); - - for (i = 0; i < 1025; i++) { - gdouble mag; - - mag = (gdouble) out[i].r * (gdouble) out[i].r; - mag += (gdouble) out[i].i * (gdouble) out[i].i; - mag /= 32767.0 * 32767.0; - mag = 10.0 * log10 (mag); - if (i < 2) - fail_unless (mag > -15.0); - else - fail_unless (mag < -55.0); - } - - gst_fft_s16_free (ctx); - g_free (in); - g_free (out); -} - -GST_END_TEST; - -GST_START_TEST (test_s16_11025hz) -{ - gint i; - gint16 *in; - GstFFTS16Complex *out; - GstFFTS16 *ctx; - - in = g_new (gint16, 2048); - out = g_new (GstFFTS16Complex, 1025); - ctx = gst_fft_s16_new (2048, FALSE); - - for (i = 0; i < 2048; i += 4) { - in[i] = 0; - in[i + 1] = G_MAXINT16; - in[i + 2] = 0; - in[i + 3] = G_MININT16; - } - - gst_fft_s16_window (ctx, in, GST_FFT_WINDOW_HAMMING); - gst_fft_s16_fft (ctx, in, out); - - for (i = 0; i < 1025; i++) { - gdouble mag; - - mag = (gdouble) out[i].r * (gdouble) out[i].r; - mag += (gdouble) out[i].i * (gdouble) out[i].i; - mag /= 32767.0 * 32767.0; - mag = 10.0 * log10 (mag); - - if (abs (512 - i) < 2) - fail_unless (mag > -20.0); - else - fail_unless (mag < -55.0); - } - - gst_fft_s16_free (ctx); - g_free (in); - g_free (out); -} - -GST_END_TEST; - -GST_START_TEST (test_s16_22050hz) -{ - gint i; - gint16 *in; - GstFFTS16Complex *out; - GstFFTS16 *ctx; - - in = g_new (gint16, 2048); - out = g_new (GstFFTS16Complex, 1025); - ctx = gst_fft_s16_new (2048, FALSE); - - for (i = 0; i < 2048; i += 2) { - in[i] = G_MAXINT16; - in[i + 1] = G_MININT16; - } - - gst_fft_s16_window (ctx, in, GST_FFT_WINDOW_HAMMING); - gst_fft_s16_fft (ctx, in, out); - - for (i = 0; i < 1025; i++) { - gdouble mag; - - mag = (gdouble) out[i].r * (gdouble) out[i].r; - mag += (gdouble) out[i].i * (gdouble) out[i].i; - mag /= 32767.0 * 32767.0; - mag = 10.0 * log10 (mag); - - if (i > 1022) - fail_unless (mag > -15.0); - else - fail_unless (mag < -55.0); - } - - gst_fft_s16_free (ctx); - g_free (in); - g_free (out); -} - -GST_END_TEST; - -GST_START_TEST (test_s32_0hz) -{ - gint i; - gint32 *in; - GstFFTS32Complex *out; - GstFFTS32 *ctx; - - in = g_new (gint32, 2048); - out = g_new (GstFFTS32Complex, 1025); - ctx = gst_fft_s32_new (2048, FALSE); - - for (i = 0; i < 2048; i++) - in[i] = 2147483647; - - gst_fft_s32_window (ctx, in, GST_FFT_WINDOW_HAMMING); - gst_fft_s32_fft (ctx, in, out); - - for (i = 0; i < 1025; i++) { - gdouble mag; - - mag = (gdouble) out[i].r * (gdouble) out[i].r; - mag += (gdouble) out[i].i * (gdouble) out[i].i; - mag /= 2147483647.0 * 2147483647.0; - mag = 10.0 * log10 (mag); - - if (i < 2) - fail_unless (mag > -15.0); - else - fail_unless (mag < -60.0); - } - - gst_fft_s32_free (ctx); - g_free (in); - g_free (out); -} - -GST_END_TEST; - -GST_START_TEST (test_s32_11025hz) -{ - gint i; - gint32 *in; - GstFFTS32Complex *out; - GstFFTS32 *ctx; - - in = g_new (gint32, 2048); - out = g_new (GstFFTS32Complex, 1025); - ctx = gst_fft_s32_new (2048, FALSE); - - for (i = 0; i < 2048; i += 4) { - in[i] = 0; - in[i + 1] = G_MAXINT32; - in[i + 2] = 0; - in[i + 3] = G_MININT32; - } - - gst_fft_s32_window (ctx, in, GST_FFT_WINDOW_HAMMING); - gst_fft_s32_fft (ctx, in, out); - - for (i = 0; i < 1025; i++) { - gdouble mag; - - mag = (gdouble) out[i].r * (gdouble) out[i].r; - mag += (gdouble) out[i].i * (gdouble) out[i].i; - mag /= 2147483647.0 * 2147483647.0; - mag = 10.0 * log10 (mag); - - if (abs (512 - i) < 2) - fail_unless (mag > -20.0); - else - fail_unless (mag < -60.0); - } - - gst_fft_s32_free (ctx); - g_free (in); - g_free (out); -} - -GST_END_TEST; - -GST_START_TEST (test_s32_22050hz) -{ - gint i; - gint32 *in; - GstFFTS32Complex *out; - GstFFTS32 *ctx; - - in = g_new (gint32, 2048); - out = g_new (GstFFTS32Complex, 1025); - ctx = gst_fft_s32_new (2048, FALSE); - - for (i = 0; i < 2048; i += 2) { - in[i] = G_MAXINT32; - in[i + 1] = G_MININT32; - } - - gst_fft_s32_window (ctx, in, GST_FFT_WINDOW_HAMMING); - gst_fft_s32_fft (ctx, in, out); - - for (i = 0; i < 1025; i++) { - gdouble mag; - - mag = (gdouble) out[i].r * (gdouble) out[i].r; - mag += (gdouble) out[i].i * (gdouble) out[i].i; - mag /= 2147483647.0 * 2147483647.0; - mag = 10.0 * log10 (mag); - - if (i > 1022) - fail_unless (mag > -15.0); - else - fail_unless (mag < -60.0); - } - - gst_fft_s32_free (ctx); - g_free (in); - g_free (out); -} - -GST_END_TEST; - -GST_START_TEST (test_f32_0hz) -{ - gint i; - gfloat *in; - GstFFTF32Complex *out; - GstFFTF32 *ctx; - - in = g_new (gfloat, 2048); - out = g_new (GstFFTF32Complex, 1025); - ctx = gst_fft_f32_new (2048, FALSE); - - for (i = 0; i < 2048; i++) - in[i] = 1.0; - - gst_fft_f32_window (ctx, in, GST_FFT_WINDOW_HAMMING); - gst_fft_f32_fft (ctx, in, out); - - for (i = 0; i < 1025; i++) { - gdouble mag; - - mag = (gdouble) out[i].r * (gdouble) out[i].r; - mag += (gdouble) out[i].i * (gdouble) out[i].i; - mag /= 2048.0 * 2048.0; - mag = 10.0 * log10 (mag); - - if (i < 2) - fail_unless (mag > -15.0); - else - fail_unless (mag < -60.0); - } - - gst_fft_f32_free (ctx); - g_free (in); - g_free (out); -} - -GST_END_TEST; - -GST_START_TEST (test_f32_11025hz) -{ - gint i; - gfloat *in; - GstFFTF32Complex *out; - GstFFTF32 *ctx; - - in = g_new (gfloat, 2048); - out = g_new (GstFFTF32Complex, 1025); - ctx = gst_fft_f32_new (2048, FALSE); - - for (i = 0; i < 2048; i += 4) { - in[i] = 0.0; - in[i + 1] = 1.0; - in[i + 2] = 0.0; - in[i + 3] = -1.0; - } - - gst_fft_f32_window (ctx, in, GST_FFT_WINDOW_HAMMING); - gst_fft_f32_fft (ctx, in, out); - - for (i = 0; i < 1025; i++) { - gdouble mag; - - mag = (gdouble) out[i].r * (gdouble) out[i].r; - mag += (gdouble) out[i].i * (gdouble) out[i].i; - mag /= 2048.0 * 2048.0; - mag = 10.0 * log10 (mag); - - if (abs (512 - i) < 2) - fail_unless (mag > -20.0); - else - fail_unless (mag < -60.0); - } - - gst_fft_f32_free (ctx); - g_free (in); - g_free (out); -} - -GST_END_TEST; - -GST_START_TEST (test_f32_22050hz) -{ - gint i; - gfloat *in; - GstFFTF32Complex *out; - GstFFTF32 *ctx; - - in = g_new (gfloat, 2048); - out = g_new (GstFFTF32Complex, 1025); - ctx = gst_fft_f32_new (2048, FALSE); - - for (i = 0; i < 2048; i += 2) { - in[i] = 1.0; - in[i + 1] = -1.0; - } - - gst_fft_f32_window (ctx, in, GST_FFT_WINDOW_HAMMING); - gst_fft_f32_fft (ctx, in, out); - - for (i = 0; i < 1025; i++) { - gdouble mag; - - mag = (gdouble) out[i].r * (gdouble) out[i].r; - mag += (gdouble) out[i].i * (gdouble) out[i].i; - mag /= 2048.0 * 2048.0; - mag = 10.0 * log10 (mag); - - if (i > 1022) - fail_unless (mag > -15.0); - else - fail_unless (mag < -60.0); - } - - gst_fft_f32_free (ctx); - g_free (in); - g_free (out); -} - -GST_END_TEST; - -GST_START_TEST (test_f64_0hz) -{ - gint i; - gdouble *in; - GstFFTF64Complex *out; - GstFFTF64 *ctx; - - in = g_new (gdouble, 2048); - out = g_new (GstFFTF64Complex, 1025); - ctx = gst_fft_f64_new (2048, FALSE); - - for (i = 0; i < 2048; i++) - in[i] = 1.0; - - gst_fft_f64_window (ctx, in, GST_FFT_WINDOW_HAMMING); - gst_fft_f64_fft (ctx, in, out); - - for (i = 0; i < 1025; i++) { - gdouble mag; - - mag = (gdouble) out[i].r * (gdouble) out[i].r; - mag += (gdouble) out[i].i * (gdouble) out[i].i; - mag /= 2048.0 * 2048.0; - mag = 10.0 * log10 (mag); - - if (i < 2) - fail_unless (mag > -15.0); - else - fail_unless (mag < -60.0); - } - - gst_fft_f64_free (ctx); - g_free (in); - g_free (out); -} - -GST_END_TEST; - -GST_START_TEST (test_f64_11025hz) -{ - gint i; - gdouble *in; - GstFFTF64Complex *out; - GstFFTF64 *ctx; - - in = g_new (gdouble, 2048); - out = g_new (GstFFTF64Complex, 1025); - ctx = gst_fft_f64_new (2048, FALSE); - - for (i = 0; i < 2048; i += 4) { - in[i] = 0.0; - in[i + 1] = 1.0; - in[i + 2] = 0.0; - in[i + 3] = -1.0; - } - - gst_fft_f64_window (ctx, in, GST_FFT_WINDOW_HAMMING); - gst_fft_f64_fft (ctx, in, out); - - for (i = 0; i < 1025; i++) { - gdouble mag; - - mag = (gdouble) out[i].r * (gdouble) out[i].r; - mag += (gdouble) out[i].i * (gdouble) out[i].i; - mag /= 2048.0 * 2048.0; - mag = 10.0 * log10 (mag); - - if (abs (512 - i) < 2) - fail_unless (mag > -20.0); - else - fail_unless (mag < -60.0); - } - - gst_fft_f64_free (ctx); - g_free (in); - g_free (out); -} - -GST_END_TEST; - -GST_START_TEST (test_f64_22050hz) -{ - gint i; - gdouble *in; - GstFFTF64Complex *out; - GstFFTF64 *ctx; - - in = g_new (gdouble, 2048); - out = g_new (GstFFTF64Complex, 1025); - ctx = gst_fft_f64_new (2048, FALSE); - - for (i = 0; i < 2048; i += 2) { - in[i] = 1.0; - in[i + 1] = -1.0; - } - - gst_fft_f64_window (ctx, in, GST_FFT_WINDOW_HAMMING); - gst_fft_f64_fft (ctx, in, out); - - for (i = 0; i < 1025; i++) { - gdouble mag; - - mag = (gdouble) out[i].r * (gdouble) out[i].r; - mag += (gdouble) out[i].i * (gdouble) out[i].i; - mag /= 2048.0 * 2048.0; - mag = 10.0 * log10 (mag); - - if (i > 1022) - fail_unless (mag > -15.0); - else - fail_unless (mag < -60.0); - } - - gst_fft_f64_free (ctx); - g_free (in); - g_free (out); -} - -GST_END_TEST; - -static Suite * -fft_suite (void) -{ - Suite *s = suite_create ("fft library"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_next_fast_length); - tcase_add_test (tc_chain, test_s16_0hz); - tcase_add_test (tc_chain, test_s16_11025hz); - tcase_add_test (tc_chain, test_s16_22050hz); - tcase_add_test (tc_chain, test_s32_0hz); - tcase_add_test (tc_chain, test_s32_11025hz); - tcase_add_test (tc_chain, test_s32_22050hz); - tcase_add_test (tc_chain, test_f32_0hz); - tcase_add_test (tc_chain, test_f32_11025hz); - tcase_add_test (tc_chain, test_f32_22050hz); - tcase_add_test (tc_chain, test_f64_0hz); - tcase_add_test (tc_chain, test_f64_11025hz); - tcase_add_test (tc_chain, test_f64_22050hz); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = fft_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/libs/mixer.c b/tests/check/libs/mixer.c deleted file mode 100644 index 1133ecb1..00000000 --- a/tests/check/libs/mixer.c +++ /dev/null @@ -1,241 +0,0 @@ -/* GStreamer - * - * unit tests for audio support library - * - * Copyright (C) 2007 Jan Schmidt <thaytan@noraisin.net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/check/gstcheck.h> - -#include <gst/interfaces/mixer.h> - -#include <string.h> - -#define TEST_ELEMENT_TYPE (test_element_get_type()) - -typedef struct TestElement TestElement; -typedef struct TestElementClass TestElementClass; - -struct TestElement -{ - GstElement parent; -}; - -struct TestElementClass -{ - GstElementClass parent_class; -}; - -static void init_interface (GType type); -static void gst_implements_interface_init (GstImplementsInterfaceClass * klass); - -GST_BOILERPLATE_FULL (TestElement, test_element, GstElement, GST_TYPE_ELEMENT, - init_interface); - -static void -test_element_mixer_interface_init (GstMixerClass * klass) -{ - /* Not actually implementing any interfaces for this test atm */ -} - -static void -init_interface (GType type) -{ - static const GInterfaceInfo mixer_iface_info = { - (GInterfaceInitFunc) test_element_mixer_interface_init, - NULL, - NULL, - }; - static const GInterfaceInfo implements_iface_info = { - (GInterfaceInitFunc) gst_implements_interface_init, - NULL, - NULL, - }; - - g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE, - &implements_iface_info); - g_type_add_interface_static (type, GST_TYPE_MIXER, &mixer_iface_info); -} - -static void -test_element_base_init (gpointer klass) -{ -} - -static void -test_element_class_init (TestElementClass * klass) -{ -} - -static gboolean -test_element_interface_supported (GstImplementsInterface * ifacE, - GType interface_type) -{ - if (interface_type == GST_TYPE_MIXER) - return TRUE; - - return FALSE; -} - -static void -gst_implements_interface_init (GstImplementsInterfaceClass * klass) -{ - klass->supported = test_element_interface_supported; -} - -static void -test_element_init (TestElement * this, TestElementClass * klass) -{ -} - -GST_START_TEST (test_messages) -{ - /* Create an empty GstElement that has a GstMixer interface and then - * send some notifications and validate them */ - GstElement *test_element = - (GstElement *) g_object_new (TEST_ELEMENT_TYPE, NULL); - GstBus *bus = gst_bus_new (); - GstMixerTrack *mtrack = g_object_new (GST_TYPE_MIXER_TRACK, NULL); - GstMixerOptions *mopts = g_object_new (GST_TYPE_MIXER_OPTIONS, NULL); - GstMixerTrack *t; - GstMixerOptions *o; - gint vols_in[2] = { 50, 75 }; - gboolean mute, record; - gint *vols_out; - gint n_chans, i; - const gchar *val; - GstMessage *message; - - mtrack->num_channels = 2; - mtrack->flags = GST_MIXER_TRACK_MUTE | GST_MIXER_TRACK_RECORD; - - gst_element_set_bus (test_element, bus); - - /* Test mute-toggled */ - gst_mixer_mute_toggled (GST_MIXER (test_element), mtrack, TRUE); - message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, GST_CLOCK_TIME_NONE); - fail_if (message == NULL); - fail_unless (gst_mixer_message_get_type (message) == - GST_MIXER_MESSAGE_MUTE_TOGGLED); - /* Test that we can pass NULL args */ - gst_mixer_message_parse_mute_toggled (message, NULL, NULL); - /* Test the parsing */ - gst_mixer_message_parse_mute_toggled (message, &t, &mute); - fail_unless (t == mtrack); - fail_unless (mute == TRUE); - gst_message_unref (message); - - /* Test record-toggled */ - gst_mixer_record_toggled (GST_MIXER (test_element), mtrack, TRUE); - message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, GST_CLOCK_TIME_NONE); - fail_if (message == NULL); - fail_unless (gst_mixer_message_get_type (message) == - GST_MIXER_MESSAGE_RECORD_TOGGLED); - gst_mixer_message_parse_record_toggled (message, NULL, NULL); - gst_mixer_message_parse_record_toggled (message, &t, &record); - fail_unless (t == mtrack); - fail_unless (record == TRUE); - gst_message_unref (message); - - /* Test volume-changed */ - gst_mixer_volume_changed (GST_MIXER (test_element), mtrack, vols_in); - message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, GST_CLOCK_TIME_NONE); - fail_if (message == NULL); - fail_unless (gst_mixer_message_get_type (message) == - GST_MIXER_MESSAGE_VOLUME_CHANGED); - gst_mixer_message_parse_volume_changed (message, NULL, NULL, NULL); - gst_mixer_message_parse_volume_changed (message, NULL, NULL, &n_chans); - fail_unless (n_chans == 2); - gst_mixer_message_parse_volume_changed (message, &t, &vols_out, &n_chans); - fail_unless (mtrack == t); - for (i = 0; i < n_chans; i++) - fail_unless (vols_out[i] == vols_in[i]); - - gst_message_unref (message); - g_free (vols_out); - - /* Test option-changed */ - gst_mixer_option_changed (GST_MIXER (test_element), mopts, "TESTING"); - message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, GST_CLOCK_TIME_NONE); - fail_if (message == NULL); - fail_unless (gst_mixer_message_get_type (message) == - GST_MIXER_MESSAGE_OPTION_CHANGED); - gst_mixer_message_parse_option_changed (message, NULL, NULL); - gst_mixer_message_parse_option_changed (message, &o, &val); - fail_unless (o == mopts); - fail_unless (g_str_equal (val, "TESTING")); - gst_message_unref (message); - - /* Test options-list-changed */ - gst_mixer_options_list_changed (GST_MIXER (test_element), mopts); - message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, GST_CLOCK_TIME_NONE); - fail_if (message == NULL); - fail_unless (gst_mixer_message_get_type (message) == - GST_MIXER_MESSAGE_OPTIONS_LIST_CHANGED); - gst_mixer_message_parse_options_list_changed (message, &o); - fail_unless (o == mopts); - gst_message_unref (message); - - /* Test mixer-changed */ - gst_mixer_mixer_changed (GST_MIXER (test_element)); - message = gst_bus_poll (bus, GST_MESSAGE_ELEMENT, GST_CLOCK_TIME_NONE); - fail_if (message == NULL); - fail_unless (gst_mixer_message_get_type (message) == - GST_MIXER_MESSAGE_MIXER_CHANGED); - gst_message_unref (message); - - gst_object_unref (mtrack); - gst_object_unref (mopts); - gst_object_unref (bus); - gst_object_unref (test_element); -} - -GST_END_TEST; - -static Suite * -mixer_suite (void) -{ - Suite *s = suite_create ("mixer interface"); - TCase *tc_chain = tcase_create ("notifications"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_messages); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = mixer_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/libs/navigation.c b/tests/check/libs/navigation.c deleted file mode 100644 index 4712947b..00000000 --- a/tests/check/libs/navigation.c +++ /dev/null @@ -1,351 +0,0 @@ -/* GStreamer - * - * unit tests for the navigation interface library - * - * Copyright (C) 2009 Jan Schmidt <thaytan@noraisin.net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/check/gstcheck.h> - -#include <gst/interfaces/navigation.h> - -#include <string.h> - -#define TEST_ELEMENT_TYPE (test_element_get_type()) - -typedef struct TestElement TestElement; -typedef struct TestElementClass TestElementClass; - -struct TestElement -{ - GstElement parent; - - GstNavigationEventType sent_type; - const gchar *sent_key; - gdouble sent_x, sent_y; - gint sent_button; - GstNavigationCommand sent_command; -}; - -struct TestElementClass -{ - GstElementClass parent_class; -}; - -static void init_interface (GType type); -static void gst_implements_interface_init (GstImplementsInterfaceClass * klass); -static void nav_send_event (GstNavigation * navigation, - GstStructure * structure); - -GST_BOILERPLATE_FULL (TestElement, test_element, GstElement, GST_TYPE_ELEMENT, - init_interface); - -static void -test_element_navigation_interface_init (GstNavigationInterface * klass) -{ - klass->send_event = nav_send_event; -} - -static void -init_interface (GType type) -{ - static const GInterfaceInfo navigation_iface_info = { - (GInterfaceInitFunc) test_element_navigation_interface_init, - NULL, - NULL, - }; - static const GInterfaceInfo implements_iface_info = { - (GInterfaceInitFunc) gst_implements_interface_init, - NULL, - NULL, - }; - - g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE, - &implements_iface_info); - g_type_add_interface_static (type, GST_TYPE_NAVIGATION, - &navigation_iface_info); -} - -static void -test_element_base_init (gpointer klass) -{ -} - -static void -test_element_class_init (TestElementClass * klass) -{ -} - -static gboolean -test_element_interface_supported (GstImplementsInterface * ifacE, - GType interface_type) -{ - if (interface_type == GST_TYPE_NAVIGATION) - return TRUE; - - return FALSE; -} - -static void -gst_implements_interface_init (GstImplementsInterfaceClass * klass) -{ - klass->supported = test_element_interface_supported; -} - -static void -test_element_init (TestElement * this, TestElementClass * klass) -{ -} - -static void -nav_send_event (GstNavigation * navigation, GstStructure * structure) -{ - GstEvent *event = gst_event_new_navigation (structure); - GstNavigationEventType etype = gst_navigation_event_get_type (event); - TestElement *self = (TestElement *) (navigation); - - fail_if (etype == GST_NAVIGATION_EVENT_INVALID, - "Received navigation event could not be parsed"); - fail_unless (etype == self->sent_type, - "Received navigation event did not match sent"); - - switch (etype) { - case GST_NAVIGATION_EVENT_KEY_PRESS: - case GST_NAVIGATION_EVENT_KEY_RELEASE:{ - const gchar *key; - fail_unless (gst_navigation_event_parse_key_event (event, &key)); - fail_unless (strcmp (key, self->sent_key) == 0); - break; - } - case GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS: - case GST_NAVIGATION_EVENT_MOUSE_BUTTON_RELEASE:{ - gint button; - gdouble x, y; - fail_unless (gst_navigation_event_parse_mouse_button_event (event, - &button, &x, &y)); - fail_unless (button == self->sent_button); - fail_unless (x == self->sent_x); - fail_unless (y == self->sent_y); - break; - } - case GST_NAVIGATION_EVENT_MOUSE_MOVE:{ - gdouble x, y; - fail_unless (gst_navigation_event_parse_mouse_move_event (event, &x, &y)); - fail_unless (x == self->sent_x); - fail_unless (y == self->sent_y); - break; - } - case GST_NAVIGATION_EVENT_COMMAND:{ - GstNavigationCommand cmd; - fail_unless (gst_navigation_event_parse_command (event, &cmd)); - fail_unless (cmd == self->sent_command); - } - default: - break; - } - - gst_event_unref (event); -} - -GST_START_TEST (test_events) -{ - /* Create an empty GstElement that has a GstNavigation interface and then - * send some navigation events and validate them */ - TestElement *test_element = - (TestElement *) g_object_new (TEST_ELEMENT_TYPE, NULL); - GstNavigationCommand cmds[] = { - GST_NAVIGATION_COMMAND_MENU1, GST_NAVIGATION_COMMAND_MENU2, - GST_NAVIGATION_COMMAND_MENU3, GST_NAVIGATION_COMMAND_MENU4, - GST_NAVIGATION_COMMAND_MENU5, GST_NAVIGATION_COMMAND_MENU6, - GST_NAVIGATION_COMMAND_MENU7, GST_NAVIGATION_COMMAND_LEFT, - GST_NAVIGATION_COMMAND_RIGHT, GST_NAVIGATION_COMMAND_UP, - GST_NAVIGATION_COMMAND_DOWN, GST_NAVIGATION_COMMAND_ACTIVATE, - GST_NAVIGATION_COMMAND_PREV_ANGLE, GST_NAVIGATION_COMMAND_NEXT_ANGLE - }; - gint i; - - test_element->sent_type = GST_NAVIGATION_EVENT_KEY_PRESS; - test_element->sent_key = "1"; - gst_navigation_send_key_event (GST_NAVIGATION (test_element), "key-press", - "1"); - - test_element->sent_type = GST_NAVIGATION_EVENT_KEY_RELEASE; - test_element->sent_key = "2"; - gst_navigation_send_key_event (GST_NAVIGATION (test_element), "key-release", - "2"); - - test_element->sent_type = GST_NAVIGATION_EVENT_MOUSE_MOVE; - test_element->sent_x = 50; - test_element->sent_y = 100; - gst_navigation_send_mouse_event (GST_NAVIGATION (test_element), "mouse-move", - 0, 50, 100); - - test_element->sent_type = GST_NAVIGATION_EVENT_MOUSE_BUTTON_PRESS; - test_element->sent_x = 10; - test_element->sent_y = 20; - test_element->sent_button = 1; - gst_navigation_send_mouse_event (GST_NAVIGATION (test_element), - "mouse-button-press", 1, 10, 20); - - for (i = 0; i < G_N_ELEMENTS (cmds); i++) { - test_element->sent_type = GST_NAVIGATION_EVENT_COMMAND; - test_element->sent_command = cmds[i]; - gst_navigation_send_command (GST_NAVIGATION (test_element), cmds[i]); - } - - gst_object_unref (test_element); -} - -GST_END_TEST; - -GST_START_TEST (test_messages) -{ - GstMessage *m; - /* GST_NAVIGATION_MESSAGE_MOUSE_OVER */ - { - gboolean active; - m = gst_navigation_message_new_mouse_over (NULL, TRUE); - fail_if (m == NULL); - fail_unless (gst_navigation_message_get_type (m) == - GST_NAVIGATION_MESSAGE_MOUSE_OVER); - fail_unless (GST_MESSAGE_SRC (m) == NULL); - fail_unless (gst_navigation_message_parse_mouse_over (m, &active)); - fail_unless (active == TRUE); - gst_message_unref (m); - - m = gst_navigation_message_new_mouse_over (NULL, FALSE); - fail_if (m == NULL); - fail_unless (GST_MESSAGE_SRC (m) == NULL); - fail_unless (gst_navigation_message_get_type (m) == - GST_NAVIGATION_MESSAGE_MOUSE_OVER); - fail_unless (gst_navigation_message_parse_mouse_over (m, &active)); - fail_unless (active == FALSE); - gst_message_unref (m); - } - - /* GST_NAVIGATION_MESSAGE_COMMANDS_CHANGED */ - { - m = gst_navigation_message_new_commands_changed (NULL); - fail_if (m == NULL); - fail_unless (GST_MESSAGE_SRC (m) == NULL); - fail_unless (gst_navigation_message_get_type (m) == - GST_NAVIGATION_MESSAGE_COMMANDS_CHANGED); - gst_message_unref (m); - } - - /* GST_NAVIGATION_MESSAGE_ANGLES_CHANGED */ - { - guint angle, angles; - m = gst_navigation_message_new_angles_changed (NULL, 1, 5); - fail_if (m == NULL); - fail_unless (GST_MESSAGE_SRC (m) == NULL); - fail_unless (gst_navigation_message_get_type (m) == - GST_NAVIGATION_MESSAGE_ANGLES_CHANGED); - fail_unless (gst_navigation_message_parse_angles_changed (m, &angle, - &angles)); - fail_unless (angle == 1); - fail_unless (angles == 5); - gst_message_unref (m); - } -} - -GST_END_TEST; - -GST_START_TEST (test_queries) -{ - GstQuery *q; - - /* GST_NAVIGATION_QUERY_COMMANDS */ - { - guint n; - GstNavigationCommand cmd; - - q = gst_navigation_query_new_commands (); - fail_unless (q != NULL); - fail_unless (gst_navigation_query_get_type (q) == - GST_NAVIGATION_QUERY_COMMANDS); - gst_navigation_query_set_commands (q, 3, GST_NAVIGATION_COMMAND_LEFT, - GST_NAVIGATION_COMMAND_MENU1, GST_NAVIGATION_COMMAND_MENU5); - fail_unless (gst_navigation_query_parse_commands_length (q, &n)); - fail_unless (n == 3); - fail_unless (gst_navigation_query_parse_commands_nth (q, 1, &cmd)); - fail_unless (cmd == GST_NAVIGATION_COMMAND_MENU1); - - fail_unless (gst_navigation_query_parse_commands_length (q, NULL)); - fail_unless (gst_navigation_query_parse_commands_nth (q, 2, NULL)); - - gst_query_unref (q); - } - - /* GST_NAVIGATION_QUERY_ANGLES */ - { - guint angle, angles; - q = gst_navigation_query_new_angles (); - fail_unless (q != NULL); - fail_unless (gst_navigation_query_get_type (q) == - GST_NAVIGATION_QUERY_ANGLES); - gst_navigation_query_set_angles (q, 4, 8); - fail_unless (gst_navigation_query_parse_angles (q, &angle, &angles)); - fail_unless (angle == 4); - fail_unless (angles == 8); - - fail_unless (gst_navigation_query_parse_angles (q, NULL, &angles)); - fail_unless (gst_navigation_query_parse_angles (q, &angle, NULL)); - fail_unless (gst_navigation_query_parse_angles (q, NULL, NULL)); - - gst_query_unref (q); - } - -} - -GST_END_TEST; - -static Suite * -navigation_suite (void) -{ - Suite *s = suite_create ("navigation interface"); - TCase *tc_chain = tcase_create ("notifications"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_events); - tcase_add_test (tc_chain, test_messages); - tcase_add_test (tc_chain, test_queries); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = navigation_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/libs/netbuffer.c b/tests/check/libs/netbuffer.c deleted file mode 100644 index 3236a0fa..00000000 --- a/tests/check/libs/netbuffer.c +++ /dev/null @@ -1,96 +0,0 @@ -/* GStreamer unit tests for libgstnetbuffer - * - * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <gst/check/gstcheck.h> -#include <gst/netbuffer/gstnetbuffer.h> - -#define DATA_STRING "Yoho this is a string" - -GST_START_TEST (test_netbuffer_copy) -{ - GstNetBuffer *netbuf, *copy; - guint8 ipv6_addr[16] = { 0xff, 0x11, 0xee, 0x22, 0xdd, 0x33, 0xcc, - 0x44, 0xbb, 0x55, 0xaa, 0x66, 0x00, 0x77, 0x99, 0x88 - }; - guint8 ipv6_copy[16]; - guint32 ipv4_copy, ipv4_addr = 0xfe12dc34; - guint16 ipv6_port = 3490; - guint16 ipv4_port = 5678; - guint16 port; - - netbuf = gst_netbuffer_new (); - fail_unless (netbuf != NULL, "failed to create net buffer"); - - gst_netaddress_set_ip4_address (&netbuf->from, ipv4_addr, ipv4_port); - gst_netaddress_set_ip6_address (&netbuf->to, ipv6_addr, ipv6_port); - - GST_BUFFER_DATA (netbuf) = (guint8 *) DATA_STRING; - GST_BUFFER_SIZE (netbuf) = strlen (DATA_STRING); - GST_BUFFER_FLAG_SET (netbuf, GST_BUFFER_FLAG_DISCONT); - GST_BUFFER_FLAG_SET (netbuf, GST_BUFFER_FLAG_READONLY); - - copy = (GstNetBuffer *) gst_buffer_copy (GST_BUFFER_CAST (netbuf)); - fail_unless (copy != NULL, "failed to copy net buffer"); - fail_unless (GST_IS_NETBUFFER (copy), "copied buffer is not a GstNetBuffer!"); - - fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT_VALUE (copy), 1); - - fail_unless_equals_int (GST_BUFFER_SIZE (copy), GST_BUFFER_SIZE (netbuf)); - fail_unless (memcmp (GST_BUFFER_DATA (copy), GST_BUFFER_DATA (netbuf), - GST_BUFFER_SIZE (copy)) == 0); - - fail_if (GST_BUFFER_FLAG_IS_SET (copy, GST_BUFFER_FLAG_READONLY)); - fail_unless (GST_BUFFER_FLAG_IS_SET (copy, GST_BUFFER_FLAG_DISCONT)); - - fail_unless (gst_netaddress_get_ip4_address (©->from, &ipv4_copy, &port)); - fail_unless (ipv4_copy == ipv4_addr, - "Copied buffer has wrong IPV4 from address"); - fail_unless (port == ipv4_port, "Copied buffer has wrong IPV4 from port"); - - fail_unless (gst_netaddress_get_ip6_address (©->to, ipv6_copy, &port)); - fail_unless (memcmp (ipv6_copy, ipv6_addr, 16) == 0, - "Copied buffer has wrong IPv6 destination address"); - fail_unless (port == ipv6_port, - "Copied buffer has wrong IPv6 destination port"); - - gst_buffer_unref (GST_BUFFER_CAST (netbuf)); - gst_buffer_unref (GST_BUFFER_CAST (copy)); -} - -GST_END_TEST; - -static Suite * -netbuffer_suite (void) -{ - Suite *s = suite_create ("netbuffer"); - TCase *tc_chain = tcase_create ("netbuffer"); - - suite_add_tcase (s, tc_chain); - - tcase_add_test (tc_chain, test_netbuffer_copy); - - return s; -} - -GST_CHECK_MAIN (netbuffer); diff --git a/tests/check/libs/pbutils.c b/tests/check/libs/pbutils.c deleted file mode 100644 index 61b8b609..00000000 --- a/tests/check/libs/pbutils.c +++ /dev/null @@ -1,724 +0,0 @@ -/* GStreamer unit tests for libgstpbutils - * - * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -# include <config.h> -#endif - -#include <gst/check/gstcheck.h> -#include <gst/pbutils/pbutils.h> - -#include <stdio.h> -#include <glib/gstdio.h> -#include <glib/gprintf.h> - -#ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> /* for chmod() and getpid () */ -#endif - -#ifdef HAVE_SYS_STAT_H -#include <sys/stat.h> /* for chmod() */ -#endif - -#ifdef HAVE_UNISTD_H -#include <unistd.h> /* for unlink() */ -#endif - -static void -missing_msg_check_getters (GstMessage * msg) -{ - gchar *str; - - str = gst_missing_plugin_message_get_installer_detail (msg); - fail_unless (str != NULL); - fail_unless (*str != '\0'); - fail_unless (g_str_has_prefix (str, "gstreamer|")); - g_free (str); - - str = gst_missing_plugin_message_get_description (msg); - fail_unless (str != NULL); - fail_unless (*str != '\0'); - g_free (str); -} - -GST_START_TEST (test_pb_utils_post_missing_messages) -{ - GstElement *pipeline; - GstStructure *s; - GstMessage *msg; - GstCaps *caps; - GstBus *bus; - - gst_pb_utils_init (); - - pipeline = gst_pipeline_new ("pipeline"); - bus = gst_element_get_bus (pipeline); - - /* first, test common assertion failure cases */ - ASSERT_CRITICAL (msg = gst_missing_uri_source_message_new (NULL, "http");); - ASSERT_CRITICAL (gst_missing_uri_source_message_new (pipeline, NULL)); - - ASSERT_CRITICAL (gst_missing_uri_sink_message_new (NULL, "http")); - ASSERT_CRITICAL (gst_missing_uri_sink_message_new (pipeline, NULL)); - - ASSERT_CRITICAL (gst_missing_element_message_new (NULL, "rgbfyltr")); - ASSERT_CRITICAL (gst_missing_element_message_new (pipeline, NULL)); - - caps = gst_caps_new_simple ("audio/x-dontexist", NULL); - - ASSERT_CRITICAL (gst_missing_decoder_message_new (NULL, caps)); - ASSERT_CRITICAL (gst_missing_decoder_message_new (pipeline, NULL)); - - ASSERT_CRITICAL (gst_missing_encoder_message_new (NULL, caps)); - ASSERT_CRITICAL (gst_missing_encoder_message_new (pipeline, NULL)); - - gst_caps_unref (caps); - - /* URI source (with existing protocol) */ - msg = gst_missing_uri_source_message_new (pipeline, "http"); - fail_unless (msg != NULL); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisource"); - fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "detail"), "http"); - missing_msg_check_getters (msg); - gst_message_unref (msg); - - /* URI sink (with existing protocol) */ - msg = gst_missing_uri_sink_message_new (pipeline, "smb"); - fail_unless (msg != NULL); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisink"); - fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "detail"), "smb"); - missing_msg_check_getters (msg); - gst_message_unref (msg); - - /* URI source (with bogus protocol) */ - msg = gst_missing_uri_source_message_new (pipeline, "chchck"); - fail_unless (msg != NULL); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisource"); - fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "detail"), "chchck"); - missing_msg_check_getters (msg); - gst_message_unref (msg); - - /* URI sink (with bogus protocol) */ - msg = gst_missing_uri_sink_message_new (pipeline, "chchck"); - fail_unless (msg != NULL); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "urisink"); - fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "detail"), "chchck"); - missing_msg_check_getters (msg); - gst_message_unref (msg); - - /* element */ - msg = gst_missing_element_message_new (pipeline, "foobar"); - fail_unless (msg != NULL); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "element"); - fail_unless (gst_structure_has_field_typed (s, "detail", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "detail"), "foobar"); - missing_msg_check_getters (msg); - gst_message_unref (msg); - - /* create bogus caps that don't exist */ - caps = gst_caps_new_simple ("do/x-not", "exist", G_TYPE_BOOLEAN, FALSE, NULL); - - /* decoder (with unknown caps) */ - msg = gst_missing_decoder_message_new (pipeline, caps); - fail_unless (msg != NULL); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "decoder"); - fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS)); - missing_msg_check_getters (msg); - gst_message_unref (msg); - - /* encoder (with unknown caps) */ - msg = gst_missing_encoder_message_new (pipeline, caps); - fail_unless (msg != NULL); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "encoder"); - fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS)); - missing_msg_check_getters (msg); - gst_message_unref (msg); - - gst_caps_unref (caps); - - /* create caps that exist */ - caps = gst_caps_new_simple ("video/x-matroska", NULL); - /* decoder (with known caps) */ - msg = gst_missing_decoder_message_new (pipeline, caps); - fail_unless (msg != NULL); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "decoder"); - fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS)); - fail_unless (gst_structure_has_field_typed (s, "name", G_TYPE_STRING)); - fail_unless (gst_structure_get_string (s, "name") != NULL); - missing_msg_check_getters (msg); - gst_message_unref (msg); - - /* encoder (with known caps) */ - msg = gst_missing_encoder_message_new (pipeline, caps); - fail_unless (msg != NULL); - fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_ELEMENT); - fail_unless (msg->structure != NULL); - s = msg->structure; - fail_unless (gst_structure_has_name (s, "missing-plugin")); - fail_unless (gst_structure_has_field_typed (s, "type", G_TYPE_STRING)); - fail_unless_equals_string (gst_structure_get_string (s, "type"), "encoder"); - fail_unless (gst_structure_has_field_typed (s, "detail", GST_TYPE_CAPS)); - fail_unless (gst_structure_has_field_typed (s, "name", G_TYPE_STRING)); - fail_unless (gst_structure_get_string (s, "name") != NULL); - missing_msg_check_getters (msg); - gst_message_unref (msg); - - gst_caps_unref (caps); - - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - gst_object_unref (bus); -} - -GST_END_TEST; - -GST_START_TEST (test_pb_utils_init) -{ - /* should be fine to call multiple times */ - gst_pb_utils_init (); - gst_pb_utils_init (); - gst_pb_utils_init (); - gst_pb_utils_init (); -} - -GST_END_TEST; - -static const gchar *caps_strings[] = { - /* formats with static descriptions */ - "application/ogg", "application/vnd.rn-realmedia", "video/x-fli", - "video/x-flv", "video/x-matroska", "video/x-ms-asf", "video/x-msvideo", - "video/x-quicktime", "video/quicktime", "audio/x-ac3", "audio/ac3", - "audio/x-private-ac3", "audio/x-private1-ac3", "audio/x-adpcm", - "audio/aiff", "audio/x-alaw", "audio/amr", "audio/AMR", "audio/AMR-WB", - "audio/iLBC-sh", "audio/ms-gsm", "audio/qcelp", "audio/x-adpcm", - "audio/x-aiff", "audio/x-alac", "audio/x-amr-nb-sh", "audio/x-amr-wb-sh", - "audio/x-au", "audio/x-cinepak", "audio/x-dpcm", "audio/x-dts", - "audio/x-dv", "audio/x-flac", "audio/x-gsm", "audio/x-iec958", - "audio/x-iLBC", "audio/x-ircam", "audio/x-lpcm", "audio/x-private1-lpcm", - "audio/x-m4a", "audio/x-mod", "audio/x-mulaw", "audio/x-musepack", - "audio/x-nist", "audio/x-nsf", "audio/x-paris", "audio/x-qdm2", - "audio/x-ralf-mpeg4-generic", "audio/x-sds", "audio/x-shorten", - "audio/x-sid", "audio/x-sipro", "audio/x-spc", "audio/x-speex", - "audio/x-svx", "audio/x-tta", "audio/x-ttafile", - "audio/x-vnd.sony.atrac3", "audio/x-vorbis", "audio/x-voc", "audio/x-w64", - "audio/x-wav", "audio/x-wavpack", "audio/x-wavpack-correction", - "audio/x-wms", "audio/x-voxware", "video/sp5x", "video/vivo", - "video/x-3ivx", "video/x-4xm", "video/x-apple-video", "video/x-camtasia", - "video/x-cdxa", "video/x-cinepak", "video/x-cirrus-logic-accupak", - "video/x-compressed-yuv", "video/x-dirac", "video/x-dvd-subpicture", - "video/x-ffv", "video/x-flash-screen", "video/x-flash-video", - "video/x-h261", "video/x-huffyuv", "video/x-intel-h263", "video/x-jpeg", - "video/x-mjpeg", "video/x-mjpeg-b", "video/mpegts", "video/x-mng", - "video/x-mszh", "video/x-msvideocodec", "video/x-mve", "video/x-nut", - "video/x-nuv", "video/x-qdrw", "video/x-raw-gray", "video/x-smc", - "video/x-smoke", "video/x-tarkin", "video/x-theora", "video/x-rle", - "video/x-ultimotion", "video/x-vcd", "video/x-vmnc", "video/x-vp3", - "video/x-vp5", "video/x-vp6", "video/x-vp6-flash", "video/x-vp7", - "video/x-xvid", "video/x-zlib", "image/bmp", "image/x-bmp", - "image/x-MS-bmp", "image/gif", "image/jpeg", "image/jng", "image/png", - "image/pbm", "image/ppm", "image/svg+xml", "image/tiff", - "image/x-cmu-raster", "image/x-icon", "image/x-xcf", "image/x-pixmap", - "image/x-xpixmap", "image/x-quicktime", "image/x-sun-raster", - "image/x-tga", "video/x-dv", "video/x-dv", - /* some RTP formats */ - "application/x-rtp, media=(string)video, encoding-name=(string)TimVCodec", - "application/x-rtp, media=(string)audio, encoding-name=(string)TimACodec", - "application/x-rtp, media=(string)application, encoding-name=(string)TimMux", - "application/x-rtp, media=(string)woohoo, encoding-name=(string)TPM", - /* incomplete RTP formats */ - "application/x-rtp, media=(string)woohoo", - "application/x-rtp, encoding-name=(string)TPM", - "application/x-rtp, media=(string)woohoo", - /* formats with dynamic descriptions */ - "audio/x-adpcm", - "audio/x-adpcm, layout=(string)dvi", - "audio/x-adpcm, layout=(string)swf", - "audio/x-adpcm, layout=(string)microsoft", - "audio/x-adpcm, layout=(string)quicktime", - "audio/mpeg, mpegversion=(int)4", - "audio/mpeg, mpegversion=(int)1, layer=(int)1", - "audio/mpeg, mpegversion=(int)1, layer=(int)2", - "audio/mpeg, mpegversion=(int)1, layer=(int)3", - "audio/mpeg, mpegversion=(int)1, layer=(int)99", - "audio/mpeg, mpegversion=(int)99", - "video/mpeg, mpegversion=(int)2, systemstream=(boolean)TRUE", - "video/mpeg, systemstream=(boolean)FALSE", - "video/mpeg, mpegversion=(int)2", - "video/mpeg, mpegversion=(int)1, systemstream=(boolean)FALSE", - "video/mpeg, mpegversion=(int)2, systemstream=(boolean)FALSE", - "video/mpeg, mpegversion=(int)4, systemstream=(boolean)FALSE", - "video/mpeg, mpegversion=(int)99, systemstream=(boolean)TRUE", - "video/mpeg, mpegversion=(int)99, systemstream=(boolean)FALSE", - "video/mpeg", - "video/x-indeo, indeoversion=(int)3", - "video/x-indeo, indeoversion=(int)5", - "video/x-indeo", - "video/x-wmv, wmvversion=(int)1", - "video/x-wmv, wmvversion=(int)2", - "video/x-wmv, wmvversion=(int)3", - "video/x-wmv, wmvversion=(int)99", - "video/x-wmv", - "audio/x-wma, wmaversion=(int)1", - "audio/x-wma, wmaversion=(int)2", - "audio/x-wma, wmaversion=(int)3", - "audio/x-wma, wmaversion=(int)99", - "audio/x-wma", - "video/x-divx, divxversion=(int)3", - "video/x-divx, divxversion=(int)4", - "video/x-divx, divxversion=(int)5", - "video/x-divx, divxversion=(int)99", - "video/x-divx", - "video/x-svq, svqversion=(int)1", - "video/x-svq, svqversion=(int)3", - "video/x-svq, svqversion=(int)99", - "video/x-svq", - "video/x-h264, variant=(string)itu", - "video/x-h264, variant=(string)videosoft", - "video/x-h264, variant=(string)foobar", - "video/x-h264", - "video/x-h263, variant=(string)itu", - "video/x-h263, variant=(string)lead", - "video/x-h263, variant=(string)microsoft", - "video/x-h263, variant=(string)vdolive", - "video/x-h263, variant=(string)vivo", - "video/x-h263, variant=(string)xirlink", - "video/x-h263, variant=(string)foobar", - "video/x-h263", - "video/x-msmpeg, msmpegversion=(int)41", - "video/x-msmpeg, msmpegversion=(int)42", - "video/x-msmpeg, msmpegversion=(int)43", - "video/x-msmpeg, msmpegversion=(int)99", - "video/x-msmpeg", - "video/x-pn-realvideo, rmversion=(int)1", - "video/x-pn-realvideo, rmversion=(int)2", - "video/x-pn-realvideo, rmversion=(int)3", - "video/x-pn-realvideo, rmversion=(int)4", - "video/x-pn-realvideo, rmversion=(int)99", - "video/x-pn-realvideo", - "audio/x-pn-realaudio, raversion=(int)1", - "audio/x-pn-realaudio, raversion=(int)2", - "audio/x-pn-realaudio, raversion=(int)99", - "audio/x-pn-realaudio", - "audio/x-mace, maceversion=(int)3", - "audio/x-mace, maceversion=(int)6", - "audio/x-mace, maceversion=(int)99", - "audio/x-mace", - "video/x-truemotion, trueversion=(int)1", - "video/x-truemotion, trueversion=(int)2", - "video/x-truemotion, trueversion=(int)99", - "video/x-truemotion", - "video/x-asus, asusversion=(int)1", - "video/x-asus, asusversion=(int)2", - "video/x-asus, asusversion=(int)99", - "video/x-asus", - "video/x-xan, wcversion=(int)1", - "video/x-xan, wcversion=(int)99", - "video/x-xan", - "video/x-ati-vcr, vcrversion=(int)1", - "video/x-ati-vcr, vcrversion=(int)2", - "video/x-ati-vcr, vcrversion=(int)99", - "video/x-ati-vcr", - /* raw audio */ - "audio/x-raw-int, endianness=(int)1234, signed=(boolean)true, width=(int)16, depth=(int)16, rate=(int)44100, channels=(int)2", - "audio/x-raw-float, rate=(int)22050, channels=(int)2, endianness=(int)1234, width=(int)32", - /* raw video */ - "video/x-raw-rgb, bpp=(int)16, endianness=(int)1234, depth=(int)16, red_mask=(int)63488, green_mask=(int)2016, blue_mask=(int)31, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)1/1", - "video/x-raw-yuv, format=(fourcc)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1", - /* and a made-up format */ - "video/x-tpm" -}; - -GST_START_TEST (test_pb_utils_get_codec_description) -{ - gint i; - - gst_pb_utils_init (); - - for (i = 0; i < G_N_ELEMENTS (caps_strings); ++i) { - GstCaps *caps; - gchar *desc; - - caps = gst_caps_from_string (caps_strings[i]); - fail_unless (caps != NULL, "could not create caps from string '%s'", - caps_strings[i]); - GST_LOG ("Caps %s:", caps_strings[i]); - desc = gst_pb_utils_get_codec_description (caps); - fail_unless (desc != NULL); - GST_LOG (" - codec : %s", desc); - g_free (desc); - desc = gst_pb_utils_get_decoder_description (caps); - fail_unless (desc != NULL); - GST_LOG (" - decoder : %s", desc); - g_free (desc); - desc = gst_pb_utils_get_encoder_description (caps); - fail_unless (desc != NULL); - GST_LOG (" - encoder : %s", desc); - g_free (desc); - gst_caps_unref (caps); - } -} - -GST_END_TEST; - - -GST_START_TEST (test_pb_utils_taglist_add_codec_info) -{ - GstTagList *list; - GstCaps *caps; - - gst_pb_utils_init (); - list = gst_tag_list_new (); - caps = gst_caps_new_simple ("video/x-theora", NULL); - ASSERT_CRITICAL (fail_if - (gst_pb_utils_add_codec_description_to_tag_list (NULL, - GST_TAG_VIDEO_CODEC, caps))); - ASSERT_CRITICAL (fail_if - (gst_pb_utils_add_codec_description_to_tag_list (list, NULL, caps))); - ASSERT_CRITICAL (fail_if - (gst_pb_utils_add_codec_description_to_tag_list (list, "asdfa", caps))); - ASSERT_CRITICAL (fail_if - (gst_pb_utils_add_codec_description_to_tag_list (list, - GST_TAG_IMAGE, caps))); - ASSERT_CRITICAL (fail_if - (gst_pb_utils_add_codec_description_to_tag_list (list, - GST_TAG_VIDEO_CODEC, NULL))); - /* FIXME: do something here */ - fail_unless (gst_pb_utils_add_codec_description_to_tag_list (list, - GST_TAG_VIDEO_CODEC, caps)); - fail_if (gst_tag_list_is_empty (list)); - gst_tag_list_free (list); - gst_caps_unref (caps); -} - -GST_END_TEST; - -static gint marker; - -static void -result_cb (GstInstallPluginsReturn result, gpointer user_data) -{ - GST_LOG ("result = %u, user_data = %p", result, user_data); - - fail_unless (user_data == (gpointer) & marker); - - marker = result; -} - -#define SCRIPT_NO_XID \ - "#!/bin/sh\n" \ - "if test x$1 != xdetail1; then exit 21; fi;\n" \ - "if test x$2 != xdetail2; then exit 22; fi;\n" \ - "exit 1\n" - -#define SCRIPT_WITH_XID \ - "#!/bin/sh\n" \ - "if test x$1 != 'x--transient-for=42'; then exit 21; fi;\n" \ - "if test x$2 != xdetail1; then exit 22; fi;\n" \ - "if test x$3 != xdetail2; then exit 23; fi;\n" \ - "exit 0\n" - -/* make sure our script gets called with the right parameters */ -static void -test_pb_utils_install_plugins_do_callout (gchar ** details, - GstInstallPluginsContext * ctx, const gchar * script, - GstInstallPluginsReturn expected_result) -{ -#ifdef G_OS_UNIX - GstInstallPluginsReturn ret; - GError *err = NULL; - gchar *path; - - path = g_strdup_printf ("%s/gst-plugins-base-unit-test-helper.%s.%lu", - g_get_tmp_dir (), (g_get_user_name ())? g_get_user_name () : "nobody", - (gulong) getpid ()); - - if (!g_file_set_contents (path, script, -1, &err)) { - GST_DEBUG ("Failed to write test script to %s: %s", path, err->message); - g_error_free (err); - goto done; - } - - if (chmod (path, S_IRUSR | S_IWUSR | S_IXUSR) != 0) { - GST_DEBUG ("Could not set mode u+rwx on '%s'", path); - goto done; - } - - /* test gst_install_plugins_supported() I */ - g_setenv ("GST_INSTALL_PLUGINS_HELPER", "/i/do/not/ex.ist!", 1); - fail_if (gst_install_plugins_supported ()); - - GST_LOG ("setting GST_INSTALL_PLUGINS_HELPER to '%s'", path); - g_setenv ("GST_INSTALL_PLUGINS_HELPER", path, 1); - - /* test gst_install_plugins_supported() II */ - fail_unless (gst_install_plugins_supported ()); - - /* test sync callout */ - ret = gst_install_plugins_sync (details, ctx); - fail_unless (ret == GST_INSTALL_PLUGINS_HELPER_MISSING || - ret == expected_result, - "gst_install_plugins_sync() failed with unexpected ret %d, which is " - "neither HELPER_MISSING nor %d", ret, expected_result); - - /* test async callout */ - marker = -333; - ret = gst_install_plugins_async (details, ctx, result_cb, - (gpointer) & marker); - fail_unless (ret == GST_INSTALL_PLUGINS_HELPER_MISSING || - ret == GST_INSTALL_PLUGINS_STARTED_OK, - "gst_install_plugins_async() failed with unexpected ret %d", ret); - if (ret == GST_INSTALL_PLUGINS_STARTED_OK) { - while (marker == -333) { - g_usleep (500); - g_main_context_iteration (NULL, FALSE); - } - /* and check that the callback was called with the expected code */ - fail_unless_equals_int (marker, expected_result); - } - -done: - - unlink (path); - g_free (path); -#endif /* G_OS_UNIX */ -} - -GST_START_TEST (test_pb_utils_install_plugins) -{ - GstInstallPluginsContext *ctx; - GstInstallPluginsReturn ret; - gchar *details[] = { "detail1", "detail2", NULL }; - gchar *details_multi[] = { "detail1", "detail1", "detail2", NULL }; - - ctx = gst_install_plugins_context_new (); - - ASSERT_CRITICAL (ret = gst_install_plugins_sync (NULL, ctx); - ); - ASSERT_CRITICAL (ret = - gst_install_plugins_async (NULL, ctx, result_cb, (gpointer) & marker); - ); - ASSERT_CRITICAL (ret = - gst_install_plugins_async (details, ctx, NULL, (gpointer) & marker); - ); - - /* make sure the functions return the right error code if the helper does - * not exist */ - g_setenv ("GST_INSTALL_PLUGINS_HELPER", "/does/not/ex/is.t", 1); - ret = gst_install_plugins_sync (details, NULL); - fail_unless_equals_int (ret, GST_INSTALL_PLUGINS_HELPER_MISSING); - - marker = -333; - ret = - gst_install_plugins_async (details, NULL, result_cb, (gpointer) & marker); - fail_unless_equals_int (ret, GST_INSTALL_PLUGINS_HELPER_MISSING); - /* and check that the callback wasn't called */ - fail_unless_equals_int (marker, -333); - - /* now make sure our scripts are actually called as expected (if possible) */ - test_pb_utils_install_plugins_do_callout (details, NULL, SCRIPT_NO_XID, - GST_INSTALL_PLUGINS_NOT_FOUND); - - /* and again with context */ - gst_install_plugins_context_set_xid (ctx, 42); - test_pb_utils_install_plugins_do_callout (details, ctx, SCRIPT_WITH_XID, - GST_INSTALL_PLUGINS_SUCCESS); - - /* and make sure that duplicate detail strings get dropped */ - test_pb_utils_install_plugins_do_callout (details_multi, NULL, SCRIPT_NO_XID, - GST_INSTALL_PLUGINS_NOT_FOUND); - - /* and the same again with context */ - gst_install_plugins_context_set_xid (ctx, 42); - test_pb_utils_install_plugins_do_callout (details_multi, ctx, SCRIPT_WITH_XID, - GST_INSTALL_PLUGINS_SUCCESS); - - /* and free the context now that we don't need it any longer */ - gst_install_plugins_context_free (ctx); - - /* completely silly test to check gst_install_plugins_return_get_name() - * is somewhat well-behaved */ - { - gint i; - - for (i = -99; i < 16738; ++i) { - const gchar *s; - - s = gst_install_plugins_return_get_name ((GstInstallPluginsReturn) i); - fail_unless (s != NULL); - /* GST_LOG ("%5d = %s", i, s); */ - } - } -} - -GST_END_TEST; - -GST_START_TEST (test_pb_utils_installer_details) -{ - GstMessage *msg; - GstElement *el; - GstCaps *caps; - gchar *detail1, *detail2; - - el = gst_pipeline_new ("dummy-element"); - - /* uri source */ - detail1 = gst_missing_uri_source_installer_detail_new ("http"); - fail_unless (detail1 != NULL); - fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|")); - fail_unless (g_str_has_suffix (detail1, "|urisource-http")); - msg = gst_missing_uri_source_message_new (el, "http"); - fail_unless (msg != NULL); - detail2 = gst_missing_plugin_message_get_installer_detail (msg); - fail_unless (detail2 != NULL); - gst_message_unref (msg); - fail_unless_equals_string (detail1, detail2); - g_free (detail1); - g_free (detail2); - - /* uri sink */ - detail1 = gst_missing_uri_sink_installer_detail_new ("http"); - fail_unless (detail1 != NULL); - fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|")); - fail_unless (g_str_has_suffix (detail1, "|urisink-http")); - msg = gst_missing_uri_sink_message_new (el, "http"); - fail_unless (msg != NULL); - detail2 = gst_missing_plugin_message_get_installer_detail (msg); - fail_unless (detail2 != NULL); - gst_message_unref (msg); - fail_unless_equals_string (detail1, detail2); - g_free (detail1); - g_free (detail2); - - /* element */ - detail1 = gst_missing_element_installer_detail_new ("deinterlace"); - fail_unless (detail1 != NULL); - fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|")); - fail_unless (g_str_has_suffix (detail1, "|element-deinterlace")); - msg = gst_missing_element_message_new (el, "deinterlace"); - fail_unless (msg != NULL); - detail2 = gst_missing_plugin_message_get_installer_detail (msg); - fail_unless (detail2 != NULL); - gst_message_unref (msg); - fail_unless_equals_string (detail1, detail2); - g_free (detail1); - g_free (detail2); - - /* decoder */ - caps = gst_caps_new_simple ("audio/x-spiffy", "spiffyversion", G_TYPE_INT, - 2, "channels", G_TYPE_INT, 6, NULL); - detail1 = gst_missing_decoder_installer_detail_new (caps); - fail_unless (detail1 != NULL); - fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|")); - fail_unless (g_str_has_suffix (detail1, - "|decoder-audio/x-spiffy, spiffyversion=(int)2")); - msg = gst_missing_decoder_message_new (el, caps); - fail_unless (msg != NULL); - detail2 = gst_missing_plugin_message_get_installer_detail (msg); - fail_unless (detail2 != NULL); - gst_message_unref (msg); - gst_caps_unref (caps); - fail_unless_equals_string (detail1, detail2); - g_free (detail1); - g_free (detail2); - - /* encoder */ - caps = gst_caps_new_simple ("audio/x-spiffy", "spiffyversion", G_TYPE_INT, - 2, "channels", G_TYPE_INT, 6, NULL); - detail1 = gst_missing_encoder_installer_detail_new (caps); - fail_unless (g_str_has_prefix (detail1, "gstreamer|0.10|")); - fail_unless (g_str_has_suffix (detail1, - "|encoder-audio/x-spiffy, spiffyversion=(int)2")); - fail_unless (detail1 != NULL); - msg = gst_missing_encoder_message_new (el, caps); - fail_unless (msg != NULL); - detail2 = gst_missing_plugin_message_get_installer_detail (msg); - fail_unless (detail2 != NULL); - gst_message_unref (msg); - gst_caps_unref (caps); - fail_unless_equals_string (detail1, detail2); - g_free (detail1); - g_free (detail2); - - gst_object_unref (el); -} - -GST_END_TEST; - -static Suite * -libgstpbutils_suite (void) -{ - Suite *s = suite_create ("pbutils library"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_pb_utils_init); - tcase_add_test (tc_chain, test_pb_utils_post_missing_messages); - tcase_add_test (tc_chain, test_pb_utils_taglist_add_codec_info); - tcase_add_test (tc_chain, test_pb_utils_get_codec_description); - tcase_add_test (tc_chain, test_pb_utils_install_plugins); - tcase_add_test (tc_chain, test_pb_utils_installer_details); - return s; -} - -GST_CHECK_MAIN (libgstpbutils); diff --git a/tests/check/libs/rtp.c b/tests/check/libs/rtp.c deleted file mode 100644 index e19c96cd..00000000 --- a/tests/check/libs/rtp.c +++ /dev/null @@ -1,469 +0,0 @@ -/* GStreamer unit tests for the RTP support library - * - * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/check/gstcheck.h> - -#include <gst/rtp/gstrtpbuffer.h> -#include <gst/rtp/gstrtcpbuffer.h> -#include <string.h> - -#define RTP_HEADER_LEN 12 - -GST_START_TEST (test_rtp_buffer) -{ - GstBuffer *buf; - guint8 *data; - - /* check GstRTPHeader structure alignment and packing */ - buf = gst_rtp_buffer_new_allocate (16, 4, 0); - fail_unless (buf != NULL); - fail_unless_equals_int (GST_BUFFER_SIZE (buf), RTP_HEADER_LEN + 16 + 4); - data = GST_BUFFER_DATA (buf); - - /* check defaults */ - fail_unless_equals_int (gst_rtp_buffer_get_version (buf), 2); - fail_unless (gst_rtp_buffer_get_padding (buf) == FALSE); - fail_unless (gst_rtp_buffer_get_extension (buf) == FALSE); - fail_unless_equals_int (gst_rtp_buffer_get_csrc_count (buf), 0); - fail_unless (gst_rtp_buffer_get_marker (buf) == FALSE); - fail_unless (gst_rtp_buffer_get_payload_type (buf) == 0); - fail_unless_equals_int (GST_READ_UINT16_BE (data), 0x8000); - - /* check version in bitfield */ - gst_rtp_buffer_set_version (buf, 3); - fail_unless_equals_int (gst_rtp_buffer_get_version (buf), 3); - fail_unless_equals_int ((data[0] & 0xC0) >> 6, 3); - gst_rtp_buffer_set_version (buf, 2); - fail_unless_equals_int (gst_rtp_buffer_get_version (buf), 2); - fail_unless_equals_int ((data[0] & 0xC0) >> 6, 2); - - /* check padding bit */ - gst_rtp_buffer_set_padding (buf, TRUE); - fail_unless (gst_rtp_buffer_get_padding (buf) == TRUE); - fail_unless_equals_int ((data[0] & 0x20) >> 5, 1); - gst_rtp_buffer_set_padding (buf, FALSE); - fail_unless (gst_rtp_buffer_get_padding (buf) == FALSE); - fail_unless_equals_int ((data[0] & 0x20) >> 5, 0); - - /* check marker bit */ - gst_rtp_buffer_set_marker (buf, TRUE); - fail_unless (gst_rtp_buffer_get_marker (buf) == TRUE); - fail_unless_equals_int ((data[1] & 0x80) >> 7, 1); - gst_rtp_buffer_set_marker (buf, FALSE); - fail_unless (gst_rtp_buffer_get_marker (buf) == FALSE); - fail_unless_equals_int ((data[1] & 0x80) >> 7, 0); - - /* check sequence offset */ - gst_rtp_buffer_set_seq (buf, 0xF2C9); - fail_unless_equals_int (gst_rtp_buffer_get_seq (buf), 0xF2C9); - fail_unless_equals_int (GST_READ_UINT16_BE (data + 2), 0xF2C9); - gst_rtp_buffer_set_seq (buf, 0); - fail_unless_equals_int (gst_rtp_buffer_get_seq (buf), 0); - fail_unless_equals_int (GST_READ_UINT16_BE (data + 2), 0); - - /* check timestamp offset */ - gst_rtp_buffer_set_timestamp (buf, 432191); - fail_unless_equals_int (GST_READ_UINT32_BE (data + 4), 432191); - fail_unless_equals_int (gst_rtp_buffer_get_timestamp (buf), 432191); - gst_rtp_buffer_set_timestamp (buf, 0); - fail_unless_equals_int (gst_rtp_buffer_get_timestamp (buf), 0); - fail_unless_equals_int (GST_READ_UINT32_BE (data + 4), 0); - - /* check ssrc offset */ - gst_rtp_buffer_set_ssrc (buf, 0xf04043C2); - fail_unless_equals_int (gst_rtp_buffer_get_ssrc (buf), (gint) 0xf04043c2); - fail_unless_equals_int (GST_READ_UINT32_BE (data + 4 + 4), (gint) 0xf04043c2); - gst_rtp_buffer_set_ssrc (buf, 0); - fail_unless_equals_int (gst_rtp_buffer_get_ssrc (buf), 0); - fail_unless_equals_int (GST_READ_UINT32_BE (data + 4 + 4), 0); - - /* check csrc bits */ - fail_unless_equals_int (gst_rtp_buffer_get_csrc_count (buf), 0); - ASSERT_CRITICAL (gst_rtp_buffer_get_csrc (buf, 0)); - fail_unless_equals_int (data[0] & 0xf, 0); - gst_buffer_unref (buf); - - /* and again, this time with CSRCs */ - buf = gst_rtp_buffer_new_allocate (16, 4, 3); - fail_unless (buf != NULL); - fail_unless_equals_int (GST_BUFFER_SIZE (buf), - RTP_HEADER_LEN + 16 + 4 + 4 * 3); - - data = GST_BUFFER_DATA (buf); - - fail_unless_equals_int (gst_rtp_buffer_get_csrc_count (buf), 3); - ASSERT_CRITICAL (gst_rtp_buffer_get_csrc (buf, 3)); - fail_unless_equals_int (data[0] & 0xf, 3); - fail_unless_equals_int (gst_rtp_buffer_get_csrc (buf, 0), 0); - fail_unless_equals_int (gst_rtp_buffer_get_csrc (buf, 1), 0); - fail_unless_equals_int (gst_rtp_buffer_get_csrc (buf, 2), 0); - - data += RTP_HEADER_LEN; /* skip the other header stuff */ - gst_rtp_buffer_set_csrc (buf, 0, 0xf7c0); - fail_unless_equals_int (GST_READ_UINT32_BE (data + 0 * 4), 0xf7c0); - gst_rtp_buffer_set_csrc (buf, 1, 0xf7c1); - fail_unless_equals_int (GST_READ_UINT32_BE (data + 1 * 4), 0xf7c1); - gst_rtp_buffer_set_csrc (buf, 2, 0xf7c2); - fail_unless_equals_int (GST_READ_UINT32_BE (data + 2 * 4), 0xf7c2); - ASSERT_CRITICAL (gst_rtp_buffer_set_csrc (buf, 3, 0xf123)); - gst_buffer_unref (buf); -} - -GST_END_TEST; - -GST_START_TEST (test_rtp_buffer_validate_corrupt) -{ - GstBuffer *buf; - guint8 corrupt_rtp_packet[58] = { - 0x90, 0x7a, 0xbf, 0x28, 0x3a, 0x8a, 0x0a, 0xf4, 0x69, 0x6b, 0x76, 0xc0, - 0x21, 0xe0, 0xe0, 0x60, 0x81, 0x10, 0x84, 0x30, 0x21, 0x52, 0x06, 0xc2, - 0xb8, 0x30, 0x10, 0x4c, 0x08, 0x62, 0x67, 0xc2, 0x6e, 0x1a, 0x53, 0x3f, - 0xaf, 0xd6, 0x1b, 0x29, 0x40, 0xe0, 0xa5, 0x83, 0x01, 0x4b, 0x04, 0x02, - 0xb0, 0x97, 0x63, 0x08, 0x10, 0x4b, 0x43, 0x85, 0x37, 0x2c - }; - - buf = gst_buffer_new (); - GST_BUFFER_DATA (buf) = corrupt_rtp_packet; - GST_BUFFER_SIZE (buf) = sizeof (corrupt_rtp_packet); - fail_if (gst_rtp_buffer_validate (buf)); - gst_buffer_unref (buf); -} - -GST_END_TEST; - -GST_START_TEST (test_rtp_buffer_list) -{ - GstBuffer *rtp_header; - GstBuffer *rtp_payload; - GstBufferList *list = NULL; - GstBufferListIterator *it; - guint i; - - list = gst_buffer_list_new (); - it = gst_buffer_list_iterate (list); - - /* Creating a list of two RTP packages */ - - /* Create first group to hold the rtp header and the payload */ - gst_buffer_list_iterator_add_group (it); - rtp_header = gst_rtp_buffer_new_allocate (0, 0, 0); - gst_buffer_list_iterator_add (it, rtp_header); - rtp_payload = gst_buffer_new_and_alloc (42); - gst_buffer_list_iterator_add (it, rtp_payload); - - /* Create second group to hold an rtp header and a payload */ - gst_buffer_list_iterator_add_group (it); - rtp_header = gst_rtp_buffer_new_allocate (0, 0, 0); - gst_buffer_list_iterator_add (it, rtp_header); - rtp_payload = gst_buffer_new_and_alloc (42); - gst_buffer_list_iterator_add (it, rtp_payload); - - gst_buffer_list_iterator_free (it); - - /* Test SEQ number */ - i = gst_rtp_buffer_list_set_seq (list, 1024); - fail_if (1026 != i); - fail_if (!gst_rtp_buffer_list_validate (list)); - - /* Timestamp */ - gst_rtp_buffer_list_set_timestamp (list, 432191); - fail_unless_equals_int (gst_rtp_buffer_list_get_timestamp (list), 432191); - - /* SSRC */ - gst_rtp_buffer_list_set_ssrc (list, 0xf04043C2); - fail_unless_equals_int (gst_rtp_buffer_list_get_ssrc (list), - (gint) 0xf04043c2); - - /* Payload type */ - gst_rtp_buffer_list_set_payload_type (list, 127); - fail_unless_equals_int (gst_rtp_buffer_list_get_payload_type (list), 127); - - gst_buffer_list_unref (list); -} - -GST_END_TEST; - -GST_START_TEST (test_rtp_buffer_set_extension_data) -{ - GstBuffer *buf; - guint8 *data; - guint16 bits; - guint size; - gpointer pointer; - - /* check GstRTPHeader structure alignment and packing */ - buf = gst_rtp_buffer_new_allocate (4, 0, 0); - data = GST_BUFFER_DATA (buf); - - /* should be impossible to set the extension data */ - ASSERT_WARNING (fail_unless (gst_rtp_buffer_set_extension_data (buf, 0, - 4) == FALSE)); - fail_unless (gst_rtp_buffer_get_extension (buf) == FALSE); - - /* should be possible to set the extension data */ - fail_unless (gst_rtp_buffer_set_extension_data (buf, 270, 0) == TRUE); - fail_unless (gst_rtp_buffer_get_extension (buf) == TRUE); - gst_rtp_buffer_get_extension_data (buf, &bits, &pointer, &size); - fail_unless (bits == 270); - fail_unless (size == 0); - fail_unless (pointer == GST_BUFFER_DATA (buf) + 16); - pointer = gst_rtp_buffer_get_payload (buf); - fail_unless (pointer == GST_BUFFER_DATA (buf) + 16); - gst_buffer_unref (buf); - - buf = gst_rtp_buffer_new_allocate (20, 0, 0); - data = GST_BUFFER_DATA (buf); - fail_unless (gst_rtp_buffer_get_extension (buf) == FALSE); - fail_unless (gst_rtp_buffer_set_extension_data (buf, 333, 2) == TRUE); - fail_unless (gst_rtp_buffer_get_extension (buf) == TRUE); - gst_rtp_buffer_get_extension_data (buf, &bits, &pointer, &size); - fail_unless (bits == 333); - fail_unless (size == 2); - fail_unless (pointer == GST_BUFFER_DATA (buf) + 16); - pointer = gst_rtp_buffer_get_payload (buf); - fail_unless (pointer == GST_BUFFER_DATA (buf) + 24); - gst_buffer_unref (buf); -} - -GST_END_TEST; - -GST_START_TEST (test_rtp_seqnum_compare) -{ -#define ASSERT_COMP(a,b,c) fail_unless (gst_rtp_buffer_compare_seqnum ((guint16)a,(guint16)b) == c); - ASSERT_COMP (0xfffe, 0xfffd, -1); - ASSERT_COMP (0xffff, 0xfffe, -1); - ASSERT_COMP (0x0000, 0xffff, -1); - ASSERT_COMP (0x0001, 0x0000, -1); - ASSERT_COMP (0x0002, 0x0001, -1); - - ASSERT_COMP (0xffff, 0xfffd, -2); - ASSERT_COMP (0x0000, 0xfffd, -3); - ASSERT_COMP (0x0001, 0xfffd, -4); - ASSERT_COMP (0x0002, 0xfffd, -5); - - ASSERT_COMP (0x7ffe, 0x7ffd, -1); - ASSERT_COMP (0x7fff, 0x7ffe, -1); - ASSERT_COMP (0x8000, 0x7fff, -1); - ASSERT_COMP (0x8001, 0x8000, -1); - ASSERT_COMP (0x8002, 0x8001, -1); - - ASSERT_COMP (0x7fff, 0x7ffd, -2); - ASSERT_COMP (0x8000, 0x7ffd, -3); - ASSERT_COMP (0x8001, 0x7ffd, -4); - ASSERT_COMP (0x8002, 0x7ffd, -5); - - ASSERT_COMP (0x7ffd, 0xffff, -0x7ffe); - ASSERT_COMP (0x7ffe, 0x0000, -0x7ffe); - ASSERT_COMP (0x7fff, 0x0001, -0x7ffe); - ASSERT_COMP (0x7fff, 0x0000, -0x7fff); - ASSERT_COMP (0x8000, 0x0001, -0x7fff); - ASSERT_COMP (0x8001, 0x0002, -0x7fff); - - ASSERT_COMP (0xfffd, 0x7ffe, -0x7fff); - ASSERT_COMP (0xfffe, 0x7fff, -0x7fff); - ASSERT_COMP (0xffff, 0x8000, -0x7fff); - ASSERT_COMP (0x0000, 0x8001, -0x7fff); - ASSERT_COMP (0x0001, 0x8002, -0x7fff); - - ASSERT_COMP (0xfffe, 0x7ffe, -0x8000); - ASSERT_COMP (0xffff, 0x7fff, -0x8000); - ASSERT_COMP (0x0000, 0x8000, -0x8000); - ASSERT_COMP (0x0001, 0x8001, -0x8000); - - ASSERT_COMP (0x7ffe, 0xfffe, -0x8000); - ASSERT_COMP (0x7fff, 0xffff, -0x8000); - ASSERT_COMP (0x8000, 0x0000, -0x8000); - ASSERT_COMP (0x8001, 0x0001, -0x8000); - - ASSERT_COMP (0x0001, 0x0002, 1); - ASSERT_COMP (0x0000, 0x0001, 1); - ASSERT_COMP (0xffff, 0x0000, 1); - ASSERT_COMP (0xfffe, 0xffff, 1); - ASSERT_COMP (0xfffd, 0xfffe, 1); - - ASSERT_COMP (0x0000, 0x0002, 2); - ASSERT_COMP (0xffff, 0x0002, 3); - ASSERT_COMP (0xfffe, 0x0002, 4); - ASSERT_COMP (0xfffd, 0x0002, 5); - - ASSERT_COMP (0x8001, 0x8002, 1); - ASSERT_COMP (0x8000, 0x8001, 1); - ASSERT_COMP (0x7fff, 0x8000, 1); - ASSERT_COMP (0x7ffe, 0x7fff, 1); - ASSERT_COMP (0x7ffd, 0x7ffe, 1); - - ASSERT_COMP (0x8000, 0x8002, 2); - ASSERT_COMP (0x7fff, 0x8002, 3); - ASSERT_COMP (0x7ffe, 0x8002, 4); - ASSERT_COMP (0x7ffd, 0x8002, 5); - - ASSERT_COMP (0xfffe, 0x7ffd, 0x7fff); - ASSERT_COMP (0xffff, 0x7ffe, 0x7fff); - ASSERT_COMP (0x0000, 0x7fff, 0x7fff); - ASSERT_COMP (0x0001, 0x8000, 0x7fff); - ASSERT_COMP (0x0002, 0x8001, 0x7fff); - - ASSERT_COMP (0x7ffe, 0xfffd, 0x7fff); - ASSERT_COMP (0x7fff, 0xfffe, 0x7fff); - ASSERT_COMP (0x8000, 0xffff, 0x7fff); - ASSERT_COMP (0x8001, 0x0000, 0x7fff); - ASSERT_COMP (0x8002, 0x0001, 0x7fff); -#undef ASSERT_COMP -} - -GST_END_TEST; - -GST_START_TEST (test_rtcp_buffer) -{ - GstBuffer *buf; - GstRTCPPacket packet; - guint8 *data; - - buf = gst_rtcp_buffer_new (1400); - fail_unless (buf != NULL); - fail_unless_equals_int (GST_BUFFER_SIZE (buf), 1400); - data = GST_BUFFER_DATA (buf); - - fail_unless (gst_rtcp_buffer_get_first_packet (buf, &packet) == FALSE); - fail_unless (gst_rtcp_buffer_get_packet_count (buf) == 0); - fail_unless (gst_rtcp_buffer_validate (buf) == FALSE); - - /* add an SR packet */ - fail_unless (gst_rtcp_buffer_add_packet (buf, GST_RTCP_TYPE_SR, - &packet) == TRUE); - - fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); - fail_unless (gst_rtcp_packet_get_count (&packet) == 0); - fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_SR); - fail_unless (gst_rtcp_packet_get_length (&packet) == 6); - - gst_rtcp_packet_sr_set_sender_info (&packet, 0x44556677, - G_GUINT64_CONSTANT (1), 0x11111111, 101, 123456); - { - guint32 ssrc; - guint64 ntptime; - guint32 rtptime; - guint32 packet_count; - guint32 octet_count; - - gst_rtcp_packet_sr_get_sender_info (&packet, &ssrc, &ntptime, &rtptime, - &packet_count, &octet_count); - - fail_unless (ssrc == 0x44556677); - fail_unless (ntptime == G_GUINT64_CONSTANT (1)); - fail_unless (rtptime == 0x11111111); - fail_unless (packet_count == 101); - fail_unless (octet_count == 123456); - } - - /* go to first packet, this should be the packet we just added */ - fail_unless (gst_rtcp_buffer_get_first_packet (buf, &packet) == TRUE); - - fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); - fail_unless (gst_rtcp_packet_get_count (&packet) == 0); - fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_SR); - fail_unless (gst_rtcp_packet_get_length (&packet) == 6); - - fail_unless (gst_rtcp_packet_move_to_next (&packet) == FALSE); - - /* add some SDES */ - fail_unless (gst_rtcp_buffer_add_packet (buf, GST_RTCP_TYPE_SDES, - &packet) == TRUE); - fail_unless (gst_rtcp_packet_sdes_add_item (&packet, 0xff658743) == TRUE); - fail_unless (gst_rtcp_packet_sdes_add_entry (&packet, GST_RTCP_SDES_CNAME, - sizeof ("test@foo.bar"), (guint8 *) "test@foo.bar") == TRUE); - - /* add some BYE */ - fail_unless (gst_rtcp_buffer_add_packet (buf, GST_RTCP_TYPE_BYE, - &packet) == TRUE); - fail_unless (gst_rtcp_packet_bye_add_ssrc (&packet, 0x5613212f) == TRUE); - fail_unless (gst_rtcp_packet_bye_add_ssrc (&packet, 0x00112233) == TRUE); - fail_unless (gst_rtcp_packet_bye_get_ssrc_count (&packet) == 2); - - fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); - fail_unless (gst_rtcp_packet_get_count (&packet) == 2); - fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_BYE); - fail_unless (gst_rtcp_packet_get_length (&packet) == 2); - - /* move to SDES */ - fail_unless (gst_rtcp_buffer_get_first_packet (buf, &packet) == TRUE); - fail_unless (gst_rtcp_packet_move_to_next (&packet) == TRUE); - - fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); - fail_unless (gst_rtcp_packet_get_count (&packet) == 1); - fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_SDES); - fail_unless (gst_rtcp_packet_get_length (&packet) == 5); - - /* remove the SDES */ - fail_unless (gst_rtcp_packet_remove (&packet) == TRUE); - - /* we are now at the BYE packet */ - fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); - fail_unless (gst_rtcp_packet_get_count (&packet) == 2); - fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_BYE); - fail_unless (gst_rtcp_packet_get_length (&packet) == 2); - - /* close and validate */ - gst_rtcp_buffer_end (buf); - fail_unless (gst_rtcp_buffer_validate (buf) == TRUE); - gst_buffer_unref (buf); -} - -GST_END_TEST; - -static Suite * -rtp_suite (void) -{ - Suite *s = suite_create ("rtp support library"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_rtp_buffer); - tcase_add_test (tc_chain, test_rtp_buffer_validate_corrupt); - tcase_add_test (tc_chain, test_rtp_buffer_set_extension_data); - tcase_add_test (tc_chain, test_rtp_seqnum_compare); - - tcase_add_test (tc_chain, test_rtcp_buffer); - - tcase_add_test (tc_chain, test_rtp_buffer_list); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = rtp_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/libs/tag.c b/tests/check/libs/tag.c deleted file mode 100644 index 292df929..00000000 --- a/tests/check/libs/tag.c +++ /dev/null @@ -1,783 +0,0 @@ -/* GStreamer - * - * unit tests for the tag support library - * - * Copyright (C) 2006-2009 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/check/gstcheck.h> - -#include <gst/tag/tag.h> -#include <string.h> - -GST_START_TEST (test_parse_extended_comment) -{ - gchar *key, *val, *lang; - - /* first check the g_return_val_if_fail conditions */ - ASSERT_CRITICAL (gst_tag_parse_extended_comment (NULL, NULL, NULL, NULL, - FALSE)); - ASSERT_CRITICAL (gst_tag_parse_extended_comment ("\377\000", NULL, NULL, NULL, - FALSE)); - - key = val = lang = NULL; - fail_unless (gst_tag_parse_extended_comment ("a=b", &key, &lang, &val, - FALSE) == TRUE); - fail_unless (key != NULL); - fail_unless (lang == NULL); - fail_unless (val != NULL); - fail_unless_equals_string (key, "a"); - fail_unless_equals_string (val, "b"); - g_free (key); - g_free (lang); - g_free (val); - - key = val = lang = NULL; - fail_unless (gst_tag_parse_extended_comment ("a[l]=b", &key, &lang, &val, - FALSE) == TRUE); - fail_unless (key != NULL); - fail_unless (lang != NULL); - fail_unless (val != NULL); - fail_unless_equals_string (key, "a"); - fail_unless_equals_string (lang, "l"); - fail_unless_equals_string (val, "b"); - g_free (key); - g_free (lang); - g_free (val); - - key = val = lang = NULL; - fail_unless (gst_tag_parse_extended_comment ("foo=bar", &key, &lang, &val, - FALSE) == TRUE); - fail_unless (key != NULL); - fail_unless (lang == NULL); - fail_unless (val != NULL); - fail_unless_equals_string (key, "foo"); - fail_unless_equals_string (val, "bar"); - g_free (key); - g_free (lang); - g_free (val); - - key = val = lang = NULL; - fail_unless (gst_tag_parse_extended_comment ("foo[fr]=bar", &key, &lang, &val, - FALSE) == TRUE); - fail_unless (key != NULL); - fail_unless (lang != NULL); - fail_unless (val != NULL); - fail_unless_equals_string (key, "foo"); - fail_unless_equals_string (lang, "fr"); - fail_unless_equals_string (val, "bar"); - g_free (key); - g_free (lang); - g_free (val); - - key = val = lang = NULL; - fail_unless (gst_tag_parse_extended_comment ("foo=[fr]bar", &key, &lang, &val, - FALSE) == TRUE); - fail_unless (key != NULL); - fail_unless (lang == NULL); - fail_unless (val != NULL); - fail_unless_equals_string (key, "foo"); - fail_unless_equals_string (val, "[fr]bar"); - g_free (key); - g_free (lang); - g_free (val); - - /* test NULL for output locations */ - fail_unless (gst_tag_parse_extended_comment ("foo[fr]=bar", NULL, NULL, NULL, - FALSE) == TRUE); - - /* test strict mode (key must be specified) */ - fail_unless (gst_tag_parse_extended_comment ("foo[fr]=bar", NULL, NULL, NULL, - TRUE) == TRUE); - fail_unless (gst_tag_parse_extended_comment ("foo=bar", NULL, NULL, NULL, - TRUE) == TRUE); - fail_unless (gst_tag_parse_extended_comment ("foobar", NULL, NULL, NULL, - TRUE) == FALSE); - - /* test non-strict mode (if there's no key, that's fine too) */ - fail_unless (gst_tag_parse_extended_comment ("foobar", NULL, NULL, NULL, - FALSE) == TRUE); - fail_unless (gst_tag_parse_extended_comment ("[fr]bar", NULL, NULL, NULL, - FALSE) == TRUE); - - key = val = lang = NULL; - fail_unless (gst_tag_parse_extended_comment ("[fr]bar", &key, &lang, &val, - FALSE) == TRUE); - fail_unless (key == NULL); - fail_unless (lang == NULL); - fail_unless (val != NULL); - fail_unless_equals_string (val, "[fr]bar"); - g_free (key); - g_free (lang); - g_free (val); -} - -GST_END_TEST; - -#define ASSERT_TAG_LIST_HAS_STRING(list,field,string) \ - { \ - gboolean got_match = FALSE; \ - guint i, size; \ - \ - fail_unless (gst_tag_list_get_tag_size (list,field) > 0); \ - size = gst_tag_list_get_tag_size (list,field); \ - for (i = 0; i < size; ++i) { \ - gchar *___s = NULL; \ - \ - fail_unless (gst_tag_list_get_string_index (list, field, i, &___s)); \ - fail_unless (___s != NULL); \ - if (g_str_equal (___s, string)) { \ - got_match = TRUE; \ - g_free (___s); \ - break; \ - } \ - g_free (___s); \ - } \ - fail_unless (got_match); \ - } - -#define ASSERT_TAG_LIST_HAS_UINT(list,field,num) \ - { \ - guint ___n; \ - \ - fail_unless (gst_tag_list_get_tag_size (list,field) > 0); \ - fail_unless (gst_tag_list_get_tag_size (list,field) == 1); \ - fail_unless (gst_tag_list_get_uint_index (list, field, 0, &___n)); \ - fail_unless_equals_int (___n, num); \ - } - -#define MATCH_DOUBLE(p1, p2) ((p1 < p2 + 1e-6) && (p2 < p1 + 1e-6)) -#define ASSERT_TAG_LIST_HAS_DOUBLE(list,field,d) \ - { \ - gdouble ___d; \ - \ - fail_unless (gst_tag_list_get_tag_size (list,field) > 0); \ - fail_unless (gst_tag_list_get_tag_size (list,field) == 1); \ - fail_unless (gst_tag_list_get_double_index (list, field, 0, &___d)); \ - fail_unless (MATCH_DOUBLE (d, ___d), \ - "%f does not match expected %f", ___d, d); \ - } - -GST_START_TEST (test_muscibrainz_tag_registration) -{ - GstTagList *list; - - gst_tag_register_musicbrainz_tags (); - - list = gst_tag_list_new (); - - /* musicbrainz tags aren't registered yet */ - gst_vorbis_tag_add (list, "MUSICBRAINZ_TRACKID", "123456"); - gst_vorbis_tag_add (list, "MUSICBRAINZ_ARTISTID", "234567"); - gst_vorbis_tag_add (list, "MUSICBRAINZ_ALBUMID", "345678"); - gst_vorbis_tag_add (list, "MUSICBRAINZ_ALBUMARTISTID", "4567890"); - gst_vorbis_tag_add (list, "MUSICBRAINZ_TRMID", "5678901"); - /* MUSICBRAINZ_SORTNAME = GST_TAG_ARTIST_SORTNAME now */ - gst_vorbis_tag_add (list, "MUSICBRAINZ_SORTNAME", "Five, 678901"); - - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_MUSICBRAINZ_TRACKID, "123456"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_MUSICBRAINZ_ARTISTID, "234567"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_MUSICBRAINZ_ALBUMID, "345678"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_MUSICBRAINZ_ALBUMARTISTID, - "4567890"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_MUSICBRAINZ_TRMID, "5678901"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_ARTIST_SORTNAME, "Five, 678901"); - - gst_tag_list_free (list); -} - -GST_END_TEST; - -/* is there an easier way to compare two structures / tagslists? */ -static gboolean -taglists_are_equal (const GstTagList * list_1, const GstTagList * list_2) -{ - GstCaps *c_list_1 = gst_caps_new_empty (); - GstCaps *c_list_2 = gst_caps_new_empty (); - gboolean ret; - - gst_caps_append_structure (c_list_1, - gst_structure_copy ((GstStructure *) list_1)); - gst_caps_append_structure (c_list_2, - gst_structure_copy ((GstStructure *) list_2)); - - ret = gst_caps_is_equal (c_list_2, c_list_1); - - gst_caps_unref (c_list_1); - gst_caps_unref (c_list_2); - - return ret; -} - -GST_START_TEST (test_vorbis_tags) -{ - GstTagList *list; - - list = gst_tag_list_new (); - - /* NULL pointers aren't allowed */ - ASSERT_CRITICAL (gst_vorbis_tag_add (NULL, "key", "value")); - ASSERT_CRITICAL (gst_vorbis_tag_add (list, NULL, "value")); - ASSERT_CRITICAL (gst_vorbis_tag_add (list, "key", NULL)); - - /* must be UTF-8 */ - ASSERT_CRITICAL (gst_vorbis_tag_add (list, "key", "v\377lue")); - ASSERT_CRITICAL (gst_vorbis_tag_add (list, "k\377y", "value")); - - /* key can't have a '=' in it */ - ASSERT_CRITICAL (gst_vorbis_tag_add (list, "k=y", "value")); - ASSERT_CRITICAL (gst_vorbis_tag_add (list, "key=", "value")); - - /* should be allowed in values though */ - gst_vorbis_tag_add (list, "keeey", "va=ue"); - - /* add some tags */ - gst_vorbis_tag_add (list, "TITLE", "Too"); - gst_vorbis_tag_add (list, "ALBUM", "Aoo"); - gst_vorbis_tag_add (list, "ARTIST", "Alboo"); - gst_vorbis_tag_add (list, "PERFORMER", "Perfoo"); - gst_vorbis_tag_add (list, "COPYRIGHT", "Copyfoo"); - gst_vorbis_tag_add (list, "DESCRIPTION", "Descoo"); - gst_vorbis_tag_add (list, "LICENSE", "Licoo"); - gst_vorbis_tag_add (list, "LICENSE", - "http://creativecommons.org/licenses/by/3.0/"); - gst_vorbis_tag_add (list, "LOCATION", "Bristol, UK"); - gst_vorbis_tag_add (list, "ORGANIZATION", "Orgoo"); - gst_vorbis_tag_add (list, "GENRE", "Goo"); - gst_vorbis_tag_add (list, "CONTACT", "Coo"); - gst_vorbis_tag_add (list, "COMMENT", "Stroodle is good"); - gst_vorbis_tag_add (list, "COMMENT", "Peroxysulfid stroodles the brain"); - - gst_vorbis_tag_add (list, "TRACKNUMBER", "5"); - gst_vorbis_tag_add (list, "TRACKTOTAL", "77"); - gst_vorbis_tag_add (list, "DISCNUMBER", "1"); - gst_vorbis_tag_add (list, "DISCTOTAL", "2"); - gst_vorbis_tag_add (list, "DATE", "1954-12-31"); - - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_TITLE, "Too"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_ALBUM, "Aoo"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_ARTIST, "Alboo"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_PERFORMER, "Perfoo"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_COPYRIGHT, "Copyfoo"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_DESCRIPTION, "Descoo"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LICENSE, "Licoo"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LICENSE_URI, - "http://creativecommons.org/licenses/by/3.0/"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_GEO_LOCATION_NAME, "Bristol, UK"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_ORGANIZATION, "Orgoo"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_GENRE, "Goo"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_CONTACT, "Coo"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_COMMENT, - "Peroxysulfid stroodles the brain"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_COMMENT, "Stroodle is good"); - ASSERT_TAG_LIST_HAS_UINT (list, GST_TAG_TRACK_NUMBER, 5); - ASSERT_TAG_LIST_HAS_UINT (list, GST_TAG_TRACK_COUNT, 77); - ASSERT_TAG_LIST_HAS_UINT (list, GST_TAG_ALBUM_VOLUME_NUMBER, 1); - ASSERT_TAG_LIST_HAS_UINT (list, GST_TAG_ALBUM_VOLUME_COUNT, 2); - - { - GDate *date = NULL; - - fail_unless (gst_tag_list_get_date (list, GST_TAG_DATE, &date)); - fail_unless (date != NULL); - fail_unless (g_date_get_day (date) == 31); - fail_unless (g_date_get_month (date) == G_DATE_DECEMBER); - fail_unless (g_date_get_year (date) == 1954); - - g_date_free (date); - } - - /* unknown vorbis comments should go into a GST_TAG_EXTENDED_COMMENT */ - gst_vorbis_tag_add (list, "CoEdSub_ID", "98172AF-973-10-B"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_EXTENDED_COMMENT, - "CoEdSub_ID=98172AF-973-10-B"); - gst_vorbis_tag_add (list, "RuBuWuHash", "1337BA42F91"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_EXTENDED_COMMENT, - "RuBuWuHash=1337BA42F91"); - - gst_vorbis_tag_add (list, "REPLAYGAIN_REFERENCE_LOUDNESS", "89."); - ASSERT_TAG_LIST_HAS_DOUBLE (list, GST_TAG_REFERENCE_LEVEL, 89.); - gst_vorbis_tag_add (list, "REPLAYGAIN_TRACK_GAIN", "+12.36"); - ASSERT_TAG_LIST_HAS_DOUBLE (list, GST_TAG_TRACK_GAIN, +12.36); - gst_vorbis_tag_add (list, "REPLAYGAIN_TRACK_PEAK", "0.96349"); - ASSERT_TAG_LIST_HAS_DOUBLE (list, GST_TAG_TRACK_PEAK, 0.96349); - gst_vorbis_tag_add (list, "REPLAYGAIN_ALBUM_GAIN", "+10.12"); - ASSERT_TAG_LIST_HAS_DOUBLE (list, GST_TAG_ALBUM_GAIN, +10.12); - /* now check that we can parse floating point numbers with any separator - * (',' or '.') regardless of the current locale */ - gst_vorbis_tag_add (list, "REPLAYGAIN_ALBUM_PEAK", "0,98107"); - ASSERT_TAG_LIST_HAS_DOUBLE (list, GST_TAG_ALBUM_PEAK, 0.98107); - gst_vorbis_tag_add (list, "LICENSE", "http://foo.com/license-1.html"); - - /* make sure we can convert back and forth without loss */ - { - GstTagList *new_list, *even_newer_list; - GstBuffer *buf, *buf2; - gchar *vendor_id = NULL; - - buf = gst_tag_list_to_vorbiscomment_buffer (list, - (const guint8 *) "\003vorbis", 7, "libgstunittest"); - fail_unless (buf != NULL); - new_list = gst_tag_list_from_vorbiscomment_buffer (buf, - (const guint8 *) "\003vorbis", 7, &vendor_id); - fail_unless (new_list != NULL); - fail_unless (vendor_id != NULL); - g_free (vendor_id); - vendor_id = NULL; - - GST_LOG ("new_list = %" GST_PTR_FORMAT, new_list); - fail_unless (taglists_are_equal (list, new_list)); - - buf2 = gst_tag_list_to_vorbiscomment_buffer (new_list, - (const guint8 *) "\003vorbis", 7, "libgstunittest"); - fail_unless (buf2 != NULL); - even_newer_list = gst_tag_list_from_vorbiscomment_buffer (buf2, - (const guint8 *) "\003vorbis", 7, &vendor_id); - fail_unless (even_newer_list != NULL); - fail_unless (vendor_id != NULL); - g_free (vendor_id); - vendor_id = NULL; - - GST_LOG ("even_newer_list = %" GST_PTR_FORMAT, even_newer_list); - fail_unless (taglists_are_equal (new_list, even_newer_list)); - - gst_tag_list_free (new_list); - gst_tag_list_free (even_newer_list); - gst_buffer_unref (buf); - gst_buffer_unref (buf2); - } - - /* there can only be one language per taglist ... */ - gst_tag_list_free (list); - list = gst_tag_list_new (); - gst_vorbis_tag_add (list, "LANGUAGE", "fr"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "fr"); - - gst_tag_list_free (list); - list = gst_tag_list_new (); - gst_vorbis_tag_add (list, "LANGUAGE", "[fr]"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "fr"); - - gst_tag_list_free (list); - list = gst_tag_list_new (); - gst_vorbis_tag_add (list, "LANGUAGE", "French [fr]"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "fr"); - - gst_tag_list_free (list); - list = gst_tag_list_new (); - gst_vorbis_tag_add (list, "LANGUAGE", "[eng] English"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "eng"); - - gst_tag_list_free (list); - list = gst_tag_list_new (); - gst_vorbis_tag_add (list, "LANGUAGE", "eng"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "eng"); - - gst_tag_list_free (list); - list = gst_tag_list_new (); - gst_vorbis_tag_add (list, "LANGUAGE", "[eng]"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "eng"); - - /* free-form *sigh* */ - gst_tag_list_free (list); - list = gst_tag_list_new (); - gst_vorbis_tag_add (list, "LANGUAGE", "English"); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_LANGUAGE_CODE, "English"); - - /* now, while we still have a taglist, test _to_vorbiscomment_buffer() */ - { - GstBuffer *buf1, *buf2; - - ASSERT_CRITICAL (gst_tag_list_to_vorbiscomment_buffer (NULL, - (const guint8 *) "x", 1, "x")); - - buf1 = gst_tag_list_to_vorbiscomment_buffer (list, NULL, 0, NULL); - fail_unless (buf1 != NULL); - - buf2 = gst_tag_list_to_vorbiscomment_buffer (list, - (const guint8 *) "foo", 3, NULL); - fail_unless (buf2 != NULL); - - fail_unless (memcmp (GST_BUFFER_DATA (buf1), GST_BUFFER_DATA (buf2) + 3, - GST_BUFFER_SIZE (buf1)) == 0); - - gst_buffer_unref (buf1); - gst_buffer_unref (buf2); - } - - gst_tag_list_free (list); - - /* make sure gst_tag_list_from_vorbiscomment_buffer() works with an - * empty ID (for Speex) */ - { - const guint8 speex_comments_buf1[] = { 0x03, 0x00, 0x00, 0x00, 'f', 'o', - 'o', 0x00, 0x00, 0x00, 0x00 - }; - GstBuffer *buf; - gchar *vendor = NULL; - - buf = gst_buffer_new (); - GST_BUFFER_DATA (buf) = (guint8 *) speex_comments_buf1; - GST_BUFFER_SIZE (buf) = sizeof (speex_comments_buf1); - - /* make sure it doesn't memcmp over the end of the buffer */ - fail_unless (gst_tag_list_from_vorbiscomment_buffer (buf, - (const guint8 *) "averylongstringbrownfoxjumpoverthefence", 39, - &vendor) == NULL); - fail_unless (vendor == NULL); - - /* make sure it bails out if the ID doesn't match */ - fail_unless (gst_tag_list_from_vorbiscomment_buffer (buf, - (guint8 *) "short", 4, &vendor) == NULL); - fail_unless (vendor == NULL); - - /* now read properly */ - list = gst_tag_list_from_vorbiscomment_buffer (buf, NULL, 0, &vendor); - fail_unless (vendor != NULL); - fail_unless_equals_string (vendor, "foo"); - fail_unless (list != NULL); - fail_unless (gst_structure_n_fields ((GstStructure *) list) == 0); - g_free (vendor); - gst_tag_list_free (list); - - /* now again without vendor */ - list = gst_tag_list_from_vorbiscomment_buffer (buf, NULL, 0, NULL); - fail_unless (list != NULL); - fail_unless (gst_structure_n_fields ((GstStructure *) list) == 0); - gst_tag_list_free (list); - - gst_buffer_unref (buf); - } - - /* the same with an ID */ - { - const guint8 vorbis_comments_buf[] = { 0x03, 'v', 'o', 'r', 'b', 'i', 's', - 0x03, 0x00, 0x00, 0x00, 'f', 'o', 'o', 0x01, 0x00, 0x00, 0x00, - strlen ("ARTIST=foo bar"), 0x00, 0x00, 0x00, 'A', 'R', 'T', 'I', 'S', - 'T', '=', 'f', 'o', 'o', ' ', 'b', 'a', 'r' - }; - GstBuffer *buf; - gchar *vendor = NULL; - - buf = gst_buffer_new (); - GST_BUFFER_DATA (buf) = (guint8 *) vorbis_comments_buf; - GST_BUFFER_SIZE (buf) = sizeof (vorbis_comments_buf); - - /* make sure it doesn't memcmp over the end of the buffer */ - fail_unless (gst_tag_list_from_vorbiscomment_buffer (buf, - (const guint8 *) "averylongstringbrownfoxjumpoverthefence", 39, - &vendor) == NULL); - fail_unless (vendor == NULL); - - /* make sure it bails out if the ID doesn't match */ - fail_unless (gst_tag_list_from_vorbiscomment_buffer (buf, - (guint8 *) "short", 4, &vendor) == NULL); - fail_unless (vendor == NULL); - - /* now read properly */ - list = gst_tag_list_from_vorbiscomment_buffer (buf, - (guint8 *) "\003vorbis", 7, &vendor); - fail_unless (vendor != NULL); - fail_unless_equals_string (vendor, "foo"); - fail_unless (list != NULL); - fail_unless (gst_structure_n_fields ((GstStructure *) list) == 1); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_ARTIST, "foo bar"); - g_free (vendor); - gst_tag_list_free (list); - - /* now again without vendor */ - list = gst_tag_list_from_vorbiscomment_buffer (buf, - (guint8 *) "\003vorbis", 7, NULL); - fail_unless (list != NULL); - fail_unless (gst_structure_n_fields ((GstStructure *) list) == 1); - ASSERT_TAG_LIST_HAS_STRING (list, GST_TAG_ARTIST, "foo bar"); - gst_tag_list_free (list); - - gst_buffer_unref (buf); - } - - /* check date with time */ - { - GDate *date = NULL; - - list = gst_tag_list_new (); - gst_vorbis_tag_add (list, "DATE", "2006-09-25 22:02:38"); - - fail_unless (gst_tag_list_get_date_index (list, GST_TAG_DATE, 0, &date)); - fail_unless (date != NULL); - fail_unless (g_date_get_day (date) == 25); - fail_unless (g_date_get_month (date) == G_DATE_SEPTEMBER); - fail_unless (g_date_get_year (date) == 2006); - - g_date_free (date); - gst_tag_list_free (list); - } - - /* check date with month/day of 00-00 */ - { - GDate *date = NULL; - - list = gst_tag_list_new (); - gst_vorbis_tag_add (list, "DATE", "1992-00-00"); - - fail_unless (gst_tag_list_get_date_index (list, GST_TAG_DATE, 0, &date)); - fail_unless (date != NULL); - fail_unless (g_date_get_year (date) == 1992); - - g_date_free (date); - gst_tag_list_free (list); - } - - /* check date with valid month, but day of 00 */ - { - GDate *date = NULL; - - list = gst_tag_list_new (); - gst_vorbis_tag_add (list, "DATE", "1992-05-00"); - - fail_unless (gst_tag_list_get_date_index (list, GST_TAG_DATE, 0, &date)); - fail_unless (date != NULL); - fail_unless (g_date_get_year (date) == 1992); - fail_unless (g_date_get_month (date) == G_DATE_MAY); - - g_date_free (date); - gst_tag_list_free (list); - } -} - -GST_END_TEST; - -GST_START_TEST (test_id3_tags) -{ - guint i; - - fail_unless (gst_tag_id3_genre_count () > 0); - - for (i = 0; i < gst_tag_id3_genre_count (); ++i) { - const gchar *genre; - - genre = gst_tag_id3_genre_get (i); - fail_unless (genre != NULL); - } - - { - /* TODO: GstTagList *gst_tag_list_new_from_id3v1 (const guint8 *data) */ - } - - /* gst_tag_from_id3_tag */ - fail_unless (gst_tag_from_id3_tag ("TALB") != NULL); - ASSERT_CRITICAL (gst_tag_from_id3_tag (NULL)); - fail_unless (gst_tag_from_id3_tag ("R2D2") == NULL); - fail_unless_equals_string (gst_tag_from_id3_tag ("WCOP"), - GST_TAG_COPYRIGHT_URI); - - /* gst_tag_from_id3_user_tag */ - ASSERT_CRITICAL (gst_tag_from_id3_user_tag (NULL, "foo")); - ASSERT_CRITICAL (gst_tag_from_id3_user_tag ("foo", NULL)); - fail_unless (gst_tag_from_id3_user_tag ("R2D2", "R2D2") == NULL); - - /* gst_tag_to_id3_tag */ - ASSERT_CRITICAL (gst_tag_to_id3_tag (NULL)); - fail_unless (gst_tag_to_id3_tag ("R2D2") == NULL); - fail_unless (gst_tag_to_id3_tag (GST_TAG_ARTIST) != NULL); - fail_unless_equals_string (gst_tag_to_id3_tag (GST_TAG_COPYRIGHT_URI), - "WCOP"); - - fail_unless (GST_TYPE_TAG_IMAGE_TYPE != 0); - fail_unless (g_type_name (GST_TYPE_TAG_IMAGE_TYPE) != NULL); -} - -GST_END_TEST; - - -GST_START_TEST (test_id3v1_utf8_tag) -{ - const guint8 id3v1[128] = { - /* marker */ - 'T', 'A', 'G', - /* title (30 bytes) */ - 'D', 0xc3, 0xad, 'v', 'k', 'a', ' ', 's', - ' ', 'p', 'e', 'r', 'l', 'a', 'm', 'i', - ' ', 'v', 'e', ' ', 'v', 'l', 'a', 's', - 'e', 'c', 'h', 0, 0, 0, - /* artist (30 bytes) */ - 'A', 'l', 'e', 0xc5, 0xa1, ' ', 'B', 'r', 'i', 'c', 'h', 't', 'a', - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* album (30 bytes) */ - 'B', 'e', 's', 't', ' ', 'o', 'f', ' ', '(', 'P', 'r', 'o', 's', 't', - 0xc4, 0x9b, ' ', 0xc3, 0xba, 0xc5, 0xbe, 'a', 's', 'n', 0xc3, 0xbd, ')', - 0, 0, 0, - /* year (4 bytes) */ - '2', '0', '0', '0', - /* comment (28 bytes) */ - '-', '-', '-', ' ', 0xc4, 0x8d, 'e', 's', 'k', 0xc3, 0xa9, ' ', 'p', - 0xc3, 0xad, 's', 'n', 'i', 0xc4, 0x8d, 'k', 'y', ' ', '-', '-', '-', - 0, 0, - /* track number */ - 0, 0, - /* genre */ - 0x11 - }; - GstTagList *tags; - GDate *d; - gchar *s; - - /* set this, to make sure UTF-8 strings are really interpreted properly - * as UTF-8, regardless of the locale set */ - g_setenv ("GST_ID3V1_TAG_ENCODING", "WINDOWS-1250", TRUE); - - tags = gst_tag_list_new_from_id3v1 (id3v1); - fail_unless (tags != NULL); - - GST_LOG ("Got tags: %" GST_PTR_FORMAT, tags); - - s = NULL; - fail_unless (gst_tag_list_get_string (tags, GST_TAG_TITLE, &s)); - fail_unless (s != NULL); - fail_unless_equals_string (s, "DÃvka s perlami ve vlasech"); - g_free (s); - - s = NULL; - fail_unless (gst_tag_list_get_string (tags, GST_TAG_ARTIST, &s)); - fail_unless (s != NULL); - fail_unless_equals_string (s, "AleÅ¡ Brichta"); - g_free (s); - - s = NULL; - fail_unless (gst_tag_list_get_string (tags, GST_TAG_ALBUM, &s)); - fail_unless (s != NULL); - fail_unless_equals_string (s, "Best of (ProstÄ› úžasný)"); - g_free (s); - - d = NULL; - fail_unless (gst_tag_list_get_date (tags, GST_TAG_DATE, &d)); - fail_unless (d != NULL); - fail_unless_equals_int (g_date_get_year (d), 2000); - g_date_free (d); - d = NULL; - - gst_tag_list_free (tags); - - g_unsetenv ("GST_ID3V1_TAG_ENCODING"); -} - -GST_END_TEST; - -GST_START_TEST (test_language_utils) -{ - gchar **lang_codes, **c; - -#define ASSERT_STRINGS_EQUAL fail_unless_equals_string - - lang_codes = gst_tag_get_language_codes (); - fail_unless (lang_codes != NULL); - fail_unless (*lang_codes != NULL); - - for (c = lang_codes; c != NULL && *c != NULL; ++c) { - const gchar *lang_name, *c1, *c2t, *c2b; - - lang_name = gst_tag_get_language_name (*c); - fail_unless (lang_name != NULL); - fail_unless (g_utf8_validate (lang_name, -1, NULL)); - - c1 = gst_tag_get_language_code_iso_639_1 (*c); - fail_unless (c1 != NULL); - fail_unless (g_utf8_validate (c1, -1, NULL)); - - c2t = gst_tag_get_language_code_iso_639_2T (*c); - fail_unless (c2t != NULL); - fail_unless (g_utf8_validate (c2t, -1, NULL)); - - c2b = gst_tag_get_language_code_iso_639_2B (*c); - fail_unless (c2b != NULL); - fail_unless (g_utf8_validate (c2b, -1, NULL)); - - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_1 (*c), *c); - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_1 (c2t), *c); - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_1 (c2b), *c); - - GST_DEBUG ("[%s] %s %s %s : %s\n", *c, c1, c2t, c2b, lang_name); - - } - g_strfreev (lang_codes); - - fail_unless (gst_tag_get_language_name ("de") != NULL); - fail_unless (gst_tag_get_language_name ("deu") != NULL); - fail_unless (gst_tag_get_language_name ("ger") != NULL); - fail_unless_equals_string (gst_tag_get_language_name ("deu"), - gst_tag_get_language_name ("ger")); - fail_unless_equals_string (gst_tag_get_language_name ("de"), - gst_tag_get_language_name ("ger")); - fail_unless (gst_tag_get_language_name ("de") != - gst_tag_get_language_name ("fr")); - - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code ("deu"), "de"); - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code ("de"), "de"); - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code ("ger"), "de"); - - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_1 ("deu"), "de"); - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_1 ("de"), "de"); - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_1 ("ger"), "de"); - - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_2T ("de"), "deu"); - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_2T ("deu"), "deu"); - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_2T ("ger"), "deu"); - - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_2B ("de"), "ger"); - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_2B ("deu"), "ger"); - ASSERT_STRINGS_EQUAL (gst_tag_get_language_code_iso_639_2B ("ger"), "ger"); -} - -GST_END_TEST; - -static Suite * -tag_suite (void) -{ - Suite *s = suite_create ("tag support library"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_muscibrainz_tag_registration); - tcase_add_test (tc_chain, test_parse_extended_comment); - tcase_add_test (tc_chain, test_vorbis_tags); - tcase_add_test (tc_chain, test_id3_tags); - tcase_add_test (tc_chain, test_id3v1_utf8_tag); - tcase_add_test (tc_chain, test_language_utils); - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = tag_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/libs/video.c b/tests/check/libs/video.c deleted file mode 100644 index 56e9f5f7..00000000 --- a/tests/check/libs/video.c +++ /dev/null @@ -1,598 +0,0 @@ -/* GStreamer unit test for video - * - * Copyright (C) <2003> David A. Schleef <ds@schleef.org> - * Copyright (C) <2006> Jan Schmidt <thaytan@mad.scientist.com> - * Copyright (C) <2008> Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <unistd.h> - -#include <gst/check/gstcheck.h> - -#include <gst/video/video.h> -#include <string.h> - -/* These are from the current/old videotestsrc; we check our new public API - * in libgstvideo against the old one to make sure the sizes and offsets - * end up the same */ - -typedef struct paintinfo_struct paintinfo; -struct paintinfo_struct -{ - unsigned char *dest; /* pointer to first byte of video data */ - unsigned char *yp, *up, *vp; /* pointers to first byte of each component - * for both packed/planar YUV and RGB */ - unsigned char *ap; /* pointer to first byte of alpha component */ - unsigned char *endptr; /* pointer to byte beyond last video data */ - int ystride; - int ustride; - int vstride; - int width; - int height; -}; - -struct fourcc_list_struct -{ - char *fourcc; - char *name; - int bitspp; - void (*paint_setup) (paintinfo * p, unsigned char *dest); -}; - -static void paint_setup_I420 (paintinfo * p, unsigned char *dest); -static void paint_setup_YV12 (paintinfo * p, unsigned char *dest); -static void paint_setup_YUY2 (paintinfo * p, unsigned char *dest); -static void paint_setup_UYVY (paintinfo * p, unsigned char *dest); -static void paint_setup_YVYU (paintinfo * p, unsigned char *dest); -static void paint_setup_IYU2 (paintinfo * p, unsigned char *dest); -static void paint_setup_Y41B (paintinfo * p, unsigned char *dest); -static void paint_setup_Y42B (paintinfo * p, unsigned char *dest); -static void paint_setup_Y800 (paintinfo * p, unsigned char *dest); -static void paint_setup_AYUV (paintinfo * p, unsigned char *dest); - -#if 0 -static void paint_setup_IMC1 (paintinfo * p, unsigned char *dest); -static void paint_setup_IMC2 (paintinfo * p, unsigned char *dest); -static void paint_setup_IMC3 (paintinfo * p, unsigned char *dest); -static void paint_setup_IMC4 (paintinfo * p, unsigned char *dest); -#endif -static void paint_setup_YUV9 (paintinfo * p, unsigned char *dest); -static void paint_setup_YVU9 (paintinfo * p, unsigned char *dest); - -int fourcc_get_size (struct fourcc_list_struct *fourcc, int w, int h); - -struct fourcc_list_struct fourcc_list[] = { -/* packed */ - {"YUY2", "YUY2", 16, paint_setup_YUY2}, - {"UYVY", "UYVY", 16, paint_setup_UYVY}, - {"Y422", "Y422", 16, paint_setup_UYVY}, - {"UYNV", "UYNV", 16, paint_setup_UYVY}, /* FIXME: UYNV? */ - {"YVYU", "YVYU", 16, paint_setup_YVYU}, - {"AYUV", "AYUV", 32, paint_setup_AYUV}, - - /* interlaced */ - /*{ "IUYV", "IUY2", 16, paint_setup_YVYU }, */ - - /* inverted */ - /*{ "cyuv", "cyuv", 16, paint_setup_YVYU }, */ - - /*{ "Y41P", "Y41P", 12, paint_setup_YVYU }, */ - - /* interlaced */ - /*{ "IY41", "IY41", 12, paint_setup_YVYU }, */ - - /*{ "Y211", "Y211", 8, paint_setup_YVYU }, */ - - /*{ "Y41T", "Y41T", 12, paint_setup_YVYU }, */ - /*{ "Y42P", "Y42P", 16, paint_setup_YVYU }, */ - /*{ "CLJR", "CLJR", 8, paint_setup_YVYU }, */ - /*{ "IYU1", "IYU1", 12, paint_setup_YVYU }, */ - {"IYU2", "IYU2", 24, paint_setup_IYU2}, - -/* planar */ - /* YVU9 */ - {"YVU9", "YVU9", 9, paint_setup_YVU9}, - /* YUV9 */ - {"YUV9", "YUV9", 9, paint_setup_YUV9}, - /* IF09 */ - /* YV12 */ - {"YV12", "YV12", 12, paint_setup_YV12}, - /* I420 */ - {"I420", "I420", 12, paint_setup_I420}, - /* NV12 */ - /* NV21 */ -#if 0 - /* IMC1 */ - {"IMC1", "IMC1", 16, paint_setup_IMC1}, - /* IMC2 */ - {"IMC2", "IMC2", 12, paint_setup_IMC2}, - /* IMC3 */ - {"IMC3", "IMC3", 16, paint_setup_IMC3}, - /* IMC4 */ - {"IMC4", "IMC4", 12, paint_setup_IMC4}, -#endif - /* CLPL */ - /* Y41B */ - {"Y41B", "Y41B", 12, paint_setup_Y41B}, - /* Y42B */ - {"Y42B", "Y42B", 16, paint_setup_Y42B}, - /* Y800 grayscale */ - {"Y800", "Y800", 8, paint_setup_Y800} -}; - -/* returns the size in bytes for one video frame of the given dimensions - * given the fourcc */ -int -fourcc_get_size (struct fourcc_list_struct *fourcc, int w, int h) -{ - paintinfo pi = { NULL, }; - paintinfo *p = π - - p->width = w; - p->height = h; - - fourcc->paint_setup (p, NULL); - - return (unsigned long) p->endptr; -} - -static void -paint_setup_I420 (paintinfo * p, unsigned char *dest) -{ - p->yp = dest; - p->ystride = GST_ROUND_UP_4 (p->width); - p->up = p->yp + p->ystride * GST_ROUND_UP_2 (p->height); - p->ustride = GST_ROUND_UP_8 (p->width) / 2; - p->vp = p->up + p->ustride * GST_ROUND_UP_2 (p->height) / 2; - p->vstride = GST_ROUND_UP_8 (p->ystride) / 2; - p->endptr = p->vp + p->vstride * GST_ROUND_UP_2 (p->height) / 2; -} - -static void -paint_setup_YV12 (paintinfo * p, unsigned char *dest) -{ - p->yp = dest; - p->ystride = GST_ROUND_UP_4 (p->width); - p->vp = p->yp + p->ystride * GST_ROUND_UP_2 (p->height); - p->vstride = GST_ROUND_UP_8 (p->ystride) / 2; - p->up = p->vp + p->vstride * GST_ROUND_UP_2 (p->height) / 2; - p->ustride = GST_ROUND_UP_8 (p->ystride) / 2; - p->endptr = p->up + p->ustride * GST_ROUND_UP_2 (p->height) / 2; -} - -static void -paint_setup_AYUV (paintinfo * p, unsigned char *dest) -{ - p->ap = dest; - p->yp = dest + 1; - p->up = dest + 2; - p->vp = dest + 3; - p->ystride = p->width * 4; - p->endptr = dest + p->ystride * p->height; -} - -static void -paint_setup_YUY2 (paintinfo * p, unsigned char *dest) -{ - p->yp = dest; - p->up = dest + 1; - p->vp = dest + 3; - p->ystride = GST_ROUND_UP_2 (p->width) * 2; - p->endptr = dest + p->ystride * p->height; -} - -static void -paint_setup_UYVY (paintinfo * p, unsigned char *dest) -{ - p->yp = dest + 1; - p->up = dest; - p->vp = dest + 2; - p->ystride = GST_ROUND_UP_2 (p->width) * 2; - p->endptr = dest + p->ystride * p->height; -} - -static void -paint_setup_YVYU (paintinfo * p, unsigned char *dest) -{ - p->yp = dest; - p->up = dest + 3; - p->vp = dest + 1; - p->ystride = GST_ROUND_UP_2 (p->width) * 2; - p->endptr = dest + p->ystride * p->height; -} - -static void -paint_setup_IYU2 (paintinfo * p, unsigned char *dest) -{ - /* untested */ - p->yp = dest + 1; - p->up = dest + 0; - p->vp = dest + 2; - p->ystride = GST_ROUND_UP_4 (p->width * 3); - p->endptr = dest + p->ystride * p->height; -} - -static void -paint_setup_Y41B (paintinfo * p, unsigned char *dest) -{ - p->yp = dest; - p->ystride = GST_ROUND_UP_4 (p->width); - p->up = p->yp + p->ystride * p->height; - p->ustride = GST_ROUND_UP_16 (p->width) / 4; - p->vp = p->up + p->ustride * p->height; - p->vstride = GST_ROUND_UP_16 (p->width) / 4; - p->endptr = p->vp + p->vstride * p->height; -} - -static void -paint_setup_Y42B (paintinfo * p, unsigned char *dest) -{ - p->yp = dest; - p->ystride = GST_ROUND_UP_4 (p->width); - p->up = p->yp + p->ystride * p->height; - p->ustride = GST_ROUND_UP_8 (p->width) / 2; - p->vp = p->up + p->ustride * p->height; - p->vstride = GST_ROUND_UP_8 (p->width) / 2; - p->endptr = p->vp + p->vstride * p->height; -} - -static void -paint_setup_Y800 (paintinfo * p, unsigned char *dest) -{ - /* untested */ - p->yp = dest; - p->ystride = GST_ROUND_UP_4 (p->width); - p->endptr = dest + p->ystride * p->height; -} - -#if 0 -static void -paint_setup_IMC1 (paintinfo * p, unsigned char *dest) -{ - p->yp = dest; - p->up = dest + p->width * p->height; - p->vp = dest + p->width * p->height + p->width * p->height / 2; -} - -static void -paint_setup_IMC2 (paintinfo * p, unsigned char *dest) -{ - p->yp = dest; - p->vp = dest + p->width * p->height; - p->up = dest + p->width * p->height + p->width / 2; -} - -static void -paint_setup_IMC3 (paintinfo * p, unsigned char *dest) -{ - p->yp = dest; - p->up = dest + p->width * p->height + p->width * p->height / 2; - p->vp = dest + p->width * p->height; -} - -static void -paint_setup_IMC4 (paintinfo * p, unsigned char *dest) -{ - p->yp = dest; - p->vp = dest + p->width * p->height + p->width / 2; - p->up = dest + p->width * p->height; -} -#endif - -static void -paint_setup_YVU9 (paintinfo * p, unsigned char *dest) -{ - int h = GST_ROUND_UP_4 (p->height); - - p->yp = dest; - p->ystride = GST_ROUND_UP_4 (p->width); - p->vp = p->yp + p->ystride * GST_ROUND_UP_4 (p->height); - p->vstride = GST_ROUND_UP_4 (p->ystride / 4); - p->up = p->vp + p->vstride * GST_ROUND_UP_4 (h / 4); - p->ustride = GST_ROUND_UP_4 (p->ystride / 4); - p->endptr = p->up + p->ustride * GST_ROUND_UP_4 (h / 4); -} - -static void -paint_setup_YUV9 (paintinfo * p, unsigned char *dest) -{ - /* untested */ - int h = GST_ROUND_UP_4 (p->height); - - p->yp = dest; - p->ystride = GST_ROUND_UP_4 (p->width); - p->up = p->yp + p->ystride * h; - p->ustride = GST_ROUND_UP_4 (p->ystride / 4); - p->vp = p->up + p->ustride * GST_ROUND_UP_4 (h / 4); - p->vstride = GST_ROUND_UP_4 (p->ystride / 4); - p->endptr = p->vp + p->vstride * GST_ROUND_UP_4 (h / 4); -} - -#define gst_video_format_is_packed video_format_is_packed -static gboolean -video_format_is_packed (GstVideoFormat fmt) -{ - switch (fmt) { - case GST_VIDEO_FORMAT_I420: - case GST_VIDEO_FORMAT_YV12: - case GST_VIDEO_FORMAT_Y41B: - case GST_VIDEO_FORMAT_Y42B: - return FALSE; - case GST_VIDEO_FORMAT_YUY2: - case GST_VIDEO_FORMAT_YVYU: - case GST_VIDEO_FORMAT_UYVY: - case GST_VIDEO_FORMAT_AYUV: - case GST_VIDEO_FORMAT_RGBx: - case GST_VIDEO_FORMAT_BGRx: - case GST_VIDEO_FORMAT_xRGB: - case GST_VIDEO_FORMAT_xBGR: - case GST_VIDEO_FORMAT_RGBA: - case GST_VIDEO_FORMAT_BGRA: - case GST_VIDEO_FORMAT_ARGB: - case GST_VIDEO_FORMAT_ABGR: - case GST_VIDEO_FORMAT_RGB: - case GST_VIDEO_FORMAT_BGR: - return TRUE; - default: - g_return_val_if_reached (FALSE); - } - return FALSE; -} - -GST_START_TEST (test_video_formats) -{ - guint i; - - for (i = 0; i < G_N_ELEMENTS (fourcc_list); ++i) { - GstVideoFormat fmt; - const gchar *s; - guint32 fourcc; - guint w, h; - - s = fourcc_list[i].fourcc; - fourcc = GST_MAKE_FOURCC (s[0], s[1], s[2], s[3]); - fmt = gst_video_format_from_fourcc (fourcc); - - if (fmt == GST_VIDEO_FORMAT_UNKNOWN) - continue; - - GST_INFO ("Fourcc %s, packed=%d", fourcc_list[i].fourcc, - gst_video_format_is_packed (fmt)); - - fail_unless (gst_video_format_is_yuv (fmt)); - - /* use any non-NULL pointer so we can compare against NULL */ - { - paintinfo paintinfo = { 0, }; - fourcc_list[i].paint_setup (&paintinfo, (unsigned char *) s); - if (paintinfo.ap != NULL) { - fail_unless (gst_video_format_has_alpha (fmt)); - } else { - fail_if (gst_video_format_has_alpha (fmt)); - } - } - - for (w = 1; w <= 65; ++w) { - for (h = 1; h <= 65; ++h) { - paintinfo paintinfo = { 0, }; - guint off0, off1, off2, off3; - guint size; - - GST_LOG ("%s, %dx%d", fourcc_list[i].fourcc, w, h); - - paintinfo.width = w; - paintinfo.height = h; - fourcc_list[i].paint_setup (&paintinfo, NULL); - fail_unless_equals_int (gst_video_format_get_row_stride (fmt, 0, w), - paintinfo.ystride); - if (!gst_video_format_is_packed (fmt)) { - /* planar */ - fail_unless_equals_int (gst_video_format_get_row_stride (fmt, 1, w), - paintinfo.ustride); - fail_unless_equals_int (gst_video_format_get_row_stride (fmt, 2, w), - paintinfo.vstride); - /* check component_width * height against offsets/size somehow? */ - } - - size = gst_video_format_get_size (fmt, w, h); - fail_unless_equals_int (size, (unsigned long) paintinfo.endptr); - - off0 = gst_video_format_get_component_offset (fmt, 0, w, h); - fail_unless_equals_int (off0, (unsigned long) paintinfo.yp); - off1 = gst_video_format_get_component_offset (fmt, 1, w, h); - fail_unless_equals_int (off1, (unsigned long) paintinfo.up); - off2 = gst_video_format_get_component_offset (fmt, 2, w, h); - fail_unless_equals_int (off2, (unsigned long) paintinfo.vp); - - /* should be 0 if there's no alpha component */ - off3 = gst_video_format_get_component_offset (fmt, 3, w, h); - fail_unless_equals_int (off3, (unsigned long) paintinfo.ap); - - /* some gstvideo checks ... (FIXME: fails for Y41B and Y42B; not sure - * if the check or the _get_component_size implementation is wrong) */ - if (fmt != GST_VIDEO_FORMAT_Y41B && fmt != GST_VIDEO_FORMAT_Y42B) { - guint cs0, cs1, cs2, cs3; - - cs0 = gst_video_format_get_component_width (fmt, 0, w) * - gst_video_format_get_component_height (fmt, 0, h); - cs1 = gst_video_format_get_component_width (fmt, 1, w) * - gst_video_format_get_component_height (fmt, 1, h); - cs2 = gst_video_format_get_component_width (fmt, 2, w) * - gst_video_format_get_component_height (fmt, 2, h); - - /* GST_LOG ("cs0=%d,cs1=%d,cs2=%d,off0=%d,off1=%d,off2=%d,size=%d", - cs0, cs1, cs2, off0, off1, off2, size); */ - - if (!gst_video_format_is_packed (fmt)) - fail_unless (cs0 <= off1); - - if (gst_video_format_has_alpha (fmt)) { - cs3 = gst_video_format_get_component_width (fmt, 3, w) * - gst_video_format_get_component_height (fmt, 3, h); - fail_unless (cs3 < size); - /* U/V/alpha shouldn't take up more space than the Y component */ - fail_if (cs1 > cs0, "cs1 (%d) should be <= cs0 (%d)", cs1, cs0); - fail_if (cs2 > cs0, "cs2 (%d) should be <= cs0 (%d)", cs2, cs0); - fail_if (cs3 > cs0, "cs3 (%d) should be <= cs0 (%d)", cs3, cs0); - - /* all components together shouldn't take up more space than size */ - fail_unless (cs0 + cs1 + cs2 + cs3 <= size); - } else { - /* U/V shouldn't take up more space than the Y component */ - fail_if (cs1 > cs0, "cs1 (%d) should be <= cs0 (%d)", cs1, cs0); - fail_if (cs2 > cs0, "cs2 (%d) should be <= cs0 (%d)", cs2, cs0); - - /* all components together shouldn't take up more space than size */ - fail_unless (cs0 + cs1 + cs2 <= size, - "cs0 (%d) + cs1 (%d) + cs2 (%d) should be <= size (%d)", - cs0, cs1, cs2, size); - } - } - } - } - } -} - -GST_END_TEST; - -GST_START_TEST (test_dar_calc) -{ - guint display_ratio_n, display_ratio_d; - - /* Ensure that various Display Ratio calculations are correctly done */ - /* video 768x576, par 16/15, display par 16/15 = 4/3 */ - fail_unless (gst_video_calculate_display_ratio (&display_ratio_n, - &display_ratio_d, 768, 576, 16, 15, 16, 15)); - fail_unless (display_ratio_n == 4 && display_ratio_d == 3); - - /* video 720x480, par 32/27, display par 1/1 = 16/9 */ - fail_unless (gst_video_calculate_display_ratio (&display_ratio_n, - &display_ratio_d, 720, 480, 32, 27, 1, 1)); - fail_unless (display_ratio_n == 16 && display_ratio_d == 9); - - /* video 360x288, par 533333/500000, display par 16/15 = - * dar 1599999/1600000 */ - fail_unless (gst_video_calculate_display_ratio (&display_ratio_n, - &display_ratio_d, 360, 288, 533333, 500000, 16, 15)); - fail_unless (display_ratio_n == 1599999 && display_ratio_d == 1280000); -} - -GST_END_TEST; - -GST_START_TEST (test_parse_caps_rgb) -{ - struct - { - const gchar *tmpl_caps_string; - GstVideoFormat fmt; - } formats[] = { - /* 24 bit */ - { - GST_VIDEO_CAPS_RGB, GST_VIDEO_FORMAT_RGB}, { - GST_VIDEO_CAPS_BGR, GST_VIDEO_FORMAT_BGR}, - /* 32 bit (no alpha) */ - { - GST_VIDEO_CAPS_RGBx, GST_VIDEO_FORMAT_RGBx}, { - GST_VIDEO_CAPS_xRGB, GST_VIDEO_FORMAT_xRGB}, { - GST_VIDEO_CAPS_BGRx, GST_VIDEO_FORMAT_BGRx}, { - GST_VIDEO_CAPS_xBGR, GST_VIDEO_FORMAT_xBGR}, - /* 32 bit (with alpha) */ - { - GST_VIDEO_CAPS_RGBA, GST_VIDEO_FORMAT_RGBA}, { - GST_VIDEO_CAPS_ARGB, GST_VIDEO_FORMAT_ARGB}, { - GST_VIDEO_CAPS_BGRA, GST_VIDEO_FORMAT_BGRA}, { - GST_VIDEO_CAPS_ABGR, GST_VIDEO_FORMAT_ABGR} - }; - gint i; - - for (i = 0; i < G_N_ELEMENTS (formats); ++i) { - GstVideoFormat fmt = GST_VIDEO_FORMAT_UNKNOWN; - GstCaps *caps, *caps2; - int w = -1, h = -1; - - caps = gst_caps_from_string (formats[i].tmpl_caps_string); - gst_caps_set_simple (caps, "width", G_TYPE_INT, 2 * (i + 1), "height", - G_TYPE_INT, i + 1, "framerate", GST_TYPE_FRACTION, 15, 1, - "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL); - g_assert (gst_caps_is_fixed (caps)); - - GST_DEBUG ("testing caps: %" GST_PTR_FORMAT, caps); - - fail_unless (gst_video_format_parse_caps (caps, &fmt, &w, &h)); - fail_unless_equals_int (fmt, formats[i].fmt); - fail_unless_equals_int (w, 2 * (i + 1)); - fail_unless_equals_int (h, i + 1); - - /* make sure they're serialised back correctly */ - caps2 = gst_video_format_new_caps (fmt, w, h, 15, 1, 1, 1); - fail_unless (caps != NULL); - fail_unless (gst_caps_is_equal (caps, caps2)); - - gst_caps_unref (caps); - gst_caps_unref (caps2); - } -} - -GST_END_TEST; - -GST_START_TEST (test_events) -{ - GstEvent *e; - gboolean in_still; - - e = gst_video_event_new_still_frame (TRUE); - fail_if (e == NULL, "Failed to create still frame event"); - fail_unless (gst_video_event_parse_still_frame (e, &in_still), - "Failed to parse still frame event"); - fail_unless (gst_video_event_parse_still_frame (e, NULL), - "Failed to parse still frame event w/ in_still == NULL"); - fail_unless (in_still == TRUE); - gst_event_unref (e); - - e = gst_video_event_new_still_frame (FALSE); - fail_if (e == NULL, "Failed to create still frame event"); - fail_unless (gst_video_event_parse_still_frame (e, &in_still), - "Failed to parse still frame event"); - fail_unless (gst_video_event_parse_still_frame (e, NULL), - "Failed to parse still frame event w/ in_still == NULL"); - fail_unless (in_still == FALSE); - gst_event_unref (e); -} - -GST_END_TEST; - -static Suite * -video_suite (void) -{ - Suite *s = suite_create ("video support library"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_video_formats); - tcase_add_test (tc_chain, test_dar_calc); - tcase_add_test (tc_chain, test_parse_caps_rgb); - tcase_add_test (tc_chain, test_events); - - return s; -} - -GST_CHECK_MAIN (video); diff --git a/tests/check/pipelines/.gitignore b/tests/check/pipelines/.gitignore deleted file mode 100644 index 500b0d1f..00000000 --- a/tests/check/pipelines/.gitignore +++ /dev/null @@ -1,9 +0,0 @@ -.dirstamp -basetime -gio -simple-launch-lines -theoraenc -vorbisdec -vorbisenc -oggmux -streamheader diff --git a/tests/check/pipelines/basetime.c b/tests/check/pipelines/basetime.c deleted file mode 100644 index 00072ef0..00000000 --- a/tests/check/pipelines/basetime.c +++ /dev/null @@ -1,153 +0,0 @@ -/* GStreamer - * - * unit test for audiotestsrc basetime handling - * - * Copyright (C) 2009 Maemo Multimedia <multimedia at maemo dot org> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/check/gstcheck.h> - -#ifndef GST_DISABLE_PARSE - -static GstClockTime old_ts = GST_CLOCK_TIME_NONE; - -static gboolean -break_mainloop (gpointer data) -{ - GMainLoop *loop; - - loop = (GMainLoop *) data; - g_main_loop_quit (loop); - - return FALSE; -} - -static gboolean -buffer_probe_cb (GstPad * pad, GstBuffer * buffer) -{ - if (old_ts != GST_CLOCK_TIME_NONE) { - fail_unless (GST_BUFFER_TIMESTAMP (buffer) != old_ts, - "Two buffers had same timestamp"); - } - old_ts = GST_BUFFER_TIMESTAMP (buffer); - - return TRUE; -} - -GST_START_TEST (test_basetime_calculation) -{ - GstElement *p1, *bin; - GstElement *asrc, *asink; - GstPad *pad; - GMainLoop *loop; - - loop = g_main_loop_new (NULL, FALSE); - - /* The "main" pipeline */ - p1 = gst_parse_launch ("fakesrc ! fakesink", NULL); - fail_if (p1 == NULL); - - /* Create a sub-bin that is activated only in "certain situations" */ - asrc = gst_element_factory_make (DEFAULT_AUDIOSRC, NULL); - if (asrc == NULL) { - GST_WARNING ("Cannot run test. test audio source %s not available", - DEFAULT_AUDIOSRC); - gst_element_set_state (p1, GST_STATE_NULL); - gst_object_unref (p1); - return; - } - asink = gst_element_factory_make ("fakesink", NULL); - - bin = gst_bin_new ("audiobin"); - gst_bin_add_many (GST_BIN (bin), asrc, asink, NULL); - gst_element_link (asrc, asink); - - gst_bin_add (GST_BIN (p1), bin); - gst_element_set_state (p1, GST_STATE_READY); - - pad = gst_element_get_static_pad (asink, "sink"); - fail_unless (pad != NULL, "Could not get pad out of sink"); - - gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe_cb), NULL); - gst_element_set_locked_state (bin, TRUE); - - /* Run main pipeline first */ - gst_element_set_state (p1, GST_STATE_PLAYING); - g_timeout_add (2 * 1000, break_mainloop, loop); - g_main_loop_run (loop); - - /* Now activate the audio pipeline */ - gst_element_set_locked_state (bin, FALSE); - gst_element_set_state (p1, GST_STATE_PAUSED); - - /* Normally our custom audiobin would send this message */ - gst_element_post_message (asrc, - gst_message_new_clock_provide (GST_OBJECT (asrc), NULL, TRUE)); - - /* At this point a new clock is selected */ - gst_element_set_state (p1, GST_STATE_PLAYING); - - g_timeout_add (2 * 1000, break_mainloop, loop); - g_main_loop_run (loop); - - gst_object_unref (pad); - gst_element_set_state (p1, GST_STATE_NULL); - gst_object_unref (p1); -} - -GST_END_TEST; - -#endif /* #ifndef GST_DISABLE_PARSE */ - -static Suite * -baseaudiosrc_suite (void) -{ - Suite *s = suite_create ("baseaudiosrc"); - TCase *tc_chain = tcase_create ("general"); - - /* timeout 6 sec */ - tcase_set_timeout (tc_chain, 6); - suite_add_tcase (s, tc_chain); - -#ifndef GST_DISABLE_PARSE - tcase_add_test (tc_chain, test_basetime_calculation); -#endif - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = baseaudiosrc_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/pipelines/gio.c b/tests/check/pipelines/gio.c deleted file mode 100644 index b7bbc199..00000000 --- a/tests/check/pipelines/gio.c +++ /dev/null @@ -1,181 +0,0 @@ -/* GStreamer - * - * unit test for GIO - * - * Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org> - * - * 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 <gst/check/gstcheck.h> -#include <gst/check/gstbufferstraw.h> -#include <gio/gio.h> - -static gboolean got_eos = FALSE; - -static gboolean -message_handler (GstBus * bus, GstMessage * msg, gpointer data) -{ - GMainLoop *loop = (GMainLoop *) data; - - switch (GST_MESSAGE_TYPE (msg)) { - case GST_MESSAGE_EOS: - got_eos = TRUE; - g_main_loop_quit (loop); - break; - case GST_MESSAGE_ERROR:{ - gchar *debug; - GError *err; - - gst_message_parse_error (msg, &err, &debug); - g_free (debug); - - /* Will abort the check */ - g_warning ("Error: %s\n", err->message); - g_error_free (err); - - g_main_loop_quit (loop); - break; - } - default: - break; - } - - return TRUE; -} - -GST_START_TEST (test_memory_stream) -{ - GMainLoop *loop; - GstElement *bin; - GstElement *src, *sink; - GstBus *bus; - - GMemoryInputStream *input; - GMemoryOutputStream *output; - - guint8 *in_data; - guint8 *out_data; - gint i; - GstFormat fmt = GST_FORMAT_BYTES; - gint64 duration; - - got_eos = FALSE; - - in_data = g_new (guint8, 512); - out_data = g_new (guint8, 512); - for (i = 0; i < 512; i++) - in_data[i] = i % 256; - - input = - G_MEMORY_INPUT_STREAM (g_memory_input_stream_new_from_data (in_data, 512, - (GDestroyNotify) g_free)); - - output = G_MEMORY_OUTPUT_STREAM (g_memory_output_stream_new (out_data, 512, - (GReallocFunc) g_realloc, (GDestroyNotify) g_free)); - out_data = NULL; - - loop = g_main_loop_new (NULL, FALSE); - - bin = gst_pipeline_new ("bin"); - - src = gst_element_factory_make ("giostreamsrc", "src"); - fail_unless (src != NULL); - g_object_set (G_OBJECT (src), "stream", input, NULL); - - sink = gst_element_factory_make ("giostreamsink", "sink"); - fail_unless (sink != NULL); - g_object_set (G_OBJECT (sink), "stream", output, NULL); - - gst_bin_add_many (GST_BIN (bin), src, sink, NULL); - - fail_unless (gst_element_link_many (src, sink, NULL)); - - bus = gst_element_get_bus (bin); - gst_bus_add_watch (bus, message_handler, loop); - gst_object_unref (bus); - - gst_element_set_state (bin, GST_STATE_PAUSED); - gst_element_get_state (bin, NULL, NULL, -1); - - fail_unless (gst_element_query_duration (bin, &fmt, &duration)); - fail_unless_equals_int (duration, 512); - - gst_element_set_state (bin, GST_STATE_PLAYING); - - g_main_loop_run (loop); - - gst_element_set_state (bin, GST_STATE_NULL); - - fail_unless (got_eos); - got_eos = FALSE; - - out_data = g_memory_output_stream_get_data (G_MEMORY_OUTPUT_STREAM (output)); - - for (i = 0; i < 512; i++) - fail_unless_equals_int (in_data[i], out_data[i]); - - gst_element_set_state (bin, GST_STATE_PAUSED); - gst_element_get_state (bin, NULL, NULL, -1); - - fail_unless (gst_element_query_duration (bin, &fmt, &duration)); - fail_unless_equals_int (duration, 512); - - gst_element_set_state (bin, GST_STATE_PLAYING); - - g_main_loop_run (loop); - - gst_element_set_state (bin, GST_STATE_NULL); - gst_object_unref (bin); - - fail_unless (got_eos); - - g_object_unref (input); - g_object_unref (output); - - g_main_loop_unref (loop); -} - -GST_END_TEST; - -static Suite * -gio_testsuite (void) -{ - Suite *s = suite_create ("gio"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - tcase_add_test (tc_chain, test_memory_stream); - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = gio_testsuite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/pipelines/oggmux.c b/tests/check/pipelines/oggmux.c deleted file mode 100644 index 16bb3f20..00000000 --- a/tests/check/pipelines/oggmux.c +++ /dev/null @@ -1,430 +0,0 @@ -/* GStreamer - * - * unit tests for oggmux - * - * Copyright (C) 2006 James Livingston <doclivingston at gmail.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <string.h> - -#include <gst/check/gstcheck.h> -#include <ogg/ogg.h> - - -typedef enum -{ - CODEC_UNKNOWN, - CODEC_VORBIS, - CODEC_THEORA, - CODEC_SPEEX, -} ChainCodec; - -typedef struct -{ - gboolean eos; - gulong serialno; - gint64 last_granule; - ChainCodec codec; -} ChainState; - -static ogg_sync_state oggsync; -static GHashTable *eos_chain_states; -static gulong probe_id; - - -static ChainCodec -get_page_codec (ogg_page * page) -{ - ChainCodec codec = CODEC_UNKNOWN; - ogg_stream_state state; - ogg_packet packet; - - ogg_stream_init (&state, ogg_page_serialno (page)); - if (ogg_stream_pagein (&state, page) == 0) { - if (ogg_stream_packetpeek (&state, &packet) > 0) { - if (strncmp ((char *) &packet.packet[1], "vorbis", - strlen ("vorbis")) == 0) - codec = CODEC_VORBIS; - else if (strncmp ((char *) &packet.packet[1], "theora", - strlen ("theora")) == 0) - codec = CODEC_THEORA; - else if (strncmp ((char *) &packet.packet[0], "Speex ", - strlen ("Speex ")) == 0) - codec = CODEC_SPEEX; - } - } - ogg_stream_clear (&state); - - return codec; -} - -static gboolean -check_chain_final_state (gpointer key, ChainState * state, gpointer data) -{ - fail_unless (state->eos, "missing EOS flag on chain %u", state->serialno); - - /* return TRUE to empty the chain table */ - return TRUE; -} - -static void -fail_if_audio (gpointer key, ChainState * state, gpointer data) -{ - fail_if (state->codec == CODEC_VORBIS, - "vorbis BOS occurred before theora BOS"); - fail_if (state->codec == CODEC_SPEEX, "speex BOS occurred before theora BOS"); -} - -static ChainState * -validate_ogg_page (ogg_page * page) -{ - gulong serialno; - gint64 granule; - ChainState *state; - - serialno = ogg_page_serialno (page); - granule = ogg_page_granulepos (page); - state = g_hash_table_lookup (eos_chain_states, GINT_TO_POINTER (serialno)); - - fail_if (ogg_page_packets (page) == 0 && granule != -1, - "Must have granulepos -1 when page has no packets, has %" G_GINT64_FORMAT, - granule); - - if (ogg_page_bos (page)) { - fail_unless (state == NULL, "Extraneous BOS flag on chain %u", serialno); - - state = g_new0 (ChainState, 1); - g_hash_table_insert (eos_chain_states, GINT_TO_POINTER (serialno), state); - state->serialno = serialno; - state->last_granule = granule; - state->codec = get_page_codec (page); - - /* check for things like BOS ordering, etc */ - switch (state->codec) { - case CODEC_THEORA: - /* check we have no vorbis/speex chains yet */ - g_hash_table_foreach (eos_chain_states, (GHFunc) fail_if_audio, NULL); - break; - case CODEC_VORBIS: - case CODEC_SPEEX: - /* no checks (yet) */ - break; - case CODEC_UNKNOWN: - default: - break; - } - } else if (ogg_page_eos (page)) { - fail_unless (state != NULL, "Missing BOS flag on chain %u", serialno); - state->eos = TRUE; - } else { - fail_unless (state != NULL, "Missing BOS flag on chain %u", serialno); - fail_unless (!state->eos, "Data after EOS flag on chain %u", serialno); - } - - if (granule != -1) { - fail_unless (granule >= state->last_granule, - "Granulepos out-of-order for chain %u: old=%" G_GINT64_FORMAT ", new=" - G_GINT64_FORMAT, serialno, state->last_granule, granule); - state->last_granule = granule; - } - - return state; -} - -static void -is_video (gpointer key, ChainState * state, gpointer data) -{ - if (state->codec == CODEC_THEORA) - *((gboolean *) data) = TRUE; -} - - -static gboolean -eos_buffer_probe (GstPad * pad, GstBuffer * buffer, gpointer unused) -{ - gint ret; - gint size; - guint8 *data; - gchar *oggbuffer; - ChainState *state = NULL; - gboolean has_video = FALSE; - - size = GST_BUFFER_SIZE (buffer); - data = GST_BUFFER_DATA (buffer); - - oggbuffer = ogg_sync_buffer (&oggsync, size); - memcpy (oggbuffer, data, size); - ogg_sync_wrote (&oggsync, size); - - do { - ogg_page page; - - ret = ogg_sync_pageout (&oggsync, &page); - if (ret > 0) - state = validate_ogg_page (&page); - } - while (ret != 0); - - if (state) { - /* Now, we can do buffer-level checks... - * If we have video somewhere, then we should have DELTA_UNIT set on all - * non-header (not IN_CAPS), non-video buffers - */ - g_hash_table_foreach (eos_chain_states, (GHFunc) is_video, &has_video); - if (has_video && state->codec != CODEC_THEORA) { - if (!GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_IN_CAPS)) - fail_unless (GST_BUFFER_FLAG_IS_SET (buffer, - GST_BUFFER_FLAG_DELTA_UNIT), - "Non-video buffer doesn't have DELTA_UNIT in stream with video"); - } - } - - return TRUE; -} - -static void -start_pipeline (GstElement * bin, GstPad * pad) -{ - GstStateChangeReturn ret; - - ogg_sync_init (&oggsync); - - eos_chain_states = - g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); - probe_id = - gst_pad_add_buffer_probe (pad, G_CALLBACK (eos_buffer_probe), NULL); - - ret = gst_element_set_state (bin, GST_STATE_PLAYING); - fail_if (ret == GST_STATE_CHANGE_FAILURE, "Could not start test pipeline"); - if (ret == GST_STATE_CHANGE_ASYNC) { - ret = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE); - fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not start test pipeline"); - } -} - -static void -stop_pipeline (GstElement * bin, GstPad * pad) -{ - GstStateChangeReturn ret; - - ret = gst_element_set_state (bin, GST_STATE_NULL); - fail_if (ret == GST_STATE_CHANGE_FAILURE, "Could not stop test pipeline"); - if (ret == GST_STATE_CHANGE_ASYNC) { - ret = gst_element_get_state (bin, NULL, NULL, GST_CLOCK_TIME_NONE); - fail_if (ret != GST_STATE_CHANGE_SUCCESS, "Could not stop test pipeline"); - } - - gst_pad_remove_buffer_probe (pad, (guint) probe_id); - ogg_sync_clear (&oggsync); - - /* check end conditions, such as EOS flags */ - g_hash_table_foreach_remove (eos_chain_states, - (GHRFunc) check_chain_final_state, NULL); -} - -static gboolean -eos_watch (GstBus * bus, GstMessage * message, GMainLoop * loop) -{ - if (GST_MESSAGE_TYPE (message) == GST_MESSAGE_EOS) { - g_main_loop_quit (loop); - } - return TRUE; -} - -static void -test_pipeline (const char *pipeline) -{ - GstElement *bin, *sink; - GstPad *pad, *sinkpad; - GstBus *bus; - GError *error = NULL; - GMainLoop *loop; - GstPadLinkReturn linkret; - - bin = gst_parse_launch (pipeline, &error); - fail_unless (bin != NULL, "Error parsing pipeline: %s", - error ? error->message : "(invalid error)"); - pad = gst_bin_find_unlinked_pad (GST_BIN (bin), GST_PAD_SRC); - fail_unless (pad != NULL, "Could not locate free src pad"); - - /* connect the fake sink */ - sink = gst_element_factory_make ("fakesink", "fake_sink"); - fail_unless (sink != NULL, "Could create fakesink"); - fail_unless (gst_bin_add (GST_BIN (bin), sink), "Could not insert fakesink"); - sinkpad = gst_element_get_static_pad (sink, "sink"); - fail_unless (sinkpad != NULL, "Could not get fakesink src pad"); - - linkret = gst_pad_link (pad, sinkpad); - fail_unless (GST_PAD_LINK_SUCCESSFUL (linkret), - "Could not link to fake sink"); - gst_object_unref (sinkpad); - - /* run until we receive EOS */ - loop = g_main_loop_new (NULL, FALSE); - bus = gst_element_get_bus (bin); - gst_bus_add_watch (bus, (GstBusFunc) eos_watch, loop); - gst_object_unref (bus); - - start_pipeline (bin, pad); - g_main_loop_run (loop); - - /* we're EOS now; make sure oggmux out caps have stream headers on them */ - { - GstStructure *s; - GstCaps *muxcaps; - - muxcaps = gst_pad_get_negotiated_caps (sinkpad); - fail_unless (muxcaps != NULL); - s = gst_caps_get_structure (muxcaps, 0); - fail_unless (gst_structure_has_name (s, "application/ogg")); - fail_unless (gst_structure_has_field (s, "streamheader")); - fail_unless (gst_structure_has_field_typed (s, "streamheader", - GST_TYPE_ARRAY)); - gst_caps_unref (muxcaps); - } - - stop_pipeline (bin, pad); - - /* clean up */ - g_main_loop_unref (loop); - gst_object_unref (pad); - gst_object_unref (bin); -} - -#ifdef HAVE_VORBIS -GST_START_TEST (test_vorbis) -{ - test_pipeline - ("audiotestsrc num-buffers=5 ! audioconvert ! vorbisenc ! oggmux"); -} - -GST_END_TEST; - -GST_START_TEST (test_vorbis_oggmux_unlinked) -{ - GstElement *pipe; - GstMessage *msg; - - pipe = gst_parse_launch ("audiotestsrc ! vorbisenc ! oggmux", NULL); - if (pipe == NULL) { - g_printerr ("Skipping test 'test_vorbis_oggmux_unlinked'"); - return; - } - /* no sink, no async state change */ - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED), - GST_STATE_CHANGE_SUCCESS); - /* we expect an error (without any criticals/warnings) */ - msg = gst_bus_timed_pop_filtered (GST_ELEMENT_BUS (pipe), -1, - GST_MESSAGE_ERROR); - gst_message_unref (msg); - fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_NULL), - GST_STATE_CHANGE_SUCCESS); - gst_object_unref (pipe); -} - -GST_END_TEST; -#endif - -#ifdef HAVE_THEORA -GST_START_TEST (test_theora) -{ - test_pipeline - ("videotestsrc num-buffers=5 ! ffmpegcolorspace ! theoraenc ! oggmux"); -} - -GST_END_TEST; -#endif - -#if (defined (HAVE_THEORA) && defined (HAVE_VORBIS)) -GST_START_TEST (test_theora_vorbis) -{ - test_pipeline - ("videotestsrc num-buffers=10 ! ffmpegcolorspace ! theoraenc ! queue ! oggmux name=mux " - "audiotestsrc num-buffers=2 ! audioconvert ! vorbisenc ! queue ! mux."); -} - -GST_END_TEST; - -GST_START_TEST (test_vorbis_theora) -{ - test_pipeline - ("videotestsrc num-buffers=2 ! ffmpegcolorspace ! theoraenc ! queue ! oggmux name=mux " - "audiotestsrc num-buffers=10 ! audioconvert ! vorbisenc ! queue ! mux."); -} - -GST_END_TEST; -#endif - -GST_START_TEST (test_simple_cleanup) -{ - GstElement *oggmux; - - oggmux = gst_element_factory_make ("oggmux", NULL); - gst_object_unref (oggmux); -} - -GST_END_TEST; - -GST_START_TEST (test_request_pad_cleanup) -{ - GstElement *oggmux; - GstPad *pad; - - oggmux = gst_element_factory_make ("oggmux", NULL); - pad = gst_element_get_request_pad (oggmux, "sink_%d"); - fail_unless (pad != NULL); - gst_object_unref (pad); - pad = gst_element_get_request_pad (oggmux, "sink_%d"); - fail_unless (pad != NULL); - gst_object_unref (pad); - gst_object_unref (oggmux); -} - -GST_END_TEST; - -static Suite * -oggmux_suite (void) -{ - Suite *s = suite_create ("oggmux"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); -#ifdef HAVE_VORBIS - tcase_add_test (tc_chain, test_vorbis); - tcase_add_test (tc_chain, test_vorbis_oggmux_unlinked); -#endif - -#ifdef HAVE_THEORA - tcase_add_test (tc_chain, test_theora); -#endif - -#if (defined (HAVE_THEORA) && defined (HAVE_VORBIS)) - tcase_add_test (tc_chain, test_vorbis_theora); - tcase_add_test (tc_chain, test_theora_vorbis); -#endif - - tcase_add_test (tc_chain, test_simple_cleanup); - tcase_add_test (tc_chain, test_request_pad_cleanup); - return s; -} - -GST_CHECK_MAIN (oggmux); diff --git a/tests/check/pipelines/simple-launch-lines.c b/tests/check/pipelines/simple-launch-lines.c deleted file mode 100644 index 51c3052e..00000000 --- a/tests/check/pipelines/simple-launch-lines.c +++ /dev/null @@ -1,240 +0,0 @@ -/* GStreamer - * Copyright (C) 2005 Andy Wingo <wingo@pobox.com> - * - * simple_launch_lines.c: Unit test for simple pipelines - * - * 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 <gst/check/gstcheck.h> - -#ifndef GST_DISABLE_PARSE - -static GstElement * -setup_pipeline (const gchar * pipe_descr) -{ - GstElement *pipeline; - - GST_LOG ("pipeline: %s", pipe_descr); - pipeline = gst_parse_launch (pipe_descr, NULL); - g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL); - return pipeline; -} - -/* - * run_pipeline: - * @pipe: the pipeline to run - * @desc: the description for use in messages - * @events: is a mask of expected events - * @tevent: is the expected terminal event. - * - * the poll call will time out after half a second. - */ -static void -run_pipeline (GstElement * pipe, const gchar * descr, - GstMessageType events, GstMessageType tevent) -{ - GstBus *bus; - GstMessage *message; - GstMessageType revent; - GstStateChangeReturn ret; - - g_assert (pipe); - bus = gst_element_get_bus (pipe); - g_assert (bus); - - fail_if (gst_element_set_state (pipe, GST_STATE_PLAYING) == - GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to playing", descr); - ret = gst_element_get_state (pipe, NULL, NULL, 10 * GST_SECOND); - if (ret == GST_STATE_CHANGE_ASYNC) { - g_critical ("Pipeline '%s' failed to go to PLAYING fast enough", descr); - goto done; - } else if (ret != GST_STATE_CHANGE_SUCCESS) { - g_critical ("Pipeline '%s' failed to go into PLAYING state", descr); - goto done; - } - - while (1) { - message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2); - - - /* always have to pop the message before getting back into poll */ - if (message) { - revent = GST_MESSAGE_TYPE (message); - gst_message_unref (message); - } else { - revent = GST_MESSAGE_UNKNOWN; - } - - if (revent == tevent) { - break; - } else if (revent == GST_MESSAGE_UNKNOWN) { - g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s", - tevent, descr); - break; - } else if (revent & events) { - continue; - } - g_critical - ("Unexpected message received of type %d, '%s', looking for %d: %s", - revent, gst_message_type_get_name (revent), tevent, descr); - } - -done: - fail_if (gst_element_set_state (pipe, GST_STATE_NULL) == - GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to NULL", descr); - gst_element_get_state (pipe, NULL, NULL, GST_CLOCK_TIME_NONE); - gst_object_unref (pipe); - - gst_bus_set_flushing (bus, TRUE); - gst_object_unref (bus); -} - -GST_START_TEST (test_element_negotiation) -{ - gchar *s; - - /* Ensures that filtering buffers with unknown caps down to fixed-caps - * will apply those caps to the buffers. - * see http://bugzilla.gnome.org/show_bug.cgi?id=315126 */ - s = "fakesrc num-buffers=2 ! " - "audio/x-raw-int,width=16,depth=16,rate=22050,channels=1," - "signed=(boolean)true,endianness=1234 ! " - "audioconvert ! audio/x-raw-int,width=16,depth=16,rate=22050,channels=1 " - "! fakesink"; - run_pipeline (setup_pipeline (s), s, - GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), - GST_MESSAGE_UNKNOWN); - -#ifdef HAVE_LIBVISUAL - s = "audiotestsrc num-buffers=30 ! tee name=t ! alsasink t. ! audioconvert ! " - "libvisual_lv_scope ! ffmpegcolorspace ! xvimagesink"; - run_pipeline (setup_pipeline (s), s, - GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), - GST_MESSAGE_UNKNOWN); -#endif -} - -GST_END_TEST; - -GST_START_TEST (test_basetransform_based) -{ - /* Each of these tests is to check whether various basetransform based - * elements can select output caps when not allowed to do passthrough - * and going to a generic sink such as fakesink or filesink */ - const gchar *s; - - /* Check that videoscale can pick a height given only a width */ - s = "videotestsrc num-buffers=2 ! " - "video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! " - "videoscale ! video/x-raw-yuv,width=640 ! fakesink"; - run_pipeline (setup_pipeline (s), s, - GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), - GST_MESSAGE_UNKNOWN); - - /* Test that ffmpegcolorspace can pick an output format that isn't - * passthrough without completely specified output caps */ - s = "videotestsrc num-buffers=2 ! " - "video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! " - "ffmpegcolorspace ! video/x-raw-rgb ! fakesink"; - run_pipeline (setup_pipeline (s), s, - GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), - GST_MESSAGE_UNKNOWN); - - /* Check that audioresample can pick a samplerate to use from a - * range that doesn't include the input */ - s = "audiotestsrc num-buffers=2 ! " - "audio/x-raw-int,width=16,depth=16,rate=8000 ! " - "audioresample ! audio/x-raw-int,rate=[16000,48000] ! fakesink"; - run_pipeline (setup_pipeline (s), s, - GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), - GST_MESSAGE_UNKNOWN); - - /* Check that audioconvert can pick a depth to use, given a width */ - s = "audiotestsrc num-buffers=30 ! audio/x-raw-int,width=16,depth=16 ! " - "audioconvert ! " "audio/x-raw-int,width=32 ! fakesink"; - run_pipeline (setup_pipeline (s), s, - GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), - GST_MESSAGE_UNKNOWN); - - /* Check that videoscale doesn't claim to be able to transform input in - * formats it can't handle for a given scaling method; ffmpegcolorspace - * should then make sure a format that can be handled is chosen (4-tap - * scaling is not implemented for RGB and packed yuv currently) */ - s = "videotestsrc num-buffers=2 ! video/x-raw-rgb,width=64,height=64 ! " - "ffmpegcolorspace ! videoscale method=4-tap ! ffmpegcolorspace ! " - "video/x-raw-rgb,width=32,height=32,framerate=(fraction)30/1," - "pixel-aspect-ratio=(fraction)1/1,bpp=(int)24,depth=(int)24," - "red_mask=(int)16711680,green_mask=(int)65280,blue_mask=(int)255," - "endianness=(int)4321 ! fakesink"; - run_pipeline (setup_pipeline (s), s, - GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), - GST_MESSAGE_UNKNOWN); - s = "videotestsrc num-buffers=2 ! video/x-raw-yuv,format=(fourcc)AYUV," - "width=64,height=64 ! ffmpegcolorspace ! videoscale method=4-tap ! " - "ffmpegcolorspace ! video/x-raw-yuv,format=(fourcc)AYUV,width=32," - "height=32 ! fakesink"; - run_pipeline (setup_pipeline (s), s, - GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), - GST_MESSAGE_UNKNOWN); - /* make sure nothing funny happens in passthrough mode (we don't check that - * passthrough mode is chosen though) */ - s = "videotestsrc num-buffers=2 ! video/x-raw-yuv,format=(fourcc)I420," - "width=64,height=64 ! ffmpegcolorspace ! videoscale method=4-tap ! " - "ffmpegcolorspace ! video/x-raw-yuv,format=(fourcc)I420,width=32," - "height=32 ! fakesink"; - run_pipeline (setup_pipeline (s), s, - GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING), - GST_MESSAGE_UNKNOWN); -} - -GST_END_TEST; - -#endif /* #ifndef GST_DISABLE_PARSE */ -static Suite * -simple_launch_lines_suite (void) -{ - Suite *s = suite_create ("Pipelines"); - TCase *tc_chain = tcase_create ("linear"); - - /* time out after 60s, not the default 3 */ - tcase_set_timeout (tc_chain, 60); - - suite_add_tcase (s, tc_chain); -#ifndef GST_DISABLE_PARSE - tcase_add_test (tc_chain, test_element_negotiation); - tcase_add_test (tc_chain, test_basetransform_based); -#endif - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = simple_launch_lines_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/pipelines/streamheader.c b/tests/check/pipelines/streamheader.c deleted file mode 100644 index c3872ad2..00000000 --- a/tests/check/pipelines/streamheader.c +++ /dev/null @@ -1,256 +0,0 @@ -/* GStreamer - * - * unit test for streamheader handling - * - * Copyright (C) 2007 Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <unistd.h> - -#include <gst/check/gstcheck.h> -#include <gst/check/gstbufferstraw.h> - -#ifndef GST_DISABLE_PARSE - -/* this tests a gdp-serialized tag from audiotestsrc being sent only once - * to clients of multifdsink */ - -static int n_tags = 0; - -static gboolean -tag_event_probe_cb (GstPad * pad, GstEvent * event, GMainLoop * loop) -{ - switch (GST_EVENT_TYPE (event)) { - case GST_EVENT_TAG: - { - ++n_tags; - fail_if (n_tags > 1, "More than 1 tag received"); - break; - } - case GST_EVENT_EOS: - { - g_main_loop_quit (loop); - break; - } - default: - break; - } - - return TRUE; -} - -GST_START_TEST (test_multifdsink_gdp_tag) -{ - GstElement *p1, *p2; - GstElement *src, *sink, *depay; - GstPad *pad; - GMainLoop *loop; - int pfd[2]; - - loop = g_main_loop_new (NULL, FALSE); - - p1 = gst_parse_launch ("audiotestsrc num-buffers=10 ! gdppay" - " ! multifdsink name=p1sink", NULL); - fail_if (p1 == NULL); - p2 = gst_parse_launch ("fdsrc name=p2src ! gdpdepay name=depay" - " ! fakesink name=p2sink signal-handoffs=True", NULL); - fail_if (p2 == NULL); - - fail_if (pipe (pfd) == -1); - - - gst_element_set_state (p1, GST_STATE_READY); - - sink = gst_bin_get_by_name (GST_BIN (p1), "p1sink"); - g_signal_emit_by_name (sink, "add", pfd[1], NULL); - gst_object_unref (sink); - - src = gst_bin_get_by_name (GST_BIN (p2), "p2src"); - g_object_set (G_OBJECT (src), "fd", pfd[0], NULL); - gst_object_unref (src); - - depay = gst_bin_get_by_name (GST_BIN (p2), "depay"); - fail_if (depay == NULL); - - pad = gst_element_get_static_pad (depay, "src"); - fail_unless (pad != NULL, "Could not get pad out of depay"); - gst_object_unref (depay); - - gst_pad_add_event_probe (pad, G_CALLBACK (tag_event_probe_cb), loop); - - gst_element_set_state (p1, GST_STATE_PLAYING); - gst_element_set_state (p2, GST_STATE_PLAYING); - - g_main_loop_run (loop); - - assert_equals_int (n_tags, 1); - - gst_element_set_state (p1, GST_STATE_NULL); - gst_object_unref (p1); - gst_element_set_state (p2, GST_STATE_NULL); - gst_object_unref (p2); -} - -GST_END_TEST; - -#ifdef HAVE_VORBIS -/* this tests gdp-serialized Vorbis header pages being sent only once - * to clients of multifdsink; the gdp depayloader should deserialize - * exactly three in_caps buffers for the three header packets */ - -static int n_in_caps = 0; - -static gboolean -buffer_probe_cb (GstPad * pad, GstBuffer * buffer) -{ - if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_IN_CAPS)) { - GstCaps *caps; - GstStructure *s; - const GValue *sh; - GArray *buffers; - GstBuffer *buf; - int i; - gboolean found = FALSE; - - n_in_caps++; - - caps = gst_buffer_get_caps (buffer); - s = gst_caps_get_structure (caps, 0); - fail_unless (gst_structure_has_field (s, "streamheader")); - sh = gst_structure_get_value (s, "streamheader"); - buffers = g_value_peek_pointer (sh); - assert_equals_int (buffers->len, 3); - - - for (i = 0; i < 3; ++i) { - GValue *val; - - val = &g_array_index (buffers, GValue, i); - buf = g_value_peek_pointer (val); - fail_unless (GST_IS_BUFFER (buf)); - if (GST_BUFFER_SIZE (buf) == GST_BUFFER_SIZE (buffer)) { - if (memcmp (GST_BUFFER_DATA (buf), GST_BUFFER_DATA (buffer), - GST_BUFFER_SIZE (buffer)) == 0) { - found = TRUE; - } - } - } - fail_unless (found, "Did not find incoming IN_CAPS buffer %p on caps", - buffer); - - gst_caps_unref (caps); - } - - return TRUE; -} - -GST_START_TEST (test_multifdsink_gdp_vorbisenc) -{ - GstElement *p1, *p2; - GstElement *src, *sink, *depay; - GstPad *pad; - GMainLoop *loop; - int pfd[2]; - - loop = g_main_loop_new (NULL, FALSE); - - p1 = gst_parse_launch ("audiotestsrc num-buffers=10 ! audioconvert " - " ! vorbisenc ! gdppay ! multifdsink name=p1sink", NULL); - fail_if (p1 == NULL); - p2 = gst_parse_launch ("fdsrc name=p2src ! gdpdepay name=depay" - " ! fakesink name=p2sink signal-handoffs=True", NULL); - fail_if (p2 == NULL); - - fail_if (pipe (pfd) == -1); - - - gst_element_set_state (p1, GST_STATE_READY); - - sink = gst_bin_get_by_name (GST_BIN (p1), "p1sink"); - g_signal_emit_by_name (sink, "add", pfd[1], NULL); - gst_object_unref (sink); - - src = gst_bin_get_by_name (GST_BIN (p2), "p2src"); - g_object_set (G_OBJECT (src), "fd", pfd[0], NULL); - gst_object_unref (src); - - depay = gst_bin_get_by_name (GST_BIN (p2), "depay"); - fail_if (depay == NULL); - - pad = gst_element_get_static_pad (depay, "src"); - fail_unless (pad != NULL, "Could not get pad out of depay"); - gst_object_unref (depay); - - gst_pad_add_event_probe (pad, G_CALLBACK (tag_event_probe_cb), loop); - gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe_cb), NULL); - - gst_element_set_state (p1, GST_STATE_PLAYING); - gst_element_set_state (p2, GST_STATE_PLAYING); - - g_main_loop_run (loop); - - assert_equals_int (n_in_caps, 3); - - gst_element_set_state (p1, GST_STATE_NULL); - gst_object_unref (p1); - gst_element_set_state (p2, GST_STATE_NULL); - gst_object_unref (p2); -} - -GST_END_TEST; -#endif /* HAVE_VORBIS */ - -#endif /* #ifndef GST_DISABLE_PARSE */ - -static Suite * -streamheader_suite (void) -{ - Suite *s = suite_create ("streamheader"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); -#ifndef GST_DISABLE_PARSE - tcase_add_test (tc_chain, test_multifdsink_gdp_tag); -#ifdef HAVE_VORBIS - tcase_add_test (tc_chain, test_multifdsink_gdp_vorbisenc); -#endif -#endif - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = streamheader_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/pipelines/theoraenc.c b/tests/check/pipelines/theoraenc.c deleted file mode 100644 index ddc37d61..00000000 --- a/tests/check/pipelines/theoraenc.c +++ /dev/null @@ -1,463 +0,0 @@ -/* GStreamer - * - * unit test for theoraenc - * - * Copyright (C) 2006 Andy Wingo <wingo at pobox.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <gst/check/gstcheck.h> -#include <gst/check/gstbufferstraw.h> - -#include <theora/theora.h> - -#ifndef GST_DISABLE_PARSE - -#define TIMESTAMP_OFFSET G_GINT64_CONSTANT(3249870963) -#define FRAMERATE 10 - -/* I know all of these have a shift of 6 bits */ -#define GRANULEPOS_SHIFT 6 - - -#define check_buffer_is_header(buffer,is_header) \ - fail_unless (GST_BUFFER_FLAG_IS_SET (buffer, \ - GST_BUFFER_FLAG_IN_CAPS) == is_header, \ - "GST_BUFFER_IN_CAPS is set to %d but expected %d", \ - GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_IN_CAPS), is_header) - -#define check_buffer_timestamp(buffer,timestamp) \ - fail_unless (GST_BUFFER_TIMESTAMP (buffer) == timestamp, \ - "expected timestamp %" GST_TIME_FORMAT \ - ", but got timestamp %" GST_TIME_FORMAT, \ - GST_TIME_ARGS (timestamp), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer))) - -#define check_buffer_duration(buffer,duration) \ - fail_unless (GST_BUFFER_DURATION (buffer) == duration, \ - "expected duration %" GST_TIME_FORMAT \ - ", but got duration %" GST_TIME_FORMAT, \ - GST_TIME_ARGS (duration), GST_TIME_ARGS (GST_BUFFER_DURATION (buffer))) - -static gboolean old_libtheora; - -static void -check_libtheora (void) -{ - old_libtheora = (theora_version_number () <= 0x00030200); -} - -static void -check_buffer_granulepos (GstBuffer * buffer, gint64 granulepos) -{ - GstClockTime clocktime; - int framecount; - - /* With old versions of libtheora, the granulepos represented the - * start time, not end time. Adapt for that. */ - if (old_libtheora) { - if (granulepos >> GRANULEPOS_SHIFT) - granulepos -= 1 << GRANULEPOS_SHIFT; - else if (granulepos) - granulepos -= 1; - } - - fail_unless (GST_BUFFER_OFFSET_END (buffer) == granulepos, - "expected granulepos %" G_GUINT64_FORMAT - ", but got granulepos %" G_GUINT64_FORMAT, - granulepos, GST_BUFFER_OFFSET_END (buffer)); - - /* contrary to what we record as TIMESTAMP, we can use OFFSET to check - * the granulepos correctly here */ - framecount = GST_BUFFER_OFFSET_END (buffer); - framecount = granulepos >> GRANULEPOS_SHIFT; - framecount += granulepos & ((1 << GRANULEPOS_SHIFT) - 1); - clocktime = gst_util_uint64_scale (framecount, GST_SECOND, FRAMERATE); - - fail_unless (clocktime == GST_BUFFER_OFFSET (buffer), - "expected OFFSET set to clocktime %" GST_TIME_FORMAT - ", but got %" GST_TIME_FORMAT, - GST_TIME_ARGS (clocktime), GST_TIME_ARGS (GST_BUFFER_OFFSET (buffer))); -} - -/* this check is here to check that the granulepos we derive from the - timestamp is about correct. This is "about correct" because you can't - precisely go from timestamp to granulepos due to the downward-rounding - characteristics of gst_util_uint64_scale, so you check if granulepos is - equal to the number, or the number plus one. */ -/* should be from_endtime, but theora's granulepos mapping is "special" */ -static void -check_buffer_granulepos_from_starttime (GstBuffer * buffer, - GstClockTime starttime) -{ - gint64 granulepos, expected, framecount; - - granulepos = GST_BUFFER_OFFSET_END (buffer); - /* Now convert to 'granulepos for start time', depending on libtheora - * version */ - if (!old_libtheora) { - if (granulepos & ((1 << GRANULEPOS_SHIFT) - 1)) - granulepos -= 1; - else if (granulepos) - granulepos -= 1 << GRANULEPOS_SHIFT; - } - - framecount = granulepos >> GRANULEPOS_SHIFT; - framecount += granulepos & ((1 << GRANULEPOS_SHIFT) - 1); - expected = gst_util_uint64_scale (starttime, FRAMERATE, GST_SECOND); - - fail_unless (framecount == expected || framecount == expected + 1, - "expected frame count %" G_GUINT64_FORMAT - " or %" G_GUINT64_FORMAT - ", but got frame count %" G_GUINT64_FORMAT, - expected, expected + 1, framecount); -} - -GST_START_TEST (test_granulepos_offset) -{ - GstElement *bin; - GstPad *pad; - gchar *pipe_str; - GstBuffer *buffer; - GError *error = NULL; - - pipe_str = g_strdup_printf ("videotestsrc timestamp-offset=%" G_GUINT64_FORMAT - " num-buffers=10 ! video/x-raw-yuv,format=(fourcc)I420,framerate=10/1" - " ! theoraenc ! fakesink name=fs0", TIMESTAMP_OFFSET); - - bin = gst_parse_launch (pipe_str, &error); - fail_unless (bin != NULL, "Error parsing pipeline: %s", - error ? error->message : "(invalid error)"); - g_free (pipe_str); - - /* get the pad */ - { - GstElement *sink = gst_bin_get_by_name (GST_BIN (bin), "fs0"); - - fail_unless (sink != NULL, "Could not get fakesink out of bin"); - pad = gst_element_get_static_pad (sink, "sink"); - fail_unless (pad != NULL, "Could not get pad out of fakesink"); - gst_object_unref (sink); - } - - gst_buffer_straw_start_pipeline (bin, pad); - - /* header packets should have timestamp == NONE, granulepos 0, IN_CAPS */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - check_buffer_is_header (buffer, TRUE); - gst_buffer_unref (buffer); - - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - check_buffer_is_header (buffer, TRUE); - gst_buffer_unref (buffer); - - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - check_buffer_is_header (buffer, TRUE); - gst_buffer_unref (buffer); - - { - GstClockTime next_timestamp; - gint64 last_granulepos; - - /* first buffer should have timestamp of TIMESTAMP_OFFSET, granulepos to - * match the timestamp of the end of the last sample in the output buffer. - * Note that one cannot go timestamp->granulepos->timestamp and get the - * same value due to loss of precision with granulepos. theoraenc does - * take care to timestamp correctly based on the offset of the input data - * however, so it does do sub-granulepos timestamping. */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - last_granulepos = GST_BUFFER_OFFSET_END (buffer); - check_buffer_timestamp (buffer, TIMESTAMP_OFFSET); - /* don't really have a good way of checking duration... */ - check_buffer_granulepos_from_starttime (buffer, TIMESTAMP_OFFSET); - check_buffer_is_header (buffer, FALSE); - - next_timestamp = TIMESTAMP_OFFSET + GST_BUFFER_DURATION (buffer); - - gst_buffer_unref (buffer); - - /* check continuity with the next buffer */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, next_timestamp); - check_buffer_duration (buffer, - gst_util_uint64_scale (GST_BUFFER_OFFSET_END (buffer), GST_SECOND, - FRAMERATE) - - gst_util_uint64_scale (last_granulepos, GST_SECOND, FRAMERATE)); - check_buffer_granulepos_from_starttime (buffer, next_timestamp); - check_buffer_is_header (buffer, FALSE); - - gst_buffer_unref (buffer); - } - - gst_buffer_straw_stop_pipeline (bin, pad); - - gst_object_unref (pad); - gst_object_unref (bin); -} - -GST_END_TEST; - -GST_START_TEST (test_continuity) -{ - GstElement *bin; - GstPad *pad; - gchar *pipe_str; - GstBuffer *buffer; - GError *error = NULL; - - pipe_str = g_strdup_printf ("videotestsrc num-buffers=10" - " ! video/x-raw-yuv,format=(fourcc)I420,framerate=10/1" - " ! theoraenc ! fakesink name=fs0"); - - bin = gst_parse_launch (pipe_str, &error); - fail_unless (bin != NULL, "Error parsing pipeline: %s", - error ? error->message : "(invalid error)"); - g_free (pipe_str); - - /* get the pad */ - { - GstElement *sink = gst_bin_get_by_name (GST_BIN (bin), "fs0"); - - fail_unless (sink != NULL, "Could not get fakesink out of bin"); - pad = gst_element_get_static_pad (sink, "sink"); - fail_unless (pad != NULL, "Could not get pad out of fakesink"); - gst_object_unref (sink); - } - - gst_buffer_straw_start_pipeline (bin, pad); - - /* header packets should have timestamp == NONE, granulepos 0 */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - check_buffer_is_header (buffer, TRUE); - gst_buffer_unref (buffer); - - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - check_buffer_is_header (buffer, TRUE); - gst_buffer_unref (buffer); - - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - check_buffer_is_header (buffer, TRUE); - gst_buffer_unref (buffer); - - { - GstClockTime next_timestamp; - gint64 last_granulepos; - - /* first buffer should have timestamp of TIMESTAMP_OFFSET, granulepos to - * match the timestamp of the end of the last sample in the output buffer. - * Note that one cannot go timestamp->granulepos->timestamp and get the - * same value due to loss of precision with granulepos. theoraenc does - * take care to timestamp correctly based on the offset of the input data - * however, so it does do sub-granulepos timestamping. */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - last_granulepos = GST_BUFFER_OFFSET_END (buffer); - check_buffer_timestamp (buffer, 0); - /* plain division because I know the answer is exact */ - check_buffer_duration (buffer, GST_SECOND / 10); - check_buffer_granulepos (buffer, 1 << GRANULEPOS_SHIFT); - check_buffer_is_header (buffer, FALSE); - - next_timestamp = GST_BUFFER_DURATION (buffer); - - gst_buffer_unref (buffer); - - /* check continuity with the next buffer */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, next_timestamp); - check_buffer_duration (buffer, GST_SECOND / 10); - check_buffer_granulepos (buffer, (1 << GRANULEPOS_SHIFT) | 1); - check_buffer_is_header (buffer, FALSE); - - gst_buffer_unref (buffer); - } - - gst_buffer_straw_stop_pipeline (bin, pad); - - gst_object_unref (pad); - gst_object_unref (bin); -} - -GST_END_TEST; - -static gboolean -drop_second_data_buffer (GstPad * droppad, GstBuffer * buffer, gpointer unused) -{ - return !(GST_BUFFER_OFFSET (buffer) == 1); -} - -GST_START_TEST (test_discontinuity) -{ - GstElement *bin; - GstPad *pad, *droppad; - gchar *pipe_str; - GstBuffer *buffer; - GError *error = NULL; - guint drop_id; - - pipe_str = g_strdup_printf ("videotestsrc num-buffers=10" - " ! video/x-raw-yuv,format=(fourcc)I420,framerate=10/1" - " ! theoraenc ! fakesink name=fs0"); - - bin = gst_parse_launch (pipe_str, &error); - fail_unless (bin != NULL, "Error parsing pipeline: %s", - error ? error->message : "(invalid error)"); - g_free (pipe_str); - - /* the plan: same as test_continuity, but dropping a buffer and seeing if - theoraenc correctly notes the discontinuity */ - - /* get the pad to use to drop buffers */ - { - GstElement *sink = gst_bin_get_by_name (GST_BIN (bin), "theoraenc0"); - - fail_unless (sink != NULL, "Could not get theoraenc out of bin"); - droppad = gst_element_get_static_pad (sink, "sink"); - fail_unless (droppad != NULL, "Could not get pad out of theoraenc"); - gst_object_unref (sink); - } - - /* get the pad */ - { - GstElement *sink = gst_bin_get_by_name (GST_BIN (bin), "fs0"); - - fail_unless (sink != NULL, "Could not get fakesink out of bin"); - pad = gst_element_get_static_pad (sink, "sink"); - fail_unless (pad != NULL, "Could not get pad out of fakesink"); - gst_object_unref (sink); - } - - drop_id = gst_pad_add_buffer_probe (droppad, - G_CALLBACK (drop_second_data_buffer), NULL); - gst_buffer_straw_start_pipeline (bin, pad); - - /* header packets should have timestamp == NONE, granulepos 0 */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - check_buffer_is_header (buffer, TRUE); - gst_buffer_unref (buffer); - - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - check_buffer_is_header (buffer, TRUE); - gst_buffer_unref (buffer); - - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - check_buffer_is_header (buffer, TRUE); - gst_buffer_unref (buffer); - - { - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, 0); - /* plain division because I know the answer is exact */ - check_buffer_duration (buffer, GST_SECOND / 10); - check_buffer_granulepos (buffer, 1 << GRANULEPOS_SHIFT); - check_buffer_is_header (buffer, FALSE); - fail_if (GST_BUFFER_IS_DISCONT (buffer), "expected continuous buffer yo"); - gst_buffer_unref (buffer); - - /* check discontinuity with the next buffer */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_duration (buffer, GST_SECOND / 10); - /* After a discont, we'll always get a keyframe, so this one should be - * 3<<GRANULEPOS_SHIFT */ - check_buffer_granulepos (buffer, 3 << GRANULEPOS_SHIFT); - check_buffer_is_header (buffer, FALSE); - fail_unless (GST_BUFFER_IS_DISCONT (buffer), - "expected discontinuous buffer yo"); - gst_buffer_unref (buffer); - - /* Then the buffer after that should be continuous */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - fail_if (GST_BUFFER_IS_DISCONT (buffer), "expected continuous buffer yo"); - /* plain division because I know the answer is exact */ - check_buffer_duration (buffer, GST_SECOND / 10); - check_buffer_granulepos (buffer, (3 << GRANULEPOS_SHIFT) | 1); - check_buffer_is_header (buffer, FALSE); - gst_buffer_unref (buffer); - } - - gst_buffer_straw_stop_pipeline (bin, pad); - gst_pad_remove_buffer_probe (droppad, drop_id); - - gst_object_unref (droppad); - gst_object_unref (pad); - gst_object_unref (bin); -} - -GST_END_TEST; - -#endif /* #ifndef GST_DISABLE_PARSE */ - -static Suite * -theoraenc_suite (void) -{ - Suite *s = suite_create ("theoraenc"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); - - check_libtheora (); - -#ifndef GST_DISABLE_PARSE - tcase_add_test (tc_chain, test_granulepos_offset); - tcase_add_test (tc_chain, test_continuity); - tcase_add_test (tc_chain, test_discontinuity); -#endif - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = theoraenc_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/pipelines/vorbisdec.c b/tests/check/pipelines/vorbisdec.c deleted file mode 100644 index 9d467607..00000000 --- a/tests/check/pipelines/vorbisdec.c +++ /dev/null @@ -1,125 +0,0 @@ -/* GStreamer - * - * unit test for vorbisdec - * - * Copyright (C) 2007 Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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 <gst/check/gstcheck.h> -#include <gst/check/gstbufferstraw.h> - -#ifndef GST_DISABLE_PARSE - -static GMainLoop *loop; -static gint messages = 0; - -static void -element_message_cb (GstBus * bus, GstMessage * message, gpointer user_data) -{ - gchar *s; - - s = gst_structure_to_string (gst_message_get_structure (message)); - GST_DEBUG ("Received message: %s", s); - g_free (s); - - messages++; -} - -static void -eos_message_cb (GstBus * bus, GstMessage * message, gpointer user_data) -{ - GST_DEBUG ("Received eos"); - g_main_loop_quit (loop); -} - -GST_START_TEST (test_timestamps) -{ - GstElement *pipeline; - gchar *pipe_str; - GstBus *bus; - GError *error = NULL; - - pipe_str = g_strdup_printf ("audiotestsrc num-buffers=100" - " ! audio/x-raw-int,rate=44100 ! audioconvert ! vorbisenc ! vorbisdec" - " ! identity check-imperfect-timestamp=TRUE ! fakesink"); - - pipeline = gst_parse_launch (pipe_str, &error); - fail_unless (pipeline != NULL, "Error parsing pipeline: %s", - error ? error->message : "(invalid error)"); - g_free (pipe_str); - - bus = gst_element_get_bus (pipeline); - fail_if (bus == NULL); - gst_bus_add_signal_watch (bus); - g_signal_connect (bus, "message::element", (GCallback) element_message_cb, - NULL); - g_signal_connect (bus, "message::eos", (GCallback) eos_message_cb, NULL); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - /* run until we receive EOS */ - loop = g_main_loop_new (NULL, FALSE); - - g_main_loop_run (loop); - - gst_element_set_state (pipeline, GST_STATE_NULL); - - /* FIXME: there seems to be a bug in vorbisdec on decoding the last packet - * where it calculates the timestamp based on the granulepos of the incoming - * packet and subtracting the number of samples it can decode, which can - * result in a discontinuity in timestamps. - * See http://bugzilla.gnome.org/show_bug.cgi?id=423086 - * Fix that bug and drop this number to 0. - */ - fail_if (messages > 1, "Received imperfect timestamp messages"); - gst_object_unref (pipeline); -} - -GST_END_TEST; -#endif /* #ifndef GST_DISABLE_PARSE */ - -static Suite * -vorbisenc_suite (void) -{ - Suite *s = suite_create ("vorbisenc"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); -#ifndef GST_DISABLE_PARSE - tcase_add_test (tc_chain, test_timestamps); -#endif - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = vorbisenc_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/check/pipelines/vorbisenc.c b/tests/check/pipelines/vorbisenc.c deleted file mode 100644 index b207dffe..00000000 --- a/tests/check/pipelines/vorbisenc.c +++ /dev/null @@ -1,410 +0,0 @@ -/* GStreamer - * - * unit test for vorbisenc - * - * Copyright (C) 2006 Andy Wingo <wingo at pobox.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <gst/check/gstcheck.h> -#include <gst/check/gstbufferstraw.h> - -#ifndef GST_DISABLE_PARSE - -#define TIMESTAMP_OFFSET G_GINT64_CONSTANT(3249870963) - -static void -check_buffer_timestamp (GstBuffer * buffer, GstClockTime timestamp) -{ - fail_unless (GST_BUFFER_TIMESTAMP (buffer) == timestamp, - "expected timestamp %" GST_TIME_FORMAT - ", but got timestamp %" GST_TIME_FORMAT, - GST_TIME_ARGS (timestamp), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer))); -} - -static void -check_buffer_duration (GstBuffer * buffer, GstClockTime duration) -{ - fail_unless (GST_BUFFER_DURATION (buffer) == duration, - "expected duration %" GST_TIME_FORMAT - ", but got duration %" GST_TIME_FORMAT, - GST_TIME_ARGS (duration), GST_TIME_ARGS (GST_BUFFER_DURATION (buffer))); -} - -static void -check_buffer_granulepos (GstBuffer * buffer, gint64 granulepos) -{ - GstClockTime clocktime; - - fail_unless (GST_BUFFER_OFFSET_END (buffer) == granulepos, - "expected granulepos %" G_GUINT64_FORMAT - ", but got granulepos %" G_GUINT64_FORMAT, - granulepos, GST_BUFFER_OFFSET_END (buffer)); - - /* contrary to what we record as TIMESTAMP, we can use OFFSET to check - * the granulepos correctly here */ - clocktime = gst_util_uint64_scale (GST_BUFFER_OFFSET_END (buffer), 44100, - GST_SECOND); - - fail_unless (clocktime == GST_BUFFER_OFFSET (buffer), - "expected OFFSET set to clocktime %" GST_TIME_FORMAT - ", but got %" GST_TIME_FORMAT, - GST_TIME_ARGS (clocktime), GST_TIME_ARGS (GST_BUFFER_OFFSET (buffer))); -} - -/* this check is here to check that the granulepos we derive from the timestamp - is about correct. This is "about correct" because you can't precisely go from - timestamp to granulepos due to the downward-rounding characteristics of - gst_util_uint64_scale, so you check if granulepos is equal to the number, or - the number plus one. */ -static void -check_buffer_granulepos_from_endtime (GstBuffer * buffer, GstClockTime endtime) -{ - gint64 granulepos, expected; - - granulepos = GST_BUFFER_OFFSET_END (buffer); - expected = gst_util_uint64_scale (endtime, 44100, GST_SECOND); - - fail_unless (granulepos == expected || granulepos == expected + 1, - "expected granulepos %" G_GUINT64_FORMAT - " or %" G_GUINT64_FORMAT - ", but got granulepos %" G_GUINT64_FORMAT, - expected, expected + 1, granulepos); -} - -GST_START_TEST (test_granulepos_offset) -{ - GstElement *bin; - GstPad *pad; - gchar *pipe_str; - GstBuffer *buffer; - GError *error = NULL; - - pipe_str = g_strdup_printf ("audiotestsrc timestamp-offset=%" G_GUINT64_FORMAT - " ! audio/x-raw-int,rate=44100" - " ! audioconvert ! vorbisenc ! fakesink", TIMESTAMP_OFFSET); - - bin = gst_parse_launch (pipe_str, &error); - fail_unless (bin != NULL, "Error parsing pipeline: %s", - error ? error->message : "(invalid error)"); - g_free (pipe_str); - - /* get the pad */ - { - GstElement *sink = gst_bin_get_by_name (GST_BIN (bin), "fakesink0"); - - fail_unless (sink != NULL, "Could not get fakesink out of bin"); - pad = gst_element_get_static_pad (sink, "sink"); - fail_unless (pad != NULL, "Could not get pad out of fakesink"); - gst_object_unref (sink); - } - - gst_buffer_straw_start_pipeline (bin, pad); - - /* header packets should have timestamp == NONE, granulepos 0 */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - GST_DEBUG ("Got buffer in test"); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - gst_buffer_unref (buffer); - GST_DEBUG ("Unreffed buffer in test"); - - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - gst_buffer_unref (buffer); - - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - gst_buffer_unref (buffer); - - { - GstClockTime next_timestamp; - gint64 last_granulepos = 0; - - /* first buffer should have timestamp of TIMESTAMP_OFFSET, granulepos to - * match the timestamp of the end of the last sample in the output buffer. - * Note that one cannot go timestamp->granulepos->timestamp and get the same - * value due to loss of precision with granulepos. vorbisenc does take care - * to timestamp correctly based on the offset of the input data however, so - * it does do sub-granulepos timestamping. */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - last_granulepos = GST_BUFFER_OFFSET_END (buffer); - check_buffer_timestamp (buffer, TIMESTAMP_OFFSET); - /* don't really have a good way of checking duration... */ - check_buffer_granulepos_from_endtime (buffer, - TIMESTAMP_OFFSET + GST_BUFFER_DURATION (buffer)); - - next_timestamp = TIMESTAMP_OFFSET + GST_BUFFER_DURATION (buffer); - - gst_buffer_unref (buffer); - - /* check continuity with the next buffer */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, next_timestamp); - check_buffer_duration (buffer, - gst_util_uint64_scale (GST_BUFFER_OFFSET_END (buffer), GST_SECOND, - 44100) - - gst_util_uint64_scale (last_granulepos, GST_SECOND, 44100)); - check_buffer_granulepos_from_endtime (buffer, - next_timestamp + GST_BUFFER_DURATION (buffer)); - - gst_buffer_unref (buffer); - } - - gst_buffer_straw_stop_pipeline (bin, pad); - - gst_object_unref (pad); - gst_object_unref (bin); -} - -GST_END_TEST; - -GST_START_TEST (test_timestamps) -{ - GstElement *bin; - GstPad *pad; - gchar *pipe_str; - GstBuffer *buffer; - GError *error = NULL; - - pipe_str = g_strdup_printf ("audiotestsrc" - " ! audio/x-raw-int,rate=44100 ! audioconvert ! vorbisenc ! fakesink"); - - bin = gst_parse_launch (pipe_str, &error); - fail_unless (bin != NULL, "Error parsing pipeline: %s", - error ? error->message : "(invalid error)"); - g_free (pipe_str); - - /* get the pad */ - { - GstElement *sink = gst_bin_get_by_name (GST_BIN (bin), "fakesink0"); - - fail_unless (sink != NULL, "Could not get fakesink out of bin"); - pad = gst_element_get_static_pad (sink, "sink"); - fail_unless (pad != NULL, "Could not get pad out of fakesink"); - gst_object_unref (sink); - } - - gst_buffer_straw_start_pipeline (bin, pad); - - /* check header packets */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - gst_buffer_unref (buffer); - - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - gst_buffer_unref (buffer); - - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - gst_buffer_unref (buffer); - - { - GstClockTime next_timestamp; - gint64 last_granulepos; - - /* first buffer has timestamp 0 */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - last_granulepos = GST_BUFFER_OFFSET_END (buffer); - check_buffer_timestamp (buffer, 0); - /* don't really have a good way of checking duration... */ - check_buffer_granulepos_from_endtime (buffer, GST_BUFFER_DURATION (buffer)); - - next_timestamp = GST_BUFFER_DURATION (buffer); - - gst_buffer_unref (buffer); - - /* check continuity with the next buffer */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, next_timestamp); - check_buffer_duration (buffer, - gst_util_uint64_scale (GST_BUFFER_OFFSET_END (buffer), GST_SECOND, - 44100) - - gst_util_uint64_scale (last_granulepos, GST_SECOND, 44100)); - check_buffer_granulepos_from_endtime (buffer, - next_timestamp + GST_BUFFER_DURATION (buffer)); - - gst_buffer_unref (buffer); - } - - gst_buffer_straw_stop_pipeline (bin, pad); - - gst_object_unref (pad); - gst_object_unref (bin); -} - -GST_END_TEST; - -static gboolean -drop_second_data_buffer (GstPad * droppad, GstBuffer * buffer, gpointer unused) -{ - return !(GST_BUFFER_OFFSET (buffer) == 1024); -} - -GST_START_TEST (test_discontinuity) -{ - GstElement *bin; - GstPad *pad, *droppad; - gchar *pipe_str; - GstBuffer *buffer; - GError *error = NULL; - guint drop_id; - - pipe_str = g_strdup_printf ("audiotestsrc samplesperbuffer=1024" - " ! audio/x-raw-int,rate=44100" " ! audioconvert ! vorbisenc ! fakesink"); - - bin = gst_parse_launch (pipe_str, &error); - fail_unless (bin != NULL, "Error parsing pipeline: %s", - error ? error->message : "(invalid error)"); - g_free (pipe_str); - - /* the plan: same as test_timestamps, but dropping a buffer and seeing if - vorbisenc correctly notes the discontinuity */ - - /* get the pad to use to drop buffers */ - { - GstElement *sink = gst_bin_get_by_name (GST_BIN (bin), "vorbisenc0"); - - fail_unless (sink != NULL, "Could not get vorbisenc out of bin"); - droppad = gst_element_get_static_pad (sink, "sink"); - fail_unless (droppad != NULL, "Could not get pad out of vorbisenc"); - gst_object_unref (sink); - } - - /* get the pad */ - { - GstElement *sink = gst_bin_get_by_name (GST_BIN (bin), "fakesink0"); - - fail_unless (sink != NULL, "Could not get fakesink out of bin"); - pad = gst_element_get_static_pad (sink, "sink"); - fail_unless (pad != NULL, "Could not get pad out of fakesink"); - gst_object_unref (sink); - } - - drop_id = gst_pad_add_buffer_probe (droppad, - G_CALLBACK (drop_second_data_buffer), NULL); - gst_buffer_straw_start_pipeline (bin, pad); - - /* check header packets */ - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - gst_buffer_unref (buffer); - - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - gst_buffer_unref (buffer); - - buffer = gst_buffer_straw_get_buffer (bin, pad); - check_buffer_timestamp (buffer, GST_CLOCK_TIME_NONE); - check_buffer_duration (buffer, GST_CLOCK_TIME_NONE); - check_buffer_granulepos (buffer, 0); - gst_buffer_unref (buffer); - - /* two phases: continuous granulepos values up to 1024, then a first - discontinuous granulepos whose granulepos corresponds to a gap ending at - 2048. */ - { - GstClockTime next_timestamp = 0; - gint64 last_granulepos = 0; - - while (last_granulepos < 1024) { - buffer = gst_buffer_straw_get_buffer (bin, pad); - last_granulepos = GST_BUFFER_OFFSET_END (buffer); - check_buffer_timestamp (buffer, next_timestamp); - fail_if (GST_BUFFER_IS_DISCONT (buffer), "expected continuous buffer"); - next_timestamp += GST_BUFFER_DURATION (buffer); - gst_buffer_unref (buffer); - } - - fail_unless (last_granulepos == 1024, - "unexpected granulepos: %" G_GUINT64_FORMAT, last_granulepos); - } - - { - buffer = gst_buffer_straw_get_buffer (bin, pad); - /* The first buffer after the discontinuity will produce zero output - * samples (because of the overlap/add), so it won't increment the - * granulepos, which should be 2048 after the discontinuity. - */ - fail_unless (GST_BUFFER_OFFSET_END (buffer) == 2048, - "expected granulepos after gap: %" G_GUINT64_FORMAT, - GST_BUFFER_OFFSET_END (buffer)); - fail_unless (GST_BUFFER_IS_DISCONT (buffer), - "expected discontinuous buffer"); - gst_buffer_unref (buffer); - } - - gst_buffer_straw_stop_pipeline (bin, pad); - gst_pad_remove_buffer_probe (droppad, drop_id); - - gst_object_unref (droppad); - gst_object_unref (pad); - gst_object_unref (bin); -} - -GST_END_TEST; - -#endif /* #ifndef GST_DISABLE_PARSE */ - -static Suite * -vorbisenc_suite (void) -{ - Suite *s = suite_create ("vorbisenc"); - TCase *tc_chain = tcase_create ("general"); - - suite_add_tcase (s, tc_chain); -#ifndef GST_DISABLE_PARSE - tcase_add_test (tc_chain, test_granulepos_offset); - tcase_add_test (tc_chain, test_timestamps); - tcase_add_test (tc_chain, test_discontinuity); -#endif - - return s; -} - -int -main (int argc, char **argv) -{ - int nf; - - Suite *s = vorbisenc_suite (); - SRunner *sr = srunner_create (s); - - gst_check_init (&argc, &argv); - - srunner_run_all (sr, CK_NORMAL); - nf = srunner_ntests_failed (sr); - srunner_free (sr); - - return nf; -} diff --git a/tests/examples/Makefile.am b/tests/examples/Makefile.am deleted file mode 100644 index 7c4e1f8a..00000000 --- a/tests/examples/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -if HAVE_FT2 -FT2_SUBDIRS = seek snapshot -else -FT2_SUBDIRS = -endif - -if USE_GIO -GIO_SUBDIRS = gio -endif - -SUBDIRS = app $(FT2_SUBDIRS) $(GIO_SUBDIRS) volume dynamic v4l overlay - -DIST_SUBDIRS = app seek volume dynamic snapshot gio v4l overlay diff --git a/tests/examples/app/.gitignore b/tests/examples/app/.gitignore deleted file mode 100644 index 8a2c7615..00000000 --- a/tests/examples/app/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -appsrc_ex -appsrc-ra -appsrc-seekable -appsrc-stream -appsrc-stream2 -appsink-src diff --git a/tests/examples/app/Makefile.am b/tests/examples/app/Makefile.am deleted file mode 100644 index 7d721b4c..00000000 --- a/tests/examples/app/Makefile.am +++ /dev/null @@ -1,32 +0,0 @@ - -noinst_PROGRAMS = appsrc_ex appsrc-stream appsrc-stream2 appsrc-ra \ - appsrc-seekable appsink-src - -appsrc_ex_SOURCES = appsrc_ex.c -appsrc_ex_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -appsrc_ex_LDFLAGS = \ - $(top_builddir)/gst-libs/gst/app/libgstapp-@GST_MAJORMINOR@.la \ - $(GST_LIBS) - -appsrc_stream_SOURCES = appsrc-stream.c -appsrc_stream_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -appsrc_stream_LDFLAGS = $(GST_LIBS) - -appsrc_stream2_SOURCES = appsrc-stream2.c -appsrc_stream2_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -appsrc_stream2_LDFLAGS = $(GST_LIBS) - -appsrc_ra_SOURCES = appsrc-ra.c -appsrc_ra_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -appsrc_ra_LDFLAGS = $(GST_LIBS) - -appsrc_seekable_SOURCES = appsrc-seekable.c -appsrc_seekable_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -appsrc_seekable_LDFLAGS = $(GST_LIBS) - -appsink_src_SOURCES = appsink-src.c -appsink_src_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -appsink_src_LDFLAGS = \ - $(top_builddir)/gst-libs/gst/app/libgstapp-@GST_MAJORMINOR@.la \ - $(GST_LIBS) - diff --git a/tests/examples/app/appsink-src.c b/tests/examples/app/appsink-src.c deleted file mode 100644 index a92dfb51..00000000 --- a/tests/examples/app/appsink-src.c +++ /dev/null @@ -1,192 +0,0 @@ -#include <gst/gst.h> - -#include <string.h> - -#include <gst/app/gstappsrc.h> -#include <gst/app/gstappsink.h> -#include <gst/app/gstappbuffer.h> - -/* these are the caps we are going to pass through the appsink and appsrc */ -const gchar *audio_caps = - "audio/x-raw-int,channels=1,rate=8000,signed=(boolean)true,width=16,depth=16,endianness=1234"; - -typedef struct -{ - GMainLoop *loop; - GstElement *source; - GstElement *sink; -} ProgramData; - -/* called when the appsink notifies us that there is a new buffer ready for - * processing */ -static void -on_new_buffer_from_source (GstElement * elt, ProgramData * data) -{ - guint size; - gpointer raw_buffer; - GstBuffer *app_buffer, *buffer; - GstElement *source; - - /* get the buffer from appsink */ - buffer = gst_app_sink_pull_buffer (GST_APP_SINK (elt)); - - /* turn it into an app buffer, it's not really needed, we could simply push - * the retrieved buffer from appsink into appsrc just fine. */ - size = GST_BUFFER_SIZE (buffer); - g_print ("Pushing a buffer of size %d\n", size); - raw_buffer = g_malloc0 (size); - memcpy (raw_buffer, GST_BUFFER_DATA (buffer), size); - app_buffer = gst_app_buffer_new (raw_buffer, size, g_free, raw_buffer); - - /* newer basesrc will set caps for use automatically but it does not really - * hurt to set it on the buffer again */ - gst_buffer_set_caps (app_buffer, GST_BUFFER_CAPS (buffer)); - - /* we don't need the appsink buffer anymore */ - gst_buffer_unref (buffer); - - /* get source an push new buffer */ - source = gst_bin_get_by_name (GST_BIN (data->sink), "testsource"); - gst_app_src_push_buffer (GST_APP_SRC (source), app_buffer); -} - -/* called when we get a GstMessage from the source pipeline when we get EOS, we - * notify the appsrc of it. */ -static gboolean -on_source_message (GstBus * bus, GstMessage * message, ProgramData * data) -{ - GstElement *source; - - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_EOS: - g_print ("The source got dry\n"); - source = gst_bin_get_by_name (GST_BIN (data->sink), "testsource"); - gst_app_src_end_of_stream (GST_APP_SRC (source)); - break; - case GST_MESSAGE_ERROR: - g_print ("Received error\n"); - g_main_loop_quit (data->loop); - break; - default: - break; - } - return TRUE; -} - -/* called when we get a GstMessage from the sink pipeline when we get EOS, we - * exit the mainloop and this testapp. */ -static gboolean -on_sink_message (GstBus * bus, GstMessage * message, ProgramData * data) -{ - /* nil */ - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_EOS: - g_print ("Finished playback\n"); - g_main_loop_quit (data->loop); - break; - case GST_MESSAGE_ERROR: - g_print ("Received error\n"); - g_main_loop_quit (data->loop); - break; - default: - break; - } - return TRUE; -} - -int -main (int argc, char *argv[]) -{ - gchar *filename = NULL; - ProgramData *data = NULL; - gchar *string = NULL; - GstBus *bus = NULL; - GstElement *testsink = NULL; - GstElement *testsource = NULL; - - gst_init (&argc, &argv); - - if (argc == 2) - filename = g_strdup (argv[1]); - else - filename = g_strdup ("/usr/share/sounds/ekiga/ring.wav"); - - data = g_new0 (ProgramData, 1); - - data->loop = g_main_loop_new (NULL, FALSE); - - /* setting up source pipeline, we read from a file and convert to our desired - * caps. */ - string = - g_strdup_printf - ("filesrc location=\"%s\" ! wavparse ! audioconvert ! audioresample ! appsink caps=\"%s\" name=testsink", - filename, audio_caps); - g_free (filename); - data->source = gst_parse_launch (string, NULL); - g_free (string); - - if (data->source == NULL) { - g_print ("Bad source\n"); - return -1; - } - - /* to be notified of messages from this pipeline, mostly EOS */ - bus = gst_element_get_bus (data->source); - gst_bus_add_watch (bus, (GstBusFunc) on_source_message, data); - gst_object_unref (bus); - - /* we use appsink in push mode, it sends us a signal when data is available - * and we pull out the data in the signal callback. We want the appsink to - * push as fast as it can, hence the sync=false */ - testsink = gst_bin_get_by_name (GST_BIN (data->source), "testsink"); - g_object_set (G_OBJECT (testsink), "emit-signals", TRUE, "sync", FALSE, NULL); - g_signal_connect (testsink, "new-buffer", - G_CALLBACK (on_new_buffer_from_source), data); - gst_object_unref (testsink); - - /* setting up sink pipeline, we push audio data into this pipeline that will - * then play it back using the default audio sink. We have no blocking - * behaviour on the src which means that we will push the entire file into - * memory. */ - string = - g_strdup_printf ("appsrc name=testsource caps=\"%s\" ! autoaudiosink", - audio_caps); - data->sink = gst_parse_launch (string, NULL); - g_free (string); - - if (data->sink == NULL) { - g_print ("Bad sink\n"); - return -1; - } - - testsource = gst_bin_get_by_name (GST_BIN (data->sink), "testsource"); - /* configure for time-based format */ - g_object_set (testsource, "format", GST_FORMAT_TIME, NULL); - /* uncomment the next line to block when appsrc has buffered enough */ - /* g_object_set (testsource, "block", TRUE, NULL); */ - gst_object_unref (testsource); - - bus = gst_element_get_bus (data->sink); - gst_bus_add_watch (bus, (GstBusFunc) on_sink_message, data); - gst_object_unref (bus); - - /* launching things */ - gst_element_set_state (data->sink, GST_STATE_PLAYING); - gst_element_set_state (data->source, GST_STATE_PLAYING); - - /* let's run !, this loop will quit when the sink pipeline goes EOS or when an - * error occurs in the source or sink pipelines. */ - g_print ("Let's run!\n"); - g_main_loop_run (data->loop); - g_print ("Going out\n"); - - gst_element_set_state (data->source, GST_STATE_NULL); - gst_element_set_state (data->sink, GST_STATE_NULL); - - gst_object_unref (data->source); - gst_object_unref (data->sink); - g_main_loop_unref (data->loop); - g_free (data); - - return 0; -} diff --git a/tests/examples/app/appsrc-ra.c b/tests/examples/app/appsrc-ra.c deleted file mode 100644 index 46b19cae..00000000 --- a/tests/examples/app/appsrc-ra.c +++ /dev/null @@ -1,229 +0,0 @@ -/* GStreamer - * - * appsrc-ra.c: example for using appsrc in random-access mode. - * - * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -/* FIXME: remove once we depend on GLib >= 2.22 */ -#if !GLIB_CHECK_VERSION (2, 22, 0) -#define g_mapped_file_unref g_mapped_file_free -#endif - -GST_DEBUG_CATEGORY (appsrc_playbin_debug); -#define GST_CAT_DEFAULT appsrc_playbin_debug - -/* - * an example application of using appsrc in random-access mode. When the - * appsrc requests data with the need-data signal, we retrieve a buffer of the - * requested size and push it to appsrc. - * - * This is a good example how one would deal with a local file resource. - * - * Appsrc in random-access mode needs seeking support and we must thus connect - * to the seek signal to perform any seeks when requested. - * - * In random-access mode we must set the size of the source material. - */ -typedef struct _App App; - -struct _App -{ - GstElement *playbin; - GstElement *appsrc; - - GMainLoop *loop; - - GMappedFile *file; - guint8 *data; - gsize length; - guint64 offset; -}; - -App s_app; - -/* This method is called by the need-data signal callback, we feed data into the - * appsrc with the requested size. - */ -static void -feed_data (GstElement * appsrc, guint size, App * app) -{ - GstBuffer *buffer; - GstFlowReturn ret; - - buffer = gst_buffer_new (); - - if (app->offset >= app->length) { - /* we are EOS, send end-of-stream */ - g_signal_emit_by_name (app->appsrc, "end-of-stream", &ret); - return; - } - - /* read the amount of data, we are allowed to return less if we are EOS */ - if (app->offset + size > app->length) - size = app->length - app->offset; - - GST_BUFFER_DATA (buffer) = app->data + app->offset; - GST_BUFFER_SIZE (buffer) = size; - /* we need to set an offset for random access */ - GST_BUFFER_OFFSET (buffer) = app->offset; - GST_BUFFER_OFFSET_END (buffer) = app->offset + size; - - GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, - app->offset, size); - g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret); - gst_buffer_unref (buffer); - - app->offset += size; - - return; -} - -/* called when appsrc wants us to return data from a new position with the next - * call to push-buffer. */ -static gboolean -seek_data (GstElement * appsrc, guint64 position, App * app) -{ - GST_DEBUG ("seek to offset %" G_GUINT64_FORMAT, position); - app->offset = position; - - return TRUE; -} - -/* this callback is called when playbin2 has constructed a source object to read - * from. Since we provided the appsrc:// uri to playbin2, this will be the - * appsrc that we must handle. We set up some signals to push data into appsrc - * and one to perform a seek. */ -static void -found_source (GObject * object, GObject * orig, GParamSpec * pspec, App * app) -{ - /* get a handle to the appsrc */ - g_object_get (orig, pspec->name, &app->appsrc, NULL); - - GST_DEBUG ("got appsrc %p", app->appsrc); - - /* we can set the length in appsrc. This allows some elements to estimate the - * total duration of the stream. It's a good idea to set the property when you - * can but it's not required. */ - g_object_set (app->appsrc, "size", (gint64) app->length, NULL); - gst_util_set_object_arg (G_OBJECT (app->appsrc), "stream-type", - "random-access"); - - /* configure the appsrc, we will push a buffer to appsrc when it needs more - * data */ - g_signal_connect (app->appsrc, "need-data", G_CALLBACK (feed_data), app); - g_signal_connect (app->appsrc, "seek-data", G_CALLBACK (seek_data), app); -} - -static gboolean -bus_message (GstBus * bus, GstMessage * message, App * app) -{ - GST_DEBUG ("got message %s", - gst_message_type_get_name (GST_MESSAGE_TYPE (message))); - - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_ERROR: - g_error ("received error"); - g_main_loop_quit (app->loop); - break; - case GST_MESSAGE_EOS: - g_main_loop_quit (app->loop); - break; - default: - break; - } - return TRUE; -} - -int -main (int argc, char *argv[]) -{ - App *app = &s_app; - GError *error = NULL; - GstBus *bus; - - gst_init (&argc, &argv); - - GST_DEBUG_CATEGORY_INIT (appsrc_playbin_debug, "appsrc-playbin", 0, - "appsrc playbin example"); - - if (argc < 2) { - g_print ("usage: %s <filename>\n", argv[0]); - return -1; - } - - /* try to open the file as an mmapped file */ - app->file = g_mapped_file_new (argv[1], FALSE, &error); - if (error) { - g_print ("failed to open file: %s\n", error->message); - g_error_free (error); - return -2; - } - /* get some vitals, this will be used to read data from the mmapped file and - * feed it to appsrc. */ - app->length = g_mapped_file_get_length (app->file); - app->data = (guint8 *) g_mapped_file_get_contents (app->file); - app->offset = 0; - - /* create a mainloop to get messages */ - app->loop = g_main_loop_new (NULL, TRUE); - - app->playbin = gst_element_factory_make ("playbin2", NULL); - g_assert (app->playbin); - - bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin)); - - /* add watch for messages */ - gst_bus_add_watch (bus, (GstBusFunc) bus_message, app); - - /* set to read from appsrc */ - g_object_set (app->playbin, "uri", "appsrc://", NULL); - - /* get notification when the source is created so that we get a handle to it - * and can configure it */ - g_signal_connect (app->playbin, "deep-notify::source", - (GCallback) found_source, app); - - /* go to playing and wait in a mainloop. */ - gst_element_set_state (app->playbin, GST_STATE_PLAYING); - - /* this mainloop is stopped when we receive an error or EOS */ - g_main_loop_run (app->loop); - - GST_DEBUG ("stopping"); - - gst_element_set_state (app->playbin, GST_STATE_NULL); - - /* free the file */ - g_mapped_file_unref (app->file); - - gst_object_unref (bus); - g_main_loop_unref (app->loop); - - return 0; -} diff --git a/tests/examples/app/appsrc-seekable.c b/tests/examples/app/appsrc-seekable.c deleted file mode 100644 index adff5bb9..00000000 --- a/tests/examples/app/appsrc-seekable.c +++ /dev/null @@ -1,234 +0,0 @@ -/* GStreamer - * - * appsrc-seekable.c: example for using appsrc in seekable mode. - * - * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -/* FIXME: remove once we depend on GLib >= 2.22 */ -#if !GLIB_CHECK_VERSION (2, 22, 0) -#define g_mapped_file_unref g_mapped_file_free -#endif - -GST_DEBUG_CATEGORY (appsrc_playbin_debug); -#define GST_CAT_DEFAULT appsrc_playbin_debug - -/* - * an example application of using appsrc in seekable mode. When the - * appsrc requests data with the need-data signal, we retrieve a buffer and - * push it to appsrc. We can also use the method as demonstrated in - * appsrc-stream.c, ie. pushing buffers when we can. - * - * This is a good example how one would deal with a remote http server that - * supports range requests. - * - * Appsrc in seekable mode needs seeking support and we must thus connect - * to the seek signal to perform any seeks when requested. - * - * In seekable mode we should set the size of the source material. - */ -typedef struct _App App; - -struct _App -{ - GstElement *playbin; - GstElement *appsrc; - - GMainLoop *loop; - - GMappedFile *file; - guint8 *data; - gsize length; - guint64 offset; -}; - -App s_app; - -#define CHUNK_SIZE 4096 - -/* This method is called by the need-data signal callback, we feed data into the - * appsrc with an arbitrary size. - */ -static void -feed_data (GstElement * appsrc, guint size, App * app) -{ - GstBuffer *buffer; - guint len; - GstFlowReturn ret; - - buffer = gst_buffer_new (); - - if (app->offset >= app->length) { - /* we are EOS, send end-of-stream */ - g_signal_emit_by_name (app->appsrc, "end-of-stream", &ret); - return; - } - - /* read any amount of data, we are allowed to return less if we are EOS */ - len = CHUNK_SIZE; - if (app->offset + len > app->length) - len = app->length - app->offset; - - GST_BUFFER_DATA (buffer) = app->data + app->offset; - GST_BUFFER_SIZE (buffer) = len; - - GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, - app->offset, len); - g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret); - gst_buffer_unref (buffer); - - app->offset += len; - - return; -} - -/* called when appsrc wants us to return data from a new position with the next - * call to push-buffer. */ -static gboolean -seek_data (GstElement * appsrc, guint64 position, App * app) -{ - GST_DEBUG ("seek to offset %" G_GUINT64_FORMAT, position); - app->offset = position; - - return TRUE; -} - -/* this callback is called when playbin2 has constructed a source object to read - * from. Since we provided the appsrc:// uri to playbin2, this will be the - * appsrc that we must handle. We set up some signals to push data into appsrc - * and one to perform a seek. */ -static void -found_source (GObject * object, GObject * orig, GParamSpec * pspec, App * app) -{ - /* get a handle to the appsrc */ - g_object_get (orig, pspec->name, &app->appsrc, NULL); - - GST_DEBUG ("got appsrc %p", app->appsrc); - - /* we can set the length in appsrc. This allows some elements to estimate the - * total duration of the stream. It's a good idea to set the property when you - * can but it's not required. */ - g_object_set (app->appsrc, "size", (gint64) app->length, NULL); - /* we are seekable in push mode, this means that the element usually pushes - * out buffers of an undefined size and that seeks happen only occasionally - * and only by request of the user. */ - gst_util_set_object_arg (G_OBJECT (app->appsrc), "stream-type", "seekable"); - - /* configure the appsrc, we will push a buffer to appsrc when it needs more - * data */ - g_signal_connect (app->appsrc, "need-data", G_CALLBACK (feed_data), app); - g_signal_connect (app->appsrc, "seek-data", G_CALLBACK (seek_data), app); -} - -static gboolean -bus_message (GstBus * bus, GstMessage * message, App * app) -{ - GST_DEBUG ("got message %s", - gst_message_type_get_name (GST_MESSAGE_TYPE (message))); - - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_ERROR: - g_error ("received error"); - g_main_loop_quit (app->loop); - break; - case GST_MESSAGE_EOS: - g_main_loop_quit (app->loop); - break; - default: - break; - } - return TRUE; -} - -int -main (int argc, char *argv[]) -{ - App *app = &s_app; - GError *error = NULL; - GstBus *bus; - - gst_init (&argc, &argv); - - GST_DEBUG_CATEGORY_INIT (appsrc_playbin_debug, "appsrc-playbin", 0, - "appsrc playbin example"); - - if (argc < 2) { - g_print ("usage: %s <filename>\n", argv[0]); - return -1; - } - - /* try to open the file as an mmapped file */ - app->file = g_mapped_file_new (argv[1], FALSE, &error); - if (error) { - g_print ("failed to open file: %s\n", error->message); - g_error_free (error); - return -2; - } - /* get some vitals, this will be used to read data from the mmapped file and - * feed it to appsrc. */ - app->length = g_mapped_file_get_length (app->file); - app->data = (guint8 *) g_mapped_file_get_contents (app->file); - app->offset = 0; - - /* create a mainloop to get messages */ - app->loop = g_main_loop_new (NULL, TRUE); - - app->playbin = gst_element_factory_make ("playbin2", NULL); - g_assert (app->playbin); - - bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin)); - - /* add watch for messages */ - gst_bus_add_watch (bus, (GstBusFunc) bus_message, app); - - /* set to read from appsrc */ - g_object_set (app->playbin, "uri", "appsrc://", NULL); - - /* get notification when the source is created so that we get a handle to it - * and can configure it */ - g_signal_connect (app->playbin, "deep-notify::source", - (GCallback) found_source, app); - - /* go to playing and wait in a mainloop. */ - gst_element_set_state (app->playbin, GST_STATE_PLAYING); - - /* this mainloop is stopped when we receive an error or EOS */ - g_main_loop_run (app->loop); - - GST_DEBUG ("stopping"); - - gst_element_set_state (app->playbin, GST_STATE_NULL); - - /* free the file */ - g_mapped_file_unref (app->file); - - gst_object_unref (bus); - g_main_loop_unref (app->loop); - - return 0; -} diff --git a/tests/examples/app/appsrc-stream.c b/tests/examples/app/appsrc-stream.c deleted file mode 100644 index ea3286f2..00000000 --- a/tests/examples/app/appsrc-stream.c +++ /dev/null @@ -1,254 +0,0 @@ -/* GStreamer - * - * appsrc-stream.c: example for using appsrc in streaming mode. - * - * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -/* FIXME: remove once we depend on GLib >= 2.22 */ -#if !GLIB_CHECK_VERSION (2, 22, 0) -#define g_mapped_file_unref g_mapped_file_free -#endif - -GST_DEBUG_CATEGORY (appsrc_playbin_debug); -#define GST_CAT_DEFAULT appsrc_playbin_debug - -/* - * an example application of using appsrc in streaming push mode. We simply push - * buffers into appsrc. The size of the buffers we push can be any size we - * choose. - * - * This example is very close to how one would deal with a streaming webserver - * that does not support range requests or does not report the total file size. - * - * Some optimisations are done so that we don't push too much data. We connect - * to the need-data and enough-data signals to start/stop sending buffers. - * - * Appsrc in streaming mode (the default) does not support seeking so we don't - * have to handle any seek callbacks. - * - * Some formats are able to estimate the duration of the media file based on the - * file length (mp3, mpeg,..), others report an unknown length (ogg,..). - */ -typedef struct _App App; - -struct _App -{ - GstElement *playbin; - GstElement *appsrc; - - GMainLoop *loop; - guint sourceid; - - GMappedFile *file; - guint8 *data; - gsize length; - guint64 offset; -}; - -App s_app; - -#define CHUNK_SIZE 4096 - -/* This method is called by the idle GSource in the mainloop. We feed CHUNK_SIZE - * bytes into appsrc. - * The ide handler is added to the mainloop when appsrc requests us to start - * sending data (need-data signal) and is removed when appsrc has enough data - * (enough-data signal). - */ -static gboolean -read_data (App * app) -{ - GstBuffer *buffer; - guint len; - GstFlowReturn ret; - - buffer = gst_buffer_new (); - - if (app->offset >= app->length) { - /* we are EOS, send end-of-stream and remove the source */ - g_signal_emit_by_name (app->appsrc, "end-of-stream", &ret); - return FALSE; - } - - /* read the next chunk */ - len = CHUNK_SIZE; - if (app->offset + len > app->length) - len = app->length - app->offset; - - GST_BUFFER_DATA (buffer) = app->data + app->offset; - GST_BUFFER_SIZE (buffer) = len; - - GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, - app->offset, len); - g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret); - gst_buffer_unref (buffer); - if (ret != GST_FLOW_OK) { - /* some error, stop sending data */ - return FALSE; - } - - app->offset += len; - - return TRUE; -} - -/* This signal callback is called when appsrc needs data, we add an idle handler - * to the mainloop to start pushing data into the appsrc */ -static void -start_feed (GstElement * playbin, guint size, App * app) -{ - if (app->sourceid == 0) { - GST_DEBUG ("start feeding"); - app->sourceid = g_idle_add ((GSourceFunc) read_data, app); - } -} - -/* This callback is called when appsrc has enough data and we can stop sending. - * We remove the idle handler from the mainloop */ -static void -stop_feed (GstElement * playbin, App * app) -{ - if (app->sourceid != 0) { - GST_DEBUG ("stop feeding"); - g_source_remove (app->sourceid); - app->sourceid = 0; - } -} - -/* this callback is called when playbin2 has constructed a source object to read - * from. Since we provided the appsrc:// uri to playbin2, this will be the - * appsrc that we must handle. We set up some signals to start and stop pushing - * data into appsrc */ -static void -found_source (GObject * object, GObject * orig, GParamSpec * pspec, App * app) -{ - /* get a handle to the appsrc */ - g_object_get (orig, pspec->name, &app->appsrc, NULL); - - GST_DEBUG ("got appsrc %p", app->appsrc); - - /* we can set the length in appsrc. This allows some elements to estimate the - * total duration of the stream. It's a good idea to set the property when you - * can but it's not required. */ - g_object_set (app->appsrc, "size", (gint64) app->length, NULL); - - /* configure the appsrc, we will push data into the appsrc from the - * mainloop. */ - g_signal_connect (app->appsrc, "need-data", G_CALLBACK (start_feed), app); - g_signal_connect (app->appsrc, "enough-data", G_CALLBACK (stop_feed), app); -} - -static gboolean -bus_message (GstBus * bus, GstMessage * message, App * app) -{ - GST_DEBUG ("got message %s", - gst_message_type_get_name (GST_MESSAGE_TYPE (message))); - - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_ERROR: - g_error ("received error"); - g_main_loop_quit (app->loop); - break; - case GST_MESSAGE_EOS: - g_main_loop_quit (app->loop); - break; - default: - break; - } - return TRUE; -} - -int -main (int argc, char *argv[]) -{ - App *app = &s_app; - GError *error = NULL; - GstBus *bus; - - gst_init (&argc, &argv); - - GST_DEBUG_CATEGORY_INIT (appsrc_playbin_debug, "appsrc-playbin", 0, - "appsrc playbin example"); - - if (argc < 2) { - g_print ("usage: %s <filename>\n", argv[0]); - return -1; - } - - /* try to open the file as an mmapped file */ - app->file = g_mapped_file_new (argv[1], FALSE, &error); - if (error) { - g_print ("failed to open file: %s\n", error->message); - g_error_free (error); - return -2; - } - /* get some vitals, this will be used to read data from the mmapped file and - * feed it to appsrc. */ - app->length = g_mapped_file_get_length (app->file); - app->data = (guint8 *) g_mapped_file_get_contents (app->file); - app->offset = 0; - - /* create a mainloop to get messages and to handle the idle handler that will - * feed data to appsrc. */ - app->loop = g_main_loop_new (NULL, TRUE); - - app->playbin = gst_element_factory_make ("playbin2", NULL); - g_assert (app->playbin); - - bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin)); - - /* add watch for messages */ - gst_bus_add_watch (bus, (GstBusFunc) bus_message, app); - - /* set to read from appsrc */ - g_object_set (app->playbin, "uri", "appsrc://", NULL); - - /* get notification when the source is created so that we get a handle to it - * and can configure it */ - g_signal_connect (app->playbin, "deep-notify::source", - (GCallback) found_source, app); - - /* go to playing and wait in a mainloop. */ - gst_element_set_state (app->playbin, GST_STATE_PLAYING); - - /* this mainloop is stopped when we receive an error or EOS */ - g_main_loop_run (app->loop); - - GST_DEBUG ("stopping"); - - gst_element_set_state (app->playbin, GST_STATE_NULL); - - /* free the file */ - g_mapped_file_unref (app->file); - - gst_object_unref (bus); - g_main_loop_unref (app->loop); - - return 0; -} diff --git a/tests/examples/app/appsrc-stream2.c b/tests/examples/app/appsrc-stream2.c deleted file mode 100644 index e0c8922a..00000000 --- a/tests/examples/app/appsrc-stream2.c +++ /dev/null @@ -1,224 +0,0 @@ -/* GStreamer - * - * appsrc-stream2.c: example for using appsrc in streaming mode. - * - * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -/* FIXME: remove once we depend on GLib >= 2.22 */ -#if !GLIB_CHECK_VERSION (2, 22, 0) -#define g_mapped_file_unref g_mapped_file_free -#endif - -GST_DEBUG_CATEGORY (appsrc_playbin_debug); -#define GST_CAT_DEFAULT appsrc_playbin_debug - -/* - * an example application of using appsrc in streaming pull mode. When the - * appsrc request data with the need-data signal, we retrieve a buffer of an - * arbitrary size and push it to appsrc. - * - * This example keeps the internal buffer queue of appsrc to a minimal size, - * only feeding data to appsrc when needed. - * - * This is a good example how one would deal with a live resource, such as a udp - * socket where one would feed the most recently acquired buffer to appsrc. - * - * Usually one would timestamp the buffers with the running_time of the - * pipeline or configure the appsrc to do timestamping by setting the - * do-timestamp property to TRUE. - * - * Appsrc in streaming mode (the default) does not support seeking so we don't - * have to handle any seek callbacks. - * - * Some formats are able to estimate the duration of the media file based on the - * file length (mp3, mpeg,..), others report an unknown length (ogg,..). - */ -typedef struct _App App; - -struct _App -{ - GstElement *playbin; - GstElement *appsrc; - - GMainLoop *loop; - - GMappedFile *file; - guint8 *data; - gsize length; - guint64 offset; -}; - -App s_app; - -#define CHUNK_SIZE 4096 - -/* This method is called by the need-data signal callback, we feed data into the - * appsrc. - */ -static void -feed_data (GstElement * appsrc, guint size, App * app) -{ - GstBuffer *buffer; - guint len; - GstFlowReturn ret; - - buffer = gst_buffer_new (); - - if (app->offset >= app->length) { - /* we are EOS, send end-of-stream */ - g_signal_emit_by_name (app->appsrc, "end-of-stream", &ret); - return; - } - - /* read the next chunk */ - len = CHUNK_SIZE; - if (app->offset + len > app->length) - len = app->length - app->offset; - - GST_BUFFER_DATA (buffer) = app->data + app->offset; - GST_BUFFER_SIZE (buffer) = len; - - GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, - app->offset, len); - g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret); - gst_buffer_unref (buffer); - - app->offset += len; - - return; -} - -/* this callback is called when playbin2 has constructed a source object to read - * from. Since we provided the appsrc:// uri to playbin2, this will be the - * appsrc that we must handle. We set up a signals to push data into appsrc. */ -static void -found_source (GObject * object, GObject * orig, GParamSpec * pspec, App * app) -{ - /* get a handle to the appsrc */ - g_object_get (orig, pspec->name, &app->appsrc, NULL); - - GST_DEBUG ("got appsrc %p", app->appsrc); - - /* we can set the length in appsrc. This allows some elements to estimate the - * total duration of the stream. It's a good idea to set the property when you - * can but it's not required. */ - g_object_set (app->appsrc, "size", (gint64) app->length, NULL); - - /* configure the appsrc, we will push a buffer to appsrc when it needs more - * data */ - g_signal_connect (app->appsrc, "need-data", G_CALLBACK (feed_data), app); -} - -static gboolean -bus_message (GstBus * bus, GstMessage * message, App * app) -{ - GST_DEBUG ("got message %s", - gst_message_type_get_name (GST_MESSAGE_TYPE (message))); - - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_ERROR: - g_error ("received error"); - g_main_loop_quit (app->loop); - break; - case GST_MESSAGE_EOS: - g_main_loop_quit (app->loop); - break; - default: - break; - } - return TRUE; -} - -int -main (int argc, char *argv[]) -{ - App *app = &s_app; - GError *error = NULL; - GstBus *bus; - - gst_init (&argc, &argv); - - GST_DEBUG_CATEGORY_INIT (appsrc_playbin_debug, "appsrc-playbin", 0, - "appsrc playbin example"); - - if (argc < 2) { - g_print ("usage: %s <filename>\n", argv[0]); - return -1; - } - - /* try to open the file as an mmapped file */ - app->file = g_mapped_file_new (argv[1], FALSE, &error); - if (error) { - g_print ("failed to open file: %s\n", error->message); - g_error_free (error); - return -2; - } - /* get some vitals, this will be used to read data from the mmapped file and - * feed it to appsrc. */ - app->length = g_mapped_file_get_length (app->file); - app->data = (guint8 *) g_mapped_file_get_contents (app->file); - app->offset = 0; - - /* create a mainloop to get messages */ - app->loop = g_main_loop_new (NULL, TRUE); - - app->playbin = gst_element_factory_make ("playbin2", NULL); - g_assert (app->playbin); - - bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin)); - - /* add watch for messages */ - gst_bus_add_watch (bus, (GstBusFunc) bus_message, app); - - /* set to read from appsrc */ - g_object_set (app->playbin, "uri", "appsrc://", NULL); - - /* get notification when the source is created so that we get a handle to it - * and can configure it */ - g_signal_connect (app->playbin, "deep-notify::source", - (GCallback) found_source, app); - - /* go to playing and wait in a mainloop. */ - gst_element_set_state (app->playbin, GST_STATE_PLAYING); - - /* this mainloop is stopped when we receive an error or EOS */ - g_main_loop_run (app->loop); - - GST_DEBUG ("stopping"); - - gst_element_set_state (app->playbin, GST_STATE_NULL); - - /* free the file */ - g_mapped_file_unref (app->file); - - gst_object_unref (bus); - g_main_loop_unref (app->loop); - - return 0; -} diff --git a/tests/examples/app/appsrc_ex.c b/tests/examples/app/appsrc_ex.c deleted file mode 100644 index c7aa4b6c..00000000 --- a/tests/examples/app/appsrc_ex.c +++ /dev/null @@ -1,95 +0,0 @@ - - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> -#include <gst/app/gstappsrc.h> -#include <gst/app/gstappbuffer.h> -#include <gst/app/gstappsink.h> - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - - -typedef struct _App App; -struct _App -{ - GstElement *pipe; - GstElement *src; - GstElement *id; - GstElement *sink; -}; - -App s_app; - -static void dont_eat_my_chicken_wings (void *priv); - -int -main (int argc, char *argv[]) -{ - App *app = &s_app; - int i; - - gst_init (&argc, &argv); - - app->pipe = gst_pipeline_new (NULL); - g_assert (app->pipe); - - app->src = gst_element_factory_make ("appsrc", NULL); - g_assert (app->src); - gst_bin_add (GST_BIN (app->pipe), app->src); - - app->id = gst_element_factory_make ("identity", NULL); - g_assert (app->id); - gst_bin_add (GST_BIN (app->pipe), app->id); - - app->sink = gst_element_factory_make ("appsink", NULL); - g_assert (app->sink); - gst_bin_add (GST_BIN (app->pipe), app->sink); - - gst_element_link (app->src, app->id); - gst_element_link (app->id, app->sink); - - gst_element_set_state (app->pipe, GST_STATE_PLAYING); - - for (i = 0; i < 10; i++) { - GstBuffer *buf; - void *data; - - data = malloc (100); - memset (data, i, 100); - - buf = gst_app_buffer_new (data, 100, dont_eat_my_chicken_wings, data); - printf ("%d: creating buffer for pointer %p, %p\n", i, data, buf); - gst_app_src_push_buffer (GST_APP_SRC (app->src), buf); - } - - /* push EOS */ - gst_app_src_end_of_stream (GST_APP_SRC (app->src)); - - /* _is_eos() does not block and returns TRUE if there is not currently an EOS - * to be retrieved */ - while (!gst_app_sink_is_eos (GST_APP_SINK (app->sink))) { - GstBuffer *buf; - - /* pull the next item, this can return NULL when there is no more data and - * EOS has been received */ - buf = gst_app_sink_pull_buffer (GST_APP_SINK (app->sink)); - printf ("retrieved buffer %p\n", buf); - if (buf) - gst_buffer_unref (buf); - } - gst_element_set_state (app->pipe, GST_STATE_NULL); - - return 0; -} - -static void -dont_eat_my_chicken_wings (void *priv) -{ - printf ("freeing buffer for pointer %p\n", priv); - free (priv); -} diff --git a/tests/examples/dynamic/.gitignore b/tests/examples/dynamic/.gitignore deleted file mode 100644 index 99b7654b..00000000 --- a/tests/examples/dynamic/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -addstream -codec-select -sprinkle -sprinkle2 -sprinkle3 diff --git a/tests/examples/dynamic/Makefile.am b/tests/examples/dynamic/Makefile.am deleted file mode 100644 index 087d5fe4..00000000 --- a/tests/examples/dynamic/Makefile.am +++ /dev/null @@ -1,21 +0,0 @@ -noinst_PROGRAMS = addstream codec-select sprinkle sprinkle2 sprinkle3 - -addstream_SOURCES = addstream.c -addstream_CFLAGS = $(GST_CFLAGS) -D_GNU_SOURCE -addstream_LDFLAGS = $(GST_LIBS) - -codec_select_SOURCES = codec-select.c -codec_select_CFLAGS = $(GST_CFLAGS) -D_GNU_SOURCE -codec_select_LDFLAGS = $(GST_LIBS) - -sprinkle_SOURCES = sprinkle.c -sprinkle_CFLAGS = $(GST_CFLAGS) -D_GNU_SOURCE -sprinkle_LDFLAGS = $(GST_LIBS) - -sprinkle2_SOURCES = sprinkle2.c -sprinkle2_CFLAGS = $(GST_CFLAGS) -D_GNU_SOURCE -sprinkle2_LDFLAGS = $(GST_LIBS) - -sprinkle3_SOURCES = sprinkle3.c -sprinkle3_CFLAGS = $(GST_CFLAGS) -D_GNU_SOURCE -sprinkle3_LDFLAGS = $(GST_LIBS) diff --git a/tests/examples/dynamic/addstream.c b/tests/examples/dynamic/addstream.c deleted file mode 100644 index 66ad0bec..00000000 --- a/tests/examples/dynamic/addstream.c +++ /dev/null @@ -1,253 +0,0 @@ -/* GStreamer - * - * addstream.c: sample application to dynamically add streams to a running - * pipeline - * - * Copyright (C) <2007> Wim Taymans <wim dot taymans at gmail dot 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> - -static GstElement *pipeline; -static GstClock *theclock; -static GMainLoop *loop; -static GstElement *bin1, *bin2, *bin3, *bin4, *bin5; - -/* start a bin with the given description */ -static GstElement * -create_stream (const gchar * descr) -{ - GstElement *bin; - GError *error = NULL; - - bin = gst_parse_launch (descr, &error); - if (error) { - g_print ("pipeline could not be constructed: %s\n", error->message); - g_error_free (error); - return NULL; - } - - /* add the bin to the pipeline now, this will set the current base_time of the - * pipeline on the new bin. */ - gst_bin_add (GST_BIN_CAST (pipeline), bin); - - return bin; -} - -static gboolean -pause_play_stream (GstElement * bin, gint seconds) -{ - gboolean punch_in; - GstStateChangeReturn ret; - GstClockTime now, base_time, running_time; - - /* get current running time, we need this value to continue playback of - * non-live pipelines. */ - now = gst_clock_get_time (theclock); - base_time = gst_element_get_base_time (bin); - - running_time = now - base_time; - - /* set the new bin to PAUSED, the parent bin will notice (because of the ASYNC - * message and will perform latency calculations again when going to PLAYING - * later. */ - ret = gst_element_set_state (bin, GST_STATE_PAUSED); - - switch (ret) { - case GST_STATE_CHANGE_NO_PREROLL: - /* live source, timestamps are running_time of the pipeline clock. */ - punch_in = FALSE; - break; - case GST_STATE_CHANGE_SUCCESS: - /* success, no async state changes, same as async, timestamps start - * from 0 */ - case GST_STATE_CHANGE_ASYNC: - /* no live source, bin will preroll. We have to punch it in because in - * this situation timestamps start from 0. */ - punch_in = TRUE; - break; - default: - case GST_STATE_CHANGE_FAILURE: - return FALSE; - } - - if (seconds) - g_usleep (seconds * G_USEC_PER_SEC); - - if (punch_in) { - /* new bin has to be aligned with previous running_time. We do this by taking - * the current absolute clock time and calculating the base time that would - * give the previous running_time. We set this base_time on the bin before - * setting it to PLAYING. */ - now = gst_clock_get_time (theclock); - base_time = now - running_time; - - gst_element_set_base_time (bin, base_time); - } - - /* now set the pipeline to PLAYING */ - gst_element_set_state (bin, GST_STATE_PLAYING); - - return TRUE; -} - -static void -message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline) -{ - const GstStructure *s; - - s = gst_message_get_structure (message); - g_print ("message from \"%s\" (%s): ", - GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))), - gst_message_type_get_name (GST_MESSAGE_TYPE (message))); - if (s) { - gchar *sstr; - - sstr = gst_structure_to_string (s); - g_print ("%s\n", sstr); - g_free (sstr); - } else { - g_print ("no message details\n"); - } -} - -static void -eos_message_received (GstBus * bus, GstMessage * message, - GstPipeline * pipeline) -{ - message_received (bus, message, pipeline); - g_main_loop_quit (loop); -} - -static gboolean -perform_step (gpointer pstep) -{ - gint step = GPOINTER_TO_INT (pstep); - - switch (step) { - case 0: - /* live stream locks on to running_time, pipeline configures latency. */ - g_print ("creating bin1\n"); - bin1 = - create_stream - ("( v4l2src ! ffmpegcolorspace ! timeoverlay ! queue ! xvimagesink name=v4llive )"); - pause_play_stream (bin1, 0); - g_timeout_add (1000, (GSourceFunc) perform_step, GINT_TO_POINTER (1)); - break; - case 1: - /* live stream locks on to running_time, pipeline reconfigures latency - * together with the previously added bin so that they run synchronized. */ - g_print ("creating bin2\n"); - bin2 = create_stream ("( alsasrc ! queue ! alsasink name=alsalive )"); - pause_play_stream (bin2, 0); - g_timeout_add (1000, (GSourceFunc) perform_step, GINT_TO_POINTER (2)); - break; - case 2: - /* non-live stream, need base_time to align with current running live sources. */ - g_print ("creating bin3\n"); - bin3 = create_stream ("( audiotestsrc ! alsasink name=atnonlive )"); - pause_play_stream (bin3, 0); - g_timeout_add (1000, (GSourceFunc) perform_step, GINT_TO_POINTER (3)); - break; - case 3: - g_print ("creating bin4\n"); - bin4 = - create_stream - ("( videotestsrc ! timeoverlay ! ffmpegcolorspace ! ximagesink name=vtnonlive )"); - pause_play_stream (bin4, 0); - g_timeout_add (1000, (GSourceFunc) perform_step, GINT_TO_POINTER (4)); - break; - case 4: - /* live stream locks on to running_time */ - g_print ("creating bin5\n"); - bin5 = - create_stream - ("( videotestsrc is-live=1 ! timeoverlay ! ffmpegcolorspace ! ximagesink name=vtlive )"); - pause_play_stream (bin5, 0); - g_timeout_add (1000, (GSourceFunc) perform_step, GINT_TO_POINTER (5)); - break; - case 5: - /* pause the fist live stream for 2 seconds */ - g_print ("PAUSE bin1 for 2 seconds\n"); - pause_play_stream (bin1, 2); - /* pause the non-live stream for 2 seconds */ - g_print ("PAUSE bin4 for 2 seconds\n"); - pause_play_stream (bin4, 2); - /* pause the pseudo live stream for 2 seconds */ - g_print ("PAUSE bin5 for 2 seconds\n"); - pause_play_stream (bin5, 2); - g_print ("Waiting 5 seconds\n"); - g_timeout_add (5000, (GSourceFunc) perform_step, GINT_TO_POINTER (6)); - break; - case 6: - g_print ("quiting\n"); - g_main_loop_quit (loop); - break; - default: - break; - } - return FALSE; -} - -int -main (int argc, char *argv[]) -{ - GstBus *bus; - - gst_init (&argc, &argv); - - loop = g_main_loop_new (NULL, TRUE); - - pipeline = gst_pipeline_new ("pipeline"); - - /* setup message handling */ - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - g_signal_connect (bus, "message::error", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::warning", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::eos", (GCallback) eos_message_received, - pipeline); - - /* we set the pipeline to PLAYING, this will distribute a default clock and - * start running. no preroll is needed */ - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - /* get the clock now. Since we never set the pipeline to PAUSED again, the - * clock will not change, even when we add new clock providers later. */ - theclock = gst_element_get_clock (pipeline); - - /* start our actions while we are in the mainloop so that we can catch errors - * and other messages. */ - g_idle_add ((GSourceFunc) perform_step, GINT_TO_POINTER (0)); - /* go to main loop */ - g_main_loop_run (loop); - - gst_element_set_state (pipeline, GST_STATE_NULL); - - gst_object_unref (bus); - gst_object_unref (pipeline); - gst_object_unref (theclock); - - return 0; -} diff --git a/tests/examples/dynamic/codec-select.c b/tests/examples/dynamic/codec-select.c deleted file mode 100644 index 2d8f9fac..00000000 --- a/tests/examples/dynamic/codec-select.c +++ /dev/null @@ -1,298 +0,0 @@ -/* GStreamer - * - * codec-select.c: sample application to dynamically select a codec - * - * Copyright (C) <2008> Wim Taymans <wim dot taymans at gmail dot 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * This example sets up a pipeline to 'encode' an audiotestsrc into 3 different - * formats. The format can be selected dynamically at runtime. - * - * Each of the encoders require the audio in a specific different format. - * - * This example uses identity as the encoder and enforces the caps on identity - * with a capsfilter. - * - * This is a good example of input and output selector and how these elements - * preserve segment and timing information while switching between streams. - */ - -#include <string.h> -#include <gst/gst.h> - -/* Create an encoder element. - * We make a bin containing: - * - * audioresample ! <enccaps> ! identity - * - * The sinkpad of audioresample and source pad of identity are ghosted on the - * bin. - */ -static GstElement * -make_encoder (const GstCaps * caps) -{ - GstElement *result; - GstElement *audioresample; - GstElement *capsfilter; - GstElement *identity; - GstPad *pad; - - /* create result bin */ - result = gst_bin_new (NULL); - g_assert (result); - - /* create elements */ - audioresample = gst_element_factory_make ("audioresample", NULL); - g_assert (audioresample); - - capsfilter = gst_element_factory_make ("capsfilter", NULL); - g_assert (capsfilter); - g_object_set (capsfilter, "caps", caps, NULL); - - identity = gst_element_factory_make ("identity", NULL); - g_assert (identity); - g_object_set (identity, "silent", TRUE, NULL); - - /* add elements to result bin */ - gst_bin_add (GST_BIN (result), audioresample); - gst_bin_add (GST_BIN (result), capsfilter); - gst_bin_add (GST_BIN (result), identity); - - /* link elements */ - gst_element_link_pads (audioresample, "src", capsfilter, "sink"); - gst_element_link_pads (capsfilter, "src", identity, "sink"); - - /* ghost src and sink pads */ - pad = gst_element_get_static_pad (audioresample, "sink"); - gst_element_add_pad (result, gst_ghost_pad_new ("sink", pad)); - gst_object_unref (pad); - - pad = gst_element_get_static_pad (identity, "src"); - gst_element_add_pad (result, gst_ghost_pad_new ("src", pad)); - gst_object_unref (pad); - - return result; -} - -/* - * We generate: - * - * audiotestsrc ! <audiocaps> ! output-selector ! [enc1 .. enc3] ! input-selector - * select-all = true ! fakesink - * - * <audiocaps> makes sure we only produce one format from the audiotestsrc. - * - * Each encX element consists of: - * - * audioresample ! <enccaps> ! identity ! - * - * This way we can simply switch encoders without having to renegotiate. - */ -static GstElement * -make_pipeline (void) -{ - GstElement *result; - GstElement *audiotestsrc; - GstElement *audiocaps; - GstElement *outputselect; - GstElement *inputselect; - GstElement *sink; - GstCaps *caps; - GstCaps *capslist[3]; - gint i; - - /* create result pipeline */ - result = gst_pipeline_new (NULL); - g_assert (result); - - /* create various elements */ - audiotestsrc = gst_element_factory_make ("audiotestsrc", NULL); - g_object_set (audiotestsrc, "num-buffers", 1000, NULL); - g_assert (audiotestsrc); - - audiocaps = gst_element_factory_make ("capsfilter", NULL); - g_assert (audiocaps); - - caps = - gst_caps_from_string - ("audio/x-raw-int,signed=true,width=16,depth=16,rate=48000,channels=1"); - g_object_set (audiocaps, "caps", caps, NULL); - gst_caps_unref (caps); - - outputselect = gst_element_factory_make ("output-selector", "select"); - g_assert (outputselect); - - inputselect = gst_element_factory_make ("input-selector", NULL); - g_assert (inputselect); - g_object_set (inputselect, "select-all", TRUE, NULL); - - sink = gst_element_factory_make ("fakesink", NULL); - g_object_set (sink, "sync", TRUE, NULL); - g_object_set (sink, "silent", TRUE, NULL); - g_assert (sink); - - /* add elements */ - gst_bin_add (GST_BIN (result), audiotestsrc); - gst_bin_add (GST_BIN (result), audiocaps); - gst_bin_add (GST_BIN (result), outputselect); - gst_bin_add (GST_BIN (result), inputselect); - gst_bin_add (GST_BIN (result), sink); - - /* link elements */ - gst_element_link_pads (audiotestsrc, "src", audiocaps, "sink"); - gst_element_link_pads (audiocaps, "src", outputselect, "sink"); - gst_element_link_pads (inputselect, "src", sink, "sink"); - - /* make caps */ - capslist[0] = - gst_caps_from_string - ("audio/x-raw-int,signed=true,width=16,depth=16,rate=48000,channels=1"); - capslist[1] = - gst_caps_from_string - ("audio/x-raw-int,signed=true,width=16,depth=16,rate=16000,channels=1"); - capslist[2] = - gst_caps_from_string - ("audio/x-raw-int,signed=true,width=16,depth=16,rate=8000,channels=1"); - - /* create encoder elements */ - for (i = 0; i < 3; i++) { - GstElement *encoder; - GstPad *srcpad, *sinkpad; - - encoder = make_encoder (capslist[i]); - g_assert (encoder); - - gst_bin_add (GST_BIN (result), encoder); - - srcpad = gst_element_get_request_pad (outputselect, "src%d"); - sinkpad = gst_element_get_static_pad (encoder, "sink"); - gst_pad_link (srcpad, sinkpad); - gst_object_unref (srcpad); - gst_object_unref (sinkpad); - - srcpad = gst_element_get_static_pad (encoder, "src"); - sinkpad = gst_element_get_request_pad (inputselect, "sink%d"); - gst_pad_link (srcpad, sinkpad); - gst_object_unref (srcpad); - gst_object_unref (sinkpad); - } - - return result; -} - -static gboolean -do_switch (GstElement * pipeline) -{ - gint rand; - GstElement *select; - gchar *name; - GstPad *pad; - - rand = g_random_int_range (0, 3); - - g_print ("switching to %d\n", rand); - - /* find the selector */ - select = gst_bin_get_by_name (GST_BIN (pipeline), "select"); - - /* get the named pad */ - name = g_strdup_printf ("src%d", rand); - pad = gst_element_get_static_pad (select, name); - g_free (name); - - /* set the active pad */ - g_object_set (select, "active-pad", pad, NULL); - - return TRUE; -} - -static gboolean -my_bus_callback (GstBus * bus, GstMessage * message, gpointer data) -{ - GstElement *sender = (GstElement *) GST_MESSAGE_SRC (message); - const gchar *name = gst_element_get_name (sender); - GMainLoop *loop = (GMainLoop *) data; - - g_print ("Got %s message from %s\n", GST_MESSAGE_TYPE_NAME (message), name); - - switch (GST_MESSAGE_TYPE (message)) { - - case GST_MESSAGE_ERROR:{ - GError *err; - gchar *debug; - - gst_message_parse_error (message, &err, &debug); - g_print ("Error: %s (%s)\n", err->message, debug); - g_error_free (err); - g_free (debug); - - g_main_loop_quit (loop); - break; - } - case GST_MESSAGE_EOS: - /* end-of-stream */ - g_main_loop_quit (loop); - break; - default: - /* unhandled message */ - break; - } - - return TRUE; -} - -gint -main (gint argc, gchar * argv[]) -{ - GstElement *pipeline; - GstBus *bus; - GMainLoop *loop; - - /* init GStreamer */ - gst_init (&argc, &argv); - loop = g_main_loop_new (NULL, FALSE); - - /* set up */ - pipeline = make_pipeline (); - - g_signal_connect (pipeline, "deep_notify", - G_CALLBACK (gst_object_default_deep_notify), NULL); - - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - gst_bus_add_watch (bus, my_bus_callback, loop); - gst_object_unref (bus); - - g_print ("Starting pipeline\n"); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - /* add a timeout to cycle between the formats */ - g_timeout_add (1000, (GSourceFunc) do_switch, pipeline); - - /* now run */ - g_main_loop_run (loop); - - g_print ("Nulling pipeline\n"); - - /* also clean up */ - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - - return 0; -} diff --git a/tests/examples/dynamic/sprinkle.c b/tests/examples/dynamic/sprinkle.c deleted file mode 100644 index 1b75840a..00000000 --- a/tests/examples/dynamic/sprinkle.c +++ /dev/null @@ -1,264 +0,0 @@ -/* GStreamer - * - * sprinkle.c: sample application to dynamically mix tones with adder - * - * Copyright (C) <2009> Wim Taymans <wim dot taymans at gmail dot 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Produces a sweeping sprinkle of tones by dynamically adding and removing - * elements to adder. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> - -static GstElement *pipeline, *adder; -static GMainLoop *loop; - -typedef struct -{ - GstElement *element; - GstPad *srcpad; - GstPad *sinkpad; - gdouble freq; -} SourceInfo; - -/* dynamically add the source to the pipeline and link it to a new pad on - * adder */ -static SourceInfo * -add_source (gdouble freq) -{ - SourceInfo *info; - - info = g_new0 (SourceInfo, 1); - info->freq = freq; - - /* make source with unique name */ - info->element = gst_element_factory_make ("audiotestsrc", NULL); - - g_object_set (info->element, "freq", freq, NULL); - - /* add to the bin */ - gst_bin_add (GST_BIN (pipeline), info->element); - - /* get pad from the element */ - info->srcpad = gst_element_get_static_pad (info->element, "src"); - - /* get new pad from adder, adder will now wait for data on this pad */ - info->sinkpad = gst_element_get_request_pad (adder, "sink%d"); - - /* link pad to adder */ - gst_pad_link (info->srcpad, info->sinkpad); - - /* and play the element */ - gst_element_set_state (info->element, GST_STATE_PLAYING); - - g_print ("added freq %f\n", info->freq); - - return info; -} - -/* remove the source from the pipeline after removing it from adder */ -static void -remove_source (SourceInfo * info) -{ - g_print ("remove freq %f\n", info->freq); - - /* lock the state so that we can put it to NULL without the parent messing - * with our state */ - gst_element_set_locked_state (info->element, TRUE); - - /* first stop the source. Remember that this might block when in the PAUSED - * state. Alternatively one could send EOS to the source, install an event - * probe and schedule a state change/unlink/release from the mainthread. - * Note that changing the state of a source makes it emit an EOS, which can - * make adder go EOS. */ - gst_element_set_state (info->element, GST_STATE_NULL); - - /* unlink from adder */ - gst_pad_unlink (info->srcpad, info->sinkpad); - gst_object_unref (info->srcpad); - - /* remove from the bin */ - gst_bin_remove (GST_BIN (pipeline), info->element); - - /* give back the pad */ - gst_element_release_request_pad (adder, info->sinkpad); - gst_object_unref (info->sinkpad); - - g_free (info); -} - -/* we'll keep the state of the sources in this structure. We keep 3 sources - * alive */ -typedef struct -{ - guint count; - SourceInfo *infos[3]; -} SprinkleState; - -static SprinkleState * -create_state (void) -{ - SprinkleState *state; - - state = g_new0 (SprinkleState, 1); - - return state; -} - -static void -free_state (SprinkleState * state) -{ - SourceInfo *info; - gint i; - - for (i = 0; i < 3; i++) { - info = state->infos[i]; - if (info) - remove_source (info); - } - - g_free (state); -} - -static gboolean -do_sprinkle (SprinkleState * state) -{ - SourceInfo *info; - gint i; - - /* first remove the oldest info */ - info = state->infos[2]; - - if (info) - remove_source (info); - - /* move sources */ - for (i = 2; i > 0; i--) { - state->infos[i] = state->infos[i - 1]; - } - - /* add new source, stop adding sources after 10 rounds. */ - if (state->count < 10) { - state->infos[0] = add_source ((state->count * 100) + 200); - state->count++; - } else { - state->infos[0] = NULL; - } - return TRUE; -} - -static void -message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline) -{ - const GstStructure *s; - - s = gst_message_get_structure (message); - g_print ("message from \"%s\" (%s): ", - GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))), - gst_message_type_get_name (GST_MESSAGE_TYPE (message))); - if (s) { - gchar *sstr; - - sstr = gst_structure_to_string (s); - g_print ("%s\n", sstr); - g_free (sstr); - } else { - g_print ("no message details\n"); - } -} - -static void -eos_message_received (GstBus * bus, GstMessage * message, - GstPipeline * pipeline) -{ - message_received (bus, message, pipeline); - g_main_loop_quit (loop); -} - -int -main (int argc, char *argv[]) -{ - GstBus *bus; - GstElement *filter, *convert, *sink; - GstCaps *caps; - gboolean res; - SprinkleState *state; - - gst_init (&argc, &argv); - - loop = g_main_loop_new (NULL, TRUE); - - pipeline = gst_pipeline_new ("pipeline"); - - /* add the fixed part to the pipeline. Remember that we need a capsfilter - * after adder so that multiple sources are not racing to negotiate - * a format */ - adder = gst_element_factory_make ("adder", "adder"); - filter = gst_element_factory_make ("capsfilter", "filter"); - convert = gst_element_factory_make ("audioconvert", "convert"); - sink = gst_element_factory_make ("autoaudiosink", "sink"); - - caps = gst_caps_new_simple ("audio/x-raw-int", - "endianness", G_TYPE_INT, G_LITTLE_ENDIAN, - "channels", G_TYPE_INT, 1, - "width", G_TYPE_INT, 16, - "depth", G_TYPE_INT, 16, - "rate", G_TYPE_INT, 44100, "signed", G_TYPE_BOOLEAN, TRUE, NULL); - g_object_set (filter, "caps", caps, NULL); - gst_caps_unref (caps); - - gst_bin_add_many (GST_BIN (pipeline), adder, filter, convert, sink, NULL); - - res = gst_element_link_many (adder, filter, convert, sink, NULL); - g_assert (res); - - /* setup message handling */ - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - g_signal_connect (bus, "message::error", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::warning", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::eos", (GCallback) eos_message_received, - pipeline); - - /* we set the pipeline to PLAYING, the pipeline will not yet preroll because - * there is no source providing data for it yet */ - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - /* and add the function that modifies the pipeline every 100ms */ - state = create_state (); - g_timeout_add (100, (GSourceFunc) do_sprinkle, state); - - /* go to main loop */ - g_main_loop_run (loop); - - gst_element_set_state (pipeline, GST_STATE_NULL); - - free_state (state); - gst_object_unref (bus); - gst_object_unref (pipeline); - - return 0; -} diff --git a/tests/examples/dynamic/sprinkle2.c b/tests/examples/dynamic/sprinkle2.c deleted file mode 100644 index abab47ce..00000000 --- a/tests/examples/dynamic/sprinkle2.c +++ /dev/null @@ -1,288 +0,0 @@ -/* GStreamer - * - * sprinkle.c: sample application to dynamically mix tones with adder - * - * Copyright (C) <2009> Wim Taymans <wim dot taymans at gmail dot 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Produces a sweeping sprinkle of tones by dynamically adding and removing - * elements to adder. - * - * gcc `pkg-config --cflags --libs gstreamer-0.10` sprinkle2.c -osprinkle2 - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> - -static GstElement *pipeline, *adder; -static GMainLoop *loop; - -typedef struct -{ - GstElement *src, *fx; - GstPad *src_srcpad; - GstPad *fx_sinkpad, *fx_srcpad; - GstPad *adder_sinkpad; - gdouble freq; - gfloat pos; -} SourceInfo; - -/* dynamically add the source to the pipeline and link it to a new pad on - * adder */ -static SourceInfo * -add_source (gdouble freq, gfloat pos) -{ - SourceInfo *info; - - info = g_new0 (SourceInfo, 1); - info->freq = freq; - info->pos = pos; - - /* make source with unique name */ - info->src = gst_element_factory_make ("audiotestsrc", NULL); - info->fx = gst_element_factory_make ("audiopanorama", NULL); - - g_object_set (info->src, "freq", freq, "volume", (gdouble) 0.35, NULL); - g_object_set (info->fx, "panorama", pos, NULL); - - /* add to the bin */ - gst_bin_add (GST_BIN (pipeline), info->src); - gst_bin_add (GST_BIN (pipeline), info->fx); - - /* get pads from the elements */ - info->src_srcpad = gst_element_get_static_pad (info->src, "src"); - info->fx_srcpad = gst_element_get_static_pad (info->fx, "src"); - info->fx_sinkpad = gst_element_get_static_pad (info->fx, "sink"); - - /* get new pad from adder, adder will now wait for data on this pad */ - info->adder_sinkpad = gst_element_get_request_pad (adder, "sink%d"); - - /* link src to fx and fx to adder */ - gst_pad_link (info->fx_srcpad, info->adder_sinkpad); - gst_pad_link (info->src_srcpad, info->fx_sinkpad); - - /* and play the elements, change the state from sink to source */ - gst_element_set_state (info->fx, GST_STATE_PLAYING); - gst_element_set_state (info->src, GST_STATE_PLAYING); - - g_print ("added freq %5.0f, pos %3.1f\n", info->freq, info->pos); - - return info; -} - -/* remove the source from the pipeline after removing it from adder */ -static void -remove_source (SourceInfo * info) -{ - g_print ("remove freq %5.0f, pos %3.1f\n", info->freq, info->pos); - - /* lock the state so that we can put it to NULL without the parent messing - * with our state */ - gst_element_set_locked_state (info->src, TRUE); - gst_element_set_locked_state (info->fx, TRUE); - - /* first stop the source. Remember that this might block when in the PAUSED - * state. Alternatively one could send EOS to the source, install an event - * probe and schedule a state change/unlink/release from the mainthread. */ - gst_element_set_state (info->fx, GST_STATE_NULL); - /* NOTE that the source emits EOS when shutting down but the EOS will not - * reach the adder sinkpad because the effect is in the NULL state. We will - * send an EOS to adder later. */ - gst_element_set_state (info->src, GST_STATE_NULL); - - /* unlink from adder */ - gst_pad_unlink (info->src_srcpad, info->fx_sinkpad); - gst_pad_unlink (info->fx_srcpad, info->adder_sinkpad); - gst_object_unref (info->src_srcpad); - gst_object_unref (info->fx_srcpad); - gst_object_unref (info->fx_sinkpad); - - /* remove from the bin */ - gst_bin_remove (GST_BIN (pipeline), info->src); - gst_bin_remove (GST_BIN (pipeline), info->fx); - - /* send EOS to the sinkpad to make adder EOS when needed */ - gst_pad_send_event (info->adder_sinkpad, gst_event_new_eos ()); - - /* give back the pad */ - gst_element_release_request_pad (adder, info->adder_sinkpad); - gst_object_unref (info->adder_sinkpad); - - g_free (info); -} - -/* we'll keep the state of the sources in this structure. We keep 3 sources - * alive */ -typedef struct -{ - guint count; - SourceInfo *infos[3]; -} SprinkleState; - -static SprinkleState * -create_state (void) -{ - SprinkleState *state; - - state = g_new0 (SprinkleState, 1); - - return state; -} - -static void -free_state (SprinkleState * state) -{ - SourceInfo *info; - gint i; - - for (i = 0; i < 3; i++) { - info = state->infos[i]; - if (info) - remove_source (info); - } - - g_free (state); -} - -static gboolean -do_sprinkle (SprinkleState * state) -{ - SourceInfo *info; - gint i; - - /* first remove the oldest info */ - info = state->infos[2]; - - if (info) - remove_source (info); - - /* move sources */ - for (i = 2; i > 0; i--) { - state->infos[i] = state->infos[i - 1]; - } - - /* add new source, stop adding sources after 10 rounds. */ - if (state->count < 20) { - state->infos[0] = add_source ( - (gdouble) ((state->count * 100) + 200), - ((gfloat) (state->count % 5) / 2.0 - 1.0)); - state->count++; - } else { - state->infos[0] = NULL; - } - return TRUE; -} - -static void -message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline) -{ - const GstStructure *s; - - s = gst_message_get_structure (message); - g_print ("message from \"%s\" (%s): ", - GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))), - gst_message_type_get_name (GST_MESSAGE_TYPE (message))); - if (s) { - gchar *sstr; - - sstr = gst_structure_to_string (s); - g_print ("%s\n", sstr); - g_free (sstr); - } else { - g_print ("no message details\n"); - } -} - -static void -eos_message_received (GstBus * bus, GstMessage * message, - GstPipeline * pipeline) -{ - message_received (bus, message, pipeline); - g_main_loop_quit (loop); -} - -int -main (int argc, char *argv[]) -{ - GstBus *bus; - GstElement *filter, *convert, *sink; - GstCaps *caps; - gboolean res; - SprinkleState *state; - - gst_init (&argc, &argv); - - loop = g_main_loop_new (NULL, TRUE); - - pipeline = gst_pipeline_new ("pipeline"); - - /* add the fixed part to the pipeline. Remember that we need a capsfilter - * after adder so that multiple sources are not racing to negotiate - * a format */ - adder = gst_element_factory_make ("adder", "adder"); - filter = gst_element_factory_make ("capsfilter", "filter"); - convert = gst_element_factory_make ("audioconvert", "convert"); - sink = gst_element_factory_make ("autoaudiosink", "sink"); - - caps = gst_caps_new_simple ("audio/x-raw-int", - "endianness", G_TYPE_INT, G_LITTLE_ENDIAN, - "channels", G_TYPE_INT, 2, - "width", G_TYPE_INT, 16, - "depth", G_TYPE_INT, 16, - "rate", G_TYPE_INT, 44100, "signed", G_TYPE_BOOLEAN, TRUE, NULL); - g_object_set (filter, "caps", caps, NULL); - gst_caps_unref (caps); - - gst_bin_add_many (GST_BIN (pipeline), adder, filter, convert, sink, NULL); - - res = gst_element_link_many (adder, filter, convert, sink, NULL); - g_assert (res); - - /* setup message handling */ - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - g_signal_connect (bus, "message::error", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::warning", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::eos", (GCallback) eos_message_received, - pipeline); - - /* we set the pipeline to PLAYING, the pipeline will not yet preroll because - * there is no source providing data for it yet */ - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - /* and add the function that modifies the pipeline every 100ms */ - state = create_state (); - g_timeout_add (100, (GSourceFunc) do_sprinkle, state); - - /* go to main loop */ - g_main_loop_run (loop); - - gst_element_set_state (pipeline, GST_STATE_NULL); - - free_state (state); - gst_object_unref (bus); - gst_object_unref (pipeline); - - return 0; -} diff --git a/tests/examples/dynamic/sprinkle3.c b/tests/examples/dynamic/sprinkle3.c deleted file mode 100644 index 5983c335..00000000 --- a/tests/examples/dynamic/sprinkle3.c +++ /dev/null @@ -1,301 +0,0 @@ -/* GStreamer - * - * sprinkle.c: sample application to dynamically mix tones with adder - * - * Copyright (C) <2009> Wim Taymans <wim dot taymans at gmail dot 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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Produces a sweeping sprinkle of tones by dynamically adding and removing - * elements to adder. - * - * gcc `pkg-config --cflags --libs gstreamer-0.10` sprinkle3.c -osprinkle3 - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> - -static GstElement *pipeline, *adder; -static GMainLoop *loop; - -typedef struct -{ - GstElement *bin, *src, *fx; - GstPad *src_srcpad; - GstPad *fx_sinkpad, *fx_srcpad; - GstPad *adder_sinkpad; - GstPad *bin_srcpad; - gdouble freq; - gfloat pos; -} SourceInfo; - -/* dynamically add the source to the pipeline and link it to a new pad on - * adder */ -static SourceInfo * -add_source (gdouble freq, gfloat pos) -{ - SourceInfo *info; - - info = g_new0 (SourceInfo, 1); - info->freq = freq; - info->pos = pos; - - /* make source with unique name */ - info->bin = gst_element_factory_make ("bin", NULL); - info->src = gst_element_factory_make ("audiotestsrc", NULL); - info->fx = gst_element_factory_make ("audiopanorama", NULL); - - g_object_set (info->src, "freq", freq, "volume", (gdouble) 0.35, NULL); - g_object_set (info->fx, "panorama", pos, NULL); - - /* add to the bin */ - gst_bin_add (GST_BIN (info->bin), info->src); - gst_bin_add (GST_BIN (info->bin), info->fx); - - /* get pads from the elements */ - info->src_srcpad = gst_element_get_static_pad (info->src, "src"); - info->fx_srcpad = gst_element_get_static_pad (info->fx, "src"); - info->fx_sinkpad = gst_element_get_static_pad (info->fx, "sink"); - - /* create and add a pad for the bin */ - info->bin_srcpad = gst_ghost_pad_new ("src", info->fx_srcpad); - gst_element_add_pad (info->bin, info->bin_srcpad); - - /* get new pad from adder, adder will now wait for data on this pad */ - info->adder_sinkpad = gst_element_get_request_pad (adder, "sink%d"); - - /* link inside the bin */ - gst_pad_link (info->src_srcpad, info->fx_sinkpad); - - /* add bin to pipeline */ - gst_bin_add (GST_BIN (pipeline), info->bin); - - /* link bin to adder */ - gst_pad_link (info->bin_srcpad, info->adder_sinkpad); - - /* and play the elements */ - gst_element_set_state (info->bin, GST_STATE_PLAYING); - - g_print ("added freq %5.0f, pos %3.1f\n", info->freq, info->pos); - - return info; -} - -/* remove the source from the pipeline after removing it from adder */ -static void -remove_source (SourceInfo * info) -{ - g_print ("remove freq %5.0f, pos %3.1f\n", info->freq, info->pos); - - /* lock the state so that we can put it to NULL without the parent messing - * with our state */ - gst_element_set_locked_state (info->bin, TRUE); - - /* first stop the source. Remember that this might block when in the PAUSED - * state. Alternatively one could send EOS to the source, install an event - * probe and schedule a state change/unlink/release from the mainthread. */ - /* NOTE that the source inside the bin will emit EOS but it will not reach - * adder because the element after the source is shut down first. We will send - * EOS later */ - gst_element_set_state (info->bin, GST_STATE_NULL); - - /* unlink bin from adder */ - gst_pad_unlink (info->bin_srcpad, info->adder_sinkpad); - - /* release pads */ - gst_object_unref (info->src_srcpad); - gst_object_unref (info->fx_srcpad); - gst_object_unref (info->fx_sinkpad); - - /* remove from the bin */ - gst_bin_remove (GST_BIN (pipeline), info->bin); - - /* send EOS to the sinkpad to make adder EOS when needed */ - gst_pad_send_event (info->adder_sinkpad, gst_event_new_eos ()); - - /* give back the pad */ - gst_element_release_request_pad (adder, info->adder_sinkpad); - gst_object_unref (info->adder_sinkpad); - - g_free (info); -} - -/* we'll keep the state of the sources in this structure. We keep 3 sources - * alive */ -typedef struct -{ - guint count; - SourceInfo *infos[3]; -} SprinkleState; - -static SprinkleState * -create_state (void) -{ - SprinkleState *state; - - state = g_new0 (SprinkleState, 1); - - return state; -} - -static void -free_state (SprinkleState * state) -{ - SourceInfo *info; - gint i; - - for (i = 0; i < 3; i++) { - info = state->infos[i]; - if (info) - remove_source (info); - } - - g_free (state); -} - -static gboolean -do_sprinkle (SprinkleState * state) -{ - SourceInfo *info; - gint i; - - /* first remove the oldest info */ - info = state->infos[2]; - - if (info) - remove_source (info); - - /* move sources */ - for (i = 2; i > 0; i--) { - state->infos[i] = state->infos[i - 1]; - } - - /* add new source, stop adding sources after 10 rounds. */ - if (state->count < 20) { - state->infos[0] = add_source ( - (gdouble) ((state->count * 100) + 200), - ((gfloat) (state->count % 5) / 2.0 - 1.0)); - state->count++; - } else { - state->infos[0] = NULL; - } - - GST_DEBUG_BIN_TO_DOT_FILE_WITH_TS (GST_BIN (pipeline), - /*GST_DEBUG_GRAPH_SHOW_ALL, */ - GST_DEBUG_GRAPH_SHOW_CAPS_DETAILS | GST_DEBUG_GRAPH_SHOW_STATES, - "sprinkle3"); - return TRUE; -} - -static void -message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline) -{ - const GstStructure *s; - - s = gst_message_get_structure (message); - g_print ("message from \"%s\" (%s): ", - GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))), - gst_message_type_get_name (GST_MESSAGE_TYPE (message))); - if (s) { - gchar *sstr; - - sstr = gst_structure_to_string (s); - g_print ("%s\n", sstr); - g_free (sstr); - } else { - g_print ("no message details\n"); - } -} - -static void -eos_message_received (GstBus * bus, GstMessage * message, - GstPipeline * pipeline) -{ - message_received (bus, message, pipeline); - g_main_loop_quit (loop); -} - -int -main (int argc, char *argv[]) -{ - GstBus *bus; - GstElement *filter, *convert, *sink; - GstCaps *caps; - gboolean res; - SprinkleState *state; - - gst_init (&argc, &argv); - - loop = g_main_loop_new (NULL, TRUE); - - pipeline = gst_pipeline_new ("pipeline"); - - /* add the fixed part to the pipeline. Remember that we need a capsfilter - * after adder so that multiple sources are not racing to negotiate - * a format */ - adder = gst_element_factory_make ("adder", "adder"); - filter = gst_element_factory_make ("capsfilter", "filter"); - convert = gst_element_factory_make ("audioconvert", "convert"); - sink = gst_element_factory_make ("autoaudiosink", "sink"); - - caps = gst_caps_new_simple ("audio/x-raw-int", - "endianness", G_TYPE_INT, G_LITTLE_ENDIAN, - "channels", G_TYPE_INT, 2, - "width", G_TYPE_INT, 16, - "depth", G_TYPE_INT, 16, - "rate", G_TYPE_INT, 44100, "signed", G_TYPE_BOOLEAN, TRUE, NULL); - g_object_set (filter, "caps", caps, NULL); - gst_caps_unref (caps); - - gst_bin_add_many (GST_BIN (pipeline), adder, filter, convert, sink, NULL); - - res = gst_element_link_many (adder, filter, convert, sink, NULL); - g_assert (res); - - /* setup message handling */ - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - g_signal_connect (bus, "message::error", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::warning", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::eos", (GCallback) eos_message_received, - pipeline); - - /* we set the pipeline to PLAYING, the pipeline will not yet preroll because - * there is no source providing data for it yet */ - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - /* and add the function that modifies the pipeline every 100ms */ - state = create_state (); - g_timeout_add (100, (GSourceFunc) do_sprinkle, state); - - /* go to main loop */ - g_main_loop_run (loop); - - gst_element_set_state (pipeline, GST_STATE_NULL); - - free_state (state); - gst_object_unref (bus); - gst_object_unref (pipeline); - - return 0; -} diff --git a/tests/examples/gio/.gitignore b/tests/examples/gio/.gitignore deleted file mode 100644 index 673c0788..00000000 --- a/tests/examples/gio/.gitignore +++ /dev/null @@ -1 +0,0 @@ -giosrc-mounting diff --git a/tests/examples/gio/Makefile.am b/tests/examples/gio/Makefile.am deleted file mode 100644 index 278edb71..00000000 --- a/tests/examples/gio/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -if HAVE_GTK -if USE_GIO -noinst_PROGRAMS = giosrc-mounting -giosrc_mounting_SOURCES = giosrc-mounting.c -giosrc_mounting_CFLAGS = $(GTK_CFLAGS) $(GIO_CFLAGS) $(GST_CFLAGS) -giosrc_mounting_LDFLAGS = $(GTK_LIBS) $(GIO_LIBS) $(GST_LIBS) -endif -endif diff --git a/tests/examples/gio/giosrc-mounting.c b/tests/examples/gio/giosrc-mounting.c deleted file mode 100644 index b6d4731a..00000000 --- a/tests/examples/gio/giosrc-mounting.c +++ /dev/null @@ -1,126 +0,0 @@ -/* GStreamer - * - * Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk> - * - * 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 <gst/gst.h> -#include <gtk/gtk.h> - -#include <string.h> - -static GstElement *pipeline = NULL; - -static void -mount_cb (GObject * obj, GAsyncResult * res, gpointer user_data) -{ - gboolean ret; - GError *err = NULL; - - ret = g_file_mount_enclosing_volume_finish (G_FILE (obj), res, &err); - - if (ret) { - g_print ("mounted successfully\n"); - gst_bus_set_flushing ((GstBus *) user_data, FALSE); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - } else { - g_print ("mounting failed: %s\n", err->message); - g_clear_error (&err); - gtk_main_quit (); - } -} - -gboolean -message_handler (GstBus * bus, GstMessage * message, gpointer user_data) -{ - - switch (message->type) { - case GST_MESSAGE_ELEMENT:{ - const GstStructure *s = gst_message_get_structure (message); - const gchar *name = gst_structure_get_name (s); - - if (strcmp (name, "not-mounted") == 0) { - GMountOperation *mop = gtk_mount_operation_new (NULL); - GFile *file = - G_FILE (g_value_get_object (gst_structure_get_value - (message->structure, "file"))); - - g_print ("not-mounted\n"); - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_bus_set_flushing (bus, TRUE); - - g_file_mount_enclosing_volume (file, G_MOUNT_MOUNT_NONE, - mop, NULL, mount_cb, bus); - - g_object_unref (mop); - } - break; - } - - case GST_MESSAGE_EOS: - g_print ("EOS\n"); - gtk_main_quit (); - break; - case GST_MESSAGE_ERROR:{ - GError *err = NULL; - - gst_message_parse_error (message, &err, NULL); - g_print ("error: %s\n", err->message); - g_clear_error (&err); - - gtk_main_quit (); - break; - } - default: - break; - } - - return TRUE; -} - -int -main (int argc, char *argv[]) -{ - GstBus *bus; - gint watch_id; - - if (argc != 2) { - g_print ("usage: giosrc-mounting URI\n"); - return -1; - } - - gst_init (NULL, NULL); - gtk_init (NULL, NULL); - - pipeline = gst_element_factory_make ("playbin2", NULL); - g_assert (pipeline); - g_object_set (G_OBJECT (pipeline), "uri", argv[1], NULL); - - bus = gst_element_get_bus (pipeline); - watch_id = gst_bus_add_watch (bus, message_handler, NULL); - gst_object_unref (bus); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - gtk_main (); - - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - - return 0; -} diff --git a/tests/examples/overlay/.gitignore b/tests/examples/overlay/.gitignore deleted file mode 100644 index c8795e7f..00000000 --- a/tests/examples/overlay/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -gtk-xoverlay -qt-xoverlay -qtgv-xoverlay -moc_*.cpp - diff --git a/tests/examples/overlay/Makefile.am b/tests/examples/overlay/Makefile.am deleted file mode 100644 index 55085521..00000000 --- a/tests/examples/overlay/Makefile.am +++ /dev/null @@ -1,47 +0,0 @@ -EXAMPLES = - -if USE_X - -if HAVE_GTK_X11 -EXAMPLES += gtk-xoverlay - -gtk_xoverlay_SOURCES = gtk-xoverlay.c -gtk_xoverlay_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(X_CFLAGS) $(GTK_CFLAGS) -gtk_xoverlay_LDADD = $(GST_LIBS) $(X_LIBS) $(LIBM) $(GTK_LIBS) \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la -endif - -if HAVE_QT -EXAMPLES += qt-xoverlay - -qt_xoverlay_SOURCES = qt-xoverlay.cpp -qt_xoverlay_CXXFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CXXFLAGS) $(X_CFLAGS) $(QT_CFLAGS) -qt_xoverlay_LDADD = $(GST_LIBS) $(X_LIBS) $(LIBM) $(QT_LIBS) \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la - -endif - -if HAVE_QT_GV -EXAMPLES += qtgv-xoverlay - -qtgv_xoverlay_SOURCES = qtgv-xoverlay.cpp -qtgv_xoverlay_CXXFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CXXFLAGS) $(X_CFLAGS) $(QT_CFLAGS) -qtgv_xoverlay_LDADD = $(GST_LIBS) $(X_LIBS) $(LIBM) $(QT_LIBS) \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la - -# qt moc support, according to http://qtnode.net/wiki/Qt_with_autotools - -nodist_qtgv_xoverlay_SOURCES = moc_qtgv-xoverlay.cpp - -moc_%.cpp:%.h - moc $< -o $@ - -EXTRA_DIST = $(nodist_qtgv_xoverlay_SOURCES:moc_%.cpp=%.h) qtgv-xoverlay.h -CLEANFILES = $(nodist_qtgv_xoverlay_SOURCES) - -endif - -endif - -noinst_PROGRAMS = $(EXAMPLES) - diff --git a/tests/examples/overlay/gtk-xoverlay.c b/tests/examples/overlay/gtk-xoverlay.c deleted file mode 100644 index 9a08c95f..00000000 --- a/tests/examples/overlay/gtk-xoverlay.c +++ /dev/null @@ -1,147 +0,0 @@ -/* GStreamer - * Copyright (C) <2010> Stefan Kost <ensonic@users.sf.net> - * - * gtk-xoverlay: demonstrate overlay handling using gtk - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <glib.h> -#include <gdk/gdkx.h> -#include <gtk/gtk.h> - -#include <gst/gst.h> -#include <gst/interfaces/xoverlay.h> - -#include <string.h> - -static void -window_closed (GtkWidget * widget, GdkEvent * event, gpointer user_data) -{ - GstElement *pipeline = user_data; - - gtk_widget_hide_all (widget); - gst_element_set_state (pipeline, GST_STATE_NULL); - gtk_main_quit (); -} - -/* slightly convoluted way to find a working video sink that's not a bin, - * one could use autovideosink from gst-plugins-good instead - */ -static GstElement * -find_video_sink (void) -{ - GstStateChangeReturn sret; - GstElement *sink; - - if ((sink = gst_element_factory_make ("xvimagesink", NULL))) { - sret = gst_element_set_state (sink, GST_STATE_READY); - if (sret == GST_STATE_CHANGE_SUCCESS) - return sink; - - gst_element_set_state (sink, GST_STATE_NULL); - } - gst_object_unref (sink); - - if ((sink = gst_element_factory_make ("ximagesink", NULL))) { - sret = gst_element_set_state (sink, GST_STATE_READY); - if (sret == GST_STATE_CHANGE_SUCCESS) - return sink; - - gst_element_set_state (sink, GST_STATE_NULL); - } - gst_object_unref (sink); - - if (strcmp (DEFAULT_VIDEOSINK, "xvimagesink") == 0 || - strcmp (DEFAULT_VIDEOSINK, "ximagesink") == 0) - return NULL; - - if ((sink = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL))) { - if (GST_IS_BIN (sink)) { - gst_object_unref (sink); - return NULL; - } - - sret = gst_element_set_state (sink, GST_STATE_READY); - if (sret == GST_STATE_CHANGE_SUCCESS) - return sink; - - gst_element_set_state (sink, GST_STATE_NULL); - } - gst_object_unref (sink); - return NULL; -} - -int -main (int argc, char **argv) -{ - GtkWidget *window, *video_window; - GstElement *pipeline, *src, *sink; - gulong embed_xid; - GstStateChangeReturn sret; - - if (!g_thread_supported ()) - g_thread_init (NULL); - - gst_init (&argc, &argv); - gtk_init (&argc, &argv); - - /* prepare the pipeline */ - - pipeline = gst_pipeline_new ("xvoverlay"); - src = gst_element_factory_make ("videotestsrc", NULL); - sink = find_video_sink (); - - if (sink == NULL) - g_error ("Couldn't find a working video sink."); - - gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); - gst_element_link (src, sink); - - /* prepare the ui */ - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - g_signal_connect (G_OBJECT (window), "delete-event", - G_CALLBACK (window_closed), (gpointer) pipeline); - gtk_window_set_default_size (GTK_WINDOW (window), 320, 240); - gtk_window_set_title (GTK_WINDOW (window), "GstXOverlay Gtk+ demo"); - - video_window = gtk_drawing_area_new (); - gtk_widget_set_double_buffered (video_window, FALSE); - gtk_container_add (GTK_CONTAINER (window), video_window); - gtk_container_set_border_width (GTK_CONTAINER (window), 16); - - gtk_widget_show_all (window); - gtk_widget_realize (window); - - embed_xid = GDK_WINDOW_XID (video_window->window); - gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (sink), embed_xid); - - /* run the pipeline */ - - sret = gst_element_set_state (pipeline, GST_STATE_PLAYING); - if (sret == GST_STATE_CHANGE_FAILURE) - gst_element_set_state (pipeline, GST_STATE_NULL); - else - gtk_main (); - - gst_object_unref (pipeline); - return 0; -} diff --git a/tests/examples/overlay/qt-xoverlay.cpp b/tests/examples/overlay/qt-xoverlay.cpp deleted file mode 100644 index 7edfabb7..00000000 --- a/tests/examples/overlay/qt-xoverlay.cpp +++ /dev/null @@ -1,130 +0,0 @@ -/* GStreamer - * Copyright (C) <2010> Stefan Kost <ensonic@users.sf.net> - * - * qt-xoverlay: demonstrate overlay handling using qt - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <glib.h> -#include <gst/gst.h> -#include <gst/interfaces/xoverlay.h> - -#include <QApplication> -#include <QTimer> -#include <QWidget> - -/* slightly convoluted way to find a working video sink that's not a bin, - * one could use autovideosink from gst-plugins-good instead - */ -static GstElement * -find_video_sink (void) -{ - GstStateChangeReturn sret; - GstElement *sink; - - if ((sink = gst_element_factory_make ("xvimagesink", NULL))) { - sret = gst_element_set_state (sink, GST_STATE_READY); - if (sret == GST_STATE_CHANGE_SUCCESS) - return sink; - - gst_element_set_state (sink, GST_STATE_NULL); - } - gst_object_unref (sink); - - if ((sink = gst_element_factory_make ("ximagesink", NULL))) { - sret = gst_element_set_state (sink, GST_STATE_READY); - if (sret == GST_STATE_CHANGE_SUCCESS) - return sink; - - gst_element_set_state (sink, GST_STATE_NULL); - } - gst_object_unref (sink); - - if (strcmp (DEFAULT_VIDEOSINK, "xvimagesink") == 0 || - strcmp (DEFAULT_VIDEOSINK, "ximagesink") == 0) - return NULL; - - if ((sink = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL))) { - if (GST_IS_BIN (sink)) { - gst_object_unref (sink); - return NULL; - } - - sret = gst_element_set_state (sink, GST_STATE_READY); - if (sret == GST_STATE_CHANGE_SUCCESS) - return sink; - - gst_element_set_state (sink, GST_STATE_NULL); - } - gst_object_unref (sink); - return NULL; -} - -int main(int argc, char *argv[]) -{ - if (!g_thread_supported ()) - g_thread_init (NULL); - - gst_init (&argc, &argv); - QApplication app(argc, argv); - app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit ())); - - /* prepare the pipeline */ - - GstElement *pipeline = gst_pipeline_new ("xvoverlay"); - GstElement *src = gst_element_factory_make ("videotestsrc", NULL); - GstElement *sink = find_video_sink (); - - if (sink == NULL) - g_error ("Couldn't find a working video sink."); - - gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); - gst_element_link (src, sink); - - /* prepare the ui */ - - QWidget window; - window.resize(320, 240); - window.setWindowTitle("GstXOverlay Qt demo"); - window.show(); - - WId xwinid = window.winId(); - gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (sink), xwinid); - - /* run the pipeline */ - - GstStateChangeReturn sret = gst_element_set_state (pipeline, - GST_STATE_PLAYING); - if (sret == GST_STATE_CHANGE_FAILURE) { - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - /* Exit application */ - QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit())); - } - - int ret = app.exec(); - - window.hide(); - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - - return ret; -} diff --git a/tests/examples/overlay/qtgv-xoverlay.cpp b/tests/examples/overlay/qtgv-xoverlay.cpp deleted file mode 100644 index 69252864..00000000 --- a/tests/examples/overlay/qtgv-xoverlay.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* GStreamer - * Copyright (C) <2010> Alexander Bokovoy <ab@samba.org> - * - * qtgv-xoverlay: demonstrate overlay handling using qt graphics view - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "qtgv-xoverlay.h" - -#include <QApplication> -#include <QTimer> - -#include <gst/interfaces/xoverlay.h> - -SinkPipeline::SinkPipeline(QGraphicsView *parent) : QObject(parent) -{ - GstStateChangeReturn sret; - - pipeline = gst_pipeline_new ("xvoverlay"); - src = gst_element_factory_make ("videotestsrc", NULL); - - if ((sink = gst_element_factory_make ("xvimagesink", NULL))) { - sret = gst_element_set_state (sink, GST_STATE_READY); - if (sret != GST_STATE_CHANGE_SUCCESS) { - gst_element_set_state (sink, GST_STATE_NULL); - gst_object_unref (sink); - - if ((sink = gst_element_factory_make ("ximagesink", NULL))) { - sret = gst_element_set_state (sink, GST_STATE_READY); - if (sret != GST_STATE_CHANGE_SUCCESS) { - gst_element_set_state (sink, GST_STATE_NULL); - gst_object_unref (sink); - - if (strcmp (DEFAULT_VIDEOSINK, "xvimagesink") != 0 && - strcmp (DEFAULT_VIDEOSINK, "ximagesink") != 0) { - - if ((sink = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL))) { - if (!GST_IS_BIN (sink)) { - sret = gst_element_set_state (sink, GST_STATE_READY); - if (sret != GST_STATE_CHANGE_SUCCESS) { - gst_element_set_state (sink, GST_STATE_NULL); - gst_object_unref (sink); - sink = NULL; - } - } else { - gst_object_unref (sink); - sink = NULL; - } - } - } - } - } - } - } - - if (sink == NULL) - g_error ("Couldn't find a working video sink."); - - gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); - gst_element_link (src, sink); - xwinid = parent->winId(); -} - -SinkPipeline::~SinkPipeline() -{ - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); -} - -void SinkPipeline::startPipeline() -{ - GstStateChangeReturn sret; - - /* we know what the video sink is in this case (xvimagesink), so we can - * just set it directly here now (instead of waiting for a prepare-xwindow-id - * element message in a sync bus handler and setting it there) */ - - gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (sink), xwinid); - - sret = gst_element_set_state (pipeline, GST_STATE_PLAYING); - if (sret == GST_STATE_CHANGE_FAILURE) { - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - /* Exit application */ - QTimer::singleShot(0, QApplication::activeWindow(), SLOT(quit())); - } -} - -int main( int argc, char **argv ) -{ - QApplication app(argc, argv); - - QGraphicsScene scene; - scene.setSceneRect( -100.0, -100.0, 200.0, 200.0 ); - - QGraphicsView view( &scene ); - view.resize(320, 240); - view.setWindowTitle("GstXOverlay Qt GraphicsView demo"); - view.show(); - - gst_init (&argc, &argv); - SinkPipeline pipeline(&view); - pipeline.startPipeline(); - - int ret = app.exec(); - - view.hide(); - - return ret; -} diff --git a/tests/examples/overlay/qtgv-xoverlay.h b/tests/examples/overlay/qtgv-xoverlay.h deleted file mode 100644 index 091fff8b..00000000 --- a/tests/examples/overlay/qtgv-xoverlay.h +++ /dev/null @@ -1,45 +0,0 @@ -/* GStreamer - * Copyright (C) <2010> Alexander Bokovoy <ab@samba.org> - * - * qtgv-xoverlay: demonstrate overlay handling using qt graphics view - * - * 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. - */ - -#ifndef QTGV_XOVERLAY_H -#define QTGV_XOVERLAY_H - -#include <QGraphicsView> -#include <gst/gst.h> - - -class SinkPipeline : public QObject -{ - Q_OBJECT -public: - SinkPipeline(QGraphicsView *parent = 0); - ~SinkPipeline(); - - void startPipeline(); - -private: - GstElement *pipeline; - GstElement *sink; - GstElement *src; - WId xwinid; -}; - -#endif // QTGV_XOVERLAY_H diff --git a/tests/examples/seek/.gitignore b/tests/examples/seek/.gitignore deleted file mode 100644 index e64781b2..00000000 --- a/tests/examples/seek/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -scrubby -seek -stepping -stepping2 diff --git a/tests/examples/seek/Makefile.am b/tests/examples/seek/Makefile.am deleted file mode 100644 index 792f96c1..00000000 --- a/tests/examples/seek/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -if HAVE_GTK_X11 -GTK_EXAMPLES=seek scrubby -endif - -examples = $(GTK_EXAMPLES) stepping stepping2 - -noinst_PROGRAMS = $(examples) - -LDADD = \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la \ - $(GST_LIBS) $(GTK_LIBS) $(LIBM) - -AM_CFLAGS = $(GST_CFLAGS) $(GST_BASE_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GTK_CFLAGS) -I$(top_builddir)/gst-libs diff --git a/tests/examples/seek/scrubby.c b/tests/examples/seek/scrubby.c deleted file mode 100644 index 7517ec2a..00000000 --- a/tests/examples/seek/scrubby.c +++ /dev/null @@ -1,570 +0,0 @@ -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <gst/gst.h> -#include <string.h> - -GST_DEBUG_CATEGORY_STATIC (scrubby_debug); -#define GST_CAT_DEFAULT (scrubby_debug) - -static GstElement *pipeline; -static gint64 position; -static gint64 duration; -static GtkAdjustment *adjustment; -static GtkWidget *hscale; -static GtkAdjustment *sadjustment; -static GtkWidget *shscale; -static gboolean verbose = FALSE; - -static guint bus_watch = 0; -static guint update_id = 0; -static guint changed_id = 0; -static guint schanged_id = 0; - -//#define SOURCE "filesrc" -#define SOURCE "gnomevfssrc" -#define ASINK "alsasink" -//#define ASINK "osssink" -#define VSINK "xvimagesink" -//#define VSINK "ximagesink" -//#define VSINK "aasink" -//#define VSINK "cacasink" - -#define RANGE_PREC 10000 -#define SEGMENT_LEN 100 -#define UPDATE_INTERVAL 500 - -static gdouble prev_range = -1.0; -static GstClockTime prev_time = GST_CLOCK_TIME_NONE; -static gdouble cur_range; -static GstClockTime cur_time; -static GstClockTimeDiff diff; -static gdouble cur_speed = 1.0; - -typedef struct -{ - const gchar *padname; - GstPad *target; - GstElement *bin; -} -dyn_link; - -static GstElement * -gst_element_factory_make_or_warn (gchar * type, gchar * name) -{ - GstElement *element = gst_element_factory_make (type, name); - - if (!element) { - g_warning ("Failed to create element %s of type %s", name, type); - } - - return element; -} - -static void -dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data) -{ - dyn_link *connect = (dyn_link *) data; - - if (connect->padname == NULL || - !strcmp (gst_pad_get_name (newpad), connect->padname)) { - if (connect->bin) - gst_bin_add (GST_BIN (pipeline), connect->bin); - gst_pad_link (newpad, connect->target); - } -} - -static void -setup_dynamic_link (GstElement * element, const gchar * padname, - GstPad * target, GstElement * bin) -{ - dyn_link *connect; - - connect = g_new0 (dyn_link, 1); - connect->padname = g_strdup (padname); - connect->target = target; - connect->bin = bin; - - g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link), - connect); -} - -static GstElement * -make_wav_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *decoder, *audiosink; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - decoder = gst_element_factory_make_or_warn ("wavparse", "decoder"); - audiosink = gst_element_factory_make_or_warn (ASINK, "sink"); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link (src, decoder); - - setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink, - "sink"), NULL); - - return pipeline; -} - -static GstElement * -make_playerbin_pipeline (const gchar * location) -{ - GstElement *player; - - player = gst_element_factory_make ("playbin", "player"); - g_assert (player); - - g_object_set (G_OBJECT (player), "uri", location, NULL); - - return player; -} - -static gchar * -format_value (GtkScale * scale, gdouble value) -{ - gint64 real; - gint64 seconds; - gint64 subseconds; - - real = value * duration / RANGE_PREC; - seconds = (gint64) real / GST_SECOND; - subseconds = (gint64) real / (GST_SECOND / RANGE_PREC); - - return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02" - G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100); -} - -static gboolean -update_scale (gpointer data) -{ - GstFormat format; - - position = 0; - duration = 0; - - format = GST_FORMAT_TIME; - - gst_element_query_position (pipeline, &format, &position); - gst_element_query_duration (pipeline, &format, &duration); - - if (position >= duration) - duration = position; - - if (duration > 0) { - gtk_adjustment_set_value (adjustment, - position * (gdouble) RANGE_PREC / duration); - gtk_widget_queue_draw (hscale); - } - - return TRUE; -} - -static void -speed_cb (GtkWidget * widget) -{ - GstEvent *s_event; - gboolean res; - - GST_DEBUG ("speed change"); - cur_speed = gtk_range_get_value (GTK_RANGE (widget)); - - if (cur_speed == 0.0) - return; - - s_event = gst_event_new_seek (cur_speed, - GST_FORMAT_TIME, 0, GST_SEEK_TYPE_NONE, -1, GST_SEEK_TYPE_NONE, -1); - - res = gst_element_send_event (pipeline, s_event); - if (!res) - g_print ("speed change failed\n"); -} - -static gboolean do_seek (GtkWidget * widget, gboolean flush, gboolean segment); - -static void -seek_cb (GtkWidget * widget) -{ - if (changed_id) { - GST_DEBUG ("seek because of slider move"); - - if (do_seek (widget, TRUE, TRUE)) { - g_source_remove (changed_id); - changed_id = 0; - } - } -} - -static gboolean -do_seek (GtkWidget * widget, gboolean flush, gboolean segment) -{ - gint64 start, stop; - gboolean res = FALSE; - GstEvent *s_event; - gdouble rate; - GTimeVal tv; - gboolean valid; - gdouble new_range; - - if (segment) - new_range = gtk_range_get_value (GTK_RANGE (widget)); - else { - new_range = (gdouble) RANGE_PREC; - cur_time = -1; - } - - valid = prev_time != -1; - - GST_DEBUG ("flush %d, segment %d, valid %d", flush, segment, valid); - - if (new_range == cur_range) - return FALSE; - - prev_time = cur_time; - prev_range = cur_range; - - cur_range = new_range; - - g_get_current_time (&tv); - cur_time = GST_TIMEVAL_TO_TIME (tv); - - if (!valid) - return FALSE; - - GST_DEBUG ("cur: %lf, %" GST_TIME_FORMAT, cur_range, - GST_TIME_ARGS (cur_time)); - GST_DEBUG ("prev: %lf, %" GST_TIME_FORMAT, prev_range, - GST_TIME_ARGS (prev_time)); - - diff = cur_time - prev_time; - - GST_DEBUG ("diff: %" GST_TIME_FORMAT, GST_TIME_ARGS (diff)); - - start = prev_range * duration / RANGE_PREC; - /* play 50 milliseconds */ - stop = segment ? cur_range * duration / RANGE_PREC : duration; - - if (start == stop) - return FALSE; - - if (segment) - rate = (stop - start) / (gdouble) diff; - else - rate = cur_speed; - - if (start > stop) { - gint64 tmp; - - tmp = start; - start = stop; - stop = tmp; - } - - if (rate == 0.0) - return TRUE; - - GST_DEBUG ("seek to %" GST_TIME_FORMAT " -- %" GST_TIME_FORMAT ", rate %lf" - " on element %s", - GST_TIME_ARGS (start), GST_TIME_ARGS (stop), rate, - GST_ELEMENT_NAME (pipeline)); - - s_event = gst_event_new_seek (rate, - GST_FORMAT_TIME, - (flush ? GST_SEEK_FLAG_FLUSH : 0) | - (segment ? GST_SEEK_FLAG_SEGMENT : 0), - GST_SEEK_TYPE_SET, start, GST_SEEK_TYPE_SET, stop); - - res = gst_element_send_event (pipeline, s_event); - if (!res) - g_print ("seek failed\n"); - - gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE); - - return TRUE; -} - -static gboolean -start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) -{ - if (update_id) { - g_source_remove (update_id); - update_id = 0; - } - - if (changed_id == 0) { - changed_id = - g_signal_connect (hscale, "value_changed", G_CALLBACK (seek_cb), - pipeline); - } - - GST_DEBUG ("start seek"); - - return FALSE; -} - -static gboolean -stop_seek (GtkWidget * widget, gpointer user_data) -{ - update_id = - g_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); - - GST_DEBUG ("stop seek"); - - if (changed_id) { - g_source_remove (changed_id); - changed_id = 0; - } - - do_seek (hscale, FALSE, FALSE); - - return FALSE; -} - -static void -play_cb (GtkButton * button, gpointer data) -{ - GstState state; - - gst_element_get_state (pipeline, &state, NULL, GST_CLOCK_TIME_NONE); - if (state != GST_STATE_PLAYING) { - g_print ("PLAY pipeline\n"); - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE); - gst_element_set_state (pipeline, GST_STATE_PLAYING); - update_id = - g_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); - } -} - -static void -pause_cb (GtkButton * button, gpointer data) -{ - GstState state; - - gst_element_get_state (pipeline, &state, NULL, GST_CLOCK_TIME_NONE); - if (state != GST_STATE_PAUSED) { - g_print ("PAUSE pipeline\n"); - gst_element_set_state (pipeline, GST_STATE_PAUSED); - g_source_remove (update_id); - } -} - -static void -stop_cb (GtkButton * button, gpointer data) -{ - GstState state; - - gst_element_get_state (pipeline, &state, NULL, GST_CLOCK_TIME_NONE); - if (state != GST_STATE_READY) { - g_print ("READY pipeline\n"); - gst_element_set_state (pipeline, GST_STATE_READY); - /* position and speed return to their default values */ - gtk_adjustment_set_value (adjustment, 0.0); - gtk_adjustment_set_value (sadjustment, 1.0); - g_source_remove (update_id); - } -} - -static void -print_message (GstMessage * message) -{ - const GstStructure *s; - - s = gst_message_get_structure (message); - g_print ("Got Message from element \"%s\"\n", - GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message)))); - - if (s) { - gchar *sstr; - - sstr = gst_structure_to_string (s); - g_print ("%s\n", sstr); - g_free (sstr); - } -} - -static gboolean -bus_message (GstBus * bus, GstMessage * message, gpointer data) -{ - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_EOS: - g_print ("EOS\n"); - break; - case GST_MESSAGE_ERROR: - case GST_MESSAGE_WARNING: - print_message (message); - break; - case GST_MESSAGE_SEGMENT_START: - break; - case GST_MESSAGE_SEGMENT_DONE: - GST_DEBUG ("segment_done, doing next seek"); - if (!do_seek (hscale, FALSE, update_id == 0)) { - if (changed_id == 0) { - changed_id = - g_signal_connect (hscale, "value_changed", G_CALLBACK (seek_cb), - pipeline); - } - } - break; - default: - break; - } - - return TRUE; -} - -typedef struct -{ - gchar *name; - GstElement *(*func) (const gchar * location); -} -Pipeline; - -static Pipeline pipelines[] = { - {"wav", make_wav_pipeline}, - {"playerbin", make_playerbin_pipeline}, - {NULL, NULL}, -}; - -#define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1) - -static void -print_usage (int argc, char **argv) -{ - gint i; - - g_print ("usage: %s <type> <filename>\n", argv[0]); - g_print (" possible types:\n"); - - for (i = 0; i < NUM_TYPES; i++) { - g_print (" %d = %s\n", i, pipelines[i].name); - } -} - -int -main (int argc, char **argv) -{ - GtkWidget *window, *hbox, *vbox, *play_button, *pause_button, *stop_button; - GstBus *bus; - GOptionEntry options[] = { - {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, - "Verbose properties", NULL}, - {NULL} - }; - gint type; - GOptionContext *ctx; - GError *err = NULL; - - if (!g_thread_supported ()) - g_thread_init (NULL); - - ctx = g_option_context_new ("seek"); - g_option_context_add_main_entries (ctx, options, NULL); - g_option_context_add_group (ctx, gst_init_get_option_group ()); - - if (!g_option_context_parse (ctx, &argc, &argv, &err)) { - g_print ("Error initializing: %s\n", err->message); - exit (1); - } - - GST_DEBUG_CATEGORY_INIT (scrubby_debug, "scrubby", 0, "scrubby example"); - - gtk_init (&argc, &argv); - - if (argc != 3) { - print_usage (argc, argv); - exit (-1); - } - - type = atoi (argv[1]); - - if (type < 0 || type >= NUM_TYPES) { - print_usage (argc, argv); - exit (-1); - } - - pipeline = pipelines[type].func (argv[2]); - g_assert (pipeline); - - /* initialize gui elements ... */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - hbox = gtk_hbox_new (FALSE, 0); - vbox = gtk_vbox_new (FALSE, 0); - play_button = gtk_button_new_with_label ("play"); - pause_button = gtk_button_new_with_label ("pause"); - stop_button = gtk_button_new_with_label ("stop"); - - adjustment = - GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.0, (gdouble) RANGE_PREC, 0.1, - 1.0, 1.0)); - hscale = gtk_hscale_new (adjustment); - gtk_scale_set_digits (GTK_SCALE (hscale), 2); - gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS); - - sadjustment = - GTK_ADJUSTMENT (gtk_adjustment_new (1.0, 0.0, 5.0, 0.1, 1.0, 0.0)); - shscale = gtk_hscale_new (sadjustment); - gtk_scale_set_digits (GTK_SCALE (shscale), 2); - gtk_range_set_update_policy (GTK_RANGE (shscale), GTK_UPDATE_CONTINUOUS); - - schanged_id = - g_signal_connect (shscale, "value_changed", G_CALLBACK (speed_cb), - pipeline); - - g_signal_connect (hscale, "button_press_event", G_CALLBACK (start_seek), - pipeline); - g_signal_connect (hscale, "button_release_event", G_CALLBACK (stop_seek), - pipeline); - g_signal_connect (hscale, "format_value", G_CALLBACK (format_value), - pipeline); - - /* do the packing stuff ... */ - gtk_window_set_default_size (GTK_WINDOW (window), 96, 96); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_add (GTK_CONTAINER (vbox), hbox); - gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (vbox), shscale, TRUE, TRUE, 2); - - /* connect things ... */ - g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), - pipeline); - g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), - pipeline); - g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), - pipeline); - g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL); - - /* show the gui. */ - gtk_widget_show_all (window); - - if (verbose) { - g_signal_connect (pipeline, "deep_notify", - G_CALLBACK (gst_object_default_deep_notify), NULL); - } - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - g_assert (bus); - - bus_watch = gst_bus_add_watch_full (bus, - G_PRIORITY_HIGH, bus_message, pipeline, NULL); - - gtk_main (); - - g_print ("NULL pipeline\n"); - gst_element_set_state (pipeline, GST_STATE_NULL); - - g_print ("free pipeline\n"); - gst_object_unref (pipeline); - - return 0; -} diff --git a/tests/examples/seek/seek.c b/tests/examples/seek/seek.c deleted file mode 100644 index 405e00ed..00000000 --- a/tests/examples/seek/seek.c +++ /dev/null @@ -1,2945 +0,0 @@ -/* GStreamer - * - * seek.c: seeking sample application - * - * Copyright (C) 2005 Wim Taymans <wim@fluendo.com> - * 2006 Stefan Kost <ensonic@users.sf.net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdlib.h> -#include <math.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <gst/gst.h> -#include <string.h> - -#ifdef HAVE_X -#include <gdk/gdkx.h> -#endif -#include <gst/interfaces/xoverlay.h> - -GST_DEBUG_CATEGORY_STATIC (seek_debug); -#define GST_CAT_DEFAULT (seek_debug) - -/* configuration */ - -//#define SOURCE "filesrc" -#define SOURCE "gnomevfssrc" - -#define ASINK "alsasink" -//#define ASINK "osssink" - -#define VSINK "xvimagesink" -//#define VSINK "sdlvideosink" -//#define VSINK "ximagesink" -//#define VSINK "aasink" -//#define VSINK "cacasink" - -#define FILL_INTERVAL 100 -//#define UPDATE_INTERVAL 500 -//#define UPDATE_INTERVAL 100 -#define UPDATE_INTERVAL 40 - -/* number of milliseconds to play for after a seek */ -#define SCRUB_TIME 100 - -/* timeout for gst_element_get_state() after a seek */ -#define SEEK_TIMEOUT 40 * GST_MSECOND - -#define DEFAULT_VIDEO_HEIGHT 300 - -/* the state to go to when stop is pressed */ -#define STOP_STATE GST_STATE_READY - - -static GList *seekable_pads = NULL; -static GList *rate_pads = NULL; -static GList *seekable_elements = NULL; - -static gboolean accurate_seek = FALSE; -static gboolean keyframe_seek = FALSE; -static gboolean loop_seek = FALSE; -static gboolean flush_seek = TRUE; -static gboolean scrub = TRUE; -static gboolean play_scrub = FALSE; -static gboolean skip_seek = FALSE; -static gdouble rate = 1.0; - -static GstElement *pipeline; -static gint pipeline_type; -static const gchar *pipeline_spec; -static gint64 position = -1; -static gint64 duration = -1; -static GtkAdjustment *adjustment; -static GtkWidget *hscale, *statusbar; -static guint status_id = 0; -static gboolean stats = FALSE; -static gboolean elem_seek = FALSE; -static gboolean verbose = FALSE; - -static gboolean is_live = FALSE; -static gboolean buffering = FALSE; -static GstBufferingMode mode; -static gint64 buffering_left; -static GstState state = GST_STATE_NULL; -static guint update_id = 0; -static guint seek_timeout_id = 0; -static gulong changed_id; -static guint fill_id = 0; - -static gint n_video = 0, n_audio = 0, n_text = 0; -static gboolean need_streams = TRUE; -static GtkWidget *video_combo, *audio_combo, *text_combo, *vis_combo; -static GtkWidget *vis_checkbox, *video_checkbox, *audio_checkbox; -static GtkWidget *text_checkbox, *mute_checkbox, *volume_spinbutton; -static GtkWidget *skip_checkbox, *video_window, *download_checkbox; -static GtkWidget *buffer_checkbox, *rate_spinbutton; - -static GStaticMutex state_mutex = G_STATIC_MUTEX_INIT; - -static GtkWidget *format_combo, *step_amount_spinbutton, *step_rate_spinbutton; -static GtkWidget *shuttle_checkbox, *step_button; -static GtkWidget *shuttle_hscale; -static GtkAdjustment *shuttle_adjustment; - -static GList *paths = NULL, *l = NULL; - -/* we keep an array of the visualisation entries so that we can easily switch - * with the combo box index. */ -typedef struct -{ - GstElementFactory *factory; -} VisEntry; - -static GArray *vis_entries; - -static void clear_streams (GstElement * pipeline); -static void volume_notify_cb (GstElement * pipeline, GParamSpec * arg, - gpointer user_dat); - -/* pipeline construction */ - -typedef struct -{ - const gchar *padname; - GstPad *target; - GstElement *bin; -} -dyn_link; - -static GstElement * -gst_element_factory_make_or_warn (gchar * type, gchar * name) -{ - GstElement *element = gst_element_factory_make (type, name); - - if (!element) { - g_warning ("Failed to create element %s of type %s", name, type); - } - - return element; -} - -static void -dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data) -{ - gchar *padname; - dyn_link *connect = (dyn_link *) data; - - padname = gst_pad_get_name (newpad); - - if (connect->padname == NULL || !strcmp (padname, connect->padname)) { - if (connect->bin) - gst_bin_add (GST_BIN (pipeline), connect->bin); - gst_pad_link (newpad, connect->target); - - //seekable_pads = g_list_prepend (seekable_pads, newpad); - rate_pads = g_list_prepend (rate_pads, newpad); - } - g_free (padname); -} - -static void -setup_dynamic_link (GstElement * element, const gchar * padname, - GstPad * target, GstElement * bin) -{ - dyn_link *connect; - - connect = g_new0 (dyn_link, 1); - connect->padname = g_strdup (padname); - connect->target = target; - connect->bin = bin; - - g_signal_connect (G_OBJECT (element), "pad-added", G_CALLBACK (dynamic_link), - connect); -} - -static GstElement * -make_mod_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *decoder, *audiosink; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - decoder = gst_element_factory_make_or_warn ("modplug", "decoder"); - audiosink = gst_element_factory_make_or_warn (ASINK, "sink"); - //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link (src, decoder); - gst_element_link (decoder, audiosink); - - seekable = gst_element_get_static_pad (decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_dv_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *demux, *decoder, *audiosink, *videosink; - GstElement *a_queue, *v_queue; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - demux = gst_element_factory_make_or_warn ("dvdemux", "demuxer"); - v_queue = gst_element_factory_make_or_warn ("queue", "v_queue"); - decoder = gst_element_factory_make_or_warn ("ffdec_dvvideo", "decoder"); - videosink = gst_element_factory_make_or_warn (VSINK, "v_sink"); - a_queue = gst_element_factory_make_or_warn ("queue", "a_queue"); - audiosink = gst_element_factory_make_or_warn ("alsasink", "a_sink"); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - gst_bin_add (GST_BIN (pipeline), a_queue); - gst_bin_add (GST_BIN (pipeline), audiosink); - gst_bin_add (GST_BIN (pipeline), v_queue); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), videosink); - - gst_element_link (src, demux); - gst_element_link (a_queue, audiosink); - gst_element_link (v_queue, decoder); - gst_element_link (decoder, videosink); - - setup_dynamic_link (demux, "video", gst_element_get_static_pad (v_queue, - "sink"), NULL); - setup_dynamic_link (demux, "audio", gst_element_get_static_pad (a_queue, - "sink"), NULL); - - seekable = gst_element_get_static_pad (decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - - return pipeline; -} - -static GstElement * -make_wav_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *decoder, *audiosink; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - decoder = gst_element_factory_make_or_warn ("wavparse", "decoder"); - audiosink = gst_element_factory_make_or_warn (ASINK, "sink"); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link (src, decoder); - - setup_dynamic_link (decoder, "src", gst_element_get_static_pad (audiosink, - "sink"), NULL); - - seekable_elements = g_list_prepend (seekable_elements, audiosink); - - /* force element seeking on this pipeline */ - elem_seek = TRUE; - - return pipeline; -} - -static GstElement * -make_flac_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *decoder, *audiosink; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - decoder = gst_element_factory_make_or_warn ("flacdec", "decoder"); - audiosink = gst_element_factory_make_or_warn (ASINK, "sink"); - g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link (src, decoder); - gst_element_link (decoder, audiosink); - - seekable = gst_element_get_static_pad (decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_sid_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *decoder, *audiosink; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - decoder = gst_element_factory_make_or_warn ("siddec", "decoder"); - audiosink = gst_element_factory_make_or_warn (ASINK, "sink"); - //g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link (src, decoder); - gst_element_link (decoder, audiosink); - - seekable = gst_element_get_static_pad (decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_parse_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *parser, *fakesink; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - parser = gst_element_factory_make_or_warn ("mpegparse", "parse"); - fakesink = gst_element_factory_make_or_warn ("fakesink", "sink"); - g_object_set (G_OBJECT (fakesink), "silent", TRUE, NULL); - g_object_set (G_OBJECT (fakesink), "sync", TRUE, NULL); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), parser); - gst_bin_add (GST_BIN (pipeline), fakesink); - - gst_element_link (src, parser); - gst_element_link (parser, fakesink); - - seekable = gst_element_get_static_pad (parser, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (parser, "sink")); - - return pipeline; -} - -static GstElement * -make_vorbis_pipeline (const gchar * location) -{ - GstElement *pipeline, *audio_bin; - GstElement *src, *demux, *decoder, *convert, *audiosink; - GstPad *pad, *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - demux = gst_element_factory_make_or_warn ("oggdemux", "demux"); - decoder = gst_element_factory_make_or_warn ("vorbisdec", "decoder"); - convert = gst_element_factory_make_or_warn ("audioconvert", "convert"); - audiosink = gst_element_factory_make_or_warn (ASINK, "sink"); - g_object_set (G_OBJECT (audiosink), "sync", TRUE, NULL); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - audio_bin = gst_bin_new ("a_decoder_bin"); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - gst_bin_add (GST_BIN (audio_bin), decoder); - gst_bin_add (GST_BIN (audio_bin), convert); - gst_bin_add (GST_BIN (audio_bin), audiosink); - gst_bin_add (GST_BIN (pipeline), audio_bin); - - gst_element_link (src, demux); - gst_element_link (decoder, convert); - gst_element_link (convert, audiosink); - - pad = gst_element_get_static_pad (decoder, "sink"); - gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad)); - gst_object_unref (pad); - - setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin, - "sink"), NULL); - - seekable = gst_element_get_static_pad (decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_theora_pipeline (const gchar * location) -{ - GstElement *pipeline, *video_bin; - GstElement *src, *demux, *decoder, *convert, *videosink; - GstPad *pad, *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - demux = gst_element_factory_make_or_warn ("oggdemux", "demux"); - decoder = gst_element_factory_make_or_warn ("theoradec", "decoder"); - convert = gst_element_factory_make_or_warn ("ffmpegcolorspace", "convert"); - videosink = gst_element_factory_make_or_warn (VSINK, "sink"); - - g_object_set (G_OBJECT (src), "location", location, NULL); - - video_bin = gst_bin_new ("v_decoder_bin"); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - gst_bin_add (GST_BIN (video_bin), decoder); - gst_bin_add (GST_BIN (video_bin), convert); - gst_bin_add (GST_BIN (video_bin), videosink); - gst_bin_add (GST_BIN (pipeline), video_bin); - - gst_element_link (src, demux); - gst_element_link (decoder, convert); - gst_element_link (convert, videosink); - - pad = gst_element_get_static_pad (decoder, "sink"); - gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad)); - gst_object_unref (pad); - - setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin, - "sink"), NULL); - - seekable = gst_element_get_static_pad (decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_vorbis_theora_pipeline (const gchar * location) -{ - GstElement *pipeline, *audio_bin, *video_bin; - GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert; - GstElement *audiosink, *videosink; - GstElement *a_queue, *v_queue, *v_scale; - GstPad *seekable; - GstPad *pad; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - g_object_set (G_OBJECT (src), "location", location, NULL); - - demux = gst_element_factory_make_or_warn ("oggdemux", "demux"); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - gst_element_link (src, demux); - - audio_bin = gst_bin_new ("a_decoder_bin"); - a_queue = gst_element_factory_make_or_warn ("queue", "a_queue"); - a_decoder = gst_element_factory_make_or_warn ("vorbisdec", "a_dec"); - a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert"); - audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink"); - - gst_bin_add (GST_BIN (pipeline), audio_bin); - - gst_bin_add (GST_BIN (audio_bin), a_queue); - gst_bin_add (GST_BIN (audio_bin), a_decoder); - gst_bin_add (GST_BIN (audio_bin), a_convert); - gst_bin_add (GST_BIN (audio_bin), audiosink); - - gst_element_link (a_queue, a_decoder); - gst_element_link (a_decoder, a_convert); - gst_element_link (a_convert, audiosink); - - pad = gst_element_get_static_pad (a_queue, "sink"); - gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad)); - gst_object_unref (pad); - - setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin, - "sink"), NULL); - - video_bin = gst_bin_new ("v_decoder_bin"); - v_queue = gst_element_factory_make_or_warn ("queue", "v_queue"); - v_decoder = gst_element_factory_make_or_warn ("theoradec", "v_dec"); - v_convert = - gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert"); - v_scale = gst_element_factory_make_or_warn ("videoscale", "v_scale"); - videosink = gst_element_factory_make_or_warn (VSINK, "v_sink"); - - gst_bin_add (GST_BIN (pipeline), video_bin); - - gst_bin_add (GST_BIN (video_bin), v_queue); - gst_bin_add (GST_BIN (video_bin), v_decoder); - gst_bin_add (GST_BIN (video_bin), v_convert); - gst_bin_add (GST_BIN (video_bin), v_scale); - gst_bin_add (GST_BIN (video_bin), videosink); - - gst_element_link_many (v_queue, v_decoder, v_convert, v_scale, videosink, - NULL); - - pad = gst_element_get_static_pad (v_queue, "sink"); - gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad)); - gst_object_unref (pad); - - setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin, - "sink"), NULL); - - seekable = gst_element_get_static_pad (a_decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder, - "sink")); - - return pipeline; -} - -static GstElement * -make_avi_msmpeg4v3_mp3_pipeline (const gchar * location) -{ - GstElement *pipeline, *audio_bin, *video_bin; - GstElement *src, *demux, *a_decoder, *a_convert, *v_decoder, *v_convert; - GstElement *audiosink, *videosink; - GstElement *a_queue, *v_queue; - GstPad *seekable, *pad; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - g_object_set (G_OBJECT (src), "location", location, NULL); - - demux = gst_element_factory_make_or_warn ("avidemux", "demux"); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - gst_element_link (src, demux); - - audio_bin = gst_bin_new ("a_decoder_bin"); - a_queue = gst_element_factory_make_or_warn ("queue", "a_queue"); - a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec"); - a_convert = gst_element_factory_make_or_warn ("audioconvert", "a_convert"); - audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink"); - - gst_bin_add (GST_BIN (audio_bin), a_queue); - gst_bin_add (GST_BIN (audio_bin), a_decoder); - gst_bin_add (GST_BIN (audio_bin), a_convert); - gst_bin_add (GST_BIN (audio_bin), audiosink); - - gst_element_link (a_queue, a_decoder); - gst_element_link (a_decoder, a_convert); - gst_element_link (a_convert, audiosink); - - gst_bin_add (GST_BIN (pipeline), audio_bin); - - pad = gst_element_get_static_pad (a_queue, "sink"); - gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad)); - gst_object_unref (pad); - - setup_dynamic_link (demux, NULL, gst_element_get_static_pad (audio_bin, - "sink"), NULL); - - video_bin = gst_bin_new ("v_decoder_bin"); - v_queue = gst_element_factory_make_or_warn ("queue", "v_queue"); - v_decoder = gst_element_factory_make_or_warn ("ffdec_msmpeg4", "v_dec"); - v_convert = - gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_convert"); - videosink = gst_element_factory_make_or_warn (VSINK, "v_sink"); - - gst_bin_add (GST_BIN (video_bin), v_queue); - gst_bin_add (GST_BIN (video_bin), v_decoder); - gst_bin_add (GST_BIN (video_bin), v_convert); - gst_bin_add (GST_BIN (video_bin), videosink); - - gst_element_link_many (v_queue, v_decoder, v_convert, videosink, NULL); - - gst_bin_add (GST_BIN (pipeline), video_bin); - - pad = gst_element_get_static_pad (v_queue, "sink"); - gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad)); - gst_object_unref (pad); - - setup_dynamic_link (demux, NULL, gst_element_get_static_pad (video_bin, - "sink"), NULL); - - seekable = gst_element_get_static_pad (a_decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder, - "sink")); - - return pipeline; -} - -static GstElement * -make_mp3_pipeline (const gchar * location) -{ - GstElement *pipeline; - GstElement *src, *parser, *decoder, *audiosink, *queue; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - parser = gst_element_factory_make_or_warn ("mp3parse", "parse"); - decoder = gst_element_factory_make_or_warn ("mad", "dec"); - queue = gst_element_factory_make_or_warn ("queue", "queue"); - audiosink = gst_element_factory_make_or_warn (ASINK, "sink"); - - seekable_elements = g_list_prepend (seekable_elements, audiosink); - - g_object_set (G_OBJECT (src), "location", location, NULL); - //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), parser); - gst_bin_add (GST_BIN (pipeline), decoder); - gst_bin_add (GST_BIN (pipeline), queue); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link (src, parser); - gst_element_link (parser, decoder); - gst_element_link (decoder, queue); - gst_element_link (queue, audiosink); - - seekable = gst_element_get_static_pad (queue, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (decoder, "sink")); - - return pipeline; -} - -static GstElement * -make_avi_pipeline (const gchar * location) -{ - GstElement *pipeline, *audio_bin, *video_bin; - GstElement *src, *demux, *a_decoder, *v_decoder, *audiosink, *videosink; - GstElement *a_queue = NULL, *v_queue = NULL; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - g_object_set (G_OBJECT (src), "location", location, NULL); - - demux = gst_element_factory_make_or_warn ("avidemux", "demux"); - seekable_elements = g_list_prepend (seekable_elements, demux); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - gst_element_link (src, demux); - - audio_bin = gst_bin_new ("a_decoder_bin"); - a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec"); - audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink"); - a_queue = gst_element_factory_make_or_warn ("queue", "a_queue"); - gst_element_link (a_decoder, a_queue); - gst_element_link (a_queue, audiosink); - gst_bin_add (GST_BIN (audio_bin), a_decoder); - gst_bin_add (GST_BIN (audio_bin), a_queue); - gst_bin_add (GST_BIN (audio_bin), audiosink); - gst_element_set_state (audio_bin, GST_STATE_PAUSED); - - setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder, - "sink"), audio_bin); - - seekable = gst_element_get_static_pad (a_queue, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder, - "sink")); - - video_bin = gst_bin_new ("v_decoder_bin"); - v_decoder = gst_element_factory_make_or_warn ("ffmpegdecall", "v_dec"); - videosink = gst_element_factory_make_or_warn (VSINK, "v_sink"); - v_queue = gst_element_factory_make_or_warn ("queue", "v_queue"); - gst_element_link (v_decoder, v_queue); - gst_element_link (v_queue, videosink); - gst_bin_add (GST_BIN (video_bin), v_decoder); - gst_bin_add (GST_BIN (video_bin), v_queue); - gst_bin_add (GST_BIN (video_bin), videosink); - - gst_element_set_state (video_bin, GST_STATE_PAUSED); - - setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder, - "sink"), video_bin); - - seekable = gst_element_get_static_pad (v_queue, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder, - "sink")); - - return pipeline; -} - -static GstElement * -make_mpeg_pipeline (const gchar * location) -{ - GstElement *pipeline, *audio_bin, *video_bin; - GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter; - GstElement *audiosink, *videosink; - GstElement *a_queue, *v_queue; - GstPad *seekable; - GstPad *pad; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - g_object_set (G_OBJECT (src), "location", location, NULL); - - //demux = gst_element_factory_make_or_warn ("mpegdemux", "demux"); - demux = gst_element_factory_make_or_warn ("flupsdemux", "demux"); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - gst_element_link (src, demux); - - audio_bin = gst_bin_new ("a_decoder_bin"); - a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec"); - a_queue = gst_element_factory_make_or_warn ("queue", "a_queue"); - audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink"); - gst_bin_add (GST_BIN (audio_bin), a_decoder); - gst_bin_add (GST_BIN (audio_bin), a_queue); - gst_bin_add (GST_BIN (audio_bin), audiosink); - - gst_element_link (a_decoder, a_queue); - gst_element_link (a_queue, audiosink); - - gst_bin_add (GST_BIN (pipeline), audio_bin); - - pad = gst_element_get_static_pad (a_decoder, "sink"); - gst_element_add_pad (audio_bin, gst_ghost_pad_new ("sink", pad)); - gst_object_unref (pad); - - setup_dynamic_link (demux, "audio_c0", gst_element_get_static_pad (audio_bin, - "sink"), NULL); - - video_bin = gst_bin_new ("v_decoder_bin"); - v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec"); - v_queue = gst_element_factory_make_or_warn ("queue", "v_queue"); - v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter"); - videosink = gst_element_factory_make_or_warn (VSINK, "v_sink"); - - gst_bin_add (GST_BIN (video_bin), v_decoder); - gst_bin_add (GST_BIN (video_bin), v_queue); - gst_bin_add (GST_BIN (video_bin), v_filter); - gst_bin_add (GST_BIN (video_bin), videosink); - - gst_element_link (v_decoder, v_queue); - gst_element_link (v_queue, v_filter); - gst_element_link (v_filter, videosink); - - gst_bin_add (GST_BIN (pipeline), video_bin); - - pad = gst_element_get_static_pad (v_decoder, "sink"); - gst_element_add_pad (video_bin, gst_ghost_pad_new ("sink", pad)); - gst_object_unref (pad); - - setup_dynamic_link (demux, "video_e0", gst_element_get_static_pad (video_bin, - "sink"), NULL); - - seekable = gst_element_get_static_pad (v_filter, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder, - "sink")); - - return pipeline; -} - -static GstElement * -make_mpegnt_pipeline (const gchar * location) -{ - GstElement *pipeline, *audio_bin, *video_bin; - GstElement *src, *demux, *a_decoder, *v_decoder, *v_filter; - GstElement *audiosink, *videosink; - GstElement *a_queue; - GstPad *seekable; - - pipeline = gst_pipeline_new ("app"); - - src = gst_element_factory_make_or_warn (SOURCE, "src"); - g_object_set (G_OBJECT (src), "location", location, NULL); - - demux = gst_element_factory_make_or_warn ("mpegdemux", "demux"); - //g_object_set (G_OBJECT (demux), "sync", TRUE, NULL); - - seekable_elements = g_list_prepend (seekable_elements, demux); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - gst_element_link (src, demux); - - audio_bin = gst_bin_new ("a_decoder_bin"); - a_decoder = gst_element_factory_make_or_warn ("mad", "a_dec"); - a_queue = gst_element_factory_make_or_warn ("queue", "a_queue"); - audiosink = gst_element_factory_make_or_warn (ASINK, "a_sink"); - //g_object_set (G_OBJECT (audiosink), "fragment", 0x00180008, NULL); - g_object_set (G_OBJECT (audiosink), "sync", FALSE, NULL); - gst_element_link (a_decoder, a_queue); - gst_element_link (a_queue, audiosink); - gst_bin_add (GST_BIN (audio_bin), a_decoder); - gst_bin_add (GST_BIN (audio_bin), a_queue); - gst_bin_add (GST_BIN (audio_bin), audiosink); - - setup_dynamic_link (demux, "audio_00", gst_element_get_static_pad (a_decoder, - "sink"), audio_bin); - - seekable = gst_element_get_static_pad (a_queue, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (a_decoder, - "sink")); - - video_bin = gst_bin_new ("v_decoder_bin"); - v_decoder = gst_element_factory_make_or_warn ("mpeg2dec", "v_dec"); - v_filter = gst_element_factory_make_or_warn ("ffmpegcolorspace", "v_filter"); - videosink = gst_element_factory_make_or_warn (VSINK, "v_sink"); - gst_element_link_many (v_decoder, v_filter, videosink, NULL); - - gst_bin_add_many (GST_BIN (video_bin), v_decoder, v_filter, videosink, NULL); - - setup_dynamic_link (demux, "video_00", gst_element_get_static_pad (v_decoder, - "sink"), video_bin); - - seekable = gst_element_get_static_pad (v_decoder, "src"); - seekable_pads = g_list_prepend (seekable_pads, seekable); - rate_pads = g_list_prepend (rate_pads, seekable); - rate_pads = - g_list_prepend (rate_pads, gst_element_get_static_pad (v_decoder, - "sink")); - - return pipeline; -} - -static void -playerbin_set_uri (GstElement * player, const gchar * location) -{ - gchar *uri; - - /* Add "file://" prefix for convenience */ - if (g_str_has_prefix (location, "/")) { - uri = g_strconcat ("file://", location, NULL); - g_object_set (G_OBJECT (player), "uri", uri, NULL); - g_free (uri); - } else { - g_object_set (G_OBJECT (player), "uri", location, NULL); - } -} - -static GstElement * -construct_playerbin (const gchar * name, const gchar * location) -{ - GstElement *player; - - player = gst_element_factory_make (name, "player"); - g_assert (player); - - playerbin_set_uri (player, location); - - seekable_elements = g_list_prepend (seekable_elements, player); - - /* force element seeking on this pipeline */ - elem_seek = TRUE; - - return player; -} - -static GstElement * -make_playerbin_pipeline (const gchar * location) -{ - return construct_playerbin ("playbin", location); -} - -static GstElement * -make_playerbin2_pipeline (const gchar * location) -{ - GstElement *pipeline = construct_playerbin ("playbin2", location); - - /* FIXME: this is not triggered, playbin2 is not forwarding it from the sink */ - g_signal_connect (pipeline, "notify::volume", G_CALLBACK (volume_notify_cb), - NULL); - return pipeline; -} - -#ifndef GST_DISABLE_PARSE -static GstElement * -make_parselaunch_pipeline (const gchar * description) -{ - GstElement *pipeline; - GError *error = NULL; - - pipeline = gst_parse_launch (description, &error); - - seekable_elements = g_list_prepend (seekable_elements, pipeline); - - elem_seek = TRUE; - - return pipeline; -} -#endif - -typedef struct -{ - gchar *name; - GstElement *(*func) (const gchar * location); -} -Pipeline; - -static Pipeline pipelines[] = { - {"mp3", make_mp3_pipeline}, - {"avi", make_avi_pipeline}, - {"mpeg1", make_mpeg_pipeline}, - {"mpegparse", make_parse_pipeline}, - {"vorbis", make_vorbis_pipeline}, - {"theora", make_theora_pipeline}, - {"ogg/v/t", make_vorbis_theora_pipeline}, - {"avi/msmpeg4v3/mp3", make_avi_msmpeg4v3_mp3_pipeline}, - {"sid", make_sid_pipeline}, - {"flac", make_flac_pipeline}, - {"wav", make_wav_pipeline}, - {"mod", make_mod_pipeline}, - {"dv", make_dv_pipeline}, - {"mpeg1nothreads", make_mpegnt_pipeline}, - {"playerbin", make_playerbin_pipeline}, -#ifndef GST_DISABLE_PARSE - {"parse-launch", make_parselaunch_pipeline}, -#endif - {"playerbin2", make_playerbin2_pipeline}, - {NULL, NULL}, -}; - -#define NUM_TYPES ((sizeof (pipelines) / sizeof (Pipeline)) - 1) - -/* ui callbacks and helpers */ - -static gchar * -format_value (GtkScale * scale, gdouble value) -{ - gint64 real; - gint64 seconds; - gint64 subseconds; - - real = value * duration / 100; - seconds = (gint64) real / GST_SECOND; - subseconds = (gint64) real / (GST_SECOND / 100); - - return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02" - G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100); -} - - -static gchar * -shuttle_format_value (GtkScale * scale, gdouble value) -{ - return g_strdup_printf ("%0.*g", gtk_scale_get_digits (scale), value); -} - -typedef struct -{ - const gchar *name; - const GstFormat format; -} -seek_format; - -static seek_format seek_formats[] = { - {"tim", GST_FORMAT_TIME}, - {"byt", GST_FORMAT_BYTES}, - {"buf", GST_FORMAT_BUFFERS}, - {"def", GST_FORMAT_DEFAULT}, - {NULL, 0}, -}; - -G_GNUC_UNUSED static void -query_rates (void) -{ - GList *walk = rate_pads; - - while (walk) { - GstPad *pad = GST_PAD (walk->data); - gint i = 0; - - g_print ("rate/sec %8.8s: ", GST_PAD_NAME (pad)); - while (seek_formats[i].name) { - gint64 value; - GstFormat format; - - format = seek_formats[i].format; - - if (gst_pad_query_convert (pad, GST_FORMAT_TIME, GST_SECOND, &format, - &value)) { - g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value); - } else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); - } - - i++; - } - g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad)); - - walk = g_list_next (walk); - } -} - -G_GNUC_UNUSED static void -query_positions_elems (void) -{ - GList *walk = seekable_elements; - - while (walk) { - GstElement *element = GST_ELEMENT (walk->data); - gint i = 0; - - g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element)); - while (seek_formats[i].name) { - gint64 position, total; - GstFormat format; - - format = seek_formats[i].format; - - if (gst_element_query_position (element, &format, &position) && - gst_element_query_duration (element, &format, &total)) { - g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ", - seek_formats[i].name, position, total); - } else { - g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*", - "*NA*"); - } - i++; - } - g_print (" %s\n", GST_ELEMENT_NAME (element)); - - walk = g_list_next (walk); - } -} - -G_GNUC_UNUSED static void -query_positions_pads (void) -{ - GList *walk = seekable_pads; - - while (walk) { - GstPad *pad = GST_PAD (walk->data); - gint i = 0; - - g_print ("positions %8.8s: ", GST_PAD_NAME (pad)); - while (seek_formats[i].name) { - GstFormat format; - gint64 position, total; - - format = seek_formats[i].format; - - if (gst_pad_query_position (pad, &format, &position) && - gst_pad_query_duration (pad, &format, &total)) { - g_print ("%s %13" G_GINT64_FORMAT " / %13" G_GINT64_FORMAT " | ", - seek_formats[i].name, position, total); - } else { - g_print ("%s %13.13s / %13.13s | ", seek_formats[i].name, "*NA*", - "*NA*"); - } - - i++; - } - g_print (" %s:%s\n", GST_DEBUG_PAD_NAME (pad)); - - walk = g_list_next (walk); - } -} - -static gboolean start_seek (GtkWidget * widget, GdkEventButton * event, - gpointer user_data); -static gboolean stop_seek (GtkWidget * widget, GdkEventButton * event, - gpointer user_data); -static void seek_cb (GtkWidget * widget); - -static void -set_scale (gdouble value) -{ - g_signal_handlers_block_by_func (hscale, (void *) start_seek, - (void *) pipeline); - g_signal_handlers_block_by_func (hscale, (void *) stop_seek, - (void *) pipeline); - g_signal_handlers_block_by_func (hscale, (void *) seek_cb, (void *) pipeline); - gtk_adjustment_set_value (adjustment, value); - g_signal_handlers_unblock_by_func (hscale, (void *) start_seek, - (void *) pipeline); - g_signal_handlers_unblock_by_func (hscale, (void *) stop_seek, - (void *) pipeline); - g_signal_handlers_unblock_by_func (hscale, (void *) seek_cb, - (void *) pipeline); - gtk_widget_queue_draw (hscale); -} - -static gboolean -update_fill (gpointer data) -{ - if (elem_seek) { - if (seekable_elements) { - GstElement *element = GST_ELEMENT (seekable_elements->data); - GstQuery *query; - - query = gst_query_new_buffering (GST_FORMAT_PERCENT); - if (gst_element_query (element, query)) { - gint64 start, stop; - GstFormat format; - gdouble fill; - gboolean busy; - gint percent; - - gst_query_parse_buffering_percent (query, &busy, &percent); - gst_query_parse_buffering_range (query, &format, &start, &stop, NULL); - - GST_DEBUG ("start %" G_GINT64_FORMAT ", stop %" G_GINT64_FORMAT, - start, stop); - - if (stop != -1) - fill = 100.0 * stop / GST_FORMAT_PERCENT_MAX; - else - fill = 100.0; - - gtk_range_set_fill_level (GTK_RANGE (hscale), fill); - } - gst_query_unref (query); - } - } - return TRUE; -} - -static gboolean -update_scale (gpointer data) -{ - GstFormat format = GST_FORMAT_TIME; - - //position = 0; - //duration = 0; - - if (elem_seek) { - if (seekable_elements) { - GstElement *element = GST_ELEMENT (seekable_elements->data); - - gst_element_query_position (element, &format, &position); - gst_element_query_duration (element, &format, &duration); - } - } else { - if (seekable_pads) { - GstPad *pad = GST_PAD (seekable_pads->data); - - gst_pad_query_position (pad, &format, &position); - gst_pad_query_duration (pad, &format, &duration); - } - } - - if (stats) { - if (elem_seek) { - query_positions_elems (); - } else { - query_positions_pads (); - } - query_rates (); - } - - if (position >= duration) - duration = position; - - if (duration > 0) { - set_scale (position * 100.0 / duration); - } - - /* FIXME: see make_playerbin2_pipeline() and volume_notify_cb() */ - if (pipeline_type == 16) { - g_object_notify (G_OBJECT (pipeline), "volume"); - } - - return TRUE; -} - -static void do_seek (GtkWidget * widget); -static void connect_bus_signals (GstElement * pipeline); -static void set_update_scale (gboolean active); -static void set_update_fill (gboolean active); - -static gboolean -end_scrub (GtkWidget * widget) -{ - GST_DEBUG ("end scrub, PAUSE"); - gst_element_set_state (pipeline, GST_STATE_PAUSED); - seek_timeout_id = 0; - - return FALSE; -} - -static gboolean -send_event (GstEvent * event) -{ - gboolean res = FALSE; - - if (!elem_seek) { - GList *walk = seekable_pads; - - while (walk) { - GstPad *seekable = GST_PAD (walk->data); - - GST_DEBUG ("send event on pad %s:%s", GST_DEBUG_PAD_NAME (seekable)); - - gst_event_ref (event); - res = gst_pad_send_event (seekable, event); - - walk = g_list_next (walk); - } - } else { - GList *walk = seekable_elements; - - while (walk) { - GstElement *seekable = GST_ELEMENT (walk->data); - - GST_DEBUG ("send event on element %s", GST_ELEMENT_NAME (seekable)); - - gst_event_ref (event); - res = gst_element_send_event (seekable, event); - - walk = g_list_next (walk); - } - } - gst_event_unref (event); - return res; -} - -static void -do_seek (GtkWidget * widget) -{ - gint64 real; - gboolean res = FALSE; - GstEvent *s_event; - GstSeekFlags flags; - - real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100; - - flags = 0; - if (flush_seek) - flags |= GST_SEEK_FLAG_FLUSH; - if (accurate_seek) - flags |= GST_SEEK_FLAG_ACCURATE; - if (keyframe_seek) - flags |= GST_SEEK_FLAG_KEY_UNIT; - if (loop_seek) - flags |= GST_SEEK_FLAG_SEGMENT; - if (skip_seek) - flags |= GST_SEEK_FLAG_SKIP; - - if (rate >= 0) { - s_event = gst_event_new_seek (rate, - GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, real, GST_SEEK_TYPE_SET, - GST_CLOCK_TIME_NONE); - GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT, - rate, GST_TIME_ARGS (real), GST_TIME_ARGS (duration)); - } else { - s_event = gst_event_new_seek (rate, - GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0), - GST_SEEK_TYPE_SET, real); - GST_DEBUG ("seek with rate %lf to %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT, - rate, GST_TIME_ARGS (0), GST_TIME_ARGS (real)); - } - - res = send_event (s_event); - - if (res) { - if (flush_seek) { - gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT); - } else { - set_update_scale (TRUE); - } - } else { - g_print ("seek failed\n"); - set_update_scale (TRUE); - } -} - -static void -seek_cb (GtkWidget * widget) -{ - /* If the timer hasn't expired yet, then the pipeline is running */ - if (play_scrub && seek_timeout_id != 0) { - GST_DEBUG ("do scrub seek, PAUSED"); - gst_element_set_state (pipeline, GST_STATE_PAUSED); - } - - GST_DEBUG ("do seek"); - do_seek (widget); - - if (play_scrub) { - GST_DEBUG ("do scrub seek, PLAYING"); - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - if (seek_timeout_id == 0) { - seek_timeout_id = - g_timeout_add (SCRUB_TIME, (GSourceFunc) end_scrub, widget); - } - } -} - -static void -set_update_fill (gboolean active) -{ - GST_DEBUG ("fill scale is %d", active); - - if (active) { - if (fill_id == 0) { - fill_id = - g_timeout_add (FILL_INTERVAL, (GtkFunction) update_fill, pipeline); - } - } else { - if (fill_id) { - g_source_remove (fill_id); - fill_id = 0; - } - } -} - -static void -set_update_scale (gboolean active) -{ - - GST_DEBUG ("update scale is %d", active); - - if (active) { - if (update_id == 0) { - update_id = - g_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); - } - } else { - if (update_id) { - g_source_remove (update_id); - update_id = 0; - } - } -} - -static gboolean -start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) -{ - if (event->type != GDK_BUTTON_PRESS) - return FALSE; - - set_update_scale (FALSE); - - if (state == GST_STATE_PLAYING && flush_seek && scrub) { - GST_DEBUG ("start scrub seek, PAUSE"); - gst_element_set_state (pipeline, GST_STATE_PAUSED); - } - - if (changed_id == 0 && flush_seek && scrub) { - changed_id = - g_signal_connect (hscale, "value_changed", G_CALLBACK (seek_cb), - pipeline); - } - - return FALSE; -} - -static gboolean -stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) -{ - if (changed_id) { - g_signal_handler_disconnect (hscale, changed_id); - changed_id = 0; - } - - if (!flush_seek || !scrub) { - GST_DEBUG ("do final seek"); - do_seek (widget); - } - - if (seek_timeout_id != 0) { - g_source_remove (seek_timeout_id); - seek_timeout_id = 0; - /* Still scrubbing, so the pipeline is playing, see if we need PAUSED - * instead. */ - if (state == GST_STATE_PAUSED) { - GST_DEBUG ("stop scrub seek, PAUSED"); - gst_element_set_state (pipeline, GST_STATE_PAUSED); - } - } else { - if (state == GST_STATE_PLAYING) { - GST_DEBUG ("stop scrub seek, PLAYING"); - gst_element_set_state (pipeline, GST_STATE_PLAYING); - } - } - - return FALSE; -} - -static void -play_cb (GtkButton * button, gpointer data) -{ - GstStateChangeReturn ret; - - if (state != GST_STATE_PLAYING) { - g_print ("PLAY pipeline\n"); - gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id); - - ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); - switch (ret) { - case GST_STATE_CHANGE_FAILURE: - goto failed; - case GST_STATE_CHANGE_NO_PREROLL: - is_live = TRUE; - break; - default: - break; - } - state = GST_STATE_PLAYING; - gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing"); - } - - return; - -failed: - { - g_print ("PLAY failed\n"); - gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Play failed"); - } -} - -static void -pause_cb (GtkButton * button, gpointer data) -{ - g_static_mutex_lock (&state_mutex); - if (state != GST_STATE_PAUSED) { - GstStateChangeReturn ret; - - gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id); - g_print ("PAUSE pipeline\n"); - ret = gst_element_set_state (pipeline, GST_STATE_PAUSED); - switch (ret) { - case GST_STATE_CHANGE_FAILURE: - goto failed; - case GST_STATE_CHANGE_NO_PREROLL: - is_live = TRUE; - break; - default: - break; - } - - state = GST_STATE_PAUSED; - gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Paused"); - } - g_static_mutex_unlock (&state_mutex); - - return; - -failed: - { - g_static_mutex_unlock (&state_mutex); - g_print ("PAUSE failed\n"); - gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Pause failed"); - } -} - -static void -stop_cb (GtkButton * button, gpointer data) -{ - if (state != STOP_STATE) { - GstStateChangeReturn ret; - - g_print ("READY pipeline\n"); - gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id); - - g_static_mutex_lock (&state_mutex); - ret = gst_element_set_state (pipeline, STOP_STATE); - if (ret == GST_STATE_CHANGE_FAILURE) - goto failed; - - state = STOP_STATE; - gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped"); - - is_live = FALSE; - buffering = FALSE; - set_update_scale (FALSE); - set_scale (0.0); - set_update_fill (FALSE); - - if (pipeline_type == 16) - clear_streams (pipeline); - g_static_mutex_unlock (&state_mutex); - -#if 0 - /* if one uses parse_launch, play, stop and play again it fails as all the - * pads after the demuxer can't be reconnected - */ - if (!strcmp (pipelines[pipeline_type].name, "parse-launch")) { - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - - g_list_free (seekable_elements); - seekable_elements = NULL; - g_list_free (seekable_pads); - seekable_pads = NULL; - g_list_free (rate_pads); - rate_pads = NULL; - - pipeline = pipelines[pipeline_type].func (pipeline_spec); - g_assert (pipeline); - gst_element_set_state (pipeline, STOP_STATE); - connect_bus_signals (pipeline); - } -#endif - } - return; - -failed: - { - g_static_mutex_unlock (&state_mutex); - g_print ("STOP failed\n"); - gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stop failed"); - } -} - -static void -accurate_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - accurate_seek = gtk_toggle_button_get_active (button); -} - -static void -key_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - keyframe_seek = gtk_toggle_button_get_active (button); -} - -static void -loop_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - loop_seek = gtk_toggle_button_get_active (button); - if (state == GST_STATE_PLAYING) { - do_seek (hscale); - } -} - -static void -flush_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - flush_seek = gtk_toggle_button_get_active (button); -} - -static void -scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - scrub = gtk_toggle_button_get_active (button); -} - -static void -play_scrub_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - play_scrub = gtk_toggle_button_get_active (button); -} - -static void -skip_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - skip_seek = gtk_toggle_button_get_active (button); - if (state == GST_STATE_PLAYING) { - do_seek (hscale); - } -} - -static void -rate_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline) -{ - gboolean res = FALSE; - GstEvent *s_event; - GstSeekFlags flags; - - rate = gtk_spin_button_get_value (button); - - GST_DEBUG ("rate changed to %lf", rate); - - flags = 0; - if (flush_seek) - flags |= GST_SEEK_FLAG_FLUSH; - if (loop_seek) - flags |= GST_SEEK_FLAG_SEGMENT; - if (accurate_seek) - flags |= GST_SEEK_FLAG_ACCURATE; - if (keyframe_seek) - flags |= GST_SEEK_FLAG_KEY_UNIT; - if (skip_seek) - flags |= GST_SEEK_FLAG_SKIP; - - if (rate >= 0.0) { - s_event = gst_event_new_seek (rate, - GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position, - GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE); - } else { - s_event = gst_event_new_seek (rate, - GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0), - GST_SEEK_TYPE_SET, position); - } - - res = send_event (s_event); - - if (res) { - if (flush_seek) { - gst_element_get_state (GST_ELEMENT (pipeline), NULL, NULL, SEEK_TIMEOUT); - } - } else - g_print ("seek failed\n"); -} - -static void -update_flag (GstPipeline * pipeline, gint num, gboolean state) -{ - gint flags; - - g_object_get (pipeline, "flags", &flags, NULL); - if (state) - flags |= (1 << num); - else - flags &= ~(1 << num); - g_object_set (pipeline, "flags", flags, NULL); -} - -static void -vis_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - gboolean state; - - state = gtk_toggle_button_get_active (button); - update_flag (pipeline, 3, state); - gtk_widget_set_sensitive (vis_combo, state); -} - -static void -audio_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - gboolean state; - - state = gtk_toggle_button_get_active (button); - update_flag (pipeline, 1, state); - gtk_widget_set_sensitive (audio_combo, state); -} - -static void -video_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - gboolean state; - - state = gtk_toggle_button_get_active (button); - update_flag (pipeline, 0, state); - gtk_widget_set_sensitive (video_combo, state); -} - -static void -text_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - gboolean state; - - state = gtk_toggle_button_get_active (button); - update_flag (pipeline, 2, state); - gtk_widget_set_sensitive (text_combo, state); -} - -static void -mute_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - gboolean mute; - - mute = gtk_toggle_button_get_active (button); - g_object_set (pipeline, "mute", mute, NULL); -} - -static void -download_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - gboolean state; - - state = gtk_toggle_button_get_active (button); - update_flag (pipeline, 7, state); -} - -static void -buffer_toggle_cb (GtkToggleButton * button, GstPipeline * pipeline) -{ - gboolean state; - - state = gtk_toggle_button_get_active (button); - update_flag (pipeline, 8, state); -} - -static void -clear_streams (GstElement * pipeline) -{ - gint i; - - /* remove previous info */ - for (i = 0; i < n_video; i++) - gtk_combo_box_remove_text (GTK_COMBO_BOX (video_combo), 0); - for (i = 0; i < n_audio; i++) - gtk_combo_box_remove_text (GTK_COMBO_BOX (audio_combo), 0); - for (i = 0; i < n_text; i++) - gtk_combo_box_remove_text (GTK_COMBO_BOX (text_combo), 0); - - n_audio = n_video = n_text = 0; - gtk_widget_set_sensitive (video_combo, FALSE); - gtk_widget_set_sensitive (audio_combo, FALSE); - gtk_widget_set_sensitive (text_combo, FALSE); - - need_streams = TRUE; -} - -static void -update_streams (GstPipeline * pipeline) -{ - gint i; - - if (pipeline_type == 16 && need_streams) { - GstTagList *tags; - gchar *name, *str; - gint active_idx; - gboolean state; - - /* remove previous info */ - clear_streams (GST_ELEMENT_CAST (pipeline)); - - /* here we get and update the different streams detected by playbin2 */ - g_object_get (pipeline, "n-video", &n_video, NULL); - g_object_get (pipeline, "n-audio", &n_audio, NULL); - g_object_get (pipeline, "n-text", &n_text, NULL); - - g_print ("video %d, audio %d, text %d\n", n_video, n_audio, n_text); - - active_idx = 0; - for (i = 0; i < n_video; i++) { - g_signal_emit_by_name (pipeline, "get-video-tags", i, &tags); - if (tags) { - str = gst_structure_to_string ((GstStructure *) tags); - g_print ("video %d: %s\n", i, str); - g_free (str); - } - /* find good name for the label */ - name = g_strdup_printf ("video %d", i + 1); - gtk_combo_box_append_text (GTK_COMBO_BOX (video_combo), name); - g_free (name); - } - state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (video_checkbox)); - gtk_widget_set_sensitive (video_combo, state && n_video > 0); - gtk_combo_box_set_active (GTK_COMBO_BOX (video_combo), active_idx); - - active_idx = 0; - for (i = 0; i < n_audio; i++) { - g_signal_emit_by_name (pipeline, "get-audio-tags", i, &tags); - if (tags) { - str = gst_structure_to_string ((GstStructure *) tags); - g_print ("audio %d: %s\n", i, str); - g_free (str); - } - /* find good name for the label */ - name = g_strdup_printf ("audio %d", i + 1); - gtk_combo_box_append_text (GTK_COMBO_BOX (audio_combo), name); - g_free (name); - } - state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (audio_checkbox)); - gtk_widget_set_sensitive (audio_combo, state && n_audio > 0); - gtk_combo_box_set_active (GTK_COMBO_BOX (audio_combo), active_idx); - - active_idx = 0; - for (i = 0; i < n_text; i++) { - g_signal_emit_by_name (pipeline, "get-text-tags", i, &tags); - - name = NULL; - if (tags) { - const GValue *value; - - str = gst_structure_to_string ((GstStructure *) tags); - g_print ("text %d: %s\n", i, str); - g_free (str); - - /* get the language code if we can */ - value = gst_tag_list_get_value_index (tags, GST_TAG_LANGUAGE_CODE, 0); - if (value && G_VALUE_HOLDS_STRING (value)) { - name = g_strdup_printf ("text %s", g_value_get_string (value)); - } - } - /* find good name for the label if we didn't use a tag */ - if (name == NULL) - name = g_strdup_printf ("text %d", i + 1); - - gtk_combo_box_append_text (GTK_COMBO_BOX (text_combo), name); - g_free (name); - } - state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (text_checkbox)); - gtk_widget_set_sensitive (text_combo, state && n_text > 0); - gtk_combo_box_set_active (GTK_COMBO_BOX (text_combo), active_idx); - - need_streams = FALSE; - } -} - -static void -video_combo_cb (GtkComboBox * combo, GstPipeline * pipeline) -{ - gint active; - - active = gtk_combo_box_get_active (combo); - - g_print ("setting current video track %d\n", active); - g_object_set (pipeline, "current-video", active, NULL); -} - -static void -audio_combo_cb (GtkComboBox * combo, GstPipeline * pipeline) -{ - gint active; - - active = gtk_combo_box_get_active (combo); - - g_print ("setting current audio track %d\n", active); - g_object_set (pipeline, "current-audio", active, NULL); -} - -static void -text_combo_cb (GtkComboBox * combo, GstPipeline * pipeline) -{ - gint active; - - active = gtk_combo_box_get_active (combo); - - g_print ("setting current text track %d\n", active); - g_object_set (pipeline, "current-text", active, NULL); -} - -static gboolean -filter_features (GstPluginFeature * feature, gpointer data) -{ - GstElementFactory *f; - - if (!GST_IS_ELEMENT_FACTORY (feature)) - return FALSE; - f = GST_ELEMENT_FACTORY (feature); - if (!g_strrstr (gst_element_factory_get_klass (f), "Visualization")) - return FALSE; - - return TRUE; -} - -static void -init_visualization_features (void) -{ - GList *list, *walk; - - vis_entries = g_array_new (FALSE, FALSE, sizeof (VisEntry)); - - list = gst_registry_feature_filter (gst_registry_get_default (), - filter_features, FALSE, NULL); - - for (walk = list; walk; walk = g_list_next (walk)) { - VisEntry entry; - const gchar *name; - - entry.factory = GST_ELEMENT_FACTORY (walk->data); - name = gst_element_factory_get_longname (entry.factory); - - g_array_append_val (vis_entries, entry); - gtk_combo_box_append_text (GTK_COMBO_BOX (vis_combo), name); - } - gtk_combo_box_set_active (GTK_COMBO_BOX (vis_combo), 0); -} - -static void -vis_combo_cb (GtkComboBox * combo, GstPipeline * pipeline) -{ - guint index; - VisEntry *entry; - GstElement *element; - - /* get the selected index and get the factory for this index */ - index = gtk_combo_box_get_active (GTK_COMBO_BOX (vis_combo)); - if (vis_entries->len > 0) { - entry = &g_array_index (vis_entries, VisEntry, index); - - /* create an instance of the element from the factory */ - element = gst_element_factory_create (entry->factory, NULL); - if (!element) - return; - - /* set vis plugin for playbin2 */ - g_object_set (pipeline, "vis-plugin", element, NULL); - } -} - -static void -volume_spinbutton_changed_cb (GtkSpinButton * button, GstPipeline * pipeline) -{ - gdouble volume; - - volume = gtk_spin_button_get_value (button); - - g_object_set (pipeline, "volume", volume, NULL); -} - -static void -volume_notify_cb (GstElement * pipeline, GParamSpec * arg, gpointer user_dat) -{ - gdouble cur_volume, new_volume; - - g_object_get (pipeline, "volume", &new_volume, NULL); - cur_volume = gtk_spin_button_get_value (GTK_SPIN_BUTTON (volume_spinbutton)); - if (fabs (cur_volume - new_volume) > 0.001) { - g_signal_handlers_block_by_func (volume_spinbutton, - volume_spinbutton_changed_cb, pipeline); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), new_volume); - g_signal_handlers_unblock_by_func (volume_spinbutton, - volume_spinbutton_changed_cb, pipeline); - } -} - -static void -shot_cb (GtkButton * button, gpointer data) -{ - GstBuffer *buffer; - GstCaps *caps; - - /* convert to our desired format (RGB24) */ - caps = gst_caps_new_simple ("video/x-raw-rgb", - "bpp", G_TYPE_INT, 24, "depth", G_TYPE_INT, 24, - /* Note: we don't ask for a specific width/height here, so that - * videoscale can adjust dimensions from a non-1/1 pixel aspect - * ratio to a 1/1 pixel-aspect-ratio */ - "pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, - "endianness", G_TYPE_INT, G_BIG_ENDIAN, - "red_mask", G_TYPE_INT, 0xff0000, - "green_mask", G_TYPE_INT, 0x00ff00, - "blue_mask", G_TYPE_INT, 0x0000ff, NULL); - - /* convert the latest frame to the requested format */ - g_signal_emit_by_name (pipeline, "convert-frame", caps, &buffer); - gst_caps_unref (caps); - - if (buffer) { - GstCaps *caps; - GstStructure *s; - gboolean res; - gint width, height; - GdkPixbuf *pixbuf; - GError *error = NULL; - - /* get the snapshot buffer format now. We set the caps on the appsink so - * that it can only be an rgb buffer. The only thing we have not specified - * on the caps is the height, which is dependant on the pixel-aspect-ratio - * of the source material */ - caps = GST_BUFFER_CAPS (buffer); - if (!caps) { - g_warning ("could not get snapshot format\n"); - goto done; - } - s = gst_caps_get_structure (caps, 0); - - /* we need to get the final caps on the buffer to get the size */ - res = gst_structure_get_int (s, "width", &width); - res |= gst_structure_get_int (s, "height", &height); - if (!res) { - g_warning ("could not get snapshot dimension\n"); - goto done; - } - - /* create pixmap from buffer and save, gstreamer video buffers have a stride - * that is rounded up to the nearest multiple of 4 */ - pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer), - GDK_COLORSPACE_RGB, FALSE, 8, width, height, - GST_ROUND_UP_4 (width * 3), NULL, NULL); - - /* save the pixbuf */ - gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL); - - done: - gst_buffer_unref (buffer); - } -} - -/* called when the Step button is pressed */ -static void -step_cb (GtkButton * button, gpointer data) -{ - GstEvent *event; - GstFormat format; - guint64 amount; - gdouble rate; - gboolean flush, res; - gint active; - - active = gtk_combo_box_get_active (GTK_COMBO_BOX (format_combo)); - amount = - gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON - (step_amount_spinbutton)); - rate = gtk_spin_button_get_value (GTK_SPIN_BUTTON (step_rate_spinbutton)); - flush = TRUE; - - switch (active) { - case 0: - format = GST_FORMAT_BUFFERS; - break; - case 1: - format = GST_FORMAT_TIME; - amount *= GST_MSECOND; - break; - default: - format = GST_FORMAT_UNDEFINED; - break; - } - - event = gst_event_new_step (format, amount, rate, flush, FALSE); - - res = send_event (event); -} - -static void -message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline) -{ - const GstStructure *s; - - s = gst_message_get_structure (message); - g_print ("message from \"%s\" (%s): ", - GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))), - gst_message_type_get_name (GST_MESSAGE_TYPE (message))); - if (s) { - gchar *sstr; - - sstr = gst_structure_to_string (s); - g_print ("%s\n", sstr); - g_free (sstr); - } else { - g_print ("no message details\n"); - } -} - -static gboolean shuttling = FALSE; -static gdouble shuttle_rate = 0.0; -static gdouble play_rate = 1.0; - -static void -do_shuttle (GstElement * element) -{ - guint64 duration; - - if (shuttling) - duration = 40 * GST_MSECOND; - else - duration = -1; - - gst_element_send_event (element, - gst_event_new_step (GST_FORMAT_TIME, duration, shuttle_rate, FALSE, - FALSE)); -} - -static void -msg_sync_step_done (GstBus * bus, GstMessage * message, GstElement * element) -{ - GstFormat format; - guint64 amount; - gdouble rate; - gboolean flush; - gboolean intermediate; - guint64 duration; - gboolean eos; - - gst_message_parse_step_done (message, &format, &amount, &rate, &flush, - &intermediate, &duration, &eos); - - if (eos) { - g_print ("stepped till EOS\n"); - return; - } - - if (g_static_mutex_trylock (&state_mutex)) { - if (shuttling) - do_shuttle (element); - g_static_mutex_unlock (&state_mutex); - } else { - /* ignore step messages that come while we are doing a state change */ - g_print ("state change is busy\n"); - } -} - -static void -shuttle_toggled (GtkToggleButton * button, GstElement * element) -{ - gboolean active; - - active = gtk_toggle_button_get_active (button); - - if (active != shuttling) { - shuttling = active; - g_print ("shuttling %s\n", shuttling ? "active" : "inactive"); - if (active) { - shuttle_rate = 0.0; - play_rate = 1.0; - pause_cb (NULL, NULL); - gst_element_get_state (element, NULL, NULL, -1); - } - } -} - -static void -shuttle_rate_switch (GstElement * element) -{ - GstSeekFlags flags; - GstEvent *s_event; - gboolean res; - - if (state == GST_STATE_PLAYING) { - /* pause when we need to */ - pause_cb (NULL, NULL); - gst_element_get_state (element, NULL, NULL, -1); - } - - if (play_rate == 1.0) - play_rate = -1.0; - else - play_rate = 1.0; - - g_print ("rate changed to %lf %" GST_TIME_FORMAT "\n", play_rate, - GST_TIME_ARGS (position)); - - flags = GST_SEEK_FLAG_FLUSH; - flags |= GST_SEEK_FLAG_ACCURATE; - - if (play_rate >= 0.0) { - s_event = gst_event_new_seek (play_rate, - GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, position, - GST_SEEK_TYPE_SET, GST_CLOCK_TIME_NONE); - } else { - s_event = gst_event_new_seek (play_rate, - GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0), - GST_SEEK_TYPE_SET, position); - } - res = send_event (s_event); - if (res) { - gst_element_get_state (element, NULL, NULL, SEEK_TIMEOUT); - } else { - g_print ("seek failed\n"); - } -} - -static void -shuttle_value_changed (GtkRange * range, GstElement * element) -{ - gdouble rate; - - rate = gtk_adjustment_get_value (shuttle_adjustment); - - if (rate == 0.0) { - g_print ("rate 0.0, pause\n"); - pause_cb (NULL, NULL); - gst_element_get_state (element, NULL, NULL, -1); - } else { - g_print ("rate changed %0.3g\n", rate); - - if ((rate < 0.0 && play_rate > 0.0) || (rate > 0.0 && play_rate < 0.0)) { - shuttle_rate_switch (element); - } - - shuttle_rate = ABS (rate); - if (state != GST_STATE_PLAYING) { - do_shuttle (element); - play_cb (NULL, NULL); - } - } -} - -static void -msg_async_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline) -{ - GST_DEBUG ("async done"); - /* when we get ASYNC_DONE we can query position, duration and other - * properties */ - update_scale (pipeline); - - /* update the available streams */ - update_streams (pipeline); -} - -static void -msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline) -{ - const GstStructure *s; - - s = gst_message_get_structure (message); - - /* We only care about state changed on the pipeline */ - if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) { - GstState old, new, pending; - - gst_message_parse_state_changed (message, &old, &new, &pending); - - /* When state of the pipeline changes to paused or playing we start updating scale */ - if (new == GST_STATE_PLAYING) { - set_update_scale (TRUE); - } else { - set_update_scale (FALSE); - } - } -} - -static void -msg_segment_done (GstBus * bus, GstMessage * message, GstPipeline * pipeline) -{ - GstEvent *s_event; - GstSeekFlags flags; - gboolean res; - GstFormat format; - - GST_DEBUG ("position is %" GST_TIME_FORMAT, GST_TIME_ARGS (position)); - gst_message_parse_segment_done (message, &format, &position); - GST_DEBUG ("end of segment at %" GST_TIME_FORMAT, GST_TIME_ARGS (position)); - - flags = 0; - /* in the segment-done callback we never flush as this would not make sense - * for seamless playback. */ - if (loop_seek) - flags |= GST_SEEK_FLAG_SEGMENT; - if (skip_seek) - flags |= GST_SEEK_FLAG_SKIP; - - s_event = gst_event_new_seek (rate, - GST_FORMAT_TIME, flags, GST_SEEK_TYPE_SET, G_GINT64_CONSTANT (0), - GST_SEEK_TYPE_SET, duration); - - GST_DEBUG ("restart loop with rate %lf to 0 / %" GST_TIME_FORMAT, - rate, GST_TIME_ARGS (duration)); - - res = send_event (s_event); - if (!res) - g_print ("segment seek failed\n"); -} - -/* in stream buffering mode we PAUSE the pipeline until we receive a 100% - * message */ -static void -do_stream_buffering (gint percent) -{ - gchar *bufstr; - - gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id); - bufstr = g_strdup_printf ("Buffering...%d", percent); - gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr); - g_free (bufstr); - - if (percent == 100) { - /* a 100% message means buffering is done */ - buffering = FALSE; - /* if the desired state is playing, go back */ - if (state == GST_STATE_PLAYING) { - /* no state management needed for live pipelines */ - if (!is_live) { - fprintf (stderr, "Done buffering, setting pipeline to PLAYING ...\n"); - gst_element_set_state (pipeline, GST_STATE_PLAYING); - } - gtk_statusbar_pop (GTK_STATUSBAR (statusbar), status_id); - gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Playing"); - } - } else { - /* buffering busy */ - if (buffering == FALSE && state == GST_STATE_PLAYING) { - /* we were not buffering but PLAYING, PAUSE the pipeline. */ - if (!is_live) { - fprintf (stderr, "Buffering, setting pipeline to PAUSED ...\n"); - gst_element_set_state (pipeline, GST_STATE_PAUSED); - } - } - buffering = TRUE; - } -} - -static void -do_download_buffering (gint percent) -{ - if (!buffering && percent < 100) { - gchar *bufstr; - - buffering = TRUE; - - bufstr = g_strdup_printf ("Downloading..."); - gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, bufstr); - g_free (bufstr); - - /* once we get a buffering message, we'll do the fill update */ - set_update_fill (TRUE); - - if (state == GST_STATE_PLAYING && !is_live) { - fprintf (stderr, "Downloading, setting pipeline to PAUSED ...\n"); - gst_element_set_state (pipeline, GST_STATE_PAUSED); - /* user has to manually start the playback */ - state = GST_STATE_PAUSED; - } - } -} - -static void -msg_buffering (GstBus * bus, GstMessage * message, GstPipeline * data) -{ - gint percent; - - gst_message_parse_buffering (message, &percent); - - /* get more stats */ - gst_message_parse_buffering_stats (message, &mode, NULL, NULL, - &buffering_left); - - switch (mode) { - case GST_BUFFERING_DOWNLOAD: - do_download_buffering (percent); - break; - case GST_BUFFERING_LIVE: - case GST_BUFFERING_TIMESHIFT: - case GST_BUFFERING_STREAM: - do_stream_buffering (percent); - break; - } -} - -static void -msg_clock_lost (GstBus * bus, GstMessage * message, GstPipeline * data) -{ - g_print ("clock lost! PAUSE and PLAY to select a new clock\n"); - - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gst_element_set_state (pipeline, GST_STATE_PLAYING); -} - -#ifdef HAVE_X - -static gulong embed_xid = 0; - -/* We set the xid here in response to the prepare-xwindow-id message via a - * bus sync handler because we don't know the actual videosink used from the - * start (as we don't know the pipeline, or bin elements such as autovideosink - * or gconfvideosink may be used which create the actual videosink only once - * the pipeline is started) */ -static GstBusSyncReply -bus_sync_handler (GstBus * bus, GstMessage * message, GstPipeline * data) -{ - if ((GST_MESSAGE_TYPE (message) == GST_MESSAGE_ELEMENT) && - gst_structure_has_name (message->structure, "prepare-xwindow-id")) { - GstElement *element = GST_ELEMENT (GST_MESSAGE_SRC (message)); - - g_print ("got prepare-xwindow-id, setting XID %lu\n", embed_xid); - - if (g_object_class_find_property (G_OBJECT_GET_CLASS (element), - "force-aspect-ratio")) { - g_object_set (element, "force-aspect-ratio", TRUE, NULL); - } - - /* Should have been initialised from main thread before (can't use - * GDK_WINDOW_XID here with Gtk+ >= 2.18, because the sync handler will - * be called from a streaming thread and GDK_WINDOW_XID maps to more than - * a simple structure lookup with Gtk+ >= 2.18, where 'more' is stuff that - * shouldn't be done from a non-GUI thread without explicit locking). */ - g_assert (embed_xid != 0); - - gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (element), embed_xid); - } - return GST_BUS_PASS; -} -#endif - -static gboolean -handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data) -{ - if (state < GST_STATE_PAUSED) { - gdk_draw_rectangle (widget->window, widget->style->black_gc, TRUE, - 0, 0, widget->allocation.width, widget->allocation.height); - } - return FALSE; -} - -static void -realize_cb (GtkWidget * widget, gpointer data) -{ -#if GTK_CHECK_VERSION(2,18,0) - /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it - * as well */ - if (!gdk_window_ensure_native (widget->window)) - g_error ("Couldn't create native window needed for GstXOverlay!"); -#endif - -#ifdef HAVE_X - embed_xid = GDK_WINDOW_XID (video_window->window); - g_print ("Window realize: video window XID = %lu\n", embed_xid); -#endif -} - -static void -msg_eos (GstBus * bus, GstMessage * message, GstPipeline * data) -{ - message_received (bus, message, data); - - /* Set new uri for playerbins and continue playback */ - if (l && (pipeline_type == 14 || pipeline_type == 16)) { - stop_cb (NULL, NULL); - l = g_list_next (l); - if (l) { - playerbin_set_uri (GST_ELEMENT (data), l->data); - play_cb (NULL, NULL); - } - } -} - -static void -msg_step_done (GstBus * bus, GstMessage * message, GstPipeline * data) -{ - if (!shuttling) - message_received (bus, message, data); -} - -static void -connect_bus_signals (GstElement * pipeline) -{ - GstBus *bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - -#ifdef HAVE_X - /* handle prepare-xwindow-id element message synchronously */ - gst_bus_set_sync_handler (bus, (GstBusSyncHandler) bus_sync_handler, - pipeline); -#endif - - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - gst_bus_enable_sync_message_emission (bus); - - g_signal_connect (bus, "message::state-changed", - (GCallback) msg_state_changed, pipeline); - g_signal_connect (bus, "message::segment-done", (GCallback) msg_segment_done, - pipeline); - g_signal_connect (bus, "message::async-done", (GCallback) msg_async_done, - pipeline); - - g_signal_connect (bus, "message::new-clock", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::clock-lost", (GCallback) msg_clock_lost, - pipeline); - g_signal_connect (bus, "message::error", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::warning", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::eos", (GCallback) msg_eos, pipeline); - g_signal_connect (bus, "message::tag", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::element", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::segment-done", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::buffering", (GCallback) msg_buffering, - pipeline); -// g_signal_connect (bus, "message::step-done", (GCallback) msg_step_done, -// pipeline); - g_signal_connect (bus, "message::step-start", (GCallback) msg_step_done, - pipeline); - g_signal_connect (bus, "sync-message::step-done", - (GCallback) msg_sync_step_done, pipeline); - - gst_object_unref (bus); -} - -/* Return GList of paths described in location string */ -static GList * -handle_wildcards (const gchar * location) -{ - GList *res = NULL; - gchar *path = g_path_get_dirname (location); - gchar *pattern = g_path_get_basename (location); - GPatternSpec *pspec = g_pattern_spec_new (pattern); - GDir *dir = g_dir_open (path, 0, NULL); - const gchar *name; - - g_print ("matching %s from %s\n", pattern, path); - - if (!dir) { - g_print ("opening directory %s failed\n", path); - goto out; - } - - while ((name = g_dir_read_name (dir)) != NULL) { - if (g_pattern_match_string (pspec, name)) { - res = g_list_append (res, g_strjoin ("/", path, name, NULL)); - g_print (" found clip %s\n", name); - } - } - - g_dir_close (dir); -out: - g_pattern_spec_free (pspec); - g_free (pattern); - g_free (path); - - return res; -} - -static void -delete_event_cb (void) -{ - stop_cb (NULL, NULL); - gtk_main_quit (); -} - -static void -print_usage (int argc, char **argv) -{ - gint i; - - g_print ("usage: %s <type> <filename>\n", argv[0]); - g_print (" possible types:\n"); - - for (i = 0; i < NUM_TYPES; i++) { - g_print (" %d = %s\n", i, pipelines[i].name); - } -} - -int -main (int argc, char **argv) -{ - GtkWidget *window, *hbox, *vbox, *panel, *expander, *pb2vbox, *boxes, - *flagtable, *boxes2, *step; - GtkWidget *play_button, *pause_button, *stop_button, *shot_button; - GtkWidget *accurate_checkbox, *key_checkbox, *loop_checkbox, *flush_checkbox; - GtkWidget *scrub_checkbox, *play_scrub_checkbox; - GtkWidget *rate_label, *volume_label; - GOptionEntry options[] = { - {"stats", 's', 0, G_OPTION_ARG_NONE, &stats, - "Show pad stats", NULL}, - {"elem", 'e', 0, G_OPTION_ARG_NONE, &elem_seek, - "Seek on elements instead of pads", NULL}, - {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, - "Verbose properties", NULL}, - {NULL} - }; - GOptionContext *ctx; - GError *err = NULL; - - if (!g_thread_supported ()) - g_thread_init (NULL); - - ctx = g_option_context_new ("- test seeking in gsteamer"); - g_option_context_add_main_entries (ctx, options, NULL); - g_option_context_add_group (ctx, gst_init_get_option_group ()); - g_option_context_add_group (ctx, gtk_get_option_group (TRUE)); - - if (!g_option_context_parse (ctx, &argc, &argv, &err)) { - g_print ("Error initializing: %s\n", err->message); - exit (1); - } - - GST_DEBUG_CATEGORY_INIT (seek_debug, "seek", 0, "seek example"); - - if (argc != 3) { - print_usage (argc, argv); - exit (-1); - } - - pipeline_type = atoi (argv[1]); - - if (pipeline_type < 0 || pipeline_type >= NUM_TYPES) { - print_usage (argc, argv); - exit (-1); - } - - pipeline_spec = argv[2]; - - if (g_strrstr (pipeline_spec, "*") != NULL || - g_strrstr (pipeline_spec, "?") != NULL) { - paths = handle_wildcards (pipeline_spec); - } else { - paths = g_list_prepend (paths, g_strdup (pipeline_spec)); - } - - if (!paths) { - g_print ("opening %s failed\n", pipeline_spec); - exit (-1); - } - - l = paths; - - pipeline = pipelines[pipeline_type].func ((gchar *) l->data); - g_assert (pipeline); - - /* initialize gui elements ... */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - video_window = gtk_drawing_area_new (); - g_signal_connect (video_window, "expose-event", - G_CALLBACK (handle_expose_cb), NULL); - g_signal_connect (video_window, "realize", G_CALLBACK (realize_cb), NULL); - gtk_widget_set_double_buffered (video_window, FALSE); - - statusbar = gtk_statusbar_new (); - status_id = gtk_statusbar_get_context_id (GTK_STATUSBAR (statusbar), "seek"); - gtk_statusbar_push (GTK_STATUSBAR (statusbar), status_id, "Stopped"); - hbox = gtk_hbox_new (FALSE, 0); - vbox = gtk_vbox_new (FALSE, 0); - flagtable = gtk_table_new (4, 2, FALSE); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 3); - - /* media controls */ - play_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PLAY); - pause_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_PAUSE); - stop_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_STOP); - - /* seek flags */ - accurate_checkbox = gtk_check_button_new_with_label ("Accurate Seek"); - key_checkbox = gtk_check_button_new_with_label ("Key-unit Seek"); - loop_checkbox = gtk_check_button_new_with_label ("Loop"); - flush_checkbox = gtk_check_button_new_with_label ("Flush"); - scrub_checkbox = gtk_check_button_new_with_label ("Scrub"); - play_scrub_checkbox = gtk_check_button_new_with_label ("Play Scrub"); - skip_checkbox = gtk_check_button_new_with_label ("Play Skip"); - rate_spinbutton = gtk_spin_button_new_with_range (-100, 100, 0.1); - gtk_spin_button_set_digits (GTK_SPIN_BUTTON (rate_spinbutton), 3); - rate_label = gtk_label_new ("Rate"); - - gtk_widget_set_tooltip_text (accurate_checkbox, - "accurate position is requested, this might be considerably slower for some formats"); - gtk_widget_set_tooltip_text (key_checkbox, - "seek to the nearest keyframe. This might be faster but less accurate"); - gtk_widget_set_tooltip_text (loop_checkbox, "loop playback"); - gtk_widget_set_tooltip_text (flush_checkbox, "flush pipeline after seeking"); - gtk_widget_set_tooltip_text (rate_spinbutton, "define the playback rate, " - "negative value trigger reverse playback"); - gtk_widget_set_tooltip_text (scrub_checkbox, "show images while seeking"); - gtk_widget_set_tooltip_text (play_scrub_checkbox, "play video while seeking"); - gtk_widget_set_tooltip_text (skip_checkbox, - "Skip frames while playing at high frame rates"); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (flush_checkbox), TRUE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (scrub_checkbox), TRUE); - - gtk_spin_button_set_value (GTK_SPIN_BUTTON (rate_spinbutton), rate); - - /* step expander */ - { - GtkWidget *hbox; - - step = gtk_expander_new ("step options"); - hbox = gtk_hbox_new (FALSE, 0); - - format_combo = gtk_combo_box_new_text (); - gtk_combo_box_append_text (GTK_COMBO_BOX (format_combo), "frames"); - gtk_combo_box_append_text (GTK_COMBO_BOX (format_combo), "time (ms)"); - gtk_combo_box_set_active (GTK_COMBO_BOX (format_combo), 0); - gtk_box_pack_start (GTK_BOX (hbox), format_combo, FALSE, FALSE, 2); - - step_amount_spinbutton = gtk_spin_button_new_with_range (1, 1000, 1); - gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_amount_spinbutton), 0); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_amount_spinbutton), 1.0); - gtk_box_pack_start (GTK_BOX (hbox), step_amount_spinbutton, FALSE, FALSE, - 2); - - step_rate_spinbutton = gtk_spin_button_new_with_range (0.0, 100, 0.1); - gtk_spin_button_set_digits (GTK_SPIN_BUTTON (step_rate_spinbutton), 3); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (step_rate_spinbutton), 1.0); - gtk_box_pack_start (GTK_BOX (hbox), step_rate_spinbutton, FALSE, FALSE, 2); - - step_button = gtk_button_new_from_stock (GTK_STOCK_MEDIA_FORWARD); - gtk_button_set_label (GTK_BUTTON (step_button), "Step"); - gtk_box_pack_start (GTK_BOX (hbox), step_button, FALSE, FALSE, 2); - - g_signal_connect (G_OBJECT (step_button), "clicked", G_CALLBACK (step_cb), - pipeline); - - /* shuttle scale */ - shuttle_checkbox = gtk_check_button_new_with_label ("Shuttle"); - gtk_box_pack_start (GTK_BOX (hbox), shuttle_checkbox, FALSE, FALSE, 2); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (shuttle_checkbox), FALSE); - g_signal_connect (shuttle_checkbox, "toggled", G_CALLBACK (shuttle_toggled), - pipeline); - - shuttle_adjustment = - GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -3.00, 4.0, 0.1, 1.0, 1.0)); - shuttle_hscale = gtk_hscale_new (shuttle_adjustment); - gtk_scale_set_digits (GTK_SCALE (shuttle_hscale), 2); - gtk_scale_set_value_pos (GTK_SCALE (shuttle_hscale), GTK_POS_TOP); - gtk_range_set_update_policy (GTK_RANGE (shuttle_hscale), - GTK_UPDATE_CONTINUOUS); - g_signal_connect (shuttle_hscale, "value_changed", - G_CALLBACK (shuttle_value_changed), pipeline); - g_signal_connect (shuttle_hscale, "format_value", - G_CALLBACK (shuttle_format_value), pipeline); - - gtk_box_pack_start (GTK_BOX (hbox), shuttle_hscale, TRUE, TRUE, 2); - - gtk_container_add (GTK_CONTAINER (step), hbox); - } - - /* seek bar */ - adjustment = - GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0)); - hscale = gtk_hscale_new (adjustment); - gtk_scale_set_digits (GTK_SCALE (hscale), 2); - gtk_scale_set_value_pos (GTK_SCALE (hscale), GTK_POS_RIGHT); -#if GTK_CHECK_VERSION(2,12,0) - gtk_range_set_show_fill_level (GTK_RANGE (hscale), TRUE); - gtk_range_set_fill_level (GTK_RANGE (hscale), 100.0); -#endif - gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS); - - g_signal_connect (hscale, "button_press_event", G_CALLBACK (start_seek), - pipeline); - g_signal_connect (hscale, "button_release_event", G_CALLBACK (stop_seek), - pipeline); - g_signal_connect (hscale, "format_value", G_CALLBACK (format_value), - pipeline); - - if (pipeline_type == 16) { - /* the playbin2 panel controls for the video/audio/subtitle tracks */ - panel = gtk_hbox_new (FALSE, 0); - video_combo = gtk_combo_box_new_text (); - audio_combo = gtk_combo_box_new_text (); - text_combo = gtk_combo_box_new_text (); - gtk_widget_set_sensitive (video_combo, FALSE); - gtk_widget_set_sensitive (audio_combo, FALSE); - gtk_widget_set_sensitive (text_combo, FALSE); - gtk_box_pack_start (GTK_BOX (panel), video_combo, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (panel), audio_combo, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (panel), text_combo, TRUE, TRUE, 2); - g_signal_connect (G_OBJECT (video_combo), "changed", - G_CALLBACK (video_combo_cb), pipeline); - g_signal_connect (G_OBJECT (audio_combo), "changed", - G_CALLBACK (audio_combo_cb), pipeline); - g_signal_connect (G_OBJECT (text_combo), "changed", - G_CALLBACK (text_combo_cb), pipeline); - /* playbin2 panel for flag checkboxes and volume/mute */ - boxes = gtk_hbox_new (FALSE, 0); - vis_checkbox = gtk_check_button_new_with_label ("Vis"); - video_checkbox = gtk_check_button_new_with_label ("Video"); - audio_checkbox = gtk_check_button_new_with_label ("Audio"); - text_checkbox = gtk_check_button_new_with_label ("Text"); - mute_checkbox = gtk_check_button_new_with_label ("Mute"); - download_checkbox = gtk_check_button_new_with_label ("Download"); - buffer_checkbox = gtk_check_button_new_with_label ("Buffer"); - volume_label = gtk_label_new ("Volume"); - volume_spinbutton = gtk_spin_button_new_with_range (0, 10.0, 0.1); - gtk_spin_button_set_value (GTK_SPIN_BUTTON (volume_spinbutton), 1.0); - gtk_box_pack_start (GTK_BOX (boxes), video_checkbox, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (boxes), audio_checkbox, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (boxes), text_checkbox, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (boxes), vis_checkbox, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (boxes), mute_checkbox, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (boxes), download_checkbox, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (boxes), buffer_checkbox, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (boxes), volume_label, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (boxes), volume_spinbutton, TRUE, TRUE, 2); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (vis_checkbox), FALSE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (audio_checkbox), TRUE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (video_checkbox), TRUE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (text_checkbox), TRUE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (mute_checkbox), FALSE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (download_checkbox), FALSE); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (buffer_checkbox), FALSE); - g_signal_connect (G_OBJECT (vis_checkbox), "toggled", - G_CALLBACK (vis_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (audio_checkbox), "toggled", - G_CALLBACK (audio_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (video_checkbox), "toggled", - G_CALLBACK (video_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (text_checkbox), "toggled", - G_CALLBACK (text_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (mute_checkbox), "toggled", - G_CALLBACK (mute_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (download_checkbox), "toggled", - G_CALLBACK (download_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (buffer_checkbox), "toggled", - G_CALLBACK (buffer_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (volume_spinbutton), "value_changed", - G_CALLBACK (volume_spinbutton_changed_cb), pipeline); - /* playbin2 panel for snapshot */ - boxes2 = gtk_hbox_new (FALSE, 0); - shot_button = gtk_button_new_from_stock (GTK_STOCK_SAVE); - gtk_widget_set_tooltip_text (shot_button, - "save a screenshot .png in the current directory"); - g_signal_connect (G_OBJECT (shot_button), "clicked", G_CALLBACK (shot_cb), - pipeline); - vis_combo = gtk_combo_box_new_text (); - g_signal_connect (G_OBJECT (vis_combo), "changed", - G_CALLBACK (vis_combo_cb), pipeline); - gtk_widget_set_sensitive (vis_combo, FALSE); - gtk_box_pack_start (GTK_BOX (boxes2), shot_button, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (boxes2), vis_combo, TRUE, TRUE, 2); - - /* fill the vis combo box and the array of factories */ - init_visualization_features (); - } else { - panel = boxes = boxes2 = NULL; - } - - /* do the packing stuff ... */ - gtk_window_set_default_size (GTK_WINDOW (window), 250, 96); - /* FIXME: can we avoid this for audio only? */ - gtk_widget_set_size_request (GTK_WIDGET (video_window), -1, - DEFAULT_VIDEO_HEIGHT); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_box_pack_start (GTK_BOX (vbox), video_window, TRUE, TRUE, 2); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), flagtable, FALSE, FALSE, 2); - gtk_table_attach_defaults (GTK_TABLE (flagtable), accurate_checkbox, 0, 1, 0, - 1); - gtk_table_attach_defaults (GTK_TABLE (flagtable), flush_checkbox, 1, 2, 0, 1); - gtk_table_attach_defaults (GTK_TABLE (flagtable), loop_checkbox, 2, 3, 0, 1); - gtk_table_attach_defaults (GTK_TABLE (flagtable), key_checkbox, 0, 1, 1, 2); - gtk_table_attach_defaults (GTK_TABLE (flagtable), scrub_checkbox, 1, 2, 1, 2); - gtk_table_attach_defaults (GTK_TABLE (flagtable), play_scrub_checkbox, 2, 3, - 1, 2); - gtk_table_attach_defaults (GTK_TABLE (flagtable), skip_checkbox, 3, 4, 0, 1); - gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_label, 4, 5, 0, 1); - gtk_table_attach_defaults (GTK_TABLE (flagtable), rate_spinbutton, 4, 5, 1, - 2); - if (panel && boxes && boxes2) { - expander = gtk_expander_new ("playbin2 options"); - pb2vbox = gtk_vbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (pb2vbox), panel, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (pb2vbox), boxes, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (pb2vbox), boxes2, FALSE, FALSE, 2); - gtk_container_add (GTK_CONTAINER (expander), pb2vbox); - gtk_box_pack_start (GTK_BOX (vbox), expander, FALSE, FALSE, 2); - } - gtk_box_pack_start (GTK_BOX (vbox), step, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (vbox), hscale, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (vbox), statusbar, FALSE, FALSE, 2); - - /* connect things ... */ - g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), - pipeline); - g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), - pipeline); - g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), - pipeline); - g_signal_connect (G_OBJECT (accurate_checkbox), "toggled", - G_CALLBACK (accurate_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (key_checkbox), "toggled", - G_CALLBACK (key_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (loop_checkbox), "toggled", - G_CALLBACK (loop_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (flush_checkbox), "toggled", - G_CALLBACK (flush_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (scrub_checkbox), "toggled", - G_CALLBACK (scrub_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (play_scrub_checkbox), "toggled", - G_CALLBACK (play_scrub_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (skip_checkbox), "toggled", - G_CALLBACK (skip_toggle_cb), pipeline); - g_signal_connect (G_OBJECT (rate_spinbutton), "value_changed", - G_CALLBACK (rate_spinbutton_changed_cb), pipeline); - - g_signal_connect (G_OBJECT (window), "delete-event", delete_event_cb, NULL); - - /* show the gui. */ - gtk_widget_show_all (window); - - /* realize window now so that the video window gets created and we can - * obtain its XID before the pipeline is started up and the videosink - * asks for the XID of the window to render onto */ - gtk_widget_realize (window); - - /* we should have the XID now */ - g_assert (embed_xid != 0); - - if (verbose) { - g_signal_connect (pipeline, "deep_notify", - G_CALLBACK (gst_object_default_deep_notify), NULL); - } - - connect_bus_signals (pipeline); - gtk_main (); - - g_print ("NULL pipeline\n"); - gst_element_set_state (pipeline, GST_STATE_NULL); - - g_print ("free pipeline\n"); - gst_object_unref (pipeline); - - g_list_foreach (paths, (GFunc) g_free, NULL); - g_list_free (paths); - - return 0; -} diff --git a/tests/examples/seek/stepping.c b/tests/examples/seek/stepping.c deleted file mode 100644 index 6f6997fc..00000000 --- a/tests/examples/seek/stepping.c +++ /dev/null @@ -1,124 +0,0 @@ -/* GStreamer - * - * stepping.c: stepping sample application - * - * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdlib.h> -#include <math.h> - -#include <gst/gst.h> - -static GMainLoop *loop; - -static gdouble period = 0.0; - -static gboolean -do_step (GstElement * bin) -{ - gdouble length; - - length = sin (period); - - period += M_PI / 40; - - length += 1.1; - length *= 100 * GST_MSECOND; - - gst_element_send_event (bin, - gst_event_new_step (GST_FORMAT_TIME, length, 1.0, TRUE, FALSE)); - - return FALSE; -} - -static gboolean -handle_message (GstBus * bus, GstMessage * message, gpointer data) -{ - GstElement *bin = GST_ELEMENT_CAST (data); - - switch (message->type) { - case GST_MESSAGE_EOS: - g_message ("got EOS"); - g_main_loop_quit (loop); - break; - case GST_MESSAGE_WARNING: - case GST_MESSAGE_ERROR: - { - GError *gerror; - gchar *debug; - - if (message->type == GST_MESSAGE_ERROR) - gst_message_parse_error (message, &gerror, &debug); - else - gst_message_parse_warning (message, &gerror, &debug); - - gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); - g_error_free (gerror); - g_free (debug); - g_main_loop_quit (loop); - break; - } - case GST_MESSAGE_ASYNC_DONE: - g_timeout_add (40, (GSourceFunc) do_step, bin); - break; - default: - break; - } - return TRUE; -} - -int -main (int argc, char *argv[]) -{ - GstElement *bin; - GstBus *bus; - - gst_init (&argc, &argv); - - if (argc < 2) { - g_print ("usage: %s <uri>\n", argv[0]); - return -1; - } - - /* create a new bin to hold the elements */ - bin = gst_element_factory_make ("playbin2", "bin"); - g_assert (bin); - g_object_set (bin, "uri", argv[1], NULL); - - bus = gst_pipeline_get_bus (GST_PIPELINE (bin)); - gst_bus_add_watch (bus, handle_message, bin); - - /* go to the PAUSED state and wait for preroll */ - g_message ("prerolling first frame"); - gst_element_set_state (bin, GST_STATE_PAUSED); - gst_element_get_state (bin, NULL, NULL, -1); - - loop = g_main_loop_new (NULL, TRUE); - g_main_loop_run (loop); - - g_message ("finished"); - - /* stop the bin */ - gst_element_set_state (bin, GST_STATE_NULL); - - g_main_loop_unref (loop); - gst_object_unref (bus); - - exit (0); -} diff --git a/tests/examples/seek/stepping2.c b/tests/examples/seek/stepping2.c deleted file mode 100644 index 8cea180e..00000000 --- a/tests/examples/seek/stepping2.c +++ /dev/null @@ -1,142 +0,0 @@ -/* GStreamer - * - * stepping.c: stepping sample application - * - * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdlib.h> -#include <math.h> - -#include <gst/gst.h> - -static GMainLoop *loop; - -static gdouble period = 0.0; - -static void -do_step (GstElement * bin) -{ - gdouble rate; - - rate = sin (period); - - period += M_PI / 150; - - rate += 1.2; - - gst_element_send_event (bin, - gst_event_new_step (GST_FORMAT_TIME, 40 * GST_MSECOND, rate, FALSE, - FALSE)); -} - -static void -handle_sync_message (GstBus * bus, GstMessage * message, gpointer data) -{ - GstElement *bin; - - bin = GST_ELEMENT_CAST (data); - - switch (message->type) { - case GST_MESSAGE_STEP_DONE: - do_step (bin); - break; - default: - break; - } -} - -static void -handle_message (GstBus * bus, GstMessage * message, gpointer data) -{ - switch (message->type) { - case GST_MESSAGE_EOS: - g_message ("got EOS"); - g_main_loop_quit (loop); - break; - case GST_MESSAGE_WARNING: - case GST_MESSAGE_ERROR: - { - GError *gerror; - gchar *debug; - - if (message->type == GST_MESSAGE_ERROR) - gst_message_parse_error (message, &gerror, &debug); - else - gst_message_parse_warning (message, &gerror, &debug); - - gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); - g_error_free (gerror); - g_free (debug); - if (message->type == GST_MESSAGE_ERROR) - g_main_loop_quit (loop); - break; - } - default: - break; - } -} - -int -main (int argc, char *argv[]) -{ - GstElement *bin; - GstBus *bus; - - gst_init (&argc, &argv); - - if (argc < 2) { - g_print ("usage: %s <uri>\n", argv[0]); - return -1; - } - - /* create a new bin to hold the elements */ - bin = gst_element_factory_make ("playbin2", "bin"); - g_assert (bin); - g_object_set (bin, "uri", argv[1], NULL); - - bus = gst_pipeline_get_bus (GST_PIPELINE (bin)); - gst_bus_add_signal_watch (bus); - gst_bus_enable_sync_message_emission (bus); - - g_signal_connect (bus, "message", (GCallback) handle_message, bin); - g_signal_connect (bus, "sync-message", (GCallback) handle_sync_message, bin); - - /* go to the PAUSED state and wait for preroll */ - g_message ("prerolling first frame"); - gst_element_set_state (bin, GST_STATE_PAUSED); - gst_element_get_state (bin, NULL, NULL, -1); - - /* queue step */ - do_step (bin); - - gst_element_set_state (bin, GST_STATE_PLAYING); - - loop = g_main_loop_new (NULL, TRUE); - g_main_loop_run (loop); - - g_message ("finished"); - - /* stop the bin */ - gst_element_set_state (bin, GST_STATE_NULL); - - g_main_loop_unref (loop); - gst_object_unref (bus); - - exit (0); -} diff --git a/tests/examples/snapshot/.gitignore b/tests/examples/snapshot/.gitignore deleted file mode 100644 index a701b4cb..00000000 --- a/tests/examples/snapshot/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -snapshot -snapshot.png diff --git a/tests/examples/snapshot/Makefile.am b/tests/examples/snapshot/Makefile.am deleted file mode 100644 index 16830eef..00000000 --- a/tests/examples/snapshot/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -if HAVE_GTK -GTK_EXAMPLES=snapshot -endif - -examples = $(GTK_EXAMPLES) - -noinst_PROGRAMS = $(examples) - -LIBS = $(GST_LIBS) $(GTK_LIBS) -AM_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS) diff --git a/tests/examples/snapshot/snapshot.c b/tests/examples/snapshot/snapshot.c deleted file mode 100644 index b3071113..00000000 --- a/tests/examples/snapshot/snapshot.c +++ /dev/null @@ -1,151 +0,0 @@ -/* GStreamer snapshot example - * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <gst/gst.h> -#include <gtk/gtk.h> - -#include <stdlib.h> - -#define CAPS "video/x-raw-rgb,width=160,pixel-aspect-ratio=1/1,bpp=(int)24,depth=(int)24,endianness=(int)4321,red_mask=(int)0xff0000, green_mask=(int)0x00ff00, blue_mask=(int)0x0000ff" - -int -main (int argc, char *argv[]) -{ - GstElement *pipeline, *sink; - gint width, height; - GstBuffer *buffer; - gchar *descr; - GError *error = NULL; - GdkPixbuf *pixbuf; - gint64 duration, position; - GstFormat format; - GstStateChangeReturn ret; - gboolean res; - - gst_init (&argc, &argv); - - if (argc != 2) { - g_print ("usage: %s <uri>\n Writes snapshot.png in the current directory", - argv[0]); - exit (-1); - } - - /* create a new pipeline */ - descr = - g_strdup_printf ("uridecodebin uri=%s ! ffmpegcolorspace ! videoscale ! " - " appsink name=sink caps=\"" CAPS "\"", argv[1]); - pipeline = gst_parse_launch (descr, &error); - - if (error != NULL) { - g_print ("could not construct pipeline: %s", error->message); - g_error_free (error); - exit (-1); - } - - /* get sink */ - sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink"); - - /* set to PAUSED to make the first frame arrive in the sink */ - ret = gst_element_set_state (pipeline, GST_STATE_PAUSED); - switch (ret) { - case GST_STATE_CHANGE_FAILURE: - g_print ("failed to play the file\n"); - exit (-1); - case GST_STATE_CHANGE_NO_PREROLL: - /* for live sources, we need to set the pipeline to PLAYING before we can - * receive a buffer. We don't do that yet */ - g_print ("live sources not supported yet\n"); - exit (-1); - default: - break; - } - /* This can block for up to 5 seconds. If your machine is really overloaded, - * it might time out before the pipeline prerolled and we generate an error. A - * better way is to run a mainloop and catch errors there. */ - ret = gst_element_get_state (pipeline, NULL, NULL, 5 * GST_SECOND); - if (ret == GST_STATE_CHANGE_FAILURE) { - g_print ("failed to play the file\n"); - exit (-1); - } - - /* get the duration */ - format = GST_FORMAT_TIME; - gst_element_query_duration (pipeline, &format, &duration); - - if (duration != -1) - /* we have a duration, seek to 5% */ - position = duration * 5 / 100; - else - /* no duration, seek to 1 second, this could EOS */ - position = 1 * GST_SECOND; - - /* seek to the a position in the file. Most files have a black first frame so - * by seeking to somewhere else we have a bigger chance of getting something - * more interesting. An optimisation would be to detect black images and then - * seek a little more */ - gst_element_seek_simple (pipeline, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, - position); - - /* get the preroll buffer from appsink, this block untils appsink really - * prerolls */ - g_signal_emit_by_name (sink, "pull-preroll", &buffer, NULL); - - /* if we have a buffer now, convert it to a pixbuf. It's possible that we - * don't have a buffer because we went EOS right away or had an error. */ - if (buffer) { - GstCaps *caps; - GstStructure *s; - - /* get the snapshot buffer format now. We set the caps on the appsink so - * that it can only be an rgb buffer. The only thing we have not specified - * on the caps is the height, which is dependant on the pixel-aspect-ratio - * of the source material */ - caps = GST_BUFFER_CAPS (buffer); - if (!caps) { - g_print ("could not get snapshot format\n"); - exit (-1); - } - s = gst_caps_get_structure (caps, 0); - - /* we need to get the final caps on the buffer to get the size */ - res = gst_structure_get_int (s, "width", &width); - res |= gst_structure_get_int (s, "height", &height); - if (!res) { - g_print ("could not get snapshot dimension\n"); - exit (-1); - } - - /* create pixmap from buffer and save, gstreamer video buffers have a stride - * that is rounded up to the nearest multiple of 4 */ - pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer), - GDK_COLORSPACE_RGB, FALSE, 8, width, height, - GST_ROUND_UP_4 (width * 3), NULL, NULL); - - /* save the pixbuf */ - gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL); - } else { - g_print ("could not make snapshot\n"); - } - - /* cleanup and exit */ - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - - exit (0); -} diff --git a/tests/examples/v4l/.gitignore b/tests/examples/v4l/.gitignore deleted file mode 100644 index da0c4eb8..00000000 --- a/tests/examples/v4l/.gitignore +++ /dev/null @@ -1 +0,0 @@ -probe diff --git a/tests/examples/v4l/Makefile.am b/tests/examples/v4l/Makefile.am deleted file mode 100644 index 6132cdc0..00000000 --- a/tests/examples/v4l/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -noinst_PROGRAMS = probe - -probe_SOURCES = probe.c -probe_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) \ - $(GST_BASE_CFLAGS) $(GST_CFLAGS) -probe_LDFLAGS = \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la \ - $(GST_PLUGINS_BASE_LIBS) \ - $(GST_BASE_LIBS) $(GST_LIBS) - diff --git a/tests/examples/v4l/probe.c b/tests/examples/v4l/probe.c deleted file mode 100644 index 435aeac9..00000000 --- a/tests/examples/v4l/probe.c +++ /dev/null @@ -1,85 +0,0 @@ -/* GStreamer - * Copyright (C) 2009 Filippo Argiolas <filippo.argiolas@gmail.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <stdlib.h> -#include <gst/gst.h> -#include <gst/interfaces/propertyprobe.h> - -int -main (int argc, char *argv[]) -{ - GstElement *src, *sink; - GstElement *bin; - GstPropertyProbe *probe = NULL; - const GParamSpec *pspec = NULL; - GValueArray *array = NULL; - gint i, ret; - GValue *value; - const gchar *device; - gchar *name; - guint flags; - - gst_init (&argc, &argv); - - bin = gst_pipeline_new ("pipeline"); - g_assert (bin); - - src = gst_element_factory_make ("v4lsrc", "v4l_source"); - g_assert (src); - sink = gst_element_factory_make ("fakesink", "fake_sink"); - g_assert (sink); - - /* add objects to the main pipeline */ - gst_bin_add_many (GST_BIN (bin), src, sink, NULL); - /* link the elements */ - gst_element_link_many (src, sink, NULL); - - /* probe devices */ - g_print ("Probing devices with propertyprobe...\n"); - probe = GST_PROPERTY_PROBE (src); - pspec = gst_property_probe_get_property (probe, "device"); - array = gst_property_probe_probe_and_get_values (probe, pspec); - - if (!array) { - g_print ("No device found\n"); - exit (1); - } - - for (i = 0; i < array->n_values; i++) { - value = g_value_array_get_nth (array, i); - device = g_value_get_string (value); - g_print ("Device: %s\n", device); - g_object_set_property (G_OBJECT (src), "device", value); - gst_element_set_state (bin, GST_STATE_READY); - ret = gst_element_get_state (bin, NULL, NULL, 10 * GST_SECOND); - if (ret != GST_STATE_CHANGE_SUCCESS) { - g_print ("Couldn't set STATE_READY\n"); - continue; - } - g_object_get (G_OBJECT (src), "device-name", &name, NULL); - g_print ("Name: %s\n", name); - g_free (name); - g_object_get (G_OBJECT (src), "flags", &flags, NULL); - g_print ("Flags: 0x%08X\n", flags); - gst_element_set_state (bin, GST_STATE_NULL); - g_print ("\n"); - } - - exit (0); -} diff --git a/tests/examples/volume/.gitignore b/tests/examples/volume/.gitignore deleted file mode 100644 index 4833bbb0..00000000 --- a/tests/examples/volume/.gitignore +++ /dev/null @@ -1 +0,0 @@ -volume diff --git a/tests/examples/volume/Makefile.am b/tests/examples/volume/Makefile.am deleted file mode 100644 index c4da3371..00000000 --- a/tests/examples/volume/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -if HAVE_GTK -noinst_PROGRAMS = volume -volume_SOURCES = volume.c -volume_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS) -D_GNU_SOURCE -volume_LDFLAGS = $(GTK_LIBS) $(GST_LIBS) $(LIBM) -endif diff --git a/tests/examples/volume/volume.c b/tests/examples/volume/volume.c deleted file mode 100644 index 59e4981f..00000000 --- a/tests/examples/volume/volume.c +++ /dev/null @@ -1,172 +0,0 @@ -/* GStreamer - * - * volume.c: sample application to change the volume of a pipeline - * - * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <math.h> - -#include <gst/gst.h> -#include <gtk/gtk.h> - -/* global pointer for the scale widget */ -GtkWidget *elapsed; -GtkWidget *scale; - -#ifndef M_LN10 -#define M_LN10 (log(10.0)) -#endif - -static void -value_changed_callback (GtkWidget * widget, GstElement * volume) -{ - gdouble value; - gdouble level; - - value = gtk_range_get_value (GTK_RANGE (widget)); - level = exp (value / 20.0 * M_LN10); - g_print ("Value: %f dB, level: %f\n", value, level); - g_object_set (volume, "volume", level, NULL); -} - -static void -setup_gui (GstElement * volume) -{ - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *label, *hbox; - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - g_signal_connect (window, "destroy", gtk_main_quit, NULL); - - vbox = gtk_vbox_new (TRUE, 0); - gtk_container_add (GTK_CONTAINER (window), vbox); - - /* elapsed widget */ - hbox = gtk_hbox_new (TRUE, 0); - label = gtk_label_new ("Elapsed"); - elapsed = gtk_label_new ("0.000"); - gtk_container_add (GTK_CONTAINER (hbox), label); - gtk_container_add (GTK_CONTAINER (hbox), elapsed); - gtk_container_add (GTK_CONTAINER (vbox), hbox); - - /* volume */ - hbox = gtk_hbox_new (TRUE, 0); - label = gtk_label_new ("volume"); - gtk_container_add (GTK_CONTAINER (hbox), label); - scale = gtk_hscale_new_with_range (-90.0, 10.0, 0.2); - gtk_range_set_value (GTK_RANGE (scale), 0.0); - gtk_widget_set_size_request (scale, 100, -1); - gtk_container_add (GTK_CONTAINER (hbox), scale); - gtk_container_add (GTK_CONTAINER (vbox), hbox); - g_signal_connect (scale, "value-changed", - G_CALLBACK (value_changed_callback), volume); - - gtk_widget_show_all (GTK_WIDGET (window)); -} - -static void -message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline) -{ - const GstStructure *s; - - s = gst_message_get_structure (message); - g_print ("message from \"%s\" (%s): ", - GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))), - gst_message_type_get_name (GST_MESSAGE_TYPE (message))); - if (s) { - gchar *sstr; - - sstr = gst_structure_to_string (s); - g_print ("%s\n", sstr); - g_free (sstr); - } else { - g_print ("no message details\n"); - } -} - -static void -eos_message_received (GstBus * bus, GstMessage * message, - GstPipeline * pipeline) -{ - message_received (bus, message, pipeline); - gtk_main_quit (); -} - -int -main (int argc, char *argv[]) -{ - - GstElement *pipeline = NULL; - -#ifndef GST_DISABLE_PARSE - GError *error = NULL; -#endif - GstElement *volume; - GstBus *bus; - -#ifdef GST_DISABLE_PARSE - g_print ("GStreamer was built without pipeline parsing capabilities.\n"); - g_print - ("Please rebuild GStreamer with pipeline parsing capabilities activated to use this example.\n"); - return 1; -#else - gst_init (&argc, &argv); - gtk_init (&argc, &argv); - - pipeline = gst_parse_launchv ((const gchar **) &argv[1], &error); - if (error) { - g_print ("pipeline could not be constructed: %s\n", error->message); - g_print ("Please give a complete pipeline with a 'volume' element.\n"); - g_print ("Example: audiotestsrc ! volume ! %s\n", DEFAULT_AUDIOSINK); - g_error_free (error); - return 1; - } -#endif - volume = gst_bin_get_by_name (GST_BIN (pipeline), "volume0"); - if (volume == NULL) { - g_print ("Please give a pipeline with a 'volume' element in it\n"); - return 1; - } - - /* setup message handling */ - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - g_signal_connect (bus, "message::error", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::warning", (GCallback) message_received, - pipeline); - g_signal_connect (bus, "message::eos", (GCallback) eos_message_received, - pipeline); - - /* setup GUI */ - setup_gui (volume); - - /* go to main loop */ - gst_element_set_state (pipeline, GST_STATE_PLAYING); - gtk_main (); - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - - return 0; -} diff --git a/tests/icles/.gitignore b/tests/icles/.gitignore deleted file mode 100644 index d8083fdb..00000000 --- a/tests/icles/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -stress-playbin -stress-xoverlay -test-textoverlay -test-scale -test-box -test-colorkey -playbin-text diff --git a/tests/icles/Makefile.am b/tests/icles/Makefile.am deleted file mode 100644 index fa49403c..00000000 --- a/tests/icles/Makefile.am +++ /dev/null @@ -1,49 +0,0 @@ -if USE_X -X_TESTS = stress-xoverlay - -stress_xoverlay_SOURCES = stress-xoverlay.c -stress_xoverlay_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(X_CFLAGS) -stress_xoverlay_LDADD = $(GST_LIBS) $(X_LIBS) $(LIBM) \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la - -if HAVE_GTK_X11 -X_TESTS += test-colorkey - -test_colorkey_SOURCES = test-colorkey.c -test_colorkey_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) $(X_CFLAGS) $(GTK_CFLAGS) -test_colorkey_LDADD = $(GST_LIBS) $(X_LIBS) $(LIBM) $(GTK_LIBS) \ - $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-$(GST_MAJORMINOR).la -endif - -else -X_TESTS = -endif - -if USE_PANGO -PANGO_TESTS = test-textoverlay - -test_textoverlay_SOURCES = test-textoverlay.c -test_textoverlay_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -test_textoverlay_LDADD = $(GST_LIBS) $(LIBM) - -else -PANGO_TESTS = -endif - -stress_playbin_SOURCES = stress-playbin.c -stress_playbin_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -stress_playbin_LDADD = $(GST_LIBS) $(LIBM) - -test_scale_SOURCES = test-scale.c -test_scale_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -test_scale_LDADD = $(GST_LIBS) $(LIBM) - -test_box_SOURCES = test-box.c -test_box_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -test_box_LDADD = $(GST_LIBS) $(LIBM) - -playbin_text_SOURCES = playbin-text.c -playbin_text_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS) -playbin_text_LDADD = $(GST_LIBS) $(LIBM) - -noinst_PROGRAMS = $(X_TESTS) $(PANGO_TESTS) stress-playbin test-scale test-box playbin-text diff --git a/tests/icles/playbin-text.c b/tests/icles/playbin-text.c deleted file mode 100644 index a9868048..00000000 --- a/tests/icles/playbin-text.c +++ /dev/null @@ -1,174 +0,0 @@ -/* GStreamer - * - * Copyright (C) 2009 Wim Taymans <wim.taymans@gmail.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> - -#include <stdio.h> -#include <string.h> -#include <stdlib.h> - -typedef struct _App App; - -struct _App -{ - GstElement *playbin; - GstElement *textsink; - - GMainLoop *loop; -}; - -App s_app; - -static gboolean -bus_message (GstBus * bus, GstMessage * message, App * app) -{ - GST_DEBUG ("got message %s", - gst_message_type_get_name (GST_MESSAGE_TYPE (message))); - - switch (GST_MESSAGE_TYPE (message)) { - case GST_MESSAGE_ERROR: - { - GError *gerror; - gchar *debug; - - gst_message_parse_error (message, &gerror, &debug); - gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); - g_error_free (gerror); - g_free (debug); - - g_main_loop_quit (app->loop); - break; - } - case GST_MESSAGE_WARNING: - { - GError *gerror; - gchar *debug; - - gst_message_parse_warning (message, &gerror, &debug); - gst_object_default_error (GST_MESSAGE_SRC (message), gerror, debug); - g_error_free (gerror); - g_free (debug); - - g_main_loop_quit (app->loop); - break; - } - case GST_MESSAGE_EOS: - g_message ("received EOS"); - g_main_loop_quit (app->loop); - break; - default: - break; - } - return TRUE; -} - -static void -have_subtitle (GstElement * appsink, App * app) -{ - GstBuffer *buffer; - - /* get the buffer, we can also wakeup the mainloop to get the subtitle from - * appsink in the mainloop */ - g_signal_emit_by_name (appsink, "pull-buffer", &buffer); - - if (buffer) { - guint8 *data; - guint size; - GstFormat format; - gint64 position; - GstClock *clock; - GstClockTime base_time, running_time; - - format = GST_FORMAT_TIME; - gst_element_query_position (appsink, &format, &position); - - clock = gst_element_get_clock (appsink); - base_time = gst_element_get_base_time (appsink); - - running_time = gst_clock_get_time (clock) - base_time; - - gst_object_unref (clock); - - g_message ("received a subtitle at position %" GST_TIME_FORMAT - ", running_time %" GST_TIME_FORMAT, GST_TIME_ARGS (position), - GST_TIME_ARGS (running_time)); - - data = GST_BUFFER_DATA (buffer); - size = GST_BUFFER_SIZE (buffer); - - gst_util_dump_mem (data, size); - } -} - -int -main (int argc, char *argv[]) -{ - App *app = &s_app; - GstBus *bus; - - gst_init (&argc, &argv); - - if (argc < 2) { - g_print ("usage: %s <filename>\n", argv[0]); - return -1; - } - - /* create a mainloop to get messages */ - app->loop = g_main_loop_new (NULL, TRUE); - - app->playbin = gst_element_factory_make ("playbin2", NULL); - g_assert (app->playbin); - - /* set appsink to get the subtitles */ - app->textsink = gst_element_factory_make ("appsink", "subtitle_sink"); - g_object_set (G_OBJECT (app->textsink), "emit-signals", TRUE, NULL); - g_object_set (G_OBJECT (app->textsink), "ts-offset", 0 * GST_SECOND, NULL); - g_signal_connect (app->textsink, "new-buffer", G_CALLBACK (have_subtitle), - app); - - g_object_set (G_OBJECT (app->playbin), "text-sink", app->textsink, NULL); - - bus = gst_pipeline_get_bus (GST_PIPELINE (app->playbin)); - - /* add watch for messages */ - gst_bus_add_watch (bus, (GstBusFunc) bus_message, app); - - /* set to read from appsrc */ - g_object_set (app->playbin, "uri", argv[1], NULL); - - /* go to playing and wait in a mainloop. */ - gst_element_set_state (app->playbin, GST_STATE_PLAYING); - - /* this mainloop is stopped when we receive an error or EOS */ - g_main_loop_run (app->loop); - - g_message ("stopping"); - - gst_element_set_state (app->playbin, GST_STATE_NULL); - - gst_object_unref (bus); - g_main_loop_unref (app->loop); - - return 0; -} diff --git a/tests/icles/stress-playbin.c b/tests/icles/stress-playbin.c deleted file mode 100644 index 33272a26..00000000 --- a/tests/icles/stress-playbin.c +++ /dev/null @@ -1,156 +0,0 @@ -#include <gst/gst.h> -#include <stdlib.h> -#include <string.h> - -#define TEST_RUNTIME 120.0 /* how long to run the test, in seconds */ - -static void -play_file (const gchar * bin, const gint delay, const gchar * uri) -{ - GstStateChangeReturn sret; - GstMessage *msg; - GstElement *play; - guint wait_nanosecs; - - play = gst_element_factory_make (bin, "playbin"); - - g_object_set (play, "uri", uri, NULL); - g_printerr ("Playing %s\n", uri); - sret = gst_element_set_state (play, GST_STATE_PLAYING); - if (sret != GST_STATE_CHANGE_ASYNC && sret != GST_STATE_CHANGE_SUCCESS) { - g_printerr ("ERROR: state change failed, sret=%d\n", sret); - goto next; - } - - wait_nanosecs = g_random_int_range (0, GST_MSECOND * delay); - msg = gst_bus_poll (GST_ELEMENT_BUS (play), - GST_MESSAGE_ERROR | GST_MESSAGE_EOS, wait_nanosecs); - if (msg) { - switch (GST_MESSAGE_TYPE (msg)) { - case GST_MESSAGE_ERROR: - { - GError *gerror; - gchar *debug; - - gst_message_parse_error (msg, &gerror, &debug); - gst_object_default_error (GST_MESSAGE_SRC (msg), gerror, debug); - g_error_free (gerror); - g_free (debug); - break; - } - case GST_MESSAGE_EOS: - g_printerr ("Got EOS\n"); - break; - default: - g_printerr ("Got unexpected %s messge\n", GST_MESSAGE_TYPE_NAME (msg)); - break; - } - gst_message_unref (msg); - goto next; - } - - /* on to the next one */ - g_print ("."); - -next: - gst_element_set_state (play, GST_STATE_NULL); - gst_object_unref (play); -} - -static void -check_arg (GPtrArray * files, const gchar * arg) -{ - GDir *dir; - - if ((dir = g_dir_open (arg, 0, NULL))) { - const gchar *entry; - - while ((entry = g_dir_read_name (dir))) { - gchar *path; - - path = g_strconcat (arg, G_DIR_SEPARATOR_S, entry, NULL); - check_arg (files, path); - g_free (path); - } - - g_dir_close (dir); - return; - } else if (g_file_test (arg, G_FILE_TEST_EXISTS)) { - /* hack: technically an URI is not just file:// + path, but it'll do here */ - g_ptr_array_add (files, g_strdup_printf ("file://%s", arg)); - } -} - -int -main (int argc, char **argv) -{ - GPtrArray *files; - gchar **args = NULL; - guint num, i; - GError *err = NULL; - gchar *bin = NULL; - gint run = 100; - GOptionContext *ctx; - GOptionEntry options[] = { - {"bin", '\000', 0, G_OPTION_ARG_STRING, &bin, "playbin factory name", NULL}, - {"runtime", '\000', 0, G_OPTION_ARG_INT, &run, "maximum play time (ms)", - NULL}, - {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL}, - {NULL} - }; - GTimer *timer; - - if (!g_thread_supported ()) - g_thread_init (NULL); - - ctx = g_option_context_new ("FILES OR DIRECTORIES WITH AUDIO FILES"); - g_option_context_add_main_entries (ctx, options, NULL); - g_option_context_add_group (ctx, gst_init_get_option_group ()); - if (!g_option_context_parse (ctx, &argc, &argv, &err)) { - g_print ("Error initializing: %s\n", GST_STR_NULL (err->message)); - exit (1); - } - g_option_context_free (ctx); - - if (!bin) - bin = "playbin"; - - if (strcmp (bin, "playbin") && strcmp (bin, "playbin2")) { - g_print ("Please provide a valid playbin argument; playbin | playbin2"); - return 1; - } - if (args == NULL || *args == NULL) { - g_print ("Please provide one or more directories with audio files\n\n"); - return 1; - } - - files = g_ptr_array_new (); - - num = g_strv_length (args); - for (i = 0; i < num; ++i) { - if (g_path_is_absolute (args[i])) { - check_arg (files, args[i]); - } else { - g_warning ("Argument '%s' is not an absolute file path", args[i]); - } - } - - if (files->len == 0) { - g_print ("Did not find any files\n\n"); - return 1; - } - - timer = g_timer_new (); - - while (g_timer_elapsed (timer, NULL) < TEST_RUNTIME) { - gint32 idx; - - idx = g_random_int_range (0, files->len); - play_file (bin, run, (const gchar *) g_ptr_array_index (files, idx)); - } - - g_strfreev (args); - g_timer_destroy (timer); - - return 0; -} diff --git a/tests/icles/stress-xoverlay.c b/tests/icles/stress-xoverlay.c deleted file mode 100644 index 4a7a3c7a..00000000 --- a/tests/icles/stress-xoverlay.c +++ /dev/null @@ -1,247 +0,0 @@ -/* GStreamer - * Copyright (C) <2005> Julien Moutte <julien@moutte.net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> -#include <gst/interfaces/xoverlay.h> - -#include <X11/Xlib.h> -#include <X11/Xutil.h> - -#include <math.h> -#include <sys/time.h> - -static GMainLoop *loop; - -static Display *disp; -static Window root, win = 0; -static GC gc; -static gint width = 320, height = 240, x = 0, y = 0; -static gint disp_width, disp_height; - -static inline long -myclock (void) -{ - struct timeval tv; - - gettimeofday (&tv, NULL); - return (tv.tv_sec * 1000 + tv.tv_usec / 1000); -} - -static void -open_display (void) -{ - gint screen_num; - - disp = XOpenDisplay (NULL); - root = DefaultRootWindow (disp); - screen_num = DefaultScreen (disp); - disp_width = DisplayWidth (disp, screen_num); - disp_height = DisplayHeight (disp, screen_num); -} - -static void -close_display (void) -{ - XCloseDisplay (disp); -} - -static gboolean -resize_window (GstPipeline * pipeline) -{ - width = (sin (myclock () / 300.0) * 200) + 640; - height = (sin (myclock () / 300.0) * 200) + 480; - - XResizeWindow (disp, win, width, height); - - XSync (disp, FALSE); - - return TRUE; -} - -static gboolean -move_window (GstPipeline * pipeline) -{ - x += 5; - y = disp_height - height + (sin (myclock () / 300.0) * height); - if (x > disp_width) - x = 0; - - XMoveWindow (disp, win, x, y); - - XSync (disp, FALSE); - - return TRUE; -} - -static gboolean -toggle_events (GstXOverlay * ov) -{ - static gboolean events_toggled; - - gst_x_overlay_handle_events (ov, events_toggled); - - if (events_toggled) { - g_print ("Events are handled\n"); - events_toggled = FALSE; - } else { - g_print ("Events are NOT handled\n"); - events_toggled = TRUE; - } - - return TRUE; -} - -static gboolean -cycle_window (GstXOverlay * ov) -{ - XGCValues values; - Window old_win = win; - GC old_gc = gc; - - win = XCreateSimpleWindow (disp, root, 0, 0, width, height, 0, 0, 0); - - XSetWindowBackgroundPixmap (disp, win, None); - - gc = XCreateGC (disp, win, 0, &values); - - XMapRaised (disp, win); - - XSync (disp, FALSE); - - gst_x_overlay_set_xwindow_id (ov, win); - - if (old_win) { - XDestroyWindow (disp, old_win); - XFreeGC (disp, old_gc); - XSync (disp, FALSE); - } - - return TRUE; -} - -static GstBusSyncReply -create_window (GstBus * bus, GstMessage * message, GstPipeline * pipeline) -{ - const GstStructure *s; - GstXOverlay *ov = NULL; - - s = gst_message_get_structure (message); - if (s == NULL || !gst_structure_has_name (s, "prepare-xwindow-id")) { - return GST_BUS_PASS; - } - - ov = GST_X_OVERLAY (GST_MESSAGE_SRC (message)); - - g_print ("Creating our own window\n"); - - cycle_window (ov); - - g_timeout_add (50, (GSourceFunc) resize_window, pipeline); - g_timeout_add (50, (GSourceFunc) move_window, pipeline); - g_timeout_add (100, (GSourceFunc) cycle_window, ov); - g_timeout_add (2000, (GSourceFunc) toggle_events, ov); - - gst_message_unref (message); - return GST_BUS_DROP; -} - -#if 0 -static gboolean -terminate_playback (GstElement * pipeline) -{ - g_print ("Terminating playback\n"); - g_main_loop_quit (loop); - return FALSE; -} -#endif - -static gboolean -pause_playback (GstElement * pipeline) -{ - g_print ("Pausing playback\n"); - gst_element_set_state (pipeline, GST_STATE_PAUSED); - return FALSE; -} - -static gboolean -start_playback (GstElement * pipeline) -{ - g_print ("Starting playback\n"); - gst_element_set_state (pipeline, GST_STATE_PLAYING); - return FALSE; -} - -int -main (int argc, char **argv) -{ - GstElement *pipeline; - GstBus *bus; - -#ifndef GST_DISABLE_PARSE - GError *error = NULL; -#endif - - gst_init (&argc, &argv); - - if (argc != 2) { - g_print ("Usage: %s \"pipeline description with launch format\"\n", - argv[0]); - g_print ("The pipeline should contain an element implementing XOverlay.\n"); - g_print ("Example: %s \"videotestsrc ! ximagesink\"\n", argv[0]); - return -1; - } -#ifdef GST_DISABLE_PARSE - g_print ("GStreamer was built without pipeline parsing capabilities.\n"); - g_print - ("Please rebuild GStreamer with pipeline parsing capabilities activated to use this example.\n"); - return 1; -#else - pipeline = gst_parse_launch (argv[1], &error); - if (error) { - g_print ("Error while parsing pipeline description: %s\n", error->message); - return -1; - } -#endif - - loop = g_main_loop_new (NULL, FALSE); - - open_display (); - - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - gst_bus_set_sync_handler (bus, (GstBusSyncHandler) create_window, pipeline); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - /* We want to get out after */ - //g_timeout_add (500000, (GSourceFunc) terminate_playback, pipeline); - g_timeout_add (10000, (GSourceFunc) pause_playback, pipeline); - g_timeout_add (20000, (GSourceFunc) start_playback, pipeline); - - g_main_loop_run (loop); - - close_display (); - - g_main_loop_unref (loop); - - return 0; -} diff --git a/tests/icles/test-box.c b/tests/icles/test-box.c deleted file mode 100644 index 6d04e560..00000000 --- a/tests/icles/test-box.c +++ /dev/null @@ -1,144 +0,0 @@ -/* GStreamer interactive videoscale test - * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdlib.h> - -#include <gst/gst.h> - -#define CAPS " capsfilter caps=\"video/x-raw-yuv, format=(fourcc)I420, width=(int)640, height=(int)480\" " - -static GstElement * -make_pipeline (gint type) -{ - GstElement *result; - gchar *pstr; - - switch (type) { - case 0: - pstr = - g_strdup_printf ("videotestsrc ! " CAPS - " ! videobox name=box ! videoscale ! " CAPS - " ! ffmpegcolorspace ! ximagesink"); - break; - default: - return NULL; - } - - result = gst_parse_launch_full (pstr, NULL, GST_PARSE_FLAG_NONE, NULL); - g_print ("created test %d: \"%s\"\n", type, pstr); - g_free (pstr); - - return result; -} - -#define MAX_ROUND 100 - -int -main (int argc, char **argv) -{ - GstElement *pipe, *filter; - gint left, right; - gint top, bottom; - gint rdir, ldir; - gint tdir, bdir; - gint round, type, stop; - - gst_init (&argc, &argv); - - type = 0; - stop = -1; - - if (argc > 1) { - type = atoi (argv[1]); - stop = type + 1; - } - - while (TRUE) { - GstMessage *message; - - pipe = make_pipeline (type); - if (pipe == NULL) - break; - - filter = gst_bin_get_by_name (GST_BIN (pipe), "box"); - g_assert (filter); - - /* start with no borders or cropping */ - left = right = top = bottom = 0; - rdir = ldir = tdir = bdir = -10; - - for (round = 0; round < MAX_ROUND; round++) { - g_print ("box to %dx%d %dx%d (%d/%d) \r", left, right, top, bottom, - round, MAX_ROUND); - - g_object_set (filter, "left", left, "right", right, "top", top, "bottom", - bottom, NULL); - - if (round == 0) - gst_element_set_state (pipe, GST_STATE_PLAYING); - - left += ldir; - if (left >= 40) - ldir = -10; - else if (left < -30) - ldir = 10; - - right += rdir; - if (right >= 30) - rdir = -10; - else if (right < -20) - rdir = 10; - - top += tdir; - if (top >= 20) - tdir = -10; - else if (top < -30) - tdir = 10; - - bottom += bdir; - if (bottom >= 60) - bdir = -10; - else if (bottom < -40) - bdir = 10; - - message = - gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, - 50 * GST_MSECOND); - if (message) { - g_print ("got error \n"); - - gst_message_unref (message); - } - } - g_print ("test %d done \n", type); - - gst_object_unref (filter); - gst_element_set_state (pipe, GST_STATE_NULL); - gst_object_unref (pipe); - - type++; - if (type == stop) - break; - } - return 0; -} diff --git a/tests/icles/test-colorkey.c b/tests/icles/test-colorkey.c deleted file mode 100644 index b727e806..00000000 --- a/tests/icles/test-colorkey.c +++ /dev/null @@ -1,258 +0,0 @@ -/* GStreamer - * Copyright (C) <2008> Stefan Kost <ensonic@users.sf.net> - * - * test-colorkey: test manual colorkey handling - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdlib.h> -#include <string.h> - -#include <glib.h> -#include <gdk/gdkx.h> -#include <gtk/gtk.h> - -#include <gst/gst.h> -#include <gst/interfaces/xoverlay.h> -#include <gst/interfaces/propertyprobe.h> - -static GtkWidget *video_window = NULL; -static GstElement *sink = NULL; -static gulong embed_xid = 0; -static GdkGC *trans_gc = NULL; - -static void -redraw_overlay (GtkWidget * widget) -{ - gdk_draw_rectangle (widget->window, widget->style->white_gc, TRUE, - 0, 0, widget->allocation.width, widget->allocation.height); - - if (trans_gc) { - guint x, y; - guint h = widget->allocation.height * 0.75; - - gdk_draw_rectangle (widget->window, trans_gc, TRUE, - 0, 0, widget->allocation.width, h); - - for (y = h; y < widget->allocation.height; y++) { - for (x = 0; x < widget->allocation.width; x++) { - if (((x & 1) || (y & 1)) && (x & 1) != (y & 1)) { - gdk_draw_point (widget->window, trans_gc, x, y); - } - } - } - } -} - -static gboolean -handle_resize_cb (GtkWidget * widget, GdkEventConfigure * event, gpointer data) -{ - redraw_overlay (widget); - return FALSE; -} - -static gboolean -handle_expose_cb (GtkWidget * widget, GdkEventExpose * event, gpointer data) -{ - redraw_overlay (widget); - return FALSE; -} - -static void -realize_cb (GtkWidget * widget, gpointer data) -{ -#if GTK_CHECK_VERSION(2,18,0) - /* This is here just for pedagogical purposes, GDK_WINDOW_XID will call it - * as well */ - if (!gdk_window_ensure_native (widget->window)) - g_error ("Couldn't create native window needed for GstXOverlay!"); -#endif - - embed_xid = GDK_WINDOW_XID (video_window->window); - g_print ("Window realize: got XID %lu\n", embed_xid); -} - -static void -msg_state_changed (GstBus * bus, GstMessage * message, GstPipeline * pipeline) -{ - const GstStructure *s; - - s = gst_message_get_structure (message); - - /* We only care about state changed on the pipeline */ - if (s && GST_MESSAGE_SRC (message) == GST_OBJECT_CAST (pipeline)) { - GstState old, new, pending; - gint color; - - gst_message_parse_state_changed (message, &old, &new, &pending); - - /* When state of the pipeline changes to paused or playing we start updating scale */ - switch (GST_STATE_TRANSITION (old, new)) { - case GST_STATE_CHANGE_READY_TO_PAUSED: - g_object_get (G_OBJECT (sink), "colorkey", &color, NULL); - if (color != -1) { - GdkColor trans_color = { 0, - (color & 0xff0000) >> 8, - (color & 0xff00), - (color & 0xff) << 8 - }; - - trans_gc = gdk_gc_new (video_window->window); - gdk_gc_set_rgb_fg_color (trans_gc, &trans_color); - } - handle_resize_cb (video_window, NULL, NULL); - break; - default: - break; - } - } -} - -static void -window_closed (GtkWidget * widget, GdkEvent * event, gpointer user_data) -{ - GstElement *pipeline = user_data; - - g_print ("stopping\n"); - gtk_widget_hide_all (widget); - gst_element_set_state (pipeline, GST_STATE_NULL); - gtk_main_quit (); -} - -static gboolean -start_pipeline (gpointer user_data) -{ - GstElement *pipeline = GST_ELEMENT (user_data); - GstStateChangeReturn sret; - - sret = gst_element_set_state (pipeline, GST_STATE_PLAYING); - if (sret == GST_STATE_CHANGE_FAILURE) { - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - gtk_main_quit (); - } - return FALSE; -} - -int -main (int argc, char **argv) -{ - GtkWidget *window; - GstElement *pipeline, *src; - GstBus *bus; - GstStateChangeReturn sret; - GstPropertyProbe *probe; - GValueArray *arr; - - if (!g_thread_supported ()) - g_thread_init (NULL); - - gst_init (&argc, &argv); - gtk_init (&argc, &argv); - - /* prepare the pipeline */ - - pipeline = gst_pipeline_new ("xvoverlay"); - src = gst_element_factory_make ("videotestsrc", NULL); - sink = gst_element_factory_make ("xvimagesink", NULL); - gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL); - gst_element_link (src, sink); - -#define COLOR_GRAY 0x7F7F7F - - g_object_set (G_OBJECT (sink), "autopaint-colorkey", FALSE, - "force-aspect-ratio", TRUE, "draw-borders", FALSE, - "colorkey", COLOR_GRAY, NULL); - - /* check xvimagesink capabilities */ - sret = gst_element_set_state (pipeline, GST_STATE_READY); - if (sret == GST_STATE_CHANGE_FAILURE) { - g_printerr ("Can't set pipeline to READY\n"); - gst_object_unref (pipeline); - return -1; - } - - probe = GST_PROPERTY_PROBE (sink); - if (!probe) { - g_printerr ("Can't probe sink\n"); - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - return -1; - } - arr = - gst_property_probe_probe_and_get_values_name (probe, - "autopaint-colorkey"); - if (!arr || !arr->n_values) { - g_printerr ("Can't disable autopaint-colorkey property\n"); - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - return -1; - } - if (arr) - g_value_array_free (arr); - - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH); - g_signal_connect (bus, "message::state-changed", - G_CALLBACK (msg_state_changed), pipeline); - gst_object_unref (bus); - - /* prepare the ui */ - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - g_signal_connect (G_OBJECT (window), "delete-event", - G_CALLBACK (window_closed), (gpointer) pipeline); - gtk_window_set_default_size (GTK_WINDOW (window), 320, 240); - - video_window = gtk_drawing_area_new (); - g_signal_connect (G_OBJECT (video_window), "configure-event", - G_CALLBACK (handle_resize_cb), NULL); - g_signal_connect (G_OBJECT (video_window), "expose-event", - G_CALLBACK (handle_expose_cb), NULL); - g_signal_connect (video_window, "realize", G_CALLBACK (realize_cb), NULL); - gtk_widget_set_double_buffered (video_window, FALSE); - gtk_container_add (GTK_CONTAINER (window), video_window); - - /* show the gui and play */ - - gtk_widget_show_all (window); - - /* realize window now so that the video window gets created and we can - * obtain its XID before the pipeline is started up and the videosink - * asks for the XID of the window to render onto */ - gtk_widget_realize (window); - - /* we should have the XID now */ - g_assert (embed_xid != 0); - - /* we know what the video sink is in this case (xvimagesink), so we can - * just set it directly here now (instead of waiting for a prepare-xwindow-id - * element message in a sync bus handler and setting it there) */ - g_print ("setting XID %lu\n", embed_xid); - gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (sink), embed_xid); - - g_idle_add (start_pipeline, pipeline); - gtk_main (); - - gst_object_unref (pipeline); - - return 0; -} diff --git a/tests/icles/test-scale.c b/tests/icles/test-scale.c deleted file mode 100644 index 6d131193..00000000 --- a/tests/icles/test-scale.c +++ /dev/null @@ -1,164 +0,0 @@ -/* GStreamer interactive videoscale test - * Copyright (C) 2008 Wim Taymans <wim.taymans@gmail.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., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <stdlib.h> - -#include <gst/gst.h> - -static GstElement * -make_pipeline (gint type) -{ - GstElement *result; - gchar *pstr; - - switch (type) { - case 0: - pstr = g_strdup_printf ("videotestsrc ! capsfilter name=filter ! " - "ximagesink"); - break; - case 1: - pstr = g_strdup_printf ("videotestsrc ! queue ! capsfilter name=filter ! " - "ximagesink"); - break; - case 2: - pstr = g_strdup_printf ("videotestsrc peer-alloc=0 ! videoscale ! " - "capsfilter name=filter ! " "ximagesink"); - break; - case 3: - pstr = - g_strdup_printf ("videotestsrc peer-alloc=0 ! queue ! videoscale ! " - "capsfilter name=filter ! " "ximagesink"); - break; - case 4: - pstr = - g_strdup_printf ("videotestsrc peer-alloc=0 ! videoscale ! queue ! " - "capsfilter name=filter ! " "ximagesink"); - break; - case 5: - pstr = g_strdup_printf ("videotestsrc peer-alloc=0 ! " - "capsfilter name=filter ! " "ximagesink"); - break; - case 6: - pstr = g_strdup_printf ("videotestsrc ! videoscale ! " - "capsfilter name=filter ! " "ximagesink"); - break; - case 7: - pstr = g_strdup_printf ("v4l2src ! ffmpegcolorspace ! videoscale ! " - "capsfilter name=filter ! " "ximagesink"); - break; - default: - return NULL; - } - - result = gst_parse_launch_full (pstr, NULL, GST_PARSE_FLAG_NONE, NULL); - g_print ("created test %d: \"%s\"\n", type, pstr); - g_free (pstr); - - return result; -} - -#define MAX_ROUND 100 - -int -main (int argc, char **argv) -{ - GstElement *pipe, *filter; - GstCaps *caps; - gint width, height; - gint xdir, ydir; - gint round, type, stop; - - gst_init (&argc, &argv); - - type = 0; - stop = -1; - - if (argc > 1) { - type = atoi (argv[1]); - stop = type + 1; - } - - while (TRUE) { - GstMessage *message; - - pipe = make_pipeline (type); - if (pipe == NULL) - break; - - filter = gst_bin_get_by_name (GST_BIN (pipe), "filter"); - g_assert (filter); - - width = 320; - height = 240; - xdir = ydir = -10; - - for (round = 0; round < MAX_ROUND; round++) { - gchar *capsstr; - g_print ("resize to %dx%d (%d/%d) \r", width, height, round, MAX_ROUND); - - /* we prefer our fixed width and height but allow other dimensions to pass - * as well */ - capsstr = - g_strdup_printf ("video/x-raw-rgb, width=(int)%d, height=(int)%d;" - "video/x-raw-rgb", width, height); - caps = gst_caps_from_string (capsstr); - g_free (capsstr); - g_object_set (filter, "caps", caps, NULL); - gst_caps_unref (caps); - - if (round == 0) - gst_element_set_state (pipe, GST_STATE_PLAYING); - - width += xdir; - if (width >= 320) - xdir = -10; - else if (width < 200) - xdir = 10; - - height += ydir; - if (height >= 240) - ydir = -10; - else if (height < 150) - ydir = 10; - - message = - gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, - 50 * GST_MSECOND); - if (message) { - g_print ("got error \n"); - - gst_message_unref (message); - } - } - g_print ("test %d done \n", type); - - gst_object_unref (filter); - gst_element_set_state (pipe, GST_STATE_NULL); - gst_object_unref (pipe); - - type++; - if (type == stop) - break; - } - return 0; -} diff --git a/tests/icles/test-textoverlay.c b/tests/icles/test-textoverlay.c deleted file mode 100644 index 8d989a8f..00000000 --- a/tests/icles/test-textoverlay.c +++ /dev/null @@ -1,125 +0,0 @@ -/* GStreamer interactive textoverlay test - * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> - -static void -set_enum_property_by_name (gpointer object, const gchar * prop, - const gchar * value) -{ - GParamSpec *pspec; - GValue val = { 0, }; - GEnumClass *eclass; - GEnumValue *eval; - - pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (object), prop); - g_return_if_fail (pspec != NULL); - - g_value_init (&val, pspec->value_type); - g_object_get_property (G_OBJECT (object), prop, &val); - eclass = G_ENUM_CLASS (g_type_class_peek (G_VALUE_TYPE (&val))); - g_return_if_fail (eclass != NULL); - eval = g_enum_get_value_by_name (eclass, value); - if (eval == NULL) - eval = g_enum_get_value_by_nick (eclass, value); - g_return_if_fail (eval != NULL); - g_value_set_enum (&val, eval->value); - g_object_set_property (G_OBJECT (object), prop, &val); - g_value_unset (&val); -} - -static void -show_text (GstElement * textoverlay, const gchar * txt, const gchar * valign, - const gchar * halign, const gchar * line_align) -{ - GstElement *pipe; - - g_object_set (textoverlay, "text", txt, NULL); - - set_enum_property_by_name (textoverlay, "valignment", valign); - set_enum_property_by_name (textoverlay, "halignment", halign); - set_enum_property_by_name (textoverlay, "line-alignment", line_align); - - pipe = textoverlay; - while (GST_ELEMENT_PARENT (pipe)) - pipe = GST_ELEMENT_PARENT (pipe); - - gst_element_set_state (pipe, GST_STATE_PLAYING); - gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, GST_SECOND); - gst_element_set_state (pipe, GST_STATE_NULL); -} - -static void -test_textoverlay (int width, int height) -{ - const gchar *valigns[] = { /* "baseline", */ "bottom", "top" }; - const gchar *haligns[] = { "left", "center", "right" }; - const gchar *linealigns[] = { "left", "center", "right" }; - GstElement *pipe, *toverlay; - gchar *pstr; - gint a, b, c; - - pstr = g_strdup_printf ("videotestsrc pattern=blue ! " - "video/x-raw-yuv,width=%d,height=%d ! t.video_sink " - "textoverlay name=t font-desc=\"Sans Serif, 20\" ! " - " ffmpegcolorspace ! videoscale ! autovideosink", width, height); - - pipe = gst_parse_launch_full (pstr, NULL, GST_PARSE_FLAG_NONE, NULL); - g_assert (pipe); - - toverlay = gst_bin_get_by_name (GST_BIN (pipe), "t"); - g_assert (toverlay); - - g_object_set (toverlay, "xpad", 3, "ypad", 3, NULL); - - for (a = 0; a < G_N_ELEMENTS (valigns); ++a) { - for (b = 0; b < G_N_ELEMENTS (haligns); ++b) { - for (c = 0; c < G_N_ELEMENTS (linealigns); ++c) { - gchar *s; - - s = g_strdup_printf ("line-alignment = %s\n" - "<----- halignment = %s ----->\nvalignment = %s", - linealigns[c], haligns[b], valigns[a]); - show_text (toverlay, s, valigns[a], haligns[b], linealigns[c]); - g_free (s); - } - } - } - - g_free (pstr); -} - -int -main (int argc, char **argv) -{ - gst_init (&argc, &argv); - - test_textoverlay (640, 480); - - g_print ("Now with odd width/height ...\n"); - test_textoverlay (639, 479); - - /* test_textoverlay (796, 256); */ - - return 0; -} diff --git a/tests/old/Makefile.am b/tests/old/Makefile.am deleted file mode 100644 index c376eaa7..00000000 --- a/tests/old/Makefile.am +++ /dev/null @@ -1,26 +0,0 @@ -if USE_ALSA -ALSA_DIR=alsa -else -ALSA_DIR= -endif - -# if HAVE_GTK -# EMBED_DIR=embed -# else -# EMBED_DIR= -# endif - -SUBDIRS = \ - $(ALSA_DIR) #seeking -DIST_SUBDIRS = \ - alsa - -GST_PLUGIN_PATH=$(shell cd $(top_builddir) && pwd) - -#$(TESTS): -# @echo -e '\nrunning gst-register...\n' -# $(GST_TOOLS_DIR)/gst-register --gst-plugin-path=$(GST_PLUGIN_PATH) - -#TESTS=$(GST_TOOLS_DIR)/gst-compprep - -.PHONY: $(TESTS) diff --git a/tests/old/examples/Makefile.am b/tests/old/examples/Makefile.am deleted file mode 100644 index b4431197..00000000 --- a/tests/old/examples/Makefile.am +++ /dev/null @@ -1,15 +0,0 @@ -if HAVE_FT2 -FT2_SUBDIRS=seeking -else -FT2_SUBDIRS= -endif - -# if HAVE_GTK -# GTK_SUBDIRS=dynparams $(FT2_SUBDIRS) -# else -GTK_SUBDIRS= -# endif - -SUBDIRS=$(GTK_SUBDIRS) -#DIST_SUBDIRS=capsfilter seeking indexing switch -DIST_SUBDIRS=seeking diff --git a/tests/old/examples/capsfilter/Makefile.am b/tests/old/examples/capsfilter/Makefile.am deleted file mode 100644 index f8562fee..00000000 --- a/tests/old/examples/capsfilter/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -noinst_PROGRAMS = capsfilter1 - -LDADD = $(GST_LIBS) -AM_CFLAGS = $(GST_CFLAGS) - - diff --git a/tests/old/examples/capsfilter/capsfilter1.c b/tests/old/examples/capsfilter/capsfilter1.c deleted file mode 100644 index a59f728e..00000000 --- a/tests/old/examples/capsfilter/capsfilter1.c +++ /dev/null @@ -1,87 +0,0 @@ -#include <string.h> -#include <gst/gst.h> - -/* This app uses a filter to connect colorspace and videosink - * so that only RGB data can pass the connection, colorspace will use - * a converter to convert the I420 data to RGB. Without a filter, this - * connection would use the I420 format (assuming Xv is enabled) */ - -static void -new_pad_func (GstElement * element, GstPad * newpad, gpointer data) -{ - GstElement *pipeline = (GstElement *) data; - GstElement *queue = gst_bin_get_by_name (GST_BIN (pipeline), "queue"); - - if (!strcmp (gst_pad_get_name (newpad), "video_00")) { - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gst_pad_link (newpad, gst_element_get_pad (queue, "sink")); - gst_element_set_state (pipeline, GST_STATE_PLAYING); - } -} - -gint -main (gint argc, gchar * argv[]) -{ - GstElement *pipeline; - GstElement *filesrc; - GstElement *demux; - GstElement *thread; - GstElement *queue; - GstElement *mpeg2dec; - GstElement *colorspace; - GstElement *videosink; - gboolean res; - - gst_init (&argc, &argv); - - if (argc < 2) { - g_print ("usage: %s <mpeg1 system stream>\n", argv[0]); - return (-1); - } - - pipeline = gst_pipeline_new ("main_pipeline"); - filesrc = gst_element_factory_make ("filesrc", "filesrc"); - g_return_val_if_fail (filesrc, -1); - g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); - demux = gst_element_factory_make ("mpegdemux", "demux"); - g_return_val_if_fail (demux, -1); - g_signal_connect (G_OBJECT (demux), "new_pad", G_CALLBACK (new_pad_func), - pipeline); - - thread = gst_thread_new ("thread"); - queue = gst_element_factory_make ("queue", "queue"); - mpeg2dec = gst_element_factory_make ("mpeg2dec", "mpeg2dec"); - g_return_val_if_fail (mpeg2dec, -1); - colorspace = gst_element_factory_make ("ffmpegcolorspace", "colorspace"); - g_return_val_if_fail (colorspace, -1); - videosink = gst_element_factory_make (DEFAULT_VIDEOSINK, "videosink"); - g_return_val_if_fail (videosink, -1); - - gst_bin_add (GST_BIN (pipeline), filesrc); - gst_bin_add (GST_BIN (pipeline), demux); - - gst_bin_add (GST_BIN (thread), queue); - gst_bin_add (GST_BIN (thread), mpeg2dec); - gst_bin_add (GST_BIN (thread), colorspace); - gst_bin_add (GST_BIN (thread), videosink); - gst_bin_add (GST_BIN (pipeline), thread); - - gst_element_link_pads (filesrc, "src", demux, "sink"); - gst_element_link_pads (queue, "src", mpeg2dec, "sink"); - gst_element_link_pads (mpeg2dec, "src", colorspace, "sink"); - /* force RGB data passing between colorspace and videosink */ - res = gst_element_link_pads_filtered (colorspace, "src", videosink, "sink", - gst_caps_new_simple ("video/x-raw-rgb", NULL)); - if (!res) { - g_print ("could not connect colorspace and videosink\n"); - return -1; - } - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - while (gst_bin_iterate (GST_BIN (pipeline))); - - gst_element_set_state (pipeline, GST_STATE_NULL); - - return 0; -} diff --git a/tests/old/examples/gob/Makefile.am b/tests/old/examples/gob/Makefile.am deleted file mode 100644 index 7abde4dc..00000000 --- a/tests/old/examples/gob/Makefile.am +++ /dev/null @@ -1,19 +0,0 @@ - -plugin_LTLIBRARIES = libgstidentity2.la - -GOB_FILES_ID = gst-identity2.c gst-identity2.h gst-identity2-private.h - -BUILT_SOURCES = \ - $(GOB_FILES_ID) - -libgstidentity2_la_SOURCES = gst-identity2.gob $(GOB_FILES_ID) -libgstidentity2_la_CFLAGS = $(GST_CFLAGS) -libgstidentity2_la_LIBADD = - -%.c %.h %-private.h: %.gob - gob $< - -CLEANFILES = $(GOB_FILES_ID) - -dist-hook: - cd $(distdir); rm -f $(CLEANFILES) diff --git a/tests/old/examples/gob/gst-identity2.gob b/tests/old/examples/gob/gst-identity2.gob deleted file mode 100644 index 2c58f06f..00000000 --- a/tests/old/examples/gob/gst-identity2.gob +++ /dev/null @@ -1,139 +0,0 @@ - -%header{ -#include <gst/gst.h> -#include "gst-identity2.h" -#include "gst-identity2-private.h" -%} - -class Gst:Identity2 from Gst:Element { - - /* plugin init */ - private gboolean - plugin_init (GModule *module, GstPlugin *plugin) - { - static GstElementDetails identity2_details = - GST_ELEMENT_DETAILS ( - "GOB Identity", - "Filter/Effect", - "Does nothing", - "Wim Taymans <wim.taymans@chello.be>"); - GstElementFactory *factory; - - factory = gst_elementfactory_new ("identity2", TYPE_SELF, - &identity2_details); - g_return_val_if_fail (factory != NULL, FALSE); - - gst_plugin_add_feature (plugin, &(factory->feature)); - - return TRUE; - } - - /* pads FIXME gob oculd be improved here */ - private GstPad *sinkpad = - { - gst_pad_new ("sink", GST_PAD_SINK); - gst_element_add_pad (GST_ELEMENT (o), o->_priv->sinkpad); - gst_pad_set_chain_function (o->_priv->sinkpad, chain); - gst_pad_set_bufferpool_function (o->_priv->sinkpad, get_bufferpool); - //gst_pad_set_negotiate_function (o->_priv->sinkpad, negotiate_sink); - }; - private GstPad *srcpad = - { - gst_pad_new ("src", GST_PAD_SRC); - gst_element_add_pad (GST_ELEMENT (o), o->_priv->srcpad); - //gst_pad_set_negotiate_function (o->_priv->srcpad, negotiate_src); - }; - - /* arguments */ - /* - private gboolean loop_based = FALSE; argument BOOL loop_based - get { - ARG = self->_priv->loop_based; - } - set { - self->_priv->loop_based = ARG; - if (self->_priv->loop_based) { - gst_element_set_loop_function (GST_ELEMENT (self), loop); - gst_pad_set_chain_function (self->_priv->sinkpad, NULL); - } - else { - gst_pad_set_chain_function (self->_priv->sinkpad, chain); - gst_element_set_loop_function (GST_ELEMENT (self), NULL); - } - };*/ - private guint sleep_time = 0; argument UINT sleep_time link; - private gboolean silent = FALSE; argument BOOL silent link; - - /* signals */ - private signal last NONE(NONE) void handoff(self); - - /* core code here */ - private GstBufferPool* - get_bufferpool (GstPad *pad (check null)) - { - Self *self = SELF (gst_pad_get_parent (pad)); - - return gst_pad_get_bufferpool (self->_priv->srcpad); - } - - /* private GstPadNegotiateReturn - negotiate_src (GstPad *pad, GstCaps **caps, gpointer *data) - { - Self *self = SELF (gst_pad_get_parent (pad)); - - return gst_pad_negotiate_proxy (pad, self->_priv->sinkpad, caps); - } - - private GstPadNegotiateReturn - negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data) - { - Self *self = SELF (gst_pad_get_parent (pad)); - - return gst_pad_negotiate_proxy (pad, self->_priv->srcpad, caps); - } */ - - private void - chain (GstPad *pad (check null), GstBuffer *buf (check null)) - { - Self *self; - - self = SELF (gst_pad_get_parent (pad)); - - if (!self->_priv->silent) - g_print("identity2: chain ******* (%s:%s)i \n",GST_DEBUG_PAD_NAME(pad)); - - handoff (self); - gst_pad_push (self->_priv->srcpad, buf); - - if (self->_priv->sleep_time) - usleep (self->_priv->sleep_time); - } - - /*private void - loop (GstElement *element (check null)) - { - Self *self = SELF (element); - GstBuffer *buf; - - do { - buf = gst_pad_pull (self->_priv->sinkpad); - g_print("identity2: loop ******* (%s:%s)i \n",GST_DEBUG_PAD_NAME(self->_priv->sinkpad)); - - handoff (self); - gst_pad_push (self->_priv->srcpad, buf); - - if (self->_priv->sleep_time) - usleep (self->_priv->sleep_time); - - } while (!GST_ELEMENT_IS_COTHREAD_STOPPING(element)); - }*/ -} - -%{ -GstPluginDesc plugin_desc = { - GST_VERSION_MAJOR, - GST_VERSION_MINOR, - "identity2", - gst_identity2_plugin_init -}; -%} diff --git a/tests/old/examples/indexing/.gitignore b/tests/old/examples/indexing/.gitignore deleted file mode 100644 index 5ce09473..00000000 --- a/tests/old/examples/indexing/.gitignore +++ /dev/null @@ -1 +0,0 @@ -indexmpeg diff --git a/tests/old/examples/indexing/Makefile.am b/tests/old/examples/indexing/Makefile.am deleted file mode 100644 index 022bfc85..00000000 --- a/tests/old/examples/indexing/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -examples = indexmpeg - -noinst_PROGRAMS = $(examples) - -# we have nothing but apps here, we can do this safely -LIBS = $(GST_LIBS) $(GTK_LIBS) -AM_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS) diff --git a/tests/old/examples/indexing/indexmpeg.c b/tests/old/examples/indexing/indexmpeg.c deleted file mode 100644 index a670ad8a..00000000 --- a/tests/old/examples/indexing/indexmpeg.c +++ /dev/null @@ -1,321 +0,0 @@ -/* GStreamer - * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> - * - * 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 <string.h> -#include <gst/gst.h> - -static gboolean verbose = FALSE; -static gboolean quiet = FALSE; - -static void -entry_added (GstIndex * index, GstIndexEntry * entry) -{ - switch (entry->type) { - case GST_INDEX_ENTRY_ID: - g_print ("id %d describes writer %s\n", entry->id, - GST_INDEX_ID_DESCRIPTION (entry)); - break; - case GST_INDEX_ENTRY_FORMAT: - g_print ("%d: registered format %d for %s\n", entry->id, - GST_INDEX_FORMAT_FORMAT (entry), GST_INDEX_FORMAT_KEY (entry)); - break; - case GST_INDEX_ENTRY_ASSOCIATION: - { - gint i; - - g_print ("%p, %d: %08x ", entry, entry->id, - GST_INDEX_ASSOC_FLAGS (entry)); - for (i = 0; i < GST_INDEX_NASSOCS (entry); i++) { - g_print ("%d %" G_GINT64_FORMAT " ", GST_INDEX_ASSOC_FORMAT (entry, i), - GST_INDEX_ASSOC_VALUE (entry, i)); - } - g_print ("\n"); - break; - } - default: - break; - } -} - -typedef struct -{ - const gchar *padname; - GstPad *target; - GstElement *bin; - GstElement *pipeline; - GstIndex *index; -} -dyn_link; - -static void -dynamic_link (GstPadTemplate * templ, GstPad * newpad, gpointer data) -{ - dyn_link *link = (dyn_link *) data; - - if (!strcmp (gst_pad_get_name (newpad), link->padname)) { - gst_element_set_state (link->pipeline, GST_STATE_PAUSED); - gst_bin_add (GST_BIN (link->pipeline), link->bin); - gst_pad_link (newpad, link->target); - gst_element_set_index (link->bin, link->index); - gst_element_set_state (link->pipeline, GST_STATE_PLAYING); - } -} - -static void -setup_dynamic_linking (GstElement * pipeline, - GstElement * element, - const gchar * padname, GstPad * target, GstElement * bin, GstIndex * index) -{ - dyn_link *link; - - link = g_new0 (dyn_link, 1); - link->padname = g_strdup (padname); - link->target = target; - link->bin = bin; - link->pipeline = pipeline; - link->index = index; - - g_signal_connect (G_OBJECT (element), "new_pad", G_CALLBACK (dynamic_link), - link); -} - -static GstElement * -make_mpeg_systems_pipeline (const gchar * path, GstIndex * index) -{ - GstElement *pipeline; - GstElement *src, *demux; - - pipeline = gst_pipeline_new ("pipeline"); - - src = gst_element_factory_make ("filesrc", "src"); - g_object_set (G_OBJECT (src), "location", path, NULL); - - demux = gst_element_factory_make ("mpegdemux", "demux"); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - - if (index) { - gst_element_set_index (pipeline, index); - } - - gst_element_link_pads (src, "src", demux, "sink"); - - return pipeline; -} - -static GstElement * -make_mpeg_decoder_pipeline (const gchar * path, GstIndex * index) -{ - GstElement *pipeline; - GstElement *src, *demux; - GstElement *video_bin, *audio_bin; - GstElement *video_decoder, *audio_decoder; - - pipeline = gst_pipeline_new ("pipeline"); - - src = gst_element_factory_make ("filesrc", "src"); - g_object_set (G_OBJECT (src), "location", path, NULL); - - demux = gst_element_factory_make ("mpegdemux", "demux"); - - gst_bin_add (GST_BIN (pipeline), src); - gst_bin_add (GST_BIN (pipeline), demux); - - gst_element_link_pads (src, "src", demux, "sink"); - - video_bin = gst_bin_new ("video_bin"); - video_decoder = gst_element_factory_make ("mpeg2dec", "video_decoder"); - - gst_bin_add (GST_BIN (video_bin), video_decoder); - - setup_dynamic_linking (pipeline, demux, "video_00", - gst_element_get_pad (video_decoder, "sink"), video_bin, index); - - audio_bin = gst_bin_new ("audio_bin"); - audio_decoder = gst_element_factory_make ("mad", "audio_decoder"); - - setup_dynamic_linking (pipeline, demux, "audio_00", - gst_element_get_pad (audio_decoder, "sink"), audio_bin, index); - - gst_bin_add (GST_BIN (audio_bin), audio_decoder); - - if (index) { - gst_element_set_index (pipeline, index); - } - - return pipeline; -} - -static void -print_progress (GstPad * pad) -{ - gint i = 0; - gchar status[53]; - GstFormat format; - gboolean res; - gint64 value; - gint percent = 0; - - status[0] = '|'; - - format = GST_FORMAT_PERCENT; - res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &value); - if (res) { - percent = value / (2 * GST_FORMAT_PERCENT_SCALE); - } - - for (i = 0; i < percent; i++) { - status[i + 1] = '='; - } - for (i = percent; i < 50; i++) { - status[i + 1] = ' '; - } - status[51] = '|'; - status[52] = 0; - - g_print ("%s\r", status); -} - -gint -main (gint argc, gchar * argv[]) -{ - GstElement *pipeline; - GstElement *src; - GstPad *pad; - GstIndex *index; - gint count = 0; - GstEvent *event; - gboolean res; - GstElement *sink; - struct poptOption options[] = { - {"verbose", 'v', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &verbose, 0, - "Print index entries", NULL}, - {"quiet", 'q', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &quiet, 0, - "don't print progress bar", NULL}, - POPT_TABLEEND - }; - - if (!gst_init_check_with_popt_table (&argc, &argv, options) || argc < 3) { - g_print ("usage: %s [-v] <type> <filename> \n" - " type can be: 0 mpeg_systems\n" - " 1 mpeg_decoder\n" - " -v : report added index entries\n" - " -q : don't print progress\n", argv[0]); - return -1; - } - - /* create index that elements can fill */ - index = gst_index_factory_make ("memindex"); - if (index) { - if (verbose) - g_signal_connect (G_OBJECT (index), "entry_added", - G_CALLBACK (entry_added), NULL); - - g_object_set (G_OBJECT (index), "resolver", 1, NULL); - } - - /* construct pipeline */ - switch (atoi (argv[1])) { - case 0: - pipeline = make_mpeg_systems_pipeline (argv[2], index); - break; - case 1: - pipeline = make_mpeg_decoder_pipeline (argv[2], index); - break; - default: - g_print ("unknown type %d\n", atoi (argv[1])); - return -1; - } - - /* setup some default info/error handlers */ - g_signal_connect (G_OBJECT (pipeline), "deep_notify", - G_CALLBACK (gst_element_default_deep_notify), NULL); - g_signal_connect (G_OBJECT (pipeline), "error", - G_CALLBACK (gst_element_default_error), NULL); - - /* get a pad to perform progress reporting on */ - src = gst_bin_get_by_name (GST_BIN (pipeline), "src"); - pad = gst_element_get_pad (src, "src"); - - /* prepare for iteration */ - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - g_print ("indexing %s...\n", argv[2]); - /* run through the complete stream to let it generate an index */ - while (gst_bin_iterate (GST_BIN (pipeline))) { - if (!quiet && (count % 1000 == 0)) { - print_progress (pad); - } - count++; - } - g_print ("\n"); - - /* bring to ready to restart the pipeline */ - gst_element_set_state (pipeline, GST_STATE_READY); - gst_element_set_state (pipeline, GST_STATE_PAUSED); - - if (index) - GST_OBJECT_FLAG_UNSET (index, GST_INDEX_WRITABLE); - - src = gst_bin_get_by_name (GST_BIN (pipeline), "video_decoder"); - - { - gint id; - GstIndexEntry *entry; - gint64 result; - gint total_tm; - - gst_index_get_writer_id (index, GST_OBJECT (src), &id); - - entry = gst_index_get_assoc_entry (index, id, GST_INDEX_LOOKUP_BEFORE, 0, - GST_FORMAT_TIME, G_MAXINT64); - g_assert (entry); - gst_index_entry_assoc_map (entry, GST_FORMAT_TIME, &result); - total_tm = result * 60 / GST_SECOND; - g_print ("total time = %.2fs\n", total_tm / 60.0); - } - - pad = gst_element_get_pad (src, "src"); - sink = gst_element_factory_make ("fakesink", "sink"); - gst_element_link_pads (src, "src", sink, "sink"); - gst_bin_add (GST_BIN (pipeline), sink); - - g_print ("seeking %s...\n", argv[2]); - event = gst_event_new_seek (GST_FORMAT_TIME | - GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, 5 * GST_SECOND); - - res = gst_pad_send_event (pad, event); - if (!res) { - g_warning ("seek failed"); - } - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - count = 0; - while (gst_bin_iterate (GST_BIN (pipeline))) { - if (!quiet && (count % 1000 == 0)) { - print_progress (pad); - } - count++; - } - - gst_element_set_state (pipeline, GST_STATE_NULL); - - return 1; -} diff --git a/tests/old/examples/seek/.gitignore b/tests/old/examples/seek/.gitignore deleted file mode 100644 index fcb1d209..00000000 --- a/tests/old/examples/seek/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -cdparanoia -cdplayer -seek -spider_seek -vorbisfile - diff --git a/tests/old/examples/seek/Makefile.am b/tests/old/examples/seek/Makefile.am deleted file mode 100644 index b53022bb..00000000 --- a/tests/old/examples/seek/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -examples = seek scrubby #cdplayer cdparanoia - -noinst_PROGRAMS = $(examples) - -# we have nothing but apps here, we can do this safely -LIBS = $(GST_LIBS) $(GTK_LIBS) -AM_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS) diff --git a/tests/old/examples/seek/cdparanoia.c b/tests/old/examples/seek/cdparanoia.c deleted file mode 100644 index f5b8c326..00000000 --- a/tests/old/examples/seek/cdparanoia.c +++ /dev/null @@ -1,215 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include <stdlib.h> -#include <gst/gst.h> -#include <string.h> - -static void -get_position_info (GstElement * cdparanoia) -{ - GstFormat track_format; - const GstFormat *formats; - GstPad *pad; - - track_format = gst_format_get_by_nick ("track"); - g_assert (track_format != 0); - - pad = gst_element_get_pad (cdparanoia, "src"); - formats = gst_pad_get_formats (pad); - - while (*formats) { - const GstFormatDefinition *definition; - GstFormat format; - gint64 position; - gboolean res; - - definition = gst_format_get_details (*formats); - - format = *formats; - res = gst_pad_query (pad, GST_QUERY_POSITION, &format, &position); - - if (format == GST_FORMAT_TIME) { - position /= GST_SECOND; - g_print ("%s: %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT, - definition->nick, position / 60, position % 60); - } else { - g_print ("%s: %" G_GINT64_FORMAT, definition->nick, position); - } - - formats++; - if (*formats) { - g_print (", "); - } - } - g_print ("\r"); -} - -static void -get_track_info (GstElement * cdparanoia) -{ - GstFormat track_format; - gint64 total_tracks = 0, total_time = 0; - GstPad *pad; - const GstFormat *formats; - gint i; - gint64 time_count = 0; - - track_format = gst_format_get_by_nick ("track"); - g_assert (track_format != 0); - - pad = gst_element_get_pad (cdparanoia, "src"); - formats = gst_pad_get_formats (pad); - - /* we loop over all supported formats and report the total - * number of them */ - while (*formats) { - const GstFormatDefinition *definition; - gint64 total; - GstFormat format; - gboolean res; - - definition = gst_format_get_details (*formats); - - format = *formats; - res = gst_pad_query (pad, GST_QUERY_TOTAL, &format, &total); - if (res) { - if (format == GST_FORMAT_TIME) { - total /= GST_SECOND; - g_print ("%s total: %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT "\n", - definition->nick, total / 60, total % 60); - } else - g_print ("%s total: %" G_GINT64_FORMAT "\n", definition->nick, total); - - if (format == track_format) - total_tracks = total; - else if (format == GST_FORMAT_TIME) - total_time = total; - } else - g_print ("failed to get %s total\n", definition->nick); - - formats++; - } - - /* then we loop over all the tracks to get more info. - * since pad_convert always works from 0, the time from track 1 needs - * to be substracted from track 2 */ - for (i = 0; i <= total_tracks; i++) { - gint64 time; - gboolean res; - - if (i < total_tracks) { - GstFormat format; - - format = GST_FORMAT_TIME; - res = gst_pad_convert (pad, track_format, i, &format, &time); - time /= GST_SECOND; - } else { - time = total_time; - res = TRUE; - } - - if (res) { - /* for the first track (i==0) we wait until we have the - * time of the next track */ - if (i > 0) { - gint64 length = time - time_count; - - g_print ("track %d: %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT - " -> %" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ", length: %" - G_GINT64_FORMAT ":%02" G_GINT64_FORMAT "\n", - i - 1, - time_count / 60, time_count % 60, - time / 60, time % 60, length / 60, length % 60); - } - } else { - g_print ("could not get time for track %d\n", i); - } - - time_count = time; - } -} - -int -main (int argc, char **argv) -{ - GstElement *pipeline; - GstElement *cdparanoia; - GstElement *audiosink; - GstPad *pad; - GstFormat track_format; - GstEvent *event; - gint count; - gboolean res; - - gst_init (&argc, &argv); - - pipeline = gst_pipeline_new ("pipeline"); - - cdparanoia = gst_element_factory_make ("cdparanoia", "cdparanoia"); - g_assert (cdparanoia); - g_object_set (G_OBJECT (cdparanoia), "paranoia_mode", 0, NULL); - - audiosink = gst_element_factory_make (DEFAULT_AUDIOSINK, DEFAULT_AUDIOSINK); - g_assert (audiosink); - - gst_bin_add (GST_BIN (pipeline), cdparanoia); - gst_bin_add (GST_BIN (pipeline), audiosink); - - gst_element_link_pads (cdparanoia, "src", audiosink, "sink"); - - g_signal_connect (G_OBJECT (pipeline), "deep_notify", - G_CALLBACK (gst_object_default_deep_notify), NULL); - - gst_element_set_state (pipeline, GST_STATE_PAUSED); - - /* now we go into probe mode */ - get_track_info (cdparanoia); - - track_format = gst_format_get_by_nick ("track"); - g_assert (track_format != 0); - - pad = gst_element_get_pad (cdparanoia, "src"); - g_assert (pad); - - g_print ("playing from track 3\n"); - /* seek to track3 */ - event = gst_event_new_seek (track_format | - GST_SEEK_METHOD_SET | GST_SEEK_FLAG_FLUSH, 3); - - res = gst_pad_send_event (pad, event); - if (!res) - g_warning ("seek failed"); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - count = 0; - while (count++ < 500) { - get_position_info (cdparanoia); - g_usleep (G_USEC_PER_SEC / 2); - } - gst_element_set_state (pipeline, GST_STATE_PAUSED); - - g_print ("\nplaying from second 25 to second 29\n"); - /* seek to some seconds */ - event = gst_event_new_segment_seek (GST_FORMAT_TIME | - GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, 25 * GST_SECOND, 29 * GST_SECOND); - res = gst_pad_send_event (pad, event); - if (!res) - g_warning ("seek failed"); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - count = 0; - while (count++ < 500) { - get_position_info (cdparanoia); - g_usleep (G_USEC_PER_SEC / 2); - } - g_print ("\n"); - - /* shutdown everything again */ - gst_element_set_state (pipeline, GST_STATE_NULL); - - return 0; -} diff --git a/tests/old/examples/seek/cdplayer.c b/tests/old/examples/seek/cdplayer.c deleted file mode 100644 index 6305d50c..00000000 --- a/tests/old/examples/seek/cdplayer.c +++ /dev/null @@ -1,292 +0,0 @@ -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> -#include <gst/gst.h> -#include <string.h> - -static GList *seekable_elements = NULL; - -static GstElement *pipeline; -static GtkAdjustment *adjustment; -static gboolean stats = FALSE; -static guint64 duration; - -static guint update_id; - -#define UPDATE_INTERVAL 500 - -static GstElement * -make_cdaudio_pipeline (void) -{ - GstElement *cdaudio; - - cdaudio = gst_element_factory_make ("cdaudio", "cdaudio"); - g_assert (cdaudio != NULL); - - seekable_elements = g_list_prepend (seekable_elements, cdaudio); - - return cdaudio; -} - -static gchar * -format_value (GtkScale * scale, gdouble value) -{ - gint64 real; - gint64 seconds; - gint64 subseconds; - - real = value * duration / 100; - seconds = (gint64) real / GST_SECOND; - subseconds = (gint64) real / (GST_SECOND / 100); - - return g_strdup_printf ("%02" G_GINT64_FORMAT ":%02" G_GINT64_FORMAT ":%02" - G_GINT64_FORMAT, seconds / 60, seconds % 60, subseconds % 100); -} - -typedef struct -{ - const gchar *name; - const GstFormat format; -} -seek_format; - -static seek_format seek_formats[] = { - {"tim", GST_FORMAT_TIME}, - {"byt", GST_FORMAT_BYTES}, - {"buf", GST_FORMAT_BUFFERS}, - {"def", GST_FORMAT_DEFAULT}, - {NULL, 0}, -}; - - -G_GNUC_UNUSED static void -query_durations () -{ - GList *walk = seekable_elements; - - while (walk) { - GstElement *element = GST_ELEMENT (walk->data); - gint i = 0; - - g_print ("durations %8.8s: ", GST_ELEMENT_NAME (element)); - while (seek_formats[i].name) { - gboolean res; - gint64 value; - GstFormat format; - - format = seek_formats[i].format; - res = gst_element_query (element, GST_QUERY_TOTAL, &format, &value); - if (res) { - g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value); - } else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); - } - i++; - } - g_print (" %s\n", GST_ELEMENT_NAME (element)); - walk = g_list_next (walk); - } -} - -G_GNUC_UNUSED static void -query_positions () -{ - GList *walk = seekable_elements; - - while (walk) { - GstElement *element = GST_ELEMENT (walk->data); - gint i = 0; - - g_print ("positions %8.8s: ", GST_ELEMENT_NAME (element)); - while (seek_formats[i].name) { - gboolean res; - gint64 value; - GstFormat format; - - format = seek_formats[i].format; - res = gst_element_query (element, GST_QUERY_POSITION, &format, &value); - if (res) { - g_print ("%s %13" G_GINT64_FORMAT " | ", seek_formats[i].name, value); - } else { - g_print ("%s %13.13s | ", seek_formats[i].name, "*NA*"); - } - i++; - } - g_print (" %s\n", GST_ELEMENT_NAME (element)); - walk = g_list_next (walk); - } -} - -static gboolean -update_scale (gpointer data) -{ - GstClock *clock; - guint64 position = 0; - GstFormat format = GST_FORMAT_TIME; - - duration = 0; - clock = gst_pipeline_get_clock (GST_PIPELINE (pipeline)); - - if (seekable_elements) { - GstElement *element = GST_ELEMENT (seekable_elements->data); - - gst_element_query (element, GST_QUERY_TOTAL, &format, &duration); - gst_element_query (element, GST_QUERY_POSITION, &format, &position); - } - - if (stats) { - if (clock) - g_print ("clock: %13" G_GUINT64_FORMAT " (%s)\n", - position, gst_object_get_name (GST_OBJECT (clock))); - query_durations (); - query_positions (); - } - if (duration > 0) { - gtk_adjustment_set_value (adjustment, position * 100.0 / duration); - } - - return TRUE; -} - -static gboolean -start_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) -{ - gst_element_set_state (pipeline, GST_STATE_PAUSED); - g_timeout_remove (update_id); - - return FALSE; -} - -static gboolean -stop_seek (GtkWidget * widget, GdkEventButton * event, gpointer user_data) -{ - gint64 real = gtk_range_get_value (GTK_RANGE (widget)) * duration / 100; - gboolean res; - GstEvent *s_event; - GList *walk = seekable_elements; - - while (walk) { - GstElement *seekable = GST_ELEMENT (walk->data); - - g_print ("seek to %" G_GINT64_FORMAT " on element %s\n", real, - GST_ELEMENT_NAME (seekable)); - s_event = - gst_event_new_seek (GST_FORMAT_TIME | GST_SEEK_METHOD_SET | - GST_SEEK_FLAG_FLUSH, real); - - res = gst_element_send_event (seekable, s_event); - - walk = g_list_next (walk); - } - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - update_id = - g_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); - - return FALSE; -} - -static void -play_cb (GtkButton * button, gpointer data) -{ - GstState state; - - gst_element_get_state (pipeline, &state, NULL, GST_CLOCK_TIME_NONE); - if (state != GST_STATE_PLAYING) { - gst_element_set_state (pipeline, GST_STATE_PLAYING); - update_id = - g_timeout_add (UPDATE_INTERVAL, (GtkFunction) update_scale, pipeline); - } -} - -static void -pause_cb (GtkButton * button, gpointer data) -{ - GstState state; - - gst_element_get_state (pipeline, &state, NULL, GST_CLOCK_TIME_NONE); - if (state != GST_STATE_PAUSED) { - gst_element_set_state (pipeline, GST_STATE_PAUSED); - g_timeout_remove (update_id); - } -} - -static void -stop_cb (GtkButton * button, gpointer data) -{ - GstState state; - - gst_element_get_state (pipeline, &state, NULL, GST_CLOCK_TIME_NONE); - if (state != GST_STATE_READY) { - gst_element_set_state (pipeline, GST_STATE_READY); - g_timeout_remove (update_id); - } -} - -int -main (int argc, char **argv) -{ - GtkWidget *window, *hbox, *vbox, - *play_button, *pause_button, *stop_button, *hscale; - struct poptOption options[] = { - {"stats", 's', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &stats, 0, - "Show element stats", NULL}, - POPT_TABLEEND - }; - - gst_init_with_popt_table (&argc, &argv, options); - gtk_init (&argc, &argv); - - pipeline = make_cdaudio_pipeline (); - - g_signal_connect (pipeline, "deep_notify", - G_CALLBACK (gst_object_default_deep_notify), NULL); - - /* initialize gui elements ... */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - hbox = gtk_hbox_new (FALSE, 0); - vbox = gtk_vbox_new (FALSE, 0); - play_button = gtk_button_new_with_label ("play"); - pause_button = gtk_button_new_with_label ("pause"); - stop_button = gtk_button_new_with_label ("stop"); - - adjustment = - GTK_ADJUSTMENT (gtk_adjustment_new (0.0, 0.00, 100.0, 0.1, 1.0, 1.0)); - hscale = gtk_hscale_new (adjustment); - gtk_scale_set_digits (GTK_SCALE (hscale), 2); - gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_CONTINUOUS); - - g_signal_connect (GTK_OBJECT (hscale), - "button_press_event", G_CALLBACK (start_seek), pipeline); - g_signal_connect (GTK_OBJECT (hscale), - "button_release_event", G_CALLBACK (stop_seek), pipeline); - g_signal_connect (GTK_OBJECT (hscale), - "format_value", G_CALLBACK (format_value), pipeline); - - /* do the packing stuff ... */ - gtk_window_set_default_size (GTK_WINDOW (window), 96, 96); - gtk_container_add (GTK_CONTAINER (window), vbox); - gtk_container_add (GTK_CONTAINER (vbox), hbox); - gtk_box_pack_start (GTK_BOX (hbox), play_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), pause_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (hbox), stop_button, FALSE, FALSE, 2); - gtk_box_pack_start (GTK_BOX (vbox), hscale, TRUE, TRUE, 2); - - /* connect things ... */ - g_signal_connect (G_OBJECT (play_button), "clicked", G_CALLBACK (play_cb), - pipeline); - g_signal_connect (G_OBJECT (pause_button), "clicked", G_CALLBACK (pause_cb), - pipeline); - g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_cb), - pipeline); - g_signal_connect (G_OBJECT (window), "delete_event", gtk_main_quit, NULL); - - /* show the gui. */ - gtk_widget_show_all (window); - - gtk_main (); - - gst_element_set_state (pipeline, GST_STATE_NULL); - - return 0; -} diff --git a/tests/old/examples/seek/chained.c b/tests/old/examples/seek/chained.c deleted file mode 100644 index bf23e05a..00000000 --- a/tests/old/examples/seek/chained.c +++ /dev/null @@ -1,107 +0,0 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include <stdlib.h> -#include <gst/gst.h> -#include <string.h> - -static GstElement *bin; - -static void -unlinked (GstPad * pad, GstPad * peerpad, GstElement * pipeline) -{ - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gst_bin_remove (GST_BIN (pipeline), bin); - gst_element_set_state (bin, GST_STATE_READY); - gst_element_set_state (pipeline, GST_STATE_PLAYING); -} - -static void -new_pad (GstElement * elem, GstPad * newpad, GstElement * pipeline) -{ - GstScheduler *sched; - GstClock *clock; - - g_print ("new pad %s\n", gst_pad_get_name (newpad)); - - gst_element_set_state (pipeline, GST_STATE_PAUSED); - gst_bin_add (GST_BIN (pipeline), bin); - - sched = gst_element_get_scheduler (GST_ELEMENT (pipeline)); - clock = gst_scheduler_get_clock (sched); - gst_scheduler_set_clock (sched, clock); - - gst_pad_link (newpad, gst_element_get_pad (bin, "sink")); - - g_signal_connect (G_OBJECT (newpad), "unlinked", G_CALLBACK (unlinked), - pipeline); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); -} - -int -main (int argc, char **argv) -{ - GstElement *pipeline; - GstElement *filesrc; - GstElement *oggdemux; - GstElement *vorbisdec; - GstElement *audioconvert; - GstElement *audiosink; - - gst_init (&argc, &argv); - - if (argc < 2) { - g_print ("usage: %s <oggfile>\n", argv[0]); - return (-1); - } - - pipeline = gst_pipeline_new ("pipeline"); - - filesrc = gst_element_factory_make ("filesrc", "filesrc"); - g_assert (filesrc); - g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); - - oggdemux = gst_element_factory_make ("oggdemux", "oggdemux"); - g_assert (oggdemux); - - gst_bin_add (GST_BIN (pipeline), filesrc); - gst_bin_add (GST_BIN (pipeline), oggdemux); - - gst_element_link_pads (filesrc, "src", oggdemux, "sink"); - - g_signal_connect (G_OBJECT (oggdemux), "new_pad", G_CALLBACK (new_pad), - pipeline); - - bin = gst_bin_new ("bin"); - vorbisdec = gst_element_factory_make ("vorbisdec", "vorbisdec"); - g_assert (vorbisdec); - audioconvert = gst_element_factory_make ("audioconvert", "audioconvert"); - g_assert (audioconvert); - audiosink = gst_element_factory_make (DEFAULT_AUDIOSINK, DEFAULT_AUDIOSINK); - g_assert (audiosink); - gst_bin_add (GST_BIN (bin), vorbisdec); - gst_bin_add (GST_BIN (bin), audioconvert); - gst_bin_add (GST_BIN (bin), audiosink); - - gst_element_link_pads (vorbisdec, "src", audioconvert, "sink"); - gst_element_link_pads (audioconvert, "src", audiosink, "sink"); - - gst_element_add_ghost_pad (bin, gst_element_get_pad (vorbisdec, "sink"), - "sink"); - - g_object_ref (G_OBJECT (bin)); - - g_signal_connect (pipeline, "deep_notify", - G_CALLBACK (gst_element_default_deep_notify), NULL); - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - while (gst_bin_iterate (GST_BIN (pipeline))) - /* nop */ ; - - /* stop probe */ - gst_element_set_state (pipeline, GST_STATE_NULL); - - return 0; -} diff --git a/tests/old/examples/stats/Makefile.am b/tests/old/examples/stats/Makefile.am deleted file mode 100644 index 0f7d81cf..00000000 --- a/tests/old/examples/stats/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -noinst_PROGRAMS = mp2ogg - -LDADD = $(GST_LIBS) -AM_CFLAGS = $(GST_CFLAGS) - - diff --git a/tests/old/examples/stats/mp2ogg.c b/tests/old/examples/stats/mp2ogg.c deleted file mode 100644 index fc56d5b5..00000000 --- a/tests/old/examples/stats/mp2ogg.c +++ /dev/null @@ -1,102 +0,0 @@ -/* GStreamer - * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> - * - * 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 <gst/gst.h> - -/* This example app demonstartes the use of pad query and convert to - * get useful statistics about a plugin. In this case we monitor the - * compression status of mpeg audio to ogg vorbis transcoding. - */ - -gint -main (gint argc, gchar * argv[]) -{ - GstElement *pipeline; - GError *error = NULL; - gchar *description; - GstElement *encoder, *decoder; - GstPad *dec_sink, *enc_src; - - gst_init (&argc, &argv); - - if (argc < 3) { - g_print ("usage: %s <inputfile> <outputfile>\n", argv[0]); - return -1; - } - - description = g_strdup_printf ("filesrc location=\"%s\" ! mad name=decoder ! " - "vorbisenc name=encoder ! filesink location=\"%s\"", argv[1], argv[2]); - - pipeline = GST_ELEMENT (gst_parse_launch (description, &error)); - if (!pipeline) { - if (error) - g_print ("ERROR: pipeline could not be constructed: %s\n", - error->message); - else - g_print ("ERROR: pipeline could not be constructed\n"); - return -1; - } - - decoder = gst_bin_get_by_name (GST_BIN (pipeline), "decoder"); - encoder = gst_bin_get_by_name (GST_BIN (pipeline), "encoder"); - - dec_sink = gst_element_get_pad (decoder, "sink"); - enc_src = gst_element_get_pad (encoder, "src"); - - if (gst_element_set_state (pipeline, - GST_STATE_PLAYING) != GST_STATE_CHANGE_SUCCESS) { - g_print ("pipeline doesn't want to play\n"); - return -1; - } - - while (gst_bin_iterate (GST_BIN (pipeline))) { - gint64 position; - gint64 duration; - gint64 bitrate_enc, bitrate_dec; - GstFormat format; - - format = GST_FORMAT_TIME; - /* get the position */ - gst_pad_query (enc_src, GST_QUERY_POSITION, &format, &position); - - /* get the total duration */ - gst_pad_query (enc_src, GST_QUERY_TOTAL, &format, &duration); - - format = GST_FORMAT_BYTES; - /* see how many bytes are genereated per 8 seconds (== bitrate) */ - gst_pad_convert (enc_src, GST_FORMAT_TIME, 8 * GST_SECOND, - &format, &bitrate_enc); - - gst_pad_convert (dec_sink, GST_FORMAT_TIME, 8 * GST_SECOND, - &format, &bitrate_dec); - - g_print ("[%2dm %.2ds] of [%2dm %.2ds], " - "src avg bitrate: %" G_GINT64_FORMAT ", dest avg birate: %" - G_GINT64_FORMAT ", ratio [%02.2f] \r", - (gint) (position / (GST_SECOND * 60)), - (gint) (position / (GST_SECOND)) % 60, - (gint) (duration / (GST_SECOND * 60)), - (gint) (duration / (GST_SECOND)) % 60, bitrate_dec, bitrate_enc, - (gfloat) bitrate_dec / bitrate_enc); - } - - g_print ("\n"); - - return 0; -} diff --git a/tests/old/examples/switch/.gitignore b/tests/old/examples/switch/.gitignore deleted file mode 100644 index 7893c435..00000000 --- a/tests/old/examples/switch/.gitignore +++ /dev/null @@ -1 +0,0 @@ -switcher diff --git a/tests/old/examples/switch/Makefile.am b/tests/old/examples/switch/Makefile.am deleted file mode 100644 index 9a706048..00000000 --- a/tests/old/examples/switch/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ - -noinst_PROGRAMS = switcher - -switcher_SOURCES = switcher.c -switcher_CFLAGS = $(GST_CFLAGS) -switcher_LDFLAGS = $(GST_LIBS) - diff --git a/tests/old/examples/switch/switcher.c b/tests/old/examples/switch/switcher.c deleted file mode 100644 index 8d463c2a..00000000 --- a/tests/old/examples/switch/switcher.c +++ /dev/null @@ -1,104 +0,0 @@ -/* GStreamer - * Copyright (C) 2003 Julien Moutte <julien@moutte.net> - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include <gst/gst.h> - -static GMainLoop *loop = NULL; - - - -static void -got_eos (GstElement * pipeline) -{ - g_main_loop_quit (loop); -} - -static gboolean -idle_iterate (GstElement * pipeline) -{ - gst_bin_iterate (GST_BIN (pipeline)); - return (GST_STATE (GST_ELEMENT (pipeline)) == GST_STATE_PLAYING); -} - -static gboolean -switch_timer (GstElement * video_switch) -{ - gint nb_sources, active_source; - - g_object_get (G_OBJECT (video_switch), "nb_sources", &nb_sources, NULL); - g_object_get (G_OBJECT (video_switch), "active_source", &active_source, NULL); - - active_source++; - - if (active_source > nb_sources - 1) - active_source = 0; - - g_object_set (G_OBJECT (video_switch), "active_source", active_source, NULL); - - g_message ("current number of sources : %d, active source %d", - nb_sources, active_source); - - return (GST_STATE (GST_ELEMENT (video_switch)) == GST_STATE_PLAYING); -} - -int -main (int argc, char *argv[]) -{ - GstElement *pipeline, *src1, *src2, *video_switch, *video_sink; - - /* Initing GStreamer library */ - gst_init (&argc, &argv); - - loop = g_main_loop_new (NULL, FALSE); - - pipeline = gst_pipeline_new ("pipeline"); - src1 = gst_element_factory_make ("videotestsrc", "src1"); - g_object_set (G_OBJECT (src1), "pattern", 0, NULL); - src2 = gst_element_factory_make ("videotestsrc", "src2"); - g_object_set (G_OBJECT (src2), "pattern", 1, NULL); - video_switch = gst_element_factory_make ("switch", "video_switch"); - video_sink = gst_element_factory_make (DEFAULT_VIDEOSINK, "video_sink"); - - gst_bin_add_many (GST_BIN (pipeline), src1, src2, video_switch, - video_sink, NULL); - - gst_element_link (src1, video_switch); - gst_element_link (src2, video_switch); - gst_element_link (video_switch, video_sink); - - g_signal_connect (G_OBJECT (pipeline), "eos", G_CALLBACK (got_eos), NULL); - - gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); - - g_idle_add ((GSourceFunc) idle_iterate, pipeline); - g_timeout_add (2000, (GSourceFunc) switch_timer, video_switch); - - g_main_loop_run (loop); - - gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_READY); - - /* unref */ - gst_object_unref (pipeline); - - exit (0); -} diff --git a/tests/old/testsuite/alsa/.gitignore b/tests/old/testsuite/alsa/.gitignore deleted file mode 100644 index abf7b414..00000000 --- a/tests/old/testsuite/alsa/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -formats -srcstate -state diff --git a/tests/old/testsuite/alsa/Makefile.am b/tests/old/testsuite/alsa/Makefile.am deleted file mode 100644 index 6557bc58..00000000 --- a/tests/old/testsuite/alsa/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -testprogs = formats state srcstate - -noinst_PROGRAMS = $(testprogs) - -formats_SOURCES = formats.c sinesrc.c sinesrc.h -state_SOURCES = state.c sinesrc.c sinesrc.h -srcstate_SOURCES =srcstate.c - -# we have nothing but apps here, we can do this safely -LIBS = $(GST_LIBS) -AM_CFLAGS = $(GST_CFLAGS) - -noinst_HEADERS = sinesrc.h diff --git a/tests/old/testsuite/alsa/formats.c b/tests/old/testsuite/alsa/formats.c deleted file mode 100644 index 0142e9d9..00000000 --- a/tests/old/testsuite/alsa/formats.c +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de> - * - * formats.c: Tests the different formats on alsasink - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "sinesrc.h" - -GstElement *pipeline; -gint channels = 1; -gboolean sign = FALSE; -gint endianness = G_LITTLE_ENDIAN; -gint depth = 8; -gint width = 8; - -#define NUMBER_OF_INT_TESTS 28 -#define NUMBER_OF_FLOAT_TESTS 2 -#define NUMBER_OF_LAW_TESTS 2 - -gint last = 0; -gint counter = 0; - -static void create_pipeline (void); - - -static void -pre_get_func (SineSrc * src) -{ - counter++; -}; -static void -create_pipeline (void) -{ - GstElement *src; - SineSrc *sinesrc; - GstElement *alsasink; - - pipeline = gst_pipeline_new ("pipeline"); - src = sinesrc_new (); - alsasink = gst_element_factory_make ("alsasink", "alsasink"); - - gst_bin_add_many (GST_BIN (pipeline), src, alsasink, NULL); - gst_element_link (src, alsasink); - - /* prepare our sinesrc */ - sinesrc = (SineSrc *) src; - sinesrc->pre_get_func = pre_get_func; - sinesrc->newcaps = TRUE; - /* int tests */ - if (last < NUMBER_OF_INT_TESTS) { - sinesrc->type = SINE_SRC_INT; - sinesrc->sign = ((last % 2) == 0) ? TRUE : FALSE; - sinesrc->endianness = - ((last / 2) % 2 == 0) ? G_LITTLE_ENDIAN : G_BIG_ENDIAN; - switch ((last / 4) % 8) { - case 0: - sinesrc->depth = 8; - sinesrc->width = 8; - break; - case 1: - sinesrc->depth = 16; - sinesrc->width = 16; - break; - case 2: - sinesrc->depth = 24; - sinesrc->width = 32; - break; - case 3: - sinesrc->depth = 32; - sinesrc->width = 32; - break; - /* nomore tests below until i know what 24bit width means to alsa wrt endianness */ - case 4: - sinesrc->depth = 24; - sinesrc->width = 24; - break; - case 5: - sinesrc->depth = 20; - sinesrc->width = 24; - break; - case 6: - sinesrc->depth = 18; - sinesrc->width = 24; - break; - case 7: - /* not used yet */ - sinesrc->depth = 8; - sinesrc->width = 8; - break; - default: - g_assert_not_reached (); - } - - g_print ("Setting format to: format: \"int\"\n" - " sign: %s\n" - " endianness: %d\n" - " width: %d\n" - " depth: %d\n", - sinesrc->sign ? "TRUE" : "FALSE", sinesrc->endianness, - sinesrc->width, sinesrc->depth); - } else if (last < NUMBER_OF_INT_TESTS + NUMBER_OF_FLOAT_TESTS) { - gint temp = last - NUMBER_OF_INT_TESTS; - - sinesrc->type = SINE_SRC_FLOAT; - switch (temp) { - case 0: - sinesrc->width = 32; - break; - case 1: - sinesrc->width = 64; - break; - default: - g_assert_not_reached (); - } - g_print ("Setting format to float width %d\n", sinesrc->width); - } else if (last < - NUMBER_OF_INT_TESTS + NUMBER_OF_FLOAT_TESTS + NUMBER_OF_LAW_TESTS) { - gint temp = last - NUMBER_OF_INT_TESTS - NUMBER_OF_FLOAT_TESTS; - GstElement *law; - - sinesrc->type = SINE_SRC_INT; - sinesrc->sign = TRUE; - sinesrc->endianness = G_BYTE_ORDER; - sinesrc->depth = 16; - sinesrc->width = 16; - - if (temp == 0) { - law = gst_element_factory_make ("mulawenc", "mulaw"); - } else { - law = gst_element_factory_make ("alawenc", "alaw"); - } - g_assert (law); - gst_element_unlink (src, alsasink); - gst_bin_add (GST_BIN (pipeline), law); - gst_element_link_many (src, law, alsasink, NULL); - if (temp == 0) { - g_print ("Setting format to: format: \"MU law\"\n"); - } else { - g_print ("Setting format to: format: \"A law\"\n"); - } - } else { - g_print ("All formats work like a charm.\n"); - exit (0); - } - gst_element_set_state (pipeline, GST_STATE_PLAYING); -} - -gint -main (gint argc, gchar * argv[]) -{ - gst_init (&argc, &argv); - - g_print ("\n" - "This test will test the various formats ALSA and GStreamer support.\n" - "You will hear a short sine tone on your default ALSA soundcard for every\n" - "format tested. They should all sound the same (incl. volume).\n" "\n"); - create_pipeline (); - - while (pipeline) { - gst_bin_iterate (GST_BIN (pipeline)); - if ((counter / 200) > last) { - last = counter / 200; - gst_object_unref (pipeline); - create_pipeline (); - } - } - - return 0; -} diff --git a/tests/old/testsuite/alsa/sinesrc.c b/tests/old/testsuite/alsa/sinesrc.c deleted file mode 100644 index f684aaec..00000000 --- a/tests/old/testsuite/alsa/sinesrc.c +++ /dev/null @@ -1,349 +0,0 @@ -/* - * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de> - * - * sinesrc.c: An elemnt emitting a sine src in lots of different formats - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "sinesrc.h" -#include <math.h> -#include <string.h> /* memcpy */ - -#define SAMPLES_PER_WAVE 200 - -static GstStaticPadTemplate sinesrc_src_factory = - GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("audio/x-raw-int, " - "endianness = (int) { LITTLE_ENDIAN, BIG_ENDIAN }, " - "signed = (boolean) { FALSE, TRUE }, " - "width = (int) [8, 32], " - "depth = (int) [8, 32], " - "rate = (int) [8000, 192000], " - "channels = (int) [1, 16];" - "audio/x-raw-float, " - "endianness = (int) BYTE_ORDER, " - "width = (int) {32, 64}, " - "rate = (int) [8000, 192000], " "channels = (int) [1, 16]") - ); - -static GstElementClass *parent_class = NULL; - -static void sinesrc_init (SineSrc * src); -static void sinesrc_class_init (SineSrcClass * klass); - -static GstData *sinesrc_get (GstPad * pad); -static GstStateChangeReturn sinesrc_change_state (GstElement * element, - GstStateChange transition); - - -GType -sinesrc_get_type (void) -{ - static GType sinesrc_type = 0; - - if (!sinesrc_type) { - static const GTypeInfo sinesrc_info = { - sizeof (SineSrcClass), NULL, NULL, - (GClassInitFunc) sinesrc_class_init, NULL, NULL, - sizeof (SineSrc), 0, - (GInstanceInitFunc) sinesrc_init, - }; - - sinesrc_type = g_type_register_static (GST_TYPE_ELEMENT, "SineSrc", - &sinesrc_info, 0); - } - return sinesrc_type; -} -static void -sinesrc_class_init (SineSrcClass * klass) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (klass); - - element_class->change_state = sinesrc_change_state; - - parent_class = g_type_class_peek_parent (klass); -} - -static void -sinesrc_init (SineSrc * src) -{ - src->src = - gst_pad_new_from_template (gst_static_pad_template_get - (&sinesrc_src_factory), "src"); - gst_element_add_pad (GST_ELEMENT (src), src->src); - gst_pad_set_get_function (src->src, sinesrc_get); - - src->width = 16; - src->depth = 16; - src->sign = TRUE; - src->endianness = G_BYTE_ORDER; - src->rate = 44100; - src->channels = 1; - src->type = SINE_SRC_INT; - src->newcaps = TRUE; - - src->pre_get_func = NULL; - - GST_OBJECT (src)->name = "sinesrc"; -} - -static void -sinesrc_force_caps (SineSrc * src) -{ - GstCaps *caps; - - if (!src->newcaps) - return; - - src->newcaps = FALSE; - - switch (src->type) { - case SINE_SRC_INT: - caps = gst_caps_new_simple ("audio/x-raw-int", - "signed", G_TYPE_BOOLEAN, src->sign, - "depth", G_TYPE_INT, src->depth, NULL); - if (src->width > 8) - gst_caps_set_simple (caps, - "endianness", G_TYPE_INT, src->endianness, NULL); - break; - case SINE_SRC_FLOAT: - g_assert (src->width == 32 || src->width == 64); - caps = gst_caps_new_simple ("audio/x-raw-float", - "endianness", G_TYPE_INT, src->endianness, NULL); - break; - default: - caps = NULL; - g_assert_not_reached (); - } - gst_caps_set_simple (caps, - "width", G_TYPE_INT, src->width, - "rate", G_TYPE_INT, src->rate, - "channels", G_TYPE_INT, src->channels, NULL); - - if (gst_pad_try_set_caps (src->src, caps) != GST_PAD_LINK_OK) - g_assert_not_reached (); -} - -/* always return 1 wave - * there are 200 waves in 1 second, so the frequency is samplerate/200 - */ -static guint8 -UIDENTITY (guint8 x) -{ - return x; -}; -static gint8 -IDENTITY (gint8 x) -{ - return x; -}; - -#define POPULATE(format, be_func, le_func) G_STMT_START {\ - format val = (format) int_value;\ - format *p = data;\ - switch (src->endianness) {\ - case G_LITTLE_ENDIAN:\ - val = le_func (val);\ - break;\ - case G_BIG_ENDIAN:\ - val = be_func (val);\ - break;\ - default: \ - g_assert_not_reached ();\ - };\ - for (j = 0; j < src->channels; j++) {\ - *p = val;\ - p ++;\ - }\ - data = p;\ -} G_STMT_END - -static GstData * -sinesrc_get (GstPad * pad) -{ - GstBuffer *buf; - SineSrc *src; - - void *data; - gint i, j; - gdouble value; - - g_return_val_if_fail (pad != NULL, NULL); - src = SINESRC (gst_pad_get_parent (pad)); - - if (src->pre_get_func) - src->pre_get_func (src); - - buf = gst_buffer_new_and_alloc ((src->width / 8) * src->channels * - SAMPLES_PER_WAVE); - g_assert (buf); - data = GST_BUFFER_DATA (buf); - g_assert (data); - - for (i = 0; i < SAMPLES_PER_WAVE; i++) { - value = sin (i * 2 * M_PI / SAMPLES_PER_WAVE); - switch (src->type) { - case SINE_SRC_INT:{ - gint64 int_value = - (value + (src->sign ? 0 : 1)) * (((guint64) 1) << (src->depth - 1)); - if (int_value == - (1 + (src->sign ? 0 : 1)) * (((guint64) 1) << (src->depth - 1))) - int_value--; - switch (src->width) { - case 8: - if (src->sign) - POPULATE (gint8, IDENTITY, IDENTITY); - else - POPULATE (guint8, UIDENTITY, UIDENTITY); - break; - case 16: - if (src->sign) - POPULATE (gint16, GINT16_TO_BE, GINT16_TO_LE); - else - POPULATE (guint16, GUINT16_TO_BE, GUINT16_TO_LE); - break; - case 24: - if (src->sign) { - gpointer p; - gint32 val = (gint32) int_value; - - switch (src->endianness) { - case G_LITTLE_ENDIAN: - val = GINT32_TO_LE (val); - break; - case G_BIG_ENDIAN: - val = GINT32_TO_BE (val); - break; - default: - g_assert_not_reached (); - }; - p = &val; - if (src->endianness == G_BIG_ENDIAN) - p++; - for (j = 0; j < src->channels; j++) { - memcpy (data, p, 3); - data += 3; - } - } else { - gpointer p; - guint32 val = (guint32) int_value; - - switch (src->endianness) { - case G_LITTLE_ENDIAN: - val = GUINT32_TO_LE (val); - break; - case G_BIG_ENDIAN: - val = GUINT32_TO_BE (val); - break; - default: - g_assert_not_reached (); - }; - p = &val; - if (src->endianness == G_BIG_ENDIAN) - p++; - for (j = 0; j < src->channels; j++) { - memcpy (data, p, 3); - data += 3; - } - } - break; - case 32: - if (src->sign) - POPULATE (gint32, GINT32_TO_BE, GINT32_TO_LE); - else - POPULATE (guint32, GUINT32_TO_BE, GUINT32_TO_LE); - break; - default: - g_assert_not_reached (); - } - break; - } - case SINE_SRC_FLOAT: - if (src->width == 32) { - gfloat *p = (gfloat *) data; - gfloat fval = (gfloat) value; - - for (j = 0; j < src->channels; j++) { - *p = fval; - p++; - } - data = p; - break; - } - if (src->width == 64) { - gdouble *p = (gdouble *) data; - - for (j = 0; j < src->channels; j++) { - *p = value; - p++; - } - data = p; - break; - } - g_assert_not_reached (); - default: - g_assert_not_reached (); - } - } - - if (src->newcaps) { - sinesrc_force_caps (src); - } - return GST_DATA (buf); -} - -GstElement * -sinesrc_new (void) -{ - return GST_ELEMENT (g_object_new (TYPE_SINESRC, NULL)); -} - -void -sinesrc_set_pre_get_func (SineSrc * src, PreGetFunc func) -{ - src->pre_get_func = func; -} - -static GstStateChangeReturn -sinesrc_change_state (GstElement * element, GstStateChange transition) -{ - SineSrc *sinesrc; - - g_return_val_if_fail (element != NULL, FALSE); - sinesrc = SINESRC (element); - - switch (transition) { - case GST_STATE_CHANGE_NULL_TO_READY: - case GST_STATE_CHANGE_READY_TO_PAUSED: - case GST_STATE_CHANGE_PAUSED_TO_PLAYING: - case GST_STATE_CHANGE_PLAYING_TO_PAUSED: - break; - case GST_STATE_CHANGE_PAUSED_TO_READY: - sinesrc->newcaps = TRUE; - break; - case GST_STATE_CHANGE_READY_TO_NULL: - break; - default: - g_assert_not_reached (); - } - - if (GST_ELEMENT_CLASS (parent_class)->change_state) - return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition); - - return GST_STATE_CHANGE_SUCCESS; -} diff --git a/tests/old/testsuite/alsa/sinesrc.h b/tests/old/testsuite/alsa/sinesrc.h deleted file mode 100644 index 057428d3..00000000 --- a/tests/old/testsuite/alsa/sinesrc.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de> - * - * sinesrc.h: Header file for sinesrc.c - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#ifndef __SINESRC_H__ -#define __SINESRC_H__ - - -#include <gst/gst.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - - -#define TYPE_SINESRC \ - (sinesrc_get_type()) -#define SINESRC(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),TYPE_SINESRC,SineSrc)) -#define SINESRC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),TYPE_SINESRC,SineSrcClass)) -#define IS_SINESRC(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),TYPE_SINESRC)) -#define IS_SINESRC_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),TYPE_SINESRC)) - -typedef struct _SineSrc SineSrc; -typedef struct _SineSrcClass SineSrcClass; - -typedef void (*PreGetFunc) (SineSrc *src); - -typedef enum { - SINE_SRC_INT, - SINE_SRC_FLOAT -} SineSrcAudio; - -struct _SineSrc { - GstElement element; - - /* pads */ - GstPad *src; - - /* audio parameters */ - SineSrcAudio type; - gint width; /* int + float */ - gint depth; /* int */ - gboolean sign; /* int */ - gint endianness; /* int */ - - gint rate; - gint channels; /* interleaved */ - - gboolean newcaps; - - /* freaky stuff for testing */ - PreGetFunc pre_get_func; -}; - -struct _SineSrcClass { - GstElementClass parent_class; -}; - -GType sinesrc_get_type (void); -GstElement * sinesrc_new (void); - -void sinesrc_set_pre_get_func (SineSrc *src, PreGetFunc func); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __GST_SINESRC_H__ */ diff --git a/tests/old/testsuite/alsa/srcstate.c b/tests/old/testsuite/alsa/srcstate.c deleted file mode 100644 index 4ae536da..00000000 --- a/tests/old/testsuite/alsa/srcstate.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de> - * - * srcstate.c: Tests alsasrc for state changes - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -#include <gst/gst.h> - -GstElement *pipeline; - -static void -set_state (GstState state) -{ - GstState old_state = gst_element_get_state (pipeline); - - g_print ("Setting state from %s to %s...", - gst_element_state_get_name (old_state), - gst_element_state_get_name (state)); - - if (!gst_element_set_state (pipeline, state)) { - g_print (" ERROR\n"); - exit (-1); - } - - if (state == GST_STATE_PLAYING) { - gint i; - - g_print (" DONE - iterating a bit..."); - for (i = 0; i < 5; i++) { - if (!gst_bin_iterate (GST_BIN (pipeline))) { - g_print (" ERROR in iteration %d\n", i); - exit (-2); - } - } - } - g_print (" DONE\n"); -} - -static void -create_pipeline (void) -{ - GstElement *alsasrc; - GstElement *fakesink; - - pipeline = gst_pipeline_new ("pipeline"); - alsasrc = gst_element_factory_make ("alsasrc", "alsasrc"); - fakesink = gst_element_factory_make ("fakesink", "fakesink"); - - gst_bin_add_many (GST_BIN (pipeline), alsasrc, fakesink, NULL); - gst_element_link (alsasrc, fakesink); - -} - -gint -main (gint argc, gchar * argv[]) -{ - gst_init (&argc, &argv); - - g_print ("\n" "This test will check if state changes work on the alsasrc.\n"); - create_pipeline (); - - /* simulate some state changes here */ - set_state (GST_STATE_READY); - set_state (GST_STATE_NULL); - set_state (GST_STATE_READY); - set_state (GST_STATE_NULL); - set_state (GST_STATE_PAUSED); - set_state (GST_STATE_NULL); - set_state (GST_STATE_PLAYING); - set_state (GST_STATE_PAUSED); - set_state (GST_STATE_PLAYING); - set_state (GST_STATE_READY); - set_state (GST_STATE_PLAYING); - set_state (GST_STATE_NULL); - set_state (GST_STATE_PLAYING); - - g_print ("The alsa plugin mastered another test.\n"); - - gst_object_unref (pipeline); - - return 0; -} diff --git a/tests/old/testsuite/alsa/state.c b/tests/old/testsuite/alsa/state.c deleted file mode 100644 index 9cbd8acf..00000000 --- a/tests/old/testsuite/alsa/state.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2003 Benjamin Otte <in7y118@public.uni-hamburg.de> - * - * state.c: Tests alsasink for state changes - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU 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 - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free - * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include "sinesrc.h" - -GstElement *pipeline; - -static void -set_state (GstState state) -{ - GstState old_state = gst_element_get_state (pipeline); - - g_print ("Setting state from %s to %s...", - gst_element_state_get_name (old_state), - gst_element_state_get_name (state)); - - if (!gst_element_set_state (pipeline, state)) { - g_print (" ERROR\n"); - exit (-1); - } - - if (state == GST_STATE_PLAYING) { - gint i; - - g_print (" DONE - iterating a bit..."); - for (i = 0; i < 400; i++) { - if (!gst_bin_iterate (GST_BIN (pipeline))) { - g_print (" ERROR in iteration %d\n", i); - exit (-2); - } - } - } - g_print (" DONE\n"); -} - -static void -create_pipeline (void) -{ - GstElement *src; - SineSrc *sinesrc; - GstElement *alsasink; - - pipeline = gst_pipeline_new ("pipeline"); - src = sinesrc_new (); - alsasink = gst_element_factory_make ("alsasink", "alsasink"); - - gst_bin_add_many (GST_BIN (pipeline), src, alsasink, NULL); - gst_element_link (src, alsasink); - - /* prepare our sinesrc */ - sinesrc = (SineSrc *) src; - sinesrc->newcaps = TRUE; - sinesrc->type = SINE_SRC_INT; - sinesrc->sign = TRUE; - sinesrc->endianness = G_BYTE_ORDER; - sinesrc->depth = 16; - sinesrc->width = 16; -} - -gint -main (gint argc, gchar * argv[]) -{ - gst_init (&argc, &argv); - - g_print ("\n" - "This test will check if state changes work on the alsasink.\n" - "You will hear some short sine tones on your default ALSA soundcard,\n" - "but they are not important in this test.\n" "\n"); - create_pipeline (); - - /* simulate some state changes here */ - set_state (GST_STATE_READY); - set_state (GST_STATE_NULL); - set_state (GST_STATE_READY); - set_state (GST_STATE_NULL); - set_state (GST_STATE_PAUSED); - set_state (GST_STATE_NULL); - set_state (GST_STATE_PLAYING); - set_state (GST_STATE_PAUSED); - set_state (GST_STATE_PLAYING); - set_state (GST_STATE_READY); - set_state (GST_STATE_PLAYING); - set_state (GST_STATE_NULL); - set_state (GST_STATE_PLAYING); - - g_print ("The alsa plugin mastered another test.\n"); - - gst_object_unref (pipeline); - - return 0; -} diff --git a/tests/old/testsuite/embed/Makefile.am b/tests/old/testsuite/embed/Makefile.am deleted file mode 100644 index 2ffdc768..00000000 --- a/tests/old/testsuite/embed/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ - -noinst_PROGRAMS = embed - -# we have nothing but apps here, we can do this safely -LIBS = $(GST_LIBS) $(GTK_LIBS) \ - $(top_builddir)/gst-libs/gst/libgstinterfaces-$(GST_MAJORMINOR).la -AM_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS) diff --git a/tests/old/testsuite/embed/embed.c b/tests/old/testsuite/embed/embed.c deleted file mode 100644 index ed4a93cc..00000000 --- a/tests/old/testsuite/embed/embed.c +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Sample app for element embedding. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif -#include <gst/gst.h> -#include <gst/xoverlay/xoverlay.h> -#include <gtk/gtk.h> -#include <gdk/gdkx.h> - -static void -cb_expose (GtkWidget * w, GdkEventExpose * ev, GstElement * e) -{ - if (GST_IS_X_OVERLAY (e) && - !GTK_WIDGET_NO_WINDOW (w) && GTK_WIDGET_REALIZED (w)) { - gst_x_overlay_set_xwindow_id (GST_X_OVERLAY (e), - GDK_WINDOW_XWINDOW (w->window)); - } -} - -int -main (int argc, char *argv[]) -{ - GtkWidget *window, *content; - GstElement *testsrc, *csp, *videosink, *pipeline; - - gtk_init (&argc, &argv); - gst_init (&argc, &argv); - - pipeline = gst_element_factory_make ("pipeline", NULL); - testsrc = gst_element_factory_make ("videotestsrc", NULL); - csp = gst_element_factory_make ("ffmpegcolorspace", NULL); - videosink = gst_element_factory_make (DEFAULT_VIDEOSINK, NULL); - - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_default_size (GTK_WINDOW (window), 640, 480); - gtk_window_set_title (GTK_WINDOW (window), "My application"); - content = gtk_event_box_new (); - gtk_container_add (GTK_CONTAINER (window), content); - g_signal_connect (content, "expose-event", G_CALLBACK (cb_expose), videosink); - gtk_widget_show_all (window); - - gst_bin_add_many (GST_BIN (pipeline), testsrc, csp, videosink, NULL); - gst_element_link_many (testsrc, csp, videosink, NULL); - - g_idle_add ((GSourceFunc) gst_bin_iterate, pipeline); - gst_element_set_state (pipeline, GST_STATE_PLAYING); - - gtk_main (); - - return 0; -} diff --git a/tests/old/testsuite/gst-lint b/tests/old/testsuite/gst-lint deleted file mode 100755 index a924f052..00000000 --- a/tests/old/testsuite/gst-lint +++ /dev/null @@ -1,571 +0,0 @@ -#!/usr/bin/perl -w -# vi: set ts=4: -# - -# -# GStreamer developers: please add comments on any tests you think -# are dumb or have too many false positives. -# - -# -# Future ideas: -# - spell check comments -# - check each function for at least one assertion (?) -# - check parameters that init/set/get have consistent types -# - check for gst_caps_set() without check for writeability -# - check .so files for stray symbols -# - -# -# Random "other" testing ideas -# - load each plugin individually -# - -sub check_copyright(); -sub check_license(); -sub check_buffer_alloc(); -sub check_bad_includes(); -sub check_begin_decls(); -sub check_c99_comments(); -sub check_carriage_returns(); -sub check_printf_lld(); -sub check_glibisms(); -sub check_indentation(); -sub check_no_ignore(); -sub check_deprecated(); -sub check_config_h(); -sub check_varargs_functions(); -sub check_debugging(); -sub check_old_typefind(); -sub check_bad_casts(); -sub check_old_plugin(); -sub check_signal_new(); -sub check_gnuc_const(); -sub check_caps(); -sub check_lib_deprecated(); -sub check_typo(); -sub check_explicit_caps(); -sub check_signals(); -sub check_gettext(); -sub check_padtemplate(); -sub check_parent_class(); - -sub m_check_plugindir(); -sub m_check_interfaces(); - -open FIND, "find . -name \"*.[ch]\" -print|"; - -foreach $filename (<FIND>) { - chomp $filename; - open FILE, "$filename"; - @lines = <FILE>; - close FILE; - - print "I: $filename\n"; - - # important stuff - check_bad_includes(); - check_printf_lld(); - check_no_ignore(); - check_deprecated(); - check_config_h(); - check_old_typefind(); - check_old_plugin(); - check_caps(); - check_lib_deprecated(); - check_typo(); - check_glibisms(); - check_explicit_caps(); - check_signals(); - check_gettext(); - check_padtemplate(); - check_parent_class(); - - # less important stuff - check_license(); - -if (0) { - check_copyright(); - - check_gnuc_const(); - check_begin_decls(); - check_buffer_alloc(); - check_c99_comments(); - check_carriage_returns(); - #check_indentation(); - check_varargs_functions(); - check_debugging(); - check_bad_casts(); - check_signal_new(); -} -} - -open FIND, "find . -name \"Makefile.am\" -print|"; - -foreach $filename (<FIND>) { - chomp $filename; - open FILE, "$filename"; - @lines = <FILE>; - close FILE; - - print "I: $filename\n"; - - m_check_plugindir(); - m_check_interfaces(); -} - -# -# Every source file must have a copyright block -# -sub check_copyright() -{ - if (! grep { /copyright/i; } @lines) { - print "E: no copyright block\n"; - } -} - -# -# Every source file should have a license statement -# -sub check_license() -{ - if (grep { /Lesser General Public License/; } @lines) { - print "I: license is LGPL\n"; - } elsif (grep { /Library General Public License/; } @lines) { - print "I: license is LGPL\n"; - print "W: copyright header uses \"Library\" LGPL\n"; - } elsif (grep { /General Public License/; } @lines) { - print "I: license is GPL\n"; - } else { - print "E: unknown license or no copyright block\n"; - } -} - -# -# Suggest usage of gst_buffer_new_and_alloc() -# -sub check_buffer_alloc() -{ - my $n = 0; - my $lineno = 1; - - foreach $line (@lines){ - if($line =~ /gst_buffer_new/){ - $n=5; - } - if($n>0 && $line =~ /malloc/){ - print "W: ($lineno) gst_buffer_new() followed by malloc(), suggest gst_buffer_new_and_alloc()\n"; - return; - } - $n--; - $lineno++; - } -} - -sub check_bad_includes() -{ - # - # malloc.h is non-standard (and probably not what is indended) - # - if (grep { /^#include\s+<malloc.h>/; } @lines) { - print "E: bad header: malloc.h\n" - } -} - -sub check_begin_decls() -{ - # - # Prefer "G_BEGIN_DECLS" to 'extern "C" {' - # - if($filename =~ /\.h$/){ - if (grep { /extern\s*\"C\"\s*/; } @lines) { - print "W: extern \"C\" { should be changed to G_BEGIN_DECLS,G_END_DECLS\n"; - }elsif (!grep { /G_BEGIN_DECLS/; } @lines) { - print "E: header doesn't use G_BEGIN_DECLS\n"; - } - } -} - -# -# Prefer c89-style comments -# -sub check_c99_comments() -{ - if (grep { /\/\//; } @lines) { - print "W: //-style comments should be converted to /* */\n" - } -} - -# -# DOS end-of-line characters are just wrong -# -sub check_carriage_returns() -{ - if (grep { /\r/; } @lines) { - print "E: source has carriage returns (DOS-style files)\n" - } -} - -# -# Many uses of %lld are wrong. This could have a lot of false-positives -# -sub check_printf_lld() -{ - if (grep { /\".*\%\d*ll[du].*\"/; } @lines) { - print "W: Possible \%lld or \%llu in printf format\n" - } -} - -# -# Glib functions are preferred -# -sub check_glibisms() -{ - if (grep { /\bcalloc\s*\(/; } @lines) { - print "E: use g_malloc0() instead of calloc()\n" - } - if (grep { /\bfree\s*\(/; } @lines) { - print "E: use g_free() instead of free()\n" - } - if (grep { /\bmalloc\s*\(/; } @lines) { - print "E: use g_malloc() instead of malloc()\n" - } - if (grep { /\bprintf\s*\(/; } @lines) { - print "E: use g_print() instead of printf()\n" - } - if (grep { /\brealloc\s*\(/; } @lines) { - print "E: use g_realloc() instead of realloc()\n" - } - if (grep { /^#include\s+<ctype.h>/; } @lines) { - print "E: ctype.h functions are not locale-independent and don't work in UTF-8 locales. Use g_ascii_is*()\n" - } -} - -# -# I don't think that indentation necessarily needs to be fixed, since -# it causes problems with patching and cvs annotate. -# -# This takes forever and isn't very useful -# -sub check_indentation() -{ - my $changed_lines; - my $percent; - - `indent -br -bad -cbi0 -cli2 -bls -l80 -ut -ce $filename -o .check_plugin.tmp`; - $changed_lines = `diff $filename .check_plugin.tmp | grep '^>' | wc -l`; - `rm -f .check_plugin.tmp`; - - $percent = int(100 * $changed_lines / $#lines); - - if($percent < 10){ - print "I: indent changed $percent % of the lines\n"; - }elsif($percent <20){ - print "W: indent changed $percent % of the lines\n"; - }else{ - print "E: indent changed $percent % of the lines\n"; - } -} - - -# -# Check (roughly) for functions whose value should not be ignored -# -sub check_no_ignore() -{ - if (grep { /^\s+gst_buffer_merge\s*\(/; } @lines) { - print "E: return value of gst_buffer_merge () possibly ignored\n"; - } - if (grep { /^\s+malloc\s*\(/; } @lines) { - print "E: return value of malloc() possibly ignored\n"; - } - if (grep { /^\s+gst_buffer_new\s*\(/; } @lines) { - print "E: return value of gst_buffer_new() possibly ignored\n"; - } -} - -# -# Check for some deprecated stuff (that _shouldn't_ be around anymore) -# -sub check_deprecated() -{ - # - # Check for old GST_DEBUG() usage - # (none found) - # - if (grep { /GST_DEBUG\s*\(\s+\d/; } @lines) { - print "E: old-style GST_DEBUG()\n"; - } - if (grep { /GST_INFO\s*\(\s+\d/; } @lines) { - print "E: old-style GST_DEBUG()\n"; - } - if (grep { /GstEventFlags/; } @lines) { - print "W: who uses GstEventFlags\n"; - } - if (grep { /g_type_class_ref/ } @lines) { - print "W: g_type_class_ref should be changed to g_type_class_peek_parent\n"; - } - -} - -# -# Every .c file should include config.h before any other headers -# No .h file should include config.h -# -sub check_config_h() -{ - if($filename =~ /\.c$/){ - # - # config.h should be wrapped - # - my @includes = grep { /^#include/; } @lines; - - if (!grep { /^#include\s+["<]config.h[">]/; } @includes) { - print "E: #include <config.h> missing\n"; - }else{ - if (!($includes[0] =~ /^#include\s+["<]config.h[">]/)){ - print "E: #include <config.h> is not first include\n"; - } - if(!grep { /^#ifdef HAVE_CONFIG_H/; } @lines) { - print "E: #include <config.h> not surrounded by #ifdef HAVE_CONFIG_H\n"; - } - } - } - - if($filename =~ /\.h$/){ - if (grep { /^#include\s+["<]config.h[">]/; } @lines) { - print "E: headers should not #include <config.h>\n"; - } - } - -} - -# -# Check for functions that take varargs to make sure they are -# named correctly -# -sub check_varargs_functions() -{ - if($filename =~ /\.h$/){ - if (grep { /varargs/; } @lines) { - print "I: has varargs\n"; - } - } -} - -# -# Debugging checks -# -sub check_debugging() -{ - if (grep { /\Wg_print\W/ || /\Wprintf\W/ && /\Wfprintf\W/; } @lines) { - print "W: friendly libraries don't print to stdio or stderr\n"; - } - - if (grep { /GST_DEBUG.*\\n"/; } @lines) { - print "W: possible newline in GST_DEBUG()\n"; - } - -} - -# -# check for plugindir= -# -sub m_check_plugindir() -{ - if (grep { /plugindir\s*=/; } @lines) { - print "E: plugindir= is no longer necessary\n"; - } -} - -# -# check for old typefinding code -# -sub check_old_typefind() -{ - if (grep { /GstTypeDefinition/ || /GstTypeFactory/ } @lines) { - print "E: old typefind interface has been removed\n"; - } -} - -# -# check for casts that we've deemed incorrect (fix the prototype) -# -sub check_bad_casts() -{ - if (grep { /GBaseInitFunc/ || /GBaseFinalizeFunc/ || - /GClassInitFunc/ || /GClassFinalizeFunc/ || - /GInstanceInitFunc/ || /GInterfaceInitFunc/ || - /GInterfaceFinalizeFunc/ } @lines) { - print "W: bad casts (fix prototype)\n"; - } - if (grep { /\(\s*Gst[A-Z][A-Za-z]*\s*\*\s*\)/ } @lines ) { - print "W: use GST_XXX() instead of (GstXxx *)\n"; - } - -} - -# -# check for old plugin code -# -sub check_old_plugin() -{ - if (grep { /plugin_init.*GModule.*GstPlugin/ } @lines) { - print "E: old plugin interface detected\n"; - } - if (grep { /GstPluginDesc.*plugin_desc/ } @lines) { - print "W: should use GST_PLUGIN_DEFINE() instead of GstPluginDesc\n"; - } -} - -# -# Check for calls to g_signal_new() with a callback type of G_TYPE_POINTER -# -sub check_signal_new() -{ - my $n = 0; - my $lineno = 1; - - foreach $line (@lines){ - if($line =~ /g_signal_new/){ - $n=5; - } - if($n>0 && $line =~ /G_TYPE_POINTER/){ - print "W: ($lineno) g_signal_new() with callback type of G_TYPE_POINTER. Register and use a boxed type instead.\n"; - return; - } - $n--; - $lineno++; - } -} - -# -# Check that libgstinterfaces is in LDADD -# -sub m_check_interfaces() -{ - if (grep { /libgstinterfaces.la/ } @lines) { - if (! grep { /libgstinterfaces_la/ } @lines) { - if (! grep { /_LDADD.*libgstinterfaces.la/ } @lines) { - print "E: libgstinterfaces.la not in LDADD\n"; - } - } - } -} - -# -# Check that get_type() functions return G_CONST_RETURN GType -# -sub check_gnuc_const() -{ - my $n = 0; - my $lineno = 1; - - foreach $line (@lines){ - if($line =~ /GType.*get_type.*/ && - !($line =~ /GType.*get_type.*G_GNUC_CONST/)) { - - print "E: get_type function does not have G_GNUC_CONST attribute\n"; - } - } -} - -# -# Check caps usage -# -sub check_caps() -{ - if (grep { /gst_pad_get_caps/ } @lines) { - print "E: elements should not call gst_pad_get_caps(), use gst_pad_get_allowed_caps()\n"; - } -} - -# -# Check for use of deprecated functions -# -sub check_lib_deprecated() -{ - if (grep { /bzero/ } @lines) { - print "E: change bzero() to memset()\n"; - } -} - -# -# Check for typos -# -sub check_typo() -{ - if (grep { /;\s*;\s*$/ } @lines) { - print "W: typo? \";;\"\n"; - } -} - -# -# set_explicit_caps() should preceed pad_add() -# -sub check_explicit_caps() -{ - my $n = 0; - my $lineno = 1; - - foreach $line (@lines){ - if($line =~ /gst_element_add_pad/){ - $n=10; - } - if($n>0 && $line =~ /gst_pad_set_explicit_caps/){ - print "W: ($lineno) explicit caps should be set before adding pad\n"; - return; - } - $n--; - $lineno++; - } -} - -# -# Check for - in signal names -# -sub check_signals() -{ - if (grep { /g_signal_new.*\".*-.*\"/; } @lines) { - print "E: g_signal_new() with a signal name with a - in it (we prefer _)\n" - } -} - -# -# Check for things that gettext gets wrong -# -sub check_gettext() -{ - if (grep { /\b_\(.*G_GU?INT64_FORMAT/ || - /\b_\(.*GST_TIME_FORMAT/ || - /\b_\(.*GST_FOURCC_FORMAT/ } @lines) { - print "E: gettext doesn't handle format strings that are defines\n" - } -} - -# -# Check that pad templates are statically scoped -# -sub check_padtemplate() -{ - foreach $line (@lines){ - if ($line =~ /GstStaticPadTemplate/ && !($line =~ /static/)) { - print "W: pad template definitions should be static\n"; - return; - } - } -} - -# -# Check that parent_class is statically scoped -# -sub check_parent_class() -{ - foreach $line (@lines){ - if ($line =~ /Gst.*\*\s*parent_class/ && !($line =~ /static/)) { - print "E: parent_class definitions should be static\n"; - return; - } - } -} - |