From 175a97ec6b78532d5cf3faf483623d918a0ce76c Mon Sep 17 00:00:00 2001 From: Eddy Hsu Date: Thu, 22 Aug 2024 21:13:46 +0000 Subject: [PATCH] comp: ctc: add ctc binary control. Add binary controls of Google CTC component to load different configs. Signed-off-by: Eddy Hsu --- .../google/google_ctc_audio_processing.c | 50 +++++++++---------- .../google/google_ctc_audio_processing.h | 14 ++++++ .../google/google_ctc_audio_processing_ipc3.c | 16 +++++- .../google/google_ctc_audio_processing_ipc4.c | 16 +++++- .../google/google_ctc_audio_processing_mock.c | 11 ---- ..._ctc_audio_processing_sof_message_reader.h | 32 ------------ 6 files changed, 67 insertions(+), 72 deletions(-) delete mode 100644 third_party/include/google_ctc_audio_processing_sof_message_reader.h diff --git a/src/audio/google/google_ctc_audio_processing.c b/src/audio/google/google_ctc_audio_processing.c index 47205cdb3..a749b420c 100644 --- a/src/audio/google/google_ctc_audio_processing.c +++ b/src/audio/google/google_ctc_audio_processing.c @@ -15,7 +15,6 @@ #include #include -#include #include "google_ctc_audio_processing.h" @@ -298,31 +297,15 @@ static int google_ctc_audio_processing_reconfigure(struct processing_module *mod config, size); cd->reconfigure = false; - - uint8_t *processing_config; - size_t processing_config_size; - bool processing_config_present; - - GoogleCtcAudioProcessingParseSofConfigMessage(config, size, - &processing_config, - &processing_config_size, - &processing_config_present); - - if (processing_config_present) { - comp_info(dev, - "google_ctc_audio_processing_reconfigure(): Applying config of size %zu bytes", - processing_config_size); - - ret = GoogleCtcAudioProcessingReconfigure(cd->state, - processing_config, - processing_config_size); - if (ret) { - comp_err(dev, "GoogleCtcAudioProcessingReconfigure failed: %d", - ret); - return ret; - } + comp_info(dev, + "google_ctc_audio_processing_reconfigure(): Applying config of size %zu bytes", + size); + ret = GoogleCtcAudioProcessingReconfigure(cd->state, config, size); + if (ret) { + comp_err(dev, "GoogleCtcAudioProcessingReconfigure failed: %d", + ret); + return ret; } - return 0; } @@ -335,6 +318,8 @@ static int ctc_prepare(struct processing_module *mod, struct comp_buffer *source; enum sof_ipc_frame fmt; int num_channels; + uint8_t *config; + int config_size; comp_info(mod->dev, "ctc_prepare()"); @@ -367,10 +352,21 @@ static int ctc_prepare(struct processing_module *mod, } cd->next_avail_output_samples = cd->chunk_frames * num_channels; + config = comp_get_data_blob(cd->tuning_handler, &config_size, NULL); + + if (config_size != CTC_BLOB_CONFIG_SIZE) { + comp_info(mod->dev, "ctc_prepare(): config_size not expected: %d", config_size); + config = NULL; + config_size = 0; + } cd->state = GoogleCtcAudioProcessingCreateWithConfig(cd->chunk_frames, audio_stream_get_rate(&source->stream), - /*config=*/NULL, - /*config_size=*/0); + config, + config_size); + if (!cd->state) { + comp_err(mod->dev, "ctc_prepare(), failed to create CTC"); + return -ENOMEM; + } return 0; } diff --git a/src/audio/google/google_ctc_audio_processing.h b/src/audio/google/google_ctc_audio_processing.h index 8fb00d9a5..df537c3dc 100644 --- a/src/audio/google/google_ctc_audio_processing.h +++ b/src/audio/google/google_ctc_audio_processing.h @@ -37,10 +37,24 @@ struct google_ctc_audio_processing_comp_data { uint32_t chunk_frames; GoogleCtcAudioProcessingState *state; struct comp_data_blob_handler *tuning_handler; + bool enabled; bool reconfigure; ctc_func ctc_func; }; +struct google_ctc_config { + /* size of the whole ctc config */ + uint32_t size; + + /* reserved */ + uint32_t reserved[4]; + + uint32_t data[]; +} __packed; + +#define CTC_BLOB_DATA_SIZE 4100 +#define CTC_BLOB_CONFIG_SIZE (sizeof(struct google_ctc_config) + CTC_BLOB_DATA_SIZE) + int ctc_set_config(struct processing_module *mod, uint32_t param_id, enum module_cfg_fragment_position pos, uint32_t data_offset_size, diff --git a/src/audio/google/google_ctc_audio_processing_ipc3.c b/src/audio/google/google_ctc_audio_processing_ipc3.c index 04e2bc563..5bce62064 100644 --- a/src/audio/google/google_ctc_audio_processing_ipc3.c +++ b/src/audio/google/google_ctc_audio_processing_ipc3.c @@ -28,6 +28,8 @@ int ctc_set_config(struct processing_module *mod, uint32_t param_id, struct sof_ipc_ctrl_data *cdata = (struct sof_ipc_ctrl_data *)fragment; struct google_ctc_audio_processing_comp_data *cd = module_get_private_data(mod); int ret; + struct google_ctc_config *config; + int size; switch (cdata->cmd) { case SOF_CTRL_CMD_BINARY: @@ -35,7 +37,19 @@ int ctc_set_config(struct processing_module *mod, uint32_t param_id, if (ret) return ret; if (comp_is_new_data_blob_available(cd->tuning_handler)) { - comp_get_data_blob(cd->tuning_handler, NULL, NULL); + config = comp_get_data_blob(cd->tuning_handler, &size, NULL); + if (size != CTC_BLOB_CONFIG_SIZE) { + comp_err(mod->dev, + "ctc_set_config(): Invalid config size = %d", + size); + return -EINVAL; + } + if (config->size != CTC_BLOB_CONFIG_SIZE) { + comp_err(mod->dev, + "ctc_set_config(): Invalid config->size = %d", + config->size); + return -EINVAL; + } cd->reconfigure = true; } return 0; diff --git a/src/audio/google/google_ctc_audio_processing_ipc4.c b/src/audio/google/google_ctc_audio_processing_ipc4.c index f02f749d3..e4ac1d747 100644 --- a/src/audio/google/google_ctc_audio_processing_ipc4.c +++ b/src/audio/google/google_ctc_audio_processing_ipc4.c @@ -27,6 +27,8 @@ int ctc_set_config(struct processing_module *mod, uint32_t param_id, { struct google_ctc_audio_processing_comp_data *cd = module_get_private_data(mod); int ret; + struct google_ctc_config *config; + int size; switch (param_id) { case 0: @@ -44,7 +46,19 @@ int ctc_set_config(struct processing_module *mod, uint32_t param_id, return ret; if (comp_is_new_data_blob_available(cd->tuning_handler)) { - comp_get_data_blob(cd->tuning_handler, NULL, NULL); + config = comp_get_data_blob(cd->tuning_handler, &size, NULL); + if (size != CTC_BLOB_CONFIG_SIZE) { + comp_err(mod->dev, + "ctc_set_config(): Invalid config size = %d", + size); + return -EINVAL; + } + if (config->size != CTC_BLOB_CONFIG_SIZE) { + comp_err(mod->dev, + "ctc_set_config(): Invalid config->size = %d", + config->size); + return -EINVAL; + } cd->reconfigure = true; } diff --git a/src/audio/google/google_ctc_audio_processing_mock.c b/src/audio/google/google_ctc_audio_processing_mock.c index fe5c8fa79..3828ce5b2 100644 --- a/src/audio/google/google_ctc_audio_processing_mock.c +++ b/src/audio/google/google_ctc_audio_processing_mock.c @@ -52,17 +52,6 @@ void GoogleCtcAudioProcessingProcess(GoogleCtcAudioProcessingState *state, src, sizeof(float) * num_frames * num_channels); } -void GoogleCtcAudioProcessingParseSofConfigMessage(uint8_t *message, - size_t message_size, - uint8_t **config, - size_t *config_size, - bool *config_present) -{ - *config = NULL; - *config_size = 0; - *config_present = false; -} - int GoogleCtcAudioProcessingReconfigure(GoogleCtcAudioProcessingState *state, const uint8_t *config, int config_size) { diff --git a/third_party/include/google_ctc_audio_processing_sof_message_reader.h b/third_party/include/google_ctc_audio_processing_sof_message_reader.h deleted file mode 100644 index 0066c5ff5..000000000 --- a/third_party/include/google_ctc_audio_processing_sof_message_reader.h +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright(c) 2024 Google LLC. - * - * Author: Eddy Hsu - */ -#ifndef GOOGLE_CTC_AUDIO_PROCESSING_SOF_MESSAGE_READER_H_ -#define GOOGLE_CTC_AUDIO_PROCESSING_SOF_MESSAGE_READER_H_ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// Parses the fields from a SOF config message `message` of size `message_size` -// intended for the GoogleCtcAudioProcessing component and the corresponding -// outputs parameters based on the content. Any previous content in the output -// parameters is overwritten regardless of the content in `message`. -void GoogleCtcAudioProcessingParseSofConfigMessage(uint8_t *message, - size_t message_size, - uint8_t **config, - size_t *config_size, - bool *config_present); - -#ifdef __cplusplus -} -#endif - -#endif // GOOGLE_CTC_AUDIO_PROCESSING_SOF_MESSAGE_READER_H_