From fa77edf9a47ed186fc30a9692f141a434e26369f Mon Sep 17 00:00:00 2001 From: Marcin Szkudlinski Date: Mon, 12 Jun 2023 12:55:29 +0200 Subject: [PATCH] pipeline2.0: change module prepare API to use sink/src.c Module prepare is an operation that needs to set up sink and source according to needs. Therefore it must have access to sink/source handlers This commit adds handlers to API. In case the module uses legacy audio stream sink/source pointers will be NULLs and number of sinks/sources will be zero Signed-off-by: Marcin Szkudlinski --- src/audio/eq_fir/eq_fir.c | 4 +- src/audio/eq_iir/eq_iir.c | 4 +- src/audio/mfcc/mfcc.c | 4 +- src/audio/mixer/mixer.c | 4 +- src/audio/mixin_mixout/mixin_mixout.c | 8 ++- src/audio/module_adapter/module/cadence.c | 4 +- src/audio/module_adapter/module/dts.c | 4 +- src/audio/module_adapter/module/generic.c | 6 +- .../module_adapter/module/iadk_modules.c | 4 +- src/audio/module_adapter/module/passthrough.c | 4 +- .../module_adapter/module/volume/volume.c | 4 +- src/audio/module_adapter/module/waves.c | 4 +- src/audio/module_adapter/module_adapter.c | 55 ++++++++++++++++++- src/audio/mux/mux.c | 4 +- src/audio/selector/selector.c | 4 +- src/audio/tdfb/tdfb.c | 4 +- src/audio/up_down_mixer/up_down_mixer.c | 4 +- .../sof/audio/module_adapter/module/generic.h | 4 +- .../module_adapter/module/module_interface.h | 4 +- src/samples/audio/smart_amp_test_ipc4.c | 4 +- test/cmocka/src/audio/eq_fir/eq_fir_process.c | 2 +- test/cmocka/src/audio/eq_iir/eq_iir_process.c | 2 +- 22 files changed, 117 insertions(+), 24 deletions(-) diff --git a/src/audio/eq_fir/eq_fir.c b/src/audio/eq_fir/eq_fir.c index 0b9e46f12..98efc0f72 100644 --- a/src/audio/eq_fir/eq_fir.c +++ b/src/audio/eq_fir/eq_fir.c @@ -564,7 +564,9 @@ static void eq_fir_set_alignment(struct audio_stream __sparse_cache *source, audio_stream_init_alignment_constants(byte_align, frame_align_req, sink); } -static int eq_fir_prepare(struct processing_module *mod) +static int eq_fir_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct comp_data *cd = module_get_private_data(mod); struct comp_buffer *sourceb, *sinkb; diff --git a/src/audio/eq_iir/eq_iir.c b/src/audio/eq_iir/eq_iir.c index 5004e1324..a14f564e5 100644 --- a/src/audio/eq_iir/eq_iir.c +++ b/src/audio/eq_iir/eq_iir.c @@ -879,7 +879,9 @@ static void eq_iir_set_passthrough_func(struct comp_data *cd, #endif } -static int eq_iir_prepare(struct processing_module *mod) +static int eq_iir_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct comp_data *cd = module_get_private_data(mod); struct comp_buffer *sourceb, *sinkb; diff --git a/src/audio/mfcc/mfcc.c b/src/audio/mfcc/mfcc.c index 744fafb36..b93e49dab 100644 --- a/src/audio/mfcc/mfcc.c +++ b/src/audio/mfcc/mfcc.c @@ -186,7 +186,9 @@ static void mfcc_set_alignment(struct audio_stream *source, struct audio_stream audio_stream_init_alignment_constants(byte_align, frame_align_req, sink); } -static int mfcc_prepare(struct processing_module *mod) +static int mfcc_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct mfcc_comp_data *cd = module_get_private_data(mod); struct comp_buffer *sourceb; diff --git a/src/audio/mixer/mixer.c b/src/audio/mixer/mixer.c index f9b2f92ca..f7d967ca7 100644 --- a/src/audio/mixer/mixer.c +++ b/src/audio/mixer/mixer.c @@ -217,7 +217,9 @@ static inline void mixer_set_frame_alignment(struct audio_stream __sparse_cache audio_stream_init_alignment_constants(byte_align, frame_align_req, source); } -static int mixer_prepare(struct processing_module *mod) +static int mixer_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct mixer_data *md = module_get_private_data(mod); struct comp_buffer __sparse_cache *sink_c; diff --git a/src/audio/mixin_mixout/mixin_mixout.c b/src/audio/mixin_mixout/mixin_mixout.c index af081f491..a4f969780 100644 --- a/src/audio/mixin_mixout/mixin_mixout.c +++ b/src/audio/mixin_mixout/mixin_mixout.c @@ -686,7 +686,9 @@ static int mixin_params(struct processing_module *mod) * We should also make sure that we propagate the prepare call to downstream * if downstream is not currently active. */ -static int mixin_prepare(struct processing_module *mod) +static int mixin_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct mixin_data *md = module_get_private_data(mod); struct comp_dev *dev = mod->dev; @@ -805,7 +807,9 @@ static int mixout_params(struct processing_module *mod) return 0; } -static int mixout_prepare(struct processing_module *mod) +static int mixout_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct module_source_info __sparse_cache *mod_source_info; struct comp_dev *dev = mod->dev; diff --git a/src/audio/module_adapter/module/cadence.c b/src/audio/module_adapter/module/cadence.c index 5ae8715ca..250bf4373 100644 --- a/src/audio/module_adapter/module/cadence.c +++ b/src/audio/module_adapter/module/cadence.c @@ -501,7 +501,9 @@ static int cadence_codec_init_process(struct processing_module *mod) return 0; } -static int cadence_codec_prepare(struct processing_module *mod) +static int cadence_codec_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { int ret = 0, mem_tabs_size; struct comp_dev *dev = mod->dev; diff --git a/src/audio/module_adapter/module/dts.c b/src/audio/module_adapter/module/dts.c index c59e51990..a2d7cb54e 100644 --- a/src/audio/module_adapter/module/dts.c +++ b/src/audio/module_adapter/module/dts.c @@ -183,7 +183,9 @@ static int dts_codec_init(struct processing_module *mod) return ret; } -static int dts_codec_prepare(struct processing_module *mod) +static int dts_codec_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { int ret; struct comp_dev *dev = mod->dev; diff --git a/src/audio/module_adapter/module/generic.c b/src/audio/module_adapter/module/generic.c index 521152d2e..ef29ec7c4 100644 --- a/src/audio/module_adapter/module/generic.c +++ b/src/audio/module_adapter/module/generic.c @@ -192,7 +192,9 @@ static int validate_config(struct module_config *cfg) return 0; } -int module_prepare(struct processing_module *mod) +int module_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { int ret; struct module_data *md = &mod->priv; @@ -205,7 +207,7 @@ int module_prepare(struct processing_module *mod) if (mod->priv.state < MODULE_INITIALIZED) return -EPERM; - ret = md->ops->prepare(mod); + ret = md->ops->prepare(mod, sources, num_of_sources, sinks, num_of_sinks); if (ret) { comp_err(dev, "module_prepare() error %d: module specific prepare failed, comp_id %d", ret, dev_comp_id(dev)); diff --git a/src/audio/module_adapter/module/iadk_modules.c b/src/audio/module_adapter/module/iadk_modules.c index 3af85e271..bf7e9aa1c 100644 --- a/src/audio/module_adapter/module/iadk_modules.c +++ b/src/audio/module_adapter/module/iadk_modules.c @@ -117,7 +117,9 @@ static int iadk_modules_init(struct processing_module *mod) * configuration. Its internal structure is proprietary to the module implementation. * There is one assumption - all IADK modules utilize IPC4 protocol. */ -static int iadk_modules_prepare(struct processing_module *mod) +static int iadk_modules_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct comp_dev *dev = mod->dev; int ret = 0; diff --git a/src/audio/module_adapter/module/passthrough.c b/src/audio/module_adapter/module/passthrough.c index 46b652adb..a7e41c04f 100644 --- a/src/audio/module_adapter/module/passthrough.c +++ b/src/audio/module_adapter/module/passthrough.c @@ -20,7 +20,9 @@ static int passthrough_codec_init(struct processing_module *mod) return 0; } -static int passthrough_codec_prepare(struct processing_module *mod) +static int passthrough_codec_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct comp_dev *dev = mod->dev; struct module_data *codec = &mod->priv; diff --git a/src/audio/module_adapter/module/volume/volume.c b/src/audio/module_adapter/module/volume/volume.c index 48a167cf8..f36b03da1 100644 --- a/src/audio/module_adapter/module/volume/volume.c +++ b/src/audio/module_adapter/module/volume/volume.c @@ -1242,7 +1242,9 @@ static void volume_set_alignment(struct audio_stream __sparse_cache *source, * Volume component is usually first and last in pipelines so it makes sense * to also do some type of conversion here. */ -static int volume_prepare(struct processing_module *mod) +static int volume_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct vol_data *cd = module_get_private_data(mod); struct module_data *md = &mod->priv; diff --git a/src/audio/module_adapter/module/waves.c b/src/audio/module_adapter/module/waves.c index 5b0b61a97..90b3a24a5 100644 --- a/src/audio/module_adapter/module/waves.c +++ b/src/audio/module_adapter/module/waves.c @@ -688,7 +688,9 @@ static int waves_codec_init(struct processing_module *mod) return ret; } -static int waves_codec_prepare(struct processing_module *mod) +static int waves_codec_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct comp_dev *dev = mod->dev; int ret; diff --git a/src/audio/module_adapter/module_adapter.c b/src/audio/module_adapter/module_adapter.c index 15d299708..bece14f8c 100644 --- a/src/audio/module_adapter/module_adapter.c +++ b/src/audio/module_adapter/module_adapter.c @@ -165,6 +165,55 @@ err: return NULL; } +static int module_adapter_sink_src_prepare(struct comp_dev *dev) +{ + struct comp_buffer __sparse_cache *source_buffers_c[PLATFORM_MAX_STREAMS]; + struct comp_buffer __sparse_cache *sinks_buffers_c[PLATFORM_MAX_STREAMS]; + struct sof_sink __sparse_cache *audio_sink[PLATFORM_MAX_STREAMS]; + struct sof_source __sparse_cache *audio_src[PLATFORM_MAX_STREAMS]; + struct processing_module *mod = comp_get_drvdata(dev); + struct list_item *blist; + uint32_t num_of_sources = 0; + uint32_t num_of_sinks = 0; + int ret; + + /* acquire all sink and source buffers, get handlers to sink/source API */ + list_for_item(blist, &dev->bsink_list) { + struct comp_buffer *sink_buffer_uc; + + sink_buffer_uc = container_of(blist, struct comp_buffer, source_list); + sinks_buffers_c[num_of_sinks] = buffer_acquire(sink_buffer_uc); + audio_sink[num_of_sinks] = + audio_stream_get_sink(&sinks_buffers_c[num_of_sinks]->stream); + sink_reset_num_of_processed_bytes(audio_sink[num_of_sinks]); + num_of_sinks++; + } + + list_for_item(blist, &dev->bsource_list) { + struct comp_buffer *source_buffer_uc; + + source_buffer_uc = container_of(blist, struct comp_buffer, sink_list); + source_buffers_c[num_of_sources] = buffer_acquire(source_buffer_uc); + audio_src[num_of_sources] = + audio_stream_get_source(&source_buffers_c[num_of_sources]->stream); + source_reset_num_of_processed_bytes(audio_src[num_of_sources]); + num_of_sources++; + } + + /* Prepare module */ + ret = module_prepare(mod, audio_src, num_of_sources, audio_sink, num_of_sinks); + + /* release all source buffers in reverse order */ + for (int i = num_of_sources - 1; i >= 0; i--) + buffer_release(source_buffers_c[i]); + + /* release all sink buffers in reverse order */ + for (int i = num_of_sinks - 1; i >= 0 ; i--) + buffer_release(sinks_buffers_c[i]); + + return ret; +} + /* * \brief Prepare the module * \param[in] dev - component device pointer. @@ -189,7 +238,11 @@ int module_adapter_prepare(struct comp_dev *dev) comp_dbg(dev, "module_adapter_prepare() start"); /* Prepare module */ - ret = module_prepare(mod); + if (IS_PROCESSING_MODE_SINK_SOURCE(mod)) + ret = module_adapter_sink_src_prepare(dev); + else + ret = module_prepare(mod, NULL, 0, NULL, 0); + if (ret) { if (ret != PPL_STATUS_PATH_STOP) comp_err(dev, "module_adapter_prepare() error %x: module prepare failed", diff --git a/src/audio/mux/mux.c b/src/audio/mux/mux.c index 443a2b24b..e899fcf58 100644 --- a/src/audio/mux/mux.c +++ b/src/audio/mux/mux.c @@ -617,7 +617,9 @@ static int mux_reset(struct processing_module *mod) return 0; } -static int mux_prepare(struct processing_module *mod) +static int mux_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct comp_dev *dev = mod->dev; struct comp_data *cd = module_get_private_data(mod); diff --git a/src/audio/selector/selector.c b/src/audio/selector/selector.c index 9bc6d542e..065c020cb 100644 --- a/src/audio/selector/selector.c +++ b/src/audio/selector/selector.c @@ -890,7 +890,9 @@ static int selector_process(struct processing_module *mod, * \param[in,out] mod Selector base module device. * \return Error code. */ -static int selector_prepare(struct processing_module *mod) +static int selector_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct comp_data *cd = module_get_private_data(mod); struct module_data *md = &mod->priv; diff --git a/src/audio/tdfb/tdfb.c b/src/audio/tdfb/tdfb.c index 24479526b..d1b04b7fa 100644 --- a/src/audio/tdfb/tdfb.c +++ b/src/audio/tdfb/tdfb.c @@ -725,7 +725,9 @@ static void tdfb_set_alignment(struct audio_stream __sparse_cache *source, audio_stream_init_alignment_constants(byte_align, frame_align_req, sink); } -static int tdfb_prepare(struct processing_module *mod) +static int tdfb_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct tdfb_comp_data *cd = module_get_private_data(mod); struct comp_buffer *sourceb, *sinkb; diff --git a/src/audio/up_down_mixer/up_down_mixer.c b/src/audio/up_down_mixer/up_down_mixer.c index 2959556e3..e1887865a 100644 --- a/src/audio/up_down_mixer/up_down_mixer.c +++ b/src/audio/up_down_mixer/up_down_mixer.c @@ -399,7 +399,9 @@ err: } /* just stubs for now. Remove these after making these ops optional in the module adapter */ -static int up_down_mixer_prepare(struct processing_module *mod) +static int up_down_mixer_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct up_down_mixer_data *cd = module_get_private_data(mod); struct comp_dev *dev = mod->dev; diff --git a/src/include/sof/audio/module_adapter/module/generic.h b/src/include/sof/audio/module_adapter/module/generic.h index 22bd45c1f..fc4c8b9fd 100644 --- a/src/include/sof/audio/module_adapter/module/generic.h +++ b/src/include/sof/audio/module_adapter/module/generic.h @@ -219,7 +219,9 @@ int module_init(struct processing_module *mod, struct module_interface *interfac void *module_allocate_memory(struct processing_module *mod, uint32_t size, uint32_t alignment); int module_free_memory(struct processing_module *mod, void *ptr); void module_free_all_memory(struct processing_module *mod); -int module_prepare(struct processing_module *mod); +int module_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks); int module_process_sink_src(struct processing_module *mod, struct sof_source __sparse_cache **sources, int num_of_sources, struct sof_sink __sparse_cache **sinks, int num_of_sinks); diff --git a/src/include/sof/audio/module_adapter/module/module_interface.h b/src/include/sof/audio/module_adapter/module/module_interface.h index cd7622208..dec02f3cf 100644 --- a/src/include/sof/audio/module_adapter/module/module_interface.h +++ b/src/include/sof/audio/module_adapter/module/module_interface.h @@ -82,7 +82,9 @@ struct module_interface { * Module specific prepare procedure, called as part of module_adapter * component preparation in .prepare() */ - int (*prepare)(struct processing_module *mod); + int (*prepare)(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks); /** * Module specific processing procedure diff --git a/src/samples/audio/smart_amp_test_ipc4.c b/src/samples/audio/smart_amp_test_ipc4.c index 7900c1d6f..e73ca26fd 100644 --- a/src/samples/audio/smart_amp_test_ipc4.c +++ b/src/samples/audio/smart_amp_test_ipc4.c @@ -364,7 +364,9 @@ static int smart_amp_reset(struct processing_module *mod) return 0; } -static int smart_amp_prepare(struct processing_module *mod) +static int smart_amp_prepare(struct processing_module *mod, + struct sof_source __sparse_cache **sources, int num_of_sources, + struct sof_sink __sparse_cache **sinks, int num_of_sinks) { struct smart_amp_data *sad = module_get_private_data(mod); struct comp_dev *dev = mod->dev; diff --git a/test/cmocka/src/audio/eq_fir/eq_fir_process.c b/test/cmocka/src/audio/eq_fir/eq_fir_process.c index c725f64e3..5cd53c1cf 100644 --- a/test/cmocka/src/audio/eq_fir/eq_fir_process.c +++ b/test/cmocka/src/audio/eq_fir/eq_fir_process.c @@ -171,7 +171,7 @@ static int setup(void **state) mod->stream_params->channels = params->channels; mod->period_bytes = get_frame_bytes(params->source_format, params->channels) * 48000 / 1000; - ret = module_prepare(mod); + ret = module_prepare(mod, NULL, 0, NULL, 0); if (ret) return ret; diff --git a/test/cmocka/src/audio/eq_iir/eq_iir_process.c b/test/cmocka/src/audio/eq_iir/eq_iir_process.c index 86295ad32..b960a6997 100644 --- a/test/cmocka/src/audio/eq_iir/eq_iir_process.c +++ b/test/cmocka/src/audio/eq_iir/eq_iir_process.c @@ -170,7 +170,7 @@ static int setup(void **state) mod->stream_params->channels = params->channels; mod->period_bytes = get_frame_bytes(params->source_format, params->channels) * 48000 / 1000; - ret = module_prepare(mod); + ret = module_prepare(mod, NULL, 0, NULL, 0); if (ret) return ret;