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
00182
00183
00184
00185 #ifndef __OPAL_MANAGER_H
00186 #define __OPAL_MANAGER_H
00187
00188 #ifdef P_USE_PRAGMA
00189 #pragma interface
00190 #endif
00191
00192 #include <opal/buildopts.h>
00193
00194 #include <opal/call.h>
00195 #include <opal/guid.h>
00196 #include <codec/silencedetect.h>
00197 #include <codec/echocancel.h>
00198
00199 #include <ptclib/pstun.h>
00200 #include <ptlib/videoio.h>
00201
00202 class OpalEndPoint;
00203 class OpalMediaPatch;
00204
00205
00222 class OpalManager : public PObject
00223 {
00224 PCLASSINFO(OpalManager, PObject);
00225 public:
00230 OpalManager();
00231
00236 ~OpalManager();
00238
00248 void AttachEndPoint(
00249 OpalEndPoint * endpoint
00250 );
00251
00255 void DetachEndPoint(
00256 OpalEndPoint * endpoint
00257 );
00258
00261 OpalEndPoint * FindEndPoint(
00262 const PString & prefix
00263 );
00264
00267 const PList<OpalEndPoint> & GetEndPoints() const { return endpoints; }
00269
00291 virtual BOOL SetUpCall(
00292 const PString & partyA,
00293 const PString & partyB,
00294 PString & token,
00295 void * userData = NULL
00296 );
00297
00306 virtual void OnEstablishedCall(
00307 OpalCall & call
00308 );
00309
00315 virtual BOOL HasCall(
00316 const PString & token
00317 ) { return activeCalls.FindWithLock(token, PSafeReference) != NULL; }
00318
00325 virtual BOOL IsCallEstablished(
00326 const PString & token
00327 );
00328
00337 PSafePtr<OpalCall> FindCallWithLock(
00338 const PString & token,
00339 PSafetyMode mode = PSafeReadWrite
00340 ) { return activeCalls.FindWithLock(token, mode); }
00341
00349 virtual BOOL ClearCall(
00350 const PString & token,
00351 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00352 PSyncPoint * sync = NULL
00353 );
00354
00362 virtual BOOL ClearCallSynchronous(
00363 const PString & token,
00364 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser
00365 );
00366
00372 virtual void ClearAllCalls(
00373 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00374 BOOL wait = TRUE
00375 );
00376
00390 virtual void OnClearedCall(
00391 OpalCall & call
00392 );
00393
00402 virtual OpalCall * CreateCall();
00403 virtual OpalCall * CreateCall(
00404 void * userData
00405 );
00406
00415 virtual void DestroyCall(
00416 OpalCall * call
00417 );
00418
00422 PString GetNextCallToken();
00424
00461 virtual BOOL MakeConnection(
00462 OpalCall & call,
00463 const PString & party
00464 );
00465 virtual BOOL MakeConnection(
00466 OpalCall & call,
00467 const PString & party,
00468 void * userData
00469 );
00470
00497 virtual BOOL OnIncomingConnection(
00498 OpalConnection & connection
00499 );
00500
00507 virtual PString OnRouteConnection(
00508 OpalConnection & connection
00509 );
00510
00527 virtual void OnAlerting(
00528 OpalConnection & connection
00529 );
00530
00531 virtual OpalConnection::AnswerCallResponse
00532 OnAnswerCall(OpalConnection & connection,
00533 const PString & caller
00534 );
00535
00547 virtual void OnConnected(
00548 OpalConnection & connection
00549 );
00550
00563 virtual void OnEstablished(
00564 OpalConnection & connection
00565 );
00566
00582 virtual void OnReleased(
00583 OpalConnection & connection
00584 );
00585
00592 virtual void OnHold(
00593 OpalConnection & connection
00594 );
00595
00600 virtual BOOL OnForwarded(
00601 OpalConnection & connection,
00602 const PString & remoteParty
00603 );
00605
00617 virtual void AdjustMediaFormats(
00618 const OpalConnection & connection,
00619 OpalMediaFormatList & mediaFormats
00620 ) const;
00621
00624 virtual BOOL IsMediaBypassPossible(
00625 const OpalConnection & source,
00626 const OpalConnection & destination,
00627 unsigned sessionID
00628 ) const;
00629
00645 virtual BOOL OnOpenMediaStream(
00646 OpalConnection & connection,
00647 OpalMediaStream & stream
00648 );
00649
00654 virtual void OnClosedMediaStream(
00655 const OpalMediaStream & stream
00656 );
00657
00662 virtual void AddVideoMediaFormats(
00663 OpalMediaFormatList & mediaFormats,
00664 const OpalConnection * connection = NULL
00665 ) const;
00666
00669 virtual BOOL CreateVideoInputDevice(
00670 const OpalConnection & connection,
00671 const OpalMediaFormat & mediaFormat,
00672 PVideoInputDevice * & device,
00673 BOOL & autoDelete
00674 );
00675
00679 virtual BOOL CreateVideoOutputDevice(
00680 const OpalConnection & connection,
00681 const OpalMediaFormat & mediaFormat,
00682 BOOL preview,
00683 PVideoOutputDevice * & device,
00684 BOOL & autoDelete
00685 );
00686
00694 virtual OpalMediaPatch * CreateMediaPatch(
00695 OpalMediaStream & source
00696 );
00697
00702 virtual void DestroyMediaPatch(
00703 OpalMediaPatch * patch
00704 );
00705
00713 virtual BOOL OnStartMediaPatch(
00714 const OpalMediaPatch & patch
00715 );
00717
00725 virtual void OnUserInputString(
00726 OpalConnection & connection,
00727 const PString & value
00728 );
00729
00736 virtual void OnUserInputTone(
00737 OpalConnection & connection,
00738 char tone,
00739 int duration
00740 );
00742
00755 virtual OpalT120Protocol * CreateT120ProtocolHandler(
00756 const OpalConnection & connection
00757 ) const;
00758
00769 virtual OpalT38Protocol * CreateT38ProtocolHandler(
00770 const OpalConnection & connection
00771 ) const;
00772
00773 class RouteEntry : public PObject
00774 {
00775 PCLASSINFO(RouteEntry, PObject);
00776 public:
00777 RouteEntry(const PString & pat, const PString & dest);
00778 void PrintOn(ostream & strm) const;
00779 PString pattern;
00780 PString destination;
00781 PRegularExpression regex;
00782 };
00783 PLIST(RouteTable, RouteEntry);
00784
00811 virtual BOOL AddRouteEntry(
00812 const PString & spec
00813 );
00814
00821 BOOL SetRouteTable(
00822 const PStringArray & specs
00823 );
00824
00829 void SetRouteTable(
00830 const RouteTable & table
00831 );
00832
00835 const RouteTable & GetRouteTable() const { return routeTable; }
00836
00839 virtual PString ApplyRouteTable(
00840 const PString & proto,
00841 const PString & addr
00842 );
00844
00849 const PString & GetDefaultUserName() const { return defaultUserName; }
00850
00853 void SetDefaultUserName(
00854 const PString & name
00855 ) { defaultUserName = name; }
00856
00859 const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
00860
00863 void SetDefaultDisplayName(
00864 const PString & name
00865 ) { defaultDisplayName = name; }
00866
00869 BOOL CanAutoStartReceiveVideo() const { return autoStartReceiveVideo; }
00870
00873 void SetAutoStartReceiveVideo(BOOL can) { autoStartReceiveVideo = can; }
00874
00877 BOOL CanAutoStartTransmitVideo() const { return autoStartTransmitVideo; }
00878
00881 void SetAutoStartTransmitVideo(BOOL can) { autoStartTransmitVideo = can; }
00882
00889 virtual BOOL IsLocalAddress(
00890 const PIPSocket::Address & remoteAddress
00891 ) const;
00892
00899 virtual BOOL TranslateIPAddress(
00900 PIPSocket::Address & localAddress,
00901 const PIPSocket::Address & remoteAddress
00902 );
00903
00906 const PIPSocket::Address & GetTranslationAddress() const { return translationAddress; }
00907
00910 void SetTranslationAddress(
00911 const PIPSocket::Address & address
00912 ) { translationAddress = address; }
00913
00919 PSTUNClient * GetSTUN(
00920 const PIPSocket::Address & address = 0
00921 ) const;
00922
00927 PSTUNClient::NatTypes SetSTUNServer(
00928 const PString & server
00929 );
00930
00933 WORD GetTCPPortBase() const { return tcpPorts.base; }
00934
00937 WORD GetTCPPortMax() const { return tcpPorts.max; }
00938
00941 void SetTCPPorts(unsigned tcpBase, unsigned tcpMax);
00942
00945 WORD GetNextTCPPort();
00946
00949 WORD GetUDPPortBase() const { return udpPorts.base; }
00950
00953 WORD GetUDPPortMax() const { return udpPorts.max; }
00954
00957 void SetUDPPorts(unsigned udpBase, unsigned udpMax);
00958
00961 WORD GetNextUDPPort();
00962
00965 WORD GetRtpIpPortBase() const { return rtpIpPorts.base; }
00966
00969 WORD GetRtpIpPortMax() const { return rtpIpPorts.max; }
00970
00973 void SetRtpIpPorts(unsigned udpBase, unsigned udpMax);
00974
00977 WORD GetRtpIpPortPair();
00978
00981 BYTE GetRtpIpTypeofService() const { return rtpIpTypeofService; }
00982
00985 void SetRtpIpTypeofService(unsigned tos) { rtpIpTypeofService = (BYTE)tos; }
00986
00990 unsigned GetMinAudioJitterDelay() const { return minAudioJitterDelay; }
00991
00995 unsigned GetMaxAudioJitterDelay() const { return maxAudioJitterDelay; }
00996
00999 void SetAudioJitterDelay(
01000 unsigned minDelay,
01001 unsigned maxDelay
01002 );
01003
01006 const PStringArray & GetMediaFormatOrder() const { return mediaFormatOrder; }
01007
01010 void SetMediaFormatOrder(const PStringArray & order) { mediaFormatOrder = order; }
01011
01014 const PStringArray & GetMediaFormatMask() const { return mediaFormatMask; }
01015
01018 void SetMediaFormatMask(const PStringArray & mask) { mediaFormatMask = mask; }
01019
01022 virtual void SetSilenceDetectParams(
01023 const OpalSilenceDetector::Params & params
01024 ) { silenceDetectParams = params; }
01025
01028 const OpalSilenceDetector::Params & GetSilenceDetectParams() const { return silenceDetectParams; }
01029
01032 virtual void SetEchoCancelParams(
01033 const OpalEchoCanceler::Params & params
01034 ) { echoCancelParams = params; }
01035
01038 const OpalEchoCanceler::Params & GetEchoCancelParams() const { return echoCancelParams; }
01039
01047 virtual BOOL SetVideoInputDevice(
01048 const PVideoDevice::OpenArgs & deviceArgs
01049 );
01050
01054 const PVideoDevice::OpenArgs & GetVideoInputDevice() const { return videoInputDevice; }
01055
01063 virtual BOOL SetVideoPreviewDevice(
01064 const PVideoDevice::OpenArgs & deviceArgs
01065 );
01066
01070 const PVideoDevice::OpenArgs & GetVideoPreviewDevice() const { return videoPreviewDevice; }
01071
01079 virtual BOOL SetVideoOutputDevice(
01080 const PVideoDevice::OpenArgs & deviceArgs
01081 );
01082
01086 const PVideoDevice::OpenArgs & GetVideoOutputDevice() const { return videoOutputDevice; }
01087
01088 BOOL DetectInBandDTMFDisabled() const
01089 { return disableDetectInBandDTMF; }
01090
01093 void DisableDetectInBandDTMF(
01094 BOOL mode
01095 ) { disableDetectInBandDTMF = mode; }
01096
01099 const PTimeInterval & GetNoMediaTimeout() const { return noMediaTimeout; }
01100
01103 BOOL SetNoMediaTimeout(
01104 const PTimeInterval & newInterval
01105 );
01106
01109 const PString & GetDefaultILSServer() const { return ilsServer; }
01110
01113 void SetDefaultILSServer(
01114 const PString & server
01115 ) { ilsServer = server; }
01117
01118
01119 void GarbageCollection();
01120
01121 protected:
01122
01123 PString defaultUserName;
01124 PString defaultDisplayName;
01125 BOOL autoStartReceiveVideo;
01126 BOOL autoStartTransmitVideo;
01127 BYTE rtpIpTypeofService;
01128 unsigned minAudioJitterDelay;
01129 unsigned maxAudioJitterDelay;
01130 PStringArray mediaFormatOrder;
01131 PStringArray mediaFormatMask;
01132 BOOL disableDetectInBandDTMF;
01133 PTimeInterval noMediaTimeout;
01134 PString ilsServer;
01135
01136 OpalSilenceDetector::Params silenceDetectParams;
01137 OpalEchoCanceler::Params echoCancelParams;
01138
01139 PVideoDevice::OpenArgs videoInputDevice;
01140 PVideoDevice::OpenArgs videoPreviewDevice;
01141 PVideoDevice::OpenArgs videoOutputDevice;
01142
01143 struct PortInfo {
01144 void Set(
01145 unsigned base,
01146 unsigned max,
01147 unsigned range,
01148 unsigned dflt
01149 );
01150 WORD GetNext(
01151 unsigned increment
01152 );
01153
01154 PMutex mutex;
01155 WORD base;
01156 WORD max;
01157 WORD current;
01158 } tcpPorts, udpPorts, rtpIpPorts;
01159
01160 PIPSocket::Address translationAddress;
01161 PSTUNClient * stun;
01162
01163 RouteTable routeTable;
01164 PMutex routeTableMutex;
01165
01166
01167 PMutex inUseFlag;
01168
01169 PList<OpalEndPoint> endpoints;
01170
01171 unsigned lastCallTokenID;
01172
01173 class CallDict : public PSafeDictionary<PString, OpalCall>
01174 {
01175 public:
01176 CallDict(OpalManager & mgr) : manager(mgr) { }
01177 virtual void DeleteObject(PObject * object) const;
01178 OpalManager & manager;
01179 } activeCalls;
01180
01181 BOOL clearingAllCalls;
01182 PSyncPoint allCallsCleared;
01183 PThread * garbageCollector;
01184 PSyncPoint garbageCollectExit;
01185 PDECLARE_NOTIFIER(PThread, OpalManager, GarbageMain);
01186
01187 friend OpalCall::OpalCall(OpalManager & mgr);
01188 friend void OpalCall::OnReleased(OpalConnection & connection);
01189 };
01190
01191
01192 PString OpalGetVersion();
01193 unsigned OpalGetMajorVersion();
01194 unsigned OpalGetMinorVersion();
01195 unsigned OpalGetBuildNumber();
01196
01197
01198 #endif // __OPAL_MANAGER_H
01199
01200
01201