GStreamer bus system is mainly used to provide users with internal elements event information. Using the GStreamer bus system, just call Gst_bus_add_watch and register a callback. The problem, however, is when the interface is invoked, and the thread used to handle the bus event. The callback is implemented internally with the glib source mechanism, and the source is attach to a gmaincontext, and a gmainloop is needed to listen to the context. Typically, the thread that calls Gst_bus_add_watch, without any processing, is null for the source attach Gmaincontext, which is the default Main context. The thread that listens to the default Main context is not necessarily the caller thread, so there is a multi-threaded mutex problem when the resource is reclaimed.
The method that requires the callback function to execute in the caller thread is as follows:
1. After creating the caller thread, create the thread's own gmaincontext and Gmainloop, and then call G_main_context_push_thread_default, which is the thread's own default context, and use Gmainloop to listen;
2. After calling Gst_bus_add_watch in the thread, the callback is executed in the caller thread, avoiding the problem of multi-threaded mutex.
This method avoids the problem that the main thread of the application is overburdened. In addition, all GIO-based applications also use G_main_context_push_thread_default to disperse the load on each thread.