From 5b55118e7f716a072ddbcc859cbaee579e9fd525 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Mon, 10 Apr 2023 18:21:19 +0300 Subject: [PATCH] bluez5: media-sink: fix reference time vs. resampling delay Determine correctly if we are resampling, and have the associated delay. Add off-by-one sample adjustment to the resampling delay, which seems to correctly align the resampled audio with non-resampled. --- spa/plugins/bluez5/media-sink.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spa/plugins/bluez5/media-sink.c b/spa/plugins/bluez5/media-sink.c index c84538f9c..26f574510 100644 --- a/spa/plugins/bluez5/media-sink.c +++ b/spa/plugins/bluez5/media-sink.c @@ -465,6 +465,7 @@ static uint64_t get_reference_time(struct impl *this, uint64_t *duration_ns_ret) { struct port *port = &this->port; uint64_t t, duration_ns; + bool resampling; if (!this->process_rate || !this->process_duration) { if (this->position) { @@ -486,9 +487,12 @@ static uint64_t get_reference_time(struct impl *this, uint64_t *duration_ns_ret) / port->current_format.info.raw.rate); /* Account for resampling delay */ - if (port->rate_match && this->clock && SPA_FLAG_IS_SET(port->rate_match->flags, SPA_IO_RATE_MATCH_FLAG_ACTIVE)) + resampling = (port->current_format.info.raw.rate != this->process_rate) || this->following; + if (port->rate_match && this->clock && resampling) { t -= (uint64_t)port->rate_match->delay * SPA_NSEC_PER_SEC / this->clock->rate.denom; + t += SPA_NSEC_PER_SEC / port->current_format.info.raw.rate; + } return t; }