1 /* GStreamer unit tests for ffdec_adpcm
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 * decodebin, GstPad * pad, GstBin * pipeline)
30 GST_INFO_OBJECT (pad, "got pad");
32 sink = gst_bin_get_by_name (pipeline, "fakesink");
33 fail_unless (gst_element_link (decodebin, sink));
34 gst_object_unref (sink);
36 gst_element_set_state (sink, GST_STATE_PAUSED);
39 static GstBusSyncReply
40 error_cb (GstBus * bus, GstMessage * msg, gpointer user_data)
42 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
43 const gchar *file = (const gchar *) user_data;
47 gst_message_parse_error (msg, &err, &dbg);
48 g_error ("ERROR for %s: %s\n%s\n", file, err->message, dbg);
55 pad_check_get_range (GstPad * pad)
61 decode_file (const gchar * file, gboolean push_mode)
63 GstStateChangeReturn state_ret;
64 GstElement *sink, *src, *dec, *pipeline;
69 pipeline = gst_pipeline_new ("pipeline");
70 fail_unless (pipeline != NULL, "Failed to create pipeline!");
72 src = gst_element_factory_make ("filesrc", "filesrc");
73 fail_unless (src != NULL, "Failed to create filesrc!");
76 GstPad *pad = gst_element_get_static_pad (src, "src");
78 /* KIDS: don't do this at home! */
79 gst_pad_set_checkgetrange_function (pad, pad_check_get_range);
80 gst_object_unref (pad);
83 dec = gst_element_factory_make ("decodebin2", "decodebin2");
84 fail_unless (dec != NULL, "Failed to create decodebin2!");
86 sink = gst_element_factory_make ("fakesink", "fakesink");
87 fail_unless (sink != NULL, "Failed to create fakesink!");
89 bus = gst_element_get_bus (pipeline);
91 /* kids, don't use a sync handler for this at home, really; we do because
92 * we just want to abort and nothing else */
93 gst_bus_set_sync_handler (bus, error_cb, (gpointer) file);
95 gst_bin_add_many (GST_BIN (pipeline), src, dec, sink, NULL);
96 gst_element_link_many (src, dec, NULL);
98 path = g_build_filename (GST_TEST_FILES_PATH, file, NULL);
99 GST_LOG ("reading file '%s'", path);
100 g_object_set (src, "location", path, NULL);
102 /* can't link uridecodebin and sink yet, do that later */
103 g_signal_connect (dec, "pad-added", G_CALLBACK (pad_added_cb), pipeline);
105 state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
106 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
108 if (state_ret == GST_STATE_CHANGE_ASYNC) {
109 GST_LOG ("waiting for pipeline to reach PAUSED state");
110 state_ret = gst_element_get_state (pipeline, NULL, NULL, -1);
111 fail_unless_equals_int (state_ret, GST_STATE_CHANGE_SUCCESS);
114 state_ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
115 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
117 GST_LOG ("PAUSED, let's decode");
118 msg = gst_bus_timed_pop_filtered (bus, 10 * GST_SECOND, GST_MESSAGE_EOS);
119 GST_LOG ("Done, got EOS message");
120 fail_unless (msg != NULL);
121 gst_message_unref (msg);
122 gst_object_unref (bus);
124 fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
125 GST_STATE_CHANGE_SUCCESS);
126 gst_object_unref (pipeline);
134 run_check_for_file (const gchar * filename)
138 /* first, pull-based */
139 ret = decode_file (filename, FALSE);
140 fail_unless (ret == TRUE, "Failed to decode '%s' (pull mode)", filename);
142 /* first, pull-based */
143 ret = decode_file (filename, TRUE);
144 fail_unless (ret == TRUE, "Failed to decode '%s' (push mode)", filename);
147 GST_START_TEST (test_low_sample_rate_adpcm)
149 if (!gst_default_registry_check_feature_version ("wavparse", 0, 10, 0) ||
150 !gst_default_registry_check_feature_version ("decodebin2", 0, 10, 0)) {
151 g_printerr ("skipping test_low_sample_rate_adpcm: required element "
152 "wavparse or element decodebin2 not found\n");
156 run_check_for_file ("591809.wav");
162 ffdec_adpcm_suite (void)
164 Suite *s = suite_create ("ffdec_adpcm");
165 TCase *tc_chain = tcase_create ("general");
167 suite_add_tcase (s, tc_chain);
168 tcase_add_test (tc_chain, test_low_sample_rate_adpcm);
173 GST_CHECK_MAIN (ffdec_adpcm)