From 44793f3d4801e952a5efaf9b823705fbd0ace681 Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Tue, 12 Dec 2023 09:41:22 -0800 Subject: [PATCH] google_rtc_audio_processing: Guard buffer pointer following It seems like in IPC4 SOF will dynamically tear down streams not in use, such that the stream pointer field of a comp_buffer object will become null when and existing playback stream ends (which is oddly asymmetric, given that the topology/kernel itself will otherwise try to artificially START the reference stream for the benefit of AEC). In IPC3, the topology seems static and those pointers never change. Add an extra test for safety. It's cheap. Signed-off-by: Andy Ross --- src/audio/google/google_rtc_audio_processing.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/audio/google/google_rtc_audio_processing.c b/src/audio/google/google_rtc_audio_processing.c index c74b985b0c55..ff3792cb160b 100644 --- a/src/audio/google/google_rtc_audio_processing.c +++ b/src/audio/google/google_rtc_audio_processing.c @@ -756,6 +756,12 @@ static void mic_out_copy(struct sof_sink *sink, int frames, float **src_bufs) sink_commit_buffer(sink, bytes); } +static bool ref_stream_active(struct google_rtc_audio_processing_comp_data *cd) +{ + return cd->ref_comp_buffer->source && + cd->ref_comp_buffer->source->state == COMP_STATE_ACTIVE; +} + static int mod_process(struct processing_module *mod, struct sof_source **sources, int num_of_sources, struct sof_sink **sinks, int num_of_sinks) { @@ -767,8 +773,7 @@ static int mod_process(struct processing_module *mod, struct sof_source **source struct sof_source *mic = sources[cd->raw_microphone_source]; struct sof_source *ref = sources[cd->aec_reference_source]; struct sof_sink *out = sinks[0]; - - bool ref_ok = cd->ref_comp_buffer->source->state == COMP_STATE_ACTIVE; + bool ref_ok = ref_stream_active(cd); /* Would be cleaner to store a bit of state to elide a bzero * we already did, but we'd be doing the copy of real data in @@ -818,7 +823,7 @@ static bool mod_is_ready_to_process(struct processing_module *mod, struct sof_source *mic = sources[cd->raw_microphone_source]; struct sof_source *ref = sources[cd->aec_reference_source]; struct sof_sink *out = sinks[0]; - bool ref_ok = cd->ref_comp_buffer->source->state == COMP_STATE_ACTIVE; + bool ref_ok = ref_stream_active(cd); /* this should source_get_min_available(ref_stream)!!! * Currently the topology sets IBS incorrectly