X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Favs.c;h=53e3320424ee122c90b6244dce72ba55a6040b6d;hb=369380e1c4c6fc9b0d9ff04ec23d46b252ba7110;hp=12fb3976d582088cf0bf97fefc955f66cdecbaf4;hpb=ec6402b7c595c3ceed6d1b8c1b75c6aa8336e052;p=ffmpeg diff --git a/libavcodec/avs.c b/libavcodec/avs.c index 12fb3976d58..53e3320424e 100644 --- a/libavcodec/avs.c +++ b/libavcodec/avs.c @@ -21,10 +21,11 @@ #include "avcodec.h" #include "get_bits.h" +#include "internal.h" typedef struct { - AVFrame picture; + AVFrame *frame; } AvsContext; typedef enum { @@ -44,41 +45,45 @@ typedef enum { static int avs_decode_frame(AVCodecContext * avctx, - void *data, int *data_size, AVPacket *avpkt) + void *data, int *got_frame, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; + const uint8_t *buf_end = avpkt->data + avpkt->size; int buf_size = avpkt->size; AvsContext *const avs = avctx->priv_data; AVFrame *picture = data; - AVFrame *const p = (AVFrame *) & avs->picture; + AVFrame *const p = avs->frame; const uint8_t *table, *vect; uint8_t *out; - int i, j, x, y, stride, vect_w = 3, vect_h = 3; + int i, j, x, y, stride, ret, vect_w = 3, vect_h = 3; AvsVideoSubType sub_type; AvsBlockType type; GetBitContext change_map; - if (avctx->reget_buffer(avctx, p)) { + if ((ret = ff_reget_buffer(avctx, p)) < 0) { av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); - return -1; + return ret; } - p->reference = 1; p->pict_type = AV_PICTURE_TYPE_P; p->key_frame = 0; - out = avs->picture.data[0]; - stride = avs->picture.linesize[0]; + out = p->data[0]; + stride = p->linesize[0]; + if (buf_end - buf < 4) + return AVERROR_INVALIDDATA; sub_type = buf[0]; type = buf[1]; buf += 4; if (type == AVS_PALETTE) { int first, last; - uint32_t *pal = (uint32_t *) avs->picture.data[1]; + uint32_t *pal = (uint32_t *) p->data[1]; first = AV_RL16(buf); last = first + AV_RL16(buf + 2); + if (first >= 256 || last > 256 || buf_end - buf < 4 + 4 + 3 * (last - first)) + return AVERROR_INVALIDDATA; buf += 4; for (i=first; ipicture; - *data_size = sizeof(AVPicture); + if ((ret = av_frame_ref(picture, p)) < 0) + return ret; + *got_frame = 1; return buf_size; } static av_cold int avs_decode_init(AVCodecContext * avctx) { - avctx->pix_fmt = PIX_FMT_PAL8; + AvsContext *s = avctx->priv_data; + + s->frame = av_frame_alloc(); + if (!s->frame) + return AVERROR(ENOMEM); + + avctx->pix_fmt = AV_PIX_FMT_PAL8; + ff_set_dimensions(avctx, 318, 198); + + return 0; +} + +static av_cold int avs_decode_end(AVCodecContext *avctx) +{ + AvsContext *s = avctx->priv_data; + av_frame_free(&s->frame); return 0; } + AVCodec ff_avs_decoder = { .name = "avs", + .long_name = NULL_IF_CONFIG_SMALL("AVS (Audio Video Standard) video"), .type = AVMEDIA_TYPE_VIDEO, - .id = CODEC_ID_AVS, + .id = AV_CODEC_ID_AVS, .priv_data_size = sizeof(AvsContext), .init = avs_decode_init, .decode = avs_decode_frame, + .close = avs_decode_end, .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("AVS (Audio Video Standard) video"), };