filter-chain: pass dict in plugin load function

So that we can pass some more properties around and remove the
quantum_limit hardcoded value.
This commit is contained in:
Wim Taymans 2024-11-07 16:40:38 +01:00
parent c7854e1da4
commit 1661f15b9c
6 changed files with 26 additions and 15 deletions

View file

@ -701,9 +701,9 @@ static const struct spa_dict_item module_props[] = {
#define DEFAULT_RATE 48000
struct fc_plugin *load_ladspa_plugin(const struct spa_support *support, uint32_t n_support,
struct dsp_ops *dsp, const char *path, const char *config);
struct dsp_ops *dsp, const char *path, const struct spa_dict *info);
struct fc_plugin *load_builtin_plugin(const struct spa_support *support, uint32_t n_support,
struct dsp_ops *dsp, const char *path, const char *config);
struct dsp_ops *dsp, const char *path, const struct spa_dict *info);
struct plugin {
struct spa_list link;
@ -844,6 +844,7 @@ struct impl {
struct pw_context *context;
struct pw_impl_module *module;
struct pw_properties *props;
struct spa_hook module_listener;
@ -1814,7 +1815,7 @@ static struct plugin *plugin_load(struct impl *impl, const char *type, const cha
pw_log_error("can't load plugin type '%s': %m", type);
pl = NULL;
} else {
pl = plugin_func(support, n_support, &impl->dsp, path, NULL);
pl = plugin_func(support, n_support, &impl->dsp, path, &impl->props->dict);
}
if (pl == NULL)
goto exit;
@ -3012,6 +3013,7 @@ static void impl_destroy(struct impl *impl)
spa_list_consume(pl, &impl->plugin_func_list, link)
free_plugin_func(pl);
pw_properties_free(impl->props);
free(impl->silence_data);
free(impl->discard_data);
free(impl);
@ -3082,6 +3084,7 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
pw_log_error( "can't create properties: %m");
goto error;
}
impl->props = props;
impl->capture_props = pw_properties_new(NULL, NULL);
impl->playback_props = pw_properties_new(NULL, NULL);
@ -3106,6 +3109,8 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
pw_context_get_properties(impl->context),
"default.clock.quantum-limit", 8192u);
pw_properties_setf(props, "clock.quantum-limit", "%u", impl->quantum_limit);
impl->silence_data = calloc(impl->quantum_limit, sizeof(float));
if (impl->silence_data == NULL) {
res = -errno;
@ -3208,7 +3213,6 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
pw_log_error("can't connect: %m");
goto error;
}
pw_properties_free(props);
pw_proxy_add_listener((struct pw_proxy*)impl->core,
&impl->core_proxy_listener,
@ -3226,7 +3230,6 @@ int pipewire__module_init(struct pw_impl_module *module, const char *args)
return 0;
error:
pw_properties_free(props);
impl_destroy(impl);
return res;
}

View file

@ -2119,7 +2119,7 @@ static void builtin_plugin_unload(struct fc_plugin *p)
}
struct fc_plugin *load_builtin_plugin(const struct spa_support *support, uint32_t n_support,
struct dsp_ops *dsp, const char *plugin, const char *config)
struct dsp_ops *dsp, const char *plugin, const struct spa_dict *info)
{
struct plugin *impl = calloc (1, sizeof (struct plugin));
impl->plugin.make_desc = builtin_make_desc;

View file

@ -210,7 +210,7 @@ exit:
}
struct fc_plugin *load_ladspa_plugin(const struct spa_support *support, uint32_t n_support,
struct dsp_ops *dsp, const char *plugin, const char *config)
struct dsp_ops *dsp, const char *plugin, const struct spa_dict *info)
{
struct fc_plugin *pl = NULL;

View file

@ -460,7 +460,7 @@ static void lv2_unload(struct fc_plugin *plugin)
SPA_EXPORT
struct fc_plugin *pipewire__filter_chain_plugin_load(const struct spa_support *support, uint32_t n_support,
struct dsp_ops *ops, const char *plugin_uri, const char *config)
struct dsp_ops *dsp, const char *plugin_uri, const struct spa_dict *info)
{
struct context *c;
const LilvPlugins *plugins;

View file

@ -80,7 +80,7 @@ static inline void fc_descriptor_free(const struct fc_descriptor *desc)
#define FC_PLUGIN_LOAD_FUNC "pipewire__filter_chain_plugin_load"
typedef struct fc_plugin *(fc_plugin_load_func)(const struct spa_support *support, uint32_t n_support,
struct dsp_ops *dsp, const char *path, const char *config);
struct dsp_ops *dsp, const char *path, const struct spa_dict *info);
#endif /* PLUGIN_H */

View file

@ -14,13 +14,12 @@
#include <mysofa.h>
#define MAX_SAMPLES 8192u
struct plugin {
struct fc_plugin plugin;
struct dsp_ops *dsp_ops;
struct spa_loop *data_loop;
struct spa_loop *main_loop;
uint32_t quantum_limit;
};
struct spatializer_impl {
@ -179,8 +178,8 @@ static void * spatializer_instantiate(const struct fc_plugin *plugin, const stru
pw_log_info("using n_samples:%u %d:%d blocksize sofa:%s", impl->n_samples,
impl->blocksize, impl->tailsize, filename);
impl->tmp[0] = calloc(MAX_SAMPLES, sizeof(float));
impl->tmp[1] = calloc(MAX_SAMPLES, sizeof(float));
impl->tmp[0] = calloc(impl->plugin->quantum_limit, sizeof(float));
impl->tmp[1] = calloc(impl->plugin->quantum_limit, sizeof(float));
impl->rate = SampleRate;
return impl;
error:
@ -279,7 +278,7 @@ static void spatializer_run(void * Instance, unsigned long SampleCount)
struct spatializer_impl *impl = Instance;
if (impl->interpolate) {
uint32_t len = SPA_MIN(SampleCount, MAX_SAMPLES);
uint32_t len = SPA_MIN(SampleCount, impl->plugin->quantum_limit);
struct free_data free_data;
float *l = impl->tmp[0], *r = impl->tmp[1];
@ -424,12 +423,21 @@ static void sofa_plugin_unload(struct fc_plugin *p)
SPA_EXPORT
struct fc_plugin *pipewire__filter_chain_plugin_load(const struct spa_support *support, uint32_t n_support,
struct dsp_ops *dsp, const char *plugin, const char *config)
struct dsp_ops *dsp, const char *plugin, const struct spa_dict *info)
{
struct plugin *impl = calloc(1, sizeof (struct plugin));
impl->plugin.make_desc = sofa_make_desc;
impl->plugin.unload = sofa_plugin_unload;
impl->quantum_limit = 8192u;
for (uint32_t i = 0; info && i < info->n_items; i++) {
const char *k = info->items[i].key;
const char *s = info->items[i].value;
if (spa_streq(k, "clock.quantum-limit"))
spa_atou32(s, &impl->quantum_limit, 0);
}
impl->dsp_ops = dsp;
pffft_select_cpu(dsp->cpu_flags);