2004-06-14 10:04:44 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
2005-12-30 14:54:06 +00:00
|
|
|
* volume.c: sample application to change the volume of a pipeline
|
2004-06-14 10:04:44 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 23:05:09 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2004-06-14 10:04:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
/* global pointer for the scale widget */
|
2011-10-27 07:33:55 +00:00
|
|
|
static GtkWidget *elapsed;
|
|
|
|
static GtkWidget *scale;
|
2004-06-14 10:04:44 +00:00
|
|
|
|
2004-06-14 20:24:08 +00:00
|
|
|
#ifndef M_LN10
|
|
|
|
#define M_LN10 (log(10.0))
|
|
|
|
#endif
|
|
|
|
|
2004-06-14 10:04:44 +00:00
|
|
|
static void
|
|
|
|
value_changed_callback (GtkWidget * widget, GstElement * volume)
|
|
|
|
{
|
|
|
|
gdouble value;
|
|
|
|
gdouble level;
|
|
|
|
|
|
|
|
value = gtk_range_get_value (GTK_RANGE (widget));
|
2004-06-14 20:24:08 +00:00
|
|
|
level = exp (value / 20.0 * M_LN10);
|
2004-06-14 10:04:44 +00:00
|
|
|
g_print ("Value: %f dB, level: %f\n", value, level);
|
|
|
|
g_object_set (volume, "volume", level, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_gui (GstElement * volume)
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *label, *hbox;
|
|
|
|
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
|
|
|
g_signal_connect (window, "destroy", gtk_main_quit, NULL);
|
|
|
|
|
2015-04-01 14:02:13 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
2004-06-14 10:04:44 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
|
|
|
|
|
|
|
/* elapsed widget */
|
2015-04-01 14:02:13 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2015-04-01 14:58:28 +00:00
|
|
|
label = gtk_label_new ("Elapsed: ");
|
|
|
|
elapsed = gtk_label_new ("0.0");
|
2004-06-14 10:04:44 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), label);
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), elapsed);
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
|
|
|
|
|
|
|
/* volume */
|
2015-04-01 14:02:13 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2004-06-14 10:04:44 +00:00
|
|
|
label = gtk_label_new ("volume");
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), label);
|
2015-04-01 14:02:13 +00:00
|
|
|
scale = gtk_scale_new_with_range (GTK_ORIENTATION_HORIZONTAL, -90.0, 10.0,
|
|
|
|
0.2);
|
2004-06-14 10:04:44 +00:00
|
|
|
gtk_range_set_value (GTK_RANGE (scale), 0.0);
|
|
|
|
gtk_widget_set_size_request (scale, 100, -1);
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), scale);
|
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
|
|
|
g_signal_connect (scale, "value-changed",
|
|
|
|
G_CALLBACK (value_changed_callback), volume);
|
|
|
|
|
|
|
|
gtk_widget_show_all (GTK_WIDGET (window));
|
|
|
|
}
|
|
|
|
|
2015-04-01 14:58:28 +00:00
|
|
|
static gboolean
|
|
|
|
progress_update (gpointer data)
|
|
|
|
{
|
|
|
|
GstElement *pipeline = (GstElement *) data;
|
|
|
|
gint64 position;
|
|
|
|
gchar *position_str;
|
|
|
|
|
|
|
|
if (gst_element_query_position (pipeline, GST_FORMAT_TIME, &position))
|
|
|
|
position_str = g_strdup_printf ("%.1f", (gfloat) position / GST_SECOND);
|
|
|
|
else
|
|
|
|
position_str = g_strdup_printf ("n/a");
|
|
|
|
gtk_label_set_text (GTK_LABEL (elapsed), position_str);
|
|
|
|
|
|
|
|
g_free (position_str);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-12-30 14:54:06 +00:00
|
|
|
static void
|
|
|
|
message_received (GstBus * bus, GstMessage * message, GstPipeline * pipeline)
|
|
|
|
{
|
|
|
|
const GstStructure *s;
|
|
|
|
|
|
|
|
s = gst_message_get_structure (message);
|
|
|
|
g_print ("message from \"%s\" (%s): ",
|
|
|
|
GST_STR_NULL (GST_ELEMENT_NAME (GST_MESSAGE_SRC (message))),
|
|
|
|
gst_message_type_get_name (GST_MESSAGE_TYPE (message)));
|
|
|
|
if (s) {
|
|
|
|
gchar *sstr;
|
|
|
|
|
|
|
|
sstr = gst_structure_to_string (s);
|
|
|
|
g_print ("%s\n", sstr);
|
|
|
|
g_free (sstr);
|
|
|
|
} else {
|
|
|
|
g_print ("no message details\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
eos_message_received (GstBus * bus, GstMessage * message,
|
|
|
|
GstPipeline * pipeline)
|
|
|
|
{
|
|
|
|
message_received (bus, message, pipeline);
|
|
|
|
gtk_main_quit ();
|
|
|
|
}
|
|
|
|
|
2004-06-14 10:04:44 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
|
|
|
|
GstElement *pipeline = NULL;
|
2006-05-09 11:31:47 +00:00
|
|
|
|
|
|
|
#ifndef GST_DISABLE_PARSE
|
2004-06-14 10:04:44 +00:00
|
|
|
GError *error = NULL;
|
2006-05-09 11:31:47 +00:00
|
|
|
#endif
|
2004-06-14 10:04:44 +00:00
|
|
|
GstElement *volume;
|
2005-12-30 14:54:06 +00:00
|
|
|
GstBus *bus;
|
2004-06-14 10:04:44 +00:00
|
|
|
|
2006-05-09 11:31:47 +00:00
|
|
|
#ifdef GST_DISABLE_PARSE
|
|
|
|
g_print ("GStreamer was built without pipeline parsing capabilities.\n");
|
|
|
|
g_print
|
|
|
|
("Please rebuild GStreamer with pipeline parsing capabilities activated to use this example.\n");
|
|
|
|
return 1;
|
|
|
|
#else
|
2004-06-14 10:04:44 +00:00
|
|
|
gst_init (&argc, &argv);
|
|
|
|
gtk_init (&argc, &argv);
|
|
|
|
|
|
|
|
pipeline = gst_parse_launchv ((const gchar **) &argv[1], &error);
|
|
|
|
if (error) {
|
|
|
|
g_print ("pipeline could not be constructed: %s\n", error->message);
|
|
|
|
g_print ("Please give a complete pipeline with a 'volume' element.\n");
|
2005-11-23 15:36:58 +00:00
|
|
|
g_print ("Example: audiotestsrc ! volume ! %s\n", DEFAULT_AUDIOSINK);
|
2004-06-14 10:04:44 +00:00
|
|
|
g_error_free (error);
|
|
|
|
return 1;
|
|
|
|
}
|
2006-05-09 11:31:47 +00:00
|
|
|
#endif
|
2004-06-14 10:04:44 +00:00
|
|
|
volume = gst_bin_get_by_name (GST_BIN (pipeline), "volume0");
|
|
|
|
if (volume == NULL) {
|
|
|
|
g_print ("Please give a pipeline with a 'volume' element in it\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-12-30 14:54:06 +00:00
|
|
|
/* setup message handling */
|
|
|
|
bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
|
|
|
|
gst_bus_add_signal_watch_full (bus, G_PRIORITY_HIGH);
|
|
|
|
g_signal_connect (bus, "message::error", (GCallback) message_received,
|
|
|
|
pipeline);
|
|
|
|
g_signal_connect (bus, "message::warning", (GCallback) message_received,
|
|
|
|
pipeline);
|
|
|
|
g_signal_connect (bus, "message::eos", (GCallback) eos_message_received,
|
|
|
|
pipeline);
|
|
|
|
|
2004-06-14 10:04:44 +00:00
|
|
|
/* setup GUI */
|
|
|
|
setup_gui (volume);
|
|
|
|
|
|
|
|
/* go to main loop */
|
|
|
|
gst_element_set_state (pipeline, GST_STATE_PLAYING);
|
2015-04-01 14:58:28 +00:00
|
|
|
g_timeout_add (100, progress_update, pipeline);
|
2005-12-30 14:54:06 +00:00
|
|
|
gtk_main ();
|
2005-05-09 21:37:17 +00:00
|
|
|
gst_element_set_state (pipeline, GST_STATE_NULL);
|
2017-05-11 10:12:52 +00:00
|
|
|
gst_object_unref (volume);
|
2005-12-30 14:54:06 +00:00
|
|
|
gst_object_unref (pipeline);
|
2014-08-06 11:41:46 +00:00
|
|
|
gst_object_unref (bus);
|
2004-06-14 10:04:44 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|