mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
spa: use core to load spa_handle
This commit is contained in:
parent
165f3e06ad
commit
3780bd1b30
3 changed files with 20 additions and 101 deletions
|
|
@ -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.mask = SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP;
|
||||||
this->data_source.rmask = 0;
|
this->data_source.rmask = 0;
|
||||||
|
|
||||||
return SPA_RESULT_RETURN_ASYNC(0);
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int node_clear(struct node *this)
|
static int node_clear(struct node *this)
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@
|
||||||
#include <pipewire/node.h>
|
#include <pipewire/node.h>
|
||||||
#include <pipewire/device.h>
|
#include <pipewire/device.h>
|
||||||
#include <pipewire/keys.h>
|
#include <pipewire/keys.h>
|
||||||
|
#include <pipewire/pipewire.h>
|
||||||
|
|
||||||
#include "spa-monitor.h"
|
#include "spa-monitor.h"
|
||||||
#include "spa-device.h"
|
#include "spa-device.h"
|
||||||
|
|
@ -63,8 +64,6 @@ struct impl {
|
||||||
struct pw_core *core;
|
struct pw_core *core;
|
||||||
struct pw_global *parent;
|
struct pw_global *parent;
|
||||||
|
|
||||||
void *hnd;
|
|
||||||
|
|
||||||
struct spa_list item_list;
|
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;
|
struct spa_handle *handle;
|
||||||
int res;
|
int res;
|
||||||
void *iface;
|
void *iface;
|
||||||
void *hnd;
|
|
||||||
uint32_t index;
|
|
||||||
spa_handle_factory_enum_func_t enum_func;
|
|
||||||
const struct spa_handle_factory *factory;
|
|
||||||
char *filename;
|
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);
|
asprintf(&filename, "%s/%s.so", dir, lib);
|
||||||
|
|
||||||
if ((hnd = dlopen(filename, RTLD_NOW)) == NULL) {
|
support = pw_core_get_support(core, &n_support);
|
||||||
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;;) {
|
handle = pw_load_spa_handle(lib,
|
||||||
if ((res = enum_func(&factory, &index)) <= 0) {
|
factory_name,
|
||||||
if (res != 0)
|
NULL,
|
||||||
pw_log_error("can't enumerate factories: %s", spa_strerror(res));
|
n_support, support);
|
||||||
goto enum_failed;
|
|
||||||
}
|
|
||||||
if (strcmp(factory->name, factory_name) == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
handle = calloc(1, spa_handle_factory_get_size(factory, NULL));
|
|
||||||
if (handle == NULL)
|
if (handle == NULL)
|
||||||
goto no_mem;
|
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) {
|
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 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 = calloc(1, sizeof(struct impl) + user_data_size);
|
||||||
impl->core = core;
|
impl->core = core;
|
||||||
impl->parent = parent;
|
impl->parent = parent;
|
||||||
impl->hnd = hnd;
|
|
||||||
|
|
||||||
this = &impl->this;
|
this = &impl->this;
|
||||||
this->monitor = iface;
|
this->monitor = iface;
|
||||||
|
|
@ -402,14 +376,8 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
interface_failed:
|
interface_failed:
|
||||||
spa_handle_clear(handle);
|
pw_unload_spa_handle(handle);
|
||||||
init_failed:
|
|
||||||
free(handle);
|
|
||||||
no_mem:
|
no_mem:
|
||||||
enum_failed:
|
|
||||||
no_symbol:
|
|
||||||
dlclose(hnd);
|
|
||||||
open_failed:
|
|
||||||
free(filename);
|
free(filename);
|
||||||
return NULL;
|
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)
|
spa_list_for_each_safe(mitem, tmp, &impl->item_list, link)
|
||||||
destroy_item(mitem);
|
destroy_item(mitem);
|
||||||
|
|
||||||
spa_handle_clear(monitor->handle);
|
pw_unload_spa_handle(monitor->handle);
|
||||||
free(monitor->handle);
|
|
||||||
free(monitor->lib);
|
free(monitor->lib);
|
||||||
free(monitor->factory_name);
|
free(monitor->factory_name);
|
||||||
free(monitor->system_name);
|
free(monitor->system_name);
|
||||||
|
|
||||||
dlclose(impl->hnd);
|
|
||||||
free(impl);
|
free(impl);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@
|
||||||
#include "pipewire/port.h"
|
#include "pipewire/port.h"
|
||||||
#include "pipewire/log.h"
|
#include "pipewire/log.h"
|
||||||
#include "pipewire/private.h"
|
#include "pipewire/private.h"
|
||||||
|
#include "pipewire/pipewire.h"
|
||||||
|
|
||||||
struct impl {
|
struct impl {
|
||||||
struct pw_node *this;
|
struct pw_node *this;
|
||||||
|
|
@ -50,7 +51,6 @@ struct impl {
|
||||||
|
|
||||||
enum pw_spa_node_flags flags;
|
enum pw_spa_node_flags flags;
|
||||||
|
|
||||||
void *hnd;
|
|
||||||
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 *lib;
|
||||||
|
|
@ -73,13 +73,10 @@ static void spa_node_free(void *data)
|
||||||
|
|
||||||
spa_hook_remove(&impl->node_listener);
|
spa_hook_remove(&impl->node_listener);
|
||||||
if (impl->handle) {
|
if (impl->handle) {
|
||||||
spa_handle_clear(impl->handle);
|
pw_unload_spa_handle(impl->handle);
|
||||||
free(impl->handle);
|
|
||||||
}
|
}
|
||||||
free(impl->lib);
|
free(impl->lib);
|
||||||
free(impl->factory_name);
|
free(impl->factory_name);
|
||||||
if (impl->hnd)
|
|
||||||
dlclose(impl->hnd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void complete_init(struct impl *impl)
|
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;
|
struct spa_node *spa_node;
|
||||||
int res;
|
int res;
|
||||||
struct spa_handle *handle;
|
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;
|
void *iface;
|
||||||
char *filename;
|
|
||||||
const char *dir;
|
|
||||||
const struct spa_support *support;
|
const struct spa_support *support;
|
||||||
uint32_t n_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);
|
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)
|
if (handle == NULL)
|
||||||
goto no_mem;
|
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) {
|
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 interface_failed;
|
||||||
}
|
}
|
||||||
|
if (SPA_RESULT_IS_ASYNC(res))
|
||||||
|
flags |= PW_SPA_NODE_FLAG_ASYNC;
|
||||||
|
|
||||||
spa_node = iface;
|
spa_node = iface;
|
||||||
|
|
||||||
if (properties != NULL) {
|
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);
|
spa_node, handle, properties, user_data_size);
|
||||||
|
|
||||||
impl = this->user_data;
|
impl = this->user_data;
|
||||||
impl->hnd = hnd;
|
|
||||||
impl->handle = handle;
|
impl->handle = handle;
|
||||||
impl->lib = filename;
|
impl->lib = strdup(lib);
|
||||||
impl->factory_name = strdup(factory_name);
|
impl->factory_name = strdup(factory_name);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
interface_failed:
|
interface_failed:
|
||||||
spa_handle_clear(handle);
|
pw_unload_spa_handle(handle);
|
||||||
init_failed:
|
|
||||||
free(handle);
|
|
||||||
enum_failed:
|
|
||||||
no_mem:
|
no_mem:
|
||||||
no_symbol:
|
|
||||||
dlclose(hnd);
|
|
||||||
open_failed:
|
|
||||||
free(filename);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue