From fe06d5533f8085d685456c99cb1872c64c19f02e Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt Date: Fri, 12 Sep 2025 18:23:14 +0200 Subject: [PATCH] swresample/x86/rematrix_init: Avoid allocation for native_simd_one Reviewed-by: Michael Niedermayer Signed-off-by: Andreas Rheinhardt --- libswresample/rematrix.c | 1 - libswresample/swresample.c | 2 +- libswresample/swresample_internal.h | 5 ++++- libswresample/x86/rematrix_init.c | 12 +++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c index 906f6e0f34..76681e9229 100644 --- a/libswresample/rematrix.c +++ b/libswresample/rematrix.c @@ -562,7 +562,6 @@ av_cold int swri_rematrix_init(SwrContext *s){ av_cold void swri_rematrix_free(SwrContext *s){ av_freep(&s->native_matrix); av_freep(&s->native_simd_matrix); - av_freep(&s->native_simd_one); } int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy){ diff --git a/libswresample/swresample.c b/libswresample/swresample.c index 67fb7964b2..998ee7b73a 100644 --- a/libswresample/swresample.c +++ b/libswresample/swresample.c @@ -688,7 +688,7 @@ static int swr_convert_internal(struct SwrContext *s, AudioData *out, int out_co if(len1) for(ch=0; chch_count; ch++) - s->mix_2_1_simd(conv_src->ch[ch], preout->ch[ch], s->dither.noise.ch[ch] + s->dither.noise.bps * s->dither.noise_pos, s->native_simd_one, 0, 0, len1); + s->mix_2_1_simd(conv_src->ch[ch], preout->ch[ch], s->dither.noise.ch[ch] + s->dither.noise.bps * s->dither.noise_pos, &s->native_simd_one, 0, 0, len1); if(out_count != len1) for(ch=0; chch_count; ch++) s->mix_2_1_f(conv_src->ch[ch] + off, preout->ch[ch] + off, s->dither.noise.ch[ch] + s->dither.noise.bps * s->dither.noise_pos + off, &s->native_one, 0, 0, out_count - len1); diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h index 1c889272c8..b016ba3315 100644 --- a/libswresample/swresample_internal.h +++ b/libswresample/swresample_internal.h @@ -179,7 +179,10 @@ struct SwrContext { double d; } native_one; uint8_t *native_matrix; - uint8_t *native_simd_one; + union { + int16_t i16[2]; + float f; + } native_simd_one; uint8_t *native_simd_matrix; uint8_t matrix_ch[SWR_CH_MAX][SWR_CH_MAX+1]; ///< Lists of input channels per output channel that have non zero rematrixing coefficients mix_1_1_func_type *mix_1_1_f; diff --git a/libswresample/x86/rematrix_init.c b/libswresample/x86/rematrix_init.c index 5d2c7d9a37..89ec362d62 100644 --- a/libswresample/x86/rematrix_init.c +++ b/libswresample/x86/rematrix_init.c @@ -48,8 +48,7 @@ av_cold int swri_rematrix_init_x86(struct SwrContext *s){ s->mix_2_1_simd = ff_mix_2_1_a_int16_sse2; } s->native_simd_matrix = av_calloc(num, 2 * sizeof(int16_t)); - s->native_simd_one = av_mallocz(2 * sizeof(int16_t)); - if (!s->native_simd_matrix || !s->native_simd_one) + if (!s->native_simd_matrix) return AVERROR(ENOMEM); for(i=0; inative_matrix)[i * nb_in + j]) + (1<>1)) >> sh; } } - ((int16_t*)s->native_simd_one)[1] = 14; - ((int16_t*)s->native_simd_one)[0] = 16384; + s->native_simd_one.i16[1] = 14; + s->native_simd_one.i16[0] = 16384; } else if(s->midbuf.fmt == AV_SAMPLE_FMT_FLTP){ if(EXTERNAL_SSE(mm_flags)) { s->mix_1_1_simd = ff_mix_1_1_a_float_sse; @@ -75,11 +74,10 @@ av_cold int swri_rematrix_init_x86(struct SwrContext *s){ s->mix_2_1_simd = ff_mix_2_1_a_float_avx; } s->native_simd_matrix = av_calloc(num, sizeof(float)); - s->native_simd_one = av_mallocz(sizeof(float)); - if (!s->native_simd_matrix || !s->native_simd_one) + if (!s->native_simd_matrix) return AVERROR(ENOMEM); memcpy(s->native_simd_matrix, s->native_matrix, num * sizeof(float)); - memcpy(s->native_simd_one, &s->native_one.f, sizeof(float)); + s->native_simd_one.f = s->native_one.f; } #endif