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 #ifndef __OPAL_SIPCON_H
00181 #define __OPAL_SIPCON_H
00182
00183 #ifdef P_USE_PRAGMA
00184 #pragma interface
00185 #endif
00186
00187
00188 #include <opal/connection.h>
00189 #include <sip/sippdu.h>
00190
00191
00192 class OpalCall;
00193 class SIPEndPoint;
00194
00195
00197
00200 class SIPConnection : public OpalConnection
00201 {
00202 PCLASSINFO(SIPConnection, OpalConnection);
00203 public:
00204
00209 SIPConnection(
00210 OpalCall & call,
00211 SIPEndPoint & endpoint,
00212 const PString & token,
00213 const SIPURL & address,
00214 OpalTransport * transport
00215 );
00216
00219 ~SIPConnection();
00221
00230 virtual BOOL SetUpConnection();
00231
00235 virtual void TransferConnection(
00236 const PString & remoteParty,
00237 const PString & callIdentity = PString::Empty()
00239 );
00240
00243 virtual void HoldConnection();
00244
00248 virtual void RetrieveConnection();
00249
00252 virtual BOOL IsConnectionOnHold();
00253
00264 virtual BOOL SetAlerting(
00265 const PString & calleeName,
00266 BOOL withMedia
00267 );
00268
00273 virtual BOOL SetConnected();
00274
00277 virtual OpalMediaFormatList GetMediaFormats() const;
00278
00281 virtual BOOL OpenSourceMediaStream(
00282 const OpalMediaFormatList & mediaFormats,
00283 unsigned sessionID
00284 );
00285
00288 virtual OpalMediaStream * OpenSinkMediaStream(
00289 OpalMediaStream & source
00290 );
00291
00306 virtual OpalMediaStream * CreateMediaStream(
00307 const OpalMediaFormat & mediaFormat,
00308 unsigned sessionID,
00309 BOOL isSource
00310 );
00311
00312
00328 virtual OpalConnection::AnswerCallResponse OnAnswerCall(
00329 const PString & callerName
00330 );
00331
00342 void AnsweringCall(
00343 AnswerCallResponse response
00344 );
00345
00346
00358 virtual void OnConnected();
00359
00365 virtual BOOL IsMediaBypassPossible(
00366 unsigned sessionID
00367 ) const;
00368
00386 virtual void OnReleased();
00388
00393 virtual void OnTransactionFailed(
00394 SIPTransaction & transaction
00395 );
00396
00399 virtual void OnReceivedPDU(SIP_PDU & pdu);
00400
00403 virtual void OnReceivedINVITE(SIP_PDU & pdu);
00404
00407 virtual void OnReceivedACK(SIP_PDU & pdu);
00408
00411 virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
00412
00415 virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
00416
00419 virtual void OnReceivedREFER(SIP_PDU & pdu);
00420
00423 virtual void OnReceivedBYE(SIP_PDU & pdu);
00424
00427 virtual void OnReceivedCANCEL(SIP_PDU & pdu);
00428
00431 virtual void OnReceivedResponse(
00432 SIPTransaction & transaction,
00433 SIP_PDU & response
00434 );
00435
00438 virtual void OnReceivedTrying(SIP_PDU & pdu);
00439
00442 virtual void OnReceivedRinging(SIP_PDU & pdu);
00443
00446 virtual void OnReceivedSessionProgress(SIP_PDU & pdu);
00447
00450 virtual void OnReceivedAuthenticationRequired(
00451 SIPTransaction & transaction,
00452 SIP_PDU & response
00453 );
00454
00457 virtual void OnReceivedRedirection(SIP_PDU & pdu);
00458
00462 virtual void OnReceivedOK(
00463 SIPTransaction & transaction,
00464 SIP_PDU & response
00465 );
00466
00474 void QueuePDU(
00475 SIP_PDU * pdu
00476 );
00477
00485 virtual void OnRTPStatistics(
00486 const RTP_Session & session
00487 ) const;
00489
00490
00500 virtual BOOL ForwardCall(
00501 const PString & forwardParty
00502 );
00503
00507 BOOL SendPDU(SIP_PDU &, const OpalTransportAddress &);
00508
00509 unsigned GetNextCSeq() { return ++lastSentCSeq; }
00510
00511 BOOL BuildSDP(
00512 SDPSessionDescription * &,
00513 RTP_SessionManager & rtpSessions,
00514 unsigned rtpSessionId
00515 );
00516
00517 SIPTransaction * GetTransaction (PString transactionID) { return transactions.GetAt(transactionID); }
00518
00519 void AddTransaction(
00520 SIPTransaction * transaction
00521 ) { transactions.SetAt(transaction->GetTransactionID(), transaction); }
00522
00523 void RemoveTransaction(
00524 SIPTransaction * transaction
00525 ) { transactions.SetAt(transaction->GetTransactionID(), NULL); }
00526
00527
00528 OpalTransportAddress GetLocalAddress(WORD port = 0) const;
00529
00530 OpalTransport & GetTransport() const { return *transport; }
00531
00532 PString GetLocalPartyAddress() const { return localPartyAddress; }
00533
00536 void SetLocalPartyAddress();
00537 void SetLocalPartyAddress(
00538 const PString & addr
00539 ) { localPartyAddress = addr; }
00540
00545 const PString GetRemotePartyCallbackURL() const;
00546
00547 PString GetTag() const { return GetIdentifier().AsString(); }
00548 SIPEndPoint & GetEndPoint() const { return endpoint; }
00549 const SIPURL & GetTargetAddress() const { return targetAddress; }
00550 const PStringList & GetRouteSet() const { return routeSet; }
00551 const SIPAuthentication & GetAuthenticator() const { return authentication; }
00552
00553 protected:
00554 PDECLARE_NOTIFIER(PThread, SIPConnection, HandlePDUsThreadMain);
00555 virtual RTP_UDP *OnUseRTPSession(
00556 const unsigned rtpSessionId,
00557 const OpalTransportAddress & mediaAddress,
00558 OpalTransportAddress & localAddress
00559 );
00560 virtual void OnReceivedSDP(SIP_PDU & pdu);
00561 virtual BOOL OnReceivedSDPMediaDescription(
00562 SDPSessionDescription & sdp,
00563 SDPMediaDescription::MediaType mediaType,
00564 unsigned sessionId
00565 );
00566 virtual BOOL OnSendSDPMediaDescription(
00567 const SDPSessionDescription & sdpIn,
00568 SDPMediaDescription::MediaType mediaType,
00569 unsigned sessionId,
00570 SDPSessionDescription & sdpOut
00571 );
00572 virtual BOOL OnOpenSourceMediaStreams(
00573 const OpalMediaFormatList & remoteFormatList,
00574 unsigned sessionId,
00575 SDPMediaDescription *localMedia
00576 );
00577 SDPMediaDescription::Direction GetDirection(unsigned sessionId);
00578 static BOOL WriteINVITE(OpalTransport & transport, void * param);
00579
00580 void InitRFC2833Handler();
00581
00582 SIPEndPoint & endpoint;
00583 OpalTransport * transport;
00584 OpalTransportAddress lastTransportAddress;
00585
00586 PMutex transportMutex;
00587 PMutex streamsMutex;
00588 BOOL local_hold;
00589 BOOL remote_hold;
00590 PString localPartyAddress;
00591 PString forwardParty;
00592 SIP_PDU * originalInvite;
00593 SDPSessionDescription remoteSDP;
00594 PStringList routeSet;
00595 SIPURL targetAddress;
00596 SIPAuthentication authentication;
00597
00598 SIP_PDU_Queue pduQueue;
00599 PSemaphore pduSemaphore;
00600 PThread * pduHandler;
00601
00602 SIPTransaction * referTransaction;
00603 SIPTransactionList invitations;
00604 SIPTransactionDict transactions;
00605 unsigned lastSentCSeq;
00606
00607 enum {
00608 ReleaseWithBYE,
00609 ReleaseWithCANCEL,
00610 ReleaseWithResponse,
00611 ReleaseWithNothing,
00612 } releaseMethod;
00613
00614 OpalMediaFormatList remoteFormatList;
00615 };
00616
00617
00620 class SIP_RTP_Session : public RTP_UserData
00621 {
00622 PCLASSINFO(SIP_RTP_Session, RTP_UserData);
00623
00628 SIP_RTP_Session(
00629 const SIPConnection & connection
00630 );
00632
00641 virtual void OnTxStatistics(
00642 const RTP_Session & session
00643 ) const;
00644
00651 virtual void OnRxStatistics(
00652 const RTP_Session & session
00653 ) const;
00655
00656
00657 protected:
00658 const SIPConnection & connection;
00659 };
00660
00661
00662 #endif // __OPAL_SIPCON_H
00663
00664
00665