1 /* GStreamer unit tests for decodebin2
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 ("decodebin2", "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 GST_LOG ("Linking fakesink");
116 sink = gst_element_factory_make ("fakesink", "sink");
117 fail_unless (sink != NULL, "Failed to create fakesink element");
119 gst_bin_add (GST_BIN (pipeline), sink);
121 sinkpad = gst_element_get_static_pad (sink, "sink");
122 fail_unless_equals_int (gst_pad_link (srcpad, sinkpad), GST_PAD_LINK_OK);
123 gst_object_unref (sinkpad);
125 gst_element_set_state (sink, GST_STATE_PLAYING);
128 GST_START_TEST (test_reuse_without_decoders)
130 GstElement *pipe, *src, *decodebin, *sink;
132 pipe = gst_pipeline_new (NULL);
133 fail_unless (pipe != NULL, "failed to create pipeline");
135 src = gst_element_factory_make ("audiotestsrc", "src");
136 fail_unless (src != NULL, "Failed to create audiotestsrc element");
138 decodebin = gst_element_factory_make ("decodebin2", "decodebin");
139 fail_unless (decodebin != NULL, "Failed to create decodebin element");
141 g_signal_connect (decodebin, "new-decoded-pad",
142 G_CALLBACK (new_decoded_pad_plug_fakesink_cb), pipe);
144 fail_unless (gst_bin_add (GST_BIN (pipe), src));
145 fail_unless (gst_bin_add (GST_BIN (pipe), decodebin));
146 fail_unless (gst_element_link (src, decodebin), "can't link src<->decodebin");
148 fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_READY),
149 GST_STATE_CHANGE_SUCCESS);
150 /* it's push-based, so should be async */
151 fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED),
152 GST_STATE_CHANGE_ASYNC);
154 /* wait for state change to complete */
155 fail_unless_equals_int (gst_element_get_state (pipe, NULL, NULL, -1),
156 GST_STATE_CHANGE_SUCCESS);
158 /* there shouldn't be any errors */
159 fail_if (gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, 0) != NULL);
162 gst_element_set_state (pipe, GST_STATE_READY);
164 sink = gst_bin_get_by_name (GST_BIN (pipe), "sink");
165 gst_bin_remove (GST_BIN (pipe), sink);
166 gst_element_set_state (sink, GST_STATE_NULL);
167 gst_object_unref (sink);
169 GST_LOG ("second try");
171 fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_READY),
172 GST_STATE_CHANGE_SUCCESS);
173 /* it's push-based, so should be async */
174 fail_unless_equals_int (gst_element_set_state (pipe, GST_STATE_PAUSED),
175 GST_STATE_CHANGE_ASYNC);
177 /* wait for state change to complete */
178 fail_unless_equals_int (gst_element_get_state (pipe, NULL, NULL, -1),
179 GST_STATE_CHANGE_SUCCESS);
181 /* there shouldn't be any errors */
182 fail_if (gst_bus_poll (GST_ELEMENT_BUS (pipe), GST_MESSAGE_ERROR, 0) != NULL);
184 gst_element_set_state (pipe, GST_STATE_NULL);
185 gst_object_unref (pipe);
191 decodebin2_suite (void)
193 Suite *s = suite_create ("decodebin2");
194 TCase *tc_chain = tcase_create ("general");
196 suite_add_tcase (s, tc_chain);
197 tcase_add_test (tc_chain, test_text_plain_streams);
198 tcase_add_test (tc_chain, test_reuse_without_decoders);
203 GST_CHECK_MAIN (decodebin2);