Fix linphone tester

This commit is contained in:
Gautier Pelloux-Prayer 2015-01-06 14:58:44 +01:00
parent cbf41122b3
commit 47e6e1456c

View file

@ -47,45 +47,45 @@ public class LinphoneTestManager implements LinphoneListener {
private static LinphoneTestManager instance; private static LinphoneTestManager instance;
private Context mIContext; private Context mIContext;
private LinphoneCore mLc1, mLc2; private LinphoneCore mLc1, mLc2;
public String lastMessageReceived; public String lastMessageReceived;
public boolean isDTMFReceived = false; public boolean isDTMFReceived = false;
public boolean autoAnswer = true; public boolean autoAnswer = true;
public boolean declineCall = false; public boolean declineCall = false;
private final String linphoneRootCaFile; private final String linphoneRootCaFile;
private Timer mTimer1 = new Timer("Linphone scheduler 1"); private Timer mTimer1 = new Timer("Linphone scheduler 1");
private Timer mTimer2 = new Timer("Linphone scheduler 2"); private Timer mTimer2 = new Timer("Linphone scheduler 2");
private LinphoneTestManager(Context ac, Context ic) { private LinphoneTestManager(Context ac, Context ic) {
mIContext = ic; mIContext = ic;
linphoneRootCaFile = ac.getFilesDir().getAbsolutePath() + "/rootca.pem"; linphoneRootCaFile = ac.getFilesDir().getAbsolutePath() + "/rootca.pem";
} }
public static LinphoneTestManager createAndStart(Context ac, Context ic, int id) { public static LinphoneTestManager createAndStart(Context ac, Context ic, int id) {
if (instance == null) if (instance == null)
instance = new LinphoneTestManager(ac, ic); instance = new LinphoneTestManager(ac, ic);
instance.startLibLinphone(ic, id); instance.startLibLinphone(ic, id);
TelephonyManager tm = (TelephonyManager) ac.getSystemService(Context.TELEPHONY_SERVICE); TelephonyManager tm = (TelephonyManager) ac.getSystemService(Context.TELEPHONY_SERVICE);
boolean gsmIdle = tm.getCallState() == TelephonyManager.CALL_STATE_IDLE; boolean gsmIdle = tm.getCallState() == TelephonyManager.CALL_STATE_IDLE;
setGsmIdle(gsmIdle, id); setGsmIdle(gsmIdle, id);
return instance; return instance;
} }
private synchronized void startLibLinphone(Context c, int id) { private synchronized void startLibLinphone(Context c, int id) {
try { try {
LinphoneCoreFactory.instance().setDebugMode(true, "LinphoneTester"); LinphoneCoreFactory.instance().setDebugMode(true, "LinphoneTester");
final LinphoneCore mLc = LinphoneCoreFactory.instance().createLinphoneCore(this, c); final LinphoneCore mLc = LinphoneCoreFactory.instance().createLinphoneCore(this, c);
if (id == 2) { if (id == 2) {
mLc2 = mLc; mLc2 = mLc;
} else { } else {
mLc1 = mLc; mLc1 = mLc;
} }
mLc.setContext(c); mLc.setContext(c);
try { try {
String versionName = c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName; String versionName = c.getPackageManager().getPackageInfo(c.getPackageName(), 0).versionName;
@ -104,29 +104,29 @@ public class LinphoneTestManager implements LinphoneListener {
int availableCores = Runtime.getRuntime().availableProcessors(); int availableCores = Runtime.getRuntime().availableProcessors();
Log.w("MediaStreamer : " + availableCores + " cores detected and configured"); Log.w("MediaStreamer : " + availableCores + " cores detected and configured");
mLc.setCpuCount(availableCores); mLc.setCpuCount(availableCores);
Transports t = mLc.getSignalingTransportPorts(); Transports t = mLc.getSignalingTransportPorts();
t.udp = -1; t.udp = -1;
t.tcp = -1; t.tcp = -1;
mLc.setSignalingTransportPorts(t); mLc.setSignalingTransportPorts(t);
try { try {
initFromConf(mLc); initFromConf(mLc);
} catch (LinphoneException e) { } catch (LinphoneException e) {
Log.w("no config ready yet"); Log.w("no config ready yet");
} }
TimerTask lTask = new TimerTask() { TimerTask lTask = new TimerTask() {
@Override @Override
public void run() { public void run() {
mLc.iterate(); mLc.iterate();
} }
}; };
if (id == 2) { if (id == 2) {
mTimer2.scheduleAtFixedRate(lTask, 0, 20); mTimer2.scheduleAtFixedRate(lTask, 0, 20);
} else { } else {
mTimer1.scheduleAtFixedRate(lTask, 0, 20); mTimer1.scheduleAtFixedRate(lTask, 0, 20);
} }
resetCameraFromPreferences(); resetCameraFromPreferences();
@ -135,7 +135,7 @@ public class LinphoneTestManager implements LinphoneListener {
Log.e(e, "Cannot start linphone"); Log.e(e, "Cannot start linphone");
} }
} }
private void resetCameraFromPreferences() { private void resetCameraFromPreferences() {
boolean useFrontCam = true; boolean useFrontCam = true;
int camId = 0; int camId = 0;
@ -146,19 +146,19 @@ public class LinphoneTestManager implements LinphoneListener {
} }
LinphoneManager.getLc().setVideoDevice(camId); LinphoneManager.getLc().setVideoDevice(camId);
} }
public void initFromConf(LinphoneCore mLc) throws LinphoneConfigException, LinphoneCoreException { public void initFromConf(LinphoneCore mLc) throws LinphoneConfigException, LinphoneCoreException {
LinphoneCoreFactory.instance().setDebugMode(true, "LinphoneTester"); LinphoneCoreFactory.instance().setDebugMode(true, "LinphoneTester");
initAccounts(mLc); initAccounts(mLc);
mLc.setVideoPolicy(true, true); mLc.setVideoPolicy(true, true);
mLc.enableVideo(true, true); mLc.enableVideo(true, true);
mLc.setUseRfc2833ForDtmfs(false); mLc.setUseRfc2833ForDtmfs(false);
mLc.setUseSipInfoForDtmfs(true); mLc.setUseSipInfoForDtmfs(true);
mLc.setNetworkReachable(true); mLc.setNetworkReachable(true);
} }
public boolean detectVideoCodec(String mime, LinphoneCore mLc) { public boolean detectVideoCodec(String mime, LinphoneCore mLc) {
@ -167,7 +167,7 @@ public class LinphoneTestManager implements LinphoneListener {
} }
return false; return false;
} }
public boolean detectAudioCodec(String mime, LinphoneCore mLc){ public boolean detectAudioCodec(String mime, LinphoneCore mLc){
for (PayloadType audioCodec : mLc.getAudioCodecs()) { for (PayloadType audioCodec : mLc.getAudioCodecs()) {
if (mime.equals(audioCodec.getMime())) return true; if (mime.equals(audioCodec.getMime())) return true;
@ -179,11 +179,11 @@ public class LinphoneTestManager implements LinphoneListener {
MediaEncryption me = MediaEncryption.None; MediaEncryption me = MediaEncryption.None;
mLc.setMediaEncryption(me); mLc.setMediaEncryption(me);
} }
private void initAccounts(LinphoneCore mLc) throws LinphoneCoreException { private void initAccounts(LinphoneCore mLc) throws LinphoneCoreException {
mLc.clearAuthInfos(); mLc.clearAuthInfos();
mLc.clearProxyConfigs(); mLc.clearProxyConfigs();
String username, password, domain; String username, password, domain;
if (mLc.equals(mLc1)) { if (mLc.equals(mLc1)) {
username = mIContext.getString(org.linphone.test.R.string.account_test_calls_login); username = mIContext.getString(org.linphone.test.R.string.account_test_calls_login);
@ -194,7 +194,7 @@ public class LinphoneTestManager implements LinphoneListener {
password = mIContext.getString(org.linphone.test.R.string.conference_account_password); password = mIContext.getString(org.linphone.test.R.string.conference_account_password);
domain = mIContext.getString(org.linphone.test.R.string.conference_account_domain); domain = mIContext.getString(org.linphone.test.R.string.conference_account_domain);
} }
LinphoneAuthInfo lAuthInfo = LinphoneCoreFactory.instance().createAuthInfo(username, password, null, domain); LinphoneAuthInfo lAuthInfo = LinphoneCoreFactory.instance().createAuthInfo(username, password, null, domain);
mLc.addAuthInfo(lAuthInfo); mLc.addAuthInfo(lAuthInfo);
String identity = "sip:" + username +"@" + domain; String identity = "sip:" + username +"@" + domain;
@ -204,7 +204,7 @@ public class LinphoneTestManager implements LinphoneListener {
LinphoneProxyConfig proxycon = mLc.createProxyConfig(identity, proxyAddr.asStringUriOnly(), proxyAddr.asStringUriOnly(), true); LinphoneProxyConfig proxycon = mLc.createProxyConfig(identity, proxyAddr.asStringUriOnly(), proxyAddr.asStringUriOnly(), true);
mLc.addProxyConfig(proxycon); mLc.addProxyConfig(proxycon);
mLc.setDefaultProxyConfig(proxycon); mLc.setDefaultProxyConfig(proxycon);
LinphoneProxyConfig lDefaultProxyConfig = mLc.getDefaultProxyConfig(); LinphoneProxyConfig lDefaultProxyConfig = mLc.getDefaultProxyConfig();
if (lDefaultProxyConfig != null) { if (lDefaultProxyConfig != null) {
//escape + //escape +
@ -217,13 +217,13 @@ public class LinphoneTestManager implements LinphoneListener {
public static synchronized final LinphoneTestManager getInstance() { public static synchronized final LinphoneTestManager getInstance() {
return instance; return instance;
} }
public static synchronized final LinphoneCore getLc(int i) { public static synchronized final LinphoneCore getLc(int i) {
if (i == 2) if (i == 2)
return getInstance().mLc2; return getInstance().mLc2;
return getInstance().mLc1; return getInstance().mLc1;
} }
public static synchronized final LinphoneCore getLc() { public static synchronized final LinphoneCore getLc() {
return getLc(1); return getLc(1);
} }
@ -261,7 +261,7 @@ public class LinphoneTestManager implements LinphoneListener {
mTimer2.cancel(); mTimer2.cancel();
mLc1.destroy(); mLc1.destroy();
mLc2.destroy(); mLc2.destroy();
} }
catch (RuntimeException e) { catch (RuntimeException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -280,7 +280,7 @@ public class LinphoneTestManager implements LinphoneListener {
@Override @Override
public void globalState(LinphoneCore lc, GlobalState state, String message) { public void globalState(LinphoneCore lc, GlobalState state, String message) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
@ -305,14 +305,14 @@ public class LinphoneTestManager implements LinphoneListener {
public void callStatsUpdated(LinphoneCore lc, LinphoneCall call, public void callStatsUpdated(LinphoneCore lc, LinphoneCall call,
LinphoneCallStats stats) { LinphoneCallStats stats) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void callEncryptionChanged(LinphoneCore lc, LinphoneCall call, public void callEncryptionChanged(LinphoneCore lc, LinphoneCall call,
boolean encrypted, String authenticationToken) { boolean encrypted, String authenticationToken) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
@ -326,20 +326,20 @@ public class LinphoneTestManager implements LinphoneListener {
public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf, public void newSubscriptionRequest(LinphoneCore lc, LinphoneFriend lf,
String url) { String url) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) { public void notifyPresenceReceived(LinphoneCore lc, LinphoneFriend lf) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void textReceived(LinphoneCore lc, LinphoneChatRoom cr, public void textReceived(LinphoneCore lc, LinphoneChatRoom cr,
LinphoneAddress from, String message) { LinphoneAddress from, String message) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
@ -361,68 +361,68 @@ public class LinphoneTestManager implements LinphoneListener {
public void notifyReceived(LinphoneCore lc, LinphoneCall call, public void notifyReceived(LinphoneCore lc, LinphoneCall call,
LinphoneAddress from, byte[] event) { LinphoneAddress from, byte[] event) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void show(LinphoneCore lc) { public void show(LinphoneCore lc) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void displayStatus(LinphoneCore lc, String message) { public void displayStatus(LinphoneCore lc, String message) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void displayMessage(LinphoneCore lc, String message) { public void displayMessage(LinphoneCore lc, String message) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void displayWarning(LinphoneCore lc, String message) { public void displayWarning(LinphoneCore lc, String message) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void transferState(LinphoneCore lc, LinphoneCall call, public void transferState(LinphoneCore lc, LinphoneCall call,
State new_call_state) { State new_call_state) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void infoReceived(LinphoneCore lc, LinphoneCall call, public void infoReceived(LinphoneCore lc, LinphoneCall call,
LinphoneInfoMessage info) { LinphoneInfoMessage info) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void subscriptionStateChanged(LinphoneCore lc, LinphoneEvent ev, public void subscriptionStateChanged(LinphoneCore lc, LinphoneEvent ev,
SubscriptionState state) { SubscriptionState state) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void notifyReceived(LinphoneCore lc, LinphoneEvent ev, public void notifyReceived(LinphoneCore lc, LinphoneEvent ev,
String eventName, LinphoneContent content) { String eventName, LinphoneContent content) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void publishStateChanged(LinphoneCore lc, LinphoneEvent ev, public void publishStateChanged(LinphoneCore lc, LinphoneEvent ev,
PublishState state) { PublishState state) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void isComposingReceived(LinphoneCore lc, LinphoneChatRoom cr) { public void isComposingReceived(LinphoneCore lc, LinphoneChatRoom cr) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
@ -438,27 +438,41 @@ public class LinphoneTestManager implements LinphoneListener {
public void authInfoRequested(LinphoneCore lc, String realm, public void authInfoRequested(LinphoneCore lc, String realm,
String username, String Domain) { String username, String Domain) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void fileTransferProgressIndication(LinphoneCore lc, public void fileTransferProgressIndication(LinphoneCore lc,
LinphoneChatMessage message, LinphoneContent content, int progress) { LinphoneChatMessage message, LinphoneContent content, int progress) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public void fileTransferRecv(LinphoneCore lc, LinphoneChatMessage message, public void fileTransferRecv(LinphoneCore lc, LinphoneChatMessage message,
LinphoneContent content, byte[] buffer, int size) { LinphoneContent content, byte[] buffer, int size) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override @Override
public int fileTransferSend(LinphoneCore lc, LinphoneChatMessage message, public int fileTransferSend(LinphoneCore lc, LinphoneChatMessage message,
LinphoneContent content, ByteBuffer buffer, int size) { LinphoneContent content, ByteBuffer buffer, int size) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return 0; return 0;
} }
@Override
public void uploadProgressIndication(LinphoneCore lc, int offset, int total) {
// TODO Auto-generated method stub
}
@Override
public void uploadStateChanged(LinphoneCore lc, LinphoneCore.LogCollectionUploadState state,
String info) {
// TODO Auto-generated method stub
}
} }