1 /* GStreamer unit tests for flvmux
3 * Copyright (C) 2009 Tim-Philipp Müller <tim centricular net>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include <gst/check/gstcheck.h>
25 static GstBusSyncReply
26 error_cb (GstBus * bus, GstMessage * msg, gpointer user_data)
28 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
32 gst_message_parse_error (msg, &err, &dbg);
33 g_error ("ERROR: %s\n%s\n", err->message, dbg);
40 handoff_cb (GstElement * element, GstBuffer * buf, GstPad * pad,
44 GST_LOG ("counter = %d", *p_counter);
46 fail_unless (GST_BUFFER_CAPS (buf) != NULL);
50 mux_pcm_audio (guint num_buffers, guint repeat)
52 GstElement *src, *sink, *flvmux, *conv, *pipeline;
53 GstPad *sinkpad, *srcpad;
56 GST_LOG ("num_buffers = %u", num_buffers);
58 pipeline = gst_pipeline_new ("pipeline");
59 fail_unless (pipeline != NULL, "Failed to create pipeline!");
61 /* kids, don't use a sync handler for this at home, really; we do because
62 * we just want to abort and nothing else */
63 gst_bus_set_sync_handler (GST_ELEMENT_BUS (pipeline), error_cb, NULL);
65 src = gst_element_factory_make ("audiotestsrc", "audiotestsrc");
66 fail_unless (src != NULL, "Failed to create 'audiotestsrc' element!");
68 g_object_set (src, "num-buffers", num_buffers, NULL);
70 conv = gst_element_factory_make ("audioconvert", "audioconvert");
71 fail_unless (conv != NULL, "Failed to create 'audioconvert' element!");
73 flvmux = gst_element_factory_make ("flvmux", "flvmux");
74 fail_unless (flvmux != NULL, "Failed to create 'flvmux' element!");
76 sink = gst_element_factory_make ("fakesink", "fakesink");
77 fail_unless (sink != NULL, "Failed to create 'fakesink' element!");
79 g_object_set (sink, "signal-handoffs", TRUE, NULL);
80 g_signal_connect (sink, "handoff", G_CALLBACK (handoff_cb), &counter);
82 gst_bin_add_many (GST_BIN (pipeline), src, conv, flvmux, sink, NULL);
84 fail_unless (gst_element_link (src, conv));
85 fail_unless (gst_element_link (flvmux, sink));
87 /* now link the elements */
88 sinkpad = gst_element_get_request_pad (flvmux, "audio");
89 fail_unless (sinkpad != NULL, "Could not get audio request pad");
91 srcpad = gst_element_get_static_pad (conv, "src");
92 fail_unless (srcpad != NULL, "Could not get audioconvert's source pad");
94 fail_unless_equals_int (gst_pad_link (srcpad, sinkpad), GST_PAD_LINK_OK);
96 gst_object_unref (srcpad);
97 gst_object_unref (sinkpad);
100 GstStateChangeReturn state_ret;
103 GST_LOG ("repeat=%d", repeat);
107 state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
108 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
110 if (state_ret == GST_STATE_CHANGE_ASYNC) {
111 GST_LOG ("waiting for pipeline to reach PAUSED state");
112 state_ret = gst_element_get_state (pipeline, NULL, NULL, -1);
113 fail_unless_equals_int (state_ret, GST_STATE_CHANGE_SUCCESS);
116 GST_LOG ("PAUSED, let's do the rest of it");
118 state_ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
119 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
121 msg = gst_bus_poll (GST_ELEMENT_BUS (pipeline), GST_MESSAGE_EOS, -1);
122 fail_unless (msg != NULL, "Expected EOS message on bus!");
125 gst_message_unref (msg);
127 /* should have some output */
128 fail_unless (counter > 2);
130 fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
131 GST_STATE_CHANGE_SUCCESS);
133 /* repeat = test re-usability */
135 } while (repeat > 0);
137 gst_object_unref (pipeline);
140 GST_START_TEST (test_index_writing)
142 /* note: there's a magic 128 value in flvmux when doing index writing */
143 if ((__i__ % 33) == 1)
144 mux_pcm_audio (__i__, 2);
152 Suite *s = suite_create ("flvmux");
153 TCase *tc_chain = tcase_create ("general");
155 suite_add_tcase (s, tc_chain);
156 tcase_add_loop_test (tc_chain, test_index_writing, 1, 499);
161 GST_CHECK_MAIN (flvmux)