diff options
Diffstat (limited to 'libavcodec/eacmv.c')
-rw-r--r-- | libavcodec/eacmv.c | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/libavcodec/eacmv.c b/libavcodec/eacmv.c index 0dce066..33c6145 100644 --- a/libavcodec/eacmv.c +++ b/libavcodec/eacmv.c @@ -2,20 +2,20 @@ * Electronic Arts CMV Video Decoder * Copyright (c) 2007-2008 Peter Ross * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -45,6 +45,10 @@ typedef struct CmvContext { static av_cold int cmv_decode_init(AVCodecContext *avctx){ CmvContext *s = avctx->priv_data; + avcodec_get_frame_defaults(&s->frame); + avcodec_get_frame_defaults(&s->last_frame); + avcodec_get_frame_defaults(&s->last2_frame); + s->avctx = avctx; avctx->pix_fmt = AV_PIX_FMT_PAL8; return 0; @@ -108,9 +112,10 @@ static void cmv_decode_inter(CmvContext * s, const uint8_t *buf, const uint8_t * }else{ /* inter using last frame as reference */ int xoffset = (buf[i] & 0xF) - 7; int yoffset = ((buf[i] >> 4)) - 7; - cmv_motcomp(s->frame.data[0], s->frame.linesize[0], - s->last_frame.data[0], s->last_frame.linesize[0], - x*4, y*4, xoffset, yoffset, s->avctx->width, s->avctx->height); + if (s->last_frame.data[0]) + cmv_motcomp(s->frame.data[0], s->frame.linesize[0], + s->last_frame.data[0], s->last_frame.linesize[0], + x*4, y*4, xoffset, yoffset, s->avctx->width, s->avctx->height); } i++; } @@ -127,8 +132,13 @@ static void cmv_process_header(CmvContext *s, const uint8_t *buf, const uint8_t s->width = AV_RL16(&buf[4]); s->height = AV_RL16(&buf[6]); - if (s->avctx->width!=s->width || s->avctx->height!=s->height) + if (s->avctx->width!=s->width || s->avctx->height!=s->height) { avcodec_set_dimensions(s->avctx, s->width, s->height); + if (s->frame.data[0]) + s->avctx->release_buffer(s->avctx, &s->frame); + if (s->last_frame.data[0]) + s->avctx->release_buffer(s->avctx, &s->last_frame); + } s->avctx->time_base.num = 1; s->avctx->time_base.den = AV_RL16(&buf[10]); @@ -138,7 +148,7 @@ static void cmv_process_header(CmvContext *s, const uint8_t *buf, const uint8_t buf += 16; for (i=pal_start; i<pal_start+pal_count && i<AVPALETTE_COUNT && buf_end - buf >= 3; i++) { - s->palette[i] = AV_RB24(buf); + s->palette[i] = 0xFFU << 24 | AV_RB24(buf); buf += 3; } } @@ -159,8 +169,11 @@ static int cmv_decode_frame(AVCodecContext *avctx, return AVERROR_INVALIDDATA; if (AV_RL32(buf)==MVIh_TAG||AV_RB32(buf)==MVIh_TAG) { + unsigned size = AV_RL32(buf + 4); cmv_process_header(s, buf+EA_PREAMBLE_SIZE, buf_end); - return buf_size; + if (size > buf_end - buf - EA_PREAMBLE_SIZE) + return -1; + buf += size; } if (av_image_check_size(s->width, s->height, 0, s->avctx)) @@ -172,8 +185,10 @@ static int cmv_decode_frame(AVCodecContext *avctx, FFSWAP(AVFrame, s->last_frame, s->last2_frame); FFSWAP(AVFrame, s->frame, s->last_frame); - s->frame.reference = 1; - s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; + s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | + FF_BUFFER_HINTS_READABLE | + FF_BUFFER_HINTS_PRESERVE; if (ff_get_buffer(avctx, &s->frame)<0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); return -1; |