From f264d336fe61c12ce9607c3060aa5d3dca947c61 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 21 Dec 2011 18:13:06 -0500 Subject: truespeech: fix invalid reads in truespeech_apply_twopoint_filter() fixes Bug 171 --- libavcodec/truespeech.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libavcodec/truespeech.c b/libavcodec/truespeech.c index 524884ddf5..5ef0a01427 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; -- cgit v1.2.3 From 4bf3c8f226252e18de8051fd0d417c1d39857b67 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 13 Dec 2011 18:49:06 -0800 Subject: mov: Don't stick the QuickTime field ordering atom in extradata. The 'fiel' atoms can be found in H.264 tracks clobbering the extradata. MJPEG supports non field based extradata, and this data should be preserved when copying. --- avconv.c | 1 + libavcodec/avcodec.h | 15 +++++++++++++++ libavcodec/mjpegdec.c | 9 +++------ libavformat/mov.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- libavformat/movenc.c | 21 ++++++++++++++++++++- 5 files changed, 83 insertions(+), 8 deletions(-) diff --git a/avconv.c b/avconv.c index ecbf5233c4..dfef98f51f 100644 --- a/avconv.c +++ b/avconv.c @@ -2070,6 +2070,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/libavcodec/avcodec.h b/libavcodec/avcodec.h index 6ce3224bfb..5d39b98123 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1262,6 +1262,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. @@ -3108,6 +3117,12 @@ typedef struct AVCodecContext { * libavcodec functions. */ struct AVCodecInternal *internal; + + /** Field order + * - encoding: set by libavcodec + * - decoding: Set by libavcodec + */ + enum AVFieldOrder field_order; } AVCodecContext; /** diff --git a/libavcodec/mjpegdec.c b/libavcodec/mjpegdec.c index 17e87ed65b..058b08fa83 100644 --- a/libavcodec/mjpegdec.c +++ b/libavcodec/mjpegdec.c @@ -110,12 +110,9 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } } - 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/libavformat/mov.c b/libavformat/mov.c index d9fb8fb991..d3674d9e12 100644 --- a/libavformat/mov.c +++ b/libavformat/mov.c @@ -841,6 +841,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) { @@ -908,6 +942,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) @@ -2331,7 +2374,7 @@ static const MOVParseTableEntry mov_default_parse_table[] = { { MKTAG('e','d','t','s'), mov_read_default }, { MKTAG('e','l','s','t'), mov_read_elst }, { MKTAG('e','n','d','a'), mov_read_enda }, -{ MKTAG('f','i','e','l'), mov_read_extradata }, +{ MKTAG('f','i','e','l'), mov_read_fiel }, { MKTAG('f','t','y','p'), mov_read_ftyp }, { MKTAG('g','l','b','l'), mov_read_glbl }, { MKTAG('h','d','l','r'), mov_read_hdlr }, diff --git a/libavformat/movenc.c b/libavformat/movenc.c index 0463528362..e11eb509d8 100644 --- a/libavformat/movenc.c +++ b/libavformat/movenc.c @@ -783,6 +783,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); @@ -869,7 +886,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 && -- cgit v1.2.3 From 131609dc2a75e6783396853023d6f49333e3f495 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 21 Dec 2011 06:41:57 +0100 Subject: sws: readd PAL8 to isPacked() Fixes PAL8 to YUV conversion. --- libswscale/swscale_internal.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index 50554439f0..bb3b52d8c9 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -609,9 +609,11 @@ const char *sws_format_name(enum PixelFormat format); (av_pix_fmt_descriptors[x].nb_components == 2 || \ av_pix_fmt_descriptors[x].nb_components == 4) -#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\ + ) #define isPlanar(x) \ (av_pix_fmt_descriptors[x].nb_components >= 2 && \ -- cgit v1.2.3 From 9a3f10695a011861dcf5a649e3e72580b1a4eed4 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 21 Dec 2011 16:09:11 -0500 Subject: ra144enc: zero the reflection coeffs if the filter is unstable fixes use of uninitialized values if the filter is still unstable after using the previous frame lpc coefficients. --- libavcodec/ra144enc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libavcodec/ra144enc.c b/libavcodec/ra144enc.c index 1d260b7a22..ee38bd5c54 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++) { -- cgit v1.2.3 From 196c9e5c8c1706e81217e372ea6a3a101486af9e Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 21 Dec 2011 20:47:52 +0100 Subject: lavfi: always build vsrc_buffer. It's a part of public API. --- configure | 2 -- libavfilter/Makefile | 2 +- libavfilter/allfilters.c | 7 ++++++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 1c7fb3b7ec..8e2e08b95f 100755 --- a/configure +++ b/configure @@ -1525,14 +1525,12 @@ postproc_deps="gpl" # programs avconv_deps="avcodec avformat swscale" -avconv_select="buffer_filter" avplay_deps="avcodec avformat swscale sdl" avplay_select="rdft" avprobe_deps="avcodec avformat" avserver_deps="avformat ffm_muxer fork rtp_protocol rtsp_demuxer" avserver_extralibs='$ldl' ffmpeg_deps="avcodec avformat swscale" -ffmpeg_select="buffer_filter" doc_deps="texi2html" diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 63974d0089..c269db5797 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -12,6 +12,7 @@ OBJS = allfilters.o \ drawutils.o \ formats.o \ graphparser.o \ + vsrc_buffer.o OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o @@ -59,7 +60,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_COLOR_FILTER) += vsrc_color.o OBJS-$(CONFIG_FREI0R_SRC_FILTER) += vf_frei0r.o OBJS-$(CONFIG_MOVIE_FILTER) += vsrc_movie.o diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c index d72987402c..a6f17317e9 100644 --- a/libavfilter/allfilters.c +++ b/libavfilter/allfilters.c @@ -80,7 +80,6 @@ void avfilter_register_all(void) REGISTER_FILTER (VFLIP, vflip, vf); REGISTER_FILTER (YADIF, yadif, vf); - REGISTER_FILTER (BUFFER, buffer, vsrc); REGISTER_FILTER (COLOR, color, vsrc); REGISTER_FILTER (FREI0R, frei0r_src, vsrc); REGISTER_FILTER (MOVIE, movie, vsrc); @@ -89,4 +88,10 @@ void avfilter_register_all(void) REGISTER_FILTER (TESTSRC, testsrc, vsrc); REGISTER_FILTER (NULLSINK, nullsink, vsink); + + /* vsrc_buffer is a part of public API => registered unconditionally */ + { + extern avfilter_vsrc_buffer; + avfilter_register(&avfilter_vsrc_buffer); + } } -- cgit v1.2.3 From aaf47bcde7580e95bbaae0e13b454377d1bb217b Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Thu, 22 Dec 2011 16:33:31 +0100 Subject: Drop ALT_ prefix from BITSTREAM_READER_LE name. The prefix is a historic remnant that probably meant "alternative". Now that the A32 bitstream reader has been dropped it makes no sense anymore. --- libavcodec/apedec.c | 2 +- libavcodec/bink.c | 2 +- libavcodec/binkaudio.c | 2 +- libavcodec/eatgq.c | 2 +- libavcodec/eatgv.c | 2 +- libavcodec/escape124.c | 2 +- libavcodec/get_bits.h | 8 ++++---- libavcodec/indeo2.c | 6 +++--- libavcodec/indeo2data.h | 2 +- libavcodec/indeo5.c | 2 +- libavcodec/interplayvideo.c | 2 +- libavcodec/ivi_common.c | 2 +- libavcodec/msgsmdec.c | 2 +- libavcodec/nellymoser.c | 2 +- libavcodec/nellymoserdec.c | 2 +- libavcodec/qdm2.c | 2 +- libavcodec/ra288.c | 2 +- libavcodec/sipr.c | 2 +- libavcodec/smacker.c | 2 +- libavcodec/tiertexseqv.c | 2 +- libavcodec/tta.c | 2 +- libavcodec/vble.c | 2 +- libavcodec/vorbis.c | 2 +- libavcodec/vorbisdec.c | 2 +- libavcodec/wavpack.c | 2 +- libavcodec/xan.c | 2 +- libavcodec/xxan.c | 2 +- 27 files changed, 32 insertions(+), 32 deletions(-) diff --git a/libavcodec/apedec.c b/libavcodec/apedec.c index 2d03c554a6..fa50d6178d 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/bink.c b/libavcodec/bink.c index b55ea07699..f38c030b7c 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 adffc6b2b6..d73ffcdabc 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 ed4cbc7528..e82ed32470 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 597d0db8da..ccdb35ef2b 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 815cd58a9b..f6d7c8268e 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/get_bits.h b/libavcodec/get_bits.h index 8abfde1150..1668600b2d 100644 --- a/libavcodec/get_bits.h +++ b/libavcodec/get_bits.h @@ -126,7 +126,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 = \ @@ -166,7 +166,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 @@ -256,7 +256,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 @@ -290,7 +290,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 398a9acd92..ecf89cc817 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" @@ -166,7 +166,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 @@ -207,7 +207,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 ef85e32d87..ed8d83c83b 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 ba1bc18eff..8b72b1f0c2 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 d0e8f4cdc6..db98bec9c5 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 bd3d4e6fd4..9cec0a83a2 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/msgsmdec.c b/libavcodec/msgsmdec.c index ff9b275b77..1a288ee291 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 af286fbf87..7f585e4128 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/qdm2.c b/libavcodec/qdm2.c index 9341c69281..91c47a8ec2 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/ra288.c b/libavcodec/ra288.c index 062d9fac94..4cb2493fc9 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 c832b9b1fd..4502fa5f2a 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 ba7da02622..0c7c40560f 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 d48fa15a72..12d5bce4ac 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/tta.c b/libavcodec/tta.c index c8d58fd9ec..7ec5435a06 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/vble.c b/libavcodec/vble.c index a13bcf8c5f..fa205f5982 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 8ff24ab627..86df2886f2 100644 --- a/libavcodec/vorbis.c +++ b/libavcodec/vorbis.c @@ -22,7 +22,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 381b61d060..70690ddb2c 100644 --- a/libavcodec/vorbisdec.c +++ b/libavcodec/vorbisdec.c @@ -25,7 +25,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 3cf5986103..7d16a9b5a6 100644 --- a/libavcodec/wavpack.c +++ b/libavcodec/wavpack.c @@ -18,7 +18,7 @@ * License along with Libav; 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 f3e92b75f2..4c4721ada2 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 6211ca450d..58c80c05fa 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" -- cgit v1.2.3 From fede015468e696b0dad01a03f6628c1a4cae955e Mon Sep 17 00:00:00 2001 From: "Paul B. Mahol" Date: Wed, 21 Dec 2011 00:19:12 +0000 Subject: v410dec: include correct headers This file does not use anything from get_bits.h but needs intreadwrite.h. Signed-off-by: Paul B Mahol Signed-off-by: Janne Grunau --- libavcodec/v410dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/v410dec.c b/libavcodec/v410dec.c index 5df95f8beb..71cbe0b355 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) { -- cgit v1.2.3 From f77f640b3035d357a6c6ffcea243c7ea0d8ebc67 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Wed, 21 Dec 2011 13:07:54 +0100 Subject: pthreads: reset active_thread_type when slice thread_init returrns early --- libavcodec/pthread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index 7e03c64f40..ac15fefd68 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -237,8 +237,10 @@ static int thread_init(AVCodecContext *avctx) ThreadContext *c; int thread_count = avctx->thread_count; - if (thread_count <= 1) + if (thread_count <= 1) { + avctx->active_thread_type = 0; return 0; + } c = av_mallocz(sizeof(ThreadContext)); if (!c) -- cgit v1.2.3 From ea4d5f48373ab856e01a3cf05426db6e823e01d1 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Wed, 21 Dec 2011 01:18:01 +0100 Subject: linux: use number of CPUs as automatic thread count Use sched_getaffinity to determine the number of logical CPUs. Limits the number of threads to 16 since slice threading of H.264 seems to be buggy with more than 16 threads. --- configure | 2 ++ libavcodec/pthread.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/configure b/configure index 8e2e08b95f..b5ee3b5bb2 100755 --- a/configure +++ b/configure @@ -1117,6 +1117,7 @@ HAVE_LIST=" posix_memalign round roundf + sched_getaffinity sdl sdl_video_size setmode @@ -2853,6 +2854,7 @@ check_func setrlimit check_func strerror_r check_func strptime check_func strtok_r +check_func sched_getaffinity check_func_headers io.h setmode check_func_headers lzo/lzo1x.h lzo1x_999_compress check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index ac15fefd68..1800f291d7 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -30,6 +30,12 @@ */ #include "config.h" + +#if HAVE_SCHED_GETAFFINITY +#define _GNU_SOURCE +#include +#endif + #include "avcodec.h" #include "internal.h" #include "thread.h" @@ -133,6 +139,29 @@ 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); + } +#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; @@ -237,6 +266,13 @@ static int thread_init(AVCodecContext *avctx) ThreadContext *c; int thread_count = avctx->thread_count; + 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; @@ -697,6 +733,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; -- cgit v1.2.3 From ad29ecbff0aa41adc535c118cbd956b93dab7289 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Wed, 21 Dec 2011 01:26:19 +0100 Subject: windows: use number of CPUs as automatic thread count --- configure | 2 ++ libavcodec/pthread.c | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/configure b/configure index b5ee3b5bb2..64233ccaa2 100755 --- a/configure +++ b/configure @@ -1086,6 +1086,7 @@ HAVE_LIST=" gethrtime GetProcessMemoryInfo GetProcessTimes + GetSystemInfo getrusage gnu_as ibm_asm @@ -2859,6 +2860,7 @@ 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/libavcodec/pthread.c b/libavcodec/pthread.c index 1800f291d7..bf6733fe7f 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -34,6 +34,8 @@ #if HAVE_SCHED_GETAFFINITY #define _GNU_SOURCE #include +#elif HAVE_GETSYSTEMINFO +#include #endif #include "avcodec.h" @@ -156,6 +158,10 @@ static int get_logical_cpus(AVCodecContext *avctx) if (!ret) { nb_cpus = CPU_COUNT(&cpuset); } +#elif HAVE_GETSYSTEMINFO + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + nb_cpus = sysinfo.dwNumberOfProcessors; #endif av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus); return FFMIN(nb_cpus, MAX_AUTO_THREADS); -- cgit v1.2.3 From b9e2226972737ab202ac1f5a6e005af80072bb39 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Thu, 22 Dec 2011 21:10:07 +0100 Subject: bsd: use number of logical CPUs as automatic thread count --- configure | 2 ++ libavcodec/pthread.c | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/configure b/configure index 64233ccaa2..9b510de878 100755 --- a/configure +++ b/configure @@ -1138,6 +1138,7 @@ HAVE_LIST=" symver symver_asm_label symver_gnu_asm + sysctl sys_mman_h sys_resource_h sys_select_h @@ -2856,6 +2857,7 @@ check_func strerror_r check_func strptime check_func strtok_r check_func sched_getaffinity +check_func sysctl check_func_headers io.h setmode check_func_headers lzo/lzo1x.h lzo1x_999_compress check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c index bf6733fe7f..0b57156b99 100644 --- a/libavcodec/pthread.c +++ b/libavcodec/pthread.c @@ -36,6 +36,9 @@ #include #elif HAVE_GETSYSTEMINFO #include +#elif HAVE_SYSCTL +#include +#include #endif #include "avcodec.h" @@ -162,6 +165,13 @@ static int get_logical_cpus(AVCodecContext *avctx) 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); -- cgit v1.2.3 From c32e4029d99fb1bff3df86f62a3ce61d2419aae0 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Wed, 21 Dec 2011 01:37:44 +0100 Subject: options: set minimum for "threads" to zero A negative number of threads does not make sense and 0 is used for autodetection. Adds a symbolic name for autodetection. --- libavcodec/options.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavcodec/options.c b/libavcodec/options.c index a3a102c0c8..4ac9313f27 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -370,7 +370,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}, -- cgit v1.2.3 From 01a01bf8bdafab1c81c3039850aba042b247626f Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Wed, 21 Dec 2011 19:27:53 +0000 Subject: adpcm: fix IMA SMJPEG decoding Signed-off-by: Janne Grunau --- libavcodec/adpcm.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/libavcodec/adpcm.c b/libavcodec/adpcm.c index 48f44fe8dc..2081ef64d7 100644 --- a/libavcodec/adpcm.c +++ b/libavcodec/adpcm.c @@ -1001,11 +1001,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; -- cgit v1.2.3 From 355d917c0bd8163a3f1c7d4a6866dac749efdb84 Mon Sep 17 00:00:00 2001 From: Shitiz Garg Date: Wed, 14 Dec 2011 18:29:21 +0530 Subject: 4xm: Add a check in decode_i_frame to prevent buffer overreads Fixes bugzilla #135 Signed-off-by: Janne Grunau --- libavcodec/4xm.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c index ba8bb4a652..1c49ff1eba 100644 --- a/libavcodec/4xm.c +++ b/libavcodec/4xm.c @@ -653,9 +653,18 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length){ uint16_t *dst= (uint16_t*)f->current_picture.data[0]; const int stride= f->current_picture.linesize[0]>>1; const unsigned int bitstream_size= AV_RL32(buf); - const int token_count av_unused = AV_RL32(buf + bitstream_size + 8); - unsigned int prestream_size= 4*AV_RL32(buf + bitstream_size + 4); - const uint8_t *prestream= buf + bitstream_size + 12; + int token_count av_unused; + unsigned int prestream_size; + const uint8_t *prestream; + + if (length < bitstream_size + 12) { + av_log(f->avctx, AV_LOG_ERROR, "packet size too small\n"); + return AVERROR_INVALIDDATA; + } + + token_count = AV_RL32(buf + bitstream_size + 8); + prestream_size = 4 * AV_RL32(buf + bitstream_size + 4); + prestream = buf + bitstream_size + 12; if(prestream_size + bitstream_size + 12 != length || bitstream_size > (1<<26) -- cgit v1.2.3 From ad3161ec1d70291efcf40121d703ef73c0b08e5b Mon Sep 17 00:00:00 2001 From: Gaurav Narula Date: Mon, 12 Dec 2011 20:24:54 +0530 Subject: kvmc: fix invalid reads Signed-off-by: Janne Grunau --- libavcodec/kmvc.c | 82 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 16 deletions(-) diff --git a/libavcodec/kmvc.c b/libavcodec/kmvc.c index 07ca19479b..6c55863e7d 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); -- cgit v1.2.3 From 408dbbd0a7ae86b55681a1a8bd543965b28af037 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Thu, 22 Dec 2011 21:05:26 +0100 Subject: build: fix standalone compilation of Core Audio Format demuxer The demuxer depends on code from mov.c, which in turn depends on code from mov_chan.c, so link against it. --- libavformat/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavformat/Makefile b/libavformat/Makefile index c3a4c0d07b..bc89b34270 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -49,7 +49,8 @@ OBJS-$(CONFIG_BFI_DEMUXER) += bfi.o OBJS-$(CONFIG_BINK_DEMUXER) += bink.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_CAVSVIDEO_DEMUXER) += cavsvideodec.o rawdec.o OBJS-$(CONFIG_CAVSVIDEO_MUXER) += rawenc.o OBJS-$(CONFIG_CDG_DEMUXER) += cdg.o -- cgit v1.2.3 From e2c97aee393a0f74d9ce91c5389b812ffdb0b4e8 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Thu, 22 Dec 2011 21:09:23 +0100 Subject: build: fix standalone compilation of Microsoft XMV demuxer The demuxer depends on the RIFF codec tags code, so link against it. --- libavformat/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/Makefile b/libavformat/Makefile index bc89b34270..751e1c95ad 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -311,7 +311,7 @@ OBJS-$(CONFIG_WTV_DEMUXER) += wtv.o asfdec.o asf.o asfcrypt.o \ avlanguage.o mpegts.o isom.o riff.o OBJS-$(CONFIG_WV_DEMUXER) += wv.o apetag.o OBJS-$(CONFIG_XA_DEMUXER) += xa.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 -- cgit v1.2.3 From 4e8d6218c3cb8b9feffb70f8a53859540b975b36 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Thu, 22 Dec 2011 21:10:38 +0100 Subject: build: fix standalone compilation of OMA muxer The muxer depends on the id3v2 writing code, so link against it. --- libavformat/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/Makefile b/libavformat/Makefile index 751e1c95ad..ee623d7b11 100644 --- a/libavformat/Makefile +++ b/libavformat/Makefile @@ -180,7 +180,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 -- cgit v1.2.3