Skip to content

Commit

Permalink
audio: module adapter: separate generic source to ipc3 and ipc4
Browse files Browse the repository at this point in the history
There is a lot of check inside in generic source file for ipc3,
so first duplicate then remove those checks from ipc4.

Signed-off-by: Baofeng Tian <[email protected]>
  • Loading branch information
btian1 committed Sep 13, 2023
1 parent 72d79de commit 8d6d803
Show file tree
Hide file tree
Showing 9 changed files with 473 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/audio/module_adapter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@


if(CONFIG_IPC_MAJOR_3)
add_local_sources(sof module_adapter.c module_adapter_ipc3.c module/generic.c)
add_local_sources(sof module_adapter.c module_adapter_ipc3.c module/generic_ipc3.c)
elseif(CONFIG_IPC_MAJOR_4)
add_local_sources(sof module_adapter.c module_adapter_ipc4.c module/generic.c)
add_local_sources(sof module_adapter.c module_adapter_ipc4.c module/generic_ipc4.c)
endif()

if((NOT CONFIG_LIBRARY) OR CONFIG_LIBRARY_STATIC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,11 @@ int module_init(struct processing_module *mod, struct module_interface *interfac

comp_dbg(dev, "module_init() start");

#if CONFIG_IPC_MAJOR_3
if (mod->priv.state == MODULE_INITIALIZED)
return 0;
if (mod->priv.state > MODULE_INITIALIZED)
return -EPERM;
#endif

if (!interface) {
comp_err(dev, "module_init(): could not find module interface for comp id %d",
dev_comp_id(dev));
Expand Down Expand Up @@ -119,9 +118,8 @@ int module_init(struct processing_module *mod, struct module_interface *interfac
}

comp_dbg(dev, "module_init() done");
#if CONFIG_IPC_MAJOR_3

md->state = MODULE_INITIALIZED;
#endif

return ret;
}
Expand Down Expand Up @@ -205,12 +203,11 @@ int module_prepare(struct processing_module *mod,

comp_dbg(dev, "module_prepare() start");

#if CONFIG_IPC_MAJOR_3
if (mod->priv.state == MODULE_IDLE)
return 0;
if (mod->priv.state < MODULE_INITIALIZED)
return -EPERM;
#endif

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",
Expand All @@ -227,10 +224,8 @@ int module_prepare(struct processing_module *mod,

md->cfg.avail = false;
md->cfg.data = NULL;

#if CONFIG_IPC_MAJOR_3
md->state = MODULE_IDLE;
#endif

comp_dbg(dev, "module_prepare() done");

return ret;
Expand All @@ -248,7 +243,6 @@ int module_process_legacy(struct processing_module *mod,

comp_dbg(dev, "module_process_legacy() start");

#if CONFIG_IPC_MAJOR_3
if (md->state != MODULE_IDLE) {
comp_err(dev, "module_process(): wrong state of comp_id %x, state %d",
dev_comp_id(dev), md->state);
Expand All @@ -257,7 +251,6 @@ int module_process_legacy(struct processing_module *mod,

/* set state to processing */
md->state = MODULE_PROCESSING;
#endif
if (md->ops->process_audio_stream)
ret = md->ops->process_audio_stream(mod, input_buffers, num_input_buffers,
output_buffers, num_output_buffers);
Expand All @@ -275,10 +268,9 @@ int module_process_legacy(struct processing_module *mod,

comp_dbg(dev, "module_process_legacy() done");

#if CONFIG_IPC_MAJOR_3
/* reset state to idle */
md->state = MODULE_IDLE;
#endif

return 0;
}

Expand All @@ -294,7 +286,6 @@ int module_process_sink_src(struct processing_module *mod,

comp_dbg(dev, "module_process sink src() start");

#if CONFIG_IPC_MAJOR_3
if (md->state != MODULE_IDLE) {
comp_err(dev, "module_process(): wrong state of comp_id %x, state %d",
dev_comp_id(dev), md->state);
Expand All @@ -303,7 +294,6 @@ int module_process_sink_src(struct processing_module *mod,

/* set state to processing */
md->state = MODULE_PROCESSING;
#endif
assert(md->ops->process);
ret = md->ops->process(mod, sources, num_of_sources, sinks, num_of_sinks);

Expand All @@ -315,10 +305,9 @@ int module_process_sink_src(struct processing_module *mod,

comp_dbg(dev, "module_process sink src() done");

#if CONFIG_IPC_MAJOR_3
/* reset state to idle */
md->state = MODULE_IDLE;
#endif

return ret;
}

Expand All @@ -327,11 +316,9 @@ int module_reset(struct processing_module *mod)
int ret;
struct module_data *md = &mod->priv;

#if CONFIG_IPC_MAJOR_3
/* if the module was never prepared, no need to reset */
if (md->state < MODULE_IDLE)
return 0;
#endif

ret = md->ops->reset(mod);
if (ret) {
Expand All @@ -347,13 +334,12 @@ int module_reset(struct processing_module *mod)
rfree(md->cfg.data);
md->cfg.data = NULL;

#if CONFIG_IPC_MAJOR_3
/*
* reset the state to allow the module's prepare callback to be invoked again for the
* subsequent triggers
*/
md->state = MODULE_INITIALIZED;
#endif

return 0;
}

Expand Down Expand Up @@ -391,9 +377,8 @@ int module_free(struct processing_module *mod)
rfree(md->runtime_params);
md->runtime_params = NULL;
}
#if CONFIG_IPC_MAJOR_3
md->state = MODULE_DISABLED;
#endif

return ret;
}

Expand All @@ -418,12 +403,8 @@ int module_set_configuration(struct processing_module *mod,
const uint8_t *fragment_in, size_t fragment_size, uint8_t *response,
size_t response_size)
{
#if CONFIG_IPC_MAJOR_3
struct sof_ipc_ctrl_data *cdata = (struct sof_ipc_ctrl_data *)fragment_in;
const uint8_t *fragment = (const uint8_t *)cdata->data[0].data;
#elif CONFIG_IPC_MAJOR_4
const uint8_t *fragment = fragment_in;
#endif
struct module_data *md = &mod->priv;
struct comp_dev *dev = mod->dev;
size_t offset = 0;
Expand Down
Loading

0 comments on commit 8d6d803

Please sign in to comment.