Commit aca21478 authored by Anton Khirnov's avatar Anton Khirnov

vmdvideo: use the AVFrame API properly.

parent 3c8ea9d4
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment