*/
typedef struct KmvcContext {
AVCodecContext *avctx;
- AVFrame pic;
int setpal;
int palsize;
AVPacket *avpkt)
{
KmvcContext *const ctx = avctx->priv_data;
+ AVFrame *frame = data;
uint8_t *out, *src;
- int i;
+ int i, ret;
int header;
int blocksize;
const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL);
bytestream2_init(&ctx->g, avpkt->data, avpkt->size);
- if (ctx->pic.data[0])
- avctx->release_buffer(avctx, &ctx->pic);
- ctx->pic.reference = 1;
- ctx->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
- if (ff_get_buffer(avctx, &ctx->pic) < 0) {
+ if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
+ return ret;
}
header = bytestream2_get_byte(&ctx->g);
}
if (header & KMVC_KEYFRAME) {
- ctx->pic.key_frame = 1;
- ctx->pic.pict_type = AV_PICTURE_TYPE_I;
+ frame->key_frame = 1;
+ frame->pict_type = AV_PICTURE_TYPE_I;
} else {
- ctx->pic.key_frame = 0;
- ctx->pic.pict_type = AV_PICTURE_TYPE_P;
+ frame->key_frame = 0;
+ frame->pict_type = AV_PICTURE_TYPE_P;
}
if (header & KMVC_PALETTE) {
- ctx->pic.palette_has_changed = 1;
+ frame->palette_has_changed = 1;
// palette starts from index 1 and has 127 entries
for (i = 1; i <= ctx->palsize; i++) {
ctx->pal[i] = bytestream2_get_be24(&ctx->g);
}
if (pal) {
- ctx->pic.palette_has_changed = 1;
+ frame->palette_has_changed = 1;
memcpy(ctx->pal, pal, AVPALETTE_SIZE);
}
if (ctx->setpal) {
ctx->setpal = 0;
- ctx->pic.palette_has_changed = 1;
+ frame->palette_has_changed = 1;
}
/* make the palette available on the way out */
- memcpy(ctx->pic.data[1], ctx->pal, 1024);
+ memcpy(frame->data[1], ctx->pal, 1024);
blocksize = bytestream2_get_byte(&ctx->g);
if (blocksize != 8 && blocksize != 127) {
av_log(avctx, AV_LOG_ERROR, "Block size = %i\n", blocksize);
- return -1;
+ return AVERROR_INVALIDDATA;
}
memset(ctx->cur, 0, 320 * 200);
switch (header & KMVC_METHOD) {
break;
default:
av_log(avctx, AV_LOG_ERROR, "Unknown compression method %i\n", header & KMVC_METHOD);
- return -1;
+ return AVERROR_INVALIDDATA;
}
- out = ctx->pic.data[0];
+ out = frame->data[0];
src = ctx->cur;
for (i = 0; i < avctx->height; i++) {
memcpy(out, src, avctx->width);
src += 320;
- out += ctx->pic.linesize[0];
+ out += frame->linesize[0];
}
/* flip buffers */
}
*got_frame = 1;
- *(AVFrame *) data = ctx->pic;
/* always report that the buffer was completely consumed */
return avpkt->size;
if (avctx->width > 320 || avctx->height > 200) {
av_log(avctx, AV_LOG_ERROR, "KMVC supports frames <= 320x200\n");
- return -1;
+ return AVERROR(EINVAL);
}
c->frm0 = av_mallocz(320 * 200);
av_freep(&c->frm0);
av_freep(&c->frm1);
- if (c->pic.data[0])
- avctx->release_buffer(avctx, &c->pic);
return 0;
}