[FFmpeg-devel] [PATCH] lavu/buffer: add release function

wm4 nfxjfg at googlemail.com
Fri Feb 28 01:43:31 CET 2014


On Fri, 28 Feb 2014 01:21:22 +0100
Lukasz Marek <lukasz.m.luki at gmail.com> wrote:

> On 25.02.2014 17:47, wm4 wrote:
> > On Sun, 23 Feb 2014 23:19:23 +0100
> > Lukasz Marek <lukasz.m.luki at gmail.com> wrote:
> >
> >> new function allows to unref buffer and obtain its data.
> >>
> >
> >
> >>   /**
> >> + * Free a given reference and pass underlaying data to user provided pointer.
> >> + * If there is more than one reference then data is copied.
> >> + *
> >> + * @param buf  the reference to be released. The pointer is set to NULL on return.
> >> + * @param data pointer to be passed with underlaying data.
> >> + * @return 0 on success, a negative AVERROR on failure.
> >> + *
> >> + * @note on error buffer is properly released and *data is set to NULL.
> >> + */
> >> +int av_buffer_release(AVBufferRef **buf, uint8_t **data);
> >> +
> >> +/**
> >
> > What's the point of this? You can access the data at any time, as long
> > as you have a reference to it. You can use av_buffer_make_writeable
> > (not sure if I spelled this correctly) to get an exclusive buffer. If
> > there are more than 1 references or the buffer is marked read-only,
> > then it will make a copy.
> 
> At some point application may don't need profits from using AVBufferRef, 
> but may prefer to control "raw" buffer on some other way, like 
> std::shared_ptr c++ hated here stuff :)

I'm not sure what you want to say here.

> > Keep in mind that a buffer can come from a user application. There is
> > no way you could free such a buffer correctly by destroying the buffer
> > reference and just returning the raw data.
> 
> I don't get it.

I'm not sure if I get this function either. What happens if the buffer
was created with av_buffer_create()? Assume the AVBuffer has only 1
reference, and av_buffer_release() is called on it. Then when will the
user's free callback be called?

As I see it, this function could make sense if you own the AVBuffer
anyway, but then it'll be useful only in very few situations. Also, it
will lead to undefined behavior on buffers which you don't actually own,
so this function is very dangerous.



More information about the ffmpeg-devel mailing list