call to the GstBus unexpectedly stops while playing audio file....
Victor henri
nadaeck at hotmail.com
Sat Apr 23 10:55:36 PDT 2011
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20110423/f35259b6/attachment-0001.htm>
More information about the gstreamer-devel
mailing list