[asterisk-scf-commits] asterisk-scf/release/media_rtp_pjmedia.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Thu Jun 2 16:54:02 CDT 2011


branch "master" has been updated
       via  f8435c69f85df0811d78d3b7ee67a8e5bc36747d (commit)
      from  fcea6350ddac837d6fabf6caf124c38e762f836a (commit)

Summary of changes:
 config/Rtp.config                  |    6 ++++
 config/RtpConfigurator.py          |    6 ++++
 local-slice/RtpConfigurationIf.ice |   36 ++++++++++++++++++++++
 src/RTPConfiguration.cpp           |   58 ++++++++++++++++++++++++++++++++++++
 src/RTPConfiguration.h             |    3 ++
 src/RTPSession.cpp                 |   33 ++++++++++++++++++--
 6 files changed, 138 insertions(+), 4 deletions(-)


- Log -----------------------------------------------------------------
commit f8435c69f85df0811d78d3b7ee67a8e5bc36747d
Author: Joshua Colp <jcolp at digium.com>
Date:   Thu Jun 2 18:53:42 2011 -0300

    Add support for pushing what IP addresses the RTP component should bind to.

diff --git a/config/Rtp.config b/config/Rtp.config
index d8da13e..e1a99dd 100644
--- a/config/Rtp.config
+++ b/config/Rtp.config
@@ -10,3 +10,9 @@ endport=20000
 
 # Number of worker threads for incoming media
 workerthreadcount=4
+
+# IPv4 address we should bind sessions to
+#ipv4bind=
+
+# IPv6 address we should bind sessions to
+#ipv6bind=
diff --git a/config/RtpConfigurator.py b/config/RtpConfigurator.py
index 56d2bff..60a1bba 100755
--- a/config/RtpConfigurator.py
+++ b/config/RtpConfigurator.py
@@ -40,6 +40,12 @@ class RtpSectionVisitors(Configurator.SectionVisitors):
         workerItem = AsteriskSCF.Media.RTP.V1.WorkerThreadCountItem()
         mapper.map('workerthreadcount', workerItem, 'count', AsteriskSCF.Media.RTP.V1.WorkerThreadCountItemName, config.getint, 4)
 
+        ipv4BindingItem = AsteriskSCF.Media.RTP.V1.BindingIPv4Item()
+        mapper.map('ipv4bind', ipv4BindingItem, 'address', AsteriskSCF.Media.RTP.V1.BindingIPv4AddressItemName, config.get, None)
+
+        ipv6BindingItem = AsteriskSCF.Media.RTP.V1.BindingIPv6Item()
+        mapper.map('ipv6bind', ipv6BindingItem, 'address', AsteriskSCF.Media.RTP.V1.BindingIPv6AddressItemName, config.get, None)
+
         for option in config.options(section):
             mapper.execute(group, section, option)
 
diff --git a/local-slice/RtpConfigurationIf.ice b/local-slice/RtpConfigurationIf.ice
index 09fc822..c380070 100644
--- a/local-slice/RtpConfigurationIf.ice
+++ b/local-slice/RtpConfigurationIf.ice
@@ -136,6 +136,42 @@ module V1
        int count = 4;
    };
 
+   /**
+    * Name that the IPv4 binding configuration item should be inserted as
+    */
+   const string BindingIPv4AddressItemName = "bindingIPv4";
+
+   /**
+    * Binding address for IPv4 traffic
+    */
+   class BindingIPv4Item extends RtpConfigurationItem
+   {
+       /**
+	* Address that IPv4 sessions should be binded to.
+	*
+	* Default value is all.
+	*/
+       string address;
+   };
+
+   /**
+    * Name that the IPv6 binding configuration item should be inserted as
+    */
+   const string BindingIPv6AddressItemName = "bindingIPv6";
+
+   /**
+    * Binding address for IPv6 traffic
+    */
+   class BindingIPv6Item extends RtpConfigurationItem
+   {
+       /**
+	* Address that IPv6 sessions should be binded to.
+	*
+	* Default value is all.
+	*/
+       string address;
+   };
+
 }; /* module V1 */
 
 }; /* module RTP */
diff --git a/src/RTPConfiguration.cpp b/src/RTPConfiguration.cpp
index 2975829..b0a788b 100644
--- a/src/RTPConfiguration.cpp
+++ b/src/RTPConfiguration.cpp
@@ -400,3 +400,61 @@ int ConfigurationServiceImpl::getWorkerThreadCount()
 
     return workerThreadCount->count;
 }
+
+/**
+ * Internal function which returns the IPv4 address to bind to.
+ */
+std::string ConfigurationServiceImpl::getBindIPv4address()
+{
+    boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+
+    if (!mImplPriv->mGeneralGroup)
+    {
+        return "";
+    }
+
+    ConfigurationItemDict::iterator item = mImplPriv->mGeneralGroup->configurationItems.find(BindingIPv4AddressItemName);
+
+    if (item == mImplPriv->mGeneralGroup->configurationItems.end())
+    {
+        return "";
+    }
+
+    BindingIPv4ItemPtr binding = BindingIPv4ItemPtr::dynamicCast(item->second);
+
+    if (!binding)
+    {
+	return "";
+    }
+
+    return binding->address;
+}
+
+/**
+ * Internal function which returns the IPv6 address to bind to.
+ */
+std::string ConfigurationServiceImpl::getBindIPv6address()
+{
+    boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+
+    if (!mImplPriv->mGeneralGroup)
+    {
+        return "";
+    }
+
+    ConfigurationItemDict::iterator item = mImplPriv->mGeneralGroup->configurationItems.find(BindingIPv6AddressItemName);
+
+    if (item == mImplPriv->mGeneralGroup->configurationItems.end())
+    {
+        return "";
+    }
+
+    BindingIPv6ItemPtr binding = BindingIPv6ItemPtr::dynamicCast(item->second);
+
+    if (!binding)
+    {
+        return "";
+    }
+
+    return binding->address;
+}
diff --git a/src/RTPConfiguration.h b/src/RTPConfiguration.h
index 96d2180..af1a978 100644
--- a/src/RTPConfiguration.h
+++ b/src/RTPConfiguration.h
@@ -43,6 +43,9 @@ public:
     int getStartPort();
     int getEndPort();
     int getWorkerThreadCount();
+
+    std::string getBindIPv4address();
+    std::string getBindIPv6address();
 private:
     /**
      * Private implementation details.
diff --git a/src/RTPSession.cpp b/src/RTPSession.cpp
index 7bbf164..641e5c8 100644
--- a/src/RTPSession.cpp
+++ b/src/RTPSession.cpp
@@ -146,14 +146,27 @@ RTPSessionImpl::RTPSessionImpl(const Ice::ObjectAdapterPtr& adapter, const RTPSe
 
     assert(status == PJ_SUCCESS);
 
-    int af = (params->ipv6 == true) ? pj_AF_INET6() : pj_AF_INET();
+    int af;
+    pj_str_t binding;
+
+    if (params->ipv6 == true)
+    {
+	af = pj_AF_INET6();
+	pj_strset(&binding, (char*)(configurationService->getBindIPv6address().c_str()), (configurationService->getBindIPv6address().size()));
+    }
+    else
+    {
+	af = pj_AF_INET();
+        pj_strset(&binding, (char*)(configurationService->getBindIPv4address().c_str()), (configurationService->getBindIPv4address().size()));
+    }
+
     int minimumPort = configurationService->getStartPort();
     int maximumPort = configurationService->getEndPort();
 
     /* Now create some transport we can use to actually send or receive the media. */
     for (int port = minimumPort; port < maximumPort; port += 2)
     {
-        if ((status = pjmedia_transport_udp_create3(mImpl->mEndpoint, af, "RTP", NULL, port, 0, &mImpl->mTransport)) ==
+        if ((status = pjmedia_transport_udp_create3(mImpl->mEndpoint, af, "RTP", pj_strlen(&binding) ? &binding : NULL, port, 0, &mImpl->mTransport)) ==
                 PJ_SUCCESS)
         {
 	    mImpl->mSessionStateItem->mPort = port;
@@ -195,9 +208,21 @@ RTPSessionImpl::RTPSessionImpl(const Ice::ObjectAdapterPtr& adapter, pj_pool_fac
 
     assert(status == PJ_SUCCESS);
 
-    int af = (ipv6 == true) ? pj_AF_INET6() : pj_AF_INET();
+    int af;
+    pj_str_t binding;
+
+    if (ipv6 == true)
+    {
+        af = pj_AF_INET6();
+        pj_strset(&binding, (char*)(configurationService->getBindIPv6address().c_str()), (configurationService->getBindIPv6address().size()));
+    }
+    else
+    {
+        af = pj_AF_INET();
+        pj_strset(&binding, (char*)(configurationService->getBindIPv4address().c_str()), (configurationService->getBindIPv4address().size()));
+    }
 
-    if ((status = pjmedia_transport_udp_create3(mImpl->mEndpoint, af, "RTP", NULL, port, 0, &mImpl->mTransport))
+    if ((status = pjmedia_transport_udp_create3(mImpl->mEndpoint, af, "RTP", pj_strlen(&binding) ? &binding : NULL, port, 0, &mImpl->mTransport))
             != PJ_SUCCESS)
     {
 	// TODO: This is also bad, something is using the port

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


-- 
asterisk-scf/release/media_rtp_pjmedia.git



More information about the asterisk-scf-commits mailing list