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/kgv1dec.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'libavcodec/kgv1dec.c') diff --git a/libavcodec/kgv1dec.c b/libavcodec/kgv1dec.c index 01655a54b8..74ae6b7ffe 100644 --- a/libavcodec/kgv1dec.c +++ b/libavcodec/kgv1dec.c @@ -32,20 +32,20 @@ typedef struct { AVCodecContext *avctx; - AVFrame prev, cur; + AVFrame prev; } KgvContext; static void decode_flush(AVCodecContext *avctx) { KgvContext * const c = avctx->priv_data; - if (c->prev.data[0]) - avctx->release_buffer(avctx, &c->prev); + av_frame_unref(&c->prev); } static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { + AVFrame *frame = data; const uint8_t *buf = avpkt->data; const uint8_t *buf_end = buf + avpkt->size; KgvContext * const c = avctx->priv_data; @@ -65,17 +65,15 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, return res; if (w != avctx->width || h != avctx->height) { - if (c->prev.data[0]) - avctx->release_buffer(avctx, &c->prev); + av_frame_unref(&c->prev); avcodec_set_dimensions(avctx, w, h); } maxcnt = w * h; - c->cur.reference = 3; - if ((res = ff_get_buffer(avctx, &c->cur)) < 0) + if ((res = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0) return res; - out = (uint16_t *) c->cur.data[0]; + out = (uint16_t *) frame->data[0]; if (c->prev.data[0]) { prev = (uint16_t *) c->prev.data[0]; } else { @@ -156,12 +154,11 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, if (outcnt - maxcnt) av_log(avctx, AV_LOG_DEBUG, "frame finished with %d diff\n", outcnt - maxcnt); - *got_frame = 1; - *(AVFrame*)data = c->cur; + av_frame_unref(&c->prev); + if ((res = av_frame_ref(&c->prev, frame)) < 0) + return res; - if (c->prev.data[0]) - avctx->release_buffer(avctx, &c->prev); - FFSWAP(AVFrame, c->cur, c->prev); + *got_frame = 1; return avpkt->size; } -- cgit v1.2.3