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 #ifndef __OPAL_CONNECTION_H
00211 #define __OPAL_CONNECTION_H
00212
00213 #ifdef P_USE_PRAGMA
00214 #pragma interface
00215 #endif
00216
00217 #include <opal/buildopts.h>
00218
00219 #include <opal/mediafmt.h>
00220 #include <opal/mediastrm.h>
00221 #include <opal/guid.h>
00222 #include <opal/transports.h>
00223 #include <ptclib/dtmf.h>
00224 #include <ptlib/safecoll.h>
00225 #include <rtp/rtp.h>
00226
00227 class OpalEndPoint;
00228 class OpalCall;
00229 class OpalSilenceDetector;
00230 class OpalEchoCanceler;
00231 class OpalRFC2833Proto;
00232 class OpalRFC2833Info;
00233 class OpalT120Protocol;
00234 class OpalT38Protocol;
00235
00236
00254 class OpalConnection : public PSafeObject
00255 {
00256 PCLASSINFO(OpalConnection, PSafeObject);
00257 public:
00262 enum CallEndReason {
00263 EndedByLocalUser,
00264 EndedByNoAccept,
00265 EndedByAnswerDenied,
00266 EndedByRemoteUser,
00267 EndedByRefusal,
00268 EndedByNoAnswer,
00269 EndedByCallerAbort,
00270 EndedByTransportFail,
00271 EndedByConnectFail,
00272 EndedByGatekeeper,
00273 EndedByNoUser,
00274 EndedByNoBandwidth,
00275 EndedByCapabilityExchange,
00276 EndedByCallForwarded,
00277 EndedBySecurityDenial,
00278 EndedByLocalBusy,
00279 EndedByLocalCongestion,
00280 EndedByRemoteBusy,
00281 EndedByRemoteCongestion,
00282 EndedByUnreachable,
00283 EndedByNoEndPoint,
00284 EndedByHostOffline,
00285 EndedByTemporaryFailure,
00286 EndedByQ931Cause,
00287 EndedByDurationLimit,
00288 EndedByInvalidConferenceID,
00289 NumCallEndReasons
00290 };
00291
00292 #if PTRACING
00293 friend ostream & operator<<(ostream & o, CallEndReason reason);
00294 #endif
00295
00296 enum AnswerCallResponse {
00297 AnswerCallNow,
00298 AnswerCallDenied,
00299 AnswerCallPending,
00300 AnswerCallDeferred,
00301 AnswerCallAlertWithMedia,
00302 AnswerCallDeferredWithMedia,
00303 NumAnswerCallResponses
00304 };
00305 #if PTRACING
00306 friend ostream & operator<<(ostream & o, AnswerCallResponse s);
00307 #endif
00308
00309
00314 OpalConnection(
00315 OpalCall & call,
00316 OpalEndPoint & endpoint,
00317 const PString & token
00318 );
00319
00322 ~OpalConnection();
00324
00331 void PrintOn(
00332 ostream & strm
00333 ) const;
00335
00338 enum Phases {
00339 UninitialisedPhase,
00340 SetUpPhase,
00341 AlertingPhase,
00342 ConnectedPhase,
00343 EstablishedPhase,
00344 ReleasingPhase,
00345 ReleasedPhase,
00346 NumPhases
00347 };
00348
00353 inline Phases GetPhase() const { return phase; }
00354
00363 CallEndReason GetCallEndReason() const { return callEndReason; }
00364
00369 virtual void SetCallEndReason(
00370 CallEndReason reason
00371 );
00372
00380 void ClearCall(
00381 CallEndReason reason = EndedByLocalUser
00382 );
00383
00386 virtual void ClearCallSynchronous(
00387 PSyncPoint * sync,
00388 CallEndReason reason = EndedByLocalUser
00389 );
00390
00394 virtual void TransferConnection(
00395 const PString & remoteParty,
00396 const PString & callIdentity = PString::Empty()
00398 );
00399
00402 virtual void HoldConnection();
00403
00407 virtual void RetrieveConnection();
00408
00411 virtual BOOL IsConnectionOnHold();
00413
00437 virtual BOOL OnIncomingConnection();
00438
00445 virtual BOOL SetUpConnection() = 0;
00446
00462 virtual void OnAlerting();
00463
00474 virtual BOOL SetAlerting(
00475 const PString & calleeName,
00476 BOOL withMedia
00477 ) = 0;
00478
00495 virtual AnswerCallResponse OnAnswerCall(
00496 const PString & callerName
00497 );
00498
00509 virtual void AnsweringCall(
00510 AnswerCallResponse response
00511 );
00512
00523 virtual void OnConnected();
00524
00529 virtual BOOL SetConnected() = 0;
00530
00541 virtual void OnEstablished();
00542
00551 virtual void Release(
00552 CallEndReason reason = EndedByLocalUser
00553 );
00554
00572 virtual void OnReleased();
00574
00584 virtual PString GetDestinationAddress();
00585
00595 virtual BOOL ForwardCall(
00596 const PString & forwardParty
00597 );
00599
00608 virtual OpalMediaFormatList GetMediaFormats() const = 0;
00609
00618 virtual void AdjustMediaFormats(
00619 OpalMediaFormatList & mediaFormats
00620 ) const;
00621
00624 virtual BOOL OpenSourceMediaStream(
00625 const OpalMediaFormatList & mediaFormats,
00626 unsigned sessionID
00627 );
00628
00631 virtual OpalMediaStream * OpenSinkMediaStream(
00632 OpalMediaStream & source
00633 );
00634
00637 virtual void StartMediaStreams();
00638
00641 virtual void CloseMediaStreams();
00642
00645 virtual void RemoveMediaStreams();
00646
00649 virtual void PauseMediaStreams(BOOL paused);
00650
00665 virtual OpalMediaStream * CreateMediaStream(
00666 const OpalMediaFormat & mediaFormat,
00667 unsigned sessionID,
00668 BOOL isSource
00669 );
00670
00682 virtual BOOL OnOpenMediaStream(
00683 OpalMediaStream & stream
00684 );
00685
00690 virtual void OnClosedMediaStream(
00691 const OpalMediaStream & stream
00692 );
00693
00698 virtual void OnPatchMediaStream(
00699 BOOL isSource,
00700 OpalMediaPatch & patch
00701 );
00702
00708 OpalMediaStream * GetMediaStream(
00709 unsigned sessionId,
00710 BOOL source
00711 ) const;
00712
00718 virtual BOOL IsMediaBypassPossible(
00719 unsigned sessionID
00720 ) const;
00721
00724 struct MediaInformation {
00725 MediaInformation() { rfc2833 = RTP_DataFrame::IllegalPayloadType; }
00726
00727 OpalTransportAddress data;
00728 OpalTransportAddress control;
00729 RTP_DataFrame::PayloadTypes rfc2833;
00730 };
00731
00740 virtual BOOL GetMediaInformation(
00741 unsigned sessionID,
00742 MediaInformation & info
00743 ) const;
00744
00749 virtual void AddVideoMediaFormats(
00750 OpalMediaFormatList & mediaFormats
00751 ) const;
00752
00755 virtual BOOL CreateVideoInputDevice(
00756 const OpalMediaFormat & mediaFormat,
00757 PVideoInputDevice * & device,
00758 BOOL & autoDelete
00759 );
00760
00764 virtual BOOL CreateVideoOutputDevice(
00765 const OpalMediaFormat & mediaFormat,
00766 BOOL preview,
00767 PVideoOutputDevice * & device,
00768 BOOL & autoDelete
00769 );
00771
00777 virtual RTP_Session * GetSession(
00778 unsigned sessionID
00779 ) const;
00780
00795 virtual RTP_Session * UseSession(
00796 const OpalTransport & transport,
00797 unsigned sessionID,
00798 RTP_QOS * rtpqos = NULL
00799 );
00800
00805 virtual void ReleaseSession(
00806 unsigned sessionID
00807 );
00808
00813 virtual RTP_Session * CreateSession(
00814 const OpalTransport & transport,
00815 unsigned sessionID,
00816 RTP_QOS * rtpqos
00817 );
00819
00824 unsigned GetBandwidthAvailable() const { return bandwidthAvailable; }
00825
00830 virtual BOOL SetBandwidthAvailable(
00831 unsigned newBandwidth,
00832 BOOL force = FALSE
00833 );
00834
00839 virtual unsigned GetBandwidthUsed() const;
00840
00849 virtual BOOL SetBandwidthUsed(
00850 unsigned releasedBandwidth,
00851 unsigned requiredBandwidth
00852 );
00854
00863 virtual BOOL SendUserInputString(
00864 const PString & value
00865 );
00866
00883 virtual BOOL SendUserInputTone(
00884 char tone,
00885 unsigned duration = 0
00886 );
00887
00894 virtual void OnUserInputString(
00895 const PString & value
00896 );
00897
00904 virtual void OnUserInputTone(
00905 char tone,
00906 unsigned duration
00907 );
00908
00912 void SendUserInputHookFlash(
00913 unsigned duration = 500
00914 ) { SendUserInputTone('!', duration); }
00915
00918 virtual PString GetUserInput(
00919 unsigned timeout = 30
00920 );
00921
00926 virtual void SetUserInput(
00927 const PString & input
00928 );
00929
00932 virtual PString ReadUserInput(
00933 const char * terminators = "#\r\n",
00934 unsigned lastDigitTimeout = 4,
00935 unsigned firstDigitTimeout = 30
00936 );
00937
00944 virtual BOOL PromptUserInput(
00945 BOOL play
00946 );
00948
00963 virtual OpalT120Protocol * CreateT120ProtocolHandler();
00964
00977 virtual OpalT38Protocol * CreateT38ProtocolHandler();
00978
00980
00985 OpalEndPoint & GetEndPoint() const { return endpoint; }
00986
00989 OpalCall & GetCall() const { return ownerCall; }
00990
00993 const PString & GetToken() const { return callToken; }
00994
00997 BOOL IsOriginating() const { return originating; }
00998
01001 PTime GetSetupUpTime() const { return setupTime; }
01002
01005 PTime GetAlertingTime() const { return alertingTime; }
01006
01009 PTime GetConnectionStartTime() const { return connectedTime; }
01010
01013 PTime GetConnectionEndTime() const { return callEndTime; }
01014
01017 const PString & GetLocalPartyName() const { return localPartyName; }
01018
01021 virtual void SetLocalPartyName(const PString & name);
01022
01025 const PString & GetDisplayName() const { return displayName; }
01026
01029 void SetDisplayName(const PString & name) { displayName = name; }
01030
01033 const PString & GetRemotePartyName() const { return remotePartyName; }
01034
01037 const PString & GetRemoteApplication() const { return remoteApplication; }
01038
01043 const PString & GetRemotePartyNumber() const { return remotePartyNumber; }
01044
01047 const PString & GetRemotePartyAddress() const { return remotePartyAddress; }
01048
01053 virtual const PString GetRemotePartyCallbackURL() const { return remotePartyAddress; }
01054
01055
01059 virtual const PString & GetCalledDestinationNumber() const { return calledDestinationNumber; }
01060
01064 virtual const PString & GetCalledDestinationName() const { return calledDestinationName; }
01065
01069 unsigned GetMinAudioJitterDelay() const { return minAudioJitterDelay; }
01070
01074 unsigned GetMaxAudioJitterDelay() const { return maxAudioJitterDelay; }
01075
01078 void SetAudioJitterDelay(
01079 unsigned minDelay,
01080 unsigned maxDelay
01081 );
01082
01085 OpalSilenceDetector * GetSilenceDetector() const { return silenceDetector; }
01086
01089 OpalEchoCanceler * GetEchoCanceler() const { return echoCanceler; }
01090
01093 virtual const OpalGloballyUniqueID & GetIdentifier() const
01094 { return callIdentifier; }
01095
01096 virtual OpalTransport & GetTransport() const
01097 { return *(OpalTransport *)NULL; }
01098
01099 PDICTIONARY(MediaAddressesDict, POrdinalKey, OpalTransportAddress);
01100 MediaAddressesDict & GetMediaTransportAddresses()
01101 { return mediaTransportAddresses; }
01102
01104
01105 const RTP_DataFrame::PayloadMapType & GetRTPPayloadMap() const
01106 { return rtpPayloadMap; }
01107
01108 PMutex & GetMediaStreamMutex() { return mediaStreamMutex; }
01109
01110 protected:
01111 PDECLARE_NOTIFIER(OpalRFC2833Info, OpalConnection, OnUserInputInlineRFC2833);
01112 PDECLARE_NOTIFIER(RTP_DataFrame, OpalConnection, OnUserInputInBandDTMF);
01113 PDECLARE_NOTIFIER(PThread, OpalConnection, OnReleaseThreadMain);
01114
01115
01116 OpalCall & ownerCall;
01117 OpalEndPoint & endpoint;
01118
01119 Phases phase;
01120 PString callToken;
01121 OpalGloballyUniqueID callIdentifier;
01122 BOOL originating;
01123 PTime setupTime;
01124 PTime alertingTime;
01125 PTime connectedTime;
01126 PTime callEndTime;
01127 PString localPartyName;
01128 PString displayName;
01129 PString remotePartyName;
01130 PString remoteApplication;
01131 PString remotePartyNumber;
01132 PString remotePartyAddress;
01133 CallEndReason callEndReason;
01134 PString calledDestinationNumber;
01135 PString calledDestinationName;
01136
01137 PString userInputString;
01138 PMutex userInputMutex;
01139 PSyncPoint userInputAvailable;
01140 BOOL detectInBandDTMF;
01141 OpalSilenceDetector * silenceDetector;
01142 OpalEchoCanceler * echoCanceler;
01143 OpalRFC2833Proto * rfc2833Handler;
01144 OpalT120Protocol * t120handler;
01145 OpalT38Protocol * t38handler;
01146
01147
01148 MediaAddressesDict mediaTransportAddresses;
01149 PMutex mediaStreamMutex;
01150 OpalMediaStreamList mediaStreams;
01151 RTP_SessionManager rtpSessions;
01152 unsigned minAudioJitterDelay;
01153 unsigned maxAudioJitterDelay;
01154 unsigned bandwidthAvailable;
01155
01156 RTP_DataFrame::PayloadMapType rtpPayloadMap;
01157
01158
01159
01160 PDTMFDecoder dtmfDecoder;
01161
01165 void SetPhase(Phases phaseToSet);
01166
01167 #if PTRACING
01168 friend ostream & operator<<(ostream & o, Phases p);
01169 #endif
01170 };
01171
01172
01173 #endif // __OPAL_CONNECTION_H
01174
01175
01176