Trying to undersand g_signal_connect()

Rick Blacker rick_blacker at hotmail.com
Thu Nov 3 04:44:04 UTC 2016


All, I'm working through the gstreamer tutorial https://gstreamer.freed
esktop.org/data/doc/gstreamer/head/manual/manual.pdf

On page page 43 is a simple streaming example. One of the things they
are showing is how to connect a callback to a signal. In this case, whe
a pad is added


=======================================================================
Here is where the signal is connected in the main function
=======================================================================
g_signal_connect( demuxer, "pad-added", G_CALLBACK( on_pad_added ),
decoder );



=======================================================================
Here is the code for the callback
======================================================================
static void on_pad_added( GstElement *element, GstPad *pad, 
					gpointer data )
{
	GstPad 		*sinkpad;
	GstElement 	*decoder = ( GstElement * ) data;

	/* We can now link this pad with the vorbis-decoder sink pad */
	g_print( "Dynamic pad created, linking demuxer/decoder\n" );

	// Get the sink pad from the vorbis decoder element 
	sinkpad = gst_element_get_static_pad( decoder, "sink" );

	gst_pad_link( pad, sinkpad );

	gst_object_unref( sinkpad );
}




In the code is the following comment

* note that the ogg demuxer will be linked to the vorbis decoder 
* dynamically. The reason is that Ogg may contain various streams 
* (for example audio and video). The source pad(s) will be created
* at run time, by the ogg demuxer when it detects the amount and 
* nature of streams. Therefore we connect a callback function which 
* will be executed when the "pad-added" is emitted.

I get the comment. But what is throwing me off is the actual code for
the definition of the callback. It's taking a pointer to an element,
but that element is not even being used. I might have thought that it
was a pointer to the demuxer.  

Which leads me to... Why are we adding the demuxer to the g_signal_call
?  Also where is the connection from the demuxer to the decoder? Is the
GstPad pad the pad on the demuxer???  

I guess what is throwing me off is the definition of calling 
g_signal_connect with it's required parameters and the declaration of
on_pad_added and it's function definition.  


Anyway, thanks for any clarification!!!

Rick






More information about the gstreamer-devel mailing list