does the last element unref the data buffer went it is done with it?
Tim Müller
tim at centricular.com
Thu Feb 11 09:35:44 UTC 2016
On Wed, 2016-02-10 at 19:55 -0800, Andres Gonzalez wrote:
Hi,
> GstBuffer *pVideoBuffer = gst_buffer_new_wrapped_full
> (GST_MEMORY_FLAG_READONLY,
> pBuffer, m_nSize, 0, m_nSize,
> m_pGstStreamBuffers, freeVideoBufferCB);
The m_pGstStreamBuffers here looks suspicious (because plural), but I
gather that's not your problem (yet), but that the callback isn't
getting called.
> In the GStreamer Application Development Manual (1.7.0.1), chapter 9
> on Buffers, the next to last paragraph seems to imply that typically
> an element will unref the buffer when it has passed it on to the next
> element in the pipeline. So I thought the last element in my
> pipeline would unref the buffer and then it would call the
> GDestroyNotify routine.
It depends on the pipeline which element will unref which buffer.
Sometimes buffer are just passed through from source to sink, at other
times an element will just create a new output buffer and unref the
input buffer (or create a new output buffer and keep the input buffer
around for a while, but then later unref it).
> Obviously I have it totally wrong because, using the above buffer
> with its GDestroyNotify routine (freeVideoBufferCB), it does not get
> called after each buffer is used, but instead, is called when the
> application exits,which by then has accumulated many, many
> references.
Buffers should be (created and) freed on a regular basis, not just when
the application exits. What's your pipeline exactly?
The simplest test case would be:
appsrc ! fakesink enable-last-sample=false
then
appsrc ! fakesink
(here the fakesink will hold onto the last buffer until the next buffer arrives)
> So my question is how does the application know when the last element
> in the pipeline is finished with the data buffer so it can be
> unreffed? My application is not getting any GST_MESSAGE_BUFFERING
> events and I cannot find any signals that appear appropriate.
There are no signals, and BUFFERING messages have nothing to do with
this either really :)
Make sure you're familiar with the concept of refcounting. Think of it
as a 'keepalive' count.
When a buffer is created, it starts out with a refcount of 1, and
whoever created it is the owner.
When a buffer is pushed to the next element, the ownership of the
buffer (that reference) is passed along to the next element.
When the next element is done with it and doesn't need the buffer any
longer, it will unref the buffer to drop its ownership/keepalive count.
When the buffer refcount reaches 0, the buffer will be freed and your
destroy notify function from gst_buffer_new_wrap_full() will be called
with the userdata/destroynotifydata.
Cheers
-Tim
--
Tim Müller, Centricular Ltd - http://www.centricular.com
More information about the gstreamer-devel
mailing list