diff --git a/moonlight-common/src/com/limelight/nvstream/av/RtpReorderQueue.java b/moonlight-common/src/com/limelight/nvstream/av/RtpReorderQueue.java index 3815aa2a..6e45fe89 100644 --- a/moonlight-common/src/com/limelight/nvstream/av/RtpReorderQueue.java +++ b/moonlight-common/src/com/limelight/nvstream/av/RtpReorderQueue.java @@ -4,6 +4,7 @@ import java.util.Iterator; import java.util.LinkedList; import com.limelight.LimeLog; +import com.limelight.utils.TimeHelper; public class RtpReorderQueue { private final int maxSize; @@ -59,7 +60,7 @@ public class RtpReorderQueue { RtpQueueEntry entry = new RtpQueueEntry(); entry.packet = packet; - entry.queueTime = System.currentTimeMillis(); + entry.queueTime = TimeHelper.getMonotonicMillis(); entry.sequenceNumber = seq; if (oldestQueuedTime == Long.MAX_VALUE) { @@ -118,8 +119,8 @@ public class RtpReorderQueue { boolean needsUpdate = false; // Check that the queue's time constraint is satisfied - if (System.currentTimeMillis() - oldestQueuedTime > maxQueueTime) { - LimeLog.info("Discarding RTP packet queued for too long"); + if (TimeHelper.getMonotonicMillis() - oldestQueuedTime > maxQueueTime) { + LimeLog.info("Discarding RTP packet queued for too long: "+(TimeHelper.getMonotonicMillis() - oldestQueuedTime)); queue.remove(oldestQueuedEntry); needsUpdate = true; } diff --git a/moonlight-common/src/com/limelight/nvstream/av/video/VideoDepacketizer.java b/moonlight-common/src/com/limelight/nvstream/av/video/VideoDepacketizer.java index d8cc3f17..121755ee 100644 --- a/moonlight-common/src/com/limelight/nvstream/av/video/VideoDepacketizer.java +++ b/moonlight-common/src/com/limelight/nvstream/av/video/VideoDepacketizer.java @@ -9,6 +9,7 @@ import com.limelight.nvstream.av.SequenceHelper; import com.limelight.nvstream.av.buffer.AbstractPopulatedBufferList; import com.limelight.nvstream.av.buffer.AtomicPopulatedBufferList; import com.limelight.nvstream.av.buffer.UnsynchronizedPopulatedBufferList; +import com.limelight.utils.TimeHelper; public class VideoDepacketizer { @@ -301,7 +302,7 @@ public class VideoDepacketizer { { if (firstPacket) { // Setup state for the new frame - frameStartTime = System.currentTimeMillis(); + frameStartTime = TimeHelper.getMonotonicMillis(); } // Add the payload data to the chain @@ -426,7 +427,7 @@ public class VideoDepacketizer { && cachedSpecialDesc.data[cachedSpecialDesc.offset+cachedSpecialDesc.length] == 0x67) { // The slow path doesn't update the frame start time by itself - frameStartTime = System.currentTimeMillis(); + frameStartTime = TimeHelper.getMonotonicMillis(); // SPS and PPS prefix is padded between NALs, so we must decode it with the slow path addInputDataSlow(packet, cachedReassemblyDesc); diff --git a/moonlight-common/src/com/limelight/nvstream/control/ControlStream.java b/moonlight-common/src/com/limelight/nvstream/control/ControlStream.java index 568e6809..ad224974 100644 --- a/moonlight-common/src/com/limelight/nvstream/control/ControlStream.java +++ b/moonlight-common/src/com/limelight/nvstream/control/ControlStream.java @@ -13,6 +13,7 @@ import com.limelight.LimeLog; import com.limelight.nvstream.ConnectionContext; import com.limelight.nvstream.av.ConnectionStatusListener; import com.limelight.nvstream.av.video.VideoDecoderRenderer; +import com.limelight.utils.TimeHelper; public class ControlStream implements ConnectionStatusListener { @@ -538,17 +539,17 @@ public class ControlStream implements ConnectionStatusListener { } // Reset the loss count if it's been too long - if (System.currentTimeMillis() > LOSS_PERIOD_MS + lossTimestamp) { + if (TimeHelper.getMonotonicMillis() > LOSS_PERIOD_MS + lossTimestamp) { lossCount = 0; - lossTimestamp = System.currentTimeMillis(); + lossTimestamp = TimeHelper.getMonotonicMillis(); } // Count this loss event if (++lossCount == MAX_LOSS_COUNT_IN_PERIOD) { // Reset the loss event count if it's been too long - if (System.currentTimeMillis() > LOSS_EVENT_TIME_THRESHOLD_MS + lossEventTimestamp) { + if (TimeHelper.getMonotonicMillis() > LOSS_EVENT_TIME_THRESHOLD_MS + lossEventTimestamp) { lossEventCount = 0; - lossEventTimestamp = System.currentTimeMillis(); + lossEventTimestamp = TimeHelper.getMonotonicMillis(); } if (++lossEventCount == LOSS_EVENTS_TO_WARN) { diff --git a/moonlight-common/src/com/limelight/utils/TimeHelper.java b/moonlight-common/src/com/limelight/utils/TimeHelper.java new file mode 100644 index 00000000..7b33c603 --- /dev/null +++ b/moonlight-common/src/com/limelight/utils/TimeHelper.java @@ -0,0 +1,7 @@ +package com.limelight.utils; + +public class TimeHelper { + public static long getMonotonicMillis() { + return System.nanoTime() / 1000000L; + } +}