diff options
Diffstat (limited to 'libavcodec')
39 files changed, 204 insertions, 69 deletions
diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c index 370fe6df47..5dcb6d8276 100644 --- a/libavcodec/4xm.c +++ b/libavcodec/4xm.c @@ -688,10 +688,13 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length){ unsigned int prestream_size; const uint8_t *prestream; - if (bitstream_size > (1<<26) || length < bitstream_size + 12) - return -1; - prestream_size = 4*AV_RL32(buf + bitstream_size + 4); - prestream = buf + bitstream_size + 12; + if (bitstream_size > (1<<26) || length < bitstream_size + 12) { + av_log(f->avctx, AV_LOG_ERROR, "packet size too small\n"); + return AVERROR_INVALIDDATA; + } + + prestream_size = 4 * AV_RL32(buf + bitstream_size + 4); + prestream = buf + bitstream_size + 12; if (prestream_size > (1<<26) || prestream_size != length - (bitstream_size + 12)){ diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index e7657945dd..688fba430c 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -1007,11 +1007,15 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, break; case CODEC_ID_ADPCM_IMA_AMV: case CODEC_ID_ADPCM_IMA_SMJPEG: - c->status[0].predictor = (int16_t)bytestream_get_le16(&src); - c->status[0].step_index = bytestream_get_le16(&src); - - if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV) - src+=4; + if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV) { + c->status[0].predictor = sign_extend(bytestream_get_le16(&src), 16); + c->status[0].step_index = bytestream_get_le16(&src); + src += 4; + } else { + c->status[0].predictor = sign_extend(bytestream_get_be16(&src), 16); + c->status[0].step_index = bytestream_get_byte(&src); + src += 1; + } for (n = nb_samples >> (1 - st); n > 0; n--, src++) { char hi, lo; diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c index df7529835c..73fa030e6e 100644 --- a/libavcodec/apedec.c +++ b/libavcodec/apedec.c @@ -20,7 +20,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "avcodec.h" #include "dsputil.h" #include "get_bits.h" diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 90719dc9ee..e476538ecb 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1335,6 +1335,15 @@ typedef struct AVFrame { struct AVCodecInternal; +enum AVFieldOrder { + AV_FIELD_UNKNOWN, + AV_FIELD_PROGRESSIVE, + AV_FIELD_TT, //< Top coded_first, top displayed first + AV_FIELD_BB, //< Bottom coded first, bottom displayed first + AV_FIELD_TB, //< Top coded first, bottom displayed first + AV_FIELD_BT, //< Bottom coded first, top displayed first +}; + /** * main external API structure. * New fields can be added to the end with minor version bumps. @@ -3191,6 +3200,12 @@ typedef struct AVCodecContext { */ struct AVCodecInternal *internal; + /** Field order + * - encoding: set by libavcodec + * - decoding: Set by libavcodec + */ + enum AVFieldOrder field_order; + /** * Current statistics for PTS correction. * - decoding: maintained and used by libavcodec, not intended to be used by user apps diff --git a/libavcodec/bink.c b/libavcodec/bink.c index 6df7a3237b..39c94a088c 100644 --- a/libavcodec/bink.c +++ b/libavcodec/bink.c @@ -27,7 +27,7 @@ #include "binkdsp.h" #include "mathops.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" #define BINK_FLAG_ALPHA 0x00100000 diff --git a/libavcodec/binkaudio.c b/libavcodec/binkaudio.c index c60f0687bf..9f51c7a856 100644 --- a/libavcodec/binkaudio.c +++ b/libavcodec/binkaudio.c @@ -29,7 +29,7 @@ */ #include "avcodec.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" #include "dsputil.h" #include "dct.h" diff --git a/libavcodec/eatgq.c b/libavcodec/eatgq.c index 95692a471b..da9ff3bba0 100644 --- a/libavcodec/eatgq.c +++ b/libavcodec/eatgq.c @@ -29,7 +29,7 @@ */ #include "avcodec.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" #include "bytestream.h" #include "dsputil.h" diff --git a/libavcodec/eatgv.c b/libavcodec/eatgv.c index 7b0cd3467c..37f84bf5ef 100644 --- a/libavcodec/eatgv.c +++ b/libavcodec/eatgv.c @@ -29,7 +29,7 @@ */ #include "avcodec.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" #include "libavutil/lzo.h" #include "libavutil/imgutils.h" diff --git a/libavcodec/escape124.c b/libavcodec/escape124.c index 2c86d5f34f..c9025fddde 100644 --- a/libavcodec/escape124.c +++ b/libavcodec/escape124.c @@ -21,7 +21,7 @@ #include "avcodec.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" typedef union MacroBlock { diff --git a/libavcodec/escape130.c b/libavcodec/escape130.c index 5adfefa88d..c9f4d77c6a 100644 --- a/libavcodec/escape130.c +++ b/libavcodec/escape130.c @@ -21,7 +21,7 @@ #include "avcodec.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" typedef struct Escape130Context { diff --git a/libavcodec/g723_1.c b/libavcodec/g723_1.c index bb9856d2ee..6b84161f19 100644 --- a/libavcodec/g723_1.c +++ b/libavcodec/g723_1.c @@ -26,7 +26,7 @@ */ #include "avcodec.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" #include "acelp_vectors.h" #include "celp_filters.h" diff --git a/libavcodec/get_bits.h b/libavcodec/get_bits.h index c888a7bc09..648c958cb0 100644 --- a/libavcodec/get_bits.h +++ b/libavcodec/get_bits.h @@ -124,7 +124,7 @@ for examples see get_bits, show_bits, skip_bits, get_vlc #define CLOSE_READER(name, gb) (gb)->index = name##_index -#ifdef ALT_BITSTREAM_READER_LE +#ifdef BITSTREAM_READER_LE # ifdef LONG_BITSTREAM_READER # define UPDATE_CACHE(name, gb) name##_cache = \ @@ -164,7 +164,7 @@ for examples see get_bits, show_bits, skip_bits, get_vlc #define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) -#ifdef ALT_BITSTREAM_READER_LE +#ifdef BITSTREAM_READER_LE # define SHOW_UBITS(name, gb, num) zero_extend(name##_cache, num) # define SHOW_SBITS(name, gb, num) sign_extend(name##_cache, num) #else @@ -254,7 +254,7 @@ static inline unsigned int get_bits1(GetBitContext *s) { unsigned int index = s->index; uint8_t result = s->buffer[index>>3]; -#ifdef ALT_BITSTREAM_READER_LE +#ifdef BITSTREAM_READER_LE result >>= index & 7; result &= 1; #else @@ -288,7 +288,7 @@ static inline unsigned int get_bits_long(GetBitContext *s, int n) if (n <= MIN_CACHE_BITS) return get_bits(s, n); else { -#ifdef ALT_BITSTREAM_READER_LE +#ifdef BITSTREAM_READER_LE int ret = get_bits(s, 16); return ret | (get_bits(s, n-16) << 16); #else diff --git a/libavcodec/indeo2.c b/libavcodec/indeo2.c index 871a604406..eb58939338 100644 --- a/libavcodec/indeo2.c +++ b/libavcodec/indeo2.c @@ -23,7 +23,7 @@ * @file * Intel Indeo 2 decoder. */ -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "avcodec.h" #include "get_bits.h" #include "indeo2data.h" @@ -163,7 +163,7 @@ static int ir2_decode_frame(AVCodecContext *avctx, s->decode_delta = buf[18]; /* decide whether frame uses deltas or not */ -#ifndef ALT_BITSTREAM_READER_LE +#ifndef BITSTREAM_READER_LE for (i = 0; i < buf_size; i++) buf[i] = av_reverse[buf[i]]; #endif @@ -205,7 +205,7 @@ static av_cold int ir2_decode_init(AVCodecContext *avctx){ ir2_vlc.table = vlc_tables; ir2_vlc.table_allocated = 1 << CODE_VLC_BITS; -#ifdef ALT_BITSTREAM_READER_LE +#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); diff --git a/libavcodec/indeo2data.h b/libavcodec/indeo2data.h index b2e0b8a509..0d6d82f22c 100644 --- a/libavcodec/indeo2data.h +++ b/libavcodec/indeo2data.h @@ -26,7 +26,7 @@ #define IR2_CODES 143 static const uint16_t ir2_codes[IR2_CODES][2] = { -#ifdef ALT_BITSTREAM_READER_LE +#ifdef BITSTREAM_READER_LE {0x0000, 3}, {0x0004, 3}, {0x0006, 3}, {0x0001, 5}, {0x0009, 5}, {0x0019, 5}, {0x000D, 5}, {0x001D, 5}, {0x0023, 6}, {0x0013, 6}, {0x0033, 6}, {0x000B, 6}, diff --git a/libavcodec/indeo5.c b/libavcodec/indeo5.c index 4c6bfd66d1..0256fc1d4a 100644 --- a/libavcodec/indeo5.c +++ b/libavcodec/indeo5.c @@ -27,7 +27,7 @@ * Known FOURCCs: 'IV50' */ -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "avcodec.h" #include "get_bits.h" #include "dsputil.h" diff --git a/libavcodec/interplayvideo.c b/libavcodec/interplayvideo.c index c8aa8bf65b..d27c9ba9c7 100644 --- a/libavcodec/interplayvideo.c +++ b/libavcodec/interplayvideo.c @@ -41,7 +41,7 @@ #include "avcodec.h" #include "bytestream.h" #include "dsputil.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" #define PALETTE_COUNT 256 diff --git a/libavcodec/ivi_common.c b/libavcodec/ivi_common.c index f240845382..d1ee2e00c9 100644 --- a/libavcodec/ivi_common.c +++ b/libavcodec/ivi_common.c @@ -26,7 +26,7 @@ * Indeo5 decoders. */ -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "avcodec.h" #include "get_bits.h" #include "ivi_common.h" diff --git a/libavcodec/kmvc.c b/libavcodec/kmvc.c index 8663c9524a..19f9677649 100644 --- a/libavcodec/kmvc.c +++ b/libavcodec/kmvc.c @@ -57,17 +57,21 @@ typedef struct BitBuf { #define kmvc_init_getbits(bb, src) bb.bits = 7; bb.bitbuf = *src++; -#define kmvc_getbit(bb, src, res) {\ +#define kmvc_getbit(bb, src, src_end, res) {\ res = 0; \ if (bb.bitbuf & (1 << bb.bits)) res = 1; \ bb.bits--; \ if(bb.bits == -1) { \ + if (src >= src_end) { \ + av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); \ + return AVERROR_INVALIDDATA; \ + } \ bb.bitbuf = *src++; \ bb.bits = 7; \ } \ } -static void kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int w, int h) +static int kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int src_size, int w, int h) { BitBuf bb; int res, val; @@ -75,13 +79,18 @@ static void kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int w, int bx, by; int l0x, l1x, l0y, l1y; int mx, my; + const uint8_t *src_end = src + src_size; kmvc_init_getbits(bb, src); for (by = 0; by < h; by += 8) for (bx = 0; bx < w; bx += 8) { - kmvc_getbit(bb, src, res); + kmvc_getbit(bb, src, src_end, res); if (!res) { // fill whole 8x8 block + if (src >= src_end) { + av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); + return AVERROR_INVALIDDATA; + } val = *src++; for (i = 0; i < 64; i++) BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val; @@ -89,14 +98,22 @@ static void kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int w, for (i = 0; i < 4; i++) { l0x = bx + (i & 1) * 4; l0y = by + (i & 2) * 2; - kmvc_getbit(bb, src, res); + kmvc_getbit(bb, src, src_end, res); if (!res) { - kmvc_getbit(bb, src, res); + kmvc_getbit(bb, src, src_end, res); if (!res) { // fill whole 4x4 block + if (src >= src_end) { + av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); + return AVERROR_INVALIDDATA; + } val = *src++; for (j = 0; j < 16; j++) BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val; } else { // copy block from already decoded place + if (src >= src_end) { + av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); + return AVERROR_INVALIDDATA; + } val = *src++; mx = val & 0xF; my = val >> 4; @@ -108,16 +125,24 @@ static void kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int w, for (j = 0; j < 4; j++) { l1x = l0x + (j & 1) * 2; l1y = l0y + (j & 2); - kmvc_getbit(bb, src, res); + kmvc_getbit(bb, src, src_end, res); if (!res) { - kmvc_getbit(bb, src, res); + kmvc_getbit(bb, src, src_end, res); if (!res) { // fill whole 2x2 block + if (src >= src_end) { + av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); + return AVERROR_INVALIDDATA; + } val = *src++; BLK(ctx->cur, l1x, l1y) = val; BLK(ctx->cur, l1x + 1, l1y) = val; BLK(ctx->cur, l1x, l1y + 1) = val; BLK(ctx->cur, l1x + 1, l1y + 1) = val; } else { // copy block from already decoded place + if (src >= src_end) { + av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); + return AVERROR_INVALIDDATA; + } val = *src++; mx = val & 0xF; my = val >> 4; @@ -140,9 +165,11 @@ static void kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int w, } } } + + return 0; } -static void kmvc_decode_inter_8x8(KmvcContext * ctx, const uint8_t * src, int w, int h) +static int kmvc_decode_inter_8x8(KmvcContext * ctx, const uint8_t * src, int src_size, int w, int h) { BitBuf bb; int res, val; @@ -150,15 +177,20 @@ static void kmvc_decode_inter_8x8(KmvcContext * ctx, const uint8_t * src, int w, int bx, by; int l0x, l1x, l0y, l1y; int mx, my; + const uint8_t *src_end = src + src_size; kmvc_init_getbits(bb, src); for (by = 0; by < h; by += 8) for (bx = 0; bx < w; bx += 8) { - kmvc_getbit(bb, src, res); + kmvc_getbit(bb, src, src_end, res); if (!res) { - kmvc_getbit(bb, src, res); + kmvc_getbit(bb, src, src_end, res); if (!res) { // fill whole 8x8 block + if (src >= src_end) { + av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); + return AVERROR_INVALIDDATA; + } val = *src++; for (i = 0; i < 64; i++) BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val; @@ -171,14 +203,22 @@ static void kmvc_decode_inter_8x8(KmvcContext * ctx, const uint8_t * src, int w, for (i = 0; i < 4; i++) { l0x = bx + (i & 1) * 4; l0y = by + (i & 2) * 2; - kmvc_getbit(bb, src, res); + kmvc_getbit(bb, src, src_end, res); if (!res) { - kmvc_getbit(bb, src, res); + kmvc_getbit(bb, src, src_end, res); if (!res) { // fill whole 4x4 block + if (src >= src_end) { + av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); + return AVERROR_INVALIDDATA; + } val = *src++; for (j = 0; j < 16; j++) BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val; } else { // copy block + if (src >= src_end) { + av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); + return AVERROR_INVALIDDATA; + } val = *src++; mx = (val & 0xF) - 8; my = (val >> 4) - 8; @@ -190,16 +230,24 @@ static void kmvc_decode_inter_8x8(KmvcContext * ctx, const uint8_t * src, int w, for (j = 0; j < 4; j++) { l1x = l0x + (j & 1) * 2; l1y = l0y + (j & 2); - kmvc_getbit(bb, src, res); + kmvc_getbit(bb, src, src_end, res); if (!res) { - kmvc_getbit(bb, src, res); + kmvc_getbit(bb, src, src_end, res); if (!res) { // fill whole 2x2 block + if (src >= src_end) { + av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); + return AVERROR_INVALIDDATA; + } val = *src++; BLK(ctx->cur, l1x, l1y) = val; BLK(ctx->cur, l1x + 1, l1y) = val; BLK(ctx->cur, l1x, l1y + 1) = val; BLK(ctx->cur, l1x + 1, l1y + 1) = val; } else { // copy block + if (src >= src_end) { + av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); + return AVERROR_INVALIDDATA; + } val = *src++; mx = (val & 0xF) - 8; my = (val >> 4) - 8; @@ -222,6 +270,8 @@ static void kmvc_decode_inter_8x8(KmvcContext * ctx, const uint8_t * src, int w, } } } + + return 0; } static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPacket *avpkt) @@ -299,10 +349,10 @@ static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPa memcpy(ctx->cur, ctx->prev, 320 * 200); break; case 3: - kmvc_decode_intra_8x8(ctx, buf, avctx->width, avctx->height); + kmvc_decode_intra_8x8(ctx, buf, buf_size, avctx->width, avctx->height); break; case 4: - kmvc_decode_inter_8x8(ctx, buf, avctx->width, avctx->height); + kmvc_decode_inter_8x8(ctx, buf, buf_size, avctx->width, avctx->height); break; default: av_log(avctx, AV_LOG_ERROR, "Unknown compression method %i\n", header & KMVC_METHOD); diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 246c30714d..e082147f35 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -112,12 +112,9 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) build_basic_mjpeg_vlc(s); } } - if (avctx->extradata_size > 9 && - AV_RL32(avctx->extradata + 4) == MKTAG('f','i','e','l')) { - if (avctx->extradata[9] == 6) { /* quicktime icefloe 019 */ - s->interlace_polarity = 1; /* bottom field first */ - av_log(avctx, AV_LOG_DEBUG, "mjpeg bottom field first\n"); - } + if (avctx->field_order == AV_FIELD_BB) { /* quicktime icefloe 019 */ + s->interlace_polarity = 1; /* bottom field first */ + av_log(avctx, AV_LOG_DEBUG, "mjpeg bottom field first\n"); } if (avctx->codec->id == CODEC_ID_AMV) s->flipped = 1; diff --git a/libavcodec/msgsmdec.c b/libavcodec/msgsmdec.c index e759451c83..2ec553b2fe 100644 --- a/libavcodec/msgsmdec.c +++ b/libavcodec/msgsmdec.c @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "avcodec.h" #include "msgsmdec.h" #include "gsmdec_template.c" diff --git a/libavcodec/nellymoser.c b/libavcodec/nellymoser.c index 0716c25a20..cbcc4f941b 100644 --- a/libavcodec/nellymoser.c +++ b/libavcodec/nellymoser.c @@ -35,7 +35,7 @@ #include "avcodec.h" #include "dsputil.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" const float ff_nelly_dequantization_table[127] = { diff --git a/libavcodec/nellymoserdec.c b/libavcodec/nellymoserdec.c index c2e7cda461..9e39097982 100644 --- a/libavcodec/nellymoserdec.c +++ b/libavcodec/nellymoserdec.c @@ -41,7 +41,7 @@ #include "fmtconvert.h" #include "sinewin.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" diff --git a/libavcodec/options.c b/libavcodec/options.c index 272776c110..f3d1ce3e8f 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -371,7 +371,8 @@ static const AVOption options[]={ {"float", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_AA_FLOAT }, INT_MIN, INT_MAX, V|D, "aa"}, #endif {"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, -{"threads", NULL, OFFSET(thread_count), AV_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E|D}, +{"threads", NULL, OFFSET(thread_count), AV_OPT_TYPE_INT, {.dbl = 1 }, 0, INT_MAX, V|E|D, "threads"}, +{"auto", "detect a good number of threads", 0, AV_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, V|E|D, "threads"}, {"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"mb_threshold", "macroblock threshold", OFFSET(mb_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, {"dc", "intra_dc_precision", OFFSET(intra_dc_precision), AV_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX, V|E}, diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index bca01edef5..e8bc318711 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -30,6 +30,17 @@ */ #include "config.h" + +#if HAVE_SCHED_GETAFFINITY +#define _GNU_SOURCE +#include <sched.h> +#elif HAVE_GETSYSTEMINFO +#include <windows.h> +#elif HAVE_SYSCTL +#include <sys/sysctl.h> +#include <sys/types.h> +#endif + #include "avcodec.h" #include "internal.h" #include "thread.h" @@ -135,6 +146,40 @@ typedef struct FrameThreadContext { int die; ///< Set when threads should exit. } FrameThreadContext; + +/* H264 slice threading seems to be buggy with more than 16 threads, + * limit the number of threads to 16 for automatic detection */ +#define MAX_AUTO_THREADS 16 + +static int get_logical_cpus(AVCodecContext *avctx) +{ + int ret, nb_cpus = 1; +#if HAVE_SCHED_GETAFFINITY + cpu_set_t cpuset; + + CPU_ZERO(&cpuset); + + ret = sched_getaffinity(0, sizeof(cpuset), &cpuset); + if (!ret) { + nb_cpus = CPU_COUNT(&cpuset); + } +#elif HAVE_GETSYSTEMINFO + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + nb_cpus = sysinfo.dwNumberOfProcessors; +#elif HAVE_SYSCTL + int mib[2] = { CTL_HW, HW_NCPU }; + size_t len = sizeof(nb_cpus); + + ret = sysctl(mib, 2, &nb_cpus, &len, NULL, 0); + if (ret == -1) + nb_cpus = 0; +#endif + av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus); + return FFMIN(nb_cpus, MAX_AUTO_THREADS); +} + + static void* attribute_align_arg worker(void *v) { AVCodecContext *avctx = v; @@ -239,8 +284,17 @@ static int thread_init(AVCodecContext *avctx) ThreadContext *c; int thread_count = avctx->thread_count; - if (thread_count <= 1) + if (!thread_count) { + int nb_cpus = get_logical_cpus(avctx); + // use number of cores + 1 as thread count if there is motre than one + if (nb_cpus > 1) + thread_count = avctx->thread_count = nb_cpus + 1; + } + + if (thread_count <= 1) { + avctx->active_thread_type = 0; return 0; + } c = av_mallocz(sizeof(ThreadContext)); if (!c) @@ -704,6 +758,13 @@ static int frame_thread_init(AVCodecContext *avctx) FrameThreadContext *fctx; int i, err = 0; + if (!thread_count) { + int nb_cpus = get_logical_cpus(avctx); + // use number of cores + 1 as thread count if there is motre than one + if (nb_cpus > 1) + thread_count = avctx->thread_count = nb_cpus + 1; + } + if (thread_count <= 1) { avctx->active_thread_type = 0; return 0; diff --git a/libavcodec/qdm2.c b/libavcodec/qdm2.c index cc71825838..0eca7ade21 100644 --- a/libavcodec/qdm2.c +++ b/libavcodec/qdm2.c @@ -35,7 +35,7 @@ #include <stddef.h> #include <stdio.h> -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "avcodec.h" #include "get_bits.h" #include "dsputil.h" diff --git a/libavcodec/ra144enc.c b/libavcodec/ra144enc.c index 19fe06c840..2436bac147 100644 --- a/libavcodec/ra144enc.c +++ b/libavcodec/ra144enc.c @@ -477,7 +477,10 @@ static int ra144_encode_frame(AVCodecContext *avctx, uint8_t *frame, * The filter is unstable: use the coefficients of the previous frame. */ ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[1]); - ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx); + if (ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx)) { + /* the filter is still unstable. set reflection coeffs to zero. */ + memset(lpc_refl, 0, sizeof(lpc_refl)); + } } init_put_bits(&pb, frame, buf_size); for (i = 0; i < LPC_ORDER; i++) { diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c index 3a9f409f4a..26b576d804 100644 --- a/libavcodec/ra288.c +++ b/libavcodec/ra288.c @@ -20,7 +20,7 @@ */ #include "avcodec.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" #include "ra288.h" #include "lpc.h" diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c index d66c14fb12..db9cda7742 100644 --- a/libavcodec/sipr.c +++ b/libavcodec/sipr.c @@ -27,7 +27,7 @@ #include "libavutil/mathematics.h" #include "avcodec.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" #include "dsputil.h" diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c index fdc28e1a07..30f99b488d 100644 --- a/libavcodec/smacker.c +++ b/libavcodec/smacker.c @@ -35,7 +35,7 @@ #include "libavutil/audioconvert.h" #include "mathops.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" #include "bytestream.h" diff --git a/libavcodec/tiertexseqv.c b/libavcodec/tiertexseqv.c index e8abcd9c76..a9ebb4786c 100644 --- a/libavcodec/tiertexseqv.c +++ b/libavcodec/tiertexseqv.c @@ -25,7 +25,7 @@ */ #include "avcodec.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c index bb4ce6f219..9bbbf5172e 100644 --- a/libavcodec/truespeech.c +++ b/libavcodec/truespeech.c @@ -179,6 +179,7 @@ static void truespeech_apply_twopoint_filter(TSContext *dec, int quart) for(i = 0; i < 146; i++) tmp[i] = dec->filtbuf[i]; off = (t / 25) + dec->offset1[quart >> 1] + 18; + off = av_clip(off, 0, 145); ptr0 = tmp + 145 - off; ptr1 = tmp + 146; filter = (const int16_t*)ts_order2_coeffs + (t % 25) * 2; diff --git a/libavcodec/tta.c b/libavcodec/tta.c index 684b3fe414..f629901888 100644 --- a/libavcodec/tta.c +++ b/libavcodec/tta.c @@ -27,7 +27,7 @@ * @author Alex Beregszaszi */ -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE //#define DEBUG #include <limits.h> #include "avcodec.h" diff --git a/libavcodec/v410dec.c b/libavcodec/v410dec.c index 6640ba0345..d746dd0921 100644 --- a/libavcodec/v410dec.c +++ b/libavcodec/v410dec.c @@ -20,8 +20,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "libavutil/intreadwrite.h" #include "avcodec.h" -#include "get_bits.h" static av_cold int v410_decode_init(AVCodecContext *avctx) { diff --git a/libavcodec/vble.c b/libavcodec/vble.c index 88b8200f2a..cee153c979 100644 --- a/libavcodec/vble.c +++ b/libavcodec/vble.c @@ -24,7 +24,7 @@ * VBLE Decoder */ -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "avcodec.h" #include "dsputil.h" diff --git a/libavcodec/vorbis.c b/libavcodec/vorbis.c index 1624948626..b850b59dd0 100644 --- a/libavcodec/vorbis.c +++ b/libavcodec/vorbis.c @@ -26,7 +26,7 @@ * @author Denes Balatoni ( dbalatoni programozo hu ) */ -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "avcodec.h" #include "get_bits.h" diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c index 03ecc38ed4..85076483ab 100644 --- a/libavcodec/vorbisdec.c +++ b/libavcodec/vorbisdec.c @@ -29,7 +29,7 @@ #include <inttypes.h> #include <math.h> -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "avcodec.h" #include "get_bits.h" #include "dsputil.h" diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c index 8d9b804852..1ac0ecd3c7 100644 --- a/libavcodec/wavpack.c +++ b/libavcodec/wavpack.c @@ -18,7 +18,7 @@ * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "avcodec.h" #include "get_bits.h" #include "unary.h" diff --git a/libavcodec/xan.c b/libavcodec/xan.c index c469594e34..8518250141 100644 --- a/libavcodec/xan.c +++ b/libavcodec/xan.c @@ -35,7 +35,7 @@ #include "libavutil/intreadwrite.h" #include "avcodec.h" #include "bytestream.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" // for av_memcpy_backptr #include "libavutil/lzo.h" diff --git a/libavcodec/xxan.c b/libavcodec/xxan.c index 180dcd47e8..0bfebc8789 100644 --- a/libavcodec/xxan.c +++ b/libavcodec/xxan.c @@ -23,7 +23,7 @@ #include "avcodec.h" #include "libavutil/intreadwrite.h" #include "bytestream.h" -#define ALT_BITSTREAM_READER_LE +#define BITSTREAM_READER_LE #include "get_bits.h" // for av_memcpy_backptr #include "libavutil/lzo.h" |