Merge branch 'sklug/upstream/fix-stream-synchronization-v1' into 'master'

RFC: Improve/fix timestamping issues with gstpipewiresrc

See merge request pipewire/pipewire!2786
This commit is contained in:
Stefan Klug 2026-05-22 17:45:57 +00:00
commit 7f17b50ae6
5 changed files with 71 additions and 85 deletions

View file

@ -1060,20 +1060,12 @@ void handle_completed_request(struct impl *impl, libcamera::Request *request)
const FrameMetadata &fmd = buffer->metadata();
if (impl->clock) {
double target = (double)port->info.rate.num / port->info.rate.denom;
double corr;
if (impl->dll.bw == 0.0) {
spa_dll_set_bw(&impl->dll, SPA_DLL_BW_MAX, port->info.rate.denom, port->info.rate.denom);
impl->clock->next_nsec = fmd.timestamp;
corr = 1.0;
} else {
double diff = ((double)impl->clock->next_nsec - (double)fmd.timestamp) / SPA_NSEC_PER_SEC;
double error = port->info.rate.denom * (diff - target);
corr = spa_dll_update(&impl->dll, SPA_CLAMPD(error, -128., 128.));
}
/* FIXME, we should follow the driver clock and target_ values.
* for now we ignore and use our own. */
/*
* The clock has SPA_IO_CLOCK_FLAG_NO_RATE set, so there is no
* need to update any rate specific fields.
* As libcamera uses CLOCK_MONOTONIC internally, there is no
* need to adjust the timestamps.
*/
impl->clock->target_rate = port->rate;
impl->clock->target_duration = 1;
@ -1082,8 +1074,8 @@ void handle_completed_request(struct impl *impl, libcamera::Request *request)
impl->clock->position = fmd.sequence;
impl->clock->duration = 1;
impl->clock->delay = 0;
impl->clock->rate_diff = corr;
impl->clock->next_nsec += (uint64_t) (target * SPA_NSEC_PER_SEC * corr);
impl->clock->rate_diff = 1.0;
impl->clock->next_nsec = fmd.timestamp+1;
}
if (b->h) {