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;
24 * Linphone core main object created by method {@link LinphoneCoreFactory#createLinphoneCore(LinphoneCoreListener, String, String, Object)}.
28 public interface LinphoneCore {
30 * linphone core states
32 static public class GlobalState {
34 static private Vector<GlobalState> values = new Vector<GlobalState>();
38 static public GlobalState GlobalOff = new GlobalState(0,"GlobalOff");
42 static public GlobalState GlobalStartup = new GlobalState(1,"GlobalStartup");
46 static public GlobalState GlobalOn = new GlobalState(2,"GlobalOn");
50 static public GlobalState GlobalShutdown = new GlobalState(3,"GlobalShutdown");
52 private final int mValue;
53 private final String mStringValue;
56 private GlobalState(int value,String stringValue) {
58 values.addElement(this);
59 mStringValue=stringValue;
61 public static GlobalState fromInt(int value) {
63 for (int i=0; i<values.size();i++) {
64 GlobalState state = (GlobalState) values.elementAt(i);
65 if (state.mValue == value) return state;
67 throw new RuntimeException("state not found ["+value+"]");
69 public String toString() {
74 * Describes proxy registration states.
77 static public class RegistrationState {
79 private static Vector<RegistrationState> values = new Vector<RegistrationState>();
83 public static RegistrationState RegistrationNone = new RegistrationState(0,"RegistrationNone");
87 public static RegistrationState RegistrationProgress = new RegistrationState(1,"RegistrationProgress");
91 public static RegistrationState RegistrationOk = new RegistrationState(2,"RegistrationOk");
95 public static RegistrationState RegistrationCleared = new RegistrationState(3,"RegistrationCleared");
99 public static RegistrationState RegistrationFailed = new RegistrationState(4,"RegistrationFailed");
100 private final int mValue;
101 private final String mStringValue;
104 private RegistrationState(int value,String stringValue) {
106 values.addElement(this);
107 mStringValue=stringValue;
109 public static RegistrationState fromInt(int value) {
111 for (int i=0; i<values.size();i++) {
112 RegistrationState state = (RegistrationState) values.elementAt(i);
113 if (state.mValue == value) return state;
115 throw new RuntimeException("state not found ["+value+"]");
117 public String toString() {
122 * Describes firewall policy.
125 static public class FirewallPolicy {
127 static private Vector<FirewallPolicy> values = new Vector<FirewallPolicy>();
129 * No firewall is assumed.
131 static public FirewallPolicy NoFirewall = new FirewallPolicy(0,"NoFirewall");
133 * Use NAT address (discouraged)
135 static public FirewallPolicy UseNatAddress = new FirewallPolicy(1,"UseNatAddress");
137 * Use stun server to discover RTP addresses and ports.
139 static public FirewallPolicy UseStun = new FirewallPolicy(2,"UseStun");
143 static public FirewallPolicy UseIce = new FirewallPolicy(3,"UseIce");
145 private final int mValue;
146 private final String mStringValue;
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) {
184 public String toString() {
185 return "udp["+udp+"] tcp["+tcp+"] tls["+tls+"]";
189 * Media (RTP) encryption enum-like.
192 static public final class MediaEncryption {
194 static private Vector<MediaEncryption> values = new Vector<MediaEncryption>();
198 static public final MediaEncryption None = new MediaEncryption(0,"None");
202 static public final MediaEncryption SRTP = new MediaEncryption(1,"SRTP");
206 static public final MediaEncryption ZRTP = new MediaEncryption(2,"ZRTP");
207 protected final int mValue;
208 private final String mStringValue;
211 private MediaEncryption(int value,String stringValue) {
213 values.addElement(this);
214 mStringValue=stringValue;
216 public static MediaEncryption fromInt(int value) {
218 for (int i=0; i<values.size();i++) {
219 MediaEncryption menc = (MediaEncryption) values.elementAt(i);
220 if (menc.mValue == value) return menc;
222 throw new RuntimeException("MediaEncryption not found ["+value+"]");
224 public String toString() {
229 * EC Calibrator Status
231 static public class EcCalibratorStatus {
233 static private Vector<EcCalibratorStatus> values = new Vector<EcCalibratorStatus>();
234 /* Do not change the values of these constants or the strings associated with them to prevent breaking
235 the collection of echo canceller calibration results during the wizard! */
236 public static final int IN_PROGRESS_STATUS=0;
237 public static final int DONE_STATUS=1;
238 public static final int FAILED_STATUS=2;
239 public static final int DONE_NO_ECHO_STATUS=3;
241 * Calibration in progress
243 static public EcCalibratorStatus InProgress = new EcCalibratorStatus(IN_PROGRESS_STATUS,"InProgress");
245 * Calibration done that produced an echo delay measure
247 static public EcCalibratorStatus Done = new EcCalibratorStatus(DONE_STATUS,"Done");
251 static public EcCalibratorStatus Failed = new EcCalibratorStatus(FAILED_STATUS,"Failed");
253 * Calibration done with no echo detected
255 static public EcCalibratorStatus DoneNoEcho = new EcCalibratorStatus(DONE_NO_ECHO_STATUS, "DoneNoEcho");
257 private final int mValue;
258 private final String mStringValue;
261 private EcCalibratorStatus(int value,String stringValue) {
263 values.addElement(this);
264 mStringValue=stringValue;
266 public static EcCalibratorStatus fromInt(int value) {
268 for (int i=0; i<values.size();i++) {
269 EcCalibratorStatus status = (EcCalibratorStatus) values.elementAt(i);
270 if (status.mValue == value) return status;
272 throw new RuntimeException("status not found ["+value+"]");
274 public String toString() {
283 * Set the context of creation of the LinphoneCore.
285 public void setContext(Object context);
288 * clear all added proxy configs
290 public void clearProxyConfigs();
292 * Add a proxy configuration. This will start registration on the proxy, if registration is enabled.
294 * @throws LinphoneCoreException
296 public void addProxyConfig(LinphoneProxyConfig proxyCfg) throws LinphoneCoreException;
298 * Sets the default proxy.
300 * This default proxy must be part of the list of already entered {@link LinphoneProxyConfig}.
301 * Toggling it as default will make LinphoneCore use the identity associated with the proxy configuration in all incoming and outgoing calls.
304 public void setDefaultProxyConfig(LinphoneProxyConfig proxyCfg);
307 * get he default proxy configuration, that is the one used to determine the current identity.
308 * @return null if no default proxy config
310 public LinphoneProxyConfig getDefaultProxyConfig() ;
313 * clear all the added auth info
315 void clearAuthInfos();
317 * Adds authentication information to the LinphoneCore.
318 * <br>This information will be used during all SIP transacations that require authentication.
321 void addAuthInfo(LinphoneAuthInfo info);
324 * Build an address according to the current proxy config. In case destination is not a sip address, the default proxy domain is automatically appended
327 * @throws If no LinphoneAddress can be built from destination
329 public LinphoneAddress interpretUrl(String destination) throws LinphoneCoreException;
332 * Starts a call given a destination. Internally calls {@link #interpretUrl(String)} then {@link #invite(LinphoneAddress)}.
335 public LinphoneCall invite(String destination)throws LinphoneCoreException;
337 * Initiates an outgoing call given a destination LinphoneAddress
338 *<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.
339 * @param to the destination of the call (sip address).
340 * @return LinphoneCall
341 * @throws LinphoneCoreException
343 public LinphoneCall invite(LinphoneAddress to)throws LinphoneCoreException;
346 * @param aCall to be terminated
348 public void terminateCall(LinphoneCall aCall);
350 * Returns The LinphoneCall the current call if one is in call
353 public LinphoneCall getCurrentCall();
356 * get current call remote address in case of in/out call
357 * @return null if no call engaged yet
359 public LinphoneAddress getRemoteAddress();
362 * @return TRUE if there is a call running or pending.
364 public boolean isIncall();
367 * @return Returns true if in incoming call is pending, ie waiting for being answered or declined.
369 public boolean isInComingInvitePending();
371 * Main loop function. It is crucial that your application call it periodically.
373 * #iterate() performs various backgrounds tasks:
374 * <li>receiving of SIP messages
375 * <li> handles timers and timeout
376 * <li> performs registration to proxies
377 * <li> authentication retries The application MUST call this function from periodically, in its main loop.
378 * <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.
381 public void iterate();
383 * Accept an incoming call.
385 * Basically the application is notified of incoming calls within the
386 * {@link LinphoneCoreListener#callState} listener method.
387 * The application can later respond positively to the call using
389 * @throws LinphoneCoreException
391 public void acceptCall(LinphoneCall aCall) throws LinphoneCoreException;
394 * Accept an incoming call.
396 * Basically the application is notified of incoming calls within the
397 * {@link LinphoneCoreListener#callState} listener method.
398 * The application can later respond positively to the call using
400 * @throws LinphoneCoreException
402 public void acceptCallWithParams(LinphoneCall aCall, LinphoneCallParams params) throws LinphoneCoreException;
405 * Accept call modifications initiated by other end.
407 * Basically the application is notified of incoming calls within the
408 * {@link LinphoneCoreListener#callState} listener method.
409 * The application can later respond positively to the call using
411 * @throws LinphoneCoreException
413 public void acceptCallUpdate(LinphoneCall aCall, LinphoneCallParams params) throws LinphoneCoreException;
417 * Prevent LinphoneCore from performing an automatic answer
419 * Basically the application is notified of incoming calls within the
420 * {@link LinphoneCoreListener#callState} listener method.
421 * The application can later respond positively to the call using
423 * @throws LinphoneCoreException
425 public void deferCallUpdate(LinphoneCall aCall) throws LinphoneCoreException;
427 public void startRinging();
430 * @return a list of LinphoneCallLog
432 public LinphoneCallLog[] getCallLogs();
435 * This method is called by the application to notify the Linphone core library when network is reachable.
436 * Calling this method with true trigger Linphone to initiate a registration process for all proxy
437 * configuration with parameter register set to enable.
438 * This method disable the automatic registration mode. It means you must call this method after each network state changes
439 * @param network state
442 public void setNetworkReachable(boolean isReachable);
445 * @return if false, there is no network connection.
447 public boolean isNetworkReachable();
449 * destroy linphone core and free all underlying resources
451 public void destroy();
453 * Allow to control play level before entering sound card:
456 public void setPlaybackGain(float gain);
458 * get play level before entering sound card:
459 * @return level in db
461 public float getPlaybackGain();
464 * @param level [0..100]
466 public void setPlayLevel(int level);
468 * get playback level [0..100];
469 * -1 if not cannot be determined
472 public int getPlayLevel();
474 * Mutes or unmutes the local microphone.
477 void muteMic(boolean isMuted);
480 * @return true is mic is muted
482 boolean isMicMuted();
485 * Initiate a dtmf signal if in call
488 void sendDtmf(char number);
490 * Initiate a dtmf signal to the speaker if not in call.
491 * Sending of the DTMF is done in another function.
493 * @param duration in ms , -1 for unlimited
495 void playDtmf(char number,int duration);
502 * remove all call logs
504 void clearCallLogs();
506 * get payload type from mime type, clock rate, and number of channels.-
508 * return null if not found
510 PayloadType findPayloadType(String mime, int clockRate, int channels);
512 * get payload type from mime type and clock rate..
514 * return null if not found
516 PayloadType findPayloadType(String mime, int clockRate);
518 * not implemented yet
521 * @throws LinphoneCoreException
523 void enablePayloadType(PayloadType pt, boolean enable) throws LinphoneCoreException;
525 * Enables or disable echo cancellation.
528 void enableEchoCancellation(boolean enable);
531 * @return true if echo cancellation is enabled.
533 boolean isEchoCancellationEnabled();
535 * Get echo limiter status (another method of doing echo suppression, more brute force)
536 * @return true if echo limiter is enabled
538 boolean isEchoLimiterEnabled();
540 * @param transports used for signaling (TCP, UDP and TLS)
542 void setSignalingTransportPorts(Transports transports);
544 * @return transports used for signaling (TCP, UDP, TLS)
546 Transports getSignalingTransportPorts();
548 * Activates or deactivates the speaker.
551 void enableSpeaker(boolean value);
553 * Tells whether the speaker is activated.
554 * @return true if speaker enabled, false otherwise
556 boolean isSpeakerEnabled();
558 * add a friend to the current buddy list, if subscription attribute is set, a SIP SUBSCRIBE message is sent.
559 * @param lf LinphoenFriend to add
560 * @throws LinphoneCoreException
562 void addFriend(LinphoneFriend lf) throws LinphoneCoreException;
565 * Set my presence status
566 * @param minute_away how long in away
567 * @param status sip uri used to redirect call in state LinphoneStatusMoved
569 void setPresenceInfo(int minute_away,String alternative_contact, OnlineStatus status);
571 * Create a new chat room for messaging from a sip uri like sip:joe@sip.linphone.org
572 * @param to destination address for messages
574 * @return {@link LinphoneChatRoom} where messaging can take place.
576 LinphoneChatRoom createChatRoom(String to);
578 void setVideoWindow(Object w);
579 void setPreviewWindow(Object w);
580 void setDeviceRotation(int rotation);
582 void setVideoDevice(int id);
583 int getVideoDevice();
586 * Enables video globally.
589 * This function does not have any effect during calls. It just indicates #LinphoneCore to
590 * initiate future calls with video or not. The two boolean parameters indicate in which
591 * direction video is enabled. Setting both to false disables video entirely.
593 * @param vcap_enabled indicates whether video capture is enabled
594 * @param display_enabled indicates whether video display should be shown
597 void enableVideo(boolean vcap_enabled, boolean display_enabled);
599 * Returns TRUE if video is enabled, FALSE otherwise.
602 boolean isVideoEnabled();
605 * Specify a STUN server to help firewall traversal.
606 * @param stun_server Stun server address and port, such as stun.linphone.org or stun.linphone.org:3478
608 void setStunServer(String stun_server);
610 * @return stun server address if previously set.
612 String getStunServer();
615 * Sets policy regarding workarounding NATs
616 * @param pol one of the FirewallPolicy members.
618 void setFirewallPolicy(FirewallPolicy pol);
620 * @return previously set firewall policy.
622 FirewallPolicy getFirewallPolicy();
624 LinphoneCall inviteAddressWithParams(LinphoneAddress destination, LinphoneCallParams params) throws LinphoneCoreException ;
626 int updateCall(LinphoneCall call, LinphoneCallParams params);
628 LinphoneCallParams createDefaultCallParameters();
631 * Sets the path to a wav file used for ringing.
633 * @param path The file must be a wav 16bit linear. Local ring is disabled if null
635 void setRing(String path);
637 * gets the path to a wav file used for ringing.
639 * @param null if not set
644 * Sets file or folder containing trusted root CAs
646 * @param path path to file with multiple PEM certif or to folder with multiple PEM files
648 void setRootCA(String path);
650 void setUploadBandwidth(int bw);
652 void setDownloadBandwidth(int bw);
655 * Sets audio packetization interval suggested for remote end.
656 * @param ptime packetization interval in milliseconds
658 void setDownloadPtime(int ptime);
661 * Sets audio packetization interval sent to remote end.
662 * @param ptime packetization interval in milliseconds
664 void setUploadPtime(int ptime);
666 void setPreferredVideoSize(VideoSize vSize);
668 VideoSize getPreferredVideoSize();
671 * Returns the currently supported audio codecs, as PayloadType elements
674 PayloadType[] getAudioCodecs();
676 * Returns the currently supported video codecs, as PayloadType elements
679 PayloadType[] getVideoCodecs();
681 * enable signaling keep alive. small udp packet sent periodically to keep udp NAT association
683 void enableKeepAlive(boolean enable);
685 * get keep elive mode
686 * @return true if enable
688 boolean isKeepAliveEnabled();
690 * Start an echo calibration of the sound devices, in order to find adequate settings for the echo canceler automatically.
691 * status is notified to {@link LinphoneCoreListener#ecCalibrationStatus(EcCalibratorStatus, int, Object)}
693 * @throws LinphoneCoreException if operation is still in progress;
695 void startEchoCalibration(Object data) throws LinphoneCoreException;
697 void enableIpv6(boolean enable);
702 void adjustSoftwareVolume(int i);
704 boolean pauseCall(LinphoneCall call);
705 boolean resumeCall(LinphoneCall call);
706 boolean pauseAllCalls();
708 void setZrtpSecretsCache(String file);
709 void enableEchoLimiter(boolean val);
711 boolean isInConference();
712 boolean enterConference();
713 void leaveConference();
715 void addToConference(LinphoneCall call);
716 void addAllToConference();
717 void removeFromConference(LinphoneCall call);
719 void terminateConference();
720 int getConferenceSize();
722 void terminateAllCalls();
723 LinphoneCall[] getCalls();
727 void transferCall(LinphoneCall call, String referTo);
728 void transferCallToAnother(LinphoneCall callToTransfer, LinphoneCall destination);
730 LinphoneCall findCallFromUri(String uri);
733 void setMaxCalls(int max);
734 boolean isMyself(String uri);
737 * Use this method to check the calls state and forbid proposing actions
738 * which could result in an active call.
739 * Eg: don't start a new call if one is in outgoing ringing.
740 * Eg: don't merge to conference either as it could result
741 * in two active calls (conference and accepted call).
744 boolean soundResourcesLocked();
746 * Returns whether given media encryption is supported by liblinphone.
748 boolean mediaEncryptionSupported(MediaEncryption menc);
750 * set media encryption (rtp) to use
751 * @params menc: MediaEncryption.None, MediaEncryption.SRTP or MediaEncryption.ZRTP
753 void setMediaEncryption(MediaEncryption menc);
755 * return selected media encryption
756 * @return MediaEncryption.None, MediaEncryption.SRTP or MediaEncryption.ZRTP
758 MediaEncryption getMediaEncryption();
760 * Set media encryption required for outgoing calls
762 void setMediaEncryptionMandatory(boolean yesno);
764 * @return if media encryption is required for outgoing calls
766 boolean isMediaEncryptionMandatory();
769 * @param path path to music file played to remote side when on hold.
771 void setPlayFile(String path);
772 void tunnelEnable(boolean enable);
773 void tunnelAutoDetect();
774 void tunnelCleanServers();
775 void tunnelSetHttpProxy(String proxy_host, int port, String username, String password);
777 * @param host tunnel server ip address
778 * @param port tunnel server tls port, recommended value is 443
779 * @param udpMirrorPort remote port on the tunnel server side used to test udp reachability
780 * @param roundTripDelay udp packet round trip delay in ms considered as acceptable. recommended value is 1000 ms
782 void tunnelAddServerAndMirror(String host, int port, int udpMirrorPort, int roundTripDelay);
784 boolean isTunnelAvailable();
786 LinphoneProxyConfig[] getProxyConfigList();
788 void setVideoPolicy(boolean autoInitiate, boolean autoAccept);
790 void setStaticPicture(String path);
792 void setUserAgent(String name, String version);
794 void setCpuCount(int count);
799 public void removeCallLog(LinphoneCallLog log);
802 * @return count of missed calls
804 public int getMissedCallsCount();
807 * Set missed calls count to zero
809 public void resetMissedCallsCount();
811 * re-initiates registration if network is up.
813 public void refreshRegisters();
816 * return the version code of linphone core
818 public String getVersion();
821 * remove a linphone friend from linphone core and linphonerc
823 void removeFriend(LinphoneFriend lf);
826 * return a linphone friend (if exists) that matches the sip address
828 LinphoneFriend findFriendByAddress(String sipUri);
831 * Sets the UDP port used for audio streaming.
833 void setAudioPort(int port);
836 * Sets the UDP port range from which to randomly select the port used for audio streaming.
838 void setAudioPortRange(int minPort, int maxPort);
841 * Sets the UDP port used for video streaming.
843 void setVideoPort(int port);
846 * Sets the UDP port range from which to randomly select the port used for video streaming.
848 void setVideoPortRange(int minPort, int maxPort);
851 * Set the incoming call timeout in seconds.
852 * If an incoming call isn't answered for this timeout period, it is
853 * automatically declined.
855 void setIncomingTimeout(int timeout);
858 * Set the call timeout in seconds.
859 * Once this time is elapsed (ringing included), the call is automatically hung up.
861 void setInCallTimeout(int timeout);
863 void setMicrophoneGain(float gain);
866 * Set username and display name to use if no LinphoneProxyConfig configured
868 void setPrimaryContact(String displayName, String username);
871 * Enable/Disable the use of SIP INFO for DTMFs
873 void setUseSipInfoForDtmfs(boolean use);
876 * Enable/Disable the use of inband DTMFs
878 void setUseRfc2833ForDtmfs(boolean use);
881 * @return returns LpConfig object to read/write to the config file: usefull if you wish to extend
882 * the config file with your own sections
884 LpConfig getConfig();