first succesfull register

This commit is contained in:
Jehan Monnier 2010-01-21 17:31:28 +01:00
parent aae69af5c3
commit 63a6a2715d
11 changed files with 167 additions and 50 deletions

View file

@ -14,5 +14,7 @@
</application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
</manifest>

View file

@ -14,13 +14,6 @@ use_ipv6=0
register_only_when_network_is_up=0
default_proxy=0
[proxy_0]
reg_proxy=sip:mty11.axtel.net
reg_identity=sip:???@mty11.axtel.net
reg_expires=3600
reg_sendregister=1
publish=0
[rtp]
audio_rtp_port=7076
video_rtp_port=9078

View file

@ -2,31 +2,121 @@ package org.linphone;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Timer;
import java.util.TimerTask;
import org.linphone.core.LinphoneAuthInfo;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneCoreListener;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LinphoneCore.GeneralState;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
public class Linphone extends Activity {
public class Linphone extends Activity implements LinphoneCoreListener {
static final String TAG="Linphone";
/** Called when the activity is first created. */
@Override
private static String LINPHONE_FACTORY_RC = "/data/data/org.linphone/files/linphonerc";
private static String LINPHONE_RC = "/data/data/org.linphone/files/.linphonerc";
private static String RINGBACK_SND = "/data/data/org.linphone/files/oldphone_mono.wav";
private LinphoneCore mLinphoneCore;
private LinphoneProxyConfig mProxyConfig;
private LinphoneAuthInfo mAuthInfo;
Timer mTimer = new Timer("Linphone scheduler");
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try {
copyAssetsFromPackage();
mLinphoneCore = LinphoneCoreFactory.instance().createLinphoneCore( this
, new File(LINPHONE_RC)
, new File(LINPHONE_FACTORY_RC)
, null);
mAuthInfo = LinphoneCoreFactory.instance().createAuthInfo("jehan", "223299");
mLinphoneCore.addAuthInfo(mAuthInfo);
mProxyConfig = mLinphoneCore.createProxyConfig("sip:jehan@sip.antisip.com", "sip:sip.antisip.com",null);
mProxyConfig.enableRegister(true);
mLinphoneCore.addtProxyConfig(mProxyConfig);
mLinphoneCore.setDefaultProxyConfig(mProxyConfig);
TimerTask lTask = new TimerTask() {
@Override
public void run() {
mLinphoneCore.iterate();
}
};
mTimer.scheduleAtFixedRate(lTask, 0, 100);
} catch (Exception e) {
Log.e(TAG,"Cannot start linphone",e);
}
}
public void copyAssetsFromPackage() throws IOException {
File lFileToPlay = new File("/data/data/"+this.getPackageName()+"/files/oldphone_mono.wav");
if (!lFileToPlay.exists()) {
FileOutputStream lOutputStream = openFileOutput ("oldphone_mono.wav", 0);
InputStream lInputStream = getResources().openRawResource(R.raw.oldphone_mono);
copyIfNotExist(R.raw.oldphone_mono,RINGBACK_SND);
copyIfNotExist(R.raw.linphonerc,LINPHONE_FACTORY_RC);
}
private void copyIfNotExist(int ressourceId,String target) throws IOException {
File lFileToCopy = new File(target);
if (!lFileToCopy.exists()) {
FileOutputStream lOutputStream = openFileOutput (lFileToCopy.getName(), 0);
InputStream lInputStream = getResources().openRawResource(ressourceId);
int readByte;
while (( readByte = lInputStream.read())!=-1) {
lOutputStream.write(readByte);
byte[] buff = new byte[8048];
while (( readByte = lInputStream.read(buff))!=-1) {
lOutputStream.write(buff,0, readByte);
}
lOutputStream.flush();
lOutputStream.close();
lInputStream.close();
}
}
}
public void authInfoRequested(LinphoneCore lc, String realm, String username) {
// TODO Auto-generated method stub
}
public void byeReceived(LinphoneCore lc, String from) {
// TODO Auto-generated method stub
}
public void displayMessage(LinphoneCore lc, String message) {
// TODO Auto-generated method stub
}
public void displayStatus(LinphoneCore lc, String message) {
// TODO Auto-generated method stub
}
public void displayWarning(LinphoneCore lc, String message) {
// TODO Auto-generated method stub
}
public void generalState(LinphoneCore lc, GeneralState state) {
// TODO Auto-generated method stub
}
public void inviteReceived(LinphoneCore lc, String from) {
// TODO Auto-generated method stub
}
public void show(LinphoneCore lc) {
// TODO Auto-generated method stub
}
}

View file

@ -21,3 +21,5 @@ package org.linphone.core;
public interface LinphoneAuthInfo {
}

View file

@ -0,0 +1,13 @@
package org.linphone.core;
class LinphoneAuthInfoImpl implements LinphoneAuthInfo {
protected final long nativePtr;
private native long newLinphoneAuthInfo(String username, String userid, String passwd, String ha1,String realm);
private native void delete(long ptr);
protected LinphoneAuthInfoImpl(String username,String password) {
nativePtr = newLinphoneAuthInfo(username,null,password,null,null);
}
protected void finalize() throws Throwable {
delete(nativePtr);
}
}

View file

@ -18,8 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.core;
import java.io.File;
import java.net.URI;
public interface LinphoneCore {
/*
@ -51,8 +50,16 @@ public interface LinphoneCore {
}
public LinphoneProxyConfig createProxyConfig(URI identity,URI proxy,URI route);
/**
* @param identity sip uri sip:jehan@linphone.org
* @param proxy sip uri (sip:linphone.org)
* @param route optionnal sip usi (sip:linphone.org)
* @return
*/
public LinphoneProxyConfig createProxyConfig(String identity,String proxy,String route) throws LinphoneCoreException;
public void addtProxyConfig(LinphoneProxyConfig proxyCfg) throws LinphoneCoreException;
public void setDefaultProxyConfig(LinphoneProxyConfig proxyCfg);
/**

View file

@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.core;
@SuppressWarnings("serial")
public class LinphoneCoreException extends Exception {
public LinphoneCoreException() {

View file

@ -19,10 +19,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
package org.linphone.core;
import java.io.File;
import java.io.IOException;
public class LinphoneCoreFactory {
static {
System.loadLibrary("liblinphone");
System.loadLibrary("linphone");
}
static LinphoneCoreFactory theLinphoneCoreFactory = new LinphoneCoreFactory();
@ -31,11 +32,11 @@ public class LinphoneCoreFactory {
return theLinphoneCoreFactory;
}
public LinphoneAuthInfo createAuthInfo(String username,String password) {
throw new RuntimeException("Not Implemented yet");
return new LinphoneAuthInfoImpl(username,password) ;
}
public LinphoneCore createLinphoneCore(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) {
throw new RuntimeException("Not Implemented yet");
public LinphoneCore createLinphoneCore(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException {
return new LinphoneCoreImpl(listener,userConfig,factoryConfig,userdata);
}

View file

@ -20,35 +20,36 @@ package org.linphone.core;
import java.io.File;
import java.io.IOException;
import java.net.URI;
public class LinphoneCoreImpl implements LinphoneCore {
class LinphoneCoreImpl implements LinphoneCore {
private final LinphoneCoreListener mListener;
private final long nativePtr;
private native long newLinphoneCore(LinphoneCoreListener listener,String userConfig,String factoryConfig,Object userdata);
private native void iterate(long nativePtr);
private native void setDefaultProxyConfig(long nativePtr,long proxyCfgNativePtr);
private native int addProxyConfig(long nativePtr,long proxyCfgNativePtr);
private native void addAuthInfo(long nativePtr,long authInfoNativePtr);
LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException {
mListener=listener;
nativePtr = newLinphoneCore(listener,userConfig.getCanonicalPath(),factoryConfig.getCanonicalPath(),userdata);
}
public void addAuthInfo(LinphoneAuthInfo info) {
// TODO Auto-generated method stub
addAuthInfo(nativePtr,((LinphoneAuthInfoImpl)info).nativePtr);
}
public LinphoneProxyConfig createProxyConfig(URI identity, URI proxy,URI route) {
public LinphoneProxyConfig createProxyConfig(String identity, String proxy,String route) throws LinphoneCoreException {
return new LinphoneProxyConfigImpl(identity, proxy, route);
}
public LinphoneProxyConfig getDefaultProxyConfig() {
// TODO Auto-generated method stub
return null;
throw new RuntimeException("not implemenetd yet");
}
public void invite(String url) {
// TODO Auto-generated method stub
throw new RuntimeException("not implemenetd yet");
}
public void iterate() {
@ -56,8 +57,13 @@ public class LinphoneCoreImpl implements LinphoneCore {
}
public void setDefaultProxyConfig(LinphoneProxyConfig proxyCfg) {
// TODO Auto-generated method stub
setDefaultProxyConfig(nativePtr,((LinphoneProxyConfigImpl)proxyCfg).nativePtr);
}
public void addtProxyConfig(LinphoneProxyConfig proxyCfg) throws LinphoneCoreException{
if (addProxyConfig(nativePtr,((LinphoneProxyConfigImpl)proxyCfg).nativePtr) !=0) {
throw new LinphoneCoreException("bad proxy config");
}
}
}

View file

@ -22,4 +22,5 @@ public interface LinphoneProxyConfig {
void enableRegister(boolean value);
}

View file

@ -18,37 +18,38 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.linphone.core;
import java.net.URI;
public class LinphoneProxyConfigImpl implements LinphoneProxyConfig {
final long nativePtr;
protected LinphoneProxyConfigImpl(URI identity,URI proxy,URI route) {
nativePtr = createAndAdd();
edit(nativePtr);
setIdentity(nativePtr,identity.getScheme()+":"+identity.getHost());
done(nativePtr);
class LinphoneProxyConfigImpl implements LinphoneProxyConfig {
protected final long nativePtr;
protected LinphoneProxyConfigImpl(String identity,String proxy,String route) throws LinphoneCoreException {
nativePtr = newLinphoneProxyConfig();
setIdentity(nativePtr,identity);
if (setProxy(nativePtr,proxy)!=0) {
throw new LinphoneCoreException("Bad proxy address ["+proxy+"]");
}
}
protected void finalize() throws Throwable {
deleteNative(nativePtr);
delete(nativePtr);
}
private native long createAndAdd();
private native long deleteNative(long ptr);
private native long newLinphoneProxyConfig();
private native void delete(long ptr);
private native void edit(long ptr);
private native void done(long ptr);
//private native void edit(long ptr);
//private native void done(long ptr);
private native void setIdentity(long ptr,String identity);
/*private native void setProxy(long ptr,String identity);*/
private native int setProxy(long ptr,String proxy);
private native void enableRegister(long ptr,boolean value);
public void enableRegister(boolean value) {
edit(nativePtr);
//edit(nativePtr);
enableRegister(nativePtr,value);
done(nativePtr);
//done(nativePtr);
}
}