]> sjero.net Git - linphone/blob - java/impl/org/linphone/core/LinphoneCoreImpl.java
64db42ee325ed8b7e462f212ed7c0ecdbd8e1c34
[linphone] / java / impl / org / linphone / core / LinphoneCoreImpl.java
1 /*
2 LinphoneCoreImpl.java
3 Copyright (C) 2010  Belledonne Communications, Grenoble, France
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19 package org.linphone.core;
20
21 import static android.media.AudioManager.MODE_IN_CALL;
22 import static android.media.AudioManager.MODE_RINGTONE;
23 import android.content.Context;
24 import android.media.AudioManager;
25
26 import java.io.File;
27 import java.io.IOException;
28
29 import org.linphone.core.LinphoneCall.State;
30 import org.linphone.mediastream.video.capture.hwconf.Hacks;
31
32
33 class LinphoneCoreImpl implements LinphoneCore {
34
35         private final  LinphoneCoreListener mListener; //to make sure to keep a reference on this object
36         private long nativePtr = 0;
37         private Context mContext = null;
38         private AudioManager mAudioManager = null;
39         private boolean mSpeakerEnabled = false;
40         private native long newLinphoneCore(LinphoneCoreListener listener,String userConfig,String factoryConfig,Object  userdata);
41         private native void iterate(long nativePtr);
42         private native long getDefaultProxyConfig(long nativePtr);
43
44         private native void setDefaultProxyConfig(long nativePtr,long proxyCfgNativePtr);
45         private native int addProxyConfig(LinphoneProxyConfig jprtoxyCfg,long nativePtr,long proxyCfgNativePtr);
46         private native void clearAuthInfos(long nativePtr);
47         
48         private native void clearProxyConfigs(long nativePtr);
49         private native void addAuthInfo(long nativePtr,long authInfoNativePtr);
50         private native Object invite(long nativePtr,String uri);
51         private native void terminateCall(long nativePtr, long call);
52         private native long getRemoteAddress(long nativePtr);
53         private native boolean  isInCall(long nativePtr);
54         private native boolean isInComingInvitePending(long nativePtr);
55         private native void acceptCall(long nativePtr, long call);
56         private native long getCallLog(long nativePtr,int position);
57         private native int getNumberOfCallLogs(long nativePtr);
58         private native void delete(long nativePtr);
59         private native void setNetworkStateReachable(long nativePtr,boolean isReachable);
60         private native boolean isNetworkStateReachable(long nativePtr);
61         private native void setPlaybackGain(long nativeptr, float gain);
62         private native float getPlaybackGain(long nativeptr);
63         private native void muteMic(long nativePtr,boolean isMuted);
64         private native long interpretUrl(long nativePtr,String destination);
65         private native Object inviteAddress(long nativePtr,long to);
66         private native Object inviteAddressWithParams(long nativePtrLc,long to, long nativePtrParam);
67         private native void sendDtmf(long nativePtr,char dtmf);
68         private native void clearCallLogs(long nativePtr);
69         private native boolean isMicMuted(long nativePtr);
70         private native long findPayloadType(long nativePtr, String mime, int clockRate, int channels);
71         private native int enablePayloadType(long nativePtr, long payloadType,  boolean enable);
72         private native void enableEchoCancellation(long nativePtr,boolean enable);
73         private native boolean isEchoCancellationEnabled(long nativePtr);
74         private native Object getCurrentCall(long nativePtr) ;
75         private native void playDtmf(long nativePtr,char dtmf,int duration);
76         private native void stopDtmf(long nativePtr);
77         private native void setVideoWindowId(long nativePtr, Object wid);
78         private native void setPreviewWindowId(long nativePtr, Object wid);
79         private native void setDeviceRotation(long nativePtr, int rotation);
80         private native void addFriend(long nativePtr,long friend);
81         private native void setPresenceInfo(long nativePtr,int minute_away, String alternative_contact,int status);
82         private native long createChatRoom(long nativePtr,String to);
83         private native void enableVideo(long nativePtr,boolean vcap_enabled,boolean display_enabled);
84         private native boolean isVideoEnabled(long nativePtr);
85         private native void setFirewallPolicy(long nativePtr, int enum_value);
86         private native int getFirewallPolicy(long nativePtr);
87         private native void setStunServer(long nativePtr, String stun_server);
88         private native String getStunServer(long nativePtr);
89         private native long createDefaultCallParams(long nativePtr);
90         private native int updateCall(long ptrLc, long ptrCall, long ptrParams);
91         private native void setUploadBandwidth(long nativePtr, int bw);
92         private native void setDownloadBandwidth(long nativePtr, int bw);
93         private native void setPreferredVideoSize(long nativePtr, int width, int heigth);
94         private native int[] getPreferredVideoSize(long nativePtr);
95         private native void setRing(long nativePtr, String path);
96         private native String getRing(long nativePtr);
97         private native void setRootCA(long nativePtr, String path);
98         private native long[] listVideoPayloadTypes(long nativePtr);
99         private native long[] getProxyConfigList(long nativePtr);
100         private native long[] listAudioPayloadTypes(long nativePtr);
101         private native void enableKeepAlive(long nativePtr,boolean enable);
102         private native boolean isKeepAliveEnabled(long nativePtr);
103         private native int startEchoCalibration(long nativePtr,Object data);
104         private native int getSignalingTransportPort(long nativePtr, int code);
105         private native void setSignalingTransportPorts(long nativePtr, int udp, int tcp, int tls);
106         private native void enableIpv6(long nativePtr,boolean enable);
107         private native int pauseCall(long nativePtr, long callPtr);
108         private native int pauseAllCalls(long nativePtr);
109         private native int resumeCall(long nativePtr, long callPtr);
110         private native void setUploadPtime(long nativePtr, int ptime);
111         private native void setDownloadPtime(long nativePtr, int ptime);
112         private native void setZrtpSecretsCache(long nativePtr, String file);
113         private native void enableEchoLimiter(long nativePtr2, boolean val);
114         private native int setVideoDevice(long nativePtr2, int id);
115         private native int getVideoDevice(long nativePtr2);
116         private native int getMediaEncryption(long nativePtr);
117         private native void setMediaEncryption(long nativePtr, int menc);
118         private native boolean isMediaEncryptionMandatory(long nativePtr);
119         private native void setMediaEncryptionMandatory(long nativePtr, boolean yesno);
120         private native void removeCallLog(long nativePtr, long callLogPtr);
121         private native int getMissedCallsCount(long nativePtr);
122         private native void resetMissedCallsCount(long nativePtr);
123         private native String getVersion(long nativePtr);
124         private native void setAudioPort(long nativePtr, int port);
125         private native void setVideoPort(long nativePtr, int port);
126         private native void setAudioPortRange(long nativePtr, int minPort, int maxPort);
127         private native void setVideoPortRange(long nativePtr, int minPort, int maxPort);
128         private native void setIncomingTimeout(long nativePtr, int timeout);
129         private native void setInCallTimeout(long nativePtr, int timeout);
130         private native void setPrimaryContact(long nativePtr, String displayName, String username);
131         
132         LinphoneCoreImpl(LinphoneCoreListener listener, File userConfig,File factoryConfig,Object  userdata) throws IOException {
133                 mListener=listener;
134                 nativePtr = newLinphoneCore(listener,userConfig.getCanonicalPath(),factoryConfig.getCanonicalPath(),userdata);
135         }
136         LinphoneCoreImpl(LinphoneCoreListener listener) throws IOException {
137                 mListener=listener;
138                 nativePtr = newLinphoneCore(listener,null,null,null);
139         }
140         
141         protected void finalize() throws Throwable {
142                 
143         }
144
145         private boolean contextInitialized() {
146                 if (mContext == null) {
147                         Log.e("Context of LinphoneCore has not been initialized, call setContext() after creating LinphoneCore.");
148                         return false;
149                 }
150                 return true;
151         }
152         public void setContext(Object context) {
153                 mContext = (Context)context;
154                 mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
155         }
156
157         public synchronized void addAuthInfo(LinphoneAuthInfo info) {
158                 isValid();
159                 addAuthInfo(nativePtr,((LinphoneAuthInfoImpl)info).nativePtr);
160         }
161
162         public synchronized LinphoneProxyConfig getDefaultProxyConfig() {
163                 isValid();
164                 long lNativePtr = getDefaultProxyConfig(nativePtr);
165                 if (lNativePtr!=0) {
166                         return new LinphoneProxyConfigImpl(lNativePtr); 
167                 } else {
168                         return null;
169                 }
170         }
171
172         public synchronized LinphoneCall invite(String uri) {
173                 isValid();
174                 return (LinphoneCall)invite(nativePtr,uri);
175         }
176
177         public synchronized void iterate() {
178                 isValid();
179                 iterate(nativePtr);
180         }
181
182         public synchronized void setDefaultProxyConfig(LinphoneProxyConfig proxyCfg) {
183                 isValid();
184                 setDefaultProxyConfig(nativePtr,((LinphoneProxyConfigImpl)proxyCfg).nativePtr);
185         }
186         public synchronized void addProxyConfig(LinphoneProxyConfig proxyCfg) throws LinphoneCoreException{
187                 isValid();
188                 if (addProxyConfig(proxyCfg,nativePtr,((LinphoneProxyConfigImpl)proxyCfg).nativePtr) !=0) {
189                         throw new LinphoneCoreException("bad proxy config");
190                 }
191         }
192         public synchronized void clearAuthInfos() {
193                 isValid();
194                 clearAuthInfos(nativePtr);
195                 
196         }
197         public synchronized void clearProxyConfigs() {
198                 isValid();
199                 clearProxyConfigs(nativePtr);
200         }
201         public synchronized void terminateCall(LinphoneCall aCall) {
202                 isValid();
203                 if (aCall!=null)terminateCall(nativePtr,((LinphoneCallImpl)aCall).nativePtr);
204         }
205         public synchronized LinphoneAddress getRemoteAddress() {
206                 isValid();
207                 long ptr = getRemoteAddress(nativePtr);
208                 if (ptr==0) {
209                         return null;
210                 } else {
211                         return new LinphoneAddressImpl(ptr);
212                 }
213         }
214         public synchronized  boolean isIncall() {
215                 isValid();
216                 return isInCall(nativePtr);
217         }
218         public synchronized boolean isInComingInvitePending() {
219                 isValid();
220                 return isInComingInvitePending(nativePtr);
221         }
222         public synchronized void acceptCall(LinphoneCall aCall) {
223                 isValid();
224                 acceptCall(nativePtr,((LinphoneCallImpl)aCall).nativePtr);
225         }
226         public synchronized LinphoneCallLog[] getCallLogs() {
227                 isValid();
228                 LinphoneCallLog[] logs = new LinphoneCallLog[getNumberOfCallLogs(nativePtr)]; 
229                 for (int i=0;i < getNumberOfCallLogs(nativePtr);i++) {
230                         logs[i] = new LinphoneCallLogImpl(getCallLog(nativePtr, i));
231                 }
232                 return logs;
233         }
234         public synchronized void destroy() {
235                 isValid();
236                 delete(nativePtr);
237                 nativePtr = 0;
238         }
239         
240         private void isValid() {
241                 if (nativePtr == 0) {
242                         throw new RuntimeException("object already destroyed");
243                 }
244         }
245         public synchronized void setNetworkReachable(boolean isReachable) {
246                 setNetworkStateReachable(nativePtr,isReachable);
247         }
248         public synchronized void setPlaybackGain(float gain) {
249                 setPlaybackGain(nativePtr,gain);
250                 
251         }
252         public synchronized float getPlaybackGain() {
253                 return getPlaybackGain(nativePtr);
254         }
255         public synchronized void muteMic(boolean isMuted) {
256                 muteMic(nativePtr,isMuted);
257         }
258
259         public synchronized LinphoneAddress interpretUrl(String destination) throws LinphoneCoreException {
260                 long lAddress = interpretUrl(nativePtr,destination);
261                 if (lAddress != 0) {
262                         return new LinphoneAddressImpl(lAddress,true);
263                 } else {
264                         throw new LinphoneCoreException("Cannot interpret ["+destination+"]");
265                 }
266         }
267         public synchronized LinphoneCall invite(LinphoneAddress to) throws LinphoneCoreException { 
268                 LinphoneCall call = (LinphoneCall)inviteAddress(nativePtr,((LinphoneAddressImpl)to).nativePtr);
269                 if (call!=null) {
270                         return call;
271                 } else {
272                         throw new LinphoneCoreException("Unable to invite address " + to.asString());
273                 }
274         }
275
276         public synchronized void sendDtmf(char number) {
277                 sendDtmf(nativePtr,number);
278         }
279         public synchronized void clearCallLogs() {
280                 clearCallLogs(nativePtr);
281         }
282         public synchronized boolean isMicMuted() {
283                 return isMicMuted(nativePtr);
284         }
285         public synchronized PayloadType findPayloadType(String mime, int clockRate, int channels) {
286                 isValid();
287                 long playLoadType = findPayloadType(nativePtr, mime, clockRate, channels);
288                 if (playLoadType == 0) {
289                         return null;
290                 } else {
291                         return new PayloadTypeImpl(playLoadType);
292                 }
293         }
294         public synchronized void enablePayloadType(PayloadType pt, boolean enable)
295                         throws LinphoneCoreException {
296                 isValid();
297                 if (enablePayloadType(nativePtr,((PayloadTypeImpl)pt).nativePtr,enable) != 0) {
298                         throw new LinphoneCoreException("cannot enable payload type ["+pt+"]");
299                 }
300                 
301         }
302         public synchronized void enableEchoCancellation(boolean enable) {
303                 isValid();
304                 enableEchoCancellation(nativePtr, enable);
305         }
306         public synchronized boolean isEchoCancellationEnabled() {
307                 isValid();
308                 return isEchoCancellationEnabled(nativePtr);
309                 
310         }
311
312         public synchronized LinphoneCall getCurrentCall() {
313                 isValid();
314                 return (LinphoneCall)getCurrentCall(nativePtr);
315         }
316         
317         public int getPlayLevel() {
318                 // TODO Auto-generated method stub
319                 return 0;
320         }
321         public void setPlayLevel(int level) {
322                 // TODO Auto-generated method stub
323                 
324         }
325
326         private void applyAudioHacks() {
327                 if (Hacks.needGalaxySAudioHack()) {
328                         /* The microphone gain is way too high on the Galaxy S so correct it here. */
329                         setMicrophoneGain(-9.0f);
330                 }
331         }
332         private void setAudioModeIncallForGalaxyS() {
333                 if (!contextInitialized()) return;
334                 mAudioManager.setMode(MODE_IN_CALL);
335         }
336         public void routeAudioToSpeakerHelper(boolean speakerOn) {
337                 if (!contextInitialized()) return;
338                 if (Hacks.needGalaxySAudioHack())
339                         setAudioModeIncallForGalaxyS();
340                 mAudioManager.setSpeakerphoneOn(speakerOn);
341         }
342         private native void forceSpeakerState(long nativePtr, boolean speakerOn);
343         public void enableSpeaker(boolean value) {
344                 final LinphoneCall call = getCurrentCall();
345                 mSpeakerEnabled = value;
346                 applyAudioHacks();
347                 if (call != null && call.getState() == State.StreamsRunning && Hacks.needGalaxySAudioHack()) {
348                         Log.d("Hack to have speaker=", value, " while on call");
349                         forceSpeakerState(nativePtr, value);
350                 } else {
351                         routeAudioToSpeakerHelper(value);
352                 }
353         }
354         public boolean isSpeakerEnabled() {
355                 return mSpeakerEnabled;
356         }
357         public synchronized void playDtmf(char number, int duration) {
358                 playDtmf(nativePtr,number, duration);
359                 
360         }
361         public synchronized void stopDtmf() {
362                 stopDtmf(nativePtr);
363         }
364         
365         public synchronized void addFriend(LinphoneFriend lf) throws LinphoneCoreException {
366                 addFriend(nativePtr,((LinphoneFriendImpl)lf).nativePtr);
367                 
368         }
369         public synchronized void setPresenceInfo(int minute_away, String alternative_contact,
370                         OnlineStatus status) {
371                 setPresenceInfo(nativePtr,minute_away,alternative_contact,status.mValue);
372                 
373         }
374         public synchronized LinphoneChatRoom createChatRoom(String to) {
375                 return new LinphoneChatRoomImpl(createChatRoom(nativePtr,to));
376         }
377         public synchronized void setPreviewWindow(Object w) {
378                 setPreviewWindowId(nativePtr,w);
379         }
380         public synchronized void setVideoWindow(Object w) {
381                 setVideoWindowId(nativePtr, w);
382         }
383         public synchronized void setDeviceRotation(int rotation) {
384                 setDeviceRotation(nativePtr, rotation);
385         }
386         
387         public synchronized void enableVideo(boolean vcap_enabled, boolean display_enabled) {
388                 enableVideo(nativePtr,vcap_enabled, display_enabled);
389         }
390         public synchronized boolean isVideoEnabled() {
391                 return isVideoEnabled(nativePtr);
392         }
393         public synchronized FirewallPolicy getFirewallPolicy() {
394                 return FirewallPolicy.fromInt(getFirewallPolicy(nativePtr));
395         }
396         public synchronized String getStunServer() {
397                 return getStunServer(nativePtr);
398         }
399         public synchronized void setFirewallPolicy(FirewallPolicy pol) {
400                 setFirewallPolicy(nativePtr,pol.value());
401         }
402         public synchronized void setStunServer(String stunServer) {
403                 setStunServer(nativePtr,stunServer);
404         }
405         
406         public synchronized LinphoneCallParams createDefaultCallParameters() {
407                 return new LinphoneCallParamsImpl(createDefaultCallParams(nativePtr));
408         }
409         
410         public synchronized LinphoneCall inviteAddressWithParams(LinphoneAddress to, LinphoneCallParams params) throws LinphoneCoreException {
411                 long ptrDestination = ((LinphoneAddressImpl)to).nativePtr;
412                 long ptrParams =((LinphoneCallParamsImpl)params).nativePtr;
413                 
414                 LinphoneCall call = (LinphoneCall)inviteAddressWithParams(nativePtr, ptrDestination, ptrParams);
415                 if (call!=null) {
416                         return call;
417                 } else {
418                         throw new LinphoneCoreException("Unable to invite with params " + to.asString());
419                 }
420         }
421
422         public synchronized int updateCall(LinphoneCall call, LinphoneCallParams params) {
423                 long ptrCall = ((LinphoneCallImpl) call).nativePtr;
424                 long ptrParams = params!=null ? ((LinphoneCallParamsImpl)params).nativePtr : 0;
425
426                 return updateCall(nativePtr, ptrCall, ptrParams);
427         }
428         public synchronized void setUploadBandwidth(int bw) {
429                 setUploadBandwidth(nativePtr, bw);
430         }
431
432         public synchronized void setDownloadBandwidth(int bw) {
433                 setDownloadBandwidth(nativePtr, bw);
434         }
435
436         public synchronized void setPreferredVideoSize(VideoSize vSize) {
437                 setPreferredVideoSize(nativePtr, vSize.width, vSize.height);
438         }
439
440         public synchronized VideoSize getPreferredVideoSize() {
441                 int[] nativeSize = getPreferredVideoSize(nativePtr);
442
443                 VideoSize vSize = new VideoSize();
444                 vSize.width = nativeSize[0];
445                 vSize.height = nativeSize[1];
446                 return vSize;
447         }
448         public synchronized void setRing(String path) {
449                 setRing(nativePtr, path);
450         }
451         public synchronized String getRing() {
452                 return getRing(nativePtr);
453         }
454         
455         public synchronized void setRootCA(String path) {
456                 setRootCA(nativePtr, path);
457         }
458         
459         public synchronized LinphoneProxyConfig[] getProxyConfigList() {
460                 long[] typesPtr = getProxyConfigList(nativePtr);
461                 if (typesPtr == null) return null;
462                 
463                 LinphoneProxyConfig[] proxies = new LinphoneProxyConfig[typesPtr.length];
464
465                 for (int i=0; i < proxies.length; i++) {
466                         proxies[i] = new LinphoneProxyConfigImpl(typesPtr[i]);
467                 }
468
469                 return proxies;
470         }
471         
472         public synchronized PayloadType[] getVideoCodecs() {
473                 long[] typesPtr = listVideoPayloadTypes(nativePtr);
474                 if (typesPtr == null) return null;
475                 
476                 PayloadType[] codecs = new PayloadType[typesPtr.length];
477
478                 for (int i=0; i < codecs.length; i++) {
479                         codecs[i] = new PayloadTypeImpl(typesPtr[i]);
480                 }
481
482                 return codecs;
483         }
484         public synchronized PayloadType[] getAudioCodecs() {
485                 long[] typesPtr = listAudioPayloadTypes(nativePtr);
486                 if (typesPtr == null) return null;
487                 
488                 PayloadType[] codecs = new PayloadType[typesPtr.length];
489
490                 for (int i=0; i < codecs.length; i++) {
491                         codecs[i] = new PayloadTypeImpl(typesPtr[i]);
492                 }
493
494                 return codecs;
495         }
496         public synchronized boolean isNetworkReachable() {
497                 return isNetworkStateReachable(nativePtr);
498         }
499         
500         public synchronized void enableKeepAlive(boolean enable) {
501                 enableKeepAlive(nativePtr,enable);
502                 
503         }
504         public synchronized boolean isKeepAliveEnabled() {
505                 return isKeepAliveEnabled(nativePtr);
506         }
507         public synchronized void startEchoCalibration(Object data) throws LinphoneCoreException {
508                 startEchoCalibration(nativePtr, data);
509         }
510         
511         public synchronized Transports getSignalingTransportPorts() {
512                 Transports transports = new Transports();
513                 transports.udp = getSignalingTransportPort(nativePtr, 0);
514                 transports.tcp = getSignalingTransportPort(nativePtr, 1);
515                 transports.tls = getSignalingTransportPort(nativePtr, 3);
516                 // See C struct LCSipTransports in linphonecore.h
517                 // Code is the index in the structure
518                 return transports;
519         }
520         public synchronized void setSignalingTransportPorts(Transports transports) {
521                 setSignalingTransportPorts(nativePtr, transports.udp, transports.tcp, transports.tls);
522         }
523
524         public synchronized void enableIpv6(boolean enable) {
525                 enableIpv6(nativePtr,enable);
526         }
527         public synchronized void adjustSoftwareVolume(int i) {
528                 //deprecated, does the same as setPlaybackGain().
529         }
530
531         public synchronized boolean pauseCall(LinphoneCall call) {
532                 return 0 == pauseCall(nativePtr, ((LinphoneCallImpl) call).nativePtr);
533         }
534         public synchronized boolean resumeCall(LinphoneCall call) {
535                 return 0 == resumeCall(nativePtr, ((LinphoneCallImpl) call).nativePtr);
536         }
537         public synchronized boolean pauseAllCalls() {
538                 return 0 == pauseAllCalls(nativePtr);
539         }
540         public synchronized void setDownloadPtime(int ptime) {
541                 setDownloadPtime(nativePtr,ptime);
542                 
543         }
544         public synchronized void setUploadPtime(int ptime) {
545                 setUploadPtime(nativePtr,ptime);
546         }
547
548         public synchronized void setZrtpSecretsCache(String file) {
549                 setZrtpSecretsCache(nativePtr,file);
550         }
551         public synchronized void enableEchoLimiter(boolean val) {
552                 enableEchoLimiter(nativePtr,val);
553         }
554         public void setVideoDevice(int id) {
555                 Log.i("Setting camera id :", id);
556                 if (setVideoDevice(nativePtr, id) != 0) {
557                         Log.e("Failed to set video device to id:", id);
558                 }
559         }
560         public int getVideoDevice() {
561                 return getVideoDevice(nativePtr);
562         }
563
564
565         private native void leaveConference(long nativePtr);    
566         public synchronized void leaveConference() {
567                 leaveConference(nativePtr);
568         }
569
570         private native boolean enterConference(long nativePtr); 
571         public synchronized boolean enterConference() {
572                 return enterConference(nativePtr);
573         }
574
575         private native boolean isInConference(long nativePtr);
576         public synchronized boolean isInConference() {
577                 return isInConference(nativePtr);
578         }
579
580         private native void terminateConference(long nativePtr);
581         public synchronized void terminateConference() {
582                 terminateConference(nativePtr);
583         }
584         private native int getConferenceSize(long nativePtr);
585         public synchronized int getConferenceSize() {
586                 return getConferenceSize(nativePtr);
587         }
588         private native int getCallsNb(long nativePtr);
589         public synchronized int getCallsNb() {
590                 return getCallsNb(nativePtr);
591         }
592         private native void terminateAllCalls(long nativePtr);
593         public synchronized void terminateAllCalls() {
594                 terminateAllCalls(nativePtr);
595         }
596         private native Object getCall(long nativePtr, int position);
597         public synchronized LinphoneCall[] getCalls() {
598                 int size = getCallsNb(nativePtr);
599                 LinphoneCall[] calls = new LinphoneCall[size];
600                 for (int i=0; i < size; i++) {
601                         calls[i]=((LinphoneCall)getCall(nativePtr, i));
602                 }
603                 return calls;
604         }
605         private native void addAllToConference(long nativePtr);
606         public synchronized void addAllToConference() {
607                 addAllToConference(nativePtr);
608                 
609         }
610         private native void addToConference(long nativePtr, long nativePtrLcall);
611         public synchronized void addToConference(LinphoneCall call) {
612                 addToConference(nativePtr, getCallPtr(call));
613                 
614         }
615         private native void removeFromConference(long nativePtr, long nativeCallPtr);
616         public synchronized void removeFromConference(LinphoneCall call) {
617                 removeFromConference(nativePtr,getCallPtr(call));
618         }
619
620         private long getCallPtr(LinphoneCall call) {
621                 return ((LinphoneCallImpl)call).nativePtr;
622         }
623         
624         private long getCallParamsPtr(LinphoneCallParams callParams) {
625                 return ((LinphoneCallParamsImpl)callParams).nativePtr;
626         }
627
628         private native int transferCall(long nativePtr, long callPtr, String referTo);
629         public synchronized void transferCall(LinphoneCall call, String referTo) {
630                 transferCall(nativePtr, getCallPtr(call), referTo);
631         }
632
633         private native int transferCallToAnother(long nativePtr, long callPtr, long destPtr);
634         public synchronized void transferCallToAnother(LinphoneCall call, LinphoneCall dest) {
635                 transferCallToAnother(nativePtr, getCallPtr(call), getCallPtr(dest));
636         }
637
638         private native Object findCallFromUri(long nativePtr, String uri);
639         @Override
640         public synchronized LinphoneCall findCallFromUri(String uri) {
641                 return (LinphoneCall) findCallFromUri(nativePtr, uri);
642         }
643
644         public synchronized MediaEncryption getMediaEncryption() {
645                 return MediaEncryption.fromInt(getMediaEncryption(nativePtr));
646         }
647         public synchronized boolean isMediaEncryptionMandatory() {
648                 return isMediaEncryptionMandatory(nativePtr);
649         }
650         public synchronized void setMediaEncryption(MediaEncryption menc) {
651                 setMediaEncryption(nativePtr, menc.mValue);     
652         }
653         public synchronized void setMediaEncryptionMandatory(boolean yesno) {
654                 setMediaEncryptionMandatory(nativePtr, yesno);
655         }
656
657         private native int getMaxCalls(long nativePtr);
658         public synchronized int getMaxCalls() {
659                 return getMaxCalls(nativePtr);
660         }
661         @Override
662         public boolean isMyself(String uri) {
663                 LinphoneProxyConfig lpc = getDefaultProxyConfig();
664                 if (lpc == null) return false;
665                 return uri.equals(lpc.getIdentity());
666         }
667
668         private native boolean soundResourcesLocked(long nativePtr);
669         public synchronized boolean soundResourcesLocked() {
670                 return soundResourcesLocked(nativePtr);
671         }
672
673         private native void setMaxCalls(long nativePtr, int max);
674         @Override
675         public synchronized void setMaxCalls(int max) {
676                 setMaxCalls(nativePtr, max);
677         }
678         private native boolean isEchoLimiterEnabled(long nativePtr);
679         @Override
680         public synchronized boolean isEchoLimiterEnabled() {
681                 return isEchoLimiterEnabled(nativePtr);
682         }
683         private native boolean mediaEncryptionSupported(long nativePtr, int menc);
684         @Override
685         public synchronized boolean mediaEncryptionSupported(MediaEncryption menc) {
686                 return mediaEncryptionSupported(nativePtr,menc.mValue);
687         }
688
689         private native void setPlayFile(long nativePtr, String path);
690
691         @Override
692         public synchronized void setPlayFile(String path) {
693                 setPlayFile(nativePtr, path);
694         }
695
696
697         private native void tunnelAddServerAndMirror(long nativePtr, String host, int port, int mirror, int ms);
698         @Override
699         public synchronized void tunnelAddServerAndMirror(String host, int port, int mirror, int ms) {
700                 tunnelAddServerAndMirror(nativePtr, host, port, mirror, ms);
701         }
702
703         private native void tunnelAutoDetect(long nativePtr);
704         @Override
705         public synchronized void tunnelAutoDetect() {
706                 tunnelAutoDetect(nativePtr);
707         }
708
709         private native void tunnelCleanServers(long nativePtr);
710         @Override
711         public synchronized void tunnelCleanServers() {
712                 tunnelCleanServers(nativePtr);
713         }
714
715         private native void tunnelEnable(long nativePtr, boolean enable);
716         @Override
717         public synchronized void tunnelEnable(boolean enable) {
718                 tunnelEnable(nativePtr, enable);
719         }
720
721         @Override
722         public native boolean isTunnelAvailable();
723         
724         private native void acceptCallWithParams(long nativePtr, long aCall,
725                         long params);
726         @Override
727         public synchronized void acceptCallWithParams(LinphoneCall aCall,
728                         LinphoneCallParams params) throws LinphoneCoreException {
729                 acceptCallWithParams(nativePtr, getCallPtr(aCall), getCallParamsPtr(params));
730         }
731         
732         private native void acceptCallUpdate(long nativePtr, long aCall, long params);
733         @Override
734         public synchronized void acceptCallUpdate(LinphoneCall aCall, LinphoneCallParams params)
735                         throws LinphoneCoreException {
736                 acceptCallUpdate(nativePtr, getCallPtr(aCall), getCallParamsPtr(params));               
737         }
738         
739         private native void deferCallUpdate(long nativePtr, long aCall);
740         @Override
741         public synchronized void deferCallUpdate(LinphoneCall aCall)
742                         throws LinphoneCoreException {
743                 deferCallUpdate(nativePtr, getCallPtr(aCall));
744         }
745
746         public synchronized void startRinging() {
747                 if (!contextInitialized()) return;
748                 if (Hacks.needGalaxySAudioHack()) {
749                         mAudioManager.setMode(MODE_RINGTONE);
750                 }
751         }
752         
753         private native void setVideoPolicy(long nativePtr, boolean autoInitiate, boolean autoAccept);
754         public synchronized void setVideoPolicy(boolean autoInitiate, boolean autoAccept) {
755                 setVideoPolicy(nativePtr, autoInitiate, autoAccept);
756         }
757         private native void setStaticPicture(long nativePtr, String path);
758         public void setStaticPicture(String path) {
759                 setStaticPicture(nativePtr, path);
760         }
761         private native void setUserAgent(long nativePtr, String name, String version);
762         @Override
763         public void setUserAgent(String name, String version) {
764                 setUserAgent(nativePtr,name,version);
765         }
766
767         private native void setCpuCountNative(int count);
768         public void setCpuCount(int count)
769         {
770                 setCpuCountNative(count);
771         }
772         
773         public int getMissedCallsCount() {
774                 return getMissedCallsCount(nativePtr);
775         }
776         
777         public void removeCallLog(LinphoneCallLog log) {
778                 removeCallLog(nativePtr, ((LinphoneCallLogImpl) log).getNativePtr());
779         }
780
781         public void resetMissedCallsCount() {
782                 resetMissedCallsCount(nativePtr);
783         }
784         
785         private native void tunnelSetHttpProxy(long nativePtr, String proxy_host, int port,
786                         String username, String password);
787         @Override
788         public void tunnelSetHttpProxy(String proxy_host, int port,
789                         String username, String password) {
790                 tunnelSetHttpProxy(nativePtr, proxy_host, port, username, password);
791         }
792         
793         private native void refreshRegisters(long nativePtr);
794         public void refreshRegisters() {
795                 refreshRegisters(nativePtr);
796         }
797         
798         @Override
799         public String getVersion() {
800                 return getVersion(nativePtr);
801         }
802         
803         @Override
804         public PayloadType findPayloadType(String mime, int clockRate) {
805                 return findPayloadType(mime, clockRate, 1);
806         }
807         
808         private native void removeFriend(long ptr, long lf);
809         @Override
810         public void removeFriend(LinphoneFriend lf) {
811                 removeFriend(nativePtr, lf.getNativePtr());
812         }
813         
814         private native long getFriendByAddress(long ptr, String sipUri);
815         @Override
816         public LinphoneFriend findFriendByAddress(String sipUri) {
817                 long ptr = getFriendByAddress(nativePtr, sipUri);
818                 if (ptr == 0) {
819                         return null;
820                 }
821                 return new LinphoneFriendImpl(ptr);
822         }
823         
824         public void setAudioPort(int port) {
825                 setAudioPort(nativePtr, port);
826         }
827         
828         public void setVideoPort(int port) {
829                 setVideoPort(nativePtr, port);
830         }
831         
832         public void setAudioPortRange(int minPort, int maxPort) {
833                 setAudioPortRange(nativePtr, minPort, maxPort);
834         }
835         
836         public void setVideoPortRange(int minPort, int maxPort) {
837                 setVideoPortRange(nativePtr, minPort, maxPort);
838         }
839         
840         public void setIncomingTimeout(int timeout) {
841                 setIncomingTimeout(nativePtr, timeout);
842         }
843         
844         public void setInCallTimeout(int timeout)
845         {
846                 setInCallTimeout(nativePtr, timeout);
847         }
848         
849         private native void setMicrophoneGain(long ptr, float gain);
850         public void setMicrophoneGain(float gain) {
851                 setMicrophoneGain(nativePtr, gain);
852         }
853         
854         public void setPrimaryContact(String displayName, String username) {
855                 setPrimaryContact(nativePtr, displayName, username);
856         }
857         
858         private native void setUseSipInfoForDtmfs(long ptr, boolean use);
859         public void setUseSipInfoForDtmfs(boolean use) {
860                 setUseSipInfoForDtmfs(nativePtr, use);
861         }
862         
863         private native void setUseRfc2833ForDtmfs(long ptr, boolean use);
864         public void setUseRfc2833ForDtmfs(boolean use) {
865                 setUseRfc2833ForDtmfs(nativePtr, use);
866         }
867 }