Skip to content

Commit

Permalink
buf: use API for sink iteration in components
Browse files Browse the repository at this point in the history
this commit changes all components to use
comp_dev_for_each_consumer for iteration through
bsink_list

pipeline code, like module adapter or ipc helpers was
omitted intentionally

Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
  • Loading branch information
marcinszkudlinski committed Sep 18, 2024
1 parent f5db20a commit 5c35b40
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 62 deletions.
10 changes: 4 additions & 6 deletions src/audio/copier/copier.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,13 @@ static int copier_copy_to_sinks(struct copier_data *cd, struct comp_dev *dev,
struct comp_buffer *src_c,
struct comp_copy_limits *processed_data)
{
struct list_item *sink_list;
struct comp_buffer *sink;
int ret = 0;

/* module copy, one source to multiple sink buffers */
list_for_item(sink_list, &dev->bsink_list) {
comp_dev_for_each_consumer(dev, sink) {
struct comp_dev *sink_dev;

sink = container_of(sink_list, struct comp_buffer, source_list);
sink_dev = sink->sink;
processed_data->sink_bytes = 0;
if (sink_dev->state == COMP_STATE_ACTIVE) {
Expand Down Expand Up @@ -1066,14 +1064,14 @@ static int copier_bind(struct processing_module *mod, void *data)
const uint32_t src_queue_id = bu->extension.r.src_queue;
struct copier_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;
struct list_item *list;

if (dev->ipc_config.id != src_id)
return 0; /* Another component is a data producer */

/* update sink format */
list_for_item(list, &dev->bsink_list) {
struct comp_buffer *buffer = container_of(list, struct comp_buffer, source_list);
struct comp_buffer *buffer;

comp_dev_for_each_consumer(dev, buffer) {
uint32_t id = IPC4_SRC_QUEUE_ID(buf_get_id(buffer));

if (src_queue_id == id) {
Expand Down
6 changes: 1 addition & 5 deletions src/audio/copier/copier_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ void copier_update_params(struct copier_data *cd, struct comp_dev *dev,
struct sof_ipc_stream_params *params)
{
struct comp_buffer *sink;
struct list_item *sink_list;

memset(params, 0, sizeof(*params));
params->direction = cd->direction;
Expand All @@ -80,11 +79,8 @@ void copier_update_params(struct copier_data *cd, struct comp_dev *dev,
params->no_stream_position = 1;

/* update each sink format */
list_for_item(sink_list, &dev->bsink_list) {
comp_dev_for_each_consumer(dev, sink) {
int j;

sink = container_of(sink_list, struct comp_buffer, source_list);

j = IPC4_SINK_QUEUE_ID(buf_get_id(sink));

ipc4_update_buffer_format(sink, &cd->out_fmt[j]);
Expand Down
8 changes: 2 additions & 6 deletions src/audio/crossover/crossover.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,13 @@ static int crossover_assign_sinks(struct processing_module *mod,
struct sof_crossover_config *config = cd->config;
struct comp_dev *dev = mod->dev;
struct comp_buffer *sink;
struct list_item *sink_list;
int num_sinks = 0;
int i;
int j = 0;

list_for_item(sink_list, &dev->bsink_list) {
comp_dev_for_each_consumer(dev, sink) {
unsigned int sink_id, state;

sink = container_of(sink_list, struct comp_buffer, source_list);
sink_id = crossover_get_sink_id(cd, buffer_pipeline_id(sink), j);
state = sink->sink->state;
if (state != dev->state) {
Expand Down Expand Up @@ -529,7 +527,6 @@ static int crossover_prepare(struct processing_module *mod,
struct comp_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;
struct comp_buffer *source, *sink;
struct list_item *sink_list;
int channels;
int ret = 0;

Expand All @@ -546,8 +543,7 @@ static int crossover_prepare(struct processing_module *mod,
channels = audio_stream_get_channels(&source->stream);

/* Validate frame format and buffer size of sinks */
list_for_item(sink_list, &dev->bsink_list) {
sink = container_of(sink_list, struct comp_buffer, source_list);
comp_dev_for_each_consumer(dev, sink) {
if (cd->source_format != audio_stream_get_frm_fmt(&sink->stream)) {
comp_err(dev, "crossover_prepare(): Source fmt %d and sink fmt %d are different.",
cd->source_format, audio_stream_get_frm_fmt(&sink->stream));
Expand Down
4 changes: 1 addition & 3 deletions src/audio/crossover/crossover_ipc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,13 @@ int crossover_check_sink_assign(struct processing_module *mod,
{
struct comp_dev *dev = mod->dev;
struct comp_buffer *sink;
struct list_item *sink_list;
int num_assigned_sinks = 0;
uint8_t assigned_sinks[SOF_CROSSOVER_MAX_STREAMS] = {0};
int i;

list_for_item(sink_list, &dev->bsink_list) {
comp_dev_for_each_consumer(dev, sink) {
unsigned int pipeline_id;

sink = container_of(sink_list, struct comp_buffer, source_list);
pipeline_id = buffer_pipeline_id(sink);

i = crossover_get_stream_index(mod, config, pipeline_id);
Expand Down
4 changes: 1 addition & 3 deletions src/audio/crossover/crossover_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ void crossover_params(struct processing_module *mod)
{
struct sof_ipc_stream_params *params = mod->stream_params;
struct comp_buffer *sinkb, *sourceb;
struct list_item *sink_list;
struct comp_dev *dev = mod->dev;

comp_dbg(dev, "crossover_params()");
Expand All @@ -122,8 +121,7 @@ void crossover_params(struct processing_module *mod)
sourceb = list_first_item(&dev->bsource_list, struct comp_buffer, sink_list);
ipc4_update_buffer_format(sourceb, &mod->priv.cfg.base_cfg.audio_fmt);

list_for_item(sink_list, &dev->bsink_list) {
sinkb = container_of(sink_list, struct comp_buffer, source_list);
comp_dev_for_each_consumer(dev, sinkb) {
ipc4_update_buffer_format(sinkb, &mod->priv.cfg.base_cfg.audio_fmt);
}
}
31 changes: 12 additions & 19 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,16 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,

if (dev->direction == SOF_IPC_STREAM_PLAYBACK) {
#if CONFIG_IPC_MAJOR_4
struct list_item *sink_list;
/*
* copy from local buffer to all sinks that are not gateway buffers
* using the right PCM converter function.
*/
list_for_item(sink_list, &dev->bsink_list) {
struct comp_buffer *sink;

comp_dev_for_each_consumer(dev, sink) {
struct comp_dev *sink_dev;
struct comp_buffer *sink;
int j;

sink = container_of(sink_list, struct comp_buffer, source_list);

if (sink == dd->dma_buffer)
continue;

Expand Down Expand Up @@ -319,20 +317,18 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
ret = stream_copy_from_no_consume(dd->dma_buffer, dd->local_buffer,
dd->process, bytes, dd->chmap);
#if CONFIG_IPC_MAJOR_4
struct list_item *sink_list;
/* Skip in case of endpoint DAI devices created by the copier */
if (converter) {
/*
* copy from DMA buffer to all sink buffers using the right PCM converter
* function
*/
list_for_item(sink_list, &dev->bsink_list) {
struct comp_buffer *sink;

comp_dev_for_each_consumer(dev, sink) {
struct comp_dev *sink_dev;
struct comp_buffer *sink;
int j;

sink = container_of(sink_list, struct comp_buffer, source_list);

/* this has been handled above already */
if (sink == dd->local_buffer)
continue;
Expand Down Expand Up @@ -1592,17 +1588,16 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
sink_frames = free_bytes / audio_stream_frame_bytes(&dd->dma_buffer->stream);
frames = MIN(src_frames, sink_frames);

struct list_item *sink_list;
/*
* In the case of playback DAI's with multiple sink buffers, compute the
* minimum number of frames based on the DMA avail_bytes and the free
* samples in all active sink buffers.
*/
list_for_item(sink_list, &dev->bsink_list) {
struct comp_buffer *sink;

comp_dev_for_each_consumer(dev, sink) {
struct comp_dev *sink_dev;
struct comp_buffer *sink;

sink = container_of(sink_list, struct comp_buffer, source_list);
sink_dev = sink->sink;

if (sink_dev && sink_dev->state == COMP_STATE_ACTIVE &&
Expand All @@ -1613,8 +1608,6 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
}
}
} else {
struct list_item *sink_list;

src_frames = avail_bytes / audio_stream_frame_bytes(&dd->dma_buffer->stream);

/*
Expand All @@ -1630,11 +1623,11 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
* minimum number of samples based on the DMA avail_bytes and the free
* samples in all active sink buffers.
*/
list_for_item(sink_list, &dev->bsink_list) {
struct comp_buffer *sink;

comp_dev_for_each_consumer(dev, sink) {
struct comp_dev *sink_dev;
struct comp_buffer *sink;

sink = container_of(sink_list, struct comp_buffer, source_list);
sink_dev = sink->sink;

if (sink_dev && sink_dev->state == COMP_STATE_ACTIVE &&
Expand Down
16 changes: 6 additions & 10 deletions src/audio/kpb.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ static int kpb_bind(struct comp_dev *dev, void *data)
{
struct comp_data *kpb = comp_get_drvdata(dev);
struct ipc4_module_bind_unbind *bu;
struct list_item *blist;
int buf_id;
int ret = 0;

Expand All @@ -343,9 +342,9 @@ static int kpb_bind(struct comp_dev *dev, void *data)
* (Detector/MicSel has one input pin). To properly connect KPB sink
* with Detector source we're looking for buffer with id=0.
*/
struct comp_buffer *sink;

list_for_item(blist, &dev->bsink_list) {
struct comp_buffer *sink = container_of(blist, struct comp_buffer, source_list);
comp_dev_for_each_consumer(dev, sink) {
int sink_buf_id;

if (!sink->sink) {
Expand Down Expand Up @@ -858,10 +857,9 @@ static int kpb_prepare(struct comp_dev *dev)
* NOTE! We assume here that channel selector component device
* is connected to the KPB sinks as well as host device.
*/
struct list_item *blist;
struct comp_buffer *sink;

list_for_item(blist, &dev->bsink_list) {
struct comp_buffer *sink = container_of(blist, struct comp_buffer, source_list);
comp_dev_for_each_consumer(dev, sink) {
enum sof_comp_type type;

if (!sink->sink) {
Expand All @@ -888,13 +886,11 @@ static int kpb_prepare(struct comp_dev *dev)
* If OBS is not equal to IBS it means that KPB will work in micselector mode.
*/
if (kpb->ipc4_cfg.base_cfg.ibs != kpb->ipc4_cfg.base_cfg.obs) {
struct list_item *sink_list;
uint32_t sink_id;

list_for_item(sink_list, &dev->bsink_list) {
struct comp_buffer *sink =
container_of(sink_list, struct comp_buffer, source_list);
struct comp_buffer *sink;

comp_dev_for_each_consumer(dev, sink) {
sink_id = buf_get_id(sink);

if (sink_id == 0)
Expand Down
4 changes: 1 addition & 3 deletions src/audio/mux/mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,6 @@ static int demux_process(struct processing_module *mod,
{
struct comp_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;
struct list_item *clist;
struct comp_buffer *sink;
struct audio_stream *sinks_stream[MUX_MAX_STREAMS] = { NULL };
struct mux_look_up *look_ups[MUX_MAX_STREAMS] = { NULL };
Expand All @@ -245,8 +244,7 @@ static int demux_process(struct processing_module *mod,
comp_dbg(dev, "demux_process()");

/* align sink streams with their respective configurations */
list_for_item(clist, &dev->bsink_list) {
sink = container_of(clist, struct comp_buffer, source_list);
comp_dev_for_each_consumer(dev, sink) {
if (sink->sink->state == dev->state) {
i = get_stream_index(dev, cd, buffer_pipeline_id(sink));
/* return if index wrong */
Expand Down
6 changes: 2 additions & 4 deletions src/audio/selector/selector.c
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,6 @@ static void set_selector_params(struct processing_module *mod,
const struct sof_selector_ipc4_config *sel_cfg = &cd->sel_ipc4_cfg;
const struct ipc4_audio_format *out_fmt = NULL;
struct comp_buffer *src_buf;
struct list_item *sink_list;
int i;

if (cd->sel_ipc4_cfg.init_payload_fmt == IPC4_SEL_INIT_PAYLOAD_BASE_WITH_EXT)
Expand All @@ -664,10 +663,9 @@ static void set_selector_params(struct processing_module *mod,
params->chmap[i] = (out_fmt->ch_map >> i * 4) & 0xf;

/* update each sink format */
list_for_item(sink_list, &dev->bsink_list) {
struct comp_buffer *sink_buf =
container_of(sink_list, struct comp_buffer, source_list);
struct comp_buffer *sink_buf;

comp_dev_for_each_consumer(dev, sink_buf) {
ipc4_update_buffer_format(sink_buf, out_fmt);
audio_stream_set_channels(&sink_buf->stream, params->channels);
audio_stream_set_rate(&sink_buf->stream, params->rate);
Expand Down
5 changes: 2 additions & 3 deletions src/probe/probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ 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 *sink_list, *source_list;
struct list_item *source_list;
unsigned int queue_id;

switch (probe_point.fields.type) {
Expand All @@ -1075,8 +1075,7 @@ static struct comp_buffer *ipc4_get_buffer(struct ipc_comp_dev *dev, probe_point
}
break;
case PROBE_TYPE_OUTPUT:
list_for_item(sink_list, &dev->cd->bsink_list) {
buf = container_of(sink_list, struct comp_buffer, source_list);
comp_dev_for_each_consumer(dev->cd, buf) {
queue_id = IPC4_SINK_QUEUE_ID(buf_get_id(buf));

if (queue_id == probe_point.fields.index)
Expand Down

0 comments on commit 5c35b40

Please sign in to comment.