[gst-devel] spectrum while playing a file

Jan Schmidt thaytan at noraisin.net
Tue Nov 16 06:23:09 CET 2010


Hi Victor,

As always when dealing with decodebin, or any element that has dynamic
pads, you need to trigger on new-pad creation and link decodebin
downstream then.

Here is an example in python:

http://www.jonobacon.org/2006/11/03/gstreamer-dynamic-pads-explained/

- Jan.

On Mon, 2010-11-15 at 17:45 -0800, victor wrote:
> Hello to all
> 
> I'd like to implement a spectrum measurment on a file that i'm playing; i'm
> aware of the exeamples at 
> http://http://cgit.freedesktop.org/gstreamer/gst-plugins-good/tree/tests/examples/spectrum/
> http://http://cgit.freedesktop.org/gstreamer/gst-plugins-good/tree/tests/examples/spectrum/ 
> but the exeamples are with either "alsasrc" or "audiotestsrc"; nothing with
> a file that is played.
> 
> When i type in a terminal : 
> filesrc location="/home/victor/Music/my_file.wav" ! decodebin2 ! spectrum
> bands=100 threshold=-80 message=TRUE message-phase=TRUE interval=1000000 !
> alsasink
> 
> it works (i don't have the display of the spectrum but i have the sound file
> playing).
> 
> When i try it in a C program, i always have the 'complain' that elemets
> cannot be linked...
> 
> Please, is there a think t forgot....?
> 
> Here is my "int main" function:
> 
> int
> main (int argc, char *argv[])
> {
>   GstElement *bin;
>   GstElement *src, *audioconvert, *decodebin, *spectrum, *sink;
>   GstBus *bus;
>   GstCaps *caps;
>   GMainLoop *loop;
> 
>   gst_init (&argc, &argv);
> 
>   bin = gst_pipeline_new ("bin");
> 
>   src = gst_element_factory_make ("filesrc", "src");
>   g_object_set (G_OBJECT (src), "location",
> "file:///home/victor/Music/Gurdieff-Elena/gymnastique_medicale.wav", NULL);
>   decodebin = gst_element_factory_make ("decodebin2", "decodebin2");
>   g_signal_connect (decodebin, "new-decoded-pad", G_CALLBACK (cb_newpad),
> NULL);
>   spectrum = gst_element_factory_make ("spectrum", "spectrum");
>   g_object_set (G_OBJECT (spectrum), "bands", spect_bands, "threshold", -80,
>       "message", TRUE, "message-phase", TRUE, NULL);
>   sink = gst_element_factory_make ("alsasink", "sink");
>   g_object_set (G_OBJECT (sink), "sync", TRUE, NULL);
>   gst_bin_add_many (GST_BIN (bin), src, decodebin, spectrum, sink, NULL);
> 
>   caps = gst_caps_new_simple ("audio/x-raw-int",
>       "rate", G_TYPE_INT, AUDIOFREQ, NULL);
> 
>   if (!gst_element_link (src, decodebin))
> { fprintf (stderr, "can't link elements 1\n");
>     exit (1);
>   }
>   if (!gst_element_link_filtered (decodebin, spectrum, caps)) 
>     { fprintf (stderr, "can't link elements 2\n");
>     exit (1);
>   }
>   if  (!gst_element_link (spectrum, sink)) {
>     fprintf (stderr, "can't link elements 3\n");
>     exit (1);
>   }
>   gst_caps_unref (caps);
> 
>   bus = gst_element_get_bus (bin);
>   gst_bus_add_watch (bus, message_handler, NULL);
>   gst_object_unref (bus);
> 
>   gst_element_set_state (bin, GST_STATE_PLAYING);
> 
>   /* we need to run a GLib main loop to get the messages */
>   loop = g_main_loop_new (NULL, FALSE);
>   g_main_loop_run (loop);
> 
>   gst_element_set_state (bin, GST_STATE_NULL);
> 
>   gst_object_unref (bin);
> 
>   return 0;
> }
> 
> Thank you
> 
>  Victor
> 
> 
> 

-- 
Jan Schmidt <thaytan at noraisin.net>





More information about the gstreamer-devel mailing list