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 #ifndef OPAL_OPAL_CONNECTION_H
00036 #define OPAL_OPAL_CONNECTION_H
00037
00038 #ifdef P_USE_PRAGMA
00039 #pragma interface
00040 #endif
00041
00042 #include <opal/buildopts.h>
00043
00044 #include <opal/mediafmt.h>
00045 #include <opal/mediastrm.h>
00046 #include <opal/guid.h>
00047 #include <opal/transports.h>
00048 #include <ptclib/dtmf.h>
00049 #include <ptlib/safecoll.h>
00050 #include <rtp/rtp.h>
00051 #include <im/t140.h>
00052
00053 class OpalEndPoint;
00054 class OpalCall;
00055 class OpalSilenceDetector;
00056 class OpalEchoCanceler;
00057 class OpalRFC2833Proto;
00058 class OpalRFC2833Info;
00059
00060
00061 #define OPAL_OPT_AUTO_START "AutoStart"
00062 #define OPAL_OPT_CALL_IDENTIFIER "Call-Identifier"
00063 #define OPAL_OPT_CALLING_PARTY_URL "Calling-Party-URL"
00064 #define OPAL_OPT_CALLING_PARTY_NUMBER "Calling-Party-Number"
00065 #define OPAL_OPT_CALLING_PARTY_NAME "Calling-Party-Name"
00066 #define OPAL_OPT_CALLING_PARTY_DOMAIN "Calling-Party-Domain"
00067 #define OPAL_OPT_CALLING_DISPLAY_NAME "Calling-Display-Name"
00068 #define OPAL_OPT_ORIGINATOR_ADDRESS "Originator-Address"
00069 #define OPAL_OPT_INTERFACE "Interface"
00070 #define OPAL_OPT_ENABLE_INBAND_DTMF "EnableInbandDTMF"
00071 #define OPAL_OPT_DTMF_MULT "dtmfmult"
00072 #define OPAL_OPT_DTMF_DIV "dtmfdiv"
00073 #define OPAL_OPT_DISABLE_JITTER "Disable-Jitter"
00074 #define OPAL_OPT_MAX_JITTER "Max-Jitter"
00075 #define OPAL_OPT_MIN_JITTER "Min-Jitter"
00076 #define OPAL_OPT_RECORD_AUDIO "Record-Audio"
00077 #define OPAL_OPT_ALERTING_TYPE "Alerting-Type"
00078
00079
00291 class OpalProductInfo
00292 {
00293 public:
00294 OpalProductInfo();
00295
00296 static OpalProductInfo & Default();
00297
00298 PCaselessString AsString() const;
00299
00300 PString vendor;
00301 PString name;
00302 PString version;
00303 PString comments;
00304 BYTE t35CountryCode;
00305 BYTE t35Extension;
00306 WORD manufacturerCode;
00307 };
00308
00309
00327 class OpalConnection : public PSafeObject
00328 {
00329 PCLASSINFO(OpalConnection, PSafeObject);
00330 public:
00335 enum CallEndReason {
00336 EndedByLocalUser,
00337 EndedByNoAccept,
00338 EndedByAnswerDenied,
00339 EndedByRemoteUser,
00340 EndedByRefusal,
00341 EndedByNoAnswer,
00342 EndedByCallerAbort,
00343 EndedByTransportFail,
00344 EndedByConnectFail,
00345 EndedByGatekeeper,
00346 EndedByNoUser,
00347 EndedByNoBandwidth,
00348 EndedByCapabilityExchange,
00349 EndedByCallForwarded,
00350 EndedBySecurityDenial,
00351 EndedByLocalBusy,
00352 EndedByLocalCongestion,
00353 EndedByRemoteBusy,
00354 EndedByRemoteCongestion,
00355 EndedByUnreachable,
00356 EndedByNoEndPoint,
00357 EndedByHostOffline,
00358 EndedByTemporaryFailure,
00359 EndedByQ931Cause,
00360 EndedByDurationLimit,
00361 EndedByInvalidConferenceID,
00362 EndedByNoDialTone,
00363 EndedByNoRingBackTone,
00364 EndedByOutOfService,
00365 EndedByAcceptingCallWaiting,
00366 EndedByGkAdmissionFailed,
00367 NumCallEndReasons,
00368
00369 EndedWithQ931Code = 0x100
00370 };
00371
00372 #if PTRACING
00373 friend ostream & operator<<(ostream & o, CallEndReason reason);
00374 #endif
00375
00376 enum AnswerCallResponse {
00377 AnswerCallNow,
00378 AnswerCallDenied,
00379 AnswerCallPending,
00380 AnswerCallDeferred,
00381 AnswerCallAlertWithMedia,
00382 AnswerCallDeferredWithMedia,
00383 AnswerCallProgress,
00384 AnswerCallNowAndReleaseCurrent,
00385 NumAnswerCallResponses
00386 };
00387 #if PTRACING
00388 friend ostream & operator<<(ostream & o, AnswerCallResponse s);
00389 #endif
00390
00393 enum Options {
00394 FastStartOptionDisable = 0x0001,
00395 FastStartOptionEnable = 0x0002,
00396 FastStartOptionMask = 0x0003,
00397
00398 H245TunnelingOptionDisable = 0x0004,
00399 H245TunnelingOptionEnable = 0x0008,
00400 H245TunnelingOptionMask = 0x000c,
00401
00402 H245inSetupOptionDisable = 0x0010,
00403 H245inSetupOptionEnable = 0x0020,
00404 H245inSetupOptionMask = 0x0030,
00405
00406 DetectInBandDTMFOptionDisable = 0x0040,
00407 DetectInBandDTMFOptionEnable = 0x0080,
00408 DetectInBandDTMFOptionMask = 0x00c0,
00409
00410 RTPAggregationDisable = 0x0100,
00411 RTPAggregationEnable = 0x0200,
00412 RTPAggregationMask = 0x0300,
00413
00414 SendDTMFAsDefault = 0x0000,
00415 SendDTMFAsString = 0x0400,
00416 SendDTMFAsTone = 0x0800,
00417 SendDTMFAsRFC2833 = 0x0c00,
00418 SendDTMFMask = 0x0c00
00419 };
00420
00421 class StringOptions : public PStringToString
00422 {
00423 };
00424
00429 OpalConnection(
00430 OpalCall & call,
00431 OpalEndPoint & endpoint,
00432 const PString & token,
00433 unsigned options = 0,
00434 OpalConnection::StringOptions * stringOptions = NULL
00435 );
00436
00439 ~OpalConnection();
00441
00448 void PrintOn(
00449 ostream & strm
00450 ) const;
00452
00469 virtual bool IsNetworkConnection() const = 0;
00470
00474 enum Phases {
00475 UninitialisedPhase,
00476 SetUpPhase,
00477 ProceedingPhase,
00478 AlertingPhase,
00479 ConnectedPhase,
00480 EstablishedPhase,
00481 ReleasingPhase,
00482 ReleasedPhase,
00483 NumPhases
00484 };
00485
00490 inline Phases GetPhase() const { return phase; }
00491
00500 CallEndReason GetCallEndReason() const { return callEndReason; }
00501
00506 virtual void SetCallEndReason(
00507 CallEndReason reason
00508 );
00509
00517 void ClearCall(
00518 CallEndReason reason = EndedByLocalUser
00519 );
00520
00523 virtual void ClearCallSynchronous(
00524 PSyncPoint * sync,
00525 CallEndReason reason = EndedByLocalUser
00526 );
00527
00531 unsigned GetQ931Cause() const { return q931Cause; }
00532
00536 void SetQ931Cause(unsigned v) { q931Cause = v; }
00537
00544 virtual bool TransferConnection(
00545 const PString & remoteParty
00546 );
00547
00550 virtual bool HoldConnection();
00551
00555 virtual bool RetrieveConnection();
00556
00559 virtual PBoolean IsConnectionOnHold();
00560
00565 virtual void OnHold(
00566 bool fromRemote,
00567 bool onHold
00568 );
00570
00598 virtual PBoolean OnIncomingConnection(unsigned int options, OpalConnection::StringOptions * stringOptions);
00599 virtual PBoolean OnIncomingConnection(unsigned int options);
00600 virtual PBoolean OnIncomingConnection();
00601
00608 virtual PBoolean SetUpConnection() = 0;
00609
00613 virtual PBoolean OnSetUpConnection();
00614
00615
00630 virtual void OnProceeding();
00631
00642 virtual void OnAlerting();
00643
00654 virtual PBoolean SetAlerting(
00655 const PString & calleeName,
00656 PBoolean withMedia
00657 ) = 0;
00658
00675 virtual AnswerCallResponse OnAnswerCall(
00676 const PString & callerName
00677 );
00678
00689 virtual void AnsweringCall(
00690 AnswerCallResponse response
00691 );
00692
00707 virtual void OnConnected();
00708
00719 virtual PBoolean SetConnected();
00720
00732 virtual void OnEstablished();
00733
00742 virtual void Release(
00743 CallEndReason reason = EndedByLocalUser
00744 );
00745
00763 virtual void OnReleased();
00765
00776 virtual PString GetDestinationAddress();
00777
00787 virtual PBoolean ForwardCall(
00788 const PString & forwardParty
00789 );
00790
00793 PSafePtr<OpalConnection> GetOtherPartyConnection() const;
00794
00797 template <class cls> PSafePtr<cls> GetOtherPartyConnectionAs() const { return PSafePtrCast<OpalConnection, cls>(GetOtherPartyConnection()); }
00799
00808 virtual OpalMediaFormatList GetMediaFormats() const;
00809
00814 virtual OpalMediaFormatList GetLocalMediaFormats();
00815
00824 virtual void AdjustMediaFormats(
00825 OpalMediaFormatList & mediaFormats
00826 ) const;
00827
00830 virtual OpalMediaStreamPtr OpenMediaStream(
00831 const OpalMediaFormat & mediaFormat,
00832 unsigned sessionID,
00833 bool isSource
00834 );
00835
00840 virtual bool CloseMediaStream(
00841 unsigned sessionId,
00842 bool source
00843 );
00844
00849 virtual bool CloseMediaStream(
00850 OpalMediaStream & stream
00851 );
00852
00860 bool RemoveMediaStream(
00861 OpalMediaStream & strm
00862 );
00863
00866 virtual void StartMediaStreams();
00867
00870 virtual void CloseMediaStreams();
00871
00874 virtual void PauseMediaStreams(PBoolean paused);
00875
00888 virtual OpalMediaStream * CreateMediaStream(
00889 const OpalMediaFormat & mediaFormat,
00890 unsigned sessionID,
00891 PBoolean isSource
00892 );
00893
00897 OpalMediaStreamPtr GetMediaStream(
00898 const PString & streamID,
00899 bool source
00900 ) const;
00901
00907 OpalMediaStreamPtr GetMediaStream(
00908 unsigned sessionId,
00909 bool source
00910 ) const;
00911
00917 OpalMediaStreamPtr GetMediaStream(
00918 const OpalMediaType & mediaType,
00919 bool source
00920 ) const;
00921
00933 virtual PBoolean OnOpenMediaStream(
00934 OpalMediaStream & stream
00935 );
00936
00941 virtual void OnClosedMediaStream(
00942 const OpalMediaStream & stream
00943 );
00944
00949 virtual void OnPatchMediaStream(
00950 PBoolean isSource,
00951 OpalMediaPatch & patch
00952 );
00953
00958 virtual void AttachRFC2833HandlerToPatch(PBoolean isSource, OpalMediaPatch & patch);
00959
00965 virtual PBoolean IsMediaBypassPossible(
00966 unsigned sessionID
00967 ) const;
00968
00969 #if OPAL_VIDEO
00970
00975 virtual void AddVideoMediaFormats(
00976 OpalMediaFormatList & mediaFormats
00977 ) const;
00978
00981 virtual PBoolean CreateVideoInputDevice(
00982 const OpalMediaFormat & mediaFormat,
00983 PVideoInputDevice * & device,
00984 PBoolean & autoDelete
00985 );
00986
00990 virtual PBoolean CreateVideoOutputDevice(
00991 const OpalMediaFormat & mediaFormat,
00992 PBoolean preview,
00993 PVideoOutputDevice * & device,
00994 PBoolean & autoDelete
00995 );
00996 #endif
00997
01000 virtual PBoolean SetAudioVolume(
01001 PBoolean source,
01002 unsigned percentage
01003 );
01004
01008 virtual unsigned GetAudioSignalLevel(
01009 PBoolean source
01010 );
01012
01017 unsigned GetBandwidthAvailable() const { return bandwidthAvailable; }
01018
01023 virtual PBoolean SetBandwidthAvailable(
01024 unsigned newBandwidth,
01025 PBoolean force = PFalse
01026 );
01027
01032 virtual unsigned GetBandwidthUsed() const;
01033
01042 virtual PBoolean SetBandwidthUsed(
01043 unsigned releasedBandwidth,
01044 unsigned requiredBandwidth
01045 );
01047
01050 enum SendUserInputModes {
01051 SendUserInputAsQ931,
01052 SendUserInputAsString,
01053 SendUserInputAsTone,
01054 SendUserInputAsInlineRFC2833,
01055 SendUserInputAsSeparateRFC2833,
01056 SendUserInputAsProtocolDefault,
01057 NumSendUserInputModes
01058 };
01059 #if PTRACING
01060 friend ostream & operator<<(ostream & o, SendUserInputModes m);
01061 #endif
01062
01065 virtual void SetSendUserInputMode(SendUserInputModes mode);
01066
01069 virtual SendUserInputModes GetSendUserInputMode() const { return sendUserInputMode; }
01070
01076 virtual SendUserInputModes GetRealSendUserInputMode() const { return GetSendUserInputMode(); }
01077
01084 virtual PBoolean SendUserInputString(
01085 const PString & value
01086 );
01087
01104 virtual PBoolean SendUserInputTone(
01105 char tone,
01106 unsigned duration = 0
01107 );
01108
01115 virtual void OnUserInputString(
01116 const PString & value
01117 );
01118
01125 virtual void OnUserInputTone(
01126 char tone,
01127 unsigned duration
01128 );
01129
01133 void SendUserInputHookFlash(
01134 unsigned duration = 500
01135 ) { SendUserInputTone('!', duration); }
01136
01139 virtual PString GetUserInput(
01140 unsigned timeout = 30
01141 );
01142
01147 virtual void SetUserInput(
01148 const PString & input
01149 );
01150
01153 virtual PString ReadUserInput(
01154 const char * terminators = "#\r\n",
01155 unsigned lastDigitTimeout = 4,
01156 unsigned firstDigitTimeout = 30
01157 );
01158
01165 virtual PBoolean PromptUserInput(
01166 PBoolean play
01167 );
01169
01174 virtual bool GarbageCollection();
01176
01181 OpalEndPoint & GetEndPoint() const { return endpoint; }
01182
01185 OpalCall & GetCall() const { return ownerCall; }
01186
01189 const PString & GetToken() const { return callToken; }
01190
01193 PBoolean IsOriginating() const { return originating; }
01194
01197 PTime GetSetupUpTime() const { return setupTime; }
01198
01201 PTime GetAlertingTime() const { return alertingTime; }
01202
01205 PTime GetConnectionStartTime() const { return connectedTime; }
01206
01209 PTime GetConnectionEndTime() const { return callEndTime; }
01210
01213 const OpalProductInfo & GetProductInfo() const { return productInfo; }
01214
01217 void SetProductInfo(
01218 const OpalProductInfo & info
01219 ) { productInfo = info; }
01220
01223 virtual PString GetPrefixName() const;
01224
01227 const PString & GetLocalPartyName() const { return localPartyName; }
01228
01231 virtual void SetLocalPartyName(const PString & name);
01232
01235 virtual PString GetLocalPartyURL() const;
01236
01239 const PString & GetDisplayName() const { return displayName; }
01240
01243 void SetDisplayName(const PString & name) { displayName = name; }
01244
01247 const PString & GetRemotePartyName() const { return remotePartyName; }
01248
01251 void SetRemotePartyName(const PString & name) { remotePartyName = name; }
01252
01261 const PString & GetRemotePartyNumber() const { return remotePartyNumber; }
01262
01268 const PString & GetRemotePartyAddress() const { return remotePartyAddress; }
01269
01272 void SetRemotePartyAddress(const PString & addr) { remotePartyAddress = addr; }
01273
01280 virtual PString GetRemotePartyURL() const;
01281
01282
01283 const PString GetRemotePartyCallbackURL() const { return GetRemotePartyURL(); }
01284
01288 PCaselessString GetRemoteApplication() const { return remoteProductInfo.AsString(); }
01289
01292 const OpalProductInfo & GetRemoteProductInfo() const { return remoteProductInfo; }
01293
01294
01301 const PString & GetCalledPartyName() const { return m_calledPartyName; }
01302
01309 const PString & GetCalledPartyNumber() const { return m_calledPartyNumber; }
01310
01318 virtual PString GetCalledPartyURL();
01319
01320
01321
01322
01323
01324
01325 void CopyPartyNames(const OpalConnection & other);
01326
01327
01341 virtual PString GetAlertingType() const;
01342
01356 virtual bool SetAlertingType(const PString & info);
01357
01358
01362 unsigned GetMinAudioJitterDelay() const { return minAudioJitterDelay; }
01363
01367 unsigned GetMaxAudioJitterDelay() const { return maxAudioJitterDelay; }
01368
01371 void SetAudioJitterDelay(
01372 unsigned minDelay,
01373 unsigned maxDelay
01374 );
01375
01378 OpalSilenceDetector * GetSilenceDetector() const { return silenceDetector; }
01379
01382 OpalEchoCanceler * GetEchoCanceler() const { return echoCanceler; }
01383
01387 virtual PString GetIdentifier() const;
01388
01397 virtual PINDEX GetMaxRtpPayloadSize() const;
01398
01399 virtual OpalTransport & GetTransport() const
01400 { return *(OpalTransport *)NULL; }
01401
01402 PDICTIONARY(MediaAddressesDict, POrdinalKey, OpalTransportAddress);
01403 MediaAddressesDict & GetMediaTransportAddresses()
01404 { return mediaTransportAddresses; }
01405
01406 #if OPAL_STATISTICS
01407
01409 unsigned GetVideoUpdateRequestsSent() const { return m_VideoUpdateRequestsSent; }
01410 #endif
01411
01412
01414 const StringOptions & GetStringOptions() const { return m_connStringOptions; }
01415
01417 void SetStringOptions(
01418 const StringOptions & options,
01419 bool overwrite
01420 );
01421
01422 virtual void ApplyStringOptions(OpalConnection::StringOptions & stringOptions);
01423 virtual void OnApplyStringOptions();
01424
01425 virtual void PreviewPeerMediaFormats(const OpalMediaFormatList & fmts);
01426
01427 virtual void EnableRecording();
01428 virtual void DisableRecording();
01429
01430 virtual void OnMediaPatchStart(
01431 unsigned sessionId,
01432 bool isSource
01433 );
01434 virtual void OnMediaPatchStop(
01435 unsigned sessionId,
01436 bool isSource
01437 );
01438
01442 PDECLARE_NOTIFIER(OpalMediaCommand, OpalConnection, OnMediaCommand);
01443
01450 virtual OpalMediaType::AutoStartMode GetAutoStart(
01451 const OpalMediaType & mediaType
01452 ) const;
01453
01454 #if OPAL_HAS_IM
01455 struct IMInfo : public PObject {
01456 unsigned sessionId;
01457 OpalMediaFormat mediaFormat;
01458 T140String body;
01459 };
01460
01461 virtual bool SendIM(const OpalMediaFormat & format, const T140String & body);
01462 virtual bool SendIM(const OpalMediaFormat & format, const RTP_DataFrame & body);
01463 virtual void OnReceiveIM(const IMInfo & im);
01464
01465 void AddIMListener(
01466 const PNotifier & listener
01467 );
01468 #endif
01469
01470 protected:
01471 void OnConnectedInternal();
01472
01473 #if OPAL_PTLIB_DTMF
01474 PDECLARE_NOTIFIER(RTP_DataFrame, OpalConnection, OnUserInputInBandDTMF);
01475 #endif
01476 PDECLARE_NOTIFIER(PThread, OpalConnection, OnReleaseThreadMain);
01477 PDECLARE_NOTIFIER(RTP_DataFrame, OpalConnection, OnRecordAudio);
01478
01479
01480 OpalCall & ownerCall;
01481 OpalEndPoint & endpoint;
01482
01483 private:
01484 PMutex phaseMutex;
01485 Phases phase;
01486
01487 protected:
01488 PString callToken;
01489 PBoolean originating;
01490 PTime setupTime;
01491 PTime alertingTime;
01492 PTime connectedTime;
01493 PTime callEndTime;
01494 OpalProductInfo productInfo;
01495 PString localPartyName;
01496 PString displayName;
01497 PString remotePartyName;
01498 OpalProductInfo remoteProductInfo;
01499 PString remotePartyNumber;
01500 PString remotePartyAddress;
01501 CallEndReason callEndReason;
01502 bool synchronousOnRelease;
01503 PString m_calledPartyNumber;
01504 PString m_calledPartyName;
01505
01506 SendUserInputModes sendUserInputMode;
01507 PString userInputString;
01508 PSyncPoint userInputAvailable;
01509 PBoolean detectInBandDTMF;
01510 unsigned dtmfScaleMultiplier;
01511 unsigned dtmfScaleDivisor;
01512 unsigned q931Cause;
01513
01514 OpalSilenceDetector * silenceDetector;
01515 OpalEchoCanceler * echoCanceler;
01516
01517 MediaAddressesDict mediaTransportAddresses;
01518 PSafeList<OpalMediaStream> mediaStreams;
01519
01520 unsigned minAudioJitterDelay;
01521 unsigned maxAudioJitterDelay;
01522 unsigned bandwidthAvailable;
01523
01524
01525
01526 #if OPAL_PTLIB_DTMF
01527 PDTMFDecoder dtmfDecoder;
01528 #endif
01529
01533 void SetPhase(Phases phaseToSet);
01534
01535 #if PTRACING
01536 friend ostream & operator<<(ostream & o, Phases p);
01537 #endif
01538
01539 StringOptions m_connStringOptions;
01540 PString recordAudioFilename;
01541 PNotifier recordNotifier;
01542
01543 #if OPAL_STATISTICS
01544 unsigned m_VideoUpdateRequestsSent;
01545 #endif
01546
01547 struct AutoStartInfo {
01548 unsigned preferredSessionId;
01549 OpalMediaType::AutoStartMode autoStart;
01550 };
01551
01552 class AutoStartMap : public std::map<OpalMediaType, AutoStartInfo>
01553 {
01554 public:
01555 AutoStartMap();
01556 void Initialise(const OpalConnection::StringOptions & stringOptions);
01557 OpalMediaType::AutoStartMode GetAutoStart(const OpalMediaType & mediaType) const;
01558 void SetAutoStart(const OpalMediaType & mediaType, OpalMediaType::AutoStartMode autoStart);
01559
01560 protected:
01561 bool m_initialised;
01562 PMutex m_mutex;
01563
01564 };
01565 AutoStartMap m_autoStartInfo;
01566
01567 #if OPAL_HAS_IM
01568 mutable PList<PNotifier> m_imListeners;
01569 #endif
01570
01571 };
01572
01573 #endif // OPAL_OPAL_CONNECTION_H
01574
01575
01576