From 6b33226281d1281177e76a28fce56612ea11e326 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Wed, 15 Jun 2011 00:35:58 +0100 Subject: [PATCH] tests: fix up unit tests for playbin2/decodebin2 renames and updates Even if they don't work yet. --- tests/check/Makefile.am | 14 +- tests/check/elements/.gitignore | 4 +- tests/check/elements/decodebin.c | 21 +- tests/check/elements/decodebin2.c | 212 ------ ...{playbin2-compressed.c => playbin-compressed.c} | 10 +- tests/check/elements/playbin.c | 307 ++++++--- tests/check/elements/playbin2.c | 755 --------------------- 7 files changed, 230 insertions(+), 1093 deletions(-) delete mode 100644 tests/check/elements/decodebin2.c rename tests/check/elements/{playbin2-compressed.c => playbin-compressed.c} (99%) delete mode 100644 tests/check/elements/playbin2.c diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index cae8714..dc3ebc0 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -121,15 +121,13 @@ check_PROGRAMS = \ elements/audioresample \ elements/audiotestsrc \ elements/decodebin \ - elements/decodebin2 \ $(check_encodebin) \ elements/ffmpegcolorspace \ elements/gdpdepay \ elements/gdppay \ elements/multifdsink \ elements/playbin \ - elements/playbin2 \ - elements/playbin2-compressed \ + elements/playbin-compressed \ $(check_subparse) \ elements/videorate \ elements/videoscale \ @@ -375,11 +373,8 @@ 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_playbin2_compressed_LDADD = $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la $(GST_BASE_LIBS) $(LDADD) -elements_playbin2_compressed_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS) +elements_playbin_compressed_LDADD = $(top_builddir)/gst-libs/gst/interfaces/libgstinterfaces-@GST_MAJORMINOR@.la $(GST_BASE_LIBS) $(LDADD) +elements_playbin_compressed_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS) elements_decodebin_LDADD = $(GST_BASE_LIBS) $(LDADD) elements_decodebin_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS) @@ -387,9 +382,6 @@ elements_decodebin_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS) elements_encodebin_LDADD = $(top_builddir)/gst-libs/gst/pbutils/libgstpbutils-@GST_MAJORMINOR@.la $(GST_BASE_LIBS) $(LDADD) elements_encodebin_CFLAGS = $(GST_PLUGINS_BASE_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) diff --git a/tests/check/elements/.gitignore b/tests/check/elements/.gitignore index 80240a0..3105b23 100644 --- a/tests/check/elements/.gitignore +++ b/tests/check/elements/.gitignore @@ -8,7 +8,6 @@ audiorate audioresample audiotestsrc decodebin -decodebin2 encodebin gdpdepay gdppay @@ -25,6 +24,5 @@ ffmpegcolorspace videoscale vorbistag playbin -playbin2 -playbin2-compressed +playbin-compressed subparse diff --git a/tests/check/elements/decodebin.c b/tests/check/elements/decodebin.c index 005c63f..2fb46e9 100644 --- a/tests/check/elements/decodebin.c +++ b/tests/check/elements/decodebin.c @@ -48,7 +48,7 @@ src_need_data_cb (GstElement * src, guint size, gpointer data) GstFlowReturn ret; buf = gst_buffer_new (); - gst_buffer_take_memory (buf, + gst_buffer_take_memory (buf, 0, gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, (gpointer) dummytext, NULL, sizeof (dummytext), 0, sizeof (dummytext))); @@ -61,11 +61,11 @@ src_need_data_cb (GstElement * src, guint size, gpointer data) } static void -decodebin_new_decoded_pad_cb (GstElement * decodebin, GstPad * pad, +decodebin_pad_added_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"); + fail_unless (decodebin == NULL, "pad-added should not be emitted"); } /* make sure that decodebin errors out instead of creating a new decoded pad @@ -88,8 +88,8 @@ GST_START_TEST (test_text_plain_streams) 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); + g_signal_connect (decodebin, "pad-added", + G_CALLBACK (decodebin_pad_added_cb), NULL); fail_unless (gst_bin_add (GST_BIN (pipe), src)); fail_unless (gst_bin_add (GST_BIN (pipe), decodebin)); @@ -114,12 +114,14 @@ GST_START_TEST (test_text_plain_streams) GST_END_TEST; static void -new_decoded_pad_plug_fakesink_cb (GstElement * decodebin, GstPad * srcpad, +pad_added_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"); @@ -145,8 +147,8 @@ GST_START_TEST (test_reuse_without_decoders) 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); + g_signal_connect (decodebin, "pad-added", + G_CALLBACK (pad_added_plug_fakesink_cb), pipe); fail_unless (gst_bin_add (GST_BIN (pipe), src)); fail_unless (gst_bin_add (GST_BIN (pipe), decodebin)); @@ -166,10 +168,11 @@ GST_START_TEST (test_reuse_without_decoders) fail_if (gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, 0) != NULL); /* reset */ - gst_element_set_state (pipe, GST_STATE_NULL); + 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"); diff --git a/tests/check/elements/decodebin2.c b/tests/check/elements/decodebin2.c deleted file mode 100644 index c57be0b..0000000 --- a/tests/check/elements/decodebin2.c +++ /dev/null @@ -1,212 +0,0 @@ -/* GStreamer unit tests for decodebin2 - * - * Copyright (C) 2006 Tim-Philipp Müller - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include - -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_need_data_cb (GstElement * src, guint size, gpointer data) -{ - GstBuffer *buf; - GstFlowReturn ret; - - buf = gst_buffer_new (); - gst_buffer_take_memory (buf, - gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY, - (gpointer) dummytext, NULL, sizeof (dummytext), 0, - sizeof (dummytext))); - - GST_BUFFER_OFFSET (buf) = 0; - - g_signal_emit_by_name (src, "push-buffer", buf, &ret); - - fail_unless (ret == GST_FLOW_OK); -} - -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 ("appsrc", "src"); - fail_unless (src != NULL, "Failed to create appsrc element"); - - g_object_set (src, "emit-signals", TRUE, NULL); - g_object_set (src, "num-buffers", 1, NULL); - g_signal_connect (src, "need-data", G_CALLBACK (src_need_data_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/playbin2-compressed.c b/tests/check/elements/playbin-compressed.c similarity index 99% rename from tests/check/elements/playbin2-compressed.c rename to tests/check/elements/playbin-compressed.c index c992b1c..884107e 100644 --- a/tests/check/elements/playbin2-compressed.c +++ b/tests/check/elements/playbin-compressed.c @@ -1,4 +1,4 @@ -/* GStreamer unit tests for playbin2 compressed stream support +/* GStreamer unit tests for playbin compressed stream support * * Copyright (C) 2006 Tim-Philipp Müller * Copyright (C) 2010 Sebastian Dröge @@ -647,7 +647,7 @@ create_playbin (const gchar * uri, gboolean set_sink) { GstElement *playbin, *sink; - playbin = gst_element_factory_make ("playbin2", "playbin2"); + playbin = gst_element_factory_make ("playbin", "playbin"); fail_unless (playbin != NULL, "Failed to create playbin element"); if (set_sink) { @@ -2474,9 +2474,9 @@ GST_END_TEST; #endif static Suite * -playbin2_compressed_suite (void) +playbin_compressed_suite (void) { - Suite *s = suite_create ("playbin2_compressed"); + Suite *s = suite_create ("playbin_compressed"); TCase *tc_chain = tcase_create ("general"); suite_add_tcase (s, tc_chain); @@ -2528,4 +2528,4 @@ playbin2_compressed_suite (void) return s; } -GST_CHECK_MAIN (playbin2_compressed); +GST_CHECK_MAIN (playbin_compressed); diff --git a/tests/check/elements/playbin.c b/tests/check/elements/playbin.c index 1de9024..52820da 100644 --- a/tests/check/elements/playbin.c +++ b/tests/check/elements/playbin.c @@ -31,25 +31,14 @@ 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) +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 ())); @@ -83,24 +72,31 @@ test_sink_usage_video_only_stream (void) 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, "n-video", &nstreams, NULL); + fail_unless_equals_int (nstreams, 1); - 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); - } + 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); } -/* this tests async error handling when setting up the subbin */ -DEFINE_TEST (test_suburi_error_unknowntype); +GST_END_TEST; -static void -test_suburi_error_unknowntype (void) +/* this tests async error handling when setting up the subbin */ +GST_START_TEST (test_suburi_error_unknowntype) { GstElement *playbin, *fakesink; @@ -132,10 +128,9 @@ test_suburi_error_unknowntype (void) gst_object_unref (playbin); } -DEFINE_TEST (test_suburi_error_invalidfile); +GST_END_TEST; -static void -test_suburi_error_invalidfile (void) +GST_START_TEST (test_suburi_error_invalidfile) { GstElement *playbin, *fakesink; @@ -166,10 +161,9 @@ test_suburi_error_invalidfile (void) gst_object_unref (playbin); } -DEFINE_TEST (test_suburi_error_wrongproto); +GST_END_TEST; -static void -test_suburi_error_wrongproto (void) +GST_START_TEST (test_suburi_error_wrongproto) { GstElement *playbin, *fakesink; @@ -200,6 +194,8 @@ test_suburi_error_wrongproto (void) gst_object_unref (playbin); } +GST_END_TEST; + static GstElement * create_playbin (const gchar * uri) { @@ -226,10 +222,7 @@ create_playbin (const gchar * uri) return playbin; } -DEFINE_TEST (test_missing_urisource_handler); - -static void -test_missing_urisource_handler (void) +GST_START_TEST (test_missing_urisource_handler) { GstStructure *s; GstMessage *msg; @@ -250,8 +243,8 @@ test_missing_urisource_handler (void) 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; + s = (GstStructure *) gst_message_get_structure (msg); + fail_unless (s != NULL); 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"), @@ -278,10 +271,9 @@ test_missing_urisource_handler (void) gst_object_unref (playbin); } -DEFINE_TEST (test_missing_suburisource_handler); +GST_END_TEST; -static void -test_missing_suburisource_handler (void) +GST_START_TEST (test_missing_suburisource_handler) { GstStructure *s; GstMessage *msg; @@ -304,8 +296,8 @@ test_missing_suburisource_handler (void) 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; + s = (GstStructure *) gst_message_get_structure (msg); + fail_unless (s != NULL); 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"); @@ -313,11 +305,11 @@ test_missing_suburisource_handler (void) 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); + msg = gst_bus_poll (bus, GST_MESSAGE_WARNING, -1); + fail_unless_equals_int (GST_MESSAGE_TYPE (msg), GST_MESSAGE_WARNING); - /* make sure the error is a CORE MISSING_PLUGIN one */ - gst_message_parse_error (msg, &err, NULL); + /* 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)); @@ -325,24 +317,37 @@ test_missing_suburisource_handler (void) "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); } -DEFINE_TEST (test_missing_primary_decoder); +GST_END_TEST; -static void -test_missing_primary_decoder (void) +GST_START_TEST (test_missing_primary_decoder) { 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 ())); @@ -360,41 +365,148 @@ test_missing_primary_decoder (void) 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; + s = (GstStructure *) gst_message_get_structure (msg); + fail_unless (s != NULL); 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 STREAM CODEC_NOT_FOUND one */ + /* make sure the error is a CORE MISSING_PLUGIN 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); - } + 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 ("playbin", 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 playbin */ + 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 playbin */ + 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, playbin 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; + +static void +source_setup (GstElement * playbin, GstElement * source, GstElement ** p_src) +{ + GST_LOG ("source-setup called, source = %s", G_OBJECT_TYPE_NAME (source)); + *p_src = gst_object_ref (source); + GST_LOG ("here"); +} + +GST_START_TEST (test_source_setup) +{ + GstElement *playbin, *videosink; + GstElement *src = NULL; + + if (!gst_default_registry_check_feature_version ("redvideosrc", 0, 10, 0)) { + fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, + gst_red_video_src_get_type ())); + } + + playbin = gst_element_factory_make ("playbin", NULL); + g_object_set (playbin, "uri", "redvideo://", NULL); + + videosink = gst_element_factory_make ("fakesink", "myvideosink"); + g_object_set (playbin, "video-sink", videosink, NULL); + + g_signal_connect (playbin, "source-setup", G_CALLBACK (source_setup), &src); + + 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 (src != NULL); + fail_unless (G_OBJECT_TYPE (src) == gst_red_video_src_get_type ()); + + fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_NULL), + GST_STATE_CHANGE_SUCCESS); + + gst_object_unref (playbin); + gst_object_unref (src); +} + +GST_END_TEST; + /*** redvideo:// source ***/ static GstURIType @@ -454,10 +566,9 @@ static GstFlowReturn gst_red_video_src_create (GstPushSrc * src, GstBuffer ** p_buf) { GstBuffer *buf; - GstCaps *caps; guint8 *data; guint w = 64, h = 64; - gsize size; + guint size; size = w * h * 3 / 2; buf = gst_buffer_new_and_alloc (size); @@ -467,20 +578,24 @@ gst_red_video_src_create (GstPushSrc * src, GstBuffer ** p_buf) memset (data + (w * h) + ((w * h) / 4), 255, (w * h) / 4); gst_buffer_unmap (buf, data, size); - 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 GstCaps * +gst_red_video_src_get_caps (GstBaseSrc * src, GstCaps * filter) +{ + guint w = 64, h = 64; + return 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); +} + static void gst_red_video_src_class_init (GstRedVideoSrcClass * klass) { GstPushSrcClass *pushsrc_class = GST_PUSH_SRC_CLASS (klass); + GstBaseSrcClass *basesrc_class = GST_BASE_SRC_CLASS (klass); 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") @@ -493,6 +608,7 @@ gst_red_video_src_class_init (GstRedVideoSrcClass * klass) "Red Video Src", "Source/Video", "yep", "me"); pushsrc_class->create = gst_red_video_src_create; + basesrc_class->get_caps = gst_red_video_src_get_caps; } static void @@ -562,7 +678,6 @@ static GstFlowReturn gst_codec_src_create (GstPushSrc * src, GstBuffer ** p_buf) { GstBuffer *buf; - GstCaps *caps; guint8 *data; buf = gst_buffer_new_and_alloc (20); @@ -570,18 +685,21 @@ gst_codec_src_create (GstPushSrc * src, GstBuffer ** p_buf) memset (data, 0, 20); gst_buffer_unmap (buf, data, 20); - 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 GstCaps * +gst_codec_src_get_caps (GstBaseSrc * src, GstCaps * filter) +{ + return gst_caps_new_simple ("application/x-codec", NULL); +} + static void gst_codec_src_class_init (GstCodecSrcClass * klass) { GstPushSrcClass *pushsrc_class = GST_PUSH_SRC_CLASS (klass); + GstBaseSrcClass *basesrc_class = GST_BASE_SRC_CLASS (klass); static GstStaticPadTemplate src_templ = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS, GST_STATIC_CAPS ("application/x-codec") @@ -594,6 +712,7 @@ gst_codec_src_class_init (GstCodecSrcClass * klass) "Codec Src", "Source/Video", "yep", "me"); pushsrc_class->create = gst_codec_src_create; + basesrc_class->get_caps = gst_codec_src_get_caps; } static void @@ -613,23 +732,15 @@ playbin_suite (void) 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); + 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); + tcase_add_test (tc_chain, test_source_setup); /* one day we might also want to have the following checks: * tcase_add_test (tc_chain, test_missing_secondary_decoder_one_fatal); diff --git a/tests/check/elements/playbin2.c b/tests/check/elements/playbin2.c deleted file mode 100644 index 18f2d40..0000000 --- a/tests/check/elements/playbin2.c +++ /dev/null @@ -1,755 +0,0 @@ -/* GStreamer unit tests for playbin2 - * - * Copyright (C) 2006 Tim-Philipp Müller - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include - -#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); - s = (GstStructure *) gst_message_get_structure (msg); - fail_unless (s != NULL); - 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); - s = (GstStructure *) gst_message_get_structure (msg); - fail_unless (s != NULL); - 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); - s = (GstStructure *) gst_message_get_structure (msg); - fail_unless (s != NULL); - 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; - -static void -source_setup (GstElement * playbin, GstElement * source, GstElement ** p_src) -{ - GST_LOG ("source-setup called, source = %s", G_OBJECT_TYPE_NAME (source)); - *p_src = gst_object_ref (source); - GST_LOG ("here"); -} - -GST_START_TEST (test_source_setup) -{ - GstElement *playbin, *videosink; - GstElement *src = NULL; - - if (!gst_default_registry_check_feature_version ("redvideosrc", 0, 10, 0)) { - fail_unless (gst_element_register (NULL, "redvideosrc", GST_RANK_PRIMARY, - gst_red_video_src_get_type ())); - } - - playbin = gst_element_factory_make ("playbin2", NULL); - g_object_set (playbin, "uri", "redvideo://", NULL); - - videosink = gst_element_factory_make ("fakesink", "myvideosink"); - g_object_set (playbin, "video-sink", videosink, NULL); - - g_signal_connect (playbin, "source-setup", G_CALLBACK (source_setup), &src); - - 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 (src != NULL); - fail_unless (G_OBJECT_TYPE (src) == gst_red_video_src_get_type ()); - - fail_unless_equals_int (gst_element_set_state (playbin, GST_STATE_NULL), - GST_STATE_CHANGE_SUCCESS); - - gst_object_unref (playbin); - gst_object_unref (src); -} - -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[] = { (char *) "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; - -G_DEFINE_TYPE_WITH_CODE (GstRedVideoSrc, gst_red_video_src, - GST_TYPE_PUSH_SRC, gst_red_video_src_init_type (g_define_type_id)); - -static GstFlowReturn -gst_red_video_src_create (GstPushSrc * src, GstBuffer ** p_buf) -{ - GstBuffer *buf; - guint8 *data; - guint w = 64, h = 64; - guint size; - - size = w * h * 3 / 2; - buf = gst_buffer_new_and_alloc (size); - data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE); - memset (data, 76, w * h); - memset (data + (w * h), 85, (w * h) / 4); - memset (data + (w * h) + ((w * h) / 4), 255, (w * h) / 4); - gst_buffer_unmap (buf, data, size); - - *p_buf = buf; - return GST_FLOW_OK; -} - -static GstCaps * -gst_red_video_src_get_caps (GstBaseSrc * src, GstCaps * filter) -{ - guint w = 64, h = 64; - return 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); -} - -static void -gst_red_video_src_class_init (GstRedVideoSrcClass * klass) -{ - GstPushSrcClass *pushsrc_class = GST_PUSH_SRC_CLASS (klass); - GstBaseSrcClass *basesrc_class = GST_BASE_SRC_CLASS (klass); - 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_simple (element_class, - "Red Video Src", "Source/Video", "yep", "me"); - - pushsrc_class->create = gst_red_video_src_create; - basesrc_class->get_caps = gst_red_video_src_get_caps; -} - -static void -gst_red_video_src_init (GstRedVideoSrc * src) -{ -} - -/*** 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[] = { (char *) "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; - -G_DEFINE_TYPE_WITH_CODE (GstCodecSrc, gst_codec_src, - GST_TYPE_PUSH_SRC, gst_codec_src_init_type (g_define_type_id)); - -static GstFlowReturn -gst_codec_src_create (GstPushSrc * src, GstBuffer ** p_buf) -{ - GstBuffer *buf; - guint8 *data; - - buf = gst_buffer_new_and_alloc (20); - data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE); - memset (data, 0, 20); - gst_buffer_unmap (buf, data, 20); - - *p_buf = buf; - return GST_FLOW_OK; -} - -static GstCaps * -gst_codec_src_get_caps (GstBaseSrc * src, GstCaps * filter) -{ - return gst_caps_new_simple ("application/x-codec", NULL); -} - -static void -gst_codec_src_class_init (GstCodecSrcClass * klass) -{ - GstPushSrcClass *pushsrc_class = GST_PUSH_SRC_CLASS (klass); - GstBaseSrcClass *basesrc_class = GST_BASE_SRC_CLASS (klass); - 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_simple (element_class, - "Codec Src", "Source/Video", "yep", "me"); - - pushsrc_class->create = gst_codec_src_create; - basesrc_class->get_caps = gst_codec_src_get_caps; -} - -static void -gst_codec_src_init (GstCodecSrc * src) -{ -} - -#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); - tcase_add_test (tc_chain, test_source_setup); - - /* 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); -- 2.7.4