Skip to content

Commit

Permalink
iadk: module_adapter: Switch IADK modules to use source/sink
Browse files Browse the repository at this point in the history
The IADK libraries should support source/sink interface. This patch
changes IADK adapter part to implement source/sink interface.

Signed-off-by: Jaroslaw Stelter <Jaroslaw.Stelter@intel.com>
  • Loading branch information
jxstelter committed Dec 18, 2023
1 parent 68c6357 commit 417c2e5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 52 deletions.
59 changes: 36 additions & 23 deletions src/audio/module_adapter/iadk/iadk_module_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
extern "C" {
#endif

#include <sof/audio/sink_api.h>
#include <sof/audio/source_api.h>

typedef intel_adsp::ProcessingModuleInterface::ErrorCode::Type IntelErrorCode;

namespace dsp_fw
Expand All @@ -37,45 +40,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,
Expand Down Expand Up @@ -204,15 +217,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
Expand Down
32 changes: 10 additions & 22 deletions src/audio/module_adapter/module/modules.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

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

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

/**
Expand Down
22 changes: 15 additions & 7 deletions src/include/sof/audio/module_adapter/iadk/iadk_module_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@
#include <adsp_stddef.h>
#include <system_error.h>

#ifdef __cplusplus
extern "C" {
#endif

#include <sof/audio/module_adapter/module/module_interface.h>

#ifdef __cplusplus
} /* extern "C" */
#endif

extern "C" {
namespace dsp_fw
{
Expand Down Expand Up @@ -56,10 +64,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
Expand Down Expand Up @@ -137,9 +145,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 */

Expand Down

0 comments on commit 417c2e5

Please sign in to comment.