libgstapp ownership

Tim Müller tim at centricular.com
Mon Oct 20 12:52:18 PDT 2014


On Mon, 2014-10-20 at 20:19 +0100, Chris Tapp wrote:

Hi Chris,

> The documentation for gst_app_src_push_buffer() says "This function
> takes ownership of the buffer" does that mean it adds a ref count to
> the buffer, or does it just mean that a ref-counted object passed in
> does not have to be unref'ed?

It means when you pass in a ref-counted or allocated object, you must
not use it afterwards and do not need to unref/free it. You can always
add another ref of course if you want to hang on to it and then unref
that again later.


> For example, is the following valid:
> 
>    GstBuffer * buffer = gst_sample_get_buffer( aSample );   // Buffer is valid as long as aSample is valid - take a reference if needed longer
> 
>    gst_app_src_push_buffer( myAppSrc, buffer );             // Does push_buffer take a reference?

This is not valid, because gst_sample_get_buffer() does not give you a
reference to the buffer, but push_buffer() gives away a reference, so
now you basically gave away the sample's reference, and things will go
downhill quickly from here.

> or should it be:
> 
>    gst_app_src_push_buffer( myAppSrc, gst_sample_ref( buffer ) );   // Take a reference before passing in.

This is correct in this particular context.

Regards
 -Tim

-- 
Tim Müller, Centricular Ltd - http://www.centricular.com



More information about the gstreamer-devel mailing list