I am writing an audio application that will play audio stream using gstreamer based on events its received from external application.
So i have something like this in my main function: int main(void) { int Chnl1=0, Chnl2=1; ... /* init */ gst_init (); while(event) { ..... if (event == File1PlayToChl1) playAudioFileWithGstreamer(Chnl1); if (event == File2PlayToChl2) playAudioFileWithGstreamer(Chnl2); .... } .... ... } and for example: void playAudioFileWithGstreamer(int chnl_number) { /* create source and destination elements */ // source is File1 or File2 // destination is a audio output stereo (2chl) sound card /* put together a pipeline */ //if file == File1, connect File1 to sound card Channel 0 //if file == File2, connect File2 to sound card Channel 1 /* start the pipeline */ gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); [..] } Is g_main_loop_run (loop) a blocking function and will not return until the file playback is done? My objective is to be able to play File1 (if that was the first event) and then allow the while loop to still listen to events and when an event for File2 arrive (assuming that File1 event will not come anymore), I want to play File 2 on the 2nd channel of the SAME sound card. My problem is that g_main_loop_run (loop) blocks the first playback and prevent the while loop to receive events and does not allow my application to play the 2 files in parallel (simultaneously)!!! Is anyone can give me some hints how to implement this use case as regards to how/where to use g_main_loop_run() ? Thanks. |
On Wed, 2016-09-07 at 11:01 -0700, ge_keep wrote:
> > *Is g_main_loop_run (loop) a blocking function and will not return until the > file playback is done?* > My objective is to be able to play File1 (if that was the first event) and > then allow the while loop to still listen to events and when an event for > File2 arrive (assuming that File1 event will not come anymore), I want to > play File 2 on the 2nd channel of the SAME sound card. My problem is that > g_main_loop_run (loop) blocks the first playback and prevent the while loop > to receive events and does not allow my application to play the 2 files in > parallel (simultaneously)!!! > > Is anyone can give me some hints how to implement this use case as regards > to how/where to use g_main_loop_run() ? you called g_main_loop_quit(). In the meantime it will consume all events that are happening. So you either want to integrate your events with GMainLoop (for which there are lots of different possibilities, depending on what kind of events you get and from where), or you don't want to use a GMainLoop and do your own event loop instead (in which case you can use other parts of the GstBus API for getting GstMessages, depending on how you want to integrate with your own event loop). -- Sebastian Dröge, Centricular Ltd · http://www.centricular.com _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel signature.asc (949 bytes) Download Attachment |
Thank you Sebastian. Your answer really helps me to understand better.
You mentioned: "...you can use other parts of the GstBus API for getting GstMessages,.." Do you mean that in case I still want to keep my own events loop (with the while(event)) and use the GstBus API, I DO NOT need to call g_main_loop_run()? It looks to me that GstBus API helps to report on events happening in gstreamer pipelines back to the top level application. |
On Thu, 2016-09-08 at 10:18 -0700, ge_keep wrote:
> Thank you Sebastian. Your answer really helps me to understand better. > You mentioned: > > "...you can use other parts of the GstBus API for getting GstMessages,.." > > Do you mean that in case I still want to keep my own events loop (with the > while(event)) and use the GstBus API, I DO NOT need to call > g_main_loop_run()? > It looks to me that GstBus API helps to report on events happening in > gstreamer pipelines back to the top level application. docs, you can also e.g. poll the bus or get (synchronously) notified when some new message is there. I did something here for getting it integrated somehow into the Qt event loop for example: https://github.com/sdroege/gst-snippets/blob/master/qt5-eventloop/gst-qt-example.cc -- Sebastian Dröge, Centricular Ltd · http://www.centricular.com _______________________________________________ gstreamer-devel mailing list [hidden email] https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel signature.asc (949 bytes) Download Attachment |
Free forum by Nabble | Edit this page |