Skip to content

Commit 22c398c

Browse files
lyakhRanderWang
authored andcommitted
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> Signed-off-by: Rander Wang <rander.wang@intel.com>
1 parent 5f3d492 commit 22c398c

File tree

5 files changed

+72
-18
lines changed

5 files changed

+72
-18
lines changed

src/audio/module_adapter/module/generic.c

Lines changed: 3 additions & 3 deletions
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;
@@ -258,10 +258,10 @@ int module_process_legacy(struct processing_module *mod,
258258
/* set state to processing */
259259
md->state = MODULE_PROCESSING;
260260
#endif
261-
if (md->ops->process_audio_stream)
261+
if (IS_PROCESSING_MODE_AUDIO_STREAM(mod))
262262
ret = md->ops->process_audio_stream(mod, input_buffers, num_input_buffers,
263263
output_buffers, num_output_buffers);
264-
else if (md->ops->process_raw_data)
264+
else if (IS_PROCESSING_MODE_RAW_DATA(mod))
265265
ret = md->ops->process_raw_data(mod, input_buffers, num_input_buffers,
266266
output_buffers, num_output_buffers);
267267
else

src/audio/module_adapter/module/modules.c

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,22 @@ 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 {
157+
mod->proc_type = MODULE_PROCESS_TYPE_RAW;
147158
ret = iadk_wrapper_init(md->module_adapter);
148159
}
160+
149161
return ret;
150162
}
151163

@@ -195,18 +207,45 @@ static int modules_init_process(struct processing_module *mod)
195207
return 0;
196208
}
197209

210+
static int modules_process(struct processing_module *mod,
211+
struct sof_source **sources, int num_of_sources,
212+
struct sof_sink **sinks, int num_of_sinks)
213+
{
214+
if (!mod->is_native_sof)
215+
return -EOPNOTSUPP;
216+
217+
struct module_interface *mod_in = (struct module_interface *)mod->priv.module_adapter;
218+
219+
return mod_in->process(mod, sources, num_of_sources, sinks, num_of_sinks);
220+
}
221+
222+
static int modules_process_audio_stream(struct processing_module *mod,
223+
struct input_stream_buffer *input_buffers,
224+
int num_input_buffers,
225+
struct output_stream_buffer *output_buffers,
226+
int num_output_buffers)
227+
{
228+
if (!mod->is_native_sof)
229+
return -EOPNOTSUPP;
230+
231+
struct module_interface *mod_in = (struct module_interface *)mod->priv.module_adapter;
232+
233+
return mod_in->process_audio_stream(mod, input_buffers, num_input_buffers,
234+
output_buffers, num_output_buffers);
235+
}
236+
198237
/*
199-
* \brief modules_process.
238+
* \brief modules_process_raw.
200239
* \param[in] mod - processing module pointer.
201240
*
202241
* \return: zero on success
203242
* error code on failure
204243
*/
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)
244+
static int modules_process_raw(struct processing_module *mod,
245+
struct input_stream_buffer *input_buffers,
246+
int num_input_buffers,
247+
struct output_stream_buffer *output_buffers,
248+
int num_output_buffers)
210249
{
211250
struct comp_dev *dev = mod->dev;
212251
struct module_data *md = &mod->priv;
@@ -384,7 +423,9 @@ static int modules_reset(struct processing_module *mod)
384423
static const struct module_interface interface = {
385424
.init = modules_init,
386425
.prepare = modules_prepare,
387-
.process_raw_data = modules_process,
426+
.process_raw_data = modules_process_raw,
427+
.process = modules_process,
428+
.process_audio_stream = modules_process_audio_stream,
388429
.set_processing_mode = modules_set_processing_mode,
389430
.get_processing_mode = modules_get_processing_mode,
390431
.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
@@ -93,6 +93,16 @@ struct comp_dev *module_adapter_new(const struct comp_driver *drv,
9393
mod->max_sources = 1;
9494
mod->max_sinks = 1;
9595

96+
/* The order of preference */
97+
if (interface->process)
98+
mod->proc_type = MODULE_PROCESS_TYPE_SOURCE_SINK;
99+
else if (interface->process_audio_stream)
100+
mod->proc_type = MODULE_PROCESS_TYPE_STREAM;
101+
else if (interface->process_raw_data)
102+
mod->proc_type = MODULE_PROCESS_TYPE_RAW;
103+
else
104+
goto err;
105+
96106
/* Init processing module */
97107
ret = module_init(mod, interface);
98108
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.
@@ -153,6 +159,8 @@ struct processing_module {
153159
/* max source/sinks supported by the module */
154160
uint32_t max_sources;
155161
uint32_t max_sinks;
162+
163+
enum module_processing_type proc_type;
156164
#endif /* SOF_MODULE_PRIVATE */
157165
};
158166

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)