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 #include <opal/rtpconn.h>
00041 #include <sip/sippdu.h>
00042 #if OPAL_VIDEO
00043 #include <opal/pcss.h>
00044 #include <codec/vidcodec.h>
00045 #endif
00046
00047 class OpalCall;
00048 class SIPEndPoint;
00049
00050
00052
00055
00056 class SIPConnection : public OpalRTPConnection
00057 {
00058 PCLASSINFO(SIPConnection, OpalRTPConnection);
00059 public:
00060
00065 SIPConnection(
00066 OpalCall & call,
00067 SIPEndPoint & endpoint,
00068 const PString & token,
00069 const SIPURL & address,
00070 OpalTransport * transport,
00071 unsigned int options = 0,
00072 OpalConnection::StringOptions * stringOptions = NULL
00073 );
00074
00077 ~SIPConnection();
00079
00090 virtual bool IsNetworkConnection() const { return true; }
00091
00094 virtual PString GetPrefixName() const;
00095
00102 virtual PString GetRemotePartyURL() const;
00103
00110 virtual PBoolean SetUpConnection();
00111
00118 virtual PString GetDestinationAddress();
00119
00127 virtual PString GetCalledPartyURL();
00128
00135 virtual bool TransferConnection(
00136 const PString & remoteParty
00137 );
00138
00141 virtual bool HoldConnection();
00142
00146 virtual bool RetrieveConnection();
00147
00150 virtual PBoolean IsConnectionOnHold();
00151
00162 virtual PBoolean SetAlerting(
00163 const PString & calleeName,
00164 PBoolean withMedia
00165 );
00166
00171 virtual PBoolean SetConnected();
00172
00175 virtual OpalMediaFormatList GetMediaFormats() const;
00176
00179 virtual OpalMediaStreamPtr OpenMediaStream(
00180 const OpalMediaFormat & mediaFormat,
00181 unsigned sessionID,
00182 bool isSource
00183 );
00184
00189 virtual bool CloseMediaStream(
00190 OpalMediaStream & stream
00191 );
00192
00210 virtual void OnReleased();
00211
00221 virtual PBoolean ForwardCall(
00222 const PString & forwardParty
00223 );
00224
00230 virtual SendUserInputModes GetRealSendUserInputMode() const;
00231
00248 PBoolean SendUserInputTone(char tone, unsigned duration);
00249
00257 virtual void OnRTPStatistics(
00258 const RTP_Session & session
00259 ) const;
00261
00266 virtual void OnTransactionFailed(
00267 SIPTransaction & transaction
00268 );
00269
00272 virtual void OnReceivedPDU(SIP_PDU & pdu);
00273
00276 virtual void OnReceivedINVITE(SIP_PDU & pdu);
00277
00280 virtual void OnReceivedReINVITE(SIP_PDU & pdu);
00281
00284 virtual void OnReceivedACK(SIP_PDU & pdu);
00285
00288 virtual void OnReceivedOPTIONS(SIP_PDU & pdu);
00289
00292 virtual void OnReceivedNOTIFY(SIP_PDU & pdu);
00293
00296 virtual void OnReceivedREFER(SIP_PDU & pdu);
00297
00300 virtual void OnReceivedINFO(SIP_PDU & pdu);
00301
00304 virtual void OnReceivedPING(SIP_PDU & pdu);
00305
00308 virtual void OnReceivedBYE(SIP_PDU & pdu);
00309
00312 virtual void OnReceivedCANCEL(SIP_PDU & pdu);
00313
00318 virtual void OnReceivedResponseToINVITE(
00319 SIPTransaction & transaction,
00320 SIP_PDU & response
00321 );
00322
00325 virtual void OnReceivedResponse(
00326 SIPTransaction & transaction,
00327 SIP_PDU & response
00328 );
00329
00332 virtual void OnReceivedTrying(SIP_PDU & pdu);
00333
00336 virtual void OnReceivedRinging(SIP_PDU & pdu);
00337
00340 virtual void OnReceivedSessionProgress(SIP_PDU & pdu);
00341
00345 virtual PBoolean OnReceivedAuthenticationRequired(
00346 SIPTransaction & transaction,
00347 SIP_PDU & response
00348 );
00349
00352 virtual void OnReceivedRedirection(SIP_PDU & pdu);
00353
00357 virtual void OnReceivedOK(
00358 SIPTransaction & transaction,
00359 SIP_PDU & response
00360 );
00361
00364 virtual void OnCreatingINVITE(SIP_PDU & pdu);
00365
00368 virtual PBoolean SendInviteOK(const SDPSessionDescription & sdp);
00369
00372 virtual PBoolean SendInviteResponse(
00373 SIP_PDU::StatusCodes code,
00374 const char * contact = NULL,
00375 const char * extra = NULL,
00376 const SDPSessionDescription * sdp = NULL
00377 );
00379
00380 unsigned GetNextCSeq() { return ++lastSentCSeq; }
00381
00382 OpalTransportAddress GetLocalAddress(WORD port = 0) const;
00383
00384 OpalTransport & GetTransport() const { return *transport; }
00385
00386 SIPEndPoint & GetEndPoint() const { return endpoint; }
00387 const SIPURL & GetRequestURI() const { return m_requestURI; }
00388 const PString & GetDialogFrom() const { return m_dialogFrom; }
00389 const PString & GetDialogTo() const { return m_dialogTo; }
00390 const PStringList & GetRouteSet() const { return routeSet; }
00391 SIPAuthentication * GetAuthenticator() const { return authentication; }
00392
00393 #if OPAL_VIDEO
00394
00399 virtual PBoolean OnMediaControlXML(SIP_PDU & pdu);
00400 #endif
00401
00402 virtual void OnMediaCommand(OpalMediaCommand & note, INT extra);
00403
00404 protected:
00405 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnInviteResponseRetry);
00406 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnAckTimeout);
00407
00408 void AdjustOutgoingINVITE();
00409 virtual RTP_UDP *OnUseRTPSession(
00410 const unsigned rtpSessionId,
00411 const OpalMediaType & mediaType,
00412 const OpalTransportAddress & mediaAddress,
00413 OpalTransportAddress & localAddress
00414 );
00415
00416 virtual bool OnSendSDP(
00417 bool isAnswerSDP,
00418 OpalRTPSessionManager & rtpSessions,
00419 SDPSessionDescription & sdpOut
00420 );
00421 virtual bool OfferSDPMediaDescription(
00422 const OpalMediaType & mediaType,
00423 unsigned sessionID,
00424 OpalRTPSessionManager & rtpSessions,
00425 SDPSessionDescription & sdpOut
00426 );
00427 virtual bool AnswerSDPMediaDescription(
00428 const SDPSessionDescription & sdpIn,
00429 unsigned sessionIndex,
00430 SDPSessionDescription & sdpOut
00431 );
00432
00433 virtual void OnReceivedSDP(
00434 SIP_PDU & pdu
00435 );
00436 virtual bool OnReceivedSDPMediaDescription(
00437 SDPSessionDescription & sdp,
00438 unsigned sessionId
00439 );
00440 friend class SIPInvite;
00441 static PBoolean WriteINVITE(OpalTransport & transport, void * param);
00442
00443 OpalTransport * CreateTransport(const OpalTransportAddress & address, PBoolean isLocalAddress = PFalse);
00444
00445 void UpdateRemoteAddresses(const PString & addr);
00446
00447 SIPEndPoint & endpoint;
00448 OpalTransport * transport;
00449 bool deleteTransport;
00450
00451 enum HoldState {
00452 eHoldOff,
00453 eRetrieveInProgress,
00454
00455
00456 eHoldOn,
00457 eHoldInProgress
00458 };
00459 HoldState m_holdToRemote;
00460 bool m_holdFromRemote;
00461 PString forwardParty;
00462
00463 SIP_PDU * originalInvite;
00464 PTime originalInviteTime;
00465
00466 bool needReINVITE;
00467 PStringList routeSet;
00468 SIPURL m_requestURI;
00469 PString m_dialogFrom;
00470 PString m_dialogTo;
00471 SIPAuthentication * authentication;
00472
00473 std::map<SIP_PDU::Methods, unsigned> m_lastRxCSeq;
00474
00475 PTimer ackTimer;
00476 PTimer ackRetry;
00477 SIP_PDU ackPacket;
00478 bool ackReceived;
00479 PSafePtr<SIPTransaction> referTransaction;
00480 PSafeList<SIPTransaction> forkedInvitations;
00481 PAtomicInteger lastSentCSeq;
00482
00483 enum {
00484 ReleaseWithBYE,
00485 ReleaseWithCANCEL,
00486 ReleaseWithResponse,
00487 ReleaseWithNothing,
00488 } releaseMethod;
00489
00490 OpalMediaFormatList remoteFormatList;
00491
00492 protected:
00493 PTimer sessionTimer;
00494 public:
00495 PDECLARE_NOTIFIER(PTimer, SIPConnection, OnSessionTimeout);
00496 };
00497
00498
00501 class SIP_RTP_Session : public RTP_UserData
00502 {
00503 PCLASSINFO(SIP_RTP_Session, RTP_UserData);
00504
00509 SIP_RTP_Session(
00510 const SIPConnection & connection
00511 );
00513
00522 virtual void OnTxStatistics(
00523 const RTP_Session & session
00524 ) const;
00525
00532 virtual void OnRxStatistics(
00533 const RTP_Session & session
00534 ) const;
00535
00536 #if OPAL_VIDEO
00537
00541 virtual void OnRxIntraFrameRequest(
00542 const RTP_Session & session
00543 ) const;
00544
00548 virtual void OnTxIntraFrameRequest(
00549 const RTP_Session & session
00550 ) const;
00551 #endif
00552
00553
00554 void OnClearCall(const RTP_Session & );
00555
00556 protected:
00557 const SIPConnection & connection;
00558 };
00559
00560
00561 #endif // __OPAL_SIPCON_H
00562
00563
00564