spa: don't pass library around

Don't pass the library in the methods, we use the factory_name to
find the object. Make it possible to override the default library
with a property.
This commit is contained in:
Wim Taymans 2019-05-31 16:06:14 +02:00
parent 1d1f035e78
commit d4def56bcb
13 changed files with 99 additions and 86 deletions

View file

@ -304,9 +304,9 @@ struct pw_node *pw_audio_dsp_new(struct pw_core *core,
} }
pw_properties_set(pr, "factory.mode", factory); pw_properties_set(pr, "factory.mode", factory);
factory = "audioconvert"; factory = "audioconvert";
pw_properties_set(pr, "spa.library.name", "audioconvert/libspa-audioconvert");
node = pw_spa_node_load(core, NULL, NULL, node = pw_spa_node_load(core, NULL, NULL,
"audioconvert/libspa-audioconvert",
factory, factory,
node_name, node_name,
PW_SPA_NODE_FLAG_ACTIVATE | PW_SPA_NODE_FLAG_NO_REGISTER, PW_SPA_NODE_FLAG_ACTIVATE | PW_SPA_NODE_FLAG_NO_REGISTER,

View file

@ -32,6 +32,13 @@
#include <pipewire/pipewire.h> #include <pipewire/pipewire.h>
#include "pipewire/private.h" #include "pipewire/private.h"
#define FACTORY_USAGE PW_KEY_LINK_OUTPUT_NODE"=<output-node> " \
"["PW_KEY_LINK_OUTPUT_PORT"=<output-port>] " \
PW_KEY_LINK_INPUT_NODE"=<input-node " \
"["PW_KEY_LINK_INPUT_PORT"=<input-port>] " \
"["PW_KEY_OBJECT_LINGER"=<bool>] " \
"["PW_KEY_LINK_PASSIVE"=<bool>]"
static const struct spa_dict_item module_props[] = { static const struct spa_dict_item module_props[] = {
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" }, { PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
{ PW_KEY_MODULE_DESCRIPTION, "Allow clients to create links" }, { PW_KEY_MODULE_DESCRIPTION, "Allow clients to create links" },
@ -244,7 +251,7 @@ static void *create_object(void *_data,
return link; return link;
no_properties: no_properties:
pw_log_error("link-factory needs properties"); pw_log_error("link-factory usage:" FACTORY_USAGE);
pw_resource_error(resource, -EINVAL, "no properties"); pw_resource_error(resource, -EINVAL, "no properties");
goto done; goto done;
no_output: no_output:

View file

@ -33,6 +33,9 @@
#include "spa-device.h" #include "spa-device.h"
#define FACTORY_USAGE "spa.factory.name=<factory-name> " \
"[spa.library.name=<library-name>]"
static const struct spa_dict_item module_props[] = { static const struct spa_dict_item module_props[] = {
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" }, { PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
{ PW_KEY_MODULE_DESCRIPTION, "Provide a factory to make SPA devices" }, { PW_KEY_MODULE_DESCRIPTION, "Provide a factory to make SPA devices" },
@ -78,28 +81,23 @@ static void *create_object(void *_data,
struct factory_data *data = _data; struct factory_data *data = _data;
struct pw_core *core = data->core; struct pw_core *core = data->core;
struct pw_device *device; struct pw_device *device;
const char *lib, *factory_name, *name; const char *factory_name, *name;
struct device_data *nd; struct device_data *nd;
if (properties == NULL) if (properties == NULL)
goto no_properties; goto no_properties;
lib = pw_properties_get(properties, "spa.library.name");
factory_name = pw_properties_get(properties, "spa.factory.name"); factory_name = pw_properties_get(properties, "spa.factory.name");
name = pw_properties_get(properties, "name"); if (factory_name == NULL)
if (lib == NULL && factory_name != NULL)
lib = pw_core_find_spa_lib(core, factory_name);
if (lib == NULL || factory_name == NULL)
goto no_properties; goto no_properties;
name = pw_properties_get(properties, "name");
if (name == NULL) if (name == NULL)
name = "spa-device"; name = "spa-device";
device = pw_spa_device_load(core, device = pw_spa_device_load(core,
NULL, NULL,
pw_factory_get_global(data->this), pw_factory_get_global(data->this),
lib,
factory_name, factory_name,
name, name,
0, 0,
@ -123,12 +121,9 @@ static void *create_object(void *_data,
return device; return device;
no_properties: no_properties:
pw_log_error("needed properties: [spa.library.name=<library-name>] spa.factory.name=<factory-name>"); pw_log_error("factory %p: usage: " FACTORY_USAGE, data->this);
if (resource) { if (resource) {
pw_resource_error(resource, -EINVAL, pw_resource_error(resource, -EINVAL, "usage: " FACTORY_USAGE);
"needed properties: "
"[spa.library.name=<library-name>] "
"spa.factory.name=<factory-name>");
} }
return NULL; return NULL;
no_mem: no_mem:

View file

@ -38,16 +38,18 @@
#include "spa-monitor.h" #include "spa-monitor.h"
#include "spa-device.h" #include "spa-device.h"
#define MODULE_USAGE "<factory> <name> [key=value ...]"
static const struct spa_dict_item module_props[] = { static const struct spa_dict_item module_props[] = {
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" }, { PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
{ PW_KEY_MODULE_DESCRIPTION, "Load and manage an SPA device" }, { PW_KEY_MODULE_DESCRIPTION, "Load and manage an SPA device" },
{ PW_KEY_MODULE_USAGE, MODULE_USAGE },
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
struct device_data { struct device_data {
struct pw_device *this; struct pw_device *this;
struct pw_core *core; struct pw_core *core;
struct pw_properties *properties;
struct spa_hook module_listener; struct spa_hook module_listener;
}; };
@ -76,12 +78,12 @@ int pipewire__module_init(struct pw_module *module, const char *args)
if (args == NULL) if (args == NULL)
goto wrong_arguments; goto wrong_arguments;
argv = pw_split_strv(args, " \t", 4, &n_tokens); argv = pw_split_strv(args, " \t", 3, &n_tokens);
if (n_tokens < 3) if (n_tokens < 2)
goto not_enough_arguments; goto not_enough_arguments;
if (n_tokens == 4) { if (n_tokens == 3) {
props = pw_properties_new_string(argv[3]); props = pw_properties_new_string(argv[2]);
if (props == NULL) if (props == NULL)
return -ENOMEM; return -ENOMEM;
} }
@ -89,7 +91,7 @@ int pipewire__module_init(struct pw_module *module, const char *args)
device = pw_spa_device_load(core, device = pw_spa_device_load(core,
NULL, NULL,
pw_module_get_global(module), pw_module_get_global(module),
argv[0], argv[1], argv[2], argv[0], argv[1],
0, 0,
props, props,
sizeof(struct device_data)); sizeof(struct device_data));
@ -102,7 +104,6 @@ int pipewire__module_init(struct pw_module *module, const char *args)
data = pw_spa_device_get_user_data(device); data = pw_spa_device_get_user_data(device);
data->this = device; data->this = device;
data->core = core; data->core = core;
data->properties = props;
pw_log_debug("module %p: new", module); pw_log_debug("module %p: new", module);
pw_module_add_listener(module, &data->module_listener, &module_events, data); pw_module_add_listener(module, &data->module_listener, &module_events, data);
@ -114,6 +115,6 @@ int pipewire__module_init(struct pw_module *module, const char *args)
not_enough_arguments: not_enough_arguments:
pw_free_strv(argv); pw_free_strv(argv);
wrong_arguments: wrong_arguments:
pw_log_error("usage: module-spa-device <plugin> <factory> <name> [key=value ...]"); pw_log_error("usage: module-spa-device " MODULE_USAGE);
return -EINVAL; return -EINVAL;
} }

View file

@ -39,9 +39,12 @@
#include "spa-monitor.h" #include "spa-monitor.h"
#define MODULE_USAGE "<factory> <name> [key=value ...]"
static const struct spa_dict_item module_props[] = { static const struct spa_dict_item module_props[] = {
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" }, { PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
{ PW_KEY_MODULE_DESCRIPTION, "Manage SPA monitors" }, { PW_KEY_MODULE_DESCRIPTION, "Manage SPA monitors" },
{ PW_KEY_MODULE_USAGE, MODULE_USAGE },
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
@ -68,7 +71,7 @@ SPA_EXPORT
int pipewire__module_init(struct pw_module *module, const char *args) int pipewire__module_init(struct pw_module *module, const char *args)
{ {
struct pw_core *core = pw_module_get_core(module); struct pw_core *core = pw_module_get_core(module);
const char *dir, *lib; struct pw_properties *props = NULL;
char **argv; char **argv;
int n_tokens; int n_tokens;
struct pw_spa_monitor *monitor; struct pw_spa_monitor *monitor;
@ -81,18 +84,16 @@ int pipewire__module_init(struct pw_module *module, const char *args)
if (n_tokens < 2) if (n_tokens < 2)
goto not_enough_arguments; goto not_enough_arguments;
if ((dir = getenv("SPA_PLUGIN_DIR")) == NULL) if (n_tokens == 3) {
dir = PLUGINDIR; props = pw_properties_new_string(argv[2]);
if (props == NULL)
if (n_tokens < 3) return -ENOMEM;
lib = pw_core_find_spa_lib(core, argv[0]); }
else
lib = argv[2];
monitor = pw_spa_monitor_load(core, monitor = pw_spa_monitor_load(core,
pw_module_get_global(module), pw_module_get_global(module),
dir, lib, argv[0], argv[1], argv[0], argv[1],
NULL, props,
sizeof(struct data)); sizeof(struct data));
if (monitor == NULL) if (monitor == NULL)
return -ENOMEM; return -ENOMEM;
@ -111,6 +112,6 @@ int pipewire__module_init(struct pw_module *module, const char *args)
not_enough_arguments: not_enough_arguments:
pw_free_strv(argv); pw_free_strv(argv);
wrong_arguments: wrong_arguments:
pw_log_error("usage: module-spa-monitor <factory> <name> [<plugin>]"); pw_log_error("usage: module-spa-monitor " MODULE_USAGE);
return -EINVAL; return -EINVAL;
} }

View file

@ -33,6 +33,9 @@
#include "spa-node.h" #include "spa-node.h"
#define FACTORY_USAGE "spa.factory.name=<factory-name> " \
"[spa.library.name=<library-name>]"
static const struct spa_dict_item module_props[] = { static const struct spa_dict_item module_props[] = {
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" }, { PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
{ PW_KEY_MODULE_DESCRIPTION, "Provide a factory to make SPA nodes" }, { PW_KEY_MODULE_DESCRIPTION, "Provide a factory to make SPA nodes" },
@ -78,28 +81,23 @@ static void *create_object(void *_data,
struct factory_data *data = _data; struct factory_data *data = _data;
struct pw_core *core = data->core; struct pw_core *core = data->core;
struct pw_node *node; struct pw_node *node;
const char *lib, *factory_name, *name; const char *factory_name, *name;
struct node_data *nd; struct node_data *nd;
if (properties == NULL) if (properties == NULL)
goto no_properties; goto no_properties;
lib = pw_properties_get(properties, "spa.library.name");
factory_name = pw_properties_get(properties, "spa.factory.name"); factory_name = pw_properties_get(properties, "spa.factory.name");
name = pw_properties_get(properties, "name"); if (factory_name == NULL)
if (lib == NULL && factory_name != NULL)
lib = pw_core_find_spa_lib(core, factory_name);
if (lib == NULL || factory_name == NULL)
goto no_properties; goto no_properties;
name = pw_properties_get(properties, "name");
if (name == NULL) if (name == NULL)
name = "spa-node"; name = "spa-node";
node = pw_spa_node_load(core, node = pw_spa_node_load(core,
NULL, NULL,
pw_factory_get_global(data->this), pw_factory_get_global(data->this),
lib,
factory_name, factory_name,
name, name,
PW_SPA_NODE_FLAG_ACTIVATE, PW_SPA_NODE_FLAG_ACTIVATE,
@ -123,12 +121,9 @@ static void *create_object(void *_data,
return node; return node;
no_properties: no_properties:
pw_log_error("needed properties: [spa.library.name=<library-name>] spa.factory.name=<factory-name>"); pw_log_error("factory %p: usage: " FACTORY_USAGE, data->this);
if (resource) { if (resource) {
pw_resource_error(resource, -EINVAL, pw_resource_error(resource, -EINVAL, "usage: " FACTORY_USAGE);
"needed properties: "
"[spa.library.name=<library-name>] "
"spa.factory.name=<factory-name>");
} }
return NULL; return NULL;
no_mem: no_mem:

View file

@ -40,9 +40,12 @@
#include "spa-monitor.h" #include "spa-monitor.h"
#include "spa-node.h" #include "spa-node.h"
#define MODULE_USAGE "<factory> <name> [key=value ...]"
static const struct spa_dict_item module_props[] = { static const struct spa_dict_item module_props[] = {
{ PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" }, { PW_KEY_MODULE_AUTHOR, "Wim Taymans <wim.taymans@gmail.com>" },
{ PW_KEY_MODULE_DESCRIPTION, "Load and manage an SPA node" }, { PW_KEY_MODULE_DESCRIPTION, "Load and manage an SPA node" },
{ PW_KEY_MODULE_USAGE, MODULE_USAGE },
{ PW_KEY_MODULE_VERSION, PACKAGE_VERSION }, { PW_KEY_MODULE_VERSION, PACKAGE_VERSION },
}; };
@ -78,12 +81,12 @@ int pipewire__module_init(struct pw_module *module, const char *args)
if (args == NULL) if (args == NULL)
goto wrong_arguments; goto wrong_arguments;
argv = pw_split_strv(args, " \t", 4, &n_tokens); argv = pw_split_strv(args, " \t", 3, &n_tokens);
if (n_tokens < 3) if (n_tokens < 2)
goto not_enough_arguments; goto not_enough_arguments;
if (n_tokens == 4) { if (n_tokens == 3) {
props = pw_properties_new_string(argv[3]); props = pw_properties_new_string(argv[2]);
if (props == NULL) if (props == NULL)
return -ENOMEM; return -ENOMEM;
} }
@ -91,7 +94,7 @@ int pipewire__module_init(struct pw_module *module, const char *args)
node = pw_spa_node_load(core, node = pw_spa_node_load(core,
NULL, NULL,
pw_module_get_global(module), pw_module_get_global(module),
argv[0], argv[1], argv[2], argv[0], argv[1],
PW_SPA_NODE_FLAG_ACTIVATE, PW_SPA_NODE_FLAG_ACTIVATE,
props, props,
sizeof(struct node_data)); sizeof(struct node_data));
@ -116,6 +119,6 @@ int pipewire__module_init(struct pw_module *module, const char *args)
not_enough_arguments: not_enough_arguments:
pw_free_strv(argv); pw_free_strv(argv);
wrong_arguments: wrong_arguments:
pw_log_error("usage: module-spa-node <plugin> <factory> <name> [key=value ...]"); pw_log_error("usage: module-spa-node " MODULE_USAGE);
return -EINVAL; return -EINVAL;
} }

View file

@ -52,7 +52,6 @@ struct impl {
void *unload; void *unload;
struct spa_handle *handle; struct spa_handle *handle;
struct spa_device *device; struct spa_device *device;
char *lib;
char *factory_name; char *factory_name;
struct spa_hook device_listener; struct spa_hook device_listener;
@ -70,7 +69,6 @@ static void device_destroy(void *data)
spa_hook_remove(&impl->device_listener); spa_hook_remove(&impl->device_listener);
if (impl->handle) if (impl->handle)
pw_unload_spa_handle(impl->handle); pw_unload_spa_handle(impl->handle);
free(impl->lib);
free(impl->factory_name); free(impl->factory_name);
} }
@ -126,7 +124,6 @@ void *pw_spa_device_get_user_data(struct pw_device *device)
struct pw_device *pw_spa_device_load(struct pw_core *core, struct pw_device *pw_spa_device_load(struct pw_core *core,
struct pw_client *owner, struct pw_client *owner,
struct pw_global *parent, struct pw_global *parent,
const char *lib,
const char *factory_name, const char *factory_name,
const char *name, const char *name,
enum pw_spa_device_flags flags, enum pw_spa_device_flags flags,
@ -137,31 +134,42 @@ struct pw_device *pw_spa_device_load(struct pw_core *core,
struct impl *impl; struct impl *impl;
struct spa_handle *handle; struct spa_handle *handle;
const struct spa_support *support; const struct spa_support *support;
const char *lib = NULL;
uint32_t n_support; uint32_t n_support;
void *iface; void *iface;
int res; int res;
support = pw_core_get_support(core, &n_support); support = pw_core_get_support(core, &n_support);
if (lib == NULL && properties)
lib = pw_properties_get(properties, "spa.library.name");
if (lib == NULL)
lib = pw_core_find_spa_lib(core, factory_name);
if (lib == NULL)
goto exit;
handle = pw_load_spa_handle(lib, factory_name, handle = pw_load_spa_handle(lib, factory_name,
properties ? &properties->dict : NULL, n_support, support); properties ? &properties->dict : NULL, n_support, support);
if (handle == NULL) if (handle == NULL)
goto open_failed; goto exit;
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Device, &iface)) < 0) { if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Device, &iface)) < 0) {
pw_log_error("can't get device interface %d\n", res); pw_log_error("can't get device interface %d\n", res);
goto open_failed; goto exit_unload;
} }
this = pw_spa_device_new(core, owner, parent, name, flags, this = pw_spa_device_new(core, owner, parent, name, flags,
iface, handle, properties, user_data_size); iface, handle, properties, user_data_size);
if (this == NULL)
goto exit;
impl = this->user_data; impl = this->user_data;
impl->lib = strdup(lib);
impl->factory_name = strdup(factory_name); impl->factory_name = strdup(factory_name);
return this; return this;
open_failed: exit_unload:
pw_unload_spa_handle(handle);
exit:
return NULL; return NULL;
} }

View file

@ -54,7 +54,6 @@ struct pw_device *
pw_spa_device_load(struct pw_core *core, pw_spa_device_load(struct pw_core *core,
struct pw_client *owner, /**< optional owner */ struct pw_client *owner, /**< optional owner */
struct pw_global *parent, /**< optional parent */ struct pw_global *parent, /**< optional parent */
const char *lib,
const char *factory_name, const char *factory_name,
const char *name, const char *name,
enum pw_spa_device_flags flags, enum pw_spa_device_flags flags,

View file

@ -264,8 +264,6 @@ static const struct spa_monitor_callbacks callbacks = {
struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core, struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
struct pw_global *parent, struct pw_global *parent,
const char *dir,
const char *lib,
const char *factory_name, const char *factory_name,
const char *system_name, const char *system_name,
struct pw_properties *properties, struct pw_properties *properties,
@ -274,13 +272,18 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
struct impl *impl; struct impl *impl;
struct pw_spa_monitor *this; struct pw_spa_monitor *this;
struct spa_handle *handle; struct spa_handle *handle;
const char *lib = NULL;
int res; int res;
void *iface; void *iface;
char *filename;
const struct spa_support *support; const struct spa_support *support;
uint32_t n_support; uint32_t n_support;
asprintf(&filename, "%s/%s.so", dir, lib); if (lib == NULL && properties)
lib = pw_properties_get(properties, "spa.library.name");
if (lib == NULL)
lib = pw_core_find_spa_lib(core, factory_name);
if (lib == NULL)
goto exit;
support = pw_core_get_support(core, &n_support); support = pw_core_get_support(core, &n_support);
@ -289,20 +292,23 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
properties ? &properties->dict : NULL, properties ? &properties->dict : NULL,
n_support, support); n_support, support);
if (handle == NULL) if (handle == NULL)
goto no_mem; goto exit;
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Monitor, &iface)) < 0) { if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Monitor, &iface)) < 0) {
pw_log_error("can't get MONITOR interface: %d", res); pw_log_error("can't get MONITOR interface: %d", res);
goto interface_failed; goto exit_unload;
} }
impl = calloc(1, sizeof(struct impl) + user_data_size); impl = calloc(1, sizeof(struct impl) + user_data_size);
if (impl == NULL)
goto exit_unload;
impl->core = core; impl->core = core;
impl->parent = parent; impl->parent = parent;
spa_list_init(&impl->item_list);
this = &impl->this; this = &impl->this;
this->monitor = iface; this->monitor = iface;
this->lib = filename;
this->factory_name = strdup(factory_name); this->factory_name = strdup(factory_name);
this->system_name = strdup(system_name); this->system_name = strdup(system_name);
this->handle = handle; this->handle = handle;
@ -313,16 +319,13 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
update_monitor(core, this->system_name); update_monitor(core, this->system_name);
spa_list_init(&impl->item_list);
spa_monitor_set_callbacks(this->monitor, &callbacks, impl); spa_monitor_set_callbacks(this->monitor, &callbacks, impl);
return this; return this;
interface_failed: exit_unload:
pw_unload_spa_handle(handle); pw_unload_spa_handle(handle);
no_mem: exit:
free(filename);
return NULL; return NULL;
} }
@ -338,7 +341,6 @@ void pw_spa_monitor_destroy(struct pw_spa_monitor *monitor)
destroy_object(obj); destroy_object(obj);
pw_unload_spa_handle(monitor->handle); pw_unload_spa_handle(monitor->handle);
free(monitor->lib);
free(monitor->factory_name); free(monitor->factory_name);
free(monitor->system_name); free(monitor->system_name);
if (monitor->properties) if (monitor->properties)

View file

@ -36,7 +36,6 @@ extern "C" {
struct pw_spa_monitor { struct pw_spa_monitor {
struct spa_monitor *monitor; struct spa_monitor *monitor;
char *lib;
char *factory_name; char *factory_name;
char *system_name; char *system_name;
struct spa_handle *handle; struct spa_handle *handle;
@ -48,8 +47,6 @@ struct pw_spa_monitor {
struct pw_spa_monitor * struct pw_spa_monitor *
pw_spa_monitor_load(struct pw_core *core, pw_spa_monitor_load(struct pw_core *core,
struct pw_global *parent, struct pw_global *parent,
const char *dir,
const char *lib,
const char *factory_name, const char *factory_name,
const char *system_name, const char *system_name,
struct pw_properties *properties, struct pw_properties *properties,

View file

@ -53,7 +53,6 @@ struct impl {
struct spa_handle *handle; struct spa_handle *handle;
struct spa_node *node; /**< handle to SPA node */ struct spa_node *node; /**< handle to SPA node */
char *lib;
char *factory_name; char *factory_name;
struct spa_hook node_listener; struct spa_hook node_listener;
@ -75,7 +74,6 @@ static void spa_node_free(void *data)
if (impl->handle) { if (impl->handle) {
pw_unload_spa_handle(impl->handle); pw_unload_spa_handle(impl->handle);
} }
free(impl->lib);
free(impl->factory_name); free(impl->factory_name);
} }
@ -242,7 +240,6 @@ setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_propertie
struct pw_node *pw_spa_node_load(struct pw_core *core, struct pw_node *pw_spa_node_load(struct pw_core *core,
struct pw_client *owner, struct pw_client *owner,
struct pw_global *parent, struct pw_global *parent,
const char *lib,
const char *factory_name, const char *factory_name,
const char *name, const char *name,
enum pw_spa_node_flags flags, enum pw_spa_node_flags flags,
@ -252,12 +249,20 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
struct pw_node *this; struct pw_node *this;
struct impl *impl; struct impl *impl;
struct spa_node *spa_node; struct spa_node *spa_node;
const char *lib = NULL;
int res; int res;
struct spa_handle *handle; struct spa_handle *handle;
void *iface; void *iface;
const struct spa_support *support; const struct spa_support *support;
uint32_t n_support; uint32_t n_support;
if (lib == NULL && properties)
lib = pw_properties_get(properties, "spa.library.name");
if (lib == NULL)
lib = pw_core_find_spa_lib(core, factory_name);
if (lib == NULL)
goto exit;
support = pw_core_get_support(core, &n_support); support = pw_core_get_support(core, &n_support);
handle = pw_load_spa_handle(lib, handle = pw_load_spa_handle(lib,
@ -265,11 +270,11 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
properties ? &properties->dict : NULL, properties ? &properties->dict : NULL,
n_support, support); n_support, support);
if (handle == NULL) if (handle == NULL)
goto no_mem; goto exit;
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Node, &iface)) < 0) { if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Node, &iface)) < 0) {
pw_log_error("can't get node interface %d", res); pw_log_error("can't get node interface %d", res);
goto interface_failed; goto exit_unload;
} }
if (SPA_RESULT_IS_ASYNC(res)) if (SPA_RESULT_IS_ASYNC(res))
flags |= PW_SPA_NODE_FLAG_ASYNC; flags |= PW_SPA_NODE_FLAG_ASYNC;
@ -284,16 +289,17 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
this = pw_spa_node_new(core, owner, parent, name, flags, this = pw_spa_node_new(core, owner, parent, name, flags,
spa_node, handle, properties, user_data_size); spa_node, handle, properties, user_data_size);
if (this == NULL)
goto exit;
impl = this->user_data; impl = this->user_data;
impl->handle = handle; impl->handle = handle;
impl->lib = strdup(lib);
impl->factory_name = strdup(factory_name); impl->factory_name = strdup(factory_name);
return this; return this;
interface_failed: exit_unload:
pw_unload_spa_handle(handle); pw_unload_spa_handle(handle);
no_mem: exit:
return NULL; return NULL;
} }

View file

@ -55,7 +55,6 @@ struct pw_node *
pw_spa_node_load(struct pw_core *core, pw_spa_node_load(struct pw_core *core,
struct pw_client *owner, /**< optional owner */ struct pw_client *owner, /**< optional owner */
struct pw_global *parent, /**< optional parent */ struct pw_global *parent, /**< optional parent */
const char *lib,
const char *factory_name, const char *factory_name,
const char *name, const char *name,
enum pw_spa_node_flags flags, enum pw_spa_node_flags flags,