Make structure private

Make structs private. Expose methods for things we need.
Signals only work on exposed structures so make a new callback helper to
signal events.
This commit is contained in:
Wim Taymans 2017-08-04 10:18:54 +02:00
parent e24c934a1b
commit b898eb46cd
72 changed files with 2980 additions and 2120 deletions

View file

@ -24,6 +24,7 @@
#include "config.h"
#include "pipewire/interfaces.h"
#include "pipewire/private.h"
#include "pipewire/core.h"
#include "pipewire/module.h"
@ -32,29 +33,27 @@ struct impl {
struct pw_module *module;
struct pw_properties *properties;
struct pw_listener global_added;
struct pw_listener global_removed;
struct pw_callback_info core_callbacks;
struct spa_list node_list;
};
struct node_info {
struct spa_list l;
struct impl *impl;
struct pw_node *node;
struct spa_list link;
struct pw_listener state_changed;
struct pw_listener port_added;
struct pw_listener port_removed;
struct pw_listener port_unlinked;
struct pw_listener link_state_changed;
struct pw_listener link_destroy;
struct pw_callback_info node_callbacks;
struct pw_link *link;
struct pw_callback_info link_callbacks;
};
static struct node_info *find_node_info(struct impl *impl, struct pw_node *node)
{
struct node_info *info;
spa_list_for_each(info, &impl->node_list, link) {
spa_list_for_each(info, &impl->node_list, l) {
if (info->node == node)
return info;
}
@ -63,22 +62,19 @@ static struct node_info *find_node_info(struct impl *impl, struct pw_node *node)
static void node_info_free(struct node_info *info)
{
spa_list_remove(&info->link);
pw_signal_remove(&info->state_changed);
pw_signal_remove(&info->port_added);
pw_signal_remove(&info->port_removed);
pw_signal_remove(&info->port_unlinked);
pw_signal_remove(&info->link_destroy);
pw_signal_remove(&info->link_state_changed);
spa_list_remove(&info->l);
pw_callback_remove(&info->node_callbacks);
pw_callback_remove(&info->link_callbacks);
free(info);
}
static void try_link_port(struct pw_node *node, struct pw_port *port, struct node_info *info);
static void
on_link_port_unlinked(struct pw_listener *listener, struct pw_link *link, struct pw_port *port)
link_port_unlinked(void *data, struct pw_port *port)
{
struct node_info *info = SPA_CONTAINER_OF(listener, struct node_info, port_unlinked);
struct node_info *info = data;
struct pw_link *link = info->link;
struct impl *impl = info->impl;
pw_log_debug("module %p: link %p: port %p unlinked", impl, link, port);
@ -87,10 +83,10 @@ on_link_port_unlinked(struct pw_listener *listener, struct pw_link *link, struct
}
static void
on_link_state_changed(struct pw_listener *listener,
struct pw_link *link, enum pw_link_state old, enum pw_link_state state)
link_state_changed(void *data, enum pw_link_state old, enum pw_link_state state, const char *error)
{
struct node_info *info = SPA_CONTAINER_OF(listener, struct node_info, link_state_changed);
struct node_info *info = data;
struct pw_link *link = info->link;
struct impl *impl = info->impl;
switch (state) {
@ -98,17 +94,16 @@ on_link_state_changed(struct pw_listener *listener,
{
struct pw_resource *resource;
pw_log_debug("module %p: link %p: state error: %s", impl, link,
link->error);
pw_log_debug("module %p: link %p: state error: %s", impl, link, error);
spa_list_for_each(resource, &link->resource_list, link) {
pw_core_resource_error(resource->client->core_resource,
resource->id, SPA_RESULT_ERROR, link->error);
resource->id, SPA_RESULT_ERROR, error);
}
if (info->node->owner) {
pw_core_resource_error(info->node->owner->client->core_resource,
info->node->owner->id,
SPA_RESULT_ERROR, link->error);
SPA_RESULT_ERROR, error);
}
break;
}
@ -128,20 +123,24 @@ on_link_state_changed(struct pw_listener *listener,
}
static void
on_link_destroy(struct pw_listener *listener, struct pw_link *link)
link_destroy(void *data)
{
struct node_info *info = SPA_CONTAINER_OF(listener, struct node_info, link_destroy);
struct node_info *info = data;
struct pw_link *link = info->link;
struct impl *impl = info->impl;
pw_log_debug("module %p: link %p destroyed", impl, link);
pw_signal_remove(&info->port_unlinked);
pw_signal_remove(&info->link_state_changed);
pw_signal_remove(&info->link_destroy);
spa_list_init(&info->port_unlinked.link);
spa_list_init(&info->link_state_changed.link);
spa_list_init(&info->link_destroy.link);
pw_callback_remove(&info->link_callbacks);
spa_list_init(&info->link_callbacks.link);
}
static const struct pw_link_callbacks link_callbacks = {
PW_VERSION_LINK_CALLBACKS,
.destroy = link_destroy,
.port_unlinked = link_port_unlinked,
.state_changed = link_state_changed,
};
static void try_link_port(struct pw_node *node, struct pw_port *port, struct node_info *info)
{
struct impl *impl = info->impl;
@ -184,10 +183,9 @@ static void try_link_port(struct pw_node *node, struct pw_port *port, struct nod
if (link == NULL)
goto error;
pw_signal_add(&link->port_unlinked, &info->port_unlinked, on_link_port_unlinked);
pw_signal_add(&link->state_changed, &info->link_state_changed, on_link_state_changed);
pw_signal_add(&link->destroy_signal, &info->link_destroy, on_link_destroy);
info->link = link;
pw_link_add_callbacks(link, &info->link_callbacks, &link_callbacks, info);
pw_link_activate(link);
return;
@ -202,15 +200,13 @@ static void try_link_port(struct pw_node *node, struct pw_port *port, struct nod
return;
}
static void on_port_added(struct pw_listener *listener, struct pw_node *node, struct pw_port *port)
static void node_port_added(void *data, struct pw_port *port)
{
struct node_info *info = SPA_CONTAINER_OF(listener, struct node_info, port_added);
try_link_port(node, port, info);
struct node_info *info = data;
try_link_port(info->node, port, info);
}
static void
on_port_removed(struct pw_listener *listener, struct pw_node *node, struct pw_port *port)
static void node_port_removed(void *data, struct pw_port *port)
{
}
@ -219,26 +215,32 @@ static void on_node_created(struct pw_node *node, struct node_info *info)
struct pw_port *port;
spa_list_for_each(port, &node->input_ports, link)
on_port_added(&info->port_added, node, port);
node_port_added(info, port);
spa_list_for_each(port, &node->output_ports, link)
on_port_added(&info->port_added, node, port);
node_port_added(info, port);
}
static void
on_state_changed(struct pw_listener *listener,
struct pw_node *node, enum pw_node_state old, enum pw_node_state state)
node_state_changed(void *data, enum pw_node_state old, enum pw_node_state state, const char *error)
{
struct node_info *info = SPA_CONTAINER_OF(listener, struct node_info, state_changed);
struct node_info *info = data;
if (old == PW_NODE_STATE_CREATING && state == PW_NODE_STATE_SUSPENDED)
on_node_created(node, info);
on_node_created(info->node, info);
}
static const struct pw_node_callbacks node_callbacks = {
PW_VERSION_NODE_CALLBACKS,
.port_added = node_port_added,
.port_removed = node_port_removed,
.state_changed = node_state_changed,
};
static void
on_global_added(struct pw_listener *listener, struct pw_core *core, struct pw_global *global)
core_global_added(void *data, struct pw_global *global)
{
struct impl *impl = SPA_CONTAINER_OF(listener, struct impl, global_added);
struct impl *impl = data;
if (global->type == impl->core->type.node) {
struct pw_node *node = global->object;
@ -247,14 +249,11 @@ on_global_added(struct pw_listener *listener, struct pw_core *core, struct pw_gl
ninfo = calloc(1, sizeof(struct node_info));
ninfo->impl = impl;
ninfo->node = node;
spa_list_insert(impl->node_list.prev, &ninfo->link);
spa_list_init(&ninfo->port_unlinked.link);
spa_list_init(&ninfo->link_state_changed.link);
spa_list_init(&ninfo->link_destroy.link);
pw_signal_add(&node->port_added, &ninfo->port_added, on_port_added);
pw_signal_add(&node->port_removed, &ninfo->port_removed, on_port_removed);
pw_signal_add(&node->state_changed, &ninfo->state_changed, on_state_changed);
spa_list_insert(impl->node_list.prev, &ninfo->l);
pw_node_add_callbacks(node, &ninfo->node_callbacks, &node_callbacks, ninfo);
spa_list_init(&ninfo->link_callbacks.link);
pw_log_debug("module %p: node %p added", impl, node);
@ -264,9 +263,9 @@ on_global_added(struct pw_listener *listener, struct pw_core *core, struct pw_gl
}
static void
on_global_removed(struct pw_listener *listener, struct pw_core *core, struct pw_global *global)
core_global_removed(void *data, struct pw_global *global)
{
struct impl *impl = SPA_CONTAINER_OF(listener, struct impl, global_removed);
struct impl *impl = data;
if (global->type == impl->core->type.node) {
struct pw_node *node = global->object;
@ -279,6 +278,13 @@ on_global_removed(struct pw_listener *listener, struct pw_core *core, struct pw_
}
}
const struct pw_core_callbacks core_callbacks = {
PW_VERSION_CORE_CALLBACKS,
.global_added = core_global_added,
.global_removed = core_global_removed,
};
/**
* module_new:
* @core: #struct pw_core
@ -302,8 +308,7 @@ static bool module_init(struct pw_module *module, struct pw_properties *properti
spa_list_init(&impl->node_list);
pw_signal_add(&core->global_added, &impl->global_added, on_global_added);
pw_signal_add(&core->global_removed, &impl->global_removed, on_global_removed);
pw_core_add_callbacks(core, &impl->core_callbacks, &core_callbacks, impl);
return impl;
}

View file

@ -25,6 +25,7 @@
#include "config.h"
#include "pipewire/interfaces.h"
#include "pipewire/private.h"
#include "pipewire/core.h"
#include "pipewire/module.h"
@ -32,12 +33,12 @@
struct pw_protocol *pw_protocol_native_ext_client_node_init(struct pw_core *core);
struct impl {
struct pw_node_factory this;
struct factory_data {
struct pw_node_factory *this;
struct pw_properties *properties;
};
static struct pw_node *create_node(struct pw_node_factory *factory,
static struct pw_node *create_node(void *_data,
struct pw_resource *resource,
const char *name,
struct pw_properties *properties)
@ -59,32 +60,34 @@ static struct pw_node *create_node(struct pw_node_factory *factory,
return NULL;
}
static const struct pw_node_factory_implementation impl_factory = {
PW_VERSION_NODE_FACRORY_IMPLEMENTATION,
.create_node = create_node,
};
static bool module_init(struct pw_module *module, struct pw_properties *properties)
{
struct pw_core *core = module->core;
struct impl *impl;
struct pw_node_factory *factory;
struct factory_data *data;
impl = calloc(1, sizeof(struct impl));
if (impl == NULL)
factory = pw_node_factory_new(core, "client-node", sizeof(*data));
if (factory == NULL)
return false;
pw_log_debug("module %p: new", impl);
data = pw_node_factory_get_user_data(factory);
data->this = factory;
data->properties = properties;
impl->properties = properties;
pw_log_debug("module %p: new", module);
impl->this.core = core;
impl->this.name = "client-node";
pw_signal_init(&impl->this.destroy_signal);
impl->this.create_node = create_node;
pw_node_factory_set_implementation(factory,
&impl_factory,
data);
pw_protocol_native_ext_client_node_init(core);
spa_list_insert(core->node_factory_list.prev, &impl->this.link);
impl->this.global = pw_core_add_global(core, NULL, module->global,
core->type.node_factory, 0,
NULL, impl);
pw_node_factory_export(factory, NULL, module->global);
return true;
}

View file

@ -33,6 +33,7 @@
#include "spa/lib/format.h"
#include "pipewire/pipewire.h"
#include "pipewire/private.h"
#include "pipewire/interfaces.h"
#include "pipewire/transport.h"
@ -120,8 +121,8 @@ struct impl {
struct pw_transport *transport;
struct pw_listener node_free;
struct pw_listener initialized;
struct pw_callback_info node_callbacks;
struct pw_callback_info resource_callbacks;
int fds[2];
int other_fds[2];
@ -830,11 +831,9 @@ static int handle_node_event(struct proxy *this, struct spa_event *event)
}
static void
client_node_done(void *object, int seq, int res)
client_node_done(void *data, int seq, int res)
{
struct pw_resource *resource = object;
struct pw_client_node *node = resource->object;
struct impl *impl = SPA_CONTAINER_OF(node, struct impl, this);
struct impl *impl = data;
struct proxy *this = &impl->proxy;
this->callbacks->done(&this->node, seq, res, this->user_data);
@ -842,14 +841,12 @@ client_node_done(void *object, int seq, int res)
static void
client_node_update(void *object,
client_node_update(void *data,
uint32_t change_mask,
uint32_t max_input_ports,
uint32_t max_output_ports, const struct spa_props *props)
{
struct pw_resource *resource = object;
struct pw_client_node *node = resource->object;
struct impl *impl = SPA_CONTAINER_OF(node, struct impl, this);
struct impl *impl = data;
struct proxy *this = &impl->proxy;
if (change_mask & PW_CLIENT_NODE_UPDATE_MAX_INPUTS)
@ -862,7 +859,7 @@ client_node_update(void *object,
}
static void
client_node_port_update(void *object,
client_node_port_update(void *data,
enum spa_direction direction,
uint32_t port_id,
uint32_t change_mask,
@ -872,9 +869,7 @@ client_node_port_update(void *object,
uint32_t n_params,
const struct spa_param **params, const struct spa_port_info *info)
{
struct pw_resource *resource = object;
struct pw_client_node *node = resource->object;
struct impl *impl = SPA_CONTAINER_OF(node, struct impl, this);
struct impl *impl = data;
struct proxy *this = &impl->proxy;
bool remove;
@ -896,30 +891,26 @@ client_node_port_update(void *object,
}
}
static void client_node_event(void *object, struct spa_event *event)
static void client_node_event(void *data, struct spa_event *event)
{
struct pw_resource *resource = object;
struct pw_client_node *node = resource->object;
struct impl *impl = SPA_CONTAINER_OF(node, struct impl, this);
struct impl *impl = data;
struct proxy *this = &impl->proxy;
this->callbacks->event(&this->node, event, this->user_data);
}
static void client_node_destroy(void *object)
static void client_node_destroy(void *data)
{
struct pw_resource *resource = object;
struct pw_client_node *node = resource->object;
pw_client_node_destroy(node);
struct impl *impl = data;
pw_client_node_destroy(&impl->this);
}
static struct pw_client_node_methods client_node_methods = {
PW_VERSION_CLIENT_NODE_METHODS,
&client_node_done,
&client_node_update,
&client_node_port_update,
&client_node_event,
&client_node_destroy,
.done = client_node_done,
.update = client_node_update,
.port_update = client_node_port_update,
.event = client_node_event,
.destroy = client_node_destroy,
};
static void proxy_on_data_fd_events(struct spa_source *source)
@ -1035,10 +1026,11 @@ static int client_node_get_fds(struct pw_client_node *node, int *readfd, int *wr
return SPA_RESULT_OK;
}
static void on_initialized(struct pw_listener *listener, struct pw_node *node)
static void node_initialized(void *data)
{
struct impl *impl = SPA_CONTAINER_OF(listener, struct impl, initialized);
struct impl *impl = data;
struct pw_client_node *this = &impl->this;
struct pw_node *node = this->node;
struct pw_transport_info info;
int readfd, writefd;
@ -1072,10 +1064,10 @@ static int proxy_clear(struct proxy *this)
return SPA_RESULT_OK;
}
static void client_node_resource_destroy(struct pw_resource *resource)
static void client_node_resource_destroy(void *data)
{
struct pw_client_node *this = resource->object;
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
struct impl *impl = data;
struct pw_client_node *this = &impl->this;
struct proxy *proxy = &impl->proxy;
pw_log_debug("client-node %p: destroy", impl);
@ -1083,26 +1075,24 @@ static void client_node_resource_destroy(struct pw_resource *resource)
impl->proxy.resource = this->resource = NULL;
pw_signal_remove(&impl->initialized);
if (proxy->data_source.fd != -1)
spa_loop_remove_source(proxy->data_loop, &proxy->data_source);
pw_node_destroy(this->node);
}
static void on_node_free(struct pw_listener *listener, struct pw_node *node)
static void node_free(void *data)
{
struct impl *impl = SPA_CONTAINER_OF(listener, struct impl, node_free);
struct impl *impl = data;
pw_log_debug("client-node %p: free", &impl->this);
proxy_clear(&impl->proxy);
pw_signal_remove(&impl->node_free);
if (impl->transport)
pw_transport_destroy(impl->transport);
pw_callback_remove(&impl->node_callbacks);
if (impl->fds[0] != -1)
close(impl->fds[0]);
if (impl->fds[1] != -1)
@ -1110,6 +1100,17 @@ static void on_node_free(struct pw_listener *listener, struct pw_node *node)
free(impl);
}
static const struct pw_node_callbacks node_callbacks = {
PW_VERSION_NODE_CALLBACKS,
.free = node_free,
.initialized = node_initialized,
};
static const struct pw_resource_callbacks resource_callbacks = {
PW_VERSION_RESOURCE_CALLBACKS,
.destroy = client_node_resource_destroy,
};
/** Create a new client node
* \param client an owner \ref pw_client
* \param id an id
@ -1156,14 +1157,17 @@ struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
if (this->node == NULL)
goto error_no_node;
this->resource->destroy = (pw_destroy_t) client_node_resource_destroy;
pw_resource_add_callbacks(this->resource,
&impl->resource_callbacks,
&resource_callbacks,
impl);
pw_resource_set_implementation(this->resource,
this, &client_node_methods);
&client_node_methods,
impl);
impl->proxy.resource = this->resource;
pw_signal_add(&this->node->free_signal, &impl->node_free, on_node_free);
pw_signal_add(&this->node->initialized, &impl->initialized, on_initialized);
pw_node_add_callbacks(this->node, &impl->node_callbacks, &node_callbacks, impl);
return this;

View file

@ -25,6 +25,7 @@
#include "pipewire/interfaces.h"
#include "pipewire/protocol.h"
#include "pipewire/client.h"
#include "pipewire/private.h"
#include "extensions/protocol-native.h"
#include "extensions/client-node.h"

View file

@ -30,6 +30,7 @@
#include <dbus/dbus.h>
#include "pipewire/interfaces.h"
#include "pipewire/private.h"
#include "pipewire/utils.h"
#include "pipewire/core.h"
@ -41,8 +42,7 @@ struct impl {
DBusConnection *bus;
struct pw_listener global_added;
struct pw_listener global_removed;
struct pw_callback_info core_callbacks;
struct spa_list client_list;
@ -57,8 +57,7 @@ struct client_info {
const struct pw_core_methods *old_methods;
struct pw_core_methods core_methods;
struct spa_list async_pending;
struct pw_listener resource_impl;
struct pw_listener resource_removed;
struct pw_callback_info client_callback;
};
struct async_pending {
@ -139,6 +138,7 @@ static void client_info_free(struct client_info *cinfo)
spa_list_for_each_safe(p, tmp, &cinfo->async_pending, link)
free_pending(p);
pw_callback_remove(&cinfo->client_callback);
spa_list_remove(&cinfo->link);
free(cinfo);
}
@ -432,11 +432,10 @@ do_create_link(void *object,
new_id);
}
static void on_resource_impl(struct pw_listener *listener,
struct pw_client *client,
struct pw_resource *resource)
static void client_resource_impl(void *data, struct pw_resource *resource)
{
struct client_info *cinfo = SPA_CONTAINER_OF(listener, struct client_info, resource_impl);
struct client_info *cinfo = data;
struct pw_client *client = cinfo->client;
if (resource->type == client->core->type.core) {
cinfo->old_methods = resource->implementation;
@ -448,10 +447,15 @@ static void on_resource_impl(struct pw_listener *listener,
}
}
const struct pw_client_callbacks client_callbacks = {
PW_VERSION_CLIENT_CALLBACKS,
.resource_impl = client_resource_impl,
};
static void
on_global_added(struct pw_listener *listener, struct pw_core *core, struct pw_global *global)
core_global_added(void *data, struct pw_global *global)
{
struct impl *impl = SPA_CONTAINER_OF(listener, struct impl, global_added);
struct impl *impl = data;
if (global->type == impl->core->type.client) {
struct pw_client *client = global->object;
@ -463,7 +467,7 @@ on_global_added(struct pw_listener *listener, struct pw_core *core, struct pw_gl
cinfo->is_sandboxed = client_is_sandboxed(client);
spa_list_init(&cinfo->async_pending);
pw_signal_add(&client->resource_impl, &cinfo->resource_impl, on_resource_impl);
pw_client_add_callbacks(client, &cinfo->client_callback, &client_callbacks, cinfo);
spa_list_insert(impl->client_list.prev, &cinfo->link);
@ -472,9 +476,9 @@ on_global_added(struct pw_listener *listener, struct pw_core *core, struct pw_gl
}
static void
on_global_removed(struct pw_listener *listener, struct pw_core *core, struct pw_global *global)
core_global_removed(void *data, struct pw_global *global)
{
struct impl *impl = SPA_CONTAINER_OF(listener, struct impl, global_removed);
struct impl *impl = data;
if (global->type == impl->core->type.client) {
struct pw_client *client = global->object;
@ -487,6 +491,12 @@ on_global_removed(struct pw_listener *listener, struct pw_core *core, struct pw_
}
}
const struct pw_core_callbacks core_callbacks = {
PW_VERSION_CORE_CALLBACKS,
.global_added = core_global_added,
.global_removed = core_global_removed,
};
static void dispatch_cb(struct spa_loop_utils *utils, struct spa_source *source, void *userdata)
{
struct impl *impl = userdata;
@ -689,8 +699,8 @@ static struct impl *module_new(struct pw_core *core, struct pw_properties *prope
spa_list_init(&impl->client_list);
pw_signal_add(&core->global_added, &impl->global_added, on_global_added);
pw_signal_add(&core->global_removed, &impl->global_removed, on_global_removed);
pw_core_add_callbacks(core, &impl->core_callbacks, &core_callbacks, impl);
core->permission_func = do_permission;
core->permission_data = impl;

View file

@ -35,6 +35,7 @@
#include "config.h"
#include "pipewire/pipewire.h"
#include "pipewire/private.h"
#include "pipewire/log.h"
#include "pipewire/interfaces.h"
@ -97,15 +98,14 @@ struct client {
struct pw_client *client;
int fd;
struct spa_source *source;
struct pw_listener busy_changed;
struct pw_callback_info client_callbacks;
};
static int process_messages(struct client *client);
static void client_destroy(void *data)
{
struct pw_client *client = data;
struct client *this = client->user_data;
struct client *this = data;
pw_loop_destroy_source(this->impl->core->main_loop, this->source);
spa_list_remove(&this->link);
@ -399,18 +399,17 @@ process_messages(struct client *client)
}
static void
on_busy_changed(struct pw_listener *listener,
struct pw_client *client)
client_busy_changed(void *data, bool busy)
{
struct client *c = SPA_CONTAINER_OF(listener, struct client, busy_changed);
struct client *c = data;
enum spa_io mask = SPA_IO_ERR | SPA_IO_HUP;
if (!client->busy)
if (!busy)
mask |= SPA_IO_IN;
pw_loop_update_io(c->impl->core->main_loop, c->source, mask);
if (!client->busy)
if (!busy)
process_messages(c);
}
@ -430,6 +429,12 @@ connection_data(struct spa_loop_utils *utils,
process_messages(client);
}
static const struct pw_client_callbacks client_callbacks = {
PW_VERSION_CLIENT_CALLBACKS,
.destroy = client_destroy,
.busy_changed = client_busy_changed,
};
static struct client *client_new(struct impl *impl, int fd)
{
struct client *this;
@ -449,8 +454,6 @@ static struct client *client_new(struct impl *impl, int fd)
if (client == NULL)
goto no_client;
client->destroy = client_destroy;
this = client->user_data;
this->impl = impl;
this->fd = fd;
@ -464,7 +467,7 @@ static struct client *client_new(struct impl *impl, int fd)
spa_list_insert(impl->client_list.prev, &this->link);
pw_signal_add(&client->busy_changed, &this->busy_changed, on_busy_changed);
pw_client_add_callbacks(client, &this->client_callbacks, &client_callbacks, this);
pw_log_error("module-jack %p: added new client", impl);

View file

@ -25,6 +25,7 @@
#include "config.h"
#include "pipewire/core.h"
#include "pipewire/private.h"
#include "pipewire/module.h"
#include "modules/spa/spa-node.h"

View file

@ -30,6 +30,7 @@
#include "config.h"
#include "pipewire/pipewire.h"
#include "pipewire/private.h"
#include "pipewire/log.h"
#include "pipewire/interfaces.h"
#include "pipewire/core.h"
@ -86,10 +87,11 @@ struct listener {
};
struct client_data {
struct pw_client *client;
int fd;
struct spa_source *source;
struct pw_protocol_native_connection *connection;
struct pw_listener busy_changed;
struct pw_callback_info client_callbacks;
};
static void
@ -162,18 +164,18 @@ process_messages(struct pw_client *client)
}
static void
on_busy_changed(struct pw_listener *listener,
struct pw_client *client)
client_busy_changed(void *data, bool busy)
{
struct client_data *data = SPA_CONTAINER_OF(listener, struct client_data, busy_changed);
struct pw_client *client = data;
struct client_data *c = client->user_data;
enum spa_io mask = SPA_IO_ERR | SPA_IO_HUP;
if (!client->busy)
if (!busy)
mask |= SPA_IO_IN;
pw_loop_update_io(client->core->main_loop, data->source, mask);
pw_loop_update_io(client->core->main_loop, c->source, mask);
if (!client->busy)
if (busy)
process_messages(client);
}
@ -207,7 +209,7 @@ connection_data(struct spa_loop_utils *utils,
process_messages(client);
}
static void client_destroy(void *data)
static void client_free(void *data)
{
struct pw_client *client = data;
struct client_data *this = client->user_data;
@ -219,6 +221,12 @@ static void client_destroy(void *data)
close(this->fd);
}
static const struct pw_client_callbacks client_callbacks = {
PW_VERSION_CLIENT_CALLBACKS,
.free = client_free,
.busy_changed = client_busy_changed,
};
static struct pw_client *client_new(struct listener *l, int fd)
{
struct client_data *this;
@ -240,9 +248,8 @@ static struct pw_client *client_new(struct listener *l, int fd)
if (client == NULL)
goto no_client;
client->destroy = client_destroy;
this = client->user_data;
this = pw_client_get_user_data(client);
this->client = client;
this->fd = fd;
this->source = pw_loop_add_io(protocol->core->main_loop,
this->fd,
@ -257,7 +264,7 @@ static struct pw_client *client_new(struct listener *l, int fd)
client->protocol = protocol;
spa_list_insert(l->this.client_list.prev, &client->protocol_link);
pw_signal_add(&client->busy_changed, &this->busy_changed, on_busy_changed);
pw_client_add_callbacks(client, &this->client_callbacks, &client_callbacks, client);
pw_global_bind(protocol->core->global, client, PW_PERM_RWX, PW_VERSION_CORE, 0);
@ -474,7 +481,7 @@ on_remote_data(struct spa_loop_utils *utils,
pw_log_trace("protocol-native %p: got message %d from %u", this, opcode, id);
proxy = pw_map_lookup(&this->objects, id);
if (proxy == NULL) {
if (proxy == NULL || proxy->marshal == NULL) {
pw_log_error("protocol-native %p: could not find proxy %u", this, id);
continue;
}
@ -764,7 +771,7 @@ static bool module_init(struct pw_module *module, struct pw_properties *properti
pw_log_debug("protocol-native %p: new", this);
d = this->user_data;
d = pw_protocol_get_user_data(this);
d->module = module;
if ((val = pw_properties_get(core->properties, "pipewire.daemon"))) {

View file

@ -28,11 +28,10 @@
#include <spa/lib/debug.h>
#include <pipewire/pipewire.h>
#include <pipewire/private.h>
#include "connection.h"
/** \cond */
#define MAX_BUFFER_SIZE (1024 * 32)
#define MAX_FDS 28

View file

@ -23,6 +23,7 @@
#include "spa/pod-iter.h"
#include "pipewire/pipewire.h"
#include "pipewire/private.h"
#include "pipewire/protocol.h"
#include "pipewire/interfaces.h"
#include "pipewire/resource.h"

View file

@ -28,20 +28,19 @@
struct impl {
struct pw_core *core;
struct pw_type *t;
struct pw_properties *properties;
struct pw_listener global_added;
struct pw_listener global_removed;
struct pw_callback_info core_callbacks;
struct spa_list node_list;
};
struct node_info {
struct spa_list link;
struct impl *impl;
struct pw_node *node;
struct spa_list link;
struct pw_listener node_state_request;
struct pw_listener node_state_changed;
struct pw_callback_info node_callbacks;
struct spa_source *idle_timeout;
};
@ -59,7 +58,7 @@ static struct node_info *find_node_info(struct impl *impl, struct pw_node *node)
static void remove_idle_timeout(struct node_info *info)
{
if (info->idle_timeout) {
pw_loop_destroy_source(info->impl->core->main_loop, info->idle_timeout);
pw_loop_destroy_source(pw_core_get_main_loop(info->impl->core), info->idle_timeout);
info->idle_timeout = NULL;
}
}
@ -68,8 +67,7 @@ static void node_info_free(struct node_info *info)
{
spa_list_remove(&info->link);
remove_idle_timeout(info);
pw_signal_remove(&info->node_state_request);
pw_signal_remove(&info->node_state_changed);
pw_callback_remove(&info->node_callbacks);
free(info);
}
@ -83,63 +81,65 @@ static void idle_timeout(struct spa_loop_utils *utils, struct spa_source *source
}
static void
on_node_state_request(struct pw_listener *listener, struct pw_node *node, enum pw_node_state state)
node_state_request(void *data, enum pw_node_state state)
{
struct node_info *info = SPA_CONTAINER_OF(listener, struct node_info, node_state_request);
struct node_info *info = data;
remove_idle_timeout(info);
}
static void
on_node_state_changed(struct pw_listener *listener,
struct pw_node *node, enum pw_node_state old, enum pw_node_state state)
node_state_changed(void *data, enum pw_node_state old, enum pw_node_state state, const char *error)
{
struct node_info *info = SPA_CONTAINER_OF(listener, struct node_info, node_state_changed);
struct node_info *info = data;
struct impl *impl = info->impl;
if (state != PW_NODE_STATE_IDLE) {
remove_idle_timeout(info);
} else {
struct timespec value;
struct pw_loop *main_loop = pw_core_get_main_loop(impl->core);
pw_log_debug("module %p: node %p became idle", impl, node);
info->idle_timeout = pw_loop_add_timer(impl->core->main_loop,
idle_timeout, info);
pw_log_debug("module %p: node %p became idle", impl, info->node);
info->idle_timeout = pw_loop_add_timer(main_loop, idle_timeout, info);
value.tv_sec = 3;
value.tv_nsec = 0;
pw_loop_update_timer(impl->core->main_loop,
info->idle_timeout, &value, NULL, false);
pw_loop_update_timer(main_loop, info->idle_timeout, &value, NULL, false);
}
}
static void
on_global_added(struct pw_listener *listener, struct pw_core *core, struct pw_global *global)
{
struct impl *impl = SPA_CONTAINER_OF(listener, struct impl, global_added);
static const struct pw_node_callbacks node_callbacks = {
PW_VERSION_NODE_CALLBACKS,
.state_request = node_state_request,
.state_changed = node_state_changed,
};
if (global->type == impl->core->type.node) {
struct pw_node *node = global->object;
static void
core_global_added(void *data, struct pw_global *global)
{
struct impl *impl = data;
if (pw_global_get_type(global) == impl->t->node) {
struct pw_node *node = pw_global_get_object(global);
struct node_info *info;
info = calloc(1, sizeof(struct node_info));
info->impl = impl;
info->node = node;
spa_list_insert(impl->node_list.prev, &info->link);
pw_signal_add(&node->state_request, &info->node_state_request,
on_node_state_request);
pw_signal_add(&node->state_changed, &info->node_state_changed,
on_node_state_changed);
pw_node_add_callbacks(node, &info->node_callbacks, &node_callbacks, info);
pw_log_debug("module %p: node %p added", impl, node);
}
}
static void
on_global_removed(struct pw_listener *listener, struct pw_core *core, struct pw_global *global)
core_global_removed(void *data, struct pw_global *global)
{
struct impl *impl = SPA_CONTAINER_OF(listener, struct impl, global_removed);
struct impl *impl = data;
if (global->type == impl->core->type.node) {
struct pw_node *node = global->object;
if (pw_global_get_type(global) == impl->t->node) {
struct pw_node *node = pw_global_get_object(global);
struct node_info *info;
if ((info = find_node_info(impl, node)))
@ -149,6 +149,11 @@ on_global_removed(struct pw_listener *listener, struct pw_core *core, struct pw_
}
}
const struct pw_core_callbacks core_callbacks = {
PW_VERSION_CORE_CALLBACKS,
.global_added = core_global_added,
.global_removed = core_global_removed,
};
/**
* module_new:
@ -159,20 +164,20 @@ on_global_removed(struct pw_listener *listener, struct pw_core *core, struct pw_
*
* Returns: a new #struct impl
*/
static struct impl *module_new(struct pw_core *core, struct pw_properties *properties)
static bool module_init(struct pw_module *module, struct pw_properties *properties)
{
struct impl *impl;
impl = calloc(1, sizeof(struct impl));
pw_log_debug("module %p: new", impl);
impl->core = core;
impl->core = pw_module_get_core(module);
impl->t = pw_core_get_type(impl->core);
impl->properties = properties;
spa_list_init(&impl->node_list);
pw_signal_add(&core->global_added, &impl->global_added, on_global_added);
pw_signal_add(&core->global_removed, &impl->global_removed, on_global_removed);
pw_core_add_callbacks(impl->core, &impl->core_callbacks, &core_callbacks, impl);
return impl;
}
@ -190,6 +195,5 @@ static void module_destroy(struct impl *impl)
bool pipewire__module_init(struct pw_module *module, const char *args)
{
module_new(module->core, NULL);
return true;
return module_init(module, NULL);
}

View file

@ -49,7 +49,9 @@ bool pipewire__module_init(struct pw_module *module, const char *args)
if ((dir = getenv("SPA_PLUGIN_DIR")) == NULL)
dir = PLUGINDIR;
pw_spa_monitor_load(module->core, module->global, dir, argv[0], argv[1], argv[2]);
pw_spa_monitor_load(pw_module_get_core(module),
pw_module_get_global(module),
dir, argv[0], argv[1], argv[2]);
pw_free_strv(argv);

View file

@ -25,21 +25,24 @@
#include "config.h"
#include "pipewire/interfaces.h"
#include "pipewire/private.h"
#include "pipewire/core.h"
#include "pipewire/module.h"
#include "spa-node.h"
struct impl {
struct pw_node_factory this;
struct factory_data {
struct pw_core *core;
struct pw_node_factory *this;
struct pw_properties *properties;
};
static struct pw_node *create_node(struct pw_node_factory *factory,
static struct pw_node *create_node(void *_data,
struct pw_resource *resource,
const char *name,
struct pw_properties *properties)
{
struct factory_data *data = _data;
struct pw_node *node;
const char *lib, *factory_name;
@ -52,7 +55,7 @@ static struct pw_node *create_node(struct pw_node_factory *factory,
if(lib == NULL || factory_name == NULL)
goto no_properties;
node = pw_spa_node_load(factory->core,
node = pw_spa_node_load(data->core,
NULL,
NULL,
lib,
@ -82,28 +85,32 @@ static struct pw_node *create_node(struct pw_node_factory *factory,
return NULL;
}
static const struct pw_node_factory_implementation impl_factory = {
PW_VERSION_NODE_FACRORY_IMPLEMENTATION,
.create_node = create_node,
};
static bool module_init(struct pw_module *module, struct pw_properties *properties)
{
struct pw_core *core = module->core;
struct impl *impl;
struct pw_node_factory *factory;
struct factory_data *data;
impl = calloc(1, sizeof(struct impl));
if (impl == NULL)
factory = pw_node_factory_new(core, "spa-node-factory", sizeof(*data));
if (factory == NULL)
return false;
pw_log_debug("module %p: new", impl);
data = pw_node_factory_get_user_data(factory);
data->this = factory;
data->properties = properties;
impl->properties = properties;
pw_log_debug("module %p: new", module);
impl->this.core = core;
impl->this.name = "spa-node-factory";
pw_signal_init(&impl->this.destroy_signal);
impl->this.create_node = create_node;
pw_node_factory_set_implementation(factory,
&impl_factory,
data);
spa_list_insert(core->node_factory_list.prev, &impl->this.link);
impl->this.global = pw_core_add_global(core, NULL, module->global, core->type.node_factory, 0,
NULL, impl);
pw_node_factory_export(factory, NULL, module->global);
return true;
}

View file

@ -60,7 +60,7 @@ bool pipewire__module_init(struct pw_module *module, const char *args)
pw_free_strv(prop);
}
pw_spa_node_load(module->core, NULL, module->global, argv[0], argv[1], argv[2], props);
pw_spa_node_load(pw_module_get_core(module), NULL, pw_module_get_global(module), argv[0], argv[1], argv[2], props);
pw_free_strv(argv);

View file

@ -47,6 +47,7 @@ struct impl {
struct pw_spa_monitor this;
struct pw_core *core;
struct pw_type *t;
struct pw_global *parent;
void *hnd;
@ -66,13 +67,16 @@ static void add_item(struct pw_spa_monitor *this, struct spa_monitor_item *item)
const char *name, *id, *klass;
struct spa_handle_factory *factory;
struct spa_pod *info = NULL;
struct pw_type *t = pw_core_get_type(impl->core);
const struct spa_support *support;
uint32_t n_support;
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);
t->monitor.name, SPA_POD_TYPE_STRING, &name,
t->monitor.id, SPA_POD_TYPE_STRING, &id,
t->monitor.klass, SPA_POD_TYPE_STRING, &klass,
t->monitor.factory, SPA_POD_TYPE_POINTER, &factory,
t->monitor.info, SPA_POD_TYPE_STRUCT, &info, 0);
pw_log_debug("monitor %p: add: \"%s\" (%s)", this, name, id);
@ -92,19 +96,22 @@ static void add_item(struct pw_spa_monitor *this, struct spa_monitor_item *item)
}
pw_properties_set(props, "media.class", klass);
support = pw_core_get_support(impl->core, &n_support);
handle = calloc(1, factory->size);
if ((res = spa_handle_factory_init(factory,
handle,
&props->dict,
impl->core->support, impl->core->n_support)) < 0) {
support,
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) {
if ((res = spa_handle_get_interface(handle, t->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) {
if ((res = spa_handle_get_interface(handle, t->spa_clock, &clock_iface)) < 0) {
pw_log_info("no CLOCK interface: %d", res);
}
@ -143,10 +150,11 @@ static void remove_item(struct pw_spa_monitor *this, struct spa_monitor_item *it
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
struct monitor_item *mitem;
const char *name, *id;
struct pw_type *t = pw_core_get_type(impl->core);
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);
t->monitor.name, SPA_POD_TYPE_STRING, &name,
t->monitor.id, SPA_POD_TYPE_STRING, &id, 0);
pw_log_debug("monitor %p: remove: \"%s\" (%s)", this, name, id);
mitem = find_item(this, id);
@ -158,19 +166,20 @@ static void on_monitor_event(struct spa_monitor *monitor, struct spa_event *even
{
struct impl *impl = user_data;
struct pw_spa_monitor *this = &impl->this;
struct pw_type *t = pw_core_get_type(impl->core);
if (SPA_EVENT_TYPE(event) == impl->core->type.monitor.Added) {
if (SPA_EVENT_TYPE(event) == t->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) {
} else if (SPA_EVENT_TYPE(event) == t->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) {
} else if (SPA_EVENT_TYPE(event) == t->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);
t->monitor.name, SPA_POD_TYPE_STRING, &name, 0);
pw_log_debug("monitor %p: changed: \"%s\"", this, name);
}
@ -180,10 +189,13 @@ static void update_monitor(struct pw_core *core, const char *name)
{
const char *monitors;
struct spa_dict_item item;
const struct spa_dict *props;
struct spa_dict dict = SPA_DICT_INIT(1, &item);
if (core->properties)
monitors = pw_properties_get(core->properties, "monitors");
props = pw_core_get_properties(core);
if (props)
monitors = spa_dict_lookup(props, "monitors");
else
monitors = NULL;
@ -220,6 +232,9 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
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;
struct pw_type *t = pw_core_get_type(core);
asprintf(&filename, "%s/%s.so", dir, lib);
@ -241,13 +256,14 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
if (strcmp(factory->name, factory_name) == 0)
break;
}
support = pw_core_get_support(core, &n_support);
handle = calloc(1, factory->size);
if ((res = spa_handle_factory_init(factory,
handle, NULL, core->support, core->n_support)) < 0) {
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, core->type.spa_monitor, &iface)) < 0) {
if ((res = spa_handle_get_interface(handle, t->spa_monitor, &iface)) < 0) {
free(handle);
pw_log_error("can't get MONITOR interface: %d", res);
goto interface_failed;
@ -255,6 +271,7 @@ struct pw_spa_monitor *pw_spa_monitor_load(struct pw_core *core,
impl = calloc(1, sizeof(struct impl));
impl->core = core;
impl->t = t;
impl->parent = parent;
impl->hnd = hnd;

View file

@ -30,6 +30,7 @@
#include <spa/node.h>
#include "spa-node.h"
#include "pipewire/private.h"
struct impl {
struct pw_node *this;
@ -41,101 +42,111 @@ struct impl {
struct spa_node *node; /**< handle to SPA node */
char *lib;
char *factory_name;
struct pw_callback_info node_callbacks;
};
struct port {
struct pw_port *port;
enum pw_direction direction;
uint32_t port_id;
struct spa_node *node;
};
static int port_impl_enum_formats(struct pw_port *port,
static int port_impl_set_io(void *data, struct spa_port_io *io)
{
struct port *p = data;
return spa_node_port_set_io(p->node, p->direction, p->port_id, io);
}
static int port_impl_enum_formats(void *data,
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);
struct port *p = data;
return spa_node_port_enum_formats(p->node, p->direction, p->port_id, format, filter, index);
}
static int port_impl_set_format(struct pw_port *port, uint32_t flags, const struct spa_format *format)
static int port_impl_set_format(void *data, uint32_t flags, const 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);
struct port *p = data;
return spa_node_port_set_format(p->node, p->direction, p->port_id, flags, format);
}
static int port_impl_get_format(struct pw_port *port, const struct spa_format **format)
static int port_impl_get_format(void *data, 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);
struct port *p = data;
return spa_node_port_get_format(p->node, p->direction, p->port_id, format);
}
static int port_impl_get_info(struct pw_port *port, const struct spa_port_info **info)
static int port_impl_get_info(void *data, 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);
struct port *p = data;
return spa_node_port_get_info(p->node, p->direction, p->port_id, info);
}
static int port_impl_enum_params(struct pw_port *port, uint32_t index, struct spa_param **param)
static int port_impl_enum_params(void *data, 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);
struct port *p = data;
return spa_node_port_enum_params(p->node, p->direction, p->port_id, index, param);
}
static int port_impl_set_param(struct pw_port *port, struct spa_param *param)
static int port_impl_set_param(void *data, struct spa_param *param)
{
struct port *p = port->user_data;
return spa_node_port_set_param(p->node, port->direction, port->port_id, param);
struct port *p = data;
return spa_node_port_set_param(p->node, p->direction, p->port_id, param);
}
static int port_impl_use_buffers(struct pw_port *port, struct spa_buffer **buffers, uint32_t n_buffers)
static int port_impl_use_buffers(void *data, 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);
struct port *p = data;
return spa_node_port_use_buffers(p->node, p->direction, p->port_id, buffers, n_buffers);
}
static int port_impl_alloc_buffers(struct pw_port *port,
static int port_impl_alloc_buffers(void *data,
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,
struct port *p = data;
return spa_node_port_alloc_buffers(p->node, p->direction, p->port_id,
params, n_params, buffers, n_buffers);
}
static int port_impl_reuse_buffer(struct pw_port *port, uint32_t buffer_id)
static int port_impl_reuse_buffer(void *data, uint32_t buffer_id)
{
struct port *p = port->user_data;
return spa_node_port_reuse_buffer(p->node, port->port_id, buffer_id);
struct port *p = data;
return spa_node_port_reuse_buffer(p->node, p->port_id, buffer_id);
}
static int port_impl_send_command(struct pw_port *port, struct spa_command *command)
static int port_impl_send_command(void *data, struct spa_command *command)
{
struct port *p = port->user_data;
struct port *p = data;
return spa_node_port_send_command(p->node,
port->direction,
port->port_id,
p->direction,
p->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,
.set_io = port_impl_set_io,
.enum_formats = port_impl_enum_formats,
.set_format = port_impl_set_format,
.get_format = port_impl_get_format,
.get_info = port_impl_get_info,
.enum_params = port_impl_enum_params,
.set_param = port_impl_set_param,
.use_buffers = port_impl_use_buffers,
.alloc_buffers = port_impl_alloc_buffers,
.reuse_buffer = port_impl_reuse_buffer,
.send_command = port_impl_send_command,
};
static struct pw_port *
make_port(struct pw_node *node, enum pw_direction direction, uint32_t port_id)
make_port(struct impl *impl, enum pw_direction direction, uint32_t port_id)
{
struct impl *impl = node->user_data;
struct pw_node *node = impl->this;
struct pw_port *port;
struct port *p;
@ -143,13 +154,13 @@ make_port(struct pw_node *node, enum pw_direction direction, uint32_t port_id)
if (port == NULL)
return NULL;
p = port->user_data;
p = pw_port_get_user_data(port);
p->port = port;
p->direction = direction;
p->port_id = port_id;
p->node = impl->node;
port->implementation = &port_impl;
spa_node_port_set_io(impl->node, direction, port_id, &port->io);
pw_port_set_implementation(port, &port_impl, p);
pw_port_add(port, node);
return port;
@ -192,7 +203,7 @@ static void update_port_ids(struct impl *impl)
|| 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]);
np = make_port(impl, PW_DIRECTION_INPUT, input_port_ids[i]);
ports = np->link.next;
i++;
@ -220,7 +231,7 @@ static void update_port_ids(struct impl *impl)
|| 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]);
np = make_port(impl, PW_DIRECTION_OUTPUT, output_port_ids[i]);
ports = np->link.next;
i++;
} else if (p) {
@ -235,66 +246,66 @@ static void update_port_ids(struct impl *impl)
}
static int node_impl_get_props(struct pw_node *node, struct spa_props **props)
static int node_impl_get_props(void *data, struct spa_props **props)
{
struct impl *impl = node->user_data;
struct impl *impl = data;
return spa_node_get_props(impl->node, props);
}
static int node_impl_set_props(struct pw_node *node, const struct spa_props *props)
static int node_impl_set_props(void *data, const struct spa_props *props)
{
struct impl *impl = node->user_data;
struct impl *impl = data;
return spa_node_set_props(impl->node, props);
}
static int node_impl_send_command(struct pw_node *node, const struct spa_command *command)
static int node_impl_send_command(void *data, const struct spa_command *command)
{
struct impl *impl = node->user_data;
struct impl *impl = data;
return spa_node_send_command(impl->node, command);
}
static struct pw_port*
node_impl_add_port(struct pw_node *node,
node_impl_add_port(void *data,
enum pw_direction direction,
uint32_t port_id)
{
struct impl *impl = node->user_data;
struct impl *impl = 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);
pw_log_error("node %p: could not add port %d %d", impl->this, port_id, res);
return NULL;
}
return make_port(node, direction, port_id);
return make_port(impl, direction, port_id);
}
static int node_impl_schedule_input(struct pw_node *node)
static int node_impl_process_input(void *data)
{
struct impl *impl = node->user_data;
struct impl *impl = data;
return spa_node_process_input(impl->node);
}
static int node_impl_schedule_output(struct pw_node *node)
static int node_impl_process_output(void *data)
{
struct impl *impl = node->user_data;
struct impl *impl = 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,
.get_props = node_impl_get_props,
.set_props = node_impl_set_props,
.send_command = node_impl_send_command,
.add_port = node_impl_add_port,
.process_input = node_impl_process_input,
.process_output = node_impl_process_output,
};
static void pw_spa_node_destroy(void *object)
static void pw_spa_node_destroy(void *data)
{
struct pw_node *node = object;
struct impl *impl = node->user_data;
struct impl *impl = data;
struct pw_node *node = impl->this;
pw_log_debug("spa-node %p: destroy", node);
@ -326,7 +337,7 @@ static void on_node_done(struct spa_node *node, int seq, int res, void *user_dat
}
pw_log_debug("spa-node %p: async complete event %d %d", this, seq, res);
pw_signal_emit(&this->async_complete, this, seq, res);
pw_callback_emit(&this->callback_list, struct pw_node_callbacks, async_complete, seq, res);
}
static void on_node_event(struct spa_node *node, struct spa_event *event, void *user_data)
@ -334,21 +345,21 @@ static void on_node_event(struct spa_node *node, struct spa_event *event, void *
struct impl *impl = user_data;
struct pw_node *this = impl->this;
pw_signal_emit(&this->event, this, event);
pw_callback_emit(&this->callback_list, struct pw_node_callbacks, event, 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;
pw_signal_emit(&this->need_input, this);
pw_callback_emit_na(&this->callback_list, struct pw_node_callbacks, need_input);
}
static void on_node_have_output(struct spa_node *node, void *user_data)
{
struct impl *impl = user_data;
struct pw_node *this = impl->this;
pw_signal_emit(&this->have_output, this);
pw_callback_emit_na(&this->callback_list, struct pw_node_callbacks, have_output);
}
static void
@ -370,13 +381,18 @@ on_node_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id
}
}
static const struct spa_node_callbacks node_callbacks = {
static const struct spa_node_callbacks spa_node_callbacks = {
SPA_VERSION_NODE_CALLBACKS,
&on_node_done,
&on_node_event,
&on_node_need_input,
&on_node_have_output,
&on_node_reuse_buffer,
.done = on_node_done,
.event = on_node_event,
.need_input = on_node_need_input,
.have_output = on_node_have_output,
.reuse_buffer = on_node_reuse_buffer,
};
static const struct pw_node_callbacks node_callbacks = {
PW_VERSION_NODE_CALLBACKS,
.destroy = pw_spa_node_destroy,
};
struct pw_node *
@ -411,8 +427,6 @@ pw_spa_node_new(struct pw_core *core,
if (this == NULL)
return NULL;
this->destroy = pw_spa_node_destroy;
this->implementation = &node_impl;
this->clock = clock;
impl = this->user_data;
@ -420,7 +434,11 @@ pw_spa_node_new(struct pw_core *core,
impl->node = node;
impl->async_init = async;
if (spa_node_set_callbacks(impl->node, &node_callbacks, impl) < 0)
pw_node_add_callbacks(this, &impl->node_callbacks, &node_callbacks, impl);
pw_node_set_implementation(this, &node_impl, impl);
if (spa_node_set_callbacks(impl->node, &spa_node_callbacks, impl) < 0)
pw_log_warn("spa-node %p: error setting callback", this);
if (!async) {