1 /* GStreamer
2 *
3 * unit test for mxfmux
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
run_test(const gchar * pipeline_string)68 run_test (const gchar * pipeline_string)
69 {
70 GstElement *pipeline;
71 GstBus *bus;
72 GMainLoop *loop;
73 OnMessageUserData omud = { NULL, };
74 GstStateChangeReturn ret;
75
76 GST_DEBUG ("Testing pipeline '%s'", pipeline_string);
77
78 pipeline = gst_parse_launch (pipeline_string, NULL);
79 fail_unless (pipeline != NULL);
80 g_object_set (G_OBJECT (pipeline), "async-handling", TRUE, NULL);
81
82 loop = g_main_loop_new (NULL, FALSE);
83
84 bus = gst_element_get_bus (pipeline);
85 fail_unless (bus != NULL);
86 gst_bus_add_signal_watch (bus);
87
88 omud.loop = loop;
89 omud.eos = FALSE;
90
91 g_signal_connect (bus, "message", (GCallback) on_message_cb, &omud);
92
93 ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
94 fail_unless (ret == GST_STATE_CHANGE_SUCCESS
95 || ret == GST_STATE_CHANGE_ASYNC);
96
97 g_main_loop_run (loop);
98
99 fail_unless (gst_element_set_state (pipeline,
100 GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
101
102 fail_unless (omud.eos == TRUE);
103
104 gst_object_unref (pipeline);
105 g_main_loop_unref (loop);
106 gst_bus_remove_signal_watch (bus);
107 gst_object_unref (bus);
108 }
109
GST_START_TEST(test_mpeg2)110 GST_START_TEST (test_mpeg2)
111 {
112 const gchar *mpeg2enc_name = get_mpeg2enc_element_name ();
113 gchar *pipeline;
114
115 if (!mpeg2enc_name)
116 return;
117
118 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
119 "video/x-raw,framerate=25/1 ! "
120 "%s ! " "mxfmux name=mux ! " "fakesink", mpeg2enc_name);
121
122 run_test (pipeline);
123 g_free (pipeline);
124 }
125
126 GST_END_TEST;
127
GST_START_TEST(test_raw_video_raw_audio)128 GST_START_TEST (test_raw_video_raw_audio)
129 {
130 gchar *pipeline;
131
132 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
133 "video/x-raw,format=(string)v308,width=1920,height=1080,framerate=25/1 ! "
134 "mxfmux name=mux ! "
135 "fakesink "
136 "audiotestsrc num-buffers=250 ! "
137 "audioconvert ! " "audio/x-raw,rate=48000,channels=2 ! " "mux. ");
138
139 run_test (pipeline);
140 g_free (pipeline);
141 }
142
143 GST_END_TEST;
144
GST_START_TEST(test_raw_video_stride_transform)145 GST_START_TEST (test_raw_video_stride_transform)
146 {
147 gchar *pipeline;
148
149 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
150 "video/x-raw,format=(string)v308,width=1001,height=501,framerate=25/1 ! "
151 "mxfmux name=mux ! " "fakesink");
152
153 run_test (pipeline);
154 g_free (pipeline);
155 }
156
157 GST_END_TEST;
158
GST_START_TEST(test_jpeg2000_alaw)159 GST_START_TEST (test_jpeg2000_alaw)
160 {
161 gchar *pipeline;
162 GstElementFactory *factory = NULL;
163
164 if ((factory = gst_element_factory_find ("openjpegenc")) == NULL)
165 return;
166 gst_object_unref (factory);
167 if ((factory = gst_element_factory_find ("alawenc")) == NULL)
168 return;
169 gst_object_unref (factory);
170
171 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
172 "video/x-raw,framerate=25/1 ! "
173 "openjpegenc ! "
174 "mxfmux name=mux ! "
175 "fakesink "
176 "audiotestsrc num-buffers=250 ! " "audioconvert ! " "alawenc ! " "mux. ");
177
178 run_test (pipeline);
179 g_free (pipeline);
180 }
181
182 GST_END_TEST;
183
GST_START_TEST(test_dnxhd_mp3)184 GST_START_TEST (test_dnxhd_mp3)
185 {
186 gchar *pipeline;
187 GstElementFactory *factory = NULL;
188
189 if ((factory = gst_element_factory_find ("avenc_dnxhd")) == NULL)
190 return;
191 gst_object_unref (factory);
192 if ((factory = gst_element_factory_find ("lamemp3enc")) == NULL)
193 return;
194 gst_object_unref (factory);
195 if ((factory = gst_element_factory_find ("mpegaudioparse")) == NULL)
196 return;
197 gst_object_unref (factory);
198
199 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
200 "video/x-raw,format=(string)Y42B,width=1920,height=1080,framerate=25/1 ! "
201 "avenc_dnxhd bitrate=36000000 ! "
202 "mxfmux name=mux ! "
203 "fakesink "
204 "audiotestsrc num-buffers=250 ! "
205 "audioconvert ! "
206 "audio/x-raw,channels=2 ! lamemp3enc ! mpegaudioparse ! mux. ");
207
208 run_test (pipeline);
209 g_free (pipeline);
210 }
211
212 GST_END_TEST;
213
GST_START_TEST(test_multiple_av_streams)214 GST_START_TEST (test_multiple_av_streams)
215 {
216 gchar *pipeline;
217
218 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
219 "video/x-raw,format=(string)v308,width=1920,height=1080,framerate=25/1 ! "
220 "mxfmux name=mux ! "
221 "fakesink "
222 "audiotestsrc num-buffers=250 ! "
223 "audioconvert ! "
224 "audio/x-raw,rate=48000,channels=2 ! "
225 "mux. "
226 "videotestsrc num-buffers=100 ! "
227 "video/x-raw,format=(string)v308,width=1920,height=1080,framerate=25/1 ! "
228 "mux. "
229 "audiotestsrc num-buffers=100 ! "
230 "audioconvert ! "
231 "audio/x-raw,rate=48000,channels=2 ! "
232 "mux. "
233 "audiotestsrc num-buffers=250 ! "
234 "audioconvert ! " "audio/x-raw,rate=48000,channels=2 ! " "mux. ");
235
236 run_test (pipeline);
237 g_free (pipeline);
238 }
239
240 GST_END_TEST;
241
GST_START_TEST(test_h264_raw_audio)242 GST_START_TEST (test_h264_raw_audio)
243 {
244 gchar *pipeline;
245 GstElementFactory *factory = NULL;
246
247 if ((factory = gst_element_factory_find ("x264enc")) == NULL)
248 return;
249 gst_object_unref (factory);
250 if ((factory = gst_element_factory_find ("h264parse")) == NULL)
251 return;
252 gst_object_unref (factory);
253
254 pipeline = g_strdup_printf ("videotestsrc num-buffers=250 ! "
255 "video/x-raw,framerate=25/1 ! "
256 "x264enc ! h264parse ! "
257 "mxfmux name=mux ! "
258 "fakesink "
259 "audiotestsrc num-buffers=250 ! "
260 "audioconvert ! " "audio/x-raw,format=S24LE,channels=2 ! mux. ");
261
262 run_test (pipeline);
263 g_free (pipeline);
264 }
265
266 GST_END_TEST;
267
268 static Suite *
mxfmux_suite(void)269 mxfmux_suite (void)
270 {
271 Suite *s = suite_create ("mxfmux");
272 TCase *tc_chain = tcase_create ("general");
273
274 suite_add_tcase (s, tc_chain);
275 tcase_set_timeout (tc_chain, 180);
276
277 tcase_add_test (tc_chain, test_mpeg2);
278 tcase_add_test (tc_chain, test_raw_video_raw_audio);
279 tcase_add_test (tc_chain, test_raw_video_stride_transform);
280 tcase_add_test (tc_chain, test_jpeg2000_alaw);
281 tcase_add_test (tc_chain, test_dnxhd_mp3);
282 tcase_add_test (tc_chain, test_h264_raw_audio);
283 tcase_add_test (tc_chain, test_multiple_av_streams);
284
285 return s;
286 }
287
288 GST_CHECK_MAIN (mxfmux);
289