node: Add id to set_io

Make it possible to configure multiple io areas on a port by giving
an id to set_io.
Add some types to enumerate the supported ids
Make an area to exchange buffers and one to specify pull ranges.
The idea is to make more area types for controlable properties.
Implement enumeration of IO areas in volume.
This commit is contained in:
Wim Taymans 2017-11-21 19:34:37 +01:00
parent 4288a634f4
commit 8efea3e1ea
40 changed files with 583 additions and 208 deletions

View file

@ -517,17 +517,28 @@ impl_node_port_alloc_buffers(struct spa_node *node,
}
static int
impl_node_port_set_io(struct spa_node *node, enum spa_direction direction, uint32_t port_id, struct spa_port_io *io)
impl_node_port_set_io(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t id,
void *io)
{
struct state *this;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct state, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
this->io = io;
if (id == t->io.Buffers)
this->io = io;
else if (id == t->io.ControlRange)
this->range = io;
else
return -ENOENT;
return 0;
}
@ -563,7 +574,7 @@ impl_node_port_send_command(struct spa_node *node,
static int impl_node_process_input(struct spa_node *node)
{
struct state *this;
struct spa_port_io *input;
struct spa_io_buffers *input;
spa_return_val_if_fail(node != NULL, -EINVAL);

View file

@ -552,17 +552,26 @@ impl_node_port_alloc_buffers(struct spa_node *node,
}
static int
impl_node_port_set_io(struct spa_node *node, enum spa_direction direction, uint32_t port_id, struct spa_port_io *io)
impl_node_port_set_io(struct spa_node *node,
enum spa_direction direction,
uint32_t port_id,
uint32_t id,
void *io)
{
struct state *this;
struct type *t;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct state, node);
t = &this->type;
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
this->io = io;
if (id == t->io.Buffers)
this->io = io;
else
return -ENOENT;
return 0;
}
@ -619,7 +628,7 @@ static int impl_node_process_input(struct spa_node *node)
static int impl_node_process_output(struct spa_node *node)
{
struct state *this;
struct spa_port_io *io;
struct spa_io_buffers *io;
spa_return_val_if_fail(node != NULL, -EINVAL);

View file

@ -334,15 +334,17 @@ static inline void calc_timeout(size_t target, size_t current,
static inline void try_pull(struct state *state, snd_pcm_uframes_t frames,
snd_pcm_uframes_t written, bool do_pull)
{
struct spa_port_io *io = state->io;
struct spa_io_buffers *io = state->io;
if (spa_list_is_empty(&state->ready) && do_pull) {
spa_log_trace(state->log, "alsa-util %p: %d %lu", state, io->status,
state->filled + written);
io->status = SPA_STATUS_NEED_BUFFER;
io->range.offset = state->sample_count * state->frame_size;
io->range.min_size = state->threshold * state->frame_size;
io->range.max_size = frames * state->frame_size;
if (state->range) {
state->range->offset = state->sample_count * state->frame_size;
state->range->min_size = state->threshold * state->frame_size;
state->range->max_size = frames * state->frame_size;
}
state->callbacks->need_input(state->callbacks_data);
}
}
@ -428,7 +430,7 @@ push_frames(struct state *state,
snd_pcm_uframes_t frames)
{
snd_pcm_uframes_t total_frames = 0;
struct spa_port_io *io = state->io;
struct spa_io_buffers *io = state->io;
if (spa_list_is_empty(&state->free)) {
spa_log_trace(state->log, "no more buffers");

View file

@ -35,6 +35,7 @@ extern "C" {
#include <spa/clock/clock.h>
#include <spa/node/node.h>
#include <spa/node/io.h>
#include <spa/param/buffers.h>
#include <spa/param/meta.h>
#include <spa/param/audio/format-utils.h>
@ -66,6 +67,7 @@ struct type {
uint32_t prop_card_name;
uint32_t prop_min_latency;
uint32_t prop_max_latency;
struct spa_type_io io;
struct spa_type_param param;
struct spa_type_meta meta;
struct spa_type_data data;
@ -92,6 +94,7 @@ static inline void init_type(struct type *type, struct spa_type_map *map)
type->prop_min_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__minLatency);
type->prop_max_latency = spa_type_map_get_id(map, SPA_TYPE_PROPS__maxLatency);
spa_type_io_map(map, &type->io);
spa_type_param_map(map, &type->param);
spa_type_meta_map(map, &type->meta);
spa_type_data_map(map, &type->data);
@ -141,7 +144,8 @@ struct state {
size_t frame_size;
struct spa_port_info info;
struct spa_port_io *io;
struct spa_io_buffers *io;
struct spa_io_control_range *range;
struct buffer buffers[MAX_BUFFERS];
unsigned int n_buffers;