Running every GStremer pipeline into a separate (GLib) thread

Nicolas Dufresne nicolas at ndufresne.ca
Wed Jun 17 12:57:05 UTC 2020


Le vendredi 12 juin 2020 à 06:57 -0500, pvv a écrit :
> First of all excuse me for the stupid question as I;m a newbie in the
> GStreamer development.
> 
> I've read part of the documentation and most of the samples, but there is
> one thing I cannot understand completely. (Well there are more of course but
> this is the most interesting one :-))
> All of the samples are initializing GLib main tread trough the some form of:
> 
> loop = g_main_loop_new(NULL, FALSE);
> g_main_loop_run(loop);
> 
> As far as I understood this mail loop is used for all the signals
> processing.
> Also Bus messages are processed in it.

GMainLoop is optional with GStreamer (convenient but optional). You can
use the GstBus API directly. As for signals, these are synchronous, and
not using a messageé

> 
> So I'm a little bit concerned what will happen if I run multiple pipelines
> simultaneously.
> Or there is an issue/improper implementation in some of them.

If you decide to use a GMainLoop, you will only need one to handle
asynchronous messages, as all message gets serialized into the loop
queue. Multiple pipeline is were that becomes convenient as you don't
have to deal with multiple GstBus object.

> 
> Most probably for heavy loads the best solution is pipelines to be separated
> to multiple processes, thus mitigating all the possible problems with memory
> leaks, hangs, dead locks etc., without affecting the main 
> application.

GStreamer splits the streaming into seperate threads already. The
mainloop thread is always free for other task (like UI task).

> 
> Anyway at least running them into separate threads will be beneficial. 
> 
> Obviously it is possible to be started more than one GLib main thread, with
> creation of the GMainContext first. But I cannot understand (apparently I'm
> missing knowledge) how after that to "assign" them to pipelines or signaling
> to them, etc.
> For example in "g_signal_connect" and "g_signal_emit" is not specified on
> which "main" thread to be executed.
> 
> Some posts here claim it is possible (GStreamer supports different main
> thread), but I wasn't able to find details.
> 
> Similar problem is discussed in this  thread
> <http://gstreamer-devel.966125.n4.nabble.com/how-to-make-gstreamer-run-in-separate-thread-td1960435.html>  
> but to be honest I wasn't able to understand it.
> 
> In  this StackOverflow post
> <https://stackoverflow.com/questions/26410585/add-callback-for-separate-g-main-loop>  
> is discussed how timeouts could be attached to different GLib main threads. 
> I suppose that something similar could be made and for the GStreamer
> pipelines and objects, but I'm not sure.
> 
> Could someone enlighten me a little bit, please ?
> Thanks in advance !
> 
> 
> 
> 
> --
> Sent from: http://gstreamer-devel.966125.n4.nabble.com/
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel



More information about the gstreamer-devel mailing list