flicvideo: use the AVFrame API properly.

This commit is contained in:
Anton Khirnov 2013-11-09 10:14:46 +01:00
parent 84099f51f3
commit d100f9e7cd
1 changed files with 32 additions and 29 deletions

View File

@ -71,7 +71,7 @@
typedef struct FlicDecodeContext { typedef struct FlicDecodeContext {
AVCodecContext *avctx; AVCodecContext *avctx;
AVFrame frame; AVFrame *frame;
unsigned int palette[256]; unsigned int palette[256];
int new_palette; int new_palette;
@ -123,7 +123,10 @@ static av_cold int flic_decode_init(AVCodecContext *avctx)
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
avcodec_get_frame_defaults(&s->frame); s->frame = av_frame_alloc();
if (!s->frame)
return AVERROR(ENOMEM);
s->new_palette = 0; s->new_palette = 0;
return 0; return 0;
@ -168,13 +171,13 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
bytestream2_init(&g2, buf, buf_size); bytestream2_init(&g2, buf, buf_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, "reget_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return ret; return ret;
} }
pixels = s->frame.data[0]; pixels = s->frame->data[0];
pixel_limit = s->avctx->height * s->frame.linesize[0]; pixel_limit = s->avctx->height * s->frame->linesize[0];
frame_size = bytestream2_get_le32(&g2); frame_size = bytestream2_get_le32(&g2);
bytestream2_skip(&g2, 2); /* skip the magic number */ bytestream2_skip(&g2, 2); /* skip the magic number */
num_chunks = bytestream2_get_le16(&g2); num_chunks = bytestream2_get_le16(&g2);
@ -248,12 +251,12 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
if ((line_packets & 0xC000) == 0xC000) { if ((line_packets & 0xC000) == 0xC000) {
// line skip opcode // line skip opcode
line_packets = -line_packets; line_packets = -line_packets;
y_ptr += line_packets * s->frame.linesize[0]; y_ptr += line_packets * s->frame->linesize[0];
} else if ((line_packets & 0xC000) == 0x4000) { } else if ((line_packets & 0xC000) == 0x4000) {
av_log(avctx, AV_LOG_ERROR, "Undefined opcode (%x) in DELTA_FLI\n", line_packets); av_log(avctx, AV_LOG_ERROR, "Undefined opcode (%x) in DELTA_FLI\n", line_packets);
} else if ((line_packets & 0xC000) == 0x8000) { } else if ((line_packets & 0xC000) == 0x8000) {
// "last byte" opcode // "last byte" opcode
pixel_ptr= y_ptr + s->frame.linesize[0] - 1; pixel_ptr= y_ptr + s->frame->linesize[0] - 1;
CHECK_PIXEL_PTR(0); CHECK_PIXEL_PTR(0);
pixels[pixel_ptr] = line_packets & 0xff; pixels[pixel_ptr] = line_packets & 0xff;
} else { } else {
@ -284,7 +287,7 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
} }
} }
y_ptr += s->frame.linesize[0]; y_ptr += s->frame->linesize[0];
} }
} }
break; break;
@ -293,7 +296,7 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
/* line compressed */ /* line compressed */
starting_line = bytestream2_get_le16(&g2); starting_line = bytestream2_get_le16(&g2);
y_ptr = 0; y_ptr = 0;
y_ptr += starting_line * s->frame.linesize[0]; y_ptr += starting_line * s->frame->linesize[0];
compressed_lines = bytestream2_get_le16(&g2); compressed_lines = bytestream2_get_le16(&g2);
while (compressed_lines > 0) { while (compressed_lines > 0) {
@ -324,7 +327,7 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
} }
} }
y_ptr += s->frame.linesize[0]; y_ptr += s->frame->linesize[0];
compressed_lines--; compressed_lines--;
} }
break; break;
@ -332,7 +335,7 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
case FLI_BLACK: case FLI_BLACK:
/* set the whole frame to color 0 (which is usually black) */ /* set the whole frame to color 0 (which is usually black) */
memset(pixels, 0, memset(pixels, 0,
s->frame.linesize[0] * s->avctx->height); s->frame->linesize[0] * s->avctx->height);
break; break;
case FLI_BRUN: case FLI_BRUN:
@ -375,7 +378,7 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
} }
} }
y_ptr += s->frame.linesize[0]; y_ptr += s->frame->linesize[0];
} }
break; break;
@ -386,8 +389,8 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
"bigger than image, skipping chunk\n", chunk_size - 6); "bigger than image, skipping chunk\n", chunk_size - 6);
bytestream2_skip(&g2, chunk_size - 6); bytestream2_skip(&g2, chunk_size - 6);
} else { } else {
for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height; for (y_ptr = 0; y_ptr < s->frame->linesize[0] * s->avctx->height;
y_ptr += s->frame.linesize[0]) { y_ptr += s->frame->linesize[0]) {
bytestream2_get_buffer(&g2, &pixels[y_ptr], bytestream2_get_buffer(&g2, &pixels[y_ptr],
s->avctx->width); s->avctx->width);
} }
@ -417,13 +420,13 @@ static int flic_decode_frame_8BPP(AVCodecContext *avctx,
buf_size - bytestream2_get_bytes_left(&g2)); buf_size - bytestream2_get_bytes_left(&g2));
/* make the palette available on the way out */ /* make the palette available on the way out */
memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE); memcpy(s->frame->data[1], s->palette, AVPALETTE_SIZE);
if (s->new_palette) { if (s->new_palette) {
s->frame.palette_has_changed = 1; s->frame->palette_has_changed = 1;
s->new_palette = 0; s->new_palette = 0;
} }
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;
@ -464,13 +467,13 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
bytestream2_init(&g2, buf, buf_size); bytestream2_init(&g2, buf, buf_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, "reget_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
return ret; return ret;
} }
pixels = s->frame.data[0]; pixels = s->frame->data[0];
pixel_limit = s->avctx->height * s->frame.linesize[0]; pixel_limit = s->avctx->height * s->frame->linesize[0];
frame_size = bytestream2_get_le32(&g2); frame_size = bytestream2_get_le32(&g2);
bytestream2_skip(&g2, 2); /* skip the magic number */ bytestream2_skip(&g2, 2); /* skip the magic number */
@ -504,7 +507,7 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
line_packets = bytestream2_get_le16(&g2); line_packets = bytestream2_get_le16(&g2);
if (line_packets < 0) { if (line_packets < 0) {
line_packets = -line_packets; line_packets = -line_packets;
y_ptr += line_packets * s->frame.linesize[0]; y_ptr += line_packets * s->frame->linesize[0];
} else { } else {
compressed_lines--; compressed_lines--;
pixel_ptr = y_ptr; pixel_ptr = y_ptr;
@ -533,7 +536,7 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
} }
} }
y_ptr += s->frame.linesize[0]; y_ptr += s->frame->linesize[0];
} }
} }
break; break;
@ -546,7 +549,7 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
case FLI_BLACK: case FLI_BLACK:
/* set the whole frame to 0x0000 which is black in both 15Bpp and 16Bpp modes. */ /* set the whole frame to 0x0000 which is black in both 15Bpp and 16Bpp modes. */
memset(pixels, 0x0000, memset(pixels, 0x0000,
s->frame.linesize[0] * s->avctx->height); s->frame->linesize[0] * s->avctx->height);
break; break;
case FLI_BRUN: case FLI_BRUN:
@ -597,7 +600,7 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
pixel_ptr += 2; pixel_ptr += 2;
} }
#endif #endif
y_ptr += s->frame.linesize[0]; y_ptr += s->frame->linesize[0];
} }
break; break;
@ -637,7 +640,7 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
} }
} }
y_ptr += s->frame.linesize[0]; y_ptr += s->frame->linesize[0];
} }
break; break;
@ -650,8 +653,8 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
bytestream2_skip(&g2, chunk_size - 6); bytestream2_skip(&g2, chunk_size - 6);
} else { } else {
for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height; for (y_ptr = 0; y_ptr < s->frame->linesize[0] * s->avctx->height;
y_ptr += s->frame.linesize[0]) { y_ptr += s->frame->linesize[0]) {
pixel_countdown = s->avctx->width; pixel_countdown = s->avctx->width;
pixel_ptr = 0; pixel_ptr = 0;
@ -684,7 +687,7 @@ static int flic_decode_frame_15_16BPP(AVCodecContext *avctx,
av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \ av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \
"and final chunk ptr = %d\n", buf_size, bytestream2_tell(&g2)); "and final chunk ptr = %d\n", buf_size, bytestream2_tell(&g2));
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;
@ -733,7 +736,7 @@ static av_cold int flic_decode_end(AVCodecContext *avctx)
{ {
FlicDecodeContext *s = avctx->priv_data; FlicDecodeContext *s = avctx->priv_data;
av_frame_unref(&s->frame); av_frame_free(&s->frame);
return 0; return 0;
} }