mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-10 13:30:05 -05:00
move things around
This commit is contained in:
parent
847cef83b6
commit
d1655196c3
130 changed files with 363 additions and 335 deletions
34
src/modules/spa/meson.build
Normal file
34
src/modules/spa/meson.build
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
pipewire_module_spa_c_args = [
|
||||
'-DHAVE_CONFIG_H',
|
||||
'-D_GNU_SOURCE',
|
||||
]
|
||||
|
||||
pipewire_module_spa_monitor = shared_library('pipewire-module-spa-monitor',
|
||||
[ 'module-monitor.c', 'spa-monitor.c', 'spa-node.c' ],
|
||||
c_args : pipewire_module_spa_c_args,
|
||||
include_directories : [configinc, spa_inc],
|
||||
link_with : spalib,
|
||||
install : true,
|
||||
install_dir : '@0@/pipewire-0.1'.format(get_option('libdir')),
|
||||
dependencies : [mathlib, dl_lib, pipewire_dep],
|
||||
)
|
||||
|
||||
pipewire_module_spa_node = shared_library('pipewire-module-spa-node',
|
||||
[ 'module-node.c', 'spa-node.c' ],
|
||||
c_args : pipewire_module_spa_c_args,
|
||||
include_directories : [configinc, spa_inc],
|
||||
link_with : spalib,
|
||||
install : true,
|
||||
install_dir : '@0@/pipewire-0.1'.format(get_option('libdir')),
|
||||
dependencies : [mathlib, dl_lib, pipewire_dep],
|
||||
)
|
||||
|
||||
pipewire_module_spa_node_factory = shared_library('pipewire-module-spa-node-factory',
|
||||
[ 'module-node-factory.c', 'spa-node.c' ],
|
||||
c_args : pipewire_module_spa_c_args,
|
||||
include_directories : [configinc, spa_inc],
|
||||
link_with : spalib,
|
||||
install : true,
|
||||
install_dir : '@0@/pipewire-0.1'.format(get_option('libdir')),
|
||||
dependencies : [mathlib, dl_lib, pipewire_dep],
|
||||
)
|
||||
63
src/modules/spa/module-monitor.c
Normal file
63
src/modules/spa/module-monitor.c
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2016 Axis Communications <dev-gstreamer@axis.com>
|
||||
* @author Linus Svensson <linus.svensson@axis.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <spa/lib/props.h>
|
||||
|
||||
#include <pipewire/utils.h>
|
||||
#include <pipewire/core.h>
|
||||
#include <pipewire/module.h>
|
||||
|
||||
#include "spa-monitor.h"
|
||||
|
||||
bool pipewire__module_init(struct pw_module *module, const char *args)
|
||||
{
|
||||
const char *dir;
|
||||
char **argv;
|
||||
int n_tokens;
|
||||
|
||||
if (args == NULL)
|
||||
goto wrong_arguments;
|
||||
|
||||
argv = pw_split_strv(args, " \t", INT_MAX, &n_tokens);
|
||||
if (n_tokens < 3)
|
||||
goto not_enough_arguments;
|
||||
|
||||
if ((dir = getenv("SPA_PLUGIN_DIR")) == NULL)
|
||||
dir = PLUGINDIR;
|
||||
|
||||
pw_spa_monitor_load(module->core, dir, argv[0], argv[1], argv[2]);
|
||||
|
||||
pw_free_strv(argv);
|
||||
|
||||
return true;
|
||||
|
||||
not_enough_arguments:
|
||||
pw_free_strv(argv);
|
||||
wrong_arguments:
|
||||
pw_log_error("usage: module-spa-monitor <plugin> <factory> <name>");
|
||||
return false;
|
||||
}
|
||||
118
src/modules/spa/module-node-factory.c
Normal file
118
src/modules/spa/module-node-factory.c
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2017 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "pipewire/interfaces.h"
|
||||
#include "pipewire/core.h"
|
||||
#include "pipewire/module.h"
|
||||
|
||||
#include "spa-node.h"
|
||||
|
||||
struct impl {
|
||||
struct pw_node_factory this;
|
||||
struct pw_properties *properties;
|
||||
};
|
||||
|
||||
static struct pw_node *create_node(struct pw_node_factory *factory,
|
||||
struct pw_resource *resource,
|
||||
const char *name,
|
||||
struct pw_properties *properties)
|
||||
{
|
||||
struct pw_node *node;
|
||||
const char *lib, *factory_name;
|
||||
|
||||
if (properties == NULL)
|
||||
goto no_properties;
|
||||
|
||||
lib = pw_properties_get(properties, "spa.library.name");
|
||||
factory_name = pw_properties_get(properties, "spa.factory.name");
|
||||
|
||||
if(lib == NULL || factory_name == NULL)
|
||||
goto no_properties;
|
||||
|
||||
node = pw_spa_node_load(factory->core,
|
||||
NULL,
|
||||
lib,
|
||||
factory_name,
|
||||
name,
|
||||
properties);
|
||||
if (node == NULL)
|
||||
goto no_mem;
|
||||
|
||||
return node;
|
||||
|
||||
no_properties:
|
||||
pw_log_error("missing properties");
|
||||
if (resource) {
|
||||
pw_core_notify_error(resource->client->core_resource,
|
||||
resource->client->core_resource->id,
|
||||
SPA_RESULT_INVALID_ARGUMENTS, "missing properties");
|
||||
}
|
||||
return NULL;
|
||||
no_mem:
|
||||
pw_log_error("can't create node");
|
||||
if (resource) {
|
||||
pw_core_notify_error(resource->client->core_resource,
|
||||
resource->client->core_resource->id,
|
||||
SPA_RESULT_NO_MEMORY, "no memory");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct impl *module_new(struct pw_core *core, struct pw_properties *properties)
|
||||
{
|
||||
struct impl *impl;
|
||||
|
||||
impl = calloc(1, sizeof(struct impl));
|
||||
pw_log_debug("module %p: new", impl);
|
||||
|
||||
impl->properties = properties;
|
||||
|
||||
impl->this.core = core;
|
||||
impl->this.name = "spa-node-factory";
|
||||
pw_signal_init(&impl->this.destroy_signal);
|
||||
impl->this.create_node = create_node;
|
||||
|
||||
spa_list_insert(core->node_factory_list.prev, &impl->this.link);
|
||||
|
||||
pw_core_add_global(core, NULL, core->type.node_factory, 0, impl, NULL, &impl->this.global);
|
||||
|
||||
return impl;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void module_destroy(struct impl *impl)
|
||||
{
|
||||
pw_log_debug("module %p: destroy", impl);
|
||||
|
||||
free(impl);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool pipewire__module_init(struct pw_module *module, const char *args)
|
||||
{
|
||||
module_new(module->core, NULL);
|
||||
return true;
|
||||
}
|
||||
74
src/modules/spa/module-node.c
Normal file
74
src/modules/spa/module-node.c
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2016 Axis Communications <dev-gstreamer@axis.com>
|
||||
* @author Linus Svensson <linus.svensson@axis.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <spa/lib/props.h>
|
||||
|
||||
#include <pipewire/utils.h>
|
||||
#include <pipewire/core.h>
|
||||
#include <pipewire/module.h>
|
||||
|
||||
#include "spa-monitor.h"
|
||||
#include "spa-node.h"
|
||||
|
||||
bool pipewire__module_init(struct pw_module *module, const char *args)
|
||||
{
|
||||
struct pw_properties *props = NULL;
|
||||
char **argv;
|
||||
int i, n_tokens;
|
||||
|
||||
if (args == NULL)
|
||||
goto wrong_arguments;
|
||||
|
||||
argv = pw_split_strv(args, " \t", INT_MAX, &n_tokens);
|
||||
if (n_tokens < 3)
|
||||
goto not_enough_arguments;
|
||||
|
||||
props = pw_properties_new(NULL, NULL);
|
||||
|
||||
for (i = 3; i < n_tokens; i++) {
|
||||
char **prop;
|
||||
int n_props;
|
||||
|
||||
prop = pw_split_strv(argv[i], "=", INT_MAX, &n_props);
|
||||
if (n_props >= 2)
|
||||
pw_properties_set(props, prop[0], prop[1]);
|
||||
|
||||
pw_free_strv(prop);
|
||||
}
|
||||
|
||||
pw_spa_node_load(module->core, NULL, argv[0], argv[1], argv[2], props);
|
||||
|
||||
pw_free_strv(argv);
|
||||
|
||||
return true;
|
||||
|
||||
not_enough_arguments:
|
||||
pw_free_strv(argv);
|
||||
wrong_arguments:
|
||||
pw_log_error("usage: module-spa-node <plugin> <factory> <name> [key=value ...]");
|
||||
return false;
|
||||
}
|
||||
315
src/modules/spa/spa-monitor.c
Normal file
315
src/modules/spa/spa-monitor.c
Normal file
|
|
@ -0,0 +1,315 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include <spa/node.h>
|
||||
#include <spa/monitor.h>
|
||||
#include <spa/pod-iter.h>
|
||||
|
||||
#include <pipewire/log.h>
|
||||
#include <pipewire/node.h>
|
||||
|
||||
#include "spa-monitor.h"
|
||||
#include "spa-node.h"
|
||||
|
||||
struct monitor_item {
|
||||
char *id;
|
||||
struct spa_list link;
|
||||
struct pw_node *node;
|
||||
};
|
||||
|
||||
struct impl {
|
||||
struct pw_spa_monitor this;
|
||||
|
||||
struct pw_core *core;
|
||||
|
||||
void *hnd;
|
||||
|
||||
struct spa_list item_list;
|
||||
};
|
||||
|
||||
static void add_item(struct pw_spa_monitor *this, struct spa_monitor_item *item)
|
||||
{
|
||||
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
|
||||
int res;
|
||||
struct spa_handle *handle;
|
||||
struct monitor_item *mitem;
|
||||
void *node_iface;
|
||||
void *clock_iface;
|
||||
struct pw_properties *props = NULL;
|
||||
const char *name, *id, *klass;
|
||||
struct spa_handle_factory *factory;
|
||||
struct spa_pod *info = NULL;
|
||||
|
||||
spa_pod_object_query(&item->object,
|
||||
impl->core->type.monitor.name, SPA_POD_TYPE_STRING, &name,
|
||||
impl->core->type.monitor.id, SPA_POD_TYPE_STRING, &id,
|
||||
impl->core->type.monitor.klass, SPA_POD_TYPE_STRING, &klass,
|
||||
impl->core->type.monitor.factory, SPA_POD_TYPE_POINTER, &factory,
|
||||
impl->core->type.monitor.info, SPA_POD_TYPE_STRUCT, &info, 0);
|
||||
|
||||
pw_log_debug("monitor %p: add: \"%s\" (%s)", this, name, id);
|
||||
|
||||
props = pw_properties_new(NULL, NULL);
|
||||
|
||||
if (info) {
|
||||
struct spa_pod_iter it;
|
||||
|
||||
spa_pod_iter_pod(&it, info);
|
||||
while (true) {
|
||||
const char *key, *val;
|
||||
if (!spa_pod_iter_get
|
||||
(&it, SPA_POD_TYPE_STRING, &key, SPA_POD_TYPE_STRING, &val, 0))
|
||||
break;
|
||||
pw_properties_set(props, key, val);
|
||||
}
|
||||
}
|
||||
pw_properties_set(props, "media.class", klass);
|
||||
|
||||
handle = calloc(1, factory->size);
|
||||
if ((res = spa_handle_factory_init(factory,
|
||||
handle,
|
||||
&props->dict,
|
||||
impl->core->support, impl->core->n_support)) < 0) {
|
||||
pw_log_error("can't make factory instance: %d", res);
|
||||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface(handle, impl->core->type.spa_node, &node_iface)) < 0) {
|
||||
pw_log_error("can't get NODE interface: %d", res);
|
||||
return;
|
||||
}
|
||||
if ((res = spa_handle_get_interface(handle, impl->core->type.spa_clock, &clock_iface)) < 0) {
|
||||
pw_log_info("no CLOCK interface: %d", res);
|
||||
}
|
||||
|
||||
|
||||
mitem = calloc(1, sizeof(struct monitor_item));
|
||||
mitem->id = strdup(id);
|
||||
mitem->node = pw_spa_node_new(impl->core, NULL, name, false, node_iface, clock_iface, props);
|
||||
|
||||
spa_list_insert(impl->item_list.prev, &mitem->link);
|
||||
}
|
||||
|
||||
static struct monitor_item *find_item(struct pw_spa_monitor *this, const char *id)
|
||||
{
|
||||
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
|
||||
struct monitor_item *mitem;
|
||||
|
||||
spa_list_for_each(mitem, &impl->item_list, link) {
|
||||
if (strcmp(mitem->id, id) == 0) {
|
||||
return mitem;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void destroy_item(struct monitor_item *mitem)
|
||||
{
|
||||
pw_node_destroy(mitem->node);
|
||||
spa_list_remove(&mitem->link);
|
||||
free(mitem->id);
|
||||
free(mitem);
|
||||
}
|
||||
|
||||
static void remove_item(struct pw_spa_monitor *this, struct spa_monitor_item *item)
|
||||
{
|
||||
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
|
||||
struct monitor_item *mitem;
|
||||
const char *name, *id;
|
||||
|
||||
spa_pod_object_query(&item->object,
|
||||
impl->core->type.monitor.name, SPA_POD_TYPE_STRING, &name,
|
||||
impl->core->type.monitor.id, SPA_POD_TYPE_STRING, &id, 0);
|
||||
|
||||
pw_log_debug("monitor %p: remove: \"%s\" (%s)", this, name, id);
|
||||
mitem = find_item(this, id);
|
||||
if (mitem)
|
||||
destroy_item(mitem);
|
||||
}
|
||||
|
||||
static void on_monitor_event(struct spa_monitor *monitor, struct spa_event *event, void *user_data)
|
||||
{
|
||||
struct impl *impl = user_data;
|
||||
struct pw_spa_monitor *this = &impl->this;
|
||||
|
||||
if (SPA_EVENT_TYPE(event) == impl->core->type.monitor.Added) {
|
||||
struct spa_monitor_item *item = SPA_POD_CONTENTS(struct spa_event, event);
|
||||
add_item(this, item);
|
||||
} else if (SPA_EVENT_TYPE(event) == impl->core->type.monitor.Removed) {
|
||||
struct spa_monitor_item *item = SPA_POD_CONTENTS(struct spa_event, event);
|
||||
remove_item(this, item);
|
||||
} else if (SPA_EVENT_TYPE(event) == impl->core->type.monitor.Changed) {
|
||||
struct spa_monitor_item *item = SPA_POD_CONTENTS(struct spa_event, event);
|
||||
const char *name;
|
||||
|
||||
spa_pod_object_query(&item->object,
|
||||
impl->core->type.monitor.name, SPA_POD_TYPE_STRING, &name, 0);
|
||||
|
||||
pw_log_debug("monitor %p: changed: \"%s\"", this, name);
|
||||
}
|
||||
}
|
||||
|
||||
static void update_monitor(struct pw_core *core, const char *name)
|
||||
{
|
||||
const char *monitors;
|
||||
struct spa_dict_item item;
|
||||
struct spa_dict dict = SPA_DICT_INIT(1, &item);
|
||||
|
||||
if (core->properties)
|
||||
monitors = pw_properties_get(core->properties, "monitors");
|
||||
else
|
||||
monitors = NULL;
|
||||
|
||||
item.key = "monitors";
|
||||
if (monitors == NULL)
|
||||
item.value = name;
|
||||
else
|
||||
asprintf((char **) &item.value, "%s,%s", monitors, name);
|
||||
|
||||
pw_core_update_properties(core, &dict);
|
||||
|
||||
if (monitors != NULL)
|
||||
free((void *) item.value);
|
||||
}
|
||||
|
||||
static const struct spa_monitor_callbacks callbacks = {
|
||||
SPA_VERSION_MONITOR_CALLBACKS,
|
||||
on_monitor_event,
|
||||
};
|
||||
|
||||
struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
|
||||
const char *dir,
|
||||
const char *lib,
|
||||
const char *factory_name, const char *system_name)
|
||||
{
|
||||
struct impl *impl;
|
||||
struct pw_spa_monitor *this;
|
||||
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;
|
||||
|
||||
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;; index++) {
|
||||
if ((res = enum_func(&factory, index)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
pw_log_error("can't enumerate factories: %d", res);
|
||||
goto enum_failed;
|
||||
}
|
||||
if (strcmp(factory->name, factory_name) == 0)
|
||||
break;
|
||||
}
|
||||
handle = calloc(1, factory->size);
|
||||
if ((res = spa_handle_factory_init(factory,
|
||||
handle, NULL, core->support, core->n_support)) < 0) {
|
||||
pw_log_error("can't make factory instance: %d", res);
|
||||
goto init_failed;
|
||||
}
|
||||
if ((res = spa_handle_get_interface(handle, core->type.spa_monitor, &iface)) < 0) {
|
||||
free(handle);
|
||||
pw_log_error("can't get MONITOR interface: %d", res);
|
||||
goto interface_failed;
|
||||
}
|
||||
|
||||
impl = calloc(1, sizeof(struct impl));
|
||||
impl->core = core;
|
||||
impl->hnd = hnd;
|
||||
|
||||
this = &impl->this;
|
||||
pw_signal_init(&this->destroy_signal);
|
||||
this->monitor = iface;
|
||||
this->lib = filename;
|
||||
this->factory_name = strdup(factory_name);
|
||||
this->system_name = strdup(system_name);
|
||||
this->handle = handle;
|
||||
|
||||
update_monitor(core, this->system_name);
|
||||
|
||||
spa_list_init(&impl->item_list);
|
||||
|
||||
for (index = 0;; index++) {
|
||||
struct spa_monitor_item *item;
|
||||
int res;
|
||||
|
||||
if ((res = spa_monitor_enum_items(this->monitor, &item, index)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
pw_log_debug("spa_monitor_enum_items: got error %d\n", res);
|
||||
break;
|
||||
}
|
||||
add_item(this, item);
|
||||
}
|
||||
spa_monitor_set_callbacks(this->monitor, &callbacks, impl);
|
||||
|
||||
return this;
|
||||
|
||||
interface_failed:
|
||||
spa_handle_clear(handle);
|
||||
init_failed:
|
||||
free(handle);
|
||||
enum_failed:
|
||||
no_symbol:
|
||||
dlclose(hnd);
|
||||
open_failed:
|
||||
free(filename);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void pw_spa_monitor_destroy(struct pw_spa_monitor *monitor)
|
||||
{
|
||||
struct impl *impl = SPA_CONTAINER_OF(monitor, struct impl, this);
|
||||
struct monitor_item *mitem, *tmp;
|
||||
|
||||
pw_log_debug("spa-monitor %p: dispose", impl);
|
||||
pw_signal_emit(&monitor->destroy_signal, monitor);
|
||||
|
||||
spa_list_for_each_safe(mitem, tmp, &impl->item_list, link)
|
||||
destroy_item(mitem);
|
||||
|
||||
spa_handle_clear(monitor->handle);
|
||||
free(monitor->handle);
|
||||
free(monitor->lib);
|
||||
free(monitor->factory_name);
|
||||
free(monitor->system_name);
|
||||
|
||||
dlclose(impl->hnd);
|
||||
free(impl);
|
||||
}
|
||||
54
src/modules/spa/spa-monitor.h
Normal file
54
src/modules/spa/spa-monitor.h
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PIPEWIRE_SPA_MONITOR_H__
|
||||
#define __PIPEWIRE_SPA_MONITOR_H__
|
||||
|
||||
#include <spa/monitor.h>
|
||||
|
||||
#include <pipewire/core.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct pw_spa_monitor {
|
||||
struct spa_monitor *monitor;
|
||||
|
||||
char *lib;
|
||||
char *factory_name;
|
||||
char *system_name;
|
||||
struct spa_handle *handle;
|
||||
|
||||
PW_SIGNAL(destroy_signal, (struct pw_listener *listener, struct pw_spa_monitor *monitor));
|
||||
};
|
||||
|
||||
struct pw_spa_monitor *
|
||||
pw_spa_monitor_load(struct pw_core *core,
|
||||
const char *dir,
|
||||
const char *lib,
|
||||
const char *factory_name, const char *system_name);
|
||||
void
|
||||
pw_spa_monitor_destroy(struct pw_spa_monitor *monitor);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PIPEWIRE_SPA_MONITOR_H__ */
|
||||
588
src/modules/spa/spa-node.c
Normal file
588
src/modules/spa/spa-node.c
Normal file
|
|
@ -0,0 +1,588 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <spa/graph-scheduler3.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include <spa/node.h>
|
||||
|
||||
#include "spa-node.h"
|
||||
|
||||
struct impl {
|
||||
struct pw_node *this;
|
||||
|
||||
bool async_init;
|
||||
|
||||
void *hnd;
|
||||
struct spa_handle *handle;
|
||||
struct spa_node *node; /**< handle to SPA node */
|
||||
char *lib;
|
||||
char *factory_name;
|
||||
};
|
||||
|
||||
struct port {
|
||||
struct pw_port *port;
|
||||
|
||||
struct spa_node *node;
|
||||
};
|
||||
|
||||
|
||||
static int port_impl_enum_formats(struct pw_port *port,
|
||||
struct spa_format **format,
|
||||
const struct spa_format *filter,
|
||||
int32_t index)
|
||||
{
|
||||
struct port *p = port->user_data;
|
||||
return spa_node_port_enum_formats(p->node, port->direction, port->port_id, format, filter, index);
|
||||
}
|
||||
|
||||
static int port_impl_set_format(struct pw_port *port, uint32_t flags, struct spa_format *format)
|
||||
{
|
||||
struct port *p = port->user_data;
|
||||
return spa_node_port_set_format(p->node, port->direction, port->port_id, flags, format);
|
||||
}
|
||||
|
||||
static int port_impl_get_format(struct pw_port *port, const struct spa_format **format)
|
||||
{
|
||||
struct port *p = port->user_data;
|
||||
return spa_node_port_get_format(p->node, port->direction, port->port_id, format);
|
||||
}
|
||||
|
||||
static int port_impl_get_info(struct pw_port *port, const struct spa_port_info **info)
|
||||
{
|
||||
struct port *p = port->user_data;
|
||||
return spa_node_port_get_info(p->node, port->direction, port->port_id, info);
|
||||
}
|
||||
|
||||
static int port_impl_enum_params(struct pw_port *port, uint32_t index, struct spa_param **param)
|
||||
{
|
||||
struct port *p = port->user_data;
|
||||
return spa_node_port_enum_params(p->node, port->direction, port->port_id, index, param);
|
||||
}
|
||||
|
||||
static int port_impl_set_param(struct pw_port *port, struct spa_param *param)
|
||||
{
|
||||
struct port *p = port->user_data;
|
||||
return spa_node_port_set_param(p->node, port->direction, port->port_id, param);
|
||||
}
|
||||
|
||||
static int port_impl_use_buffers(struct pw_port *port, struct spa_buffer **buffers, uint32_t n_buffers)
|
||||
{
|
||||
struct port *p = port->user_data;
|
||||
return spa_node_port_use_buffers(p->node, port->direction, port->port_id, buffers, n_buffers);
|
||||
}
|
||||
|
||||
static int port_impl_alloc_buffers(struct pw_port *port,
|
||||
struct spa_param **params, uint32_t n_params,
|
||||
struct spa_buffer **buffers, uint32_t *n_buffers)
|
||||
{
|
||||
struct port *p = port->user_data;
|
||||
return spa_node_port_alloc_buffers(p->node, port->direction, port->port_id,
|
||||
params, n_params, buffers, n_buffers);
|
||||
}
|
||||
|
||||
static int port_impl_reuse_buffer(struct pw_port *port, uint32_t buffer_id)
|
||||
{
|
||||
struct port *p = port->user_data;
|
||||
return spa_node_port_reuse_buffer(p->node, port->port_id, buffer_id);
|
||||
}
|
||||
|
||||
static int port_impl_send_command(struct pw_port *port, struct spa_command *command)
|
||||
{
|
||||
struct port *p = port->user_data;
|
||||
return spa_node_port_send_command(p->node,
|
||||
port->direction,
|
||||
port->port_id,
|
||||
command);
|
||||
}
|
||||
|
||||
const struct pw_port_implementation port_impl = {
|
||||
PW_VERSION_PORT_IMPLEMENTATION,
|
||||
port_impl_enum_formats,
|
||||
port_impl_set_format,
|
||||
port_impl_get_format,
|
||||
port_impl_get_info,
|
||||
port_impl_enum_params,
|
||||
port_impl_set_param,
|
||||
port_impl_use_buffers,
|
||||
port_impl_alloc_buffers,
|
||||
port_impl_reuse_buffer,
|
||||
port_impl_send_command,
|
||||
};
|
||||
|
||||
static struct pw_port *
|
||||
make_port(struct pw_node *node, enum pw_direction direction, uint32_t port_id)
|
||||
{
|
||||
struct impl *impl = node->user_data;
|
||||
struct pw_port *port;
|
||||
struct port *p;
|
||||
|
||||
port = pw_port_new(direction, port_id, sizeof(struct port));
|
||||
if (port == NULL)
|
||||
return NULL;
|
||||
|
||||
p = port->user_data;
|
||||
p->node = impl->node;
|
||||
|
||||
port->implementation = &port_impl;
|
||||
|
||||
spa_node_port_set_io(impl->node, direction, port_id, &port->io);
|
||||
|
||||
pw_port_add(port, node);
|
||||
|
||||
return port;
|
||||
}
|
||||
|
||||
static void update_port_ids(struct impl *impl)
|
||||
{
|
||||
struct pw_node *this = impl->this;
|
||||
uint32_t *input_port_ids, *output_port_ids;
|
||||
uint32_t n_input_ports, n_output_ports, max_input_ports, max_output_ports;
|
||||
uint32_t i;
|
||||
struct spa_list *ports;
|
||||
|
||||
spa_node_get_n_ports(impl->node,
|
||||
&n_input_ports, &max_input_ports, &n_output_ports, &max_output_ports);
|
||||
|
||||
this->info.max_input_ports = max_input_ports;
|
||||
this->info.max_output_ports = max_output_ports;
|
||||
|
||||
input_port_ids = alloca(sizeof(uint32_t) * n_input_ports);
|
||||
output_port_ids = alloca(sizeof(uint32_t) * n_output_ports);
|
||||
|
||||
spa_node_get_port_ids(impl->node,
|
||||
max_input_ports, input_port_ids, max_output_ports, output_port_ids);
|
||||
|
||||
pw_log_debug("node %p: update_port ids %u/%u, %u/%u", this,
|
||||
n_input_ports, max_input_ports, n_output_ports, max_output_ports);
|
||||
|
||||
i = 0;
|
||||
ports = &this->input_ports;
|
||||
while (true) {
|
||||
struct pw_port *p = (ports == &this->input_ports) ? NULL :
|
||||
SPA_CONTAINER_OF(ports, struct pw_port, link);
|
||||
|
||||
if (p && i < n_input_ports && p->port_id == input_port_ids[i]) {
|
||||
pw_log_debug("node %p: exiting input port %d", this, input_port_ids[i]);
|
||||
i++;
|
||||
ports = ports->next;
|
||||
} else if ((p && i < n_input_ports && input_port_ids[i] < p->port_id)
|
||||
|| i < n_input_ports) {
|
||||
struct pw_port *np;
|
||||
pw_log_debug("node %p: input port added %d", this, input_port_ids[i]);
|
||||
np = make_port(this, PW_DIRECTION_INPUT, input_port_ids[i]);
|
||||
|
||||
ports = np->link.next;
|
||||
i++;
|
||||
} else if (p) {
|
||||
ports = ports->next;
|
||||
pw_log_debug("node %p: input port removed %d", this, p->port_id);
|
||||
pw_port_destroy(p);
|
||||
} else {
|
||||
pw_log_debug("node %p: no more input ports", this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
i = 0;
|
||||
ports = &this->output_ports;
|
||||
while (true) {
|
||||
struct pw_port *p = (ports == &this->output_ports) ? NULL :
|
||||
SPA_CONTAINER_OF(ports, struct pw_port, link);
|
||||
|
||||
if (p && i < n_output_ports && p->port_id == output_port_ids[i]) {
|
||||
pw_log_debug("node %p: exiting output port %d", this, output_port_ids[i]);
|
||||
i++;
|
||||
ports = ports->next;
|
||||
} else if ((p && i < n_output_ports && output_port_ids[i] < p->port_id)
|
||||
|| i < n_output_ports) {
|
||||
struct pw_port *np;
|
||||
pw_log_debug("node %p: output port added %d", this, output_port_ids[i]);
|
||||
np = make_port(this, PW_DIRECTION_OUTPUT, output_port_ids[i]);
|
||||
ports = np->link.next;
|
||||
i++;
|
||||
} else if (p) {
|
||||
ports = ports->next;
|
||||
pw_log_debug("node %p: output port removed %d", this, p->port_id);
|
||||
pw_port_destroy(p);
|
||||
} else {
|
||||
pw_log_debug("node %p: no more output ports", this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int node_impl_get_props(struct pw_node *node, struct spa_props **props)
|
||||
{
|
||||
struct impl *impl = node->user_data;
|
||||
return spa_node_get_props(impl->node, props);
|
||||
}
|
||||
|
||||
static int node_impl_set_props(struct pw_node *node, const struct spa_props *props)
|
||||
{
|
||||
struct impl *impl = node->user_data;
|
||||
return spa_node_set_props(impl->node, props);
|
||||
}
|
||||
|
||||
static int node_impl_send_command(struct pw_node *node, struct spa_command *command)
|
||||
{
|
||||
struct impl *impl = node->user_data;
|
||||
return spa_node_send_command(impl->node, command);
|
||||
}
|
||||
|
||||
static struct pw_port*
|
||||
node_impl_add_port(struct pw_node *node,
|
||||
enum pw_direction direction,
|
||||
uint32_t port_id)
|
||||
{
|
||||
struct impl *impl = node->user_data;
|
||||
int res;
|
||||
|
||||
if ((res = spa_node_add_port(impl->node, direction, port_id)) < 0) {
|
||||
pw_log_error("node %p: could not add port %d %d", node, port_id, res);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return make_port(node, direction, port_id);
|
||||
}
|
||||
|
||||
static int node_impl_schedule_input(struct pw_node *node)
|
||||
{
|
||||
struct impl *impl = node->user_data;
|
||||
return spa_node_process_input(impl->node);
|
||||
}
|
||||
|
||||
static int node_impl_schedule_output(struct pw_node *node)
|
||||
{
|
||||
struct impl *impl = node->user_data;
|
||||
return spa_node_process_output(impl->node);
|
||||
}
|
||||
|
||||
static const struct pw_node_implementation node_impl = {
|
||||
PW_VERSION_NODE_IMPLEMENTATION,
|
||||
node_impl_get_props,
|
||||
node_impl_set_props,
|
||||
node_impl_send_command,
|
||||
node_impl_add_port,
|
||||
node_impl_schedule_input,
|
||||
node_impl_schedule_output,
|
||||
};
|
||||
|
||||
static void pw_spa_node_destroy(void *object)
|
||||
{
|
||||
struct pw_node *node = object;
|
||||
struct impl *impl = node->user_data;
|
||||
|
||||
pw_log_debug("spa-node %p: destroy", node);
|
||||
|
||||
if (impl->handle) {
|
||||
spa_handle_clear(impl->handle);
|
||||
free(impl->handle);
|
||||
}
|
||||
free(impl->lib);
|
||||
free(impl->factory_name);
|
||||
if (impl->hnd)
|
||||
dlclose(impl->hnd);
|
||||
}
|
||||
|
||||
static void complete_init(struct impl *impl)
|
||||
{
|
||||
struct pw_node *this = impl->this;
|
||||
update_port_ids(impl);
|
||||
pw_node_export(this);
|
||||
}
|
||||
|
||||
static void on_node_done(struct spa_node *node, int seq, int res, void *user_data)
|
||||
{
|
||||
struct impl *impl = user_data;
|
||||
struct pw_node *this = impl->this;
|
||||
|
||||
if (impl->async_init) {
|
||||
complete_init(impl);
|
||||
impl->async_init = false;
|
||||
}
|
||||
|
||||
pw_log_debug("spa-node %p: async complete event %d %d", this, seq, res);
|
||||
pw_signal_emit(&this->async_complete, this, seq, res);
|
||||
}
|
||||
|
||||
static void on_node_event(struct spa_node *node, struct spa_event *event, void *user_data)
|
||||
{
|
||||
struct impl *impl = user_data;
|
||||
struct pw_node *this = impl->this;
|
||||
|
||||
pw_signal_emit(&this->event, this, event);
|
||||
}
|
||||
|
||||
static void on_node_need_input(struct spa_node *node, void *user_data)
|
||||
{
|
||||
struct impl *impl = user_data;
|
||||
struct pw_node *this = impl->this;
|
||||
|
||||
spa_graph_scheduler_pull(this->rt.sched, &this->rt.node);
|
||||
while (spa_graph_scheduler_iterate(this->rt.sched));
|
||||
}
|
||||
|
||||
static void on_node_have_output(struct spa_node *node, void *user_data)
|
||||
{
|
||||
struct impl *impl = user_data;
|
||||
struct pw_node *this = impl->this;
|
||||
|
||||
spa_graph_scheduler_push(this->rt.sched, &this->rt.node);
|
||||
while (spa_graph_scheduler_iterate(this->rt.sched));
|
||||
}
|
||||
|
||||
static void
|
||||
on_node_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id, void *user_data)
|
||||
{
|
||||
struct impl *impl = user_data;
|
||||
struct pw_node *this = impl->this;
|
||||
struct spa_graph_port *p, *pp;
|
||||
|
||||
spa_list_for_each(p, &this->rt.node.ports[SPA_DIRECTION_INPUT], link) {
|
||||
if (p->port_id != port_id)
|
||||
continue;
|
||||
|
||||
pp = p->peer;
|
||||
if (pp && pp->methods->reuse_buffer)
|
||||
pp->methods->reuse_buffer(pp, buffer_id, pp->user_data);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static const struct spa_node_callbacks node_callbacks = {
|
||||
SPA_VERSION_NODE_CALLBACKS,
|
||||
&on_node_done,
|
||||
&on_node_event,
|
||||
&on_node_need_input,
|
||||
&on_node_have_output,
|
||||
&on_node_reuse_buffer,
|
||||
};
|
||||
|
||||
struct pw_node *
|
||||
pw_spa_node_new(struct pw_core *core,
|
||||
struct pw_resource *owner,
|
||||
const char *name,
|
||||
bool async,
|
||||
struct spa_node *node,
|
||||
struct spa_clock *clock,
|
||||
struct pw_properties *properties)
|
||||
{
|
||||
struct pw_node *this;
|
||||
struct impl *impl;
|
||||
|
||||
if (node->info) {
|
||||
uint32_t i;
|
||||
|
||||
if (properties == NULL)
|
||||
properties = pw_properties_new(NULL, NULL);
|
||||
|
||||
if (properties)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < node->info->n_items; i++)
|
||||
pw_properties_set(properties,
|
||||
node->info->items[i].key,
|
||||
node->info->items[i].value);
|
||||
}
|
||||
|
||||
this = pw_node_new(core, owner, name, properties, sizeof(struct impl));
|
||||
if (this == NULL)
|
||||
return NULL;
|
||||
|
||||
this->destroy = pw_spa_node_destroy;
|
||||
this->implementation = &node_impl;
|
||||
this->clock = clock;
|
||||
|
||||
impl = this->user_data;
|
||||
impl->this = this;
|
||||
impl->node = node;
|
||||
impl->async_init = async;
|
||||
|
||||
if (spa_node_set_callbacks(impl->node, &node_callbacks, impl) < 0)
|
||||
pw_log_warn("spa-node %p: error setting callback", this);
|
||||
|
||||
if (!async) {
|
||||
complete_init(impl);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
static int
|
||||
setup_props(struct pw_core *core, struct spa_node *spa_node, struct pw_properties *pw_props)
|
||||
{
|
||||
int res;
|
||||
struct spa_props *props;
|
||||
void *state = NULL;
|
||||
const char *key;
|
||||
|
||||
if ((res = spa_node_get_props(spa_node, &props)) != SPA_RESULT_OK) {
|
||||
pw_log_debug("spa_node_get_props failed: %d", res);
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
|
||||
while ((key = pw_properties_iterate(pw_props, &state))) {
|
||||
struct spa_pod_prop *prop;
|
||||
uint32_t id;
|
||||
|
||||
if (!spa_type_is_a(key, SPA_TYPE_PROPS_BASE))
|
||||
continue;
|
||||
|
||||
id = spa_type_map_get_id(core->type.map, key);
|
||||
if (id == SPA_ID_INVALID)
|
||||
continue;
|
||||
|
||||
if ((prop = spa_pod_object_find_prop(&props->object, id))) {
|
||||
const char *value = pw_properties_get(pw_props, key);
|
||||
|
||||
pw_log_info("configure prop %s", key);
|
||||
|
||||
switch(prop->body.value.type) {
|
||||
case SPA_POD_TYPE_ID:
|
||||
SPA_POD_VALUE(struct spa_pod_id, &prop->body.value) =
|
||||
spa_type_map_get_id(core->type.map, value);
|
||||
break;
|
||||
case SPA_POD_TYPE_INT:
|
||||
SPA_POD_VALUE(struct spa_pod_int, &prop->body.value) = atoi(value);
|
||||
break;
|
||||
case SPA_POD_TYPE_LONG:
|
||||
SPA_POD_VALUE(struct spa_pod_long, &prop->body.value) = atoi(value);
|
||||
break;
|
||||
case SPA_POD_TYPE_FLOAT:
|
||||
SPA_POD_VALUE(struct spa_pod_float, &prop->body.value) = atof(value);
|
||||
break;
|
||||
case SPA_POD_TYPE_DOUBLE:
|
||||
SPA_POD_VALUE(struct spa_pod_double, &prop->body.value) = atof(value);
|
||||
break;
|
||||
case SPA_POD_TYPE_STRING:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((res = spa_node_set_props(spa_node, props)) != SPA_RESULT_OK) {
|
||||
pw_log_debug("spa_node_set_props failed: %d", res);
|
||||
return SPA_RESULT_ERROR;
|
||||
}
|
||||
return SPA_RESULT_OK;
|
||||
}
|
||||
|
||||
|
||||
struct pw_node *pw_spa_node_load(struct pw_core *core,
|
||||
struct pw_resource *owner,
|
||||
const char *lib,
|
||||
const char *factory_name,
|
||||
const char *name,
|
||||
struct pw_properties *properties)
|
||||
{
|
||||
struct pw_node *this;
|
||||
struct impl *impl;
|
||||
struct spa_node *spa_node;
|
||||
struct spa_clock *spa_clock;
|
||||
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;
|
||||
bool async;
|
||||
|
||||
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;; index++) {
|
||||
if ((res = enum_func(&factory, index)) < 0) {
|
||||
if (res != SPA_RESULT_ENUM_END)
|
||||
pw_log_error("can't enumerate factories: %d", res);
|
||||
goto enum_failed;
|
||||
}
|
||||
if (strcmp(factory->name, factory_name) == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
handle = calloc(1, factory->size);
|
||||
if ((res = spa_handle_factory_init(factory,
|
||||
handle, NULL, core->support, core->n_support)) < 0) {
|
||||
pw_log_error("can't make factory instance: %d", res);
|
||||
goto init_failed;
|
||||
}
|
||||
async = SPA_RESULT_IS_ASYNC(res);
|
||||
|
||||
if ((res = spa_handle_get_interface(handle, core->type.spa_node, &iface)) < 0) {
|
||||
pw_log_error("can't get node interface %d", res);
|
||||
goto interface_failed;
|
||||
}
|
||||
spa_node = iface;
|
||||
|
||||
if ((res = spa_handle_get_interface(handle, core->type.spa_clock, &iface)) < 0) {
|
||||
iface = NULL;
|
||||
}
|
||||
spa_clock = iface;
|
||||
|
||||
if (properties != NULL) {
|
||||
if (setup_props(core, spa_node, properties) != SPA_RESULT_OK) {
|
||||
pw_log_debug("Unrecognized properties");
|
||||
}
|
||||
}
|
||||
|
||||
this = pw_spa_node_new(core, owner, name, async, spa_node, spa_clock, properties);
|
||||
impl->hnd = hnd;
|
||||
impl->handle = handle;
|
||||
impl->lib = filename;
|
||||
impl->factory_name = strdup(factory_name);
|
||||
|
||||
return this;
|
||||
|
||||
interface_failed:
|
||||
spa_handle_clear(handle);
|
||||
init_failed:
|
||||
free(handle);
|
||||
enum_failed:
|
||||
no_symbol:
|
||||
dlclose(hnd);
|
||||
open_failed:
|
||||
free(filename);
|
||||
return NULL;
|
||||
}
|
||||
51
src/modules/spa/spa-node.h
Normal file
51
src/modules/spa/spa-node.h
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/* PipeWire
|
||||
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef __PIPEWIRE_SPA_NODE_H__
|
||||
#define __PIPEWIRE_SPA_NODE_H__
|
||||
|
||||
#include <pipewire/core.h>
|
||||
#include <pipewire/node.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct pw_node *
|
||||
pw_spa_node_new(struct pw_core *core,
|
||||
struct pw_resource *owner, /**< optional owner */
|
||||
const char *name,
|
||||
bool async,
|
||||
struct spa_node *node,
|
||||
struct spa_clock *clock,
|
||||
struct pw_properties *properties);
|
||||
|
||||
struct pw_node *
|
||||
pw_spa_node_load(struct pw_core *core,
|
||||
struct pw_resource *owner, /**< optional owner */
|
||||
const char *lib,
|
||||
const char *factory_name,
|
||||
const char *name,
|
||||
struct pw_properties *properties);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __PIPEWIRE_SPA_NODE_H__ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue