1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

vda_h264_dec: fit the new API

It fixes a memory leak in this decoder caused by the API change.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
Xidorn Quan 2013-03-29 23:15:20 +08:00 committed by Michael Niedermayer
parent ef7b6b489a
commit c7269e3a26

View File

@ -64,23 +64,30 @@ static enum AVPixelFormat get_format(struct AVCodecContext *avctx,
return AV_PIX_FMT_VDA_VLD; return AV_PIX_FMT_VDA_VLD;
} }
static int get_buffer(AVCodecContext *avctx, AVFrame *pic) typedef struct {
CVPixelBufferRef cv_buffer;
} VDABufferContext;
static void release_buffer(void *opaque, uint8_t *data)
{ {
pic->type = FF_BUFFER_TYPE_USER; VDABufferContext *context = opaque;
pic->data[0] = (void *)1; CVPixelBufferUnlockBaseAddress(context->cv_buffer, 0);
return 0; CVPixelBufferRelease(context->cv_buffer);
av_free(context);
} }
static void release_buffer(AVCodecContext *avctx, AVFrame *pic) static int get_buffer2(AVCodecContext *avctx, AVFrame *pic, int flag)
{ {
int i; VDABufferContext *context = av_mallocz(sizeof(VDABufferContext));
AVBufferRef *buffer = av_buffer_create(NULL, 0, release_buffer, context, 0);
if (!context || !buffer) {
av_free(context);
return AVERROR(ENOMEM);
}
CVPixelBufferRef cv_buffer = (CVPixelBufferRef)pic->data[3]; pic->buf[0] = buffer;
CVPixelBufferUnlockBaseAddress(cv_buffer, 0); pic->data[0] = (void *)1;
CVPixelBufferRelease(cv_buffer); return 0;
for (i = 0; i < 4; i++)
pic->data[i] = NULL;
} }
static int vdadec_decode(AVCodecContext *avctx, static int vdadec_decode(AVCodecContext *avctx,
@ -92,8 +99,11 @@ static int vdadec_decode(AVCodecContext *avctx,
ret = ff_h264_decoder.decode(avctx, data, got_frame, avpkt); ret = ff_h264_decoder.decode(avctx, data, got_frame, avpkt);
if (*got_frame) { if (*got_frame) {
AVBufferRef *buffer = pic->buf[0];
VDABufferContext *context = av_buffer_get_opaque(buffer);
CVPixelBufferRef cv_buffer = (CVPixelBufferRef)pic->data[3]; CVPixelBufferRef cv_buffer = (CVPixelBufferRef)pic->data[3];
CVPixelBufferLockBaseAddress(cv_buffer, 0); CVPixelBufferLockBaseAddress(cv_buffer, 0);
context->cv_buffer = cv_buffer;
pic->format = ctx->pix_fmt; pic->format = ctx->pix_fmt;
if (CVPixelBufferIsPlanar(cv_buffer)) { if (CVPixelBufferIsPlanar(cv_buffer)) {
int i, count = CVPixelBufferGetPlaneCount(cv_buffer); int i, count = CVPixelBufferGetPlaneCount(cv_buffer);
@ -221,8 +231,11 @@ static av_cold int vdadec_init(AVCodecContext *avctx)
/* changes callback functions */ /* changes callback functions */
avctx->get_format = get_format; avctx->get_format = get_format;
avctx->get_buffer = get_buffer; avctx->get_buffer2 = get_buffer2;
avctx->release_buffer = release_buffer; #if FF_API_GET_BUFFER
// force the old get_buffer to be empty
avctx->get_buffer = NULL;
#endif
/* init H.264 decoder */ /* init H.264 decoder */
ret = ff_h264_decoder.init(avctx); ret = ff_h264_decoder.init(avctx);