alsa: implement set_io and handle position io

Use position io for deciding the size of the output buffers in
alsasrc
This commit is contained in:
Wim Taymans 2018-10-24 10:27:57 +02:00
parent 4aab226047
commit 2206deb3e8
4 changed files with 39 additions and 12 deletions

View file

@ -161,7 +161,23 @@ static int impl_node_enum_params(struct spa_node *node,
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
{
return -ENOTSUP;
struct state *this;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct state, node);
switch (id) {
case SPA_IO_Clock:
this->clock = data;
break;
case SPA_IO_Position:
this->position = data;
break;
default:
return -ENOENT;
}
return 0;
}
static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,
@ -404,13 +420,6 @@ impl_node_port_enum_params(struct spa_node *node,
0);
break;
case 1:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Range),
SPA_PARAM_IO_size, &SPA_POD_Int(sizeof(struct spa_io_range)),
0);
break;
case 2:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
SPA_PARAM_IO_id, &SPA_POD_Id(SPA_IO_Clock),
@ -594,9 +603,6 @@ impl_node_port_set_io(struct spa_node *node,
case SPA_IO_Buffers:
this->io = data;
break;
case SPA_IO_Range:
this->range = data;
break;
case SPA_IO_Clock:
this->clock = data;
break;

View file

@ -159,7 +159,23 @@ static int impl_node_enum_params(struct spa_node *node,
static int impl_node_set_io(struct spa_node *node, uint32_t id, void *data, size_t size)
{
return -ENOTSUP;
struct state *this;
spa_return_val_if_fail(node != NULL, -EINVAL);
this = SPA_CONTAINER_OF(node, struct state, node);
switch (id) {
case SPA_IO_Clock:
this->clock = data;
break;
case SPA_IO_Position:
this->position = data;
break;
default:
return -ENOENT;
}
return 0;
}
static int impl_node_set_param(struct spa_node *node, uint32_t id, uint32_t flags,

View file

@ -767,6 +767,10 @@ static void alsa_on_capture_timeout_event(struct spa_source *source)
return;
}
if (state->position) {
state->threshold = state->position->size;
}
avail = snd_pcm_status_get_avail(status);
snd_pcm_status_get_htstamp(status, &state->now);
clock_gettime(CLOCK_MONOTONIC, &now);

View file

@ -93,6 +93,7 @@ struct state {
struct spa_io_buffers *io;
struct spa_io_range *range;
struct spa_io_clock *clock;
struct spa_io_position *position;
struct buffer buffers[MAX_BUFFERS];
unsigned int n_buffers;