[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 May 19 12:12:01 CDT 2011


branch "master" has been updated
       via  d77ecdc4c1ed57239a797b59be19f9841085cbe4 (commit)
      from  10900df1422c8cdd3c43173863a6c7f8087f9801 (commit)

Summary of changes:
 config/Rtp.config                  |   12 +
 config/RtpConfigurator.py          |   52 +++++
 config/test_media_rtp_pjmedia.conf |    4 +-
 local-slice/RtpConfigurationIf.ice |  128 ++++++++++++
 src/CMakeLists.txt                 |    3 +
 src/MediaRTPpjmedia.cpp            |   32 +++-
 src/RTPConfiguration.cpp           |  402 ++++++++++++++++++++++++++++++++++++
 src/RTPConfiguration.h             |   56 +++++
 src/RTPSession.cpp                 |   37 ++--
 src/RTPSession.h                   |    8 +-
 src/RtpStateReplicator.h           |    8 +-
 src/RtpStateReplicatorListener.cpp |   17 +-
 12 files changed, 725 insertions(+), 34 deletions(-)
 create mode 100644 config/Rtp.config
 create mode 100755 config/RtpConfigurator.py
 create mode 100644 local-slice/RtpConfigurationIf.ice
 create mode 100644 src/RTPConfiguration.cpp
 create mode 100644 src/RTPConfiguration.h


- Log -----------------------------------------------------------------
commit d77ecdc4c1ed57239a797b59be19f9841085cbe4
Author: Joshua Colp <jcolp at digium.com>
Date:   Mon May 2 14:47:29 2011 -0300

    Add support for configuration.

diff --git a/config/Rtp.config b/config/Rtp.config
new file mode 100644
index 0000000..d8da13e
--- /dev/null
+++ b/config/Rtp.config
@@ -0,0 +1,12 @@
+# General Configuation Options
+
+[general]
+
+# Start port for RTP and RTCP ports
+startport=10000
+
+# End port for RTP and RTCP ports
+endport=20000
+
+# Number of worker threads for incoming media
+workerthreadcount=4
diff --git a/config/RtpConfigurator.py b/config/RtpConfigurator.py
new file mode 100755
index 0000000..87b3f65
--- /dev/null
+++ b/config/RtpConfigurator.py
@@ -0,0 +1,52 @@
+#!/usr/bin/env python
+
+#
+# Asterisk SCF -- An open-source communications framework.
+#
+# Copyright (C) 2011, Digium, Inc.
+#
+# See http://www.asterisk.org for more information about
+# the Asterisk SCF project. Please do not directly contact
+# any of the maintainers of this project for assistance;
+# the project provides a web site, mailing lists and IRC
+# channels for your use.
+#
+# This program is free software, distributed under the terms of
+# the GNU General Public License Version 2. See the LICENSE.txt file
+# at the top of the source tree.
+#
+
+# Rtp configurator
+
+# Bring in the common configuration infrastructure
+import Ice, Configurator, sys
+
+# Load our component specific configuration definitions
+Ice.loadSlice('-I. -I/opt/Ice-3.4.1/slice -I../../slice --all ../local-slice/RtpConfigurationIf.ice')
+import AsteriskSCF.Media.RTP.V1
+
+# Add our own visitor implementations for the sections we support
+class RtpSectionVisitors(Configurator.SectionVisitors):
+    def visit_general(self, config, section):
+        group = AsteriskSCF.Media.RTP.V1.RtpGeneralGroup()
+        group.configurationItems = { }
+
+        mapper = Configurator.OptionMapper()
+
+        portsItem = AsteriskSCF.Media.RTP.V1.PortRangesItem()
+        mapper.map('startport', portsItem, 'startPort', AsteriskSCF.Media.RTP.V1.PortRangesItemName, config.getint, 10000)
+        mapper.map('endport', portsItem, 'endPort', AsteriskSCF.Media.RTP.V1.PortRangesItemName, config.getint, 20000)
+
+        workerItem = AsteriskSCF.Media.RTP.V1.WorkerThreadCountItem()
+        mapper.map('workerthreadcount', workerItem, 'count', AsteriskSCF.Media.RTP.V1.WorkerThreadCountItemName, config.getint, 4)
+
+        for option in config.options(section):
+            mapper.execute(group, section, option)
+
+        mapper.finish(group)
+
+        self.groups.append(group)
+
+# Make a configurator application and let it run
+app = Configurator.ConfiguratorApp('Rtp.config', RtpSectionVisitors())
+sys.exit(app.main(sys.argv))
diff --git a/config/test_media_rtp_pjmedia.conf b/config/test_media_rtp_pjmedia.conf
index 3a451da..480a7ae 100644
--- a/config/test_media_rtp_pjmedia.conf
+++ b/config/test_media_rtp_pjmedia.conf
@@ -4,8 +4,8 @@ IceBox.Service.MediaRTPpjmedia=media_rtp_pjmedia:create
 
 # Adapter parameters for this component
 MediaRTPpjmediaAdapter.Endpoints=tcp -p 4423
-MediaRTPpjmediaAdapterLogger.Endpoints=default
-MediaRTPpjmediaAdapterLocal.Endpoints=default
+MediaRTPpjmediaAdapterLogger.Endpoints=default -h 127.0.0.1
+MediaRTPpjmediaAdapterLocal.Endpoints=tcp -p 4424
 
 # A proxy to the service locator management service
 ServiceLocatorManagementProxy=LocatorServiceManagement:tcp -p 4422
diff --git a/local-slice/RtpConfigurationIf.ice b/local-slice/RtpConfigurationIf.ice
new file mode 100644
index 0000000..45bbd59
--- /dev/null
+++ b/local-slice/RtpConfigurationIf.ice
@@ -0,0 +1,128 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#pragma once
+#include <Ice/BuiltinSequences.ice>
+#include <AsteriskSCF/System/Component/ConfigurationIf.ice>
+
+module AsteriskSCF
+{
+
+module Media
+{
+
+module RTP
+{
+
+["suppress"]
+module V1
+{
+   /**
+    * Local visitor class for visiting RTP configuration groups
+    */
+   local class RtpConfigurationGroupVisitor extends AsteriskSCF::System::Configuration::V1::ConfigurationGroupVisitor
+   {
+   };
+
+   /**
+    * Generic RTP configuration group
+    */
+   ["visitor:RtpConfigurationGroupVisitor"] class RtpConfigurationGroup extends AsteriskSCF::System::Configuration::V1::ConfigurationGroup
+   {
+   };
+
+   /**
+    * General RTP configuration group that contains general items related to the RTP component as a whole
+    */
+   class RtpGeneralGroup extends RtpConfigurationGroup
+   {
+   };
+
+   /**
+    * Local visitor class for visiting RTP configuration items
+    */
+   local class RtpConfigurationItemVisitor extends AsteriskSCF::System::Configuration::V1::ConfigurationItemVisitor
+   {
+   };
+
+   /**
+    * Generic RTP configuration item
+    */
+   ["visitor:RtpConfigurationItemVisitor"] class RtpConfigurationItem extends AsteriskSCF::System::Configuration::V1::ConfigurationItem
+   {
+   };
+
+   /**
+    * Name that the port ranges configuration item should be inserted as
+    */
+   const string PortRangesItemName = "ports";
+
+   /**
+    * Port ranges configuration item
+    *
+    * This must be added to the general configuration group using the constant string
+    * in PortRangesItemName
+    *
+    */
+   class PortRangesItem extends RtpConfigurationItem
+   {
+       /**
+	* Start port for RTP and RTCP sockets.
+	*
+	* Default value is 10000.
+	*
+	*/
+       int startPort = 10000;
+
+       /**
+	* End port for RTP and RTCP sockets.
+	*
+	* Default value is 20000.
+	*
+	*/
+       int endPort = 20000;
+   };
+
+   /**
+    * Name that the worker thread count configuration item should be inserted as
+    */
+   const string WorkerThreadCountItemName = "workerThreadCount";
+
+   /**
+    * Worker thread count for incoming media configuration item
+    *
+    * This must be added to the general configuration group using the constant string
+    * in WorkerThreadCountItemName
+    *
+    */
+   class WorkerThreadCountItem extends RtpConfigurationItem
+   {
+       /**
+	* Number of threads that should handle incoming media.
+	*
+	* Default value is 4.
+	*/
+       int count = 4;
+   };
+
+}; /* module V1 */
+
+}; /* module RTP */
+
+}; /* module Media */
+
+}; /* module Asterisk SCF */
+
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b3396d3..c3be82a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -17,7 +17,10 @@ asterisk_scf_component_add_file(media_rtp_pjmedia RTPSource.h)
 asterisk_scf_component_add_file(media_rtp_pjmedia RTPSink.h)
 asterisk_scf_component_add_file(media_rtp_pjmedia RtpStateReplicatorListener.cpp)
 asterisk_scf_component_add_file(media_rtp_pjmedia RtpStateReplicator.h)
+asterisk_scf_component_add_file(media_rtp_pjmedia RTPConfiguration.cpp)
+asterisk_scf_component_add_file(media_rtp_pjmedia RTPConfiguration.h)
 asterisk_scf_component_add_slice(media_rtp_pjmedia ../local-slice/RtpStateReplicationIf.ice)
+asterisk_scf_component_add_slice(media_rtp_pjmedia ../local-slice/RtpConfigurationIf.ice)
 asterisk_scf_component_add_boost_libraries(media_rtp_pjmedia core thread)
 asterisk_scf_component_build_icebox(media_rtp_pjmedia)
 target_link_libraries(media_rtp_pjmedia logging-client)
diff --git a/src/MediaRTPpjmedia.cpp b/src/MediaRTPpjmedia.cpp
index 3fb0964..9989ddb 100644
--- a/src/MediaRTPpjmedia.cpp
+++ b/src/MediaRTPpjmedia.cpp
@@ -36,6 +36,7 @@
 
 #include "RTPSession.h"
 #include "RtpStateReplicator.h"
+#include "RTPConfiguration.h"
 
 using namespace std;
 using namespace AsteriskSCF::Core::Discovery::V1;
@@ -53,6 +54,7 @@ Logger lg = getLoggerFactory().getLogger("AsteriskSCF.MediaRTP");
 static const string ReplicaServiceId("MediaRtpReplica");
 static const string MediaServiceId("RTPMediaService");
 static const string MediaComparatorServiceId("RTPMediaServiceComparator");
+static const string ConfigurationServiceId("RTPConfigurationService");
 
 /**
  * Implementation of the RTPMediaService interface as defined in MediaRTPIf.ice
@@ -61,7 +63,8 @@ class RTPMediaServiceImpl : public RTPMediaService
 {
 public:
     RTPMediaServiceImpl(const Ice::ObjectAdapterPtr&, const ReplicaPtr&,
-	const AsteriskSCF::Discovery::SmartProxy<RtpStateReplicatorPrx>&);
+	const AsteriskSCF::Discovery::SmartProxy<RtpStateReplicatorPrx>&,
+	const ConfigurationServiceImplPtr&);
     RTPSessionPrx allocate(const RTPServiceLocatorParamsPtr&, const Ice::Current&);
     pj_pool_factory *getPoolFactory() { return &mCachingPool.factory; };
 private:
@@ -86,6 +89,11 @@ private:
     ReplicaPtr mReplicaService;
 
     /**
+     * A pointer to the configuration service.
+     */
+    ConfigurationServiceImplPtr mConfigurationService;
+
+    /**
      * A proxy to the state replicator.
      */
     AsteriskSCF::Discovery::SmartProxy<RtpStateReplicatorPrx> mStateReplicator;
@@ -234,6 +242,11 @@ private:
     ReplicaPtr mReplicaService;
 
     /**
+     * Instance of our configuration service implementation.
+     */
+    ConfigurationServiceImplPtr mConfigurationService;
+
+    /**
      * Instance of our state replicator listener.
      */
     RtpStateReplicatorListenerPtr mReplicatorListener;
@@ -360,8 +373,10 @@ private:
  * Constructor for the RTPMediaServiceImpl class.
  */
 RTPMediaServiceImpl::RTPMediaServiceImpl(const Ice::ObjectAdapterPtr& adapter, const ReplicaPtr& replicaService,
-        const AsteriskSCF::Discovery::SmartProxy<RtpStateReplicatorPrx>& stateReplicator) :
-    mAdapter(adapter), mReplicaService(replicaService), mStateReplicator(stateReplicator)
+    const AsteriskSCF::Discovery::SmartProxy<RtpStateReplicatorPrx>& stateReplicator,
+    const ConfigurationServiceImplPtr& configurationService) :
+    mAdapter(adapter), mReplicaService(replicaService), mConfigurationService(configurationService),
+    mStateReplicator(stateReplicator)
 {
     /* Initialize the memory caching pool using default policy as specified by pjlib. */
     pj_caching_pool_init(&mCachingPool, &pj_pool_factory_default_policy, 0);
@@ -376,7 +391,8 @@ RTPMediaServiceImpl::RTPMediaServiceImpl(const Ice::ObjectAdapterPtr& adapter, c
 RTPSessionPrx RTPMediaServiceImpl::allocate(const RTPServiceLocatorParamsPtr& params, const Ice::Current&)
 {
     RTPSessionImplPtr session =
-        new RTPSessionImpl(mAdapter, params, &mCachingPool.factory, mReplicaService, mStateReplicator);
+        new RTPSessionImpl(mAdapter, params, &mCachingPool.factory, mReplicaService, mStateReplicator,
+	    mConfigurationService);
     return session->getProxy();
 }
 
@@ -420,6 +436,9 @@ void MediaRTPpjmediaApp::start(const std::string&, const Ice::CommunicatorPtr& c
     mReplicaService = new ReplicaImpl(mLocalAdapter);
     mLocalAdapter->add(mReplicaService, mCommunicator->stringToIdentity(ReplicaServiceId));
 
+    mConfigurationService = new ConfigurationServiceImpl();
+    mLocalAdapter->add(mConfigurationService, mCommunicator->stringToIdentity(ConfigurationServiceId));
+
     mLocalAdapter->activate();
 
     mGlobalAdapter = mCommunicator->createObjectAdapter("MediaRTPpjmediaAdapter");
@@ -451,12 +470,13 @@ void MediaRTPpjmediaApp::start(const std::string&, const Ice::CommunicatorPtr& c
     }
 
     RTPMediaServiceImplPtr rtpmediaservice =
-        new RTPMediaServiceImpl(mGlobalAdapter, mReplicaService, mStateReplicator);
+        new RTPMediaServiceImpl(mGlobalAdapter, mReplicaService, mStateReplicator, mConfigurationService);
 
     if (mStateReplicator)
     {
         mReplicatorListener =
-            new RtpStateReplicatorListenerI(mGlobalAdapter, rtpmediaservice->getPoolFactory(), mGeneralState);
+            new RtpStateReplicatorListenerI(mGlobalAdapter, rtpmediaservice->getPoolFactory(), mGeneralState,
+		mConfigurationService);
         mReplicatorListenerProxy =
             RtpStateReplicatorListenerPrx::uncheckedCast(mLocalAdapter->addWithUUID(mReplicatorListener));
 
diff --git a/src/RTPConfiguration.cpp b/src/RTPConfiguration.cpp
new file mode 100644
index 0000000..1fef9f5
--- /dev/null
+++ b/src/RTPConfiguration.cpp
@@ -0,0 +1,402 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#include <IceUtil/UUID.h>
+
+#include <boost/thread.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/thread/shared_mutex.hpp>
+
+#include <AsteriskSCF/System/Component/ConfigurationIf.h>
+
+#include "RtpConfigurationIf.h"
+#include "RTPConfiguration.h"
+
+using namespace AsteriskSCF::System::Configuration::V1;
+using namespace AsteriskSCF::Media::RTP::V1;
+
+class ConfigurationServiceImplPriv
+{
+public:
+    /**
+     * General RTP configuration
+     */
+    RtpGeneralGroupPtr mGeneralGroup;
+
+    /**
+     * Shared mutex lock which protects the configuration
+     */
+    boost::shared_mutex mLock;
+};
+
+ConfigurationServiceImpl::ConfigurationServiceImpl() : mImplPriv(new ConfigurationServiceImplPriv())
+{
+}
+
+ConfigurationGroupSeq ConfigurationServiceImpl::getConfiguration(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class GroupVisitor : public RtpConfigurationGroupVisitor
+    {
+    public:
+        GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv, ConfigurationGroupSeq& visitorGroups) : mImplPriv(implPriv), mGroups(visitorGroups) { };
+
+    private:
+        /**
+         * Internal helper function which determines what configuration items should be returned
+         */
+        void insertRequestedConfigurationItems(const ConfigurationItemDict& requestedItems,
+            const ConfigurationItemDict& localItems,
+            ConfigurationItemDict& returnedItems)
+        {
+
+            boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+
+            for (ConfigurationItemDict::const_iterator requestedItem = requestedItems.cbegin();
+                 requestedItem != requestedItems.end();
+                 ++requestedItem)
+            {
+                ConfigurationItemDict::const_iterator localItem = localItems.find(requestedItem->first);
+
+                if (localItem != localItems.end())
+                {
+                    returnedItems.insert((*requestedItem));
+                }
+            }
+        }
+
+        void visitRtpGeneralGroup(const ::AsteriskSCF::Media::RTP::V1::RtpGeneralGroupPtr& group)
+        {
+            if (!mImplPriv->mGeneralGroup)
+            {
+                return;
+            }
+
+            RtpGeneralGroupPtr returnedGroup = new RtpGeneralGroup();
+
+            insertRequestedConfigurationItems(group->configurationItems, mImplPriv->mGeneralGroup->configurationItems, returnedGroup->configurationItems);
+
+            mGroups.push_back(returnedGroup);
+        };
+
+        boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
+        ConfigurationGroupSeq& mGroups;
+    };
+    
+    ConfigurationGroupSeq newGroups;
+    RtpConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv, newGroups);
+    
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+    
+    return newGroups;
+}
+
+ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationAll(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class GroupVisitor : public RtpConfigurationGroupVisitor
+    {
+    public:
+        GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv, ConfigurationGroupSeq& visitorGroups) :
+            mImplPriv(implPriv), mGroups(visitorGroups) { };
+ 
+    private:
+        void visitRtpGeneralGroup(const ::AsteriskSCF::Media::RTP::V1::RtpGeneralGroupPtr&)
+        {
+            if (!mImplPriv->mGeneralGroup)
+            {
+                return;
+            }
+     
+            mGroups.push_back(mImplPriv->mGeneralGroup);
+        };
+        
+        boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
+        ConfigurationGroupSeq& mGroups;
+    };
+    
+    ConfigurationGroupSeq newGroups;
+    RtpConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv, newGroups);
+
+    boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+    
+    return newGroups;
+}
+
+ConfigurationGroupSeq ConfigurationServiceImpl::getConfigurationGroups(const Ice::Current&)
+{
+    ConfigurationGroupSeq groups;
+ 
+    boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+   
+    if (mImplPriv->mGeneralGroup)
+    {
+        RtpGeneralGroupPtr general = new RtpGeneralGroup();
+        groups.push_back(general);
+    }
+    
+    return groups;
+}
+
+void ConfigurationServiceImpl::setConfiguration(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class GroupVisitor : public RtpConfigurationGroupVisitor
+    {
+    public:
+        GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv) : mImplPriv(implPriv) { };
+ 
+    private:
+        /**
+         * Helper function which performs serial number checking of items
+         */
+        void performSerialCheck(const ConfigurationItemDict& changedItems, const ConfigurationItemDict& localItems,
+            const AsteriskSCF::System::Configuration::V1::ConfigurationGroupPtr& group)
+        {
+            for (ConfigurationItemDict::const_iterator item = changedItems.cbegin();
+                 item != changedItems.end();
+                 ++item)
+            {
+                // If serial checking is to be skipped for this item just skip over it
+                if (item->second->serialNumber == -1)
+                {
+                    continue;
+                }
+  
+                ConfigurationItemDict::const_iterator localItem = localItems.find(item->first);
+  
+                if (localItem == localItems.end())
+                {
+                    // This is a new item so serial checking does not apply
+                    continue;
+                }
+  
+                if (item->second->serialNumber < localItem->second->serialNumber)
+                {
+                    throw SerialConflict(group, item->second);
+                }
+            }
+        }
+ 
+        void visitRtpGeneralGroup(const ::AsteriskSCF::Media::RTP::V1::RtpGeneralGroupPtr& group)
+        {
+            if (!mImplPriv->mGeneralGroup)
+            {
+                mImplPriv->mGeneralGroup = new RtpGeneralGroup();
+            }
+            else
+            {
+                performSerialCheck(group->configurationItems, mImplPriv->mGeneralGroup->configurationItems, group);
+            }
+     
+            for (ConfigurationItemDict::const_iterator item = group->configurationItems.begin();
+                 item != group->configurationItems.end();
+                 ++item)
+            {
+                mImplPriv->mGeneralGroup->configurationItems.erase(item->first);
+                mImplPriv->mGeneralGroup->configurationItems.insert((*item));
+            }
+        }
+ 
+        boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
+    };
+    
+    RtpConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv);
+
+    boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+}
+
+void ConfigurationServiceImpl::removeConfigurationItems(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class GroupVisitor : public RtpConfigurationGroupVisitor
+    {
+    public:
+        GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv) : mImplPriv(implPriv) { };
+        
+        void removeItems(RtpConfigurationItemVisitor* visitor, ConfigurationItemDict& itemsToRemove,
+            ConfigurationItemDict& localItems)
+        {
+            for (ConfigurationItemDict::const_iterator item = itemsToRemove.begin();
+                 item != itemsToRemove.end();
+                 ++item)
+            {
+                ConfigurationItemDict::iterator localItem = localItems.find(item->first);
+                if (localItem ==  localItems.end())
+                {
+                    continue;
+                }
+                if (visitor != 0)
+                {
+                    item->second->visit(visitor);
+                }
+                localItems.erase(localItem);
+            }
+        }
+ 
+        void visitRtpGeneralGroup(const ::AsteriskSCF::Media::RTP::V1::RtpGeneralGroupPtr& group)
+        {
+            if (!mImplPriv->mGeneralGroup)
+            {
+                return;
+            }
+            
+            removeItems(0, group->configurationItems, mImplPriv->mGeneralGroup->configurationItems);
+        };
+ 
+    private:
+        boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
+    };
+    
+    RtpConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv);
+
+    boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+}
+
+void ConfigurationServiceImpl::removeConfigurationGroups(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq& groups, const Ice::Current&)
+{
+    class GroupVisitor : public RtpConfigurationGroupVisitor
+    {
+    public:
+        GroupVisitor(boost::shared_ptr<ConfigurationServiceImplPriv> implPriv) : mImplPriv(implPriv) { };
+ 
+    private:
+        void visitRtpGeneralGroup(const ::AsteriskSCF::Media::RTP::V1::RtpGeneralGroupPtr&)
+        {
+            if (!mImplPriv->mGeneralGroup)
+            {
+                return;
+            }
+            
+            mImplPriv->mGeneralGroup = 0;
+        };
+        
+        boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
+    };
+    
+    RtpConfigurationGroupVisitorPtr v = new GroupVisitor(mImplPriv);
+
+    boost::unique_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    
+    for (ConfigurationGroupSeq::const_iterator group = groups.begin(); group != groups.end(); ++group)
+    {
+        (*group)->visit(v);
+    }
+}
+
+/**
+ * Internal function which returns configured start port.
+ */
+int ConfigurationServiceImpl::getStartPort()
+{
+    boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    PortRangesItemPtr portsDefault = new PortRangesItem();
+
+    if (!mImplPriv->mGeneralGroup)
+    {
+        return portsDefault->startPort;
+    }
+
+    ConfigurationItemDict::iterator item = mImplPriv->mGeneralGroup->configurationItems.find(PortRangesItemName);
+
+    if (item == mImplPriv->mGeneralGroup->configurationItems.end())
+    {
+        return portsDefault->startPort;
+    }
+
+    PortRangesItemPtr ports = PortRangesItemPtr::dynamicCast(item->second);
+
+    if (!ports || (ports->endPort <= ports->startPort) || (ports->startPort % 2))
+    {
+        return portsDefault->startPort;
+    }
+
+    return ports->startPort;
+}
+
+/**
+ * Internal function which returns configured end port.
+ */
+int ConfigurationServiceImpl::getEndPort()
+{
+    boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    PortRangesItemPtr portsDefault = new PortRangesItem();
+
+    if (!mImplPriv->mGeneralGroup)
+    {
+        return portsDefault->endPort;
+    }
+
+    ConfigurationItemDict::iterator item = mImplPriv->mGeneralGroup->configurationItems.find(PortRangesItemName);
+
+    if (item == mImplPriv->mGeneralGroup->configurationItems.end())
+    {
+        return portsDefault->endPort;
+    }
+
+    PortRangesItemPtr ports = PortRangesItemPtr::dynamicCast(item->second);
+
+    if (!ports || (ports->endPort <= ports->startPort) || (ports->endPort % 2))
+    {
+        return portsDefault->endPort;
+    }
+
+    return ports->endPort;
+}
+
+/**
+ * Internal function which returns configured worker thread count.
+ */
+int ConfigurationServiceImpl::getWorkerThreadCount()
+{
+    boost::shared_lock<boost::shared_mutex> lock(mImplPriv->mLock);
+    WorkerThreadCountItemPtr workerThreadCountDefault = new WorkerThreadCountItem();
+
+    if (!mImplPriv->mGeneralGroup)
+    {
+        return workerThreadCountDefault->count;
+    }
+
+    ConfigurationItemDict::iterator item = mImplPriv->mGeneralGroup->configurationItems.find(WorkerThreadCountItemName);
+
+    if (item == mImplPriv->mGeneralGroup->configurationItems.end())
+    {
+        return workerThreadCountDefault->count;
+    }
+
+    WorkerThreadCountItemPtr workerThreadCount = WorkerThreadCountItemPtr::dynamicCast(item->second);
+
+    if (!workerThreadCount)
+    {
+        return workerThreadCountDefault->count;
+    }
+
+    return workerThreadCount->count;
+}
diff --git a/src/RTPConfiguration.h b/src/RTPConfiguration.h
new file mode 100644
index 0000000..96d2180
--- /dev/null
+++ b/src/RTPConfiguration.h
@@ -0,0 +1,56 @@
+/*
+ * Asterisk SCF -- An open-source communications framework.
+ *
+ * Copyright (C) 2011, Digium, Inc.
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk SCF project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE.txt file
+ * at the top of the source tree.
+ */
+
+#pragma once
+
+#include <Ice/Ice.h>
+
+#include <AsteriskSCF/System/Component/ConfigurationIf.h>
+
+/*
+ * Private implementation class for ConfigurationServiceImpl.
+ */
+class ConfigurationServiceImplPriv;
+
+/**
+ * Implementation of the configuration service.
+ */
+class ConfigurationServiceImpl : public AsteriskSCF::System::Configuration::V1::ConfigurationService
+{
+public:
+    ConfigurationServiceImpl();
+
+    AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq getConfiguration(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+    AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq getConfigurationAll(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+    AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq getConfigurationGroups(const Ice::Current&);
+    void setConfiguration(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+    void removeConfigurationItems(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+    void removeConfigurationGroups(const AsteriskSCF::System::Configuration::V1::ConfigurationGroupSeq&, const Ice::Current&);
+
+    int getStartPort();
+    int getEndPort();
+    int getWorkerThreadCount();
+private:
+    /**
+     * Private implementation details.
+     */
+    boost::shared_ptr<ConfigurationServiceImplPriv> mImplPriv;
+};
+
+/**
+ * A typedef which creates a smart pointer type for ConfigurationServiceImpl.
+ */
+typedef IceUtil::Handle<ConfigurationServiceImpl> ConfigurationServiceImplPtr;
diff --git a/src/RTPSession.cpp b/src/RTPSession.cpp
index bf97327..ae9423c 100644
--- a/src/RTPSession.cpp
+++ b/src/RTPSession.cpp
@@ -30,6 +30,8 @@
 #include "RTPSource.h"
 #include "RTPSink.h"
 
+#include "RTPConfiguration.h"
+
 using namespace std;
 using namespace AsteriskSCF::Core::Discovery::V1;
 using namespace AsteriskSCF::Media::V1;
@@ -54,8 +56,8 @@ class RTPSessionImplPriv
 {
 public:
     RTPSessionImplPriv(const Ice::ObjectAdapterPtr& adapter, const FormatSeq& formats,
-            const ReplicaPtr& replicaService,
-            const AsteriskSCF::Discovery::SmartProxy<RtpStateReplicatorPrx>& stateReplicator) :
+	const ReplicaPtr& replicaService,
+	const AsteriskSCF::Discovery::SmartProxy<RtpStateReplicatorPrx>& stateReplicator) :
 	mAdapter(adapter), mFormats(formats),
         mSessionStateItem(new RtpSessionStateItem()),
         mReplicaService(replicaService), mStateReplicator(stateReplicator) { };
@@ -131,25 +133,25 @@ public:
  * Constructor for the RTPSessionImpl class (used by Ice).
  */
 RTPSessionImpl::RTPSessionImpl(const Ice::ObjectAdapterPtr& adapter, const RTPServiceLocatorParamsPtr& params,
-        pj_pool_factory* factory, const ReplicaPtr& replicaService,
-        const AsteriskSCF::Discovery::SmartProxy<RtpStateReplicatorPrx>& stateReplicator) : 
+    pj_pool_factory* factory, const ReplicaPtr& replicaService,
+    const AsteriskSCF::Discovery::SmartProxy<RtpStateReplicatorPrx>& stateReplicator,
+    const ConfigurationServiceImplPtr& configurationService) : 
     mImpl(new RTPSessionImplPriv(adapter, params->formats, replicaService, stateReplicator))
 {
     /* Add ourselves to the ICE ASM so we can be used. */
     mImpl->mProxy = RTPSessionPrx::uncheckedCast(adapter->addWithUUID(this));
 
     /* Create an endpoint in pjmedia for our media. */
-    pj_status_t status = pjmedia_endpt_create(factory, NULL, 1, &mImpl->mEndpoint);
+    pj_status_t status = pjmedia_endpt_create(factory, NULL, configurationService->getWorkerThreadCount(), &mImpl->mEndpoint);
 
-    if (status != PJ_SUCCESS)
-    {
-        /* TODO: This is bad... we can't go on! */
-    }
+    assert(status != PJ_SUCCESS);
 
     int af = (params->ipv6 == true) ? pj_AF_INET6() : pj_AF_INET();
+    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 = DEFAULT_RTP_PORT_MINIMUM; port < DEFAULT_RTP_PORT_MAXIMUM; port += 2)
+    for (int port = minimumPort; port < maximumPort; port += 2)
     {
         if ((status = pjmedia_transport_udp_create3(mImpl->mEndpoint, af, "RTP", NULL, port, 0, &mImpl->mTransport)) ==
                 PJ_SUCCESS)
@@ -183,25 +185,22 @@ RTPSessionImpl::RTPSessionImpl(const Ice::ObjectAdapterPtr& adapter, const RTPSe
  * Constructor for the RTPSessionImpl class (used by state replicator).
  */
 RTPSessionImpl::RTPSessionImpl(const Ice::ObjectAdapterPtr& adapter, pj_pool_factory* factory,
-        const Ice::Identity& sessionIdentity, const Ice::Identity& sinkIdentity, const Ice::Identity& sourceIdentity,
-    Ice::Int port, const FormatSeq& formats, bool ipv6) :
+    const Ice::Identity& sessionIdentity, const Ice::Identity& sinkIdentity, const Ice::Identity& sourceIdentity,
+    Ice::Int port, const FormatSeq& formats, bool ipv6, const ConfigurationServiceImplPtr& configurationService) :
     mImpl(new RTPSessionImplPriv(adapter, formats, 0, *(new AsteriskSCF::Discovery::SmartProxy<RtpStateReplicatorPrx>)))
 {
     mImpl->mProxy = RTPSessionPrx::uncheckedCast(adapter->add(this, sessionIdentity));
 
-    pj_status_t status = pjmedia_endpt_create(factory, NULL, 1, &mImpl->mEndpoint);
+    pj_status_t status = pjmedia_endpt_create(factory, NULL, configurationService->getWorkerThreadCount(), &mImpl->mEndpoint);
 
-    if (status != PJ_SUCCESS)
-    {
-	/* TODO: This is bad... we can't go on! */
-    }
+    assert(status != PJ_SUCCESS);
 
     int af = (ipv6 == true) ? pj_AF_INET6() : pj_AF_INET();
 
     if ((status = pjmedia_transport_udp_create3(mImpl->mEndpoint, af, "RTP", NULL, port, 0, &mImpl->mTransport))
             != PJ_SUCCESS)
     {
-	// TODO: This is also bad, something is using the port */
+	// TODO: This is also bad, something is using the port
     }
 
     mImpl->mStreamSource = new StreamSourceRTPImpl(this, "");
@@ -442,6 +441,7 @@ void RTPSessionImpl::replicateState(const RtpSessionStateItemPtr& session, const
     }
     catch (...)
     {
+	mImpl->mStateReplicator->setState(items);
     }
 }
 
@@ -486,5 +486,6 @@ void RTPSessionImpl::removeState(const RtpSessionStateItemPtr& session, const Rt
     }
     catch (...)
     {
+	mImpl->mStateReplicator->removeState(items);
     }
 }
diff --git a/src/RTPSession.h b/src/RTPSession.h
index 6638b14..4ba6e86 100644
--- a/src/RTPSession.h
+++ b/src/RTPSession.h
@@ -11,6 +11,8 @@
 #include <boost/shared_ptr.hpp>
 #include <AsteriskSCF/Discovery/SmartProxy.h>
 
+#include "RTPConfiguration.h"
+
 /**
  * Forward definition for our private implementation of RTPSession.
  */
@@ -44,9 +46,11 @@ class RTPSessionImpl : public AsteriskSCF::Media::RTP::V1::RTPSession
 public:
     RTPSessionImpl(const Ice::ObjectAdapterPtr&, const AsteriskSCF::Media::RTP::V1::RTPServiceLocatorParamsPtr&,
 	pj_pool_factory*, const AsteriskSCF::System::Component::V1::ReplicaPtr&, 
-	const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::Media::RTP::V1::RtpStateReplicatorPrx>&);
+	const AsteriskSCF::Discovery::SmartProxy<AsteriskSCF::Media::RTP::V1::RtpStateReplicatorPrx>&,
+	const ConfigurationServiceImplPtr&);
     RTPSessionImpl(const Ice::ObjectAdapterPtr&, pj_pool_factory*, const Ice::Identity&, const Ice::Identity&,
-	const Ice::Identity&, Ice::Int, const AsteriskSCF::Media::V1::FormatSeq&, bool);
+	const Ice::Identity&, Ice::Int, const AsteriskSCF::Media::V1::FormatSeq&, bool,
+	const ConfigurationServiceImplPtr&);
     AsteriskSCF::Media::V1::StreamSourceSeq getSources(const Ice::Current&);
     AsteriskSCF::Media::V1::StreamSinkSeq getSinks(const Ice::Current&);
     std::string getId(const Ice::Current&);
diff --git a/src/RtpStateReplicator.h b/src/RtpStateReplicator.h
index 4ab9e64..13c9502 100644
--- a/src/RtpStateReplicator.h
+++ b/src/RtpStateReplicator.h
@@ -20,8 +20,12 @@
 
 #include <AsteriskSCF/Replication/StateReplicator.h>
 #include "RtpStateReplicationIf.h"
+
 #include <boost/shared_ptr.hpp>
 
+#include "RTPConfiguration.h"
+
+
 typedef AsteriskSCF::Replication::StateReplicator<
     AsteriskSCF::Media::RTP::V1::RtpStateReplicator, 
     AsteriskSCF::Media::RTP::V1::RtpStateItemPtr, 
@@ -38,7 +42,9 @@ class RtpStateReplicatorListenerI : public AsteriskSCF::Media::RTP::V1::RtpState
 {
 public:
     RtpStateReplicatorListenerI(const Ice::ObjectAdapterPtr&, pj_pool_factory*, 
-      const AsteriskSCF::Media::RTP::V1::RtpGeneralStateItemPtr&);
+	const AsteriskSCF::Media::RTP::V1::RtpGeneralStateItemPtr&,
+	const ConfigurationServiceImplPtr&);
+    ~RtpStateReplicatorListenerI();
     void stateRemoved(const Ice::StringSeq&, const Ice::Current&);
     void stateSet(const AsteriskSCF::Media::RTP::V1::RtpStateItemSeq&, const Ice::Current&);
     bool operator==(const RtpStateReplicatorListenerI &rhs);
diff --git a/src/RtpStateReplicatorListener.cpp b/src/RtpStateReplicatorListener.cpp
index 2bfab90..4f3cef1 100644
--- a/src/RtpStateReplicatorListener.cpp
+++ b/src/RtpStateReplicatorListener.cpp
@@ -55,8 +55,10 @@ struct RtpStateReplicatorListenerImpl
 {
 public:
     RtpStateReplicatorListenerImpl(const Ice::ObjectAdapterPtr& adapter, pj_pool_factory *poolFactory,
-            const RtpGeneralStateItemPtr& generalState)
-        : mId(IceUtil::generateUUID()), mAdapter(adapter), mPoolFactory(poolFactory), mGeneralState(generalState) {}
+	const RtpGeneralStateItemPtr& generalState,
+	const ConfigurationServiceImplPtr& configurationService)
+        : mId(IceUtil::generateUUID()), mAdapter(adapter), mPoolFactory(poolFactory), mGeneralState(generalState),
+	  mConfigurationService(configurationService) {}
     
     void removeStateNoticeImpl(const Ice::StringSeq& itemKeys)
     {
@@ -97,7 +99,8 @@ public:
 
 		    RTPSessionImplPtr localSession =
                         new RTPSessionImpl(mImpl->mAdapter, mImpl->mPoolFactory, item->mSessionIdentity,
-			    item->mSinkIdentity, item->mSourceIdentity, item->mPort, item->mFormats, item->mIPv6);
+			    item->mSinkIdentity, item->mSourceIdentity, item->mPort, item->mFormats, item->mIPv6,
+			    mImpl->mConfigurationService);
 		    localitem->setSession(localSession);
 		}
 		else
@@ -144,11 +147,15 @@ public:
     Ice::ObjectAdapterPtr mAdapter;
     pj_pool_factory *mPoolFactory;
     RtpGeneralStateItemPtr mGeneralState;
+    ConfigurationServiceImplPtr mConfigurationService;
 };
 
 RtpStateReplicatorListenerI::RtpStateReplicatorListenerI(const Ice::ObjectAdapterPtr& adapter,
-        pj_pool_factory *poolFactory, const RtpGeneralStateItemPtr& generalState)
-    : mImpl(new RtpStateReplicatorListenerImpl(adapter, poolFactory, generalState)) 
+    pj_pool_factory *poolFactory, const RtpGeneralStateItemPtr& generalState,
+    const ConfigurationServiceImplPtr& configurationService)
+    : mImpl(new RtpStateReplicatorListenerImpl(adapter, poolFactory, generalState, configurationService)) {}
+
+RtpStateReplicatorListenerI::~RtpStateReplicatorListenerI()
 {
 }
 

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


-- 
asterisk-scf/release/media_rtp_pjmedia.git



More information about the asterisk-scf-commits mailing list