Commit b7462a39 authored by Anton Khirnov's avatar Anton Khirnov

jvdec: use the AVFrame API properly.

parent 2d2a92f7
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
typedef struct JvContext { typedef struct JvContext {
DSPContext dsp; DSPContext dsp;
AVFrame frame; AVFrame *frame;
uint32_t palette[AVPALETTE_COUNT]; uint32_t palette[AVPALETTE_COUNT];
int palette_has_changed; int palette_has_changed;
} JvContext; } JvContext;
...@@ -41,6 +41,11 @@ typedef struct JvContext { ...@@ -41,6 +41,11 @@ typedef struct JvContext {
static av_cold int decode_init(AVCodecContext *avctx) static av_cold int decode_init(AVCodecContext *avctx)
{ {
JvContext *s = avctx->priv_data; JvContext *s = avctx->priv_data;
s->frame = av_frame_alloc();
if (!s->frame)
return AVERROR(ENOMEM);
avctx->pix_fmt = AV_PIX_FMT_PAL8; avctx->pix_fmt = AV_PIX_FMT_PAL8;
ff_dsputil_init(&s->dsp, avctx); ff_dsputil_init(&s->dsp, avctx);
return 0; return 0;
...@@ -144,7 +149,7 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -144,7 +149,7 @@ static int decode_frame(AVCodecContext *avctx,
buf += 5; buf += 5;
if (video_size) { if (video_size) {
if ((ret = ff_reget_buffer(avctx, &s->frame)) < 0) { if ((ret = ff_reget_buffer(avctx, s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret; return ret;
} }
...@@ -155,15 +160,15 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -155,15 +160,15 @@ static int decode_frame(AVCodecContext *avctx,
for (j = 0; j < avctx->height; j += 8) for (j = 0; j < avctx->height; j += 8)
for (i = 0; i < avctx->width; i += 8) for (i = 0; i < avctx->width; i += 8)
decode8x8(&gb, s->frame.data[0] + j*s->frame.linesize[0] + i, decode8x8(&gb, s->frame->data[0] + j*s->frame->linesize[0] + i,
s->frame.linesize[0], &s->dsp); s->frame->linesize[0], &s->dsp);
buf += video_size; buf += video_size;
} else if (video_type == 2) { } else if (video_type == 2) {
if (buf + 1 <= buf_end) { if (buf + 1 <= buf_end) {
int v = *buf++; int v = *buf++;
for (j = 0; j < avctx->height; j++) for (j = 0; j < avctx->height; j++)
memset(s->frame.data[0] + j*s->frame.linesize[0], v, avctx->width); memset(s->frame->data[0] + j*s->frame->linesize[0], v, avctx->width);
} }
} else { } else {
av_log(avctx, AV_LOG_WARNING, "unsupported frame type %i\n", video_type); av_log(avctx, AV_LOG_WARNING, "unsupported frame type %i\n", video_type);
...@@ -180,13 +185,13 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -180,13 +185,13 @@ static int decode_frame(AVCodecContext *avctx,
} }
if (video_size) { if (video_size) {
s->frame.key_frame = 1; s->frame->key_frame = 1;
s->frame.pict_type = AV_PICTURE_TYPE_I; s->frame->pict_type = AV_PICTURE_TYPE_I;
s->frame.palette_has_changed = s->palette_has_changed; s->frame->palette_has_changed = s->palette_has_changed;
s->palette_has_changed = 0; s->palette_has_changed = 0;
memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE); memcpy(s->frame->data[1], s->palette, AVPALETTE_SIZE);
if ((ret = av_frame_ref(data, &s->frame)) < 0) if ((ret = av_frame_ref(data, s->frame)) < 0)
return ret; return ret;
*got_frame = 1; *got_frame = 1;
} }
...@@ -198,7 +203,7 @@ static av_cold int decode_close(AVCodecContext *avctx) ...@@ -198,7 +203,7 @@ static av_cold int decode_close(AVCodecContext *avctx)
{ {
JvContext *s = avctx->priv_data; JvContext *s = avctx->priv_data;
av_frame_unref(&s->frame); av_frame_free(&s->frame);
return 0; return 0;
} }
......
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