From 9728021982b7a2081543780642b922b2c5183095 Mon Sep 17 00:00:00 2001 From: Jaroslaw Stelter Date: Fri, 15 Dec 2023 14:45:37 +0100 Subject: [PATCH] iadk: module_adapter: Switch IADK modules to use source/sink The IADK libraries should support source/sink interface. This patch changes IADK adapter part to implement source/sink interface. Signed-off-by: Jaroslaw Stelter --- .../iadk/iadk_module_adapter.cpp | 56 +++++++++++-------- src/audio/module_adapter/module/modules.c | 32 ++++------- .../module_adapter/iadk/iadk_module_adapter.h | 23 +++++--- 3 files changed, 59 insertions(+), 52 deletions(-) diff --git a/src/audio/module_adapter/iadk/iadk_module_adapter.cpp b/src/audio/module_adapter/iadk/iadk_module_adapter.cpp index c71f2dd2bc1c..a540a1eb5b8c 100644 --- a/src/audio/module_adapter/iadk/iadk_module_adapter.cpp +++ b/src/audio/module_adapter/iadk/iadk_module_adapter.cpp @@ -37,45 +37,55 @@ int IadkModuleAdapter::IadkModuleAdapter_Prepare(void) return 0; } -uint32_t IadkModuleAdapter::IadkModuleAdapter_Process(struct input_stream_buffer *input_buffers, - int num_input_buffers, - struct output_stream_buffer *output_buffers, - int num_output_buffers) +uint32_t IadkModuleAdapter::IadkModuleAdapter_Process(struct sof_source **sources, + int num_of_sources, + struct sof_sink **sinks, + int num_of_sinks) { uint32_t ret = 0; - if ((num_input_buffers > 0) && (num_output_buffers > 0)) { + + if ((num_of_sources > 0) && (num_of_sinks > 0)) { intel_adsp::InputStreamBuffer input_stream_buffers[INPUT_PIN_COUNT]; intel_adsp::OutputStreamBuffer output_stream_buffers[OUTPUT_PIN_COUNT]; - for (int i = 0; i < (int)num_input_buffers; i++) { + for (int i = 0; i < (int)num_of_sources; i++) { + uint8_t *input, *input_start; + size_t input_end, i_size; + intel_adsp::InputStreamFlags flags = {}; - flags.end_of_stream = input_buffers[i].end_of_stream; + i_size = source_get_data_available(sources[i]); + ret = source_get_data(sources[i], i_size, (const void **)&input, + (const void **)&input_start, &input_end); const intel_adsp::InputStreamBuffer isb_data( - (uint8_t *)input_buffers[i].data, - input_buffers[i].size, - flags); + (uint8_t *)input, i_size, flags); new (&input_stream_buffers[i]) intel_adsp::InputStreamBuffer(isb_data); } - for (int i = 0; i < (int)num_output_buffers; i++) { + for (int i = 0; i < num_of_sinks; i++) { + uint8_t *output, *output_start; + size_t output_end, o_size; + + o_size = sink_get_free_size(sinks[i]); + ret = sink_get_buffer(sinks[i], o_size, (void **)&output, + (void **)&output_start, &output_end); const intel_adsp::OutputStreamBuffer osb_data( - (uint8_t *)output_buffers[i].data, - output_buffers[i].size); + (uint8_t *)output, o_size); new (&output_stream_buffers[i]) intel_adsp::OutputStreamBuffer(osb_data); } ret = processing_module_.Process(input_stream_buffers, output_stream_buffers); - for (int i = 0; i < (int)num_input_buffers; i++) { - input_buffers[i].consumed = input_buffers[i].size; + for (int i = 0; i < num_of_sources; i++) { + source_release_data(sources[i], input_stream_buffers[i].size); } - for (int i = 0; i < (int)num_output_buffers; i++) { - output_buffers[i].size = output_stream_buffers[i].size; + for (int i = 0; i < num_of_sinks; i++) { + sink_commit_buffer(sinks[i], output_stream_buffers[i].size); } } return ret; } + AdspErrorCode IadkModuleAdapter::IadkModuleAdapter_SetConfiguration(uint32_t config_id, enum module_cfg_fragment_position pos, @@ -204,15 +214,15 @@ int iadk_wrapper_get_configuration(void *md, uint32_t config_id, fragment_size); } - -int iadk_wrapper_process(void *md, struct input_stream_buffer *input_buffers, - int num_input_buffers, struct output_stream_buffer *output_buffers, - int num_output_buffers) +int iadk_wrapper_process(void *md, + struct sof_source **sources, int num_of_sources, + struct sof_sink **sinks, int num_of_sinks) { struct IadkModuleAdapter *mod_adp = (struct IadkModuleAdapter *) md; - return mod_adp->IadkModuleAdapter_Process(input_buffers, num_input_buffers, - output_buffers, num_output_buffers); + return mod_adp->IadkModuleAdapter_Process(sources, num_of_sources, + sinks, num_of_sinks); } + } /* namespace dsp_fw */ #ifdef __cplusplus diff --git a/src/audio/module_adapter/module/modules.c b/src/audio/module_adapter/module/modules.c index 61bcd7b02421..cd617846ff85 100644 --- a/src/audio/module_adapter/module/modules.c +++ b/src/audio/module_adapter/module/modules.c @@ -154,7 +154,7 @@ static int modules_init(struct processing_module *mod) ret = mod_in->init(mod); } else { - mod->proc_type = MODULE_PROCESS_TYPE_RAW; + mod->proc_type = MODULE_PROCESS_TYPE_SOURCE_SINK; ret = iadk_wrapper_init(md->module_adapter); } @@ -212,7 +212,8 @@ static int modules_process(struct processing_module *mod, struct sof_sink **sinks, int num_of_sinks) { if (!mod->is_native_sof) - return -EOPNOTSUPP; + return iadk_wrapper_process(mod->priv.module_adapter, sources, + num_of_sources, sinks, num_of_sinks); struct module_interface *mod_in = (struct module_interface *)mod->priv.module_adapter; @@ -247,33 +248,20 @@ static int modules_process_raw(struct processing_module *mod, struct output_stream_buffer *output_buffers, int num_output_buffers) { - struct comp_dev *dev = mod->dev; struct module_data *md = &mod->priv; - struct list_item *blist; - int ret; - int i = 0; + + if (!mod->is_native_sof) + return -EOPNOTSUPP; if (!md->mpd.init_done) modules_init_process(mod); - /* IADK modules require output buffer size to set to its real size. */ - list_for_item(blist, &dev->bsource_list) { - mod->output_buffers[i].size = md->mpd.out_buff_size; - i++; - } /* Call module specific process function. */ - if (mod->is_native_sof) { - struct module_interface *mod_in = - (struct module_interface *)mod->priv.module_adapter; + struct module_interface *mod_in = + (struct module_interface *)mod->priv.module_adapter; - ret = mod_in->process_raw_data(mod, input_buffers, num_input_buffers, - output_buffers, num_output_buffers); - } else { - ret = iadk_wrapper_process(mod->priv.module_adapter, input_buffers, - num_input_buffers, output_buffers, - num_output_buffers); - } - return ret; + return mod_in->process_raw_data(mod, input_buffers, num_input_buffers, + output_buffers, num_output_buffers); } /** diff --git a/src/include/sof/audio/module_adapter/iadk/iadk_module_adapter.h b/src/include/sof/audio/module_adapter/iadk/iadk_module_adapter.h index 4c5f8b2e71ce..0d353582e998 100644 --- a/src/include/sof/audio/module_adapter/iadk/iadk_module_adapter.h +++ b/src/include/sof/audio/module_adapter/iadk/iadk_module_adapter.h @@ -16,8 +16,17 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + #include +#ifdef __cplusplus +} /* extern "C" */ +#endif + + extern "C" { namespace dsp_fw { @@ -56,10 +65,10 @@ namespace dsp_fw * samples provided by the codec_adapter and produce/output the processed * ones back to codec_adapter. */ - uint32_t IadkModuleAdapter_Process(struct input_stream_buffer *input_buffers, - int num_input_buffers, - struct output_stream_buffer *output_buffers, - int num_output_buffers); + uint32_t IadkModuleAdapter_Process(struct sof_source **sources, + int num_of_sources, + struct sof_sink **sinks, + int num_of_sinks); /** * Module specific apply config procedure, called by codec_adapter every time @@ -137,9 +146,9 @@ int iadk_wrapper_get_configuration(void *md, uint32_t config_id, uint32_t data_offset_size, uint8_t *fragment, size_t fragment_size); -int iadk_wrapper_process(void *md, struct input_stream_buffer *input_buffers, - int num_input_buffers, struct output_stream_buffer *output_buffers, - int num_output_buffers); +int iadk_wrapper_process(void *md, + struct sof_source **sources, int num_of_sources, + struct sof_sink **sinks, int num_of_sinks); #endif /* __cplusplus */