private boolean isMarkerPacket(RtpPacket rtpPacket) { /* * FreeSWITCH sends a marker packet at the beginning of the voice frame. * If you stop talking and then start talking, a marker packet is received on start talking. (ralam sept 20, 2010). */ if (rtpPacket.hasMarker()) { if (log.isDebugEnabled()) log.debug( "Marked packet [" + rtpPacket.getPayloadType() + ", length=" + rtpPacket.getPayloadLength() + "] seqNum[rtpSeqNum=" + rtpPacket.getSeqNum() + ",lastSeqNum=" + lastSequenceNumber + "][rtpTS=" + rtpPacket.getTimestamp() + ",lastTS=" + lastPacketTimestamp + "][port=" + rtpSocket.getDatagramSocket().getLocalPort() + "]"); return true; } return false; }
private boolean isFirstPacket(RtpPacket rtpPacket) { if (firstPacket) { lastPacketReceived = System.currentTimeMillis(); firstPacket = false; if (log.isDebugEnabled()) log.debug( "First packet [" + rtpPacket.getPayloadType() + ", length=" + rtpPacket.getPayloadLength() + "] seqNum[rtpSeqNum=" + rtpPacket.getSeqNum() + ",lastSeqNum=" + lastSequenceNumber + "][rtpTS=" + rtpPacket.getTimestamp() + ",lastTS=" + lastPacketTimestamp + "][port=" + rtpSocket.getDatagramSocket().getLocalPort() + "]"); return true; } return false; }
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(); }