Skip to content

Commit

Permalink
A little more av testing
Browse files Browse the repository at this point in the history
  • Loading branch information
markwinter committed Sep 5, 2014
1 parent 562b89f commit b9226f8
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 8 deletions.
10 changes: 4 additions & 6 deletions app/src/main/java/im/tox/antox/activities/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.media.AudioManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
Expand Down Expand Up @@ -70,6 +71,9 @@ protected void onNewIntent(Intent i) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Pressing the volume keys will affect STREAM_MUSIC played from this app
setVolumeControlStream(AudioManager.STREAM_MUSIC);

preferences = PreferenceManager.getDefaultSharedPreferences(this);

/* Check if a language has been set or not */
Expand Down Expand Up @@ -175,12 +179,6 @@ public void onClickAddFriend(View v) {
}

public void onClickVoiceCallFriend(View v) {
/** Curent error when using this code
* 09-04 03:05:12.075 13525-13525/im.tox.antox W/dalvikvm﹕ JNI WARNING: JNI method called with exception pending
* 09-04 03:05:12.075 13525-13525/im.tox.antox W/dalvikvm﹕ in Lim/tox/jtoxcore/JTox;.toxav_call:(JILim/tox/jtoxcore/ToxCodecSettings;I)I (GetFieldID)
* 09-04 03:05:12.075 13525-13525/im.tox.antox W/dalvikvm﹕ Pending exception is:
* 09-04 03:05:12.075 13525-13525/im.tox.antox I/dalvikvm﹕ java.lang.NoSuchFieldError: no field with name='call_type' signature='Lim/tox/jtoxcore/ToxCodecSettings' in class Lim/tox/jtoxcore/ToxCodecSettings;
*/
ToxCodecSettings toxCodecSettings = new ToxCodecSettings(ToxCallType.TYPE_AUDIO, 0, 0, 0, 64000, 20, 48000, 1);
AntoxFriend friend = toxSingleton.getAntoxFriend(toxSingleton.activeKey);
int userID = friend.getFriendnumber();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package im.tox.antox.callbacks;

import android.content.Context;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioTrack;
import android.media.MediaPlayer;
import android.util.Log;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;

import im.tox.antox.utils.AntoxFriend;
import im.tox.jtoxcore.callbacks.OnAudioDataCallback;

Expand All @@ -19,5 +27,21 @@ public AntoxOnAudioDataCallback(Context ctx) {

public void execute(int callID, byte[] data) {
Log.d("OnAudioDataCallback", "Received callback from: " + callID);
try {
AudioTrack audioTrack = new AudioTrack(
AudioManager.STREAM_MUSIC,
48000,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
data.length,
AudioTrack.MODE_STATIC);

audioTrack.play();
audioTrack.write(data, 0, data.length);
audioTrack.stop();
audioTrack.flush();

} catch (Exception e) {
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package im.tox.antox.callbacks;

import android.content.Context;
import android.media.AudioManager;
import android.util.Log;

import im.tox.antox.R;
import im.tox.antox.data.AntoxDB;
import im.tox.antox.tox.ToxSingleton;
import im.tox.antox.utils.AntoxFriend;
import im.tox.antox.utils.AntoxFriendList;
import im.tox.jtoxcore.FriendList;
import im.tox.jtoxcore.ToxAvCallbackID;
import im.tox.jtoxcore.ToxCallType;
import im.tox.jtoxcore.ToxCodecSettings;
Expand All @@ -25,9 +30,65 @@ public AntoxOnAvCallbackCallback(Context ctx) {
public void execute(int callID, ToxAvCallbackID callbackID) {
Log.d("OnAvCallbackCallback", "Received a callback from: " + callID);
ToxSingleton toxSingleton = ToxSingleton.getInstance();
ToxCodecSettings toxCodecSettings = new ToxCodecSettings(ToxCallType.TYPE_AUDIO, 0, 0, 0, 64000, 20, 48000, 1);

try {
toxSingleton.jTox.avAnswer(0, toxCodecSettings);
switch (callbackID) {
/* Requests */
case ON_INVITE: // Incoming call request
Log.d("OnAvCallbackCallback", "Callback type: ON_INVITE");
// Display UI elements to accept or reject the call
// For testing auto-accept
ToxCodecSettings toxCodecSettings = new ToxCodecSettings(ToxCallType.TYPE_AUDIO, 500, 1280, 720, 64000, 20, 48000, 1);
toxSingleton.jTox.avAnswer(callID, toxCodecSettings);
break;

case ON_START: // Incoming call was accepted
Log.d("OnAvCallbackCallback", "Callback type: ON_START");
// Prepare for transmission
toxSingleton.jTox.avPrepareTransmission(0, 3, 40, false);

break;

case ON_CANCEL: // Incoming call timed out/stopped
Log.d("OnAvCallbackCallback", "Callback type: ON_CANCEL");
break;

case ON_REJECT: // Incoming call was rejected
Log.d("OnAvCallbackCallback", "Callback type: ON_REJECT");
break;

case ON_END: // On-going call has now been ended
Log.d("OnAvCallbackCallback", "Callback type: ON_END");
break;


/* Responses */
case ON_RINGING: // Our call has gone through and is ringing
Log.d("OnAvCallbackCallback", "Callback type: ON_RINGING");
break;

case ON_STARTING:
Log.d("OnAvCallbackCallback", "Callback type: ON_STARTING");
break;

case ON_ENDING:
Log.d("OnAvCallbackCallback", "Callback type: ON_ENDING");
break;


/* Protocol */
case ON_REQUEST_TIMEOUT:
Log.d("OnAvCallbackCallback", "Callback type: ON_REQUEST_TIMEOUT");
break;

case ON_PEER_TIMEOUT:
Log.d("OnAvCallbackCallback", "Callback type: ON_PEER_TIMEOUT");
break;

case ON_MEDIA_CHANGE:
Log.d("OnAvCallbackCallback", "Callback type: ON_MEDIA_CHANGE");
break;
}
} catch (ToxException e) {
}
}
Expand Down

0 comments on commit b9226f8

Please sign in to comment.