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> </application>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission>
</manifest> </manifest>

View file

@ -14,13 +14,6 @@ use_ipv6=0
register_only_when_network_is_up=0 register_only_when_network_is_up=0
default_proxy=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] [rtp]
audio_rtp_port=7076 audio_rtp_port=7076
video_rtp_port=9078 video_rtp_port=9078

View file

@ -2,31 +2,121 @@ package org.linphone;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; 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.app.Activity;
import android.os.Bundle; 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. */ /** Called when the activity is first created. */
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 @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.main); 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 { public void copyAssetsFromPackage() throws IOException {
File lFileToPlay = new File("/data/data/"+this.getPackageName()+"/files/oldphone_mono.wav"); copyIfNotExist(R.raw.oldphone_mono,RINGBACK_SND);
if (!lFileToPlay.exists()) { copyIfNotExist(R.raw.linphonerc,LINPHONE_FACTORY_RC);
FileOutputStream lOutputStream = openFileOutput ("oldphone_mono.wav", 0); }
InputStream lInputStream = getResources().openRawResource(R.raw.oldphone_mono); 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; int readByte;
while (( readByte = lInputStream.read())!=-1) { byte[] buff = new byte[8048];
lOutputStream.write(readByte); while (( readByte = lInputStream.read(buff))!=-1) {
lOutputStream.write(buff,0, readByte);
} }
lOutputStream.flush(); lOutputStream.flush();
lOutputStream.close(); lOutputStream.close();
lInputStream.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 { 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; package org.linphone.core;
import java.io.File;
import java.net.URI;
public interface LinphoneCore { public interface LinphoneCore {
/* /*
@ -51,7 +50,15 @@ 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); 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; package org.linphone.core;
@SuppressWarnings("serial")
public class LinphoneCoreException extends Exception { public class LinphoneCoreException extends Exception {
public LinphoneCoreException() { public LinphoneCoreException() {

View file

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

View file

@ -20,35 +20,36 @@ package org.linphone.core;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI;
public class LinphoneCoreImpl implements LinphoneCore {
class LinphoneCoreImpl implements LinphoneCore {
private final LinphoneCoreListener mListener; private final LinphoneCoreListener mListener;
private final long nativePtr; private final long nativePtr;
private native long newLinphoneCore(LinphoneCoreListener listener,String userConfig,String factoryConfig,Object userdata); private native long newLinphoneCore(LinphoneCoreListener listener,String userConfig,String factoryConfig,Object userdata);
private native void iterate(long nativePtr); 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 { LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object userdata) throws IOException {
mListener=listener; mListener=listener;
nativePtr = newLinphoneCore(listener,userConfig.getCanonicalPath(),factoryConfig.getCanonicalPath(),userdata); nativePtr = newLinphoneCore(listener,userConfig.getCanonicalPath(),factoryConfig.getCanonicalPath(),userdata);
} }
public void addAuthInfo(LinphoneAuthInfo info) { 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); return new LinphoneProxyConfigImpl(identity, proxy, route);
} }
public LinphoneProxyConfig getDefaultProxyConfig() { public LinphoneProxyConfig getDefaultProxyConfig() {
// TODO Auto-generated method stub throw new RuntimeException("not implemenetd yet");
return null;
} }
public void invite(String url) { public void invite(String url) {
// TODO Auto-generated method stub throw new RuntimeException("not implemenetd yet");
} }
public void iterate() { public void iterate() {
@ -56,8 +57,13 @@ public class LinphoneCoreImpl implements LinphoneCore {
} }
public void setDefaultProxyConfig(LinphoneProxyConfig proxyCfg) { 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); 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; package org.linphone.core;
import java.net.URI;
public class LinphoneProxyConfigImpl implements LinphoneProxyConfig {
final long nativePtr; class LinphoneProxyConfigImpl implements LinphoneProxyConfig {
protected LinphoneProxyConfigImpl(URI identity,URI proxy,URI route) {
nativePtr = createAndAdd(); protected final long nativePtr;
edit(nativePtr); protected LinphoneProxyConfigImpl(String identity,String proxy,String route) throws LinphoneCoreException {
setIdentity(nativePtr,identity.getScheme()+":"+identity.getHost()); nativePtr = newLinphoneProxyConfig();
done(nativePtr); setIdentity(nativePtr,identity);
if (setProxy(nativePtr,proxy)!=0) {
throw new LinphoneCoreException("Bad proxy address ["+proxy+"]");
}
} }
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
deleteNative(nativePtr); delete(nativePtr);
} }
private native long createAndAdd(); private native long newLinphoneProxyConfig();
private native long deleteNative(long ptr); private native void delete(long ptr);
private native void edit(long ptr); //private native void edit(long ptr);
private native void done(long ptr); //private native void done(long ptr);
private native void setIdentity(long ptr,String identity); 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); private native void enableRegister(long ptr,boolean value);
public void enableRegister(boolean value) { public void enableRegister(boolean value) {
edit(nativePtr); //edit(nativePtr);
enableRegister(nativePtr,value); enableRegister(nativePtr,value);
done(nativePtr); //done(nativePtr);
} }
} }