improve node io

Unify input and output io areas.
Add support for ranges in the io area.
Automatically recycle buffers in the output areas in process_output
Improve the mixer, add use_buffer support, use a queue of input buffers,
fix mixing, add support for ranges.
Fix mixer and v4l2 tests
This commit is contained in:
Wim Taymans 2017-04-03 14:56:04 +02:00
parent 29fbf2e841
commit 01c13adab5
28 changed files with 983 additions and 747 deletions

View file

@ -576,9 +576,10 @@ spa_alsa_sink_node_port_alloc_buffers (SpaNode *node,
}
static SpaResult
spa_alsa_sink_node_port_set_input (SpaNode *node,
uint32_t port_id,
SpaPortInput *input)
spa_alsa_sink_node_port_set_io (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaPortIO *io)
{
SpaALSASink *this;
@ -587,22 +588,14 @@ spa_alsa_sink_node_port_set_input (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaALSASink, node);
if (!CHECK_PORT (this, SPA_DIRECTION_INPUT, port_id))
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
this->io = input;
this->io = io;
return SPA_RESULT_OK;
}
static SpaResult
spa_alsa_sink_node_port_set_output (SpaNode *node,
uint32_t port_id,
SpaPortOutput *output)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static SpaResult
spa_alsa_sink_node_port_reuse_buffer (SpaNode *node,
uint32_t port_id,
@ -648,7 +641,7 @@ static SpaResult
spa_alsa_sink_node_process_input (SpaNode *node)
{
SpaALSASink *this;
SpaPortInput *input;
SpaPortIO *input;
SpaALSABuffer *b;
if (node == NULL)
@ -680,8 +673,8 @@ spa_alsa_sink_node_process_input (SpaNode *node)
this->ringbuffer = b;
} else {
spa_list_insert (this->ready.prev, &b->link);
spa_log_trace (this->log, "alsa-sink %p: queue buffer %u", this, input->buffer_id);
}
//spa_log_debug (this->log, "alsa-source: got buffer %u", input->buffer_id);
b->outstanding = false;
input->buffer_id = SPA_ID_INVALID;
input->status = SPA_RESULT_OK;
@ -716,8 +709,7 @@ static const SpaNode alsasink_node = {
spa_alsa_sink_node_port_set_props,
spa_alsa_sink_node_port_use_buffers,
spa_alsa_sink_node_port_alloc_buffers,
spa_alsa_sink_node_port_set_input,
spa_alsa_sink_node_port_set_output,
spa_alsa_sink_node_port_set_io,
spa_alsa_sink_node_port_reuse_buffer,
spa_alsa_sink_node_port_send_command,
spa_alsa_sink_node_process_input,
@ -779,7 +771,15 @@ alsa_sink_init (const SpaHandleFactory *factory,
this->main_loop = support[i].data;
}
if (this->map == NULL) {
spa_log_error (this->log, "an id-map is needed");
spa_log_error (this->log, "a type-map is needed");
return SPA_RESULT_ERROR;
}
if (this->data_loop == NULL) {
spa_log_error (this->log, "a data loop is needed");
return SPA_RESULT_ERROR;
}
if (this->main_loop == NULL) {
spa_log_error (this->log, "a main loop is needed");
return SPA_RESULT_ERROR;
}
init_type (&this->type, this->map);

View file

@ -369,8 +369,7 @@ recycle_buffer (SpaALSASource *this, uint32_t buffer_id)
SpaALSABuffer *b;
b = &this->buffers[buffer_id];
if (!b->outstanding)
return;
spa_return_if_fail (b->outstanding);
b->outstanding = false;
spa_list_insert (this->free.prev, &b->link);
@ -616,17 +615,10 @@ spa_alsa_source_node_port_alloc_buffers (SpaNode *node,
}
static SpaResult
spa_alsa_source_node_port_set_input (SpaNode *node,
uint32_t port_id,
SpaPortInput *input)
{
return SPA_RESULT_NOT_IMPLEMENTED;
}
static SpaResult
spa_alsa_source_node_port_set_output (SpaNode *node,
uint32_t port_id,
SpaPortOutput *output)
spa_alsa_source_node_port_set_io (SpaNode *node,
SpaDirection direction,
uint32_t port_id,
SpaPortIO *io)
{
SpaALSASource *this;
@ -635,10 +627,10 @@ spa_alsa_source_node_port_set_output (SpaNode *node,
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
if (!CHECK_PORT (this, SPA_DIRECTION_OUTPUT, port_id))
if (!CHECK_PORT (this, direction, port_id))
return SPA_RESULT_INVALID_PORT;
this->io = output;
this->io = io;
return SPA_RESULT_OK;
}
@ -710,6 +702,17 @@ spa_alsa_source_node_process_input (SpaNode *node)
static SpaResult
spa_alsa_source_node_process_output (SpaNode *node)
{
SpaALSASource *this;
SpaPortIO *io;
spa_return_val_if_fail (node != NULL, SPA_RESULT_INVALID_ARGUMENTS);
this = SPA_CONTAINER_OF (node, SpaALSASource, node);
if ((io = this->io) && io->buffer_id != SPA_ID_INVALID) {
recycle_buffer (this, io->buffer_id);
io->buffer_id = SPA_ID_INVALID;
}
return SPA_RESULT_OK;
}
@ -733,8 +736,7 @@ static const SpaNode alsasource_node = {
spa_alsa_source_node_port_set_props,
spa_alsa_source_node_port_use_buffers,
spa_alsa_source_node_port_alloc_buffers,
spa_alsa_source_node_port_set_input,
spa_alsa_source_node_port_set_output,
spa_alsa_source_node_port_set_io,
spa_alsa_source_node_port_reuse_buffer,
spa_alsa_source_node_port_send_command,
spa_alsa_source_node_process_input,
@ -847,6 +849,14 @@ alsa_source_init (const SpaHandleFactory *factory,
spa_log_error (this->log, "an id-map is needed");
return SPA_RESULT_ERROR;
}
if (this->data_loop == NULL) {
spa_log_error (this->log, "a data loop is needed");
return SPA_RESULT_ERROR;
}
if (this->main_loop == NULL) {
spa_log_error (this->log, "a main loop is needed");
return SPA_RESULT_ERROR;
}
init_type (&this->type, this->map);
this->node = alsasource_node;

View file

@ -228,6 +228,15 @@ pull_frames_queue (SpaALSAState *state,
if (spa_list_is_empty (&state->ready)) {
SpaEvent event = SPA_EVENT_INIT (state->type.event_node.NeedInput);
SpaPortIO *io;
if ((io = state->io)) {
io->flags = SPA_PORT_IO_FLAG_RANGE;
io->status = SPA_RESULT_OK;
io->range.offset = state->sample_count;
io->range.min_size = state->threshold;
io->range.max_size = frames;
}
state->event_cb (&state->node, &event, state->user_data);
}
while (!spa_list_is_empty (&state->ready) && to_write > 0) {
@ -334,7 +343,7 @@ push_frames_queue (SpaALSAState *state,
size_t n_bytes;
SpaALSABuffer *b;
SpaData *d;
SpaPortOutput *output;
SpaPortIO *io;
b = spa_list_first (&state->free, SpaALSABuffer, link);
spa_list_remove (&b->link);
@ -357,13 +366,13 @@ push_frames_queue (SpaALSAState *state,
d[0].chunk->size = n_bytes;
d[0].chunk->stride = 0;
if ((output = state->io)) {
b->outstanding = true;
output->buffer_id = b->outbuf->id;
output->status = SPA_RESULT_OK;
}
{
if ((io = state->io)) {
SpaEvent event = SPA_EVENT_INIT (state->type.event_node.HaveOutput);
b->outstanding = true;
io->buffer_id = b->outbuf->id;
io->status = SPA_RESULT_OK;
state->event_cb (&state->node, &event, state->user_data);
}
}

View file

@ -146,7 +146,7 @@ struct _SpaALSAState {
SpaPortInfo info;
SpaAllocParam *params[3];
uint8_t params_buffer[1024];
void *io;
SpaPortIO *io;
SpaALSABuffer buffers[MAX_BUFFERS];
unsigned int n_buffers;