diff --git a/avconv.c b/avconv.c index 77276c1954..5bf0ace388 100644 --- a/avconv.c +++ b/avconv.c @@ -2139,6 +2139,7 @@ static int transcode_init(OutputFile *output_files, codec->bit_rate = icodec->bit_rate; codec->rc_max_rate = icodec->rc_max_rate; codec->rc_buffer_size = icodec->rc_buffer_size; + codec->field_order = icodec->field_order; codec->extradata = av_mallocz(extra_size); if (!codec->extradata) { return AVERROR(ENOMEM); diff --git a/configure b/configure index 9978cb67eb..e3dde0c567 100755 --- a/configure +++ b/configure @@ -1174,6 +1174,7 @@ HAVE_LIST=" gethrtime GetProcessMemoryInfo GetProcessTimes + GetSystemInfo getrusage gnu_as ibm_asm @@ -1206,6 +1207,7 @@ HAVE_LIST=" posix_memalign round roundf + sched_getaffinity sdl sdl_video_size setmode @@ -1224,6 +1226,7 @@ HAVE_LIST=" symver symver_asm_label symver_gnu_asm + sysctl sys_mman_h sys_resource_h sys_select_h @@ -1654,14 +1657,13 @@ postproc_deps="gpl" # programs avconv_deps="avcodec avformat swscale" -avconv_select="buffer_filter" ffplay_deps="avcodec avformat swscale sdl" ffplay_select="buffersink_filter rdft" ffprobe_deps="avcodec avformat" ffserver_deps="avformat ffm_muxer fork rtp_protocol rtsp_demuxer" ffserver_extralibs='$ldl' ffmpeg_deps="avcodec avformat swscale swresample" -ffmpeg_select="buffer_filter buffersink_filter" +ffmpeg_select="buffersink_filter" doc_deps="texi2html" @@ -3000,12 +3002,15 @@ check_func ${malloc_prefix}posix_memalign && enable posix_memalign check_func setrlimit check_func strerror_r check_func strptime +check_func sched_getaffinity +check_func sysctl check_func_headers conio.h kbhit check_func_headers windows.h PeekNamedPipe check_func_headers io.h setmode check_func_headers lzo/lzo1x.h lzo1x_999_compress check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi check_func_headers windows.h GetProcessTimes +check_func_headers windows.h GetSystemInfo check_func_headers windows.h MapViewOfFile check_func_headers windows.h VirtualAlloc diff --git a/ffmpeg.c b/ffmpeg.c index 75274db17a..a05b2fcacc 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -2213,6 +2213,7 @@ static int transcode_init(OutputFile *output_files, int nb_output_files, codec->bit_rate = icodec->bit_rate; codec->rc_max_rate = icodec->rc_max_rate; codec->rc_buffer_size = icodec->rc_buffer_size; + codec->field_order = icodec->field_order; codec->extradata = av_mallocz(extra_size); if (!codec->extradata) { return AVERROR(ENOMEM); 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 +#elif HAVE_GETSYSTEMINFO +#include +#elif HAVE_SYSCTL +#include +#include +#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 #include -#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 #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 #include -#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" diff --git a/libavfilter/Makefile b/libavfilter/Makefile index a6fd18f10b..99777538b7 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -20,6 +20,7 @@ OBJS = allfilters.o \ formats.o \ graphparser.o \ transform.o \ + vsrc_buffer.o OBJS-$(CONFIG_AVCODEC) += avcodec.o @@ -83,7 +84,6 @@ OBJS-$(CONFIG_UNSHARP_FILTER) += vf_unsharp.o OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o OBJS-$(CONFIG_YADIF_FILTER) += vf_yadif.o -OBJS-$(CONFIG_BUFFER_FILTER) += vsrc_buffer.o OBJS-$(CONFIG_CELLAUTO_FILTER) += vsrc_cellauto.o OBJS-$(CONFIG_COLOR_FILTER) += vsrc_color.o OBJS-$(CONFIG_FREI0R_SRC_FILTER) += vf_frei0r.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index fb50a3a0a9..77a8a484d5 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -94,7 +94,6 @@ void avfilter_register_all(void) REGISTER_FILTER (VFLIP, vflip, vf); REGISTER_FILTER (YADIF, yadif, vf); - REGISTER_FILTER (BUFFER, buffer, vsrc); REGISTER_FILTER (CELLAUTO, cellauto, vsrc); REGISTER_FILTER (COLOR, color, vsrc); REGISTER_FILTER (FREI0R, frei0r_src, vsrc); @@ -108,4 +107,10 @@ void avfilter_register_all(void) REGISTER_FILTER (BUFFERSINK, buffersink, vsink); REGISTER_FILTER (NULLSINK, nullsink, vsink); + + /* vsrc_buffer is a part of public API => registered unconditionally */ + { + extern avfilter_vsrc_buffer; + avfilter_register(&avfilter_vsrc_buffer); + } } diff --git a/libavformat/Makefile b/libavformat/Makefile index f2a6e2efdf..877a86cac9 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -56,7 +56,8 @@ OBJS-$(CONFIG_BIT_DEMUXER) += bit.o OBJS-$(CONFIG_BIT_MUXER) += bit.o OBJS-$(CONFIG_BMV_DEMUXER) += bmv.o OBJS-$(CONFIG_C93_DEMUXER) += c93.o vocdec.o voc.o -OBJS-$(CONFIG_CAF_DEMUXER) += cafdec.o caf.o mov.o riff.o isom.o +OBJS-$(CONFIG_CAF_DEMUXER) += cafdec.o caf.o mov.o mov_chan.o \ + riff.o isom.o OBJS-$(CONFIG_CAF_MUXER) += cafenc.o caf.o riff.o isom.o OBJS-$(CONFIG_CAVSVIDEO_DEMUXER) += cavsvideodec.o rawdec.o OBJS-$(CONFIG_CAVSVIDEO_MUXER) += rawenc.o @@ -195,7 +196,7 @@ OBJS-$(CONFIG_OGG_DEMUXER) += oggdec.o \ OBJS-$(CONFIG_OGG_MUXER) += oggenc.o \ vorbiscomment.o OBJS-$(CONFIG_OMA_DEMUXER) += omadec.o pcm.o oma.o -OBJS-$(CONFIG_OMA_MUXER) += omaenc.o rawenc.o oma.o +OBJS-$(CONFIG_OMA_MUXER) += omaenc.o rawenc.o oma.o id3v2enc.o OBJS-$(CONFIG_PCM_ALAW_DEMUXER) += pcmdec.o pcm.o rawdec.o OBJS-$(CONFIG_PCM_ALAW_MUXER) += pcmenc.o rawenc.o OBJS-$(CONFIG_PCM_F32BE_DEMUXER) += pcmdec.o pcm.o rawdec.o @@ -331,7 +332,7 @@ OBJS-$(CONFIG_WTV_MUXER) += wtvenc.o wtv.o asf.o asfenc.o riff.o OBJS-$(CONFIG_WV_DEMUXER) += wv.o apetag.o OBJS-$(CONFIG_XA_DEMUXER) += xa.o OBJS-$(CONFIG_XBIN_DEMUXER) += bintext.o sauce.o -OBJS-$(CONFIG_XMV_DEMUXER) += xmv.o +OBJS-$(CONFIG_XMV_DEMUXER) += xmv.o riff.o OBJS-$(CONFIG_XWMA_DEMUXER) += xwma.o riff.o OBJS-$(CONFIG_YOP_DEMUXER) += yop.o OBJS-$(CONFIG_YUV4MPEGPIPE_MUXER) += yuv4mpeg.o diff --git a/libavformat/mov.c b/libavformat/mov.c index e18c861edc..dd8e92ee31 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -857,6 +857,40 @@ static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom) return 0; } +static int mov_read_fiel(MOVContext *c, AVIOContext *pb, MOVAtom atom) +{ + AVStream *st; + unsigned mov_field_order; + enum AVFieldOrder decoded_field_order = AV_FIELD_UNKNOWN; + + if (c->fc->nb_streams < 1) // will happen with jp2 files + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + if (atom.size < 2) + return AVERROR_INVALIDDATA; + mov_field_order = avio_rb16(pb); + if ((mov_field_order & 0xFF00) == 0x0100) + decoded_field_order = AV_FIELD_PROGRESSIVE; + else if ((mov_field_order & 0xFF00) == 0x0200) { + switch (mov_field_order & 0xFF) { + case 0x01: decoded_field_order = AV_FIELD_TT; + break; + case 0x06: decoded_field_order = AV_FIELD_BB; + break; + case 0x09: decoded_field_order = AV_FIELD_TB; + break; + case 0x0E: decoded_field_order = AV_FIELD_BT; + break; + } + } + if (decoded_field_order == AV_FIELD_UNKNOWN && mov_field_order) { + av_log(NULL, AV_LOG_ERROR, "Unknown MOV field order 0x%04x\n", mov_field_order); + } + st->codec->field_order = decoded_field_order; + + return 0; +} + /* FIXME modify qdm2/svq3/h264 decoders to take full atom as extradata */ static int mov_read_extradata(MOVContext *c, AVIOContext *pb, MOVAtom atom, enum CodecID codec_id) @@ -898,11 +932,6 @@ static int mov_read_avss(MOVContext *c, AVIOContext *pb, MOVAtom atom) return mov_read_extradata(c, pb, atom, CODEC_ID_AVS); } -static int mov_read_fiel(MOVContext *c, AVIOContext *pb, MOVAtom atom) -{ - return mov_read_extradata(c, pb, atom, CODEC_ID_MJPEG); -} - static int mov_read_jp2h(MOVContext *c, AVIOContext *pb, MOVAtom atom) { return mov_read_extradata(c, pb, atom, CODEC_ID_JPEG2000); @@ -950,6 +979,15 @@ static int mov_read_glbl(MOVContext *c, AVIOContext *pb, MOVAtom atom) if ((uint64_t)atom.size > (1<<30)) return -1; + if (atom.size >= 10) { + // Broken files created by legacy versions of Libav and FFmpeg will + // wrap a whole fiel atom inside of a glbl atom. + unsigned size = avio_rb32(pb); + unsigned type = avio_rl32(pb); + avio_seek(pb, -8, SEEK_CUR); + if (type == MKTAG('f','i','e','l') && size == atom.size) + return mov_read_default(c, pb, atom); + } av_free(st->codec->extradata); st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE); if (!st->codec->extradata) diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 2e8ef90e0e..da22c4e855 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -799,6 +799,23 @@ static int mov_write_uuid_tag_ipod(AVIOContext *pb) return 28; } +static const uint16_t fiel_data[] = { + 0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e +}; + +static int mov_write_fiel_tag(AVIOContext *pb, MOVTrack *track) +{ + unsigned mov_field_order = 0; + if (track->enc->field_order < FF_ARRAY_ELEMS(fiel_data)) + mov_field_order = fiel_data[track->enc->field_order]; + else + return 0; + avio_wb32(pb, 10); + ffio_wfourcc(pb, "fiel"); + avio_wb16(pb, mov_field_order); + return 10; +} + static int mov_write_subtitle_tag(AVIOContext *pb, MOVTrack *track) { int64_t pos = avio_tell(pb); @@ -885,7 +902,9 @@ static int mov_write_video_tag(AVIOContext *pb, MOVTrack *track) mov_write_avcc_tag(pb, track); if(track->mode == MODE_IPOD) mov_write_uuid_tag_ipod(pb); - } else if(track->vosLen > 0) + } else if (track->enc->field_order != AV_FIELD_UNKNOWN) + mov_write_fiel_tag(pb, track); + else if(track->vosLen > 0) mov_write_glbl_tag(pb, track); if (track->enc->sample_aspect_ratio.den && track->enc->sample_aspect_ratio.num && diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 4b41200c18..a9830eff20 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -655,9 +655,11 @@ const char *sws_format_name(enum PixelFormat format); || isBGRinInt(x) \ ) #else -#define isPacked(x) \ +#define isPacked(x) (\ (av_pix_fmt_descriptors[x].nb_components >= 2 && \ - !(av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR)) + !(av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR)) || \ + (x) == PIX_FMT_PAL8\ + ) #endif #define isPlanar(x) \