コード例 #1
0
 private boolean validSeqNum(RtpPacket rtpPacket) {
   /*
    * Assume if the sequence number jumps by more that 100, that the sequence number is corrupt.
    */
   return (rtpPacket.getSeqNum() > lastSequenceNumber
       && rtpPacket.getSeqNum() - lastSequenceNumber < 100);
 }
コード例 #2
0
 private void processRtpPacket(RtpPacket rtpPacket) {
   lastSequenceNumber = rtpPacket.getSeqNum();
   lastPacketTimestamp = rtpPacket.getTimestamp();
   AudioByteData audioData = new AudioByteData(rtpPacket.getPayload());
   if (listener != null) listener.onAudioDataReceived(audioData);
   else log.debug("No listener for incoming audio packet");
 }
コード例 #3
0
 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;
 }
コード例 #4
0
  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;
  }
コード例 #5
0
 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;
 }
コード例 #6
0
 private boolean seqNumRolledOver(RtpPacket rtpPacket) {
   /*
    * Max sequence num is 65535 (16-bits). Let's use 65000 as check to take into account
    * delayed packets.
    */
   if (lastSequenceNumber - rtpPacket.getSeqNum() > 65000) {
     if (log.isDebugEnabled())
       log.debug(
           "Packet rolling over seqNum[rtpSeqNum="
               + rtpPacket.getSeqNum()
               + ",lastSeqNum="
               + lastSequenceNumber
               + "][rtpTS="
               + rtpPacket.getTimestamp()
               + ",lastTS="
               + lastPacketTimestamp
               + "][port="
               + rtpSocket.getDatagramSocket().getLocalPort()
               + "]");
     return true;
   }
   return false;
 }
コード例 #7
0
  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();
  }