[asterisk-scf-commits] asterisk-scf/integration/media_rtp_pjmedia.git branch "rtcp" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Jul 11 18:29:39 CDT 2011


branch "rtcp" has been updated
       via  a71f813b8429a763e49f6124d054e70814990c12 (commit)
      from  dd244752577ee9d4ceb35759160299b0eb3014ab (commit)

Summary of changes:
 src/RTPSession.cpp |   20 +++++++++++++-------
 src/RTPSession.h   |    1 +
 src/RTPSource.cpp  |   49 +++++++++++++++++++++++++++++++++++++++++++++++--
 src/RTPSource.h    |    1 +
 4 files changed, 62 insertions(+), 9 deletions(-)


- Log -----------------------------------------------------------------
commit a71f813b8429a763e49f6124d054e70814990c12
Author: Joshua Colp <jcolp at digium.com>
Date:   Mon Jul 11 20:30:17 2011 -0300

    Allow the destination address and port for RTCP to be set.

diff --git a/src/RTPSession.cpp b/src/RTPSession.cpp
index d2cd88c..43a774d 100644
--- a/src/RTPSession.cpp
+++ b/src/RTPSession.cpp
@@ -297,7 +297,7 @@ public:
     /**
      * Constructor for this implementation.
      */
-    RTCPSessionImpl(const RTPSessionImplPtr& rtpSession) : mRtpSession(rtpSession) { }
+    RTCPSessionImpl(const RTPSessionImplPtr& session) : mSession(session) { }
 
     /**
      * Method used to retrieve the port our RTCP session is listening on.
@@ -307,23 +307,21 @@ public:
         pjmedia_transport_info transportInfo;
 
         pjmedia_transport_info_init(&transportInfo);
-        pjmedia_transport_get_info(mRtpSession->getTransport(), &transportInfo);
+        pjmedia_transport_get_info(mSession->getTransport(), &transportInfo);
 
         return pj_sockaddr_get_port(&transportInfo.sock_info.rtcp_addr_name);
     }
 
-    /**
-     * Method used to set the port to send RTCP packets to.
-     */
-    void setRemotePort(Ice::Int port, const Ice::Current&)
+    void setRemoteDetails(const std::string& address, Ice::Int port, const Ice::Current&)
     {
+        mSession->setRemoteRtcpDetails(address, port);
     }
 
 private:
     /**
      * Pointer to the RTP session.
      */
-    RTPSessionImplPtr mRtpSession;
+    RTPSessionImplPtr mSession;
 };
 
 /**
@@ -619,6 +617,14 @@ void RTPSessionImpl::setRemoteDetails(const string& address, Ice::Int port)
 }
 
 /**
+ * API call which calls into RTPSourceImpl in order to setup transport.
+ */
+void RTPSessionImpl::setRemoteRtcpDetails(const std::string& address, Ice::Int port)
+{
+    mImpl->mStreamSource->setRemoteRtcpDetails(address, port);
+}
+
+/**
  * API call which returns a media format based on payload.
  *
  * @return The media format corresponding to the payload.
diff --git a/src/RTPSession.h b/src/RTPSession.h
index 3c52ef4..3dcf9fb 100644
--- a/src/RTPSession.h
+++ b/src/RTPSession.h
@@ -66,6 +66,7 @@ public:
     AsteriskSCF::Media::V1::FormatSeq getFormats();
     void associatePayloads(const AsteriskSCF::Media::RTP::V1::PayloadMap&, const Ice::Current&);
     void setRemoteDetails(const std::string& address, Ice::Int port);
+    void setRemoteRtcpDetails(const std::string&, Ice::Int port);
     AsteriskSCF::Media::V1::FormatPtr getFormat(int payload);
     int getPayload(const AsteriskSCF::Media::V1::FormatPtr& mediaformat);
     StreamSourceRTPImplPtr getSource();
diff --git a/src/RTPSource.cpp b/src/RTPSource.cpp
index 73a2aa9..0078b32 100644
--- a/src/RTPSource.cpp
+++ b/src/RTPSource.cpp
@@ -377,8 +377,8 @@ void StreamSourceRTPImpl::setRemoteDetails(const string& address, Ice::Int port)
     pjmedia_transport_detach(mImpl->mSession->getTransport(), this);
 
     /* All ready... actually do it! */
-    status = pjmedia_transport_attach(mImpl->mSession->getTransport(), this, &addr, NULL, pj_sockaddr_get_len(&addr),
-                                      &receiveRTP, &receiveRTCP);
+    status = pjmedia_transport_attach(mImpl->mSession->getTransport(), this, &addr, &transportInfo.src_rtcp_name,
+                                      pj_sockaddr_get_len(&addr), &receiveRTP, &receiveRTCP);
 
     if (status != PJ_SUCCESS)
     {
@@ -387,6 +387,51 @@ void StreamSourceRTPImpl::setRemoteDetails(const string& address, Ice::Int port)
 }
 
 /**
+ * API call which sets up our pjmedia transport and allows media to be sent and received.
+ */
+void StreamSourceRTPImpl::setRemoteRtcpDetails(const std::string& address, Ice::Int port)
+{
+    pj_sockaddr addr;
+
+    /* This feels so dirty but convert from our std::string to a pj_str, since their API requires it. */
+    pj_str_t tmpAddress;
+    pj_strset(&tmpAddress, (char*)address.c_str(), address.size());
+
+    /* Now for the next trick - convert into a pj_sockaddr so we can pass it to pjmedia_transport_attach */
+    pj_status_t status = pj_sockaddr_parse(pj_AF_UNSPEC(), 0, &tmpAddress, &addr);
+
+    if (status != PJ_SUCCESS)
+    {
+        throw InvalidAddress();
+    }
+
+    // Confirm that the address family of the address matches that of this RTP session
+    pjmedia_transport_info transportInfo;
+
+    pjmedia_transport_info_init(&transportInfo);
+    pjmedia_transport_get_info(mImpl->mSession->getTransport(), &transportInfo);
+
+    if (transportInfo.sock_info.rtcp_addr_name.addr.sa_family != addr.addr.sa_family)
+    {
+        throw InvalidAddress();
+    }
+
+    pj_sockaddr_set_port(&addr, static_cast<pj_uint16_t>(port));
+
+    /* In case we were already attached go ahead and detach */
+    pjmedia_transport_detach(mImpl->mSession->getTransport(), this);
+
+    /* All ready... actually do it! */
+    status = pjmedia_transport_attach(mImpl->mSession->getTransport(), this, &transportInfo.src_rtp_name, &addr,
+                                      pj_sockaddr_get_len(&addr), &receiveRTP, &receiveRTCP);
+
+    if (status != PJ_SUCCESS)
+    {
+        throw InvalidAddress();
+    }
+}
+
+/**
  * API call which returns a pointer to the source state item.
  */
 RtpStreamSourceStateItemPtr StreamSourceRTPImpl::getStateItem()
diff --git a/src/RTPSource.h b/src/RTPSource.h
index f032f88..5bdbab4 100644
--- a/src/RTPSource.h
+++ b/src/RTPSource.h
@@ -32,6 +32,7 @@ public:
     Ice::Int getLocalPort(const Ice::Current&);
 
     void setRemoteDetails(const std::string& address, Ice::Int port);
+    void setRemoteRtcpDetails(const std::string&, Ice::Int);
     void setSinks(const AsteriskSCF::Media::V1::StreamSinkSeq&);
     AsteriskSCF::Replication::MediaRTPPJMedia::V1::RtpStreamSourceStateItemPtr getStateItem();
 

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/media_rtp_pjmedia.git



More information about the asterisk-scf-commits mailing list