X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Findeo2.c;h=57213082675273c73e6119ecfcffa4220c3d688b;hb=339af976b6fd9c05d1e75e75a5323efdb3d6afa1;hp=4971b84308f850a248792cb13507392f51d3cf6e;hpb=ff44c2d4f483cda53859ce019f3815c69239a7e0;p=ffmpeg diff --git a/libavcodec/indeo2.c b/libavcodec/indeo2.c index 4971b84308f..57213082675 100644 --- a/libavcodec/indeo2.c +++ b/libavcodec/indeo2.c @@ -25,6 +25,7 @@ */ #include "libavutil/attributes.h" +#include "libavutil/thread.h" #define BITSTREAM_READER_LE #include "avcodec.h" @@ -46,7 +47,7 @@ static VLC ir2_vlc; /* Indeo 2 codes are in range 0x01..0x7F and 0x81..0x90 */ static inline int ir2_get_code(GetBitContext *gb) { - return get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1) + 1; + return get_vlc2(gb, ir2_vlc.table, CODE_VLC_BITS, 1); } static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst, @@ -56,7 +57,7 @@ static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst int j; int out = 0; - if (width & 1) + if ((width & 1) || width * height / (2*(IR2_CODES - 0x7F)) > get_bits_left(&ctx->gb)) return AVERROR_INVALIDDATA; /* first line contain absolute values, other lines contain deltas */ @@ -79,10 +80,11 @@ static int ir2_decode_plane(Ir2Context *ctx, int width, int height, uint8_t *dst for (j = 1; j < height; j++) { out = 0; - if (get_bits_left(&ctx->gb) <= 0) - return AVERROR_INVALIDDATA; while (out < width) { - int c = ir2_get_code(&ctx->gb); + int c; + if (get_bits_left(&ctx->gb) <= 0) + return AVERROR_INVALIDDATA; + c = ir2_get_code(&ctx->gb); if (c >= 0x80) { /* we have a skip */ c -= 0x7F; if (out + c*2 > width) @@ -123,9 +125,9 @@ static int ir2_decode_plane_inter(Ir2Context *ctx, int width, int height, uint8_ for (j = 0; j < height; j++) { out = 0; - if (get_bits_left(&ctx->gb) <= 0) - return AVERROR_INVALIDDATA; while (out < width) { + if (get_bits_left(&ctx->gb) <= 0) + return AVERROR_INVALIDDATA; c = ir2_get_code(&ctx->gb); if (c >= 0x80) { /* we have a skip */ c -= 0x7F; @@ -160,7 +162,7 @@ static int ir2_decode_frame(AVCodecContext *avctx, int start, ret; int ltab, ctab; - if ((ret = ff_reget_buffer(avctx, p)) < 0) + if ((ret = ff_reget_buffer(avctx, p, 0)) < 0) return ret; start = 48; /* hardcoded for now */ @@ -173,10 +175,6 @@ static int ir2_decode_frame(AVCodecContext *avctx, s->decode_delta = buf[18]; /* decide whether frame uses deltas or not */ -#ifndef BITSTREAM_READER_LE - for (i = 0; i < buf_size; i++) - buf[i] = ff_reverse[buf[i]]; -#endif if ((ret = init_get_bits8(&s->gb, buf + start, buf_size - start)) < 0) return ret; @@ -228,10 +226,17 @@ static int ir2_decode_frame(AVCodecContext *avctx, return buf_size; } +static av_cold void ir2_init_static(void) +{ + INIT_VLC_STATIC_FROM_LENGTHS(&ir2_vlc, CODE_VLC_BITS, IR2_CODES, + &ir2_tab[0][1], 2, &ir2_tab[0][0], 2, 1, + 0, INIT_VLC_OUTPUT_LE, 1 << CODE_VLC_BITS); +} + static av_cold int ir2_decode_init(AVCodecContext *avctx) { + static AVOnce init_static_once = AV_ONCE_INIT; Ir2Context * const ic = avctx->priv_data; - static VLC_TYPE vlc_tables[1 << CODE_VLC_BITS][2]; ic->avctx = avctx; @@ -241,17 +246,7 @@ static av_cold int ir2_decode_init(AVCodecContext *avctx) if (!ic->picture) return AVERROR(ENOMEM); - ir2_vlc.table = vlc_tables; - ir2_vlc.table_allocated = 1 << CODE_VLC_BITS; -#ifdef BITSTREAM_READER_LE - init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES, - &ir2_codes[0][1], 4, 2, - &ir2_codes[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE); -#else - init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES, - &ir2_codes[0][1], 4, 2, - &ir2_codes[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC); -#endif + ff_thread_once(&init_static_once, ir2_init_static); return 0; } @@ -275,4 +270,5 @@ AVCodec ff_indeo2_decoder = { .close = ir2_decode_end, .decode = ir2_decode_frame, .capabilities = AV_CODEC_CAP_DR1, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, };