qt - Trouble playing audio files using gstreamer apis: application hangs -


i have written simple audio player application in c++ using gstreamer apis. followed gstreamer hello world example. code:

cmediaplayer::cmediaplayer(qstring path)  {     gst_init(null, null);     createelements(path); }  createelements(qstring &path)     {             /* create gstreamer elements */             m_pipeline  = gst_pipeline_new("audio-player");             m_filesource = gst_element_factory_make("filesrc", "file-source");             m_audiodecoder = gst_element_factory_make("mad", "mp3-decoder");             m_volume = gst_element_factory_make("volume", "volume-name");             m_audioconverter = gst_element_factory_make("audioconvert", "audio-converter");             m_sink = gst_element_factory_make("alsasink", "audio-output");           if (!m_pipeline || !m_filesource || !m_audiodecoder || !m_volume || !m_audioconverter || !m_sink) {             g_printerr ("one or more elements not created !! \n");             return false;         }         /* set pipeline */         else {             /* set message handler on bus */             gstbus *bus = gst_pipeline_get_bus (gst_pipeline (m_pipeline));             gst_bus_add_watch(bus, bus_call, m_loop);             gst_object_unref(bus);              g_object_set (g_object (m_filesource), "location", path.tolatin1().data(), null);              /* add elements pipeline */             gst_bin_add_many (gst_bin (m_pipeline), m_filesource, m_audiodecoder, m_volume, m_audioconverter, m_sink, null);              /* link elements */             if(!gst_element_link_many (m_filesource, m_audiodecoder, null)) {                 g_printerr("error: failed link file-source , audio-decoder !! \n");                 return false;             }             if(!gst_element_link_many (m_audiodecoder, m_volume, null)) {                 g_printerr("error: failed link audio-decoder , volume !! \n");                 return false;             }             if(!gst_element_link_many (m_volume, m_audioconverter, null)) {                 g_printerr("error: failed link audio-decoder , audio-converter !! \n");                 return false;             }             if(!gst_element_link_many (m_audioconverter, m_sink, null)) {                 g_printerr("error: failed link audio-converter , sink !! \n");                 return false;             }         }      /* prepare pipeline */     gst_element_set_state(m_pipeline, gst_state_ready);     gst_element_set_state(m_pipeline, gst_state_paused);  }  bus_call(gstbus *bus, gstmessage *msg, gpointer data) {      cmediaplayer *ptr = (cmediaplayer*)(data);     switch(gst_message_type(msg))     {         case gst_message_eos:             // reset position of stream             gst_element_set_state (ptr->m_pipeline, gst_state_ready);             gst_element_set_state (ptr->m_pipeline, gst_state_paused);             g_message("gst_message_eos \n");             break;          case gst_message_error:             gchar  *debug;             gerror *error;              gst_message_parse_error (msg, &error, &debug);             g_free (debug);              g_printerr ("error: %s\n", error->message);             g_error_free (error);             break;         default:             g_message("default \n");             break;     }     bus = bus; // prevent "unused" warning     return true; }  slot_play() {     m_gstreturnvalue = gst_element_set_state (m_pipeline, gst_state_playing);     if(m_gstreturnvalue == gst_state_change_failure)     {         g_printerr("error: cannot play !! \n");     } }  slot_pause() {     m_gstreturnvalue = gst_element_set_state (m_pipeline, gst_state_paused);     if(m_gstreturnvalue == gst_state_change_failure)     {         g_printerr("error: cannot pause !! \n");     } }  slot_stop() {     m_gstreturnvalue = gst_element_set_state (m_pipeline, gst_state_ready);     m_gstreturnvalue = gst_element_set_state (m_pipeline, gst_state_paused);     if(m_gstreturnvalue == gst_state_change_failure)     {         g_printerr("error: cannot stop !! \n");     } }  slot_setvolume(int vol_i) {     vol_i = (vol_i > 10) ? 10 : (vol_i < 0) ? 0 : vol_i;     g_object_set(g_object(m_volume), "volume", (gdouble(vol_i)/10), null); } 

when run application, behaves strangely. plays , doesn't. info whenever doesn't play:

0:01:12.000176325 31988   0x5e3000 info               gst_event gstevent.c:1244:gst_event_new_latency: creating latency event 0:00:00.000000000 0:01:12.000953562 31988   0x5e3000 info                     bin gstbin.c:2502:gst_bin_do_latency_func:<audio-player> configured latency of 0:00:00.000000000 0:01:12.001444706 31988   0x5e3000 info              gst_states gstbin.c:2230:gst_bin_element_set_state:<audio-output> current paused pending void_pending, desired next playing 0:01:12.004258709 31988   0x5e3000 info              gst_states gstelement.c:2328:gst_element_continue_state:<audio-output> completed state change playing 0:01:12.004433239 31988   0x5e3000 info              gst_states gstelement.c:2233:_priv_gst_element_state_changed:<audio-output> notifying state-changed paused playing (void_pending pending) 0:01:12.004624124 31988   0x5e3000 info              gst_states gstbin.c:2673:gst_bin_change_state_func:<audio-player> child 'audio-output' changed state 4(playing) 0:01:12.004783134 31988   0x5e3000 info              gst_states gstbin.c:2230:gst_bin_element_set_state:<audio-converter> current paused pending void_pending, desired next playing 0:01:12.004904644 31988   0x5e3000 info              gst_states gstelement.c:2328:gst_element_continue_state:<audio-converter> completed state change playing 0:01:12.004990634 31988   0x5e3000 info              gst_states gstelement.c:2233:_priv_gst_element_state_changed:<audio-converter> notifying state-changed paused playing (void_pending pending) 0:01:12.005134540 31988   0x5e3000 info              gst_states gstbin.c:2673:gst_bin_change_state_func:<audio-player> child 'audio-converter' changed state 4(playing) 0:01:12.005267925 31988   0x5e3000 info              gst_states gstbin.c:2230:gst_bin_element_set_state:<volume-name> current paused pending void_pending, desired next playing 0:01:12.005386310 31988   0x5e3000 info              gst_states gstelement.c:2328:gst_element_continue_state:<volume-name> completed state change playing 0:01:12.005483653 31988   0x5e3000 info              gst_states gstelement.c:2233:_priv_gst_element_state_changed:<volume-name> notifying state-changed paused playing (void_pending pending) 0:01:12.005634851 31988   0x5e3000 info              gst_states gstbin.c:2673:gst_bin_change_state_func:<audio-player> child 'volume-name' changed state 4(playing) 0:01:12.005785006 31988   0x5e3000 info              gst_states gstbin.c:2230:gst_bin_element_set_state:<mp3-decoder> current paused pending void_pending, desired next playing 0:01:12.005916673 31988   0x5e3000 info              gst_states gstelement.c:2328:gst_element_continue_state:<mp3-decoder> completed state change playing 0:01:12.006004329 31988   0x5e3000 info              gst_states gstelement.c:2233:_priv_gst_element_state_changed:<mp3-decoder> notifying state-changed paused playing (void_pending pending) 0:01:12.006142245 31988   0x5e3000 info              gst_states gstbin.c:2673:gst_bin_change_state_func:<audio-player> child 'mp3-decoder' changed state 4(playing) 0:01:12.006259484 31988   0x5e3000 info              gst_states gstbin.c:2230:gst_bin_element_set_state:<file-source> current paused pending void_pending, desired next playing 0:01:12.006381567 31988   0x5e3000 info              gst_states gstelement.c:2328:gst_element_continue_state:<file-source> completed state change playing 0:01:12.006465942 31988   0x5e3000 info              gst_states gstelement.c:2233:_priv_gst_element_state_changed:<file-source> notifying state-changed paused playing (void_pending pending) 0:01:12.006599379 31988   0x5e3000 info              gst_states gstbin.c:2673:gst_bin_change_state_func:<audio-player> child 'file-source' changed state 4(playing) 0:01:12.006726983 31988   0x5e3000 info              gst_states gstelement.c:2328:gst_element_continue_state:<audio-player> completed state change playing 0:01:12.006812868 31988   0x5e3000 info              gst_states gstelement.c:2233:_priv_gst_element_state_changed:<audio-player> notifying state-changed paused playing (void_pending pending) 

according log, state of pipeline changed playing. don't hear anything. when try stop or pause or change volume, application hangs.

i referred link. didn't help.

what missing? new gstreamer. pointers helpful.

ok working me fine, playing..

#include <gst/gst.h> #include <glib.h>  int createelements(char *path) {      /* create gstreamer elements */     gstelement *m_pipeline  = gst_pipeline_new("audio-player");     gstelement *m_filesource = gst_element_factory_make("filesrc", "file-source");     gstelement *m_audiodecoder = gst_element_factory_make("mad", "mp3-decoder");     gstelement *m_volume = gst_element_factory_make("volume", "volume-name");     gstelement *m_audioconverter = gst_element_factory_make("audioconvert", "audio-converter");     gstelement *m_sink = gst_element_factory_make("alsasink", "audio-output");      if (!m_pipeline || !m_filesource || !m_audiodecoder || !m_volume || !m_audioconverter || !m_sink) {             g_printerr ("one or more elements not created !! \n");             return 0;     } else {             g_object_set (g_object (m_filesource), "location", path, null);              gst_bin_add_many (gst_bin (m_pipeline), m_filesource, m_audiodecoder, m_volume, m_audioconverter, m_sink, null);              if(!gst_element_link_many (m_filesource, m_audiodecoder, null)) {                     g_printerr("error: failed link file-source , audio-decoder !! \n");                     return 0;             }             if(!gst_element_link_many (m_audiodecoder, m_volume, null)) {                     g_printerr("error: failed link audio-decoder , volume !! \n");                     return 0;             }             if(!gst_element_link_many (m_volume, m_audioconverter, null)) {                     g_printerr("error: failed link audio-decoder , audio-converter !! \n");                     return 0;             }             if(!gst_element_link_many (m_audioconverter, m_sink, null)) {                     g_printerr("error: failed link audio-converter , sink !! \n");                     return 0;             }     }      gst_element_set_state(m_pipeline, gst_state_paused);     sleep(3);     gst_element_set_state(m_pipeline, gst_state_playing);     sleep(1);     gst_element_set_state(m_pipeline, gst_state_paused);     sleep(2);     gst_element_set_state(m_pipeline, gst_state_playing);      return 1; }   int main(int argc, char **argv) {     gmainloop *loop = g_main_loop_new (null, false);     gst_init(&argc, &argv);     createelements(argv[1]);     g_main_loop_run (loop);     return 0; } 

update: added multiple transitions paused / playing

on linux compile with

gcc -wall alsa_player.c -o alsa_player $(pkg-config --cflags --libs gstreamer-1.0) 

run ./alsa_player file.mp3

i using gstreamer 1.6 think code run 1.x gstreamer.

update2: can try use gst-play command same task specifying alsasink:

gst-play-1.0 japaka.mp3 --audiosink=alsasink

use space pausing , playing..


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -