From 951cdf309a389f59f37b4a55cc03d9b2c24d31d7 Mon Sep 17 00:00:00 2001 From: Jonas Holmberg Date: Thu, 3 Jul 2025 16:51:21 +0200 Subject: [PATCH] echo-cancel: drop if playback is not streaming capture and sink streams may start before playback stream so process() may fail to dequeue a playback buffer. In that case advance the read pointers to avoid building up latency in the ringbuffers. --- src/modules/module-echo-cancel.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/modules/module-echo-cancel.c b/src/modules/module-echo-cancel.c index 2ff10ed95..174c8173c 100644 --- a/src/modules/module-echo-cancel.c +++ b/src/modules/module-echo-cancel.c @@ -309,11 +309,6 @@ static void process(struct impl *impl) uint32_t i, size; uint32_t rindex, pindex, oindex, pdindex, avail; - if (impl->playback != NULL && (pout = pw_stream_dequeue_buffer(impl->playback)) == NULL) { - pw_log_debug("out of playback buffers: %m"); - goto done; - } - size = impl->aec_blocksize; /* First read a block from the playback and capture ring buffers */ @@ -338,6 +333,16 @@ static void process(struct impl *impl) spa_ringbuffer_get_read_index(&impl->play_ring, &pindex); spa_ringbuffer_get_read_index(&impl->play_delayed_ring, &pdindex); + if (impl->playback != NULL && (pout = pw_stream_dequeue_buffer(impl->playback)) == NULL) { + pw_log_debug("out of playback buffers: %m"); + + /* playback stream may not yet be in streaming state, drop play + * data to avoid introducing additional playback latency */ + spa_ringbuffer_read_update(&impl->play_ring, pindex + size); + spa_ringbuffer_read_update(&impl->play_delayed_ring, pdindex + size); + goto done; + } + for (i = 0; i < impl->play_info.channels; i++) { /* echo from sink */ play[i] = &play_buf[i][0];