I'm doing a VoIP application for my thesis. I would like to know if someone can help me with this scenario: I have two threads, AudioThread and AudioSendThread. The first one its the listener that receive the audio-packet throught a DatagramSocket and play it in the phone. The second one its a recorder that grab 20 millisecond of sound and send it to the other device. I have implemented it in java but its really slow, so i decided to try OpenSL, but i dont find any documentation for something like this.
This is the AudioSendThread
public class AudioSendThread implements Runnable {
private final static String TAG = "AudioSndThread";
private boolean createdAudioP = false;
private DatagramSocket audioSndSocket;
private String ipAddr;
private byte[] buffer;
public AudioSendThread(Object o){
this.ipAddr = //getting IpAddress
audioSndSocket = (DatagramSocket)o;
}
@Override
public void run() {
if(!createdAudioP)
createdAudioP = createAudioRecorder();
if(createdAudioP)
startRecording();
DatagramPacket packet = null;
while(true){
byte[] buffer = readAudio(20); //read 20 milliseconds of audio, this is the one i would like to implement in OpenSL
try {
packet = new DatagramPacket(buffer, buffer.length, InetAddress.getByName(this.ipAddr), PORT.AUDIO);
audioSndSocket.send(packet);
} catch (IOException e) {
Log.e(TAG, e.getMessage());
return;
}
}
}
public static native void startRecording();
public static native boolean createAudioRecorder();
public static native byte[] readAudio(int millis);
static {
System.loadLibrary("SoundUtils");
}}
And thisone the AudioThread
public class AudioThread implements Runnable{
private DatagramSocket audioServSock;
@Override
public void run() {
createBufferQueueAudioPlayer();
DatagramPacket packet = null;
Thread audioSndThread = null;
try {
this.audioServSock = new DatagramSocket(PORT.AUDIO);
} catch (SocketException e1) {
e1.printStackTrace();
}
if(true){
audioSndThread = new Thread(new AudioSendThread(this.audioServSock));
audioSndThread.start();
}
byte[] buffer = new buffer[1500]; //random size
packet = new DatagramPacket(buffer, 1500);
while(true){
try {
audioServSock.receive(packet);
playAudio(buffer, packet.getLength()); //other method i would like to implement in OpenSL
} catch (IOException e) {
Log.e(TAG, Log.getStackTraceString(e));
return;
}
}
at.stop();
at.release();
}
public static native void createBufferQueueAudioPlayer();
public static native void playAudio(byte[] buffer, int length);
/** Load jni .so on initialization */
static {
System.loadLibrary("native-audio-jni");
}
}
The other native methods are taken by the NativeAudio sample of the NDK
Thanks all for any suggestion!