diff options
author | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-02-28 13:29:19 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@outlook.com> | 2024-03-02 02:54:11 +0100 |
commit | 88b3b09afa5ef00dfc89a5904614bd51de65c21b (patch) | |
tree | b81c1c704ac810f4a68b7661ddb0c39eb0283311 /libavcodec | |
parent | 6c693da690d2618b36c801f0b10607a4f68eaad6 (diff) | |
download | ffmpeg-88b3b09afa5ef00dfc89a5904614bd51de65c21b.tar.gz |
avcodec/aacenc: Move initializing DSP out of aacenc.c
Otherwise aacenc.o gets pulled in by the aacencdsp checkasm
test and it in turn pulls the rest of lavc in.
Besides being bad size-wise this also has the downside that
it pulls in avpriv_(cga|vga16)_font from libavutil which are
marked as being imported from another library when building
libavcodec as a DLL and this breaks checkasm because it links
both lavc and lavu statically.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/aaccoder.c | 26 | ||||
-rw-r--r-- | libavcodec/aaccoder_trellis.h | 2 | ||||
-rw-r--r-- | libavcodec/aaccoder_twoloop.h | 2 | ||||
-rw-r--r-- | libavcodec/aacenc.c | 21 | ||||
-rw-r--r-- | libavcodec/aacenc.h | 9 | ||||
-rw-r--r-- | libavcodec/aacenc_is.c | 6 | ||||
-rw-r--r-- | libavcodec/aacenc_ltp.c | 4 | ||||
-rw-r--r-- | libavcodec/aacenc_pred.c | 6 | ||||
-rw-r--r-- | libavcodec/aacenc_utils.h | 24 | ||||
-rw-r--r-- | libavcodec/aacencdsp.h | 72 | ||||
-rw-r--r-- | libavcodec/mips/aaccoder_mips.c | 1 | ||||
-rw-r--r-- | libavcodec/riscv/aacencdsp_init.c | 5 | ||||
-rw-r--r-- | libavcodec/x86/aacencdsp_init.c | 5 |
13 files changed, 107 insertions, 76 deletions
diff --git a/libavcodec/aaccoder.c b/libavcodec/aaccoder.c index 6291c16123..4ce54ca886 100644 --- a/libavcodec/aaccoder.c +++ b/libavcodec/aaccoder.c @@ -108,10 +108,10 @@ static av_always_inline float quantize_and_encode_band_cost_template( return cost * lambda; } if (!scaled) { - s->abs_pow34(s->scoefs, in, size); + s->aacdsp.abs_pow34(s->scoefs, in, size); scaled = s->scoefs; } - s->quant_bands(s->qcoefs, in, scaled, size, !BT_UNSIGNED, aac_cb_maxval[cb], Q34, ROUNDING); + s->aacdsp.quant_bands(s->qcoefs, in, scaled, size, !BT_UNSIGNED, aac_cb_maxval[cb], Q34, ROUNDING); if (BT_UNSIGNED) { off = 0; } else { @@ -311,7 +311,7 @@ static void encode_window_bands_info(AACEncContext *s, SingleChannelElement *sce float next_minrd = INFINITY; int next_mincb = 0; - s->abs_pow34(s->scoefs, sce->coeffs, 1024); + s->aacdsp.abs_pow34(s->scoefs, sce->coeffs, 1024); start = win*128; for (cb = 0; cb < CB_TOT_ALL; cb++) { path[0][cb].cost = 0.0f; @@ -522,7 +522,7 @@ static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, } } idx = 1; - s->abs_pow34(s->scoefs, sce->coeffs, 1024); + s->aacdsp.abs_pow34(s->scoefs, sce->coeffs, 1024); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { start = w*128; for (g = 0; g < sce->ics.num_swb; g++) { @@ -668,7 +668,7 @@ static void search_for_quantizers_fast(AVCodecContext *avctx, AACEncContext *s, if (!allz) return; - s->abs_pow34(s->scoefs, sce->coeffs, 1024); + s->aacdsp.abs_pow34(s->scoefs, sce->coeffs, 1024); ff_quantize_band_cost_cache_init(s); for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { @@ -874,8 +874,8 @@ static void search_for_pns(AACEncContext *s, AVCodecContext *avctx, SingleChanne s->fdsp->vector_fmul_scalar(PNS, PNS, scale, sce->ics.swb_sizes[g]); pns_senergy = s->fdsp->scalarproduct_float(PNS, PNS, sce->ics.swb_sizes[g]); pns_energy += pns_senergy; - s->abs_pow34(NOR34, &sce->coeffs[start_c], sce->ics.swb_sizes[g]); - s->abs_pow34(PNS34, PNS, sce->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(NOR34, &sce->coeffs[start_c], sce->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(PNS34, PNS, sce->ics.swb_sizes[g]); dist1 += quantize_band_cost(s, &sce->coeffs[start_c], NOR34, sce->ics.swb_sizes[g], @@ -1012,8 +1012,8 @@ static void search_for_ms(AACEncContext *s, ChannelElement *cpe) S[i] = M[i] - sce1->coeffs[start+(w+w2)*128+i]; } - s->abs_pow34(M34, M, sce0->ics.swb_sizes[g]); - s->abs_pow34(S34, S, sce0->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(M34, M, sce0->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(S34, S, sce0->ics.swb_sizes[g]); for (i = 0; i < sce0->ics.swb_sizes[g]; i++ ) { Mmax = FFMAX(Mmax, M34[i]); Smax = FFMAX(Smax, S34[i]); @@ -1056,10 +1056,10 @@ static void search_for_ms(AACEncContext *s, ChannelElement *cpe) - sce1->coeffs[start+(w+w2)*128+i]; } - s->abs_pow34(L34, sce0->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]); - s->abs_pow34(R34, sce1->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]); - s->abs_pow34(M34, M, sce0->ics.swb_sizes[g]); - s->abs_pow34(S34, S, sce0->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(L34, sce0->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(R34, sce1->coeffs+start+(w+w2)*128, sce0->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(M34, M, sce0->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(S34, S, sce0->ics.swb_sizes[g]); dist1 += quantize_band_cost(s, &sce0->coeffs[start + (w+w2)*128], L34, sce0->ics.swb_sizes[g], diff --git a/libavcodec/aaccoder_trellis.h b/libavcodec/aaccoder_trellis.h index 4810ff3208..245aa1c11b 100644 --- a/libavcodec/aaccoder_trellis.h +++ b/libavcodec/aaccoder_trellis.h @@ -70,7 +70,7 @@ static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, float next_minbits = INFINITY; int next_mincb = 0; - s->abs_pow34(s->scoefs, sce->coeffs, 1024); + s->aacdsp.abs_pow34(s->scoefs, sce->coeffs, 1024); start = win*128; for (cb = 0; cb < CB_TOT_ALL; cb++) { path[0][cb].cost = run_bits+4; diff --git a/libavcodec/aaccoder_twoloop.h b/libavcodec/aaccoder_twoloop.h index 0504a916ad..92dc2911a3 100644 --- a/libavcodec/aaccoder_twoloop.h +++ b/libavcodec/aaccoder_twoloop.h @@ -291,7 +291,7 @@ static void search_for_quantizers_twoloop(AVCodecContext *avctx, if (!allz) return; - s->abs_pow34(s->scoefs, sce->coeffs, 1024); + s->aacdsp.abs_pow34(s->scoefs, sce->coeffs, 1024); ff_quantize_band_cost_cache_init(s); for (i = 0; i < sizeof(minsf) / sizeof(minsf[0]); ++i) diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c index bce4e039dc..3f99188be4 100644 --- a/libavcodec/aacenc.c +++ b/libavcodec/aacenc.c @@ -1381,7 +1381,11 @@ static av_cold int aac_encode_init(AVCodecContext *avctx) ff_lpc_init(&s->lpc, 2*avctx->frame_size, TNS_MAX_ORDER, FF_LPC_TYPE_LEVINSON); s->random_state = 0x1f2e3d4c; - ff_aac_dsp_init(s); + ff_aacenc_dsp_init(&s->aacdsp); + +#if HAVE_MIPSDSP + ff_aac_coder_init_mips(s); +#endif ff_af_queue_init(avctx, &s->afq); @@ -1435,18 +1439,3 @@ const FFCodec ff_aac_encoder = { AV_SAMPLE_FMT_NONE }, .p.priv_class = &aacenc_class, }; - -void ff_aac_dsp_init(AACEncContext *s){ - s->abs_pow34 = abs_pow34_v; - s->quant_bands = quantize_bands; - -#if ARCH_RISCV - ff_aac_dsp_init_riscv(s); -#elif ARCH_X86 - ff_aac_dsp_init_x86(s); -#endif - -#if HAVE_MIPSDSP - ff_aac_coder_init_mips(s); -#endif -} diff --git a/libavcodec/aacenc.h b/libavcodec/aacenc.h index 752f1c26b2..c18e828905 100644 --- a/libavcodec/aacenc.h +++ b/libavcodec/aacenc.h @@ -33,6 +33,7 @@ #include "put_bits.h" #include "aac.h" +#include "aacencdsp.h" #include "audio_frame_queue.h" #include "psymodel.h" @@ -233,19 +234,13 @@ typedef struct AACEncContext { uint16_t quantize_band_cost_cache_generation; AACQuantizeBandCostCacheEntry quantize_band_cost_cache[256][128]; ///< memoization area for quantize_band_cost - void (*abs_pow34)(float *out, const float *in, const int size); - void (*quant_bands)(int *out, const float *in, const float *scaled, - int size, int is_signed, int maxval, const float Q34, - const float rounding); + AACEncDSPContext aacdsp; struct { float *samples; } buffer; } AACEncContext; -void ff_aac_dsp_init(AACEncContext *s); -void ff_aac_dsp_init_riscv(AACEncContext *s); -void ff_aac_dsp_init_x86(AACEncContext *s); void ff_aac_coder_init_mips(AACEncContext *c); void ff_quantize_band_cost_cache_init(struct AACEncContext *s); diff --git a/libavcodec/aacenc_is.c b/libavcodec/aacenc_is.c index 1810790d88..4943b6450c 100644 --- a/libavcodec/aacenc_is.c +++ b/libavcodec/aacenc_is.c @@ -59,9 +59,9 @@ struct AACISError ff_aac_is_encoding_err(AACEncContext *s, ChannelElement *cpe, float minthr = FFMIN(band0->threshold, band1->threshold); for (i = 0; i < sce0->ics.swb_sizes[g]; i++) IS[i] = (L[start+(w+w2)*128+i] + phase*R[start+(w+w2)*128+i])*sqrt(ener0/ener01); - s->abs_pow34(L34, &L[start+(w+w2)*128], sce0->ics.swb_sizes[g]); - s->abs_pow34(R34, &R[start+(w+w2)*128], sce0->ics.swb_sizes[g]); - s->abs_pow34(I34, IS, sce0->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(L34, &L[start+(w+w2)*128], sce0->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(R34, &R[start+(w+w2)*128], sce0->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(I34, IS, sce0->ics.swb_sizes[g]); maxval = find_max_val(1, sce0->ics.swb_sizes[g], I34); is_band_type = find_min_book(maxval, is_sf_idx); dist1 += quantize_band_cost(s, &L[start + (w+w2)*128], L34, diff --git a/libavcodec/aacenc_ltp.c b/libavcodec/aacenc_ltp.c index f3075f0e71..591ff6aedf 100644 --- a/libavcodec/aacenc_ltp.c +++ b/libavcodec/aacenc_ltp.c @@ -190,8 +190,8 @@ void ff_aac_search_for_ltp(AACEncContext *s, SingleChannelElement *sce, FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; for (i = 0; i < sce->ics.swb_sizes[g]; i++) PCD[i] = sce->coeffs[start+(w+w2)*128+i] - sce->lcoeffs[start+(w+w2)*128+i]; - s->abs_pow34(C34, &sce->coeffs[start+(w+w2)*128], sce->ics.swb_sizes[g]); - s->abs_pow34(PCD34, PCD, sce->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(C34, &sce->coeffs[start+(w+w2)*128], sce->ics.swb_sizes[g]); + s->aacdsp.abs_pow34(PCD34, PCD, sce->ics.swb_sizes[g]); dist1 += quantize_band_cost(s, &sce->coeffs[start+(w+w2)*128], C34, sce->ics.swb_sizes[g], sce->sf_idx[(w+w2)*16+g], sce->band_type[(w+w2)*16+g], s->lambda/band->threshold, INFINITY, &bits_tmp1, NULL); diff --git a/libavcodec/aacenc_pred.c b/libavcodec/aacenc_pred.c index f87fcd5a00..a486c44d42 100644 --- a/libavcodec/aacenc_pred.c +++ b/libavcodec/aacenc_pred.c @@ -270,7 +270,7 @@ void ff_aac_search_for_pred(AACEncContext *s, SingleChannelElement *sce) continue; /* Normal coefficients */ - s->abs_pow34(O34, &sce->coeffs[start_coef], num_coeffs); + s->aacdsp.abs_pow34(O34, &sce->coeffs[start_coef], num_coeffs); dist1 = ff_quantize_and_encode_band_cost(s, NULL, &sce->coeffs[start_coef], NULL, O34, num_coeffs, sce->sf_idx[sfb], cb_n, s->lambda / band->threshold, INFINITY, &cost1, NULL); @@ -279,7 +279,7 @@ void ff_aac_search_for_pred(AACEncContext *s, SingleChannelElement *sce) /* Encoded coefficients - needed for #bits, band type and quant. error */ for (i = 0; i < num_coeffs; i++) SENT[i] = sce->coeffs[start_coef + i] - sce->prcoeffs[start_coef + i]; - s->abs_pow34(S34, SENT, num_coeffs); + s->aacdsp.abs_pow34(S34, SENT, num_coeffs); if (cb_n < RESERVED_BT) cb_p = av_clip(find_min_book(find_max_val(1, num_coeffs, S34), sce->sf_idx[sfb]), cb_min, cb_max); else @@ -291,7 +291,7 @@ void ff_aac_search_for_pred(AACEncContext *s, SingleChannelElement *sce) /* Reconstructed coefficients - needed for distortion measurements */ for (i = 0; i < num_coeffs; i++) sce->prcoeffs[start_coef + i] += QERR[i] != 0.0f ? (sce->prcoeffs[start_coef + i] - QERR[i]) : 0.0f; - s->abs_pow34(P34, &sce->prcoeffs[start_coef], num_coeffs); + s->aacdsp.abs_pow34(P34, &sce->prcoeffs[start_coef], num_coeffs); if (cb_n < RESERVED_BT) cb_p = av_clip(find_min_book(find_max_val(1, num_coeffs, P34), sce->sf_idx[sfb]), cb_min, cb_max); else diff --git a/libavcodec/aacenc_utils.h b/libavcodec/aacenc_utils.h index ef2218e036..cc747c3ea6 100644 --- a/libavcodec/aacenc_utils.h +++ b/libavcodec/aacenc_utils.h @@ -37,15 +37,6 @@ #define ROUND_TO_ZERO 0.1054f #define C_QUANT 0.4054f -static inline void abs_pow34_v(float *out, const float *in, const int size) -{ - int i; - for (i = 0; i < size; i++) { - float a = fabsf(in[i]); - out[i] = sqrtf(a * sqrtf(a)); - } -} - static inline float pos_pow34(float a) { return sqrtf(a * sqrtf(a)); @@ -62,21 +53,6 @@ static inline int quant(float coef, const float Q, const float rounding) return sqrtf(a * sqrtf(a)) + rounding; } -static inline void quantize_bands(int *out, const float *in, const float *scaled, - int size, int is_signed, int maxval, const float Q34, - const float rounding) -{ - int i; - for (i = 0; i < size; i++) { - float qc = scaled[i] * Q34; - int tmp = (int)FFMIN(qc + rounding, (float)maxval); - if (is_signed && in[i] < 0.0f) { - tmp = -tmp; - } - out[i] = tmp; - } -} - static inline float find_max_val(int group_len, int swb_size, const float *scaled) { float maxval = 0.0f; diff --git a/libavcodec/aacencdsp.h b/libavcodec/aacencdsp.h new file mode 100644 index 0000000000..67836d8cf7 --- /dev/null +++ b/libavcodec/aacencdsp.h @@ -0,0 +1,72 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_AACENCDSP_H +#define AVCODEC_AACENCDSP_H + +#include <math.h> + +#include "config.h" + +#include "libavutil/macros.h" + +typedef struct AACEncDSPContext { + void (*abs_pow34)(float *out, const float *in, const int size); + void (*quant_bands)(int *out, const float *in, const float *scaled, + int size, int is_signed, int maxval, const float Q34, + const float rounding); +} AACEncDSPContext; + +void ff_aacenc_dsp_init_riscv(AACEncDSPContext *s); +void ff_aacenc_dsp_init_x86(AACEncDSPContext *s); + +static inline void abs_pow34_v(float *out, const float *in, const int size) +{ + for (int i = 0; i < size; i++) { + float a = fabsf(in[i]); + out[i] = sqrtf(a * sqrtf(a)); + } +} + +static inline void quantize_bands(int *out, const float *in, const float *scaled, + int size, int is_signed, int maxval, const float Q34, + const float rounding) +{ + for (int i = 0; i < size; i++) { + float qc = scaled[i] * Q34; + int tmp = (int)FFMIN(qc + rounding, (float)maxval); + if (is_signed && in[i] < 0.0f) { + tmp = -tmp; + } + out[i] = tmp; + } +} + +static inline void ff_aacenc_dsp_init(AACEncDSPContext *s) +{ + s->abs_pow34 = abs_pow34_v; + s->quant_bands = quantize_bands; + +#if ARCH_RISCV + ff_aacenc_dsp_init_riscv(s); +#elif ARCH_X86 + ff_aacenc_dsp_init_x86(s); +#endif +} + +#endif diff --git a/libavcodec/mips/aaccoder_mips.c b/libavcodec/mips/aaccoder_mips.c index bf27a2a5da..dd9661fbdd 100644 --- a/libavcodec/mips/aaccoder_mips.c +++ b/libavcodec/mips/aaccoder_mips.c @@ -61,6 +61,7 @@ #include "libavcodec/put_bits.h" #include "libavcodec/aac.h" #include "libavcodec/aacenc.h" +#include "libavcodec/aacencdsp.h" #include "libavcodec/aactab.h" #include "libavcodec/aacenctab.h" #include "libavcodec/aacenc_utils.h" diff --git a/libavcodec/riscv/aacencdsp_init.c b/libavcodec/riscv/aacencdsp_init.c index 83ae16f46b..b27af9d973 100644 --- a/libavcodec/riscv/aacencdsp_init.c +++ b/libavcodec/riscv/aacencdsp_init.c @@ -22,13 +22,12 @@ #include "config.h" #include "libavutil/attributes.h" -#include "libavutil/float_dsp.h" #include "libavutil/cpu.h" -#include "libavcodec/aacenc.h" +#include "libavcodec/aacencdsp.h" void ff_abs_pow34_rvv(float *out, const float *in, const int size); -av_cold void ff_aac_dsp_init_riscv(AACEncContext *s) +av_cold void ff_aacenc_dsp_init_riscv(AACEncDSPContext *s) { #if HAVE_RVV int flags = av_get_cpu_flags(); diff --git a/libavcodec/x86/aacencdsp_init.c b/libavcodec/x86/aacencdsp_init.c index 049a2417d9..e0d8dec4f8 100644 --- a/libavcodec/x86/aacencdsp_init.c +++ b/libavcodec/x86/aacencdsp_init.c @@ -22,9 +22,8 @@ #include "config.h" #include "libavutil/attributes.h" -#include "libavutil/float_dsp.h" #include "libavutil/x86/cpu.h" -#include "libavcodec/aacenc.h" +#include "libavcodec/aacencdsp.h" void ff_abs_pow34_sse(float *out, const float *in, const int size); @@ -32,7 +31,7 @@ void ff_aac_quantize_bands_sse2(int *out, const float *in, const float *scaled, int size, int is_signed, int maxval, const float Q34, const float rounding); -av_cold void ff_aac_dsp_init_x86(AACEncContext *s) +av_cold void ff_aacenc_dsp_init_x86(AACEncDSPContext *s) { int cpu_flags = av_get_cpu_flags(); |