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
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 #ifndef __OPAL_CONNECTION_H
00354 #define __OPAL_CONNECTION_H
00355
00356 #ifdef P_USE_PRAGMA
00357 #pragma interface
00358 #endif
00359
00360 #include <opal/buildopts.h>
00361
00362 #include <opal/mediafmt.h>
00363 #include <opal/mediastrm.h>
00364 #include <opal/guid.h>
00365 #include <opal/transports.h>
00366 #include <ptclib/dtmf.h>
00367 #include <ptlib/safecoll.h>
00368 #include <rtp/rtp.h>
00369
00370 class OpalEndPoint;
00371 class OpalCall;
00372 class OpalSilenceDetector;
00373 class OpalEchoCanceler;
00374 class OpalRFC2833Proto;
00375 class OpalRFC2833Info;
00376 class OpalT120Protocol;
00377 class OpalT38Protocol;
00378 class OpalH224Handler;
00379 class OpalH281Handler;
00380
00381
00384 class OpalProductInfo
00385 {
00386 public:
00387 OpalProductInfo();
00388
00389 static OpalProductInfo & Default();
00390
00391 PCaselessString AsString() const;
00392
00393 PString vendor;
00394 PString name;
00395 PString version;
00396 BYTE t35CountryCode;
00397 BYTE t35Extension;
00398 WORD manufacturerCode;
00399 };
00400
00401
00419 class OpalConnection : public PSafeObject
00420 {
00421 PCLASSINFO(OpalConnection, PSafeObject);
00422 public:
00427 enum CallEndReason {
00428 EndedByLocalUser,
00429 EndedByNoAccept,
00430 EndedByAnswerDenied,
00431 EndedByRemoteUser,
00432 EndedByRefusal,
00433 EndedByNoAnswer,
00434 EndedByCallerAbort,
00435 EndedByTransportFail,
00436 EndedByConnectFail,
00437 EndedByGatekeeper,
00438 EndedByNoUser,
00439 EndedByNoBandwidth,
00440 EndedByCapabilityExchange,
00441 EndedByCallForwarded,
00442 EndedBySecurityDenial,
00443 EndedByLocalBusy,
00444 EndedByLocalCongestion,
00445 EndedByRemoteBusy,
00446 EndedByRemoteCongestion,
00447 EndedByUnreachable,
00448 EndedByNoEndPoint,
00449 EndedByHostOffline,
00450 EndedByTemporaryFailure,
00451 EndedByQ931Cause,
00452 EndedByDurationLimit,
00453 EndedByInvalidConferenceID,
00454 EndedByNoDialTone,
00455 EndedByNoRingBackTone,
00456 EndedByOutOfService,
00457 EndedByAcceptingCallWaiting,
00458 NumCallEndReasons,
00459
00460 EndedWithQ931Code = 0x100
00461 };
00462
00463 #if PTRACING
00464 friend ostream & operator<<(ostream & o, CallEndReason reason);
00465 #endif
00466
00467 enum AnswerCallResponse {
00468 AnswerCallNow,
00469 AnswerCallDenied,
00470 AnswerCallPending,
00471 AnswerCallDeferred,
00472 AnswerCallAlertWithMedia,
00473 AnswerCallDeferredWithMedia,
00474 AnswerCallProgress,
00475 AnswerCallNowAndReleaseCurrent,
00476 NumAnswerCallResponses
00477 };
00478 #if PTRACING
00479 friend ostream & operator<<(ostream & o, AnswerCallResponse s);
00480 #endif
00481
00484 enum Options {
00485 FastStartOptionDisable = 0x0001,
00486 FastStartOptionEnable = 0x0002,
00487 FastStartOptionMask = 0x0003,
00488
00489 H245TunnelingOptionDisable = 0x0004,
00490 H245TunnelingOptionEnable = 0x0008,
00491 H245TunnelingOptionMask = 0x000c,
00492
00493 H245inSetupOptionDisable = 0x0010,
00494 H245inSetupOptionEnable = 0x0020,
00495 H245inSetupOptionMask = 0x0030,
00496
00497 DetectInBandDTMFOptionDisable = 0x0040,
00498 DetectInBandDTMFOptionEnable = 0x0080,
00499 DetectInBandDTMFOptionMask = 0x00c0,
00500
00501 RTPAggregationDisable = 0x0100,
00502 RTPAggregationEnable = 0x0200,
00503 RTPAggregationMask = 0x0300,
00504
00505 SendDTMFAsDefault = 0x0000,
00506 SendDTMFAsString = 0x0400,
00507 SendDTMFAsTone = 0x0800,
00508 SendDTMFAsRFC2833 = 0x0c00,
00509 SendDTMFMask = 0x0c00
00510 };
00511
00512 class StringOptions : public PStringToString
00513 {
00514 };
00515
00520 OpalConnection(
00521 OpalCall & call,
00522 OpalEndPoint & endpoint,
00523 const PString & token,
00524 unsigned options = 0,
00525 OpalConnection::StringOptions * stringOptions = NULL
00526 );
00527
00530 ~OpalConnection();
00532
00539 void PrintOn(
00540 ostream & strm
00541 ) const;
00543
00546 enum Phases {
00547 UninitialisedPhase,
00548 SetUpPhase,
00549 AlertingPhase,
00550 ConnectedPhase,
00551 EstablishedPhase,
00552 ReleasingPhase,
00553 ReleasedPhase,
00554 NumPhases
00555 };
00556
00561 inline Phases GetPhase() const { return phase; }
00562
00571 CallEndReason GetCallEndReason() const { return callEndReason; }
00572
00577 virtual void SetCallEndReason(
00578 CallEndReason reason
00579 );
00580
00588 void ClearCall(
00589 CallEndReason reason = EndedByLocalUser
00590 );
00591
00594 virtual void ClearCallSynchronous(
00595 PSyncPoint * sync,
00596 CallEndReason reason = EndedByLocalUser
00597 );
00598
00602 unsigned GetQ931Cause() const { return q931Cause; }
00603
00607 void SetQ931Cause(unsigned v) { q931Cause = v; }
00608
00612 virtual void TransferConnection(
00613 const PString & remoteParty,
00614 const PString & callIdentity = PString::Empty()
00616 );
00617
00620 virtual void HoldConnection();
00621
00625 virtual void RetrieveConnection();
00626
00629 virtual BOOL IsConnectionOnHold();
00631
00659 virtual BOOL OnIncomingConnection(unsigned int options, OpalConnection::StringOptions * stringOptions);
00660 virtual BOOL OnIncomingConnection(unsigned int options);
00661 virtual BOOL OnIncomingConnection();
00662
00669 virtual BOOL SetUpConnection() = 0;
00670
00674 virtual BOOL OnSetUpConnection();
00675
00676
00692 virtual void OnAlerting();
00693
00704 virtual BOOL SetAlerting(
00705 const PString & calleeName,
00706 BOOL withMedia
00707 ) = 0;
00708
00725 virtual AnswerCallResponse OnAnswerCall(
00726 const PString & callerName
00727 );
00728
00739 virtual void AnsweringCall(
00740 AnswerCallResponse response
00741 );
00742
00753 virtual void OnConnected();
00754
00759 virtual BOOL SetConnected() = 0;
00760
00771 virtual void OnEstablished();
00772
00781 virtual void Release(
00782 CallEndReason reason = EndedByLocalUser
00783 );
00784
00802 virtual void OnReleased();
00804
00814 virtual PString GetDestinationAddress();
00815
00825 virtual BOOL ForwardCall(
00826 const PString & forwardParty
00827 );
00829
00838 virtual OpalMediaFormatList GetMediaFormats() const = 0;
00839
00844 virtual OpalMediaFormatList GetLocalMediaFormats();
00845
00854 virtual void AdjustMediaFormats(
00855 OpalMediaFormatList & mediaFormats
00856 ) const;
00857
00860 virtual BOOL OpenSourceMediaStream(
00861 const OpalMediaFormatList & mediaFormats,
00862 unsigned sessionID
00863 );
00864
00867 virtual OpalMediaStream * OpenSinkMediaStream(
00868 OpalMediaStream & source
00869 );
00870
00873 virtual void StartMediaStreams();
00874
00877 virtual void CloseMediaStreams();
00878
00881 virtual void RemoveMediaStreams();
00882
00885 virtual void PauseMediaStreams(BOOL paused);
00886
00901 virtual OpalMediaStream * CreateMediaStream(
00902 const OpalMediaFormat & mediaFormat,
00903 unsigned sessionID,
00904 BOOL isSource
00905 );
00906
00918 virtual BOOL OnOpenMediaStream(
00919 OpalMediaStream & stream
00920 );
00921
00926 virtual void OnClosedMediaStream(
00927 const OpalMediaStream & stream
00928 );
00929
00934 virtual void OnPatchMediaStream(
00935 BOOL isSource,
00936 OpalMediaPatch & patch
00937 );
00938
00943 virtual void AttachRFC2833HandlerToPatch(BOOL isSource, OpalMediaPatch & patch);
00944
00950 OpalMediaStream * GetMediaStream(
00951 unsigned sessionId,
00952 BOOL source
00953 ) const;
00954
00963 BOOL RemoveMediaStream(
00964 OpalMediaStream * strm
00965 );
00966
00972 virtual BOOL IsMediaBypassPossible(
00973 unsigned sessionID
00974 ) const;
00975
00978 struct MediaInformation {
00979 MediaInformation() {
00980 rfc2833 = RTP_DataFrame::IllegalPayloadType;
00981 #if OPAL_T38FAX
00982 ciscoNSE = RTP_DataFrame::IllegalPayloadType;
00983 #endif
00984 }
00985
00986 OpalTransportAddress data;
00987 OpalTransportAddress control;
00988 RTP_DataFrame::PayloadTypes rfc2833;
00989 #if OPAL_T38FAX
00990 RTP_DataFrame::PayloadTypes ciscoNSE;
00991 #endif
00992 };
00993
01002 virtual BOOL GetMediaInformation(
01003 unsigned sessionID,
01004 MediaInformation & info
01005 ) const;
01006
01007 #if OPAL_VIDEO
01008
01013 virtual void AddVideoMediaFormats(
01014 OpalMediaFormatList & mediaFormats
01015 ) const;
01016
01019 virtual BOOL CreateVideoInputDevice(
01020 const OpalMediaFormat & mediaFormat,
01021 PVideoInputDevice * & device,
01022 BOOL & autoDelete
01023 );
01024
01028 virtual BOOL CreateVideoOutputDevice(
01029 const OpalMediaFormat & mediaFormat,
01030 BOOL preview,
01031 PVideoOutputDevice * & device,
01032 BOOL & autoDelete
01033 );
01034 #endif
01035
01038 virtual BOOL SetAudioVolume(
01039 BOOL source,
01040 unsigned percentage
01041 );
01042
01046 virtual unsigned GetAudioSignalLevel(
01047 BOOL source
01048 );
01050
01056 virtual RTP_Session * GetSession(
01057 unsigned sessionID
01058 ) const;
01059
01074 virtual RTP_Session * UseSession(
01075 unsigned sessionID
01076 );
01077 virtual RTP_Session * UseSession(
01078 const OpalTransport & transport,
01079 unsigned sessionID,
01080 RTP_QOS * rtpqos = NULL
01081 );
01082
01087 virtual void ReleaseSession(
01088 unsigned sessionID,
01089 BOOL clearAll = FALSE
01090 );
01091
01096 virtual RTP_Session * CreateSession(
01097 const OpalTransport & transport,
01098 unsigned sessionID,
01099 RTP_QOS * rtpqos
01100 );
01102
01107 unsigned GetBandwidthAvailable() const { return bandwidthAvailable; }
01108
01113 virtual BOOL SetBandwidthAvailable(
01114 unsigned newBandwidth,
01115 BOOL force = FALSE
01116 );
01117
01122 virtual unsigned GetBandwidthUsed() const;
01123
01132 virtual BOOL SetBandwidthUsed(
01133 unsigned releasedBandwidth,
01134 unsigned requiredBandwidth
01135 );
01137
01140 enum SendUserInputModes {
01141 SendUserInputAsQ931,
01142 SendUserInputAsString,
01143 SendUserInputAsTone,
01144 SendUserInputAsInlineRFC2833,
01145 SendUserInputAsSeparateRFC2833,
01146 SendUserInputAsProtocolDefault,
01147 NumSendUserInputModes
01148 };
01149 #if PTRACING
01150 friend ostream & operator<<(ostream & o, SendUserInputModes m);
01151 #endif
01152
01155 virtual void SetSendUserInputMode(SendUserInputModes mode);
01156
01159 virtual SendUserInputModes GetSendUserInputMode() const { return sendUserInputMode; }
01160
01166 virtual SendUserInputModes GetRealSendUserInputMode() const { return GetSendUserInputMode(); }
01167
01174 virtual BOOL SendUserInputString(
01175 const PString & value
01176 );
01177
01194 virtual BOOL SendUserInputTone(
01195 char tone,
01196 unsigned duration = 0
01197 );
01198
01205 virtual void OnUserInputString(
01206 const PString & value
01207 );
01208
01215 virtual void OnUserInputTone(
01216 char tone,
01217 unsigned duration
01218 );
01219
01223 void SendUserInputHookFlash(
01224 unsigned duration = 500
01225 ) { SendUserInputTone('!', duration); }
01226
01229 virtual PString GetUserInput(
01230 unsigned timeout = 30
01231 );
01232
01237 virtual void SetUserInput(
01238 const PString & input
01239 );
01240
01243 virtual PString ReadUserInput(
01244 const char * terminators = "#\r\n",
01245 unsigned lastDigitTimeout = 4,
01246 unsigned firstDigitTimeout = 30
01247 );
01248
01255 virtual BOOL PromptUserInput(
01256 BOOL play
01257 );
01259
01262 #if OPAL_T120DATA
01263
01275 virtual OpalT120Protocol * CreateT120ProtocolHandler();
01276 #endif
01277
01278 #if OPAL_T38FAX
01279
01291 virtual OpalT38Protocol * CreateT38ProtocolHandler();
01292 #endif
01293
01294 #if OPAL_H224
01295
01307 virtual OpalH224Handler *CreateH224ProtocolHandler(unsigned sessionID);
01308
01318 virtual OpalH281Handler *CreateH281ProtocolHandler(OpalH224Handler & h224Handler);
01319
01323 OpalH224Handler * GetH224Handler() const { return h224Handler; }
01324 #endif
01325
01327
01332 OpalEndPoint & GetEndPoint() const { return endpoint; }
01333
01336 OpalCall & GetCall() const { return ownerCall; }
01337
01340 const PString & GetToken() const { return callToken; }
01341
01344 BOOL IsOriginating() const { return originating; }
01345
01348 PTime GetSetupUpTime() const { return setupTime; }
01349
01352 PTime GetAlertingTime() const { return alertingTime; }
01353
01356 PTime GetConnectionStartTime() const { return connectedTime; }
01357
01360 PTime GetConnectionEndTime() const { return callEndTime; }
01361
01364 const OpalProductInfo & GetProductInfo() const { return productInfo; }
01365
01368 void SetProductInfo(
01369 const OpalProductInfo & info
01370 ) { productInfo = info; }
01371
01374 const PString & GetLocalPartyName() const { return localPartyName; }
01375
01378 virtual void SetLocalPartyName(const PString & name);
01379
01382 const PString & GetDisplayName() const { return displayName; }
01383
01386 void SetDisplayName(const PString & name) { displayName = name; }
01387
01390 const PString & GetRemotePartyName() const { return remotePartyName; }
01391
01395 PCaselessString GetRemoteApplication() const { return remoteProductInfo.AsString(); }
01396
01399 const OpalProductInfo & GetRemoteProductInfo() const { return remoteProductInfo; }
01400
01405 const PString & GetRemotePartyNumber() const { return remotePartyNumber; }
01406
01409 const PString & GetRemotePartyAddress() const { return remotePartyAddress; }
01410
01415 virtual const PString GetRemotePartyCallbackURL() const { return remotePartyAddress; }
01416
01417
01421 virtual const PString & GetCalledDestinationNumber() const { return calledDestinationNumber; }
01422
01426 virtual const PString & GetCalledDestinationName() const { return calledDestinationName; }
01427
01431 virtual const PString & GetCalledDestinationURL() const { return calledDestinationURL; }
01432
01436 unsigned GetMinAudioJitterDelay() const { return minAudioJitterDelay; }
01437
01441 unsigned GetMaxAudioJitterDelay() const { return maxAudioJitterDelay; }
01442
01445 void SetAudioJitterDelay(
01446 unsigned minDelay,
01447 unsigned maxDelay
01448 );
01449
01452 OpalSilenceDetector * GetSilenceDetector() const { return silenceDetector; }
01453
01456 OpalEchoCanceler * GetEchoCanceler() const { return echoCanceler; }
01457
01460 virtual const OpalGloballyUniqueID & GetIdentifier() const
01461 { return callIdentifier; }
01462
01463 virtual OpalTransport & GetTransport() const
01464 { return *(OpalTransport *)NULL; }
01465
01466 PDICTIONARY(MediaAddressesDict, POrdinalKey, OpalTransportAddress);
01467 MediaAddressesDict & GetMediaTransportAddresses()
01468 { return mediaTransportAddresses; }
01469
01471
01472 const RTP_DataFrame::PayloadMapType & GetRTPPayloadMap() const
01473 { return rtpPayloadMap; }
01474
01477 BOOL RemoteIsNAT() const
01478 { return remoteIsNAT; }
01479
01480 virtual void SetSecurityMode(const PString & v)
01481 { securityMode = v; }
01482
01483 virtual PString GetSecurityMode() const
01484 { return securityMode; }
01485
01486 StringOptions * GetStringOptions() const
01487 { return stringOptions; }
01488
01489 void SetStringOptions(StringOptions * options);
01490
01491 virtual BOOL OnOpenIncomingMediaChannels();
01492
01493 virtual void ApplyStringOptions();
01494
01495 virtual void PreviewPeerMediaFormats(const OpalMediaFormatList & fmts);
01496
01497 virtual void EnableRecording();
01498 virtual void DisableRecording();
01499
01500 virtual BOOL IsRTPNATEnabled(const PIPSocket::Address & localAddr,
01501 const PIPSocket::Address & peerAddr,
01502 const PIPSocket::Address & sigAddr,
01503 BOOL incoming);
01504
01505 protected:
01506 PDECLARE_NOTIFIER(OpalRFC2833Info, OpalConnection, OnUserInputInlineRFC2833);
01507 PDECLARE_NOTIFIER(OpalRFC2833Info, OpalConnection, OnUserInputInlineCiscoNSE);
01508 #if P_DTMF
01509 PDECLARE_NOTIFIER(RTP_DataFrame, OpalConnection, OnUserInputInBandDTMF);
01510 #endif
01511 PDECLARE_NOTIFIER(PThread, OpalConnection, OnReleaseThreadMain);
01512 PDECLARE_NOTIFIER(RTP_DataFrame, OpalConnection, OnRecordAudio);
01513
01514
01515 OpalCall & ownerCall;
01516 OpalEndPoint & endpoint;
01517
01518 PMutex phaseMutex;
01519 Phases phase;
01520
01521 PString callToken;
01522 OpalGloballyUniqueID callIdentifier;
01523 BOOL originating;
01524 PTime setupTime;
01525 PTime alertingTime;
01526 PTime connectedTime;
01527 PTime callEndTime;
01528 OpalProductInfo productInfo;
01529 PString localPartyName;
01530 PString displayName;
01531 PString remotePartyName;
01532 OpalProductInfo remoteProductInfo;
01533 PString remotePartyNumber;
01534 PString remotePartyAddress;
01535 CallEndReason callEndReason;
01536 PString calledDestinationNumber;
01537 PString calledDestinationName;
01538 PString calledDestinationURL;
01539 BOOL remoteIsNAT;
01540
01541 SendUserInputModes sendUserInputMode;
01542 PString userInputString;
01543 PSyncPoint userInputAvailable;
01544 BOOL detectInBandDTMF;
01545 unsigned q931Cause;
01546
01547 OpalSilenceDetector * silenceDetector;
01548 OpalEchoCanceler * echoCanceler;
01549 OpalRFC2833Proto * rfc2833Handler;
01550 #if OPAL_T120DATA
01551 OpalT120Protocol * t120handler;
01552 #endif
01553 #if OPAL_T38FAX
01554 OpalT38Protocol * t38handler;
01555 OpalRFC2833Proto * ciscoNSEHandler;
01556 #endif
01557 #if OPAL_H224
01558 OpalH224Handler * h224Handler;
01559 #endif
01560
01561 MediaAddressesDict mediaTransportAddresses;
01562 OpalMediaStreamList mediaStreams;
01563 RTP_SessionManager rtpSessions;
01564 unsigned minAudioJitterDelay;
01565 unsigned maxAudioJitterDelay;
01566 unsigned bandwidthAvailable;
01567
01568 RTP_DataFrame::PayloadMapType rtpPayloadMap;
01569
01570
01571
01572 #if P_DTMF
01573 PDTMFDecoder dtmfDecoder;
01574 #endif
01575
01576 PString securityMode;
01577
01581 void SetPhase(Phases phaseToSet);
01582
01583 #if PTRACING
01584 friend ostream & operator<<(ostream & o, Phases p);
01585 #endif
01586
01587 BOOL useRTPAggregation;
01588
01589 StringOptions * stringOptions;
01590 PString recordAudioFilename;
01591
01592 virtual OpalMediaStream * InternalCreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, BOOL isSource);
01593 };
01594
01595 class RTP_UDP;
01596
01597 class OpalSecurityMode : public PObject
01598 {
01599 PCLASSINFO(OpalSecurityMode, PObject);
01600 public:
01601 virtual RTP_UDP * CreateRTPSession(
01602 PHandleAggregator * _aggregator,
01603 unsigned id,
01604 BOOL remoteIsNAT
01605 ) = 0;
01606 virtual BOOL Open() = 0;
01607 };
01608
01609
01610 #endif // __OPAL_CONNECTION_H
01611
01612
01613