5
* Copyright (C) <2008> Mark Nauwelaerts <mnauw@users.sf.net>
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.
25
#include <gst/check/gstcheck.h>
27
/* For ease of programming we use globals to keep refs for our floating
28
* src and sink pads we create; otherwise we always have to do get_pad,
29
* get_peer, and then remove references in every test function */
30
static GstPad *mysrcpad, *mysinkpad;
32
#define AUDIO_CAPS_STRING "audio/mpeg, " \
33
"mpegversion = (int) 1, " \
35
"channels = (int) 2, " \
37
#define VIDEO_CAPS_STRING "video/mpeg, " \
38
"mpegversion = (int) 4, " \
39
"width = (int) 384, " \
40
"height = (int) 288, " \
41
"framerate = (fraction) 25/1"
43
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
46
GST_STATIC_CAPS ("video/quicktime"));
47
static GstStaticPadTemplate srcvideotemplate = GST_STATIC_PAD_TEMPLATE ("src",
50
GST_STATIC_CAPS (VIDEO_CAPS_STRING));
52
static GstStaticPadTemplate srcaudiotemplate = GST_STATIC_PAD_TEMPLATE ("src",
55
GST_STATIC_CAPS (AUDIO_CAPS_STRING));
58
/* setup and teardown needs some special handling for muxer */
60
setup_src_pad (GstElement * element,
61
GstStaticPadTemplate * template, GstCaps * caps, const gchar * sinkname)
63
GstPad *srcpad, *sinkpad;
65
GST_DEBUG_OBJECT (element, "setting up sending pad");
67
srcpad = gst_pad_new_from_static_template (template, "src");
68
fail_if (srcpad == NULL, "Could not create a srcpad");
69
ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
71
if (!(sinkpad = gst_element_get_static_pad (element, sinkname)))
72
sinkpad = gst_element_get_request_pad (element, sinkname);
73
fail_if (sinkpad == NULL, "Could not get sink pad from %s",
74
GST_ELEMENT_NAME (element));
75
/* references are owned by: 1) us, 2) qtmux, 3) collect pads */
76
ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 3);
78
fail_unless (gst_pad_set_caps (srcpad, caps));
79
fail_unless (gst_pad_link (srcpad, sinkpad) == GST_PAD_LINK_OK,
80
"Could not link source and %s sink pads", GST_ELEMENT_NAME (element));
81
gst_object_unref (sinkpad); /* because we got it higher up */
83
/* references are owned by: 1) qtmux, 2) collect pads */
84
ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2);
90
teardown_src_pad (GstPad * srcpad)
94
/* clean up floating src pad */
95
sinkpad = gst_pad_get_peer (srcpad);
96
fail_if (sinkpad == NULL);
97
/* pad refs held by 1) qtmux 2) collectpads and 3) us (through _get_peer) */
98
ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 3);
100
gst_pad_unlink (srcpad, sinkpad);
102
/* after unlinking, pad refs still held by
103
* 1) qtmux and 2) collectpads and 3) us (through _get_peer) */
104
ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 3);
105
gst_object_unref (sinkpad);
106
/* one more ref is held by element itself */
108
/* pad refs held by creator */
109
ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1);
110
gst_object_unref (srcpad);
114
setup_qtmux (GstStaticPadTemplate * srctemplate, const gchar * sinkname)
118
GST_DEBUG ("setup_qtmux");
119
qtmux = gst_check_setup_element ("qtmux");
120
mysrcpad = setup_src_pad (qtmux, srctemplate, NULL, sinkname);
121
mysinkpad = gst_check_setup_sink_pad (qtmux, &sinktemplate, NULL);
122
gst_pad_set_active (mysrcpad, TRUE);
123
gst_pad_set_active (mysinkpad, TRUE);
129
cleanup_qtmux (GstElement * qtmux, const gchar * sinkname)
131
GST_DEBUG ("cleanup_qtmux");
132
gst_element_set_state (qtmux, GST_STATE_NULL);
134
gst_pad_set_active (mysrcpad, FALSE);
135
gst_pad_set_active (mysinkpad, FALSE);
136
teardown_src_pad (mysrcpad);
137
gst_check_teardown_sink_pad (qtmux);
138
gst_check_teardown_element (qtmux);
142
check_qtmux_pad (GstStaticPadTemplate * srctemplate, const gchar * sinkname)
145
GstBuffer *inbuffer, *outbuffer;
149
guint8 data0[12] = "\000\000\000\024ftypqt ";
150
guint8 data1[8] = "\000\000\000\001mdat";
151
guint8 data2[4] = "moov";
153
qtmux = setup_qtmux (srctemplate, sinkname);
154
fail_unless (gst_element_set_state (qtmux,
155
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
156
"could not set to playing");
158
inbuffer = gst_buffer_new_and_alloc (1);
159
caps = gst_caps_copy (gst_pad_get_pad_template_caps (mysrcpad));
160
gst_buffer_set_caps (inbuffer, caps);
161
gst_caps_unref (caps);
162
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
163
GST_BUFFER_DURATION (inbuffer) = 40 * GST_MSECOND;
164
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
165
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
167
/* send eos to have moov written */
168
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()) == TRUE);
170
num_buffers = g_list_length (buffers);
171
/* at least expect ftyp, mdat header, buffer chunk and moov */
172
fail_unless (num_buffers >= 4);
174
for (i = 0; i < num_buffers; ++i) {
175
outbuffer = GST_BUFFER (buffers->data);
176
fail_if (outbuffer == NULL);
177
buffers = g_list_remove (buffers, outbuffer);
183
guint8 *data = GST_BUFFER_DATA (outbuffer);
185
fail_unless (GST_BUFFER_SIZE (outbuffer) >= 20);
186
fail_unless (memcmp (data, data0, sizeof (data0)) == 0);
187
fail_unless (memcmp (data + 16, data0 + 8, 4) == 0);
190
case 1: /* mdat header */
191
fail_unless (GST_BUFFER_SIZE (outbuffer) == 16);
192
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), data1, sizeof (data1))
195
case 2: /* buffer we put in */
196
fail_unless (GST_BUFFER_SIZE (outbuffer) == 1);
199
fail_unless (GST_BUFFER_SIZE (outbuffer) > 8);
200
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer) + 4, data2,
201
sizeof (data2)) == 0);
207
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
208
gst_buffer_unref (outbuffer);
212
g_list_free (buffers);
215
cleanup_qtmux (qtmux, sinkname);
219
check_qtmux_pad_fragmented (GstStaticPadTemplate * srctemplate,
220
const gchar * sinkname, gboolean streamable)
223
GstBuffer *inbuffer, *outbuffer;
227
guint8 data0[12] = "\000\000\000\024ftypqt ";
228
guint8 data1[4] = "mdat";
229
guint8 data2[4] = "moov";
230
guint8 data3[4] = "moof";
231
guint8 data4[4] = "mfra";
233
qtmux = setup_qtmux (srctemplate, sinkname);
234
g_object_set (qtmux, "fragment-duration", 2000, NULL);
235
g_object_set (qtmux, "streamable", streamable, NULL);
236
fail_unless (gst_element_set_state (qtmux,
237
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
238
"could not set to playing");
240
inbuffer = gst_buffer_new_and_alloc (1);
241
caps = gst_caps_copy (gst_pad_get_pad_template_caps (mysrcpad));
242
gst_buffer_set_caps (inbuffer, caps);
243
gst_caps_unref (caps);
244
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
245
GST_BUFFER_DURATION (inbuffer) = 40 * GST_MSECOND;
246
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
247
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
249
/* send eos to have all written */
250
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()) == TRUE);
252
num_buffers = g_list_length (buffers);
253
/* at least expect ftyp, moov, moof, mdat header, buffer chunk
254
* and optionally mfra */
255
fail_unless (num_buffers >= 5);
257
for (i = 0; i < num_buffers; ++i) {
258
outbuffer = GST_BUFFER (buffers->data);
259
fail_if (outbuffer == NULL);
260
buffers = g_list_remove (buffers, outbuffer);
266
guint8 *data = GST_BUFFER_DATA (outbuffer);
268
fail_unless (GST_BUFFER_SIZE (outbuffer) >= 20);
269
fail_unless (memcmp (data, data0, sizeof (data0)) == 0);
270
fail_unless (memcmp (data + 16, data0 + 8, 4) == 0);
274
fail_unless (GST_BUFFER_SIZE (outbuffer) > 8);
275
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer) + 4, data2,
276
sizeof (data2)) == 0);
279
fail_unless (GST_BUFFER_SIZE (outbuffer) > 8);
280
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer) + 4, data3,
281
sizeof (data3)) == 0);
283
case 3: /* mdat header */
284
fail_unless (GST_BUFFER_SIZE (outbuffer) == 8);
285
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer) + 4, data1,
286
sizeof (data1)) == 0);
288
case 4: /* buffer we put in */
289
fail_unless (GST_BUFFER_SIZE (outbuffer) == 1);
292
fail_unless (GST_BUFFER_SIZE (outbuffer) > 8);
293
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer) + 4, data4,
294
sizeof (data4)) == 0);
300
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
301
gst_buffer_unref (outbuffer);
305
g_list_free (buffers);
308
cleanup_qtmux (qtmux, sinkname);
312
GST_START_TEST (test_video_pad)
314
check_qtmux_pad (&srcvideotemplate, "video_%d");
319
GST_START_TEST (test_audio_pad)
321
check_qtmux_pad (&srcaudiotemplate, "audio_%d");
327
GST_START_TEST (test_video_pad_frag)
329
check_qtmux_pad_fragmented (&srcvideotemplate, "video_%d", FALSE);
334
GST_START_TEST (test_audio_pad_frag)
336
check_qtmux_pad_fragmented (&srcaudiotemplate, "audio_%d", FALSE);
342
GST_START_TEST (test_video_pad_frag_streamable)
344
check_qtmux_pad_fragmented (&srcvideotemplate, "video_%d", TRUE);
350
GST_START_TEST (test_audio_pad_frag_streamable)
352
check_qtmux_pad_fragmented (&srcaudiotemplate, "audio_%d", TRUE);
358
GST_START_TEST (test_reuse)
360
GstElement *qtmux = setup_qtmux (&srcvideotemplate, "video_%d");
364
gst_element_set_state (qtmux, GST_STATE_PLAYING);
365
gst_element_set_state (qtmux, GST_STATE_NULL);
366
gst_element_set_state (qtmux, GST_STATE_PLAYING);
367
gst_pad_set_active (mysrcpad, TRUE);
368
gst_pad_set_active (mysinkpad, TRUE);
370
inbuffer = gst_buffer_new_and_alloc (1);
371
fail_unless (inbuffer != NULL);
372
caps = gst_caps_copy (gst_pad_get_pad_template_caps (mysrcpad));
373
gst_buffer_set_caps (inbuffer, caps);
374
gst_caps_unref (caps);
375
GST_BUFFER_TIMESTAMP (inbuffer) = 0;
376
GST_BUFFER_DURATION (inbuffer) = 40 * GST_MSECOND;
377
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
378
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
380
/* send eos to have all written */
381
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()) == TRUE);
383
cleanup_qtmux (qtmux, "video_%d");
391
Suite *s = suite_create ("qtmux");
392
TCase *tc_chain = tcase_create ("general");
394
suite_add_tcase (s, tc_chain);
395
tcase_add_test (tc_chain, test_video_pad);
396
tcase_add_test (tc_chain, test_audio_pad);
397
tcase_add_test (tc_chain, test_video_pad_frag);
398
tcase_add_test (tc_chain, test_audio_pad_frag);
399
tcase_add_test (tc_chain, test_video_pad_frag_streamable);
400
tcase_add_test (tc_chain, test_audio_pad_frag_streamable);
402
tcase_add_test (tc_chain, test_reuse);
408
main (int argc, char **argv)
412
Suite *s = qtmux_suite ();
413
SRunner *sr = srunner_create (s);
415
gst_check_init (&argc, &argv);
417
srunner_run_all (sr, CK_NORMAL);
418
nf = srunner_ntests_failed (sr);