mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-20 19:42:45 +00:00
Use monotonic system time for all timestamps
This commit is contained in:
parent
e82683b0f4
commit
63964ba6a7
@ -4,6 +4,7 @@ import java.util.Iterator;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import com.limelight.LimeLog;
|
import com.limelight.LimeLog;
|
||||||
|
import com.limelight.utils.TimeHelper;
|
||||||
|
|
||||||
public class RtpReorderQueue {
|
public class RtpReorderQueue {
|
||||||
private final int maxSize;
|
private final int maxSize;
|
||||||
@ -59,7 +60,7 @@ public class RtpReorderQueue {
|
|||||||
|
|
||||||
RtpQueueEntry entry = new RtpQueueEntry();
|
RtpQueueEntry entry = new RtpQueueEntry();
|
||||||
entry.packet = packet;
|
entry.packet = packet;
|
||||||
entry.queueTime = System.currentTimeMillis();
|
entry.queueTime = TimeHelper.getMonotonicMillis();
|
||||||
entry.sequenceNumber = seq;
|
entry.sequenceNumber = seq;
|
||||||
|
|
||||||
if (oldestQueuedTime == Long.MAX_VALUE) {
|
if (oldestQueuedTime == Long.MAX_VALUE) {
|
||||||
@ -118,8 +119,8 @@ public class RtpReorderQueue {
|
|||||||
boolean needsUpdate = false;
|
boolean needsUpdate = false;
|
||||||
|
|
||||||
// Check that the queue's time constraint is satisfied
|
// Check that the queue's time constraint is satisfied
|
||||||
if (System.currentTimeMillis() - oldestQueuedTime > maxQueueTime) {
|
if (TimeHelper.getMonotonicMillis() - oldestQueuedTime > maxQueueTime) {
|
||||||
LimeLog.info("Discarding RTP packet queued for too long");
|
LimeLog.info("Discarding RTP packet queued for too long: "+(TimeHelper.getMonotonicMillis() - oldestQueuedTime));
|
||||||
queue.remove(oldestQueuedEntry);
|
queue.remove(oldestQueuedEntry);
|
||||||
needsUpdate = true;
|
needsUpdate = true;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import com.limelight.nvstream.av.SequenceHelper;
|
|||||||
import com.limelight.nvstream.av.buffer.AbstractPopulatedBufferList;
|
import com.limelight.nvstream.av.buffer.AbstractPopulatedBufferList;
|
||||||
import com.limelight.nvstream.av.buffer.AtomicPopulatedBufferList;
|
import com.limelight.nvstream.av.buffer.AtomicPopulatedBufferList;
|
||||||
import com.limelight.nvstream.av.buffer.UnsynchronizedPopulatedBufferList;
|
import com.limelight.nvstream.av.buffer.UnsynchronizedPopulatedBufferList;
|
||||||
|
import com.limelight.utils.TimeHelper;
|
||||||
|
|
||||||
public class VideoDepacketizer {
|
public class VideoDepacketizer {
|
||||||
|
|
||||||
@ -301,7 +302,7 @@ public class VideoDepacketizer {
|
|||||||
{
|
{
|
||||||
if (firstPacket) {
|
if (firstPacket) {
|
||||||
// Setup state for the new frame
|
// Setup state for the new frame
|
||||||
frameStartTime = System.currentTimeMillis();
|
frameStartTime = TimeHelper.getMonotonicMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the payload data to the chain
|
// Add the payload data to the chain
|
||||||
@ -426,7 +427,7 @@ public class VideoDepacketizer {
|
|||||||
&& cachedSpecialDesc.data[cachedSpecialDesc.offset+cachedSpecialDesc.length] == 0x67)
|
&& cachedSpecialDesc.data[cachedSpecialDesc.offset+cachedSpecialDesc.length] == 0x67)
|
||||||
{
|
{
|
||||||
// The slow path doesn't update the frame start time by itself
|
// 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
|
// SPS and PPS prefix is padded between NALs, so we must decode it with the slow path
|
||||||
addInputDataSlow(packet, cachedReassemblyDesc);
|
addInputDataSlow(packet, cachedReassemblyDesc);
|
||||||
|
@ -13,6 +13,7 @@ import com.limelight.LimeLog;
|
|||||||
import com.limelight.nvstream.ConnectionContext;
|
import com.limelight.nvstream.ConnectionContext;
|
||||||
import com.limelight.nvstream.av.ConnectionStatusListener;
|
import com.limelight.nvstream.av.ConnectionStatusListener;
|
||||||
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
|
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
|
||||||
|
import com.limelight.utils.TimeHelper;
|
||||||
|
|
||||||
public class ControlStream implements ConnectionStatusListener {
|
public class ControlStream implements ConnectionStatusListener {
|
||||||
|
|
||||||
@ -538,17 +539,17 @@ public class ControlStream implements ConnectionStatusListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reset the loss count if it's been too long
|
// 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;
|
lossCount = 0;
|
||||||
lossTimestamp = System.currentTimeMillis();
|
lossTimestamp = TimeHelper.getMonotonicMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count this loss event
|
// Count this loss event
|
||||||
if (++lossCount == MAX_LOSS_COUNT_IN_PERIOD) {
|
if (++lossCount == MAX_LOSS_COUNT_IN_PERIOD) {
|
||||||
// Reset the loss event count if it's been too long
|
// 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;
|
lossEventCount = 0;
|
||||||
lossEventTimestamp = System.currentTimeMillis();
|
lossEventTimestamp = TimeHelper.getMonotonicMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++lossEventCount == LOSS_EVENTS_TO_WARN) {
|
if (++lossEventCount == LOSS_EVENTS_TO_WARN) {
|
||||||
|
7
moonlight-common/src/com/limelight/utils/TimeHelper.java
Normal file
7
moonlight-common/src/com/limelight/utils/TimeHelper.java
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package com.limelight.utils;
|
||||||
|
|
||||||
|
public class TimeHelper {
|
||||||
|
public static long getMonotonicMillis() {
|
||||||
|
return System.nanoTime() / 1000000L;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user