* http://wiki.multimedia.cx/index.php?title=Electronic_Arts_TGV
*/
-#include "avcodec.h"
+#include "libavutil/imgutils.h"
+#include "libavutil/mem.h"
+
#define BITSTREAM_READER_LE
+#include "avcodec.h"
#include "get_bits.h"
#include "internal.h"
-#include "libavutil/imgutils.h"
-#include "libavutil/mem.h"
#define EA_PREAMBLE_SIZE 8
#define kVGT_TAG MKTAG('k', 'V', 'G', 'T')
typedef struct TgvContext {
AVCodecContext *avctx;
- AVFrame last_frame;
+ AVFrame *last_frame;
uint8_t *frame_buffer;
int width,height;
uint32_t palette[AVPALETTE_COUNT];
{
TgvContext *s = avctx->priv_data;
s->avctx = avctx;
- avctx->time_base = (AVRational){1, 15};
+ avctx->framerate = (AVRational){ 15, 1 };
avctx->pix_fmt = AV_PIX_FMT_PAL8;
+
+ s->last_frame = av_frame_alloc();
+ if (!s->last_frame)
+ return AVERROR(ENOMEM);
+
return 0;
}
/* allocate codebook buffers as necessary */
if (num_mvs > s->num_mvs) {
- s->mv_codebook = av_realloc(s->mv_codebook, num_mvs*2*sizeof(int));
+ int err = av_reallocp(&s->mv_codebook, num_mvs * 2 * sizeof(int));
+ if (err < 0)
+ return err;
s->num_mvs = num_mvs;
}
if (num_blocks_packed > s->num_blocks_packed) {
- s->block_codebook = av_realloc(s->block_codebook, num_blocks_packed*16);
+ int err;
+ if ((err = av_reallocp(&s->block_codebook, num_blocks_packed * 16)) < 0) {
+ s->num_blocks_packed = 0;
+ return err;
+ }
s->num_blocks_packed = num_blocks_packed;
}
my < 0 || my + 4 > s->avctx->height)
continue;
- src = s->last_frame.data[0] + mx + my * s->last_frame.linesize[0];
- src_stride = s->last_frame.linesize[0];
+ src = s->last_frame->data[0] + mx + my * s->last_frame->linesize[0];
+ src_stride = s->last_frame->linesize[0];
} else {
int offset = vector - num_mvs;
if (offset < num_blocks_raw)
s->width = AV_RL16(&buf[0]);
s->height = AV_RL16(&buf[2]);
if (s->avctx->width != s->width || s->avctx->height != s->height) {
- avcodec_set_dimensions(s->avctx, s->width, s->height);
av_freep(&s->frame_buffer);
- av_frame_unref(&s->last_frame);
+ av_frame_unref(s->last_frame);
+ if ((ret = ff_set_dimensions(s->avctx, s->width, s->height)) < 0)
+ return ret;
}
pal_count = AV_RL16(&buf[6]);
}
}
- if ((ret = av_image_check_size(s->width, s->height, 0, avctx)) < 0)
- return ret;
-
if ((ret = ff_get_buffer(avctx, frame, AV_GET_BUFFER_FLAG_REF)) < 0)
return ret;
s->frame_buffer + y * s->width,
s->width);
} else {
- if (!s->last_frame.data[0]) {
+ if (!s->last_frame->data[0]) {
av_log(avctx, AV_LOG_WARNING, "inter frame without corresponding intra frame\n");
return buf_size;
}
}
}
- av_frame_unref(&s->last_frame);
- if ((ret = av_frame_ref(&s->last_frame, frame)) < 0)
+ av_frame_unref(s->last_frame);
+ if ((ret = av_frame_ref(s->last_frame, frame)) < 0)
return ret;
*got_frame = 1;
static av_cold int tgv_decode_end(AVCodecContext *avctx)
{
TgvContext *s = avctx->priv_data;
- av_frame_unref(&s->last_frame);
+ av_frame_free(&s->last_frame);
av_freep(&s->frame_buffer);
av_free(s->mv_codebook);
av_free(s->block_codebook);
AVCodec ff_eatgv_decoder = {
.name = "eatgv",
+ .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts TGV video"),
.type = AVMEDIA_TYPE_VIDEO,
.id = AV_CODEC_ID_TGV,
.priv_data_size = sizeof(TgvContext),
.init = tgv_decode_init,
.close = tgv_decode_end,
.decode = tgv_decode_frame,
- .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts TGV video"),
- .capabilities = CODEC_CAP_DR1,
+ .capabilities = AV_CODEC_CAP_DR1,
};