summaryrefslogtreecommitdiff
path: root/src/examples/export-source.c
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2017-11-29 13:25:56 +0100
committerWim Taymans <wtaymans@redhat.com>2017-11-29 13:25:56 +0100
commit425073afd8ed262c007269d354c3a8b3ceedf5c3 (patch)
treeaac84450bf2c34c2d796eba9dbdb9ec72d518860 /src/examples/export-source.c
parentada3698355a3d6a8e37c8c42e45b570e4f1f4244 (diff)
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.
Diffstat (limited to 'src/examples/export-source.c')
-rw-r--r--src/examples/export-source.c59
1 files changed, 58 insertions, 1 deletions
diff --git a/src/examples/export-source.c b/src/examples/export-source.c
index 04a5f81d..0d580525 100644
--- a/src/examples/export-source.c
+++ b/src/examples/export-source.c
@@ -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);