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 #ifndef __OPAL_CONNECTION_H
00205 #define __OPAL_CONNECTION_H
00206
00207 #ifdef P_USE_PRAGMA
00208 #pragma interface
00209 #endif
00210
00211 #include <opal/buildopts.h>
00212
00213 #include <opal/mediafmt.h>
00214 #include <opal/mediastrm.h>
00215 #include <opal/guid.h>
00216 #include <opal/transports.h>
00217 #include <ptclib/dtmf.h>
00218 #include <ptlib/safecoll.h>
00219 #include <rtp/rtp.h>
00220
00221 class OpalEndPoint;
00222 class OpalCall;
00223 class OpalSilenceDetector;
00224 class OpalEchoCanceler;
00225 class OpalRFC2833Proto;
00226 class OpalRFC2833Info;
00227 class OpalT120Protocol;
00228 class OpalT38Protocol;
00229
00230
00248 class OpalConnection : public PSafeObject
00249 {
00250 PCLASSINFO(OpalConnection, PSafeObject);
00251 public:
00256 enum CallEndReason {
00257 EndedByLocalUser,
00258 EndedByNoAccept,
00259 EndedByAnswerDenied,
00260 EndedByRemoteUser,
00261 EndedByRefusal,
00262 EndedByNoAnswer,
00263 EndedByCallerAbort,
00264 EndedByTransportFail,
00265 EndedByConnectFail,
00266 EndedByGatekeeper,
00267 EndedByNoUser,
00268 EndedByNoBandwidth,
00269 EndedByCapabilityExchange,
00270 EndedByCallForwarded,
00271 EndedBySecurityDenial,
00272 EndedByLocalBusy,
00273 EndedByLocalCongestion,
00274 EndedByRemoteBusy,
00275 EndedByRemoteCongestion,
00276 EndedByUnreachable,
00277 EndedByNoEndPoint,
00278 EndedByHostOffline,
00279 EndedByTemporaryFailure,
00280 EndedByQ931Cause,
00281 EndedByDurationLimit,
00282 EndedByInvalidConferenceID,
00283 NumCallEndReasons
00284 };
00285
00286 #if PTRACING
00287 friend ostream & operator<<(ostream & o, CallEndReason reason);
00288 #endif
00289
00290 enum AnswerCallResponse {
00291 AnswerCallNow,
00292 AnswerCallDenied,
00293 AnswerCallPending,
00294 AnswerCallDeferred,
00295 AnswerCallAlertWithMedia,
00296 AnswerCallDeferredWithMedia,
00297 NumAnswerCallResponses
00298 };
00299 #if PTRACING
00300 friend ostream & operator<<(ostream & o, AnswerCallResponse s);
00301 #endif
00302
00303
00308 OpalConnection(
00309 OpalCall & call,
00310 OpalEndPoint & endpoint,
00311 const PString & token
00312 );
00313
00316 ~OpalConnection();
00318
00325 void PrintOn(
00326 ostream & strm
00327 ) const;
00329
00332 enum Phases {
00333 UninitialisedPhase,
00334 SetUpPhase,
00335 AlertingPhase,
00336 ConnectedPhase,
00337 EstablishedPhase,
00338 ReleasingPhase,
00339 ReleasedPhase,
00340 NumPhases
00341 };
00342
00347 inline Phases GetPhase() const { return phase; }
00348
00357 CallEndReason GetCallEndReason() const { return callEndReason; }
00358
00363 virtual void SetCallEndReason(
00364 CallEndReason reason
00365 );
00366
00374 void ClearCall(
00375 CallEndReason reason = EndedByLocalUser
00376 );
00377
00380 virtual void ClearCallSynchronous(
00381 PSyncPoint * sync,
00382 CallEndReason reason = EndedByLocalUser
00383 );
00384
00388 virtual void TransferConnection(
00389 const PString & remoteParty,
00390 const PString & callIdentity = PString::Empty()
00392 );
00393
00396 virtual void HoldConnection();
00397
00401 virtual void RetrieveConnection();
00402
00405 virtual BOOL IsConnectionOnHold();
00407
00431 virtual BOOL OnIncomingConnection();
00432
00439 virtual BOOL SetUpConnection() = 0;
00440
00456 virtual void OnAlerting();
00457
00468 virtual BOOL SetAlerting(
00469 const PString & calleeName,
00470 BOOL withMedia
00471 ) = 0;
00472
00489 virtual AnswerCallResponse OnAnswerCall(
00490 const PString & callerName
00491 );
00492
00503 virtual void AnsweringCall(
00504 AnswerCallResponse response
00505 );
00506
00517 virtual void OnConnected();
00518
00523 virtual BOOL SetConnected() = 0;
00524
00535 virtual void OnEstablished();
00536
00545 virtual void Release(
00546 CallEndReason reason = EndedByLocalUser
00547 );
00548
00566 virtual void OnReleased();
00568
00578 virtual PString GetDestinationAddress();
00579
00589 virtual BOOL ForwardCall(
00590 const PString & forwardParty
00591 );
00593
00602 virtual OpalMediaFormatList GetMediaFormats() const = 0;
00603
00612 virtual void AdjustMediaFormats(
00613 OpalMediaFormatList & mediaFormats
00614 ) const;
00615
00618 virtual BOOL OpenSourceMediaStream(
00619 const OpalMediaFormatList & mediaFormats,
00620 unsigned sessionID
00621 );
00622
00625 virtual OpalMediaStream * OpenSinkMediaStream(
00626 OpalMediaStream & source
00627 );
00628
00631 virtual void StartMediaStreams();
00632
00635 virtual void CloseMediaStreams();
00636
00639 virtual void RemoveMediaStreams();
00640
00643 virtual void PauseMediaStreams(BOOL paused);
00644
00659 virtual OpalMediaStream * CreateMediaStream(
00660 const OpalMediaFormat & mediaFormat,
00661 unsigned sessionID,
00662 BOOL isSource
00663 );
00664
00676 virtual BOOL OnOpenMediaStream(
00677 OpalMediaStream & stream
00678 );
00679
00684 virtual void OnClosedMediaStream(
00685 const OpalMediaStream & stream
00686 );
00687
00692 virtual void OnPatchMediaStream(
00693 BOOL isSource,
00694 OpalMediaPatch & patch
00695 );
00696
00702 OpalMediaStream * GetMediaStream(
00703 unsigned sessionId,
00704 BOOL source
00705 ) const;
00706
00712 virtual BOOL IsMediaBypassPossible(
00713 unsigned sessionID
00714 ) const;
00715
00718 struct MediaInformation {
00719 MediaInformation() { rfc2833 = RTP_DataFrame::IllegalPayloadType; }
00720
00721 OpalTransportAddress data;
00722 OpalTransportAddress control;
00723 RTP_DataFrame::PayloadTypes rfc2833;
00724 };
00725
00734 virtual BOOL GetMediaInformation(
00735 unsigned sessionID,
00736 MediaInformation & info
00737 ) const;
00738
00743 virtual void AddVideoMediaFormats(
00744 OpalMediaFormatList & mediaFormats
00745 ) const;
00746
00749 virtual BOOL CreateVideoInputDevice(
00750 const OpalMediaFormat & mediaFormat,
00751 PVideoInputDevice * & device,
00752 BOOL & autoDelete
00753 );
00754
00758 virtual BOOL CreateVideoOutputDevice(
00759 const OpalMediaFormat & mediaFormat,
00760 BOOL preview,
00761 PVideoOutputDevice * & device,
00762 BOOL & autoDelete
00763 );
00765
00771 virtual RTP_Session * GetSession(
00772 unsigned sessionID
00773 ) const;
00774
00789 virtual RTP_Session * UseSession(
00790 const OpalTransport & transport,
00791 unsigned sessionID,
00792 RTP_QOS * rtpqos = NULL
00793 );
00794
00799 virtual void ReleaseSession(
00800 unsigned sessionID
00801 );
00802
00807 virtual RTP_Session * CreateSession(
00808 const OpalTransport & transport,
00809 unsigned sessionID,
00810 RTP_QOS * rtpqos
00811 );
00813
00818 unsigned GetBandwidthAvailable() const { return bandwidthAvailable; }
00819
00824 virtual BOOL SetBandwidthAvailable(
00825 unsigned newBandwidth,
00826 BOOL force = FALSE
00827 );
00828
00833 virtual unsigned GetBandwidthUsed() const;
00834
00843 virtual BOOL SetBandwidthUsed(
00844 unsigned releasedBandwidth,
00845 unsigned requiredBandwidth
00846 );
00848
00857 virtual BOOL SendUserInputString(
00858 const PString & value
00859 );
00860
00877 virtual BOOL SendUserInputTone(
00878 char tone,
00879 unsigned duration = 0
00880 );
00881
00888 virtual void OnUserInputString(
00889 const PString & value
00890 );
00891
00898 virtual void OnUserInputTone(
00899 char tone,
00900 unsigned duration
00901 );
00902
00906 void SendUserInputHookFlash(
00907 unsigned duration = 500
00908 ) { SendUserInputTone('!', duration); }
00909
00912 virtual PString GetUserInput(
00913 unsigned timeout = 30
00914 );
00915
00920 virtual void SetUserInput(
00921 const PString & input
00922 );
00923
00926 virtual PString ReadUserInput(
00927 const char * terminators = "#\r\n",
00928 unsigned lastDigitTimeout = 4,
00929 unsigned firstDigitTimeout = 30
00930 );
00931
00938 virtual BOOL PromptUserInput(
00939 BOOL play
00940 );
00942
00957 virtual OpalT120Protocol * CreateT120ProtocolHandler();
00958
00971 virtual OpalT38Protocol * CreateT38ProtocolHandler();
00972
00974
00979 OpalEndPoint & GetEndPoint() const { return endpoint; }
00980
00983 OpalCall & GetCall() const { return ownerCall; }
00984
00987 const PString & GetToken() const { return callToken; }
00988
00991 BOOL IsOriginating() const { return originating; }
00992
00995 PTime GetSetupUpTime() const { return setupTime; }
00996
00999 PTime GetAlertingTime() const { return alertingTime; }
01000
01003 PTime GetConnectionStartTime() const { return connectedTime; }
01004
01007 PTime GetConnectionEndTime() const { return callEndTime; }
01008
01011 const PString & GetLocalPartyName() const { return localPartyName; }
01012
01015 virtual void SetLocalPartyName(const PString & name);
01016
01019 const PString & GetDisplayName() const { return displayName; }
01020
01023 void SetDisplayName(const PString & name) { displayName = name; }
01024
01027 const PString & GetRemotePartyName() const { return remotePartyName; }
01028
01031 const PString & GetRemoteApplication() const { return remoteApplication; }
01032
01037 const PString & GetRemotePartyNumber() const { return remotePartyNumber; }
01038
01041 const PString & GetRemotePartyAddress() const { return remotePartyAddress; }
01042
01047 virtual const PString GetRemotePartyCallbackURL() const { return remotePartyAddress; }
01048
01049
01053 virtual const PString & GetCalledDestinationNumber() const { return calledDestinationNumber; }
01054
01058 virtual const PString & GetCalledDestinationName() const { return calledDestinationName; }
01059
01063 unsigned GetMinAudioJitterDelay() const { return minAudioJitterDelay; }
01064
01068 unsigned GetMaxAudioJitterDelay() const { return maxAudioJitterDelay; }
01069
01072 void SetAudioJitterDelay(
01073 unsigned minDelay,
01074 unsigned maxDelay
01075 );
01076
01079 OpalSilenceDetector * GetSilenceDetector() const { return silenceDetector; }
01080
01083 OpalEchoCanceler * GetEchoCanceler() const { return echoCanceler; }
01084
01087 virtual const OpalGloballyUniqueID & GetIdentifier() const
01088 { return callIdentifier; }
01089
01090 virtual OpalTransport & GetTransport() const
01091 { return *(OpalTransport *)NULL; }
01092
01093 PDICTIONARY(MediaAddressesDict, POrdinalKey, OpalTransportAddress);
01094 MediaAddressesDict & GetMediaTransportAddresses()
01095 { return mediaTransportAddresses; }
01096
01098
01099 const RTP_DataFrame::PayloadMapType & GetRTPPayloadMap() const
01100 { return rtpPayloadMap; }
01101
01102 protected:
01103 PDECLARE_NOTIFIER(OpalRFC2833Info, OpalConnection, OnUserInputInlineRFC2833);
01104 PDECLARE_NOTIFIER(RTP_DataFrame, OpalConnection, OnUserInputInBandDTMF);
01105 PDECLARE_NOTIFIER(PThread, OpalConnection, OnReleaseThreadMain);
01106
01107
01108 OpalCall & ownerCall;
01109 OpalEndPoint & endpoint;
01110
01111 Phases phase;
01112 PString callToken;
01113 OpalGloballyUniqueID callIdentifier;
01114 BOOL originating;
01115 PTime setupTime;
01116 PTime alertingTime;
01117 PTime connectedTime;
01118 PTime callEndTime;
01119 PString localPartyName;
01120 PString displayName;
01121 PString remotePartyName;
01122 PString remoteApplication;
01123 PString remotePartyNumber;
01124 PString remotePartyAddress;
01125 CallEndReason callEndReason;
01126 PString calledDestinationNumber;
01127 PString calledDestinationName;
01128
01129 PString userInputString;
01130 PMutex userInputMutex;
01131 PSyncPoint userInputAvailable;
01132 BOOL detectInBandDTMF;
01133 OpalSilenceDetector * silenceDetector;
01134 OpalEchoCanceler * echoCanceler;
01135 OpalRFC2833Proto * rfc2833Handler;
01136 OpalT120Protocol * t120handler;
01137 OpalT38Protocol * t38handler;
01138
01139
01140 MediaAddressesDict mediaTransportAddresses;
01141 OpalMediaStreamList mediaStreams;
01142 RTP_SessionManager rtpSessions;
01143 unsigned minAudioJitterDelay;
01144 unsigned maxAudioJitterDelay;
01145 unsigned bandwidthAvailable;
01146
01147 RTP_DataFrame::PayloadMapType rtpPayloadMap;
01148
01149
01150
01151 PDTMFDecoder dtmfDecoder;
01152
01156 void SetPhase(Phases phaseToSet);
01157
01158 #if PTRACING
01159 friend ostream & operator<<(ostream & o, Phases p);
01160 #endif
01161 };
01162
01163
01164 #endif // __OPAL_CONNECTION_H
01165
01166
01167