From aca214783af9b48600b74a547dafdbbdb702d979 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 9 Nov 2013 10:14:46 +0100 Subject: [PATCH] vmdvideo: use the AVFrame API properly. --- libavcodec/vmdav.c | 48 ++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/libavcodec/vmdav.c b/libavcodec/vmdav.c index b1ecace93a..a1e39c0588 100644 --- a/libavcodec/vmdav.c +++ b/libavcodec/vmdav.c @@ -60,7 +60,7 @@ typedef struct VmdVideoContext { AVCodecContext *avctx; - AVFrame prev_frame; + AVFrame *prev_frame; const unsigned char *buf; int size; @@ -243,11 +243,11 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame) /* if only a certain region will be updated, copy the entire previous * frame before the decode */ - if (s->prev_frame.data[0] && + if (s->prev_frame->data[0] && (frame_x || frame_y || (frame_width != s->avctx->width) || (frame_height != s->avctx->height))) { - memcpy(frame->data[0], s->prev_frame.data[0], + memcpy(frame->data[0], s->prev_frame->data[0], s->avctx->height * frame->linesize[0]); } @@ -290,7 +290,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame) } dp = &frame->data[0][frame_y * frame->linesize[0] + frame_x]; - pp = &s->prev_frame.data[0][frame_y * s->prev_frame.linesize[0] + frame_x]; + pp = &s->prev_frame->data[0][frame_y * s->prev_frame->linesize[0] + frame_x]; switch (meth) { case 1: for (i = 0; i < frame_height; i++) { @@ -306,7 +306,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame) ofs += len; } else { /* interframe pixel copy */ - if (ofs + len + 1 > frame_width || !s->prev_frame.data[0]) + if (ofs + len + 1 > frame_width || !s->prev_frame->data[0]) return AVERROR_INVALIDDATA; memcpy(&dp[ofs], &pp[ofs], len + 1); ofs += len + 1; @@ -319,7 +319,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame) return AVERROR_INVALIDDATA; } dp += frame->linesize[0]; - pp += s->prev_frame.linesize[0]; + pp += s->prev_frame->linesize[0]; } break; @@ -327,7 +327,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame) for (i = 0; i < frame_height; i++) { bytestream2_get_buffer(&gb, dp, frame_width); dp += frame->linesize[0]; - pp += s->prev_frame.linesize[0]; + pp += s->prev_frame->linesize[0]; } break; @@ -352,7 +352,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame) } } else { /* interframe pixel copy */ - if (ofs + len + 1 > frame_width || !s->prev_frame.data[0]) + if (ofs + len + 1 > frame_width || !s->prev_frame->data[0]) return AVERROR_INVALIDDATA; memcpy(&dp[ofs], &pp[ofs], len + 1); ofs += len + 1; @@ -365,13 +365,23 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame) return AVERROR_INVALIDDATA; } dp += frame->linesize[0]; - pp += s->prev_frame.linesize[0]; + pp += s->prev_frame->linesize[0]; } break; } return 0; } +static av_cold int vmdvideo_decode_end(AVCodecContext *avctx) +{ + VmdVideoContext *s = avctx->priv_data; + + av_frame_free(&s->prev_frame); + av_free(s->unpack_buffer); + + return 0; +} + static av_cold int vmdvideo_decode_init(AVCodecContext *avctx) { VmdVideoContext *s = avctx->priv_data; @@ -410,6 +420,12 @@ static av_cold int vmdvideo_decode_init(AVCodecContext *avctx) palette32[i] = (r << 16) | (g << 8) | (b); } + s->prev_frame = av_frame_alloc(); + if (!s->prev_frame) { + vmdvideo_decode_end(avctx); + return AVERROR(ENOMEM); + } + return 0; } @@ -441,8 +457,8 @@ static int vmdvideo_decode_frame(AVCodecContext *avctx, memcpy(frame->data[1], s->palette, PALETTE_COUNT * 4); /* shuffle frames */ - av_frame_unref(&s->prev_frame); - if ((ret = av_frame_ref(&s->prev_frame, frame)) < 0) + av_frame_unref(s->prev_frame); + if ((ret = av_frame_ref(s->prev_frame, frame)) < 0) return ret; *got_frame = 1; @@ -451,16 +467,6 @@ static int vmdvideo_decode_frame(AVCodecContext *avctx, return buf_size; } -static av_cold int vmdvideo_decode_end(AVCodecContext *avctx) -{ - VmdVideoContext *s = avctx->priv_data; - - av_frame_unref(&s->prev_frame); - av_free(s->unpack_buffer); - - return 0; -} - /* * Audio Decoder