Skip to content

Commit

Permalink
waves: store config blob in a cache in waves.c
Browse files Browse the repository at this point in the history
Store/apply config blob in a cache to avoid that
cfg.data will be released after prepare.

Signed-off-by: barry.jan <[email protected]>
  • Loading branch information
barry-waves committed Nov 7, 2023
1 parent f8a9591 commit 739a583
Showing 1 changed file with 96 additions and 9 deletions.
105 changes: 96 additions & 9 deletions src/audio/module_adapter/module/waves/waves.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ struct waves_codec_data {
uint32_t response_max_bytes;
uint32_t request_max_bytes;
void *response;
struct module_config setup_cfg;
struct module_config setup_cfg;
uint32_t config_blob_size;
void *config_blob;
};

enum waves_codec_params {
Expand Down Expand Up @@ -456,6 +458,50 @@ static int waves_effect_revision(struct processing_module *mod)
return 0;
}

/* cache config blob*/
static int waves_effect_cache_config_blob(struct processing_module *mod, void *data, uint32_t size)
{
struct comp_dev *dev = mod->dev;
struct module_data *codec = &mod->priv;
struct waves_codec_data *waves_codec = codec->private;
int ret = 0;

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

/* release old cached config blob*/
if (waves_codec->config_blob && size != waves_codec->config_blob_size) {
comp_info(dev, "waves_effect_cache_config_blob() release blob");
module_free_memory(mod, waves_codec->config_blob);
waves_codec->config_blob = NULL;
waves_codec->config_blob_size = 0;
}

if (!waves_codec->config_blob) {
waves_codec->config_blob = module_allocate_memory(mod, size, 16);
if (!waves_codec->config_blob) {
comp_err(dev,
"waves_effect_cache_config_blob() failed to allocate %d bytes for config blob",
size);
ret = -ENOMEM;
} else {
waves_codec->config_blob_size = size;
memset(waves_codec->config_blob, 0, size);
ret = memcpy_s(waves_codec->config_blob, waves_codec->config_blob_size,
data, size);
if (ret) {
comp_err(dev,
"waves_effect_cache_config_blob(): failed to copy config blob %d",
ret);
module_free_memory(mod, waves_codec->config_blob);
waves_codec->config_blob_size = 0;
ret = -ENOMEM;
}
}
}
comp_dbg(dev, "waves_effect_cache_config_blob() done");
return ret;
}

/* apply MaxxEffect message */
static int waves_effect_message(struct processing_module *mod, void *data, uint32_t size)
{
Expand Down Expand Up @@ -492,6 +538,16 @@ static int waves_effect_message(struct processing_module *mod, void *data, uint3
return 0;
}

static int waves_handle_param_message(struct processing_module *mod, void *data, uint32_t size)
{
int ret = waves_effect_message(mod, data, size);

if (!ret)
ret = waves_effect_cache_config_blob(mod, data, size);

return ret;
}

/* apply codec config */
static int waves_effect_config(struct processing_module *mod)
{
Expand Down Expand Up @@ -544,7 +600,7 @@ static int waves_effect_config(struct processing_module *mod)
comp_info(dev, "waves_codec_configure() NOP");
break;
case PARAM_MESSAGE:
ret = waves_effect_message(mod, param->data, param_data_size);
ret = waves_handle_param_message(mod, param->data, param_data_size);
break;
case PARAM_REVISION:
ret = waves_effect_revision(mod);
Expand Down Expand Up @@ -637,6 +693,10 @@ static int waves_codec_init(struct processing_module *mod)
return ret;
}
setup_cfg->avail = true;

/* init config_blob */
waves_codec->config_blob = NULL;
waves_codec->config_blob_size = 0;
}

ret = MaxxEffect_GetMessageMaxSize(waves_codec->effect, &waves_codec->request_max_bytes,
Expand All @@ -659,6 +719,23 @@ static int waves_codec_init(struct processing_module *mod)
return ret;
}

/* apply config blob */
static int waves_effect_apply_config_blob_cache(struct processing_module *mod)
{
struct comp_dev *dev = mod->dev;
struct module_data *codec = &mod->priv;
struct waves_codec_data *waves_codec = codec->private;
int ret = 0;

comp_dbg(dev, "waves_effect_apply_config_blob_cache()");

if (waves_codec->config_blob) {
ret = waves_effect_message(mod, waves_codec->config_blob,
waves_codec->config_blob_size);
}
return ret;
}

static int waves_codec_prepare(struct processing_module *mod,
struct sof_source **sources, int num_of_sources,
struct sof_sink **sinks, int num_of_sinks)
Expand All @@ -669,21 +746,31 @@ static int waves_codec_prepare(struct processing_module *mod,
comp_dbg(dev, "waves_codec_prepare() start");

ret = waves_effect_check(dev);
if (ret)
goto error;

if (!ret)
ret = waves_effect_init(mod);
ret = waves_effect_init(mod);
if (ret)
goto error;

if (!ret)
ret = waves_effect_buffers(mod);
ret = waves_effect_buffers(mod);
if (ret)
goto error;

if (!ret)
ret = waves_effect_setup_config(mod);
ret = waves_effect_setup_config(mod);
if (ret)
goto error;

ret = waves_effect_apply_config_blob_cache(mod);
if (ret)
comp_err(dev, "waves_codec_prepare() failed %d", ret);
goto error;

comp_dbg(dev, "waves_codec_prepare() done");
return ret;

error:
comp_err(dev, "waves_codec_prepare() failed %d", ret);
return ret;
}

static int waves_codec_init_process(struct processing_module *mod)
Expand Down

0 comments on commit 739a583

Please sign in to comment.