mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-07 13:30:09 -05:00
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:
parent
504d78cd18
commit
c6c9e6a8b3
10 changed files with 87 additions and 138 deletions
|
|
@ -1043,7 +1043,8 @@ static void client_node_initialized(void *data)
|
|||
if (!exclusive &&
|
||||
media_type == SPA_MEDIA_TYPE_audio &&
|
||||
media_subtype == SPA_MEDIA_SUBTYPE_raw) {
|
||||
struct spa_dict_item items[2];
|
||||
struct spa_dict_item items[3];
|
||||
uint32_t n_items;
|
||||
const char *mode;
|
||||
void *iface;
|
||||
|
||||
|
|
@ -1052,14 +1053,14 @@ static void client_node_initialized(void *data)
|
|||
else
|
||||
mode = "merge";
|
||||
|
||||
items[0] = SPA_DICT_ITEM_INIT("factory.mode", mode);
|
||||
items[1] = SPA_DICT_ITEM_INIT("resample.peaks", monitor ? "1" : "0");
|
||||
n_items = 0;
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("factory.mode", mode);
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT("resample.peaks", monitor ? "1" : "0");
|
||||
items[n_items++] = SPA_DICT_ITEM_INIT(SPA_KEY_LIBRARY_NAME, "audioconvert/libspa-audioconvert");
|
||||
|
||||
|
||||
if ((impl->handle = pw_load_spa_handle("audioconvert/libspa-audioconvert",
|
||||
"audioconvert",
|
||||
&SPA_DICT_INIT(items, 2),
|
||||
0, NULL)) == NULL)
|
||||
if ((impl->handle = pw_core_load_spa_handle(impl->core,
|
||||
"audioconvert",
|
||||
&SPA_DICT_INIT(items, n_items))) == NULL)
|
||||
return;
|
||||
|
||||
if ((res = spa_handle_get_interface(impl->handle,
|
||||
|
|
@ -1277,7 +1278,6 @@ struct pw_client_stream *pw_client_stream_new(struct pw_resource *resource,
|
|||
spa_node_set_callbacks(impl->cnode, &node_callbacks, impl);
|
||||
|
||||
support = pw_core_get_support(impl->core, &n_support);
|
||||
|
||||
node_init(&impl->node, NULL, support, n_support);
|
||||
impl->node.impl = impl;
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue