diff --git a/spa/plugins/bluez5/a2dp-sink.c b/spa/plugins/bluez5/a2dp-sink.c index 4be19edde..291fdcfe7 100644 --- a/spa/plugins/bluez5/a2dp-sink.c +++ b/spa/plugins/bluez5/a2dp-sink.c @@ -364,13 +364,16 @@ static int send_buffer(struct impl *this) update_num_blocks(this); } - spa_log_trace(this->log, NAME " %p: send %d %u %u %u", - this, this->frame_count, this->seqnum, this->timestamp, this->buffer_used); + spa_log_trace(this->log, NAME " %p: send %d %u %u %u %u", + this, this->frame_count, this->block_size, this->seqnum, + this->timestamp, this->buffer_used); - written = send(this->flush_source.fd, this->buffer, this->buffer_used, MSG_DONTWAIT | MSG_NOSIGNAL); + written = send(this->flush_source.fd, this->buffer, + this->buffer_used, MSG_DONTWAIT | MSG_NOSIGNAL); reset_buffer(this); - spa_log_debug(this->log, NAME " %p: send %d", this, written); + spa_log_trace(this->log, NAME " %p: send %d", this, written); + if (written < 0) { spa_log_debug(this->log, NAME " %p: %m", this); return -errno; @@ -379,6 +382,11 @@ static int send_buffer(struct impl *this) return written; } +static bool want_flush(struct impl *this) +{ + return (this->frame_count * this->block_size / this->port.frame_size >= MIN_LATENCY); +} + static bool need_flush(struct impl *this) { return (this->frame_count >= this->num_blocks); @@ -435,12 +443,12 @@ static int encode_buffer(struct impl *this, const void *data, uint32_t size) return processed; } -static int flush_buffer(struct impl *this, bool force) +static int flush_buffer(struct impl *this) { spa_log_trace(this->log, NAME" %p: used:%d num_blocks:%d block_size:%d", this, this->buffer_used, this->num_blocks, this->block_size); - if (force || need_flush(this)) + if (want_flush(this) || need_flush(this)) return send_buffer(this); return 0; @@ -543,7 +551,7 @@ again: return 0; } - written = flush_buffer(this, true); + written = flush_buffer(this); if (written == -EAGAIN) { spa_log_trace(this->log, NAME" %p: delay flush", this); if (now_time - this->last_error > SPA_NSEC_PER_SEC / 2) {