private boolean shouldDropDelayedPacket(RtpPacket rtpPacket) { long now = System.currentTimeMillis(); if (now - lastPacketReceived > 100) { if (log.isDebugEnabled()) log.debug( "Delayed packet [" + rtpPacket.getRtcpPayloadType() + "," + rtpPacket.getPayloadType() + ", length=" + rtpPacket.getPayloadLength() + "] seqNum[rtpSeqNum=" + rtpPacket.getSeqNum() + ",lastSeqNum=" + lastSequenceNumber + "][rtpTS=" + rtpPacket.getTimestamp() + ",lastTS=" + lastPacketTimestamp + "][port=" + rtpSocket.getDatagramSocket().getLocalPort() + "]"); lastPacketReceived = now; return true; } lastPacketReceived = now; return false; }
public void receiveRtpPackets() { int packetReceivedCounter = 0; int internalBufferLength = payloadLength + RTP_HEADER_SIZE; byte[] internalBuffer; RtpPacket rtpPacket; while (receivePackets) { try { internalBuffer = new byte[internalBufferLength]; rtpPacket = new RtpPacket(internalBuffer, internalBufferLength); rtpSocket.receive(rtpPacket); packetReceivedCounter++; // log.debug("Received packet [" + rtpPacket.getRtcpPayloadType() + "," + // rtpPacket.getPayloadType() + ", length=" + rtpPacket.getPayloadLength() + "] // seqNum[rtpSeqNum=" + rtpPacket.getSeqNum() + ",lastSeqNum=" + lastSequenceNumber // + "][rtpTS=" + rtpPacket.getTimestamp() + ",lastTS=" + lastPacketTimestamp + // "][port=" + rtpSocket.getDatagramSocket().getLocalPort() + "]"); 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)) { // log.debug("Handling packet [" + rtpPacket.getRtcpPayloadType() + "," + // rtpPacket.getPayloadType() + ", length=" + rtpPacket.getPayloadLength() + "] // seqNum[rtpSeqNum=" + rtpPacket.getSeqNum() + ",lastSeqNum=" + lastSequenceNumber // + "][rtpTS=" + rtpPacket.getTimestamp() + ",lastTS=" + // lastPacketTimestamp + "][port=" + rtpSocket.getDatagramSocket().getLocalPort() + // "]"); processRtpPacket(rtpPacket); } 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; } } } catch ( IOException e) { // We get this when the socket closes when the call hangs up. receivePackets = false; } } log.debug("Rtp Receiver stopped. Packet Received = " + packetReceivedCounter + "."); if (listener != null) listener.onStoppedReceiving(); }