3 Copyright (C) 2010 Belledonne Communications, Grenoble, France
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.
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.
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.
19 package org.linphone.core;
22 import java.util.List;
23 import java.util.Vector;
25 import org.linphone.core.LinphoneCallParams;
28 * Linphone core main object created by method {@link LinphoneCoreFactory#createLinphoneCore(LinphoneCoreListener, String, String, Object)}.
32 public interface LinphoneCore {
34 * linphone core states
36 static public class GlobalState {
37 @SuppressWarnings("unchecked")
38 static private Vector values = new Vector();
42 static public GlobalState GlobalOff = new GlobalState(0,"GlobalOff");
46 static public GlobalState GlobalStartup = new GlobalState(1,"GlobalStartup");
50 static public GlobalState GlobalOn = new GlobalState(2,"GlobalOn");
54 static public GlobalState GlobalShutdown = new GlobalState(3,"GlobalShutdown");
56 private final int mValue;
57 private final String mStringValue;
59 @SuppressWarnings("unchecked")
60 private GlobalState(int value,String stringValue) {
62 values.addElement(this);
63 mStringValue=stringValue;
65 public static GlobalState fromInt(int value) {
67 for (int i=0; i<values.size();i++) {
68 GlobalState state = (GlobalState) values.elementAt(i);
69 if (state.mValue == value) return state;
71 throw new RuntimeException("state not found ["+value+"]");
73 public String toString() {
78 * Describes proxy registration states.
81 static public class RegistrationState {
82 @SuppressWarnings("unchecked")
83 private static Vector values = new Vector();
87 public static RegistrationState RegistrationNone = new RegistrationState(0,"RegistrationNone");
91 public static RegistrationState RegistrationProgress = new RegistrationState(1,"RegistrationProgress");
95 public static RegistrationState RegistrationOk = new RegistrationState(2,"RegistrationOk");
99 public static RegistrationState RegistrationCleared = new RegistrationState(3,"RegistrationCleared");
103 public static RegistrationState RegistrationFailed = new RegistrationState(4,"RegistrationFailed");
104 private final int mValue;
105 private final String mStringValue;
107 @SuppressWarnings("unchecked")
108 private RegistrationState(int value,String stringValue) {
110 values.addElement(this);
111 mStringValue=stringValue;
113 public static RegistrationState fromInt(int value) {
115 for (int i=0; i<values.size();i++) {
116 RegistrationState state = (RegistrationState) values.elementAt(i);
117 if (state.mValue == value) return state;
119 throw new RuntimeException("state not found ["+value+"]");
121 public String toString() {
126 * Describes firewall policy.
129 static public class FirewallPolicy {
130 @SuppressWarnings("unchecked")
131 static private Vector values = new Vector();
133 * No firewall is assumed.
135 static public FirewallPolicy NoFirewall = new FirewallPolicy(0,"NoFirewall");
137 * Use NAT address (discouraged)
139 static public FirewallPolicy UseNatAddress = new FirewallPolicy(1,"UseNatAddress");
141 * Use stun server to discover RTP addresses and ports.
143 static public FirewallPolicy UseStun = new FirewallPolicy(2,"UseStun");
145 private final int mValue;
146 private final String mStringValue;
148 @SuppressWarnings("unchecked")
149 private FirewallPolicy(int value,String stringValue) {
151 values.addElement(this);
152 mStringValue=stringValue;
154 public static FirewallPolicy fromInt(int value) {
156 for (int i=0; i<values.size();i++) {
157 FirewallPolicy state = (FirewallPolicy) values.elementAt(i);
158 if (state.mValue == value) return state;
160 throw new RuntimeException("state not found ["+value+"]");
162 public String toString() {
171 * Signaling transports ports.
173 static public class Transports {
178 public Transports() {};
179 public Transports(Transports t) {
186 * Media (RTP) encryption enum-like.
189 static public class MediaEncryption {
190 @SuppressWarnings("unchecked")
191 static private Vector values = new Vector();
195 static public MediaEncryption None = new MediaEncryption(0,"None");
199 static public MediaEncryption SRTP = new MediaEncryption(1,"SRTP");
203 static public MediaEncryption ZRTP = new MediaEncryption(2,"ZRTP");
204 protected final int mValue;
205 private final String mStringValue;
207 @SuppressWarnings("unchecked")
208 private MediaEncryption(int value,String stringValue) {
210 values.addElement(this);
211 mStringValue=stringValue;
213 public static MediaEncryption fromInt(int value) {
215 for (int i=0; i<values.size();i++) {
216 MediaEncryption menc = (MediaEncryption) values.elementAt(i);
217 if (menc.mValue == value) return menc;
219 throw new RuntimeException("MediaEncryption not found ["+value+"]");
221 public String toString() {
226 * EC Calibrator Status
228 static public class EcCalibratorStatus {
229 @SuppressWarnings("unchecked")
230 static private Vector values = new Vector();
231 public static final int IN_PROGRESS_STATUS=0;
232 public static final int DONE_STATUS=1;
233 public static final int FAILED_STATUS=2;
235 * Calibration in progress
237 static public EcCalibratorStatus InProgress = new EcCalibratorStatus(IN_PROGRESS_STATUS,"InProgress");
241 static public EcCalibratorStatus Done = new EcCalibratorStatus(DONE_STATUS,"Done");
243 * Calibration in progress
245 static public EcCalibratorStatus Failed = new EcCalibratorStatus(FAILED_STATUS,"Failed");
247 private final int mValue;
248 private final String mStringValue;
250 @SuppressWarnings("unchecked")
251 private EcCalibratorStatus(int value,String stringValue) {
253 values.addElement(this);
254 mStringValue=stringValue;
256 public static EcCalibratorStatus fromInt(int value) {
258 for (int i=0; i<values.size();i++) {
259 EcCalibratorStatus status = (EcCalibratorStatus) values.elementAt(i);
260 if (status.mValue == value) return status;
262 throw new RuntimeException("status not found ["+value+"]");
264 public String toString() {
272 * clear all added proxy configs
274 public void clearProxyConfigs();
276 * Add a proxy configuration. This will start registration on the proxy, if registration is enabled.
278 * @throws LinphoneCoreException
280 public void addProxyConfig(LinphoneProxyConfig proxyCfg) throws LinphoneCoreException;
282 * Sets the default proxy.
284 * This default proxy must be part of the list of already entered {@link LinphoneProxyConfig}.
285 * Toggling it as default will make LinphoneCore use the identity associated with the proxy configuration in all incoming and outgoing calls.
288 public void setDefaultProxyConfig(LinphoneProxyConfig proxyCfg);
291 * get he default proxy configuration, that is the one used to determine the current identity.
292 * @return null if no default proxy config
294 public LinphoneProxyConfig getDefaultProxyConfig() ;
297 * clear all the added auth info
299 void clearAuthInfos();
301 * Adds authentication information to the LinphoneCore.
302 * <br>This information will be used during all SIP transacations that require authentication.
305 void addAuthInfo(LinphoneAuthInfo info);
308 * Build an address according to the current proxy config. In case destination is not a sip address, the default proxy domain is automatically appended
311 * @throws If no LinphoneAddress can be built from destination
313 public LinphoneAddress interpretUrl(String destination) throws LinphoneCoreException;
316 * Starts a call given a destination. Internally calls {@link #interpretUrl(String)} then {@link #invite(LinphoneAddress)}.
319 public LinphoneCall invite(String destination)throws LinphoneCoreException;
321 * Initiates an outgoing call given a destination LinphoneAddress
322 *<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.
323 * @param to the destination of the call (sip address).
324 * @return LinphoneCall
325 * @throws LinphoneCoreException
327 public LinphoneCall invite(LinphoneAddress to)throws LinphoneCoreException;
330 * @param aCall to be terminated
332 public void terminateCall(LinphoneCall aCall);
334 * Returns The LinphoneCall the current call if one is in call
337 public LinphoneCall getCurrentCall();
340 * get current call remote address in case of in/out call
341 * @return null if no call engaged yet
343 public LinphoneAddress getRemoteAddress();
346 * @return TRUE if there is a call running or pending.
348 public boolean isIncall();
351 * @return Returns true if in incoming call is pending, ie waiting for being answered or declined.
353 public boolean isInComingInvitePending();
355 * Main loop function. It is crucial that your application call it periodically.
357 * #iterate() performs various backgrounds tasks:
358 * <li>receiving of SIP messages
359 * <li> handles timers and timeout
360 * <li> performs registration to proxies
361 * <li> authentication retries The application MUST call this function from periodically, in its main loop.
362 * <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.
365 public void iterate();
367 * Accept an incoming call.
369 * Basically the application is notified of incoming calls within the
370 * {@link LinphoneCoreListener#inviteReceived(LinphoneCore, String)} listener.
371 * The application can later respond positively to the call using
373 * @throws LinphoneCoreException
375 public void acceptCall(LinphoneCall aCall) throws LinphoneCoreException;
378 * Accept an incoming call.
380 * Basically the application is notified of incoming calls within the
381 * {@link LinphoneCoreListener#inviteReceived(LinphoneCore, String)} listener.
382 * The application can later respond positively to the call using
384 * @throws LinphoneCoreException
386 public void acceptCallWithParams(LinphoneCall aCall, LinphoneCallParams params) throws LinphoneCoreException;
389 * Accept call modifications initiated by other end.
391 * Basically the application is notified of incoming calls within the
392 * {@link LinphoneCoreListener#inviteReceived(LinphoneCore, String)} listener.
393 * The application can later respond positively to the call using
395 * @throws LinphoneCoreException
397 public void acceptCallUpdate(LinphoneCall aCall, LinphoneCallParams params) throws LinphoneCoreException;
401 * Prevent LinphoneCore from performing an automatic answer
403 * Basically the application is notified of incoming calls within the
404 * {@link LinphoneCoreListener#inviteReceived(LinphoneCore, String)} listener.
405 * The application can later respond positively to the call using
407 * @throws LinphoneCoreException
409 public void deferCallUpdate(LinphoneCall aCall, LinphoneCallParams params) throws LinphoneCoreException;
412 * @return a list of LinphoneCallLog
414 @SuppressWarnings("unchecked")
415 public List getCallLogs();
418 * This method is called by the application to notify the Linphone core library when network is reachable.
419 * Calling this method with true trigger Linphone to initiate a registration process for all proxy
420 * configuration with parameter register set to enable.
421 * This method disable the automatic registration mode. It means you must call this method after each network state changes
422 * @param network state
425 public void setNetworkReachable(boolean isReachable);
428 * @return if false, there is no network connection.
430 public boolean isNetworkReachable();
432 * destroy linphone core and free all underlying resources
434 public void destroy();
436 * Allow to control play level before entering sound card:
439 public void setPlaybackGain(float gain);
441 * get play level before entering sound card:
442 * @return level in db
444 public float getPlaybackGain();
447 * @param level [0..100]
449 public void setPlayLevel(int level);
451 * get playback level [0..100];
452 * -1 if not cannot be determined
455 public int getPlayLevel();
457 * Mutes or unmutes the local microphone.
460 void muteMic(boolean isMuted);
463 * @return true is mic is muted
465 boolean isMicMuted();
468 * Initiate a dtmf signal if in call
471 void sendDtmf(char number);
473 * Initiate a dtmf signal to the speaker if not in call.
474 * Sending of the DTMF is done in another function.
476 * @param duration in ms , -1 for unlimited
478 void playDtmf(char number,int duration);
485 * remove all call logs
487 void clearCallLogs();
489 * get payload type from mime type an clock rate
491 * return null if not found
493 PayloadType findPayloadType(String mime,int clockRate);
495 * not implemented yet
498 * @throws LinphoneCoreException
500 void enablePayloadType(PayloadType pt, boolean enable) throws LinphoneCoreException;
502 * Enables or disable echo cancellation.
505 void enableEchoCancellation(boolean enable);
508 * @return true if echo cancellation is enabled.
510 boolean isEchoCancellationEnabled();
512 * Get echo limiter status (another method of doing echo suppressionn, more brute force)
513 * @return true if echo limiter is enabled
515 boolean isEchoLimiterEnabled();
517 * @param transports used for signaling (TCP, UDP and TLS)
519 void setSignalingTransportPorts(Transports transports);
521 * @return transports used for signaling (TCP, UDP, TLS)
523 Transports getSignalingTransportPorts();
528 void enableSpeaker(boolean value);
533 boolean isSpeakerEnabled();
535 * add a friend to the current buddy list, if subscription attribute is set, a SIP SUBSCRIBE message is sent.
536 * @param lf LinphoenFriend to add
537 * @throws LinphoneCoreException
539 void addFriend(LinphoneFriend lf) throws LinphoneCoreException;
542 * Set my presence status
543 * @param minute_away how long in away
544 * @param status sip uri used to redirect call in state LinphoneStatusMoved
546 void setPresenceInfo(int minute_away,String alternative_contact, OnlineStatus status);
548 * Create a new chat room for messaging from a sip uri like sip:joe@sip.linphone.org
549 * @param to destination address for messages
551 * @return {@link LinphoneChatRoom} where messaging can take place.
553 LinphoneChatRoom createChatRoom(String to);
555 void setVideoWindow(Object w);
556 void setPreviewWindow(Object w);
557 void setDeviceRotation(int rotation);
559 void setVideoDevice(int id);
560 int getVideoDevice();
563 * Enables video globally.
566 * This function does not have any effect during calls. It just indicates #LinphoneCore to
567 * initiate future calls with video or not. The two boolean parameters indicate in which
568 * direction video is enabled. Setting both to false disables video entirely.
570 * @param vcap_enabled indicates whether video capture is enabled
571 * @param display_enabled indicates whether video display should be shown
574 void enableVideo(boolean vcap_enabled, boolean display_enabled);
576 * Returns TRUE if video is enabled, FALSE otherwise.
579 boolean isVideoEnabled();
582 * Specify a STUN server to help firewall traversal.
583 * @param stun_server Stun server address and port, such as stun.linphone.org or stun.linphone.org:3478
585 void setStunServer(String stun_server);
587 * @return stun server address if previously set.
589 String getStunServer();
592 * Sets policy regarding workarounding NATs
593 * @param pol one of the FirewallPolicy members.
595 void setFirewallPolicy(FirewallPolicy pol);
597 * @return previously set firewall policy.
599 FirewallPolicy getFirewallPolicy();
601 LinphoneCall inviteAddressWithParams(LinphoneAddress destination, LinphoneCallParams params) throws LinphoneCoreException ;
603 int updateCall(LinphoneCall call, LinphoneCallParams params);
605 LinphoneCallParams createDefaultCallParameters();
608 * Sets the path to a wav file used for ringing.
610 * @param path The file must be a wav 16bit linear. Local ring is disabled if null
612 void setRing(String path);
614 * gets the path to a wav file used for ringing.
616 * @param null if not set
621 * Sets file or folder containing trusted root CAs
623 * @param path path to file with multiple PEM certif or to folder with multiple PEM files
625 void setRootCA(String path);
627 void setUploadBandwidth(int bw);
629 void setDownloadBandwidth(int bw);
632 * Sets audio packetization interval suggested for remote end.
633 * @param ptime packetization interval in milliseconds
635 void setDownloadPtime(int ptime);
638 * Sets audio packetization interval sent to remote end.
639 * @param ptime packetization interval in milliseconds
641 void setUploadPtime(int ptime);
643 void setPreferredVideoSize(VideoSize vSize);
645 VideoSize getPreferredVideoSize();
648 * Returns the currently supported audio codecs, as PayloadType elements
651 PayloadType[] getAudioCodecs();
653 * Returns the currently supported video codecs, as PayloadType elements
656 PayloadType[] getVideoCodecs();
658 * enable signaling keep alive. small udp packet sent periodically to keep udp NAT association
660 void enableKeepAlive(boolean enable);
662 * get keep elive mode
663 * @return true if enable
665 boolean isKeepAliveEnabled();
667 * Start an echo calibration of the sound devices, in order to find adequate settings for the echo canceler automatically.
668 * status is notified to {@link LinphoneCoreListener#ecCalibrationStatus(EcCalibratorStatus, int, Object)}
670 * @throws LinphoneCoreException if operation is still in progress;
672 void startEchoCalibration(Object data) throws LinphoneCoreException;
674 void enableIpv6(boolean enable);
675 void adjustSoftwareVolume(int i);
677 boolean pauseCall(LinphoneCall call);
678 boolean resumeCall(LinphoneCall call);
679 boolean pauseAllCalls();
681 void setZrtpSecretsCache(String file);
682 void enableEchoLimiter(boolean val);
684 boolean isInConference();
685 boolean enterConference();
686 void leaveConference();
688 void addToConference(LinphoneCall call);
689 void addAllToConference();
690 void removeFromConference(LinphoneCall call);
692 void terminateConference();
693 int getConferenceSize();
695 void terminateAllCalls();
696 @SuppressWarnings("unchecked") List getCalls();
700 void transferCall(LinphoneCall call, String referTo);
701 void transferCallToAnother(LinphoneCall callToTransfer, LinphoneCall destination);
703 LinphoneCall findCallFromUri(String uri);
706 void setMaxCalls(int max);
707 boolean isMyself(String uri);
710 * Use this method to check the calls state and forbid proposing actions
711 * which could result in an active call.
712 * Eg: don't start a new call if one is in outgoing ringing.
713 * Eg: don't merge to conference either as it could result
714 * in two active calls (conference and accepted call).
717 boolean soundResourcesLocked();
719 * Returns whether given media encryption is supported by liblinphone.
721 boolean mediaEncryptionSupported(MediaEncryption menc);
723 * set media encryption (rtp) to use
724 * @params menc: MediaEncryption.None, MediaEncryption.SRTP or MediaEncryption.ZRTP
726 void setMediaEncryption(MediaEncryption menc);
728 * return selected media encryption
729 * @return MediaEncryption.None, MediaEncryption.SRTP or MediaEncryption.ZRTP
731 MediaEncryption getMediaEncryption();
733 * Set media encryption required for outgoing calls
735 void setMediaEncryptionMandatory(boolean yesno);
737 * @return if media encryption is required for outgoing calls
739 boolean isMediaEncryptionMandatory();
742 * @param path path to music file played to remote side when on hold.
744 void setPlayFile(String path);
745 void tunnelEnable(boolean enable);
746 void tunnelAutoDetect();
747 void tunnelEnableLogs(boolean enable);
748 void tunnelCleanServers();
750 * @param host tunnel server ip address
751 * @param port tunnel server tls port, recommended value is 443
752 * @param udpMirrorPort remote port on the tunnel server side used to test udp reachability
753 * @param roundTripDelay udp packet round trip delay in ms considered as acceptable. recommended value is 1000 ms
755 void tunnelAddServerAndMirror(String host, int port, int udpMirrorPort, int roundTripDelay);
757 boolean isTunnelAvailable();
759 LinphoneProxyConfig[] getProxyConfigList();
761 void setVideoPolicy(boolean autoInitiate, boolean autoAccept);