1 /* GStreamer unit tests for avdec_adpcm
2 *
3 * Copyright (C) 2009 Tim-Philipp Müller <tim centricular net>
4 *
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.
9 *
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.
14 *
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., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #include <gst/check/gstcheck.h>
22
23 #include <gst/gst.h>
24
25 static void
pad_added_cb(GstElement * decodebin,GstPad * pad,GstBin * pipeline)26 pad_added_cb (GstElement * decodebin, GstPad * pad, GstBin * pipeline)
27 {
28 GstElement *sink;
29
30 GST_INFO_OBJECT (pad, "got pad");
31
32 sink = gst_bin_get_by_name (pipeline, "fakesink");
33 fail_unless (gst_element_link (decodebin, sink));
34 gst_object_unref (sink);
35
36 gst_element_set_state (sink, GST_STATE_PAUSED);
37 }
38
39 static GstBusSyncReply
error_cb(GstBus * bus,GstMessage * msg,gpointer user_data)40 error_cb (GstBus * bus, GstMessage * msg, gpointer user_data)
41 {
42 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
43 const gchar *file = (const gchar *) user_data;
44 GError *err = NULL;
45 gchar *dbg = NULL;
46
47 gst_message_parse_error (msg, &err, &dbg);
48 g_error ("ERROR for %s: %s\n%s\n", file, err->message, dbg);
49 }
50
51 return GST_BUS_PASS;
52 }
53
54 static gboolean
decode_file(const gchar * file,gboolean push_mode)55 decode_file (const gchar * file, gboolean push_mode)
56 {
57 GstStateChangeReturn state_ret;
58 GstElement *sink, *src, *dec, *queue, *pipeline;
59 GstMessage *msg;
60 GstBus *bus;
61 gchar *path;
62
63 pipeline = gst_pipeline_new ("pipeline");
64 fail_unless (pipeline != NULL, "Failed to create pipeline!");
65
66 src = gst_element_factory_make ("filesrc", "filesrc");
67 fail_unless (src != NULL, "Failed to create filesrc!");
68
69 if (push_mode) {
70 queue = gst_element_factory_make ("queue", "queue");
71 } else {
72 queue = gst_element_factory_make ("identity", "identity");
73 }
74
75 dec = gst_element_factory_make ("decodebin", "decodebin");
76 fail_unless (dec != NULL, "Failed to create decodebin!");
77
78 sink = gst_element_factory_make ("fakesink", "fakesink");
79 fail_unless (sink != NULL, "Failed to create fakesink!");
80
81 bus = gst_element_get_bus (pipeline);
82
83 /* kids, don't use a sync handler for this at home, really; we do because
84 * we just want to abort and nothing else */
85 gst_bus_set_sync_handler (bus, error_cb, (gpointer) file, NULL);
86
87 gst_bin_add_many (GST_BIN (pipeline), src, queue, dec, sink, NULL);
88 gst_element_link_many (src, queue, dec, NULL);
89
90 path = g_build_filename (GST_TEST_FILES_PATH, file, NULL);
91 GST_LOG ("reading file '%s'", path);
92 g_object_set (src, "location", path, NULL);
93
94 /* can't link uridecodebin and sink yet, do that later */
95 g_signal_connect (dec, "pad-added", G_CALLBACK (pad_added_cb), pipeline);
96
97 state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
98 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
99
100 if (state_ret == GST_STATE_CHANGE_ASYNC) {
101 GST_LOG ("waiting for pipeline to reach PAUSED state");
102 state_ret = gst_element_get_state (pipeline, NULL, NULL, -1);
103 fail_unless_equals_int (state_ret, GST_STATE_CHANGE_SUCCESS);
104 }
105
106 state_ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
107 fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
108
109 GST_LOG ("PAUSED, let's decode");
110 msg = gst_bus_timed_pop_filtered (bus, 10 * GST_SECOND, GST_MESSAGE_EOS);
111 GST_LOG ("Done, got EOS message");
112 fail_unless (msg != NULL);
113 gst_message_unref (msg);
114 gst_object_unref (bus);
115
116 fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
117 GST_STATE_CHANGE_SUCCESS);
118 gst_object_unref (pipeline);
119
120 g_free (path);
121
122 return TRUE;
123 }
124
125 static void
run_check_for_file(const gchar * filename)126 run_check_for_file (const gchar * filename)
127 {
128 gboolean ret;
129
130 /* first, pull-based */
131 ret = decode_file (filename, FALSE);
132 fail_unless (ret == TRUE, "Failed to decode '%s' (pull mode)", filename);
133
134 /* second, push-based */
135 ret = decode_file (filename, TRUE);
136 fail_unless (ret == TRUE, "Failed to decode '%s' (push mode)", filename);
137 }
138
GST_START_TEST(test_low_sample_rate_adpcm)139 GST_START_TEST (test_low_sample_rate_adpcm)
140 {
141 #define MIN_VERSION GST_VERSION_MAJOR, GST_VERSION_MINOR, 0
142 if (!gst_registry_check_feature_version (gst_registry_get (), "wavparse",
143 MIN_VERSION)
144 || !gst_registry_check_feature_version (gst_registry_get (), "decodebin",
145 MIN_VERSION)) {
146 g_printerr ("skipping test_low_sample_rate_adpcm: required element "
147 "wavparse or element decodebin not found\n");
148 return;
149 }
150
151 run_check_for_file ("591809.wav");
152 }
153
154 GST_END_TEST;
155
156 static Suite *
avdec_adpcm_suite(void)157 avdec_adpcm_suite (void)
158 {
159 Suite *s = suite_create ("avdec_adpcm");
160 TCase *tc_chain = tcase_create ("general");
161
162 suite_add_tcase (s, tc_chain);
163 tcase_skip_broken_test (tc_chain, test_low_sample_rate_adpcm);
164
165 return s;
166 }
167
168 GST_CHECK_MAIN (avdec_adpcm)
169