[gst-devel] question re: buffer handling
richard at tartarus.org
Thu Aug 29 08:49:04 CEST 2002
On Thu, 2002-08-29 at 15:59, Thomas Vander Stichele wrote:
> > Since buffers are reference counted, you could use that to see if you
> > are the only one holding a reference (I think).
> Yeah, theoretically, but this could get nasty very quickly. I don't know
> if it's safe to use the reference count for this, and you'd probably have
> to do locking for it to work.
How about making a helper function which takes a buffer and returns a
buffer which is safe to modify. This function would work by getting
appropriate locks, checking the buffer reference count, returning the
same buffer if the refcount is 1 (so noone else is looking at the
buffer), or taking a copy of the buffer if the refcount is 0.
Then, before an element modifies a buffer, it should _always_ call the
helper function to get a buffer that's safe to modify.
I'm not sure that having a special flag to set is as useful as having a
function to call: perhaps the element only occasionally wants to modify
a buffer, but normally passes through, for example. (For example, an
element which does a fade out at the beginning and end of a song, but
passes buffers through unchanged otherwise)
The problem with a tee simply marking all its buffers readonly is that
you then force all the buffers to be copied, instead of allowing the
final one to be used without copying it. In other words, you force an
extra buffer copy. I'm not sure how important this is, but it would be
nice to avoid it.
More information about the gstreamer-devel