Examples of RtpPacket


Examples of local.net.RtpPacket

         return;
      }
      //else

      byte[] buffer_in=new byte[BUFFER_SIZE];
      RtpPacket rtp_packet_in=new RtpPacket(buffer_in,0);
      byte[] buffer_out=new byte[BUFFER_SIZE];
      RtpPacket rtp_packet_out=new RtpPacket(buffer_out,0);
      //rtp_packet_out.setPayloadType(p_type);     

      if (DEBUG) println("Reading blocks of max "+BUFFER_SIZE+" bytes");

      //File file=new File("audio.wav");
      //javax.sound.sampled.AudioInputStream audio_input_stream=null;
      //try {  audio_input_stream=javax.sound.sampled.AudioSystem.getAudioInputStream(file);  } catch (Exception e) {  e.printStackTrace();  }

      running=true;
      try
      rtp_socket_in.getDatagramSocket().setSoTimeout(SO_TIMEOUT);
         while (running)
         {  try
            // read a block of data from the rtp_socket_in
               rtp_socket_in.receive(rtp_packet_in);
               //if (DEBUG) System.out.print(".");
              
               // send the block to the rtp_socket_out (if still running..)
               if (running)
               {  byte[] pkt1=rtp_packet_in.getPacket();
                  int offset1=rtp_packet_in.getHeaderLength();
                  int len1=rtp_packet_in.getPayloadLength();

                  byte[] pkt2=rtp_packet_out.getPacket();
                  int offset2=rtp_packet_out.getHeaderLength();
                  int pos2=offset2;
                 
                  for (int i=0; i<len1; i++)
                  {  int linear=G711.ulaw2linear(pkt1[offset1+i]);
                     //aux[pos++]=(byte)(linear&0xFF);
                     //aux[pos++]=(byte)((linear&0xFF00)>>8);
                     //int linear2=G711.ulaw2linear(audio_input_stream.read());
                     //linear+=linear2;
                     pkt2[pos2++]=(byte)G711.linear2ulaw(linear);
                  }            
                  rtp_packet_out.setPayloadType(rtp_packet_in.getPayloadType());
                  rtp_packet_out.setSequenceNumber(rtp_packet_in.getSequenceNumber());
                  rtp_packet_out.setTimestamp(rtp_packet_in.getTimestamp());
                  rtp_packet_out.setPayloadLength(pos2-offset2);
                  rtp_socket_out.send(rtp_packet_out);
               }

            }
            catch (java.io.InterruptedIOException e) { }
View Full Code Here

Examples of local.net.RtpPacket

        int internalBufferLength = payloadLength + RTP_HEADER_SIZE;
       
        while (receivePackets) {
          try {
            byte[] internalBuffer = new byte[internalBufferLength];
            RtpPacket rtpPacket = new RtpPacket(internalBuffer, 0);                 
            rtpSocket.receive(rtpPacket);
            packetReceivedCounter++;  
            processReceivedPacket(rtpPacket);
          } catch (IOException e) {
            log.error("IOException while receiving rtp packets.");
View Full Code Here

Examples of local.net.RtpPacket

         return;
      }
      //else

      byte[] buffer=new byte[BUFFER_SIZE];
      RtpPacket rtp_packet=new RtpPacket(buffer,0);

      if (DEBUG) println("Reading blocks of max "+buffer.length+" bytes");

      //byte[] aux=new byte[BUFFER_SIZE];

      running=true;
      try
      rtp_socket.getDatagramSocket().setSoTimeout(SO_TIMEOUT);
         while (running)
         {  try
            // read a block of data from the rtp socket
               rtp_socket.receive(rtp_packet);
               //if (DEBUG) System.out.print(".");
              
               // write this block to the output_stream (only if still running..)
               if (running) output_stream.write(rtp_packet.getPacket(), rtp_packet.getHeaderLength(), rtp_packet.getPayloadLength());
               /*if (running)
               {  byte[] pkt=rtp_packet.getPacket();
                  int offset=rtp_packet.getHeaderLength();
                  int len=rtp_packet.getPayloadLength();
                  int pos=0;
View Full Code Here

Examples of local.net.RtpPacket

        rtpSocket = new RtpSocket(srcSocket, InetAddress.getByName(destAddr), destPort);
    }

    public void start() {
        packetBuffer = new byte[transcoder.getOutgoingEncodedFrameSize() + RTP_HEADER_SIZE];
        rtpPacket = new RtpPacket(packetBuffer, 0);
        rtpPacket.setPayloadType(transcoder.getCodecId());
        startPayloadPos = rtpPacket.getHeaderLength();

        sequenceNum = 0;
        timestamp = 0;
View Full Code Here

Examples of local.net.RtpPacket

        timestamp = 0;
    }

    public void queueSipDtmfDigits(String dtmfDigits) {
        byte[] dtmfbuf = new byte[transcoder.getOutgoingEncodedFrameSize() + RTP_HEADER_SIZE];
        RtpPacket dtmfpacket = new RtpPacket(dtmfbuf, 0);
        dtmfpacket.setPayloadType(dtmf2833Type);
        dtmfpacket.setPayloadLength(transcoder.getOutgoingEncodedFrameSize());

        byte[] blankbuf = new byte[transcoder.getOutgoingEncodedFrameSize() + RTP_HEADER_SIZE];
        RtpPacket blankpacket = new RtpPacket(blankbuf, 0);
        blankpacket.setPayloadType(transcoder.getCodecId());
        blankpacket.setPayloadLength(transcoder.getOutgoingEncodedFrameSize());

        for (int d = 0; d < dtmfDigits.length(); d++) {
            char digit = dtmfDigits.charAt(d);
            if (digit == '*') {
                dtmfbuf[startPayloadPos] = 10;
            }
            else if (digit == '#') {
                dtmfbuf[startPayloadPos] = 11;
            }
            else if (digit >= 'A' && digit <= 'D') {
                dtmfbuf[startPayloadPos] = (byte) (digit - 53);
            }
            else {
                dtmfbuf[startPayloadPos] = (byte) (digit - 48);
            }

            // notice we are bumping times/seqn just like audio packets
            try {
                // send start event packet 3 times
                dtmfbuf[startPayloadPos + 1] = 0; // start event flag
                // and volume
                dtmfbuf[startPayloadPos + 2] = 1; // duration 8 bits
                dtmfbuf[startPayloadPos + 3] = -32; // duration 8 bits

                for (int r = 0; r < 3; r++) {
                    dtmfpacket.setSequenceNumber(sequenceNum++);
                    dtmfpacket.setTimestamp(transcoder.getOutgoingEncodedFrameSize());
                    doRtpDelay();
                    rtpSocketSend(dtmfpacket);
                }

                // send end event packet 3 times
                dtmfbuf[startPayloadPos + 1] = -128; // end event flag
                dtmfbuf[startPayloadPos + 2] = 3; // duration 8 bits
                dtmfbuf[startPayloadPos + 3] = 116; // duration 8 bits
                for (int r = 0; r < 3; r++) {
                    dtmfpacket.setSequenceNumber(sequenceNum++);
                    dtmfpacket.setTimestamp(transcoder.getOutgoingEncodedFrameSize() );
                    doRtpDelay();
                    rtpSocketSend(dtmfpacket);
                }

                // send 200 ms of blank packets
                for (int r = 0; r < 200 / transcoder.getOutgoingPacketization(); r++) {
                    blankpacket.setSequenceNumber(sequenceNum++);
                    blankpacket.setTimestamp(transcoder.getOutgoingEncodedFrameSize());
                    doRtpDelay();
                    rtpSocketSend(blankpacket);
                }
            }
            catch (Exception e) {
View Full Code Here

Examples of local.net.RtpPacket

    processPacket = true;
    packetProcessor = new Runnable() {
      public void run() {
        while (processPacket) {
          try {         
            RtpPacket packet = packets.take();
            processPacket(packet);
          } catch (InterruptedException e) {
            log.warn("InterruptedExeption while taking event.");
          }
        }
View Full Code Here

Examples of local.net.RtpPacket

   {
      if (rtp_socket==null || input_stream==null) return;
      //else
     
      byte[] buffer=new byte[frame_size+12];
      RtpPacket rtp_packet=new RtpPacket(buffer,0);
      rtp_packet.setPayloadType(p_type);     
      int seqn=0;
      long time=0;
      //long start_time=System.currentTimeMillis();
      long byte_rate=frame_rate*frame_size;
     
      running=true;
           
      if (DEBUG) println("Reading blocks of "+(buffer.length-12)+" bytes");

      try
      while (running)
         {
            //if (DEBUG) System.out.print("o");
            int num=input_stream.read(buffer,12,buffer.length-12);
          //if (DEBUG) System.out.print("*");
            if (num>0)
            {  rtp_packet.setSequenceNumber(seqn++);
               rtp_packet.setTimestamp(time);
               rtp_packet.setPayloadLength(num);
               rtp_socket.send(rtp_packet);
               // update rtp timestamp (in milliseconds)
               long frame_time=(num*1000)/byte_rate;
               time+=frame_time;
               // wait fo next departure
View Full Code Here

Examples of net.sourceforge.peers.rtp.RtpPacket

        // duration 8 bits
        data[2] = 0;
        // duration 8 bits
        data[3] = -96;

        RtpPacket rtpPacket = new RtpPacket();
        rtpPacket.setData(data);
        rtpPacket.setPayloadType(RFC4733.PAYLOAD_TYPE_TELEPHONE_EVENT);
        rtpPacket.setMarker(true);
        packets.add(rtpPacket);

        // two classical packets

        rtpPacket = new RtpPacket();
        // set duration to 320
        data = data.clone();
        data[2] = 1;
        data[3] = 64;
        rtpPacket.setData(data);
        rtpPacket.setMarker(false);
        rtpPacket.setPayloadType(RFC4733.PAYLOAD_TYPE_TELEPHONE_EVENT);
        packets.add(rtpPacket);

        rtpPacket = new RtpPacket();
        // set duration to 320
        data = data.clone();
        data[2] = 1;
        data[3] = -32;
        rtpPacket.setData(data);
        rtpPacket.setMarker(false);
        rtpPacket.setPayloadType(RFC4733.PAYLOAD_TYPE_TELEPHONE_EVENT);
        packets.add(rtpPacket);

        data = data.clone();
        // create three end event packets
        data[1] = -0x76; // end event flag + volume set to 10
        // set Duration to 640
        data[2] = 2; // duration 8 bits
        data[3] = -128; // duration 8 bits
        for (int r = 0; r < 3; r++) {
            rtpPacket = new RtpPacket();
            rtpPacket.setData(data);
            rtpPacket.setMarker(false);
            rtpPacket.setPayloadType(RFC4733.PAYLOAD_TYPE_TELEPHONE_EVENT);
            packets.add(rtpPacket);
        }

        return packets;
    }
View Full Code Here

Examples of net.sourceforge.peers.rtp.RtpPacket

            } catch (FileNotFoundException e) {
                logger.error("cannot create file", e);
                return;
            }
        }
        RtpPacket rtpPacket = new RtpPacket();
        rtpPacket.setVersion(2);
        rtpPacket.setPadding(false);
        rtpPacket.setExtension(false);
        rtpPacket.setCsrcCount(0);
        rtpPacket.setMarker(false);
        rtpPacket.setPayloadType(codec.getPayloadType());
        Random random = new Random();
        int sequenceNumber = random.nextInt();
        rtpPacket.setSequenceNumber(sequenceNumber);
        rtpPacket.setSsrc(random.nextInt());
        int buf_size = Capture.BUFFER_SIZE / 2;
        byte[] buffer = new byte[buf_size];
        long counter = 0;
       
        while (!isStopped) {
            int numBytesRead;
            try {
                numBytesRead = encodedData.read(buffer, 0, buf_size);
            } catch (IOException e) {
                logger.error("input/output error", e);
                return;
            }
            byte[] trimmedBuffer;
            if (numBytesRead < buffer.length) {
                trimmedBuffer = new byte[numBytesRead];
                System.arraycopy(buffer, 0, trimmedBuffer, 0, numBytesRead);
            } else {
                trimmedBuffer = buffer;
            }
            if (mediaDebug) {
                try {
                    rtpSenderInput.write(trimmedBuffer);
                } catch (IOException e) {
                    logger.error("cannot write to file", e);
                    break;
                }
            }
            if (pushedPackets.size() > 0) {
                RtpPacket pushedPacket = pushedPackets.remove(0);
                rtpPacket.setMarker(pushedPacket.isMarker());
                rtpPacket.setPayloadType(pushedPacket.getPayloadType());
                byte[] data = pushedPacket.getData();
                rtpPacket.setData(data);
            } else {
                if (rtpPacket.getPayloadType() != codec.getPayloadType()) {
                    rtpPacket.setPayloadType(codec.getPayloadType());
                    rtpPacket.setMarker(false);
View Full Code Here

Examples of org.bigbluebutton.voiceconf.red5.media.net.RtpPacket

   
    public void sendAudio(byte[] audioData, long timestamp) {
      byte[] transcodedAudioDataBuffer = new byte[audioData.length + RTP_HEADER_SIZE];
      System.arraycopy(audioData, 0, transcodedAudioDataBuffer, RTP_HEADER_SIZE, audioData.length);
      RtpPacket rtpPacket = new RtpPacket(transcodedAudioDataBuffer, transcodedAudioDataBuffer.length);
      if (!marked) {
        rtpPacket.setMarker(true);
        marked = true;
        startTimestamp = System.currentTimeMillis();
      }
      rtpPacket.setPadding(false);
      rtpPacket.setExtension(false);
        rtpPacket.setPayloadType(codecId);
      rtpPacket.setSeqNum(sequenceNum++);  
      rtpPacket.setTimestamp(timestamp);
        rtpPacket.setPayloadLength(audioData.length);
        try {
    rtpSocketSend(rtpPacket);
  } catch (StreamException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.