[FFmpeg-devel] [PATCH 0/2]: allow hwaccel vda module to manage its buffers lifetime.

Hendrik Leppkes h.leppkes at gmail.com
Thu May 23 09:19:11 CEST 2013

On Thu, May 23, 2013 at 9:14 AM, Sebastien Zwickert <dilaroga at gmail.com> wrote:
> On May 23, 2013, at 8:29 AM, Hendrik Leppkes <h.leppkes at gmail.com> wrote:
>> On Wed, May 22, 2013 at 9:53 PM, Sebastien Zwickert <dilaroga at gmail.com> wrote:
>>> This patchset fixes memory leaks of vda core video buffers while seeking.
>>> It allows hwaccel modules to set a custom callback for freeing av buffers.
>>> Then vda decoder can flush correctly dropped frames.
>>> Thanks to Xidorn Quan who gives me good feebacks about the patch I shared
>>> with him in private.
>>> Sebastien Zwickert (2):
>>>  hwaccel: allow to set a user-defined callback for releasing private
>>>    av buffer.
>>>  vda: use hwaccel custom callback for releasing private picture
>>>    context.
>>> libavcodec/avcodec.h   |   12 ++++++++++++
>>> libavcodec/h264.c      |    9 ++++++++-
>>> libavcodec/mpegvideo.c |    9 ++++++++-
>>> libavcodec/vda.h       |   12 +++++++++++-
>>> libavcodec/vda_h264.c  |   18 ++++++++++++++++++
>>> 5 files changed, 57 insertions(+), 3 deletions(-)
>>> --
>>> (Apple Git-31.1)
>>> _______________________________________________
>>> ffmpeg-devel mailing list
>>> ffmpeg-devel at ffmpeg.org
>>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> You set frame->data[3] to the same buffer that needs freeing, why not
>> simply also set frame->buf appropriately to a AVBufferRef you create,
>> so that it gets free'ed with a callback there?
>> No extra release buffer callback needed from where i stand.
> I'm not sure to understand correctly but the vda buffer is part of
> Core Video SDK which is based on a ref counted memory management
> and must be released with CVPixelBufferRelease().
> So custom callback for freeing Core Video types is necessary.

You can do that if you just create a AVBufferRef around your buffer
(you can specify a release callback for AVBufferRefs) and put it
somewhere in frame->buf, it'll be free'ed with the frame then.
I'm not really liking the new function in AVHWAccel, because its not
really required with the new buffer management functions.

Considering frame->data[3] is set by the code, i think its safe to
also set frame->buf[3] to the AVBufferRef managing this buffer without
worrying about user-code.

More information about the ffmpeg-devel mailing list