From c4812af436c4bb5401c451b4d53a73057e781785 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Mon, 22 Dec 2025 15:45:02 +0200 Subject: [PATCH] bluez5: decode-buffer: fix buffer level after recovery The buffer level number includes the current quantum, so it should not be subtracted. We do this after recovery from glitch, and this throws rate matching off. The level after recovery should also include the resampler delay. --- spa/plugins/bluez5/decode-buffer.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spa/plugins/bluez5/decode-buffer.h b/spa/plugins/bluez5/decode-buffer.h index ab9c0b6a1..327f819e3 100644 --- a/spa/plugins/bluez5/decode-buffer.h +++ b/spa/plugins/bluez5/decode-buffer.h @@ -197,8 +197,6 @@ static inline size_t spa_bt_decode_buffer_get_size(struct spa_bt_decode_buffer * static inline void spa_bt_decode_buffer_write_packet(struct spa_bt_decode_buffer *this, uint32_t size, uint64_t nsec) { - const int32_t duration = this->duration_ns * this->rate / SPA_NSEC_PER_SEC; - if (nsec) { this->rx.nsec = nsec; this->rx.position = size / this->frame_size; @@ -217,7 +215,8 @@ static inline void spa_bt_decode_buffer_write_packet(struct spa_bt_decode_buffer this->level = dt * this->rate_diff * this->rate / SPA_NSEC_PER_SEC + avail + this->delay + this->delay_frac/1e9 - this->rx.position; } else { - this->level = spa_bt_decode_buffer_get_size(this) / this->frame_size - duration; + this->level = spa_bt_decode_buffer_get_size(this) / this->frame_size + + this->delay + this->delay_frac/1e9; } } @@ -259,8 +258,11 @@ static inline void spa_bt_decode_buffer_recover(struct spa_bt_decode_buffer *thi this->rx.nsec = 0; this->corr = 1.0; + spa_bt_rate_control_init(&this->ctl, target * SPA_NSEC_PER_SEC / this->rate); spa_bt_decode_buffer_write_packet(this, 0, 0); + + spa_log_debug(this->log, "%p recover level:%f", this, this->level); } static inline void spa_bt_decode_buffer_process(struct spa_bt_decode_buffer *this, uint32_t samples, int64_t duration_ns,