Skip to content

Commit

Permalink
list_for_item(blist, &dev->bsink_list) { struct comp_buffer *sink = c…
Browse files Browse the repository at this point in the history
…ontainer_of(blist, struct comp_buffer, source_list);
  • Loading branch information
marcinszkudlinski committed Sep 13, 2024
1 parent a215528 commit c7ae2ea
Show file tree
Hide file tree
Showing 15 changed files with 114 additions and 87 deletions.
15 changes: 9 additions & 6 deletions src/audio/copier/copier.c
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,14 @@ 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) {
sink = comp_dev_get_first_data_consumer(dev);
while (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 All @@ -475,6 +474,8 @@ static int copier_copy_to_sinks(struct copier_data *cd, struct comp_dev *dev,
dev->ipc_config.id);
break;
}

sink = comp_dev_get_next_data_consumer(dev, sink);
}

if (!ret) {
Expand Down Expand Up @@ -1066,20 +1067,22 @@ 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_get_first_data_consumer(dev);

while (buffer) {
uint32_t id = IPC4_SRC_QUEUE_ID(buf_get_id(buffer));

if (src_queue_id == id) {
ipc4_update_buffer_format(buffer, &cd->out_fmt[id]);
return 0;
}

buffer = comp_dev_get_next_data_consumer(dev, buffer);
}

comp_err(dev, "No sink buffer found for src_queue = %u", src_queue_id);
Expand Down
9 changes: 4 additions & 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,14 +79,14 @@ 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) {
sink = comp_dev_get_first_data_consumer(dev);
while (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]);

sink = comp_dev_get_next_data_consumer(dev, sink);
}

/* update params for the DMA buffer */
Expand Down
14 changes: 8 additions & 6 deletions src/audio/crossover/crossover.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,14 @@ 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) {
sink = comp_dev_get_first_data_consumer(dev);
while (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 @@ -145,6 +144,8 @@ static int crossover_assign_sinks(struct processing_module *mod,
assigned_obufs[i] = &output_buffers[j];
enabled[j++] = true;
num_sinks++;

sink = comp_dev_get_next_data_consumer(dev, sink);
}

return num_sinks;
Expand Down Expand Up @@ -529,7 +530,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 +546,8 @@ 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);
sink = comp_dev_get_first_data_consumer(dev);
while (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 All @@ -556,6 +556,8 @@ static int crossover_prepare(struct processing_module *mod,

if (ret < 0)
return ret;

sink = comp_dev_get_next_data_consumer(dev, sink);
}

comp_info(dev, "crossover_prepare(), source_format=%d, sink_formats=%d, nch=%d",
Expand Down
7 changes: 4 additions & 3 deletions src/audio/crossover/crossover_ipc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ 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) {
sink = comp_dev_get_first_data_consumer(dev);
while (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 All @@ -63,6 +62,8 @@ int crossover_check_sink_assign(struct processing_module *mod,

assigned_sinks[i] = true;
num_assigned_sinks++;

sink = comp_dev_get_next_data_consumer(dev, sink);
}

return num_assigned_sinks;
Expand Down
7 changes: 4 additions & 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,10 @@ 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);
sinkb = comp_dev_get_first_data_consumer(dev);
while (sinkb) {
ipc4_update_buffer_format(sinkb, &mod->priv.cfg.base_cfg.audio_fmt);

sinkb = comp_dev_get_next_data_consumer(dev, sinkb);
}
}
43 changes: 24 additions & 19 deletions src/audio/dai-zephyr.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,17 @@ 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;

sink = comp_dev_get_first_data_consumer(dev);
while (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 All @@ -306,6 +305,8 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
ret = stream_copy_from_no_consume(dd->local_buffer, sink,
converter[j], bytes, dd->chmap);
}

sink = comp_dev_get_next_data_consumer(dev, sink);
}
#endif
ret = dma_buffer_copy_to(dd->local_buffer, dd->dma_buffer,
Expand All @@ -319,20 +320,19 @@ 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;

sink = comp_dev_get_first_data_consumer(dev);
while (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 All @@ -359,6 +359,8 @@ dai_dma_cb(struct dai_data *dd, struct comp_dev *dev, uint32_t bytes,
ret = stream_copy_from_no_consume(dd->dma_buffer,
sink, converter[j],
bytes, dd->chmap);

sink = comp_dev_get_next_data_consumer(dev, sink);
}
}
#endif
Expand Down Expand Up @@ -1592,29 +1594,29 @@ 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;

sink = comp_dev_get_first_data_consumer(dev);
while (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 &&
sink->hw_params_configured) {
sink_frames =
audio_stream_get_free_frames(&sink->stream);
frames = MIN(frames, sink_frames);

sink = comp_dev_get_next_data_consumer(dev, sink);
}
}
} else {
struct list_item *sink_list;

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

/*
Expand All @@ -1630,11 +1632,12 @@ 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;

sink = comp_dev_get_first_data_consumer(dev);
while (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 @@ -1643,6 +1646,8 @@ int dai_common_copy(struct dai_data *dd, struct comp_dev *dev, pcm_converter_fun
audio_stream_get_free_frames(&sink->stream);
frames = MIN(frames, sink_frames);
}

sink = comp_dev_get_next_data_consumer(dev, sink);
}
}

Expand Down
22 changes: 12 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 = comp_dev_get_first_data_consumer(dev);

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

if (!sink->sink) {
Expand All @@ -361,6 +360,8 @@ static int kpb_bind(struct comp_dev *dev, void *data)
else
kpb->host_sink = sink;
}

sink = comp_dev_get_next_data_consumer(dev, sink);
}

return ret;
Expand Down Expand Up @@ -858,10 +859,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 = comp_dev_get_first_data_consumer(dev);

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

if (!sink->sink) {
Expand All @@ -882,25 +882,27 @@ static int kpb_prepare(struct comp_dev *dev)
default:
break;
}

sink = comp_dev_get_next_data_consumer(dev, sink);
}
#else
/* Update number of sel_sink channels.
* 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_get_first_data_consumer(dev);

while (sink) {
sink_id = buf_get_id(sink);

if (sink_id == 0)
audio_stream_set_channels(&sink->stream, kpb->num_of_sel_mic);
else
audio_stream_set_channels(&sink->stream, kpb->config.channels);

sink = comp_dev_get_next_data_consumer(dev, sink);
}
}
#endif /* CONFIG_IPC_MAJOR_4 */
Expand Down
Loading

0 comments on commit c7ae2ea

Please sign in to comment.