From be1677f56913706973cbab656dbf0c9d877d0ae5 Mon Sep 17 00:00:00 2001 From: Janne Grunau Date: Sun, 14 Dec 2025 10:06:41 +0100 Subject: [PATCH] stream: Fix pw_time.delay calculation for rate.num > 1 Pipewire uses a rate of 256/7680 with the integrated camera of Apple silicon Macbooks. To calculate pw_time.delay correctly in this case it has to be divided by time->rate.num. Without this division the delay contribution of the `((latency->min_ns + latency->max_ns) / 2)` term ends up as 255 which are 8.5 seconds. pipewiresrc reports the delay as latency in the gstreamer pipeline which results in rendering a frame every 8.5 seconds. I suspect the non-normalized rate of 256/7680 is another bug in pipewire. The rate for an UVC webcam is reported as 1/30. Both Video4Linux2 devices report a discrete frame interval of 0.033s (30fps). Fixes #4957 (cherry picked from commit f03021edd162affbba940a39a266b246e5e77375) --- src/pipewire/stream.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pipewire/stream.c b/src/pipewire/stream.c index dd14c5601..735a55b3a 100644 --- a/src/pipewire/stream.c +++ b/src/pipewire/stream.c @@ -2400,8 +2400,9 @@ int pw_stream_get_time_n(struct pw_stream *stream, struct pw_time *time, size_t time->delay += (int64_t)(((impl->latency.min_quantum + impl->latency.max_quantum) / 2.0f) * quantum); time->delay += (impl->latency.min_rate + impl->latency.max_rate) / 2; - time->delay += ((impl->latency.min_ns + impl->latency.max_ns) / 2) * - (int64_t)time->rate.denom / (int64_t)SPA_NSEC_PER_SEC; + if (time->rate.num != 0) + time->delay += ((impl->latency.min_ns + impl->latency.max_ns) / 2) * + (int64_t)time->rate.denom / ((int64_t)SPA_NSEC_PER_SEC * time->rate.num); avail_buffers = spa_ringbuffer_get_read_index(&impl->dequeued.ring, &index); avail_buffers = SPA_CLAMP(avail_buffers, 0, (int32_t)impl->n_buffers);