3 * unit test for mxfdemux
5 * Copyright (C) <2008> Sebastian Dröge <sebastian.droege@collabora.co.uk>
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.
23 #include <gst/check/gstcheck.h>
27 static GstPad *mysrcpad, *mysinkpad;
28 static GMainLoop *loop = NULL;
29 static gboolean have_eos = FALSE;
30 static gboolean have_data = FALSE;
32 static GstStaticPadTemplate mysrctemplate =
33 GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_SRC, GST_PAD_ALWAYS,
34 GST_STATIC_CAPS ("application/mxf"));
36 static GstStaticPadTemplate mysinktemplate =
37 GST_STATIC_PAD_TEMPLATE ("sink", GST_PAD_SINK, GST_PAD_ALWAYS,
41 _pad_added (GstElement * element, GstPad * pad, gpointer user_data)
43 gchar *name = gst_pad_get_name (pad);
45 fail_unless_equals_string (name, "track_2");
46 fail_unless (gst_pad_link (pad, mysinkpad) == GST_PAD_LINK_OK);
52 _sink_chain (GstPad * pad, GstBuffer * buffer)
54 GstCaps *caps = gst_caps_new_simple ("audio/x-raw-int",
55 "rate", G_TYPE_INT, 11025,
56 "channels", G_TYPE_INT, 1,
57 "signed", G_TYPE_BOOLEAN, FALSE,
58 "endianness", G_TYPE_INT, G_LITTLE_ENDIAN,
59 "depth", G_TYPE_INT, 8,
60 "width", G_TYPE_INT, 8,
63 fail_unless (GST_BUFFER_CAPS (buffer) != NULL);
64 fail_unless (gst_caps_is_always_compatible (GST_BUFFER_CAPS (buffer), caps));
66 fail_unless_equals_int (GST_BUFFER_SIZE (buffer), sizeof (mxf_essence));
67 fail_unless (memcmp (GST_BUFFER_DATA (buffer), mxf_essence,
68 sizeof (mxf_essence)) == 0);
70 fail_unless (GST_BUFFER_TIMESTAMP (buffer) == 0);
71 fail_unless (GST_BUFFER_DURATION (buffer) == 200 * GST_MSECOND);
73 gst_buffer_unref (buffer);
74 gst_caps_unref (caps);
81 _sink_event (GstPad * pad, GstEvent * event)
83 if (GST_EVENT_TYPE (event) == GST_EVENT_EOS) {
85 while (!g_main_loop_is_running (loop));
90 g_main_loop_quit (loop);
93 gst_event_unref (event);
99 _create_sink_pad (void)
101 mysinkpad = gst_pad_new_from_static_template (&mysinktemplate, "sink");
103 gst_pad_set_chain_function (mysinkpad, _sink_chain);
104 gst_pad_set_event_function (mysinkpad, _sink_event);
110 _create_src_pad_push (void)
112 mysrcpad = gst_pad_new_from_static_template (&mysrctemplate, "src");
118 _src_getrange (GstPad * pad, guint64 offset, guint length, GstBuffer ** buffer)
122 if (offset + length > sizeof (mxf_file))
123 return GST_FLOW_UNEXPECTED;
125 caps = gst_caps_new_simple ("application/mxf", NULL);
127 *buffer = gst_buffer_new ();
128 GST_BUFFER_DATA (*buffer) = (guint8 *) (mxf_file + offset);
129 GST_BUFFER_SIZE (*buffer) = length;
130 gst_buffer_set_caps (*buffer, caps);
131 gst_caps_unref (caps);
137 _src_query (GstPad * pad, GstQuery * query)
141 if (GST_QUERY_TYPE (query) != GST_QUERY_DURATION)
144 gst_query_parse_duration (query, &fmt, NULL);
146 if (fmt != GST_FORMAT_BYTES)
149 gst_query_set_duration (query, fmt, sizeof (mxf_file));
155 _create_src_pad_pull (void)
157 mysrcpad = gst_pad_new_from_static_template (&mysrctemplate, "src");
158 gst_pad_set_getrange_function (mysrcpad, _src_getrange);
159 gst_pad_set_query_function (mysrcpad, _src_query);
164 GST_START_TEST (test_pull)
166 GstElement *mxfdemux;
171 loop = g_main_loop_new (NULL, FALSE);
173 mxfdemux = gst_element_factory_make ("mxfdemux", NULL);
174 fail_unless (mxfdemux != NULL);
175 g_signal_connect (mxfdemux, "pad-added", G_CALLBACK (_pad_added), NULL);
176 sinkpad = gst_element_get_static_pad (mxfdemux, "sink");
177 fail_unless (sinkpad != NULL);
179 mysinkpad = _create_sink_pad ();
180 fail_unless (mysinkpad != NULL);
181 mysrcpad = _create_src_pad_pull ();
182 fail_unless (mysrcpad != NULL);
184 fail_unless (gst_pad_link (mysrcpad, sinkpad) == GST_PAD_LINK_OK);
185 gst_object_unref (sinkpad);
187 gst_pad_set_active (mysinkpad, TRUE);
188 gst_pad_set_active (mysrcpad, TRUE);
190 gst_element_set_state (mxfdemux, GST_STATE_PLAYING);
192 g_main_loop_run (loop);
193 fail_unless (have_eos == TRUE);
194 fail_unless (have_data == TRUE);
196 gst_element_set_state (mxfdemux, GST_STATE_NULL);
197 gst_pad_set_active (mysinkpad, FALSE);
198 gst_pad_set_active (mysrcpad, FALSE);
200 gst_object_unref (mxfdemux);
201 gst_object_unref (mysinkpad);
202 gst_object_unref (mysrcpad);
203 g_main_loop_unref (loop);
209 GST_START_TEST (test_push)
211 GstElement *mxfdemux;
218 mxfdemux = gst_element_factory_make ("mxfdemux", NULL);
219 fail_unless (mxfdemux != NULL);
220 g_signal_connect (mxfdemux, "pad-added", G_CALLBACK (_pad_added), NULL);
221 sinkpad = gst_element_get_static_pad (mxfdemux, "sink");
222 fail_unless (sinkpad != NULL);
224 buffer = gst_buffer_new ();
225 GST_BUFFER_DATA (buffer) = (guint8 *) mxf_file;
226 GST_BUFFER_SIZE (buffer) = sizeof (mxf_file);
227 GST_BUFFER_OFFSET (buffer) = 0;
229 mysinkpad = _create_sink_pad ();
230 fail_unless (mysinkpad != NULL);
231 mysrcpad = _create_src_pad_push ();
232 fail_unless (mysrcpad != NULL);
234 fail_unless (gst_pad_link (mysrcpad, sinkpad) == GST_PAD_LINK_OK);
235 gst_object_unref (sinkpad);
237 gst_pad_set_active (mysinkpad, TRUE);
238 gst_pad_set_active (mysrcpad, TRUE);
240 gst_element_set_state (mxfdemux, GST_STATE_PLAYING);
242 fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
243 fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));
245 fail_unless (have_eos == TRUE);
246 fail_unless (have_data == TRUE);
248 gst_element_set_state (mxfdemux, GST_STATE_NULL);
249 gst_pad_set_active (mysinkpad, FALSE);
250 gst_pad_set_active (mysrcpad, FALSE);
252 gst_object_unref (mxfdemux);
253 gst_object_unref (mysinkpad);
254 gst_object_unref (mysrcpad);
260 mxfdemux_suite (void)
262 Suite *s = suite_create ("mxfdemux");
263 TCase *tc_chain = tcase_create ("general");
265 suite_add_tcase (s, tc_chain);
266 tcase_set_timeout (tc_chain, 180);
267 tcase_add_test (tc_chain, test_pull);
268 tcase_add_test (tc_chain, test_push);
273 GST_CHECK_MAIN (mxfdemux);