00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 #ifndef __OPAL_MANAGER_H
00182 #define __OPAL_MANAGER_H
00183
00184 #ifdef P_USE_PRAGMA
00185 #pragma interface
00186 #endif
00187
00188 #include <opal/buildopts.h>
00189
00190 #include <opal/call.h>
00191 #include <opal/guid.h>
00192 #include <codec/silencedetect.h>
00193 #include <codec/echocancel.h>
00194 #include <ptclib/pstun.h>
00195
00196 class OpalEndPoint;
00197 class OpalMediaPatch;
00198
00199
00216 class OpalManager : public PObject
00217 {
00218 PCLASSINFO(OpalManager, PObject);
00219 public:
00224 OpalManager();
00225
00230 ~OpalManager();
00232
00242 void AttachEndPoint(
00243 OpalEndPoint * endpoint
00244 );
00245
00249 void DetachEndPoint(
00250 OpalEndPoint * endpoint
00251 );
00252
00255 OpalEndPoint * FindEndPoint(
00256 const PString & prefix
00257 );
00258
00261 const PList<OpalEndPoint> & GetEndPoints() const { return endpoints; }
00263
00285 virtual BOOL SetUpCall(
00286 const PString & partyA,
00287 const PString & partyB,
00288 PString & token,
00289 void * userData = NULL
00290 );
00291
00300 virtual void OnEstablishedCall(
00301 OpalCall & call
00302 );
00303
00309 virtual BOOL HasCall(
00310 const PString & token
00311 ) { return activeCalls.FindWithLock(token, PSafeReference) != NULL; }
00312
00319 virtual BOOL IsCallEstablished(
00320 const PString & token
00321 );
00322
00331 PSafePtr<OpalCall> FindCallWithLock(
00332 const PString & token,
00333 PSafetyMode mode = PSafeReadWrite
00334 ) { return activeCalls.FindWithLock(token, mode); }
00335
00343 virtual BOOL ClearCall(
00344 const PString & token,
00345 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00346 PSyncPoint * sync = NULL
00347 );
00348
00356 virtual BOOL ClearCallSynchronous(
00357 const PString & token,
00358 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser
00359 );
00360
00366 virtual void ClearAllCalls(
00367 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00368 BOOL wait = TRUE
00369 );
00370
00384 virtual void OnClearedCall(
00385 OpalCall & call
00386 );
00387
00396 virtual OpalCall * CreateCall();
00397 virtual OpalCall * CreateCall(
00398 void * userData
00399 );
00400
00409 virtual void DestroyCall(
00410 OpalCall * call
00411 );
00412
00416 PString GetNextCallToken();
00418
00455 virtual BOOL MakeConnection(
00456 OpalCall & call,
00457 const PString & party
00458 );
00459 virtual BOOL MakeConnection(
00460 OpalCall & call,
00461 const PString & party,
00462 void * userData
00463 );
00464
00491 virtual BOOL OnIncomingConnection(
00492 OpalConnection & connection
00493 );
00494
00501 virtual PString OnRouteConnection(
00502 OpalConnection & connection
00503 );
00504
00521 virtual void OnAlerting(
00522 OpalConnection & connection
00523 );
00524
00525 virtual OpalConnection::AnswerCallResponse
00526 OnAnswerCall(OpalConnection & connection,
00527 const PString & caller
00528 );
00529
00541 virtual void OnConnected(
00542 OpalConnection & connection
00543 );
00544
00557 virtual void OnEstablished(
00558 OpalConnection & connection
00559 );
00560
00576 virtual void OnReleased(
00577 OpalConnection & connection
00578 );
00579
00586 virtual void OnHold(
00587 OpalConnection & connection
00588 );
00589
00594 virtual BOOL OnForwarded(
00595 OpalConnection & connection,
00596 const PString & remoteParty
00597 );
00599
00611 virtual void AdjustMediaFormats(
00612 const OpalConnection & connection,
00613 OpalMediaFormatList & mediaFormats
00614 ) const;
00615
00618 virtual BOOL IsMediaBypassPossible(
00619 const OpalConnection & source,
00620 const OpalConnection & destination,
00621 unsigned sessionID
00622 ) const;
00623
00639 virtual BOOL OnOpenMediaStream(
00640 OpalConnection & connection,
00641 OpalMediaStream & stream
00642 );
00643
00648 virtual void OnClosedMediaStream(
00649 const OpalMediaStream & stream
00650 );
00651
00656 virtual void AddVideoMediaFormats(
00657 OpalMediaFormatList & mediaFormats,
00658 const OpalConnection * connection = NULL
00659 ) const;
00660
00663 virtual BOOL CreateVideoInputDevice(
00664 const OpalConnection & connection,
00665 const OpalMediaFormat & mediaFormat,
00666 PVideoInputDevice * & device,
00667 BOOL & autoDelete
00668 );
00669
00673 virtual BOOL CreateVideoOutputDevice(
00674 const OpalConnection & connection,
00675 const OpalMediaFormat & mediaFormat,
00676 BOOL preview,
00677 PVideoOutputDevice * & device,
00678 BOOL & autoDelete
00679 );
00680
00688 virtual OpalMediaPatch * CreateMediaPatch(
00689 OpalMediaStream & source
00690 );
00691
00696 virtual void DestroyMediaPatch(
00697 OpalMediaPatch * patch
00698 );
00699
00707 virtual BOOL OnStartMediaPatch(
00708 const OpalMediaPatch & patch
00709 );
00711
00719 virtual void OnUserInputString(
00720 OpalConnection & connection,
00721 const PString & value
00722 );
00723
00730 virtual void OnUserInputTone(
00731 OpalConnection & connection,
00732 char tone,
00733 int duration
00734 );
00736
00749 virtual OpalT120Protocol * CreateT120ProtocolHandler(
00750 const OpalConnection & connection
00751 ) const;
00752
00763 virtual OpalT38Protocol * CreateT38ProtocolHandler(
00764 const OpalConnection & connection
00765 ) const;
00766
00767 class RouteEntry : public PObject
00768 {
00769 PCLASSINFO(RouteEntry, PObject);
00770 public:
00771 RouteEntry(const PString & pat, const PString & dest);
00772 void PrintOn(ostream & strm) const;
00773 PString pattern;
00774 PString destination;
00775 PRegularExpression regex;
00776 };
00777 PLIST(RouteTable, RouteEntry);
00778
00805 virtual BOOL AddRouteEntry(
00806 const PString & spec
00807 );
00808
00815 BOOL SetRouteTable(
00816 const PStringArray & specs
00817 );
00818
00823 void SetRouteTable(
00824 const RouteTable & table
00825 );
00826
00829 const RouteTable & GetRouteTable() const { return routeTable; }
00830
00833 virtual PString ApplyRouteTable(
00834 const PString & proto,
00835 const PString & addr
00836 );
00838
00843 const PString & GetDefaultUserName() const { return defaultUserName; }
00844
00847 void SetDefaultUserName(
00848 const PString & name
00849 ) { defaultUserName = name; }
00850
00853 const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
00854
00857 void SetDefaultDisplayName(
00858 const PString & name
00859 ) { defaultDisplayName = name; }
00860
00863 BOOL CanAutoStartReceiveVideo() const { return autoStartReceiveVideo; }
00864
00867 void SetAutoStartReceiveVideo(BOOL can) { autoStartReceiveVideo = can; }
00868
00871 BOOL CanAutoStartTransmitVideo() const { return autoStartTransmitVideo; }
00872
00875 void SetAutoStartTransmitVideo(BOOL can) { autoStartTransmitVideo = can; }
00876
00883 virtual BOOL IsLocalAddress(
00884 const PIPSocket::Address & remoteAddress
00885 ) const;
00886
00893 virtual BOOL TranslateIPAddress(
00894 PIPSocket::Address & localAddress,
00895 const PIPSocket::Address & remoteAddress
00896 );
00897
00900 const PIPSocket::Address & GetTranslationAddress() const { return translationAddress; }
00901
00904 void SetTranslationAddress(
00905 const PIPSocket::Address & address
00906 ) { translationAddress = address; }
00907
00913 PSTUNClient * GetSTUN(
00914 const PIPSocket::Address & address = 0
00915 ) const;
00916
00921 PSTUNClient::NatTypes SetSTUNServer(
00922 const PString & server
00923 );
00924
00927 WORD GetTCPPortBase() const { return tcpPorts.base; }
00928
00931 WORD GetTCPPortMax() const { return tcpPorts.max; }
00932
00935 void SetTCPPorts(unsigned tcpBase, unsigned tcpMax);
00936
00939 WORD GetNextTCPPort();
00940
00943 WORD GetUDPPortBase() const { return udpPorts.base; }
00944
00947 WORD GetUDPPortMax() const { return udpPorts.max; }
00948
00951 void SetUDPPorts(unsigned udpBase, unsigned udpMax);
00952
00955 WORD GetNextUDPPort();
00956
00959 WORD GetRtpIpPortBase() const { return rtpIpPorts.base; }
00960
00963 WORD GetRtpIpPortMax() const { return rtpIpPorts.max; }
00964
00967 void SetRtpIpPorts(unsigned udpBase, unsigned udpMax);
00968
00971 WORD GetRtpIpPortPair();
00972
00975 BYTE GetRtpIpTypeofService() const { return rtpIpTypeofService; }
00976
00979 void SetRtpIpTypeofService(unsigned tos) { rtpIpTypeofService = (BYTE)tos; }
00980
00984 unsigned GetMinAudioJitterDelay() const { return minAudioJitterDelay; }
00985
00989 unsigned GetMaxAudioJitterDelay() const { return maxAudioJitterDelay; }
00990
00993 void SetAudioJitterDelay(
00994 unsigned minDelay,
00995 unsigned maxDelay
00996 );
00997
01000 const PStringArray & GetMediaFormatOrder() const { return mediaFormatOrder; }
01001
01004 void SetMediaFormatOrder(const PStringArray & order) { mediaFormatOrder = order; }
01005
01008 const PStringArray & GetMediaFormatMask() const { return mediaFormatMask; }
01009
01012 void SetMediaFormatMask(const PStringArray & mask) { mediaFormatMask = mask; }
01013
01016 virtual void SetSilenceDetectParams(
01017 const OpalSilenceDetector::Params & params
01018 ) { silenceDetectParams = params; }
01019
01022 const OpalSilenceDetector::Params & GetSilenceDetectParams() const { return silenceDetectParams; }
01023
01026 virtual void SetEchoCancelParams(
01027 const OpalEchoCanceler::Params & params
01028 ) { echoCancelParams = params; }
01029
01032 const OpalEchoCanceler::Params & GetEchoCancelParams() const { return echoCancelParams; }
01033
01041 virtual BOOL SetVideoInputDevice(
01042 const PVideoDevice::OpenArgs & deviceArgs
01043 );
01044
01048 const PVideoDevice::OpenArgs & GetVideoInputDevice() const { return videoInputDevice; }
01049
01057 virtual BOOL SetVideoPreviewDevice(
01058 const PVideoDevice::OpenArgs & deviceArgs
01059 );
01060
01064 const PVideoDevice::OpenArgs & GetVideoPreviewDevice() const { return videoPreviewDevice; }
01065
01073 virtual BOOL SetVideoOutputDevice(
01074 const PVideoDevice::OpenArgs & deviceArgs
01075 );
01076
01080 const PVideoDevice::OpenArgs & GetVideoOutputDevice() const { return videoOutputDevice; }
01081
01082 BOOL DetectInBandDTMFDisabled() const
01083 { return disableDetectInBandDTMF; }
01084
01087 void DisableDetectInBandDTMF(
01088 BOOL mode
01089 ) { disableDetectInBandDTMF = mode; }
01090
01093 const PTimeInterval & GetNoMediaTimeout() const { return noMediaTimeout; }
01094
01097 BOOL SetNoMediaTimeout(
01098 const PTimeInterval & newInterval
01099 );
01100
01103 const PString & GetDefaultILSServer() const { return ilsServer; }
01104
01107 void SetDefaultILSServer(
01108 const PString & server
01109 ) { ilsServer = server; }
01111
01112
01113 void GarbageCollection();
01114
01115 protected:
01116
01117 PString defaultUserName;
01118 PString defaultDisplayName;
01119 BOOL autoStartReceiveVideo;
01120 BOOL autoStartTransmitVideo;
01121 BYTE rtpIpTypeofService;
01122 unsigned minAudioJitterDelay;
01123 unsigned maxAudioJitterDelay;
01124 PStringArray mediaFormatOrder;
01125 PStringArray mediaFormatMask;
01126 BOOL disableDetectInBandDTMF;
01127 PTimeInterval noMediaTimeout;
01128 PString ilsServer;
01129
01130 OpalSilenceDetector::Params silenceDetectParams;
01131 OpalEchoCanceler::Params echoCancelParams;
01132
01133 PVideoDevice::OpenArgs videoInputDevice;
01134 PVideoDevice::OpenArgs videoPreviewDevice;
01135 PVideoDevice::OpenArgs videoOutputDevice;
01136
01137 struct PortInfo {
01138 void Set(
01139 unsigned base,
01140 unsigned max,
01141 unsigned range,
01142 unsigned dflt
01143 );
01144 WORD GetNext(
01145 unsigned increment
01146 );
01147
01148 PMutex mutex;
01149 WORD base;
01150 WORD max;
01151 WORD current;
01152 } tcpPorts, udpPorts, rtpIpPorts;
01153
01154 PIPSocket::Address translationAddress;
01155 PSTUNClient * stun;
01156
01157 RouteTable routeTable;
01158 PMutex routeTableMutex;
01159
01160
01161 PMutex inUseFlag;
01162
01163 PList<OpalEndPoint> endpoints;
01164
01165 unsigned lastCallTokenID;
01166
01167 class CallDict : public PSafeDictionary<PString, OpalCall>
01168 {
01169 public:
01170 CallDict(OpalManager & mgr) : manager(mgr) { }
01171 virtual void DeleteObject(PObject * object) const;
01172 OpalManager & manager;
01173 } activeCalls;
01174
01175 BOOL clearingAllCalls;
01176 PSyncPoint allCallsCleared;
01177 PThread * garbageCollector;
01178 PSyncPoint garbageCollectExit;
01179 PDECLARE_NOTIFIER(PThread, OpalManager, GarbageMain);
01180
01181 friend OpalCall::OpalCall(OpalManager & mgr);
01182 friend void OpalCall::OnReleased(OpalConnection & connection);
01183 };
01184
01185
01186 PString OpalGetVersion();
01187 unsigned OpalGetMajorVersion();
01188 unsigned OpalGetMinorVersion();
01189 unsigned OpalGetBuildNumber();
01190
01191
01192 #endif // __OPAL_MANAGER_H
01193
01194
01195