3 * volume.c: sample application to change the volume of a pipeline
5 * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
26 /* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
27 * with newer GTK versions (>= 3.3.0) */
28 #define GDK_DISABLE_DEPRECATION_WARNINGS
35 /* global pointer for the scale widget */
36 static GtkWidget *elapsed;
37 static GtkWidget *scale;
40 #define M_LN10 (log(10.0))
44 value_changed_callback (GtkWidget * widget, GstElement * volume)
49 value = gtk_range_get_value (GTK_RANGE (widget));
50 level = exp (value / 20.0 * M_LN10);
51 g_print ("Value: %f dB, level: %f\n", value, level);
52 g_object_set (volume, "volume", level, NULL);
56 setup_gui (GstElement * volume)
60 GtkWidget *label, *hbox;
62 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
63 g_signal_connect (window, "destroy", gtk_main_quit, NULL);
65 vbox = gtk_vbox_new (TRUE, 0);
66 gtk_container_add (GTK_CONTAINER (window), vbox);
69 hbox = gtk_hbox_new (TRUE, 0);
70 label = gtk_label_new ("Elapsed");
71 elapsed = gtk_label_new ("0.000");
72 gtk_container_add (GTK_CONTAINER (hbox), label);
73 gtk_container_add (GTK_CONTAINER (hbox), elapsed);
74 gtk_container_add (GTK_CONTAINER (vbox), hbox);
77 hbox = gtk_hbox_new (TRUE, 0);
78 label = gtk_label_new ("volume");
79 gtk_container_add (GTK_CONTAINER (hbox), label);
80 scale = gtk_hscale_new_with_range (-90.0, 10.0, 0.2);
81 gtk_range_set_value (GTK_RANGE (scale), 0.0);
82 gtk_widget_set_size_request (scale, 100, -1);
83 gtk_container_add (GTK_CONTAINER (hbox), scale);
84 gtk_container_add (GTK_CONTAINER (vbox), hbox);
85 g_signal_connect (scale, "value-changed",
86 G_CALLBACK (value_changed_callback), volume);
88 gtk_widget_show_all (GTK_WIDGET (window));
92 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
94 const GstStructure *s;
96 s = gst_message_get_structure (message);
97 g_print ("message from \"%s\" (%s): ",
98 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
99 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
103 sstr = gst_structure_to_string (s);
104 g_print ("%s\n", sstr);
107 g_print ("no message details\n");
112 eos_message_received (GstBus * bus, GstMessage * message,
113 GstPipeline * pipeline)
115 message_received (bus, message, pipeline);
120 main (int argc, char *argv[])
123 GstElement *pipeline = NULL;
125 #ifndef GST_DISABLE_PARSE
126 GError *error = NULL;
131 #ifdef GST_DISABLE_PARSE
132 g_print ("GStreamer was built without pipeline parsing capabilities.\n");
134 ("Please rebuild GStreamer with pipeline parsing capabilities activated to use this example.\n");
137 gst_init (&argc, &argv);
138 gtk_init (&argc, &argv);
140 pipeline = gst_parse_launchv ((const gchar **) &argv[1], &error);
142 g_print ("pipeline could not be constructed: %s\n", error->message);
143 g_print ("Please give a complete pipeline with a 'volume' element.\n");
144 g_print ("Example: audiotestsrc ! volume ! %s\n", DEFAULT_AUDIOSINK);
145 g_error_free (error);
149 volume = gst_bin_get_by_name (GST_BIN (pipeline), "volume0");
150 if (volume == NULL) {
151 g_print ("Please give a pipeline with a 'volume' element in it\n");
155 /* setup message handling */
156 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
157 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
158 g_signal_connect (bus, "message::error", (GCallback) message_received,
160 g_signal_connect (bus, "message::warning", (GCallback) message_received,
162 g_signal_connect (bus, "message::eos", (GCallback) eos_message_received,
168 /* go to main loop */
169 gst_element_set_state (pipeline, GST_STATE_PLAYING);
171 gst_element_set_state (pipeline, GST_STATE_NULL);
172 gst_object_unref (pipeline);