param-io: work on IO parameters

Reorganize the io parameter ids and objects. Make separate enumerations
for buffer, control, input and output properties.
Add a volume output property to export-source. This is still unused
but will eventually be routed to a PropsIn io area where it can
control the volume of a mixer, for example.
This commit is contained in:
Wim Taymans 2017-11-29 13:25:56 +01:00
parent ada3698355
commit 425073afd8
12 changed files with 240 additions and 124 deletions

View file

@ -36,6 +36,8 @@
struct type {
uint32_t format;
uint32_t props;
uint32_t prop_volume;
uint32_t io_prop_volume;
struct spa_type_meta meta;
struct spa_type_data data;
struct spa_type_media_type media_type;
@ -48,6 +50,8 @@ static inline void init_type(struct type *type, struct spa_type_map *map)
{
type->format = spa_type_map_get_id(map, SPA_TYPE__Format);
type->props = spa_type_map_get_id(map, SPA_TYPE__Props);
type->prop_volume = spa_type_map_get_id(map, SPA_TYPE_PROPS__volume);
type->io_prop_volume = spa_type_map_get_id(map, SPA_TYPE_IO_PROP_BASE "volume");
spa_type_meta_map(map, &type->meta);
spa_type_data_map(map, &type->data);
spa_type_media_type_map(map, &type->media_type);
@ -56,6 +60,17 @@ static inline void init_type(struct type *type, struct spa_type_map *map)
spa_type_audio_format_map(map, &type->audio_format);
}
#define DEFAULT_VOLUME 1.0
struct props {
double volume;
};
static void reset_props(struct props *props)
{
props->volume = DEFAULT_VOLUME;
}
struct buffer {
struct spa_buffer *buffer;
struct spa_list link;
@ -66,6 +81,8 @@ struct buffer {
struct data {
struct type type;
struct props props;
const char *path;
struct pw_main_loop *loop;
@ -84,6 +101,8 @@ struct data {
void *callbacks_data;
struct spa_io_buffers *io;
double *io_volume;
uint8_t buffer[1024];
struct spa_audio_info_raw format;
@ -138,6 +157,12 @@ static int impl_port_set_io(struct spa_node *node, enum spa_direction direction,
if (id == d->t->io.Buffers)
d->io = data;
else if (id == d->type.io_prop_volume) {
if (SPA_POD_TYPE(data) == SPA_POD_TYPE_ID)
d->io_volume = &SPA_POD_VALUE(struct spa_pod_double, data);
else
return -EINVAL;
}
else
return -ENOENT;
@ -226,7 +251,9 @@ static int impl_port_enum_params(struct spa_node *node,
uint32_t list[] = { t->param.idEnumFormat,
t->param.idFormat,
t->param.idBuffers,
t->param.idMeta };
t->param.idMeta,
t->param_io.idBuffers,
t->param_io.idPropsOut };
if (*index < SPA_N_ELEMENTS(list))
param = spa_pod_builder_object(builder,
@ -266,6 +293,34 @@ static int impl_port_enum_params(struct spa_node *node,
return 0;
}
}
else if (id == t->param_io.idBuffers) {
switch (*index) {
case 0:
param = spa_pod_builder_object(builder,
id, t->param_io.Buffers,
":", t->param_io.id, "I", t->io.Buffers,
":", t->param_io.size, "i", sizeof(struct spa_io_buffers));
break;
default:
return 0;
}
}
else if (id == t->param_io.idPropsOut) {
struct props *p = &d->props;
switch (*index) {
case 0:
param = spa_pod_builder_object(builder,
id, t->param_io.Prop,
":", t->param_io.id, "I", d->type.io_prop_volume,
":", t->param_io.size, "i", sizeof(struct spa_pod_double),
":", t->param_io.propId, "I", d->type.prop_volume,
":", t->param_io.propType, "dr", p->volume, 2, 0.0, 10.0);
break;
default:
return 0;
}
}
else
return -ENOENT;
@ -495,6 +550,8 @@ int main(int argc, char *argv[])
spa_list_init(&data.empty);
init_type(&data.type, data.t->map);
reset_props(&data.props);
data.io_volume = &data.props.volume;
spa_debug_set_type_map(data.t->map);
pw_remote_add_listener(data.remote, &data.remote_listener, &remote_events, &data);