filter-chain: pass dsp_ops around

Initialize dsp_ops in the filter-chain and pass it around.
This commit is contained in:
Wim Taymans 2022-12-16 09:28:00 +01:00
parent f7c49bbdde
commit fa10849139
6 changed files with 41 additions and 22 deletions

View file

@ -38,6 +38,7 @@
#include <spa/utils/result.h> #include <spa/utils/result.h>
#include <spa/utils/string.h> #include <spa/utils/string.h>
#include <spa/utils/json.h> #include <spa/utils/json.h>
#include <spa/support/cpu.h>
#include <spa/param/profiler.h> #include <spa/param/profiler.h>
#include <spa/pod/dynamic.h> #include <spa/pod/dynamic.h>
#include <spa/debug/pod.h> #include <spa/debug/pod.h>
@ -560,6 +561,8 @@ struct impl {
struct spa_hook core_proxy_listener; struct spa_hook core_proxy_listener;
struct spa_hook core_listener; struct spa_hook core_listener;
struct dsp_ops dsp;
struct spa_list plugin_list; struct spa_list plugin_list;
struct pw_properties *capture_props; 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); support = pw_context_get_support(impl->context, &n_support);
if (spa_streq(type, "builtin")) { 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")) { 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")) { else if (spa_streq(type, "lv2")) {
#ifdef HAVE_LILV #ifdef HAVE_LILV
pl = load_lv2_plugin(support, n_support, path, NULL); pl = load_lv2_plugin(support, n_support, &impl->dsp, path, NULL);
#else #else
pw_log_error("filter-chain is compiled without lv2 support"); pw_log_error("filter-chain is compiled without lv2 support");
pl = NULL; pl = NULL;
@ -2244,6 +2247,9 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
uint32_t pid = getpid(); uint32_t pid = getpid();
const char *str; const char *str;
int res; int res;
const struct spa_support *support;
uint32_t n_support;
struct spa_cpu *cpu_iface;
PW_LOG_TOPIC_INIT(mod_topic); 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->module = module;
impl->context = context; impl->context = context;
impl->graph.impl = impl; impl->graph.impl = impl;
spa_list_init(&impl->plugin_list); 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) if (pw_properties_get(props, PW_KEY_NODE_GROUP) == NULL)
pw_properties_setf(props, PW_KEY_NODE_GROUP, "filter-chain-%u-%u", pid, id); 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) if (pw_properties_get(props, PW_KEY_NODE_LINK_GROUP) == NULL)

View file

@ -44,7 +44,7 @@
#include "convolver.h" #include "convolver.h"
#include "dsp-ops.h" #include "dsp-ops.h"
static struct dsp_ops dsp_ops; static struct dsp_ops *dsp_ops;
struct builtin { struct builtin {
unsigned long rate; unsigned long rate;
@ -87,7 +87,7 @@ static void copy_run(void * Instance, unsigned long SampleCount)
{ {
struct builtin *impl = Instance; struct builtin *impl = Instance;
float *in = impl->port[1], *out = impl->port[0]; 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[] = { static struct fc_port copy_ports[] = {
@ -136,7 +136,7 @@ static void mixer_run(void * Instance, unsigned long SampleCount)
src[n_src] = in; src[n_src] = in;
gains[n_src++] = gain; 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[] = { 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; impl->gain = gain;
biquad_set(bq, type, freq * 2 / impl->rate, Q, 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 */ /** bq_lowpass */
@ -554,7 +554,7 @@ static float *resample_buffer(float *samples, int *n_samples,
r.channels = 1; r.channels = 1;
r.i_rate = in_rate; r.i_rate = in_rate;
r.o_rate = out_rate; r.o_rate = out_rate;
r.cpu_flags = dsp_ops.cpu_flags; r.cpu_flags = dsp_ops->cpu_flags;
r.quality = quality; r.quality = quality;
if ((res = resample_native_init(&r)) < 0) { if ((res = resample_native_init(&r)) < 0) {
pw_log_error("resampling failed: %s", spa_strerror(res)); 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, 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; dsp_ops = dsp;
uint32_t cpu_flags; pffft_select_cpu(dsp->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);
return &builtin_plugin; return &builtin_plugin;
} }

View file

@ -22,6 +22,9 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#ifndef DSP_OPS_H
#define DSP_OPS_H
#include <spa/utils/defs.h> #include <spa/utils/defs.h>
#include "biquad.h" #include "biquad.h"
@ -69,3 +72,5 @@ MAKE_BIQUAD_RUN_FUNC(c);
#if defined (HAVE_SSE) #if defined (HAVE_SSE)
MAKE_MIX_GAIN_FUNC(sse); MAKE_MIX_GAIN_FUNC(sse);
#endif #endif
#endif /* DSP_OPS_H */

View file

@ -229,7 +229,7 @@ exit:
} }
struct fc_plugin *load_ladspa_plugin(const struct spa_support *support, uint32_t n_support, 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; struct fc_plugin *pl = NULL;

View file

@ -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, 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; struct context *c;
const LilvPlugins *plugins; const LilvPlugins *plugins;

View file

@ -22,6 +22,9 @@
* DEALINGS IN THE SOFTWARE. * DEALINGS IN THE SOFTWARE.
*/ */
#ifndef PLUGIN_H
#define PLUGIN_H
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
#include <errno.h> #include <errno.h>
@ -33,6 +36,8 @@
#include <spa/utils/list.h> #include <spa/utils/list.h>
#include <spa/utils/string.h> #include <spa/utils/string.h>
#include "dsp-ops.h"
struct fc_plugin { struct fc_plugin {
const struct fc_descriptor *(*make_desc)(struct fc_plugin *plugin, const char *name); const struct fc_descriptor *(*make_desc)(struct fc_plugin *plugin, const char *name);
void (*unload) (struct fc_plugin *plugin); 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, 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, 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, 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 */