2 * Copyright (C) 2007-2009 Nokia Corporation.
4 * Author: Felipe Contreras <felipe.contreras@nokia.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation
9 * version 2.1 of the License.
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 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <gst/check/gstcheck.h>
24 #define BUFFER_SIZE 0x1000
25 #define BUFFER_COUNT 0x100
28 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
33 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
38 /* some global vars, makes it easy as for the ones above */
39 static GMutex *eos_mutex;
40 static GCond *eos_cond;
41 static gboolean eos_arrived;
44 test_sink_event (GstPad * pad, GstEvent * event)
47 switch (GST_EVENT_TYPE (event)) {
49 g_mutex_lock (eos_mutex);
51 g_cond_signal (eos_cond);
52 g_mutex_unlock (eos_mutex);
58 return gst_pad_event_default (pad, event);
62 helper (gboolean flush)
70 filter = gst_check_setup_element ("omx_dummy");
71 mysrcpad = gst_check_setup_src_pad (filter, &srctemplate, NULL);
72 mysinkpad = gst_check_setup_sink_pad (filter, &sinktemplate, NULL);
74 gst_pad_set_active (mysrcpad, TRUE);
75 gst_pad_set_active (mysinkpad, TRUE);
77 /* need to know when we are eos */
78 gst_pad_set_event_function (mysinkpad, test_sink_event);
80 /* and notify the test run */
81 eos_mutex = g_mutex_new ();
82 eos_cond = g_cond_new ();
87 fail_unless_equals_int (gst_element_set_state (filter, GST_STATE_PLAYING),
88 GST_STATE_CHANGE_SUCCESS);
92 gst_element_set_bus (filter, bus);
94 /* send buffers in order */
97 for (i = 0; i < BUFFER_COUNT; i++) {
99 inbuffer = gst_buffer_new_and_alloc (BUFFER_SIZE);
100 GST_BUFFER_DATA (inbuffer)[0] = i;
101 ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
103 fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
105 if (flush && i % FLUSH_AT == 0) {
106 gst_pad_push_event (mysrcpad, gst_event_new_flush_start ());
107 gst_pad_push_event (mysrcpad, gst_event_new_flush_stop ());
116 /* make sure there's no error on the bus */
117 message = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0);
121 gst_pad_push_event (mysrcpad, gst_event_new_eos ());
122 /* need to wait a bit to make sure src pad task digested all and sent eos */
123 g_mutex_lock (eos_mutex);
125 g_cond_wait (eos_cond, eos_mutex);
126 g_mutex_unlock (eos_mutex);
128 /* check the order of the buffers */
132 for (cur = buffers, i = 0; cur; cur = g_list_next (cur), i++) {
135 fail_unless (GST_BUFFER_DATA (buffer)[0] == i);
137 fail_unless (i == BUFFER_COUNT);
141 gst_bus_set_flushing (bus, TRUE);
142 gst_element_set_bus (filter, NULL);
143 gst_object_unref (GST_OBJECT (bus));
144 gst_check_drop_buffers ();
147 gst_element_set_state (filter, GST_STATE_NULL);
149 gst_pad_set_active (mysrcpad, FALSE);
150 gst_pad_set_active (mysinkpad, FALSE);
151 gst_check_teardown_src_pad (filter);
152 gst_check_teardown_sink_pad (filter);
153 gst_check_teardown_element (filter);
155 g_mutex_free (eos_mutex);
156 g_cond_free (eos_cond);
159 GST_START_TEST (test_flush)
165 GST_START_TEST (test_basic)
170 GST_END_TEST static Suite *
173 Suite *s = suite_create ("gstomx");
174 TCase *tc_chain = tcase_create ("general");
176 tcase_set_timeout (tc_chain, 10);
177 tcase_add_test (tc_chain, test_basic);
178 tcase_add_test (tc_chain, test_flush);
179 suite_add_tcase (s, tc_chain);
184 GST_CHECK_MAIN (gstomx);