VoIP RTP Streaming from / to server (in Java) to / from android

My goal is to have a chat application in a chat on GSM / UMTS / LTE networks; at first I wanted to use multicast addresses and peer-to-peer networks without server overload; Unfortunately, after a deep investigation, I found that multicast is not allowed on GSM / UMTS / LTE networks, so I have to use a server to refuse VoIP packets. I do not really like this solution, because I have to overload the server, but I did not find a better solution. If you have an alternative solution, it is very apprieciated ...

Therefore, I have to send VoIP from the android client to the server (PC) and vice versa. The server is in Java, it must receive VoIP packets, and then send VoIP packets to other N clients; The server is the bouncer of VoIP packets.

I developed the code, but it does not work; I don’t have any mistake, I just have very poor VoIP service: I lose a lot of things and what I hear is very noisy ... Where is the error? I believe that this should be in the server code; the server simply receives the packet and resends it, not knowing that they are VoIP on RTP.

Below you will find

  • The code I use to send VoIP packets to the server. This works because I have no problem when I use it for an individual call sending VoIP packets directly from Android to Android; The code for receiving in android packages from the server is very similar, so I do not return it. As you can see, I am using android.net.rtp.
  • The code I use on the Java server for VoIP packet failures

Thanks Fausto

// ANDROID CODE USED TO SEND VOIP TO THE SERVER

//Attribute definition
private static final AudioCodec myAudioCodec_COSTANTE = AudioCodec.PCMU ; 
private static final int myAudioGroupTX_COSTANTE = AudioGroup.MODE_NORMAL ; 
private static final int myAudioGroupRX_COSTANTE = AudioGroup.MODE_NORMAL ;
private static final int myRtpStreamTX_COSTANTE = RtpStream.MODE_SEND_ONLY ;
private static final int myRtpStreamRX_COSTANTE = RtpStream.MODE_RECEIVE_ONLY ; 
private static final int myAudioManagerTX_COSTANTE = AudioManager.MODE_IN_COMMUNICATION;
private static final int myAudioManagerRX_COSTANTE = AudioManager.MODE_IN_COMMUNICATION; 

//Method called for VoIP trasmission
myAudioStream = new AudioStream(localClientIP);
myAudioGroup = new AudioGroup();
myAudioManager =  (AudioManager) myContext.getSystemService(Context.AUDIO_SERVICE);

myAudioGroup.setMode(myAudioGroupTX_COSTANTE);
myAudioStream.join(null); 
myAudioStream.setCodec(myAudioCodec_COSTANTE);
myAudioStream.setMode(myRtpStreamTX_COSTANTE);
myAudioStream.associate(ipaddress_Server, port_Server)    
myAudioStream.join(myAudioGroup); 
myAudioManager.setMode(myAudioManagerTX_COSTANTE);
myAudioManager.setSpeakerphoneOn(false);
myAudioManager.setMicrophoneMute(false);

// JAVA SERVER CODE USED TO GET A VOYP FROM ANDROID AND DISPLAY THIS TO THE SERVER

DatagramSocket datagramSocket_RX_VoIP= new DatagramSocket();
DatagramSocket datagramSocket_TX_VoIP= new DatagramSocket();
int unicast_port_TX_VoIP = 5000 ;
String unicast_ip_TX_VoIP = "192.168.0.3";

    Thread t = new Thread(new Runnable() {
    public void run() {
    try {
        DatagramPacket myPacket;
        while (true) {
            myPacket = ManagePacket.initializePacket(); //Function to prepare the packe ; the problem is not here!!!
            datagramSocket_RX_VoIP.receive(myPacket);

            InetAddress ppp =  InetAddress.getByName(unicast_ip_TX_VoIP);
            myPacket.setAddress(ppp);
            myPacket.setPort( unicast_port_TX_VoIP ) ;
            datagramSocket_TX_VoIP.send(myPacket);
        }

    }  catch (Exception ex) {
        log.debug("Exception: " + ex.getMessage(), ex);
    }
    }
    });
    t.start();                                        
+4
source share
1 answer

You do not give enough details about your application. With any UDP streaming application, you need to solve the following problems:

  • . , , , , . . , , . - .

  • : UDP. "" . 10 №4 , №3, №5. . :

    • : . ( , ). "" , , .
    • : . . - .
  • : . RTP, .

. , , . UDP - . , , TCP, , .

+5

All Articles