diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-03-01 02:17:22 +0100 |
---|---|---|
committer | Lynne <dev@lynne.ee> | 2024-04-23 08:31:30 +0200 |
commit | 9de66fd449eb4730e262379c5fa7ef527dcd237e (patch) | |
tree | 444176d018a4c1b10cbd1891c1f8550068df0071 | |
parent | 980a55fb46771241ea379929da09d9cfe67280f6 (diff) | |
download | ffmpeg-9de66fd449eb4730e262379c5fa7ef527dcd237e.tar.gz |
avcodec/aacdec_template: Deduplicate common part of aac_decode_init()
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
-rw-r--r-- | libavcodec/aac/aacdec.c | 42 | ||||
-rw-r--r-- | libavcodec/aac_defines.h | 2 | ||||
-rw-r--r-- | libavcodec/aacdec.c | 1 | ||||
-rw-r--r-- | libavcodec/aacdec.h | 1 | ||||
-rw-r--r-- | libavcodec/aacdec_fixed.c | 1 | ||||
-rw-r--r-- | libavcodec/aacdec_template.c | 30 |
6 files changed, 44 insertions, 33 deletions
diff --git a/libavcodec/aac/aacdec.c b/libavcodec/aac/aacdec.c index 4095509d16..358fe598e5 100644 --- a/libavcodec/aac/aacdec.c +++ b/libavcodec/aac/aacdec.c @@ -32,10 +32,12 @@ #include <limits.h> #include <stddef.h> +#include "libavcodec/aac.h" #include "libavcodec/aacsbr.h" #include "libavcodec/aacdec.h" #include "libavcodec/avcodec.h" #include "libavutil/attributes.h" +#include "libavutil/error.h" #include "libavutil/log.h" #include "libavutil/macros.h" #include "libavutil/mem.h" @@ -76,6 +78,46 @@ av_cold int ff_aac_decode_close(AVCodecContext *avctx) return 0; } +av_cold int ff_aac_decode_init_common(AVCodecContext *avctx) +{ + AACDecContext *ac = avctx->priv_data; + int is_fixed = ac->is_fixed, ret; + float scale_fixed, scale_float; + const float *const scalep = is_fixed ? &scale_fixed : &scale_float; + enum AVTXType tx_type = is_fixed ? AV_TX_INT32_MDCT : AV_TX_FLOAT_MDCT; + + if (avctx->ch_layout.nb_channels > MAX_CHANNELS) { + av_log(avctx, AV_LOG_ERROR, "Too many channels\n"); + return AVERROR_INVALIDDATA; + } + + ac->random_state = 0x1f2e3d4c; + +#define MDCT_INIT(s, fn, len, sval) \ + scale_fixed = (sval) * 128.0f; \ + scale_float = (sval) / 32768.0f; \ + ret = av_tx_init(&s, &fn, tx_type, 1, len, scalep, 0); \ + if (ret < 0) \ + return ret + + MDCT_INIT(ac->mdct120, ac->mdct120_fn, 120, 1.0/120); + MDCT_INIT(ac->mdct128, ac->mdct128_fn, 128, 1.0/128); + MDCT_INIT(ac->mdct480, ac->mdct480_fn, 480, 1.0/480); + MDCT_INIT(ac->mdct512, ac->mdct512_fn, 512, 1.0/512); + MDCT_INIT(ac->mdct960, ac->mdct960_fn, 960, 1.0/960); + MDCT_INIT(ac->mdct1024, ac->mdct1024_fn, 1024, 1.0/1024); +#undef MDCT_INIT + + /* LTP forward MDCT */ + scale_fixed = -1.0; + scale_float = -32786.0*2 + 36; + ret = av_tx_init(&ac->mdct_ltp, &ac->mdct_ltp_fn, tx_type, 0, 1024, scalep, 0); + if (ret < 0) + return ret; + + return 0; +} + #define AACDEC_FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM #define OFF(field) offsetof(AACDecContext, field) static const AVOption options[] = { diff --git a/libavcodec/aac_defines.h b/libavcodec/aac_defines.h index 75bc40744a..a3b662115b 100644 --- a/libavcodec/aac_defines.h +++ b/libavcodec/aac_defines.h @@ -42,7 +42,6 @@ typedef int AAC_SIGNE; #define Q23(a) (int)((a) * 8388608.0 + 0.5) #define Q30(x) (int)((x)*1073741824.0 + 0.5) #define Q31(x) (int)((x)*2147483648.0 + 0.5) -#define TX_SCALE(x) ((x) * 128.0f) #define GET_GAIN(x, y) (-(y) * (1 << (x))) + 1024 #define AAC_MUL16(x, y) (int)(((int64_t)(x) * (y) + 0x8000) >> 16) #define AAC_MUL26(x, y) (int)(((int64_t)(x) * (y) + 0x2000000) >> 26) @@ -110,7 +109,6 @@ typedef unsigned AAC_SIGNE; #define Q23(x) ((float)(x)) #define Q30(x) ((float)(x)) #define Q31(x) ((float)(x)) -#define TX_SCALE(x) ((x) / 32768.0f) #define GET_GAIN(x, y) powf((x), -(y)) #define AAC_MUL16(x, y) ((x) * (y)) #define AAC_MUL26(x, y) ((x) * (y)) diff --git a/libavcodec/aacdec.c b/libavcodec/aacdec.c index 86b9161e64..67cdda8cde 100644 --- a/libavcodec/aacdec.c +++ b/libavcodec/aacdec.c @@ -33,7 +33,6 @@ */ #define USE_FIXED 0 -#define TX_TYPE AV_TX_FLOAT_MDCT #include "libavutil/float_dsp.h" #include "avcodec.h" diff --git a/libavcodec/aacdec.h b/libavcodec/aacdec.h index b05e68f51c..e55fea6e40 100644 --- a/libavcodec/aacdec.h +++ b/libavcodec/aacdec.h @@ -306,6 +306,7 @@ typedef struct AACDecContext { extern const struct AVClass ff_aac_decoder_class; +int ff_aac_decode_init_common(struct AVCodecContext *avctx); int ff_aac_decode_close(struct AVCodecContext *avctx); void ff_aacdec_init_mips(AACDecContext *c); diff --git a/libavcodec/aacdec_fixed.c b/libavcodec/aacdec_fixed.c index 8ed98226e9..2c87cddd6e 100644 --- a/libavcodec/aacdec_fixed.c +++ b/libavcodec/aacdec_fixed.c @@ -59,7 +59,6 @@ */ #define USE_FIXED 1 -#define TX_TYPE AV_TX_INT32_MDCT #include "libavutil/fixed_dsp.h" #include "avcodec.h" diff --git a/libavcodec/aacdec_template.c b/libavcodec/aacdec_template.c index 27cf5dc4ec..3adb4ebdf1 100644 --- a/libavcodec/aacdec_template.c +++ b/libavcodec/aacdec_template.c @@ -1145,7 +1145,6 @@ static AVOnce aac_table_init = AV_ONCE_INIT; static av_cold int aac_decode_init(AVCodecContext *avctx) { - float scale; AACDecContext *ac = avctx->priv_data; int ret; @@ -1204,11 +1203,6 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) } } - if (avctx->ch_layout.nb_channels > MAX_CHANNELS) { - av_log(avctx, AV_LOG_ERROR, "Too many channels\n"); - return AVERROR_INVALIDDATA; - } - #if USE_FIXED ac->fdsp = avpriv_alloc_fixed_dsp(avctx->flags & AV_CODEC_FLAG_BITEXACT); #else @@ -1218,29 +1212,7 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) return AVERROR(ENOMEM); } - ac->random_state = 0x1f2e3d4c; - -#define MDCT_INIT(s, fn, len, sval) \ - scale = sval; \ - ret = av_tx_init(&s, &fn, TX_TYPE, 1, len, &scale, 0); \ - if (ret < 0) \ - return ret; - - MDCT_INIT(ac->mdct120, ac->mdct120_fn, 120, TX_SCALE(1.0/120)) - MDCT_INIT(ac->mdct128, ac->mdct128_fn, 128, TX_SCALE(1.0/128)) - MDCT_INIT(ac->mdct480, ac->mdct480_fn, 480, TX_SCALE(1.0/480)) - MDCT_INIT(ac->mdct512, ac->mdct512_fn, 512, TX_SCALE(1.0/512)) - MDCT_INIT(ac->mdct960, ac->mdct960_fn, 960, TX_SCALE(1.0/960)) - MDCT_INIT(ac->mdct1024, ac->mdct1024_fn, 1024, TX_SCALE(1.0/1024)) -#undef MDCT_INIT - - /* LTP forward MDCT */ - scale = USE_FIXED ? -1.0 : -32786.0*2 + 36; - ret = av_tx_init(&ac->mdct_ltp, &ac->mdct_ltp_fn, TX_TYPE, 0, 1024, &scale, 0); - if (ret < 0) - return ret; - - return 0; + return ff_aac_decode_init_common(avctx); } /** |