Fix handling packet loss in the second of a split frame

This commit is contained in:
Cameron Gutman 2014-03-13 01:31:47 -04:00
parent 4cbaee6806
commit 7e30d043eb

View File

@ -21,6 +21,7 @@ public class VideoDepacketizer {
private int nextPacketNumber; private int nextPacketNumber;
private int startFrameNumber = 1; private int startFrameNumber = 1;
private boolean waitingForNextSuccessfulFrame; private boolean waitingForNextSuccessfulFrame;
private boolean gotNextFrameStart;
// Cached objects // Cached objects
private ByteBufferDescriptor cachedDesc = new ByteBufferDescriptor(null, 0, 0); private ByteBufferDescriptor cachedDesc = new ByteBufferDescriptor(null, 0, 0);
@ -179,12 +180,9 @@ public class VideoDepacketizer {
avcFrameDataLength = 0; avcFrameDataLength = 0;
} }
// FIXME: This check shouldn't be needed // Add the payload data to the chain
if (avcFrameDataChain != null) { avcFrameDataChain.add(location);
// Add the payload data to the chain avcFrameDataLength += location.length;
avcFrameDataChain.add(location);
avcFrameDataLength += location.length;
}
} }
public void addInputData(VideoPacket packet) public void addInputData(VideoPacket packet)
@ -232,6 +230,7 @@ public class VideoDepacketizer {
// Tell the encoder when we're done decoding this frame // Tell the encoder when we're done decoding this frame
// that we lost some previous frames // that we lost some previous frames
waitingForNextSuccessfulFrame = true; waitingForNextSuccessfulFrame = true;
gotNextFrameStart = false;
} }
else { else {
LimeLog.warning("Got packet "+packetIndex+" of frame "+frameIndex+ LimeLog.warning("Got packet "+packetIndex+" of frame "+frameIndex+
@ -239,6 +238,7 @@ public class VideoDepacketizer {
" of frame "+nextFrameNumber); " of frame "+nextFrameNumber);
// We dropped the start of this frame too // We dropped the start of this frame too
waitingForNextSuccessfulFrame = true; waitingForNextSuccessfulFrame = true;
gotNextFrameStart = false;
// Try to pickup on the next frame // Try to pickup on the next frame
nextFrameNumber = frameIndex + 1; nextFrameNumber = frameIndex + 1;
@ -258,6 +258,7 @@ public class VideoDepacketizer {
LimeLog.warning("Frame "+frameIndex+": expected packet "+nextPacketNumber+" but got "+packetIndex); LimeLog.warning("Frame "+frameIndex+": expected packet "+nextPacketNumber+" but got "+packetIndex);
// At this point, we're guaranteed that it's not FEC data that we lost // At this point, we're guaranteed that it's not FEC data that we lost
waitingForNextSuccessfulFrame = true; waitingForNextSuccessfulFrame = true;
gotNextFrameStart = false;
// Skip this frame // Skip this frame
nextFrameNumber++; nextFrameNumber++;
@ -266,6 +267,24 @@ public class VideoDepacketizer {
return; return;
} }
if (waitingForNextSuccessfulFrame) {
if (!gotNextFrameStart) {
if (!firstPacket) {
// We're waiting for the next frame, but this one is a fragment of a frame
// so we must discard it and wait for the next one
LimeLog.warning("Expected start of frame "+frameIndex);
nextFrameNumber = frameIndex + 1;
nextPacketNumber = 0;
clearAvcFrameState();
return;
}
else {
gotNextFrameStart = true;
}
}
}
nextPacketNumber++; nextPacketNumber++;
// Remove extra padding // Remove extra padding