1 /* GStreamer test for the equalizer element
2 * Copyright (C) 2007 Tim-Philipp Müller <tim centricular net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 * Will tests the equalizer by fading all bands in and out one by one and
22 * finaly all together.
34 GST_DEBUG_CATEGORY_STATIC (equalizer_test_debug);
35 #define GST_CAT_DEFAULT equalizer_test_debug
37 static GstBus *pipeline_bus;
40 check_bus (GstClockTime max_wait_time)
44 msg = gst_bus_poll (pipeline_bus, GST_MESSAGE_ERROR | GST_MESSAGE_EOS,
50 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
54 g_assert (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
55 gst_message_parse_error (msg, &err, &debug);
56 GST_ERROR ("ERROR: %s [%s]", err->message, debug);
57 g_print ("\n===========> ERROR: %s\n%s\n\n", err->message, debug);
62 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS) {
63 g_print ("\n === EOS ===\n\n");
66 gst_message_unref (msg);
73 equalizer_set_band_value (GstElement * eq, guint band, gdouble val)
77 child = gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (eq), band);
78 g_object_set (child, "gain", val, NULL);
79 g_object_unref (child);
80 g_print ("Band %2d: %.2f\n", band, val);
84 equalizer_set_all_band_values (GstElement * eq, guint num, gdouble val)
89 for (i = 0; i < num; i++) {
90 child = gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (eq), i);
91 g_object_set (child, "gain", val, NULL);
92 g_object_unref (child);
94 g_print ("All bands: %.2f\n", val);
100 equalizer_set_band_value_and_wait (GstElement * eq, guint band, gdouble val)
102 equalizer_set_band_value (eq, band, val);
103 return check_bus (100 * GST_MSECOND);
107 equalizer_set_all_band_values_and_wait (GstElement * eq, guint num, gdouble val)
109 equalizer_set_all_band_values (eq, num, val);
110 return check_bus (100 * GST_MSECOND);
114 do_slider_fiddling (GstElement * playbin, GstElement * eq)
118 gdouble d, step = 0.5;
122 g_object_get (eq, "num-bands", &num_bands, NULL);
124 g_print ("%u bands.\n", num_bands);
127 for (i = 0; !stop && i < num_bands; ++i) {
129 while (!stop && d <= 12.0) {
130 stop = equalizer_set_band_value_and_wait (eq, i, d);
134 while (!stop && d >= -24.0) {
135 stop = equalizer_set_band_value_and_wait (eq, i, d);
139 while (!stop && d <= 12.0) {
140 stop = equalizer_set_band_value_and_wait (eq, i, d);
146 while (!stop && d <= 12.0) {
147 stop = equalizer_set_all_band_values_and_wait (eq, num_bands, d);
151 while (!stop && d >= -24.0) {
152 stop = equalizer_set_all_band_values_and_wait (eq, num_bands, d);
156 while (!stop && d <= 0.0) {
157 stop = equalizer_set_all_band_values_and_wait (eq, num_bands, d);
164 main (int argc, char **argv)
166 gchar *opt_audiosink_str = NULL;
167 gchar **filenames = NULL;
168 const GOptionEntry test_goptions[] = {
169 {"audiosink", '\0', 0, G_OPTION_ARG_STRING, &opt_audiosink_str,
170 "audiosink to use (default: autoaudiosink)", NULL},
171 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, NULL},
172 {NULL, '\0', 0, 0, NULL, NULL, NULL}
175 GError *opt_err = NULL;
177 GstStateChangeReturn ret;
178 GstElement *playbin, *sink, *bin, *eq, *auconv;
182 /* command line option parsing */
183 ctx = g_option_context_new ("FILENAME");
184 g_option_context_add_group (ctx, gst_init_get_option_group ());
185 g_option_context_add_main_entries (ctx, test_goptions, NULL);
187 if (!g_option_context_parse (ctx, &argc, &argv, &opt_err)) {
188 g_error ("Error parsing command line options: %s", opt_err->message);
189 g_option_context_free (ctx);
190 g_clear_error (&opt_err);
193 g_option_context_free (ctx);
195 GST_DEBUG_CATEGORY_INIT (equalizer_test_debug, "equalizertest", 0, "eqtest");
197 if (filenames == NULL || *filenames == NULL) {
198 g_printerr ("Please specify a file to play back\n");
202 playbin = gst_element_factory_make ("playbin", "playbin");
203 if (playbin == NULL) {
204 g_error ("Couldn't create 'playbin' element");
208 if (opt_audiosink_str) {
209 g_print ("Trying audiosink '%s' ...", opt_audiosink_str);
210 sink = gst_element_factory_make (opt_audiosink_str, "sink");
211 g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
216 g_print ("Trying audiosink '%s' ...", "autoaudiosink");
217 sink = gst_element_factory_make ("autoaudiosink", "sink");
218 g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
221 g_print ("Trying audiosink '%s' ...", "alsasink");
222 sink = gst_element_factory_make ("alsasink", "sink");
223 g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
226 g_print ("Trying audiosink '%s' ...", "osssink");
227 sink = gst_element_factory_make ("osssink", "sink");
228 g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
231 g_assert (sink != NULL);
233 bin = gst_bin_new ("ausinkbin");
234 g_assert (bin != NULL);
236 eq = gst_element_factory_make ("equalizer-nbands", "equalizer");
237 g_assert (eq != NULL);
239 auconv = gst_element_factory_make ("audioconvert", "eqauconv");
240 g_assert (auconv != NULL);
242 gst_bin_add_many (GST_BIN (bin), eq, auconv, sink, NULL);
244 if (!gst_element_link (eq, auconv))
245 g_error ("Failed to link equalizer to audioconvert");
247 if (!gst_element_link (auconv, sink))
248 g_error ("Failed to link audioconvert to audio sink");
250 eq_sinkpad = gst_element_get_static_pad (eq, "sink");
251 g_assert (eq_sinkpad != NULL);
253 gst_element_add_pad (bin, gst_ghost_pad_new (NULL, eq_sinkpad));
254 gst_object_unref (eq_sinkpad);
256 g_object_set (playbin, "audio-sink", bin, NULL);
258 /* won't work: uri = gst_uri_construct ("file", filenames[0]); */
259 uri = g_strdup_printf ("file://%s", filenames[0]);
260 g_object_set (playbin, "uri", uri, NULL);
263 pipeline_bus = GST_ELEMENT_BUS (playbin);
265 ret = gst_element_set_state (playbin, GST_STATE_PLAYING);
266 if (ret == GST_STATE_CHANGE_FAILURE) {
267 g_printerr ("Failed to set playbin to PLAYING\n");
268 check_bus (1 * GST_SECOND);
272 ret = gst_element_get_state (playbin, NULL, NULL, 5 * GST_SECOND);
273 if (ret == GST_STATE_CHANGE_ASYNC) {
274 g_printerr ("Failed to go to PLAYING in 5 seconds, bailing out\n");
276 } else if (ret != GST_STATE_CHANGE_SUCCESS) {
277 g_printerr ("State change to PLAYING failed\n");
278 check_bus (1 * GST_SECOND);
282 g_print ("Playing ...\n");
283 do_slider_fiddling (playbin, eq);
285 gst_element_set_state (playbin, GST_STATE_NULL);
286 gst_object_unref (playbin);