From 1a3017e1535f6d3f77faad4107d0165b105d23ed Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 19 Jan 2023 09:57:15 +0100 Subject: [PATCH] Add patch to avoid DSP mixing issues with AVX in filter-chain. Add patch to revert API breakage with deprecated symbols. Add patch to fix scaling overflow that could cause stuttering. --- ...x-audioconvert-overflow-when-scaling.patch | 75 +++++++++++++++++++ ...hain-fix-AVX-dsp_sum-index-increment.patch | 26 +++++++ ...remove-deprecated-symbols-by-default.patch | 68 +++++++++++++++++ pipewire.spec | 10 ++- 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 0001-spa-Fix-audioconvert-overflow-when-scaling.patch create mode 100644 0002-filter-chain-fix-AVX-dsp_sum-index-increment.patch create mode 100644 0003-keys-don-t-remove-deprecated-symbols-by-default.patch diff --git a/0001-spa-Fix-audioconvert-overflow-when-scaling.patch b/0001-spa-Fix-audioconvert-overflow-when-scaling.patch new file mode 100644 index 0000000..d59e626 --- /dev/null +++ b/0001-spa-Fix-audioconvert-overflow-when-scaling.patch @@ -0,0 +1,75 @@ +From f27ccf1fc4d58bd707c1907c4c137181566e274f Mon Sep 17 00:00:00 2001 +From: Wim Taymans +Date: Mon, 16 Jan 2023 18:28:31 +0100 +Subject: [PATCH 1/3] spa: Fix audioconvert overflow when scaling + +Add SPA_SCALE32_UP that scales a uint32 without overflow. +Use this for scaling the threshold in ALSA. +Fix the scaling in audioconvert of the buffer size, the scaling was +wrong and it was also causing an overflow resulting in choppy sound in +some cases. + +See #2680 +--- + spa/include/spa/utils/defs.h | 8 ++++++++ + spa/plugins/alsa/alsa-pcm.c | 4 ++-- + spa/plugins/audioconvert/audioconvert.c | 2 +- + 3 files changed, 11 insertions(+), 3 deletions(-) + +diff --git a/spa/include/spa/utils/defs.h b/spa/include/spa/utils/defs.h +index c602c9348..3b4862663 100644 +--- a/spa/include/spa/utils/defs.h ++++ b/spa/include/spa/utils/defs.h +@@ -274,6 +274,14 @@ struct spa_fraction { + #define SPA_ROUND_DOWN_N(num,align) ((num) & ~SPA_ROUND_MASK(num, align)) + #define SPA_ROUND_UP_N(num,align) ((((num)-1) | SPA_ROUND_MASK(num, align))+1) + ++#define SPA_SCALE32_UP(val,num,denom) \ ++({ \ ++ uint64_t _val = (val); \ ++ uint64_t _denom = (denom); \ ++ (uint32_t)(((_val) * (num) + (_denom)-1) / (_denom)); \ ++}) ++ ++ + #define SPA_PTR_ALIGNMENT(p,align) ((intptr_t)(p) & ((align)-1)) + #define SPA_IS_ALIGNED(p,align) (SPA_PTR_ALIGNMENT(p,align) == 0) + #define SPA_PTR_ALIGN(p,align,type) ((type*)SPA_ROUND_UP_N((intptr_t)(p), (intptr_t)(align))) +diff --git a/spa/plugins/alsa/alsa-pcm.c b/spa/plugins/alsa/alsa-pcm.c +index 76fe433b8..d93e2869e 100644 +--- a/spa/plugins/alsa/alsa-pcm.c ++++ b/spa/plugins/alsa/alsa-pcm.c +@@ -1985,7 +1985,7 @@ static inline void check_position_config(struct state *state) + (state->rate_denom != state->position->clock.rate.denom))) { + state->duration = state->position->clock.duration; + state->rate_denom = state->position->clock.rate.denom; +- state->threshold = (state->duration * state->rate + state->rate_denom-1) / state->rate_denom; ++ state->threshold = SPA_SCALE32_UP(state->duration, state->rate, state->rate_denom); + state->max_error = SPA_MAX(256.0f, state->threshold / 2.0f); + state->resample = ((uint32_t)state->rate != state->rate_denom) || state->matching; + state->alsa_sync = true; +@@ -2547,7 +2547,7 @@ int spa_alsa_start(struct state *state) + setup_matching(state); + + spa_dll_init(&state->dll); +- state->threshold = (state->duration * state->rate + state->rate_denom-1) / state->rate_denom; ++ state->threshold = SPA_SCALE32_UP(state->duration, state->rate, state->rate_denom); + state->last_threshold = state->threshold; + state->max_error = SPA_MAX(256.0f, state->threshold / 2.0f); + +diff --git a/spa/plugins/audioconvert/audioconvert.c b/spa/plugins/audioconvert/audioconvert.c +index 578f70ff9..783ab8174 100644 +--- a/spa/plugins/audioconvert/audioconvert.c ++++ b/spa/plugins/audioconvert/audioconvert.c +@@ -1755,7 +1755,7 @@ impl_node_port_enum_params(void *object, int seq, + size = this->quantum_limit * 2; + /* scale the buffer size when we can. */ + if (irate != 0 && orate != 0) +- size = size * (irate + orate - 1) / orate; ++ size = SPA_SCALE32_UP(size, irate, orate); + } + + param = spa_pod_builder_add_object(&b, +-- +2.39.0 + diff --git a/0002-filter-chain-fix-AVX-dsp_sum-index-increment.patch b/0002-filter-chain-fix-AVX-dsp_sum-index-increment.patch new file mode 100644 index 0000000..0768cb4 --- /dev/null +++ b/0002-filter-chain-fix-AVX-dsp_sum-index-increment.patch @@ -0,0 +1,26 @@ +From 2dc1bf3af7572eab99899b565aefa9f22b993a1f Mon Sep 17 00:00:00 2001 +From: Wim Taymans +Date: Tue, 17 Jan 2023 09:24:00 +0100 +Subject: [PATCH 2/3] filter-chain: fix AVX dsp_sum index increment + +Fixes #2965 +--- + src/modules/module-filter-chain/dsp-ops-avx.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/modules/module-filter-chain/dsp-ops-avx.c b/src/modules/module-filter-chain/dsp-ops-avx.c +index 64abcaa44..7ea5456fa 100644 +--- a/src/modules/module-filter-chain/dsp-ops-avx.c ++++ b/src/modules/module-filter-chain/dsp-ops-avx.c +@@ -59,7 +59,7 @@ void dsp_sum_avx(struct dsp_ops *ops, float *r, const float *a, const float *b, + _mm256_store_ps(&r[n+24], in[3]); + } + } else { +- for (n = 0; n < unrolled; n += 16) { ++ for (n = 0; n < unrolled; n += 32) { + in[0] = _mm256_loadu_ps(&a[n+ 0]); + in[1] = _mm256_loadu_ps(&a[n+ 8]); + in[2] = _mm256_loadu_ps(&a[n+16]); +-- +2.39.0 + diff --git a/0003-keys-don-t-remove-deprecated-symbols-by-default.patch b/0003-keys-don-t-remove-deprecated-symbols-by-default.patch new file mode 100644 index 0000000..832fa0f --- /dev/null +++ b/0003-keys-don-t-remove-deprecated-symbols-by-default.patch @@ -0,0 +1,68 @@ +From 7acd8551be3b8614b62026077931bd57c5368cfd Mon Sep 17 00:00:00 2001 +From: Wim Taymans +Date: Tue, 17 Jan 2023 11:58:04 +0100 +Subject: [PATCH 3/3] keys: don't remove deprecated symbols by default + +Add a new macro to mark deprecated keys. The macro will emit a warning +about the symbol being deprecated. +PW_ENABLE_DEPRECATED will suppress the deprecation warning. +Add PW_REMOVE_DEPRECATED to completely remove the deprecated symbols. + +Fixes #2952 +--- + src/pipewire/keys.h | 11 ++++++----- + src/pipewire/utils.h | 6 ++++++ + 2 files changed, 12 insertions(+), 5 deletions(-) + +diff --git a/src/pipewire/keys.h b/src/pipewire/keys.h +index 81c9c30e0..c7cbf9da1 100644 +--- a/src/pipewire/keys.h ++++ b/src/pipewire/keys.h +@@ -29,6 +29,7 @@ + extern "C" { + #endif + ++#include + /** + * \defgroup pw_keys Key Names + * +@@ -334,14 +335,14 @@ extern "C" { + #define PW_KEY_VIDEO_FORMAT "video.format" /**< a video format */ + #define PW_KEY_VIDEO_SIZE "video.size" /**< a video size as "x/dev/null 2>&1 || : %{_libdir}/pipewire-%{apiversion}/libpipewire-module-x11-bell.so %changelog +* Thu Jan 19 2023 Wim Taymans - 0.3.64-3 +- Add patch to avoid DSP mixing issues with AVX in filter-chain. +- Add patch to revert API breakage with deprecated symbols. +- Add patch to fix scaling overflow that could cause stuttering. + * Tue Jan 17 2023 Wim Taymans - 0.3.64-2 - Re-enabled roc-toolkit support.