1 /* GStreamer unit tests for decodebin
3 * Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
25 #include <gst/check/gstcheck.h>
28 static const gchar dummytext[] =
29 "Quick Brown Fox Jumps over a Lazy Frog Quick Brown "
30 "Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick "
31 "Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog "
32 "Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy "
33 "Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a "
34 "Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps "
35 "over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox "
36 "jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown "
37 "Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick "
38 "Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog "
39 "Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a Lazy "
40 "Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps over a "
41 "Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox Jumps "
42 "over a Lazy Frog Quick Brown Fox Jumps over a Lazy Frog Quick Brown Fox ";
45 src_handoff_cb (GstElement * src, GstBuffer * buf, GstPad * pad, gpointer data)
47 GST_BUFFER_DATA (buf) = (guint8 *) dummytext;
48 GST_BUFFER_SIZE (buf) = sizeof (dummytext);
49 GST_BUFFER_OFFSET (buf) = 0;
50 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY);
54 decodebin_new_decoded_pad_cb (GstElement * decodebin, GstPad * pad,
55 gboolean last, gboolean * p_flag)
57 /* we should not be reached */
58 fail_unless (decodebin == NULL, "new-decoded-pad should not be emitted");
61 /* make sure that decodebin errors out instead of creating a new decoded pad
62 * if the entire stream is a plain text file */
63 GST_START_TEST (test_text_plain_streams)
65 GstElement *pipe, *src, *decodebin;
68 pipe = gst_pipeline_new (NULL);
69 fail_unless (pipe != NULL, "failed to create pipeline");
71 src = gst_element_factory_make ("fakesrc", "src");
72 fail_unless (src != NULL, "Failed to create fakesrc element");
74 g_object_set (src, "signal-handoffs", TRUE, NULL);
75 g_object_set (src, "num-buffers", 1, NULL);
76 g_object_set (src, "can-activate-pull", FALSE, NULL);
77 g_signal_connect (src, "handoff", G_CALLBACK (src_handoff_cb), NULL);
79 decodebin = gst_element_factory_make ("decodebin", "decodebin");
80 fail_unless (decodebin != NULL, "Failed to create decodebin element");
82 g_signal_connect (decodebin, "new-decoded-pad",
83 G_CALLBACK (decodebin_new_decoded_pad_cb), NULL);
85 fail_unless (gst_bin_add (GST_BIN (pipe), src));
86 fail_unless (gst_bin_add (GST_BIN (pipe), decodebin));
87 fail_unless (gst_element_link (src, decodebin), "can't link src<->decodebin");
89 fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_READY),
90 GST_STATE_CHANGE_SUCCESS);
91 /* it's push-based, so should be async */
92 fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED),
93 GST_STATE_CHANGE_ASYNC);
95 /* it should error out at some point */
96 msg = gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, -1);
97 fail_unless (msg != NULL);
98 fail_unless (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
99 gst_message_unref (msg);
101 gst_element_set_state (pipe, GST_STATE_NULL);
102 gst_object_unref (pipe);
108 new_decoded_pad_plug_fakesink_cb (GstElement * decodebin, GstPad * srcpad,
109 gboolean last, GstElement * pipeline)
114 sink = gst_element_factory_make ("fakesink", "sink");
115 fail_unless (sink != NULL, "Failed to create fakesink element");
117 gst_bin_add (GST_BIN (pipeline), sink);
119 sinkpad = gst_element_get_static_pad (sink, "sink");
120 fail_unless_equals_int (gst_pad_link (srcpad, sinkpad), GST_PAD_LINK_OK);
121 gst_object_unref (sinkpad);
123 gst_element_set_state (sink, GST_STATE_PLAYING);
126 GST_START_TEST (test_reuse_without_decoders)
128 GstElement *pipe, *src, *decodebin, *sink;
130 pipe = gst_pipeline_new (NULL);
131 fail_unless (pipe != NULL, "failed to create pipeline");
133 src = gst_element_factory_make ("audiotestsrc", "src");
134 fail_unless (src != NULL, "Failed to create audiotestsrc element");
136 decodebin = gst_element_factory_make ("decodebin", "decodebin");
137 fail_unless (decodebin != NULL, "Failed to create decodebin element");
139 g_signal_connect (decodebin, "new-decoded-pad",
140 G_CALLBACK (new_decoded_pad_plug_fakesink_cb), pipe);
142 fail_unless (gst_bin_add (GST_BIN (pipe), src));
143 fail_unless (gst_bin_add (GST_BIN (pipe), decodebin));
144 fail_unless (gst_element_link (src, decodebin), "can't link src<->decodebin");
146 fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_READY),
147 GST_STATE_CHANGE_SUCCESS);
148 /* it's push-based, so should be async */
149 fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED),
150 GST_STATE_CHANGE_ASYNC);
152 /* wait for state change to complete */
153 fail_unless_equals_int (gst_element_get_state (pipe, NULL, NULL, -1),
154 GST_STATE_CHANGE_SUCCESS);
156 /* there shouldn't be any errors */
157 fail_if (gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, 0) != NULL);
160 gst_element_set_state (pipe, GST_STATE_NULL);
162 sink = gst_bin_get_by_name (GST_BIN (pipe), "sink");
163 gst_bin_remove (GST_BIN (pipe), sink);
164 gst_object_unref (sink);
166 GST_LOG ("second try");
168 fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_READY),
169 GST_STATE_CHANGE_SUCCESS);
170 /* it's push-based, so should be async */
171 fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED),
172 GST_STATE_CHANGE_ASYNC);
174 /* wait for state change to complete */
175 fail_unless_equals_int (gst_element_get_state (pipe, NULL, NULL, -1),
176 GST_STATE_CHANGE_SUCCESS);
178 /* there shouldn't be any errors */
179 fail_if (gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, 0) != NULL);
181 gst_element_set_state (pipe, GST_STATE_NULL);
182 gst_object_unref (pipe);
188 decodebin_suite (void)
190 Suite *s = suite_create ("decodebin");
191 TCase *tc_chain = tcase_create ("general");
193 suite_add_tcase (s, tc_chain);
194 tcase_add_test (tc_chain, test_text_plain_streams);
195 tcase_add_test (tc_chain, test_reuse_without_decoders);
200 GST_CHECK_MAIN (decodebin);