Implement control streams

spa_io_control_range -> spa_io_range
Add helpers for sequence and control pod objects
Implement control properties in audiotestsrc, update test example.
This commit is contained in:
Wim Taymans 2018-08-28 18:16:41 +02:00
parent 90c1a95eef
commit c9526dc2bb
21 changed files with 289 additions and 272 deletions

View file

@ -398,8 +398,8 @@ impl_node_port_enum_params(struct spa_node *node,
case 1:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
":", SPA_PARAM_IO_id, "I", SPA_IO_ControlRange,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_control_range));
":", SPA_PARAM_IO_id, "I", SPA_IO_Range,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_range));
break;
case 2:
param = spa_pod_builder_object(&b,
@ -586,7 +586,7 @@ impl_node_port_set_io(struct spa_node *node,
case SPA_IO_Buffers:
this->io = data;
break;
case SPA_IO_ControlRange:
case SPA_IO_Range:
this->range = data;
break;
case SPA_IO_Clock:

View file

@ -91,7 +91,7 @@ struct state {
struct spa_port_info info;
struct spa_io_buffers *io;
struct spa_io_control_range *range;
struct spa_io_range *range;
struct spa_io_clock *clock;
struct buffer buffers[MAX_BUFFERS];

View file

@ -69,10 +69,6 @@ struct link {
struct spa_buffer **buffers;
};
struct control {
struct spa_pod_float *volume;
};
struct impl {
struct spa_handle handle;
struct spa_node node;
@ -80,7 +76,6 @@ struct impl {
struct spa_log *log;
struct props props;
struct control control;
const struct spa_node_callbacks *callbacks;
void *user_data;
@ -653,13 +648,14 @@ impl_node_port_set_io(struct spa_node *node,
spa_log_debug(this->log, "set io %d %d %d", id, direction, port_id);
if (id == SPA_IO_ControlRange)
switch (id) {
case SPA_IO_Range:
res = spa_node_port_set_io(this->resample, direction, 0, id, data, size);
// else if (id == t->io_prop_volume)
// res = spa_node_port_set_io(this->channelmix, direction, 0, id, data, size);
else
break;
default:
res = spa_node_port_set_io(this->fmt[direction], direction, port_id, id, data, size);
break;
}
return res;
}

View file

@ -74,7 +74,7 @@ struct port {
bool valid;
struct spa_io_buffers *io;
struct spa_io_control_range *ctrl;
struct spa_io_range *ctrl;
struct spa_port_info info;
struct spa_dict info_props;
@ -837,7 +837,7 @@ impl_node_port_set_io(struct spa_node *node,
case SPA_IO_Buffers:
port->io = data;
break;
case SPA_IO_ControlRange:
case SPA_IO_Range:
port->ctrl = data;
break;
default:

View file

@ -51,7 +51,7 @@ struct port {
uint32_t id;
struct spa_io_buffers *io;
struct spa_io_control_range *ctrl;
struct spa_io_range *ctrl;
struct spa_port_info info;
@ -787,7 +787,7 @@ impl_node_port_set_io(struct spa_node *node,
case SPA_IO_Buffers:
port->io = data;
break;
case SPA_IO_ControlRange:
case SPA_IO_Range:
port->ctrl = data;
break;
default:

View file

@ -60,7 +60,7 @@ struct port {
uint32_t id;
struct spa_io_buffers *io;
struct spa_io_control_range *ctrl;
struct spa_io_range *ctrl;
struct spa_port_info info;
bool have_format;
@ -623,13 +623,16 @@ impl_node_port_set_io(struct spa_node *node,
port = GET_PORT(this, direction, port_id);
if (id == SPA_IO_Buffers)
switch (id) {
case SPA_IO_Buffers:
port->io = data;
else if (id == SPA_IO_ControlRange)
break;
case SPA_IO_Range:
port->ctrl = data;
else
break;
default:
return -ENOENT;
}
return 0;
}

View file

@ -51,7 +51,7 @@ struct port {
uint32_t id;
struct spa_io_buffers *io;
struct spa_io_control_range *ctrl;
struct spa_io_range *ctrl;
struct spa_port_info info;
@ -785,13 +785,16 @@ impl_node_port_set_io(struct spa_node *node,
port = GET_PORT(this, direction, port_id);
if (id == SPA_IO_Buffers)
switch (id) {
case SPA_IO_Buffers:
port->io = data;
else if (id == SPA_IO_ControlRange)
break;
case SPA_IO_Range:
port->ctrl = data;
else
break;
default:
return -ENOENT;
}
return 0;
}

View file

@ -66,7 +66,7 @@ struct port {
struct port_props props;
struct spa_io_buffers *io;
struct spa_io_control_range *io_range;
struct spa_io_range *io_range;
double *io_volume;
int32_t *io_mute;
@ -472,42 +472,19 @@ impl_node_port_enum_params(struct spa_node *node,
case 1:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
":", SPA_PARAM_IO_id, "I", SPA_IO_ControlRange,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_control_range));
":", SPA_PARAM_IO_id, "I", SPA_IO_Range,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_range));
break;
case 2:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
":", SPA_PARAM_IO_id, "I", SPA_IO_Control,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_sequence));
break;
default:
return 0;
}
#if 0
else if (id == t->param_io.idPropsIn) {
struct port_props *p = &port->props;
if (direction == SPA_DIRECTION_OUTPUT)
return 0;
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_io.Prop,
":", t->param_io.id, "I", t->io_prop_volume,
":", t->param_io.size, "i", sizeof(struct spa_pod_double),
":", t->param.propId, "I", t->prop_volume,
":", t->param.propType, "dru", p->volume,
SPA_POD_PROP_MIN_MAX(0.0, 10.0));
break;
case 1:
param = spa_pod_builder_object(&b,
id, t->param_io.Prop,
":", t->param_io.id, "I", t->io_prop_mute,
":", t->param_io.size, "i", sizeof(struct spa_pod_bool),
":", t->param.propId, "I", t->prop_mute,
":", t->param.propType, "b", p->mute);
break;
default:
return 0;
}
}
#endif
break;
default:
return -ENOENT;
}
@ -701,25 +678,16 @@ impl_node_port_set_io(struct spa_node *node,
port = GET_PORT(this, direction, port_id);
if (id == SPA_IO_Buffers)
switch (id) {
case SPA_IO_Buffers:
port->io = data;
else if (id == SPA_IO_ControlRange)
break;
case SPA_IO_Range:
port->io_range = data;
#if 0
else if (id == t->io_prop_volume && direction == SPA_DIRECTION_INPUT)
if (data && size >= sizeof(struct spa_pod_double))
port->io_volume = &SPA_POD_VALUE(struct spa_pod_double, data);
else
port->io_volume = &port->props.volume;
else if (id == t->io_prop_mute && direction == SPA_DIRECTION_INPUT)
if (data && size >= sizeof(struct spa_pod_bool))
port->io_mute = &SPA_POD_VALUE(struct spa_pod_bool, data);
else
port->io_mute = &port->props.mute;
#endif
else
break;
default:
return -ENOENT;
}
return 0;
}

View file

@ -32,6 +32,7 @@
#include <spa/param/audio/format-utils.h>
#include <spa/param/param.h>
#include <spa/pod/filter.h>
#include <spa/control/control.h>
#define NAME "audiotestsrc"
@ -96,7 +97,8 @@ struct impl {
struct spa_port_info info;
struct spa_io_buffers *io;
struct spa_io_control_range *io_range;
struct spa_io_range *io_range;
struct spa_io_sequence *io_control;
uint32_t *io_wave;
double *io_freq;
@ -297,7 +299,7 @@ static int make_buffer(struct impl *this)
{
struct buffer *b;
struct spa_io_buffers *io = this->io;
struct spa_io_control_range *range = this->io_range;
struct spa_io_range *range = this->io_range;
int n_bytes, n_samples;
uint32_t maxsize;
void *data;
@ -659,52 +661,19 @@ impl_node_port_enum_params(struct spa_node *node,
case 1:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
":", SPA_PARAM_IO_id, "I", SPA_IO_ControlRange,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_control_range));
":", SPA_PARAM_IO_id, "I", SPA_IO_Range,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_range));
break;
case 2:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
":", SPA_PARAM_IO_id, "I", SPA_IO_Control,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_sequence));
break;
default:
return 0;
}
break;
#if 0
else if (id == t->param_io.idPropsIn) {
struct props *p = &this->props;
switch (*index) {
case 0:
param = spa_pod_builder_object(&b,
id, t->param_io.Prop,
":", t->param_io.id, "I", t->io_prop_wave,
":", t->param_io.size, "i", sizeof(struct spa_pod_id),
":", SPA_PROP_INFO_id, "I", SPA_PROP_wave,
":", SPA_PROP_INFO_type, "i", p->wave,
":", SPA_PROP_INFO_labels, "[-i",
"i", WAVE_SINE, "s", "Sine wave",
"i", WAVE_SQUARE, "s", "Square wave", "]");
break;
case 1:
param = spa_pod_builder_object(&b,
id, t->param_io.Prop,
":", t->param_io.id, "I", t->io_prop_freq,
":", t->param_io.size, "i", sizeof(struct spa_pod_double),
":", SPA_PROP_INFO_id, "I", SPA_PROP_freq,
":", SPA_PROP_INFO_type, "dr", p->freq,
SPA_POD_PROP_MIN_MAX(0.0, 50000000.0));
break;
case 2:
param = spa_pod_builder_object(&b,
id, t->param_io.Prop,
":", t->param_io.id, "I", t->io_prop_volume,
":", t->param_io.size, "i", sizeof(struct spa_pod_double),
":", SPA_PROP_INFO_id, "I", SPA_PROP_volume,
":", SPA_PROP_INFO_type, "dr", p->volume,
SPA_POD_PROP_MIN_MAX(0.0, 10.0));
break;
default:
return 0;
}
}
#endif
default:
return -ENOENT;
}
@ -880,31 +849,19 @@ impl_node_port_set_io(struct spa_node *node,
spa_return_val_if_fail(CHECK_PORT(this, direction, port_id), -EINVAL);
if (id == SPA_IO_Buffers)
switch (id) {
case SPA_IO_Buffers:
this->io = data;
else if (id == SPA_IO_ControlRange)
break;
case SPA_IO_Range:
this->io_range = data;
#if 0
else if (id == t->io_prop_wave) {
if (data && size >= sizeof(struct spa_pod_id))
this->io_wave = &SPA_POD_VALUE(struct spa_pod_id, data);
else
this->io_wave = &this->props.wave;
}
else if (id == t->io_prop_freq)
if (data && size >= sizeof(struct spa_pod_double))
this->io_freq = &SPA_POD_VALUE(struct spa_pod_double, data);
else
this->io_freq = &this->props.freq;
else if (id == t->io_prop_volume)
if (data && size >= sizeof(struct spa_pod_double))
this->io_volume = &SPA_POD_VALUE(struct spa_pod_double, data);
else
this->io_volume = &this->props.volume;
#endif
else
break;
case SPA_IO_Control:
this->io_control = data;
break;
default:
return -ENOENT;
}
return 0;
}
@ -947,6 +904,28 @@ impl_node_port_send_command(struct spa_node *node,
return -ENOTSUP;
}
static int impl_node_process_control(struct impl *this, struct spa_io_sequence *control)
{
struct spa_pod_control *c;
SPA_POD_SEQUENCE_FOREACH(&control->sequence, c) {
switch (c->type) {
case SPA_CONTROL_properties:
{
struct props *p = &this->props;
spa_pod_object_parse(&c->value,
":",SPA_PROP_frequency, "?d", &p->freq,
":",SPA_PROP_volume, "?d", &p->volume,
NULL);
break;
}
default:
break;
}
}
return 0;
}
static int impl_node_process(struct spa_node *node)
{
struct impl *this;
@ -958,6 +937,9 @@ static int impl_node_process(struct spa_node *node)
io = this->io;
spa_return_val_if_fail(io != NULL, -EIO);
if (this->io_control)
impl_node_process_control(this, this->io_control);
if (io->status == SPA_STATUS_HAVE_BUFFER)
return SPA_STATUS_HAVE_BUFFER;

View file

@ -82,7 +82,7 @@ struct impl {
struct spa_port_info info;
struct spa_io_buffers *io;
struct spa_io_control_range *range;
struct spa_io_range *range;
struct buffer buffers[MAX_BUFFERS];
unsigned int n_buffers;
@ -1196,7 +1196,7 @@ impl_node_port_set_io(struct spa_node *node,
case SPA_IO_Buffers:
this->io = data;
break;
case SPA_IO_ControlRange:
case SPA_IO_Range:
this->range = data;
break;
default:

View file

@ -64,7 +64,7 @@ struct port {
struct buffer buffers[MAX_BUFFERS];
uint32_t n_buffers;
struct spa_io_buffers *io;
struct spa_io_control_range *range;
struct spa_io_range *range;
struct spa_list empty;
};
@ -463,8 +463,8 @@ impl_node_port_enum_params(struct spa_node *node,
case 1:
param = spa_pod_builder_object(&b,
SPA_TYPE_OBJECT_ParamIO, id,
":", SPA_PARAM_IO_id, "I", SPA_IO_ControlRange,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_control_range));
":", SPA_PARAM_IO_id, "I", SPA_IO_Range,
":", SPA_PARAM_IO_size, "i", sizeof(struct spa_io_range));
break;
default:
return 0;
@ -625,13 +625,16 @@ impl_node_port_set_io(struct spa_node *node,
port = GET_PORT(this, direction, port_id);
if (id == SPA_IO_Buffers)
switch (id) {
case SPA_IO_Buffers:
port->io = data;
else if (id == SPA_IO_ControlRange)
break;
case SPA_IO_Range:
port->range = data;
else
break;
default:
return -ENOENT;
}
return 0;
}