Commit 1c11ab82 authored by Paul B Mahol's avatar Paul B Mahol

paf_video: make code independent of sizeof(AVFrame)

Signed-off-by: 's avatarPaul B Mahol <onemda@gmail.com>
parent 66e9716a
...@@ -48,7 +48,7 @@ static const uint8_t block_sequences[16][8] = ...@@ -48,7 +48,7 @@ static const uint8_t block_sequences[16][8] =
}; };
typedef struct PAFVideoDecContext { typedef struct PAFVideoDecContext {
AVFrame pic; AVFrame *pic;
GetByteContext gb; GetByteContext gb;
int current_frame; int current_frame;
...@@ -59,6 +59,19 @@ typedef struct PAFVideoDecContext { ...@@ -59,6 +59,19 @@ typedef struct PAFVideoDecContext {
uint8_t *opcodes; uint8_t *opcodes;
} PAFVideoDecContext; } PAFVideoDecContext;
static av_cold int paf_vid_close(AVCodecContext *avctx)
{
PAFVideoDecContext *c = avctx->priv_data;
int i;
av_frame_free(&c->pic);
for (i = 0; i < 4; i++)
av_freep(&c->frame[i]);
return 0;
}
static av_cold int paf_vid_init(AVCodecContext *avctx) static av_cold int paf_vid_init(AVCodecContext *avctx)
{ {
PAFVideoDecContext *c = avctx->priv_data; PAFVideoDecContext *c = avctx->priv_data;
...@@ -71,14 +84,19 @@ static av_cold int paf_vid_init(AVCodecContext *avctx) ...@@ -71,14 +84,19 @@ static av_cold int paf_vid_init(AVCodecContext *avctx)
avctx->pix_fmt = AV_PIX_FMT_PAL8; avctx->pix_fmt = AV_PIX_FMT_PAL8;
avcodec_get_frame_defaults(&c->pic); c->pic = av_frame_alloc();
if (!c->pic)
return AVERROR(ENOMEM);
c->frame_size = FFALIGN(avctx->height, 256) * avctx->width; c->frame_size = FFALIGN(avctx->height, 256) * avctx->width;
c->video_size = avctx->height * avctx->width; c->video_size = avctx->height * avctx->width;
for (i = 0; i < 4; i++) { for (i = 0; i < 4; i++) {
c->frame[i] = av_mallocz(c->frame_size); c->frame[i] = av_mallocz(c->frame_size);
if (!c->frame[i]) if (!c->frame[i]) {
paf_vid_close(avctx);
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
} }
}
return 0; return 0;
} }
...@@ -251,7 +269,7 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data, ...@@ -251,7 +269,7 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data,
uint8_t code, *dst, *src, *end; uint8_t code, *dst, *src, *end;
int i, frame, ret; int i, frame, ret;
if ((ret =ff_reget_buffer(avctx, &c->pic)) < 0) if ((ret = ff_reget_buffer(avctx, c->pic)) < 0)
return ret; return ret;
bytestream2_init(&c->gb, pkt->data, pkt->size); bytestream2_init(&c->gb, pkt->data, pkt->size);
...@@ -261,17 +279,17 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data, ...@@ -261,17 +279,17 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data,
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
memset(c->frame[i], 0, c->frame_size); memset(c->frame[i], 0, c->frame_size);
memset(c->pic.data[1], 0, AVPALETTE_SIZE); memset(c->pic->data[1], 0, AVPALETTE_SIZE);
c->current_frame = 0; c->current_frame = 0;
c->pic.key_frame = 1; c->pic->key_frame = 1;
c->pic.pict_type = AV_PICTURE_TYPE_I; c->pic->pict_type = AV_PICTURE_TYPE_I;
} else { } else {
c->pic.key_frame = 0; c->pic->key_frame = 0;
c->pic.pict_type = AV_PICTURE_TYPE_P; c->pic->pict_type = AV_PICTURE_TYPE_P;
} }
if (code & 0x40) { if (code & 0x40) {
uint32_t *out = (uint32_t *)c->pic.data[1]; uint32_t *out = (uint32_t *)c->pic->data[1];
int index, count; int index, count;
index = bytestream2_get_byte(&c->gb); index = bytestream2_get_byte(&c->gb);
...@@ -294,7 +312,7 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data, ...@@ -294,7 +312,7 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data,
b = b << 2 | b >> 4; b = b << 2 | b >> 4;
*out++ = 0xFFU << 24 | r << 16 | g << 8 | b; *out++ = 0xFFU << 24 | r << 16 | g << 8 | b;
} }
c->pic.palette_has_changed = 1; c->pic->palette_has_changed = 1;
} }
switch (code & 0x0F) { switch (code & 0x0F) {
...@@ -346,16 +364,16 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data, ...@@ -346,16 +364,16 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data,
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
dst = c->pic.data[0]; dst = c->pic->data[0];
src = c->frame[c->current_frame]; src = c->frame[c->current_frame];
for (i = 0; i < avctx->height; i++) { for (i = 0; i < avctx->height; i++) {
memcpy(dst, src, avctx->width); memcpy(dst, src, avctx->width);
dst += c->pic.linesize[0]; dst += c->pic->linesize[0];
src += avctx->width; src += avctx->width;
} }
c->current_frame = (c->current_frame + 1) & 3; c->current_frame = (c->current_frame + 1) & 3;
if ((ret = av_frame_ref(data, &c->pic)) < 0) if ((ret = av_frame_ref(data, c->pic)) < 0)
return ret; return ret;
*got_frame = 1; *got_frame = 1;
...@@ -363,19 +381,6 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data, ...@@ -363,19 +381,6 @@ static int paf_vid_decode(AVCodecContext *avctx, void *data,
return pkt->size; return pkt->size;
} }
static av_cold int paf_vid_close(AVCodecContext *avctx)
{
PAFVideoDecContext *c = avctx->priv_data;
int i;
av_frame_unref(&c->pic);
for (i = 0; i < 4; i++)
av_freep(&c->frame[i]);
return 0;
}
static av_cold int paf_aud_init(AVCodecContext *avctx) static av_cold int paf_aud_init(AVCodecContext *avctx)
{ {
if (avctx->channels != 2) { if (avctx->channels != 2) {
......
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