mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
vmdvideo: use the AVFrame API properly.
This commit is contained in:
parent
3c8ea9d4a7
commit
aca214783a
@ -60,7 +60,7 @@
|
|||||||
typedef struct VmdVideoContext {
|
typedef struct VmdVideoContext {
|
||||||
|
|
||||||
AVCodecContext *avctx;
|
AVCodecContext *avctx;
|
||||||
AVFrame prev_frame;
|
AVFrame *prev_frame;
|
||||||
|
|
||||||
const unsigned char *buf;
|
const unsigned char *buf;
|
||||||
int size;
|
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
|
/* if only a certain region will be updated, copy the entire previous
|
||||||
* frame before the decode */
|
* 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_x || frame_y || (frame_width != s->avctx->width) ||
|
||||||
(frame_height != s->avctx->height))) {
|
(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]);
|
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];
|
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) {
|
switch (meth) {
|
||||||
case 1:
|
case 1:
|
||||||
for (i = 0; i < frame_height; i++) {
|
for (i = 0; i < frame_height; i++) {
|
||||||
@ -306,7 +306,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
|
|||||||
ofs += len;
|
ofs += len;
|
||||||
} else {
|
} else {
|
||||||
/* interframe pixel copy */
|
/* 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;
|
return AVERROR_INVALIDDATA;
|
||||||
memcpy(&dp[ofs], &pp[ofs], len + 1);
|
memcpy(&dp[ofs], &pp[ofs], len + 1);
|
||||||
ofs += len + 1;
|
ofs += len + 1;
|
||||||
@ -319,7 +319,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
|
|||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
dp += frame->linesize[0];
|
dp += frame->linesize[0];
|
||||||
pp += s->prev_frame.linesize[0];
|
pp += s->prev_frame->linesize[0];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -327,7 +327,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
|
|||||||
for (i = 0; i < frame_height; i++) {
|
for (i = 0; i < frame_height; i++) {
|
||||||
bytestream2_get_buffer(&gb, dp, frame_width);
|
bytestream2_get_buffer(&gb, dp, frame_width);
|
||||||
dp += frame->linesize[0];
|
dp += frame->linesize[0];
|
||||||
pp += s->prev_frame.linesize[0];
|
pp += s->prev_frame->linesize[0];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -352,7 +352,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* interframe pixel copy */
|
/* 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;
|
return AVERROR_INVALIDDATA;
|
||||||
memcpy(&dp[ofs], &pp[ofs], len + 1);
|
memcpy(&dp[ofs], &pp[ofs], len + 1);
|
||||||
ofs += len + 1;
|
ofs += len + 1;
|
||||||
@ -365,13 +365,23 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
|
|||||||
return AVERROR_INVALIDDATA;
|
return AVERROR_INVALIDDATA;
|
||||||
}
|
}
|
||||||
dp += frame->linesize[0];
|
dp += frame->linesize[0];
|
||||||
pp += s->prev_frame.linesize[0];
|
pp += s->prev_frame->linesize[0];
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return 0;
|
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)
|
static av_cold int vmdvideo_decode_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
VmdVideoContext *s = avctx->priv_data;
|
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);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,8 +457,8 @@ static int vmdvideo_decode_frame(AVCodecContext *avctx,
|
|||||||
memcpy(frame->data[1], s->palette, PALETTE_COUNT * 4);
|
memcpy(frame->data[1], s->palette, PALETTE_COUNT * 4);
|
||||||
|
|
||||||
/* shuffle frames */
|
/* shuffle frames */
|
||||||
av_frame_unref(&s->prev_frame);
|
av_frame_unref(s->prev_frame);
|
||||||
if ((ret = av_frame_ref(&s->prev_frame, frame)) < 0)
|
if ((ret = av_frame_ref(s->prev_frame, frame)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
*got_frame = 1;
|
*got_frame = 1;
|
||||||
@ -451,16 +467,6 @@ static int vmdvideo_decode_frame(AVCodecContext *avctx,
|
|||||||
return buf_size;
|
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
|
* Audio Decoder
|
||||||
|
Loading…
Reference in New Issue
Block a user