From d03ebade1f64e0ae1847826fcfb4bfe64f3bd762 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Thu, 15 Jun 2023 20:13:15 +0300 Subject: [PATCH] Audio: Mux: Fix mistake in frames count handling The source frames count need to be checked from every active input_buffers[n].size). Similarly in consuming the source buffers it needs to be updated to every mod->input_buffers[n].consumed. Fixes: #7308 Fixes: c399624 ("Audio: Mux: Convert mux and demux to module adapter") Signed-off-by: Seppo Ingalsuo (cherry picked from commit afd86e08081835b16c960713ae2f44ffd3654ecb) Signed-off-by: Kai Vehmanen --- src/audio/mux/mux.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/audio/mux/mux.c b/src/audio/mux/mux.c index 3ebbf838ea72..be4d322f870b 100644 --- a/src/audio/mux/mux.c +++ b/src/audio/mux/mux.c @@ -527,18 +527,24 @@ static int mux_process(struct processing_module *mod, struct comp_buffer __sparse_cache *source_c; struct list_item *clist; const struct audio_stream __sparse_cache *sources_stream[MUX_MAX_STREAMS] = { NULL }; - int frames; + int frames = 0; int sink_bytes; int source_bytes; - int i; + int i, j; comp_dbg(dev, "mux_process()"); /* align source streams with their respective configurations */ + j = 0; list_for_item(clist, &dev->bsource_list) { source = container_of(clist, struct comp_buffer, sink_list); source_c = buffer_acquire(source); if (source_c->source->state == dev->state) { + if (frames) + frames = MIN(frames, input_buffers[j].size); + else + frames = input_buffers[j].size; + i = get_stream_index(dev, cd, source_c->pipeline_id); /* return if index wrong */ if (i < 0) { @@ -549,13 +555,13 @@ static int mux_process(struct processing_module *mod, sources_stream[i] = &source_c->stream; } buffer_release(source_c); + j++; } /* check if there are any sources active */ if (num_input_buffers == 0) return 0; - frames = input_buffers[0].size; source_bytes = frames * audio_stream_frame_bytes(mod->input_buffers[0].data); sink_bytes = frames * audio_stream_frame_bytes(mod->output_buffers[0].data); mux_prepare_active_look_up(cd, output_buffers[0].data, &sources_stream[0]); @@ -564,7 +570,16 @@ static int mux_process(struct processing_module *mod, cd->mux(dev, output_buffers[0].data, &sources_stream[0], frames, &cd->active_lookup); /* Update consumed and produced */ - mod->input_buffers[0].consumed = source_bytes; + j = 0; + list_for_item(clist, &dev->bsource_list) { + source = container_of(clist, struct comp_buffer, sink_list); + source_c = buffer_acquire(source); + if (source_c->source->state == dev->state) + mod->input_buffers[j].consumed = source_bytes; + + buffer_release(source_c); + j++; + } mod->output_buffers[0].size = sink_bytes; return 0; }