From 32596c0958d79091783d0b166b6aca8fae1f21a3 Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Sun, 10 Dec 2023 20:42:14 -0800 Subject: [PATCH] google_rtc_audio_processing: Cache frame size from source/sink Don't query the frame size every time it's used, cache it in the component struct to save a few cycles. This also permits a workaround: on MTL the mic stream lies about its format, claiming s26_le when it's really s32_le. We can leave the existing format error in place and just use our own configuration for now. Signed-off-by: Andy Ross --- .../google/google_rtc_audio_processing.c | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/audio/google/google_rtc_audio_processing.c b/src/audio/google/google_rtc_audio_processing.c index d40dc352ac1f..0610417e0b31 100644 --- a/src/audio/google/google_rtc_audio_processing.c +++ b/src/audio/google/google_rtc_audio_processing.c @@ -91,6 +91,8 @@ struct google_rtc_audio_processing_comp_data { int aec_reference_source; int raw_microphone_source; struct comp_buffer *ref_comp_buffer; + int ref_frame_bytes; + int out_frame_bytes; }; #if CONFIG_GOOGLE_RTC_AUDIO_PROCESSING_MIC_BITS == 16 @@ -605,7 +607,9 @@ static int google_rtc_audio_processing_prepare(struct processing_module *mod, if (mic_fmt != bits_fmt(CONFIG_GOOGLE_RTC_AUDIO_PROCESSING_MIC_BITS)) { comp_err(dev, "Mic stream must be %d bit samples\n", CONFIG_GOOGLE_RTC_AUDIO_PROCESSING_MIC_BITS); - ret = -EINVAL; + + // FIXME: squash for now, the streams lie. See below. + //ret = -EINVAL; } if (mic_fmt != out_fmt) { @@ -613,6 +617,15 @@ static int google_rtc_audio_processing_prepare(struct processing_module *mod, ret = -EINVAL; } + // FIXME: the streams have a bad format on MTL, so we can't + // use this API. Compute by hand. + // + //cd->ref_frame_bytes = source_get_frame_bytes(sources[cd->aec_reference_source]); + //cd->out_frame_bytes = sink_get_frame_bytes(sinks[0]); + cd->ref_frame_bytes = sizeof(mic_sample_t) * + source_get_channels(sources[cd->aec_reference_source]); + cd->out_frame_bytes = cd->ref_frame_bytes; + /* Blobs sent during COMP_STATE_READY is assigned to blob_handler->data * directly, so comp_is_new_data_blob_available always returns false. */ @@ -775,7 +788,7 @@ static int mod_process(struct processing_module *mod, struct sof_source **source * samples so AEC compares the most recent values. */ if (ref_ok && fref > fmic) - source_release_data(ref, (fref - fmic) * source_get_frame_bytes(ref)); + source_release_data(ref, (fref - fmic) * cd->ref_frame_bytes); for (frames_rem = frames; frames_rem; frames_rem -= n) { n = MIN(frames_rem, cd->num_frames - cd->buffered_frames); @@ -812,7 +825,7 @@ static bool mod_is_ready_to_process(struct processing_module *mod, * Currently the topology sets IBS incorrectly */ if (ref_ok && (source_get_data_available(ref) - < cd->num_frames * source_get_frame_bytes(ref))) + < cd->num_frames * cd->ref_frame_bytes)) return false; if (source_get_data_available(mic) < source_get_min_available(mic)) @@ -821,7 +834,7 @@ static bool mod_is_ready_to_process(struct processing_module *mod, /* Output comes out all at once, the output sink much have * space for the full block */ - if (sink_get_free_size(out) < cd->num_frames * sink_get_frame_bytes(out)) + if (sink_get_free_size(out) < cd->num_frames * cd->out_frame_bytes) return false; return true;