1 /* GStreamer unit test for queue
2 *
3 * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
4 * Copyright (C) 2009 Mark Nauwelaerts <mnauw users sourceforge net>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #include <gst/check/gstcheck.h>
23
24 #include <gst/gst.h>
25
26 static GstPadProbeReturn
modify_caps(GstObject * pad,GstPadProbeInfo * info,gpointer data)27 modify_caps (GstObject * pad, GstPadProbeInfo * info, gpointer data)
28 {
29 GstEvent *event = GST_PAD_PROBE_INFO_EVENT (info);
30 GstElement *filter = GST_ELEMENT (data);
31 GstCaps *caps;
32
33 fail_unless (event != NULL);
34 fail_unless (GST_IS_EVENT (event));
35
36 if (GST_EVENT_TYPE (event) != GST_EVENT_EOS)
37 return GST_PAD_PROBE_OK;
38
39 /* trigger caps negotiation error */
40 caps = gst_caps_new_empty_simple ("video/x-raw");
41 g_object_set (filter, "caps", caps, NULL);
42 gst_caps_unref (caps);
43
44 return GST_PAD_PROBE_OK;
45 }
46
GST_START_TEST(test_queue)47 GST_START_TEST (test_queue)
48 {
49 GstStateChangeReturn state_ret;
50 GstMessage *msg;
51 GstElement *pipeline, *filter, *queue;
52 GstBus *bus;
53 GstPad *pad;
54 guint probe;
55 gchar *pipe_desc =
56 g_strdup_printf ("fakesrc num-buffers=1 ! video/x-raw ! "
57 "queue min-threshold-buffers=2 name=queue ! "
58 "capsfilter name=nasty ! fakesink");
59
60 pipeline = gst_parse_launch (pipe_desc, NULL);
61 fail_unless (pipeline != NULL);
62 g_free (pipe_desc);
63
64 filter = gst_bin_get_by_name (GST_BIN (pipeline), "nasty");
65 fail_unless (filter != NULL);
66
67 /* queue waits for all data and EOS to arrive */
68 /* then probe forces downstream element to return negotiation error */
69 queue = gst_bin_get_by_name (GST_BIN (pipeline), "queue");
70 fail_unless (queue != NULL);
71 pad = gst_element_get_static_pad (queue, "sink");
72 fail_unless (pad != NULL);
73 probe =
74 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
75 (GstPadProbeCallback) modify_caps, filter, NULL);
76
77 bus = gst_element_get_bus (pipeline);
78
79 state_ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
80 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
81
82 msg = gst_bus_poll (bus, GST_MESSAGE_ERROR | GST_MESSAGE_EOS, 5 * GST_SECOND);
83 fail_unless (msg != NULL, "timeout waiting for error or eos message");
84
85 gst_message_unref (msg);
86 gst_object_unref (bus);
87
88 fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
89 GST_STATE_CHANGE_SUCCESS);
90
91 gst_pad_remove_probe (pad, probe);
92 gst_object_unref (queue);
93 gst_object_unref (pad);
94 gst_object_unref (filter);
95 gst_object_unref (pipeline);
96 }
97
98 GST_END_TEST;
99
100 static Suite *
queue_suite(void)101 queue_suite (void)
102 {
103 Suite *s = suite_create ("queue");
104 TCase *tc_chain = tcase_create ("general");
105
106 suite_add_tcase (s, tc_chain);
107 tcase_add_test (tc_chain, test_queue);
108
109 return s;
110 }
111
112 GST_CHECK_MAIN (queue)
113