From 759001c534287a96dc96d1e274665feb7059145d Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 21 Nov 2012 21:34:46 +0100 Subject: lavc decoders: work with refcounted frames. --- libavcodec/roqvideodec.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'libavcodec/roqvideodec.c') diff --git a/libavcodec/roqvideodec.c b/libavcodec/roqvideodec.c index 3ee62c01b5..ef561a3210 100644 --- a/libavcodec/roqvideodec.c +++ b/libavcodec/roqvideodec.c @@ -31,6 +31,7 @@ #include "avcodec.h" #include "bytestream.h" +#include "internal.h" #include "roqvideo.h" static void roqvideo_decode_frame(RoqContext *ri) @@ -168,8 +169,15 @@ static av_cold int roq_decode_init(AVCodecContext *avctx) s->width = avctx->width; s->height = avctx->height; - s->last_frame = &s->frames[0]; - s->current_frame = &s->frames[1]; + + s->last_frame = av_frame_alloc(); + s->current_frame = av_frame_alloc(); + if (!s->current_frame || !s->last_frame) { + av_frame_free(&s->current_frame); + av_frame_free(&s->last_frame); + return AVERROR(ENOMEM); + } + avctx->pix_fmt = AV_PIX_FMT_YUV444P; return 0; @@ -183,11 +191,11 @@ static int roq_decode_frame(AVCodecContext *avctx, int buf_size = avpkt->size; RoqContext *s = avctx->priv_data; int copy= !s->current_frame->data[0]; + int ret; - s->current_frame->reference = 3; - if (avctx->reget_buffer(avctx, s->current_frame)) { + if ((ret = ff_reget_buffer(avctx, s->current_frame)) < 0) { av_log(avctx, AV_LOG_ERROR, " RoQ: get_buffer() failed\n"); - return -1; + return ret; } if(copy) @@ -197,8 +205,9 @@ static int roq_decode_frame(AVCodecContext *avctx, bytestream2_init(&s->gb, buf, buf_size); roqvideo_decode_frame(s); + if ((ret = av_frame_ref(data, s->current_frame)) < 0) + return ret; *got_frame = 1; - *(AVFrame*)data = *s->current_frame; /* shuffle frames */ FFSWAP(AVFrame *, s->current_frame, s->last_frame); @@ -210,11 +219,8 @@ static av_cold int roq_decode_end(AVCodecContext *avctx) { RoqContext *s = avctx->priv_data; - /* release the last frame */ - if (s->last_frame->data[0]) - avctx->release_buffer(avctx, s->last_frame); - if (s->current_frame->data[0]) - avctx->release_buffer(avctx, s->current_frame); + av_frame_free(&s->current_frame); + av_frame_free(&s->last_frame); return 0; } -- cgit v1.2.1