From 739a583d3921de96a84c126d0e7dc1a90579e84c Mon Sep 17 00:00:00 2001 From: "barry.jan" Date: Mon, 6 Nov 2023 18:59:40 +0800 Subject: [PATCH] waves: store config blob in a cache in waves.c Store/apply config blob in a cache to avoid that cfg.data will be released after prepare. Signed-off-by: barry.jan --- src/audio/module_adapter/module/waves/waves.c | 105 ++++++++++++++++-- 1 file changed, 96 insertions(+), 9 deletions(-) diff --git a/src/audio/module_adapter/module/waves/waves.c b/src/audio/module_adapter/module/waves/waves.c index ab178b022eb9..02609f424c57 100644 --- a/src/audio/module_adapter/module/waves/waves.c +++ b/src/audio/module_adapter/module/waves/waves.c @@ -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 { @@ -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) { @@ -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) { @@ -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); @@ -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, @@ -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) @@ -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)