From 27c3f9c03e1d0290dfd6e185b75acdf463bdb7b2 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 30 Sep 2012 22:14:10 -0400 Subject: [PATCH 1/9] libspeexdec: set channel_layout --- libavcodec/libspeexdec.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c index b9d9149ee2..21c9d05428 100644 --- a/libavcodec/libspeexdec.c +++ b/libavcodec/libspeexdec.c @@ -22,8 +22,10 @@ #include #include #include -#include "avcodec.h" + +#include "libavutil/audioconvert.h" #include "libavutil/common.h" +#include "avcodec.h" typedef struct { AVFrame frame; @@ -76,6 +78,8 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx) "Decoding as stereo.\n", avctx->channels); avctx->channels = 2; } + avctx->channel_layout = avctx->channels == 2 ? AV_CH_LAYOUT_STEREO : + AV_CH_LAYOUT_MONO; speex_bits_init(&s->bits); s->dec_state = speex_decoder_init(mode); From 892695c851a427beef314841ea54b01be40dd0e8 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 30 Sep 2012 22:45:55 -0400 Subject: [PATCH 2/9] libspeexdec: simplify setting of frame_size --- libavcodec/libspeexdec.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c index 21c9d05428..d1180931d5 100644 --- a/libavcodec/libspeexdec.c +++ b/libavcodec/libspeexdec.c @@ -49,7 +49,6 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx) avctx->sample_fmt = AV_SAMPLE_FMT_S16; if (s->header) { avctx->channels = s->header->nb_channels; - s->frame_size = s->header->frame_size; spx_mode = s->header->mode; } else { switch (avctx->sample_rate) { @@ -71,6 +70,7 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx) return AVERROR_INVALIDDATA; } avctx->sample_rate = 8000 << spx_mode; + s->frame_size = 160 << spx_mode; if (avctx->channels < 1 || avctx->channels > 2) { /* libspeex can handle mono or stereo if initialized as stereo */ @@ -88,10 +88,6 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx) return -1; } - if (!s->header) { - speex_decoder_ctl(s->dec_state, SPEEX_GET_FRAME_SIZE, &s->frame_size); - } - if (avctx->channels == 2) { SpeexCallback callback; callback.callback_id = SPEEX_INBAND_STEREO; From 908e22b93a9532948d62e43b700d5c91ea37db2a Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 30 Sep 2012 23:09:19 -0400 Subject: [PATCH 3/9] libspeexdec: move the SpeexHeader from LibSpeexContext to where it is used --- libavcodec/libspeexdec.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c index d1180931d5..1916fea2d1 100644 --- a/libavcodec/libspeexdec.c +++ b/libavcodec/libspeexdec.c @@ -32,7 +32,6 @@ typedef struct { SpeexBits bits; SpeexStereoState stereo; void *dec_state; - SpeexHeader *header; int frame_size; } LibSpeexContext; @@ -43,13 +42,13 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx) const SpeexMode *mode; int spx_mode; - if (avctx->extradata_size >= 80) - s->header = speex_packet_to_header(avctx->extradata, avctx->extradata_size); - avctx->sample_fmt = AV_SAMPLE_FMT_S16; - if (s->header) { - avctx->channels = s->header->nb_channels; - spx_mode = s->header->mode; + if (avctx->extradata && avctx->extradata_size >= 80) { + SpeexHeader *header = speex_packet_to_header(avctx->extradata, + avctx->extradata_size); + avctx->channels = header->nb_channels; + spx_mode = header->mode; + speex_header_free(header); } else { switch (avctx->sample_rate) { case 8000: spx_mode = 0; break; @@ -153,7 +152,6 @@ static av_cold int libspeex_decode_close(AVCodecContext *avctx) { LibSpeexContext *s = avctx->priv_data; - speex_header_free(s->header); speex_bits_destroy(&s->bits); speex_decoder_destroy(s->dec_state); From 45e5d0c3ac0d144cf4dc7fb3d852ee05814bbd2b Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Sun, 30 Sep 2012 23:11:43 -0400 Subject: [PATCH 4/9] libspeexdec: properly handle DTX for multiple frames-per-packet --- libavcodec/libspeexdec.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c index 1916fea2d1..760bfe2e49 100644 --- a/libavcodec/libspeexdec.c +++ b/libavcodec/libspeexdec.c @@ -119,10 +119,12 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data, } output = (int16_t *)s->frame.data[0]; - /* if there is not enough data left for the smallest possible frame, - reset the libspeex buffer using the current packet, otherwise ignore - the current packet and keep decoding frames from the libspeex buffer. */ - if (speex_bits_remaining(&s->bits) < 43) { + /* if there is not enough data left for the smallest possible frame or the + next 5 bits are a terminator code, reset the libspeex buffer using the + current packet, otherwise ignore the current packet and keep decoding + frames from the libspeex buffer. */ + if (speex_bits_remaining(&s->bits) < 5 || + speex_bits_peek_unsigned(&s->bits, 5) == 0x1F) { /* check for flush packet */ if (!buf || !buf_size) { *got_frame_ptr = 0; From 1481e198251192c9801d4e7818c3c23bc217f705 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Wed, 3 Oct 2012 21:41:52 +0200 Subject: [PATCH 5/9] mpegvideo: set extended_data in ff_update_duplicate_context() AVFrame.extended_data has to reset to the AVFrame.data of the current thread context after copying the frame contents. Fixes crashes with frame-threading after 2bc0de38584. --- libavcodec/mpegvideo.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 592b4f2b2e..ed40c10583 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -531,6 +531,7 @@ void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src) int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { + int i; MpegEncContext *s = dst->priv_data, *s1 = src->priv_data; if (dst == src || !s1->context_initialized) @@ -572,6 +573,10 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, memcpy(&s->last_picture, &s1->last_picture, (char *) &s1->last_picture_ptr - (char *) &s1->last_picture); + // reset s->picture[].f.extended_data to s->picture[].f.data + for (i = 0; i < s->picture_count; i++) + s->picture[i].f.extended_data = s->picture[i].f.data; + s->last_picture_ptr = REBASE_PICTURE(s1->last_picture_ptr, s, s1); s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, s, s1); s->next_picture_ptr = REBASE_PICTURE(s1->next_picture_ptr, s, s1); From 769ed3057efec12820f9245f6ad3fa5bcfc95c5e Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Mon, 9 May 2011 16:05:29 +0200 Subject: [PATCH 6/9] h264probe: Don't error out on bits that no longer are reserved MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Martin Storsjö --- libavformat/h264dec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libavformat/h264dec.c b/libavformat/h264dec.c index 807008621a..0c85bae6d4 100644 --- a/libavformat/h264dec.c +++ b/libavformat/h264dec.c @@ -54,7 +54,7 @@ static int h264_probe(AVProbeData *p) case 1: sli++; break; case 5: idr++; break; case 7: - if(p->buf[i+2]&0x0F) + if (p->buf[i + 2] & 0x03) return 0; sps++; break; From c9df48909e03031aeb90facf9f307f3103691792 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 3 Oct 2012 17:26:16 -0400 Subject: [PATCH 7/9] libspeexdec: handle NULL return value from speex_packet_to_header() This will happen when the extradata is not a valid Speex header. --- libavcodec/libspeexdec.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/libavcodec/libspeexdec.c b/libavcodec/libspeexdec.c index 760bfe2e49..0c93f05a1b 100644 --- a/libavcodec/libspeexdec.c +++ b/libavcodec/libspeexdec.c @@ -40,12 +40,17 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx) { LibSpeexContext *s = avctx->priv_data; const SpeexMode *mode; + SpeexHeader *header = NULL; int spx_mode; avctx->sample_fmt = AV_SAMPLE_FMT_S16; if (avctx->extradata && avctx->extradata_size >= 80) { - SpeexHeader *header = speex_packet_to_header(avctx->extradata, - avctx->extradata_size); + header = speex_packet_to_header(avctx->extradata, + avctx->extradata_size); + if (!header) + av_log(avctx, AV_LOG_WARNING, "Invalid Speex header\n"); + } + if (header) { avctx->channels = header->nb_channels; spx_mode = header->mode; speex_header_free(header); From cd15b7c03d8df29d4c69b0620cf27d4a8c9dfb65 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 3 Oct 2012 07:54:45 +0200 Subject: [PATCH 8/9] samplefmt: make av_samples_alloc() initialize the data to silence. Right now the buffer is zeroed, which does not represent silence for U8(P). --- libavutil/samplefmt.c | 5 ++++- libavutil/samplefmt.h | 1 + libavutil/version.h | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c index 102376ae38..4f6dfd7889 100644 --- a/libavutil/samplefmt.c +++ b/libavutil/samplefmt.c @@ -174,7 +174,7 @@ int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels, if (size < 0) return size; - buf = av_mallocz(size); + buf = av_malloc(size); if (!buf) return AVERROR(ENOMEM); @@ -184,6 +184,9 @@ int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels, av_free(buf); return size; } + + av_samples_set_silence(audio_data, 0, nb_samples, nb_channels, sample_fmt); + return 0; } diff --git a/libavutil/samplefmt.h b/libavutil/samplefmt.h index 445856de73..0641c56bc5 100644 --- a/libavutil/samplefmt.h +++ b/libavutil/samplefmt.h @@ -182,6 +182,7 @@ int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, * Allocate a samples buffer for nb_samples samples, and fill data pointers and * linesize accordingly. * The allocated samples buffer can be freed by using av_freep(&audio_data[0]) + * Allocated data will be initialized to silence. * * @see enum AVSampleFormat * The documentation for AVSampleFormat describes the data layout. diff --git a/libavutil/version.h b/libavutil/version.h index 6342baefb2..b77ab1a8fc 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -38,7 +38,7 @@ #define LIBAVUTIL_VERSION_MAJOR 51 #define LIBAVUTIL_VERSION_MINOR 41 -#define LIBAVUTIL_VERSION_MICRO 0 +#define LIBAVUTIL_VERSION_MICRO 1 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \ From ab35ec29a4071871934856c00da7d6ebcc0c095b Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 30 Sep 2012 09:49:53 +0200 Subject: [PATCH 9/9] vf_overlay: get rid of pointless messing with timebase. Output frames correspond 1:1 to input frames on the main input. So use the main input timebase for output. --- libavfilter/vf_overlay.c | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c index 6dd9be4975..74c356e215 100644 --- a/libavfilter/vf_overlay.c +++ b/libavfilter/vf_overlay.c @@ -181,24 +181,10 @@ fail: static int config_output(AVFilterLink *outlink) { AVFilterContext *ctx = outlink->src; - int exact; - // common timebase computation: - AVRational tb1 = ctx->inputs[MAIN ]->time_base; - AVRational tb2 = ctx->inputs[OVERLAY]->time_base; - AVRational *tb = &ctx->outputs[0]->time_base; - exact = av_reduce(&tb->num, &tb->den, - av_gcd((int64_t)tb1.num * tb2.den, - (int64_t)tb2.num * tb1.den), - (int64_t)tb1.den * tb2.den, INT_MAX); - av_log(ctx, AV_LOG_VERBOSE, - "main_tb:%d/%d overlay_tb:%d/%d -> tb:%d/%d exact:%d\n", - tb1.num, tb1.den, tb2.num, tb2.den, tb->num, tb->den, exact); - if (!exact) - av_log(ctx, AV_LOG_WARNING, - "Timestamp conversion inexact, timestamp information loss may occurr\n"); outlink->w = ctx->inputs[MAIN]->w; outlink->h = ctx->inputs[MAIN]->h; + outlink->time_base = ctx->inputs[MAIN]->time_base; return 0; } @@ -217,10 +203,9 @@ static int start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) if (!outpicref) return AVERROR(ENOMEM); - outpicref->pts = av_rescale_q(outpicref->pts, ctx->inputs[MAIN]->time_base, - ctx->outputs[0]->time_base); - - if (!over->overpicref || over->overpicref->pts < outpicref->pts) { + if (!over->overpicref || + av_compare_ts(over->overpicref->pts, inlink->time_base, + outpicref->pts, ctx->inputs[OVERLAY]->time_base) < 0) { AVFilterBufferRef *old = over->overpicref; over->overpicref = NULL; ff_request_frame(ctx->inputs[OVERLAY]); @@ -242,8 +227,6 @@ static int start_frame_overlay(AVFilterLink *inlink, AVFilterBufferRef *inpicref inlink->cur_buf = NULL; avfilter_unref_bufferp(&over->overpicref); over->overpicref = inpicref; - over->overpicref->pts = av_rescale_q(inpicref->pts, ctx->inputs[OVERLAY]->time_base, - ctx->outputs[0]->time_base); return 0; }