Use packet flags to determine where frames end and begin instead of the packet index

This commit is contained in:
Cameron Gutman 2014-02-17 15:17:20 -05:00
parent c93812179f
commit a96de39b28
2 changed files with 14 additions and 18 deletions

View File

@ -14,7 +14,6 @@ public class VideoDepacketizer {
private LinkedList<ByteBufferDescriptor> avcNalDataChain = null; private LinkedList<ByteBufferDescriptor> avcNalDataChain = null;
private int avcNalDataLength = 0; private int avcNalDataLength = 0;
private int currentlyDecoding = DecodeUnit.TYPE_UNKNOWN; private int currentlyDecoding = DecodeUnit.TYPE_UNKNOWN;
private boolean splitFrame = false;
// Sequencing state // Sequencing state
private short lastSequenceNumber; private short lastSequenceNumber;
@ -175,15 +174,9 @@ public class VideoDepacketizer {
// Remove extra padding // Remove extra padding
location.length = packet.getPayloadLength(); location.length = packet.getPayloadLength();
boolean firstPacket = !splitFrame && packetIndex == 0; boolean firstPacket = (packet.getFlags() & VideoPacket.FLAG_SOF) != 0;
// Reset split frame state on next frame start
if (packetIndex == 0) {
splitFrame = false;
}
if (firstPacket) if (firstPacket)
{ {
if (NAL.getSpecialSequenceDescriptor(location, cachedDesc) && NAL.isAvcFrameStart(cachedDesc) if (NAL.getSpecialSequenceDescriptor(location, cachedDesc) && NAL.isAvcFrameStart(cachedDesc)
&& cachedDesc.data[cachedDesc.offset+cachedDesc.length] == 0x67) && cachedDesc.data[cachedDesc.offset+cachedDesc.length] == 0x67)
{ {
@ -195,12 +188,8 @@ public class VideoDepacketizer {
addInputDataFast(packet, location, firstPacket); addInputDataFast(packet, location, firstPacket);
if (!splitFrame && packetIndex + 1 == packetsInFrame) { if ((packet.getFlags() & VideoPacket.FLAG_EOF) != 0) {
// Reassemble the frame if this was the last packet and it's not a split frame reassembleAvcNal();
if (packet.getPayloadLength() == 968)
splitFrame = true;
else
reassembleAvcNal();
} }
} }

View File

@ -12,6 +12,10 @@ public class VideoPacket {
private int packetIndex; private int packetIndex;
private int totalPackets; private int totalPackets;
private int payloadLength; private int payloadLength;
private int flags;
public static final int FLAG_EOF = 0x2;
public static final int FLAG_SOF = 0x4;
public VideoPacket(ByteBufferDescriptor rtpPayload) public VideoPacket(ByteBufferDescriptor rtpPayload)
{ {
@ -23,12 +27,15 @@ public class VideoPacket {
frameIndex = bb.getInt(); frameIndex = bb.getInt();
packetIndex = bb.getInt(); packetIndex = bb.getInt();
totalPackets = bb.getInt(); totalPackets = bb.getInt();
flags = bb.getInt();
bb.position(bb.position()+4);
payloadLength = bb.getInt(); payloadLength = bb.getInt();
} }
public int getFlags()
{
return flags;
}
public int getFrameIndex() public int getFrameIndex()
{ {
return frameIndex; return frameIndex;