Skip to content

Commit

Permalink
list_for_item(blist, &dev->bsource_list) {
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinszkudlinski committed Sep 13, 2024
1 parent 968a024 commit 9c22d1c
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 68 deletions.
19 changes: 11 additions & 8 deletions src/audio/mixer/mixer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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;

/*
Expand All @@ -233,14 +234,16 @@ 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);

/* 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 */
Expand Down
21 changes: 10 additions & 11 deletions src/audio/module_adapter/module_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,6 @@ static int module_adapter_audio_stream_type_copy(struct comp_dev *dev)
struct comp_buffer *sources[PLATFORM_MAX_STREAMS];
struct comp_buffer *sinks[PLATFORM_MAX_STREAMS];
struct processing_module *mod = comp_mod(dev);
struct list_item *blist;
uint32_t num_input_buffers, num_output_buffers;
int ret, i = 0;

Expand All @@ -809,11 +808,11 @@ static int module_adapter_audio_stream_type_copy(struct comp_dev *dev)
}

i = 0;
list_for_item(blist, &dev->bsource_list) {
struct comp_buffer *source;

source = container_of(blist, struct comp_buffer, sink_list);
struct comp_buffer *source = comp_dev_get_first_data_producer(dev);
while(source) {
sources[i++] = source;

source = comp_dev_get_next_data_producer(dev, source);
}
num_input_buffers = i;
if (num_input_buffers > mod->max_sources) {
Expand Down Expand Up @@ -909,29 +908,29 @@ static int module_adapter_copy_ring_buffers(struct comp_dev *dev)
* DP module processing itself will take place in DP thread
* This is an adapter, to be removed when pipeline2.0 is ready
*/
struct comp_buffer *buffer;
struct processing_module *mod = comp_mod(dev);
struct list_item *blist;
int err;

list_for_item(blist, &dev->bsource_list) {
buffer = comp_dev_get_first_data_producer(dev);
while(buffer) {
/* input - we need to copy data from audio_stream (as source)
* to ring_buffer (as sink)
*/
struct comp_buffer *buffer =
container_of(blist, struct comp_buffer, sink_list);
err = audio_buffer_sync_secondary_buffer(&buffer->audio_buffer, UINT_MAX);

if (err) {
comp_err(dev, "LL to DP copy error status: %d", err);
return err;
}

buffer = comp_dev_get_next_data_producer(dev, buffer);
}

if (mod->dp_startup_delay)
return 0;

struct comp_buffer *buffer = comp_dev_get_first_data_consumer(dev);

buffer = comp_dev_get_first_data_consumer(dev);
while(buffer) {
/* output - we need to copy data from ring_buffer (as source)
* to audio_stream (as sink)
Expand Down
20 changes: 10 additions & 10 deletions src/audio/module_adapter/module_adapter_ipc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,23 @@ void module_adapter_set_params(struct processing_module *mod, struct sof_ipc_str

static int module_source_status_count(struct comp_dev *dev, uint32_t status)
{
struct list_item *blist;
int count = 0;

/* count source with state == status */
list_for_item(blist, &dev->bsource_list) {
struct comp_buffer *source = comp_dev_get_first_data_producer(dev);

while(source) {
/*
* FIXME: this is racy, state can be changed by another core.
* This is implicitly protected by serialised IPCs. Even when
* IPCs are processed in the pipeline thread, the next IPC will
* not be sent until the thread has processed and replied to the
* current one.
*/
struct comp_buffer *source = container_of(blist, struct comp_buffer,
sink_list);

if (source->source && source->source->state == status)
count++;

source = comp_dev_get_next_data_producer(dev, source);
}

return count;
Expand Down Expand Up @@ -321,7 +321,6 @@ int module_adapter_cmd(struct comp_dev *dev, int cmd, void *data, int max_data_s
int module_adapter_sink_src_prepare(struct comp_dev *dev)
{
struct processing_module *mod = comp_mod(dev);
struct list_item *blist;
int ret;
int i;

Expand All @@ -337,13 +336,14 @@ int module_adapter_sink_src_prepare(struct comp_dev *dev)
}
mod->num_of_sinks = i;

i = 0;
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);

i = 0;
while(source_buffer) {
mod->sources[i] = audio_buffer_get_source(&source_buffer->audio_buffer);
i++;

source_buffer = comp_dev_get_next_data_producer(dev, source_buffer);
}
mod->num_of_sources = i;

Expand Down
9 changes: 5 additions & 4 deletions src/audio/module_adapter/module_adapter_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ EXPORT_SYMBOL(module_adapter_get_attribute);
static bool module_adapter_multi_sink_source_prepare(struct comp_dev *dev)
{
struct processing_module *mod = comp_mod(dev);
struct list_item *blist;
int i;

/* acquire all sink and source buffers, get handlers to sink/source API */
Expand All @@ -202,13 +201,15 @@ static bool module_adapter_multi_sink_source_prepare(struct comp_dev *dev)
}
mod->num_of_sinks = i;


i = 0;
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) {
mod->sources[i] = audio_buffer_get_source(&source_buffer->audio_buffer);
i++;

source_buffer = comp_dev_get_next_data_producer(dev, source_buffer);
}
mod->num_of_sources = i;

Expand Down
21 changes: 12 additions & 9 deletions src/audio/mux/mux.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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 */
Expand All @@ -335,35 +336,37 @@ 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;
}

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;

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);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/audio/mux/mux_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/audio/smart_amp/smart_amp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -744,14 +743,14 @@ 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 */
Expand Down
10 changes: 4 additions & 6 deletions src/ipc/ipc3/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,15 @@ static bool is_hostless_downstream(struct comp_dev *current)
/* check if a pipeline is hostless when walking upstream */
static bool is_hostless_upstream(struct comp_dev *current)
{
struct list_item *clist;

/* check if current is a HOST comp */
if (current->ipc_config.type == SOF_COMP_HOST ||
current->ipc_config.type == SOF_COMP_SG_HOST)
return false;

/* check if the pipeline has a HOST comp upstream */
list_for_item(clist, &current->bsource_list) {
struct comp_buffer *buffer;

buffer = container_of(clist, struct comp_buffer, sink_list);
struct comp_buffer *buffer = comp_dev_get_first_data_producer(current);

while(buffer) {
/* don't go upstream if this component is not connected */
if (!buffer->source)
continue;
Expand All @@ -190,6 +186,8 @@ static bool is_hostless_upstream(struct comp_dev *current)
/* return if there is a host comp upstream */
if (!is_hostless_upstream(buffer->source))
return false;

buffer = comp_dev_get_next_data_producer(current, buffer);
}

return true;
Expand Down
Loading

0 comments on commit 9c22d1c

Please sign in to comment.