diff --git a/spa/plugins/bluez5/media-sink.c b/spa/plugins/bluez5/media-sink.c index 20ba4717e..a5d72fcfc 100644 --- a/spa/plugins/bluez5/media-sink.c +++ b/spa/plugins/bluez5/media-sink.c @@ -633,6 +633,7 @@ static int flush_data(struct impl *this, uint64_t now_time) int written; uint32_t total_frames; struct port *port = &this->port; + int unused_buffer; if (!this->flush_source.loop) { /* I/O in error state */ @@ -718,15 +719,21 @@ again: return 0; } - // This should be the same as buffer size to increase bitpool - // Bitpool shouldn't be increased when data is left over in the buffer - int unused_buffer = get_transport_unused_size(this); + /* + * Get socket queue size before writing to it. + * This should be the same as buffer size to increase bitpool + * Bitpool shouldn't be increased when data is left over in the buffer + */ + unused_buffer = get_transport_unused_size(this); + written = flush_buffer(this); if (written == -EAGAIN) { spa_log_trace(this->log, "%p: fail flush", this); if (now_time - this->last_error > SPA_NSEC_PER_SEC / 2) { - spa_log_debug(this->log, "%p: reduce bitpool: %i", this, this->codec->reduce_bitpool(this->codec_data)); + int res = this->codec->reduce_bitpool(this->codec_data); + + spa_log_debug(this->log, "%p: reduce bitpool: %i", this, res); this->last_error = now_time; } @@ -794,7 +801,9 @@ again: if (now_time - this->last_error > SPA_NSEC_PER_SEC) { if (unused_buffer == (int)this->fd_buffer_size) { - spa_log_debug(this->log, "%p: increase bitpool: %i", this, this->codec->increase_bitpool(this->codec_data)); + int res = this->codec->increase_bitpool(this->codec_data); + + spa_log_debug(this->log, "%p: increase bitpool: %i", this, res); } this->last_error = now_time; }