aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXidorn Quan <quanxunzhen@gmail.com>2013-03-29 23:15:20 +0800
committerMichael Niedermayer <michaelni@gmx.at>2013-03-29 17:55:48 +0100
commitc7269e3a2697c189c907832b8a36341cbb40936c (patch)
tree50bb8d8ada2d3fa30baf7664a673b386cf42cf2d
parentef7b6b489ab38a8f0abe6b8f55c0e130cbd125c9 (diff)
downloadffmpeg-c7269e3a2697c189c907832b8a36341cbb40936c.tar.gz
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>
-rw-r--r--libavcodec/vda_h264_dec.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/libavcodec/vda_h264_dec.c b/libavcodec/vda_h264_dec.c
index 1bee92baf9..4e60de0126 100644
--- a/libavcodec/vda_h264_dec.c
+++ b/libavcodec/vda_h264_dec.c
@@ -64,23 +64,30 @@ static enum AVPixelFormat get_format(struct AVCodecContext *avctx,
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;
- pic->data[0] = (void *)1;
- return 0;
+ VDABufferContext *context = opaque;
+ CVPixelBufferUnlockBaseAddress(context->cv_buffer, 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;
-
- CVPixelBufferRef cv_buffer = (CVPixelBufferRef)pic->data[3];
- CVPixelBufferUnlockBaseAddress(cv_buffer, 0);
- CVPixelBufferRelease(cv_buffer);
+ 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);
+ }
- for (i = 0; i < 4; i++)
- pic->data[i] = NULL;
+ pic->buf[0] = buffer;
+ pic->data[0] = (void *)1;
+ return 0;
}
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);
if (*got_frame) {
+ AVBufferRef *buffer = pic->buf[0];
+ VDABufferContext *context = av_buffer_get_opaque(buffer);
CVPixelBufferRef cv_buffer = (CVPixelBufferRef)pic->data[3];
CVPixelBufferLockBaseAddress(cv_buffer, 0);
+ context->cv_buffer = cv_buffer;
pic->format = ctx->pix_fmt;
if (CVPixelBufferIsPlanar(cv_buffer)) {
int i, count = CVPixelBufferGetPlaneCount(cv_buffer);
@@ -221,8 +231,11 @@ static av_cold int vdadec_init(AVCodecContext *avctx)
/* changes callback functions */
avctx->get_format = get_format;
- avctx->get_buffer = get_buffer;
- avctx->release_buffer = release_buffer;
+ avctx->get_buffer2 = get_buffer2;
+#if FF_API_GET_BUFFER
+ // force the old get_buffer to be empty
+ avctx->get_buffer = NULL;
+#endif
/* init H.264 decoder */
ret = ff_h264_decoder.init(avctx);