From 5fb72e95d7fb49e0aea724774b4cab4d0b6542e4 Mon Sep 17 00:00:00 2001 From: Marcin Szkudlinski Date: Mon, 16 Sep 2024 14:14:37 +0200 Subject: [PATCH] buf: use API for iteration bsource_list in components this commit changes all components to use comp_dev_get_next_data_producer for iteration through bsource_list pipeline code, like module adapter or ipc helpers was omitted intentionally Signed-off-by: Marcin Szkudlinski --- src/audio/mixer/mixer.c | 19 ++++++++------- src/audio/mux/mux.c | 32 ++++++++++++++----------- src/audio/mux/mux_ipc4.c | 8 +++---- src/audio/smart_amp/smart_amp.c | 8 +++---- src/probe/probe.c | 7 +++--- src/samples/audio/smart_amp_test_ipc3.c | 9 ++++--- 6 files changed, 45 insertions(+), 38 deletions(-) diff --git a/src/audio/mixer/mixer.c b/src/audio/mixer/mixer.c index e037852b079e..3c15709377f0 100644 --- a/src/audio/mixer/mixer.c +++ b/src/audio/mixer/mixer.c @@ -163,16 +163,15 @@ static int mixer_reset(struct processing_module *mod) { struct mixer_data *md = module_get_private_data(mod); struct comp_dev *dev = mod->dev; - struct list_item *blist; int dir = dev->pipeline->source_comp->direction; comp_dbg(dev, "mixer_reset()"); if (dir == SOF_IPC_STREAM_PLAYBACK) { - list_for_item(blist, &dev->bsource_list) { + struct comp_buffer *source = comp_dev_get_first_data_producer(dev); + + while (source) { /* FIXME: this is racy and implicitly protected by serialised IPCs */ - struct comp_buffer *source = container_of(blist, struct comp_buffer, - sink_list); bool stop = false; if (source->source && source->source->state > COMP_STATE_READY) @@ -182,6 +181,8 @@ static int mixer_reset(struct processing_module *mod) if (stop) /* should not reset the downstream components */ return PPL_STATUS_PATH_STOP; + + source = comp_dev_get_next_data_producer(dev, source); } } @@ -214,15 +215,15 @@ static int mixer_prepare(struct processing_module *mod, struct mixer_data *md = module_get_private_data(mod); struct comp_dev *dev = mod->dev; struct comp_buffer *sink; - struct list_item *blist; sink = comp_dev_get_first_data_consumer(dev); md->mix_func = mixer_get_processing_function(dev, sink); mixer_set_frame_alignment(&sink->stream); /* check each mixer source state */ - list_for_item(blist, &dev->bsource_list) { - struct comp_buffer *source; + struct comp_buffer *source = comp_dev_get_first_data_producer(dev); + + while (source) { bool stop; /* @@ -233,7 +234,6 @@ static int mixer_prepare(struct processing_module *mod, * preparing the mixer, so they shouldn't touch it until we're * done. */ - source = container_of(blist, struct comp_buffer, sink_list); mixer_set_frame_alignment(&source->stream); stop = source->source && (source->source->state == COMP_STATE_PAUSED || source->source->state == COMP_STATE_ACTIVE); @@ -241,6 +241,9 @@ static int mixer_prepare(struct processing_module *mod, /* only prepare downstream if we have no active sources */ if (stop) return PPL_STATUS_PATH_STOP; + + + source = comp_dev_get_next_data_producer(dev, source); } /* prepare downstream */ diff --git a/src/audio/mux/mux.c b/src/audio/mux/mux.c index 3c0f9a8f5b38..ef01521456e6 100644 --- a/src/audio/mux/mux.c +++ b/src/audio/mux/mux.c @@ -292,7 +292,6 @@ static int mux_process(struct processing_module *mod, struct comp_data *cd = module_get_private_data(mod); struct comp_dev *dev = mod->dev; struct comp_buffer *source; - struct list_item *clist; const struct audio_stream *sources_stream[MUX_MAX_STREAMS] = { NULL }; int frames = 0; int sink_bytes; @@ -303,8 +302,8 @@ static int mux_process(struct processing_module *mod, /* 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 = comp_dev_get_first_data_producer(dev); + while (source) { if (source->source->state == dev->state) { if (frames) frames = MIN(frames, input_buffers[j].size); @@ -320,6 +319,8 @@ static int mux_process(struct processing_module *mod, sources_stream[i] = &source->stream; } j++; + + source = comp_dev_get_next_data_producer(dev, source); } /* check if there are any sources active */ @@ -335,11 +336,13 @@ static int mux_process(struct processing_module *mod, /* Update consumed and produced */ j = 0; - list_for_item(clist, &dev->bsource_list) { - source = container_of(clist, struct comp_buffer, sink_list); + source = comp_dev_get_first_data_producer(dev); + while (source) { if (source->source->state == dev->state) mod->input_buffers[j].consumed = source_bytes; j++; + + source = comp_dev_get_next_data_producer(dev, source); } mod->output_buffers[0].size = sink_bytes; return 0; @@ -347,7 +350,6 @@ static int mux_process(struct processing_module *mod, static int mux_reset(struct processing_module *mod) { - struct list_item *blist; struct comp_data *cd = module_get_private_data(mod); struct comp_dev *dev = mod->dev; int dir = dev->pipeline->source_comp->direction; @@ -355,15 +357,17 @@ static int mux_reset(struct processing_module *mod) comp_dbg(dev, "mux_reset()"); if (dir == SOF_IPC_STREAM_PLAYBACK) { - list_for_item(blist, &dev->bsource_list) { - struct comp_buffer *source = container_of(blist, struct comp_buffer, - sink_list); + struct comp_buffer *source = comp_dev_get_first_data_producer(dev); + + while (source) { int state = source->source->state; /* only mux the sources with the same state with mux */ if (state > COMP_STATE_READY) /* should not reset the downstream components */ return PPL_STATUS_PATH_STOP; + + source = comp_dev_get_next_data_producer(dev, source); } } @@ -437,9 +441,6 @@ static int mux_set_config(struct processing_module *mod, uint32_t config_id, static int demux_trigger(struct processing_module *mod, int cmd) { - struct list_item *li; - struct comp_buffer *b; - /* Check for cross-pipeline sinks: in general foreign * pipelines won't be started synchronously with ours (it's * under control of host software), so output can't be @@ -449,10 +450,13 @@ static int demux_trigger(struct processing_module *mod, int cmd) * themselves. */ if (cmd == COMP_TRIGGER_PRE_START) { - list_for_item(li, &mod->dev->bsink_list) { - b = container_of(li, struct comp_buffer, source_list); + struct comp_buffer *b = comp_dev_get_first_data_producer(mod->dev); + + while (b) { if (b->sink->pipeline != mod->dev->pipeline) audio_stream_set_overrun(&b->stream, true); + + b = comp_dev_get_next_data_producer(mod->dev, b); } } diff --git a/src/audio/mux/mux_ipc4.c b/src/audio/mux/mux_ipc4.c index bd0071901805..2a4c0c9ffbfe 100644 --- a/src/audio/mux/mux_ipc4.c +++ b/src/audio/mux/mux_ipc4.c @@ -74,7 +74,6 @@ static void set_mux_params(struct processing_module *mod) struct comp_data *cd = module_get_private_data(mod); struct comp_dev *dev = mod->dev; struct comp_buffer *sink, *source; - struct list_item *source_list; int j; params->direction = dev->direction; @@ -106,9 +105,8 @@ static void set_mux_params(struct processing_module *mod) if (!list_is_empty(&dev->bsource_list)) { struct ipc4_audio_format *audio_fmt; - list_for_item(source_list, &dev->bsource_list) - { - source = container_of(source_list, struct comp_buffer, sink_list); + source = comp_dev_get_first_data_producer(dev); + while (source) { j = buf_get_id(source); cd->config.streams[j].pipeline_id = buffer_pipeline_id(source); if (j == BASE_CFG_QUEUED_ID) @@ -117,6 +115,8 @@ static void set_mux_params(struct processing_module *mod) audio_fmt = &cd->md.reference_format; ipc4_update_buffer_format(source, audio_fmt); + + source = comp_dev_get_next_data_producer(dev, source); } } diff --git a/src/audio/smart_amp/smart_amp.c b/src/audio/smart_amp/smart_amp.c index 80100022ef71..149f4a7c1844 100644 --- a/src/audio/smart_amp/smart_amp.c +++ b/src/audio/smart_amp/smart_amp.c @@ -731,7 +731,6 @@ static int smart_amp_resolve_mod_fmt(struct comp_dev *dev, uint32_t least_req_de static int smart_amp_prepare(struct comp_dev *dev) { struct smart_amp_data *sad = comp_get_drvdata(dev); - struct list_item *blist; uint16_t ff_src_fmt, fb_src_fmt, resolved_mod_fmt; uint32_t least_req_depth; uint32_t rate; @@ -744,14 +743,15 @@ static int smart_amp_prepare(struct comp_dev *dev) return ret; /* searching for stream and feedback source buffers */ - list_for_item(blist, &dev->bsource_list) { - struct comp_buffer *source_buffer = container_of(blist, struct comp_buffer, - sink_list); + struct comp_buffer *source_buffer = comp_dev_get_first_data_producer(dev); + while (source_buffer) { if (source_buffer->source->ipc_config.type == SOF_COMP_DEMUX) sad->feedback_buf = source_buffer; else sad->source_buf = source_buffer; + + source_buffer = comp_dev_get_next_data_producer(dev, source_buffer); } /* sink buffer */ diff --git a/src/probe/probe.c b/src/probe/probe.c index c7795cbf0203..a7eb70713c7f 100644 --- a/src/probe/probe.c +++ b/src/probe/probe.c @@ -1061,17 +1061,18 @@ static bool probe_purpose_needs_ext_dma(uint32_t purpose) static struct comp_buffer *ipc4_get_buffer(struct ipc_comp_dev *dev, probe_point_id_t probe_point) { struct comp_buffer *buf; - struct list_item *source_list; unsigned int queue_id; switch (probe_point.fields.type) { case PROBE_TYPE_INPUT: - list_for_item(source_list, &dev->cd->bsource_list) { - buf = container_of(source_list, struct comp_buffer, sink_list); + buf = comp_dev_get_first_data_producer(dev->cd); + while (buf) { queue_id = IPC4_SRC_QUEUE_ID(buf_get_id(buf)); if (queue_id == probe_point.fields.index) return buf; + + buf = comp_dev_get_next_data_producer(dev->cd, buf); } break; case PROBE_TYPE_OUTPUT: diff --git a/src/samples/audio/smart_amp_test_ipc3.c b/src/samples/audio/smart_amp_test_ipc3.c index 5406c41b1037..74573aa1f3f8 100644 --- a/src/samples/audio/smart_amp_test_ipc3.c +++ b/src/samples/audio/smart_amp_test_ipc3.c @@ -487,7 +487,6 @@ static int smart_amp_prepare(struct comp_dev *dev) { struct smart_amp_data *sad = comp_get_drvdata(dev); struct comp_buffer *source_buffer; - struct list_item *blist; int ret; comp_info(dev, "smart_amp_prepare()"); @@ -500,15 +499,15 @@ static int smart_amp_prepare(struct comp_dev *dev) return PPL_STATUS_PATH_STOP; /* searching for stream and feedback source buffers */ - list_for_item(blist, &dev->bsource_list) { - source_buffer = container_of(blist, struct comp_buffer, - sink_list); - + source_buffer = comp_dev_get_first_data_producer(dev); + while (source_buffer) { /* FIXME: how often can this loop be run? */ if (source_buffer->source->ipc_config.type == SOF_COMP_DEMUX) sad->feedback_buf = source_buffer; else sad->source_buf = source_buffer; + + source_buffer = comp_dev_get_next_data_producer(dev, source_buffer); } sad->sink_buf = comp_dev_get_first_data_consumer(dev);