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., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, 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 gst_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 gst_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 #if !GLIB_CHECK_VERSION (2, 31, 0)
183 if (!g_thread_supported ())
184 g_thread_init (NULL);
187 /* command line option parsing */
188 ctx = g_option_context_new ("FILENAME");
189 g_option_context_add_group (ctx, gst_init_get_option_group ());
190 g_option_context_add_main_entries (ctx, test_goptions, NULL);
192 if (!g_option_context_parse (ctx, &argc, &argv, &opt_err)) {
193 g_error ("Error parsing command line options: %s", opt_err->message);
197 GST_DEBUG_CATEGORY_INIT (equalizer_test_debug, "equalizertest", 0, "eqtest");
199 if (filenames == NULL || *filenames == NULL) {
200 g_printerr ("Please specify a file to play back\n");
204 playbin = gst_element_factory_make ("playbin", "playbin");
205 if (playbin == NULL) {
206 g_error ("Couldn't create 'playbin' element");
210 if (opt_audiosink_str) {
211 g_print ("Trying audiosink '%s' ...", opt_audiosink_str);
212 sink = gst_element_factory_make (opt_audiosink_str, "sink");
213 g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
218 g_print ("Trying audiosink '%s' ...", "autoaudiosink");
219 sink = gst_element_factory_make ("autoaudiosink", "sink");
220 g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
223 g_print ("Trying audiosink '%s' ...", "alsasink");
224 sink = gst_element_factory_make ("alsasink", "sink");
225 g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
228 g_print ("Trying audiosink '%s' ...", "osssink");
229 sink = gst_element_factory_make ("osssink", "sink");
230 g_print ("%s\n", (sink) ? "ok" : "element couldn't be created");
233 g_assert (sink != NULL);
235 bin = gst_bin_new ("ausinkbin");
236 g_assert (bin != NULL);
238 eq = gst_element_factory_make ("equalizer-nbands", "equalizer");
239 g_assert (eq != NULL);
241 auconv = gst_element_factory_make ("audioconvert", "eqauconv");
242 g_assert (auconv != NULL);
244 gst_bin_add_many (GST_BIN (bin), eq, auconv, sink, NULL);
246 if (!gst_element_link (eq, auconv))
247 g_error ("Failed to link equalizer to audioconvert");
249 if (!gst_element_link (auconv, sink))
250 g_error ("Failed to link audioconvert to audio sink");
252 eq_sinkpad = gst_element_get_static_pad (eq, "sink");
253 g_assert (eq_sinkpad != NULL);
255 gst_element_add_pad (bin, gst_ghost_pad_new (NULL, eq_sinkpad));
256 gst_object_unref (eq_sinkpad);
258 g_object_set (playbin, "audio-sink", bin, NULL);
260 /* won't work: uri = gst_uri_construct ("file", filenames[0]); */
261 uri = g_strdup_printf ("file://%s", filenames[0]);
262 g_object_set (playbin, "uri", uri, NULL);
265 pipeline_bus = GST_ELEMENT_BUS (playbin);
267 ret = gst_element_set_state (playbin, GST_STATE_PLAYING);
268 if (ret == GST_STATE_CHANGE_FAILURE) {
269 g_printerr ("Failed to set playbin to PLAYING\n");
270 check_bus (1 * GST_SECOND);
274 ret = gst_element_get_state (playbin, NULL, NULL, 5 * GST_SECOND);
275 if (ret == GST_STATE_CHANGE_ASYNC) {
276 g_printerr ("Failed to go to PLAYING in 5 seconds, bailing out\n");
278 } else if (ret != GST_STATE_CHANGE_SUCCESS) {
279 g_printerr ("State change to PLAYING failed\n");
280 check_bus (1 * GST_SECOND);
284 g_print ("Playing ...\n");
285 do_slider_fiddling (playbin, eq);
287 gst_element_set_state (playbin, GST_STATE_NULL);
288 gst_object_unref (playbin);