diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index bee9e3e28..898211576 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -560,6 +561,8 @@ struct impl { struct spa_hook core_proxy_listener; struct spa_hook core_listener; + struct dsp_ops dsp; + struct spa_list plugin_list; struct pw_properties *capture_props; @@ -1184,14 +1187,14 @@ static struct plugin *plugin_load(struct impl *impl, const char *type, const cha support = pw_context_get_support(impl->context, &n_support); if (spa_streq(type, "builtin")) { - pl = load_builtin_plugin(support, n_support, path, NULL); + pl = load_builtin_plugin(support, n_support, &impl->dsp, path, NULL); } else if (spa_streq(type, "ladspa")) { - pl = load_ladspa_plugin(support, n_support, path, NULL); + pl = load_ladspa_plugin(support, n_support, &impl->dsp, path, NULL); } else if (spa_streq(type, "lv2")) { #ifdef HAVE_LILV - pl = load_lv2_plugin(support, n_support, path, NULL); + pl = load_lv2_plugin(support, n_support, &impl->dsp, path, NULL); #else pw_log_error("filter-chain is compiled without lv2 support"); pl = NULL; @@ -2244,6 +2247,9 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) uint32_t pid = getpid(); const char *str; int res; + const struct spa_support *support; + uint32_t n_support; + struct spa_cpu *cpu_iface; PW_LOG_TOPIC_INIT(mod_topic); @@ -2274,10 +2280,16 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args) impl->module = module; impl->context = context; - impl->graph.impl = impl; + spa_list_init(&impl->plugin_list); + support = pw_context_get_support(impl->context, &n_support); + + cpu_iface = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_CPU); + impl->dsp.cpu_flags = cpu_iface ? spa_cpu_get_flags(cpu_iface) : 0; + dsp_ops_init(&impl->dsp); + if (pw_properties_get(props, PW_KEY_NODE_GROUP) == NULL) pw_properties_setf(props, PW_KEY_NODE_GROUP, "filter-chain-%u-%u", pid, id); if (pw_properties_get(props, PW_KEY_NODE_LINK_GROUP) == NULL) diff --git a/src/modules/module-filter-chain/builtin_plugin.c b/src/modules/module-filter-chain/builtin_plugin.c index 49163686e..9ad5314c9 100644 --- a/src/modules/module-filter-chain/builtin_plugin.c +++ b/src/modules/module-filter-chain/builtin_plugin.c @@ -44,7 +44,7 @@ #include "convolver.h" #include "dsp-ops.h" -static struct dsp_ops dsp_ops; +static struct dsp_ops *dsp_ops; struct builtin { unsigned long rate; @@ -87,7 +87,7 @@ static void copy_run(void * Instance, unsigned long SampleCount) { struct builtin *impl = Instance; float *in = impl->port[1], *out = impl->port[0]; - dsp_ops_copy(&dsp_ops, out, in, SampleCount); + dsp_ops_copy(dsp_ops, out, in, SampleCount); } static struct fc_port copy_ports[] = { @@ -136,7 +136,7 @@ static void mixer_run(void * Instance, unsigned long SampleCount) src[n_src] = in; gains[n_src++] = gain; } - dsp_ops_mix_gain(&dsp_ops, out, src, gains, n_src, SampleCount); + dsp_ops_mix_gain(dsp_ops, out, src, gains, n_src, SampleCount); } static struct fc_port mixer_ports[] = { @@ -275,7 +275,7 @@ static void bq_run(struct builtin *impl, unsigned long samples, int type) impl->gain = gain; biquad_set(bq, type, freq * 2 / impl->rate, Q, gain); } - dsp_ops_biquad_run(&dsp_ops, bq, out, in, samples); + dsp_ops_biquad_run(dsp_ops, bq, out, in, samples); } /** bq_lowpass */ @@ -554,7 +554,7 @@ static float *resample_buffer(float *samples, int *n_samples, r.channels = 1; r.i_rate = in_rate; r.o_rate = out_rate; - r.cpu_flags = dsp_ops.cpu_flags; + r.cpu_flags = dsp_ops->cpu_flags; r.quality = quality; if ((res = resample_native_init(&r)) < 0) { pw_log_error("resampling failed: %s", spa_strerror(res)); @@ -975,14 +975,9 @@ static struct fc_plugin builtin_plugin = { }; struct fc_plugin *load_builtin_plugin(const struct spa_support *support, uint32_t n_support, - const char *plugin, const char *config) + struct dsp_ops *dsp, const char *plugin, const char *config) { - struct spa_cpu *cpu_iface; - uint32_t cpu_flags; - cpu_iface = spa_support_find(support, n_support, SPA_TYPE_INTERFACE_CPU); - cpu_flags = cpu_iface ? spa_cpu_get_flags(cpu_iface) : 0; - dsp_ops.cpu_flags = cpu_flags; - dsp_ops_init(&dsp_ops); - pffft_select_cpu(cpu_flags); + dsp_ops = dsp; + pffft_select_cpu(dsp->cpu_flags); return &builtin_plugin; } diff --git a/src/modules/module-filter-chain/dsp-ops.h b/src/modules/module-filter-chain/dsp-ops.h index 3bf7cda19..87f0e71de 100644 --- a/src/modules/module-filter-chain/dsp-ops.h +++ b/src/modules/module-filter-chain/dsp-ops.h @@ -22,6 +22,9 @@ * DEALINGS IN THE SOFTWARE. */ +#ifndef DSP_OPS_H +#define DSP_OPS_H + #include #include "biquad.h" @@ -69,3 +72,5 @@ MAKE_BIQUAD_RUN_FUNC(c); #if defined (HAVE_SSE) MAKE_MIX_GAIN_FUNC(sse); #endif + +#endif /* DSP_OPS_H */ diff --git a/src/modules/module-filter-chain/ladspa_plugin.c b/src/modules/module-filter-chain/ladspa_plugin.c index 172fc2523..195d1ab37 100644 --- a/src/modules/module-filter-chain/ladspa_plugin.c +++ b/src/modules/module-filter-chain/ladspa_plugin.c @@ -229,7 +229,7 @@ exit: } struct fc_plugin *load_ladspa_plugin(const struct spa_support *support, uint32_t n_support, - const char *plugin, const char *config) + struct dsp_ops *dsp, const char *plugin, const char *config) { struct fc_plugin *pl = NULL; diff --git a/src/modules/module-filter-chain/lv2_plugin.c b/src/modules/module-filter-chain/lv2_plugin.c index e607e2f1e..f0bd8363b 100644 --- a/src/modules/module-filter-chain/lv2_plugin.c +++ b/src/modules/module-filter-chain/lv2_plugin.c @@ -472,7 +472,7 @@ static void lv2_unload(struct fc_plugin *plugin) } struct fc_plugin *load_lv2_plugin(const struct spa_support *support, uint32_t n_support, - const char *plugin_uri, const char *config) + struct dsp_ops *ops, const char *plugin_uri, const char *config) { struct context *c; const LilvPlugins *plugins; diff --git a/src/modules/module-filter-chain/plugin.h b/src/modules/module-filter-chain/plugin.h index 12ead2d97..72946e4cb 100644 --- a/src/modules/module-filter-chain/plugin.h +++ b/src/modules/module-filter-chain/plugin.h @@ -22,6 +22,9 @@ * DEALINGS IN THE SOFTWARE. */ +#ifndef PLUGIN_H +#define PLUGIN_H + #include #include #include @@ -33,6 +36,8 @@ #include #include +#include "dsp-ops.h" + struct fc_plugin { const struct fc_descriptor *(*make_desc)(struct fc_plugin *plugin, const char *name); void (*unload) (struct fc_plugin *plugin); @@ -98,8 +103,10 @@ static inline void fc_descriptor_free(const struct fc_descriptor *desc) } struct fc_plugin *load_ladspa_plugin(const struct spa_support *support, uint32_t n_support, - const char *path, const char *config); + struct dsp_ops *dsp, const char *path, const char *config); struct fc_plugin *load_lv2_plugin(const struct spa_support *support, uint32_t n_support, - const char *path, const char *config); + struct dsp_ops *dsp, const char *path, const char *config); struct fc_plugin *load_builtin_plugin(const struct spa_support *support, uint32_t n_support, - const char *path, const char *config); + struct dsp_ops *dsp, const char *path, const char *config); + +#endif /* PLUGIN_H */