From 97e057ff814c253c770f011736e33c0b65c9c663 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 15 Jun 2011 00:52:43 +0200 Subject: [PATCH 1/8] swscale: Fix compilation with --disable-mmx2. Some MMX2 functions were being referenced without proper #ifdefs. --- libswscale/x86/swscale_mmx.c | 2 ++ libswscale/x86/yuv2rgb_mmx.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libswscale/x86/swscale_mmx.c b/libswscale/x86/swscale_mmx.c index c86f75df51..f855a75212 100644 --- a/libswscale/x86/swscale_mmx.c +++ b/libswscale/x86/swscale_mmx.c @@ -182,6 +182,8 @@ void ff_sws_init_swScale_mmx(SwsContext *c) if (cpu_flags & AV_CPU_FLAG_MMX) sws_init_swScale_MMX(c); +#if HAVE_MMX2 if (cpu_flags & AV_CPU_FLAG_MMX2) sws_init_swScale_MMX2(c); +#endif } diff --git a/libswscale/x86/yuv2rgb_mmx.c b/libswscale/x86/yuv2rgb_mmx.c index 439482bb71..50f475a1ba 100644 --- a/libswscale/x86/yuv2rgb_mmx.c +++ b/libswscale/x86/yuv2rgb_mmx.c @@ -72,12 +72,14 @@ SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c) c->srcFormat != PIX_FMT_YUVA420P) return NULL; - if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2) { +#if HAVE_MMX2 + if (cpu_flags & AV_CPU_FLAG_MMX2) { switch (c->dstFormat) { case PIX_FMT_RGB24: return yuv420_rgb24_MMX2; case PIX_FMT_BGR24: return yuv420_bgr24_MMX2; } } +#endif if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) { switch (c->dstFormat) { From a60466dbc3aededb0a1fab96d7fe2286f4c1a8f7 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 15 Jun 2011 00:56:31 +0200 Subject: [PATCH 2/8] swscale: Remove HAVE_MMX from files that are only compiled with MMX enabled. --- libswscale/x86/rgb2rgb.c | 2 +- libswscale/x86/yuv2rgb_mmx.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libswscale/x86/rgb2rgb.c b/libswscale/x86/rgb2rgb.c index 97c50dd636..282618c301 100644 --- a/libswscale/x86/rgb2rgb.c +++ b/libswscale/x86/rgb2rgb.c @@ -127,7 +127,7 @@ void rgb2rgb_init_x86(void) { int cpu_flags = av_get_cpu_flags(); - if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) + if (cpu_flags & AV_CPU_FLAG_MMX) rgb2rgb_init_MMX(); if (HAVE_AMD3DNOW && cpu_flags & AV_CPU_FLAG_3DNOW) rgb2rgb_init_3DNOW(); diff --git a/libswscale/x86/yuv2rgb_mmx.c b/libswscale/x86/yuv2rgb_mmx.c index 50f475a1ba..0eaea77485 100644 --- a/libswscale/x86/yuv2rgb_mmx.c +++ b/libswscale/x86/yuv2rgb_mmx.c @@ -81,7 +81,7 @@ SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c) } #endif - if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) { + if (cpu_flags & AV_CPU_FLAG_MMX) { switch (c->dstFormat) { case PIX_FMT_RGB32: if (c->srcFormat == PIX_FMT_YUVA420P) { From 3636e791ec295dcea3c1ce0206d944cd5c76a650 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Tue, 26 Apr 2011 00:27:48 +0200 Subject: [PATCH 3/8] swscale: use SwsContext for av_log when available Signed-off-by: Diego Biurrun --- libswscale/utils.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libswscale/utils.c b/libswscale/utils.c index 213bf3a043..d048b22e24 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -787,11 +787,11 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) unscaled = (srcW == dstW && srcH == dstH); if (!isSupportedIn(srcFormat)) { - av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as input pixel format\n", sws_format_name(srcFormat)); + av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n", sws_format_name(srcFormat)); return AVERROR(EINVAL); } if (!isSupportedOut(dstFormat)) { - av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output pixel format\n", sws_format_name(dstFormat)); + av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n", sws_format_name(dstFormat)); return AVERROR(EINVAL); } @@ -807,12 +807,12 @@ int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) |SWS_SPLINE |SWS_BICUBLIN); if(!i || (i & (i-1))) { - av_log(NULL, AV_LOG_ERROR, "swScaler: Exactly one scaler algorithm must be chosen\n"); + av_log(c, AV_LOG_ERROR, "Exactly one scaler algorithm must be chosen\n"); return AVERROR(EINVAL); } /* sanity check */ if (srcW<4 || srcH<1 || dstW<8 || dstH<1) { //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code - av_log(NULL, AV_LOG_ERROR, "swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", + av_log(c, AV_LOG_ERROR, "%dx%d -> %dx%d is invalid scaling dimension\n", srcW, srcH, dstW, dstH); return AVERROR(EINVAL); } From 88ff180ad66d5b12f5ee0ffbda891b467725a8d3 Mon Sep 17 00:00:00 2001 From: Mans Rullgard Date: Wed, 15 Jun 2011 12:58:00 +0100 Subject: [PATCH 4/8] ARM: update ff_h264_idct8_add4_neon for 4:4:4 changes Signed-off-by: Mans Rullgard --- libavcodec/arm/h264dsp_init_arm.c | 3 +-- libavcodec/arm/h264idct_neon.S | 41 ++++++++++++++++++------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/libavcodec/arm/h264dsp_init_arm.c b/libavcodec/arm/h264dsp_init_arm.c index 483b26ab02..c2399e50ff 100644 --- a/libavcodec/arm/h264dsp_init_arm.c +++ b/libavcodec/arm/h264dsp_init_arm.c @@ -122,8 +122,7 @@ static void ff_h264dsp_init_neon(H264DSPContext *c, const int bit_depth) c->h264_idct_dc_add = ff_h264_idct_dc_add_neon; c->h264_idct_add16 = ff_h264_idct_add16_neon; c->h264_idct_add16intra = ff_h264_idct_add16intra_neon; - //FIXME: reenable when asm is updated. - //c->h264_idct_add8 = ff_h264_idct_add8_neon; + c->h264_idct_add8 = ff_h264_idct_add8_neon; c->h264_idct8_add = ff_h264_idct8_add_neon; c->h264_idct8_dc_add = ff_h264_idct8_dc_add_neon; c->h264_idct8_add4 = ff_h264_idct8_add4_neon; diff --git a/libavcodec/arm/h264idct_neon.S b/libavcodec/arm/h264idct_neon.S index b7253542a8..3c743e1607 100644 --- a/libavcodec/arm/h264idct_neon.S +++ b/libavcodec/arm/h264idct_neon.S @@ -148,24 +148,27 @@ function ff_h264_idct_add8_neon, export=1 add r5, r1, #16*4 add r1, r2, #16*32 mov r2, r3 + mov r3, r1 ldr r6, [sp, #32] movrel r7, scan8+16 - mov ip, #7 -1: ldrb r8, [r7], #1 - ldr r0, [r5], #4 + mov r12, #0 +1: ldrb r8, [r7, r12] + ldr r0, [r5, r12, lsl #2] ldrb r8, [r6, r8] - tst ip, #4 - addne r0, r0, r4 - addeq r0, r0, r9 + add r0, r0, r4 + add r1, r3, r12, lsl #5 cmp r8, #0 ldrsh r8, [r1] adrne lr, ff_h264_idct_add_neon adreq lr, ff_h264_idct_dc_add_neon cmpeq r8, #0 blxne lr - subs ip, ip, #1 - add r1, r1, #32 - bge 1b + add r12, r12, #1 + cmp r12, #4 + moveq r12, #16 + moveq r4, r9 + cmp r12, #20 + blt 1b pop {r4-r10,pc} endfunc @@ -374,11 +377,15 @@ function ff_h264_idct8_add4_neon, export=1 endfunc .section .rodata -scan8: .byte 4+1*8, 5+1*8, 4+2*8, 5+2*8 - .byte 6+1*8, 7+1*8, 6+2*8, 7+2*8 - .byte 4+3*8, 5+3*8, 4+4*8, 5+4*8 - .byte 6+3*8, 7+3*8, 6+4*8, 7+4*8 - .byte 1+1*8, 2+1*8 - .byte 1+2*8, 2+2*8 - .byte 1+4*8, 2+4*8 - .byte 1+5*8, 2+5*8 +scan8: .byte 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8 + .byte 6+ 1*8, 7+ 1*8, 6+ 2*8, 7+ 2*8 + .byte 4+ 3*8, 5+ 3*8, 4+ 4*8, 5+ 4*8 + .byte 6+ 3*8, 7+ 3*8, 6+ 4*8, 7+ 4*8 + .byte 4+ 6*8, 5+ 6*8, 4+ 7*8, 5+ 7*8 + .byte 6+ 6*8, 7+ 6*8, 6+ 7*8, 7+ 7*8 + .byte 4+ 8*8, 5+ 8*8, 4+ 9*8, 5+ 9*8 + .byte 6+ 8*8, 7+ 8*8, 6+ 9*8, 7+ 9*8 + .byte 4+11*8, 5+11*8, 4+12*8, 5+12*8 + .byte 6+11*8, 7+11*8, 6+12*8, 7+12*8 + .byte 4+13*8, 5+13*8, 4+14*8, 5+14*8 + .byte 6+13*8, 7+13*8, 6+14*8, 7+14*8 From d7ee44024c96ebdbcd718885a77e9a07779df54c Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 15 Jun 2011 08:00:03 +0200 Subject: [PATCH 5/8] ffmpeg: don't abuse a global for passing samplerate from input to output It's broken with multiple files or audio streams. This removes the default samplerate of 44100 for raw input, hence all the FATE changes. --- ffmpeg.c | 24 +++++++++++++----------- tests/fate2.mak | 2 +- tests/lavf-regression.sh | 12 ++++++------ tests/regression-funcs.sh | 2 +- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index 04672cc831..1a00bdbb5b 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -163,7 +163,7 @@ static char *vfilters = NULL; #endif static int intra_only = 0; -static int audio_sample_rate = 44100; +static int audio_sample_rate = 0; static int64_t channel_layout = 0; #define QSCALE_NONE -99999 static float audio_qscale = QSCALE_NONE; @@ -2170,6 +2170,13 @@ static int transcode(AVFormatContext **output_files, if(!ost->fifo) goto fail; ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE); + if (!codec->sample_rate) { + codec->sample_rate = icodec->sample_rate; + if (icodec->lowres) + codec->sample_rate >>= icodec->lowres; + } + choose_sample_rate(ost->st, codec->codec); + codec->time_base = (AVRational){1, codec->sample_rate}; ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1; icodec->request_channels = codec->channels; ist->decoding_needed = 1; @@ -3268,15 +3275,9 @@ static int opt_input_file(const char *opt, const char *filename) set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_input_codecs-1]); channel_layout = dec->channel_layout; audio_channels = dec->channels; - audio_sample_rate = dec->sample_rate; audio_sample_fmt = dec->sample_fmt; if(audio_disable) st->discard= AVDISCARD_ALL; - /* Note that av_find_stream_info can add more streams, and we - * currently have no chance of setting up lowres decoding - * early enough for them. */ - if (dec->lowres) - audio_sample_rate >>= dec->lowres; break; case AVMEDIA_TYPE_VIDEO: input_codecs[nb_input_codecs-1] = avcodec_find_decoder_by_name(video_codec_name); @@ -3338,6 +3339,7 @@ static int opt_input_file(const char *opt, const char *filename) input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams; video_channel = 0; + audio_sample_rate = 0; av_freep(&video_codec_name); av_freep(&audio_codec_name); @@ -3585,7 +3587,6 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx) if (audio_stream_copy) { st->stream_copy = 1; audio_enc->channels = audio_channels; - audio_enc->sample_rate = audio_sample_rate; } else { audio_enc->codec_id = codec_id; set_context_opts(audio_enc, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec); @@ -3596,14 +3597,13 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx) } audio_enc->channels = audio_channels; audio_enc->sample_fmt = audio_sample_fmt; - audio_enc->sample_rate = audio_sample_rate; + if (audio_sample_rate) + audio_enc->sample_rate = audio_sample_rate; audio_enc->channel_layout = channel_layout; if (av_get_channel_layout_nb_channels(channel_layout) != audio_channels) audio_enc->channel_layout = 0; choose_sample_fmt(st, codec); - choose_sample_rate(st, codec); } - audio_enc->time_base= (AVRational){1, audio_sample_rate}; if (audio_language) { av_dict_set(&st->metadata, "language", audio_language, 0); av_freep(&audio_language); @@ -3889,6 +3889,8 @@ static void opt_output_file(const char *filename) set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL); + audio_sample_rate = 0; + av_freep(&forced_key_frames); uninit_opts(); init_opts(); diff --git a/tests/fate2.mak b/tests/fate2.mak index 6a9448faf1..066f9ef583 100644 --- a/tests/fate2.mak +++ b/tests/fate2.mak @@ -165,7 +165,7 @@ fate-wmapro-2ch: CMP = oneoff fate-wmapro-2ch: REF = $(SAMPLES)/wmapro/Beethovens_9th-1_small.pcm FATE_TESTS += fate-ansi -fate-ansi: CMD = framecrc -i $(SAMPLES)/ansi/TRE-IOM5.ANS -pix_fmt rgb24 +fate-ansi: CMD = framecrc -ar 44100 -i $(SAMPLES)/ansi/TRE-IOM5.ANS -pix_fmt rgb24 FATE_TESTS += fate-wmv8-drm # discard last packet to avoid fails due to overread of VC-1 decoder diff --git a/tests/lavf-regression.sh b/tests/lavf-regression.sh index 94d258334b..39e752b3c6 100755 --- a/tests/lavf-regression.sh +++ b/tests/lavf-regression.sh @@ -14,7 +14,7 @@ eval do_$test=y do_lavf() { file=${outfile}lavf.$1 - do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $2 + do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $2 do_ffmpeg_crc $file $DEC_OPTS -i $target_path/$file $3 } @@ -39,8 +39,8 @@ do_image_formats() do_audio_only() { file=${outfile}lavf.$1 - do_ffmpeg $file $DEC_OPTS $2 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $3 - do_ffmpeg_crc $file $DEC_OPTS -i $target_path/$file + do_ffmpeg $file $DEC_OPTS $2 -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $3 + do_ffmpeg_crc $file $DEC_OPTS $4 -i $target_path/$file } rm -f "$logfile" @@ -55,7 +55,7 @@ fi if [ -n "$do_rm" ] ; then file=${outfile}lavf.rm -do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 -acodec ac3_fixed +do_ffmpeg $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 -acodec ac3_fixed # broken #do_ffmpeg_crc $file -i $target_path/$file fi @@ -181,11 +181,11 @@ do_audio_only wav fi if [ -n "$do_alaw" ] ; then -do_audio_only al +do_audio_only al "" "" "-ar 44100" fi if [ -n "$do_mulaw" ] ; then -do_audio_only ul +do_audio_only ul "" "" "-ar 44100" fi if [ -n "$do_au" ] ; then diff --git a/tests/regression-funcs.sh b/tests/regression-funcs.sh index 4cf2e20fd8..e57cdf111e 100755 --- a/tests/regression-funcs.sh +++ b/tests/regression-funcs.sh @@ -114,7 +114,7 @@ do_video_encoding() do_audio_encoding() { file=${outfile}$1 - do_ffmpeg $file $DEC_OPTS -ac 2 -f s16le -i $pcm_src -ab 128k $ENC_OPTS $2 + do_ffmpeg $file $DEC_OPTS -ac 2 -ar 44100 -f s16le -i $pcm_src -ab 128k $ENC_OPTS $2 } do_audio_decoding() From 8f3e999736b7bad956becb3705661f52d986eb2d Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 15 Jun 2011 08:00:03 +0200 Subject: [PATCH 6/8] ffmpeg: don't abuse a global for passing channels from input to output It's broken with multiple files or audio streams. --- ffmpeg.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index 1a00bdbb5b..3ed578902c 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -168,7 +168,7 @@ static int64_t channel_layout = 0; #define QSCALE_NONE -99999 static float audio_qscale = QSCALE_NONE; static int audio_disable = 0; -static int audio_channels = 1; +static int audio_channels = 0; static char *audio_codec_name = NULL; static unsigned int audio_codec_tag = 0; static char *audio_language = NULL; @@ -2177,6 +2177,10 @@ static int transcode(AVFormatContext **output_files, } choose_sample_rate(ost->st, codec->codec); codec->time_base = (AVRational){1, codec->sample_rate}; + if (!codec->channels) + codec->channels = icodec->channels; + if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels) + codec->channel_layout = 0; ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1; icodec->request_channels = codec->channels; ist->decoding_needed = 1; @@ -3274,7 +3278,6 @@ static int opt_input_file(const char *opt, const char *filename) input_codecs[nb_input_codecs-1] = avcodec_find_decoder_by_name(audio_codec_name); set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_input_codecs-1]); channel_layout = dec->channel_layout; - audio_channels = dec->channels; audio_sample_fmt = dec->sample_fmt; if(audio_disable) st->discard= AVDISCARD_ALL; @@ -3340,6 +3343,7 @@ static int opt_input_file(const char *opt, const char *filename) video_channel = 0; audio_sample_rate = 0; + audio_channels = 0; av_freep(&video_codec_name); av_freep(&audio_codec_name); @@ -3586,7 +3590,6 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx) } if (audio_stream_copy) { st->stream_copy = 1; - audio_enc->channels = audio_channels; } else { audio_enc->codec_id = codec_id; set_context_opts(audio_enc, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec); @@ -3595,13 +3598,12 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx) audio_enc->flags |= CODEC_FLAG_QSCALE; audio_enc->global_quality = st->quality = FF_QP2LAMBDA * audio_qscale; } - audio_enc->channels = audio_channels; + if (audio_channels) + audio_enc->channels = audio_channels; audio_enc->sample_fmt = audio_sample_fmt; if (audio_sample_rate) audio_enc->sample_rate = audio_sample_rate; audio_enc->channel_layout = channel_layout; - if (av_get_channel_layout_nb_channels(channel_layout) != audio_channels) - audio_enc->channel_layout = 0; choose_sample_fmt(st, codec); } if (audio_language) { @@ -3890,6 +3892,7 @@ static void opt_output_file(const char *filename) set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL); audio_sample_rate = 0; + audio_channels = 0; av_freep(&forced_key_frames); uninit_opts(); From a6286bda0956bfe15b4e1a9f96e1689666e1d866 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Wed, 15 Jun 2011 08:00:03 +0200 Subject: [PATCH 7/8] ffmpeg: don't abuse a global for passing framerate from input to output It's broken with multiple files or video streams. --- ffmpeg.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ffmpeg.c b/ffmpeg.c index 3ed578902c..1b31d5655f 100644 --- a/ffmpeg.c +++ b/ffmpeg.c @@ -271,6 +271,7 @@ typedef struct AVOutputStream { int resample_height; int resample_width; int resample_pix_fmt; + AVRational frame_rate; float frame_aspect_ratio; @@ -2226,6 +2227,14 @@ static int transcode(AVFormatContext **output_files, ost->encoding_needed = 1; ist->decoding_needed = 1; + if (!ost->frame_rate.num) + ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational){25,1}; + if (codec->codec && codec->codec->supported_framerates && !force_fps) { + int idx = av_find_nearest_q_idx(ost->frame_rate, codec->codec->supported_framerates); + ost->frame_rate = codec->codec->supported_framerates[idx]; + } + codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num}; + #if CONFIG_AVFILTER if (configure_video_filters(ist, ost)) { fprintf(stderr, "Error opening filters!\n"); @@ -3308,9 +3317,6 @@ static int opt_input_file(const char *opt, const char *filename) (float)rfps / rfps_base, rfps, rfps_base); } - /* update the current frame rate to match the stream frame rate */ - frame_rate.num = rfps; - frame_rate.den = rfps_base; if(video_disable) st->discard= AVDISCARD_ALL; @@ -3342,6 +3348,7 @@ static int opt_input_file(const char *opt, const char *filename) input_files[nb_input_files - 1].ist_index = nb_input_streams - ic->nb_streams; video_channel = 0; + frame_rate = (AVRational){0, 0}; audio_sample_rate = 0; audio_channels = 0; @@ -3455,16 +3462,12 @@ static void new_video_stream(AVFormatContext *oc, int file_idx) } else { const char *p; int i; - AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1}; + if (frame_rate.num) + ost->frame_rate = frame_rate; video_enc->codec_id = codec_id; set_context_opts(video_enc, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec); - if (codec && codec->supported_framerates && !force_fps) - fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)]; - video_enc->time_base.den = fps.num; - video_enc->time_base.num = fps.den; - video_enc->width = frame_width; video_enc->height = frame_height; video_enc->pix_fmt = frame_pix_fmt; @@ -3891,6 +3894,7 @@ static void opt_output_file(const char *filename) set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL); + frame_rate = (AVRational){0, 0}; audio_sample_rate = 0; audio_channels = 0; From b203f65451646b1555d458a3601159f7d89a3397 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 14 Jun 2011 13:45:38 -0400 Subject: [PATCH 8/8] ac3enc: use correct alignment and length in channel coupling dsp functions. This fixes a segfault when using the C version of ac3dsp.float_to_fixed24(). --- libavcodec/ac3enc_template.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c index 0547165aaf..f6248a82c9 100644 --- a/libavcodec/ac3enc_template.c +++ b/libavcodec/ac3enc_template.c @@ -134,36 +134,38 @@ void AC3_NAME(apply_channel_coupling)(AC3EncodeContext *s) LOCAL_ALIGNED_16(int32_t, fixed_cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]); int blk, ch, bnd, i, j; CoefSumType energy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}}; - int num_cpl_coefs = s->num_cpl_subbands * 12; + int cpl_start, num_cpl_coefs; memset(cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords)); memset(fixed_cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*fixed_cpl_coords)); + /* align start to 16-byte boundary. align length to multiple of 32. + note: coupling start bin % 4 will always be 1 */ + cpl_start = s->start_freq[CPL_CH] - 1; + num_cpl_coefs = FFALIGN(s->num_cpl_subbands * 12 + 1, 32); + cpl_start = FFMIN(256, cpl_start + num_cpl_coefs) - num_cpl_coefs; + /* calculate coupling channel from fbw channels */ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { AC3Block *block = &s->blocks[blk]; - CoefType *cpl_coef = &block->mdct_coef[CPL_CH][s->start_freq[CPL_CH]]; + CoefType *cpl_coef = &block->mdct_coef[CPL_CH][cpl_start]; if (!block->cpl_in_use) continue; - memset(cpl_coef-1, 0, (num_cpl_coefs+4) * sizeof(*cpl_coef)); + memset(cpl_coef, 0, num_cpl_coefs * sizeof(*cpl_coef)); for (ch = 1; ch <= s->fbw_channels; ch++) { - CoefType *ch_coef = &block->mdct_coef[ch][s->start_freq[CPL_CH]]; + CoefType *ch_coef = &block->mdct_coef[ch][cpl_start]; if (!block->channel_in_cpl[ch]) continue; for (i = 0; i < num_cpl_coefs; i++) cpl_coef[i] += ch_coef[i]; } - /* note: coupling start bin % 4 will always be 1 and num_cpl_coefs - will always be a multiple of 12, so we need to subtract 1 from - the start and add 4 to the length when using optimized - functions which require 16-byte alignment. */ /* coefficients must be clipped to +/- 1.0 in order to be encoded */ - s->dsp.vector_clipf(cpl_coef-1, cpl_coef-1, -1.0f, 1.0f, num_cpl_coefs+4); + s->dsp.vector_clipf(cpl_coef, cpl_coef, -1.0f, 1.0f, num_cpl_coefs); /* scale coupling coefficients from float to 24-bit fixed-point */ - s->ac3dsp.float_to_fixed24(&block->fixed_coef[CPL_CH][s->start_freq[CPL_CH]-1], - cpl_coef-1, num_cpl_coefs+4); + s->ac3dsp.float_to_fixed24(&block->fixed_coef[CPL_CH][cpl_start], + cpl_coef, num_cpl_coefs); } /* calculate energy in each band in coupling channel and each fbw channel */