3 * unit test for mxfmux ! mxfdemux pipelines
5 * Copyright (C) <2009> 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 get_mpeg2enc_element_name (void)
29 GstElementFactory *factory = NULL;
31 if ((factory = gst_element_factory_find ("mpeg2enc"))) {
32 gst_object_unref (factory);
34 } else if ((factory = gst_element_factory_find ("ffenc_mpeg2video"))) {
35 gst_object_unref (factory);
36 return "ffenc_mpeg2video";
49 on_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
51 OnMessageUserData *d = user_data;
53 switch (GST_MESSAGE_TYPE (message)) {
54 case GST_MESSAGE_ERROR:
55 case GST_MESSAGE_WARNING:
56 g_assert_not_reached ();
59 g_main_loop_quit (d->loop);
68 on_pad_added (GstElement * element, GstPad * pad, gpointer user_data)
70 gint *n_pads = user_data;
72 *n_pads = *n_pads + 1;
76 run_test (const gchar * pipeline_string, gint n_pads_expected)
81 OnMessageUserData omud = { NULL, };
82 GstStateChangeReturn ret;
86 GST_DEBUG ("Testing pipeline '%s'", pipeline_string);
88 pipeline = gst_parse_launch (pipeline_string, NULL);
89 fail_unless (pipeline != NULL);
90 g_object_set (G_OBJECT (pipeline), "async-handling", TRUE, NULL);
92 demux = gst_bin_get_by_name (GST_BIN (pipeline), "demux");
93 fail_unless (demux != NULL);
94 g_signal_connect (demux, "pad-added", (GCallback) on_pad_added, &n_pads);
95 gst_object_unref (demux);
97 loop = g_main_loop_new (NULL, FALSE);
99 bus = gst_element_get_bus (pipeline);
100 fail_unless (bus != NULL);
101 gst_bus_add_signal_watch (bus);
106 g_signal_connect (bus, "message", (GCallback) on_message_cb, &omud);
108 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
109 fail_unless (ret == GST_STATE_CHANGE_SUCCESS
110 || ret == GST_STATE_CHANGE_ASYNC);
112 g_main_loop_run (loop);
114 fail_unless (gst_element_set_state (pipeline,
115 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
117 fail_unless (omud.eos == TRUE);
118 fail_unless_equals_int (n_pads, n_pads_expected);
120 gst_object_unref (pipeline);
121 g_main_loop_unref (loop);
122 gst_bus_remove_signal_watch (bus);
123 gst_object_unref (bus);
126 GST_START_TEST (test_mpeg2)
128 const gchar *mpeg2enc_name = get_mpeg2enc_element_name ();
134 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
135 "video/x-raw-yuv,framerate=25/1 ! "
136 "%s ! " "mxfmux name=mux ! "
137 "mxfdemux name=demux ! " "fakesink", mpeg2enc_name);
139 run_test (pipeline, 1);
145 GST_START_TEST (test_raw_video_raw_audio)
149 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
150 "video/x-raw-yuv,format=(GstFourcc)v308,width=1920,height=1080,framerate=25/1 ! "
152 "mxfdemux name=demux ! "
154 "audiotestsrc num-buffers=250 ! "
155 "audioconvert ! " "audio/x-raw-int,rate=48000,channels=2 ! " "mux. ");
157 run_test (pipeline, 2);
163 GST_START_TEST (test_raw_video_stride_transform)
167 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
168 "video/x-raw-yuv,format=(GstFourcc)v308,width=1001,height=501,framerate=25/1 ! "
169 "mxfmux name=mux ! " "mxfdemux name=demux ! " "fakesink");
171 run_test (pipeline, 1);
177 GST_START_TEST (test_jpeg2000_alaw)
180 GstElementFactory *factory = NULL;
182 if ((factory = gst_element_factory_find ("jp2kenc")) == NULL)
184 gst_object_unref (factory);
185 if ((factory = gst_element_factory_find ("alawenc")) == NULL)
187 gst_object_unref (factory);
189 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
190 "video/x-raw-yuv,framerate=25/1 ! "
193 "mxfdemux name=demux ! "
195 "audiotestsrc num-buffers=250 ! " "audioconvert ! " "alawenc ! " "mux. ");
197 run_test (pipeline, 2);
203 GST_START_TEST (test_dnxhd_mp3)
206 GstElementFactory *factory = NULL;
208 if ((factory = gst_element_factory_find ("ffenc_dnxhd")) == NULL)
210 gst_object_unref (factory);
211 if ((factory = gst_element_factory_find ("lame")) == NULL)
213 gst_object_unref (factory);
214 if ((factory = gst_element_factory_find ("mp3parse")) == NULL)
216 gst_object_unref (factory);
218 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
219 "video/x-raw-yuv,format=(GstFourcc)Y42B,width=1920,height=1080,framerate=25/1 ! "
220 "ffenc_dnxhd bitrate=36000000 ! "
222 "mxfdemux name=demux ! "
224 "audiotestsrc num-buffers=250 ! "
226 "audio/x-raw-int,channels=2 ! " "lame ! " "mp3parse ! " "mux. ");
228 run_test (pipeline, 2);
234 GST_START_TEST (test_multiple_av_streams)
238 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
239 "video/x-raw-yuv,format=(GstFourcc)v308,width=1920,height=1080,framerate=25/1 ! "
241 "mxfdemux name=demux ! "
243 "audiotestsrc num-buffers=250 ! "
245 "audio/x-raw-int,rate=48000,channels=2 ! "
247 "videotestsrc num-buffers=100 ! "
248 "video/x-raw-yuv,format=(GstFourcc)v308,width=1920,height=1080,framerate=25/1 ! "
250 "audiotestsrc num-buffers=100 ! "
252 "audio/x-raw-int,rate=48000,channels=2 ! "
254 "audiotestsrc num-buffers=250 ! "
255 "audioconvert ! " "audio/x-raw-int,rate=48000,channels=2 ! " "mux. ");
257 run_test (pipeline, 5);
266 Suite *s = suite_create ("mxf");
267 TCase *tc_chain = tcase_create ("general");
269 suite_add_tcase (s, tc_chain);
270 tcase_set_timeout (tc_chain, 180);
272 tcase_add_test (tc_chain, test_mpeg2);
273 tcase_add_test (tc_chain, test_raw_video_raw_audio);
274 tcase_add_test (tc_chain, test_raw_video_stride_transform);
275 tcase_add_test (tc_chain, test_jpeg2000_alaw);
276 tcase_add_test (tc_chain, test_dnxhd_mp3);
277 tcase_add_test (tc_chain, test_multiple_av_streams);
282 GST_CHECK_MAIN (mxf);