spa: use core to load spa_handle

This commit is contained in:
Wim Taymans 2019-05-29 17:53:25 +02:00
parent 165f3e06ad
commit 3780bd1b30
3 changed files with 20 additions and 101 deletions

View file

@ -1186,7 +1186,7 @@ node_init(struct node *this,
this->data_source.mask = SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP;
this->data_source.rmask = 0;
return SPA_RESULT_RETURN_ASYNC(0);
return 0;
}
static int node_clear(struct node *this)

View file

@ -43,6 +43,7 @@
#include <pipewire/node.h>
#include <pipewire/device.h>
#include <pipewire/keys.h>
#include <pipewire/pipewire.h>
#include "spa-monitor.h"
#include "spa-device.h"
@ -63,8 +64,6 @@ struct impl {
struct pw_core *core;
struct pw_global *parent;
void *hnd;
struct spa_list item_list;
};
@ -334,45 +333,21 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
struct spa_handle *handle;
int res;
void *iface;
void *hnd;
uint32_t index;
spa_handle_factory_enum_func_t enum_func;
const struct spa_handle_factory *factory;
char *filename;
const struct spa_support *support;
uint32_t n_support;
asprintf(&filename, "%s/%s.so", dir, lib);
if ((hnd = dlopen(filename, RTLD_NOW)) == NULL) {
pw_log_error("can't load %s: %s", filename, dlerror());
goto open_failed;
}
if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
pw_log_error("can't find enum function");
goto no_symbol;
}
support = pw_core_get_support(core, &n_support);
for (index = 0;;) {
if ((res = enum_func(&factory, &index)) <= 0) {
if (res != 0)
pw_log_error("can't enumerate factories: %s", spa_strerror(res));
goto enum_failed;
}
if (strcmp(factory->name, factory_name) == 0)
break;
}
handle = calloc(1, spa_handle_factory_get_size(factory, NULL));
handle = pw_load_spa_handle(lib,
factory_name,
NULL,
n_support, support);
if (handle == NULL)
goto no_mem;
support = pw_core_get_support(core, &n_support);
if ((res = spa_handle_factory_init(factory,
handle, NULL, support, n_support)) < 0) {
pw_log_error("can't make factory instance: %d", res);
goto init_failed;
}
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Monitor, &iface)) < 0) {
pw_log_error("can't get MONITOR interface: %d", res);
goto interface_failed;
@ -381,7 +356,6 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
impl = calloc(1, sizeof(struct impl) + user_data_size);
impl->core = core;
impl->parent = parent;
impl->hnd = hnd;
this = &impl->this;
this->monitor = iface;
@ -402,14 +376,8 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
return this;
interface_failed:
spa_handle_clear(handle);
init_failed:
free(handle);
pw_unload_spa_handle(handle);
no_mem:
enum_failed:
no_symbol:
dlclose(hnd);
open_failed:
free(filename);
return NULL;
@ -425,12 +393,10 @@ void pw_spa_monitor_destroy(struct pw_spa_monitor *monitor)
spa_list_for_each_safe(mitem, tmp, &impl->item_list, link)
destroy_item(mitem);
spa_handle_clear(monitor->handle);
free(monitor->handle);
pw_unload_spa_handle(monitor->handle);
free(monitor->lib);
free(monitor->factory_name);
free(monitor->system_name);
dlclose(impl->hnd);
free(impl);
}

View file

@ -41,6 +41,7 @@
#include "pipewire/port.h"
#include "pipewire/log.h"
#include "pipewire/private.h"
#include "pipewire/pipewire.h"
struct impl {
struct pw_node *this;
@ -50,7 +51,6 @@ struct impl {
enum pw_spa_node_flags flags;
void *hnd;
struct spa_handle *handle;
struct spa_node *node; /**< handle to SPA node */
char *lib;
@ -73,13 +73,10 @@ static void spa_node_free(void *data)
spa_hook_remove(&impl->node_listener);
if (impl->handle) {
spa_handle_clear(impl->handle);
free(impl->handle);
pw_unload_spa_handle(impl->handle);
}
free(impl->lib);
free(impl->factory_name);
if (impl->hnd)
dlclose(impl->hnd);
}
static void complete_init(struct impl *impl)
@ -257,62 +254,26 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
struct spa_node *spa_node;
int res;
struct spa_handle *handle;
void *hnd;
uint32_t index;
spa_handle_factory_enum_func_t enum_func;
const struct spa_handle_factory *factory;
void *iface;
char *filename;
const char *dir;
const struct spa_support *support;
uint32_t n_support;
if ((dir = getenv("SPA_PLUGIN_DIR")) == NULL)
dir = PLUGINDIR;
asprintf(&filename, "%s/%s.so", dir, lib);
if ((hnd = dlopen(filename, RTLD_NOW)) == NULL) {
pw_log_error("can't load %s: %s", filename, dlerror());
goto open_failed;
}
if ((enum_func = dlsym(hnd, SPA_HANDLE_FACTORY_ENUM_FUNC_NAME)) == NULL) {
pw_log_error("can't find enum function");
goto no_symbol;
}
for (index = 0;;) {
if ((res = enum_func(&factory, &index)) <= 0) {
if (res != 0)
pw_log_error("can't enumerate factories: %s", spa_strerror(res));
goto enum_failed;
}
if (strcmp(factory->name, factory_name) == 0)
break;
}
support = pw_core_get_support(core, &n_support);
handle = calloc(1, spa_handle_factory_get_size(factory, NULL));
handle = pw_load_spa_handle(lib,
factory_name,
properties ? &properties->dict : NULL,
n_support, support);
if (handle == NULL)
goto no_mem;
if ((res = spa_handle_factory_init(factory,
handle,
properties ? &properties->dict : NULL,
support,
n_support)) < 0) {
pw_log_error("can't make factory instance: %d", res);
goto init_failed;
}
if (SPA_RESULT_IS_ASYNC(res))
flags |= PW_SPA_NODE_FLAG_ASYNC;
if ((res = spa_handle_get_interface(handle, SPA_TYPE_INTERFACE_Node, &iface)) < 0) {
pw_log_error("can't get node interface %d", res);
goto interface_failed;
}
if (SPA_RESULT_IS_ASYNC(res))
flags |= PW_SPA_NODE_FLAG_ASYNC;
spa_node = iface;
if (properties != NULL) {
@ -325,22 +286,14 @@ struct pw_node *pw_spa_node_load(struct pw_core *core,
spa_node, handle, properties, user_data_size);
impl = this->user_data;
impl->hnd = hnd;
impl->handle = handle;
impl->lib = filename;
impl->lib = strdup(lib);
impl->factory_name = strdup(factory_name);
return this;
interface_failed:
spa_handle_clear(handle);
init_failed:
free(handle);
enum_failed:
pw_unload_spa_handle(handle);
no_mem:
no_symbol:
dlclose(hnd);
open_failed:
free(filename);
return NULL;
}