diff options
author | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2009-02-24 16:33:51 +0100 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2009-02-24 16:33:51 +0100 |
commit | f0ae68d9440e90711c7b547f03d7165357b9c4ac (patch) | |
tree | d77797c994b5f7457b1dd3b802f08f783c8ce0e5 /tests/examples/level | |
parent | da040c2a3529801e9b7c239afb698379ede89087 (diff) | |
download | gst-plugins-bad-f0ae68d9440e90711c7b547f03d7165357b9c4ac.tar.gz gst-plugins-bad-f0ae68d9440e90711c7b547f03d7165357b9c4ac.tar.bz2 gst-plugins-bad-f0ae68d9440e90711c7b547f03d7165357b9c4ac.zip |
Move examples directory to tests/examples as in every other GStreamer module
Diffstat (limited to 'tests/examples/level')
-rw-r--r-- | tests/examples/level/Makefile.am | 11 | ||||
-rw-r--r-- | tests/examples/level/README | 39 | ||||
-rw-r--r-- | tests/examples/level/demo.c | 155 | ||||
-rw-r--r-- | tests/examples/level/plot.c | 124 |
4 files changed, 329 insertions, 0 deletions
diff --git a/tests/examples/level/Makefile.am b/tests/examples/level/Makefile.am new file mode 100644 index 00000000..bf76136f --- /dev/null +++ b/tests/examples/level/Makefile.am @@ -0,0 +1,11 @@ +noinst_PROGRAMS = demo plot + +demo_SOURCES = demo.c +demo_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS) +demo_LDFLAGS = $(GTK_LIBS) $(GST_LIBS) + +plot_SOURCES = plot.c +plot_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS) +plot_LDFLAGS = $(GTK_LIBS) $(GST_LIBS) + +EXTRA_DIST = README diff --git a/tests/examples/level/README b/tests/examples/level/README new file mode 100644 index 00000000..0ae84188 --- /dev/null +++ b/tests/examples/level/README @@ -0,0 +1,39 @@ +level plugin by thomas <thomas@apestaart.org> + +this plugin signals: + - running time since last EOS/start + - channel + - RMS level + - peak level + - decaying peak level +over the given interval. + +This is useful for a VU meter display and for plotting out the signal graph. +The VU meter can either display RMS, or display immediate peak level and +have the falloff decaying peak level displayed as a line. + +The interval for signal emission, ttl of decay peak, and falloff of decay peak +can all be set. + +The element only takes unsigned data in; it could be extended to signed as +well, if separate fast chain functions are made that displaces the incoming +data to its midpoint (ie, 0,65535 should be mapped to -32768, 32767) + +There are two demo apps, apps and plot. apps will create some GTK sliders +to display the volume. plot will output data readable by gnuplot. + +Here is a sample plot script to plot output of the plot command that was +stored to plot.dat + +set xlabel "Seconds" +set ylabel "dB" +set yrange [-60:0] +plot 'plot.dat' using 1:2 title 'L RMS' with lines, \ + 'plot.dat' using 1:3 title 'L peak' with lines, \ + 'plot.dat' using 1:4 title 'L decay' with lines + +plot 'plot.dat' using 1:5 title 'R RMS' with lines, \ + 'plot.dat' using 1:6 title 'R peak' with lines, \ + 'plot.dat' using 1:7 title 'R decay' with lines + + diff --git a/tests/examples/level/demo.c b/tests/examples/level/demo.c new file mode 100644 index 00000000..502f50f7 --- /dev/null +++ b/tests/examples/level/demo.c @@ -0,0 +1,155 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * + * demo.c: sample application to display VU meter-like output of level + * Copyright (C) 2003 + * 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 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gst/gst.h> +#include <gtk/gtk.h> + +/* global array for the scale widgets, we'll assume stereo */ +GtkWidget *elapsed; +GtkWidget *scale[2][3]; + +static void +level_callback (GstElement * element, gdouble time, gint channel, + gdouble rms, gdouble peak, gdouble decay) +{ + gchar *label; + + label = g_strdup_printf ("%.3f", time); + gtk_label_set (GTK_LABEL (elapsed), label); + g_free (label); + gtk_range_set_value (GTK_RANGE (scale[channel][0]), rms); + gtk_range_set_value (GTK_RANGE (scale[channel][1]), peak); + gtk_range_set_value (GTK_RANGE (scale[channel][2]), decay); +} + +static gboolean +idler (gpointer data) +{ + GstElement *pipeline = GST_ELEMENT (data); + + g_print ("+"); + if (gst_bin_iterate (GST_BIN (pipeline))) + return TRUE; + gtk_main_quit (); + return FALSE; +} + +static void +setup_gui () +{ + GtkWidget *window; + GtkWidget *vbox; + GtkWidget *label, *hbox; + int c; + + 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); + + for (c = 0; c < 2; ++c) { + /* RMS */ + hbox = gtk_hbox_new (TRUE, 0); + label = gtk_label_new ("RMS"); + gtk_container_add (GTK_CONTAINER (hbox), label); + scale[c][0] = gtk_hscale_new_with_range (-90.0, 0.0, 0.2); + gtk_widget_set_size_request (scale[c][0], 100, -1); + gtk_container_add (GTK_CONTAINER (hbox), scale[c][0]); + gtk_container_add (GTK_CONTAINER (vbox), hbox); + /* peak */ + hbox = gtk_hbox_new (TRUE, 0); + label = gtk_label_new ("peak"); + gtk_container_add (GTK_CONTAINER (hbox), label); + scale[c][1] = gtk_hscale_new_with_range (-90.0, 0.0, 0.2); + gtk_widget_set_size_request (scale[c][1], 100, -1); + gtk_container_add (GTK_CONTAINER (hbox), scale[c][1]); + gtk_container_add (GTK_CONTAINER (vbox), hbox); + /* decay */ + hbox = gtk_hbox_new (TRUE, 0); + label = gtk_label_new ("decaying peek"); + gtk_container_add (GTK_CONTAINER (hbox), label); + scale[c][2] = gtk_hscale_new_with_range (-90.0, 0.0, 0.2); + gtk_widget_set_size_request (scale[c][2], 100, -1); + gtk_container_add (GTK_CONTAINER (hbox), scale[c][2]); + gtk_container_add (GTK_CONTAINER (vbox), hbox); + } + + gtk_widget_show_all (GTK_WIDGET (window)); +} + +int +main (int argc, char *argv[]) +{ + + GstElement *pipeline = NULL; + GError *error = NULL; + GstElement *level; + + 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 'level' element.\n"); + g_print ("Example: sinesrc ! level ! %s\n", DEFAULT_AUDIOSINK); + g_error_free (error); + return 1; + } + + level = gst_bin_get_by_name (GST_BIN (pipeline), "level0"); + if (level == NULL) { + g_print ("Please give a pipeline with a 'level' element in it\n"); + return 1; + } + + g_object_set (level, "signal", TRUE, NULL); + g_signal_connect (level, "level", G_CALLBACK (level_callback), NULL); + + + /* setup GUI */ + setup_gui (); + + /* connect level signal */ + + /* go to main loop */ + gst_element_set_state (pipeline, GST_STATE_PLAYING); + g_idle_add (idler, pipeline); + + gtk_main (); + + return 0; +} diff --git a/tests/examples/level/plot.c b/tests/examples/level/plot.c new file mode 100644 index 00000000..44591584 --- /dev/null +++ b/tests/examples/level/plot.c @@ -0,0 +1,124 @@ +/* GStreamer + * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu> + * + * plot.c: output data points to be graphed with gnuplot + * Copyright (C) 2003 + * 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 + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <gst/gst.h> +#include <gtk/gtk.h> + +gboolean got_channel[2] = { FALSE, FALSE }; /* to see if we got the signal for this one yet */ + +gint channels = 0; /* guess at how many channels there are */ +gdouble last_time = 0.0; /* time of last signal */ +gdouble values[2][3]; /* array of levels from which to print */ + +static void +level_callback (GstElement * element, gdouble time, gint channel, + gdouble rms, gdouble peak, gdouble decay) +{ + int i = 0, j = 0; + gboolean got_all = FALSE; + + if (channel + 1 > channels) + channels = channel + 1; + + /* reset got_channel if this is a new time point */ + if (time > last_time) { + for (i = 0; i < channels; ++i) + got_channel[i] = FALSE; + last_time = time; + } + + /* store values */ + got_channel[channel] = TRUE; + values[channel][0] = rms; + values[channel][1] = peak; + values[channel][2] = decay; + + /* check if we have all channels, and output if we do */ + /* FIXME: this fails on the first, no ? */ + got_all = TRUE; + for (i = 0; i < channels; ++i) + if (!got_channel[i]) + got_all = FALSE; + if (got_all) { + g_print ("%f ", time); + for (i = 0; i < channels; ++i) + for (j = 0; j < 3; ++j) + g_print ("%f ", values[i][j]); + g_print ("\n"); + } +} + +static gboolean +idler (gpointer data) +{ + GstElement *pipeline = GST_ELEMENT (data); + + if (gst_bin_iterate (GST_BIN (pipeline))) + return TRUE; + + gtk_main_quit (); + return FALSE; +} + +int +main (int argc, char *argv[]) +{ + + GstElement *pipeline = NULL; + GError *error = NULL; + GstElement *level; + + 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 'level' element.\n"); + g_print ("Example: sinesrc ! level ! %s\n", DEFAULT_AUDIOSINK); + g_error_free (error); + return 1; + } + + level = gst_bin_get_by_name (GST_BIN (pipeline), "level0"); + if (level == NULL) { + g_print ("Please give a pipeline with a 'level' element in it\n"); + return 1; + } + + g_object_set (level, "signal", TRUE, NULL); + g_signal_connect (level, "level", G_CALLBACK (level_callback), NULL); + + + /* go to main loop */ + gst_element_set_state (pipeline, GST_STATE_PLAYING); + g_idle_add (idler, pipeline); + + gtk_main (); + + return 0; +} |