Skip to content

Commit

Permalink
module: prepare sink & source in bind & unbind function
Browse files Browse the repository at this point in the history
Module will update source & sink information when bind & unbind
event happen. Remove duplicate source & sink prepare in prepare
function.

Signed-off-by: Marcin Szkudlinski <marcin.szkudlinski@intel.com>
Signed-off-by: Rander Wang <rander.wang@intel.com>
  • Loading branch information
RanderWang committed Dec 8, 2023
1 parent a41f26d commit f2dbad7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 48 deletions.
42 changes: 5 additions & 37 deletions src/audio/module_adapter/module_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,39 +119,6 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv,
return NULL;
}

static int module_adapter_sink_src_prepare(struct comp_dev *dev)
{
struct processing_module *mod = comp_get_drvdata(dev);
struct list_item *blist;
int ret;
int i;

/* acquire all sink and source buffers, get handlers to sink/source API */
i = 0;
list_for_item(blist, &dev->bsink_list) {
struct comp_buffer *sink_buffer =
container_of(blist, struct comp_buffer, source_list);
mod->sinks[i] = audio_stream_get_sink(&sink_buffer->stream);
i++;
}
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);

mod->sources[i] = audio_stream_get_source(&source_buffer->stream);
i++;
}
mod->num_of_sources = i;

/* Prepare module */
ret = module_prepare(mod, mod->sources, mod->num_of_sources, mod->sinks, mod->num_of_sinks);

return ret;
}

#if CONFIG_ZEPHYR_DP_SCHEDULER
static int module_adapter_dp_queue_prepare(struct comp_dev *dev)
{
Expand All @@ -171,7 +138,7 @@ static int module_adapter_dp_queue_prepare(struct comp_dev *dev)
list_init(&mod->dp_queue_ll_to_dp_list);
list_init(&mod->dp_queue_dp_to_ll_list);

ret = module_adapter_sink_src_prepare(dev);
ret = module_prepare(mod, mod->sources, mod->num_of_sources, mod->sinks, mod->num_of_sinks);
if (ret)
return ret;

Expand All @@ -198,7 +165,7 @@ static int module_adapter_dp_queue_prepare(struct comp_dev *dev)
goto err;
dp_queue_append_to_list(dp_queue, &mod->dp_queue_ll_to_dp_list);

/* it will override source pointers set by module_adapter_sink_src_prepare
/* it will override source pointers set before
* module will use shadow dpQueue for processing
*/
mod->sources[i] = dp_queue_get_source(dp_queue);
Expand Down Expand Up @@ -232,7 +199,7 @@ static int module_adapter_dp_queue_prepare(struct comp_dev *dev)
goto err;

dp_queue_append_to_list(dp_queue, &mod->dp_queue_dp_to_ll_list);
/* it will override sink pointers set by module_adapter_sink_src_prepare
/* it will override sink pointers set before
* module will use shadow dpQueue for processing
*/
mod->sinks[i] = dp_queue_get_sink(dp_queue);
Expand Down Expand Up @@ -328,7 +295,8 @@ int module_adapter_prepare(struct comp_dev *dev)

else if (IS_PROCESSING_MODE_SINK_SOURCE(mod) &&
mod->dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_LL)
ret = module_adapter_sink_src_prepare(dev);
ret = module_prepare(mod, mod->sources, mod->num_of_sources,
mod->sinks, mod->num_of_sinks);

else if ((IS_PROCESSING_MODE_RAW_DATA(mod) || IS_PROCESSING_MODE_AUDIO_STREAM(mod)) &&
mod->dev->ipc_config.proc_domain == COMP_PROCESSING_DOMAIN_LL)
Expand Down
35 changes: 24 additions & 11 deletions src/audio/module_adapter/module_adapter_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,35 @@ int module_adapter_get_attribute(struct comp_dev *dev, uint32_t type, void *valu
return 0;
}

static bool module_adapter_multi_sink_source_check(struct comp_dev *dev)
static bool module_adapter_multi_sink_source_prepare(struct comp_dev *dev)
{
struct processing_module *mod = comp_get_drvdata(dev);
struct list_item *blist;
int num_sources = 0;
int num_sinks = 0;
int i;

/* acquire all sink and source buffers, get handlers to sink/source API */
i = 0;
list_for_item(blist, &dev->bsink_list) {
struct comp_buffer *sink_buffer =
container_of(blist, struct comp_buffer, source_list);
mod->sinks[i] = audio_stream_get_sink(&sink_buffer->stream);
i++;
}
mod->num_of_sinks = i;

list_for_item(blist, &dev->bsource_list)
num_sources++;
i = 0;
list_for_item(blist, &dev->bsource_list) {
struct comp_buffer *source_buffer =
container_of(blist, struct comp_buffer, sink_list);

list_for_item(blist, &dev->bsink_list)
num_sinks++;
mod->sources[i] = audio_stream_get_source(&source_buffer->stream);
i++;
}
mod->num_of_sources = i;

comp_dbg(dev, "num_sources=%d num_sinks=%d", num_sources, num_sinks);
comp_dbg(dev, "num_sources=%d num_sinks=%d", mod->num_of_sinks, mod->num_of_sinks);

if (num_sources != 1 || num_sinks != 1)
if (mod->num_of_sinks != 1 || mod->num_of_sinks != 1)
return true;

/* re-assign the source/sink modules */
Expand All @@ -190,7 +203,7 @@ int module_adapter_bind(struct comp_dev *dev, void *data)
if (ret < 0)
return ret;

mod->stream_copy_single_to_single = !module_adapter_multi_sink_source_check(dev);
mod->stream_copy_single_to_single = !module_adapter_multi_sink_source_prepare(dev);

return 0;
}
Expand All @@ -204,7 +217,7 @@ int module_adapter_unbind(struct comp_dev *dev, void *data)
if (ret < 0)
return ret;

mod->stream_copy_single_to_single = !module_adapter_multi_sink_source_check(dev);
mod->stream_copy_single_to_single = !module_adapter_multi_sink_source_prepare(dev);

return 0;
}
Expand Down
2 changes: 2 additions & 0 deletions src/include/sof/audio/module_adapter/module/modules.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ static inline void declare_dynamic_module_adapter(struct comp_driver *drv,
drv->ops.set_large_config = module_set_large_config;
drv->ops.get_large_config = module_get_large_config;
drv->ops.get_attribute = module_adapter_get_attribute;
drv->ops.bind = module_adapter_bind;
drv->ops.unbind = module_adapter_unbind;
}

#endif /* __SOF_AUDIO_MODULES__ */

0 comments on commit f2dbad7

Please sign in to comment.