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 #ifndef __OPAL_SIPCON_H
00033 #define __OPAL_SIPCON_H
00034
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038
00039 #include <opal/buildopts.h>
00040
00041 #include <opal/buildopts.h>
00042 #include <opal/rtpconn.h>
00043 #include <sip/sippdu.h>
00044 #if OPAL_VIDEO
00045 #include <opal/pcss.h>
00046 #include <codec/vidcodec.h>
00047 #endif
00048
00049 class OpalCall;
00050 class SIPEndPoint;
00051
00052
00054
00057
00058 class SIPConnection : public OpalRTPConnection
00059 {
00060 PCLASSINFO(SIPConnection, OpalRTPConnection);
00061 public:
00062
00067 SIPConnection(
00068 OpalCall & call,
00069 SIPEndPoint & endpoint,
00070 const PString & token,
00071 const SIPURL & address,
00072 OpalTransport * transport,
00073 unsigned int options = 0,
00074 OpalConnection::StringOptions * stringOptions = NULL
00075 );
00076
00079 ~SIPConnection();
00081
00092 virtual bool IsNetworkConnection() const { return true; }
00093
00096 virtual PString GetPrefixName() const;
00097
00104 virtual PString GetRemotePartyURL() const;
00105
00112 virtual PBoolean SetUpConnection();
00113
00120 virtual PString GetDestinationAddress();
00121
00129 virtual PString GetCalledPartyURL();
00130
00137 virtual bool TransferConnection(
00138 const PString & remoteParty
00139 );
00140
00143 virtual bool HoldConnection();
00144
00148 virtual bool RetrieveConnection();
00149
00152 virtual PBoolean IsConnectionOnHold();
00153
00164 virtual PBoolean SetAlerting(
00165 const PString & calleeName,
00166 PBoolean withMedia
00167 );
00168
00173 virtual PBoolean SetConnected();
00174
00177 virtual OpalMediaFormatList GetMediaFormats() const;
00178
00181 virtual OpalMediaStreamPtr OpenMediaStream(
00182 const OpalMediaFormat & mediaFormat,
00183 unsigned sessionID,
00184 bool isSource
00185 );
00186
00191 virtual bool CloseMediaStream(
00192 OpalMediaStream & stream
00193 );
00194
00212 virtual void OnReleased();
00213
00223 virtual PBoolean ForwardCall(
00224 const PString & forwardParty
00225 );
00226
00232 virtual SendUserInputModes GetRealSendUserInputMode() const;
00233
00250 PBoolean SendUserInputTone(char tone, unsigned duration);
00251
00259 virtual void OnRTPStatistics(
00260 const RTP_Session & session
00261 ) const;
00263
00268 virtual void OnTransactionFailed(
00269 SIPTransaction & transaction
00270 );
00271
00274 virtual void OnReceivedPDU(SIP_PDU & pdu);
00275
00278 virtual void OnReceivedINVITE(SIP_PDU & pdu);
00279
00282 virtual void OnReceivedReINVITE(SIP_PDU & pdu);
00283
00286 virtual void OnReceivedACK(SIP_PDU & pdu);
00287
00290 virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
00291
00294 virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
00295
00298 virtual void OnReceivedREFER(SIP_PDU & pdu);
00299
00302 virtual void OnReceivedINFO(SIP_PDU & pdu);
00303
00306 virtual void OnReceivedPING(SIP_PDU & pdu);
00307
00310 virtual void OnReceivedBYE(SIP_PDU & pdu);
00311
00314 virtual void OnReceivedCANCEL(SIP_PDU & pdu);
00315
00320 virtual void OnReceivedResponseToINVITE(
00321 SIPTransaction & transaction,
00322 SIP_PDU & response
00323 );
00324
00327 virtual void OnReceivedResponse(
00328 SIPTransaction & transaction,
00329 SIP_PDU & response
00330 );
00331
00334 virtual void OnReceivedTrying(SIP_PDU & pdu);
00335
00338 virtual void OnReceivedRinging(SIP_PDU & pdu);
00339
00342 virtual void OnReceivedSessionProgress(SIP_PDU & pdu);
00343
00347 virtual PBoolean OnReceivedAuthenticationRequired(
00348 SIPTransaction & transaction,
00349 SIP_PDU & response
00350 );
00351
00354 virtual void OnReceivedRedirection(SIP_PDU & pdu);
00355
00359 virtual void OnReceivedOK(
00360 SIPTransaction & transaction,
00361 SIP_PDU & response
00362 );
00363
00366 virtual void OnCreatingINVITE(SIP_PDU & pdu);
00367
00370 virtual PBoolean SendInviteOK(const SDPSessionDescription & sdp);
00371
00374 virtual PBoolean SendInviteResponse(
00375 SIP_PDU::StatusCodes code,
00376 const char * contact = NULL,
00377 const char * extra = NULL,
00378 const SDPSessionDescription * sdp = NULL
00379 );
00381
00382 unsigned GetNextCSeq() { return ++lastSentCSeq; }
00383
00384 OpalTransportAddress GetLocalAddress(WORD port = 0) const;
00385
00386 OpalTransport & GetTransport() const { return *transport; }
00387
00388 SIPEndPoint & GetEndPoint() const { return endpoint; }
00389 const SIPURL & GetRequestURI() const { return m_requestURI; }
00390 const PString & GetDialogFrom() const { return m_dialogFrom; }
00391 const PString & GetDialogTo() const { return m_dialogTo; }
00392 const PStringList & GetRouteSet() const { return routeSet; }
00393 SIPAuthentication * GetAuthenticator() const { return authentication; }
00394
00395 #if OPAL_VIDEO
00396
00401 virtual PBoolean OnMediaControlXML(SIP_PDU & pdu);
00402 #endif
00403
00404 virtual void OnMediaCommand(OpalMediaCommand & note, INT extra);
00405
00406 protected:
00407 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseRetry);
00408 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnAckTimeout);
00409
00410 void AdjustOutgoingINVITE();
00411 virtual RTP_UDP *OnUseRTPSession(
00412 const unsigned rtpSessionId,
00413 const OpalMediaType & mediaType,
00414 const OpalTransportAddress & mediaAddress,
00415 OpalTransportAddress & localAddress
00416 );
00417
00418 virtual bool OnSendSDP(
00419 bool isAnswerSDP,
00420 OpalRTPSessionManager & rtpSessions,
00421 SDPSessionDescription & sdpOut
00422 );
00423 virtual bool OfferSDPMediaDescription(
00424 const OpalMediaType & mediaType,
00425 unsigned sessionID,
00426 OpalRTPSessionManager & rtpSessions,
00427 SDPSessionDescription & sdpOut
00428 );
00429 virtual bool AnswerSDPMediaDescription(
00430 const SDPSessionDescription & sdpIn,
00431 unsigned sessionIndex,
00432 SDPSessionDescription & sdpOut
00433 );
00434
00435 virtual void OnReceivedSDP(
00436 SIP_PDU & pdu
00437 );
00438 virtual bool OnReceivedSDPMediaDescription(
00439 SDPSessionDescription & sdp,
00440 unsigned sessionId
00441 );
00442 friend class SIPInvite;
00443 static PBoolean WriteINVITE(OpalTransport & transport, void * param);
00444
00445 OpalTransport * CreateTransport(const OpalTransportAddress & address, PBoolean isLocalAddress = PFalse);
00446
00447 void UpdateRemoteAddresses(const PString & addr);
00448
00449 SIPEndPoint & endpoint;
00450 OpalTransport * transport;
00451 bool deleteTransport;
00452
00453 enum HoldState {
00454 eHoldOff,
00455 eRetrieveInProgress,
00456
00457
00458 eHoldOn,
00459 eHoldInProgress
00460 };
00461 HoldState m_holdToRemote;
00462 bool m_holdFromRemote;
00463 PString forwardParty;
00464
00465 SIP_PDU * originalInvite;
00466 PTime originalInviteTime;
00467
00468 bool needReINVITE;
00469 PStringList routeSet;
00470 SIPURL m_requestURI;
00471 PString m_dialogFrom;
00472 PString m_dialogTo;
00473 SIPAuthentication * authentication;
00474
00475 std::map<SIP_PDU::Methods, unsigned> m_lastRxCSeq;
00476
00477 PTimer ackTimer;
00478 PTimer ackRetry;
00479 SIP_PDU ackPacket;
00480 bool ackReceived;
00481 PSafePtr<SIPTransaction> referTransaction;
00482 PSafeList<SIPTransaction> forkedInvitations;
00483 PAtomicInteger lastSentCSeq;
00484
00485 enum {
00486 ReleaseWithBYE,
00487 ReleaseWithCANCEL,
00488 ReleaseWithResponse,
00489 ReleaseWithNothing,
00490 } releaseMethod;
00491
00492 OpalMediaFormatList remoteFormatList;
00493
00494 protected:
00495 PTimer sessionTimer;
00496 public:
00497 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnSessionTimeout);
00498 };
00499
00500
00503 class SIP_RTP_Session : public RTP_UserData
00504 {
00505 PCLASSINFO(SIP_RTP_Session, RTP_UserData);
00506
00511 SIP_RTP_Session(
00512 const SIPConnection & connection
00513 );
00515
00524 virtual void OnTxStatistics(
00525 const RTP_Session & session
00526 ) const;
00527
00534 virtual void OnRxStatistics(
00535 const RTP_Session & session
00536 ) const;
00537
00538 #if OPAL_VIDEO
00539
00543 virtual void OnRxIntraFrameRequest(
00544 const RTP_Session & session
00545 ) const;
00546
00550 virtual void OnTxIntraFrameRequest(
00551 const RTP_Session & session
00552 ) const;
00553 #endif
00554
00555
00556 void OnClearCall(const RTP_Session & );
00557
00558 protected:
00559 const SIPConnection & connection;
00560 };
00561
00562
00563 #endif // __OPAL_SIPCON_H
00564
00565
00566