From 327747de15be919f8060e12a2e82afa37500629f Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 18 Oct 2012 23:11:20 -0400 Subject: [PATCH 1/7] atrac3: simplify MDCT window calculation --- libavcodec/atrac3.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 9e0f27332e..76e251ba1c 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -177,19 +177,16 @@ static int decode_bytes(const uint8_t *input, uint8_t *out, int bytes) static av_cold void init_atrac3_window(void) { - float enc_window[256]; - int i; + int i, j; /* generate the mdct window, for details see * http://wiki.multimedia.cx/index.php?title=RealAudio_atrc#Windows */ - for (i = 0; i < 256; i++) - enc_window[i] = (sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0) * 0.5; - - for (i = 0; i < 256; i++) { - mdct_window[i] = enc_window[i] / - (enc_window[ i] * enc_window[ i] + - enc_window[255 - i] * enc_window[255 - i]); - mdct_window[511 - i] = mdct_window[i]; + for (i = 0, j = 255; i < 128; i++, j--) { + float wi = sin(((i + 0.5) / 256.0 - 0.5) * M_PI) + 1.0; + float wj = sin(((j + 0.5) / 256.0 - 0.5) * M_PI) + 1.0; + float w = 0.5 * (wi * wi + wj * wj); + mdct_window[i] = mdct_window[511 - i] = wi / w; + mdct_window[j] = mdct_window[511 - j] = wj / w; } } From 89a6c32bc1bc32a50c8d09e39389d1e1556b7a76 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 18 Oct 2012 23:25:44 -0400 Subject: [PATCH 2/7] atrac3: use sizeof(variable) instead of sizeof(type) --- libavcodec/atrac3.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 76e251ba1c..0046c72e03 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -311,13 +311,13 @@ static int decode_spectrum(GetBitContext *gb, float *output) output[first] = mantissas[j] * scale_factor; } else { /* this subband was not coded, so zero the entire subband */ - memset(output + first, 0, subband_size * sizeof(float)); + memset(output + first, 0, subband_size * sizeof(*output)); } } /* clear the subbands that were not coded */ first = subband_tab[i]; - memset(output + first, 0, (SAMPLES_PER_FRAME - first) * sizeof(float)); + memset(output + first, 0, (SAMPLES_PER_FRAME - first) * sizeof(*output)); return num_subbands; } @@ -494,7 +494,7 @@ static void gain_compensate_and_overlap(float *input, float *prev, } /* Delay for the overlapping part. */ - memcpy(prev, &input[256], 256 * sizeof(float)); + memcpy(prev, &input[256], 256 * sizeof(*prev)); } /* @@ -684,7 +684,7 @@ static int decode_channel_sound_unit(ATRAC3Context *q, GetBitContext *gb, if (band <= num_bands) imlt(q, &snd->spectrum[band * 256], snd->imdct_buf, band & 1); else - memset(snd->imdct_buf, 0, 512 * sizeof(float)); + memset(snd->imdct_buf, 0, 512 * sizeof(*snd->imdct_buf)); /* gain compensation and overlapping */ gain_compensate_and_overlap(snd->imdct_buf, @@ -742,7 +742,8 @@ static int decode_frame(AVCodecContext *avctx, const uint8_t *databuf, init_get_bits(&q->gb, ptr1, avctx->block_align * 8); /* Fill the Weighting coeffs delay buffer */ - memmove(q->weighting_delay, &q->weighting_delay[2], 4 * sizeof(int)); + memmove(q->weighting_delay, &q->weighting_delay[2], + 4 * sizeof(*q->weighting_delay)); q->weighting_delay[4] = get_bits1(&q->gb); q->weighting_delay[5] = get_bits(&q->gb, 3); @@ -982,7 +983,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) avpriv_float_dsp_init(&q->fdsp, avctx->flags & CODEC_FLAG_BITEXACT); ff_fmt_convert_init(&q->fmt_conv, avctx); - q->units = av_mallocz(sizeof(ChannelUnit) * avctx->channels); + q->units = av_mallocz(sizeof(*q->units) * avctx->channels); if (!q->units) { atrac3_decode_close(avctx); return AVERROR(ENOMEM); From 808686fc1ea66c33c585dbc5d891bacbd983a27d Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 18 Oct 2012 23:34:40 -0400 Subject: [PATCH 3/7] atrac3: remove unused ATRAC3Context field, sample_rate --- libavcodec/atrac3.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 0046c72e03..66c672a519 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -90,7 +90,6 @@ typedef struct ATRAC3Context { //@{ /** stream data */ int coding_mode; - int sample_rate; ChannelUnit *units; //@} @@ -869,9 +868,6 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) const uint8_t *edata_ptr = avctx->extradata; ATRAC3Context *q = avctx->priv_data; - /* Take data from the AVCodecContext (RM container). */ - q->sample_rate = avctx->sample_rate; - if (avctx->channels <= 0 || avctx->channels > 2) { av_log(avctx, AV_LOG_ERROR, "Channel configuration error!\n"); return AVERROR(EINVAL); From a1f4cd371ac7ff9fea6f0d3072fc886380160844 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Thu, 18 Oct 2012 23:51:37 -0400 Subject: [PATCH 4/7] atrac3: replace a calculation with FFALIGN() This allocates 4 bytes less than the previous code if avctx->block_align is a multiple of 4, but the extra 4 bytes is not really needed. --- libavcodec/atrac3.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libavcodec/atrac3.c b/libavcodec/atrac3.c index 66c672a519..9cf989246b 100644 --- a/libavcodec/atrac3.c +++ b/libavcodec/atrac3.c @@ -947,8 +947,7 @@ static av_cold int atrac3_decode_init(AVCodecContext *avctx) if (avctx->block_align >= UINT_MAX / 2) return AVERROR(EINVAL); - q->decoded_bytes_buffer = av_mallocz(avctx->block_align + - (4 - avctx->block_align % 4) + + q->decoded_bytes_buffer = av_mallocz(FFALIGN(avctx->block_align, 4) + FF_INPUT_BUFFER_PADDING_SIZE); if (q->decoded_bytes_buffer == NULL) return AVERROR(ENOMEM); From 4e61a38aa038b7027c5ed423635168d463515d24 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Oct 2012 22:40:22 +0200 Subject: [PATCH 5/7] avconv: only apply presets when we have an encoder. Fixes a crash when using a preset with stream copy. CC: libav-stable@libav.org --- avconv_opt.c | 55 ++++++++++++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/avconv_opt.c b/avconv_opt.c index 79444eb6f3..0eb601b460 100644 --- a/avconv_opt.c +++ b/avconv_opt.c @@ -754,8 +754,6 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e char *bsf = NULL, *next, *codec_tag = NULL; AVBitStreamFilterContext *bsfc, *bsfc_prev = NULL; double qscale = -1; - char *buf = NULL, *arg = NULL, *preset = NULL; - AVIOContext *s = NULL; if (!st) { av_log(NULL, AV_LOG_FATAL, "Could not alloc stream.\n"); @@ -777,37 +775,40 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e st->codec->codec_type = type; choose_encoder(o, oc, ost); if (ost->enc) { + AVIOContext *s = NULL; + char *buf = NULL, *arg = NULL, *preset = NULL; + ost->opts = filter_codec_opts(codec_opts, ost->enc->id, oc, st, ost->enc); + + MATCH_PER_STREAM_OPT(presets, str, preset, oc, st); + if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) { + do { + buf = get_line(s); + if (!buf[0] || buf[0] == '#') { + av_free(buf); + continue; + } + if (!(arg = strchr(buf, '='))) { + av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n"); + exit(1); + } + *arg++ = 0; + av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE); + av_free(buf); + } while (!s->eof_reached); + avio_close(s); + } + if (ret) { + av_log(NULL, AV_LOG_FATAL, + "Preset %s specified for stream %d:%d, but could not be opened.\n", + preset, ost->file_index, ost->index); + exit(1); + } } avcodec_get_context_defaults3(st->codec, ost->enc); st->codec->codec_type = type; // XXX hack, avcodec_get_context_defaults2() sets type to unknown for stream copy - MATCH_PER_STREAM_OPT(presets, str, preset, oc, st); - if (preset && (!(ret = get_preset_file_2(preset, ost->enc->name, &s)))) { - do { - buf = get_line(s); - if (!buf[0] || buf[0] == '#') { - av_free(buf); - continue; - } - if (!(arg = strchr(buf, '='))) { - av_log(NULL, AV_LOG_FATAL, "Invalid line found in the preset file.\n"); - exit(1); - } - *arg++ = 0; - av_dict_set(&ost->opts, buf, arg, AV_DICT_DONT_OVERWRITE); - av_free(buf); - } while (!s->eof_reached); - avio_close(s); - } - if (ret) { - av_log(NULL, AV_LOG_FATAL, - "Preset %s specified for stream %d:%d, but could not be opened.\n", - preset, ost->file_index, ost->index); - exit(1); - } - ost->max_frames = INT64_MAX; MATCH_PER_STREAM_OPT(max_frames, i64, ost->max_frames, oc, st); From 9cac8a519980c757f6f110cd780bbe3d9b7e10b2 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Oct 2012 09:02:28 +0200 Subject: [PATCH 6/7] APIchanges: update lavr bump date --- doc/APIchanges | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/APIchanges b/doc/APIchanges index ed479df569..eed0f81840 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -6,7 +6,7 @@ libavcodec: 2012-01-27 libavdevice: 2011-04-18 libavfilter: 2012-06-22 libavformat: 2012-01-27 -libavresample: 2012-04-24 +libavresample: 2012-10-05 libswscale: 2011-06-20 libavutil: 2011-04-18 From 2b8dd371e4d276ca0d342e82b8b4cc281be0630a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Mon, 22 Oct 2012 09:11:41 +0200 Subject: [PATCH 7/7] lavu: postpone recent deprecations until the next major bump --- libavutil/version.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libavutil/version.h b/libavutil/version.h index 4de2a9446f..d21f53286b 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -74,16 +74,16 @@ #define FF_API_OLD_AVOPTIONS (LIBAVUTIL_VERSION_MAJOR < 52) #endif #ifndef FF_API_PIX_FMT -#define FF_API_PIX_FMT (LIBAVUTIL_VERSION_MAJOR < 52) +#define FF_API_PIX_FMT (LIBAVUTIL_VERSION_MAJOR < 53) #endif #ifndef FF_API_CONTEXT_SIZE -#define FF_API_CONTEXT_SIZE (LIBAVUTIL_VERSION_MAJOR < 52) +#define FF_API_CONTEXT_SIZE (LIBAVUTIL_VERSION_MAJOR < 53) #endif #ifndef FF_API_PIX_FMT_DESC -#define FF_API_PIX_FMT_DESC (LIBAVUTIL_VERSION_MAJOR < 52) +#define FF_API_PIX_FMT_DESC (LIBAVUTIL_VERSION_MAJOR < 53) #endif #ifndef FF_API_AV_REVERSE -#define FF_API_AV_REVERSE (LIBAVUTIL_VERSION_MAJOR < 52) +#define FF_API_AV_REVERSE (LIBAVUTIL_VERSION_MAJOR < 53) #endif /**