Skip to content

Commit

Permalink
module_adapter: Make free, reset and prepare methods optional
Browse files Browse the repository at this point in the history
Simple modules may not need to provide free, reset and prepare functions.
To avoid having to provide dummy methods, added an if to check if a module
implemented these methods.

Signed-off-by: Adrian Warecki <adrian.warecki@intel.com>
  • Loading branch information
softwarecki authored and kv2019i committed Nov 30, 2023
1 parent 285c090 commit ae21a31
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
46 changes: 25 additions & 21 deletions src/audio/module_adapter/module/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,8 @@ int module_init(struct processing_module *mod, const struct module_interface *in
return -EIO;
}

/*check interface, there must be one and only one of processing procedure */
if (!interface->init || !interface->prepare ||
!interface->reset || !interface->free ||
/* check interface, there must be one and only one of processing procedure */
if (!interface->init ||
(!!interface->process + !!interface->process_audio_stream +
!!interface->process_raw_data != 1)) {
comp_err(dev, "module_init(): comp %d is missing mandatory interfaces",
Expand Down Expand Up @@ -211,11 +210,13 @@ int module_prepare(struct processing_module *mod,
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",
ret, dev_comp_id(dev));
return ret;
if (md->ops->prepare) {
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",
ret, dev_comp_id(dev));
return ret;
}
}

/* After prepare is done we no longer need runtime configuration
Expand Down Expand Up @@ -331,14 +332,15 @@ int module_reset(struct processing_module *mod)
if (md->state < MODULE_IDLE)
return 0;
#endif

ret = md->ops->reset(mod);
if (ret) {
if (ret != PPL_STATUS_PATH_STOP)
comp_err(mod->dev,
"module_reset() error %d: module specific reset() failed for comp %d",
ret, dev_comp_id(mod->dev));
return ret;
if (md->ops->reset) {
ret = md->ops->reset(mod);
if (ret) {
if (ret != PPL_STATUS_PATH_STOP)
comp_err(mod->dev,
"module_reset() error %d: module specific reset() failed for comp %d",
ret, dev_comp_id(mod->dev));
return ret;
}
}

md->cfg.avail = false;
Expand Down Expand Up @@ -373,13 +375,15 @@ void module_free_all_memory(struct processing_module *mod)

int module_free(struct processing_module *mod)
{
int ret;
int ret = 0;
struct module_data *md = &mod->priv;

ret = md->ops->free(mod);
if (ret)
comp_warn(mod->dev, "module_free(): error: %d for %d",
ret, dev_comp_id(mod->dev));
if (md->ops->free) {
ret = md->ops->free(mod);
if (ret)
comp_warn(mod->dev, "module_free(): error: %d for %d",
ret, dev_comp_id(mod->dev));
}

/* Free all memory shared by module_adapter & module */
md->cfg.avail = false;
Expand Down
6 changes: 3 additions & 3 deletions src/include/module/module/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct module_interface {
*/
int (*init)(struct processing_module *mod);
/**
* Module specific prepare procedure, called as part of module_adapter
* (optional) Module specific prepare procedure, called as part of module_adapter
* component preparation in .prepare()
*/
int (*prepare)(struct processing_module *mod,
Expand Down Expand Up @@ -196,13 +196,13 @@ struct module_interface {
enum module_processing_mode (*get_processing_mode)(struct processing_module *mod);

/**
* Module specific reset procedure, called as part of module_adapter component
* (optional) Module specific reset procedure, called as part of module_adapter component
* reset in .reset(). This should reset all parameters to their initial stage
* and free all memory allocated during prepare().
*/
int (*reset)(struct processing_module *mod);
/**
* Module specific free procedure, called as part of module_adapter component
* (optional) Module specific free procedure, called as part of module_adapter component
* free in .free(). This should free all memory allocated during module initialization.
*/
int (*free)(struct processing_module *mod);
Expand Down

0 comments on commit ae21a31

Please sign in to comment.