headerValue = headerByte & 0xff;
byteCount = 1;
}
final int channelId = RTMPUtils.decodeChannelId(headerValue, byteCount);
if (channelId < 0) {
throw new ProtocolException("Bad channel id: " + channelId);
}
RTMP rtmp = conn.getState();
// Get the header size and length
byte headerSize = RTMPUtils.decodeHeaderSize(headerValue, byteCount);
int headerLength = RTMPUtils.getHeaderLength(headerSize);
Header lastHeader = rtmp.getLastReadHeader(channelId);
headerLength += byteCount - 1;
switch (headerSize) {
case HEADER_NEW:
case HEADER_SAME_SOURCE:
case HEADER_TIMER_CHANGE:
if (remaining >= headerLength) {
int timeValue = RTMPUtils.readUnsignedMediumInt(in);
if (timeValue == 0xffffff) {
headerLength += 4;
}
}
break;
case HEADER_CONTINUE:
if (lastHeader != null && lastHeader.getExtendedTimestamp() != 0) {
headerLength += 4;
}
break;
default:
throw new ProtocolException("Unexpected header size " + headerSize + " check for error");
}
if (remaining < headerLength) {
log.trace("Header too small (hlen: {}), buffering. remaining: {}", headerLength, remaining);
in.position(position);
state.bufferDecoding(headerLength);
return null;
}
// Move the position back to the start
in.position(position);
final Header header = decodeHeader(in, lastHeader);
if (header == null) {
throw new ProtocolException("Header is null, check for error");
}
rtmp.setLastReadHeader(channelId, header);
// check to see if this is a new packets or continue decoding an existing one
Packet packet = rtmp.getLastReadPacket(channelId);
if (packet == null) {