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
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264 #ifndef __OPAL_MANAGER_H
00265 #define __OPAL_MANAGER_H
00266
00267 #ifdef P_USE_PRAGMA
00268 #pragma interface
00269 #endif
00270
00271 #include <opal/buildopts.h>
00272
00273 #include <opal/call.h>
00274 #include <opal/connection.h>
00275 #include <opal/guid.h>
00276 #include <opal/audiorecord.h>
00277 #include <codec/silencedetect.h>
00278 #include <codec/echocancel.h>
00279 #include <ptclib/pstun.h>
00280
00281 #if OPAL_VIDEO
00282 #include <ptlib/videoio.h>
00283 #endif
00284
00285 class OpalEndPoint;
00286 class OpalMediaPatch;
00287 class OpalH224Handler;
00288 class OpalH281Handler;
00289
00290
00307 class OpalManager : public PObject
00308 {
00309 PCLASSINFO(OpalManager, PObject);
00310 public:
00315 OpalManager();
00316
00321 ~OpalManager();
00323
00333 void AttachEndPoint(
00334 OpalEndPoint * endpoint
00335 );
00336
00340 void DetachEndPoint(
00341 OpalEndPoint * endpoint
00342 );
00343
00346 OpalEndPoint * FindEndPoint(
00347 const PString & prefix
00348 );
00349
00352 const PList<OpalEndPoint> & GetEndPoints() const { return endpoints; }
00354
00376 virtual BOOL SetUpCall(
00377 const PString & partyA,
00378 const PString & partyB,
00379 PString & token,
00380 void * userData = NULL,
00381 unsigned options = 0,
00382 OpalConnection::StringOptions * stringOptions = NULL
00383 );
00384
00393 virtual void OnEstablishedCall(
00394 OpalCall & call
00395 );
00396
00402 virtual BOOL HasCall(
00403 const PString & token
00404 ) { return activeCalls.FindWithLock(token, PSafeReference) != NULL; }
00405
00412 virtual BOOL IsCallEstablished(
00413 const PString & token
00414 );
00415
00424 PSafePtr<OpalCall> FindCallWithLock(
00425 const PString & token,
00426 PSafetyMode mode = PSafeReadWrite
00427 ) { return activeCalls.FindWithLock(token, mode); }
00428
00436 virtual BOOL ClearCall(
00437 const PString & token,
00438 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00439 PSyncPoint * sync = NULL
00440 );
00441
00449 virtual BOOL ClearCallSynchronous(
00450 const PString & token,
00451 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser
00452 );
00453
00459 virtual void ClearAllCalls(
00460 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00461 BOOL wait = TRUE
00462 );
00463
00477 virtual void OnClearedCall(
00478 OpalCall & call
00479 );
00480
00489 virtual OpalCall * CreateCall();
00490 virtual OpalCall * CreateCall(
00491 void * userData
00492 );
00493
00502 virtual void DestroyCall(
00503 OpalCall * call
00504 );
00505
00509 PString GetNextCallToken();
00511
00548 virtual BOOL MakeConnection(
00549 OpalCall & call,
00550 const PString & party,
00551 void * userData = NULL,
00552 unsigned int options = 0,
00553 OpalConnection::StringOptions * stringOptions = NULL
00554 );
00555
00582 virtual BOOL OnIncomingConnection(
00583 OpalConnection & connection,
00584 unsigned options,
00585 OpalConnection::StringOptions * stringOptions
00586 );
00587 virtual BOOL OnIncomingConnection(
00588 OpalConnection & connection,
00589 unsigned options
00590 );
00591 virtual BOOL OnIncomingConnection(
00592 OpalConnection & connection
00593 );
00594
00601 virtual PString OnRouteConnection(
00602 OpalConnection & connection
00603 );
00604
00621 virtual void OnAlerting(
00622 OpalConnection & connection
00623 );
00624
00625 virtual OpalConnection::AnswerCallResponse
00626 OnAnswerCall(OpalConnection & connection,
00627 const PString & caller
00628 );
00629
00641 virtual void OnConnected(
00642 OpalConnection & connection
00643 );
00644
00657 virtual void OnEstablished(
00658 OpalConnection & connection
00659 );
00660
00676 virtual void OnReleased(
00677 OpalConnection & connection
00678 );
00679
00686 virtual void OnHold(
00687 OpalConnection & connection
00688 );
00689
00694 virtual BOOL OnForwarded(
00695 OpalConnection & connection,
00696 const PString & remoteParty
00697 );
00699
00711 virtual void AdjustMediaFormats(
00712 const OpalConnection & connection,
00713 OpalMediaFormatList & mediaFormats
00714 ) const;
00715
00718 virtual BOOL IsMediaBypassPossible(
00719 const OpalConnection & source,
00720 const OpalConnection & destination,
00721 unsigned sessionID
00722 ) const;
00723
00739 virtual BOOL OnOpenMediaStream(
00740 OpalConnection & connection,
00741 OpalMediaStream & stream
00742 );
00743
00751 virtual void OnRTPStatistics(
00752 const OpalConnection & connection,
00753 const RTP_Session & session
00754 );
00755
00760 virtual void OnClosedMediaStream(
00761 const OpalMediaStream & stream
00762 );
00763
00764 #if OPAL_VIDEO
00765
00770 virtual void AddVideoMediaFormats(
00771 OpalMediaFormatList & mediaFormats,
00772 const OpalConnection * connection = NULL
00773 ) const;
00774
00777 virtual BOOL CreateVideoInputDevice(
00778 const OpalConnection & connection,
00779 const OpalMediaFormat & mediaFormat,
00780 PVideoInputDevice * & device,
00781 BOOL & autoDelete
00782 );
00783
00787 virtual BOOL CreateVideoOutputDevice(
00788 const OpalConnection & connection,
00789 const OpalMediaFormat & mediaFormat,
00790 BOOL preview,
00791 PVideoOutputDevice * & device,
00792 BOOL & autoDelete
00793 );
00794 #endif
00795
00803 virtual OpalMediaPatch * CreateMediaPatch(
00804 OpalMediaStream & source,
00805 BOOL requiresPatchThread = TRUE
00806 );
00807
00812 virtual void DestroyMediaPatch(
00813 OpalMediaPatch * patch
00814 );
00815
00823 virtual BOOL OnStartMediaPatch(
00824 const OpalMediaPatch & patch
00825 );
00827
00835 virtual void OnUserInputString(
00836 OpalConnection & connection,
00837 const PString & value
00838 );
00839
00846 virtual void OnUserInputTone(
00847 OpalConnection & connection,
00848 char tone,
00849 int duration
00850 );
00851
00854 virtual PString ReadUserInput(
00855 OpalConnection & connection,
00856 const char * terminators = "#\r\n",
00857 unsigned lastDigitTimeout = 4,
00858 unsigned firstDigitTimeout = 30
00859 );
00861
00864 #if OPAL_T120DATA
00865
00875 virtual OpalT120Protocol * CreateT120ProtocolHandler(
00876 const OpalConnection & connection
00877 ) const;
00878 #endif
00879
00880 #if OPAL_T38FAX
00881
00891 virtual OpalT38Protocol * CreateT38ProtocolHandler(
00892 const OpalConnection & connection
00893 ) const;
00894
00895 #endif
00896
00897 #if OPAL_H224
00898
00907 virtual OpalH224Handler * CreateH224ProtocolHandler(
00908 OpalConnection & connection, unsigned sessionID
00909 ) const;
00910
00920 virtual OpalH281Handler * CreateH281ProtocolHandler(
00921 OpalH224Handler & h224Handler
00922 ) const;
00923 #endif
00924
00925 class RouteEntry : public PObject
00926 {
00927 PCLASSINFO(RouteEntry, PObject);
00928 public:
00929 RouteEntry(const PString & pat, const PString & dest);
00930 void PrintOn(ostream & strm) const;
00931 PString pattern;
00932 PString destination;
00933 PRegularExpression regex;
00934 };
00935 PLIST(RouteTable, RouteEntry);
00936
00963 virtual BOOL AddRouteEntry(
00964 const PString & spec
00965 );
00966
00973 BOOL SetRouteTable(
00974 const PStringArray & specs
00975 );
00976
00981 void SetRouteTable(
00982 const RouteTable & table
00983 );
00984
00987 const RouteTable & GetRouteTable() const { return routeTable; }
00988
00991 virtual PString ApplyRouteTable(
00992 const PString & proto,
00993 const PString & addr
00994 );
00996
01001 const OpalProductInfo & GetProductInfo() const { return productInfo; }
01002
01005 void SetProductInfo(
01006 const OpalProductInfo & info
01007 ) { productInfo = info; }
01008
01011 const PString & GetDefaultUserName() const { return defaultUserName; }
01012
01015 void SetDefaultUserName(
01016 const PString & name
01017 ) { defaultUserName = name; }
01018
01021 const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
01022
01025 void SetDefaultDisplayName(
01026 const PString & name
01027 ) { defaultDisplayName = name; }
01028
01029 #if OPAL_VIDEO
01030
01033 BOOL CanAutoStartReceiveVideo() const { return autoStartReceiveVideo; }
01034
01037 void SetAutoStartReceiveVideo(BOOL can) { autoStartReceiveVideo = can; }
01038
01041 BOOL CanAutoStartTransmitVideo() const { return autoStartTransmitVideo; }
01042
01045 void SetAutoStartTransmitVideo(BOOL can) { autoStartTransmitVideo = can; }
01046
01047 #endif
01048
01055 virtual BOOL IsLocalAddress(
01056 const PIPSocket::Address & remoteAddress
01057 ) const;
01058
01065 virtual BOOL TranslateIPAddress(
01066 PIPSocket::Address & localAddress,
01067 const PIPSocket::Address & remoteAddress
01068 );
01069
01072 const PIPSocket::Address & GetTranslationAddress() const { return translationAddress; }
01073
01076 void SetTranslationAddress(
01077 const PIPSocket::Address & address
01078 ) { translationAddress = address; }
01079
01085 PSTUNClient * GetSTUN(
01086 const PIPSocket::Address & address = 0
01087 ) const;
01088
01093 PSTUNClient::NatTypes SetSTUNServer(
01094 const PString & server
01095 );
01096
01099 const PString & GetSTUNServer() const { return stunServer; }
01100
01103 WORD GetTCPPortBase() const { return tcpPorts.base; }
01104
01107 WORD GetTCPPortMax() const { return tcpPorts.max; }
01108
01111 void SetTCPPorts(unsigned tcpBase, unsigned tcpMax);
01112
01115 WORD GetNextTCPPort();
01116
01119 WORD GetUDPPortBase() const { return udpPorts.base; }
01120
01123 WORD GetUDPPortMax() const { return udpPorts.max; }
01124
01127 void SetUDPPorts(unsigned udpBase, unsigned udpMax);
01128
01131 WORD GetNextUDPPort();
01132
01135 WORD GetRtpIpPortBase() const { return rtpIpPorts.base; }
01136
01139 WORD GetRtpIpPortMax() const { return rtpIpPorts.max; }
01140
01143 void SetRtpIpPorts(unsigned udpBase, unsigned udpMax);
01144
01147 WORD GetRtpIpPortPair();
01148
01151 BYTE GetRtpIpTypeofService() const { return rtpIpTypeofService; }
01152
01155 void SetRtpIpTypeofService(unsigned tos) { rtpIpTypeofService = (BYTE)tos; }
01156
01160 unsigned GetMinAudioJitterDelay() const { return minAudioJitterDelay; }
01161
01165 unsigned GetMaxAudioJitterDelay() const { return maxAudioJitterDelay; }
01166
01169 void SetAudioJitterDelay(
01170 unsigned minDelay,
01171 unsigned maxDelay
01172 );
01173
01176 const PStringArray & GetMediaFormatOrder() const { return mediaFormatOrder; }
01177
01180 void SetMediaFormatOrder(const PStringArray & order) { mediaFormatOrder = order; }
01181
01184 const PStringArray & GetMediaFormatMask() const { return mediaFormatMask; }
01185
01188 void SetMediaFormatMask(const PStringArray & mask) { mediaFormatMask = mask; }
01189
01192 virtual void SetSilenceDetectParams(
01193 const OpalSilenceDetector::Params & params
01194 ) { silenceDetectParams = params; }
01195
01198 const OpalSilenceDetector::Params & GetSilenceDetectParams() const { return silenceDetectParams; }
01199
01202 virtual void SetEchoCancelParams(
01203 const OpalEchoCanceler::Params & params
01204 ) { echoCancelParams = params; }
01205
01208 const OpalEchoCanceler::Params & GetEchoCancelParams() const { return echoCancelParams; }
01209
01210 #if OPAL_VIDEO
01211
01219 virtual BOOL SetVideoInputDevice(
01220 const PVideoDevice::OpenArgs & deviceArgs
01221 );
01222
01226 const PVideoDevice::OpenArgs & GetVideoInputDevice() const { return videoInputDevice; }
01227
01235 virtual BOOL SetVideoPreviewDevice(
01236 const PVideoDevice::OpenArgs & deviceArgs
01237 );
01238
01242 const PVideoDevice::OpenArgs & GetVideoPreviewDevice() const { return videoPreviewDevice; }
01243
01251 virtual BOOL SetVideoOutputDevice(
01252 const PVideoDevice::OpenArgs & deviceArgs
01253 );
01254
01258 const PVideoDevice::OpenArgs & GetVideoOutputDevice() const { return videoOutputDevice; }
01259
01260 #endif
01261
01262 BOOL DetectInBandDTMFDisabled() const
01263 { return disableDetectInBandDTMF; }
01264
01267 void DisableDetectInBandDTMF(
01268 BOOL mode
01269 ) { disableDetectInBandDTMF = mode; }
01270
01273 const PTimeInterval & GetNoMediaTimeout() const { return noMediaTimeout; }
01274
01277 BOOL SetNoMediaTimeout(
01278 const PTimeInterval & newInterval
01279 );
01280
01283 const PString & GetDefaultILSServer() const { return ilsServer; }
01284
01287 void SetDefaultILSServer(
01288 const PString & server
01289 ) { ilsServer = server; }
01291
01292
01293 void GarbageCollection();
01294
01295 virtual void OnNewConnection(OpalConnection & conn);
01296
01297 virtual void SetDefaultSecurityMode(const PString & v)
01298 { defaultSecurityMode = v; }
01299
01300 virtual PString GetDefaultSecurityMode() const
01301 { return defaultSecurityMode; }
01302
01303 virtual BOOL UseRTPAggregation() const;
01304
01305 OpalRecordManager & GetRecordManager()
01306 { return recordManager; }
01307
01308 virtual BOOL StartRecording(const PString & callToken, const PFilePath & fn);
01309 virtual void StopRecording(const PString & callToken);
01310
01311 virtual BOOL IsRTPNATEnabled(
01312 OpalConnection & conn,
01313 const PIPSocket::Address & localAddr,
01314 const PIPSocket::Address & peerAddr,
01315 const PIPSocket::Address & sigAddr,
01316 BOOL incoming
01317 );
01318
01319 protected:
01320
01321 OpalProductInfo productInfo;
01322
01323 PString defaultUserName;
01324 PString defaultDisplayName;
01325
01326 #if OPAL_VIDEO
01327 BOOL autoStartReceiveVideo;
01328 BOOL autoStartTransmitVideo;
01329 #endif
01330
01331 BYTE rtpIpTypeofService;
01332 unsigned minAudioJitterDelay;
01333 unsigned maxAudioJitterDelay;
01334 PStringArray mediaFormatOrder;
01335 PStringArray mediaFormatMask;
01336 BOOL disableDetectInBandDTMF;
01337 PTimeInterval noMediaTimeout;
01338 PString ilsServer;
01339
01340 OpalSilenceDetector::Params silenceDetectParams;
01341 OpalEchoCanceler::Params echoCancelParams;
01342
01343 #if OPAL_VIDEO
01344 PVideoDevice::OpenArgs videoInputDevice;
01345 PVideoDevice::OpenArgs videoPreviewDevice;
01346 PVideoDevice::OpenArgs videoOutputDevice;
01347 #endif
01348
01349 struct PortInfo {
01350 void Set(
01351 unsigned base,
01352 unsigned max,
01353 unsigned range,
01354 unsigned dflt
01355 );
01356 WORD GetNext(
01357 unsigned increment
01358 );
01359
01360 PMutex mutex;
01361 WORD base;
01362 WORD max;
01363 WORD current;
01364 } tcpPorts, udpPorts, rtpIpPorts;
01365
01366 PIPSocket::Address translationAddress;
01367 PString stunServer;
01368 PSTUNClient * stun;
01369
01370 RouteTable routeTable;
01371 PMutex routeTableMutex;
01372
01373
01374 PList<OpalEndPoint> endpoints;
01375 PReadWriteMutex endpointsMutex;
01376
01377 PAtomicInteger lastCallTokenID;
01378
01379 class CallDict : public PSafeDictionary<PString, OpalCall>
01380 {
01381 public:
01382 CallDict(OpalManager & mgr) : manager(mgr) { }
01383 virtual void DeleteObject(PObject * object) const;
01384 OpalManager & manager;
01385 } activeCalls;
01386
01387 BOOL clearingAllCalls;
01388 PSyncPoint allCallsCleared;
01389 PThread * garbageCollector;
01390 PSyncPoint garbageCollectExit;
01391 PDECLARE_NOTIFIER(PThread, OpalManager, GarbageMain);
01392
01393 PString defaultSecurityMode;
01394
01395 #if OPAL_RTP_AGGREGATE
01396 BOOL useRTPAggregation;
01397 #endif
01398
01399 OpalRecordManager recordManager;
01400
01401 friend OpalCall::OpalCall(OpalManager & mgr);
01402 friend void OpalCall::OnReleased(OpalConnection & connection);
01403 };
01404
01405
01406 PString OpalGetVersion();
01407 unsigned OpalGetMajorVersion();
01408 unsigned OpalGetMinorVersion();
01409 unsigned OpalGetBuildNumber();
01410
01411
01412 #endif // __OPAL_MANAGER_H
01413
01414
01415