~ubuntu-branches/ubuntu/precise/gst-plugins-bad0.10/precise-proposed

« back to all changes in this revision

Viewing changes to tests/check/pipelines/mxf.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2009-05-12 09:51:24 UTC
  • mto: (18.3.2 experimental) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 31.
  • Revision ID: james.westby@ubuntu.com-20090512095124-ugy051q0n88kk9f8
Tags: upstream-0.10.11.2
Import upstream version 0.10.11.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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., 59 Temple Place - Suite 330,
 
20
 * Boston, MA 02111-1307, USA.
 
21
 */
 
22
 
 
23
#include <gst/check/gstcheck.h>
 
24
#include <string.h>
 
25
 
 
26
static const gchar *
 
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 ("ffenc_mpeg2video"))) {
 
35
    gst_object_unref (factory);
 
36
    return "ffenc_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
 
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
 
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
 
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
  gst_object_unref (bus);
 
109
 
 
110
  ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
 
111
  fail_unless (ret == GST_STATE_CHANGE_SUCCESS
 
112
      || ret == GST_STATE_CHANGE_ASYNC);
 
113
 
 
114
  g_main_loop_run (loop);
 
115
 
 
116
  fail_unless (gst_element_set_state (pipeline,
 
117
          GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
 
118
 
 
119
  fail_unless (omud.eos == TRUE);
 
120
  fail_unless_equals_int (n_pads, n_pads_expected);
 
121
 
 
122
  gst_object_unref (pipeline);
 
123
  g_main_loop_unref (loop);
 
124
}
 
125
 
 
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-yuv,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
 
 
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-yuv,format=(GstFourcc)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-int,rate=48000,channels=2 ! " "mux. ");
 
156
 
 
157
  run_test (pipeline, 2);
 
158
  g_free (pipeline);
 
159
}
 
160
 
 
161
GST_END_TEST;
 
162
 
 
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-yuv,format=(GstFourcc)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
 
 
177
GST_START_TEST (test_jpeg2000_alaw)
 
178
{
 
179
  gchar *pipeline;
 
180
  GstElementFactory *factory = NULL;
 
181
 
 
182
  if ((factory = gst_element_factory_find ("jp2kenc")) == 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-yuv,framerate=25/1 ! "
 
191
      "jp2kenc ! "
 
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
 
 
203
GST_START_TEST (test_dnxhd_mp3)
 
204
{
 
205
  gchar *pipeline;
 
206
  GstElementFactory *factory = NULL;
 
207
 
 
208
  if ((factory = gst_element_factory_find ("ffenc_dnxhd")) == NULL)
 
209
    return;
 
210
  gst_object_unref (factory);
 
211
  if ((factory = gst_element_factory_find ("lame")) == NULL)
 
212
    return;
 
213
  gst_object_unref (factory);
 
214
  if ((factory = gst_element_factory_find ("mp3parse")) == NULL)
 
215
    return;
 
216
  gst_object_unref (factory);
 
217
 
 
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 ! "
 
221
      "mxfmux name=mux ! "
 
222
      "mxfdemux name=demux ! "
 
223
      "fakesink  "
 
224
      "audiotestsrc num-buffers=250 ! "
 
225
      "audioconvert ! "
 
226
      "audio/x-raw-int,channels=2 ! " "lame ! " "mp3parse ! " "mux. ");
 
227
 
 
228
  run_test (pipeline, 2);
 
229
  g_free (pipeline);
 
230
}
 
231
 
 
232
GST_END_TEST;
 
233
 
 
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-yuv,format=(GstFourcc)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-int,rate=48000,channels=2 ! "
 
246
      "mux. "
 
247
      "videotestsrc num-buffers=100 ! "
 
248
      "video/x-raw-yuv,format=(GstFourcc)v308,width=1920,height=1080,framerate=25/1 ! "
 
249
      "mux. "
 
250
      "audiotestsrc num-buffers=100 ! "
 
251
      "audioconvert ! "
 
252
      "audio/x-raw-int,rate=48000,channels=2 ! "
 
253
      "mux. "
 
254
      "audiotestsrc num-buffers=250 ! "
 
255
      "audioconvert ! " "audio/x-raw-int,rate=48000,channels=2 ! " "mux. ");
 
256
 
 
257
  run_test (pipeline, 5);
 
258
  g_free (pipeline);
 
259
}
 
260
 
 
261
GST_END_TEST;
 
262
 
 
263
static Suite *
 
264
mxf_suite (void)
 
265
{
 
266
  Suite *s = suite_create ("mxf");
 
267
  TCase *tc_chain = tcase_create ("general");
 
268
 
 
269
  suite_add_tcase (s, tc_chain);
 
270
  tcase_set_timeout (tc_chain, 180);
 
271
 
 
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);
 
278
 
 
279
  return s;
 
280
}
 
281
 
 
282
GST_CHECK_MAIN (mxf);