typedef struct FourXContext {
AVCodecContext *avctx;
DSPContext dsp;
- AVFrame current_picture, last_picture;
+ AVFrame *current_picture, *last_picture;
GetBitContext pre_gb; ///< ac/dc prefix
GetBitContext gb;
GetByteContext g;
for (i = 0; i < 256; i++) {
if (f->version > 1)
- f->mv[i] = mv[i][0] + mv[i][1] * f->current_picture.linesize[0] / 2;
+ f->mv[i] = mv[i][0] + mv[i][1] * f->current_picture->linesize[0] / 2;
else
- f->mv[i] = (i & 15) - 8 + ((i >> 4) - 8) * f->current_picture.linesize[0] / 2;
+ f->mv[i] = (i & 15) - 8 + ((i >> 4) - 8) * f->current_picture->linesize[0] / 2;
}
}
int code = get_vlc2(&f->gb,
block_type_vlc[1 - (f->version > 1)][index].table,
BLOCK_TYPE_VLC_BITS, 1);
- uint16_t *start = (uint16_t *)f->last_picture.data[0];
+ uint16_t *start = (uint16_t *)f->last_picture->data[0];
uint16_t *end = start + stride * (f->avctx->height - h + 1) - (1 << log2w);
av_assert2(code >= 0 && code <= 6);
int x, y;
const int width = f->avctx->width;
const int height = f->avctx->height;
- uint16_t *src = (uint16_t *)f->last_picture.data[0];
- uint16_t *dst = (uint16_t *)f->current_picture.data[0];
- const int stride = f->current_picture.linesize[0] >> 1;
+ uint16_t *src = (uint16_t *)f->last_picture->data[0];
+ uint16_t *dst = (uint16_t *)f->current_picture->data[0];
+ const int stride = f->current_picture->linesize[0] >> 1;
unsigned int bitstream_size, bytestream_size, wordstream_size, extra,
bytestream_offset, wordstream_offset;
extra > length - bytestream_size - bitstream_size - wordstream_size) {
av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", bitstream_size, bytestream_size, wordstream_size,
bitstream_size+ bytestream_size+ wordstream_size - length);
- return -1;
+ return AVERROR_INVALIDDATA;
}
av_fast_malloc(&f->bitstream_buffer, &f->bitstream_buffer_size,
static inline void idct_put(FourXContext *f, int x, int y)
{
DCTELEM (*block)[64] = f->block;
- int stride = f->current_picture.linesize[0] >> 1;
+ int stride = f->current_picture->linesize[0] >> 1;
int i;
- uint16_t *dst = ((uint16_t*)f->current_picture.data[0]) + y * stride + x;
+ uint16_t *dst = ((uint16_t*)f->current_picture->data[0]) + y * stride + x;
for (i = 0; i < 4; i++) {
block[i][0] += 0x80 * 8 * 8;
static int decode_i_mb(FourXContext *f)
{
+ int ret;
int i;
f->dsp.clear_blocks(f->block[0]);
for (i = 0; i < 6; i++)
- if (decode_i_block(f, f->block[i]) < 0)
- return -1;
+ if ((ret = decode_i_block(f, f->block[i])) < 0)
+ return ret;
return 0;
}
const int width = f->avctx->width;
const int height = f->avctx->height;
const int mbs = (FFALIGN(width, 16) >> 4) * (FFALIGN(height, 16) >> 4);
- uint16_t *dst = (uint16_t*)f->current_picture.data[0];
- const int stride = f->current_picture.linesize[0]>>1;
+ uint16_t *dst = (uint16_t*)f->current_picture->data[0];
+ const int stride = f->current_picture->linesize[0]>>1;
const uint8_t *buf_end = buf + length;
GetByteContext g3;
static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length)
{
- int x, y;
+ int x, y, ret;
const int width = f->avctx->width;
const int height = f->avctx->height;
const unsigned int bitstream_size = AV_RL32(buf);
|| prestream_size > (1 << 26)) {
av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d %d\n",
prestream_size, bitstream_size, length);
- return -1;
+ return AVERROR_INVALIDDATA;
}
prestream = read_huffman_tables(f, prestream, buf + length - prestream);
for (y = 0; y < height; y += 16) {
for (x = 0; x < width; x += 16) {
- if (decode_i_mb(f) < 0)
- return -1;
+ if ((ret = decode_i_mb(f)) < 0)
+ return ret;
idct_put(f, x, y);
}
int buf_size = avpkt->size;
FourXContext *const f = avctx->priv_data;
AVFrame *picture = data;
- AVFrame *p, temp;
- int i, frame_4cc, frame_size;
+ AVFrame *p;
+ int i, frame_4cc, frame_size, ret;
if (buf_size < 12)
return AVERROR_INVALIDDATA;
// explicit check needed as memcpy below might not catch a NULL
if (!cfrm->data) {
av_log(f->avctx, AV_LOG_ERROR, "realloc failure\n");
- return -1;
+ return AVERROR(ENOMEM);
}
memcpy(cfrm->data + cfrm->size, buf + 20, data_size);
frame_size = buf_size - 12;
}
- temp = f->current_picture;
- f->current_picture = f->last_picture;
- f->last_picture = temp;
+ FFSWAP(AVFrame*, f->current_picture, f->last_picture);
- p = &f->current_picture;
+ p = f->current_picture;
avctx->coded_frame = p;
// alternatively we would have to use our own buffer management
avctx->flags |= CODEC_FLAG_EMU_EDGE;
p->reference= 3;
- if (avctx->reget_buffer(avctx, p) < 0) {
+ if ((ret = avctx->reget_buffer(avctx, p)) < 0) {
av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
- return -1;
+ return ret;
}
if (frame_4cc == AV_RL32("ifr2")) {
p->pict_type= AV_PICTURE_TYPE_I;
- if (decode_i2_frame(f, buf - 4, frame_size + 4) < 0) {
+ if ((ret = decode_i2_frame(f, buf - 4, frame_size + 4)) < 0) {
av_log(f->avctx, AV_LOG_ERROR, "decode i2 frame failed\n");
- return -1;
+ return ret;
}
} else if (frame_4cc == AV_RL32("ifrm")) {
p->pict_type= AV_PICTURE_TYPE_I;
- if (decode_i_frame(f, buf, frame_size) < 0) {
+ if ((ret = decode_i_frame(f, buf, frame_size)) < 0) {
av_log(f->avctx, AV_LOG_ERROR, "decode i frame failed\n");
- return -1;
+ return ret;
}
} else if (frame_4cc == AV_RL32("pfrm") || frame_4cc == AV_RL32("pfr2")) {
- if (!f->last_picture.data[0]) {
- f->last_picture.reference = 3;
- if (ff_get_buffer(avctx, &f->last_picture) < 0) {
+ if (!f->last_picture->data[0]) {
+ f->last_picture->reference = 3;
+ if ((ret = ff_get_buffer(avctx, f->last_picture)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
- return -1;
+ return ret;
}
for (i=0; i<avctx->height; i++)
- memset(f->last_picture.data[0] + i*f->last_picture.linesize[0], 0, 2*avctx->width);
+ memset(f->last_picture->data[0] + i*f->last_picture->linesize[0], 0, 2*avctx->width);
}
p->pict_type = AV_PICTURE_TYPE_P;
- if (decode_p_frame(f, buf, frame_size) < 0) {
+ if ((ret = decode_p_frame(f, buf, frame_size)) < 0) {
av_log(f->avctx, AV_LOG_ERROR, "decode p frame failed\n");
- return -1;
+ return ret;
}
} else if (frame_4cc == AV_RL32("snd_")) {
av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n",
return buf_size;
}
-
-static av_cold void common_init(AVCodecContext *avctx)
-{
- FourXContext * const f = avctx->priv_data;
-
- ff_dsputil_init(&f->dsp, avctx);
-
- f->avctx = avctx;
-}
-
static av_cold int decode_init(AVCodecContext *avctx)
{
FourXContext * const f = avctx->priv_data;
avcodec_get_frame_defaults(&f->current_picture);
avcodec_get_frame_defaults(&f->last_picture);
f->version = AV_RL32(avctx->extradata) >> 16;
- common_init(avctx);
+ ff_dsputil_init(&f->dsp, avctx);
+ f->avctx = avctx;
init_vlcs(f);
if (f->version > 2)
else
avctx->pix_fmt = AV_PIX_FMT_BGR555;
+ f->current_picture = avcodec_alloc_frame();
+ f->last_picture = avcodec_alloc_frame();
+ if (!f->current_picture || !f->last_picture) {
+ avcodec_free_frame(&f->current_picture);
+ avcodec_free_frame(&f->last_picture);
+ return AVERROR(ENOMEM);
+ }
+
return 0;
}
f->cfrm[i].allocated_size = 0;
}
ff_free_vlc(&f->pre_vlc);
- if (f->current_picture.data[0])
- avctx->release_buffer(avctx, &f->current_picture);
- if (f->last_picture.data[0])
- avctx->release_buffer(avctx, &f->last_picture);
+ if (f->current_picture->data[0])
+ avctx->release_buffer(avctx, f->current_picture);
+ if (f->last_picture->data[0])
+ avctx->release_buffer(avctx, f->last_picture);
+ avcodec_free_frame(&f->current_picture);
+ avcodec_free_frame(&f->last_picture);
return 0;
}