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 #ifndef __OPAL_MANAGER_H
00033 #define __OPAL_MANAGER_H
00034
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038
00039 #include <opal/buildopts.h>
00040
00041 #include <opal/call.h>
00042 #include <opal/connection.h>
00043 #include <opal/guid.h>
00044 #include <opal/audiorecord.h>
00045 #include <codec/silencedetect.h>
00046 #include <codec/echocancel.h>
00047 #include <ptclib/pstun.h>
00048
00049 #if OPAL_VIDEO
00050 #include <ptlib/videoio.h>
00051 #endif
00052
00053 class OpalEndPoint;
00054 class OpalMediaPatch;
00055 class OpalH224Handler;
00056 class OpalH281Handler;
00057
00058
00075 class OpalManager : public PObject
00076 {
00077 PCLASSINFO(OpalManager, PObject);
00078 public:
00083 OpalManager();
00084
00089 ~OpalManager();
00091
00101 void AttachEndPoint(
00102 OpalEndPoint * endpoint,
00103 const PString & prefix = PString::Empty()
00104 );
00105
00109 void DetachEndPoint(
00110 const PString & prefix
00111 );
00112 void DetachEndPoint(
00113 OpalEndPoint * endpoint
00114 );
00115
00118 OpalEndPoint * FindEndPoint(
00119 const PString & prefix
00120 );
00121
00124 PList<OpalEndPoint> GetEndPoints() const;
00125
00131 void ShutDownEndpoints();
00133
00155 virtual PBoolean SetUpCall(
00156 const PString & partyA,
00157 const PString & partyB,
00158 PString & token,
00159 void * userData = NULL,
00160 unsigned options = 0,
00161 OpalConnection::StringOptions * stringOptions = NULL
00162 );
00163
00172 virtual void OnEstablishedCall(
00173 OpalCall & call
00174 );
00175
00181 virtual PBoolean HasCall(
00182 const PString & token
00183 ) { return activeCalls.FindWithLock(token, PSafeReference) != NULL; }
00184
00191 virtual PBoolean IsCallEstablished(
00192 const PString & token
00193 );
00194
00203 PSafePtr<OpalCall> FindCallWithLock(
00204 const PString & token,
00205 PSafetyMode mode = PSafeReadWrite
00206 ) { return activeCalls.FindWithLock(token, mode); }
00207
00215 virtual PBoolean ClearCall(
00216 const PString & token,
00217 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00218 PSyncPoint * sync = NULL
00219 );
00220
00228 virtual PBoolean ClearCallSynchronous(
00229 const PString & token,
00230 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser
00231 );
00232
00238 virtual void ClearAllCalls(
00239 OpalConnection::CallEndReason reason = OpalConnection::EndedByLocalUser,
00240 PBoolean wait = PTrue
00241 );
00242
00256 virtual void OnClearedCall(
00257 OpalCall & call
00258 );
00259
00268 virtual OpalCall * CreateCall(
00269 void * userData
00270 );
00271 virtual OpalCall * CreateCall();
00272 OpalCall * InternalCreateCall();
00273
00282 virtual void DestroyCall(
00283 OpalCall * call
00284 );
00285
00289 PString GetNextCallToken();
00291
00328 virtual PBoolean MakeConnection(
00329 OpalCall & call,
00330 const PString & party,
00331 void * userData = NULL,
00332 unsigned int options = 0,
00333 OpalConnection::StringOptions * stringOptions = NULL
00334 );
00335
00362 virtual PBoolean OnIncomingConnection(
00363 OpalConnection & connection,
00364 unsigned options,
00365 OpalConnection::StringOptions * stringOptions
00366 );
00367 virtual PBoolean OnIncomingConnection(
00368 OpalConnection & connection,
00369 unsigned options
00370 );
00371 virtual PBoolean OnIncomingConnection(
00372 OpalConnection & connection
00373 );
00374
00381 virtual PString OnRouteConnection(
00382 OpalConnection & connection
00383 );
00384
00401 virtual void OnAlerting(
00402 OpalConnection & connection
00403 );
00404
00405 virtual OpalConnection::AnswerCallResponse
00406 OnAnswerCall(OpalConnection & connection,
00407 const PString & caller
00408 );
00409
00421 virtual void OnConnected(
00422 OpalConnection & connection
00423 );
00424
00438 virtual void OnEstablished(
00439 OpalConnection & connection
00440 );
00441
00457 virtual void OnReleased(
00458 OpalConnection & connection
00459 );
00460
00467 virtual void OnHold(
00468 OpalConnection & connection
00469 );
00470
00475 virtual PBoolean OnForwarded(
00476 OpalConnection & connection,
00477 const PString & remoteParty
00478 );
00480
00492 virtual void AdjustMediaFormats(
00493 const OpalConnection & connection,
00494 OpalMediaFormatList & mediaFormats
00495 ) const;
00496
00499 virtual PBoolean IsMediaBypassPossible(
00500 const OpalConnection & source,
00501 const OpalConnection & destination,
00502 unsigned sessionID
00503 ) const;
00504
00520 virtual PBoolean OnOpenMediaStream(
00521 OpalConnection & connection,
00522 OpalMediaStream & stream
00523 );
00524
00532 virtual void OnRTPStatistics(
00533 const OpalConnection & connection,
00534 const RTP_Session & session
00535 );
00536
00541 virtual void OnClosedMediaStream(
00542 const OpalMediaStream & stream
00543 );
00544
00545 #if OPAL_VIDEO
00546
00551 virtual void AddVideoMediaFormats(
00552 OpalMediaFormatList & mediaFormats,
00553 const OpalConnection * connection = NULL
00554 ) const;
00555
00558 virtual PBoolean CreateVideoInputDevice(
00559 const OpalConnection & connection,
00560 const OpalMediaFormat & mediaFormat,
00561 PVideoInputDevice * & device,
00562 PBoolean & autoDelete
00563 );
00564
00568 virtual PBoolean CreateVideoOutputDevice(
00569 const OpalConnection & connection,
00570 const OpalMediaFormat & mediaFormat,
00571 PBoolean preview,
00572 PVideoOutputDevice * & device,
00573 PBoolean & autoDelete
00574 );
00575 #endif
00576
00584 virtual OpalMediaPatch * CreateMediaPatch(
00585 OpalMediaStream & source,
00586 PBoolean requiresPatchThread = PTrue
00587 );
00588
00593 virtual void DestroyMediaPatch(
00594 OpalMediaPatch * patch
00595 );
00596
00604 virtual PBoolean OnStartMediaPatch(
00605 const OpalMediaPatch & patch
00606 );
00608
00616 virtual void OnUserInputString(
00617 OpalConnection & connection,
00618 const PString & value
00619 );
00620
00627 virtual void OnUserInputTone(
00628 OpalConnection & connection,
00629 char tone,
00630 int duration
00631 );
00632
00635 virtual PString ReadUserInput(
00636 OpalConnection & connection,
00637 const char * terminators = "#\r\n",
00638 unsigned lastDigitTimeout = 4,
00639 unsigned firstDigitTimeout = 30
00640 );
00642
00645 #if OPAL_T120DATA
00646
00656 virtual OpalT120Protocol * CreateT120ProtocolHandler(
00657 const OpalConnection & connection
00658 ) const;
00659 #endif
00660
00661 #if OPAL_T38FAX
00662
00672 virtual OpalT38Protocol * CreateT38ProtocolHandler(
00673 const OpalConnection & connection
00674 ) const;
00675
00676 #endif
00677
00678 #if OPAL_H224
00679
00688 virtual OpalH224Handler * CreateH224ProtocolHandler(
00689 OpalConnection & connection, unsigned sessionID
00690 ) const;
00691
00701 virtual OpalH281Handler * CreateH281ProtocolHandler(
00702 OpalH224Handler & h224Handler
00703 ) const;
00704 #endif
00705
00706 class RouteEntry : public PObject
00707 {
00708 PCLASSINFO(RouteEntry, PObject);
00709 public:
00710 RouteEntry(const PString & pat, const PString & dest);
00711 void PrintOn(ostream & strm) const;
00712 PString pattern;
00713 PString destination;
00714 PRegularExpression regex;
00715 };
00716 PARRAY(RouteTable, RouteEntry);
00717
00824 virtual PBoolean AddRouteEntry(
00825 const PString & spec
00826 );
00827
00834 PBoolean SetRouteTable(
00835 const PStringArray & specs
00836 );
00837
00842 void SetRouteTable(
00843 const RouteTable & table
00844 );
00845
00848 const RouteTable & GetRouteTable() const { return routeTable; }
00849
00857 virtual PString ApplyRouteTable(
00858 const PString & source,
00859 const PString & destination,
00860 PINDEX & entry
00861 );
00863
00868 const OpalProductInfo & GetProductInfo() const { return productInfo; }
00869
00872 void SetProductInfo(
00873 const OpalProductInfo & info,
00874 bool updateAll = true
00875 );
00876
00879 const PString & GetDefaultUserName() const { return defaultUserName; }
00880
00883 void SetDefaultUserName(
00884 const PString & name,
00885 bool updateAll = true
00886 );
00887
00890 const PString & GetDefaultDisplayName() const { return defaultDisplayName; }
00891
00894 void SetDefaultDisplayName(
00895 const PString & name,
00896 bool updateAll = true
00897 );
00898
00899 #if OPAL_VIDEO
00900
00903 PBoolean CanAutoStartReceiveVideo() const { return autoStartReceiveVideo; }
00904
00907 void SetAutoStartReceiveVideo(PBoolean can) { autoStartReceiveVideo = can; }
00908
00911 PBoolean CanAutoStartTransmitVideo() const { return autoStartTransmitVideo; }
00912
00915 void SetAutoStartTransmitVideo(PBoolean can) { autoStartTransmitVideo = can; }
00916
00917 #endif
00918
00925 virtual PBoolean IsLocalAddress(
00926 const PIPSocket::Address & remoteAddress
00927 ) const;
00928
00946 virtual PBoolean IsRTPNATEnabled(
00947 OpalConnection & connection,
00948 const PIPSocket::Address & localAddr,
00949 const PIPSocket::Address & peerAddr,
00950 const PIPSocket::Address & signalAddr,
00951 PBoolean incoming
00952 );
00953
00960 virtual PBoolean TranslateIPAddress(
00961 PIPSocket::Address & localAddress,
00962 const PIPSocket::Address & remoteAddress
00963 );
00964
00967 const PString & GetTranslationHost() const { return translationHost; }
00968
00971 bool SetTranslationHost(
00972 const PString & host
00973 );
00974
00977 const PIPSocket::Address & GetTranslationAddress() const { return translationAddress; }
00978
00981 void SetTranslationAddress(
00982 const PIPSocket::Address & address
00983 );
00984
00990 PSTUNClient * GetSTUN(
00991 const PIPSocket::Address & address = 0
00992 ) const;
00993
00998 PSTUNClient::NatTypes SetSTUNServer(
00999 const PString & server
01000 );
01001
01004 const PString & GetSTUNServer() const { return stunServer; }
01005
01008 WORD GetTCPPortBase() const { return tcpPorts.base; }
01009
01012 WORD GetTCPPortMax() const { return tcpPorts.max; }
01013
01016 void SetTCPPorts(unsigned tcpBase, unsigned tcpMax);
01017
01020 WORD GetNextTCPPort();
01021
01024 WORD GetUDPPortBase() const { return udpPorts.base; }
01025
01028 WORD GetUDPPortMax() const { return udpPorts.max; }
01029
01032 void SetUDPPorts(unsigned udpBase, unsigned udpMax);
01033
01036 WORD GetNextUDPPort();
01037
01040 WORD GetRtpIpPortBase() const { return rtpIpPorts.base; }
01041
01044 WORD GetRtpIpPortMax() const { return rtpIpPorts.max; }
01045
01048 void SetRtpIpPorts(unsigned udpBase, unsigned udpMax);
01049
01052 WORD GetRtpIpPortPair();
01053
01056 BYTE GetRtpIpTypeofService() const { return rtpIpTypeofService; }
01057
01060 void SetRtpIpTypeofService(unsigned tos) { rtpIpTypeofService = (BYTE)tos; }
01061
01066 PINDEX GetMaxRtpPayloadSize() const { return rtpPayloadSizeMax; }
01067
01072 void SetMaxRtpPayloadSize(
01073 PINDEX size,
01074 bool mtu = false
01075 ) { rtpPayloadSizeMax = size - (mtu ? (20+16+12) : 0); }
01076
01080 unsigned GetMinAudioJitterDelay() const { return minAudioJitterDelay; }
01081
01085 unsigned GetMaxAudioJitterDelay() const { return maxAudioJitterDelay; }
01086
01089 void SetAudioJitterDelay(
01090 unsigned minDelay,
01091 unsigned maxDelay
01092 );
01093
01096 const PStringArray & GetMediaFormatOrder() const { return mediaFormatOrder; }
01097
01100 void SetMediaFormatOrder(const PStringArray & order) { mediaFormatOrder = order; }
01101
01104 const PStringArray & GetMediaFormatMask() const { return mediaFormatMask; }
01105
01108 void SetMediaFormatMask(const PStringArray & mask) { mediaFormatMask = mask; }
01109
01112 virtual void SetSilenceDetectParams(
01113 const OpalSilenceDetector::Params & params
01114 ) { silenceDetectParams = params; }
01115
01118 const OpalSilenceDetector::Params & GetSilenceDetectParams() const { return silenceDetectParams; }
01119
01122 virtual void SetEchoCancelParams(
01123 const OpalEchoCanceler::Params & params
01124 ) { echoCancelParams = params; }
01125
01128 const OpalEchoCanceler::Params & GetEchoCancelParams() const { return echoCancelParams; }
01129
01130 #if OPAL_VIDEO
01131
01139 virtual PBoolean SetVideoInputDevice(
01140 const PVideoDevice::OpenArgs & deviceArgs
01141 );
01142
01146 const PVideoDevice::OpenArgs & GetVideoInputDevice() const { return videoInputDevice; }
01147
01155 virtual PBoolean SetVideoPreviewDevice(
01156 const PVideoDevice::OpenArgs & deviceArgs
01157 );
01158
01162 const PVideoDevice::OpenArgs & GetVideoPreviewDevice() const { return videoPreviewDevice; }
01163
01171 virtual PBoolean SetVideoOutputDevice(
01172 const PVideoDevice::OpenArgs & deviceArgs
01173 );
01174
01178 const PVideoDevice::OpenArgs & GetVideoOutputDevice() const { return videoOutputDevice; }
01179
01180 #endif
01181
01182 PBoolean DetectInBandDTMFDisabled() const
01183 { return disableDetectInBandDTMF; }
01184
01187 void DisableDetectInBandDTMF(
01188 PBoolean mode
01189 ) { disableDetectInBandDTMF = mode; }
01190
01193 const PTimeInterval & GetNoMediaTimeout() const { return noMediaTimeout; }
01194
01197 PBoolean SetNoMediaTimeout(
01198 const PTimeInterval & newInterval
01199 );
01200
01203 const PString & GetDefaultILSServer() const { return ilsServer; }
01204
01207 void SetDefaultILSServer(
01208 const PString & server
01209 ) { ilsServer = server; }
01211
01212
01213 void GarbageCollection();
01214
01220 virtual void OnNewConnection(
01221 OpalConnection & connection
01222 );
01223
01224 virtual void SetDefaultSecurityMode(const PString & v)
01225 { defaultSecurityMode = v; }
01226
01227 virtual PString GetDefaultSecurityMode() const
01228 { return defaultSecurityMode; }
01229
01230 virtual PBoolean UseRTPAggregation() const;
01231
01232 OpalRecordManager & GetRecordManager()
01233 { return recordManager; }
01234
01235 virtual PBoolean StartRecording(const PString & callToken, const PFilePath & fn);
01236 virtual bool IsRecording(const PString & callToken);
01237 virtual void StopRecording(const PString & callToken);
01238
01239 protected:
01240
01241 OpalProductInfo productInfo;
01242
01243 PString defaultUserName;
01244 PString defaultDisplayName;
01245
01246 #if OPAL_VIDEO
01247 PBoolean autoStartReceiveVideo;
01248 PBoolean autoStartTransmitVideo;
01249 #endif
01250
01251 BYTE rtpIpTypeofService;
01252 PINDEX rtpPayloadSizeMax;
01253 unsigned minAudioJitterDelay;
01254 unsigned maxAudioJitterDelay;
01255 PStringArray mediaFormatOrder;
01256 PStringArray mediaFormatMask;
01257 PBoolean disableDetectInBandDTMF;
01258 PTimeInterval noMediaTimeout;
01259 PString ilsServer;
01260
01261 OpalSilenceDetector::Params silenceDetectParams;
01262 OpalEchoCanceler::Params echoCancelParams;
01263
01264 #if OPAL_VIDEO
01265 PVideoDevice::OpenArgs videoInputDevice;
01266 PVideoDevice::OpenArgs videoPreviewDevice;
01267 PVideoDevice::OpenArgs videoOutputDevice;
01268 #endif
01269
01270 struct PortInfo {
01271 void Set(
01272 unsigned base,
01273 unsigned max,
01274 unsigned range,
01275 unsigned dflt
01276 );
01277 WORD GetNext(
01278 unsigned increment
01279 );
01280
01281 PMutex mutex;
01282 WORD base;
01283 WORD max;
01284 WORD current;
01285 } tcpPorts, udpPorts, rtpIpPorts;
01286
01287 class InterfaceMonitor : public PInterfaceMonitorClient
01288 {
01289 PCLASSINFO(InterfaceMonitor, PInterfaceMonitorClient);
01290
01291 enum {
01292 OpalManagerInterfaceMonitorClientPriority = 100,
01293 };
01294 public:
01295 InterfaceMonitor(PSTUNClient * stun);
01296
01297 protected:
01298 virtual void OnAddInterface(const PIPSocket::InterfaceEntry & entry);
01299 virtual void OnRemoveInterface(const PIPSocket::InterfaceEntry & entry);
01300
01301 PSTUNClient * stun;
01302 };
01303
01304 PString translationHost;
01305 PIPSocket::Address translationAddress;
01306 PString stunServer;
01307 PSTUNClient * stun;
01308 InterfaceMonitor * interfaceMonitor;
01309
01310 RouteTable routeTable;
01311 PMutex routeTableMutex;
01312
01313
01314 PReadWriteMutex endpointsMutex;
01315 PList<OpalEndPoint> endpointList;
01316 std::map<PString, OpalEndPoint *> endpointMap;
01317
01318 PAtomicInteger lastCallTokenID;
01319
01320 class CallDict : public PSafeDictionary<PString, OpalCall>
01321 {
01322 public:
01323 CallDict(OpalManager & mgr) : manager(mgr) { }
01324 virtual void DeleteObject(PObject * object) const;
01325 OpalManager & manager;
01326 } activeCalls;
01327
01328 PBoolean clearingAllCalls;
01329 PSyncPoint allCallsCleared;
01330 PThread * garbageCollector;
01331 PSyncPoint garbageCollectExit;
01332 PDECLARE_NOTIFIER(PThread, OpalManager, GarbageMain);
01333
01334 PString defaultSecurityMode;
01335
01336 #if OPAL_RTP_AGGREGATE
01337 PBoolean useRTPAggregation;
01338 #endif
01339
01340 OpalRecordManager recordManager;
01341
01342 friend OpalCall::OpalCall(OpalManager & mgr);
01343 friend void OpalCall::OnReleased(OpalConnection & connection);
01344 };
01345
01346
01347 PString OpalGetVersion();
01348 unsigned OpalGetMajorVersion();
01349 unsigned OpalGetMinorVersion();
01350 unsigned OpalGetBuildNumber();
01351
01352
01353 #endif // __OPAL_MANAGER_H
01354
01355
01356