1 /* GStreamer unit tests for flvdemux
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>
26 pad_added_cb (GstElement * flvdemux, GstPad * pad, GstBin * pipeline)
30 sink = gst_bin_get_by_name (pipeline, "fakesink");
31 fail_unless (gst_element_link (flvdemux, sink));
32 gst_object_unref (sink);
34 gst_element_set_state (sink, GST_STATE_PAUSED);
37 static GstBusSyncReply
38 error_cb (GstBus * bus, GstMessage * msg, gpointer user_data)
40 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
41 const gchar *file = (const gchar *) user_data;
45 gst_message_parse_error (msg, &err, &dbg);
46 g_error ("ERROR for %s: %s\n%s\n", file, err->message, dbg);
53 handoff_cb (GstElement * element, GstBuffer * buf, GstPad * pad,
57 GST_LOG ("counter = %d", *p_counter);
59 fail_unless (GST_BUFFER_CAPS (buf) != NULL);
63 process_file (const gchar * file, gboolean push_mode, gint repeat,
66 GstElement *src, *sep, *sink, *flvdemux, *pipeline;
71 pipeline = gst_pipeline_new ("pipeline");
72 fail_unless (pipeline != NULL, "Failed to create pipeline!");
74 bus = gst_element_get_bus (pipeline);
76 /* kids, don't use a sync handler for this at home, really; we do because
77 * we just want to abort and nothing else */
78 gst_bus_set_sync_handler (bus, error_cb, (gpointer) file);
80 src = gst_element_factory_make ("filesrc", "filesrc");
81 fail_unless (src != NULL, "Failed to create 'filesrc' element!");
84 sep = gst_element_factory_make ("queue", "queue");
85 fail_unless (sep != NULL, "Failed to create 'queue' element");
87 sep = gst_element_factory_make ("identity", "identity");
88 fail_unless (sep != NULL, "Failed to create 'identity' element");
91 flvdemux = gst_element_factory_make ("flvdemux", "flvdemux");
92 fail_unless (flvdemux != NULL, "Failed to create 'flvdemux' element!");
94 sink = gst_element_factory_make ("fakesink", "fakesink");
95 fail_unless (sink != NULL, "Failed to create 'fakesink' element!");
97 g_object_set (sink, "signal-handoffs", TRUE, NULL);
98 g_signal_connect (sink, "handoff", G_CALLBACK (handoff_cb), &counter);
100 gst_bin_add_many (GST_BIN (pipeline), src, sep, flvdemux, sink, NULL);
102 fail_unless (gst_element_link (src, sep));
103 fail_unless (gst_element_link (sep, flvdemux));
105 /* can't link flvdemux and sink yet, do that later */
106 g_signal_connect (flvdemux, "pad-added", G_CALLBACK (pad_added_cb), pipeline);
108 path = g_build_filename (GST_TEST_FILES_PATH, file, NULL);
109 GST_LOG ("processing file '%s'", path);
110 g_object_set (src, "location", path, NULL);
113 GstStateChangeReturn state_ret;
116 GST_LOG ("repeat=%d", repeat);
120 state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
121 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
123 if (state_ret == GST_STATE_CHANGE_ASYNC) {
124 GST_LOG ("waiting for pipeline to reach PAUSED state");
125 state_ret = gst_element_get_state (pipeline, NULL, NULL, -1);
126 fail_unless_equals_int (state_ret, GST_STATE_CHANGE_SUCCESS);
129 GST_LOG ("PAUSED, let's read all of it");
131 state_ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
132 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
134 msg = gst_bus_poll (bus, GST_MESSAGE_EOS, -1);
135 fail_unless (msg != NULL, "Expected EOS message on bus! (%s)", file);
137 gst_message_unref (msg);
139 if (num_buffers >= 0) {
140 fail_unless_equals_int (counter, num_buffers);
143 fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
144 GST_STATE_CHANGE_SUCCESS);
147 } while (repeat > 0);
149 gst_object_unref (bus);
150 gst_object_unref (pipeline);
155 GST_START_TEST (test_reuse_pull)
157 process_file ("pcm16sine.flv", FALSE, 3, 129);
158 gst_task_cleanup_all ();
163 GST_START_TEST (test_reuse_push)
165 process_file ("pcm16sine.flv", TRUE, 3, 129);
166 gst_task_cleanup_all ();
172 flvdemux_suite (void)
174 Suite *s = suite_create ("flvdemux");
175 TCase *tc_chain = tcase_create ("general");
177 suite_add_tcase (s, tc_chain);
178 tcase_add_test (tc_chain, test_reuse_push);
179 tcase_add_test (tc_chain, test_reuse_pull);
184 GST_CHECK_MAIN (flvdemux)