Use monotonic system time for all timestamps

This commit is contained in:
Cameron Gutman 2015-08-17 18:33:05 -07:00
parent e82683b0f4
commit 63964ba6a7
4 changed files with 19 additions and 9 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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) {

View File

@ -0,0 +1,7 @@
package com.limelight.utils;
public class TimeHelper {
public static long getMonotonicMillis() {
return System.nanoTime() / 1000000L;
}
}