module-echo-cancel: Drop buffers on overruns

Without this, if we do overrun, we'll never catch this.
This commit is contained in:
Arun Raghavan 2021-06-02 12:45:23 -04:00
parent bbae1adda0
commit 1349d5334d

View file

@ -247,10 +247,18 @@ static void capture_process(void *data)
avail = spa_ringbuffer_get_write_index(&impl->rec_ring, &index); avail = spa_ringbuffer_get_write_index(&impl->rec_ring, &index);
size = buf->buffer->datas[0].chunk->size; size = buf->buffer->datas[0].chunk->size;
if (avail + size >= impl->rec_ringsize) { if (avail + size > impl->rec_ringsize) {
pw_log_warn("capture ringbuffer xrun %d + %u > %u", uint32_t rindex, drop;
avail, size, impl->rec_ringsize);
/* FIXME: drop what we overwrite */ /* Drop enough so we have size bytes left */
drop = avail + size - impl->rec_ringsize;
pw_log_debug("capture ringbuffer xrun %d + %u > %u, dropping %u",
avail, size, impl->rec_ringsize, drop);
spa_ringbuffer_get_read_index(&impl->rec_ring, &rindex);
spa_ringbuffer_read_update(&impl->rec_ring, rindex + drop);
avail += drop;
} }
/* If we don't know what size to push yet, keep the block size the same /* If we don't know what size to push yet, keep the block size the same
@ -393,10 +401,18 @@ static void sink_process(void *data)
avail = spa_ringbuffer_get_write_index(&impl->play_ring, &index); avail = spa_ringbuffer_get_write_index(&impl->play_ring, &index);
size = buf->buffer->datas[0].chunk->size; size = buf->buffer->datas[0].chunk->size;
if (avail + size >= impl->play_ringsize) { if (avail + size > impl->play_ringsize) {
pw_log_warn("sink ringbuffer xrun %d + %u > %u", uint32_t rindex, drop;
avail, size, impl->play_ringsize);
/* FIXME: drop what we overwrite */ /* Drop enough so we have size bytes left */
drop = avail + size - impl->play_ringsize;
pw_log_debug("sink ringbuffer xrun %d + %u > %u, dropping %u",
avail, size, impl->play_ringsize, drop);
spa_ringbuffer_get_read_index(&impl->play_ring, &rindex);
spa_ringbuffer_read_update(&impl->play_ring, rindex + drop);
avail += drop;
} }
/* If we don't know what size to push yet, keep the block size the same /* If we don't know what size to push yet, keep the block size the same