public void receiveRtpPackets() {
int packetReceivedCounter = 0;
int internalBufferLength = payloadLength + RTP_HEADER_SIZE;
byte[] internalBuffer = new byte[internalBufferLength];
RtpPacket rtpPacket = new RtpPacket(internalBuffer, internalBufferLength);;
while (receivePackets) {
try {
rtpSocket.receive(rtpPacket);
packetReceivedCounter++;
if (shouldDropDelayedPacket(rtpPacket)) {
continue;
}
if (rtpPacket.isRtcpPacket()) {
/**
* Asterisk (1.6.2.5) send RTCP packets. We just ignore them (for now).
* It could be for KeepAlive (http://tools.ietf.org/html/draft-ietf-avt-app-rtp-keepalive-09)
*/
if (log.isDebugEnabled())
log.debug("RTCP packet [" + rtpPacket.getRtcpPayloadType() + ", length=" + rtpPacket.getPayloadLength() + "] seqNum[rtpSeqNum=" + rtpPacket.getSeqNum() + ",lastSeqNum=" + lastSequenceNumber
+ "][rtpTS=" + rtpPacket.getTimestamp() + ",lastTS=" + lastPacketTimestamp + "][port=" + rtpSocket.getDatagramSocket().getLocalPort() + "]");
} else {
if (shouldHandlePacket(rtpPacket)) {
lastSequenceNumber = rtpPacket.getSeqNum();
lastPacketTimestamp = rtpPacket.getTimestamp();
processRtpPacket(internalBuffer, RTP_HEADER_SIZE, rtpPacket.getPayloadLength());
} else {
if (log.isDebugEnabled())
log.debug("Corrupt packet [" + rtpPacket.getRtcpPayloadType() + "," + rtpPacket.getPayloadType() + ", length=" + rtpPacket.getPayloadLength() + "] seqNum[rtpSeqNum=" + rtpPacket.getSeqNum() + ",lastSeqNum=" + lastSequenceNumber
+ "][rtpTS=" + rtpPacket.getTimestamp() + ",lastTS=" + lastPacketTimestamp + "][port=" + rtpSocket.getDatagramSocket().getLocalPort() + "]");
if (lastPacketDropped) successivePacketDroppedCount++;
else lastPacketDropped = true;
}
}