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