core: add method to load spa_handle

Add a method that loads a spa handle based on the currently configured
libraries in the core. Remove duplicate code.
This commit is contained in:
Wim Taymans 2019-06-07 10:12:44 +02:00
parent 504d78cd18
commit c6c9e6a8b3
10 changed files with 87 additions and 138 deletions

View file

@ -133,35 +133,27 @@ struct pw_device *pw_spa_device_load(struct pw_core *core,
struct pw_device *this;
struct impl *impl;
struct spa_handle *handle;
const struct spa_support *support;
const char *lib = NULL;
uint32_t n_support;
void *iface;
int res;
support = pw_core_get_support(core, &n_support);
if (lib == NULL && properties)
lib = pw_properties_get(properties, SPA_KEY_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,
properties ? &properties->dict : NULL, n_support, support);
if (handle == NULL)
handle = pw_core_load_spa_handle(core, factory_name,
properties ? &properties->dict : NULL);
if (handle == NULL) {
pw_log_error("can't load device handle: %m");
goto exit;
}
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", res);
goto exit_unload;
}
this = pw_spa_device_new(core, owner, parent, name, flags,
iface, handle, properties, user_data_size);
if (this == NULL)
if (this == NULL) {
pw_log_error("can't create device: %m");
goto exit;
}
impl = this->user_data;
impl->factory_name = strdup(factory_name);

View file

@ -89,11 +89,9 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
int res;
struct spa_handle *handle;
struct monitor_object *obj;
const char *name, *str, *lib;
const char *name, *str;
void *iface;
struct pw_properties *props = NULL;
const struct spa_support *support;
uint32_t n_support;
if (info->props)
props = pw_properties_new_dict(info->props);
@ -111,17 +109,8 @@ static struct monitor_object *add_object(struct pw_spa_monitor *this, uint32_t i
if (now != 0 && pw_properties_get(props, PW_KEY_DEVICE_PLUGGED) == NULL)
pw_properties_setf(props, PW_KEY_DEVICE_PLUGGED, "%"PRIu64, now);
lib = pw_core_find_spa_lib(core, info->factory_name);
if (lib == NULL) {
pw_log_warn("monitor %p: unknown library for %s",
this, info->factory_name);
goto error_free_props;
}
support = pw_core_get_support(core, &n_support);
handle = pw_load_spa_handle(lib, info->factory_name,
&props->dict, n_support, support);
handle = pw_core_load_spa_handle(core, info->factory_name,
&props->dict);
if (handle == NULL) {
pw_log_error("can't make factory instance: %m");
goto error_free_props;
@ -272,25 +261,12 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
struct impl *impl;
struct pw_spa_monitor *this;
struct spa_handle *handle;
const char *lib = NULL;
int res;
void *iface;
const struct spa_support *support;
uint32_t n_support;
if (lib == NULL && properties)
lib = pw_properties_get(properties, SPA_KEY_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);
handle = pw_load_spa_handle(lib,
handle = pw_core_load_spa_handle(core,
factory_name,
properties ? &properties->dict : NULL,
n_support, support);
properties ? &properties->dict : NULL);
if (handle == NULL)
goto exit;

View file

@ -249,26 +249,13 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
struct pw_node *this;
struct impl *impl;
struct spa_node *spa_node;
const char *lib = NULL;
int res;
struct spa_handle *handle;
void *iface;
const struct spa_support *support;
uint32_t n_support;
if (lib == NULL && properties)
lib = pw_properties_get(properties, SPA_KEY_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);
handle = pw_load_spa_handle(lib,
handle = pw_core_load_spa_handle(core,
factory_name,
properties ? &properties->dict : NULL,
n_support, support);
properties ? &properties->dict : NULL);
if (handle == NULL)
goto exit;