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.
32 /* global pointer for the scale widget */
37 #define M_LN10 (log(10.0))
41 value_changed_callback (GtkWidget * widget, GstElement * volume)
46 value = gtk_range_get_value (GTK_RANGE (widget));
47 level = exp (value / 20.0 * M_LN10);
48 g_print ("Value: %f dB, level: %f\n", value, level);
49 g_object_set (volume, "volume", level, NULL);
53 setup_gui (GstElement * volume)
57 GtkWidget *label, *hbox;
59 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
60 g_signal_connect (window, "destroy", gtk_main_quit, NULL);
62 vbox = gtk_vbox_new (TRUE, 0);
63 gtk_container_add (GTK_CONTAINER (window), vbox);
66 hbox = gtk_hbox_new (TRUE, 0);
67 label = gtk_label_new ("Elapsed");
68 elapsed = gtk_label_new ("0.000");
69 gtk_container_add (GTK_CONTAINER (hbox), label);
70 gtk_container_add (GTK_CONTAINER (hbox), elapsed);
71 gtk_container_add (GTK_CONTAINER (vbox), hbox);
74 hbox = gtk_hbox_new (TRUE, 0);
75 label = gtk_label_new ("volume");
76 gtk_container_add (GTK_CONTAINER (hbox), label);
77 scale = gtk_hscale_new_with_range (-90.0, 10.0, 0.2);
78 gtk_range_set_value (GTK_RANGE (scale), 0.0);
79 gtk_widget_set_size_request (scale, 100, -1);
80 gtk_container_add (GTK_CONTAINER (hbox), scale);
81 gtk_container_add (GTK_CONTAINER (vbox), hbox);
82 g_signal_connect (scale, "value-changed",
83 G_CALLBACK (value_changed_callback), volume);
85 gtk_widget_show_all (GTK_WIDGET (window));
89 message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
91 const GstStructure *s;
93 s = gst_message_get_structure (message);
94 g_print ("message from \"%s\" (%s): ",
95 GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
96 gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
100 sstr = gst_structure_to_string (s);
101 g_print ("%s\n", sstr);
104 g_print ("no message details\n");
109 eos_message_received (GstBus * bus, GstMessage * message,
110 GstPipeline * pipeline)
112 message_received (bus, message, pipeline);
117 main (int argc, char *argv[])
120 GstElement *pipeline = NULL;
122 #ifndef GST_DISABLE_PARSE
123 GError *error = NULL;
128 #ifdef GST_DISABLE_PARSE
129 g_print ("GStreamer was built without pipeline parsing capabilities.\n");
131 ("Please rebuild GStreamer with pipeline parsing capabilities activated to use this example.\n");
134 gst_init (&argc, &argv);
135 gtk_init (&argc, &argv);
137 pipeline = gst_parse_launchv ((const gchar **) &argv[1], &error);
139 g_print ("pipeline could not be constructed: %s\n", error->message);
140 g_print ("Please give a complete pipeline with a 'volume' element.\n");
141 g_print ("Example: audiotestsrc ! volume ! %s\n", DEFAULT_AUDIOSINK);
142 g_error_free (error);
146 volume = gst_bin_get_by_name (GST_BIN (pipeline), "volume0");
147 if (volume == NULL) {
148 g_print ("Please give a pipeline with a 'volume' element in it\n");
152 /* setup message handling */
153 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
154 gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
155 g_signal_connect (bus, "message::error", (GCallback) message_received,
157 g_signal_connect (bus, "message::warning", (GCallback) message_received,
159 g_signal_connect (bus, "message::eos", (GCallback) eos_message_received,
165 /* go to main loop */
166 gst_element_set_state (pipeline, GST_STATE_PLAYING);
168 gst_element_set_state (pipeline, GST_STATE_NULL);
169 gst_object_unref (pipeline);