1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

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>
This commit is contained in:
Andreas Rheinhardt 2024-02-28 13:29:19 +01:00
parent 6c693da690
commit 88b3b09afa
14 changed files with 112 additions and 81 deletions

View File

@ -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],

View File

@ -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;

View File

@ -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)

View File

@ -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
}

View File

@ -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);

View File

@ -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,

View File

@ -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);

View File

@ -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

View File

@ -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;

72
libavcodec/aacencdsp.h Normal file
View File

@ -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

View File

@ -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"

View File

@ -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();

View File

@ -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();

View File

@ -20,10 +20,9 @@
#include <string.h>
#include "libavutil/mem.h"
#include "libavutil/mem_internal.h"
#include "libavcodec/aacenc.h"
#include "libavcodec/aacencdsp.h"
#include "checkasm.h"
@ -36,7 +35,8 @@
} \
} while (0)
static void test_abs_pow34(AACEncContext *s) {
static void test_abs_pow34(AACEncDSPContext *s)
{
#define BUF_SIZE 1024
LOCAL_ALIGNED_32(float, in, [BUF_SIZE]);
@ -63,8 +63,8 @@ static void test_abs_pow34(AACEncContext *s) {
void checkasm_check_aacencdsp(void)
{
AACEncContext s = { 0 };
ff_aac_dsp_init(&s);
AACEncDSPContext s = { 0 };
ff_aacenc_dsp_init(&s);
test_abs_pow34(&s);
}