Skip to content

Commit 2873535

Browse files
committed
module-adapter: allow multiple processing modes to be implemented
The module-adapter API has 3 processing modes: raw, stream and source-sink, and until now only one of them can be implemented by any module. However, the "modules" module, that loads loadable modules, has to implement all of them to be prepared to handle any loadable modules. This adds support for such modules. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent ecd69e0 commit 2873535

File tree

5 files changed

+69
-16
lines changed

5 files changed

+69
-16
lines changed

src/audio/module_adapter/module/generic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ int module_init(struct processing_module *mod, const struct module_interface *in
9898
/* check interface, there must be one and only one of processing procedure */
9999
if (!interface->init ||
100100
(!!interface->process + !!interface->process_audio_stream +
101-
!!interface->process_raw_data != 1)) {
101+
!!interface->process_raw_data < 1)) {
102102
comp_err(dev, "module_init(): comp %d is missing mandatory interfaces",
103103
dev_comp_id(dev));
104104
return -EIO;

src/audio/module_adapter/module/modules.c

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,21 @@ static int modules_init(struct processing_module *mod)
142142
struct module_interface *mod_in =
143143
(struct module_interface *)md->module_adapter;
144144

145+
/* The order of preference */
146+
if (mod_in->process)
147+
mod->proc_type = MODULE_PROCESS_TYPE_SOURCE_SINK;
148+
else if (mod_in->process_audio_stream)
149+
mod->proc_type = MODULE_PROCESS_TYPE_STREAM;
150+
else if (mod_in->process_raw_data)
151+
mod->proc_type = MODULE_PROCESS_TYPE_RAW;
152+
else
153+
return -EINVAL;
154+
145155
ret = mod_in->init(mod);
146156
} else {
147157
ret = iadk_wrapper_init(md->module_adapter);
148158
}
159+
149160
return ret;
150161
}
151162

@@ -195,18 +206,45 @@ static int modules_init_process(struct processing_module *mod)
195206
return 0;
196207
}
197208

209+
static int modules_process(struct processing_module *mod,
210+
struct sof_source **sources, int num_of_sources,
211+
struct sof_sink **sinks, int num_of_sinks)
212+
{
213+
if (!mod->is_native_sof)
214+
return -EOPNOTSUPP;
215+
216+
struct module_interface *mod_in = (struct module_interface *)mod->priv.module_adapter;
217+
218+
return mod_in->process(mod, sources, num_of_sources, sinks, num_of_sinks);
219+
}
220+
221+
static int modules_process_audio_stream(struct processing_module *mod,
222+
struct input_stream_buffer *input_buffers,
223+
int num_input_buffers,
224+
struct output_stream_buffer *output_buffers,
225+
int num_output_buffers)
226+
{
227+
if (!mod->is_native_sof)
228+
return -EOPNOTSUPP;
229+
230+
struct module_interface *mod_in = (struct module_interface *)mod->priv.module_adapter;
231+
232+
return mod_in->process_audio_stream(mod, input_buffers, num_input_buffers,
233+
output_buffers, num_output_buffers);
234+
}
235+
198236
/*
199-
* \brief modules_process.
237+
* \brief modules_process_raw.
200238
* \param[in] mod - processing module pointer.
201239
*
202240
* \return: zero on success
203241
* error code on failure
204242
*/
205-
static int modules_process(struct processing_module *mod,
206-
struct input_stream_buffer *input_buffers,
207-
int num_input_buffers,
208-
struct output_stream_buffer *output_buffers,
209-
int num_output_buffers)
243+
static int modules_process_raw(struct processing_module *mod,
244+
struct input_stream_buffer *input_buffers,
245+
int num_input_buffers,
246+
struct output_stream_buffer *output_buffers,
247+
int num_output_buffers)
210248
{
211249
struct comp_dev *dev = mod->dev;
212250
struct module_data *md = &mod->priv;
@@ -384,7 +422,9 @@ static int modules_reset(struct processing_module *mod)
384422
static const struct module_interface interface = {
385423
.init = modules_init,
386424
.prepare = modules_prepare,
387-
.process_raw_data = modules_process,
425+
.process_raw_data = modules_process_raw,
426+
.process = modules_process,
427+
.process_audio_stream = modules_process_audio_stream,
388428
.set_processing_mode = modules_set_processing_mode,
389429
.get_processing_mode = modules_get_processing_mode,
390430
.set_configuration = modules_set_configuration,

src/audio/module_adapter/module_adapter.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv,
9494
mod->max_sources = 1;
9595
mod->max_sinks = 1;
9696

97+
/* The order of preference */
98+
if (interface->process)
99+
mod->proc_type = MODULE_PROCESS_TYPE_SOURCE_SINK;
100+
else if (interface->process_audio_stream)
101+
mod->proc_type = MODULE_PROCESS_TYPE_STREAM;
102+
else if (interface->process_raw_data)
103+
mod->proc_type = MODULE_PROCESS_TYPE_RAW;
104+
else
105+
goto err;
106+
97107
/* Init processing module */
98108
ret = module_init(mod, interface);
99109
if (ret) {

src/include/module/module/base.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ struct module_data {
6060
#endif /* SOF_MODULE_PRIVATE */
6161
};
6262

63+
enum module_processing_type {
64+
MODULE_PROCESS_TYPE_SOURCE_SINK,
65+
MODULE_PROCESS_TYPE_STREAM,
66+
MODULE_PROCESS_TYPE_RAW,
67+
};
68+
6369
/*
6470
* A pointer to this structure is passed to module API functions (from struct module_interface).
6571
* This structure should contain only fields that should be available to a module.
@@ -154,6 +160,8 @@ struct processing_module {
154160
uint32_t max_sources;
155161
uint32_t max_sinks;
156162
#endif /* SOF_MODULE_PRIVATE */
163+
164+
enum module_processing_type proc_type;
157165
};
158166

159167
#endif /* __MODULE_MODULE_GENERIC__ */

src/include/sof/audio/module_adapter/module/generic.h

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,9 @@
2525
* helpers to determine processing type
2626
* Needed till all the modules use PROCESSING_MODE_SINK_SOURCE
2727
*/
28-
#define IS_PROCESSING_MODE_AUDIO_STREAM(mod) \
29-
(!!((struct module_data *)&(mod)->priv)->ops->process_audio_stream)
30-
31-
#define IS_PROCESSING_MODE_RAW_DATA(mod) \
32-
(!!((struct module_data *)&(mod)->priv)->ops->process_raw_data)
33-
34-
#define IS_PROCESSING_MODE_SINK_SOURCE(mod) \
35-
(!!((struct module_data *)&(mod)->priv)->ops->process)
28+
#define IS_PROCESSING_MODE_AUDIO_STREAM(mod) ((mod)->proc_type == MODULE_PROCESS_TYPE_STREAM)
29+
#define IS_PROCESSING_MODE_RAW_DATA(mod) ((mod)->proc_type == MODULE_PROCESS_TYPE_RAW)
30+
#define IS_PROCESSING_MODE_SINK_SOURCE(mod) ((mod)->proc_type == MODULE_PROCESS_TYPE_SOURCE_SINK)
3631

3732
#define MAX_BLOB_SIZE 8192
3833
#define MODULE_MAX_SOURCES 8

0 commit comments

Comments
 (0)