pipewire: only load spa_handle

Only provide a method to load a spa_handle, getting the interface
from that is easy and we only use refcounting on the handle.
This commit is contained in:
Wim Taymans 2019-05-20 09:49:39 +02:00
parent da9f0ed160
commit b195a25636
5 changed files with 86 additions and 128 deletions

View file

@ -91,6 +91,7 @@ struct impl {
enum spa_direction direction;
struct spa_node *cnode;
struct spa_handle *handle;
struct spa_node *adapter;
struct spa_hook adapter_listener;
struct spa_node *adapter_mix;
@ -1055,6 +1056,7 @@ static void client_node_initialized(void *data)
media_subtype == SPA_MEDIA_SUBTYPE_raw) {
struct spa_dict_item items[2];
const char *mode;
void *iface;
if (impl->direction == SPA_DIRECTION_OUTPUT)
mode = "split";
@ -1064,13 +1066,18 @@ static void client_node_initialized(void *data)
items[0] = SPA_DICT_ITEM_INIT("factory.mode", mode);
items[1] = SPA_DICT_ITEM_INIT("resample.peaks", monitor ? "1" : "0");
if ((impl->adapter = pw_load_spa_interface("audioconvert/libspa-audioconvert",
if ((impl->handle = pw_load_spa_handle("audioconvert/libspa-audioconvert",
"audioconvert",
SPA_TYPE_INTERFACE_Node,
&SPA_DICT_INIT(items, 2),
0, NULL)) == NULL)
return;
if ((res = spa_handle_get_interface(impl->handle,
SPA_TYPE_INTERFACE_Node, &iface)) < 0)
return;
impl->adapter = iface;
impl->adapter_mix = impl->adapter;
impl->adapter_mix_port = 0;
impl->use_converter = true;
@ -1118,8 +1125,8 @@ static void cleanup(struct impl *impl)
{
pw_log_debug("client-stream %p: cleanup", &impl->this);
if (impl->use_converter) {
if (impl->adapter)
pw_unload_spa_interface(impl->adapter);
if (impl->handle)
pw_unload_spa_handle(impl->handle);
}
free(impl->buffers);

View file

@ -68,12 +68,8 @@ static void device_destroy(void *data)
pw_log_debug("spa-device %p: free", device);
spa_hook_remove(&impl->device_listener);
if (impl->unload)
pw_unload_spa_interface(impl->unload);
if (impl->handle) {
spa_handle_clear(impl->handle);
free(impl->handle);
}
if (impl->handle)
pw_unload_spa_handle(impl->handle);
free(impl->lib);
free(impl->factory_name);
}
@ -106,6 +102,7 @@ pw_spa_device_new(struct pw_core *core,
impl->owner = owner;
impl->parent = parent;
impl->device = device;
impl->handle = handle;
impl->flags = flags;
if (user_data_size > 0)
@ -138,22 +135,28 @@ struct pw_device *pw_spa_device_load(struct pw_core *core,
{
struct pw_device *this;
struct impl *impl;
struct spa_device *device;
struct spa_handle *handle;
const struct spa_support *support;
uint32_t n_support;
void *iface;
int res;
support = pw_core_get_support(core, &n_support);
device = pw_load_spa_interface(lib, factory_name, SPA_TYPE_INTERFACE_Device,
handle = pw_load_spa_handle(lib, factory_name,
properties ? &properties->dict : NULL, n_support, support);
if (device == NULL)
if (handle == NULL)
goto open_failed;
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Device, &iface)) < 0) {
pw_log_error("can't get device interface %d\n", res);
goto open_failed;
}
this = pw_spa_device_new(core, owner, parent, name, flags,
device, NULL, properties, user_data_size);
iface, handle, properties, user_data_size);
impl = this->user_data;
impl->unload = device;
impl->lib = strdup(lib);
impl->factory_name = strdup(factory_name);