From 6566f52a7ef09bda6a3ff684d608951851315544 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Sun, 6 Dec 2020 15:55:38 +0100 Subject: [PATCH] a2dp-sink: don't accept more data when we need to flush See #449 --- spa/plugins/bluez5/a2dp-sink.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/spa/plugins/bluez5/a2dp-sink.c b/spa/plugins/bluez5/a2dp-sink.c index 428e52283..179dc7530 100644 --- a/spa/plugins/bluez5/a2dp-sink.c +++ b/spa/plugins/bluez5/a2dp-sink.c @@ -353,6 +353,11 @@ static int send_buffer(struct impl *this) return written; } +static bool need_flush(struct impl *this) +{ + return (this->frame_count + 1 >= this->num_blocks); +} + static int encode_buffer(struct impl *this, const void *data, uint32_t size) { int processed; @@ -365,6 +370,9 @@ static int encode_buffer(struct impl *this, const void *data, uint32_t size) this, size, this->buffer_used, port->frame_size, this->block_size, this->frame_count); + if (need_flush(this)) + return 0; + if (this->buffer_used >= sizeof(this->buffer)) return -ENOSPC; @@ -401,11 +409,6 @@ static int encode_buffer(struct impl *this, const void *data, uint32_t size) return processed; } -static bool need_flush(struct impl *this) -{ - return (this->frame_count + 1 >= this->num_blocks); -} - static int flush_buffer(struct impl *this, bool force) { spa_log_trace(this->log, NAME" %p: used:%d num_blocks:%d block_size%d", this,