]> sjero.net Git - linphone/blob - java/common/org/linphone/core/LinphoneCore.java
fix tunnel code for android
[linphone] / java / common / org / linphone / core / LinphoneCore.java
1 /*
2 LinphoneCore.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 java.util.Vector;
22
23 import org.linphone.core.LinphoneCallParams;
24
25 /**
26  * Linphone core main object created by method {@link LinphoneCoreFactory#createLinphoneCore(LinphoneCoreListener, String, String, Object)}.    
27  *
28  */
29
30 public interface LinphoneCore {
31         /**
32          * linphone core states
33          */
34         static public class GlobalState {
35                 
36                 static private Vector values = new Vector();
37                 /**
38                  * Off
39                  */
40                 static public GlobalState GlobalOff = new GlobalState(0,"GlobalOff");       
41                 /**
42                  * Startup
43                  */
44                 static public GlobalState GlobalStartup = new GlobalState(1,"GlobalStartup");
45                 /**
46                  * On
47                  */
48                 static public GlobalState GlobalOn = new GlobalState(2,"GlobalOn");
49                 /**
50                  * Shutdown
51                  */
52                 static public GlobalState GlobalShutdown = new GlobalState(3,"GlobalShutdown");
53
54                 private final int mValue;
55                 private final String mStringValue;
56
57                 
58                 private GlobalState(int value,String stringValue) {
59                         mValue = value;
60                         values.addElement(this);
61                         mStringValue=stringValue;
62                 }
63                 public static GlobalState fromInt(int value) {
64
65                         for (int i=0; i<values.size();i++) {
66                                 GlobalState state = (GlobalState) values.elementAt(i);
67                                 if (state.mValue == value) return state;
68                         }
69                         throw new RuntimeException("state not found ["+value+"]");
70                 }
71                 public String toString() {
72                         return mStringValue;
73                 }
74         }
75         /**
76          * Describes proxy registration states.
77          *
78          */
79         static public class RegistrationState {
80                 
81                 private static Vector values = new Vector();
82                 /**
83                  * None
84                  */
85                 public static RegistrationState RegistrationNone = new RegistrationState(0,"RegistrationNone");       
86                 /**
87                  * In Progress
88                  */
89                 public static RegistrationState RegistrationProgress  = new RegistrationState(1,"RegistrationProgress");
90                 /**
91                  * Ok
92                  */
93                 public static RegistrationState RegistrationOk = new RegistrationState(2,"RegistrationOk");
94                 /**
95                  * Cleared
96                  */
97                 public static RegistrationState RegistrationCleared = new RegistrationState(3,"RegistrationCleared");
98                 /**
99                  * Failed
100                  */
101                 public static RegistrationState RegistrationFailed = new RegistrationState(4,"RegistrationFailed");
102                 private final int mValue;
103                 private final String mStringValue;
104
105                 
106                 private RegistrationState(int value,String stringValue) {
107                         mValue = value;
108                         values.addElement(this);
109                         mStringValue=stringValue;
110                 }
111                 public static RegistrationState fromInt(int value) {
112
113                         for (int i=0; i<values.size();i++) {
114                                 RegistrationState state = (RegistrationState) values.elementAt(i);
115                                 if (state.mValue == value) return state;
116                         }
117                         throw new RuntimeException("state not found ["+value+"]");
118                 }
119                 public String toString() {
120                         return mStringValue;
121                 }
122         }
123         /**
124          * Describes firewall policy.
125          *
126          */
127         static public class FirewallPolicy {
128                 
129                 static private Vector values = new Vector();
130                 /**
131                  * No firewall is assumed.
132                  */
133                 static public FirewallPolicy NoFirewall = new FirewallPolicy(0,"NoFirewall");       
134                 /**
135                  * Use NAT address (discouraged)
136                  */
137                 static public FirewallPolicy UseNatAddress  = new FirewallPolicy(1,"UseNatAddress");
138                 /**
139                  * Use stun server to discover RTP addresses and ports.
140                  */
141                 static public FirewallPolicy UseStun = new FirewallPolicy(2,"UseStun");
142                 
143                 private final int mValue;
144                 private final String mStringValue;
145
146                 
147                 private FirewallPolicy(int value,String stringValue) {
148                         mValue = value;
149                         values.addElement(this);
150                         mStringValue=stringValue;
151                 }
152                 public static FirewallPolicy fromInt(int value) {
153
154                         for (int i=0; i<values.size();i++) {
155                                 FirewallPolicy state = (FirewallPolicy) values.elementAt(i);
156                                 if (state.mValue == value) return state;
157                         }
158                         throw new RuntimeException("state not found ["+value+"]");
159                 }
160                 public String toString() {
161                         return mStringValue;
162                 }
163                 public int value(){
164                         return mValue;
165                 }
166         }
167         
168         /**
169          * Signaling transports ports.
170          */
171         static public class Transports {
172                 public int udp;
173                 public int tcp;
174                 public int tls;
175                 
176                 public Transports() {};
177                 public Transports(Transports t) {
178                         this.udp = t.udp;
179                         this.tcp = t.tcp;
180                         this.tls = t.tls;
181                 }
182         }
183         /**
184          * Media (RTP) encryption enum-like.
185          *
186          */
187         static public class MediaEncryption {
188                 
189                 static private Vector values = new Vector();
190                 /**
191                  * None
192                  */
193                 static public MediaEncryption None = new MediaEncryption(0,"None");       
194                 /**
195                  * SRTP
196                  */
197                 static public MediaEncryption SRTP = new MediaEncryption(1,"SRTP");
198                 /**
199                  * ZRTP
200                  */
201                 static public MediaEncryption ZRTP = new MediaEncryption(2,"ZRTP");
202                 protected final int mValue;
203                 private final String mStringValue;
204
205                 
206                 private MediaEncryption(int value,String stringValue) {
207                         mValue = value;
208                         values.addElement(this);
209                         mStringValue=stringValue;
210                 }
211                 public static MediaEncryption fromInt(int value) {
212
213                         for (int i=0; i<values.size();i++) {
214                                 MediaEncryption menc = (MediaEncryption) values.elementAt(i);
215                                 if (menc.mValue == value) return menc;
216                         }
217                         throw new RuntimeException("MediaEncryption not found ["+value+"]");
218                 }
219                 public String toString() {
220                         return mStringValue;
221                 }
222         }
223         /**
224          *      EC Calibrator Status
225          */
226         static public class EcCalibratorStatus {
227                 
228                 static private Vector values = new Vector();
229                 public static final int IN_PROGRESS_STATUS=0;
230                 public static final int DONE_STATUS=1;
231                 public static final int FAILED_STATUS=2;
232                 /**
233                  * Calibration in progress
234                  */
235                 static public EcCalibratorStatus InProgress = new EcCalibratorStatus(IN_PROGRESS_STATUS,"InProgress");       
236                 /**
237                  * Calibration done
238                  */
239                 static public EcCalibratorStatus Done  = new EcCalibratorStatus(DONE_STATUS,"Done");
240                 /**
241                  * Calibration in progress
242                  */
243                 static public EcCalibratorStatus Failed = new EcCalibratorStatus(FAILED_STATUS,"Failed");
244
245                 private final int mValue;
246                 private final String mStringValue;
247
248                 
249                 private EcCalibratorStatus(int value,String stringValue) {
250                         mValue = value;
251                         values.addElement(this);
252                         mStringValue=stringValue;
253                 }
254                 public static EcCalibratorStatus fromInt(int value) {
255
256                         for (int i=0; i<values.size();i++) {
257                                 EcCalibratorStatus status = (EcCalibratorStatus) values.elementAt(i);
258                                 if (status.mValue == value) return status;
259                         }
260                         throw new RuntimeException("status not found ["+value+"]");
261                 }
262                 public String toString() {
263                         return mStringValue;
264                 }
265                 public int value(){
266                         return mValue;
267                 }
268         }
269         /**
270          * clear all added proxy configs
271          */
272         public void clearProxyConfigs();
273         /**
274          * Add a proxy configuration. This will start registration on the proxy, if registration is enabled.
275          * @param proxyCfg
276          * @throws LinphoneCoreException
277          */
278         public void addProxyConfig(LinphoneProxyConfig proxyCfg) throws LinphoneCoreException;
279         /**
280          * Sets the default proxy.
281          *<br>
282          * This default proxy must be part of the list of already entered {@link LinphoneProxyConfig}. 
283          * Toggling it as default will make LinphoneCore use the identity associated with the proxy configuration in all incoming and outgoing calls.
284          * @param proxyCfg 
285          */
286         public void setDefaultProxyConfig(LinphoneProxyConfig proxyCfg);
287         
288         /**
289          * get he default proxy configuration, that is the one used to determine the current identity.
290          * @return null if no default proxy config 
291          */
292         public LinphoneProxyConfig getDefaultProxyConfig() ;
293         
294         /**
295          * clear all the added auth info
296          */
297         void clearAuthInfos();
298         /**
299          * Adds authentication information to the LinphoneCore.
300          * <br>This information will be used during all SIP transacations that require authentication.
301          * @param info
302          */
303         void addAuthInfo(LinphoneAuthInfo info);
304         
305         /**
306          * Build an address according to the current proxy config. In case destination is not a sip address, the default proxy domain is automatically appended
307          * @param destination
308          * @return
309          * @throws If no LinphoneAddress can be built from destination
310          */
311         public LinphoneAddress interpretUrl(String destination) throws LinphoneCoreException;
312         
313         /**
314          * Starts a call given a destination. Internally calls {@link #interpretUrl(String)} then {@link #invite(LinphoneAddress)}.
315          * @param uri
316          */
317         public LinphoneCall invite(String destination)throws LinphoneCoreException;
318         /**
319          * Initiates an outgoing call given a destination LinphoneAddress
320          *<br>The LinphoneAddress can be constructed directly using linphone_address_new(), or created by linphone_core_interpret_url(). The application doesn't own a reference to the returned LinphoneCall object. Use linphone_call_ref() to safely keep the LinphoneCall pointer valid within your application.
321          * @param to the destination of the call (sip address).
322          * @return LinphoneCall
323          * @throws LinphoneCoreException
324          */
325         public LinphoneCall invite(LinphoneAddress to)throws LinphoneCoreException;
326         /**
327          * Terminates a call.
328          * @param aCall to be terminated
329          */
330         public void terminateCall(LinphoneCall aCall);
331         /**
332          * Returns The LinphoneCall the current call if one is in call
333          *
334         **/
335         public LinphoneCall getCurrentCall(); 
336         
337         /**
338          * get current call remote address in case of in/out call
339          * @return null if no call engaged yet
340          */
341         public LinphoneAddress getRemoteAddress();
342         /**
343          *  
344          * @return  TRUE if there is a call running or pending.
345          */
346         public boolean isIncall();
347         /**
348          * 
349          * @return Returns true if in incoming call is pending, ie waiting for being answered or declined.
350          */
351         public boolean isInComingInvitePending();
352         /**
353          * Main loop function. It is crucial that your application call it periodically.
354          *
355          *      #iterate() performs various backgrounds tasks:
356          * <li>receiving of SIP messages
357          * <li> handles timers and timeout
358          * <li> performs registration to proxies
359          * <li> authentication retries The application MUST call this function from periodically, in its main loop. 
360          * <br> Be careful that this function must be call from the same thread as other liblinphone methods. In not the case make sure all liblinphone calls are serialized with a mutex.
361
362          */
363         public void iterate();
364         /**
365          * Accept an incoming call.
366          *
367          * Basically the application is notified of incoming calls within the
368          * {@link LinphoneCoreListener#inviteReceived(LinphoneCore, String)} listener.
369          * The application can later respond positively to the call using
370          * this method.
371          * @throws LinphoneCoreException 
372          */
373         public void acceptCall(LinphoneCall aCall) throws LinphoneCoreException;
374         
375         /**
376          * Accept an incoming call.
377          *
378          * Basically the application is notified of incoming calls within the
379          * {@link LinphoneCoreListener#inviteReceived(LinphoneCore, String)} listener.
380          * The application can later respond positively to the call using
381          * this method.
382          * @throws LinphoneCoreException 
383          */
384         public void acceptCallWithParams(LinphoneCall aCall, LinphoneCallParams params) throws LinphoneCoreException;
385         
386         /**
387          * Accept call modifications initiated by other end.
388          *
389          * Basically the application is notified of incoming calls within the
390          * {@link LinphoneCoreListener#inviteReceived(LinphoneCore, String)} listener.
391          * The application can later respond positively to the call using
392          * this method.
393          * @throws LinphoneCoreException 
394          */
395         public void acceptCallUpdate(LinphoneCall aCall, LinphoneCallParams params) throws LinphoneCoreException;
396         
397         
398         /**
399          * Prevent LinphoneCore from performing an automatic answer
400          *
401          * Basically the application is notified of incoming calls within the
402          * {@link LinphoneCoreListener#inviteReceived(LinphoneCore, String)} listener.
403          * The application can later respond positively to the call using
404          * this method.
405          * @throws LinphoneCoreException 
406          */
407         public void deferCallUpdate(LinphoneCall aCall) throws LinphoneCoreException;
408         
409         /**
410          * @return a list of LinphoneCallLog 
411          */
412         public LinphoneCallLog[] getCallLogs();
413         
414         /**
415          * This method is called by the application to notify the Linphone core library when network is reachable.
416          * Calling this method with true trigger Linphone to initiate a registration process for all proxy
417          * configuration with parameter register set to enable.
418          * This method disable the automatic registration mode. It means you must call this method after each network state changes
419          * @param network state  
420          *
421          */
422         public void setNetworkReachable(boolean isReachable);
423         /**
424          * 
425          * @return if false, there is no network connection.
426          */
427         public boolean isNetworkReachable();
428         /**
429          * destroy linphone core and free all underlying resources
430          */
431         public void destroy();
432         /**
433          * Allow to control play level before entering  sound card:  
434          * @param level in db
435          */
436         public void setPlaybackGain(float gain);
437         /**
438          * get play level before entering  sound card:  
439          * @return level in db
440          */
441         public float getPlaybackGain();
442         /**
443          * set play level
444          * @param level [0..100]
445          */
446         public void setPlayLevel(int level);
447         /**
448          * get playback level [0..100];
449          * -1 if not cannot be determined
450          * @return
451          */
452         public int getPlayLevel();
453         /**
454          *  Mutes or unmutes the local microphone.
455          * @param isMuted
456          */
457         void muteMic(boolean isMuted);
458         /**
459          * 
460          * @return true is mic is muted
461          */
462         boolean isMicMuted();
463         
464         /**
465          * Initiate a dtmf signal if in call
466          * @param number
467          */
468         void sendDtmf(char number);
469         /**
470          * Initiate a dtmf signal to the speaker if not in call.
471          * Sending of the DTMF is done in another function.
472          * @param number
473          * @param duration in ms , -1 for unlimited
474          */
475         void playDtmf(char number,int duration);
476         /**
477          * stop current dtmf
478          */
479         void stopDtmf();
480         
481         /**
482          * remove all call logs
483          */
484         void clearCallLogs();
485         /***
486          * get payload type  from mime type an clock rate
487          * 
488          * return null if not found
489          */
490         PayloadType findPayloadType(String mime,int clockRate); 
491         /**
492          * not implemented yet
493          * @param pt
494          * @param enable
495          * @throws LinphoneCoreException
496          */
497         void enablePayloadType(PayloadType pt, boolean enable) throws LinphoneCoreException;
498         /**
499          * Enables or disable echo cancellation.
500          * @param enable
501          */
502         void enableEchoCancellation(boolean enable);
503         /**
504          * get EC status 
505          * @return true if echo cancellation is enabled.
506          */
507         boolean isEchoCancellationEnabled();
508         /**
509          * Get echo limiter status (another method of doing echo suppressionn, more brute force)
510          * @return true if echo limiter is enabled
511          */
512         boolean isEchoLimiterEnabled();
513         /**
514          * @param transports used for signaling (TCP, UDP and TLS)
515          */
516         void setSignalingTransportPorts(Transports transports);
517         /**
518          * @return transports used for signaling (TCP, UDP, TLS)
519          */
520         Transports getSignalingTransportPorts();
521         /**
522          * not implemented
523          * @param value
524          */
525         void enableSpeaker(boolean value);
526         /**
527          * not implemented
528          * @return
529          */
530         boolean isSpeakerEnabled();
531         /**
532          * add a friend to the current buddy list, if subscription attribute is set, a SIP SUBSCRIBE message is sent.
533          * @param lf LinphoenFriend to add
534          * @throws LinphoneCoreException
535          */
536         void addFriend(LinphoneFriend lf) throws LinphoneCoreException;
537
538         /**
539          * Set my presence status
540          * @param minute_away how long in away
541          * @param status sip uri used to redirect call in state LinphoneStatusMoved
542          */
543         void setPresenceInfo(int minute_away,String alternative_contact, OnlineStatus status);
544         /**
545          * Create a new chat room for messaging from a sip uri like sip:joe@sip.linphone.org
546          * @param to    destination address for messages 
547          *
548          * @return {@link LinphoneChatRoom} where messaging can take place.
549          */
550         LinphoneChatRoom createChatRoom(String to);
551         
552         void setVideoWindow(Object w);
553         void setPreviewWindow(Object w);
554         void setDeviceRotation(int rotation);
555         
556         void setVideoDevice(int id);
557         int getVideoDevice();
558         
559         /**
560          * Enables video globally.
561          *
562          * 
563          * This function does not have any effect during calls. It just indicates #LinphoneCore to
564          * initiate future calls with video or not. The two boolean parameters indicate in which
565          * direction video is enabled. Setting both to false disables video entirely.
566          *
567          * @param vcap_enabled indicates whether video capture is enabled
568          * @param display_enabled indicates whether video display should be shown
569          *
570         **/
571         void enableVideo(boolean vcap_enabled, boolean display_enabled);
572         /**
573          * Returns TRUE if video is enabled, FALSE otherwise.
574          *      
575          ***/
576         boolean isVideoEnabled();
577         
578         /**
579          * Specify a STUN server to help firewall traversal.
580          * @param stun_server Stun server address and port, such as stun.linphone.org or stun.linphone.org:3478
581          */
582         void setStunServer(String stun_server);
583         /**
584          * @return stun server address if previously set.
585          */
586         String getStunServer();
587         
588         /**
589          * Sets policy regarding workarounding NATs
590          * @param pol one of the FirewallPolicy members.
591         **/
592         void setFirewallPolicy(FirewallPolicy pol);
593         /**
594          * @return previously set firewall policy.
595          */
596         FirewallPolicy getFirewallPolicy();
597
598         LinphoneCall inviteAddressWithParams(LinphoneAddress destination, LinphoneCallParams params) throws LinphoneCoreException ;
599         
600         int updateCall(LinphoneCall call, LinphoneCallParams params);
601
602         LinphoneCallParams createDefaultCallParameters();
603
604         /**
605          * Sets the path to a wav file used for ringing.
606          *
607          * @param path The file must be a wav 16bit linear. Local ring is disabled if null
608          */
609         void setRing(String path);
610         /**
611          * gets the path to a wav file used for ringing.
612          *
613          * @param null if not set
614          */
615         String getRing();
616         
617         /**
618          * Sets file or folder containing trusted root CAs
619          *
620          * @param path path to file with multiple PEM certif or to folder with multiple PEM files
621          */     
622         void setRootCA(String path);
623         
624         void setUploadBandwidth(int bw);
625
626         void setDownloadBandwidth(int bw);
627         
628         /**
629          * Sets audio packetization interval suggested for remote end.
630          * @param ptime packetization interval in milliseconds
631          */
632         void setDownloadPtime(int ptime);
633         
634         /**
635          * Sets audio packetization interval sent to remote end.
636          * @param ptime packetization interval in milliseconds
637          */
638         void setUploadPtime(int ptime);
639
640         void setPreferredVideoSize(VideoSize vSize);
641         
642         VideoSize getPreferredVideoSize();
643         
644         /**
645          * Returns the currently supported audio codecs, as PayloadType elements
646          * @return
647          */
648         PayloadType[] getAudioCodecs();
649         /**
650          * Returns the currently supported video codecs, as PayloadType elements
651          * @return
652          */
653         PayloadType[] getVideoCodecs();
654         /**
655          * enable signaling keep alive. small udp packet sent periodically to keep udp NAT association
656          */
657         void enableKeepAlive(boolean enable);
658         /**
659          * get keep elive mode
660          * @return true if enable
661          */
662         boolean isKeepAliveEnabled();
663         /**
664          * Start an echo calibration of the sound devices, in order to find adequate settings for the echo canceler automatically.
665          * status is notified to {@link LinphoneCoreListener#ecCalibrationStatus(EcCalibratorStatus, int, Object)}
666          * @param User object
667          * @throws LinphoneCoreException if operation is still in progress;
668         **/
669         void startEchoCalibration(Object data) throws LinphoneCoreException;
670
671         void enableIpv6(boolean enable);
672         void adjustSoftwareVolume(int i);
673         
674         boolean pauseCall(LinphoneCall call);
675         boolean resumeCall(LinphoneCall call);
676         boolean pauseAllCalls();
677         
678         void setZrtpSecretsCache(String file);
679         void enableEchoLimiter(boolean val);
680
681         boolean isInConference();
682         boolean enterConference();
683         void leaveConference();
684
685         void addToConference(LinphoneCall call);
686         void addAllToConference();
687         void removeFromConference(LinphoneCall call);
688
689         void terminateConference();
690         int getConferenceSize();
691         
692         void terminateAllCalls();
693         LinphoneCall[] getCalls();
694         int getCallsNb();
695
696
697         void transferCall(LinphoneCall call, String referTo);
698         void transferCallToAnother(LinphoneCall callToTransfer, LinphoneCall destination);
699
700         LinphoneCall findCallFromUri(String uri);
701
702         int getMaxCalls();
703         void setMaxCalls(int max);
704         boolean isMyself(String uri);
705
706         /**
707          * Use this method to check the calls state and forbid proposing actions
708          * which could result in an active call.
709          * Eg: don't start a new call if one is in outgoing ringing.
710          * Eg: don't merge to conference either as it could result
711          *     in two active calls (conference and accepted call). 
712          * @return
713          */
714         boolean soundResourcesLocked();
715         /**
716          * Returns whether given media encryption is supported by liblinphone.
717          */
718         boolean mediaEncryptionSupported(MediaEncryption menc);
719         /**
720          * set media encryption (rtp) to use
721          * @params menc: MediaEncryption.None, MediaEncryption.SRTP or MediaEncryption.ZRTP
722          */
723         void setMediaEncryption(MediaEncryption menc);
724         /**
725          * return selected media encryption
726          * @return MediaEncryption.None, MediaEncryption.SRTP or MediaEncryption.ZRTP
727          */
728         MediaEncryption getMediaEncryption();
729 /**
730          * Set media encryption required for outgoing calls
731          */
732         void setMediaEncryptionMandatory(boolean yesno);
733         /**
734          * @return if media encryption is required for outgoing calls
735          */
736         boolean isMediaEncryptionMandatory();
737
738         /**
739          * @param path path to music file played to remote side when on hold.
740          */
741         void setPlayFile(String path);
742         void tunnelEnable(boolean enable);
743         void tunnelAutoDetect();
744         void tunnelCleanServers();
745         /**
746          * @param host tunnel server ip address
747          * @param port tunnel server tls port, recommended value is 443
748          * @param udpMirrorPort remote port on the tunnel server side  used to test udp reachability
749          * @param roundTripDelay udp packet round trip delay in ms considered as acceptable. recommended value is 1000 ms
750          */
751         void tunnelAddServerAndMirror(String host, int port, int udpMirrorPort, int roundTripDelay);
752
753         boolean isTunnelAvailable();
754         
755         LinphoneProxyConfig[] getProxyConfigList();
756         
757         void setVideoPolicy(boolean autoInitiate, boolean autoAccept);
758         
759         void setUserAgent(String name, String version);
760         
761         void setCpuCount(int count);
762 }