[asterisk-scf-commits] asterisk-scf/integration/media_rtp_pjmedia.git branch "modular-transport-refactor" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Jun 29 06:39:11 CDT 2011


branch "modular-transport-refactor" has been updated
       via  165e325093382173c129f80a7d125ffa52be8622 (commit)
      from  6e4cfb8aaa727ce2af9b895b49ce168a4a78b5e8 (commit)

Summary of changes:
 src/ICETransport.cpp |   15 +++++++++--
 src/ICETransport.h   |    3 +-
 src/NATConfig.cpp    |   68 --------------------------------------------------
 src/NATModule.cpp    |    7 +++-
 src/RTPSource.cpp    |   14 +++++++++-
 5 files changed, 31 insertions(+), 76 deletions(-)


- Log -----------------------------------------------------------------
commit 165e325093382173c129f80a7d125ffa52be8622
Author: Brent Eagles <beagles at digium.com>
Date:   Wed Jun 29 08:59:11 2011 -0230

    - Fix problem when the turn server is enabled but not configured (disables
      TURN)
    - Implemented a wait/notify for the localAddress query when using a STUN enabled
      transport. The call will wait until the binding request has completed.
    - Modified the ICE transport to use the info off of the stun socket passed
      in through the library callback in an effort to try and address some
      assert's in pjproject that were happening occassionally on Windows. The
      assert's appear invalid, so might be a race condition. That's a situation
      that's still evolving.

diff --git a/src/ICETransport.cpp b/src/ICETransport.cpp
index a43ad19..16ab255 100644
--- a/src/ICETransport.cpp
+++ b/src/ICETransport.cpp
@@ -534,19 +534,28 @@ void ICETransport::onSetupComplete(pjmedia_transport* transport, int status)
             pj_memcpy(mLastKnownAddr.get(), &info.sock_info.rtp_addr_name, sizeof(pj_sockaddr));
         }
     }
-    boost::unique_lock<boost::shared_mutex> lock(mLock);
+    boost::unique_lock<boost::mutex> lock(mLock);
     mLocalAddress = fromInfo(info);
+    mMonitor.notify_one();
 }
 
 AddressPtr ICETransport::localAddress() 
 {
-    boost::shared_lock<boost::shared_mutex> lock(mLock);
+    boost::unique_lock<boost::mutex> lock(mLock);
+    if (mLocalAddress)
+    {
+        return mLocalAddress;
+    }
+    for (size_t i = 0; i < 5 && !mLocalAddress; ++i)
+    {
+        mMonitor.wait(lock);
+    }
     return mLocalAddress;
 }
 
 AddressPtr ICETransport::remoteAddress() 
 {
-    boost::shared_lock<boost::shared_mutex> lock(mLock);
+    boost::unique_lock<boost::mutex> lock(mLock);
     return mRemoteAddress;
 }
 
diff --git a/src/ICETransport.h b/src/ICETransport.h
index 0c7851a..678a830 100644
--- a/src/ICETransport.h
+++ b/src/ICETransport.h
@@ -63,7 +63,8 @@ public:
         create(const PJMediaEndpointPtr& ep, const PJMediaEnvironmentPtr& configObject);
 
 private:
-    boost::shared_mutex mLock;
+    boost::mutex mLock;
+    boost::condition_variable mMonitor;
     AsteriskSCF::Helpers::AddressPtr mLocalAddress;
     AsteriskSCF::Helpers::AddressPtr mRemoteAddress;
     PJICECallbackPtr mCallback;
diff --git a/src/NATConfig.cpp b/src/NATConfig.cpp
index 96aa923..d31656d 100644
--- a/src/NATConfig.cpp
+++ b/src/NATConfig.cpp
@@ -32,74 +32,6 @@ namespace
 Logger logger = getLoggerFactory().getLogger("AsteriskSCF.MediaRTP");
 }
 
-#if 0
-
-NATConfigPtr AsteriskSCF::PJMediaRTP::NATConfig::create(const Ice::PropertiesPtr& props,
-        const string& propertyPrefix)
-{
-    string prefix(propertyPrefix);
-    if (!prefix.empty() && *(--prefix.end()) != '.')
-    {
-        prefix += '.';
-    }
-    Ice::Int isEnabled = props->getPropertyAsIntWithDefault(prefix + "Media.ICE.Enable", 0);
-    if (isEnabled == 0)
-    {
-        return NATConfigPtr(new NATConfig(AddressPtr(), AddressPtr(), false, false));
-    }
-
-    string hostname = props->getProperty(prefix + "Media.STUN.Server");
-    //
-    // XXX:
-    // This actually isn't necessarily an error, the STUN server can be determined from
-    // DNS records. Let's leave it for now.
-    //
-    //
-    if (hostname.empty())
-    {
-        throw InternalInitializationException("No STUN server configured");
-    }
-    
-    bool hasSTUN = true;
-    Ice::Int portProperty = props->getPropertyAsIntWithDefault(prefix + "Media.STUN.Port", PJ_STUN_PORT);
-    if (static_cast<unsigned>(portProperty) > UINT_MAX)
-    {
-        logger(Warning) << "Property `Media.STUN.Port' is out of range for IP port numbers, defaulting to "
-                        << PJ_STUN_PORT;
-        portProperty = PJ_STUN_PORT;
-    }
-
-    AddressSeq candidates(DNSQuery::create(hostname, portProperty)->execute());
-    if (candidates.empty())
-    {
-        throw InternalInitializationException("Unable to resolve configured STUN server");
-    }
-    AddressPtr stunAddress = candidates.front();
-        
-    //
-    // We read the properties even if TURN isn't enabled since we might make this runtime 
-    // switchable at some point and there is no harm in avoiding extra obstacles.
-    //
-    hostname = props->getProperty(prefix + "Media.TURN.Server.Hostname");
-    bool hasTURN = false;
-    AddressPtr turnAddress;
-    if (!hostname.empty())
-    {
-        portProperty = props->getPropertyAsIntWithDefault(prefix + "Media.TURN.Server.Port", 3479);
-        candidates = DNSQuery::create(hostname, portProperty)->execute();
-        if (!candidates.empty())
-        {
-            if (props->getPropertyAsIntWithDefault(prefix + "Media.TURN.Enable", 0) > 0)
-            {
-                hasTURN = true;
-            }
-            turnAddress = candidates.front();
-        }
-    }
-    return NATConfigPtr(new NATConfig(stunAddress, turnAddress, hasSTUN, hasTURN));
-}
-#endif
-
 NATConfigPtr NATConfig::create(const AsteriskSCF::Helpers::AddressPtr& stunSrv, bool enableSTUN,
         const AsteriskSCF::Helpers::AddressPtr& turnSrv, bool enableTURN)
 {
diff --git a/src/NATModule.cpp b/src/NATModule.cpp
index d6f3350..3b5636f 100644
--- a/src/NATModule.cpp
+++ b/src/NATModule.cpp
@@ -51,8 +51,11 @@ NATModulePtr AsteriskSCF::PJMediaRTP::NATModule::create(const PJMediaEnvironment
     }
     if (env->natConfig()->isTURNEnabled())
     {
-        pj_strdup2(env->memoryPool(), &transcfg->turn.server, env->natConfig()->turnServer()->hostname().c_str());
-        transcfg->turn.port = static_cast<pj_uint16_t>(env->natConfig()->turnServer()->port());
+        if (env->natConfig()->turnServer())
+        {
+            pj_strdup2(env->memoryPool(), &transcfg->turn.server, env->natConfig()->turnServer()->hostname().c_str());
+            transcfg->turn.port = static_cast<pj_uint16_t>(env->natConfig()->turnServer()->port());
+        }
     }
 
     NATModulePtr moduleObj(new NATModule(transcfg));
diff --git a/src/RTPSource.cpp b/src/RTPSource.cpp
index 639062a..9854098 100644
--- a/src/RTPSource.cpp
+++ b/src/RTPSource.cpp
@@ -149,7 +149,12 @@ void StreamSourceRTPImpl::requestFormat(const AsteriskSCF::Media::V1::FormatPtr&
  */
 std::string StreamSourceRTPImpl::getLocalAddress(const Ice::Current&)
 {
-    return mImpl->mTransport->localAddress()->hostname();
+    AsteriskSCF::Helpers::AddressPtr addr = mImpl->mTransport->localAddress();
+    if (addr)
+    {
+        return addr->hostname();
+    }
+    return "";
 }
 
 /**
@@ -157,7 +162,12 @@ std::string StreamSourceRTPImpl::getLocalAddress(const Ice::Current&)
  */
 Ice::Int StreamSourceRTPImpl::getLocalPort(const Ice::Current&)
 {
-    return mImpl->mTransport->localAddress()->port();
+    AsteriskSCF::Helpers::AddressPtr addr = mImpl->mTransport->localAddress();
+    if (addr)
+    {
+        return addr->port();
+    }
+    return 0;
 }
 
 /**

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


-- 
asterisk-scf/integration/media_rtp_pjmedia.git



More information about the asterisk-scf-commits mailing list