Package local.net

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


        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

         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

        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

        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

    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

   {
      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

TOP

Related Classes of local.net.RtpPacket

Copyright © 2018 www.massapicom. 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.