From 3dbc777c7f30409b844c38641941d5e7f90af97e Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Mon, 17 Sep 2012 23:56:32 +0100 Subject: [PATCH 1/9] build: support some non-standard ar variants This adds support for the TI and Microsoft (lib.exe) variants of the ar utility. Signed-off-by: Mans Rullgard --- configure | 13 +++++++++++++ library.mak | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 2d400c0ced..8a7eaf4f31 100755 --- a/configure +++ b/configure @@ -2415,6 +2415,17 @@ if [ -z "$CC_DEPFLAGS" ] && [ "$dep_cc" != "$cc" ]; then DEPCCFLAGS=$_flags fi +if $ar 2>&1 | grep -q Microsoft; then + arflags="-nologo" + ar_o='-out:$@' +elif $ar 2>&1 | grep -q 'Texas Instruments'; then + arflags="rq" + ar_o='$@' +else + arflags="rc" + ar_o='$@' +fi + add_cflags $extra_cflags add_asflags $extra_cflags @@ -3645,6 +3656,8 @@ DEPASFLAGS=$DEPASFLAGS \$(CPPFLAGS) YASM=$yasmexe DEPYASM=$yasmexe AR=$ar +ARFLAGS=$arflags +AR_O=$ar_o RANLIB=$ranlib LN_S=$ln_s CPPFLAGS=$CPPFLAGS diff --git a/library.mak b/library.mak index d89050e84a..19f05f9e87 100644 --- a/library.mak +++ b/library.mak @@ -25,7 +25,7 @@ $(TESTOBJS): CPPFLAGS += -DTEST $(SUBDIR)$(LIBNAME): $(OBJS) $(RM) $@ - $(AR) rc $@ $^ $(EXTRAOBJS) + $(AR) $(ARFLAGS) $(AR_O) $^ $(EXTRAOBJS) $(RANLIB) $@ install-headers: install-lib$(NAME)-headers install-lib$(NAME)-pkgconfig From ac3a9b51f77e54300827c338df0fd16251c93a73 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Tue, 18 Sep 2012 00:10:29 +0100 Subject: [PATCH 2/9] configure: msvc: default to 'lib' as 'ar' tool Signed-off-by: Mans Rullgard --- configure | 1 + 1 file changed, 1 insertion(+) diff --git a/configure b/configure index 8a7eaf4f31..49e9ecf040 100755 --- a/configure +++ b/configure @@ -2045,6 +2045,7 @@ case "$toolchain" in cc_default="c99wrap cl" ld_default="c99wrap link" nm_default="dumpbin -symbols" + ar_default="lib" ;; ?*) die "Unknown toolchain $toolchain" From 32c7589bb7ce6b8be733aa88e4786955c7c3a638 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Wed, 19 Sep 2012 19:39:52 +0200 Subject: [PATCH 3/9] mpegvideo: release frame buffers before freeing them Fixes triggering an assert in avcodec_default_release_buffer() introduced in 1b3439b30. --- libavcodec/mpegvideo.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index e2e5276c83..4682ab1121 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -1104,14 +1104,15 @@ void ff_MPV_common_end(MpegEncContext *s) av_freep(&s->reordered_input_picture); av_freep(&s->dct_offset); - free_context_frame(s); - if (s->picture && !s->avctx->internal->is_copy) { for (i = 0; i < s->picture_count; i++) { free_picture(s, &s->picture[i]); } } av_freep(&s->picture); + + free_context_frame(s); + s->context_initialized = 0; s->last_picture_ptr = s->next_picture_ptr = From 01fc5d6609e31539684785295d6c10b84d70b215 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sat, 8 Sep 2012 15:56:52 +0200 Subject: [PATCH 4/9] mpegvideo: check ff_find_unused_picture() return value for errors --- libavcodec/mpegvideo.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 4682ab1121..f9f5c5263f 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -1341,6 +1341,10 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) pic = s->current_picture_ptr; } else { i = ff_find_unused_picture(s, 0); + if (i < 0) { + av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n"); + return i; + } pic = &s->picture[i]; } @@ -1404,6 +1408,10 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) /* Allocate a dummy frame */ i = ff_find_unused_picture(s, 0); + if (i < 0) { + av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n"); + return i; + } s->last_picture_ptr = &s->picture[i]; if (ff_alloc_picture(s, s->last_picture_ptr, 0) < 0) { s->last_picture_ptr = NULL; @@ -1418,6 +1426,10 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) s->pict_type == AV_PICTURE_TYPE_B) { /* Allocate a dummy frame */ i = ff_find_unused_picture(s, 0); + if (i < 0) { + av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n"); + return i; + } s->next_picture_ptr = &s->picture[i]; if (ff_alloc_picture(s, s->next_picture_ptr, 0) < 0) { s->next_picture_ptr = NULL; From 8701f4f8e8a7aa71c39f0917472d22bf6a1f0f43 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Tue, 18 Sep 2012 15:48:14 +0200 Subject: [PATCH 5/9] mpeg4: support frame parameter changes with frame-mt Adds a flag context_reinit to MpegEncContext to relieable keep track of frame parameter changes which require a context reinitialization. This is required for broken inputs which change the frame size but error out before the context can be reinitialized. --- libavcodec/h263dec.c | 25 +++++++++++++------------ libavcodec/mpeg4videodec.c | 3 +++ libavcodec/mpegvideo.c | 9 +++++++++ libavcodec/mpegvideo.h | 4 ++++ 4 files changed, 29 insertions(+), 12 deletions(-) diff --git a/libavcodec/h263dec.c b/libavcodec/h263dec.c index 8e6085beeb..ba7fb8ae12 100644 --- a/libavcodec/h263dec.c +++ b/libavcodec/h263dec.c @@ -434,13 +434,6 @@ retry: if (ret < 0){ av_log(s->avctx, AV_LOG_ERROR, "header damaged\n"); return -1; - } else if ((s->width != avctx->coded_width || - s->height != avctx->coded_height || - (s->width + 15) >> 4 != s->mb_width || - (s->height + 15) >> 4 != s->mb_height) && - (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME))) { - av_log_missing_feature(s->avctx, "Width/height/bit depth/chroma idc changing with threads is", 0); - return AVERROR_PATCHWELCOME; // width / height changed during parallelized decoding } avctx->has_b_frames= !s->low_delay; @@ -577,21 +570,29 @@ retry: /* FIXME: By the way H263 decoder is evolving it should have */ /* an H263EncContext */ - if ( s->width != avctx->coded_width - || s->height != avctx->coded_height) { - /* H.263 could change picture size any time */ + if (!avctx->coded_width || !avctx->coded_height) { ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat s->parse_context.buffer=0; ff_MPV_common_end(s); s->parse_context= pc; - } - if (!s->context_initialized) { avcodec_set_dimensions(avctx, s->width, s->height); goto retry; } + if (s->width != avctx->coded_width || + s->height != avctx->coded_height || + s->context_reinit) { + /* H.263 could change picture size any time */ + s->context_reinit = 0; + + avcodec_set_dimensions(avctx, s->width, s->height); + + if ((ret = ff_MPV_common_frame_size_change(s))) + return ret; + } + if((s->codec_id==AV_CODEC_ID_H263 || s->codec_id==AV_CODEC_ID_H263P || s->codec_id == AV_CODEC_ID_H263I)) s->gob_index = ff_h263_get_gob_height(s); diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index 27cae9f846..4a4998cdaa 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -1600,6 +1600,9 @@ static int decode_vol_header(MpegEncContext *s, GetBitContext *gb){ height = get_bits(gb, 13); skip_bits1(gb); /* marker */ if(width && height && !(s->width && s->codec_tag == AV_RL32("MP4S"))){ /* they should be non zero but who knows ... */ + if (s->width && s->height && + (s->width != width || s->height != height)) + s->context_reinit = 1; s->width = width; s->height = height; } diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index f9f5c5263f..50331356fe 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -550,6 +550,15 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, ff_MPV_common_init(s); } + if (s->height != s1->height || s->width != s1->width || s->context_reinit) { + int err; + s->context_reinit = 0; + s->height = s1->height; + s->width = s1->width; + if ((err = ff_MPV_common_frame_size_change(s)) < 0) + return err; + } + s->avctx->coded_height = s1->avctx->coded_height; s->avctx->coded_width = s1->avctx->coded_width; s->avctx->width = s1->avctx->width; diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 88a1059102..4c220ecb0a 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -703,6 +703,10 @@ typedef struct MpegEncContext { /* temp buffers for rate control */ float *cplx_tab, *bits_tab; + + /* flag to indicate a reinitialization is required, e.g. after + * a frame size change */ + int context_reinit; } MpegEncContext; #define REBASE_PICTURE(pic, new_ctx, old_ctx) (pic ? \ From 298ed797e1f9b71d154d34d19177a2c8bef587e1 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 18 Sep 2012 16:45:09 -0700 Subject: [PATCH 6/9] tiffenc: Add support for little endian RGB48 and GRAY16 --- libavcodec/tiffenc.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c index 1bf7adcd11..96a6f0b1f3 100644 --- a/libavcodec/tiffenc.c +++ b/libavcodec/tiffenc.c @@ -214,7 +214,7 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt, uint32_t *strip_offsets = NULL; int bytes_per_row; uint32_t res[2] = { 72, 1 }; // image resolution (72/1) - static const uint16_t bpp_tab[] = { 8, 8, 8, 8 }; + uint16_t bpp_tab[] = { 8, 8, 8, 8 }; int ret; int is_yuv = 0; uint8_t *yuv_line = NULL; @@ -232,7 +232,22 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt, s->subsampling[0] = 1; s->subsampling[1] = 1; + s->bpp_tab_size = 0; switch (avctx->pix_fmt) { + case PIX_FMT_RGB48LE: + s->bpp = 48; + s->photometric_interpretation = 2; + s->bpp_tab_size = 3; + for (i = 0; i < s->bpp_tab_size; i++) { + bpp_tab[i] = 16; + } + break; + case PIX_FMT_GRAY16LE: + s->bpp = 16; + s->photometric_interpretation = 1; + s->bpp_tab_size = 1; + bpp_tab[0] = 16; + break; case PIX_FMT_RGB24: s->bpp = 24; s->photometric_interpretation = 2; @@ -272,7 +287,7 @@ static int encode_frame(AVCodecContext * avctx, AVPacket *pkt, "This colors format is not supported\n"); return -1; } - if (!is_yuv) + if (!s->bpp_tab_size) s->bpp_tab_size = (s->bpp >> 3); if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE || s->compr == TIFF_LZW) @@ -474,7 +489,8 @@ AVCodec ff_tiff_encoder = { .priv_data_size = sizeof(TiffEncoderContext), .encode2 = encode_frame, .pix_fmts = (const enum PixelFormat[]) { - PIX_FMT_RGB24, PIX_FMT_PAL8, PIX_FMT_GRAY8, + PIX_FMT_RGB24, PIX_FMT_RGB48LE, PIX_FMT_PAL8, + PIX_FMT_GRAY8, PIX_FMT_GRAY16LE, PIX_FMT_MONOBLACK, PIX_FMT_MONOWHITE, PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_YUV410P, PIX_FMT_YUV411P, From df6c3f9fb3b983e790f6d6d46c5fd26d757d9093 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 18 Sep 2012 17:46:48 -0700 Subject: [PATCH 7/9] tiffdec: Add support for GRAY16LE. Tested with the GraphicsMagick TIFF archive and Libav generated files. --- libavcodec/tiff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index f60c65ec7d..2a48050678 100644 --- a/libavcodec/tiff.c +++ b/libavcodec/tiff.c @@ -259,7 +259,7 @@ static int init_image(TiffContext *s) s->avctx->pix_fmt = PIX_FMT_RGB24; break; case 161: - s->avctx->pix_fmt = PIX_FMT_GRAY16BE; + s->avctx->pix_fmt = s->le ? PIX_FMT_GRAY16LE : PIX_FMT_GRAY16BE; break; case 324: s->avctx->pix_fmt = PIX_FMT_RGBA; From cd4739c4f2d7ed56405f40dffe6254f6275e6e41 Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Thu, 12 Jul 2012 13:38:50 +0200 Subject: [PATCH 8/9] matroska: honor error_recognition on unknown doctypes --- libavformat/matroskadec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 7792b4c52a..95130fc4df 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1346,6 +1346,10 @@ static int matroska_read_header(AVFormatContext *s) break; if (i >= FF_ARRAY_ELEMS(matroska_doctypes)) { av_log(s, AV_LOG_WARNING, "Unknown EBML doctype '%s'\n", ebml.doctype); + if (matroska->ctx->error_recognition & AV_EF_EXPLODE) { + ebml_free(ebml_syntax, &ebml); + return AVERROR_INVALIDDATA; + } } ebml_free(ebml_syntax, &ebml); From 581281e242609a222233a2e5538b89dfb88fb18e Mon Sep 17 00:00:00 2001 From: Luca Barbato Date: Fri, 14 Sep 2012 18:39:58 +0200 Subject: [PATCH 9/9] matroskadec: check realloc in lzo encoding Make all the compression encodings behave the same way. --- libavformat/matroskadec.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 95130fc4df..bb505c27ab 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -999,7 +999,11 @@ static int matroska_decode_buffer(uint8_t** buf, int* buf_size, case MATROSKA_TRACK_ENCODING_COMP_LZO: do { olen = pkt_size *= 3; - pkt_data = av_realloc(pkt_data, pkt_size+AV_LZO_OUTPUT_PADDING); + newpktdata = av_realloc(pkt_data, pkt_size + AV_LZO_OUTPUT_PADDING); + if (!newpktdata) { + goto failed; + } + pkt_data = newpktdata; result = av_lzo1x_decode(pkt_data, &olen, data, &isize); } while (result==AV_LZO_OUTPUT_FULL && pkt_size<10000000); if (result)