1 /* GStreamer
2 *
3 * unit test for mxfmux ! mxfdemux pipelines
4 *
5 * Copyright (C) <2009> Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 *
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.
11 *
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.
16 *
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., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23 #include <gst/check/gstcheck.h>
24 #include <string.h>
25
26 static const gchar *
get_mpeg2enc_element_name(void)27 get_mpeg2enc_element_name (void)
28 {
29 GstElementFactory *factory = NULL;
30
31 if ((factory = gst_element_factory_find ("mpeg2enc"))) {
32 gst_object_unref (factory);
33 return "mpeg2enc";
34 } else if ((factory = gst_element_factory_find ("avenc_mpeg2video"))) {
35 gst_object_unref (factory);
36 return "avenc_mpeg2video";
37 } else {
38 return NULL;
39 }
40 }
41
42 typedef struct
43 {
44 GMainLoop *loop;
45 gboolean eos;
46 } OnMessageUserData;
47
48 static void
on_message_cb(GstBus * bus,GstMessage * message,gpointer user_data)49 on_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
50 {
51 OnMessageUserData *d = user_data;
52
53 switch (GST_MESSAGE_TYPE (message)) {
54 case GST_MESSAGE_ERROR:
55 case GST_MESSAGE_WARNING:
56 g_assert_not_reached ();
57 break;
58 case GST_MESSAGE_EOS:
59 g_main_loop_quit (d->loop);
60 d->eos = TRUE;
61 break;
62 default:
63 break;
64 }
65 }
66
67 static void
on_pad_added(GstElement * element,GstPad * pad,gpointer user_data)68 on_pad_added (GstElement * element, GstPad * pad, gpointer user_data)
69 {
70 gint *n_pads = user_data;
71
72 *n_pads = *n_pads + 1;
73 }
74
75 static void
run_test(const gchar * pipeline_string,gint n_pads_expected)76 run_test (const gchar * pipeline_string, gint n_pads_expected)
77 {
78 GstElement *pipeline;
79 GstBus *bus;
80 GMainLoop *loop;
81 OnMessageUserData omud = { NULL, };
82 GstStateChangeReturn ret;
83 GstElement *demux;
84 gint n_pads = 0;
85
86 GST_DEBUG ("Testing pipeline '%s'", pipeline_string);
87
88 pipeline = gst_parse_launch (pipeline_string, NULL);
89 fail_unless (pipeline != NULL);
90 g_object_set (G_OBJECT (pipeline), "async-handling", TRUE, NULL);
91
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);
96
97 loop = g_main_loop_new (NULL, FALSE);
98
99 bus = gst_element_get_bus (pipeline);
100 fail_unless (bus != NULL);
101 gst_bus_add_signal_watch (bus);
102
103 omud.loop = loop;
104 omud.eos = FALSE;
105
106 g_signal_connect (bus, "message", (GCallback) on_message_cb, &omud);
107
108 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
109 fail_unless (ret == GST_STATE_CHANGE_SUCCESS
110 || ret == GST_STATE_CHANGE_ASYNC);
111
112 g_main_loop_run (loop);
113
114 fail_unless (gst_element_set_state (pipeline,
115 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
116
117 fail_unless (omud.eos == TRUE);
118 fail_unless_equals_int (n_pads, n_pads_expected);
119
120 gst_object_unref (pipeline);
121 g_main_loop_unref (loop);
122 gst_bus_remove_signal_watch (bus);
123 gst_object_unref (bus);
124 }
125
GST_START_TEST(test_mpeg2)126 GST_START_TEST (test_mpeg2)
127 {
128 const gchar *mpeg2enc_name = get_mpeg2enc_element_name ();
129 gchar *pipeline;
130
131 if (!mpeg2enc_name)
132 return;
133
134 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
135 "video/x-raw,framerate=25/1 ! "
136 "%s ! " "mxfmux name=mux ! "
137 "mxfdemux name=demux ! " "fakesink", mpeg2enc_name);
138
139 run_test (pipeline, 1);
140 g_free (pipeline);
141 }
142
143 GST_END_TEST;
144
GST_START_TEST(test_raw_video_raw_audio)145 GST_START_TEST (test_raw_video_raw_audio)
146 {
147 gchar *pipeline;
148
149 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
150 "video/x-raw,format=(string)v308,width=1920,height=1080,framerate=25/1 ! "
151 "mxfmux name=mux ! "
152 "mxfdemux name=demux ! "
153 "fakesink "
154 "audiotestsrc num-buffers=250 ! "
155 "audioconvert ! " "audio/x-raw,rate=48000,channels=2 ! " "mux. ");
156
157 run_test (pipeline, 2);
158 g_free (pipeline);
159 }
160
161 GST_END_TEST;
162
GST_START_TEST(test_raw_video_stride_transform)163 GST_START_TEST (test_raw_video_stride_transform)
164 {
165 gchar *pipeline;
166
167 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
168 "video/x-raw,format=(string)v308,width=1001,height=501,framerate=25/1 ! "
169 "mxfmux name=mux ! " "mxfdemux name=demux ! " "fakesink");
170
171 run_test (pipeline, 1);
172 g_free (pipeline);
173 }
174
175 GST_END_TEST;
176
GST_START_TEST(test_jpeg2000_alaw)177 GST_START_TEST (test_jpeg2000_alaw)
178 {
179 gchar *pipeline;
180 GstElementFactory *factory = NULL;
181
182 if ((factory = gst_element_factory_find ("openjpegenc")) == NULL)
183 return;
184 gst_object_unref (factory);
185 if ((factory = gst_element_factory_find ("alawenc")) == NULL)
186 return;
187 gst_object_unref (factory);
188
189 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
190 "video/x-raw,framerate=25/1 ! "
191 "openjpegenc ! "
192 "mxfmux name=mux ! "
193 "mxfdemux name=demux ! "
194 "fakesink "
195 "audiotestsrc num-buffers=250 ! " "audioconvert ! " "alawenc ! " "mux. ");
196
197 run_test (pipeline, 2);
198 g_free (pipeline);
199 }
200
201 GST_END_TEST;
202
GST_START_TEST(test_dnxhd_mp3)203 GST_START_TEST (test_dnxhd_mp3)
204 {
205 gchar *pipeline;
206 GstElementFactory *factory = NULL;
207
208 if ((factory = gst_element_factory_find ("avenc_dnxhd")) == NULL)
209 return;
210 gst_object_unref (factory);
211 if ((factory = gst_element_factory_find ("lamemp3enc")) == NULL)
212 return;
213 gst_object_unref (factory);
214 if ((factory = gst_element_factory_find ("mpegaudioparse")) == NULL)
215 return;
216 gst_object_unref (factory);
217
218 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
219 "video/x-raw,format=(string)Y42B,width=1920,height=1080,framerate=25/1 ! "
220 "avenc_dnxhd bitrate=36000000 ! "
221 "mxfmux name=mux ! "
222 "mxfdemux name=demux ! "
223 "fakesink "
224 "audiotestsrc num-buffers=250 ! "
225 "audioconvert ! "
226 "audio/x-raw,channels=2 ! lamemp3enc ! mpegaudioparse ! mux. ");
227
228 run_test (pipeline, 2);
229 g_free (pipeline);
230 }
231
232 GST_END_TEST;
233
GST_START_TEST(test_multiple_av_streams)234 GST_START_TEST (test_multiple_av_streams)
235 {
236 gchar *pipeline;
237
238 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
239 "video/x-raw,format=(string)v308,width=1920,height=1080,framerate=25/1 ! "
240 "mxfmux name=mux ! "
241 "mxfdemux name=demux ! "
242 "fakesink "
243 "audiotestsrc num-buffers=250 ! "
244 "audioconvert ! "
245 "audio/x-raw,rate=48000,channels=2 ! "
246 "mux. "
247 "videotestsrc num-buffers=100 ! "
248 "video/x-raw,format=(string)v308,width=1920,height=1080,framerate=25/1 ! "
249 "mux. "
250 "audiotestsrc num-buffers=100 ! "
251 "audioconvert ! "
252 "audio/x-raw,rate=48000,channels=2 ! "
253 "mux. "
254 "audiotestsrc num-buffers=250 ! "
255 "audioconvert ! " "audio/x-raw,rate=48000,channels=2 ! " "mux. ");
256
257 run_test (pipeline, 5);
258 g_free (pipeline);
259 }
260
261 GST_END_TEST;
262
GST_START_TEST(test_h264_raw_audio)263 GST_START_TEST (test_h264_raw_audio)
264 {
265 gchar *pipeline;
266 GstElementFactory *factory = NULL;
267
268 if ((factory = gst_element_factory_find ("x264enc")) == NULL)
269 return;
270 gst_object_unref (factory);
271 if ((factory = gst_element_factory_find ("h264parse")) == NULL)
272 return;
273 gst_object_unref (factory);
274
275 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
276 "video/x-raw,framerate=25/1 ! "
277 "x264enc ! h264parse ! "
278 "mxfmux name=mux ! "
279 "mxfdemux name=demux ! "
280 "fakesink "
281 "audiotestsrc num-buffers=250 ! "
282 "audioconvert ! " "audio/x-raw,format=S24LE,channels=2 ! mux. ");
283
284 run_test (pipeline, 2);
285 g_free (pipeline);
286 }
287
288 GST_END_TEST;
289
290 static Suite *
mxf_suite(void)291 mxf_suite (void)
292 {
293 Suite *s = suite_create ("mxf");
294 TCase *tc_chain = tcase_create ("general");
295
296 suite_add_tcase (s, tc_chain);
297 tcase_set_timeout (tc_chain, 180);
298
299 tcase_add_test (tc_chain, test_mpeg2);
300 tcase_add_test (tc_chain, test_raw_video_raw_audio);
301 tcase_add_test (tc_chain, test_raw_video_stride_transform);
302 tcase_add_test (tc_chain, test_jpeg2000_alaw);
303 tcase_add_test (tc_chain, test_dnxhd_mp3);
304 tcase_add_test (tc_chain, test_h264_raw_audio);
305 tcase_add_test (tc_chain, test_multiple_av_streams);
306
307 return s;
308 }
309
310 GST_CHECK_MAIN (mxf);
311