From e3b08a135f550d70d9cb8d883891512df1b54bcc Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Thu, 10 Apr 2025 13:56:14 +0200 Subject: [PATCH 04/15] avcodec/aacenc: Remove always-false check The sample rates have already been checked generically via AVCodec.supported_samplerates. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/aacenc.c | 13 ++++++------- libavcodec/aacenctab.c | 3 --- libavcodec/aacenctab.h | 2 -- libavcodec/mpeg4audio_sample_rates.h | 4 ++++ 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index 0f124408da..afb4478bfe 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -1235,14 +1235,13 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) } /* Samplerate */ - for (i = 0; i < 16; i++) - if (avctx->sample_rate == ff_mpeg4audio_sample_rates[i]) + for (int i = 0;; i++) { + av_assert1(i < 13); + if (avctx->sample_rate == ff_mpeg4audio_sample_rates[i]) { + s->samplerate_index = i; break; - s->samplerate_index = i; - ERROR_IF(s->samplerate_index == 16 || - s->samplerate_index >= ff_aac_swb_size_1024_len || - s->samplerate_index >= ff_aac_swb_size_128_len, - "Unsupported sample rate %d\n", avctx->sample_rate); + } + } /* Bitrate limiting */ WARN_IF(1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * s->channels, diff --git a/libavcodec/aacenctab.c b/libavcodec/aacenctab.c index 874365a593..ca09e22ca8 100644 --- a/libavcodec/aacenctab.c +++ b/libavcodec/aacenctab.c @@ -103,6 +103,3 @@ const uint8_t *const ff_aac_swb_size_1024[] = { swb_size_1024_16, swb_size_1024_16, swb_size_1024_8, swb_size_1024_8 }; - -const int ff_aac_swb_size_128_len = FF_ARRAY_ELEMS(ff_aac_swb_size_128); -const int ff_aac_swb_size_1024_len = FF_ARRAY_ELEMS(ff_aac_swb_size_1024); diff --git a/libavcodec/aacenctab.h b/libavcodec/aacenctab.h index 60e1f22387..fee9c245d8 100644 --- a/libavcodec/aacenctab.h +++ b/libavcodec/aacenctab.h @@ -41,9 +41,7 @@ #define AAC_MAX_CHANNELS 16 extern const uint8_t *const ff_aac_swb_size_1024[]; -extern const int ff_aac_swb_size_1024_len; extern const uint8_t *const ff_aac_swb_size_128[]; -extern const int ff_aac_swb_size_128_len; /* Supported layouts without using a PCE */ static const AVChannelLayout aac_normal_chan_layouts[7] = { diff --git a/libavcodec/mpeg4audio_sample_rates.h b/libavcodec/mpeg4audio_sample_rates.h index 0b8caa6d76..a847a97994 100644 --- a/libavcodec/mpeg4audio_sample_rates.h +++ b/libavcodec/mpeg4audio_sample_rates.h @@ -23,6 +23,10 @@ #ifndef AVCODEC_MPEG4AUDIO_SAMPLE_RATES_H #define AVCODEC_MPEG4AUDIO_SAMPLE_RATES_H +// This table contains only 13 real elements and is padded with zeroes. +// It is used by the AAC encoder as sample rate table, so the encoder +// needs to actually support all of these rates and it needs to have +// a trailing zero. const int ff_mpeg4audio_sample_rates[16] = { 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 -- 2.45.2