mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-16 07:00:00 -05:00
node: remove node state
Remove the node state. The state of the node is based on the state of the ports, which can be derived directly from calling the port methods. Track this state in the Port instead. Add a mixer module that puts a mixer in from of audio sinks. This allows multiple clients to play on one sink (still has some bugs). do some fixes in the mixer and the scheduler to make this work.
This commit is contained in:
parent
28389e05f3
commit
d3682067fa
30 changed files with 618 additions and 509 deletions
|
|
@ -75,7 +75,7 @@ typedef struct {
|
|||
SpaFormat *format;
|
||||
uint32_t n_formats;
|
||||
SpaFormat **formats;
|
||||
void *io;
|
||||
SpaPortIO *io;
|
||||
|
||||
uint32_t n_buffers;
|
||||
ProxyBuffer buffers[MAX_BUFFERS];
|
||||
|
|
@ -129,15 +129,6 @@ typedef struct
|
|||
int data_fd;
|
||||
} PinosClientNodeImpl;
|
||||
|
||||
static void
|
||||
send_async_complete (SpaProxy *this, uint32_t seq, SpaResult res)
|
||||
{
|
||||
PinosCore *core = this->pnode->core;
|
||||
SpaEventNodeAsyncComplete ac = SPA_EVENT_NODE_ASYNC_COMPLETE_INIT (core->type.event_node.AsyncComplete,
|
||||
seq, res);
|
||||
this->event_cb (&this->node, (SpaEvent *)&ac, this->user_data);
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
clear_buffers (SpaProxy *this, SpaProxyPort *port)
|
||||
{
|
||||
|
|
@ -758,7 +749,6 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node,
|
|||
{
|
||||
SpaProxy *this;
|
||||
PinosNode *pnode;
|
||||
//uint64_t cmd = 1;
|
||||
|
||||
if (node == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
|
@ -769,11 +759,11 @@ spa_proxy_node_port_reuse_buffer (SpaNode *node,
|
|||
if (!CHECK_OUT_PORT (this, SPA_DIRECTION_OUTPUT, port_id))
|
||||
return SPA_RESULT_INVALID_PORT;
|
||||
|
||||
spa_log_trace (this->log, "reuse buffer %d", buffer_id);
|
||||
{
|
||||
SpaEventNodeReuseBuffer rb = SPA_EVENT_NODE_REUSE_BUFFER_INIT (pnode->core->type.event_node.ReuseBuffer,
|
||||
port_id, buffer_id);
|
||||
pinos_transport_add_event (pnode->transport, (SpaEvent *)&rb);
|
||||
//write (this->data_source.fd, &cmd, 8);
|
||||
}
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -815,15 +805,23 @@ static SpaResult
|
|||
spa_proxy_node_process_output (SpaNode *node)
|
||||
{
|
||||
SpaProxy *this;
|
||||
int i;
|
||||
|
||||
if (node == NULL)
|
||||
return SPA_RESULT_INVALID_ARGUMENTS;
|
||||
|
||||
this = SPA_CONTAINER_OF (node, SpaProxy, node);
|
||||
|
||||
for (i = 0; i < MAX_OUTPUTS; i++) {
|
||||
SpaPortIO *io = this->out_ports[i].io;
|
||||
if (io && io->buffer_id != SPA_ID_INVALID) {
|
||||
spa_proxy_node_port_reuse_buffer (node, i, io->buffer_id);
|
||||
io->buffer_id = SPA_ID_INVALID;
|
||||
}
|
||||
}
|
||||
send_need_input (this);
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
return SPA_RESULT_HAVE_OUTPUT;
|
||||
}
|
||||
|
||||
static SpaResult
|
||||
|
|
@ -893,22 +891,6 @@ client_node_port_update (void *object,
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
client_node_state_change (void *object,
|
||||
SpaNodeState state)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
PinosClientNode *node = resource->object;
|
||||
PinosClientNodeImpl *impl = SPA_CONTAINER_OF (node, PinosClientNodeImpl, this);
|
||||
SpaProxy *this = &impl->proxy;
|
||||
SpaNodeState old = this->node.state;
|
||||
|
||||
spa_log_info (this->log, "proxy %p: got node state change %d -> %d", this, old, state);
|
||||
this->node.state = state;
|
||||
if (old == SPA_NODE_STATE_INIT)
|
||||
send_async_complete (this, 0, SPA_RESULT_OK);
|
||||
}
|
||||
|
||||
static void
|
||||
client_node_event (void *object,
|
||||
SpaEvent *event)
|
||||
|
|
@ -932,7 +914,6 @@ client_node_destroy (void *object)
|
|||
static PinosClientNodeMethods client_node_methods = {
|
||||
&client_node_update,
|
||||
&client_node_port_update,
|
||||
&client_node_state_change,
|
||||
&client_node_event,
|
||||
&client_node_destroy,
|
||||
};
|
||||
|
|
@ -965,7 +946,6 @@ proxy_on_data_fd_events (SpaSource *source)
|
|||
static const SpaNode proxy_node = {
|
||||
sizeof (SpaNode),
|
||||
NULL,
|
||||
SPA_NODE_STATE_INIT,
|
||||
spa_proxy_node_get_props,
|
||||
spa_proxy_node_set_props,
|
||||
spa_proxy_node_send_command,
|
||||
|
|
@ -1153,6 +1133,7 @@ pinos_client_node_new (PinosClient *client,
|
|||
|
||||
this->node = pinos_node_new (client->core,
|
||||
name,
|
||||
true,
|
||||
&impl->proxy.node,
|
||||
NULL,
|
||||
properties);
|
||||
|
|
|
|||
|
|
@ -543,20 +543,22 @@ pinos_core_find_format (PinosCore *core,
|
|||
SpaFormat **format_filterss,
|
||||
char **error)
|
||||
{
|
||||
SpaNodeState out_state, in_state;
|
||||
uint32_t out_state, in_state;
|
||||
SpaResult res;
|
||||
SpaFormat *filter = NULL, *format;
|
||||
uint32_t iidx = 0, oidx = 0;
|
||||
|
||||
out_state = output->node->node->state;
|
||||
in_state = input->node->node->state;
|
||||
out_state = output->state;
|
||||
in_state = input->state;
|
||||
|
||||
if (out_state > SPA_NODE_STATE_CONFIGURE && output->node->state == PINOS_NODE_STATE_IDLE)
|
||||
out_state = SPA_NODE_STATE_CONFIGURE;
|
||||
if (in_state > SPA_NODE_STATE_CONFIGURE && input->node->state == PINOS_NODE_STATE_IDLE)
|
||||
in_state = SPA_NODE_STATE_CONFIGURE;
|
||||
pinos_log_debug ("core %p: finding best format %d %d", core, out_state, in_state);
|
||||
|
||||
if (in_state == SPA_NODE_STATE_CONFIGURE && out_state > SPA_NODE_STATE_CONFIGURE) {
|
||||
if (out_state > SPA_PORT_STATE_CONFIGURE && output->node->state == PINOS_NODE_STATE_IDLE)
|
||||
out_state = SPA_PORT_STATE_CONFIGURE;
|
||||
if (in_state > SPA_PORT_STATE_CONFIGURE && input->node->state == PINOS_NODE_STATE_IDLE)
|
||||
in_state = SPA_PORT_STATE_CONFIGURE;
|
||||
|
||||
if (in_state == SPA_PORT_STATE_CONFIGURE && out_state > SPA_PORT_STATE_CONFIGURE) {
|
||||
/* only input needs format */
|
||||
if ((res = spa_node_port_get_format (output->node->node,
|
||||
SPA_DIRECTION_OUTPUT,
|
||||
|
|
@ -565,7 +567,7 @@ pinos_core_find_format (PinosCore *core,
|
|||
asprintf (error, "error get output format: %d", res);
|
||||
goto error;
|
||||
}
|
||||
} else if (out_state == SPA_NODE_STATE_CONFIGURE && in_state > SPA_NODE_STATE_CONFIGURE) {
|
||||
} else if (out_state == SPA_PORT_STATE_CONFIGURE && in_state > SPA_PORT_STATE_CONFIGURE) {
|
||||
/* only output needs format */
|
||||
if ((res = spa_node_port_get_format (input->node->node,
|
||||
SPA_DIRECTION_INPUT,
|
||||
|
|
@ -574,7 +576,7 @@ pinos_core_find_format (PinosCore *core,
|
|||
asprintf (error, "error get input format: %d", res);
|
||||
goto error;
|
||||
}
|
||||
} else if (in_state == SPA_NODE_STATE_CONFIGURE && out_state == SPA_NODE_STATE_CONFIGURE) {
|
||||
} else if (in_state == SPA_PORT_STATE_CONFIGURE && out_state == SPA_PORT_STATE_CONFIGURE) {
|
||||
again:
|
||||
/* both ports need a format */
|
||||
pinos_log_debug ("core %p: finding best format", core);
|
||||
|
|
|
|||
|
|
@ -76,14 +76,14 @@ pinos_link_update_state (PinosLink *link,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
||||
do_negotiate (PinosLink *this, uint32_t in_state, uint32_t out_state)
|
||||
{
|
||||
PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this);
|
||||
SpaResult res = SPA_RESULT_ERROR, res2;
|
||||
SpaFormat *format;
|
||||
char *error = NULL;
|
||||
|
||||
if (in_state != SPA_NODE_STATE_CONFIGURE && out_state != SPA_NODE_STATE_CONFIGURE)
|
||||
if (in_state != SPA_PORT_STATE_CONFIGURE && out_state != SPA_PORT_STATE_CONFIGURE)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_NEGOTIATING, NULL);
|
||||
|
|
@ -98,20 +98,20 @@ do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
if (format == NULL)
|
||||
goto error;
|
||||
|
||||
if (out_state > SPA_NODE_STATE_CONFIGURE && this->output->node->state == PINOS_NODE_STATE_IDLE) {
|
||||
if (out_state > SPA_PORT_STATE_CONFIGURE && this->output->node->state == PINOS_NODE_STATE_IDLE) {
|
||||
pinos_node_set_state (this->output->node, PINOS_NODE_STATE_SUSPENDED);
|
||||
out_state = SPA_NODE_STATE_CONFIGURE;
|
||||
out_state = SPA_PORT_STATE_CONFIGURE;
|
||||
}
|
||||
if (in_state > SPA_NODE_STATE_CONFIGURE && this->input->node->state == PINOS_NODE_STATE_IDLE) {
|
||||
if (in_state > SPA_PORT_STATE_CONFIGURE && this->input->node->state == PINOS_NODE_STATE_IDLE) {
|
||||
pinos_node_set_state (this->input->node, PINOS_NODE_STATE_SUSPENDED);
|
||||
in_state = SPA_NODE_STATE_CONFIGURE;
|
||||
in_state = SPA_PORT_STATE_CONFIGURE;
|
||||
}
|
||||
|
||||
pinos_log_debug ("link %p: doing set format", this);
|
||||
if (pinos_log_level_enabled (SPA_LOG_LEVEL_DEBUG))
|
||||
spa_debug_format (format, this->core->type.map);
|
||||
|
||||
if (out_state == SPA_NODE_STATE_CONFIGURE) {
|
||||
if (out_state == SPA_PORT_STATE_CONFIGURE) {
|
||||
pinos_log_debug ("link %p: doing set format on output", this);
|
||||
if ((res = spa_node_port_set_format (this->output->node->node,
|
||||
SPA_DIRECTION_OUTPUT,
|
||||
|
|
@ -121,9 +121,10 @@ do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
asprintf (&error, "error set output format: %d", res);
|
||||
goto error;
|
||||
}
|
||||
this->output->state = SPA_PORT_STATE_READY;
|
||||
pinos_work_queue_add (impl->work, this->output->node, res, NULL, NULL);
|
||||
}
|
||||
if (in_state == SPA_NODE_STATE_CONFIGURE) {
|
||||
if (in_state == SPA_PORT_STATE_CONFIGURE) {
|
||||
pinos_log_debug ("link %p: doing set format on input", this);
|
||||
if ((res2 = spa_node_port_set_format (this->input->node->node,
|
||||
SPA_DIRECTION_INPUT,
|
||||
|
|
@ -133,6 +134,7 @@ do_negotiate (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
asprintf (&error, "error set input format: %d", res2);
|
||||
goto error;
|
||||
}
|
||||
this->input->state = SPA_PORT_STATE_READY;
|
||||
pinos_work_queue_add (impl->work, this->input->node, res2, NULL, NULL);
|
||||
res = res2 != SPA_RESULT_OK ? res2 : res;
|
||||
}
|
||||
|
|
@ -322,7 +324,7 @@ alloc_buffers (PinosLink *this,
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
||||
do_allocation (PinosLink *this, uint32_t in_state, uint32_t out_state)
|
||||
{
|
||||
PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this);
|
||||
SpaResult res;
|
||||
|
|
@ -330,7 +332,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
SpaPortInfoFlags in_flags, out_flags;
|
||||
char *error = NULL;
|
||||
|
||||
if (in_state != SPA_NODE_STATE_READY && out_state != SPA_NODE_STATE_READY)
|
||||
if (in_state != SPA_PORT_STATE_READY && out_state != SPA_PORT_STATE_READY)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_ALLOCATING, NULL);
|
||||
|
|
@ -361,7 +363,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
this->input->node->live = true;
|
||||
}
|
||||
|
||||
if (in_state == SPA_NODE_STATE_READY && out_state == SPA_NODE_STATE_READY) {
|
||||
if (in_state == SPA_PORT_STATE_READY && out_state == SPA_PORT_STATE_READY) {
|
||||
if ((out_flags & SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS) &&
|
||||
(in_flags & SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS)) {
|
||||
out_flags = SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
|
|
@ -383,10 +385,10 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
res = SPA_RESULT_ERROR;
|
||||
goto error;
|
||||
}
|
||||
} else if (in_state == SPA_NODE_STATE_READY && out_state > SPA_NODE_STATE_READY) {
|
||||
} else if (in_state == SPA_PORT_STATE_READY && out_state > SPA_PORT_STATE_READY) {
|
||||
out_flags &= ~SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
||||
in_flags &= ~SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
} else if (out_state == SPA_NODE_STATE_READY && in_state > SPA_NODE_STATE_READY) {
|
||||
} else if (out_state == SPA_PORT_STATE_READY && in_state > SPA_PORT_STATE_READY) {
|
||||
in_flags &= ~SPA_PORT_INFO_FLAG_CAN_USE_BUFFERS;
|
||||
out_flags &= ~SPA_PORT_INFO_FLAG_CAN_ALLOC_BUFFERS;
|
||||
} else {
|
||||
|
|
@ -505,6 +507,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
asprintf (&error, "error alloc output buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
this->output->state = SPA_PORT_STATE_PAUSED;
|
||||
pinos_work_queue_add (impl->work, this->output->node, res, NULL, NULL);
|
||||
this->output->buffers = impl->buffers;
|
||||
this->output->n_buffers = impl->n_buffers;
|
||||
|
|
@ -521,6 +524,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
asprintf (&error, "error alloc input buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
this->input->state = SPA_PORT_STATE_PAUSED;
|
||||
pinos_work_queue_add (impl->work, this->input->node, res, NULL, NULL);
|
||||
this->input->buffers = impl->buffers;
|
||||
this->input->n_buffers = impl->n_buffers;
|
||||
|
|
@ -541,6 +545,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
asprintf (&error, "error use input buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
this->input->state = SPA_PORT_STATE_PAUSED;
|
||||
pinos_work_queue_add (impl->work, this->input->node, res, NULL, NULL);
|
||||
this->input->buffers = impl->buffers;
|
||||
this->input->n_buffers = impl->n_buffers;
|
||||
|
|
@ -556,6 +561,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
asprintf (&error, "error use output buffers: %d", res);
|
||||
goto error;
|
||||
}
|
||||
this->output->state = SPA_PORT_STATE_PAUSED;
|
||||
pinos_work_queue_add (impl->work, this->output->node, res, NULL, NULL);
|
||||
this->output->buffers = impl->buffers;
|
||||
this->output->n_buffers = impl->n_buffers;
|
||||
|
|
@ -581,24 +587,26 @@ error:
|
|||
}
|
||||
|
||||
static SpaResult
|
||||
do_start (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
||||
do_start (PinosLink *this, uint32_t in_state, uint32_t out_state)
|
||||
{
|
||||
SpaResult res = SPA_RESULT_OK;
|
||||
PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this);
|
||||
|
||||
if (in_state < SPA_NODE_STATE_PAUSED || out_state < SPA_NODE_STATE_PAUSED)
|
||||
if (in_state < SPA_PORT_STATE_PAUSED || out_state < SPA_PORT_STATE_PAUSED)
|
||||
return SPA_RESULT_OK;
|
||||
else if (in_state == SPA_NODE_STATE_STREAMING && out_state == SPA_NODE_STATE_STREAMING) {
|
||||
else if (in_state == SPA_PORT_STATE_STREAMING && out_state == SPA_PORT_STATE_STREAMING) {
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_RUNNING, NULL);
|
||||
} else {
|
||||
pinos_link_update_state (this, PINOS_LINK_STATE_PAUSED, NULL);
|
||||
|
||||
if (in_state == SPA_NODE_STATE_PAUSED) {
|
||||
if (in_state == SPA_PORT_STATE_PAUSED) {
|
||||
res = pinos_node_set_state (this->input->node, PINOS_NODE_STATE_RUNNING);
|
||||
pinos_work_queue_add (impl->work, this->input->node, res, NULL, NULL);
|
||||
this->input->state = SPA_PORT_STATE_STREAMING;
|
||||
}
|
||||
if (out_state == SPA_NODE_STATE_PAUSED) {
|
||||
if (out_state == SPA_PORT_STATE_PAUSED) {
|
||||
res = pinos_node_set_state (this->output->node, PINOS_NODE_STATE_RUNNING);
|
||||
this->output->state = SPA_PORT_STATE_STREAMING;
|
||||
pinos_work_queue_add (impl->work, this->input->node, res, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
|
@ -611,7 +619,7 @@ check_states (PinosLink *this,
|
|||
SpaResult res)
|
||||
{
|
||||
PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this);
|
||||
SpaNodeState in_state, out_state;
|
||||
uint32_t in_state, out_state;
|
||||
|
||||
again:
|
||||
if (this->state == PINOS_LINK_STATE_ERROR)
|
||||
|
|
@ -624,8 +632,8 @@ again:
|
|||
this->output->node->state == PINOS_NODE_STATE_ERROR)
|
||||
return SPA_RESULT_ERROR;
|
||||
|
||||
in_state = this->input->node->node->state;
|
||||
out_state = this->output->node->node->state;
|
||||
in_state = this->input->state;
|
||||
out_state = this->output->state;
|
||||
|
||||
pinos_log_debug ("link %p: input state %d, output state %d", this, in_state, out_state);
|
||||
|
||||
|
|
@ -638,9 +646,9 @@ again:
|
|||
if ((res = do_start (this, in_state, out_state)) != SPA_RESULT_OK)
|
||||
goto exit;
|
||||
|
||||
if (this->input->node->node->state != in_state)
|
||||
if (this->input->state != in_state)
|
||||
goto again;
|
||||
if (this->output->node->node->state != out_state)
|
||||
if (this->output->state != out_state)
|
||||
goto again;
|
||||
|
||||
return SPA_RESULT_OK;
|
||||
|
|
@ -737,6 +745,7 @@ pinos_link_activate (PinosLink *this)
|
|||
{
|
||||
PinosLinkImpl *impl = SPA_CONTAINER_OF (this, PinosLinkImpl, this);
|
||||
|
||||
pinos_log_debug ("link %p: activate", this);
|
||||
pinos_work_queue_add (impl->work,
|
||||
this,
|
||||
SPA_RESULT_WAIT_SYNC,
|
||||
|
|
@ -902,6 +911,7 @@ clear_port_buffers (PinosLink *link, PinosPort *port)
|
|||
port->direction,
|
||||
port->port_id,
|
||||
NULL, 0);
|
||||
port->state = SPA_PORT_STATE_READY;
|
||||
port->buffers = NULL;
|
||||
port->n_buffers = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,9 @@ typedef struct
|
|||
{
|
||||
PinosNode this;
|
||||
|
||||
#define STATE_IN 0
|
||||
#define STATE_OUT 1
|
||||
int state;
|
||||
PinosWorkQueue *work;
|
||||
|
||||
bool async_init;
|
||||
|
|
@ -41,13 +44,14 @@ typedef struct
|
|||
static void init_complete (PinosNode *this);
|
||||
|
||||
static void
|
||||
update_port_ids (PinosNode *node, bool create)
|
||||
update_port_ids (PinosNode *node)
|
||||
{
|
||||
PinosNodeImpl *impl = SPA_CONTAINER_OF (node, PinosNodeImpl, this);
|
||||
uint32_t *input_port_ids, *output_port_ids;
|
||||
uint32_t n_input_ports, n_output_ports, max_input_ports, max_output_ports;
|
||||
uint32_t i;
|
||||
SpaList *ports;
|
||||
SpaResult res;
|
||||
|
||||
if (node->node == NULL)
|
||||
return;
|
||||
|
|
@ -58,6 +62,15 @@ update_port_ids (PinosNode *node, bool create)
|
|||
&n_output_ports,
|
||||
&max_output_ports);
|
||||
|
||||
node->transport = pinos_transport_new (max_input_ports,
|
||||
max_output_ports);
|
||||
|
||||
node->input_port_map = calloc (max_input_ports, sizeof (PinosPort *));
|
||||
node->output_port_map = calloc (max_output_ports, sizeof (PinosPort *));
|
||||
|
||||
node->transport->area->n_inputs = n_input_ports;
|
||||
node->transport->area->n_outputs = n_output_ports;
|
||||
|
||||
input_port_ids = alloca (sizeof (uint32_t) * n_input_ports);
|
||||
output_port_ids = alloca (sizeof (uint32_t) * n_output_ports);
|
||||
|
||||
|
|
@ -67,9 +80,6 @@ update_port_ids (PinosNode *node, bool create)
|
|||
max_output_ports,
|
||||
output_port_ids);
|
||||
|
||||
node->input_port_map = realloc (node->input_port_map, sizeof (PinosPort *) * max_input_ports);
|
||||
node->output_port_map = realloc (node->output_port_map, sizeof (PinosPort *) * max_output_ports);
|
||||
|
||||
pinos_log_debug ("node %p: update_port ids %u/%u, %u/%u", node,
|
||||
n_input_ports, max_input_ports, n_output_ports, max_output_ports);
|
||||
|
||||
|
|
@ -88,6 +98,10 @@ update_port_ids (PinosNode *node, bool create)
|
|||
pinos_log_debug ("node %p: input port added %d", node, input_port_ids[i]);
|
||||
|
||||
np = pinos_port_new (node, PINOS_DIRECTION_INPUT, input_port_ids[i]);
|
||||
np->io = &node->transport->inputs[np->port_id];
|
||||
if ((res = spa_node_port_set_io (node->node, SPA_DIRECTION_INPUT, np->port_id, np->io)) < 0)
|
||||
pinos_log_warn ("node %p: can't set input IO %d", node, res);
|
||||
|
||||
spa_list_insert (ports, &np->link);
|
||||
ports = np->link.next;
|
||||
node->input_port_map[np->port_id] = np;
|
||||
|
|
@ -123,6 +137,10 @@ update_port_ids (PinosNode *node, bool create)
|
|||
pinos_log_debug ("node %p: output port added %d", node, output_port_ids[i]);
|
||||
|
||||
np = pinos_port_new (node, PINOS_DIRECTION_OUTPUT, output_port_ids[i]);
|
||||
np->io = &node->transport->outputs[np->port_id];
|
||||
if ((res = spa_node_port_set_io (node->node, SPA_DIRECTION_OUTPUT, np->port_id, np->io)) < 0)
|
||||
pinos_log_warn ("node %p: can't set output IO %d", node, res);
|
||||
|
||||
spa_list_insert (ports, &np->link);
|
||||
ports = np->link.next;
|
||||
node->output_port_map[np->port_id] = np;
|
||||
|
|
@ -143,17 +161,6 @@ update_port_ids (PinosNode *node, bool create)
|
|||
}
|
||||
}
|
||||
|
||||
node->transport = pinos_transport_new (max_input_ports,
|
||||
max_output_ports);
|
||||
|
||||
node->transport->area->n_inputs = n_input_ports;
|
||||
node->transport->area->n_outputs = n_output_ports;
|
||||
|
||||
for (i = 0; i < max_input_ports; i++)
|
||||
spa_node_port_set_io (node->node, SPA_DIRECTION_INPUT, i, &node->transport->inputs[i]);
|
||||
for (i = 0; i < max_output_ports; i++)
|
||||
spa_node_port_set_io (node->node, SPA_DIRECTION_OUTPUT, i, &node->transport->outputs[i]);
|
||||
|
||||
pinos_signal_emit (&node->transport_changed, node);
|
||||
}
|
||||
|
||||
|
|
@ -162,9 +169,6 @@ pause_node (PinosNode *this)
|
|||
{
|
||||
SpaResult res;
|
||||
|
||||
if (this->node->state <= SPA_NODE_STATE_PAUSED)
|
||||
return SPA_RESULT_OK;
|
||||
|
||||
pinos_log_debug ("node %p: pause node", this);
|
||||
{
|
||||
SpaCommand cmd = SPA_COMMAND_INIT (this->core->type.command_node.Pause);
|
||||
|
|
@ -267,7 +271,8 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
|
|||
else if (SPA_EVENT_TYPE (event) == this->core->type.event_node.NeedInput) {
|
||||
SpaResult res;
|
||||
int i;
|
||||
bool processed = false;
|
||||
|
||||
this->sched_state = STATE_IN;
|
||||
|
||||
for (i = 0; i < this->transport->area->n_inputs; i++) {
|
||||
PinosLink *link;
|
||||
|
|
@ -276,8 +281,7 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
|
|||
SpaPortIO *po;
|
||||
|
||||
pi = &this->transport->inputs[i];
|
||||
if (pi->buffer_id != SPA_ID_INVALID)
|
||||
continue;
|
||||
pinos_log_trace ("node %p: need input port %d, %d", this, i, pi->buffer_id);
|
||||
|
||||
inport = this->input_port_map[i];
|
||||
spa_list_for_each (link, &inport->rt.links, rt.input_link) {
|
||||
|
|
@ -287,23 +291,58 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
|
|||
outport = link->rt.output;
|
||||
po = &outport->node->transport->outputs[outport->port_id];
|
||||
|
||||
if (po->buffer_id != SPA_ID_INVALID) {
|
||||
processed = true;
|
||||
if (outport->node->sched_state == STATE_IN) {
|
||||
/* pull */
|
||||
*po = *pi;
|
||||
pi->buffer_id = SPA_ID_INVALID;
|
||||
|
||||
pinos_log_trace ("node %p: process output %p %d", outport->node, po, po->buffer_id);
|
||||
|
||||
res = spa_node_process_output (outport->node->node);
|
||||
|
||||
if (res == SPA_RESULT_NEED_INPUT) {
|
||||
on_node_event (outport->node->node, event, outport->node);
|
||||
if (outport->node->sched_state == STATE_OUT)
|
||||
goto push;
|
||||
}
|
||||
else if (res == SPA_RESULT_HAVE_OUTPUT) {
|
||||
outport->node->sched_state = STATE_OUT;
|
||||
}
|
||||
else
|
||||
pinos_log_warn ("node %p: got process output %d", outport->node, res);
|
||||
} else {
|
||||
/* push */
|
||||
push:
|
||||
*pi = *po;
|
||||
|
||||
pinos_log_trace ("node %p: process output %p %d", outport->node, po, po->buffer_id);
|
||||
|
||||
res = spa_node_process_output (outport->node->node);
|
||||
|
||||
if (res == SPA_RESULT_HAVE_OUTPUT)
|
||||
outport->node->sched_state = STATE_OUT;
|
||||
else if (res == SPA_RESULT_NEED_INPUT)
|
||||
outport->node->sched_state = STATE_IN;
|
||||
else if (res < 0)
|
||||
pinos_log_warn ("node %p: got process output %d", this, res);
|
||||
}
|
||||
if ((res = spa_node_process_output (outport->node->node)) < 0)
|
||||
pinos_log_warn ("node %p: got process output %d", outport->node, res);
|
||||
}
|
||||
}
|
||||
if (processed) {
|
||||
if ((res = spa_node_process_input (this->node)) < 0)
|
||||
pinos_log_warn ("node %p: got process input %d", this, res);
|
||||
if (pi->buffer_id != SPA_ID_INVALID) {
|
||||
pinos_log_trace ("node %p: process input", this);
|
||||
res = spa_node_process_input (this->node);
|
||||
|
||||
if (res == SPA_RESULT_HAVE_OUTPUT)
|
||||
this->sched_state = STATE_OUT;
|
||||
else if (res == SPA_RESULT_NEED_INPUT)
|
||||
this->sched_state = STATE_IN;
|
||||
else if (res < 0)
|
||||
pinos_log_warn ("node %p: got process input %d", this, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (SPA_EVENT_TYPE (event) == this->core->type.event_node.HaveOutput) {
|
||||
SpaResult res;
|
||||
int i;
|
||||
bool processed = false;
|
||||
|
||||
for (i = 0; i < this->transport->area->n_outputs; i++) {
|
||||
PinosLink *link;
|
||||
|
|
@ -327,13 +366,36 @@ on_node_event (SpaNode *node, SpaEvent *event, void *user_data)
|
|||
if ((res = spa_node_process_input (inport->node->node)) < 0)
|
||||
pinos_log_warn ("node %p: got process input %d", inport->node, res);
|
||||
}
|
||||
processed = true;
|
||||
}
|
||||
if (processed) {
|
||||
if ((res = spa_node_process_output (this->node)) < 0)
|
||||
pinos_log_warn ("node %p: got process output %d", this, res);
|
||||
if ((res = spa_node_process_output (this->node)) < 0)
|
||||
pinos_log_warn ("node %p: got process output %d", this, res);
|
||||
|
||||
}
|
||||
#if 0
|
||||
else if (SPA_EVENT_TYPE (event) == this->core->type.event_node.ReuseBuffer) {
|
||||
SpaEventNodeReuseBuffer *rb = (SpaEventNodeReuseBuffer *) event;
|
||||
int i;
|
||||
|
||||
pinos_log_trace ("node %p: reuse buffer %u", this, rb->body.buffer_id.value);
|
||||
|
||||
for (i = 0; i < this->transport->area->n_inputs; i++) {
|
||||
PinosLink *link;
|
||||
PinosPort *inport, *outport;
|
||||
SpaPortIO *po;
|
||||
|
||||
inport = this->input_port_map[i];
|
||||
spa_list_for_each (link, &inport->rt.links, rt.input_link) {
|
||||
if (link->rt.input == NULL || link->rt.output == NULL)
|
||||
continue;
|
||||
|
||||
outport = link->rt.output;
|
||||
po = &outport->node->transport->outputs[outport->port_id];
|
||||
|
||||
po->buffer_id = rb->body.buffer_id.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
else if (SPA_EVENT_TYPE (event) == this->core->type.event_node.RequestClockUpdate) {
|
||||
send_clock_update (this);
|
||||
}
|
||||
|
|
@ -440,7 +502,7 @@ init_complete (PinosNode *this)
|
|||
{
|
||||
PinosNodeImpl *impl = SPA_CONTAINER_OF (this, PinosNodeImpl, this);
|
||||
|
||||
update_port_ids (this, false);
|
||||
update_port_ids (this);
|
||||
pinos_log_debug ("node %p: init completed", this);
|
||||
impl->async_init = false;
|
||||
|
||||
|
|
@ -466,6 +528,7 @@ pinos_node_set_data_loop (PinosNode *node,
|
|||
PinosNode *
|
||||
pinos_node_new (PinosCore *core,
|
||||
const char *name,
|
||||
bool async,
|
||||
SpaNode *node,
|
||||
SpaClock *clock,
|
||||
PinosProperties *properties)
|
||||
|
|
@ -525,15 +588,15 @@ pinos_node_new (PinosCore *core,
|
|||
this->node->info->items[i].value);
|
||||
}
|
||||
|
||||
if (this->node->state > SPA_NODE_STATE_INIT) {
|
||||
init_complete (this);
|
||||
} else {
|
||||
impl->async_init = true;
|
||||
impl->async_init = async;
|
||||
if (async) {
|
||||
pinos_work_queue_add (impl->work,
|
||||
this,
|
||||
SPA_RESULT_RETURN_ASYNC (0),
|
||||
(PinosWorkFunc) init_complete,
|
||||
NULL);
|
||||
} else {
|
||||
init_complete (this);
|
||||
}
|
||||
|
||||
return this;
|
||||
|
|
@ -668,21 +731,27 @@ PinosPort *
|
|||
pinos_node_get_free_port (PinosNode *node,
|
||||
PinosDirection direction)
|
||||
{
|
||||
uint32_t n_ports, max_ports;
|
||||
uint32_t *n_ports, max_ports;
|
||||
SpaList *ports;
|
||||
PinosPort *port = NULL, *p;
|
||||
PinosPort *port = NULL, *p, **portmap;
|
||||
SpaPortIO *io;
|
||||
int i;
|
||||
|
||||
if (direction == PINOS_DIRECTION_INPUT) {
|
||||
max_ports = node->transport->area->max_inputs;
|
||||
n_ports = node->transport->area->n_inputs;
|
||||
n_ports = &node->transport->area->n_inputs;
|
||||
ports = &node->input_ports;
|
||||
portmap = node->input_port_map;
|
||||
io = node->transport->inputs;
|
||||
} else {
|
||||
max_ports = node->transport->area->max_outputs;
|
||||
n_ports = node->transport->area->n_outputs;
|
||||
n_ports = &node->transport->area->n_outputs;
|
||||
ports = &node->output_ports;
|
||||
portmap = node->output_port_map;
|
||||
io = node->transport->outputs;
|
||||
}
|
||||
|
||||
pinos_log_debug ("node %p: direction %d max %u, n %u", node, direction, max_ports, n_ports);
|
||||
pinos_log_debug ("node %p: direction %d max %u, n %u", node, direction, max_ports, *n_ports);
|
||||
|
||||
spa_list_for_each (p, ports, link) {
|
||||
if (spa_list_is_empty (&p->links)) {
|
||||
|
|
@ -691,9 +760,26 @@ pinos_node_get_free_port (PinosNode *node,
|
|||
}
|
||||
}
|
||||
|
||||
if (port == NULL && !spa_list_is_empty (ports))
|
||||
port = spa_list_first (ports, PinosPort, link);
|
||||
|
||||
if (port == NULL) {
|
||||
/* no port, can we create one ? */
|
||||
if (*n_ports < max_ports) {
|
||||
for (i = 0; i < max_ports && port == NULL; i++) {
|
||||
if (portmap[i] == NULL) {
|
||||
pinos_log_debug ("node %p: creating port direction %d %u", node, direction, i);
|
||||
port = portmap[i] = pinos_port_new (node, direction, i);
|
||||
port->io = &io[i];
|
||||
(*n_ports)++;
|
||||
spa_node_add_port (node->node, direction, i);
|
||||
spa_node_port_set_io (node->node, direction, i, port->io);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* for output we can reuse an existing port */
|
||||
if (direction == PINOS_DIRECTION_OUTPUT && !spa_list_is_empty (ports)) {
|
||||
port = spa_list_first (ports, PinosPort, link);
|
||||
}
|
||||
}
|
||||
}
|
||||
return port;
|
||||
|
||||
}
|
||||
|
|
@ -714,6 +800,22 @@ on_state_complete (PinosNode *node,
|
|||
pinos_node_update_state (node, state, error);
|
||||
}
|
||||
|
||||
static void
|
||||
node_activate (PinosNode *this)
|
||||
{
|
||||
PinosPort *port;
|
||||
|
||||
spa_list_for_each (port, &this->input_ports, link) {
|
||||
PinosLink *link;
|
||||
spa_list_for_each (link, &port->links, input_link)
|
||||
pinos_link_activate (link);
|
||||
}
|
||||
spa_list_for_each (port, &this->output_ports, link) {
|
||||
PinosLink *link;
|
||||
spa_list_for_each (link, &port->links, output_link)
|
||||
pinos_link_activate (link);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* pinos_node_set_state:
|
||||
* @node: a #PinosNode
|
||||
|
|
@ -747,6 +849,7 @@ pinos_node_set_state (PinosNode *node,
|
|||
break;
|
||||
|
||||
case PINOS_NODE_STATE_RUNNING:
|
||||
node_activate (node);
|
||||
send_clock_update (node);
|
||||
res = start_node (node);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ struct _PinosNode {
|
|||
SpaNode *node;
|
||||
bool live;
|
||||
SpaClock *clock;
|
||||
int sched_state;
|
||||
|
||||
SpaList resource_list;
|
||||
|
||||
|
|
@ -107,6 +108,7 @@ struct _PinosNode {
|
|||
|
||||
PinosNode * pinos_node_new (PinosCore *core,
|
||||
const char *name,
|
||||
bool async,
|
||||
SpaNode *node,
|
||||
SpaClock *clock,
|
||||
PinosProperties *properties);
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ pinos_port_new (PinosNode *node,
|
|||
this->node = node;
|
||||
this->direction = direction;
|
||||
this->port_id = port_id;
|
||||
this->state = SPA_PORT_STATE_CONFIGURE;
|
||||
|
||||
spa_list_init (&this->links);
|
||||
spa_list_init (&this->rt.links);
|
||||
|
|
@ -200,6 +201,7 @@ static SpaResult
|
|||
pinos_port_pause (PinosPort *port)
|
||||
{
|
||||
SpaCommand cmd = SPA_COMMAND_INIT (port->node->core->type.command_node.Pause);
|
||||
port->state = SPA_PORT_STATE_PAUSED;
|
||||
return spa_node_port_send_command (port->node->node,
|
||||
port->direction,
|
||||
port->port_id,
|
||||
|
|
@ -239,6 +241,7 @@ do_remove_link_done (SpaLoop *loop,
|
|||
port->direction,
|
||||
port->port_id,
|
||||
NULL, 0);
|
||||
port->state = SPA_PORT_STATE_READY;
|
||||
port->buffers = NULL;
|
||||
port->n_buffers = 0;
|
||||
}
|
||||
|
|
@ -315,6 +318,7 @@ do_clear_buffers_done (SpaLoop *loop,
|
|||
port->direction,
|
||||
port->port_id,
|
||||
NULL, 0);
|
||||
port->state = SPA_PORT_STATE_READY;
|
||||
port->buffers = NULL;
|
||||
port->n_buffers = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,8 @@ struct _PinosPort {
|
|||
PinosNode *node;
|
||||
PinosDirection direction;
|
||||
uint32_t port_id;
|
||||
uint32_t state;
|
||||
SpaPortIO *io;
|
||||
|
||||
bool allocated;
|
||||
PinosMemblock buffer_mem;
|
||||
|
|
|
|||
|
|
@ -898,23 +898,6 @@ client_node_demarshal_port_update (void *object,
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
client_node_demarshal_state_change (void *object,
|
||||
void *data,
|
||||
size_t size)
|
||||
{
|
||||
PinosResource *resource = object;
|
||||
SpaPODIter it;
|
||||
uint32_t state;
|
||||
|
||||
if (!spa_pod_iter_struct (&it, data, size) ||
|
||||
!spa_pod_iter_get (&it, SPA_POD_TYPE_INT, &state, 0))
|
||||
return false;
|
||||
|
||||
((PinosClientNodeMethods*)resource->implementation)->state_change (resource, state);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
client_node_demarshal_event (void *object,
|
||||
void *data,
|
||||
|
|
@ -1035,7 +1018,6 @@ const PinosInterface pinos_protocol_native_server_client_interface = {
|
|||
static const PinosDemarshalFunc pinos_protocol_native_server_client_node_demarshal[] = {
|
||||
&client_node_demarshal_update,
|
||||
&client_node_demarshal_port_update,
|
||||
&client_node_demarshal_state_change,
|
||||
&client_node_demarshal_event,
|
||||
&client_node_demarshal_destroy,
|
||||
};
|
||||
|
|
@ -1055,7 +1037,7 @@ static const PinosClientNodeEvents pinos_protocol_native_server_client_node_even
|
|||
};
|
||||
|
||||
const PinosInterface pinos_protocol_native_server_client_node_interface = {
|
||||
5, &pinos_protocol_native_server_client_node_demarshal,
|
||||
4, &pinos_protocol_native_server_client_node_demarshal,
|
||||
11, &pinos_protocol_native_server_client_node_events,
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue