stream: fix ticks calculation if rate is 0/0

If the rate is 0/0, converting nsec to ticks doesn't work and will
result in 0 ticks, and it is not possible to convert ticks back to a
timestamp.

This can be reproduced by connecting a GStreamer pipewiresrc to a
libcamera node. The libcamera-utils has a rate of 0/0 and the
pipewireclock won't be able to determine a correct time with that.  This
error was caused by Commit 89993a3cc6 ("gst: enable the pipewire ticks
as a clock source").

Fix this by using the nsec as ticks and setting the appropriate rate.
This commit is contained in:
Michael Tretter 2025-01-24 12:11:03 +01:00
parent 5d35986329
commit 0468712fea

View file

@ -638,11 +638,18 @@ static inline void copy_position(struct stream *impl, int64_t queued)
impl->base_pos = p->clock.position - impl->time.ticks;
impl->clock_id = p->clock.id;
}
if (SPA_FLAG_IS_SET(p->clock.flags, SPA_IO_CLOCK_FLAG_NO_RATE))
impl->time.ticks = p->clock.nsec * p->clock.rate.denom /
(SPA_NSEC_PER_SEC * p->clock.rate.num);
else
if (SPA_FLAG_IS_SET(p->clock.flags, SPA_IO_CLOCK_FLAG_NO_RATE)) {
if (p->clock.rate.num == 0 || p->clock.rate.denom == 0) {
impl->time.ticks = p->clock.nsec;
impl->time.rate.num = 1;
impl->time.rate.denom = SPA_NSEC_PER_SEC;
} else {
impl->time.ticks = p->clock.nsec * (p->clock.rate.denom /
(SPA_NSEC_PER_SEC * p->clock.rate.num));
}
} else {
impl->time.ticks = p->clock.position - impl->base_pos;
}
impl->time.delay = 0;
impl->time.queued = queued;