2017-05-23 19:15:33 +02:00
|
|
|
/* PipeWire
|
2016-07-22 17:17:44 +02:00
|
|
|
* Copyright (C) 2015 Wim Taymans <wim.taymans@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <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-05-16 09:20:42 +02:00
|
|
|
#include "spa/node.h"
|
|
|
|
|
#include "spa/format-builder.h"
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
#include "pipewire/client/pipewire.h"
|
|
|
|
|
#include "pipewire/client/interfaces.h"
|
|
|
|
|
#include "pipewire/client/transport.h"
|
|
|
|
|
|
|
|
|
|
#include "pipewire/server/core.h"
|
|
|
|
|
#include "pipewire/server/client-node.h"
|
|
|
|
|
|
2016-10-17 12:20:49 +02:00
|
|
|
#define MAX_INPUTS 64
|
|
|
|
|
#define MAX_OUTPUTS 64
|
|
|
|
|
|
2016-10-28 16:56:33 +02:00
|
|
|
#define MAX_BUFFERS 64
|
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))
|
|
|
|
|
#define CHECK_FREE_IN_PORT(this,d,p) (CHECK_IN_PORT_ID(this,d,p) && !(this)->in_ports[p].valid)
|
|
|
|
|
#define CHECK_FREE_OUT_PORT(this,d,p) (CHECK_OUT_PORT_ID(this,d,p) && !(this)->out_ports[p].valid)
|
|
|
|
|
#define CHECK_FREE_PORT(this,d,p) (CHECK_FREE_IN_PORT (this,d,p) || CHECK_FREE_OUT_PORT (this,d,p))
|
|
|
|
|
#define CHECK_IN_PORT(this,d,p) (CHECK_IN_PORT_ID(this,d,p) && (this)->in_ports[p].valid)
|
|
|
|
|
#define CHECK_OUT_PORT(this,d,p) (CHECK_OUT_PORT_ID(this,d,p) && (this)->out_ports[p].valid)
|
|
|
|
|
#define CHECK_PORT(this,d,p) (CHECK_IN_PORT (this,d,p) || CHECK_OUT_PORT (this,d,p))
|
|
|
|
|
|
2016-10-28 16:56:33 +02:00
|
|
|
#define CHECK_PORT_BUFFER(this,b,p) (b < p->n_buffers)
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy_buffer {
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_buffer *outbuf;
|
|
|
|
|
struct spa_buffer buffer;
|
|
|
|
|
struct spa_meta metas[4];
|
|
|
|
|
struct spa_data datas[4];
|
|
|
|
|
off_t offset;
|
|
|
|
|
size_t size;
|
|
|
|
|
bool outstanding;
|
2016-10-17 12:20:49 +02:00
|
|
|
};
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy_port {
|
2016-10-17 12:20:49 +02:00
|
|
|
bool valid;
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_port_info info;
|
|
|
|
|
struct spa_format *format;
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_formats;
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_format **formats;
|
2017-05-22 13:06:18 +02:00
|
|
|
uint32_t n_params;
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_param **params;
|
|
|
|
|
struct spa_port_io *io;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
uint32_t n_buffers;
|
|
|
|
|
struct proxy_buffer buffers[MAX_BUFFERS];
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
uint32_t buffer_mem_id;
|
|
|
|
|
struct pw_memblock buffer_mem;
|
|
|
|
|
};
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_node node;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl *impl;
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_type_map *map;
|
|
|
|
|
struct spa_log *log;
|
|
|
|
|
struct spa_loop *main_loop;
|
|
|
|
|
struct spa_loop *data_loop;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_node_callbacks callbacks;
|
2016-10-17 12:20:49 +02:00
|
|
|
void *user_data;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_resource *resource;
|
2016-10-17 18:29:05 +02:00
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_source data_source;
|
2017-04-21 10:24:42 +02:00
|
|
|
int writefd;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t max_inputs;
|
|
|
|
|
uint32_t n_inputs;
|
|
|
|
|
uint32_t max_outputs;
|
|
|
|
|
uint32_t n_outputs;
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy_port in_ports[MAX_INPUTS];
|
|
|
|
|
struct proxy_port out_ports[MAX_OUTPUTS];
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-04-04 20:25:02 +02:00
|
|
|
uint8_t format_buffer[1024];
|
2016-10-17 12:20:49 +02:00
|
|
|
uint32_t seq;
|
|
|
|
|
};
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl {
|
|
|
|
|
struct pw_client_node this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_core *core;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy proxy;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_transport *transport;
|
2017-04-12 10:40:17 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_listener node_free;
|
|
|
|
|
struct pw_listener initialized;
|
|
|
|
|
struct pw_listener loop_changed;
|
|
|
|
|
struct pw_listener global_added;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-04-21 10:24:42 +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
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2017-05-23 19:15:33 +02:00
|
|
|
clear_buffers (struct proxy *this, struct proxy_port *port)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
|
|
|
|
if (port->n_buffers) {
|
2016-11-03 19:41:53 +01:00
|
|
|
spa_log_info (this->log, "proxy %p: clear buffers", this);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_memblock_free (&port->buffer_mem);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
port->n_buffers = 0;
|
|
|
|
|
}
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_get_props (struct spa_node *node,
|
|
|
|
|
struct spa_props **props)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_set_props (struct spa_node *node,
|
|
|
|
|
const struct spa_props *props)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-18 17:57:04 +02:00
|
|
|
static inline void
|
2017-05-23 19:15:33 +02:00
|
|
|
do_flush (struct proxy *this)
|
2017-04-18 17:57:04 +02:00
|
|
|
{
|
|
|
|
|
uint64_t cmd = 1;
|
2017-04-21 10:24:42 +02:00
|
|
|
write (this->writefd, &cmd, 8);
|
2017-04-18 17:57:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
2017-05-23 19:15:33 +02:00
|
|
|
send_need_input (struct proxy *this)
|
2017-01-17 15:02:06 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl *impl = SPA_CONTAINER_OF (this, struct impl, proxy);
|
2017-01-17 15:02:06 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_transport_add_event (impl->transport,
|
2017-05-18 17:16:48 +02:00
|
|
|
&SPA_EVENT_INIT (impl->core->type.event_transport.NeedInput));
|
2017-04-18 17:57:04 +02:00
|
|
|
do_flush (this);
|
2017-01-17 15:02:06 +01:00
|
|
|
}
|
|
|
|
|
|
2017-04-18 17:57:04 +02:00
|
|
|
static inline void
|
2017-05-23 19:15:33 +02:00
|
|
|
send_have_output (struct proxy *this)
|
2017-01-17 15:02:06 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl *impl = SPA_CONTAINER_OF (this, struct impl, proxy);
|
2017-01-17 15:02:06 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_transport_add_event (impl->transport,
|
2017-05-18 17:16:48 +02:00
|
|
|
&SPA_EVENT_INIT (impl->core->type.event_transport.HaveOutput));
|
2017-04-18 17:57:04 +02:00
|
|
|
do_flush (this);
|
2017-01-17 15:02:06 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_send_command (struct spa_node *node,
|
|
|
|
|
struct spa_command *command)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
2017-05-25 13:28:15 +02:00
|
|
|
int res = SPA_RESULT_OK;
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_core *core;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (node == NULL || command == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-01-12 14:57:07 +01:00
|
|
|
if (this->resource == NULL)
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
|
2017-04-12 10:40:17 +02:00
|
|
|
core = this->impl->core;
|
2017-03-22 10:04:24 +01:00
|
|
|
|
2017-03-24 11:40:58 +01:00
|
|
|
if (SPA_COMMAND_TYPE (command) == core->type.command_node.ClockUpdate) {
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_client_node_notify_node_command (this->resource,
|
2017-03-22 10:04:24 +01:00
|
|
|
this->seq++,
|
|
|
|
|
command);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* send start */
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_client_node_notify_node_command (this->resource,
|
2017-03-22 10:04:24 +01:00
|
|
|
this->seq,
|
|
|
|
|
command);
|
2017-03-24 11:40:58 +01:00
|
|
|
if (SPA_COMMAND_TYPE (command) == core->type.command_node.Start)
|
2017-03-22 10:04:24 +01:00
|
|
|
send_need_input (this);
|
|
|
|
|
|
|
|
|
|
res = SPA_RESULT_RETURN_ASYNC (this->seq++);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_set_callbacks (struct spa_node *node,
|
|
|
|
|
const struct spa_node_callbacks *callbacks,
|
2017-05-11 10:29:20 +02:00
|
|
|
size_t callbacks_size,
|
|
|
|
|
void *user_data)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2017-05-11 10:29:20 +02:00
|
|
|
this->callbacks = *callbacks;
|
2016-10-17 12:20:49 +02:00
|
|
|
this->user_data = user_data;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_get_n_ports (struct spa_node *node,
|
2017-03-07 11:56:43 +01:00
|
|
|
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
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (n_input_ports)
|
|
|
|
|
*n_input_ports = this->n_inputs;
|
|
|
|
|
if (max_input_ports)
|
|
|
|
|
*max_input_ports = this->max_inputs;
|
|
|
|
|
if (n_output_ports)
|
|
|
|
|
*n_output_ports = this->n_outputs;
|
|
|
|
|
if (max_output_ports)
|
|
|
|
|
*max_output_ports = this->max_outputs;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_get_port_ids (struct spa_node *node,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_input_ports,
|
2016-10-17 12:20:49 +02:00
|
|
|
uint32_t *input_ids,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_output_ports,
|
2016-10-17 12:20:49 +02:00
|
|
|
uint32_t *output_ids)
|
|
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
int c, i;
|
|
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (input_ids) {
|
|
|
|
|
for (c = 0, i = 0; i < MAX_INPUTS && c < n_input_ports; i++) {
|
|
|
|
|
if (this->in_ports[i].valid)
|
|
|
|
|
input_ids[c++] = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (output_ids) {
|
|
|
|
|
for (c = 0, i = 0; i < MAX_OUTPUTS && c < n_output_ports; i++) {
|
|
|
|
|
if (this->out_ports[i].valid)
|
|
|
|
|
output_ids[c++] = i;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
do_update_port (struct proxy *this,
|
2017-05-25 13:28:15 +02:00
|
|
|
enum spa_direction direction,
|
2017-03-02 16:06:45 +01:00
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t change_mask,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_possible_formats,
|
2017-05-25 13:28:15 +02:00
|
|
|
const struct spa_format **possible_formats,
|
|
|
|
|
const struct spa_format *format,
|
2017-05-22 13:06:18 +02:00
|
|
|
uint32_t n_params,
|
2017-05-25 13:28:15 +02:00
|
|
|
const struct spa_param **params,
|
|
|
|
|
const struct spa_port_info *info)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy_port *port;
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t i;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-03-02 16:06:45 +01:00
|
|
|
if (direction == SPA_DIRECTION_INPUT) {
|
|
|
|
|
port = &this->in_ports[port_id];
|
2016-10-17 12:20:49 +02:00
|
|
|
} else {
|
2017-03-02 16:06:45 +01:00
|
|
|
port = &this->out_ports[port_id];
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (change_mask & PW_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS) {
|
2016-10-17 12:20:49 +02:00
|
|
|
for (i = 0; i < port->n_formats; i++)
|
|
|
|
|
free (port->formats[i]);
|
2017-03-02 16:06:45 +01:00
|
|
|
port->n_formats = n_possible_formats;
|
2017-05-25 13:28:15 +02:00
|
|
|
port->formats = realloc (port->formats, port->n_formats * sizeof (struct spa_format *));
|
2017-03-17 17:09:16 +01:00
|
|
|
for (i = 0; i < port->n_formats; i++)
|
2017-03-06 15:48:04 +01:00
|
|
|
port->formats[i] = spa_format_copy (possible_formats[i]);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
2017-05-23 19:15:33 +02:00
|
|
|
if (change_mask & PW_MESSAGE_PORT_UPDATE_FORMAT) {
|
2016-10-17 12:20:49 +02:00
|
|
|
if (port->format)
|
|
|
|
|
free (port->format);
|
2017-03-06 15:48:04 +01:00
|
|
|
port->format = spa_format_copy (format);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (change_mask & PW_MESSAGE_PORT_UPDATE_PARAMS) {
|
2017-05-22 13:06:18 +02:00
|
|
|
for (i = 0; i < port->n_params; i++)
|
|
|
|
|
free (port->params[i]);
|
|
|
|
|
port->n_params = n_params;
|
2017-05-25 13:28:15 +02:00
|
|
|
port->params = realloc (port->params, port->n_params * sizeof (struct spa_param *));
|
2017-05-22 13:06:18 +02:00
|
|
|
for (i = 0; i < port->n_params; i++)
|
|
|
|
|
port->params[i] = spa_param_copy (params[i]);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (change_mask & PW_MESSAGE_PORT_UPDATE_INFO && info)
|
2017-03-17 17:09:16 +01:00
|
|
|
port->info = *info;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (!port->valid) {
|
2017-03-02 16:06:45 +01:00
|
|
|
spa_log_info (this->log, "proxy %p: adding port %d", this, port_id);
|
2016-10-17 12:20:49 +02:00
|
|
|
port->format = NULL;
|
|
|
|
|
port->valid = true;
|
|
|
|
|
|
2017-03-02 16:06:45 +01:00
|
|
|
if (direction == SPA_DIRECTION_INPUT)
|
2016-10-17 12:20:49 +02:00
|
|
|
this->n_inputs++;
|
|
|
|
|
else
|
|
|
|
|
this->n_outputs++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
clear_port (struct proxy *this,
|
|
|
|
|
struct proxy_port *port,
|
2017-05-25 13:28:15 +02:00
|
|
|
enum spa_direction direction,
|
2016-10-17 12:20:49 +02:00
|
|
|
uint32_t port_id)
|
|
|
|
|
{
|
2017-03-02 16:06:45 +01:00
|
|
|
do_update_port (this,
|
|
|
|
|
direction,
|
|
|
|
|
port_id,
|
2017-05-23 19:15:33 +02:00
|
|
|
PW_MESSAGE_PORT_UPDATE_POSSIBLE_FORMATS |
|
|
|
|
|
PW_MESSAGE_PORT_UPDATE_FORMAT |
|
|
|
|
|
PW_MESSAGE_PORT_UPDATE_PARAMS |
|
|
|
|
|
PW_MESSAGE_PORT_UPDATE_INFO,
|
2017-03-02 16:06:45 +01:00
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
2017-05-22 13:06:18 +02:00
|
|
|
0,
|
2017-03-02 16:06:45 +01:00
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2016-10-17 12:20:49 +02:00
|
|
|
clear_buffers (this, port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
do_uninit_port (struct proxy *this,
|
2017-05-25 13:28:15 +02:00
|
|
|
enum spa_direction direction,
|
2016-10-17 12:20:49 +02:00
|
|
|
uint32_t port_id)
|
|
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy_port *port;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2016-11-03 19:41:53 +01:00
|
|
|
spa_log_info (this->log, "proxy %p: removing port %d", this, port_id);
|
2016-10-17 12:20:49 +02:00
|
|
|
if (direction == SPA_DIRECTION_INPUT) {
|
|
|
|
|
port = &this->in_ports[port_id];
|
|
|
|
|
this->n_inputs--;
|
|
|
|
|
} else {
|
|
|
|
|
port = &this->out_ports[port_id];
|
|
|
|
|
this->n_outputs--;
|
|
|
|
|
}
|
|
|
|
|
clear_port (this, port, direction, port_id);
|
|
|
|
|
port->valid = false;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_add_port (struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
2016-10-17 12:20:49 +02:00
|
|
|
uint32_t port_id)
|
|
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
|
|
|
|
struct proxy_port *port;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (!CHECK_FREE_PORT (this, direction, port_id))
|
|
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
|
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
|
|
|
|
clear_port (this, port, direction, port_id);
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_remove_port (struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
2016-10-17 12:20:49 +02:00
|
|
|
uint32_t port_id)
|
|
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
|
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
|
|
|
|
do_uninit_port (this, direction, port_id);
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_port_enum_formats (struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
2016-10-17 12:20:49 +02:00
|
|
|
uint32_t port_id,
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_format **format,
|
|
|
|
|
const struct spa_format *filter,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t index)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
|
|
|
|
struct proxy_port *port;
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_format *fmt;
|
|
|
|
|
struct spa_pod_builder b = { NULL, };
|
|
|
|
|
int res;
|
2017-04-04 20:25:02 +02:00
|
|
|
uint32_t count, match = 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-02-01 08:58:21 +01:00
|
|
|
if (node == NULL || format == NULL)
|
2016-10-17 12:20:49 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
|
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
|
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
|
|
|
|
|
2017-04-04 20:25:02 +02:00
|
|
|
count = match = filter ? 0 : index;
|
|
|
|
|
|
|
|
|
|
next:
|
|
|
|
|
if (count >= port->n_formats)
|
2016-10-17 12:20:49 +02:00
|
|
|
return SPA_RESULT_ENUM_END;
|
|
|
|
|
|
2017-04-04 20:25:02 +02:00
|
|
|
fmt = port->formats[count++];
|
|
|
|
|
|
|
|
|
|
spa_pod_builder_init (&b, this->format_buffer, sizeof (this->format_buffer));
|
|
|
|
|
|
|
|
|
|
if ((res = spa_format_filter (fmt, filter, &b)) != SPA_RESULT_OK || match++ != index)
|
|
|
|
|
goto next;
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
*format = SPA_POD_BUILDER_DEREF (&b, 0, struct spa_format);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_port_set_format (struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
2017-05-11 10:29:20 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t flags,
|
2017-05-25 13:28:15 +02:00
|
|
|
const struct spa_format *format)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
|
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
2017-01-12 14:57:07 +01:00
|
|
|
if (this->resource == NULL)
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_client_node_notify_set_format (this->resource,
|
2017-03-02 16:06:45 +01:00
|
|
|
this->seq,
|
|
|
|
|
direction,
|
|
|
|
|
port_id,
|
|
|
|
|
flags,
|
|
|
|
|
format);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
spa_proxy_node_port_get_format (struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
2016-10-17 12:20:49 +02:00
|
|
|
uint32_t port_id,
|
2017-05-25 13:28:15 +02:00
|
|
|
const struct spa_format **format)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
|
|
|
|
struct proxy_port *port;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (node == NULL || format == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
|
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
|
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
|
|
|
|
|
|
|
|
|
if (!port->format)
|
|
|
|
|
return SPA_RESULT_NO_FORMAT;
|
|
|
|
|
|
|
|
|
|
*format = port->format;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_port_get_info (struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
2016-10-17 12:20:49 +02:00
|
|
|
uint32_t port_id,
|
2017-05-25 13:28:15 +02:00
|
|
|
const struct spa_port_info **info)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
|
|
|
|
struct proxy_port *port;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (node == NULL || info == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
|
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
|
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
|
|
|
|
|
2017-03-17 17:09:16 +01:00
|
|
|
*info = &port->info;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_port_enum_params (struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
2017-05-22 13:06:18 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t index,
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_param **param)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
|
|
|
|
struct proxy_port *port;
|
2017-05-22 13:06:18 +02:00
|
|
|
|
|
|
|
|
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
spa_return_val_if_fail (param != NULL, SPA_RESULT_INVALID_ARGUMENTS);
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2017-05-22 13:06:18 +02:00
|
|
|
|
|
|
|
|
spa_return_val_if_fail (CHECK_PORT (this, direction, port_id), SPA_RESULT_INVALID_PORT);
|
|
|
|
|
|
|
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
|
|
|
|
|
|
|
|
|
if (index >= port->n_params)
|
|
|
|
|
return SPA_RESULT_ENUM_END;
|
|
|
|
|
|
|
|
|
|
*param = port->params[index];
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_port_set_param (struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
2016-10-17 12:20:49 +02:00
|
|
|
uint32_t port_id,
|
2017-05-25 13:28:15 +02:00
|
|
|
const struct spa_param *param)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_port_set_io (struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
2017-04-03 14:56:04 +02:00
|
|
|
uint32_t port_id,
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_port_io *io)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
|
|
|
|
struct proxy_port *port;
|
2016-11-07 18:23:09 +01:00
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
2016-11-07 18:23:09 +01:00
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
2017-04-03 14:56:04 +02:00
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
|
|
|
|
port->io = io;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_port_use_buffers (struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
|
uint32_t n_buffers)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
|
|
|
|
struct impl *impl;
|
|
|
|
|
struct proxy_port *port;
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t i, j;
|
2016-12-15 14:57:34 +01:00
|
|
|
size_t n_mem;
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_client_node_buffer *mb;
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_meta_shared *msh;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2017-04-26 18:42:50 +02:00
|
|
|
impl = this->impl;
|
2016-11-03 19:41:53 +01:00
|
|
|
spa_log_info (this->log, "proxy %p: use buffers %p %u", this, buffers, n_buffers);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
|
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
|
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
|
|
|
|
|
|
|
|
|
if (!port->format)
|
|
|
|
|
return SPA_RESULT_NO_FORMAT;
|
|
|
|
|
|
|
|
|
|
clear_buffers (this, port);
|
|
|
|
|
|
2016-12-15 14:57:34 +01:00
|
|
|
if (n_buffers > 0) {
|
2017-05-23 19:15:33 +02:00
|
|
|
mb = alloca (n_buffers * sizeof (struct pw_client_node_buffer));
|
2016-12-15 14:57:34 +01:00
|
|
|
} else {
|
|
|
|
|
mb = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-12 14:57:07 +01:00
|
|
|
port->n_buffers = n_buffers;
|
|
|
|
|
|
|
|
|
|
if (this->resource == NULL)
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
|
2016-10-17 12:20:49 +02:00
|
|
|
n_mem = 0;
|
|
|
|
|
for (i = 0; i < n_buffers; i++) {
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy_buffer *b = &port->buffers[i];
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-04-26 18:42:50 +02:00
|
|
|
msh = spa_buffer_find_meta (buffers[i], impl->core->type.meta.Shared);
|
2016-12-15 14:57:34 +01:00
|
|
|
if (msh == NULL) {
|
|
|
|
|
spa_log_error (this->log, "missing shared metadata on buffer %d", i);
|
|
|
|
|
return SPA_RESULT_ERROR;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-17 12:20:49 +02:00
|
|
|
b->outbuf = buffers[i];
|
2017-05-25 13:28:15 +02:00
|
|
|
memcpy (&b->buffer, buffers[i], sizeof (struct spa_buffer));
|
2016-10-17 12:20:49 +02:00
|
|
|
b->buffer.datas = b->datas;
|
|
|
|
|
b->buffer.metas = b->metas;
|
|
|
|
|
|
2016-12-15 14:57:34 +01:00
|
|
|
mb[i].buffer = &b->buffer;
|
2017-03-02 16:06:45 +01:00
|
|
|
mb[i].mem_id = n_mem++;
|
2016-12-15 14:57:34 +01:00
|
|
|
mb[i].offset = 0;
|
2017-03-02 16:06:45 +01:00
|
|
|
mb[i].size = msh->size;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_client_node_notify_add_mem (this->resource,
|
2017-03-02 16:06:45 +01:00
|
|
|
direction,
|
|
|
|
|
port_id,
|
|
|
|
|
mb[i].mem_id,
|
2017-04-26 18:42:50 +02:00
|
|
|
impl->core->type.data.MemFd,
|
2017-03-02 16:06:45 +01:00
|
|
|
msh->fd,
|
|
|
|
|
msh->flags,
|
|
|
|
|
msh->offset,
|
|
|
|
|
msh->size);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
for (j = 0; j < buffers[i]->n_metas; j++) {
|
2017-05-25 13:28:15 +02:00
|
|
|
memcpy (&b->buffer.metas[j], &buffers[i]->metas[j], sizeof (struct spa_meta));
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (j = 0; j < buffers[i]->n_datas; j++) {
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_data *d = &buffers[i]->datas[j];
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
memcpy (&b->buffer.datas[j], d, sizeof (struct spa_data));
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-04-26 18:42:50 +02:00
|
|
|
if (d->type == impl->core->type.data.DmaBuf ||
|
|
|
|
|
d->type == impl->core->type.data.MemFd) {
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_client_node_notify_add_mem (this->resource,
|
2017-04-26 18:42:50 +02:00
|
|
|
direction,
|
|
|
|
|
port_id,
|
|
|
|
|
n_mem,
|
|
|
|
|
d->type,
|
|
|
|
|
d->fd,
|
|
|
|
|
d->flags,
|
|
|
|
|
d->mapoffset,
|
|
|
|
|
d->maxsize);
|
|
|
|
|
b->buffer.datas[j].type = impl->core->type.data.Id;
|
|
|
|
|
b->buffer.datas[j].data = SPA_UINT32_TO_PTR (n_mem);
|
|
|
|
|
n_mem++;
|
|
|
|
|
}
|
|
|
|
|
else if (d->type == impl->core->type.data.MemPtr) {
|
|
|
|
|
b->buffer.datas[j].data = SPA_INT_TO_PTR (b->size);
|
|
|
|
|
b->size += d->maxsize;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
b->buffer.datas[j].type = SPA_ID_INVALID;
|
|
|
|
|
b->buffer.datas[j].data = 0;
|
|
|
|
|
spa_log_error (this->log, "invalid memory type %d", d->type);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_client_node_notify_use_buffers (this->resource,
|
2017-03-02 16:06:45 +01:00
|
|
|
this->seq,
|
|
|
|
|
direction,
|
|
|
|
|
port_id,
|
|
|
|
|
n_buffers,
|
|
|
|
|
mb);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
spa_proxy_node_port_alloc_buffers (struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
struct spa_param **params,
|
|
|
|
|
uint32_t n_params,
|
|
|
|
|
struct spa_buffer **buffers,
|
|
|
|
|
uint32_t *n_buffers)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
|
|
|
|
struct proxy_port *port;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (node == NULL || buffers == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (!CHECK_PORT (this, direction, port_id))
|
|
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
|
|
|
|
port = direction == SPA_DIRECTION_INPUT ? &this->in_ports[port_id] : &this->out_ports[port_id];
|
|
|
|
|
|
|
|
|
|
if (!port->format)
|
|
|
|
|
return SPA_RESULT_NO_FORMAT;
|
|
|
|
|
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_port_reuse_buffer (struct spa_node *node,
|
2016-10-17 12:20:49 +02:00
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t buffer_id)
|
|
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
|
|
|
|
struct impl *impl;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2017-04-12 10:40:17 +02:00
|
|
|
impl = this->impl;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
|
|
|
|
if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, port_id))
|
|
|
|
|
return SPA_RESULT_INVALID_PORT;
|
|
|
|
|
|
2017-04-08 20:33:54 +02:00
|
|
|
spa_log_trace (this->log, "reuse buffer %d", buffer_id);
|
2017-03-15 16:21:05 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_event_transport_reuse_buffer rb = PW_EVENT_TRANSPORT_REUSE_BUFFER_INIT
|
2017-05-11 10:29:20 +02:00
|
|
|
(impl->core->type.event_transport.ReuseBuffer, port_id, buffer_id);
|
2017-05-25 13:28:15 +02:00
|
|
|
pw_transport_add_event (impl->transport, (struct spa_event *)&rb);
|
2017-03-15 16:21:05 +01:00
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2016-10-18 18:19:04 +02:00
|
|
|
return SPA_RESULT_OK;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_port_send_command (struct spa_node *node,
|
|
|
|
|
enum spa_direction direction,
|
|
|
|
|
uint32_t port_id,
|
|
|
|
|
struct spa_command *command)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2016-10-21 14:57:01 +02:00
|
|
|
if (node == NULL || command == NULL)
|
2016-10-17 12:20:49 +02:00
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-03-22 10:04:24 +01:00
|
|
|
spa_log_warn (this->log, "unhandled command %d", SPA_COMMAND_TYPE (command));
|
|
|
|
|
return SPA_RESULT_NOT_IMPLEMENTED;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_process_input (struct spa_node *node)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl *impl;
|
|
|
|
|
struct proxy *this;
|
2017-04-12 10:40:17 +02:00
|
|
|
int i;
|
2016-11-07 18:23:09 +01:00
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
|
return SPA_RESULT_INVALID_ARGUMENTS;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2017-04-12 10:40:17 +02:00
|
|
|
impl = this->impl;
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-04-12 10:40:17 +02:00
|
|
|
for (i = 0; i < MAX_INPUTS; i++) {
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_port_io *io = this->in_ports[i].io;
|
2017-04-12 10:40:17 +02:00
|
|
|
|
|
|
|
|
if (!io)
|
|
|
|
|
continue;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_log_trace ("%d %d", io->status, io->buffer_id);
|
2017-04-18 17:57:04 +02:00
|
|
|
|
2017-04-12 10:40:17 +02:00
|
|
|
impl->transport->inputs[i] = *io;
|
|
|
|
|
io->status = SPA_RESULT_OK;
|
|
|
|
|
}
|
2017-01-17 15:02:06 +01:00
|
|
|
send_have_output (this);
|
2016-11-07 18:23:09 +01:00
|
|
|
|
|
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
|
|
|
|
spa_proxy_node_process_output (struct spa_node *node)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this;
|
|
|
|
|
struct impl *impl;
|
2017-04-08 20:33:54 +02:00
|
|
|
int i;
|
2017-04-18 17:57:04 +02:00
|
|
|
bool send_need = false, flush = false;
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this = SPA_CONTAINER_OF (node, struct proxy, node);
|
2017-04-12 10:40:17 +02:00
|
|
|
impl = this->impl;
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-04-08 20:33:54 +02:00
|
|
|
for (i = 0; i < MAX_OUTPUTS; i++) {
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_port_io *io = this->out_ports[i].io, tmp;
|
2017-04-12 10:40:17 +02:00
|
|
|
|
|
|
|
|
if (!io)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (io->buffer_id != SPA_ID_INVALID) {
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_event_transport_reuse_buffer rb =
|
|
|
|
|
PW_EVENT_TRANSPORT_REUSE_BUFFER_INIT (impl->core->type.event_transport.ReuseBuffer, i, io->buffer_id);
|
2017-04-12 10:40:17 +02:00
|
|
|
|
|
|
|
|
spa_log_trace (this->log, "reuse buffer %d", io->buffer_id);
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
pw_transport_add_event (impl->transport, (struct spa_event *)&rb);
|
2017-04-08 20:33:54 +02:00
|
|
|
io->buffer_id = SPA_ID_INVALID;
|
2017-04-18 17:57:04 +02:00
|
|
|
flush = true;
|
2017-04-08 20:33:54 +02:00
|
|
|
}
|
2017-04-12 10:40:17 +02:00
|
|
|
|
|
|
|
|
tmp = impl->transport->outputs[i];
|
|
|
|
|
impl->transport->outputs[i] = *io;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_log_trace ("%d %d %d %d", io->status, io->buffer_id, tmp.status, tmp.buffer_id);
|
2017-04-12 10:40:17 +02:00
|
|
|
|
2017-04-28 11:49:13 +02:00
|
|
|
if (io->status == SPA_RESULT_NEED_BUFFER)
|
2017-04-12 10:40:17 +02:00
|
|
|
send_need = true;
|
|
|
|
|
|
|
|
|
|
*io = tmp;
|
2017-04-08 20:33:54 +02:00
|
|
|
}
|
2017-04-12 10:40:17 +02:00
|
|
|
if (send_need)
|
|
|
|
|
send_need_input (this);
|
2017-04-18 17:57:04 +02:00
|
|
|
else if (flush)
|
|
|
|
|
do_flush (this);
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-04-28 11:49:13 +02:00
|
|
|
return SPA_RESULT_HAVE_BUFFER;
|
2016-11-07 18:23:09 +01:00
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2017-05-23 19:15:33 +02:00
|
|
|
handle_node_event (struct proxy *this,
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_event *event)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl *impl = SPA_CONTAINER_OF (this, struct impl, proxy);
|
2017-04-18 17:57:04 +02:00
|
|
|
int i;
|
|
|
|
|
|
2017-05-11 10:29:20 +02:00
|
|
|
if (SPA_EVENT_TYPE (event) == impl->core->type.event_transport.HaveOutput) {
|
2017-04-18 17:57:04 +02:00
|
|
|
for (i = 0; i < MAX_OUTPUTS; i++) {
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_port_io *io = this->out_ports[i].io;
|
2017-04-18 17:57:04 +02:00
|
|
|
|
|
|
|
|
if (!io)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
*io = impl->transport->outputs[i];
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_log_trace ("%d %d", io->status, io->buffer_id);
|
2017-04-18 17:57:04 +02:00
|
|
|
}
|
2017-05-11 10:29:20 +02:00
|
|
|
this->callbacks.have_output (&this->node, this->user_data);
|
|
|
|
|
}
|
|
|
|
|
else if (SPA_EVENT_TYPE (event) == impl->core->type.event_transport.NeedInput) {
|
|
|
|
|
this->callbacks.need_input (&this->node, this->user_data);
|
|
|
|
|
}
|
|
|
|
|
else if (SPA_EVENT_TYPE (event) == impl->core->type.event_transport.ReuseBuffer) {
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_event_transport_reuse_buffer *p = (struct pw_event_transport_reuse_buffer *) event;
|
2017-05-11 10:29:20 +02:00
|
|
|
this->callbacks.reuse_buffer (&this->node, p->body.port_id.value, p->body.buffer_id.value, this->user_data);
|
2017-04-18 17:57:04 +02:00
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
return SPA_RESULT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-02 16:06:45 +01:00
|
|
|
static void
|
|
|
|
|
client_node_update (void *object,
|
|
|
|
|
uint32_t change_mask,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t max_input_ports,
|
|
|
|
|
uint32_t max_output_ports,
|
2017-05-25 13:28:15 +02:00
|
|
|
const struct spa_props *props)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_resource *resource = object;
|
|
|
|
|
struct pw_client_node *node = resource->object;
|
|
|
|
|
struct impl *impl = SPA_CONTAINER_OF (node, struct impl, this);
|
|
|
|
|
struct proxy *this = &impl->proxy;
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
if (change_mask & PW_MESSAGE_NODE_UPDATE_MAX_INPUTS)
|
2017-03-02 16:06:45 +01:00
|
|
|
this->max_inputs = max_input_ports;
|
2017-05-23 19:15:33 +02:00
|
|
|
if (change_mask & PW_MESSAGE_NODE_UPDATE_MAX_OUTPUTS)
|
2017-03-02 16:06:45 +01:00
|
|
|
this->max_outputs = max_output_ports;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-03-02 16:06:45 +01:00
|
|
|
spa_log_info (this->log, "proxy %p: got node update max_in %u, max_out %u", this,
|
|
|
|
|
this->max_inputs, this->max_outputs);
|
|
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-03-02 16:06:45 +01:00
|
|
|
static void
|
|
|
|
|
client_node_port_update (void *object,
|
2017-05-25 13:28:15 +02:00
|
|
|
enum spa_direction direction,
|
2017-03-02 16:06:45 +01:00
|
|
|
uint32_t port_id,
|
|
|
|
|
uint32_t change_mask,
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t n_possible_formats,
|
2017-05-25 13:28:15 +02:00
|
|
|
const struct spa_format **possible_formats,
|
|
|
|
|
const struct spa_format *format,
|
2017-05-22 13:06:18 +02:00
|
|
|
uint32_t n_params,
|
2017-05-25 13:28:15 +02:00
|
|
|
const struct spa_param **params,
|
|
|
|
|
const struct spa_port_info *info)
|
2017-03-02 16:06:45 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_resource *resource = object;
|
|
|
|
|
struct pw_client_node *node = resource->object;
|
|
|
|
|
struct impl *impl = SPA_CONTAINER_OF (node, struct impl, this);
|
|
|
|
|
struct proxy *this = &impl->proxy;
|
2017-03-02 16:06:45 +01:00
|
|
|
bool remove;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-03-02 16:06:45 +01:00
|
|
|
spa_log_info (this->log, "proxy %p: got port update", this);
|
|
|
|
|
if (!CHECK_PORT_ID (this, direction, port_id))
|
|
|
|
|
return;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-03-02 16:06:45 +01:00
|
|
|
remove = (change_mask == 0);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-03-02 16:06:45 +01:00
|
|
|
if (remove) {
|
|
|
|
|
do_uninit_port (this, direction, port_id);
|
|
|
|
|
} else {
|
|
|
|
|
do_update_port (this,
|
|
|
|
|
direction,
|
|
|
|
|
port_id,
|
|
|
|
|
change_mask,
|
|
|
|
|
n_possible_formats,
|
|
|
|
|
possible_formats,
|
|
|
|
|
format,
|
2017-05-22 13:06:18 +02:00
|
|
|
n_params,
|
|
|
|
|
params,
|
2017-03-02 16:06:45 +01:00
|
|
|
info);
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-03-02 16:06:45 +01:00
|
|
|
static void
|
2017-03-21 20:39:20 +01:00
|
|
|
client_node_event (void *object,
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_event *event)
|
2017-03-02 16:06:45 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_resource *resource = object;
|
|
|
|
|
struct pw_client_node *node = resource->object;
|
|
|
|
|
struct impl *impl = SPA_CONTAINER_OF (node, struct impl, this);
|
|
|
|
|
struct proxy *this = &impl->proxy;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-11 10:29:20 +02:00
|
|
|
this->callbacks.event (&this->node, event, this->user_data);
|
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-03-09 19:21:50 +01:00
|
|
|
client_node_destroy (void *object)
|
2017-03-02 16:06:45 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_resource *resource = object;
|
|
|
|
|
struct pw_client_node *node = resource->object;
|
|
|
|
|
pw_client_node_destroy (node);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
static struct pw_client_node_methods client_node_methods = {
|
2017-03-02 16:06:45 +01:00
|
|
|
&client_node_update,
|
|
|
|
|
&client_node_port_update,
|
|
|
|
|
&client_node_event,
|
|
|
|
|
&client_node_destroy,
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-18 17:46:01 +01:00
|
|
|
static void
|
2017-05-25 13:28:15 +02:00
|
|
|
proxy_on_data_fd_events (struct spa_source *source)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct proxy *this = source->data;
|
|
|
|
|
struct impl *impl = this->impl;
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2017-01-17 15:02:06 +01:00
|
|
|
if (source->rmask & (SPA_IO_ERR | SPA_IO_HUP)) {
|
|
|
|
|
spa_log_warn (this->log, "proxy %p: got error", this);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-18 17:46:01 +01:00
|
|
|
if (source->rmask & SPA_IO_IN) {
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_event event;
|
2017-01-18 18:29:15 +01:00
|
|
|
uint64_t cmd;
|
2016-11-07 10:24:13 +01:00
|
|
|
|
2017-01-18 18:29:15 +01:00
|
|
|
read (this->data_source.fd, &cmd, 8);
|
2016-11-07 10:24:13 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
while (pw_transport_next_event (impl->transport, &event) == SPA_RESULT_OK) {
|
2017-05-25 13:28:15 +02:00
|
|
|
struct spa_event *ev = alloca (SPA_POD_SIZE (&event));
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_transport_parse_event (impl->transport, ev);
|
2017-05-11 10:29:20 +02:00
|
|
|
handle_node_event (this, ev);
|
2016-11-07 10:24:13 +01:00
|
|
|
}
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
}
|
2016-07-28 21:19:20 +02:00
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static const struct spa_node proxy_node = {
|
|
|
|
|
sizeof (struct spa_node),
|
2016-10-17 12:20:49 +02:00
|
|
|
NULL,
|
|
|
|
|
spa_proxy_node_get_props,
|
|
|
|
|
spa_proxy_node_set_props,
|
|
|
|
|
spa_proxy_node_send_command,
|
2017-05-11 10:29:20 +02:00
|
|
|
spa_proxy_node_set_callbacks,
|
2016-10-17 12:20:49 +02:00
|
|
|
spa_proxy_node_get_n_ports,
|
|
|
|
|
spa_proxy_node_get_port_ids,
|
|
|
|
|
spa_proxy_node_add_port,
|
|
|
|
|
spa_proxy_node_remove_port,
|
|
|
|
|
spa_proxy_node_port_enum_formats,
|
|
|
|
|
spa_proxy_node_port_set_format,
|
|
|
|
|
spa_proxy_node_port_get_format,
|
|
|
|
|
spa_proxy_node_port_get_info,
|
2017-05-22 13:06:18 +02:00
|
|
|
spa_proxy_node_port_enum_params,
|
|
|
|
|
spa_proxy_node_port_set_param,
|
2016-10-17 12:20:49 +02:00
|
|
|
spa_proxy_node_port_use_buffers,
|
|
|
|
|
spa_proxy_node_port_alloc_buffers,
|
2017-04-03 14:56:04 +02:00
|
|
|
spa_proxy_node_port_set_io,
|
2016-10-17 12:20:49 +02:00
|
|
|
spa_proxy_node_port_reuse_buffer,
|
2016-10-21 14:57:01 +02:00
|
|
|
spa_proxy_node_port_send_command,
|
2016-11-07 18:23:09 +01:00
|
|
|
spa_proxy_node_process_input,
|
|
|
|
|
spa_proxy_node_process_output,
|
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
|
|
|
|
|
proxy_init (struct proxy *this,
|
|
|
|
|
struct spa_dict *info,
|
|
|
|
|
const struct spa_support *support,
|
|
|
|
|
uint32_t n_support)
|
2016-07-22 17:17:44 +02:00
|
|
|
{
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t i;
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-10-17 12:20:49 +02:00
|
|
|
for (i = 0; i < n_support; i++) {
|
2017-03-24 11:40:58 +01:00
|
|
|
if (strcmp (support[i].type, SPA_TYPE__Log) == 0)
|
2016-10-17 12:20:49 +02:00
|
|
|
this->log = support[i].data;
|
2017-03-24 11:40:58 +01:00
|
|
|
else if (strcmp (support[i].type, SPA_TYPE_LOOP__MainLoop) == 0)
|
2016-10-17 12:20:49 +02:00
|
|
|
this->main_loop = support[i].data;
|
2017-03-24 11:40:58 +01:00
|
|
|
else if (strcmp (support[i].type, SPA_TYPE_LOOP__DataLoop) == 0)
|
2016-10-17 12:20:49 +02:00
|
|
|
this->data_loop = support[i].data;
|
|
|
|
|
}
|
|
|
|
|
if (this->data_loop == NULL) {
|
|
|
|
|
spa_log_error (this->log, "a main-loop is needed");
|
|
|
|
|
}
|
|
|
|
|
if (this->data_loop == NULL) {
|
|
|
|
|
spa_log_error (this->log, "a data-loop is needed");
|
|
|
|
|
}
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-10-17 12:20:49 +02:00
|
|
|
this->node = proxy_node;
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-11-18 17:46:01 +01:00
|
|
|
this->data_source.func = proxy_on_data_fd_events;
|
|
|
|
|
this->data_source.data = this;
|
|
|
|
|
this->data_source.fd = -1;
|
2016-11-24 17:00:42 +01:00
|
|
|
this->data_source.mask = SPA_IO_IN | SPA_IO_ERR | SPA_IO_HUP;
|
2016-11-18 17:46:01 +01:00
|
|
|
this->data_source.rmask = 0;
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2016-10-24 12:20:44 +02:00
|
|
|
return SPA_RESULT_RETURN_ASYNC (this->seq++);
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-07 18:23:09 +01:00
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
on_initialized (struct pw_listener *listener,
|
|
|
|
|
struct pw_node *node)
|
2016-11-07 18:23:09 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, initialized);
|
|
|
|
|
struct pw_client_node *this = &impl->this;
|
|
|
|
|
struct pw_transport_info info;
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2017-01-12 14:57:07 +01:00
|
|
|
if (this->resource == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
impl->transport = pw_transport_new (node->max_input_ports,
|
2017-04-12 10:40:17 +02:00
|
|
|
node->max_output_ports);
|
|
|
|
|
impl->transport->area->n_inputs = node->n_input_ports;
|
|
|
|
|
impl->transport->area->n_outputs = node->n_output_ports;
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_transport_get_info (impl->transport, &info);
|
|
|
|
|
pw_client_node_notify_transport (this->resource,
|
2017-03-02 16:06:45 +01:00
|
|
|
info.memfd,
|
|
|
|
|
info.offset,
|
|
|
|
|
info.size);
|
2016-11-07 18:23:09 +01:00
|
|
|
}
|
|
|
|
|
|
2016-11-14 12:42:00 +01:00
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
on_loop_changed (struct pw_listener *listener,
|
|
|
|
|
struct pw_node *node)
|
2016-11-14 12:42:00 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, loop_changed);
|
2016-11-18 17:46:01 +01:00
|
|
|
impl->proxy.data_loop = node->data_loop->loop->loop;
|
2016-11-14 12:42:00 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-10 17:12:53 +01:00
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
on_global_added (struct pw_listener *listener,
|
|
|
|
|
struct pw_core *core,
|
|
|
|
|
struct pw_global *global)
|
2017-01-10 17:12:53 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, global_added);
|
2017-01-12 14:57:07 +01:00
|
|
|
|
2017-01-10 17:12:53 +01:00
|
|
|
if (global->object == impl->this.node)
|
|
|
|
|
global->owner = impl->this.client;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-25 13:28:15 +02:00
|
|
|
static int
|
2017-05-23 19:15:33 +02:00
|
|
|
proxy_clear (struct proxy *this)
|
2016-07-22 17:17:44 +02:00
|
|
|
{
|
2017-03-07 11:56:43 +01:00
|
|
|
uint32_t i;
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-10-17 12:20:49 +02:00
|
|
|
for (i = 0; i < MAX_INPUTS; i++) {
|
|
|
|
|
if (this->in_ports[i].valid)
|
|
|
|
|
clear_port (this, &this->in_ports[i], SPA_DIRECTION_INPUT, i);
|
|
|
|
|
}
|
|
|
|
|
for (i = 0; i < MAX_OUTPUTS; i++) {
|
|
|
|
|
if (this->out_ports[i].valid)
|
|
|
|
|
clear_port (this, &this->out_ports[i], SPA_DIRECTION_OUTPUT, i);
|
|
|
|
|
}
|
2016-07-22 17:17:44 +02:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
return SPA_RESULT_OK;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-30 19:09:09 +01:00
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
client_node_resource_destroy (struct pw_resource *resource)
|
2016-11-30 19:09:09 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_client_node *this = resource->object;
|
|
|
|
|
struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this);
|
|
|
|
|
struct proxy *proxy = &impl->proxy;
|
2017-01-12 14:57:07 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_log_debug ("client-node %p: destroy", impl);
|
|
|
|
|
pw_signal_emit (&this->destroy_signal, this);
|
2017-01-20 15:53:03 +01:00
|
|
|
|
2017-01-12 14:57:07 +01:00
|
|
|
impl->proxy.resource = this->resource = NULL;
|
2017-01-20 15:53:03 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_signal_remove (&impl->global_added);
|
|
|
|
|
pw_signal_remove (&impl->loop_changed);
|
|
|
|
|
pw_signal_remove (&impl->initialized);
|
2017-01-20 15:53:03 +01:00
|
|
|
|
2017-04-21 10:24:42 +02:00
|
|
|
if (proxy->data_source.fd != -1)
|
2017-03-09 09:48:41 +01:00
|
|
|
spa_loop_remove_source (proxy->data_loop, &proxy->data_source);
|
2017-04-21 10:24:42 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_node_destroy (this->node);
|
2017-01-12 14:57:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-05-23 19:15:33 +02:00
|
|
|
on_node_free (struct pw_listener *listener,
|
|
|
|
|
struct pw_node *node)
|
2017-01-12 14:57:07 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl *impl = SPA_CONTAINER_OF (listener, struct impl, node_free);
|
2017-01-12 14:57:07 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_log_debug ("client-node %p: free", &impl->this);
|
2017-01-12 14:57:07 +01:00
|
|
|
proxy_clear (&impl->proxy);
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_signal_remove (&impl->node_free);
|
2017-02-02 17:48:39 +01:00
|
|
|
|
2017-04-12 10:40:17 +02:00
|
|
|
if (impl->transport)
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_transport_destroy (impl->transport);
|
2017-04-12 10:40:17 +02:00
|
|
|
|
2017-04-21 10:24:42 +02:00
|
|
|
if (impl->fds[0] != -1)
|
|
|
|
|
close (impl->fds[0]);
|
|
|
|
|
if (impl->fds[1] != -1)
|
|
|
|
|
close (impl->fds[1]);
|
2017-01-12 14:57:07 +01:00
|
|
|
free (impl);
|
2016-11-30 19:09:09 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-17 12:20:49 +02:00
|
|
|
/**
|
2017-05-23 19:15:33 +02:00
|
|
|
* pw_client_node_new:
|
|
|
|
|
* @client: a #pw_client
|
|
|
|
|
* @id: an id
|
2016-10-17 12:20:49 +02:00
|
|
|
* @name: a name
|
|
|
|
|
* @properties: extra properties
|
|
|
|
|
*
|
2017-05-23 19:15:33 +02:00
|
|
|
* Create a new #struct pw_node.
|
2016-10-17 12:20:49 +02:00
|
|
|
*
|
2017-05-23 19:15:33 +02:00
|
|
|
* Returns: a new #struct pw_node
|
2016-10-17 12:20:49 +02:00
|
|
|
*/
|
2017-05-23 19:15:33 +02:00
|
|
|
struct pw_client_node *
|
|
|
|
|
pw_client_node_new (struct pw_client *client,
|
|
|
|
|
uint32_t id,
|
|
|
|
|
const char *name,
|
|
|
|
|
struct pw_properties *properties)
|
2016-10-17 12:20:49 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl *impl;
|
|
|
|
|
struct pw_client_node *this;
|
2016-11-10 15:42:14 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
impl = calloc (1, sizeof (struct impl));
|
2016-12-22 16:50:01 +01:00
|
|
|
if (impl == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
this = &impl->this;
|
2017-01-12 14:57:07 +01:00
|
|
|
this->client = client;
|
|
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
impl->core = client->core;
|
2017-04-21 10:24:42 +02:00
|
|
|
impl->fds[0] = impl->fds[1] = -1;
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_log_debug ("client-node %p: new", impl);
|
2016-10-17 12:20:49 +02:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_signal_init (&this->destroy_signal);
|
2016-11-07 18:23:09 +01:00
|
|
|
|
2016-11-24 17:00:42 +01:00
|
|
|
proxy_init (&impl->proxy, NULL, client->core->support, client->core->n_support);
|
2016-11-10 15:42:14 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this->node = pw_node_new (client->core,
|
2017-04-12 19:24:48 +02:00
|
|
|
client,
|
2016-11-10 15:42:14 +01:00
|
|
|
name,
|
2017-04-08 20:33:54 +02:00
|
|
|
true,
|
2016-11-10 15:42:14 +01:00
|
|
|
&impl->proxy.node,
|
|
|
|
|
NULL,
|
|
|
|
|
properties);
|
2016-12-22 16:50:01 +01:00
|
|
|
if (this->node == NULL)
|
|
|
|
|
goto error_no_node;
|
2016-11-10 15:42:14 +01:00
|
|
|
|
2017-04-12 10:40:17 +02:00
|
|
|
impl->proxy.impl = impl;
|
2016-11-10 15:42:14 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
this->resource = pw_resource_new (client,
|
2016-11-24 17:00:42 +01:00
|
|
|
id,
|
2017-03-24 11:40:58 +01:00
|
|
|
client->core->type.client_node,
|
2016-11-24 17:00:42 +01:00
|
|
|
this,
|
2017-05-23 19:15:33 +02:00
|
|
|
(pw_destroy_t) client_node_resource_destroy);
|
2016-12-22 16:50:01 +01:00
|
|
|
if (this->resource == NULL)
|
|
|
|
|
goto error_no_resource;
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2016-12-22 16:50:01 +01:00
|
|
|
impl->proxy.resource = this->resource;
|
2017-01-10 17:12:53 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_signal_add (&this->node->free_signal,
|
2017-01-12 14:57:07 +01:00
|
|
|
&impl->node_free,
|
|
|
|
|
on_node_free);
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_signal_add (&this->node->initialized,
|
2017-04-12 10:40:17 +02:00
|
|
|
&impl->initialized,
|
|
|
|
|
on_initialized);
|
2017-01-10 17:12:53 +01:00
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_signal_add (&this->node->loop_changed,
|
2017-01-10 17:12:53 +01:00
|
|
|
&impl->loop_changed,
|
|
|
|
|
on_loop_changed);
|
|
|
|
|
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_signal_add (&impl->core->global_added,
|
2017-01-10 17:12:53 +01:00
|
|
|
&impl->global_added,
|
|
|
|
|
on_global_added);
|
|
|
|
|
|
2017-03-09 13:00:56 +01:00
|
|
|
this->resource->implementation = &client_node_methods;
|
2016-11-24 17:00:42 +01:00
|
|
|
|
2016-11-10 15:42:14 +01:00
|
|
|
return this;
|
2016-12-22 16:50:01 +01:00
|
|
|
|
|
|
|
|
error_no_resource:
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_node_destroy (this->node);
|
2016-12-22 16:50:01 +01:00
|
|
|
error_no_node:
|
|
|
|
|
proxy_clear (&impl->proxy);
|
|
|
|
|
free (impl);
|
|
|
|
|
return NULL;
|
2016-10-17 12:20:49 +02:00
|
|
|
}
|
|
|
|
|
|
2016-11-25 13:06:23 +01:00
|
|
|
void
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_client_node_destroy (struct pw_client_node * this)
|
2016-11-15 17:06:09 +01:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_resource_destroy (this->resource);
|
2016-11-15 17:06:09 +01:00
|
|
|
}
|
|
|
|
|
|
2016-10-14 19:23:05 +02:00
|
|
|
/**
|
2017-05-23 19:15:33 +02:00
|
|
|
* pw_client_node_get_fds:
|
|
|
|
|
* @node: a #struct pw_client_node
|
2017-04-21 10:24:42 +02:00
|
|
|
* @readfd: an fd for reading
|
|
|
|
|
* @writefd: an fd for writing
|
2016-10-14 19:23:05 +02:00
|
|
|
*
|
2017-04-21 10:24:42 +02:00
|
|
|
* Create or return a previously create set of fds for @node.
|
2016-10-14 19:23:05 +02:00
|
|
|
*
|
2016-11-14 12:42:00 +01:00
|
|
|
* Returns: %SPA_RESULT_OK on success
|
2016-10-14 19:23:05 +02:00
|
|
|
*/
|
2017-05-25 13:28:15 +02:00
|
|
|
int
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_client_node_get_fds (struct pw_client_node *this,
|
2017-04-21 10:24:42 +02:00
|
|
|
int *readfd,
|
|
|
|
|
int *writefd)
|
2016-10-14 19:23:05 +02:00
|
|
|
{
|
2017-05-23 19:15:33 +02:00
|
|
|
struct impl *impl = SPA_CONTAINER_OF (this, struct impl, this);
|
2016-10-14 19:23:05 +02:00
|
|
|
|
2017-04-21 10:24:42 +02:00
|
|
|
if (impl->fds[0] == -1) {
|
|
|
|
|
#if 0
|
|
|
|
|
if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, impl->fds) != 0)
|
2016-11-14 12:42:00 +01:00
|
|
|
return SPA_RESULT_ERRNO;
|
2016-10-14 19:23:05 +02:00
|
|
|
|
2017-04-21 10:24:42 +02:00
|
|
|
impl->proxy.data_source.fd = impl->fds[0];
|
|
|
|
|
impl->proxy.writefd = impl->fds[0];
|
|
|
|
|
impl->other_fds[0] = impl->fds[1];
|
|
|
|
|
impl->other_fds[1] = impl->fds[1];
|
2017-01-18 18:29:15 +01:00
|
|
|
#else
|
2017-04-21 10:24:42 +02:00
|
|
|
impl->fds[0] = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK);
|
|
|
|
|
impl->fds[1] = eventfd (0, EFD_CLOEXEC | EFD_NONBLOCK);
|
|
|
|
|
impl->proxy.data_source.fd = impl->fds[0];
|
|
|
|
|
impl->proxy.writefd = impl->fds[1];
|
|
|
|
|
impl->other_fds[0] = impl->fds[1];
|
|
|
|
|
impl->other_fds[1] = impl->fds[0];
|
2017-01-18 18:29:15 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
spa_loop_add_source (impl->proxy.data_loop, &impl->proxy.data_source);
|
2017-05-23 19:15:33 +02:00
|
|
|
pw_log_debug ("client-node %p: add data fd %d", this, impl->proxy.data_source.fd);
|
2016-10-14 19:23:05 +02:00
|
|
|
}
|
2017-04-21 10:24:42 +02:00
|
|
|
*readfd = impl->other_fds[0];
|
|
|
|
|
*writefd = impl->other_fds[1];
|
|
|
|
|
|
2016-11-14 12:42:00 +01:00
|
|
|
return SPA_RESULT_OK;
|
2016-10-14 19:23:05 +02:00
|
|
|
}
|