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>
|
|
|
|
|
#include <fcntl.h>
|
2016-08-02 16:34:44 +02:00
|
|
|
#include <dlfcn.h>
|
2016-10-17 12:20:49 +02:00
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <sys/mman.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>
|
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
|
|
|
|
|
|
|
|
bool have_format;
|
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
|
|
|
|
2017-06-14 18:32:39 +02:00
|
|
|
const struct spa_node_callbacks *callbacks;
|
2017-08-06 06:42:26 +02:00
|
|
|
void *callbacks_data;
|
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 max_inputs;
|
|
|
|
|
uint32_t n_inputs;
|
|
|
|
|
uint32_t max_outputs;
|
|
|
|
|
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;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
uint32_t seq;
|
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;
|
|
|
|
|
|
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;
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
int fds[2];
|
|
|
|
|
int other_fds[2];
|
2018-05-11 10:13:37 +02:00
|
|
|
|
2018-10-24 10:33:52 +02:00
|
|
|
struct spa_io_position *position;
|
2017-04-12 10:40:17 +02:00
|
|
|
};
|
2016-10-17 12:20:49 +02:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 21:36:10 +02:00
|
|
|
static void mix_init(struct mix *mix, struct port *p, uint32_t id)
|
2018-07-31 12:23:35 +02:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
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;
|
|
|
|
|
for (i = 0; i < MAX_IO; i++)
|
|
|
|
|
mix->ios[i].id = SPA_ID_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-21 18:30:41 +01:00
|
|
|
static struct io *update_io(struct impl *impl, struct port *port,
|
2018-07-31 12:23:35 +02:00
|
|
|
struct mix *mix, uint32_t id, uint32_t memid)
|
2018-03-21 09:20:40 +01:00
|
|
|
{
|
2018-09-28 05:49:38 +02:00
|
|
|
struct node *this = &impl->node;
|
2018-03-21 09:20:40 +01:00
|
|
|
int i;
|
|
|
|
|
struct io *io, *f = NULL;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_IO; i++) {
|
2018-07-31 12:23:35 +02:00
|
|
|
io = &mix->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;
|
2018-09-28 05:49:38 +02:00
|
|
|
spa_log_debug(this->log, "node %p: add io %p %d %d", this, io, id, memid);
|
2018-03-21 09:20:40 +01:00
|
|
|
|
|
|
|
|
found:
|
|
|
|
|
return io;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
static void clear_ios(struct node *this, struct mix *mix)
|
2018-03-21 09:20:40 +01:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_IO; i++) {
|
2018-07-31 12:23:35 +02:00
|
|
|
struct io *io = &mix->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);
|
2018-07-31 12:23:35 +02:00
|
|
|
clear_ios(this, mix);
|
2018-07-31 21:36:10 +02:00
|
|
|
mix->valid = false;
|
2018-07-31 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
static int impl_node_enum_params(struct spa_node *node,
|
|
|
|
|
uint32_t id, uint32_t *index,
|
|
|
|
|
const struct spa_pod *filter,
|
|
|
|
|
struct spa_pod **result,
|
|
|
|
|
struct spa_pod_builder *builder)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(index != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(builder != NULL, -EINVAL);
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
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
|
|
|
|
|
|
|
|
if (*index >= this->n_params)
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
|
|
|
|
param = this->params[(*index)++];
|
|
|
|
|
|
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;
|
|
|
|
|
|
2017-11-13 17:57:38 +01:00
|
|
|
if (spa_pod_filter(builder, result, param, filter) == 0)
|
2017-11-07 17:39:31 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2017-11-13 09:41:41 +01:00
|
|
|
return 1;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,
|
|
|
|
|
const struct spa_pod *param)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2017-11-07 17:39:31 +01:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2017-11-07 17:39:31 +01:00
|
|
|
|
|
|
|
|
if (this->resource == NULL)
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-11-07 17:39:31 +01:00
|
|
|
|
|
|
|
|
pw_client_node_resource_set_param(this->resource, this->seq, id, flags, param);
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_RETURN_ASYNC(this->seq++);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-10-23 12:31:41 +02:00
|
|
|
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
|
|
|
|
|
{
|
|
|
|
|
struct node *this;
|
|
|
|
|
|
|
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
|
|
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
|
|
|
|
|
|
|
|
|
if (this->resource == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
static int impl_node_send_command(struct spa_node *node, const struct spa_command *command)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2017-11-13 09:41:41 +01:00
|
|
|
int res = 0;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(command != NULL, -EINVAL);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
if (this->resource == NULL)
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-07-12 13:22:50 +02:00
|
|
|
pw_client_node_resource_command(this->resource, this->seq, command);
|
|
|
|
|
res = SPA_RESULT_RETURN_ASYNC(this->seq++);
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
return res;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2018-03-01 12:13:00 +01:00
|
|
|
impl_node_set_callbacks(struct spa_node *node,
|
|
|
|
|
const struct spa_node_callbacks *callbacks,
|
|
|
|
|
void *data)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2017-06-14 18:32:39 +02:00
|
|
|
this->callbacks = callbacks;
|
2017-08-06 06:42:26 +02:00
|
|
|
this->callbacks_data = data;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2018-03-01 12:13:00 +01:00
|
|
|
impl_node_get_n_ports(struct spa_node *node,
|
|
|
|
|
uint32_t *n_input_ports,
|
|
|
|
|
uint32_t *max_input_ports,
|
|
|
|
|
uint32_t *n_output_ports,
|
|
|
|
|
uint32_t *max_output_ports)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
if (n_input_ports)
|
|
|
|
|
*n_input_ports = this->n_inputs;
|
|
|
|
|
if (max_input_ports)
|
2017-07-25 19:52:31 +02:00
|
|
|
*max_input_ports = this->max_inputs == 0 ? this->n_inputs : this->max_inputs;
|
2017-05-26 08:05:01 +02:00
|
|
|
if (n_output_ports)
|
|
|
|
|
*n_output_ports = this->n_outputs;
|
|
|
|
|
if (max_output_ports)
|
2017-07-25 19:52:31 +02:00
|
|
|
*max_output_ports = this->max_outputs == 0 ? this->n_outputs : this->max_outputs;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2018-03-01 12:13:00 +01:00
|
|
|
impl_node_get_port_ids(struct spa_node *node,
|
|
|
|
|
uint32_t *input_ids,
|
|
|
|
|
uint32_t n_input_ids,
|
|
|
|
|
uint32_t *output_ids,
|
|
|
|
|
uint32_t n_output_ids)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2019-01-07 15:52:42 +01:00
|
|
|
uint32_t c, i;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
if (input_ids) {
|
2017-11-20 15:26:44 +01:00
|
|
|
for (c = 0, i = 0; i < MAX_INPUTS && c < n_input_ids; i++) {
|
2018-07-31 12:23:35 +02:00
|
|
|
if (this->in_ports[i])
|
2017-05-26 08:05:01 +02:00
|
|
|
input_ids[c++] = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (output_ids) {
|
2017-11-20 15:26:44 +01:00
|
|
|
for (c = 0, i = 0; i < MAX_OUTPUTS && c < n_output_ids; i++) {
|
2018-07-31 12:23:35 +02:00
|
|
|
if (this->out_ports[i])
|
2017-05-26 08:05:01 +02:00
|
|
|
output_ids[c++] = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
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-01-07 15:36:19 +01:00
|
|
|
port->params[i] = params[i] ? pw_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;
|
|
|
|
|
|
|
|
|
|
if (info) {
|
|
|
|
|
port->info = *info;
|
|
|
|
|
if (info->props) {
|
|
|
|
|
port->properties = pw_properties_new_dict(info->props);
|
|
|
|
|
port->info.props = &port->properties->dict;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
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)
|
|
|
|
|
return ;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2018-03-01 12:13:00 +01:00
|
|
|
impl_node_add_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
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
|
|
|
|
2018-04-13 20:02:35 +02:00
|
|
|
pw_client_node_resource_add_port(this->resource,
|
|
|
|
|
this->seq,
|
|
|
|
|
direction, port_id);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-04-13 20:02:35 +02:00
|
|
|
return SPA_RESULT_RETURN_ASYNC(this->seq++);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2018-03-01 12:13:00 +01:00
|
|
|
impl_node_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t port_id)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
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
|
|
|
|
2018-04-13 20:02:35 +02:00
|
|
|
pw_client_node_resource_remove_port(this->resource,
|
|
|
|
|
this->seq,
|
|
|
|
|
direction, port_id);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-04-13 20:02:35 +02:00
|
|
|
return SPA_RESULT_RETURN_ASYNC(this->seq++);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2018-03-01 12:13:00 +01:00
|
|
|
impl_node_port_get_info(struct spa_node *node,
|
2018-03-01 13:22:48 +01:00
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
const struct spa_port_info **info)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2017-11-28 12:43:53 +01:00
|
|
|
struct port *port;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(info != NULL, -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
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-09 17:07:04 +01:00
|
|
|
port = GET_PORT(this, direction, port_id);
|
2017-11-07 17:39:31 +01:00
|
|
|
*info = &port->info;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2018-03-01 12:13:00 +01:00
|
|
|
impl_node_port_enum_params(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t id, uint32_t *index,
|
|
|
|
|
const struct spa_pod *filter,
|
|
|
|
|
struct spa_pod **result,
|
|
|
|
|
struct spa_pod_builder *builder)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2017-11-28 12:43:53 +01:00
|
|
|
struct port *port;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-11-13 09:41:41 +01:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(index != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(builder != NULL, -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
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
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
pw_log_debug("client-node %p: port %d.%d", this,
|
|
|
|
|
direction, port_id);
|
|
|
|
|
|
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
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
if (*index >= port->n_params)
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
param = port->params[(*index)++];
|
|
|
|
|
|
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;
|
|
|
|
|
|
2017-11-13 17:57:38 +01:00
|
|
|
if (spa_pod_filter(builder, result, param, filter) == 0)
|
2017-11-07 17:39:31 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2017-11-13 09:41:41 +01:00
|
|
|
return 1;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2018-03-01 12:13:00 +01:00
|
|
|
impl_node_port_set_param(struct spa_node *node,
|
|
|
|
|
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
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
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)
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
2017-05-22 13:06:18 +02:00
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
pw_client_node_resource_port_set_param(this->resource,
|
|
|
|
|
this->seq,
|
|
|
|
|
direction, port_id,
|
|
|
|
|
id, flags,
|
|
|
|
|
param);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
return SPA_RESULT_RETURN_ASYNC(this->seq++);
|
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)
|
|
|
|
|
return 0;
|
|
|
|
|
|
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
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
update_io(impl, port, mix, id, memid);
|
2018-03-01 20:07:24 +01:00
|
|
|
|
|
|
|
|
pw_client_node_resource_port_set_io(this->resource,
|
|
|
|
|
this->seq,
|
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);
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_RETURN_ASYNC(this->seq++);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2018-03-01 12:13:00 +01:00
|
|
|
impl_node_port_set_io(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
void *data, size_t size)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
2018-07-03 21:45:07 +02:00
|
|
|
struct node *this;
|
|
|
|
|
struct impl *impl;
|
|
|
|
|
|
|
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
|
|
|
|
impl = this->impl;
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
return do_port_set_io(impl, direction, port_id, SPA_ID_INVALID, id, data, size);
|
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)
|
2017-11-13 09:41:41 +01:00
|
|
|
return 0;
|
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;
|
2017-12-01 17:24:03 +01:00
|
|
|
size_t data_size, 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;
|
|
|
|
|
|
|
|
|
|
data_size = 0;
|
|
|
|
|
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;
|
|
|
|
|
data_size += sizeof(struct spa_chunk);
|
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;
|
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
|
|
|
|
2018-04-13 20:03:14 +02:00
|
|
|
size = buffers[i]->n_datas * sizeof(struct spa_chunk);
|
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) {
|
2017-12-01 17:24:03 +01:00
|
|
|
b->buffer.datas[j].data = SPA_INT_TO_PTR(size);
|
|
|
|
|
size += d->maxsize;
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 17:39:31 +01:00
|
|
|
pw_client_node_resource_port_use_buffers(this->resource,
|
|
|
|
|
this->seq,
|
2018-07-31 12:23:35 +02:00
|
|
|
direction, port_id, mix_id,
|
2017-11-07 17:39:31 +01:00
|
|
|
n_buffers, mb);
|
2017-05-26 08:05:01 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_RETURN_ASYNC(this->seq++);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
static int
|
|
|
|
|
impl_node_port_use_buffers(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
|
uint32_t n_buffers)
|
|
|
|
|
{
|
|
|
|
|
struct node *this;
|
|
|
|
|
struct impl *impl;
|
|
|
|
|
|
|
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
|
|
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
|
|
|
|
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
|
2018-03-01 12:13:00 +01:00
|
|
|
impl_node_port_alloc_buffers(struct spa_node *node,
|
|
|
|
|
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
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2017-11-28 12:43:53 +01:00
|
|
|
struct port *port;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(buffers != NULL, -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
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-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
|
2018-03-01 12:13:00 +01:00
|
|
|
impl_node_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
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
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
spa_log_trace(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
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2018-03-01 12:13:00 +01:00
|
|
|
impl_node_port_send_command(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id, const struct spa_command *command)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
spa_return_val_if_fail(node != NULL, -EINVAL);
|
|
|
|
|
spa_return_val_if_fail(command != NULL, -EINVAL);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this = SPA_CONTAINER_OF(node, struct node, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-11-14 15:44:48 +01:00
|
|
|
if (this->resource == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
spa_log_trace(this->log, "send command %s",
|
2018-08-30 12:01:52 +02:00
|
|
|
spa_debug_type_find_name(spa_type_node_command_id, SPA_NODE_COMMAND_ID(command)));
|
2017-11-14 15:44:48 +01:00
|
|
|
|
|
|
|
|
pw_client_node_resource_port_command(this->resource,
|
|
|
|
|
direction, port_id,
|
|
|
|
|
command);
|
|
|
|
|
return 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-16 16:55:25 +01:00
|
|
|
static int impl_node_process(struct spa_node *node)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
2018-03-01 12:13:00 +01:00
|
|
|
struct node *this = SPA_CONTAINER_OF(node, struct node, node);
|
2018-05-11 10:13:37 +02:00
|
|
|
struct impl *impl = this->impl;
|
2018-10-24 10:33:52 +02:00
|
|
|
struct spa_io_position *q, *rq;
|
2018-04-13 19:57:34 +02:00
|
|
|
uint64_t cmd = 1;
|
|
|
|
|
|
2018-05-11 10:13:37 +02:00
|
|
|
spa_log_trace(this->log, "%p: send process %p", this, impl->this.node->driver_node);
|
|
|
|
|
|
2018-10-24 10:33:52 +02:00
|
|
|
q = impl->this.node->driver_node->rt.position;
|
|
|
|
|
rq = impl->position;
|
2018-06-07 11:01:20 +02:00
|
|
|
*rq = *q;
|
2018-04-13 19:57:34 +02:00
|
|
|
|
|
|
|
|
if (write(this->writefd, &cmd, 8) != 8)
|
|
|
|
|
spa_log_warn(this->log, "node %p: error %s", this, strerror(errno));
|
|
|
|
|
|
2018-03-21 15:30:55 +01:00
|
|
|
return SPA_STATUS_OK;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-06-09 17:24:18 +02:00
|
|
|
static void
|
2017-08-04 10:18:54 +02:00
|
|
|
client_node_done(void *data, int seq, int res)
|
2017-06-09 17:24:18 +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-06-09 17:24:18 +02:00
|
|
|
|
2017-08-06 06:42:26 +02:00
|
|
|
this->callbacks->done(this->callbacks_data, seq, res);
|
2017-06-09 17:24:18 +02:00
|
|
|
}
|
|
|
|
|
|
2017-03-02 16:06:45 +01:00
|
|
|
static void
|
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,
|
|
|
|
|
uint32_t max_input_ports,
|
2017-11-07 17:39:31 +01:00
|
|
|
uint32_t max_output_ports,
|
|
|
|
|
uint32_t n_params,
|
2018-06-07 10:23:41 +02:00
|
|
|
const struct spa_pod **params,
|
|
|
|
|
const struct spa_dict *props)
|
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-05-30 20:33:32 +02:00
|
|
|
if (change_mask & PW_CLIENT_NODE_UPDATE_MAX_INPUTS)
|
2017-05-26 08:05:01 +02:00
|
|
|
this->max_inputs = max_input_ports;
|
2017-05-30 20:33:32 +02:00
|
|
|
if (change_mask & PW_CLIENT_NODE_UPDATE_MAX_OUTPUTS)
|
2017-05-26 08:05:01 +02:00
|
|
|
this->max_outputs = max_output_ports;
|
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;
|
2018-05-10 11:23:51 +02:00
|
|
|
spa_log_debug(this->log, "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-01-07 15:36:19 +01:00
|
|
|
this->params[i] = params[i] ? pw_spa_pod_copy(params[i]) : NULL;
|
2017-11-07 17:39:31 +01:00
|
|
|
}
|
2018-06-07 10:23:41 +02:00
|
|
|
if (change_mask & PW_CLIENT_NODE_UPDATE_PROPS) {
|
|
|
|
|
pw_node_update_properties(impl->this.node, props);
|
|
|
|
|
}
|
2018-05-10 11:23:51 +02:00
|
|
|
spa_log_debug(this->log, "node %p: got node update max_in %u, max_out %u", this,
|
2017-05-26 08:05:01 +02:00
|
|
|
this->max_inputs, this->max_outputs);
|
2017-03-02 16:06:45 +01:00
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-03-02 16:06:45 +01:00
|
|
|
static void
|
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))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
pw_node_update_ports(impl->this.node);
|
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);
|
2018-10-08 13:00:18 +02:00
|
|
|
target->id = port_id;
|
2018-09-24 09:33:09 +02:00
|
|
|
}
|
2018-07-31 12:23:35 +02:00
|
|
|
else
|
|
|
|
|
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,
|
2017-11-07 17:39:31 +01:00
|
|
|
n_params, params, info);
|
2018-07-31 12:23:35 +02:00
|
|
|
|
|
|
|
|
if (port == NULL) {
|
|
|
|
|
if (direction == SPA_DIRECTION_INPUT) {
|
|
|
|
|
this->n_inputs++;
|
2018-09-24 09:33:09 +02:00
|
|
|
this->in_ports[port_id] = target;
|
2018-07-31 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this->n_outputs++;
|
2018-09-24 09:33:09 +02:00
|
|
|
this->out_ports[port_id] = target;
|
2018-07-31 12:23:35 +02:00
|
|
|
}
|
|
|
|
|
pw_node_update_ports(impl->this.node);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
}
|
2017-03-02 16:06:45 +01:00
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-10-13 16:18:42 +02:00
|
|
|
static void client_node_set_active(void *data, bool active)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = data;
|
|
|
|
|
pw_node_set_active(impl->this.node, active);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-04 10:18:54 +02:00
|
|
|
static void client_node_event(void *data, 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;
|
2017-08-06 06:42:26 +02:00
|
|
|
this->callbacks->event(this->callbacks_data, event);
|
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,
|
2017-08-04 10:18:54 +02:00
|
|
|
.done = client_node_done,
|
|
|
|
|
.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;
|
|
|
|
|
|
2017-09-07 10:22:32 +02:00
|
|
|
if (read(this->data_source.fd, &cmd, sizeof(uint64_t)) != sizeof(uint64_t))
|
2018-03-01 12:13:00 +01:00
|
|
|
spa_log_warn(this->log, "node %p: error reading message: %s",
|
2017-07-04 12:21:01 +02:00
|
|
|
this, strerror(errno));
|
2017-05-26 08:05:01 +02:00
|
|
|
|
2018-03-21 15:30:55 +01:00
|
|
|
spa_log_trace(this->log, "node %p: got process", this);
|
2018-03-20 11:37:11 +01:00
|
|
|
this->callbacks->process(this->callbacks_data, 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
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
static const struct spa_node impl_node = {
|
2017-06-14 18:32:39 +02:00
|
|
|
SPA_VERSION_NODE,
|
2017-05-26 08:05:01 +02:00
|
|
|
NULL,
|
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,
|
|
|
|
|
.set_callbacks = impl_node_set_callbacks,
|
|
|
|
|
.get_n_ports = impl_node_get_n_ports,
|
|
|
|
|
.get_port_ids = impl_node_get_port_ids,
|
|
|
|
|
.add_port = impl_node_add_port,
|
|
|
|
|
.remove_port = impl_node_remove_port,
|
|
|
|
|
.port_get_info = impl_node_port_get_info,
|
|
|
|
|
.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,
|
|
|
|
|
.port_send_command = impl_node_port_send_command,
|
|
|
|
|
.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
|
|
|
|
2018-03-01 12:13:00 +01:00
|
|
|
this->node = impl_node;
|
2017-05-26 08:05:01 +02:00
|
|
|
|
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;
|
|
|
|
|
|
2018-03-08 11:04:29 +01:00
|
|
|
this->seq = 1;
|
|
|
|
|
|
2017-05-26 08:05:01 +02:00
|
|
|
return SPA_RESULT_RETURN_ASYNC(this->seq++);
|
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;
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2018-06-18 13:19:54 +02:00
|
|
|
void pw_client_node_registered(struct pw_client_node *this, uint32_t node_id)
|
|
|
|
|
{
|
|
|
|
|
struct impl *impl = SPA_CONTAINER_OF(this, struct impl, this);
|
|
|
|
|
|
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]);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
2018-05-11 10:13:37 +02:00
|
|
|
uint32_t area_size, size;
|
|
|
|
|
struct mem *m;
|
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
|
|
|
|
2018-05-11 10:13:37 +02:00
|
|
|
area_size = sizeof(struct spa_io_buffers) * MAX_AREAS;
|
2018-10-24 10:33:52 +02:00
|
|
|
size = area_size + sizeof(struct spa_io_position);
|
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-05-11 10:13:37 +02:00
|
|
|
impl->position = SPA_MEMBER(impl->io_areas->ptr,
|
2018-10-24 10:33:52 +02:00
|
|
|
area_size, struct spa_io_position);
|
2018-05-11 10:13:37 +02:00
|
|
|
|
2018-08-23 17:47:57 +02:00
|
|
|
m = ensure_mem(impl, impl->io_areas->fd, SPA_DATA_MemFd, impl->io_areas->flags);
|
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-07-12 15:33:07 +02:00
|
|
|
pw_client_node_resource_set_io(this->resource,
|
2018-10-24 10:33:52 +02:00
|
|
|
SPA_IO_Position,
|
2018-07-12 15:33:07 +02:00
|
|
|
m->id,
|
|
|
|
|
area_size,
|
2018-10-24 10:33:52 +02:00
|
|
|
sizeof(struct spa_io_position));
|
2018-06-18 13:19:54 +02:00
|
|
|
|
|
|
|
|
if ((global = pw_node_get_global(node)) != NULL)
|
|
|
|
|
pw_client_node_registered(this, pw_global_get_id(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
|
|
|
|
|
impl_mix_port_enum_params(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t id, uint32_t *index,
|
|
|
|
|
const struct spa_pod *filter,
|
|
|
|
|
struct spa_pod **result,
|
|
|
|
|
struct spa_pod_builder *builder)
|
|
|
|
|
{
|
|
|
|
|
struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node);
|
|
|
|
|
return impl_node_port_enum_params(&port->node->node, direction, port->id,
|
|
|
|
|
id, index, filter, result, builder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
impl_mix_port_set_param(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction, uint32_t port_id,
|
|
|
|
|
uint32_t id, uint32_t flags,
|
|
|
|
|
const struct spa_pod *param)
|
|
|
|
|
{
|
|
|
|
|
struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node);
|
|
|
|
|
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
|
|
|
|
|
impl_mix_add_port(struct spa_node *node, enum spa_direction direction, uint32_t mix_id)
|
|
|
|
|
{
|
2018-07-31 14:28:15 +02:00
|
|
|
struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node);
|
2018-07-31 12:23:35 +02:00
|
|
|
pw_log_debug("client-node %p: add port %d:%d.%d", node, direction, port->id, mix_id);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
impl_mix_remove_port(struct spa_node *node, enum spa_direction direction, uint32_t mix_id)
|
|
|
|
|
{
|
2018-07-31 14:28:15 +02:00
|
|
|
struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node);
|
2018-07-31 12:23:35 +02:00
|
|
|
pw_log_debug("client-node %p: remove port %d:%d.%d", node, direction, port->id, mix_id);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
impl_mix_port_use_buffers(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t mix_id,
|
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
|
uint32_t n_buffers)
|
|
|
|
|
{
|
2018-07-31 14:28:15 +02:00
|
|
|
struct port *port = SPA_CONTAINER_OF(node, struct port, mix_node);
|
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
|
|
|
|
|
impl_mix_port_alloc_buffers(struct spa_node *node,
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int impl_mix_port_set_io(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction, uint32_t mix_id,
|
2018-03-01 17:39:17 +01:00
|
|
|
uint32_t id, void *data, size_t size)
|
|
|
|
|
{
|
2018-07-31 14:28:15 +02:00
|
|
|
struct port *p = SPA_CONTAINER_OF(node, struct port, mix_node);
|
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
|
|
|
|
|
impl_mix_port_reuse_buffer(struct spa_node *node, uint32_t port_id, uint32_t buffer_id)
|
|
|
|
|
{
|
|
|
|
|
struct port *p = SPA_CONTAINER_OF(node, struct port, mix_node);
|
|
|
|
|
return impl_node_port_reuse_buffer(&p->node->node, p->id, buffer_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
impl_mix_port_send_command(struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id, const struct spa_command *command)
|
|
|
|
|
{
|
|
|
|
|
struct port *p = SPA_CONTAINER_OF(node, struct port, mix_node);
|
|
|
|
|
return impl_node_port_send_command(&p->node->node, direction, p->id, command);
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
static int impl_mix_process(struct spa_node *data)
|
2018-03-01 17:39:17 +01:00
|
|
|
{
|
|
|
|
|
return SPA_STATUS_HAVE_BUFFER;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-31 12:23:35 +02:00
|
|
|
static const struct spa_node impl_port_mix = {
|
|
|
|
|
SPA_VERSION_NODE,
|
|
|
|
|
NULL,
|
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,
|
|
|
|
|
.port_send_command = impl_mix_port_send_command,
|
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;
|
|
|
|
|
struct port *p = pw_port_get_user_data(port), *dummy;
|
|
|
|
|
struct node *this = &impl->node;
|
|
|
|
|
|
|
|
|
|
pw_log_debug("client-node %p: port %p init", &impl->this, port);
|
|
|
|
|
|
|
|
|
|
if (port->direction == PW_DIRECTION_INPUT)
|
|
|
|
|
dummy = this->in_ports[port->port_id];
|
|
|
|
|
else
|
|
|
|
|
dummy = this->out_ports[port->port_id];
|
|
|
|
|
|
|
|
|
|
*p = *dummy;
|
|
|
|
|
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;
|
2018-07-31 14:28:15 +02:00
|
|
|
p->mix_node = impl_port_mix;
|
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
|
|
|
|
|
|
|
|
if (p->direction == SPA_DIRECTION_INPUT)
|
|
|
|
|
this->in_ports[p->id] = p;
|
|
|
|
|
else
|
|
|
|
|
this->out_ports[p->id] = p;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2018-07-31 14:28:15 +02:00
|
|
|
pw_port_set_mix(port, &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
|
|
|
|
|
|
|
|
port->implementation = &port_impl;
|
2018-07-31 12:23:35 +02:00
|
|
|
port->implementation_data = 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);
|
|
|
|
|
|
|
|
|
|
clear_port(this, p);
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
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,
|
|
|
|
|
};
|
|
|
|
|
|
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;
|
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);
|
|
|
|
|
|
2018-02-09 18:10:51 +01:00
|
|
|
if ((name = pw_properties_get(properties, "node.name")) == NULL)
|
|
|
|
|
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,
|
2018-04-13 20:05:46 +02:00
|
|
|
PW_SPA_NODE_FLAG_ASYNC |
|
|
|
|
|
(do_register ? 0 : PW_SPA_NODE_FLAG_NO_REGISTER),
|
2018-03-01 12:13:00 +01:00
|
|
|
&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;
|
|
|
|
|
|
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-03-01 12:13:00 +01:00
|
|
|
impl->node.resource = this->resource;
|
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
|
|
|
}
|