From: Stefan Sauer Date: Thu, 27 Oct 2011 07:51:46 +0000 (+0200) Subject: volume: move volume example to audio X-Git-Tag: RELEASE-0.11.2~2^2~250 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=92d1f5251e3d5b08dd7e7a419fc217f3f50d5729;p=platform%2Fupstream%2Fgst-plugins-base.git volume: move volume example to audio --- diff --git a/Makefile.am b/Makefile.am index 00201ecf3..f96c41797 100644 --- a/Makefile.am +++ b/Makefile.am @@ -77,6 +77,7 @@ CRUFT_FILES = \ $(top_builddir)/common/shave \ $(top_builddir)/common/shave-libtool \ $(top_builddir)/gst-libs/gst/audio/testchannels \ + $(top_builddir)/tests/examples/volume/volume \ $(top_builddir)/tools/gst-discoverer diff --git a/configure.ac b/configure.ac index 56eae4e38..3247887a0 100644 --- a/configure.ac +++ b/configure.ac @@ -1028,7 +1028,6 @@ tests/examples/overlay/Makefile tests/examples/seek/Makefile tests/examples/snapshot/Makefile tests/examples/playrec/Makefile -tests/examples/volume/Makefile tests/examples/v4l/Makefile tests/files/Makefile tests/icles/Makefile diff --git a/tests/examples/Makefile.am b/tests/examples/Makefile.am index 14795db9e..81731425a 100644 --- a/tests/examples/Makefile.am +++ b/tests/examples/Makefile.am @@ -8,8 +8,9 @@ if USE_GIO GIO_SUBDIRS = gio endif -SUBDIRS = app audio dynamic $(FT2_SUBDIRS) $(GIO_SUBDIRS) overlay playrec volume v4l encoding +SUBDIRS = app audio dynamic $(FT2_SUBDIRS) $(GIO_SUBDIRS) overlay playrec v4l encoding DIST_SUBDIRS = app audio dynamic gio overlay seek snapshot playrec volume v4l encoding include $(top_srcdir)/common/parallel-subdirs.mak + diff --git a/tests/examples/audio/.gitignore b/tests/examples/audio/.gitignore index 87308d7b4..04fcc591b 100644 --- a/tests/examples/audio/.gitignore +++ b/tests/examples/audio/.gitignore @@ -1,3 +1,4 @@ audiomix testchannels +volume diff --git a/tests/examples/audio/Makefile.am b/tests/examples/audio/Makefile.am index 0b8d10a88..d8492340e 100644 --- a/tests/examples/audio/Makefile.am +++ b/tests/examples/audio/Makefile.am @@ -1,5 +1,5 @@ if HAVE_GTK -GTK_EXAMPLES = audiomix +GTK_EXAMPLES = audiomix volume else GTK_EXAMPLES = endif @@ -15,4 +15,8 @@ if HAVE_GTK audiomix_SOURCES = audiomix.c audiomix_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS) -D_GNU_SOURCE audiomix_LDADD = $(GST_LIBS) $(GTK_LIBS) $(LIBM) + +volume_SOURCES = volume.c +volume_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS) -D_GNU_SOURCE +volume_LDADD = $(GST_LIBS) $(GTK_LIBS) $(LIBM) endif diff --git a/tests/examples/audio/volume.c b/tests/examples/audio/volume.c new file mode 100644 index 000000000..d5bf9edbb --- /dev/null +++ b/tests/examples/audio/volume.c @@ -0,0 +1,172 @@ +/* GStreamer + * + * volume.c: sample application to change the volume of a pipeline + * + * Copyright (C) <2004> Thomas Vander Stichele + * + * 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 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include +#include + +/* global pointer for the scale widget */ +static GtkWidget *elapsed; +static GtkWidget *scale; + +#ifndef M_LN10 +#define M_LN10 (log(10.0)) +#endif + +static void +value_changed_callback (GtkWidget * widget, GstElement * volume) +{ + gdouble value; + gdouble level; + + value = gtk_range_get_value (GTK_RANGE (widget)); + level = exp (value / 20.0 * M_LN10); + 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); + + vbox = gtk_vbox_new (TRUE, 0); + gtk_container_add (GTK_CONTAINER (window), vbox); + + /* elapsed widget */ + hbox = gtk_hbox_new (TRUE, 0); + label = gtk_label_new ("Elapsed"); + elapsed = gtk_label_new ("0.000"); + gtk_container_add (GTK_CONTAINER (hbox), label); + gtk_container_add (GTK_CONTAINER (hbox), elapsed); + gtk_container_add (GTK_CONTAINER (vbox), hbox); + + /* volume */ + hbox = gtk_hbox_new (TRUE, 0); + label = gtk_label_new ("volume"); + gtk_container_add (GTK_CONTAINER (hbox), label); + scale = gtk_hscale_new_with_range (-90.0, 10.0, 0.2); + 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)); +} + +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 (); +} + +int +main (int argc, char *argv[]) +{ + + GstElement *pipeline = NULL; + +#ifndef GST_DISABLE_PARSE + GError *error = NULL; +#endif + GstElement *volume; + GstBus *bus; + +#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 + 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"); + g_print ("Example: audiotestsrc ! volume ! %s\n", DEFAULT_AUDIOSINK); + g_error_free (error); + return 1; + } +#endif + 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; + } + + /* 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); + + /* setup GUI */ + setup_gui (volume); + + /* go to main loop */ + gst_element_set_state (pipeline, GST_STATE_PLAYING); + gtk_main (); + gst_element_set_state (pipeline, GST_STATE_NULL); + gst_object_unref (pipeline); + + return 0; +} diff --git a/tests/examples/volume/.gitignore b/tests/examples/volume/.gitignore deleted file mode 100644 index 4833bbb03..000000000 --- a/tests/examples/volume/.gitignore +++ /dev/null @@ -1 +0,0 @@ -volume diff --git a/tests/examples/volume/Makefile.am b/tests/examples/volume/Makefile.am deleted file mode 100644 index 7b2f067bd..000000000 --- a/tests/examples/volume/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -if HAVE_GTK -noinst_PROGRAMS = volume -volume_SOURCES = volume.c -volume_CFLAGS = $(GST_CFLAGS) $(GTK_CFLAGS) -D_GNU_SOURCE -volume_LDADD = $(GST_LIBS) $(GTK_LIBS) $(LIBM) -endif diff --git a/tests/examples/volume/volume.c b/tests/examples/volume/volume.c deleted file mode 100644 index d5bf9edbb..000000000 --- a/tests/examples/volume/volume.c +++ /dev/null @@ -1,172 +0,0 @@ -/* GStreamer - * - * volume.c: sample application to change the volume of a pipeline - * - * Copyright (C) <2004> Thomas Vander Stichele - * - * 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 - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include - -/* global pointer for the scale widget */ -static GtkWidget *elapsed; -static GtkWidget *scale; - -#ifndef M_LN10 -#define M_LN10 (log(10.0)) -#endif - -static void -value_changed_callback (GtkWidget * widget, GstElement * volume) -{ - gdouble value; - gdouble level; - - value = gtk_range_get_value (GTK_RANGE (widget)); - level = exp (value / 20.0 * M_LN10); - 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); - - vbox = gtk_vbox_new (TRUE, 0); - gtk_container_add (GTK_CONTAINER (window), vbox); - - /* elapsed widget */ - hbox = gtk_hbox_new (TRUE, 0); - label = gtk_label_new ("Elapsed"); - elapsed = gtk_label_new ("0.000"); - gtk_container_add (GTK_CONTAINER (hbox), label); - gtk_container_add (GTK_CONTAINER (hbox), elapsed); - gtk_container_add (GTK_CONTAINER (vbox), hbox); - - /* volume */ - hbox = gtk_hbox_new (TRUE, 0); - label = gtk_label_new ("volume"); - gtk_container_add (GTK_CONTAINER (hbox), label); - scale = gtk_hscale_new_with_range (-90.0, 10.0, 0.2); - 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)); -} - -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 (); -} - -int -main (int argc, char *argv[]) -{ - - GstElement *pipeline = NULL; - -#ifndef GST_DISABLE_PARSE - GError *error = NULL; -#endif - GstElement *volume; - GstBus *bus; - -#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 - 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"); - g_print ("Example: audiotestsrc ! volume ! %s\n", DEFAULT_AUDIOSINK); - g_error_free (error); - return 1; - } -#endif - 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; - } - - /* 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); - - /* setup GUI */ - setup_gui (volume); - - /* go to main loop */ - gst_element_set_state (pipeline, GST_STATE_PLAYING); - gtk_main (); - gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (pipeline); - - return 0; -}