From 5eef4afb9a5c637229469036285fa9a334f6f7d4 Mon Sep 17 00:00:00 2001 From: "Ronald S. Bultje" Date: Tue, 26 Apr 2011 18:46:08 -0700 Subject: [PATCH 01/16] avparser: don't av_malloc(0). Signed-off-by: Ronald S. Bultje --- libavcodec/parser.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libavcodec/parser.c b/libavcodec/parser.c index d5b85c3e4e..4b3d30e51a 100644 --- a/libavcodec/parser.c +++ b/libavcodec/parser.c @@ -58,10 +58,12 @@ AVCodecParserContext *av_parser_init(int codec_id) if (!s) return NULL; s->parser = parser; - s->priv_data = av_mallocz(parser->priv_data_size); - if (!s->priv_data) { - av_free(s); - return NULL; + if (parser->priv_data_size) { + s->priv_data = av_mallocz(parser->priv_data_size); + if (!s->priv_data) { + av_free(s); + return NULL; + } } if (parser->parser_init) { ret = parser->parser_init(s); From 4f2954e2327c211f3fbe20b84f4881e1f8df1528 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Tue, 26 Apr 2011 11:37:36 +0200 Subject: [PATCH 02/16] smacker: remove unnecessary call to avctx->release_buffer in decode_frame() The release_buffer was cleaning the provided frame, thus causing the successive call to avctx->reget_buffer() to allocate a new frame. In case the returned frame was not the same one previously returned but a new one with different data, it resulted in artifacts. Signed-off-by: Ronald S. Bultje --- libavcodec/smacker.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c index 3a97b720a5..aef5e2502b 100644 --- a/libavcodec/smacker.c +++ b/libavcodec/smacker.c @@ -360,8 +360,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac if(buf_size <= 769) return 0; - if(smk->pic.data[0]) - avctx->release_buffer(avctx, &smk->pic); smk->pic.reference = 1; smk->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; From 4f0b80599a534dcca57be3184b89b98f82bf2a2c Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Tue, 26 Apr 2011 11:45:40 +0200 Subject: [PATCH 03/16] ultimotion: use reget_buffer() in ulti_decode_frame() Decoder relies on previous frame data, so use reget_buffer(). Signed-off-by: Ronald S. Bultje --- libavcodec/ulti.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/libavcodec/ulti.c b/libavcodec/ulti.c index 31b1c4afcb..9a73c627a9 100644 --- a/libavcodec/ulti.c +++ b/libavcodec/ulti.c @@ -224,13 +224,10 @@ static int ulti_decode_frame(AVCodecContext *avctx, int skip; int tmp; - if(s->frame.data[0]) - avctx->release_buffer(avctx, &s->frame); - s->frame.reference = 1; s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; - if(avctx->get_buffer(avctx, &s->frame) < 0) { - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + if (avctx->reget_buffer(avctx, &s->frame) < 0) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return -1; } From f4e043ff63935a71b98a36bc98b501c36ceadb92 Mon Sep 17 00:00:00 2001 From: Stefano Sabatini Date: Tue, 26 Apr 2011 11:51:50 +0200 Subject: [PATCH 04/16] qpeg: use reget_buffer() in decode_frame() Decoder relies on previous frame data, so use reget_buffer(). This also set frame->reference to 3, as the frame will be requested unmodified later so it shouldn't be modified by the application. Fix playback of file Clock.avi. Signed-off-by: Ronald S. Bultje --- libavcodec/qpeg.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libavcodec/qpeg.c b/libavcodec/qpeg.c index c96184ff38..5dd2a2d5ca 100644 --- a/libavcodec/qpeg.c +++ b/libavcodec/qpeg.c @@ -259,12 +259,9 @@ static int decode_frame(AVCodecContext *avctx, int delta; const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); - if(p->data[0]) - avctx->release_buffer(avctx, p); - - p->reference= 0; - if(avctx->get_buffer(avctx, p) < 0){ - av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + p->reference = 3; + if (avctx->reget_buffer(avctx, p) < 0) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); return -1; } outdata = a->pic.data[0]; From e4744b59aadd6e7064491c0228d6248289a6a85a Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 26 Apr 2011 14:29:03 -0400 Subject: [PATCH 05/16] Large intensity stereo and PNS indices are legal. Clip them instead of erroring out. A magnitude of 100 corresponds to 2^25 so the will most likely result in clipped output anyway. None of the conformance streams fall in the range that need to be clipped. --- libavcodec/aacdec.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index 0c6312fb01..e289caa4f6 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -791,7 +791,8 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, { const int sf_offset = ac->sf_offset + (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ? 12 : 0); int g, i, idx = 0; - int offset[3] = { global_gain, global_gain - 90, 100 }; + int offset[3] = { global_gain, global_gain - 90, 0 }; + int clipped_offset; int noise_flag = 1; static const char *sf_str[3] = { "Global gain", "Noise gain", "Intensity stereo position" }; for (g = 0; g < ics->num_window_groups; g++) { @@ -803,12 +804,14 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, } else if ((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) { for (; i < run_end; i++, idx++) { offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; - if (offset[2] > 255U) { - av_log(ac->avctx, AV_LOG_ERROR, - "%s (%d) out of range.\n", sf_str[2], offset[2]); - return -1; + clipped_offset = av_clip(offset[2], -155, 100); + if (offset[2] != clipped_offset) { + av_log_ask_for_sample(ac->avctx, "Intensity stereo " + "position clipped (%d -> %d).\nIf you heard an " + "audible artifact, there may be a bug in the " + "decoder. ", offset[2], clipped_offset); } - sf[idx] = ff_aac_pow2sf_tab[-offset[2] + 300]; + sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + 200]; } } else if (band_type[idx] == NOISE_BT) { for (; i < run_end; i++, idx++) { @@ -816,12 +819,14 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, offset[1] += get_bits(gb, 9) - 256; else offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; - if (offset[1] > 255U) { - av_log(ac->avctx, AV_LOG_ERROR, - "%s (%d) out of range.\n", sf_str[1], offset[1]); - return -1; + clipped_offset = av_clip(offset[1], -100, 155); + if (offset[2] != clipped_offset) { + av_log_ask_for_sample(ac->avctx, "Noise gain clipped " + "(%d -> %d).\nIf you heard an audible " + "artifact, there may be a bug in the decoder. ", + offset[1], clipped_offset); } - sf[idx] = -ff_aac_pow2sf_tab[offset[1] + sf_offset + 100]; + sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + sf_offset + 100]; } } else { for (; i < run_end; i++, idx++) { From d70fa4c4238ffa69592fffa7c817532534f303c4 Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 26 Apr 2011 14:45:48 -0400 Subject: [PATCH 06/16] Define POW_SF2_ZERO in aac.h and use for ff_aac_pow2sf_tabp[] offsets instead of hardcoding 200 everywhere. --- libavcodec/aac.h | 1 + libavcodec/aac_tablegen.h | 3 ++- libavcodec/aaccoder.c | 8 ++++---- libavcodec/aacdec.c | 6 +++--- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libavcodec/aac.h b/libavcodec/aac.h index bbe7912517..63ed2511f7 100644 --- a/libavcodec/aac.h +++ b/libavcodec/aac.h @@ -130,6 +130,7 @@ typedef struct { #define SCALE_MAX_POS 255 ///< scalefactor index maximum value #define SCALE_MAX_DIFF 60 ///< maximum scalefactor difference allowed by standard #define SCALE_DIFF_ZERO 60 ///< codebook index corresponding to zero scalefactor indices difference +#define POW_SF2_ZERO 200 ///< ff_aac_pow2sf_tab index corresponding to pow(2, 0); /** * Long Term Prediction diff --git a/libavcodec/aac_tablegen.h b/libavcodec/aac_tablegen.h index c7be492084..98895694a8 100644 --- a/libavcodec/aac_tablegen.h +++ b/libavcodec/aac_tablegen.h @@ -29,13 +29,14 @@ #include "libavcodec/aac_tables.h" #else #include "libavutil/mathematics.h" +#include "libavcodec/aac.h" float ff_aac_pow2sf_tab[428]; void ff_aac_tableinit(void) { int i; for (i = 0; i < 428; i++) - ff_aac_pow2sf_tab[i] = pow(2, (i - 200) / 4.); + ff_aac_pow2sf_tab[i] = pow(2, (i - POW_SF2_ZERO) / 4.); } #endif /* CONFIG_HARDCODED_TABLES */ diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c index bc59ac5052..15fe430732 100644 --- a/libavcodec/aaccoder.c +++ b/libavcodec/aaccoder.c @@ -108,8 +108,8 @@ static av_always_inline float quantize_and_encode_band_cost_template( int *bits, int BT_ZERO, int BT_UNSIGNED, int BT_PAIR, int BT_ESC) { - const float IQ = ff_aac_pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512]; - const float Q = ff_aac_pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512]; + const float IQ = ff_aac_pow2sf_tab[POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512]; + const float Q = ff_aac_pow2sf_tab[POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512]; const float CLIPPED_ESCAPE = 165140.0f*IQ; int i, j; float cost = 0; @@ -280,7 +280,7 @@ static float find_max_val(int group_len, int swb_size, const float *scaled) { } static int find_min_book(float maxval, int sf) { - float Q = ff_aac_pow2sf_tab[200 - sf + SCALE_ONE_POS - SCALE_DIV_512]; + float Q = ff_aac_pow2sf_tab[POW_SF2_ZERO - sf + SCALE_ONE_POS - SCALE_DIV_512]; float Q34 = sqrtf(Q * sqrtf(Q)); int qmaxval, cb; qmaxval = maxval * Q34 + 0.4054f; @@ -955,7 +955,7 @@ static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s, dist -= b; } dist *= 1.0f / 512.0f / lambda; - quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[200 - scf + SCALE_ONE_POS - SCALE_DIV_512]); + quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[POW_SF2_ZERO - scf + SCALE_ONE_POS - SCALE_DIV_512]); if (quant_max >= 8191) { // too much, return to the previous quantizer sce->sf_idx[w*16+g] = prev_scf; break; diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index e289caa4f6..bcc277c3c0 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -811,7 +811,7 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, "audible artifact, there may be a bug in the " "decoder. ", offset[2], clipped_offset); } - sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + 200]; + sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + POW_SF2_ZERO]; } } else if (band_type[idx] == NOISE_BT) { for (; i < run_end; i++, idx++) { @@ -826,7 +826,7 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, "artifact, there may be a bug in the decoder. ", offset[1], clipped_offset); } - sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + sf_offset + 100]; + sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + sf_offset - 100 + POW_SF2_ZERO]; } } else { for (; i < run_end; i++, idx++) { @@ -836,7 +836,7 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, "%s (%d) out of range.\n", sf_str[0], offset[0]); return -1; } - sf[idx] = -ff_aac_pow2sf_tab[ offset[0] + sf_offset]; + sf[idx] = -ff_aac_pow2sf_tab[offset[0] + sf_offset - 200 + POW_SF2_ZERO]; } } } From 6271794041abbf79098b6c01b27f1539b3a4af5e Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 26 Apr 2011 15:30:19 -0400 Subject: [PATCH 07/16] aacdec: use a scale of 2 in the LTP MDCT rather than doubling the coefficient table values from the spec. --- libavcodec/aacdec.c | 2 +- libavcodec/aacdectab.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index bcc277c3c0..cbaecf9e2f 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -593,7 +593,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) ff_mdct_init(&ac->mdct, 11, 1, 1.0); ff_mdct_init(&ac->mdct_small, 8, 1, 1.0); - ff_mdct_init(&ac->mdct_ltp, 11, 0, 1.0); + ff_mdct_init(&ac->mdct_ltp, 11, 0, 2.0); // window initialization ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); diff --git a/libavcodec/aacdectab.h b/libavcodec/aacdectab.h index 64c2a1c395..23a7868ab2 100644 --- a/libavcodec/aacdectab.h +++ b/libavcodec/aacdectab.h @@ -36,11 +36,11 @@ #include /* @name ltp_coef - * Table of the LTP coefficient (multiplied by 2) + * Table of the LTP coefficients */ static const float ltp_coef[8] = { - 1.141658, 1.393232, 1.626008, 1.822608, - 1.969800, 2.135788, 2.2389202, 2.739066, + 0.570829, 0.696616, 0.813004, 0.911304, + 0.984900, 1.067894, 1.194601, 1.369533, }; /* @name tns_tmp2_map From 767848d7619ce43e00d1a13607a5cf2aa61d2d6e Mon Sep 17 00:00:00 2001 From: Alex Converse Date: Tue, 26 Apr 2011 17:05:07 -0400 Subject: [PATCH 08/16] aacdec: remove sf_scale and sf_offset. Instead, scalefactors are adjusted by the offset amount, removing the need for sf_scale, and the MDCT scales are adjusted to compensate for the higher scalefactors. Floating-point output will be handled by modifying the MDCT scales. --- libavcodec/aac.h | 2 -- libavcodec/aacdec.c | 26 ++++++++------------------ 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/libavcodec/aac.h b/libavcodec/aac.h index 63ed2511f7..ecb8191566 100644 --- a/libavcodec/aac.h +++ b/libavcodec/aac.h @@ -293,8 +293,6 @@ typedef struct { * @{ */ float *output_data[MAX_CHANNELS]; ///< Points to each element's 'ret' buffer (PCM output). - float sf_scale; ///< Pre-scale for correct IMDCT and dsp.float_to_int16. - int sf_offset; ///< offset into pow2sf_tab as appropriate for dsp.float_to_int16 /** @} */ DECLARE_ALIGNED(32, float, temp)[128]; diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index cbaecf9e2f..d26cce994c 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -578,12 +578,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) ac->random_state = 0x1f2e3d4c; - // -1024 - Compensate wrong IMDCT method. - // 60 - Required to scale values to the correct range [-32768,32767] - // for float to int16 conversion. (1 << (60 / 4)) == 32768 - ac->sf_scale = 1. / -1024.; - ac->sf_offset = 60; - ff_aac_tableinit(); INIT_VLC_STATIC(&vlc_scalefactors,7,FF_ARRAY_ELEMS(ff_aac_scalefactor_code), @@ -591,9 +585,9 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]), 352); - ff_mdct_init(&ac->mdct, 11, 1, 1.0); - ff_mdct_init(&ac->mdct_small, 8, 1, 1.0); - ff_mdct_init(&ac->mdct_ltp, 11, 0, 2.0); + ff_mdct_init(&ac->mdct, 11, 1, 1.0/1024.0); + ff_mdct_init(&ac->mdct_small, 8, 1, 1.0/128.0); + ff_mdct_init(&ac->mdct_ltp, 11, 0, -2.0); // window initialization ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); @@ -651,7 +645,7 @@ static void decode_ltp(AACContext *ac, LongTermPrediction *ltp, int sfb; ltp->lag = get_bits(gb, 11); - ltp->coef = ltp_coef[get_bits(gb, 3)] * ac->sf_scale; + ltp->coef = ltp_coef[get_bits(gb, 3)]; for (sfb = 0; sfb < FFMIN(max_sfb, MAX_LTP_LONG_SFB); sfb++) ltp->used[sfb] = get_bits1(gb); } @@ -789,7 +783,6 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, enum BandType band_type[120], int band_type_run_end[120]) { - const int sf_offset = ac->sf_offset + (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ? 12 : 0); int g, i, idx = 0; int offset[3] = { global_gain, global_gain - 90, 0 }; int clipped_offset; @@ -826,7 +819,7 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, "artifact, there may be a bug in the decoder. ", offset[1], clipped_offset); } - sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + sf_offset - 100 + POW_SF2_ZERO]; + sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + POW_SF2_ZERO]; } } else { for (; i < run_end; i++, idx++) { @@ -836,7 +829,7 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, "%s (%d) out of range.\n", sf_str[0], offset[0]); return -1; } - sf[idx] = -ff_aac_pow2sf_tab[offset[0] + sf_offset - 200 + POW_SF2_ZERO]; + sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO]; } } } @@ -1247,7 +1240,6 @@ static av_always_inline float flt16_trunc(float pf) } static av_always_inline void predict(PredictorState *ps, float *coef, - float sf_scale, float inv_sf_scale, int output_enable) { const float a = 0.953125; // 61.0 / 64 @@ -1264,9 +1256,9 @@ static av_always_inline void predict(PredictorState *ps, float *coef, pv = flt16_round(k1 * r0 + k2 * r1); if (output_enable) - *coef += pv * sf_scale; + *coef += pv; - e0 = *coef * inv_sf_scale; + e0 = *coef; e1 = e0 - k1 * r0; ps->cor1 = flt16_trunc(alpha * cor1 + r1 * e1); @@ -1284,7 +1276,6 @@ static av_always_inline void predict(PredictorState *ps, float *coef, static void apply_prediction(AACContext *ac, SingleChannelElement *sce) { int sfb, k; - float sf_scale = ac->sf_scale, inv_sf_scale = 1 / ac->sf_scale; if (!sce->ics.predictor_initialized) { reset_all_predictors(sce->predictor_state); @@ -1295,7 +1286,6 @@ static void apply_prediction(AACContext *ac, SingleChannelElement *sce) for (sfb = 0; sfb < ff_aac_pred_sfb_max[ac->m4ac.sampling_index]; sfb++) { for (k = sce->ics.swb_offset[sfb]; k < sce->ics.swb_offset[sfb + 1]; k++) { predict(&sce->predictor_state[k], &sce->coeffs[k], - sf_scale, inv_sf_scale, sce->ics.predictor_present && sce->ics.prediction_used[sfb]); } } From 8b00ab0113a8ca40429e0a06331be83996963a9e Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 19 Apr 2011 18:50:20 -0400 Subject: [PATCH 09/16] Check AVCodec.supported_samplerates and AVCodec.channel_layouts in avcodec_open(). If the encoder has a channel_layouts list and AVCodecContext.channel_layout is 0, then only print a warning and let the encoder decide how to handle it. --- libavcodec/utils.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 7e2847afb1..915fb31bc6 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -542,8 +542,9 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) ret = AVERROR(EINVAL); goto free_and_end; } - if (avctx->codec->sample_fmts && avctx->codec->encode) { + if (avctx->codec->encode) { int i; + if (avctx->codec->sample_fmts) { for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) if (avctx->sample_fmt == avctx->codec->sample_fmts[i]) break; @@ -552,6 +553,31 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) ret = AVERROR(EINVAL); goto free_and_end; } + } + if (avctx->codec->supported_samplerates) { + for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++) + if (avctx->sample_rate == avctx->codec->supported_samplerates[i]) + break; + if (avctx->codec->supported_samplerates[i] == 0) { + av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n"); + ret = AVERROR(EINVAL); + goto free_and_end; + } + } + if (avctx->codec->channel_layouts) { + if (!avctx->channel_layout) { + av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n"); + } else { + for (i = 0; avctx->codec->channel_layouts[i] != 0; i++) + if (avctx->channel_layout == avctx->codec->channel_layouts[i]) + break; + if (avctx->codec->channel_layouts[i] == 0) { + av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n"); + ret = AVERROR(EINVAL); + goto free_and_end; + } + } + } } if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){ From 3dfc3e70c0852c62a45923b8abb57137e4bf6240 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 20 Apr 2011 16:59:39 -0400 Subject: [PATCH 10/16] cosmetics: indentation --- libavcodec/utils.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 915fb31bc6..8bb4d1927e 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -545,14 +545,14 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) if (avctx->codec->encode) { int i; if (avctx->codec->sample_fmts) { - for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) - if (avctx->sample_fmt == avctx->codec->sample_fmts[i]) - break; - if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) { - av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n"); - ret = AVERROR(EINVAL); - goto free_and_end; - } + for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) + if (avctx->sample_fmt == avctx->codec->sample_fmts[i]) + break; + if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) { + av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n"); + ret = AVERROR(EINVAL); + goto free_and_end; + } } if (avctx->codec->supported_samplerates) { for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++) From 168f9e8c40cf383802c8c8059f283a6ea789ec1e Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 19 Apr 2011 19:02:32 -0400 Subject: [PATCH 11/16] If AVCodecContext.channel_layout and AVCodecContext.channels are both non-zero, check to make sure they do not contradict eachother. --- libavcodec/utils.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 8bb4d1927e..e4ea1e5bf7 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -578,6 +578,13 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) } } } + if (avctx->channel_layout && avctx->channels) { + if (av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels) { + av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n"); + ret = AVERROR(EINVAL); + goto free_and_end; + } + } } if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){ From 688b09fa597804ab4708271ce467a6ae025f0c17 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 19 Apr 2011 19:03:47 -0400 Subject: [PATCH 12/16] If AVCodecContext.channels is 0 and AVCodecContext.channel_layout is non-zero, set channels based on channel_layout. This allows the user to set only channel_layout and not channels. --- libavcodec/utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index e4ea1e5bf7..68441881de 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -584,6 +584,8 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) ret = AVERROR(EINVAL); goto free_and_end; } + } else if (avctx->channel_layout) { + avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout); } } From 8745e9c45865a4409272d78db1e1af86a8b955e9 Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Tue, 19 Apr 2011 19:06:52 -0400 Subject: [PATCH 13/16] ac3enc: remove check for mismatching channels and channel_layout --- libavcodec/ac3enc.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/libavcodec/ac3enc.c b/libavcodec/ac3enc.c index 77647d40e1..1f3c92aa3d 100644 --- a/libavcodec/ac3enc.c +++ b/libavcodec/ac3enc.c @@ -1988,8 +1988,6 @@ static av_cold int set_channel_info(AC3EncodeContext *s, int channels, ch_layout = *channel_layout; if (!ch_layout) ch_layout = avcodec_guess_channel_layout(channels, CODEC_ID_AC3, NULL); - if (av_get_channel_layout_nb_channels(ch_layout) != channels) - return AVERROR(EINVAL); s->lfe_on = !!(ch_layout & AV_CH_LOW_FREQUENCY); s->channels = channels; From 3fd3632ffeb18aeca6c0ab3fbe1034c3da75d983 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 27 Apr 2011 15:11:41 +0200 Subject: [PATCH 14/16] Simplify av_log_missing_feature(). Do not print the results of the conditional call to av_log_ask_for_sample() into the same line as the main output, separate the already long text. --- libavcodec/utils.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 68441881de..6c10dd32c0 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -1154,11 +1154,9 @@ void av_log_missing_feature(void *avc, const char *feature, int want_sample) av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your Libav " "version to the newest one from Git. If the problem still " "occurs, it means that your file has a feature which has not " - "been implemented.", feature); + "been implemented.\n", feature); if(want_sample) av_log_ask_for_sample(avc, NULL); - else - av_log(avc, AV_LOG_WARNING, "\n"); } void av_log_ask_for_sample(void *avc, const char *msg, ...) From 81afa5a2740b94ed1db8ad980e37deecb5f8e573 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 27 Apr 2011 15:36:21 +0200 Subject: [PATCH 15/16] simple_idct_alpha: Drop some useless casts. --- libavcodec/alpha/simple_idct_alpha.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/alpha/simple_idct_alpha.c b/libavcodec/alpha/simple_idct_alpha.c index 8f5c134365..bb76c1ec29 100644 --- a/libavcodec/alpha/simple_idct_alpha.c +++ b/libavcodec/alpha/simple_idct_alpha.c @@ -33,13 +33,13 @@ // cos(i * M_PI / 16) * sqrt(2) * (1 << 14) // W4 is actually exactly 16384, but using 16383 works around // accumulating rounding errors for some encoders -#define W1 ((int_fast32_t) 22725) -#define W2 ((int_fast32_t) 21407) -#define W3 ((int_fast32_t) 19266) -#define W4 ((int_fast32_t) 16383) -#define W5 ((int_fast32_t) 12873) -#define W6 ((int_fast32_t) 8867) -#define W7 ((int_fast32_t) 4520) +#define W1 22725 +#define W2 21407 +#define W3 19266 +#define W4 16383 +#define W5 12873 +#define W6 8867 +#define W7 4520 #define ROW_SHIFT 11 #define COL_SHIFT 20 From b239526873dc81f9b66796ad4d9fe1cb93ec34d3 Mon Sep 17 00:00:00 2001 From: Diego Biurrun Date: Wed, 27 Apr 2011 16:38:35 +0200 Subject: [PATCH 16/16] vorbisdec: Rename silly "class_" variable to plain "class". --- libavcodec/vorbisdec.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libavcodec/vorbisdec.c b/libavcodec/vorbisdec.c index d42507df84..a9ddc7d86a 100644 --- a/libavcodec/vorbisdec.c +++ b/libavcodec/vorbisdec.c @@ -1136,7 +1136,7 @@ static int vorbis_floor1_decode(vorbis_context *vc, uint_fast16_t floor1_Y[258]; uint_fast16_t floor1_Y_final[258]; int floor1_flag[258]; - uint_fast8_t class_; + uint_fast8_t class; uint_fast8_t cdim; uint_fast8_t cbits; uint_fast8_t csub; @@ -1160,20 +1160,20 @@ static int vorbis_floor1_decode(vorbis_context *vc, offset = 2; for (i = 0; i < vf->partitions; ++i) { - class_ = vf->partition_class[i]; - cdim = vf->class_dimensions[class_]; - cbits = vf->class_subclasses[class_]; + class = vf->partition_class[i]; + cdim = vf->class_dimensions[class]; + cbits = vf->class_subclasses[class]; csub = (1 << cbits) - 1; cval = 0; AV_DEBUG("Cbits %d \n", cbits); if (cbits) // this reads all subclasses for this partition's class - cval = get_vlc2(gb, vc->codebooks[vf->class_masterbook[class_]].vlc.table, - vc->codebooks[vf->class_masterbook[class_]].nb_bits, 3); + cval = get_vlc2(gb, vc->codebooks[vf->class_masterbook[class]].vlc.table, + vc->codebooks[vf->class_masterbook[class]].nb_bits, 3); for (j = 0; j < cdim; ++j) { - book = vf->subclass_books[class_][cval & csub]; + book = vf->subclass_books[class][cval & csub]; AV_DEBUG("book %d Cbits %d cval %d bits:%d \n", book, cbits, cval, get_bits_count(gb));