gst_element_get_request_pad usage question

Sebastian Dröge sebastian at centricular.com
Wed Oct 5 07:10:42 UTC 2016


On Mon, 2016-10-03 at 21:28 +0000, William Salibrici wrote:
> Hello,
> 
> The GStreamer Application Development Manual (1.8.3) page 32 shows a
> simple usage example for gst_element_get_request_pad. The example
> uses gst_object_unref (GST_OBJECT (pad)) when you are finished with
> the pad object. I found the same kind of usage in some of your test
> examples. I have also used it this way in my application C code and
> it appears to work ok.
> 
> However, I noticed that your core reference [direct from your
> documentation website] for GstElement, gst_element_get_request_pad,
> states that ‘The pad should be released with
> gst_element_release_request_pad().’ It doesn’t say anything about
> using gst_object_unref.
> 
> So my question is which one is correct – the manual or your core
> reference, or maybe both somehow? Will I end up with resource leaks
> if I don’t exactly follow the core reference?

There are two parts to this.

First of all, pads like all GObjects are reference counted and you have
to handle this correctly with the right amount of g_object_ref() and
g_object_unref() calls in the right places. Details depend on your code
and what exactly you call, see the documentation and what it says about
ownership transfer in the function documentation.


Then for request pads there's another aspect. If you request a pad from
an element, the element will give you a reference to a new pad but it
will also internally keep another reference of the pad (in the end, it
would be useless if only your code had a reference to the pad, what/how
would the element be supposed to do something with it?).
So you unref your reference when you don't need it anymore, but you
also should release the pad from the element when the element should
not have the pad at all anymore.
When the element is destroyed, it will automatically remove all
remaining pads from itself though.

-- 
Sebastian Dröge, Centricular Ltd · http://www.centricular.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 931 bytes
Desc: This is a digitally signed message part
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20161005/c25759f3/attachment.sig>


More information about the gstreamer-devel mailing list