From d48792d9a94144449e3915077625625fc7694f89 Mon Sep 17 00:00:00 2001 From: Moses Turner Date: Sun, 18 Sep 2022 14:25:21 -0500 Subject: [PATCH] u/sink: Ensure that image frames have monotonic timestamps --- src/xrt/auxiliary/util/u_sink_force_genlock.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/xrt/auxiliary/util/u_sink_force_genlock.c b/src/xrt/auxiliary/util/u_sink_force_genlock.c index 149b0e2a2..73bdab614 100644 --- a/src/xrt/auxiliary/util/u_sink_force_genlock.c +++ b/src/xrt/auxiliary/util/u_sink_force_genlock.c @@ -47,6 +47,9 @@ struct u_sink_force_genlock pthread_mutex_t mutex; pthread_cond_t cond; + //! Timestamp of the last frameset we pushed. + int64_t last_ts; + //! Should we keep running? //! currently, true upon startup, false as we're exiting. bool running; @@ -137,10 +140,16 @@ force_genlock_mainloop(void *ptr) frames[0]->timestamp = ts; frames[1]->timestamp = ts; - // Send to the consumer, in left-right order. - xrt_sink_push_frame(q->consumer_left, frames[0]); - xrt_sink_push_frame(q->consumer_right, frames[1]); - + if (ts == q->last_ts) { + U_LOG_W("Got an image frame with a duplicate timestamp! Old: %lu; New: %lu", q->last_ts, ts); + } else if (ts < q->last_ts) { + U_LOG_W("Got an image frame with a non-monotonically-increasing timestamp! Old: %lu; New: %lu", + q->last_ts, ts); + } else { + // Send to the consumer, in left-right order. + xrt_sink_push_frame(q->consumer_left, frames[0]); + xrt_sink_push_frame(q->consumer_right, frames[1]); + } /* * Drop our reference - we don't need it anymore. If the consumer wants to keep it, they will have * referenced it in their push_frame handler.