[gst-devel] Signals in GStreamer ???
jerome.patey at open-plug.com
Tue Apr 19 11:48:26 CEST 2005
I was looking at the GStreamer code, and I can't understand one
thing, about signals. I'll start my explanation with an example :
For the signal "plugin_added", it is created by the GstRegistry with :
g_signal_new ("plugin-added", G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstRegistryClass,
NULL, gst_marshal_VOID__POINTER, G_TYPE_NONE, 1, G_TYPE_POINTER);
The prototype of (GstRegistryClass, plugin_added) is :
void (*plugin_added) (GstRegistry *registry,
When a user wants to connect to this signal, he does :
g_signal_connect (G_OBJECT (registry), "plugin_added",
G_CALLBACK (plugin_added_func), NULL);
He gives a callback with the following prototype :
static void plugin_added_func (GstRegistry * registry, GstPlugin * plugin,
The g_signal_emit will ask the marshaller
(gst_marshal_VOID__POINTER) to call the different callbacks
((GstRegistryClass, plugin_added) and plugin_added_func in this case)
with the parameters "GstRegistry*", "GstPlugin*" and "gpointer".
But what I can't understand is : how can the marshaller call 2
different callbacks with 2 different prototypes. When I look at the code
of gst_marshal_VOID__POINTER (auto generated by glib-genmarshal), I see
the function call, which is similar to this, for the 2 callbacks :
callback (pointer1, pointer2, pointer3)
But the point is : (GstRegistryClass, plugin_added) must receive
only 2 parameters, and the marshaller sends 3 parameters (even though
the last one is NULL, and will not be used). plugin_added_func will
correctly receive the 3 parameters.
What happens to the last parameter not used in the first function ?
It will stay on the stack ? Then the program should crash...
On x86, I think that the caller removes the parameters from the
stack, and the called uses them, but I thought it was only in certain
cases, not always (depends on cdecl, or things like this I thought).
On ARM, the parameters are removed from the stack by the called, and
thus, how can this work ? The 3rd parameter won't be removed from the
stack (because the called has only a prototype with 2 parameters), and
so, how can it work ?
Thanks in advance for your answers...
Jerome Patey - jerome.patey at open-plug.com
Tools & Update
Open-Plug, Sophia-Antipolis, FRANCE
More information about the gstreamer-devel