Skip to content

Commit

Permalink
comp: ctc: properly set up and clean component state.
Browse files Browse the repository at this point in the history
Check CTC state is properly inited and cleanup.

Signed-off-by: Eddy Hsu <eddyhsu@google.com>
  • Loading branch information
Eddy Hsu committed Aug 22, 2024
1 parent 4a7722a commit d966cbd
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/audio/google/google_ctc_audio_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ static int ctc_free(struct processing_module *mod)
{
struct google_ctc_audio_processing_comp_data *cd = module_get_private_data(mod);

comp_info(mod->dev, "ctc_free()");

if (cd) {
rfree(cd->input);
rfree(cd->output);
Expand Down Expand Up @@ -386,6 +388,10 @@ static int ctc_prepare(struct processing_module *mod,
audio_stream_get_rate(&source->stream),
/*config=*/NULL,
/*config_size=*/0);
if (!cd->state) {
comp_err(mod->dev, "ctc_prepare(), failed to create CTC");
return -ENOMEM;
}

cd->config = comp_get_data_blob(cd->tuning_handler, NULL, NULL);
return 0;
Expand All @@ -394,11 +400,17 @@ static int ctc_prepare(struct processing_module *mod,
static int ctc_reset(struct processing_module *mod)
{
struct google_ctc_audio_processing_comp_data *cd = module_get_private_data(mod);
size_t buf_size = cd->chunk_frames * sizeof(cd->input[0]) * kMaxChannels;

comp_info(mod->dev, "ctc_reset()");

GoogleCtcAudioProcessingFree(cd->state);
cd->state = NULL;
cd->ctc_func = NULL;
cd->input_samples = 0;
cd->next_avail_output_samples = 0;
memset(cd->input, 0, buf_size);
memset(cd->output, 0, buf_size);
return 0;
}

Expand Down

0 comments on commit d966cbd

Please sign in to comment.