From dc889c4550c67d92c34c8ed8512f54f906eed4f5 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 12 Aug 2022 16:22:27 +0200 Subject: [PATCH 1/2] mixin: don't overwrite valid configuration The component .bind() method is called twice - for the upstream and for the downstream links. When mixout's .bind() is first called for the upstream link, it correctly sets up its connection to the mixin component. However, if after that .bind() is called for the downstream link, that configuration is overwritten with 0. Remove that overwrite. Signed-off-by: Guennadi Liakhovetski --- src/audio/mixin_mixout.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/audio/mixin_mixout.c b/src/audio/mixin_mixout.c index ed34bfb89e9d..eb1d675a4023 100644 --- a/src/audio/mixin_mixout.c +++ b/src/audio/mixin_mixout.c @@ -478,7 +478,7 @@ static void silence(struct audio_stream __sparse_cache *stream, uint32_t start, /* Most of the mixing is done here on mixin side. mixin mixes its source data * into each connected mixout sink buffer. Basically, if mixout sink buffer has - * no data, mixin copies its source data into mixin sink buffer. If moxout sink + * no data, mixin copies its source data into mixout sink buffer. If moxout sink * buffer has some data (written there by other mixin), mixin reads mixout sink * buffer data, mixes it with its source data and writes back to mixout sink * buffer. So after all mixin mixin_copy() calls, mixout sink buffer contains @@ -1004,11 +1004,12 @@ static int mixout_bind(struct comp_dev *dev, void *data) md = comp_get_drvdata(dev); mixed_data_info = mixed_data_info_acquire(md->mixed_data_info); - /* mixout -> new sink */ - if (dev->ipc_config.id == src_id) { - mixed_data_info->mixed_bytes = 0; - memset(mixed_data_info->source_info, 0, sizeof(mixed_data_info->source_info)); - } else { /* new mixin -> mixout */ + /* + * If dev->ipc_config.id == src_id then we're called for the downstream + * link, nothing to do + */ + if (dev->ipc_config.id != src_id) { + /* new mixin -> mixout */ struct comp_dev *mixin; struct mixout_source_info *source_info; @@ -1057,7 +1058,6 @@ static int mixout_unbind(struct comp_dev *dev, void *data) /* mixout -> new sink */ if (dev->ipc_config.id == src_id) { - /* not really necessary as same is done in mixout_bind() */ mixed_data_info->mixed_bytes = 0; memset(mixed_data_info->source_info, 0, sizeof(mixed_data_info->source_info)); } else { /* new mixin -> mixout */ From 5709daa31d99e159ecd1170239e6bee00896b3e7 Mon Sep 17 00:00:00 2001 From: Guennadi Liakhovetski Date: Fri, 12 Aug 2022 16:33:08 +0200 Subject: [PATCH 2/2] mixin: (cosmetic) simplify a conditional No need to check the same condition twice in a row, once is enough. Signed-off-by: Guennadi Liakhovetski --- src/audio/mixin_mixout.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/audio/mixin_mixout.c b/src/audio/mixin_mixout.c index eb1d675a4023..b0ecd1b244bd 100644 --- a/src/audio/mixin_mixout.c +++ b/src/audio/mixin_mixout.c @@ -557,6 +557,7 @@ static int mixin_copy(struct comp_dev *dev) if (source_avail_bytes > 0) { bytes_to_copy = MIN(source_avail_bytes, sinks_free_bytes); bytes_to_consume_from_source_buf = bytes_to_copy; + buffer_stream_invalidate(source_c, bytes_to_copy); } else { /* if source does not produce any data -- do NOT stop mixing but generate * silence as that source output. @@ -567,9 +568,6 @@ static int mixin_copy(struct comp_dev *dev) sinks_free_bytes); } - if (source_avail_bytes > 0) - buffer_stream_invalidate(source_c, bytes_to_copy); - /* iterate over all connected mixouts and mix source data into each mixout sink buffer */ list_for_item(blist, &dev->bsink_list) { struct comp_buffer *unused_in_between_buf;