bluez5: media-source: account for driver clock rate difference in rate match

The rate matching calculations are done in the system clock domain.  If
the driver ticks at a different rate, the correction factor needs to be
adjusted by the rate_diff.

setup_matching() also needs to be before spa_bt_decode_buffer_process():
as follower we should use rate matching value calculated on the
*previous* cycle, because this is what driver is doing when it adjusts
it tick rate.
This commit is contained in:
Pauli Virtanen 2025-07-11 15:11:38 +03:00 committed by Wim Taymans
parent f48a72a504
commit e446e3aac5

View file

@ -713,6 +713,10 @@ static int setup_matching(struct impl *this)
this->matching = this->following;
this->resampling = this->matching ||
(port->current_format.info.raw.rate != this->position->clock.target_rate.denom);
/* Rate match in system clock domain also when follower */
if (this->matching && this->position->clock.rate_diff > 0)
port->rate_match->rate *= this->position->clock.rate_diff;
} else {
this->matching = false;
this->resampling = false;
@ -1720,12 +1724,12 @@ static void process_buffering(struct impl *this)
break;
}
setup_matching(this);
spa_bt_decode_buffer_process(&port->buffer, samples, duration,
this->position ? this->position->clock.rate_diff : 1.0,
this->position ? this->position->clock.next_nsec : 0);
setup_matching(this);
/* copy data to buffers */
if (!spa_list_is_empty(&port->free)) {
struct buffer *buffer;