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;
21 import java.util.Vector;
23 import org.linphone.core.LinphoneCallLog;
24 import org.linphone.core.LinphoneCallParams;
27 * Linphone core main object created by method {@link LinphoneCoreFactory#createLinphoneCore(LinphoneCoreListener, String, String, Object)}.
31 public interface LinphoneCore {
33 * linphone core states
35 static public class GlobalState {
37 static private Vector values = new Vector();
41 static public GlobalState GlobalOff = new GlobalState(0,"GlobalOff");
45 static public GlobalState GlobalStartup = new GlobalState(1,"GlobalStartup");
49 static public GlobalState GlobalOn = new GlobalState(2,"GlobalOn");
53 static public GlobalState GlobalShutdown = new GlobalState(3,"GlobalShutdown");
55 private final int mValue;
56 private final String mStringValue;
59 private GlobalState(int value,String stringValue) {
61 values.addElement(this);
62 mStringValue=stringValue;
64 public static GlobalState fromInt(int value) {
66 for (int i=0; i<values.size();i++) {
67 GlobalState state = (GlobalState) values.elementAt(i);
68 if (state.mValue == value) return state;
70 throw new RuntimeException("state not found ["+value+"]");
72 public String toString() {
77 * Describes proxy registration states.
80 static public class RegistrationState {
82 private static Vector values = new Vector();
86 public static RegistrationState RegistrationNone = new RegistrationState(0,"RegistrationNone");
90 public static RegistrationState RegistrationProgress = new RegistrationState(1,"RegistrationProgress");
94 public static RegistrationState RegistrationOk = new RegistrationState(2,"RegistrationOk");
98 public static RegistrationState RegistrationCleared = new RegistrationState(3,"RegistrationCleared");
102 public static RegistrationState RegistrationFailed = new RegistrationState(4,"RegistrationFailed");
103 private final int mValue;
104 private final String mStringValue;
107 private RegistrationState(int value,String stringValue) {
109 values.addElement(this);
110 mStringValue=stringValue;
112 public static RegistrationState fromInt(int value) {
114 for (int i=0; i<values.size();i++) {
115 RegistrationState state = (RegistrationState) values.elementAt(i);
116 if (state.mValue == value) return state;
118 throw new RuntimeException("state not found ["+value+"]");
120 public String toString() {
125 * Describes firewall policy.
128 static public class FirewallPolicy {
130 static private Vector values = new Vector();
132 * No firewall is assumed.
134 static public FirewallPolicy NoFirewall = new FirewallPolicy(0,"NoFirewall");
136 * Use NAT address (discouraged)
138 static public FirewallPolicy UseNatAddress = new FirewallPolicy(1,"UseNatAddress");
140 * Use stun server to discover RTP addresses and ports.
142 static public FirewallPolicy UseStun = new FirewallPolicy(2,"UseStun");
146 static public FirewallPolicy UseIce = new FirewallPolicy(3,"UseIce");
148 private final int mValue;
149 private final String mStringValue;
152 private FirewallPolicy(int value,String stringValue) {
154 values.addElement(this);
155 mStringValue=stringValue;
157 public static FirewallPolicy fromInt(int value) {
159 for (int i=0; i<values.size();i++) {
160 FirewallPolicy state = (FirewallPolicy) values.elementAt(i);
161 if (state.mValue == value) return state;
163 throw new RuntimeException("state not found ["+value+"]");
165 public String toString() {
174 * Signaling transports ports.
176 static public class Transports {
181 public Transports() {};
182 public Transports(Transports t) {
187 public String toString() {
188 return "udp["+udp+"] tcp["+tcp+"] tls["+tls+"]";
192 * Media (RTP) encryption enum-like.
195 static public class MediaEncryption {
197 static private Vector values = new Vector();
201 static public MediaEncryption None = new MediaEncryption(0,"None");
205 static public MediaEncryption SRTP = new MediaEncryption(1,"SRTP");
209 static public MediaEncryption ZRTP = new MediaEncryption(2,"ZRTP");
210 protected final int mValue;
211 private final String mStringValue;
214 private MediaEncryption(int value,String stringValue) {
216 values.addElement(this);
217 mStringValue=stringValue;
219 public static MediaEncryption fromInt(int value) {
221 for (int i=0; i<values.size();i++) {
222 MediaEncryption menc = (MediaEncryption) values.elementAt(i);
223 if (menc.mValue == value) return menc;
225 throw new RuntimeException("MediaEncryption not found ["+value+"]");
227 public String toString() {
232 * EC Calibrator Status
234 static public class EcCalibratorStatus {
236 static private Vector values = new Vector();
237 public static final int IN_PROGRESS_STATUS=0;
238 public static final int DONE_STATUS=1;
239 public static final int FAILED_STATUS=2;
241 * Calibration in progress
243 static public EcCalibratorStatus InProgress = new EcCalibratorStatus(IN_PROGRESS_STATUS,"InProgress");
247 static public EcCalibratorStatus Done = new EcCalibratorStatus(DONE_STATUS,"Done");
249 * Calibration in progress
251 static public EcCalibratorStatus Failed = new EcCalibratorStatus(FAILED_STATUS,"Failed");
253 private final int mValue;
254 private final String mStringValue;
257 private EcCalibratorStatus(int value,String stringValue) {
259 values.addElement(this);
260 mStringValue=stringValue;
262 public static EcCalibratorStatus fromInt(int value) {
264 for (int i=0; i<values.size();i++) {
265 EcCalibratorStatus status = (EcCalibratorStatus) values.elementAt(i);
266 if (status.mValue == value) return status;
268 throw new RuntimeException("status not found ["+value+"]");
270 public String toString() {
278 * clear all added proxy configs
280 public void clearProxyConfigs();
282 * Add a proxy configuration. This will start registration on the proxy, if registration is enabled.
284 * @throws LinphoneCoreException
286 public void addProxyConfig(LinphoneProxyConfig proxyCfg) throws LinphoneCoreException;
288 * Sets the default proxy.
290 * This default proxy must be part of the list of already entered {@link LinphoneProxyConfig}.
291 * Toggling it as default will make LinphoneCore use the identity associated with the proxy configuration in all incoming and outgoing calls.
294 public void setDefaultProxyConfig(LinphoneProxyConfig proxyCfg);
297 * get he default proxy configuration, that is the one used to determine the current identity.
298 * @return null if no default proxy config
300 public LinphoneProxyConfig getDefaultProxyConfig() ;
303 * clear all the added auth info
305 void clearAuthInfos();
307 * Adds authentication information to the LinphoneCore.
308 * <br>This information will be used during all SIP transacations that require authentication.
311 void addAuthInfo(LinphoneAuthInfo info);
314 * Build an address according to the current proxy config. In case destination is not a sip address, the default proxy domain is automatically appended
317 * @throws If no LinphoneAddress can be built from destination
319 public LinphoneAddress interpretUrl(String destination) throws LinphoneCoreException;
322 * Starts a call given a destination. Internally calls {@link #interpretUrl(String)} then {@link #invite(LinphoneAddress)}.
325 public LinphoneCall invite(String destination)throws LinphoneCoreException;
327 * Initiates an outgoing call given a destination LinphoneAddress
328 *<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.
329 * @param to the destination of the call (sip address).
330 * @return LinphoneCall
331 * @throws LinphoneCoreException
333 public LinphoneCall invite(LinphoneAddress to)throws LinphoneCoreException;
336 * @param aCall to be terminated
338 public void terminateCall(LinphoneCall aCall);
340 * Returns The LinphoneCall the current call if one is in call
343 public LinphoneCall getCurrentCall();
346 * get current call remote address in case of in/out call
347 * @return null if no call engaged yet
349 public LinphoneAddress getRemoteAddress();
352 * @return TRUE if there is a call running or pending.
354 public boolean isIncall();
357 * @return Returns true if in incoming call is pending, ie waiting for being answered or declined.
359 public boolean isInComingInvitePending();
361 * Main loop function. It is crucial that your application call it periodically.
363 * #iterate() performs various backgrounds tasks:
364 * <li>receiving of SIP messages
365 * <li> handles timers and timeout
366 * <li> performs registration to proxies
367 * <li> authentication retries The application MUST call this function from periodically, in its main loop.
368 * <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.
371 public void iterate();
373 * Accept an incoming call.
375 * Basically the application is notified of incoming calls within the
376 * {@link LinphoneCoreListener#inviteReceived(LinphoneCore, String)} listener.
377 * The application can later respond positively to the call using
379 * @throws LinphoneCoreException
381 public void acceptCall(LinphoneCall aCall) throws LinphoneCoreException;
384 * Accept an incoming call.
386 * Basically the application is notified of incoming calls within the
387 * {@link LinphoneCoreListener#inviteReceived(LinphoneCore, String)} listener.
388 * The application can later respond positively to the call using
390 * @throws LinphoneCoreException
392 public void acceptCallWithParams(LinphoneCall aCall, LinphoneCallParams params) throws LinphoneCoreException;
395 * Accept call modifications initiated by other end.
397 * Basically the application is notified of incoming calls within the
398 * {@link LinphoneCoreListener#inviteReceived(LinphoneCore, String)} listener.
399 * The application can later respond positively to the call using
401 * @throws LinphoneCoreException
403 public void acceptCallUpdate(LinphoneCall aCall, LinphoneCallParams params) throws LinphoneCoreException;
407 * Prevent LinphoneCore from performing an automatic answer
409 * Basically the application is notified of incoming calls within the
410 * {@link LinphoneCoreListener#inviteReceived(LinphoneCore, String)} listener.
411 * The application can later respond positively to the call using
413 * @throws LinphoneCoreException
415 public void deferCallUpdate(LinphoneCall aCall) throws LinphoneCoreException;
418 * @return a list of LinphoneCallLog
420 public LinphoneCallLog[] getCallLogs();
423 * This method is called by the application to notify the Linphone core library when network is reachable.
424 * Calling this method with true trigger Linphone to initiate a registration process for all proxy
425 * configuration with parameter register set to enable.
426 * This method disable the automatic registration mode. It means you must call this method after each network state changes
427 * @param network state
430 public void setNetworkReachable(boolean isReachable);
433 * @return if false, there is no network connection.
435 public boolean isNetworkReachable();
437 * destroy linphone core and free all underlying resources
439 public void destroy();
441 * Allow to control play level before entering sound card:
444 public void setPlaybackGain(float gain);
446 * get play level before entering sound card:
447 * @return level in db
449 public float getPlaybackGain();
452 * @param level [0..100]
454 public void setPlayLevel(int level);
456 * get playback level [0..100];
457 * -1 if not cannot be determined
460 public int getPlayLevel();
462 * Mutes or unmutes the local microphone.
465 void muteMic(boolean isMuted);
468 * @return true is mic is muted
470 boolean isMicMuted();
473 * Initiate a dtmf signal if in call
476 void sendDtmf(char number);
478 * Initiate a dtmf signal to the speaker if not in call.
479 * Sending of the DTMF is done in another function.
481 * @param duration in ms , -1 for unlimited
483 void playDtmf(char number,int duration);
490 * remove all call logs
492 void clearCallLogs();
494 * get payload type from mime type an clock rate
496 * return null if not found
498 PayloadType findPayloadType(String mime,int clockRate);
500 * not implemented yet
503 * @throws LinphoneCoreException
505 void enablePayloadType(PayloadType pt, boolean enable) throws LinphoneCoreException;
507 * Enables or disable echo cancellation.
510 void enableEchoCancellation(boolean enable);
513 * @return true if echo cancellation is enabled.
515 boolean isEchoCancellationEnabled();
517 * Get echo limiter status (another method of doing echo suppressionn, more brute force)
518 * @return true if echo limiter is enabled
520 boolean isEchoLimiterEnabled();
522 * @param transports used for signaling (TCP, UDP and TLS)
524 void setSignalingTransportPorts(Transports transports);
526 * @return transports used for signaling (TCP, UDP, TLS)
528 Transports getSignalingTransportPorts();
533 void enableSpeaker(boolean value);
538 boolean isSpeakerEnabled();
540 * add a friend to the current buddy list, if subscription attribute is set, a SIP SUBSCRIBE message is sent.
541 * @param lf LinphoenFriend to add
542 * @throws LinphoneCoreException
544 void addFriend(LinphoneFriend lf) throws LinphoneCoreException;
547 * Set my presence status
548 * @param minute_away how long in away
549 * @param status sip uri used to redirect call in state LinphoneStatusMoved
551 void setPresenceInfo(int minute_away,String alternative_contact, OnlineStatus status);
553 * Create a new chat room for messaging from a sip uri like sip:joe@sip.linphone.org
554 * @param to destination address for messages
556 * @return {@link LinphoneChatRoom} where messaging can take place.
558 LinphoneChatRoom createChatRoom(String to);
560 void setVideoWindow(Object w);
561 void setPreviewWindow(Object w);
562 void setDeviceRotation(int rotation);
564 void setVideoDevice(int id);
565 int getVideoDevice();
568 * Enables video globally.
571 * This function does not have any effect during calls. It just indicates #LinphoneCore to
572 * initiate future calls with video or not. The two boolean parameters indicate in which
573 * direction video is enabled. Setting both to false disables video entirely.
575 * @param vcap_enabled indicates whether video capture is enabled
576 * @param display_enabled indicates whether video display should be shown
579 void enableVideo(boolean vcap_enabled, boolean display_enabled);
581 * Returns TRUE if video is enabled, FALSE otherwise.
584 boolean isVideoEnabled();
587 * Specify a STUN server to help firewall traversal.
588 * @param stun_server Stun server address and port, such as stun.linphone.org or stun.linphone.org:3478
590 void setStunServer(String stun_server);
592 * @return stun server address if previously set.
594 String getStunServer();
597 * Sets policy regarding workarounding NATs
598 * @param pol one of the FirewallPolicy members.
600 void setFirewallPolicy(FirewallPolicy pol);
602 * @return previously set firewall policy.
604 FirewallPolicy getFirewallPolicy();
606 LinphoneCall inviteAddressWithParams(LinphoneAddress destination, LinphoneCallParams params) throws LinphoneCoreException ;
608 int updateCall(LinphoneCall call, LinphoneCallParams params);
610 LinphoneCallParams createDefaultCallParameters();
613 * Sets the path to a wav file used for ringing.
615 * @param path The file must be a wav 16bit linear. Local ring is disabled if null
617 void setRing(String path);
619 * gets the path to a wav file used for ringing.
621 * @param null if not set
626 * Sets file or folder containing trusted root CAs
628 * @param path path to file with multiple PEM certif or to folder with multiple PEM files
630 void setRootCA(String path);
632 void setUploadBandwidth(int bw);
634 void setDownloadBandwidth(int bw);
637 * Sets audio packetization interval suggested for remote end.
638 * @param ptime packetization interval in milliseconds
640 void setDownloadPtime(int ptime);
643 * Sets audio packetization interval sent to remote end.
644 * @param ptime packetization interval in milliseconds
646 void setUploadPtime(int ptime);
648 void setPreferredVideoSize(VideoSize vSize);
650 VideoSize getPreferredVideoSize();
653 * Returns the currently supported audio codecs, as PayloadType elements
656 PayloadType[] getAudioCodecs();
658 * Returns the currently supported video codecs, as PayloadType elements
661 PayloadType[] getVideoCodecs();
663 * enable signaling keep alive. small udp packet sent periodically to keep udp NAT association
665 void enableKeepAlive(boolean enable);
667 * get keep elive mode
668 * @return true if enable
670 boolean isKeepAliveEnabled();
672 * Start an echo calibration of the sound devices, in order to find adequate settings for the echo canceler automatically.
673 * status is notified to {@link LinphoneCoreListener#ecCalibrationStatus(EcCalibratorStatus, int, Object)}
675 * @throws LinphoneCoreException if operation is still in progress;
677 void startEchoCalibration(Object data) throws LinphoneCoreException;
679 void enableIpv6(boolean enable);
680 void adjustSoftwareVolume(int i);
682 boolean pauseCall(LinphoneCall call);
683 boolean resumeCall(LinphoneCall call);
684 boolean pauseAllCalls();
686 void setZrtpSecretsCache(String file);
687 void enableEchoLimiter(boolean val);
689 boolean isInConference();
690 boolean enterConference();
691 void leaveConference();
693 void addToConference(LinphoneCall call);
694 void addAllToConference();
695 void removeFromConference(LinphoneCall call);
697 void terminateConference();
698 int getConferenceSize();
700 void terminateAllCalls();
701 LinphoneCall[] getCalls();
705 void transferCall(LinphoneCall call, String referTo);
706 void transferCallToAnother(LinphoneCall callToTransfer, LinphoneCall destination);
708 LinphoneCall findCallFromUri(String uri);
711 void setMaxCalls(int max);
712 boolean isMyself(String uri);
715 * Use this method to check the calls state and forbid proposing actions
716 * which could result in an active call.
717 * Eg: don't start a new call if one is in outgoing ringing.
718 * Eg: don't merge to conference either as it could result
719 * in two active calls (conference and accepted call).
722 boolean soundResourcesLocked();
724 * Returns whether given media encryption is supported by liblinphone.
726 boolean mediaEncryptionSupported(MediaEncryption menc);
728 * set media encryption (rtp) to use
729 * @params menc: MediaEncryption.None, MediaEncryption.SRTP or MediaEncryption.ZRTP
731 void setMediaEncryption(MediaEncryption menc);
733 * return selected media encryption
734 * @return MediaEncryption.None, MediaEncryption.SRTP or MediaEncryption.ZRTP
736 MediaEncryption getMediaEncryption();
738 * Set media encryption required for outgoing calls
740 void setMediaEncryptionMandatory(boolean yesno);
742 * @return if media encryption is required for outgoing calls
744 boolean isMediaEncryptionMandatory();
747 * @param path path to music file played to remote side when on hold.
749 void setPlayFile(String path);
750 void tunnelEnable(boolean enable);
751 void tunnelAutoDetect();
752 void tunnelCleanServers();
753 void tunnelSetHttpProxy(String proxy_host, int port, String username, String password);
755 * @param host tunnel server ip address
756 * @param port tunnel server tls port, recommended value is 443
757 * @param udpMirrorPort remote port on the tunnel server side used to test udp reachability
758 * @param roundTripDelay udp packet round trip delay in ms considered as acceptable. recommended value is 1000 ms
760 void tunnelAddServerAndMirror(String host, int port, int udpMirrorPort, int roundTripDelay);
762 boolean isTunnelAvailable();
764 LinphoneProxyConfig[] getProxyConfigList();
766 void setVideoPolicy(boolean autoInitiate, boolean autoAccept);
768 void setUserAgent(String name, String version);
770 void setCpuCount(int count);
775 public void removeCallLog(LinphoneCallLog log);
778 * @return count of missed calls
780 public int getMissedCallsCount();
783 * Set missed calls count to zero
785 public void resetMissedCallsCount();
787 * re-initiates registration if network is up.
789 public void refreshRegisters();
792 * return the version code of linphone core
794 public String getVersion();