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 #ifndef __OPAL_CONNECTION_H
00215 #define __OPAL_CONNECTION_H
00216
00217 #ifdef P_USE_PRAGMA
00218 #pragma interface
00219 #endif
00220
00221 #include <opal/buildopts.h>
00222
00223 #include <opal/mediafmt.h>
00224 #include <opal/mediastrm.h>
00225 #include <opal/guid.h>
00226 #include <opal/transports.h>
00227 #include <ptclib/dtmf.h>
00228 #include <ptlib/safecoll.h>
00229 #include <rtp/rtp.h>
00230
00231 class OpalEndPoint;
00232 class OpalCall;
00233 class OpalSilenceDetector;
00234 class OpalEchoCanceler;
00235 class OpalRFC2833Proto;
00236 class OpalRFC2833Info;
00237 class OpalT120Protocol;
00238 class OpalT38Protocol;
00239
00240
00258 class OpalConnection : public PSafeObject
00259 {
00260 PCLASSINFO(OpalConnection, PSafeObject);
00261 public:
00266 enum CallEndReason {
00267 EndedByLocalUser,
00268 EndedByNoAccept,
00269 EndedByAnswerDenied,
00270 EndedByRemoteUser,
00271 EndedByRefusal,
00272 EndedByNoAnswer,
00273 EndedByCallerAbort,
00274 EndedByTransportFail,
00275 EndedByConnectFail,
00276 EndedByGatekeeper,
00277 EndedByNoUser,
00278 EndedByNoBandwidth,
00279 EndedByCapabilityExchange,
00280 EndedByCallForwarded,
00281 EndedBySecurityDenial,
00282 EndedByLocalBusy,
00283 EndedByLocalCongestion,
00284 EndedByRemoteBusy,
00285 EndedByRemoteCongestion,
00286 EndedByUnreachable,
00287 EndedByNoEndPoint,
00288 EndedByHostOffline,
00289 EndedByTemporaryFailure,
00290 EndedByQ931Cause,
00291 EndedByDurationLimit,
00292 EndedByInvalidConferenceID,
00293 NumCallEndReasons
00294 };
00295
00296 #if PTRACING
00297 friend ostream & operator<<(ostream & o, CallEndReason reason);
00298 #endif
00299
00300 enum AnswerCallResponse {
00301 AnswerCallNow,
00302 AnswerCallDenied,
00303 AnswerCallPending,
00304 AnswerCallDeferred,
00305 AnswerCallAlertWithMedia,
00306 AnswerCallDeferredWithMedia,
00307 NumAnswerCallResponses
00308 };
00309 #if PTRACING
00310 friend ostream & operator<<(ostream & o, AnswerCallResponse s);
00311 #endif
00312
00313
00318 OpalConnection(
00319 OpalCall & call,
00320 OpalEndPoint & endpoint,
00321 const PString & token
00322 );
00323
00326 ~OpalConnection();
00328
00335 void PrintOn(
00336 ostream & strm
00337 ) const;
00339
00342 enum Phases {
00343 UninitialisedPhase,
00344 SetUpPhase,
00345 AlertingPhase,
00346 ConnectedPhase,
00347 EstablishedPhase,
00348 ReleasingPhase,
00349 ReleasedPhase,
00350 NumPhases
00351 };
00352
00357 inline Phases GetPhase() const { return phase; }
00358
00367 CallEndReason GetCallEndReason() const { return callEndReason; }
00368
00373 virtual void SetCallEndReason(
00374 CallEndReason reason
00375 );
00376
00384 void ClearCall(
00385 CallEndReason reason = EndedByLocalUser
00386 );
00387
00390 virtual void ClearCallSynchronous(
00391 PSyncPoint * sync,
00392 CallEndReason reason = EndedByLocalUser
00393 );
00394
00398 virtual void TransferConnection(
00399 const PString & remoteParty,
00400 const PString & callIdentity = PString::Empty()
00402 );
00403
00406 virtual void HoldConnection();
00407
00411 virtual void RetrieveConnection();
00412
00415 virtual BOOL IsConnectionOnHold();
00417
00441 virtual BOOL OnIncomingConnection();
00442
00449 virtual BOOL SetUpConnection() = 0;
00450
00466 virtual void OnAlerting();
00467
00478 virtual BOOL SetAlerting(
00479 const PString & calleeName,
00480 BOOL withMedia
00481 ) = 0;
00482
00499 virtual AnswerCallResponse OnAnswerCall(
00500 const PString & callerName
00501 );
00502
00513 virtual void AnsweringCall(
00514 AnswerCallResponse response
00515 );
00516
00527 virtual void OnConnected();
00528
00533 virtual BOOL SetConnected() = 0;
00534
00545 virtual void OnEstablished();
00546
00555 virtual void Release(
00556 CallEndReason reason = EndedByLocalUser
00557 );
00558
00576 virtual void OnReleased();
00578
00588 virtual PString GetDestinationAddress();
00589
00599 virtual BOOL ForwardCall(
00600 const PString & forwardParty
00601 );
00603
00612 virtual OpalMediaFormatList GetMediaFormats() const = 0;
00613
00622 virtual void AdjustMediaFormats(
00623 OpalMediaFormatList & mediaFormats
00624 ) const;
00625
00628 virtual BOOL OpenSourceMediaStream(
00629 const OpalMediaFormatList & mediaFormats,
00630 unsigned sessionID
00631 );
00632
00635 virtual OpalMediaStream * OpenSinkMediaStream(
00636 OpalMediaStream & source
00637 );
00638
00641 virtual void StartMediaStreams();
00642
00645 virtual void CloseMediaStreams();
00646
00649 virtual void RemoveMediaStreams();
00650
00653 virtual void PauseMediaStreams(BOOL paused);
00654
00669 virtual OpalMediaStream * CreateMediaStream(
00670 const OpalMediaFormat & mediaFormat,
00671 unsigned sessionID,
00672 BOOL isSource
00673 );
00674
00686 virtual BOOL OnOpenMediaStream(
00687 OpalMediaStream & stream
00688 );
00689
00694 virtual void OnClosedMediaStream(
00695 const OpalMediaStream & stream
00696 );
00697
00702 virtual void OnPatchMediaStream(
00703 BOOL isSource,
00704 OpalMediaPatch & patch
00705 );
00706
00712 OpalMediaStream * GetMediaStream(
00713 unsigned sessionId,
00714 BOOL source
00715 ) const;
00716
00722 virtual BOOL IsMediaBypassPossible(
00723 unsigned sessionID
00724 ) const;
00725
00728 struct MediaInformation {
00729 MediaInformation() { rfc2833 = RTP_DataFrame::IllegalPayloadType; }
00730
00731 OpalTransportAddress data;
00732 OpalTransportAddress control;
00733 RTP_DataFrame::PayloadTypes rfc2833;
00734 };
00735
00744 virtual BOOL GetMediaInformation(
00745 unsigned sessionID,
00746 MediaInformation & info
00747 ) const;
00748
00753 virtual void AddVideoMediaFormats(
00754 OpalMediaFormatList & mediaFormats
00755 ) const;
00756
00759 virtual BOOL CreateVideoInputDevice(
00760 const OpalMediaFormat & mediaFormat,
00761 PVideoInputDevice * & device,
00762 BOOL & autoDelete
00763 );
00764
00768 virtual BOOL CreateVideoOutputDevice(
00769 const OpalMediaFormat & mediaFormat,
00770 BOOL preview,
00771 PVideoOutputDevice * & device,
00772 BOOL & autoDelete
00773 );
00775
00781 virtual RTP_Session * GetSession(
00782 unsigned sessionID
00783 ) const;
00784
00799 virtual RTP_Session * UseSession(
00800 const OpalTransport & transport,
00801 unsigned sessionID,
00802 RTP_QOS * rtpqos = NULL
00803 );
00804
00809 virtual void ReleaseSession(
00810 unsigned sessionID,
00811 BOOL clearAll = FALSE
00812 );
00813
00818 virtual RTP_Session * CreateSession(
00819 const OpalTransport & transport,
00820 unsigned sessionID,
00821 RTP_QOS * rtpqos
00822 );
00824
00829 unsigned GetBandwidthAvailable() const { return bandwidthAvailable; }
00830
00835 virtual BOOL SetBandwidthAvailable(
00836 unsigned newBandwidth,
00837 BOOL force = FALSE
00838 );
00839
00844 virtual unsigned GetBandwidthUsed() const;
00845
00854 virtual BOOL SetBandwidthUsed(
00855 unsigned releasedBandwidth,
00856 unsigned requiredBandwidth
00857 );
00859
00868 virtual BOOL SendUserInputString(
00869 const PString & value
00870 );
00871
00888 virtual BOOL SendUserInputTone(
00889 char tone,
00890 unsigned duration = 0
00891 );
00892
00899 virtual void OnUserInputString(
00900 const PString & value
00901 );
00902
00909 virtual void OnUserInputTone(
00910 char tone,
00911 unsigned duration
00912 );
00913
00917 void SendUserInputHookFlash(
00918 unsigned duration = 500
00919 ) { SendUserInputTone('!', duration); }
00920
00923 virtual PString GetUserInput(
00924 unsigned timeout = 30
00925 );
00926
00931 virtual void SetUserInput(
00932 const PString & input
00933 );
00934
00937 virtual PString ReadUserInput(
00938 const char * terminators = "#\r\n",
00939 unsigned lastDigitTimeout = 4,
00940 unsigned firstDigitTimeout = 30
00941 );
00942
00949 virtual BOOL PromptUserInput(
00950 BOOL play
00951 );
00953
00968 virtual OpalT120Protocol * CreateT120ProtocolHandler();
00969
00982 virtual OpalT38Protocol * CreateT38ProtocolHandler();
00983
00985
00990 OpalEndPoint & GetEndPoint() const { return endpoint; }
00991
00994 OpalCall & GetCall() const { return ownerCall; }
00995
00998 const PString & GetToken() const { return callToken; }
00999
01002 BOOL IsOriginating() const { return originating; }
01003
01006 PTime GetSetupUpTime() const { return setupTime; }
01007
01010 PTime GetAlertingTime() const { return alertingTime; }
01011
01014 PTime GetConnectionStartTime() const { return connectedTime; }
01015
01018 PTime GetConnectionEndTime() const { return callEndTime; }
01019
01022 const PString & GetLocalPartyName() const { return localPartyName; }
01023
01026 virtual void SetLocalPartyName(const PString & name);
01027
01030 const PString & GetDisplayName() const { return displayName; }
01031
01034 void SetDisplayName(const PString & name) { displayName = name; }
01035
01038 const PString & GetRemotePartyName() const { return remotePartyName; }
01039
01042 const PString & GetRemoteApplication() const { return remoteApplication; }
01043
01048 const PString & GetRemotePartyNumber() const { return remotePartyNumber; }
01049
01052 const PString & GetRemotePartyAddress() const { return remotePartyAddress; }
01053
01058 virtual const PString GetRemotePartyCallbackURL() const { return remotePartyAddress; }
01059
01060
01064 virtual const PString & GetCalledDestinationNumber() const { return calledDestinationNumber; }
01065
01069 virtual const PString & GetCalledDestinationName() const { return calledDestinationName; }
01070
01074 unsigned GetMinAudioJitterDelay() const { return minAudioJitterDelay; }
01075
01079 unsigned GetMaxAudioJitterDelay() const { return maxAudioJitterDelay; }
01080
01083 void SetAudioJitterDelay(
01084 unsigned minDelay,
01085 unsigned maxDelay
01086 );
01087
01090 OpalSilenceDetector * GetSilenceDetector() const { return silenceDetector; }
01091
01094 OpalEchoCanceler * GetEchoCanceler() const { return echoCanceler; }
01095
01098 virtual const OpalGloballyUniqueID & GetIdentifier() const
01099 { return callIdentifier; }
01100
01101 virtual OpalTransport & GetTransport() const
01102 { return *(OpalTransport *)NULL; }
01103
01104 PDICTIONARY(MediaAddressesDict, POrdinalKey, OpalTransportAddress);
01105 MediaAddressesDict & GetMediaTransportAddresses()
01106 { return mediaTransportAddresses; }
01107
01109
01110 const RTP_DataFrame::PayloadMapType & GetRTPPayloadMap() const
01111 { return rtpPayloadMap; }
01112
01113 PMutex & GetMediaStreamMutex() { return mediaStreamMutex; }
01114
01115 protected:
01116 PDECLARE_NOTIFIER(OpalRFC2833Info, OpalConnection, OnUserInputInlineRFC2833);
01117 PDECLARE_NOTIFIER(RTP_DataFrame, OpalConnection, OnUserInputInBandDTMF);
01118 PDECLARE_NOTIFIER(PThread, OpalConnection, OnReleaseThreadMain);
01119
01120
01121 OpalCall & ownerCall;
01122 OpalEndPoint & endpoint;
01123
01124 Phases phase;
01125 PString callToken;
01126 OpalGloballyUniqueID callIdentifier;
01127 BOOL originating;
01128 PTime setupTime;
01129 PTime alertingTime;
01130 PTime connectedTime;
01131 PTime callEndTime;
01132 PString localPartyName;
01133 PString displayName;
01134 PString remotePartyName;
01135 PString remoteApplication;
01136 PString remotePartyNumber;
01137 PString remotePartyAddress;
01138 CallEndReason callEndReason;
01139 PString calledDestinationNumber;
01140 PString calledDestinationName;
01141
01142 PString userInputString;
01143 PMutex userInputMutex;
01144 PSyncPoint userInputAvailable;
01145 BOOL detectInBandDTMF;
01146 OpalSilenceDetector * silenceDetector;
01147 OpalEchoCanceler * echoCanceler;
01148 OpalRFC2833Proto * rfc2833Handler;
01149 OpalT120Protocol * t120handler;
01150 OpalT38Protocol * t38handler;
01151
01152
01153 MediaAddressesDict mediaTransportAddresses;
01154 PMutex mediaStreamMutex;
01155 OpalMediaStreamList mediaStreams;
01156 RTP_SessionManager rtpSessions;
01157 unsigned minAudioJitterDelay;
01158 unsigned maxAudioJitterDelay;
01159 unsigned bandwidthAvailable;
01160
01161 RTP_DataFrame::PayloadMapType rtpPayloadMap;
01162
01163
01164
01165 PDTMFDecoder dtmfDecoder;
01166
01170 void SetPhase(Phases phaseToSet);
01171
01172 #if PTRACING
01173 friend ostream & operator<<(ostream & o, Phases p);
01174 #endif
01175 };
01176
01177
01178 #endif // __OPAL_CONNECTION_H
01179
01180
01181