From c819f2f0e3c1ef2025a7ecfafa50b890f378ccf2 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 19 Nov 2014 10:40:39 -0800 Subject: [PATCH] Request a new IDR frame immediately if we've been waiting for one for 120 frames --- .../nvstream/av/video/VideoDepacketizer.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 749513d9..c75014a9 100644 --- a/moonlight-common/src/com/limelight/nvstream/av/video/VideoDepacketizer.java +++ b/moonlight-common/src/com/limelight/nvstream/av/video/VideoDepacketizer.java @@ -33,6 +33,9 @@ public class VideoDepacketizer { private ConnectionStatusListener controlListener; private final int nominalPacketDataLength; + private static final int CONSECUTIVE_DROP_LIMIT = 120; + private int consecutiveFrameDrops = 0; + private static final int DU_LIMIT = 15; private PopulatedBufferList decodedUnits; @@ -61,6 +64,22 @@ public class VideoDepacketizer { private void dropAvcFrameState() { waitingForIdrFrame = true; + + // Count the number of consecutive frames dropped + consecutiveFrameDrops++; + + // If we reach our limit, immediately request an IDR frame + // and reset + if (consecutiveFrameDrops == CONSECUTIVE_DROP_LIMIT) { + LimeLog.warning("Reached consecutive drop limit"); + + // Restart the count + consecutiveFrameDrops = 0; + + // Request an IDR frame + controlListener.connectionDetectedFrameLoss(0, 0); + } + cleanupAvcFrameState(); } @@ -126,6 +145,9 @@ public class VideoDepacketizer { // Clear old state cleanupAvcFrameState(); + + // Clear frame drops + consecutiveFrameDrops = 0; } }