node-driver: fix position calculation

Set the driver node position based on the current time when we
start and keep incrementing it with the previous duration.
This commit is contained in:
Wim Taymans 2023-03-24 17:34:14 +01:00
parent 5ea3c10dca
commit 78b8e1af57

View file

@ -263,15 +263,14 @@ static void on_timeout(struct spa_source *source)
current_position = scale_u64(current_time, rate, SPA_NSEC_PER_SEC);
if (SPA_LIKELY(this->clock))
position = this->clock->position;
else
position = current_position;
if (this->last_time == 0) {
spa_dll_set_bw(&this->dll, SPA_DLL_BW_MIN, duration, rate);
this->max_error = rate * MAX_ERROR_MS / 1000;
position = current_position;
} else if (SPA_LIKELY(this->clock)) {
position = this->clock->position + this->clock->duration;
} else {
position = current_position;
}
/* check the elapsed time of the other clock against
@ -304,7 +303,7 @@ static void on_timeout(struct spa_source *source)
if (SPA_LIKELY(this->clock)) {
this->clock->nsec = nsec;
this->clock->rate = this->clock->target_rate;
this->clock->position += this->clock->duration;
this->clock->position = position;
this->clock->duration = duration;
this->clock->delay = 0;
this->clock->rate_diff = corr;