问题
I'm reading the GStreamer application developer manual, which talks about the pipeline bus in the context of message handling / event handling, they talk about 2 functions: gst_bus_add_watch() and g_signal_connect(). It appears that these 2 functions are interchangeable. The application manual says:
Note that if you’re using the default GLib mainloop integration, you can, instead of attaching a watch, connect to the “message” signal on the bus.
In page 27. What's the difference between these 2 functions, and in what contexts are they useful? Who uses the callbacks that we register in these functions? Does the element itself call the callbacks?
回答1:
If you are using gst_bus_add_watch() then you provide a callback that will be called when a message is available.
If you call gst_bus_add_signal_watch() then that registers a default callback that will register a GSource to the main-loop. This enables the use of signals.
It is functionality wise equivalent, but if you are e.g. writing a glib/gtk based app, using signal everywhere might give your code more consistency.
来源:https://stackoverflow.com/questions/37220063/difference-between-gst-bus-add-watch-and-g-signal-connect