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 #ifndef __OPAL_SIPCON_H
00189 #define __OPAL_SIPCON_H
00190
00191 #ifdef P_USE_PRAGMA
00192 #pragma interface
00193 #endif
00194
00195
00196 #include <opal/connection.h>
00197 #include <sip/sippdu.h>
00198
00199
00200 class OpalCall;
00201 class SIPEndPoint;
00202
00203
00205
00208 class SIPConnection : public OpalConnection
00209 {
00210 PCLASSINFO(SIPConnection, OpalConnection);
00211 public:
00212
00217 SIPConnection(
00218 OpalCall & call,
00219 SIPEndPoint & endpoint,
00220 const PString & token,
00221 const SIPURL & address,
00222 OpalTransport * transport
00223 );
00224
00227 ~SIPConnection();
00229
00238 virtual BOOL SetUpConnection();
00239
00243 virtual void TransferConnection(
00244 const PString & remoteParty,
00245 const PString & callIdentity = PString::Empty()
00247 );
00248
00251 virtual void HoldConnection();
00252
00256 virtual void RetrieveConnection();
00257
00260 virtual BOOL IsConnectionOnHold();
00261
00272 virtual BOOL SetAlerting(
00273 const PString & calleeName,
00274 BOOL withMedia
00275 );
00276
00281 virtual BOOL SetConnected();
00282
00285 virtual OpalMediaFormatList GetMediaFormats() const;
00286
00289 virtual BOOL OpenSourceMediaStream(
00290 const OpalMediaFormatList & mediaFormats,
00291 unsigned sessionID
00292 );
00293
00296 virtual OpalMediaStream * OpenSinkMediaStream(
00297 OpalMediaStream & source
00298 );
00299
00314 virtual OpalMediaStream * CreateMediaStream(
00315 const OpalMediaFormat & mediaFormat,
00316 unsigned sessionID,
00317 BOOL isSource
00318 );
00319
00320
00336 virtual OpalConnection::AnswerCallResponse OnAnswerCall(
00337 const PString & callerName
00338 );
00339
00350 void AnsweringCall(
00351 AnswerCallResponse response
00352 );
00353
00354
00366 virtual void OnConnected();
00367
00373 virtual BOOL IsMediaBypassPossible(
00374 unsigned sessionID
00375 ) const;
00376
00394 virtual void OnReleased();
00396
00401 virtual void OnTransactionFailed(
00402 SIPTransaction & transaction
00403 );
00404
00407 virtual void OnReceivedPDU(SIP_PDU & pdu);
00408
00411 virtual void OnReceivedINVITE(SIP_PDU & pdu);
00412
00415 virtual void OnReceivedACK(SIP_PDU & pdu);
00416
00419 virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
00420
00423 virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
00424
00427 virtual void OnReceivedREFER(SIP_PDU & pdu);
00428
00431 virtual void OnReceivedBYE(SIP_PDU & pdu);
00432
00435 virtual void OnReceivedCANCEL(SIP_PDU & pdu);
00436
00439 virtual void OnReceivedResponse(
00440 SIPTransaction & transaction,
00441 SIP_PDU & response
00442 );
00443
00446 virtual void OnReceivedTrying(SIP_PDU & pdu);
00447
00450 virtual void OnReceivedRinging(SIP_PDU & pdu);
00451
00454 virtual void OnReceivedSessionProgress(SIP_PDU & pdu);
00455
00458 virtual void OnReceivedAuthenticationRequired(
00459 SIPTransaction & transaction,
00460 SIP_PDU & response
00461 );
00462
00465 virtual void OnReceivedRedirection(SIP_PDU & pdu);
00466
00470 virtual void OnReceivedOK(
00471 SIPTransaction & transaction,
00472 SIP_PDU & response
00473 );
00474
00482 void QueuePDU(
00483 SIP_PDU * pdu
00484 );
00485
00493 virtual void OnRTPStatistics(
00494 const RTP_Session & session
00495 ) const;
00497
00498
00508 virtual BOOL ForwardCall(
00509 const PString & forwardParty
00510 );
00511
00512 virtual BOOL SendACK(SIPTransaction & invite, SIP_PDU & response);
00513
00517 BOOL SendPDU(SIP_PDU &, const OpalTransportAddress &);
00518
00519 unsigned GetNextCSeq() { PWaitAndSignal m(transactionsMutex); return ++lastSentCSeq; }
00520
00521 BOOL BuildSDP(
00522 SDPSessionDescription * &,
00523 RTP_SessionManager & rtpSessions,
00524 unsigned rtpSessionId
00525 );
00526
00527 SIPTransaction * GetTransaction (const PString & transactionID) { PWaitAndSignal m(transactionsMutex); return transactions.GetAt(transactionID); }
00528
00529 void AddTransaction(
00530 SIPTransaction * transaction
00531 ) { PWaitAndSignal m(transactionsMutex); transactions.SetAt(transaction->GetTransactionID(), transaction); }
00532
00533 void RemoveTransaction(
00534 SIPTransaction * transaction
00535 ) { PWaitAndSignal m(transactionsMutex); transactions.SetAt(transaction->GetTransactionID(), NULL); }
00536
00537
00538 OpalTransportAddress GetLocalAddress(WORD port = 0) const;
00539
00540 OpalTransport & GetTransport() const { return *transport; }
00541
00542 PString GetLocalPartyAddress() const { return localPartyAddress; }
00543
00546 void SetLocalPartyAddress();
00547 void SetLocalPartyAddress(
00548 const PString & addr
00549 ) { localPartyAddress = addr; }
00550
00555 const PString GetRemotePartyCallbackURL() const;
00556
00557 PString GetTag() const { return GetIdentifier().AsString(); }
00558 SIPEndPoint & GetEndPoint() const { return endpoint; }
00559 const SIPURL & GetTargetAddress() const { return targetAddress; }
00560 const PStringList & GetRouteSet() const { return routeSet; }
00561 const SIPAuthentication & GetAuthenticator() const { return authentication; }
00562
00563 protected:
00564 PDECLARE_NOTIFIER(PThread, SIPConnection, HandlePDUsThreadMain);
00565 PDECLARE_NOTIFIER(PThread, SIPConnection, OnAckTimeout);
00566
00567 virtual RTP_UDP *OnUseRTPSession(
00568 const unsigned rtpSessionId,
00569 const OpalTransportAddress & mediaAddress,
00570 OpalTransportAddress & localAddress
00571 );
00572 virtual void OnReceivedSDP(SIP_PDU & pdu);
00573 virtual BOOL OnReceivedSDPMediaDescription(
00574 SDPSessionDescription & sdp,
00575 SDPMediaDescription::MediaType mediaType,
00576 unsigned sessionId
00577 );
00578 virtual BOOL OnSendSDPMediaDescription(
00579 const SDPSessionDescription & sdpIn,
00580 SDPMediaDescription::MediaType mediaType,
00581 unsigned sessionId,
00582 SDPSessionDescription & sdpOut
00583 );
00584 virtual BOOL OnOpenSourceMediaStreams(
00585 const OpalMediaFormatList & remoteFormatList,
00586 unsigned sessionId,
00587 SDPMediaDescription *localMedia
00588 );
00589 SDPMediaDescription::Direction GetDirection(unsigned sessionId);
00590 static BOOL WriteINVITE(OpalTransport & transport, void * param);
00591
00592 void InitRFC2833Handler();
00593
00594 SIPEndPoint & endpoint;
00595 OpalTransport * transport;
00596 OpalTransportAddress lastTransportAddress;
00597
00598 PMutex transportMutex;
00599 PMutex streamsMutex;
00600 BOOL local_hold;
00601 BOOL remote_hold;
00602 PString localPartyAddress;
00603 PString forwardParty;
00604 SIP_PDU * originalInvite;
00605 SDPSessionDescription remoteSDP;
00606 PStringList routeSet;
00607 SIPURL targetAddress;
00608 SIPAuthentication authentication;
00609
00610 SIP_PDU_Queue pduQueue;
00611 PSemaphore pduSemaphore;
00612 PThread * pduHandler;
00613
00614 PTimer ackTimer;
00615 PMutex transactionsMutex;
00616 SIPTransaction * referTransaction;
00617 PMutex invitationsMutex;
00618 SIPTransactionList invitations;
00619 SIPTransactionDict transactions;
00620 unsigned lastSentCSeq;
00621
00622 enum {
00623 ReleaseWithBYE,
00624 ReleaseWithCANCEL,
00625 ReleaseWithResponse,
00626 ReleaseWithNothing,
00627 } releaseMethod;
00628
00629 OpalMediaFormatList remoteFormatList;
00630 };
00631
00632
00635 class SIP_RTP_Session : public RTP_UserData
00636 {
00637 PCLASSINFO(SIP_RTP_Session, RTP_UserData);
00638
00643 SIP_RTP_Session(
00644 const SIPConnection & connection
00645 );
00647
00656 virtual void OnTxStatistics(
00657 const RTP_Session & session
00658 ) const;
00659
00666 virtual void OnRxStatistics(
00667 const RTP_Session & session
00668 ) const;
00670
00671
00672 protected:
00673 const SIPConnection & connection;
00674 };
00675
00676
00677 #endif // __OPAL_SIPCON_H
00678
00679
00680