From e042d9ebff1ce4e75605d76378f0696c9b121149 Mon Sep 17 00:00:00 2001 From: Dario Casalinuovo Date: Sat, 7 May 2016 13:17:54 +0200 Subject: [PATCH] MediaEventLooper: Calculate lateness from the nearest value * When the event is late there are two major situations, the first is when the enqueue time is in past compared to the performance time. The second happen when the performance time is in past compared to the enqueue time. The purpose of this change is to calculate the lateness considering always the nearest of the two values. This way the exceding latency is trimmed out from the calculus depending on what the actual source of delay is. * There is a lot more that could be done by looking at the previous lateness value. --- src/kits/media/MediaEventLooper.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/kits/media/MediaEventLooper.cpp b/src/kits/media/MediaEventLooper.cpp index dd6e43044b..2c6b46e22a 100644 --- a/src/kits/media/MediaEventLooper.cpp +++ b/src/kits/media/MediaEventLooper.cpp @@ -246,14 +246,11 @@ BMediaEventLooper::ControlLoop() // in the meantime, so that the client can // notify to the producer only the portion // that might be attributable. - bigtime_t lateness = 0; - if (waitUntil > 0) { - lateness = waitUntil - TimeSource()->RealTime(); - if (lateness > 0) { - bigtime_t enqueueLatency - = event.enqueue_time - waitUntil; - if (enqueueLatency > 0) - lateness += enqueueLatency; + bigtime_t lateness = waitUntil - TimeSource()->RealTime(); + if (lateness < 0) { + if (event.enqueue_time > waitUntil) { + lateness = event.enqueue_time + - TimeSource()->RealTime(); } } DispatchEvent(&event, -lateness, hasRealtime);