5 * Copyright (C) <2007> Wim Taymans <wim dot taymans at gmail dot com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #include <sys/types.h>
28 #include <gst/check/gstcheck.h>
34 handoff (GstElement * fakesink, GstBuffer * buf, GstPad * pad, guint * count)
39 /* construct fakesrc num-buffers=3 ! tee name=t ! queue ! fakesink t. ! queue !
40 * fakesink. Each fakesink should exactly receive 3 buffers.
42 GST_START_TEST (test_num_buffers)
50 desc = "fakesrc num-buffers=3 ! tee name=t ! queue ! fakesink name=f1 "
51 "t. ! queue ! fakesink name=f2";
52 pipeline = gst_parse_launch (desc, NULL);
53 fail_if (pipeline == NULL);
55 f1 = gst_bin_get_by_name (GST_BIN (pipeline), "f1");
57 f2 = gst_bin_get_by_name (GST_BIN (pipeline), "f2");
63 g_object_set (G_OBJECT (f1), "signal-handoffs", TRUE, NULL);
64 g_signal_connect (G_OBJECT (f1), "handoff", (GCallback) handoff, &count1);
65 g_object_set (G_OBJECT (f2), "signal-handoffs", TRUE, NULL);
66 g_signal_connect (G_OBJECT (f2), "handoff", (GCallback) handoff, &count2);
68 bus = gst_element_get_bus (pipeline);
69 fail_if (bus == NULL);
70 gst_element_set_state (pipeline, GST_STATE_PLAYING);
72 msg = gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
73 fail_if (GST_MESSAGE_TYPE (msg) != GST_MESSAGE_EOS);
74 gst_message_unref (msg);
76 fail_if (count1 != 3);
77 fail_if (count2 != 3);
79 gst_element_set_state (pipeline, GST_STATE_NULL);
80 gst_object_unref (f1);
81 gst_object_unref (f2);
82 gst_object_unref (bus);
83 gst_object_unref (pipeline);
88 /* we use fakesrc ! tee ! fakesink and then randomly request/release and link
89 * some pads from tee. This should happily run without any errors. */
90 GST_START_TEST (test_stress)
99 /* Pump 1000 buffers (10 bytes each) per second through tee for 5 secs */
100 desc = "fakesrc datarate=10000 sizemin=10 sizemax=10 num-buffers=5000 ! "
101 "video/x-raw-rgb,framerate=25/1 ! tee name=t ! "
102 "queue max-size-buffers=2 ! fakesink sync=true";
104 pipeline = gst_parse_launch (desc, NULL);
105 fail_if (pipeline == NULL);
107 tee = gst_bin_get_by_name (GST_BIN (pipeline), "t");
108 fail_if (tee == NULL);
110 /* bring the pipeline to PLAYING, then start switching */
111 bus = gst_element_get_bus (pipeline);
112 fail_if (bus == NULL);
113 gst_element_set_state (pipeline, GST_STATE_PLAYING);
114 /* Wait for the pipeline to hit playing so that parse_launch can do the
115 * initial link, otherwise we perform linking from multiple threads and cause
117 gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
119 for (i = 0; i < 50000; i++) {
122 pad = gst_element_get_request_pad (tee, "src%d");
123 gst_element_release_request_pad (tee, pad);
124 gst_object_unref (pad);
126 if ((msg = gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, 0)))
130 /* now wait for completion or error */
132 msg = gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
133 fail_if (GST_MESSAGE_TYPE (msg) != GST_MESSAGE_EOS);
134 gst_message_unref (msg);
136 gst_element_set_state (pipeline, GST_STATE_NULL);
137 gst_object_unref (tee);
138 gst_object_unref (bus);
139 gst_object_unref (pipeline);
147 Suite *s = suite_create ("tee");
148 TCase *tc_chain = tcase_create ("general");
150 suite_add_tcase (s, tc_chain);
151 tcase_add_test (tc_chain, test_num_buffers);
152 tcase_add_test (tc_chain, test_stress);
157 GST_CHECK_MAIN (tee);