Revert "Also use the slow path for the last packet in each frame because it may be padded"

This reverts commit f2e7995747a5ed195926e88ee494602f6a09d9cf.
This commit is contained in:
Cameron Gutman 2014-11-11 16:59:42 -08:00
parent bacd1d81fd
commit 9728c136f5

View File

@ -143,11 +143,9 @@ public class VideoDepacketizer {
} }
} }
private void addInputDataSlow(VideoPacket packet, ByteBufferDescriptor location, private void addInputDataSlow(VideoPacket packet, ByteBufferDescriptor location)
boolean atFrameStart, boolean hasIntraNalPadding)
{ {
// If we're at frame start, we aren't yet decoding. boolean isDecodingH264 = false;
boolean isDecodingH264 = !atFrameStart;
while (location.length != 0) while (location.length != 0)
{ {
@ -172,7 +170,6 @@ public class VideoDepacketizer {
reassembleAvcFrame(packet.getFrameIndex()); reassembleAvcFrame(packet.getFrameIndex());
// Setup state for the new NAL // Setup state for the new NAL
frameStartTime = System.currentTimeMillis();
avcFrameDataChain = new LinkedList<ByteBufferDescriptor>(); avcFrameDataChain = new LinkedList<ByteBufferDescriptor>();
avcFrameDataLength = 0; avcFrameDataLength = 0;
packetSet = new HashSet<VideoPacket>(); packetSet = new HashSet<VideoPacket>();
@ -204,17 +201,10 @@ public class VideoDepacketizer {
{ {
// Only stop if we're decoding something or this // Only stop if we're decoding something or this
// isn't padding // isn't padding
boolean isPadding = NAL.isPadding(cachedSpecialDesc); if (isDecodingH264 || !NAL.isPadding(cachedSpecialDesc))
if (isDecodingH264 || !isPadding)
{ {
break; break;
} }
else if (!hasIntraNalPadding && isPadding)
{
// There's nothing more after this
location.length = 0;
break;
}
} }
} }
@ -225,15 +215,6 @@ public class VideoDepacketizer {
if (isDecodingH264 && avcFrameDataChain != null) if (isDecodingH264 && avcFrameDataChain != null)
{ {
// HACK: It's possible that the last location in the packet could be zero-padded
// but not with enough zeros to be an invalid AVC sequence. In this case, we're going to
// just guess that 2 zeros in a row at the end are probably padding.
if (!hasIntraNalPadding && location.length == 0 &&
location.data[location.offset-2] == 0 &&
location.data[location.offset-1] == 0) {
location.offset -= 2;
}
ByteBufferDescriptor data = new ByteBufferDescriptor(location.data, start, location.offset-start); ByteBufferDescriptor data = new ByteBufferDescriptor(location.data, start, location.offset-start);
if (packetSet.add(packet)) { if (packetSet.add(packet)) {
@ -377,18 +358,13 @@ public class VideoDepacketizer {
} }
lastPacketInStream = streamPacketIndex; lastPacketInStream = streamPacketIndex;
if ((flags & VideoPacket.FLAG_EOF) != 0) if (firstPacket
{
// The last video packet can also have zero padding which we must strip using the slow path.
addInputDataSlow(packet, cachedReassemblyDesc, (flags & VideoPacket.FLAG_SOF) != 0, false);
}
else if (firstPacket
&& NAL.getSpecialSequenceDescriptor(cachedReassemblyDesc, cachedSpecialDesc) && NAL.getSpecialSequenceDescriptor(cachedReassemblyDesc, cachedSpecialDesc)
&& NAL.isAvcFrameStart(cachedSpecialDesc) && NAL.isAvcFrameStart(cachedSpecialDesc)
&& cachedSpecialDesc.data[cachedSpecialDesc.offset+cachedSpecialDesc.length] == 0x67) && cachedSpecialDesc.data[cachedSpecialDesc.offset+cachedSpecialDesc.length] == 0x67)
{ {
// 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, true, true); addInputDataSlow(packet, cachedReassemblyDesc);
} }
else else
{ {