2017-05-23 19:15:33 +02:00
|
|
|
/* PipeWire
|
2016-07-22 17:17:44 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* Copyright © 2018 Wim Taymans
|
2016-07-22 17:17:44 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2016-07-22 17:17:44 +02:00
|
|
|
*
|
2018-11-05 17:48:52 +01:00
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
2016-07-22 17:17:44 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <string.h>
|
2016-10-17 12:20:49 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdio.h>
|
2016-07-22 17:17:44 +02:00
|
|
|
#include <errno.h>
|
2016-07-28 21:19:20 +02:00
|
|
|
#include <unistd.h>
|
2019-02-12 17:42:33 +01:00
|
|
|
#include <time.h>
|
2016-09-01 10:04:25 +02:00
|
|
|
#include <sys/eventfd.h>
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2017-11-10 13:36:14 +01:00
|
|
|
#include <spa/node/node.h>
|
2019-05-20 10:14:00 +02:00
|
|
|
#include <spa/node/utils.h>
|
2018-08-13 17:17:23 +02:00
|
|
|
#include <spa/pod/filter.h>
|
2019-01-17 17:23:47 +01:00
|
|
|
#include <spa/pod/parser.h>
|
2018-08-23 17:47:57 +02:00
|
|
|
#include <spa/debug/types.h>
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-01-14 12:58:23 +01:00
|
|
|
#include <pipewire/pipewire.h>
|
2017-10-25 18:39:56 +02:00
|
|
|
#include "pipewire/private.h"
|
2017-05-23 19:15:33 +02:00
|
|
|
|
2017-07-11 15:57:20 +02:00
|
|
|
#include "modules/spa/spa-node.h"
|
2017-06-21 09:03:29 +02:00
|
|
|
#include "client-node.h"
|
2017-05-23 19:15:33 +02:00
|
|
|
|
2017-05-30 19:46:51 +02:00
|
|
|
/** \cond */
|
|
|
|
|
|
2018-03-01 17:39:17 +01:00
|
|
|
#define MAX_INPUTS 64
|
|
|
|
|
#define MAX_OUTPUTS 64
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-03-01 17:39:17 +01:00
|
|
|
#define MAX_BUFFERS 64
|
|
|
|
|
#define MAX_AREAS 1024
|
2018-03-21 18:30:41 +01:00
|
|
|
#define MAX_IO 32
|
2018-07-31 12:23:35 +02:00
|
|
|
#define MAX_MIX 128
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
#define CHECK_IN_PORT_ID(this,d,p) ((d) == SPA_DIRECTION_INPUT && (p) < MAX_INPUTS)
|
|
|
|
|
#define CHECK_OUT_PORT_ID(this,d,p) ((d) == SPA_DIRECTION_OUTPUT && (p) < MAX_OUTPUTS)
|
|
|
|
|
#define CHECK_PORT_ID(this,d,p) (CHECK_IN_PORT_ID(this,d,p) || CHECK_OUT_PORT_ID(this,d,p))
|
2018-07-31 12:23:35 +02:00
|
|
|
#define CHECK_FREE_IN_PORT(this,d,p) (CHECK_IN_PORT_ID(this,d,p) && (this)->in_ports[p] == NULL)
|
|
|
|
|
#define CHECK_FREE_OUT_PORT(this,d,p) (CHECK_OUT_PORT_ID(this,d,p) && (this)->out_ports[p] == NULL)
|
2016-10-17 12:20:49 +02:00
|
|
|
#define CHECK_FREE_PORT(this,d,p) (CHECK_FREE_IN_PORT (this,d,p) || CHECK_FREE_OUT_PORT (this,d,p))
|
2018-07-31 12:23:35 +02:00
|
|
|
#define CHECK_IN_PORT(this,d,p) (CHECK_IN_PORT_ID(this,d,p) && (this)->in_ports[p])
|
|
|
|
|
#define CHECK_OUT_PORT(this,d,p) (CHECK_OUT_PORT_ID(this,d,p) && (this)->out_ports[p])
|
2016-10-17 12:20:49 +02:00
|
|
|
#define CHECK_PORT(this,d,p) (CHECK_IN_PORT (this,d,p) || CHECK_OUT_PORT (this,d,p))
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
#define GET_IN_PORT(this,p) (this->in_ports[p])
|
|
|
|
|
#define GET_OUT_PORT(this,p) (this->out_ports[p])
|
2017-11-09 17:07:04 +01:00
|
|
|
#define GET_PORT(this,d,p) (d == SPA_DIRECTION_INPUT ? GET_IN_PORT(this,p) : GET_OUT_PORT(this,p))
|
|
|
|
|
|
2016-10-28 16:56:33 +02:00
|
|
|
#define CHECK_PORT_BUFFER(this,b,p) (b < p->n_buffers)
|
|
|
|
|
|
2018-03-01 13:22:48 +01:00
|
|
|
struct mem {
|
|
|
|
|
uint32_t id;
|
|
|
|
|
int ref;
|
|
|
|
|
int fd;
|
|
|
|
|
uint32_t type;
|
|
|
|
|
uint32_t flags;
|
|
|
|
|
};
|
|
|
|
|
|
2017-11-28 12:43:53 +01:00
|
|
|
struct buffer {
|
2017-05-26 08:05:01 +02:00
|
|
|
struct spa_buffer *outbuf;
|
|
|
|
|
struct spa_buffer buffer;
|
|
|
|
|
struct spa_meta metas[4];
|
|
|
|
|
struct spa_data datas[4];
|
2018-03-01 18:30:39 +01:00
|
|
|
uint32_t memid;
|
2016-10-17 12:20:49 +02:00
|
|
|
};
|
|
|
|
|
|
2018-03-21 09:20:40 +01:00
|
|
|
struct io {
|
|
|
|
|
uint32_t id;
|
|
|
|
|
uint32_t memid;
|
|
|
|
|
};
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
struct mix {
|
2017-05-26 08:05:01 +02:00
|
|
|
bool valid;
|
2018-07-31 12:23:35 +02:00
|
|
|
bool active;
|
2018-07-31 21:36:10 +02:00
|
|
|
uint32_t id;
|
2018-07-31 12:23:35 +02:00
|
|
|
struct port *port;
|
|
|
|
|
uint32_t n_buffers;
|
|
|
|
|
struct buffer buffers[MAX_BUFFERS];
|
|
|
|
|
struct io ios[MAX_IO];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct port {
|
|
|
|
|
struct pw_port *port;
|
2018-07-31 14:28:15 +02:00
|
|
|
struct node *node;
|
2018-07-31 12:23:35 +02:00
|
|
|
struct impl *impl;
|
|
|
|
|
|
|
|
|
|
enum spa_direction direction;
|
|
|
|
|
uint32_t id;
|
|
|
|
|
|
2018-07-31 14:28:15 +02:00
|
|
|
struct spa_node mix_node;
|
2018-07-31 12:23:35 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
struct spa_port_info info;
|
2018-02-09 18:10:51 +01:00
|
|
|
struct pw_properties *properties;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2019-04-10 17:52:42 +02:00
|
|
|
unsigned int have_format:1;
|
|
|
|
|
unsigned int removed:1;
|
2017-05-26 08:05:01 +02:00
|
|
|
uint32_t n_params;
|
2017-11-13 17:57:38 +01:00
|
|
|
struct spa_pod **params;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
struct mix mix[MAX_MIX+1];
|
2017-05-23 19:15:33 +02:00
|
|
|
};
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node {
|
2017-05-26 08:05:01 +02:00
|
|
|
struct spa_node node;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
struct impl *impl;
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
struct spa_log *log;
|
|
|
|
|
struct spa_loop *data_loop;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
struct spa_hook_list hooks;
|
2019-05-15 12:17:52 +02:00
|
|
|
struct spa_callbacks callbacks;
|
2019-01-31 17:50:55 +01:00
|
|
|
struct io ios[MAX_IO];
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
struct pw_resource *resource;
|
2016-10-17 18:29:05 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
struct spa_source data_source;
|
|
|
|
|
int writefd;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
uint32_t n_inputs;
|
|
|
|
|
uint32_t n_outputs;
|
2018-07-31 12:23:35 +02:00
|
|
|
struct port *in_ports[MAX_INPUTS];
|
|
|
|
|
struct port *out_ports[MAX_OUTPUTS];
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-09-24 09:33:09 +02:00
|
|
|
struct port dummy;
|
|
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
uint32_t n_params;
|
2017-11-13 17:57:38 +01:00
|
|
|
struct spa_pod **params;
|
2019-02-20 17:51:05 +01:00
|
|
|
|
|
|
|
|
struct spa_list pending_list;
|
2016-10-17 12:20:49 +02:00
|
|
|
};
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl {
|
2017-05-26 08:05:01 +02:00
|
|
|
struct pw_client_node this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
struct pw_core *core;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node node;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-03-02 11:04:47 +01:00
|
|
|
struct pw_map io_map;
|
2018-03-01 17:39:17 +01:00
|
|
|
struct pw_memblock *io_areas;
|
2019-02-12 17:42:33 +01:00
|
|
|
struct pw_node_activation *activation;
|
2018-03-01 17:39:17 +01:00
|
|
|
|
2017-08-08 16:56:29 +02:00
|
|
|
struct spa_hook node_listener;
|
|
|
|
|
struct spa_hook resource_listener;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-03-01 13:22:48 +01:00
|
|
|
struct pw_array mems;
|
2019-03-15 20:29:34 +01:00
|
|
|
|
|
|
|
|
uint32_t bind_node_version;
|
|
|
|
|
uint32_t bind_node_id;
|
2018-03-01 13:22:48 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
int fds[2];
|
|
|
|
|
int other_fds[2];
|
2017-04-12 10:40:17 +02:00
|
|
|
};
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
#define pw_client_node_resource(r,m,v,...) \
|
|
|
|
|
pw_resource_notify_res(r,struct pw_client_node_proxy_events,m,v,__VA_ARGS__)
|
|
|
|
|
|
|
|
|
|
#define pw_client_node_resource_add_mem(r,...) \
|
|
|
|
|
pw_client_node_resource(r,add_mem,0,__VA_ARGS__)
|
|
|
|
|
#define pw_client_node_resource_transport(r,...) \
|
|
|
|
|
pw_client_node_resource(r,transport,0,__VA_ARGS__)
|
|
|
|
|
#define pw_client_node_resource_set_param(r,...) \
|
|
|
|
|
pw_client_node_resource(r,set_param,0,__VA_ARGS__)
|
|
|
|
|
#define pw_client_node_resource_set_io(r,...) \
|
|
|
|
|
pw_client_node_resource(r,set_io,0,__VA_ARGS__)
|
|
|
|
|
#define pw_client_node_resource_event(r,...) \
|
|
|
|
|
pw_client_node_resource(r,event,0,__VA_ARGS__)
|
|
|
|
|
#define pw_client_node_resource_command(r,...) \
|
|
|
|
|
pw_client_node_resource(r,command,0,__VA_ARGS__)
|
|
|
|
|
#define pw_client_node_resource_add_port(r,...) \
|
|
|
|
|
pw_client_node_resource(r,add_port,0,__VA_ARGS__)
|
|
|
|
|
#define pw_client_node_resource_remove_port(r,...) \
|
|
|
|
|
pw_client_node_resource(r,remove_port,0,__VA_ARGS__)
|
|
|
|
|
#define pw_client_node_resource_port_set_param(r,...) \
|
|
|
|
|
pw_client_node_resource(r,port_set_param,0,__VA_ARGS__)
|
|
|
|
|
#define pw_client_node_resource_port_use_buffers(r,...) \
|
|
|
|
|
pw_client_node_resource(r,port_use_buffers,0,__VA_ARGS__)
|
|
|
|
|
#define pw_client_node_resource_port_set_io(r,...) \
|
|
|
|
|
pw_client_node_resource(r,port_set_io,0,__VA_ARGS__)
|
|
|
|
|
#define pw_client_node_resource_set_activation(r,...) \
|
|
|
|
|
pw_client_node_resource(r,set_activation,0,__VA_ARGS__)
|
2018-07-31 21:36:10 +02:00
|
|
|
static int
|
|
|
|
|
do_port_use_buffers(struct impl *impl,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t mix_id,
|
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
|
uint32_t n_buffers);
|
2018-07-31 12:23:35 +02:00
|
|
|
|
2017-05-30 19:46:51 +02:00
|
|
|
/** \endcond */
|
|
|
|
|
|
2018-03-01 13:22:48 +01:00
|
|
|
static struct mem *ensure_mem(struct impl *impl, int fd, uint32_t type, uint32_t flags)
|
|
|
|
|
{
|
|
|
|
|
struct mem *m, *f = NULL;
|
|
|
|
|
|
|
|
|
|
pw_array_for_each(m, &impl->mems) {
|
|
|
|
|
if (m->ref <= 0)
|
|
|
|
|
f = m;
|
|
|
|
|
else if (m->fd == fd)
|
|
|
|
|
goto found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (f == NULL) {
|
|
|
|
|
m = pw_array_add(&impl->mems, sizeof(struct mem));
|
|
|
|
|
m->id = pw_array_get_len(&impl->mems, struct mem) - 1;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
m = f;
|
|
|
|
|
}
|
|
|
|
|
m->fd = fd;
|
|
|
|
|
m->type = type;
|
|
|
|
|
m->flags = flags;
|
2018-07-31 12:23:35 +02:00
|
|
|
m->ref = 0;
|
|
|
|
|
|
|
|
|
|
pw_log_debug("client-node %p: add mem %d", impl, m->id);
|
2018-03-01 13:22:48 +01:00
|
|
|
|
|
|
|
|
pw_client_node_resource_add_mem(impl->node.resource,
|
|
|
|
|
m->id,
|
|
|
|
|
type,
|
|
|
|
|
m->fd,
|
|
|
|
|
m->flags);
|
|
|
|
|
found:
|
|
|
|
|
m->ref++;
|
2018-07-31 12:23:35 +02:00
|
|
|
pw_log_debug("client-node %p: mem %d, ref %d", impl, m->id, m->ref);
|
2018-03-01 13:22:48 +01:00
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
static struct mix *find_mix(struct port *p, uint32_t mix_id)
|
|
|
|
|
{
|
|
|
|
|
struct mix *mix;
|
|
|
|
|
if (mix_id == SPA_ID_INVALID)
|
|
|
|
|
return &p->mix[MAX_MIX];
|
|
|
|
|
if (mix_id >= MAX_MIX)
|
|
|
|
|
return NULL;
|
|
|
|
|
mix = &p->mix[mix_id];
|
|
|
|
|
return mix;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-31 17:50:55 +01:00
|
|
|
static void init_ios(struct io *ios)
|
2018-07-31 12:23:35 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
2019-01-31 17:50:55 +01:00
|
|
|
for (i = 0; i < MAX_IO; i++)
|
|
|
|
|
ios[i].id = SPA_ID_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void mix_init(struct mix *mix, struct port *p, uint32_t id)
|
|
|
|
|
{
|
2018-07-31 12:23:35 +02:00
|
|
|
mix->valid = true;
|
2018-07-31 21:36:10 +02:00
|
|
|
mix->id = id;
|
2018-07-31 12:23:35 +02:00
|
|
|
mix->port = p;
|
|
|
|
|
mix->active = false;
|
|
|
|
|
mix->n_buffers = 0;
|
2019-01-31 17:50:55 +01:00
|
|
|
init_ios(mix->ios);
|
2018-07-31 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static struct mix *ensure_mix(struct impl *impl, struct port *p, uint32_t mix_id)
|
|
|
|
|
{
|
|
|
|
|
struct mix *mix;
|
|
|
|
|
|
|
|
|
|
if ((mix = find_mix(p, mix_id)) == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
if (mix->valid)
|
|
|
|
|
return mix;
|
2018-07-31 21:36:10 +02:00
|
|
|
mix_init(mix, p, mix_id);
|
2018-07-31 12:23:35 +02:00
|
|
|
return mix;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-21 09:20:40 +01:00
|
|
|
static void clear_io(struct node *node, struct io *io)
|
|
|
|
|
{
|
|
|
|
|
struct mem *m;
|
2018-09-28 05:49:38 +02:00
|
|
|
spa_log_debug(node->log, "node %p: clear io %p %d %d", node, io, io->id, io->memid);
|
2018-03-21 09:20:40 +01:00
|
|
|
m = pw_array_get_unchecked(&node->impl->mems, io->memid, struct mem);
|
|
|
|
|
m->ref--;
|
|
|
|
|
io->id = SPA_ID_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-31 17:50:55 +01:00
|
|
|
static struct io *update_io(struct node *this,
|
|
|
|
|
struct io *ios, uint32_t id, uint32_t memid)
|
2018-03-21 09:20:40 +01:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
struct io *io, *f = NULL;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_IO; i++) {
|
2019-01-31 17:50:55 +01:00
|
|
|
io = &ios[i];
|
2018-03-21 09:20:40 +01:00
|
|
|
if (io->id == SPA_ID_INVALID)
|
|
|
|
|
f = io;
|
2018-07-31 12:23:35 +02:00
|
|
|
else if (io->id == id) {
|
2018-03-21 09:20:40 +01:00
|
|
|
if (io->memid != memid) {
|
2018-09-28 05:49:38 +02:00
|
|
|
clear_io(this, io);
|
2018-03-21 09:20:40 +01:00
|
|
|
if (memid == SPA_ID_INVALID)
|
|
|
|
|
io->id = SPA_ID_INVALID;
|
|
|
|
|
}
|
|
|
|
|
goto found;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-28 05:49:38 +02:00
|
|
|
if (f == NULL || memid == SPA_ID_INVALID)
|
2018-03-21 09:20:40 +01:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
io = f;
|
|
|
|
|
io->id = id;
|
|
|
|
|
io->memid = memid;
|
2019-02-07 12:34:54 +01:00
|
|
|
spa_log_debug(this->log, "node %p: add io %p %s %d", this, io,
|
|
|
|
|
spa_debug_type_find_name(spa_type_io, id), memid);
|
2018-03-21 09:20:40 +01:00
|
|
|
|
|
|
|
|
found:
|
|
|
|
|
return io;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-31 17:50:55 +01:00
|
|
|
static void clear_ios(struct node *this, struct io *ios)
|
2018-03-21 09:20:40 +01:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_IO; i++) {
|
2019-01-31 17:50:55 +01:00
|
|
|
struct io *io = &ios[i];
|
2018-03-21 09:20:40 +01:00
|
|
|
if (io->id != SPA_ID_INVALID)
|
|
|
|
|
clear_io(this, io);
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-03-01 13:22:48 +01:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
static int clear_buffers(struct node *this, struct mix *mix)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 13:22:48 +01:00
|
|
|
uint32_t i, j;
|
|
|
|
|
struct impl *impl = this->impl;
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
for (i = 0; i < mix->n_buffers; i++) {
|
|
|
|
|
struct buffer *b = &mix->buffers[i];
|
2018-03-01 18:30:39 +01:00
|
|
|
struct mem *m;
|
2018-03-01 13:22:48 +01:00
|
|
|
|
|
|
|
|
spa_log_debug(this->log, "node %p: clear buffer %d", this, i);
|
|
|
|
|
|
|
|
|
|
for (j = 0; j < b->buffer.n_datas; j++) {
|
|
|
|
|
struct spa_data *d = &b->datas[j];
|
|
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
if (d->type == SPA_DATA_DmaBuf ||
|
|
|
|
|
d->type == SPA_DATA_MemFd) {
|
2018-03-01 13:22:48 +01:00
|
|
|
uint32_t id;
|
|
|
|
|
|
|
|
|
|
id = SPA_PTR_TO_UINT32(b->buffer.datas[j].data);
|
|
|
|
|
m = pw_array_get_unchecked(&impl->mems, id, struct mem);
|
|
|
|
|
m->ref--;
|
2018-07-31 12:23:35 +02:00
|
|
|
pw_log_debug("client-node %p: mem %d, ref %d", impl, m->id, m->ref);
|
2018-03-01 13:22:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
2018-03-01 18:30:39 +01:00
|
|
|
m = pw_array_get_unchecked(&impl->mems, b->memid, struct mem);
|
|
|
|
|
m->ref--;
|
2018-07-31 12:23:35 +02:00
|
|
|
pw_log_debug("client-node %p: mem %d, ref %d", impl, m->id, m->ref);
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2018-07-31 12:23:35 +02:00
|
|
|
mix->n_buffers = 0;
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
static void mix_clear(struct node *this, struct mix *mix)
|
|
|
|
|
{
|
2018-07-31 21:36:10 +02:00
|
|
|
struct port *port = mix->port;
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
if (!mix->valid)
|
|
|
|
|
return;
|
2018-07-31 21:36:10 +02:00
|
|
|
do_port_use_buffers(this->impl, port->direction, port->id,
|
|
|
|
|
mix->id, NULL, 0);
|
2019-01-31 17:50:55 +01:00
|
|
|
clear_ios(this, mix->ios);
|
2018-07-31 21:36:10 +02:00
|
|
|
mix->valid = false;
|
2018-07-31 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_enum_params(void *object, int seq,
|
2019-02-20 17:51:05 +01:00
|
|
|
uint32_t id, uint32_t start, uint32_t num,
|
2019-02-25 12:29:57 +01:00
|
|
|
const struct spa_pod *filter)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2019-02-20 17:51:05 +01:00
|
|
|
uint8_t buffer[1024];
|
|
|
|
|
struct spa_pod_builder b = { 0 };
|
2019-02-25 12:29:57 +01:00
|
|
|
struct spa_result_node_params result;
|
2019-02-20 17:51:05 +01:00
|
|
|
uint32_t count = 0;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2019-02-20 17:51:05 +01:00
|
|
|
spa_return_val_if_fail(num != 0, -EINVAL);
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
result.id = id;
|
2019-02-20 17:51:05 +01:00
|
|
|
result.next = start;
|
|
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
while (true) {
|
2017-11-13 17:57:38 +01:00
|
|
|
struct spa_pod *param;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
result.index = result.next++;
|
|
|
|
|
if (result.index >= this->n_params)
|
2019-02-27 16:43:01 +01:00
|
|
|
break;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
param = this->params[result.index];
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2019-01-17 17:23:47 +01:00
|
|
|
if (param == NULL || !spa_pod_is_object_id(param, id))
|
2017-11-09 17:07:04 +01:00
|
|
|
continue;
|
|
|
|
|
|
2019-02-20 17:51:05 +01:00
|
|
|
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
|
|
|
|
if (spa_pod_filter(&b, &result.param, param, filter) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
pw_log_debug("client-node %p: %d param %u", this, seq, result.index);
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_node_emit_result(&this->hooks, seq, 0, &result);
|
2019-02-20 17:51:05 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
if (++count == num)
|
2017-11-07 17:39:31 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2019-02-20 17:51:05 +01:00
|
|
|
return 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_set_param(void *object, uint32_t id, uint32_t flags,
|
2018-03-01 12:13:00 +01:00
|
|
|
const struct spa_pod *param)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2017-11-07 17:39:31 +01:00
|
|
|
|
|
|
|
|
if (this->resource == NULL)
|
2019-02-20 17:51:05 +01:00
|
|
|
return -EIO;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2019-02-18 12:31:36 +01:00
|
|
|
return pw_client_node_resource_set_param(this->resource, id, flags, param);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_set_io(void *object, uint32_t id, void *data, size_t size)
|
2018-10-23 12:31:41 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2019-01-31 17:50:55 +01:00
|
|
|
struct impl *impl;
|
|
|
|
|
struct pw_memblock *mem;
|
|
|
|
|
struct mem *m;
|
|
|
|
|
uint32_t memid, mem_offset, mem_size;
|
2018-10-23 12:31:41 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-10-23 12:31:41 +02:00
|
|
|
|
2019-01-31 17:50:55 +01:00
|
|
|
impl = this->impl;
|
2018-10-23 12:31:41 +02:00
|
|
|
|
2019-02-20 17:51:05 +01:00
|
|
|
if (impl->this.flags & 1)
|
2018-10-23 12:31:41 +02:00
|
|
|
return 0;
|
|
|
|
|
|
2019-02-20 17:51:05 +01:00
|
|
|
if (this->resource == NULL)
|
|
|
|
|
return -EIO;
|
|
|
|
|
|
2019-01-31 17:50:55 +01:00
|
|
|
if (data) {
|
|
|
|
|
if ((mem = pw_memblock_find(data)) == NULL)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
mem_offset = SPA_PTRDIFF(data, mem->ptr);
|
|
|
|
|
mem_size = mem->size;
|
|
|
|
|
if (mem_size - mem_offset < size)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
mem_offset += mem->offset;
|
2019-02-07 12:34:54 +01:00
|
|
|
mem_size = size;
|
2019-01-31 17:50:55 +01:00
|
|
|
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
|
|
|
|
|
memid = m->id;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
memid = SPA_ID_INVALID;
|
|
|
|
|
mem_offset = mem_size = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
update_io(this, this->ios, id, memid);
|
|
|
|
|
|
|
|
|
|
pw_client_node_resource_set_io(this->resource,
|
|
|
|
|
id,
|
|
|
|
|
memid,
|
|
|
|
|
mem_offset, mem_size);
|
|
|
|
|
return 0;
|
2018-10-23 12:31:41 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_send_command(void *object, const struct spa_command *command)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(command != NULL, -EINVAL);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
if (this->resource == NULL)
|
2019-02-20 17:51:05 +01:00
|
|
|
return -EIO;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
pw_log_debug("client-node %p: send command %d", this, SPA_COMMAND_TYPE(command));
|
2019-02-18 12:31:36 +01:00
|
|
|
return pw_client_node_resource_command(this->resource, command);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2019-02-14 17:08:46 +01:00
|
|
|
|
|
|
|
|
static void emit_port_info(struct node *this, struct port *port)
|
|
|
|
|
{
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_node_emit_port_info(&this->hooks,
|
2019-02-20 17:51:05 +01:00
|
|
|
port->direction, port->id, &port->info);
|
2019-02-14 17:08:46 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_add_listener(void *object,
|
2019-03-01 12:00:42 +01:00
|
|
|
struct spa_hook *listener,
|
|
|
|
|
const struct spa_node_events *events,
|
|
|
|
|
void *data)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2019-03-01 12:00:42 +01:00
|
|
|
struct spa_hook_list save;
|
2019-02-14 17:08:46 +01:00
|
|
|
uint32_t i;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_hook_list_isolate(&this->hooks, &save, listener, events, data);
|
2019-02-20 17:51:05 +01:00
|
|
|
|
2019-02-14 17:08:46 +01:00
|
|
|
for (i = 0; i < MAX_INPUTS; i++) {
|
|
|
|
|
if (this->in_ports[i])
|
|
|
|
|
emit_port_info(this, this->in_ports[i]);
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2019-02-14 17:08:46 +01:00
|
|
|
for (i = 0; i < MAX_OUTPUTS; i++) {
|
|
|
|
|
if (this->out_ports[i])
|
|
|
|
|
emit_port_info(this, this->out_ports[i]);
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_hook_list_join(&this->hooks, &save);
|
|
|
|
|
|
2019-03-15 20:28:42 +01:00
|
|
|
return 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-01 12:00:42 +01:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_set_callbacks(void *object,
|
2019-03-01 12:00:42 +01:00
|
|
|
const struct spa_node_callbacks *callbacks,
|
|
|
|
|
void *data)
|
|
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2019-03-01 12:00:42 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2019-03-01 12:00:42 +01:00
|
|
|
|
2019-05-15 12:17:52 +02:00
|
|
|
this->callbacks = SPA_CALLBACKS_INIT(callbacks, data);
|
2019-03-01 12:00:42 +01:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-18 12:31:36 +01:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_sync(void *object, int seq)
|
2019-02-18 12:31:36 +01:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
|
|
|
|
|
|
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
|
|
|
|
|
|
|
|
|
pw_log_debug("client-node %p: sync", this);
|
2019-02-20 17:51:05 +01:00
|
|
|
if (this->resource == NULL)
|
|
|
|
|
return -EIO;
|
2019-05-20 16:11:23 +02:00
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
return pw_resource_ping(this->resource, seq);
|
2019-02-18 12:31:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-17 12:20:49 +02:00
|
|
|
static void
|
2018-03-01 12:13:00 +01:00
|
|
|
do_update_port(struct node *this,
|
2018-07-31 12:23:35 +02:00
|
|
|
struct port *port,
|
2017-05-26 08:05:01 +02:00
|
|
|
uint32_t change_mask,
|
|
|
|
|
uint32_t n_params,
|
2017-11-13 17:57:38 +01:00
|
|
|
const struct spa_pod **params,
|
2017-05-26 08:05:01 +02:00
|
|
|
const struct spa_port_info *info)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2019-01-07 15:52:42 +01:00
|
|
|
uint32_t i;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-05-30 20:33:32 +02:00
|
|
|
if (change_mask & PW_CLIENT_NODE_PORT_UPDATE_PARAMS) {
|
2017-11-07 17:39:31 +01:00
|
|
|
port->have_format = false;
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_log_debug(this->log, "node %p: port %u update %d params", this, port->id, n_params);
|
2017-05-26 08:05:01 +02:00
|
|
|
for (i = 0; i < port->n_params; i++)
|
|
|
|
|
free(port->params[i]);
|
|
|
|
|
port->n_params = n_params;
|
2017-11-13 17:57:38 +01:00
|
|
|
port->params = realloc(port->params, port->n_params * sizeof(struct spa_pod *));
|
2017-11-07 17:39:31 +01:00
|
|
|
|
|
|
|
|
for (i = 0; i < port->n_params; i++) {
|
2019-02-20 17:51:05 +01:00
|
|
|
port->params[i] = params[i] ? spa_pod_copy(params[i]) : NULL;
|
2017-11-28 12:43:53 +01:00
|
|
|
|
2019-01-17 17:23:47 +01:00
|
|
|
if (port->params[i] && spa_pod_is_object_id(port->params[i], SPA_PARAM_Format))
|
2017-11-07 17:39:31 +01:00
|
|
|
port->have_format = true;
|
|
|
|
|
}
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
|
|
|
|
|
2018-02-09 18:10:51 +01:00
|
|
|
if (change_mask & PW_CLIENT_NODE_PORT_UPDATE_INFO) {
|
|
|
|
|
if (port->properties)
|
|
|
|
|
pw_properties_free(port->properties);
|
|
|
|
|
port->properties = NULL;
|
|
|
|
|
port->info.props = NULL;
|
2019-03-01 12:00:42 +01:00
|
|
|
port->info.n_params = 0;
|
|
|
|
|
port->info.params = NULL;
|
2018-02-09 18:10:51 +01:00
|
|
|
|
|
|
|
|
if (info) {
|
|
|
|
|
port->info = *info;
|
|
|
|
|
if (info->props) {
|
|
|
|
|
port->properties = pw_properties_new_dict(info->props);
|
|
|
|
|
port->info.props = &port->properties->dict;
|
|
|
|
|
}
|
2019-03-04 17:54:17 +01:00
|
|
|
port->info.n_params = 0;
|
|
|
|
|
port->info.params = NULL;
|
2019-03-04 12:30:45 +01:00
|
|
|
spa_node_emit_port_info(&this->hooks, port->direction, port->id, info);
|
2018-02-09 18:10:51 +01:00
|
|
|
}
|
|
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2018-07-31 12:23:35 +02:00
|
|
|
clear_port(struct node *this, struct port *port)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-07-31 12:23:35 +02:00
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
spa_log_debug(this->log, "node %p: clear port %p", this, port);
|
|
|
|
|
|
|
|
|
|
if (port == NULL)
|
2019-03-06 09:52:07 +01:00
|
|
|
return;
|
2018-07-31 12:23:35 +02:00
|
|
|
|
|
|
|
|
do_update_port(this, port,
|
2017-05-30 20:33:32 +02:00
|
|
|
PW_CLIENT_NODE_PORT_UPDATE_PARAMS |
|
2017-11-07 17:39:31 +01:00
|
|
|
PW_CLIENT_NODE_PORT_UPDATE_INFO, 0, NULL, NULL);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
for (i = 0; i < MAX_MIX+1; i++) {
|
|
|
|
|
struct mix *mix = &port->mix[i];
|
|
|
|
|
mix_clear(this, mix);
|
|
|
|
|
}
|
2017-11-09 17:07:04 +01:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
if (port->direction == SPA_DIRECTION_INPUT) {
|
2018-08-14 16:53:05 +02:00
|
|
|
if (this->in_ports[port->id] == port) {
|
|
|
|
|
this->in_ports[port->id] = NULL;
|
|
|
|
|
this->n_inputs--;
|
|
|
|
|
}
|
2018-07-31 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
else {
|
2018-08-14 16:53:05 +02:00
|
|
|
if (this->out_ports[port->id] == port) {
|
|
|
|
|
this->out_ports[port->id] = NULL;
|
|
|
|
|
this->n_outputs--;
|
|
|
|
|
}
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2019-03-06 09:52:07 +01:00
|
|
|
if (!port->removed)
|
|
|
|
|
spa_node_emit_port_info(&this->hooks, port->direction, port->id, NULL);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_add_port(void *object, enum spa_direction direction, uint32_t port_id,
|
2019-02-18 13:22:46 +01:00
|
|
|
const struct spa_dict *props)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(CHECK_FREE_PORT(this, direction, port_id), -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-02-18 13:22:46 +01:00
|
|
|
return pw_client_node_resource_add_port(this->resource, direction, port_id, props);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_remove_port(void *object, enum spa_direction direction, uint32_t port_id)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-02-18 12:31:36 +01:00
|
|
|
return pw_client_node_resource_remove_port(this->resource, direction, port_id);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_enum_params(void *object, int seq,
|
2018-03-01 12:13:00 +01:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
2019-02-20 17:51:05 +01:00
|
|
|
uint32_t id, uint32_t start, uint32_t num,
|
2019-02-25 12:29:57 +01:00
|
|
|
const struct spa_pod *filter)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2017-11-28 12:43:53 +01:00
|
|
|
struct port *port;
|
2019-02-20 17:51:05 +01:00
|
|
|
uint8_t buffer[1024];
|
|
|
|
|
struct spa_pod_builder b = { 0 };
|
2019-02-25 12:29:57 +01:00
|
|
|
struct spa_result_node_params result;
|
2019-02-20 17:51:05 +01:00
|
|
|
uint32_t count = 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2019-02-20 17:51:05 +01:00
|
|
|
spa_return_val_if_fail(num != 0, -EINVAL);
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-11-09 17:07:04 +01:00
|
|
|
port = GET_PORT(this, direction, port_id);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
pw_log_debug("client-node %p: %d port %d.%d %u %u %u", this, seq,
|
|
|
|
|
direction, port_id, id, start, num);
|
2018-07-31 12:23:35 +02:00
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
result.id = id;
|
2019-02-20 17:51:05 +01:00
|
|
|
result.next = start;
|
|
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
while (true) {
|
2017-11-13 17:57:38 +01:00
|
|
|
struct spa_pod *param;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
result.index = result.next++;
|
|
|
|
|
if (result.index >= port->n_params)
|
2019-02-27 16:43:01 +01:00
|
|
|
break;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
param = port->params[result.index];
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2019-01-17 17:23:47 +01:00
|
|
|
if (param == NULL || !spa_pod_is_object_id(param, id))
|
2017-11-09 17:07:04 +01:00
|
|
|
continue;
|
|
|
|
|
|
2019-02-20 17:51:05 +01:00
|
|
|
spa_pod_builder_init(&b, buffer, sizeof(buffer));
|
|
|
|
|
if (spa_pod_filter(&b, &result.param, param, filter) < 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
2019-02-25 12:29:57 +01:00
|
|
|
pw_log_debug("client-node %p: %d param %u", this, seq, result.index);
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_node_emit_result(&this->hooks, seq, 0, &result);
|
2019-02-20 17:51:05 +01:00
|
|
|
|
2019-02-27 16:43:01 +01:00
|
|
|
if (++count == num)
|
2017-11-07 17:39:31 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2019-02-20 17:51:05 +01:00
|
|
|
return 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_set_param(void *object,
|
2018-03-01 12:13:00 +01:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t id, uint32_t flags,
|
|
|
|
|
const struct spa_pod *param)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
if (this->resource == NULL)
|
2019-02-20 17:51:05 +01:00
|
|
|
return -EIO;
|
2017-05-22 13:06:18 +02:00
|
|
|
|
2019-02-18 12:31:36 +01:00
|
|
|
pw_log_debug("node %p: port %d.%d add param %s %d", this,
|
|
|
|
|
direction, port_id,
|
|
|
|
|
spa_debug_type_find_name(spa_type_param, id), id);
|
|
|
|
|
|
|
|
|
|
return pw_client_node_resource_port_set_param(this->resource,
|
2017-11-07 17:39:31 +01:00
|
|
|
direction, port_id,
|
|
|
|
|
id, flags,
|
|
|
|
|
param);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-01 20:07:24 +01:00
|
|
|
static int do_port_set_io(struct impl *impl,
|
2018-07-03 21:45:07 +02:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
2018-07-31 12:23:35 +02:00
|
|
|
uint32_t mix_id,
|
2018-07-03 21:45:07 +02:00
|
|
|
uint32_t id, void *data, size_t size)
|
2018-03-01 20:07:24 +01:00
|
|
|
{
|
|
|
|
|
struct node *this = &impl->node;
|
|
|
|
|
struct pw_memblock *mem;
|
|
|
|
|
struct mem *m;
|
|
|
|
|
uint32_t memid, mem_offset, mem_size;
|
2018-03-21 09:20:40 +01:00
|
|
|
struct port *port;
|
2018-07-31 12:23:35 +02:00
|
|
|
struct mix *mix;
|
2018-03-01 20:07:24 +01:00
|
|
|
|
2018-03-02 11:04:47 +01:00
|
|
|
pw_log_debug("client-node %p: %s port %d.%d set io %p %zd", impl,
|
|
|
|
|
direction == SPA_DIRECTION_INPUT ? "input" : "output",
|
2018-07-31 12:23:35 +02:00
|
|
|
port_id, mix_id, data, size);
|
2018-03-02 11:04:47 +01:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2018-03-01 20:07:24 +01:00
|
|
|
|
|
|
|
|
if (this->resource == NULL)
|
2019-02-20 17:51:05 +01:00
|
|
|
return -EIO;
|
2018-03-01 20:07:24 +01:00
|
|
|
|
2018-03-21 09:20:40 +01:00
|
|
|
port = GET_PORT(this, direction, port_id);
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
if ((mix = find_mix(port, mix_id)) == NULL || !mix->valid)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2018-03-01 20:07:24 +01:00
|
|
|
if (data) {
|
|
|
|
|
if ((mem = pw_memblock_find(data)) == NULL)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2018-03-08 11:04:29 +01:00
|
|
|
mem_offset = SPA_PTRDIFF(data, mem->ptr);
|
2018-03-01 20:07:24 +01:00
|
|
|
mem_size = mem->size;
|
|
|
|
|
if (mem_size - mem_offset < size)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2018-03-08 11:04:29 +01:00
|
|
|
mem_offset += mem->offset;
|
2018-08-23 17:47:57 +02:00
|
|
|
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
|
2018-03-01 20:07:24 +01:00
|
|
|
memid = m->id;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
memid = SPA_ID_INVALID;
|
|
|
|
|
mem_offset = mem_size = 0;
|
|
|
|
|
}
|
2018-06-01 11:19:22 +02:00
|
|
|
|
2019-01-31 17:50:55 +01:00
|
|
|
update_io(this, mix->ios, id, memid);
|
2018-03-01 20:07:24 +01:00
|
|
|
|
2019-02-18 12:31:36 +01:00
|
|
|
return pw_client_node_resource_port_set_io(this->resource,
|
2018-03-21 18:30:41 +01:00
|
|
|
direction, port_id,
|
2018-07-31 12:23:35 +02:00
|
|
|
mix_id,
|
2018-03-01 20:07:24 +01:00
|
|
|
id,
|
|
|
|
|
memid,
|
|
|
|
|
mem_offset, mem_size);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_set_io(void *object,
|
2018-03-01 12:13:00 +01:00
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
void *data, size_t size)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
2019-03-14 12:04:20 +01:00
|
|
|
/* ignore io on the node itself, we only care about the io on the
|
2019-03-11 16:43:43 +01:00
|
|
|
* port mixers, the io on the node ports itself is handled on the
|
|
|
|
|
* client side */
|
2019-03-14 12:04:20 +01:00
|
|
|
return -EINVAL;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2018-07-31 12:23:35 +02:00
|
|
|
do_port_use_buffers(struct impl *impl,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t mix_id,
|
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
|
uint32_t n_buffers)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-07-31 12:23:35 +02:00
|
|
|
struct node *this = &impl->node;
|
|
|
|
|
struct port *p;
|
|
|
|
|
struct mix *mix;
|
2017-11-28 18:23:44 +01:00
|
|
|
uint32_t i, j;
|
2017-05-26 08:05:01 +02:00
|
|
|
struct pw_client_node_buffer *mb;
|
2017-08-06 06:42:26 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_log_debug(this->log, "client-node %p: %s port %d.%d use buffers %p %u", impl,
|
|
|
|
|
direction == SPA_DIRECTION_INPUT ? "input" : "output",
|
|
|
|
|
port_id, mix_id, buffers, n_buffers);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
p = GET_PORT(this, direction, port_id);
|
|
|
|
|
if (!p->have_format)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EIO;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
if ((mix = find_mix(p, mix_id)) == NULL || !mix->valid)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
|
|
clear_buffers(this, mix);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
if (n_buffers > 0) {
|
|
|
|
|
mb = alloca(n_buffers * sizeof(struct pw_client_node_buffer));
|
|
|
|
|
} else {
|
|
|
|
|
mb = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
mix->n_buffers = n_buffers;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
if (this->resource == NULL)
|
2019-02-20 17:51:05 +01:00
|
|
|
return -EIO;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
for (i = 0; i < n_buffers; i++) {
|
2018-07-31 12:23:35 +02:00
|
|
|
struct buffer *b = &mix->buffers[i];
|
2018-03-01 13:22:48 +01:00
|
|
|
struct pw_memblock *mem;
|
|
|
|
|
struct mem *m;
|
2019-01-25 13:28:56 +01:00
|
|
|
size_t data_size;
|
2017-11-28 18:23:44 +01:00
|
|
|
void *baseptr;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
b->outbuf = buffers[i];
|
|
|
|
|
memcpy(&b->buffer, buffers[i], sizeof(struct spa_buffer));
|
|
|
|
|
b->buffer.datas = b->datas;
|
|
|
|
|
b->buffer.metas = b->metas;
|
|
|
|
|
|
2017-11-28 18:23:44 +01:00
|
|
|
if (buffers[i]->n_metas > 0)
|
|
|
|
|
baseptr = buffers[i]->metas[0].data;
|
|
|
|
|
else if (buffers[i]->n_datas > 0)
|
|
|
|
|
baseptr = buffers[i]->datas[0].chunk;
|
|
|
|
|
else
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2018-03-01 13:22:48 +01:00
|
|
|
if ((mem = pw_memblock_find(baseptr)) == NULL)
|
2017-11-28 18:23:44 +01:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
2019-01-25 13:28:56 +01:00
|
|
|
data_size = buffers[i]->n_datas * sizeof(struct spa_chunk);
|
2017-11-28 18:23:44 +01:00
|
|
|
for (j = 0; j < buffers[i]->n_metas; j++) {
|
2019-01-24 18:28:52 +01:00
|
|
|
data_size += SPA_ROUND_UP_N(buffers[i]->metas[j].size, 8);
|
2017-11-28 18:23:44 +01:00
|
|
|
}
|
|
|
|
|
for (j = 0; j < buffers[i]->n_datas; j++) {
|
|
|
|
|
struct spa_data *d = buffers[i]->datas;
|
2018-08-23 17:47:57 +02:00
|
|
|
if (d->type == SPA_DATA_MemPtr)
|
2017-11-28 18:23:44 +01:00
|
|
|
data_size += d->maxsize;
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
m = ensure_mem(impl, mem->fd, SPA_DATA_MemFd, mem->flags);
|
2018-03-01 18:30:39 +01:00
|
|
|
b->memid = m->id;
|
2018-03-01 13:22:48 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
mb[i].buffer = &b->buffer;
|
2018-03-01 18:30:39 +01:00
|
|
|
mb[i].mem_id = b->memid;
|
2019-01-08 11:53:36 +01:00
|
|
|
mb[i].offset = SPA_PTRDIFF(baseptr, SPA_MEMBER(mem->ptr, mem->offset, void));
|
2017-11-28 18:23:44 +01:00
|
|
|
mb[i].size = data_size;
|
2019-01-25 13:28:56 +01:00
|
|
|
spa_log_debug(this->log, "buffer %d %d %d %d", i, mb[i].mem_id,
|
|
|
|
|
mb[i].offset, mb[i].size);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-28 18:23:44 +01:00
|
|
|
for (j = 0; j < buffers[i]->n_metas; j++)
|
|
|
|
|
memcpy(&b->buffer.metas[j], &buffers[i]->metas[j], sizeof(struct spa_meta));
|
|
|
|
|
b->buffer.n_metas = j;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
for (j = 0; j < buffers[i]->n_datas; j++) {
|
|
|
|
|
struct spa_data *d = &buffers[i]->datas[j];
|
|
|
|
|
|
|
|
|
|
memcpy(&b->buffer.datas[j], d, sizeof(struct spa_data));
|
|
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
if (d->type == SPA_DATA_DmaBuf ||
|
|
|
|
|
d->type == SPA_DATA_MemFd) {
|
2018-03-01 13:22:48 +01:00
|
|
|
m = ensure_mem(impl, d->fd, d->type, d->flags);
|
|
|
|
|
b->buffer.datas[j].data = SPA_UINT32_TO_PTR(m->id);
|
2018-08-23 17:47:57 +02:00
|
|
|
} else if (d->type == SPA_DATA_MemPtr) {
|
2019-01-25 13:28:56 +01:00
|
|
|
spa_log_debug(this->log, "mem %d %zd", j, SPA_PTRDIFF(d->data, baseptr));
|
|
|
|
|
b->buffer.datas[j].data = SPA_INT_TO_PTR(SPA_PTRDIFF(d->data, baseptr));
|
2017-05-26 08:05:01 +02:00
|
|
|
} else {
|
|
|
|
|
b->buffer.datas[j].type = SPA_ID_INVALID;
|
2018-04-11 10:54:47 +02:00
|
|
|
b->buffer.datas[j].data = NULL;
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_log_error(this->log, "invalid memory type %d", d->type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-18 12:31:36 +01:00
|
|
|
return pw_client_node_resource_port_use_buffers(this->resource,
|
2018-07-31 12:23:35 +02:00
|
|
|
direction, port_id, mix_id,
|
2017-11-07 17:39:31 +01:00
|
|
|
n_buffers, mb);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_use_buffers(void *object,
|
2018-07-31 12:23:35 +02:00
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
|
uint32_t n_buffers)
|
|
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2018-07-31 12:23:35 +02:00
|
|
|
struct impl *impl;
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-07-31 12:23:35 +02:00
|
|
|
|
|
|
|
|
impl = this->impl;
|
|
|
|
|
|
|
|
|
|
return do_port_use_buffers(impl, direction, port_id,
|
|
|
|
|
SPA_ID_INVALID, buffers, n_buffers);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_alloc_buffers(void *object,
|
2018-03-01 12:13:00 +01:00
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
struct spa_pod **params,
|
|
|
|
|
uint32_t n_params,
|
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
|
uint32_t *n_buffers)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2017-11-28 12:43:53 +01:00
|
|
|
struct port *port;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(buffers != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-11-09 17:07:04 +01:00
|
|
|
port = GET_PORT(this, direction, port_id);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
if (!port->have_format)
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EIO;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_log_warn(this->log, "not supported");
|
2017-11-13 09:41:41 +01:00
|
|
|
return -ENOTSUP;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_node_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
spa_return_val_if_fail(this != NULL, -EINVAL);
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(CHECK_OUT_PORT(this, SPA_DIRECTION_OUTPUT, port_id), -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-03-21 11:31:53 +01:00
|
|
|
spa_log_trace_fp(this->log, "reuse buffer %d", buffer_id);
|
2017-10-25 18:39:56 +02:00
|
|
|
|
2018-04-12 10:12:40 +02:00
|
|
|
return -ENOTSUP;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_node_process(void *object)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct node *this = object;
|
2018-05-11 10:13:37 +02:00
|
|
|
struct impl *impl = this->impl;
|
2019-02-12 17:42:33 +01:00
|
|
|
struct pw_node *n = impl->this.node;
|
|
|
|
|
struct timespec ts;
|
2019-03-07 23:01:32 +01:00
|
|
|
uint64_t cmd = 1;
|
2018-04-13 19:57:34 +02:00
|
|
|
|
2019-03-21 11:31:53 +01:00
|
|
|
spa_log_trace_fp(this->log, "%p: send process %p", this, impl->this.node->driver_node);
|
2018-05-11 10:13:37 +02:00
|
|
|
|
2019-02-12 17:42:33 +01:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
|
n->rt.activation->status = TRIGGERED;
|
2019-03-07 23:01:32 +01:00
|
|
|
n->rt.activation->signal_time = SPA_TIMESPEC_TO_NSEC(&ts);
|
2019-02-12 17:42:33 +01:00
|
|
|
|
|
|
|
|
if (write(this->writefd, &cmd, sizeof(cmd)) != sizeof(cmd))
|
|
|
|
|
spa_log_warn(this->log, "node %p: error %m", this);
|
2018-04-13 19:57:34 +02:00
|
|
|
|
2018-03-21 15:30:55 +01:00
|
|
|
return SPA_STATUS_OK;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static struct pw_node_proxy *
|
2019-03-15 20:29:34 +01:00
|
|
|
client_node_get_node(void *data,
|
|
|
|
|
uint32_t version,
|
2019-05-20 16:11:23 +02:00
|
|
|
size_t user_data_size)
|
2019-03-15 20:29:34 +01:00
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
|
|
|
|
struct node *this = &impl->node;
|
2019-05-20 16:11:23 +02:00
|
|
|
uint32_t new_id = user_data_size;
|
|
|
|
|
|
2019-03-15 20:29:34 +01:00
|
|
|
pw_log_debug("node %p: bind %u/%u", this, new_id, version);
|
2019-05-20 16:11:23 +02:00
|
|
|
|
2019-03-15 20:29:34 +01:00
|
|
|
impl->bind_node_version = version;
|
|
|
|
|
impl->bind_node_id = new_id;
|
|
|
|
|
pw_map_insert_at(&this->resource->client->objects, new_id, NULL);
|
2019-05-20 16:11:23 +02:00
|
|
|
|
|
|
|
|
return NULL;
|
2019-03-15 20:29:34 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-18 12:31:36 +01:00
|
|
|
static int
|
2017-08-04 10:18:54 +02:00
|
|
|
client_node_update(void *data,
|
2017-05-26 08:05:01 +02:00
|
|
|
uint32_t change_mask,
|
2017-11-07 17:39:31 +01:00
|
|
|
uint32_t n_params,
|
2018-06-07 10:23:41 +02:00
|
|
|
const struct spa_pod **params,
|
2019-03-04 12:30:45 +01:00
|
|
|
const struct spa_node_info *info)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-08-04 10:18:54 +02:00
|
|
|
struct impl *impl = data;
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this = &impl->node;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
if (change_mask & PW_CLIENT_NODE_UPDATE_PARAMS) {
|
2019-01-07 15:52:42 +01:00
|
|
|
uint32_t i;
|
2019-03-15 20:28:42 +01:00
|
|
|
pw_log_debug("node %p: update %d params", this, n_params);
|
2017-11-07 17:39:31 +01:00
|
|
|
|
|
|
|
|
for (i = 0; i < this->n_params; i++)
|
|
|
|
|
free(this->params[i]);
|
|
|
|
|
this->n_params = n_params;
|
2017-11-13 17:57:38 +01:00
|
|
|
this->params = realloc(this->params, this->n_params * sizeof(struct spa_pod *));
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
for (i = 0; i < this->n_params; i++)
|
2019-02-20 17:51:05 +01:00
|
|
|
this->params[i] = params[i] ? spa_pod_copy(params[i]) : NULL;
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
2019-03-04 12:30:45 +01:00
|
|
|
if (change_mask & PW_CLIENT_NODE_UPDATE_INFO) {
|
|
|
|
|
spa_node_emit_info(&this->hooks, info);
|
2018-06-07 10:23:41 +02:00
|
|
|
}
|
2019-03-15 20:28:42 +01:00
|
|
|
pw_log_debug("node %p: got node update", this);
|
2019-02-18 12:31:36 +01:00
|
|
|
return 0;
|
2017-03-02 16:06:45 +01:00
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-02-18 12:31:36 +01:00
|
|
|
static int
|
2017-08-04 10:18:54 +02:00
|
|
|
client_node_port_update(void *data,
|
2017-05-26 08:05:01 +02:00
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t change_mask,
|
|
|
|
|
uint32_t n_params,
|
2017-11-13 17:57:38 +01:00
|
|
|
const struct spa_pod **params,
|
2017-11-07 17:39:31 +01:00
|
|
|
const struct spa_port_info *info)
|
2017-03-02 16:06:45 +01:00
|
|
|
{
|
2017-08-04 10:18:54 +02:00
|
|
|
struct impl *impl = data;
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this = &impl->node;
|
2018-07-31 12:23:35 +02:00
|
|
|
struct port *port;
|
2017-05-26 08:05:01 +02:00
|
|
|
bool remove;
|
|
|
|
|
|
2018-05-10 11:23:51 +02:00
|
|
|
spa_log_debug(this->log, "node %p: got port update", this);
|
2017-05-26 08:05:01 +02:00
|
|
|
if (!CHECK_PORT_ID(this, direction, port_id))
|
2019-02-18 12:31:36 +01:00
|
|
|
return -EINVAL;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
remove = (change_mask == 0);
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
port = GET_PORT(this, direction, port_id);
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (remove) {
|
2018-07-31 12:23:35 +02:00
|
|
|
clear_port(this, port);
|
2017-05-26 08:05:01 +02:00
|
|
|
} else {
|
2018-09-24 09:33:09 +02:00
|
|
|
struct port *target;
|
2018-07-31 12:23:35 +02:00
|
|
|
|
2018-09-24 09:33:09 +02:00
|
|
|
if (port == NULL) {
|
|
|
|
|
target = &this->dummy;
|
|
|
|
|
spa_zero(this->dummy);
|
2019-03-04 12:30:45 +01:00
|
|
|
target->direction = direction;
|
|
|
|
|
target->id = port_id;
|
2019-02-14 17:08:46 +01:00
|
|
|
} else
|
2018-07-31 12:23:35 +02:00
|
|
|
target = port;
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
do_update_port(this,
|
2018-07-31 12:23:35 +02:00
|
|
|
target,
|
2017-05-26 08:05:01 +02:00
|
|
|
change_mask,
|
2019-02-14 17:08:46 +01:00
|
|
|
n_params, params,
|
|
|
|
|
info);
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2019-02-18 12:31:36 +01:00
|
|
|
return 0;
|
2017-03-02 16:06:45 +01:00
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2019-02-18 12:31:36 +01:00
|
|
|
static int client_node_set_active(void *data, bool active)
|
2017-10-13 16:18:42 +02:00
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
2019-02-18 12:31:36 +01:00
|
|
|
return pw_node_set_active(impl->this.node, active);
|
2017-10-13 16:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-28 13:51:12 +02:00
|
|
|
static int client_node_event(void *data, const struct spa_event *event)
|
2017-03-02 16:06:45 +01:00
|
|
|
{
|
2017-08-04 10:18:54 +02:00
|
|
|
struct impl *impl = data;
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this = &impl->node;
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_node_emit_event(&this->hooks, event);
|
2019-02-18 12:31:36 +01:00
|
|
|
return 0;
|
2017-03-02 16:06:45 +01:00
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
static struct pw_client_node_proxy_methods client_node_methods = {
|
|
|
|
|
PW_VERSION_CLIENT_NODE_PROXY_METHODS,
|
2019-03-15 20:29:34 +01:00
|
|
|
.get_node = client_node_get_node,
|
2017-08-04 10:18:54 +02:00
|
|
|
.update = client_node_update,
|
|
|
|
|
.port_update = client_node_port_update,
|
2017-10-13 16:18:42 +02:00
|
|
|
.set_active = client_node_set_active,
|
2017-08-04 10:18:54 +02:00
|
|
|
.event = client_node_event,
|
2017-03-02 16:06:45 +01:00
|
|
|
};
|
|
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
static void node_on_data_fd_events(struct spa_source *source)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this = source->data;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
if (source->rmask & (SPA_IO_ERR | SPA_IO_HUP)) {
|
2018-03-01 12:13:00 +01:00
|
|
|
spa_log_warn(this->log, "node %p: got error", this);
|
2017-05-26 08:05:01 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (source->rmask & SPA_IO_IN) {
|
|
|
|
|
uint64_t cmd;
|
|
|
|
|
|
2019-02-12 17:42:33 +01:00
|
|
|
if (read(this->data_source.fd, &cmd, sizeof(cmd)) != sizeof(cmd) || cmd != 1)
|
|
|
|
|
spa_log_warn(this->log, "node %p: read %"PRIu64" failed %m", this, cmd);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2019-03-21 11:31:53 +01:00
|
|
|
spa_log_trace_fp(this->log, "node %p: got ready", this);
|
2019-05-15 11:19:23 +02:00
|
|
|
spa_node_call_ready(&this->callbacks, SPA_STATUS_HAVE_BUFFER);
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
2016-07-28 21:19:20 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static const struct spa_node_methods impl_node = {
|
|
|
|
|
SPA_VERSION_NODE_METHODS,
|
2019-03-01 12:00:42 +01:00
|
|
|
.add_listener = impl_node_add_listener,
|
2019-02-18 12:31:36 +01:00
|
|
|
.set_callbacks = impl_node_set_callbacks,
|
|
|
|
|
.sync = impl_node_sync,
|
2018-07-31 12:23:35 +02:00
|
|
|
.enum_params = impl_node_enum_params,
|
|
|
|
|
.set_param = impl_node_set_param,
|
2018-10-23 12:31:41 +02:00
|
|
|
.set_io = impl_node_set_io,
|
2018-07-31 12:23:35 +02:00
|
|
|
.send_command = impl_node_send_command,
|
|
|
|
|
.add_port = impl_node_add_port,
|
|
|
|
|
.remove_port = impl_node_remove_port,
|
|
|
|
|
.port_enum_params = impl_node_port_enum_params,
|
|
|
|
|
.port_set_param = impl_node_port_set_param,
|
|
|
|
|
.port_use_buffers = impl_node_port_use_buffers,
|
|
|
|
|
.port_alloc_buffers = impl_node_port_alloc_buffers,
|
|
|
|
|
.port_set_io = impl_node_port_set_io,
|
|
|
|
|
.port_reuse_buffer = impl_node_port_reuse_buffer,
|
|
|
|
|
.process = impl_node_process,
|
2016-10-17 12:20:49 +02:00
|
|
|
};
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2018-03-01 12:13:00 +01:00
|
|
|
node_init(struct node *this,
|
2018-03-01 13:22:48 +01:00
|
|
|
struct spa_dict *info,
|
|
|
|
|
const struct spa_support *support,
|
|
|
|
|
uint32_t n_support)
|
2016-07-22 17:17:44 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < n_support; i++) {
|
2018-08-23 17:47:57 +02:00
|
|
|
switch (support[i].type) {
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_INTERFACE_Log:
|
2017-05-26 08:05:01 +02:00
|
|
|
this->log = support[i].data;
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
2018-08-27 15:03:11 +02:00
|
|
|
case SPA_TYPE_INTERFACE_DataLoop:
|
2017-05-26 08:05:01 +02:00
|
|
|
this->data_loop = support[i].data;
|
2018-08-23 17:47:57 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
|
|
|
|
if (this->data_loop == NULL) {
|
|
|
|
|
spa_log_error(this->log, "a data-loop is needed");
|
2017-11-13 09:41:41 +01:00
|
|
|
return -EINVAL;
|
2017-08-07 10:25:02 +02:00
|
|
|
}
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
this->node.iface = SPA_INTERFACE_INIT(
|
|
|
|
|
SPA_TYPE_INTERFACE_Node,
|
|
|
|
|
SPA_VERSION_NODE,
|
|
|
|
|
&impl_node, this);
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_hook_list_init(&this->hooks);
|
2019-02-20 17:51:05 +01:00
|
|
|
spa_list_init(&this->pending_list);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2019-01-31 17:50:55 +01:00
|
|
|
init_ios(this->ios);
|
|
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this->data_source.func = node_on_data_fd_events;
|
2017-05-26 08:05:01 +02:00
|
|
|
this->data_source.data = this;
|
|
|
|
|
this->data_source.fd = -1;
|
|
|
|
|
this->data_source.mask = SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP;
|
|
|
|
|
this->data_source.rmask = 0;
|
|
|
|
|
|
2019-03-15 20:28:42 +01:00
|
|
|
return SPA_RESULT_RETURN_ASYNC(0);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
static int node_clear(struct node *this)
|
2016-07-22 17:17:44 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
uint32_t i;
|
|
|
|
|
|
2019-01-31 17:50:55 +01:00
|
|
|
clear_ios(this, this->ios);
|
|
|
|
|
|
2018-04-20 16:27:19 +02:00
|
|
|
for (i = 0; i < this->n_params; i++)
|
|
|
|
|
free(this->params[i]);
|
|
|
|
|
free(this->params);
|
|
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 14:52:22 +01:00
|
|
|
static int do_remove_source(struct spa_loop *loop,
|
|
|
|
|
bool async,
|
|
|
|
|
uint32_t seq,
|
|
|
|
|
const void *data,
|
|
|
|
|
size_t size,
|
|
|
|
|
void *user_data)
|
|
|
|
|
{
|
|
|
|
|
struct spa_source *source = user_data;
|
|
|
|
|
spa_loop_remove_source(loop, source);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
static void client_node_resource_destroy(void *data)
|
2016-11-30 19:09:09 +01:00
|
|
|
{
|
2017-08-04 10:18:54 +02:00
|
|
|
struct impl *impl = data;
|
|
|
|
|
struct pw_client_node *this = &impl->this;
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *node = &impl->node;
|
2017-01-12 14:57:07 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
pw_log_debug("client-node %p: destroy", impl);
|
2017-01-20 15:53:03 +01:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
impl->node.resource = this->resource = NULL;
|
2018-05-17 17:30:30 +02:00
|
|
|
spa_hook_remove(&impl->resource_listener);
|
2017-01-20 15:53:03 +01:00
|
|
|
|
2018-03-14 14:52:22 +01:00
|
|
|
if (node->data_source.fd != -1) {
|
|
|
|
|
spa_loop_invoke(node->data_loop,
|
|
|
|
|
do_remove_source,
|
|
|
|
|
SPA_ID_INVALID,
|
|
|
|
|
NULL,
|
|
|
|
|
0,
|
|
|
|
|
true,
|
|
|
|
|
&node->data_source);
|
|
|
|
|
}
|
2017-05-26 08:05:01 +02:00
|
|
|
pw_node_destroy(this->node);
|
2017-01-12 14:57:07 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-25 16:25:27 +01:00
|
|
|
static void client_node_resource_error(void *data, int seq, int res, const char *message)
|
2019-02-18 12:31:36 +01:00
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
|
|
|
|
struct node *this = &impl->node;
|
2019-02-25 16:25:27 +01:00
|
|
|
struct spa_result_node_error result;
|
|
|
|
|
|
|
|
|
|
pw_log_error("client-node %p: error seq:%d %d (%s)", this, seq, res, message);
|
|
|
|
|
result.message = message;
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_node_emit_result(&this->hooks, seq, res, &result);
|
2019-02-18 12:31:36 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
static void client_node_resource_pong(void *data, int seq)
|
2019-02-18 12:31:36 +01:00
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
|
|
|
|
struct node *this = &impl->node;
|
2019-02-20 17:51:05 +01:00
|
|
|
|
2019-03-01 14:04:05 +01:00
|
|
|
pw_log_debug("client-node %p: got pong, emit result %d", this, seq);
|
2019-03-01 12:00:42 +01:00
|
|
|
spa_node_emit_result(&this->hooks, seq, 0, NULL);
|
2019-02-18 12:31:36 +01:00
|
|
|
}
|
|
|
|
|
|
2019-03-15 20:29:34 +01:00
|
|
|
void pw_client_node_registered(struct pw_client_node *this, struct pw_global *global)
|
2018-06-18 13:19:54 +02:00
|
|
|
{
|
|
|
|
|
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
|
2019-03-06 09:52:40 +01:00
|
|
|
struct pw_node *node = this->node;
|
2019-03-15 20:29:34 +01:00
|
|
|
uint32_t node_id = global->id;
|
2019-03-06 09:52:40 +01:00
|
|
|
struct mem *m;
|
2018-06-18 13:19:54 +02:00
|
|
|
|
2018-07-03 21:43:21 +02:00
|
|
|
pw_log_debug("client-node %p: %d", this, node_id);
|
2018-06-18 13:19:54 +02:00
|
|
|
pw_client_node_resource_transport(this->resource,
|
|
|
|
|
node_id,
|
|
|
|
|
impl->other_fds[0],
|
|
|
|
|
impl->other_fds[1]);
|
2019-03-06 09:52:40 +01:00
|
|
|
|
|
|
|
|
m = ensure_mem(impl, node->activation->fd, SPA_DATA_MemFd, node->activation->flags);
|
|
|
|
|
|
|
|
|
|
pw_client_node_resource_set_activation(this->resource,
|
|
|
|
|
node_id,
|
|
|
|
|
impl->other_fds[1],
|
|
|
|
|
m->id,
|
|
|
|
|
0,
|
|
|
|
|
sizeof(struct pw_node_activation));
|
2019-03-15 20:29:34 +01:00
|
|
|
|
|
|
|
|
if (impl->bind_node_id) {
|
|
|
|
|
pw_global_bind(global, this->resource->client, PW_PERM_RWX,
|
|
|
|
|
impl->bind_node_version, impl->bind_node_id);
|
|
|
|
|
}
|
2018-06-18 13:19:54 +02:00
|
|
|
}
|
|
|
|
|
|
2017-10-25 16:47:43 +02:00
|
|
|
static void node_initialized(void *data)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
|
|
|
|
struct pw_client_node *this = &impl->this;
|
|
|
|
|
struct pw_node *node = this->node;
|
2018-04-13 19:57:34 +02:00
|
|
|
struct pw_global *global;
|
2019-02-07 12:34:54 +01:00
|
|
|
size_t size;
|
2017-10-25 16:47:43 +02:00
|
|
|
|
|
|
|
|
if (this->resource == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
impl->fds[0] = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
|
|
|
|
|
impl->fds[1] = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
|
2018-03-01 12:13:00 +01:00
|
|
|
impl->node.data_source.fd = impl->fds[0];
|
|
|
|
|
impl->node.writefd = impl->fds[1];
|
2017-10-25 16:47:43 +02:00
|
|
|
impl->other_fds[0] = impl->fds[1];
|
|
|
|
|
impl->other_fds[1] = impl->fds[0];
|
|
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
spa_loop_add_source(impl->node.data_loop, &impl->node.data_source);
|
2017-11-30 16:36:29 +01:00
|
|
|
pw_log_debug("client-node %p: transport fd %d %d", node, impl->fds[0], impl->fds[1]);
|
2017-10-25 16:47:43 +02:00
|
|
|
|
2019-02-07 12:34:54 +01:00
|
|
|
size = sizeof(struct spa_io_buffers) * MAX_AREAS;
|
2018-05-11 10:13:37 +02:00
|
|
|
|
2018-03-01 17:39:17 +01:00
|
|
|
if (pw_memblock_alloc(PW_MEMBLOCK_FLAG_WITH_FD |
|
|
|
|
|
PW_MEMBLOCK_FLAG_MAP_READWRITE |
|
|
|
|
|
PW_MEMBLOCK_FLAG_SEAL,
|
2018-05-11 10:13:37 +02:00
|
|
|
size,
|
2018-03-01 17:39:17 +01:00
|
|
|
&impl->io_areas) < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-03-02 11:04:47 +01:00
|
|
|
pw_log_debug("client-node %p: io areas %p", node, impl->io_areas->ptr);
|
2018-03-01 17:39:17 +01:00
|
|
|
|
2018-06-18 13:19:54 +02:00
|
|
|
if ((global = pw_node_get_global(node)) != NULL)
|
2019-03-15 20:29:34 +01:00
|
|
|
pw_client_node_registered(this, global);
|
2017-10-25 16:47:43 +02:00
|
|
|
}
|
|
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
static void node_free(void *data)
|
2017-01-12 14:57:07 +01:00
|
|
|
{
|
2017-08-04 10:18:54 +02:00
|
|
|
struct impl *impl = data;
|
2017-01-12 14:57:07 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
pw_log_debug("client-node %p: free", &impl->this);
|
2018-03-01 12:13:00 +01:00
|
|
|
node_clear(&impl->node);
|
2017-01-12 14:57:07 +01:00
|
|
|
|
2017-08-08 16:56:29 +02:00
|
|
|
spa_hook_remove(&impl->node_listener);
|
2017-08-04 10:18:54 +02:00
|
|
|
|
2018-03-01 13:22:48 +01:00
|
|
|
pw_array_clear(&impl->mems);
|
2018-03-01 20:06:43 +01:00
|
|
|
if (impl->io_areas)
|
|
|
|
|
pw_memblock_free(impl->io_areas);
|
2018-03-01 13:22:48 +01:00
|
|
|
|
2018-04-20 16:27:19 +02:00
|
|
|
pw_map_clear(&impl->io_map);
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (impl->fds[0] != -1)
|
|
|
|
|
close(impl->fds[0]);
|
|
|
|
|
if (impl->fds[1] != -1)
|
|
|
|
|
close(impl->fds[1]);
|
|
|
|
|
free(impl);
|
2016-11-30 19:09:09 +01:00
|
|
|
}
|
|
|
|
|
|
2018-03-02 11:04:47 +01:00
|
|
|
static int port_init_mix(void *data, struct pw_port_mix *mix)
|
|
|
|
|
{
|
2018-07-31 12:23:35 +02:00
|
|
|
struct port *port = data;
|
|
|
|
|
struct impl *impl = port->impl;
|
|
|
|
|
struct mix *m;
|
|
|
|
|
|
|
|
|
|
if ((m = ensure_mix(impl, port, mix->port.port_id)) == NULL)
|
|
|
|
|
return -ENOMEM;
|
2018-03-02 11:04:47 +01:00
|
|
|
|
2018-03-14 20:15:42 +01:00
|
|
|
mix->id = pw_map_insert_new(&impl->io_map, NULL);
|
2018-03-02 11:04:47 +01:00
|
|
|
|
2018-04-13 20:04:22 +02:00
|
|
|
mix->io = SPA_MEMBER(impl->io_areas->ptr,
|
2018-03-14 20:15:42 +01:00
|
|
|
mix->id * sizeof(struct spa_io_buffers), void);
|
2018-04-13 20:04:22 +02:00
|
|
|
mix->io->buffer_id = SPA_ID_INVALID;
|
|
|
|
|
mix->io->status = SPA_STATUS_NEED_BUFFER;
|
2018-03-02 11:04:47 +01:00
|
|
|
|
2018-04-13 20:04:22 +02:00
|
|
|
pw_log_debug("client-node %p: init mix io %d %p %p", impl, mix->id, mix->io,
|
2018-03-14 20:15:42 +01:00
|
|
|
impl->io_areas->ptr);
|
2018-03-02 11:04:47 +01:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int port_release_mix(void *data, struct pw_port_mix *mix)
|
2018-03-01 17:39:17 +01:00
|
|
|
{
|
2018-07-31 12:23:35 +02:00
|
|
|
struct port *port = data;
|
|
|
|
|
struct impl *impl = port->impl;
|
|
|
|
|
struct node *this = &impl->node;
|
|
|
|
|
struct mix *m;
|
2018-03-02 11:04:47 +01:00
|
|
|
|
2018-04-13 20:04:22 +02:00
|
|
|
pw_log_debug("client-node %p: remove mix io %d %p %p", impl, mix->id, mix->io,
|
2018-03-14 20:15:42 +01:00
|
|
|
impl->io_areas->ptr);
|
2018-03-01 17:39:17 +01:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
if ((m = find_mix(port, mix->port.port_id)) == NULL || !m->valid)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
2018-03-14 20:15:42 +01:00
|
|
|
pw_map_remove(&impl->io_map, mix->id);
|
2018-07-31 12:23:35 +02:00
|
|
|
mix_clear(this, m);
|
2018-03-02 11:04:47 +01:00
|
|
|
return 0;
|
2018-03-01 17:39:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static const struct pw_port_implementation port_impl = {
|
|
|
|
|
PW_VERSION_PORT_IMPLEMENTATION,
|
2018-03-02 11:04:47 +01:00
|
|
|
.init_mix = port_init_mix,
|
|
|
|
|
.release_mix = port_release_mix,
|
2018-03-01 17:39:17 +01:00
|
|
|
};
|
|
|
|
|
|
2018-07-31 14:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_mix_port_enum_params(void *object, int seq,
|
2018-07-31 14:28:15 +02:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
2019-02-20 17:51:05 +01:00
|
|
|
uint32_t id, uint32_t start, uint32_t num,
|
2019-02-25 12:29:57 +01:00
|
|
|
const struct spa_pod *filter)
|
2018-07-31 14:28:15 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct port *port = object;
|
2019-02-25 12:29:57 +01:00
|
|
|
return impl_node_port_enum_params(&port->node->node, seq, direction, port->id,
|
|
|
|
|
id, start, num, filter);
|
2018-07-31 14:28:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_mix_port_set_param(void *object,
|
2018-07-31 14:28:15 +02:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t id, uint32_t flags,
|
|
|
|
|
const struct spa_pod *param)
|
|
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct port *port = object;
|
2018-07-31 14:28:15 +02:00
|
|
|
return impl_node_port_set_param(&port->node->node, direction, port->id,
|
|
|
|
|
id, flags, param);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_mix_add_port(void *object, enum spa_direction direction, uint32_t mix_id,
|
2019-02-18 13:22:46 +01:00
|
|
|
const struct spa_dict *props)
|
2018-07-31 12:23:35 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct port *port = object;
|
|
|
|
|
pw_log_debug("client-node %p: add port %d:%d.%d", object, direction, port->id, mix_id);
|
2018-07-31 12:23:35 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_mix_remove_port(void *object, enum spa_direction direction, uint32_t mix_id)
|
2018-07-31 12:23:35 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct port *port = object;
|
|
|
|
|
pw_log_debug("client-node %p: remove port %d:%d.%d", object, direction, port->id, mix_id);
|
2018-07-31 12:23:35 +02:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_mix_port_use_buffers(void *object,
|
2018-07-31 12:23:35 +02:00
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t mix_id,
|
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
|
uint32_t n_buffers)
|
|
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct port *port = object;
|
2018-07-31 12:23:35 +02:00
|
|
|
struct impl *impl = port->impl;
|
|
|
|
|
|
|
|
|
|
return do_port_use_buffers(impl, direction, port->id, mix_id, buffers, n_buffers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_mix_port_alloc_buffers(void *object,
|
2018-07-31 12:23:35 +02:00
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
struct spa_pod **params,
|
|
|
|
|
uint32_t n_params,
|
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
|
uint32_t *n_buffers)
|
|
|
|
|
{
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_mix_port_set_io(void *object,
|
2018-07-31 12:23:35 +02:00
|
|
|
enum spa_direction direction, uint32_t mix_id,
|
2018-03-01 17:39:17 +01:00
|
|
|
uint32_t id, void *data, size_t size)
|
|
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct port *p = object;
|
2018-07-31 12:23:35 +02:00
|
|
|
struct pw_port *port = p->port;
|
|
|
|
|
struct impl *impl = port->owner_data;
|
2018-03-21 18:30:41 +01:00
|
|
|
struct pw_port_mix *mix;
|
2018-03-01 17:39:17 +01:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
mix = pw_map_lookup(&port->mix_port_map, mix_id);
|
2018-03-21 18:30:41 +01:00
|
|
|
if (mix == NULL)
|
|
|
|
|
return -EIO;
|
|
|
|
|
|
2018-08-25 12:08:29 +02:00
|
|
|
if (id == SPA_IO_Buffers) {
|
2018-07-03 21:45:07 +02:00
|
|
|
if (data && size >= sizeof(struct spa_io_buffers))
|
|
|
|
|
mix->io = data;
|
|
|
|
|
else
|
|
|
|
|
mix->io = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 20:07:24 +01:00
|
|
|
return do_port_set_io(impl,
|
2018-07-31 12:23:35 +02:00
|
|
|
direction, port->port_id, mix->port.port_id,
|
2018-03-01 20:07:24 +01:00
|
|
|
id, data, size);
|
2018-03-01 17:39:17 +01:00
|
|
|
}
|
|
|
|
|
|
2018-07-31 14:28:15 +02:00
|
|
|
static int
|
2019-05-20 16:11:23 +02:00
|
|
|
impl_mix_port_reuse_buffer(void *object, uint32_t port_id, uint32_t buffer_id)
|
2018-07-31 14:28:15 +02:00
|
|
|
{
|
2019-05-20 16:11:23 +02:00
|
|
|
struct port *p = object;
|
2018-07-31 14:28:15 +02:00
|
|
|
return impl_node_port_reuse_buffer(&p->node->node, p->id, buffer_id);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static int impl_mix_process(void *object)
|
2018-03-01 17:39:17 +01:00
|
|
|
{
|
|
|
|
|
return SPA_STATUS_HAVE_BUFFER;
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
static const struct spa_node_methods impl_port_mix = {
|
|
|
|
|
SPA_VERSION_NODE_METHODS,
|
2018-07-31 14:28:15 +02:00
|
|
|
.port_enum_params = impl_mix_port_enum_params,
|
|
|
|
|
.port_set_param = impl_mix_port_set_param,
|
2018-07-31 12:23:35 +02:00
|
|
|
.add_port = impl_mix_add_port,
|
|
|
|
|
.remove_port = impl_mix_remove_port,
|
|
|
|
|
.port_use_buffers = impl_mix_port_use_buffers,
|
|
|
|
|
.port_alloc_buffers = impl_mix_port_alloc_buffers,
|
|
|
|
|
.port_set_io = impl_mix_port_set_io,
|
2018-07-31 14:28:15 +02:00
|
|
|
.port_reuse_buffer = impl_mix_port_reuse_buffer,
|
2018-07-31 12:23:35 +02:00
|
|
|
.process = impl_mix_process,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static void node_port_init(void *data, struct pw_port *port)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
2019-02-14 17:08:46 +01:00
|
|
|
struct port *p = pw_port_get_user_data(port);
|
2018-07-31 12:23:35 +02:00
|
|
|
struct node *this = &impl->node;
|
|
|
|
|
|
|
|
|
|
pw_log_debug("client-node %p: port %p init", &impl->this, port);
|
|
|
|
|
|
2019-02-14 17:08:46 +01:00
|
|
|
*p = this->dummy;
|
2018-07-31 12:23:35 +02:00
|
|
|
p->port = port;
|
2018-07-31 14:28:15 +02:00
|
|
|
p->node = this;
|
2018-07-31 12:23:35 +02:00
|
|
|
p->direction = port->direction;
|
|
|
|
|
p->id = port->port_id;
|
|
|
|
|
p->impl = impl;
|
2019-05-20 16:11:23 +02:00
|
|
|
p->mix_node.iface = SPA_INTERFACE_INIT(
|
|
|
|
|
SPA_TYPE_INTERFACE_Node,
|
|
|
|
|
SPA_VERSION_NODE,
|
|
|
|
|
&impl_port_mix, p);
|
2018-07-31 21:36:10 +02:00
|
|
|
mix_init(&p->mix[MAX_MIX], p, SPA_ID_INVALID);
|
2018-07-31 12:23:35 +02:00
|
|
|
|
2019-02-14 17:08:46 +01:00
|
|
|
if (p->direction == SPA_DIRECTION_INPUT) {
|
2018-07-31 12:23:35 +02:00
|
|
|
this->in_ports[p->id] = p;
|
2019-02-14 17:08:46 +01:00
|
|
|
this->n_inputs++;
|
|
|
|
|
} else {
|
2018-07-31 12:23:35 +02:00
|
|
|
this->out_ports[p->id] = p;
|
2019-02-14 17:08:46 +01:00
|
|
|
this->n_outputs++;
|
|
|
|
|
}
|
2018-07-31 12:23:35 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 17:39:17 +01:00
|
|
|
static void node_port_added(void *data, struct pw_port *port)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
2018-07-31 12:23:35 +02:00
|
|
|
struct port *p = pw_port_get_user_data(port);
|
2018-03-01 17:39:17 +01:00
|
|
|
|
2019-05-20 16:11:23 +02:00
|
|
|
pw_port_set_mix(port, (struct spa_node *)&p->mix_node,
|
2018-07-31 12:23:35 +02:00
|
|
|
PW_PORT_MIX_FLAG_MULTI |
|
|
|
|
|
PW_PORT_MIX_FLAG_MIX_ONLY);
|
2018-03-01 17:39:17 +01:00
|
|
|
|
2019-05-15 12:17:52 +02:00
|
|
|
port->impl = SPA_CALLBACKS_INIT(&port_impl, p);
|
2018-03-01 17:39:17 +01:00
|
|
|
port->owner_data = impl;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
static void node_port_removed(void *data, struct pw_port *port)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
|
|
|
|
struct node *this = &impl->node;
|
|
|
|
|
struct port *p = pw_port_get_user_data(port);
|
|
|
|
|
|
|
|
|
|
pw_log_debug("client-node %p: port %p remove", &impl->this, port);
|
|
|
|
|
|
2019-03-06 09:52:07 +01:00
|
|
|
p->removed = true;
|
2018-07-31 12:23:35 +02:00
|
|
|
clear_port(this, p);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-12 17:42:33 +01:00
|
|
|
static void node_peer_added(void *data, struct pw_node *peer)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
|
|
|
|
struct node *this = &impl->node;
|
|
|
|
|
struct mem *m;
|
|
|
|
|
|
|
|
|
|
if (this->resource == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
m = ensure_mem(impl, peer->activation->fd, SPA_DATA_MemFd, peer->activation->flags);
|
|
|
|
|
|
|
|
|
|
pw_log_debug("client-node %p: peer %p %u added %u", &impl->this, peer,
|
|
|
|
|
peer->info.id, m->id);
|
|
|
|
|
|
|
|
|
|
pw_client_node_resource_set_activation(this->resource,
|
|
|
|
|
peer->info.id,
|
|
|
|
|
peer->source.fd,
|
|
|
|
|
m->id,
|
|
|
|
|
0,
|
|
|
|
|
sizeof(struct pw_node_activation));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void node_peer_removed(void *data, struct pw_node *peer)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
|
|
|
|
struct node *this = &impl->node;
|
|
|
|
|
|
|
|
|
|
if (this->resource == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
pw_client_node_resource_set_activation(this->resource,
|
|
|
|
|
peer->info.id,
|
|
|
|
|
-1,
|
|
|
|
|
SPA_ID_INVALID,
|
|
|
|
|
0,
|
|
|
|
|
0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void node_driver_changed(void *data, struct pw_node *old, struct pw_node *driver)
|
|
|
|
|
{
|
|
|
|
|
node_peer_removed(data, old);
|
|
|
|
|
node_peer_added(data, driver);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
static const struct pw_node_events node_events = {
|
|
|
|
|
PW_VERSION_NODE_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.free = node_free,
|
|
|
|
|
.initialized = node_initialized,
|
2018-07-31 12:23:35 +02:00
|
|
|
.port_init = node_port_init,
|
2018-03-01 17:39:17 +01:00
|
|
|
.port_added = node_port_added,
|
2018-07-31 12:23:35 +02:00
|
|
|
.port_removed = node_port_removed,
|
2019-02-12 17:42:33 +01:00
|
|
|
.peer_added = node_peer_added,
|
|
|
|
|
.peer_removed = node_peer_removed,
|
|
|
|
|
.driver_changed = node_driver_changed,
|
2017-08-04 10:18:54 +02:00
|
|
|
};
|
|
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
static const struct pw_resource_events resource_events = {
|
|
|
|
|
PW_VERSION_RESOURCE_EVENTS,
|
2017-08-04 10:18:54 +02:00
|
|
|
.destroy = client_node_resource_destroy,
|
2019-02-18 12:31:36 +01:00
|
|
|
.error = client_node_resource_error,
|
2019-03-01 14:04:05 +01:00
|
|
|
.pong = client_node_resource_pong,
|
2017-08-04 10:18:54 +02:00
|
|
|
};
|
|
|
|
|
|
2019-03-06 20:33:55 +01:00
|
|
|
static int process_node(void *data)
|
2019-02-12 17:42:33 +01:00
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
2019-03-21 11:31:53 +01:00
|
|
|
pw_log_trace_fp("client-node %p: process", impl);
|
2019-05-20 16:11:23 +02:00
|
|
|
return spa_node_process((struct spa_node*)&impl->node.node);
|
2019-02-12 17:42:33 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-30 19:46:51 +02:00
|
|
|
/** Create a new client node
|
|
|
|
|
* \param client an owner \ref pw_client
|
|
|
|
|
* \param id an id
|
|
|
|
|
* \param name a name
|
|
|
|
|
* \param properties extra properties
|
|
|
|
|
* \return a newly allocated client node
|
2016-10-17 12:20:49 +02:00
|
|
|
*
|
2017-05-30 19:46:51 +02:00
|
|
|
* Create a new \ref pw_node.
|
2016-10-17 12:20:49 +02:00
|
|
|
*
|
2017-05-30 19:46:51 +02:00
|
|
|
* \memberof pw_client_node
|
2016-10-17 12:20:49 +02:00
|
|
|
*/
|
2017-07-11 12:24:03 +02:00
|
|
|
struct pw_client_node *pw_client_node_new(struct pw_resource *resource,
|
2018-07-03 21:43:21 +02:00
|
|
|
struct pw_global *parent,
|
2018-04-13 20:05:46 +02:00
|
|
|
struct pw_properties *properties,
|
|
|
|
|
bool do_register)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-26 08:05:01 +02:00
|
|
|
struct impl *impl;
|
|
|
|
|
struct pw_client_node *this;
|
2017-08-08 15:01:36 +02:00
|
|
|
struct pw_client *client = pw_resource_get_client(resource);
|
|
|
|
|
struct pw_core *core = pw_client_get_core(client);
|
|
|
|
|
const struct spa_support *support;
|
|
|
|
|
uint32_t n_support;
|
2018-02-09 18:10:51 +01:00
|
|
|
const char *name;
|
2016-12-22 16:50:01 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
impl = calloc(1, sizeof(struct impl));
|
|
|
|
|
if (impl == NULL)
|
|
|
|
|
return NULL;
|
2017-01-12 14:57:07 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
this = &impl->this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
impl->core = core;
|
2017-05-26 08:05:01 +02:00
|
|
|
impl->fds[0] = impl->fds[1] = -1;
|
|
|
|
|
pw_log_debug("client-node %p: new", impl);
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2018-07-12 15:33:07 +02:00
|
|
|
support = pw_core_get_support(impl->core, &n_support);
|
2018-03-01 12:13:00 +01:00
|
|
|
node_init(&impl->node, NULL, support, n_support);
|
|
|
|
|
impl->node.impl = impl;
|
2019-02-20 17:51:05 +01:00
|
|
|
impl->node.resource = resource;
|
|
|
|
|
this->flags = do_register ? 0 : 1;
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2018-03-02 11:04:47 +01:00
|
|
|
pw_map_init(&impl->io_map, 64, 64);
|
2018-03-01 13:22:48 +01:00
|
|
|
pw_array_init(&impl->mems, 64);
|
|
|
|
|
|
2019-05-24 15:47:48 +02:00
|
|
|
if ((name = pw_properties_get(properties, PW_KEY_NODE_NAME)) == NULL)
|
2018-02-09 18:10:51 +01:00
|
|
|
name = "client-node";
|
|
|
|
|
|
2017-07-11 12:24:03 +02:00
|
|
|
this->resource = resource;
|
2018-07-03 21:43:21 +02:00
|
|
|
this->parent = parent;
|
2017-07-11 12:24:03 +02:00
|
|
|
this->node = pw_spa_node_new(core,
|
2017-09-18 11:54:25 +02:00
|
|
|
pw_resource_get_client(this->resource),
|
2018-07-03 21:43:21 +02:00
|
|
|
parent,
|
2017-07-07 17:55:26 +02:00
|
|
|
name,
|
2019-03-15 20:28:42 +01:00
|
|
|
PW_SPA_NODE_FLAG_ASYNC |
|
2018-04-13 20:05:46 +02:00
|
|
|
(do_register ? 0 : PW_SPA_NODE_FLAG_NO_REGISTER),
|
2019-05-20 16:11:23 +02:00
|
|
|
(struct spa_node *)&impl->node.node,
|
2017-07-07 17:55:26 +02:00
|
|
|
NULL,
|
2017-08-22 18:30:10 +02:00
|
|
|
properties, 0);
|
2017-06-21 09:03:29 +02:00
|
|
|
if (this->node == NULL)
|
|
|
|
|
goto error_no_node;
|
|
|
|
|
|
2018-03-21 15:30:55 +01:00
|
|
|
this->node->remote = true;
|
2019-02-20 17:51:05 +01:00
|
|
|
this->flags = 0;
|
2018-03-21 15:30:55 +01:00
|
|
|
|
2019-03-06 20:33:55 +01:00
|
|
|
this->node->rt.target.signal = process_node;
|
|
|
|
|
this->node->rt.target.data = impl;
|
2019-02-12 17:42:33 +01:00
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
pw_resource_add_listener(this->resource,
|
|
|
|
|
&impl->resource_listener,
|
|
|
|
|
&resource_events,
|
|
|
|
|
impl);
|
2017-06-15 17:54:55 +02:00
|
|
|
pw_resource_set_implementation(this->resource,
|
2017-08-04 10:18:54 +02:00
|
|
|
&client_node_methods,
|
|
|
|
|
impl);
|
2017-06-15 17:54:55 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
this->node->port_user_data_size = sizeof(struct port);
|
2017-01-12 14:57:07 +01:00
|
|
|
|
2017-08-04 16:49:13 +02:00
|
|
|
pw_node_add_listener(this->node, &impl->node_listener, &node_events, impl);
|
2017-01-10 17:12:53 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
return this;
|
2017-01-10 17:12:53 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
error_no_node:
|
2017-06-21 09:03:29 +02:00
|
|
|
pw_resource_destroy(this->resource);
|
2018-03-01 12:13:00 +01:00
|
|
|
node_clear(&impl->node);
|
2017-05-26 08:05:01 +02:00
|
|
|
free(impl);
|
|
|
|
|
return NULL;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-01 19:25:01 +02:00
|
|
|
/** Destroy a client node
|
|
|
|
|
* \param node the client node to destroy
|
|
|
|
|
* \memberof pw_client_node
|
|
|
|
|
*/
|
|
|
|
|
void pw_client_node_destroy(struct pw_client_node *node)
|
2016-11-15 17:06:09 +01:00
|
|
|
{
|
2017-06-01 19:25:01 +02:00
|
|
|
pw_resource_destroy(node->resource);
|
2016-11-15 17:06:09 +01:00
|
|
|
}
|