call to the GstBus unexpectedly stops while playing audio file....
Stefan Kost
ensonic at hora-obscura.de
Tue Apr 26 12:05:58 PDT 2011
Am 25.04.2011 04:13, schrieb Victor henri:
> I reply to myself:
>
> 2 things:
>
> 1. I was using decodebin wich tends to be deprecated now AFAIK; I've rewritten
> it with playbin2;
>
> 2. it is solved in my new rewriting; I'm not sure how I did, but I have noticed
> this:
>
> I have started a new playbin2 function from scratch : it worked; then i tried to
> link it from my gtk graphical interface : it didn't work; the call to the
> function with playbin2 was direct, like that :
>
> g_signal_connect(G_OBJECT(pButton[0]), "clicked",
> G_CALLBACK(playbin2), NULL);
>
> When I changed, to
>
> g_signal_connect(G_OBJECT(pButton[0]), "clicked",
> G_CALLBACK(onPlay), NULL);
The callback has to be a function that would call
gst_element_set_state(playbin2,GST_STATE_PLAYING);
Passing an object pointer as a callback would lead to a crasher.
Stefan
>
> where the 'onPlay' function calls the playbin2 function, it started to work...
> but it still doesn't make sense for me.......
>
> Victor
>
> --------------------------------------------------------------------------------
> From: nadaeck at hotmail.com
> To: gstreamer-devel at lists.freedesktop.org
> Subject: call to the GstBus unexpectedly stops while playing audio file....
> Date: Sat, 23 Apr 2011 19:55:36 +0200
>
> Hello
>
> I'm playing an audio files with decodebin. This works fine but and the file is
> played, but the call to the GstBus is somehow stopped while the file is still
> beeing played, despite the bus calling function returns TRUE everytime.
>
> I have added a 'spectrum' element since my goal is to work on harmonics analysis.
>
> Please how could I fix this?
>
> This is the code :
>
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> #include <gst/gst.h>
>
> GstElement *audio;
> int counter = 0;
> GMainLoop *loop;
>
> static void cb_newpad (GstElement *decodebin, GstPad *pad, gboolean last,
> gpointer data)
> {
> GstCaps *caps;
> GstStructure *str;
> GstPad *audiopad;
>
> audiopad = gst_element_get_static_pad (audio, "sink");
> if (GST_PAD_IS_LINKED (audiopad)) {
> g_object_unref (audiopad);
> return;
> }
>
> caps = gst_pad_get_caps (pad);
> str = gst_caps_get_structure (caps, 0);
> if (!g_strrstr (gst_structure_get_name (str), "audio")) {
> gst_caps_unref (caps);
> gst_object_unref (audiopad);
> return;
> }
> gst_caps_unref (caps);
>
> gst_pad_link (pad, audiopad);
> g_object_unref (audiopad);
> }
>
> static gboolean message_handler (GstBus * bus, GstMessage * message, gpointer data)
> {
> counter ++;
> printf("%d\n", counter);
> int ii = 0;
> const GValue *magnitudes;
>
> if (message->type == GST_MESSAGE_ELEMENT) {
> counter = 0;
> const GstStructure *s = gst_message_get_structure (message);
> const gchar *name = gst_structure_get_name (s);
> GstClockTime endtime;
>
> if (strcmp (name, "spectrum") == 0) {
> if (!gst_structure_get_clock_time (s, "endtime", &endtime)){
> //endtime = GST_CLOCK_TIME_NONE;
> magnitudes = gst_structure_get_value (s, "magnitude");
> }
> }
>
> }
> else if (message->type == GST_MESSAGE_EOS) {
> g_main_loop_quit (loop);
> }
> return TRUE;
> }
>
> main(int argc, char **argv)
> {
> int AUDIOFREQ = 44100;
> int interval = 100000000;
> int spect_bands = 20;
> GstElement *src, *dec, *audioconvert, *conv, *spectrum, *sink;
> GstBus *bus;
> GstCaps *caps;
> GstPad *audiopad;
> GstStateChangeReturn res;
> GstElement *pipeline;
> gchar *uri;
>
>
> gst_init (NULL, NULL);
> loop = g_main_loop_new(NULL, FALSE);
>
> pipeline = gst_pipeline_new ("pipeline");
> bus = gst_element_get_bus (pipeline);
> gst_bus_add_watch (bus, message_handler, loop);
> gst_object_unref (bus);
>
> src = gst_element_factory_make ("filesrc", "source");
> g_object_set (G_OBJECT (src), "location",
> "/home/victor/Music/chopin_nocturne.mp3" , NULL);
> dec = gst_element_factory_make ("decodebin", "decoder");
> g_signal_connect (dec, "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, "interval", interval, NULL);
> gst_bin_add_many (GST_BIN (pipeline), src, dec, NULL);
> gst_element_link (src, dec);
>
> audio = gst_bin_new ("audiobin");
> conv = gst_element_factory_make ("audioconvert", "aconv");
> audiopad = gst_element_get_static_pad (conv, "sink");
> sink = gst_element_factory_make ("alsasink", "sink");
> gst_bin_add_many (GST_BIN (audio), conv, spectrum, sink, NULL);
> gst_element_link_many (conv, spectrum, sink, NULL);
> gst_element_add_pad (audio,
> gst_ghost_pad_new ("sink", audiopad));
> gst_object_unref (audiopad);
> gst_bin_add (GST_BIN (pipeline), audio);
>
> gst_element_set_state (pipeline, GST_STATE_PLAYING);
>
> g_main_loop_run (loop);
> gst_element_set_state (pipeline, GST_STATE_NULL);
> gst_object_unref (GST_OBJECT (pipeline));
>
> }
>
>
> This works since the music is played (I've chosen a defined mp3 piece from my
> hard drive), but the counter that is the 'message_handler' function stops at
> '43'.....
>
> Does anyone have a clue to help me please?
>
> Thank you
>
> Victor
> _______________________________________________ gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
>
>
>
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
More information about the gstreamer-devel
mailing list