From ac25d126de9232cf5389571636169c4c3d66afa2 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 22 Feb 2022 18:20:07 +0100 Subject: [PATCH] channelmix: use the right channelmap For merger setup (consuming a source) we want to expose the channelmap of the remixed signal (to the application/sink). For splitter setup (providing data) we want to expose the channelmap of the original source (before remixing to sink). Hide the merge channel props because they contain the channelmap before mising and we want to expose the remixed signal in merger mode. This fixes some weird volume issues when an input stream is linked to a source and is remixing, like when a stereo stream is captured from a mono source. --- spa/plugins/audioconvert/channelmix.c | 11 +++++++++-- spa/plugins/audioconvert/merger.c | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/spa/plugins/audioconvert/channelmix.c b/spa/plugins/audioconvert/channelmix.c index f4e62be57..90f845a64 100644 --- a/spa/plugins/audioconvert/channelmix.c +++ b/spa/plugins/audioconvert/channelmix.c @@ -145,6 +145,7 @@ struct impl { struct spa_cpu *cpu; uint32_t quantum_limit; + enum spa_direction direction; struct spa_io_position *io_position; struct spa_hook_list hooks; @@ -360,7 +361,7 @@ static int setup_convert(struct impl *this, if ((res = channelmix_init(&this->mix)) < 0) return res; - remap_volumes(this, src_info); + remap_volumes(this, this->direction == SPA_DIRECTION_INPUT ? src_info : dst_info); set_volume(this); emit_props_changed(this); @@ -714,7 +715,7 @@ static int apply_props(struct impl *this, const struct spa_pod *param) } } if (changed) { - struct port *port = GET_IN_PORT(this, 0); + struct port *port = GET_PORT(this, this->direction, 0); if (have_soft_volume) p->have_soft_volume = true; else if (have_channel_volume) @@ -1579,6 +1580,12 @@ impl_init(const struct spa_handle_factory *factory, this->props.n_channels = parse_position(this->props.channel_map, s, strlen(s)); else if (spa_streq(k, "clock.quantum-limit")) spa_atou32(s, &this->quantum_limit, 0); + else if (spa_streq(k, "factory.mode")) { + if (spa_streq(s, "merge")) + this->direction = SPA_DIRECTION_OUTPUT; + else + this->direction = SPA_DIRECTION_INPUT; + } else channelmix_set_param(this, k, s); diff --git a/spa/plugins/audioconvert/merger.c b/spa/plugins/audioconvert/merger.c index 7ff696048..3a1de2040 100644 --- a/spa/plugins/audioconvert/merger.c +++ b/spa/plugins/audioconvert/merger.c @@ -386,10 +386,13 @@ static int impl_node_enum_params(void *object, int seq, case SPA_PARAM_Props: { +#if 0 struct props *p = &this->props; struct spa_pod_frame f[2]; +#endif switch (result.index) { +#if 0 case 0: spa_pod_builder_push_object(&b, &f[0], SPA_TYPE_OBJECT_Props, id); @@ -422,6 +425,7 @@ static int impl_node_enum_params(void *object, int seq, spa_pod_builder_pop(&b, &f[1]); param = spa_pod_builder_pop(&b, &f[0]); break; +#endif default: return 0; }