From 2335657343bc2f07997482851bcd6249fd8da5bc Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Mon, 4 Dec 2023 21:32:05 +0200 Subject: [PATCH] bluez5: media-sink: keep one more buffer free We delay the audio a bit to keep packet intervals equal, which keeps some data in buffers. In theory the calculation keeps one buffer free, but it doesn't explicitly keep "extra" buffer space so in theory might flush too late and next process() might not have free buffers. However, as we encode next packet right away this shouldn't really occur... Try to keep one extra spare buffer free so that the flush time is certainly early enough. --- spa/plugins/bluez5/media-sink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spa/plugins/bluez5/media-sink.c b/spa/plugins/bluez5/media-sink.c index 1bbbc4875..5ea375964 100644 --- a/spa/plugins/bluez5/media-sink.c +++ b/spa/plugins/bluez5/media-sink.c @@ -53,7 +53,7 @@ struct props { }; #define FILL_FRAMES 4 -#define MIN_BUFFERS 2 +#define MIN_BUFFERS 3 #define MAX_BUFFERS 32 #define BUFFER_SIZE (8192*8) #define RATE_CTL_DIFF_MAX 0.005 @@ -888,7 +888,7 @@ again: */ #if 1 this->next_flush_time += SPA_MIN(packet_time, - duration_ns * (port->n_buffers - 1)); + duration_ns * (SPA_MAX(port->n_buffers, 2u) - 2)); #endif } else { if (this->next_flush_time == 0)