diff options
| author | Tim Redfern <tim@eclectronics.org> | 2013-12-29 12:19:38 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2013-12-29 12:19:38 +0000 |
| commit | f7813a5324be39d13ab536c245d15dfc602a7849 (patch) | |
| tree | fad99148b88823d34a5df2f0a25881a002eb291b /ffmpeg/libavcodec/eatgv.c | |
| parent | b7a5a477b8ff4d4e3028b9dfb9a9df0a41463f92 (diff) | |
basic type mechanism working
Diffstat (limited to 'ffmpeg/libavcodec/eatgv.c')
| -rw-r--r-- | ffmpeg/libavcodec/eatgv.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/ffmpeg/libavcodec/eatgv.c b/ffmpeg/libavcodec/eatgv.c index 54074b3..f204a13 100644 --- a/ffmpeg/libavcodec/eatgv.c +++ b/ffmpeg/libavcodec/eatgv.c @@ -40,7 +40,7 @@ typedef struct TgvContext { AVCodecContext *avctx; - AVFrame last_frame; + AVFrame *last_frame; uint8_t *frame_buffer; int width,height; uint32_t palette[AVPALETTE_COUNT]; @@ -57,7 +57,11 @@ static av_cold int tgv_decode_init(AVCodecContext *avctx) s->avctx = avctx; avctx->time_base = (AVRational){1, 15}; avctx->pix_fmt = AV_PIX_FMT_PAL8; - avcodec_get_frame_defaults(&s->last_frame); + + s->last_frame = av_frame_alloc(); + if (!s->last_frame) + return AVERROR(ENOMEM); + return 0; } @@ -169,12 +173,19 @@ static int tgv_decode_inter(TgvContext *s, AVFrame *frame, /* allocate codebook buffers as necessary */ if (num_mvs > s->num_mvs) { - s->mv_codebook = av_realloc(s->mv_codebook, num_mvs*2*sizeof(int)); + if (av_reallocp_array(&s->mv_codebook, num_mvs, sizeof(*s->mv_codebook))) { + s->num_mvs = 0; + return AVERROR(ENOMEM); + } 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; } @@ -226,8 +237,8 @@ static int tgv_decode_inter(TgvContext *s, AVFrame *frame, 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) @@ -275,9 +286,10 @@ static int tgv_decode_frame(AVCodecContext *avctx, 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]); @@ -288,9 +300,6 @@ static int tgv_decode_frame(AVCodecContext *avctx, } } - 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; @@ -302,7 +311,7 @@ static int tgv_decode_frame(AVCodecContext *avctx, frame->pict_type = AV_PICTURE_TYPE_I; if (!s->frame_buffer && - !(s->frame_buffer = av_malloc(s->width * s->height))) + !(s->frame_buffer = av_mallocz(s->width * s->height))) return AVERROR(ENOMEM); if (unpack(buf, buf_end, s->frame_buffer, s->avctx->width, s->avctx->height) < 0) { @@ -314,7 +323,7 @@ static int tgv_decode_frame(AVCodecContext *avctx, 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; } @@ -326,8 +335,8 @@ static int tgv_decode_frame(AVCodecContext *avctx, } } - 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; @@ -338,7 +347,7 @@ static int tgv_decode_frame(AVCodecContext *avctx, 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); @@ -347,12 +356,12 @@ static av_cold int tgv_decode_end(AVCodecContext *avctx) 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, }; |
