[asterisk-scf-commits] asterisk-scf/integration/bridging.git branch "master" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Tue Aug 24 10:13:09 CDT 2010


branch "master" has been updated
       via  735d80bc996b104beead3908121d426427e180c8 (commit)
       via  7aae58899005c25495968a65b6d8076ba5a742fb (commit)
      from  9debae0c2994968e641ba1e22a339adc48dfe10e (commit)

Summary of changes:
 src/BridgeImpl.cpp    |   66 +++++++++-----
 src/BridgeImpl.h      |   22 ++++-
 src/CMakeLists.txt    |    1 +
 src/MediaSplicer.cpp  |  241 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/MediaSplicer.h    |   32 +++++++
 test/CMakeLists.txt   |    1 +
 test/TestBridging.cpp |  166 ++++++++++++++++++++++++++++++++++
 7 files changed, 503 insertions(+), 26 deletions(-)
 create mode 100644 src/MediaSplicer.cpp
 create mode 100644 src/MediaSplicer.h


- Log -----------------------------------------------------------------
commit 735d80bc996b104beead3908121d426427e180c8
Author: Brent Eagles <beagles at digium.com>
Date:   Tue Aug 24 12:42:18 2010 -0230

    Update the submodules to catchup on slice

diff --git a/slice b/slice
index e88ddfb..5d80463 160000
--- a/slice
+++ b/slice
@@ -1 +1 @@
-Subproject commit e88ddfb27c75ef7e4315a598c9c2749052cc0f5b
+Subproject commit 5d804630eb1081d200e1408644b6af22a8a751f3

commit 7aae58899005c25495968a65b6d8076ba5a742fb
Author: Brent Eagles <beagles at digium.com>
Date:   Tue Aug 24 12:39:29 2010 -0230

    Integrate a media splicer functionality to allow media interconnections.

diff --git a/slice b/slice
index 5d80463..e88ddfb 160000
--- a/slice
+++ b/slice
@@ -1 +1 @@
-Subproject commit 5d804630eb1081d200e1408644b6af22a8a751f3
+Subproject commit e88ddfb27c75ef7e4315a598c9c2749052cc0f5b
diff --git a/src/BridgeImpl.cpp b/src/BridgeImpl.cpp
index d6f4ec7..fa573be 100644
--- a/src/BridgeImpl.cpp
+++ b/src/BridgeImpl.cpp
@@ -87,7 +87,7 @@ namespace BridgeService
     //
     // Functor to support using for_each on shutdown.
     //
-    class BridgeShutdownFunctor : public std::unary_function<Session::V1::SessionEndpointPtr, void>
+    class BridgeShutdownFunctor : public std::unary_function<BridgeImpl::BridgeEndpoint, void>
     {
     public:
         BridgeShutdownFunctor(const Core::Endpoint::V1::EndpointIdPtr& id, const Session::V1::ResponseCodePtr& responseCode) : 
@@ -96,15 +96,19 @@ namespace BridgeService
         {
         }
 
-        void operator()(const Hydra::Core::Endpoint::V1::BaseEndpointPtr b) 
+        void operator()(const BridgeImpl::BridgeEndpoint& b) 
         { 
-            if(!b)
+            if(b.endpoint)
             {
-                Hydra::Session::V1::SessionEndpointPtr p(Hydra::Session::V1::SessionEndpointPtr::dynamicCast(b));
+                Hydra::Session::V1::SessionEndpointPtr p(Hydra::Session::V1::SessionEndpointPtr::dynamicCast(b.endpoint));
                 assert(p != 0);
                 if(p->callback)
                 {
-                    Hydra::Session::V1::SessionEndpointPtr::dynamicCast(b)->callback->terminated(mId, mResponseCode);
+                    p->callback->terminated(mId, mResponseCode);
+                }
+                if(b.connector)
+                {
+                    b.connector->unplug();
                 }
             }
         }
@@ -116,6 +120,11 @@ namespace BridgeService
 } // End of namespace BridgeService
 } // End of namespace Hydra
 
+static std::string endpointIdToString(const Hydra::Core::Endpoint::V1::EndpointIdPtr& id)
+{
+    return id->endpointManagerId + ":" + id->destinationId;
+}
+
 Hydra::BridgeService::BridgeImpl::BridgeImpl(
   const Hydra::Session::V1::SessionEndpointPtr& adminEp,
   const Hydra::Session::V1::SessionEndpointSeq& initialEndpoints,
@@ -124,12 +133,19 @@ Hydra::BridgeService::BridgeImpl::BridgeImpl(
 
   ) :
     mState(Running),
-    mAdminEndpoint(adminEp),
-    mEndpoints(initialEndpoints),
     mMonitor(manager),
     mEvents(new Hydra::BridgeService::EventTopicWrapper(ev)),
     mAdminEndpointInList(true)
 {
+    if(adminEp)
+    {
+        mAdminEndpoint = std::auto_ptr<Hydra::BridgeService::BridgeImpl::BridgeEndpoint>(new Hydra::BridgeService::BridgeImpl::BridgeEndpoint(adminEp, 0));
+        mAdminEndpoint->connector = mSplicer.connect(endpointIdToString(adminEp->id), adminEp->mediaSession);
+    }
+    for(Hydra::Session::V1::SessionEndpointSeq::const_iterator i = initialEndpoints.begin(); i != initialEndpoints.end(); ++i)
+    {
+        mEndpoints.push_back(BridgeEndpoint(*i, mSplicer.connect(endpointIdToString((*i)->id), (*i)->mediaSession)));
+    }
 }
 
 void Hydra::BridgeService::BridgeImpl::addEndpoint(const Hydra::Core::Endpoint::V1::BaseEndpointPtr& ep, const Ice::Current& current)
@@ -155,7 +171,7 @@ void Hydra::BridgeService::BridgeImpl::addEndpoint(const Hydra::Core::Endpoint::
     }
     boost::unique_lock<boost::shared_mutex> lock(mLock);
     statePreCheck();
-    Hydra::Session::V1::SessionEndpointSeq::iterator  i = find(ep->id);
+    std::vector<Hydra::BridgeService::BridgeImpl::BridgeEndpoint>::iterator  i = find(ep->id);
     if(i != mEndpoints.end())
     {
         mLogger.getDebugStream() << __FUNCTION__ << ": endpoint with id " << ep->id->endpointManagerId << ":" << ep->id->destinationId << " already registered." << std::endl;
@@ -167,11 +183,11 @@ void Hydra::BridgeService::BridgeImpl::addEndpoint(const Hydra::Core::Endpoint::
         bool result = mMonitor->onAddEndpoint(ep);
         mLogger.getDebugStream() << __FUNCTION__ << "onAddEndpoint() returned " << result << std::endl;
     }
+
     //
-    // It's hear that the media operations will be calculated and the media allocator accessed for building the media operations for
-    // the bridge.
+    // Connect media.
     //
-    mEndpoints.push_back(newEndpoint);
+    mEndpoints.push_back(BridgeEndpoint(newEndpoint, mSplicer.connect(endpointIdToString(newEndpoint->id), newEndpoint->mediaSession)));
     mLogger.getDebugStream() << __FUNCTION__ << ": bridge " << current.adapter->getCommunicator()->identityToString(current.id) <<
          " now has " << mEndpoints.size() << " endpoints." << std::endl;
     mEvents->endpointAdded(newEndpoint);
@@ -190,7 +206,7 @@ void Hydra::BridgeService::BridgeImpl::removeEndpoint(const Hydra::Core::Endpoin
     {
         throw Hydra::Core::Endpoint::V1::InvalidEndpointId(ep);
     }
-    Hydra::Session::V1::SessionEndpointSeq::iterator  i = find(ep);
+    std::vector<Hydra::BridgeService::BridgeImpl::BridgeEndpoint>::iterator  i = find(ep);
     if(i == mEndpoints.end())
     {
         throw Hydra::Core::Bridging::V1::UnknownEndpoint(ep);
@@ -198,10 +214,14 @@ void Hydra::BridgeService::BridgeImpl::removeEndpoint(const Hydra::Core::Endpoin
 
     if(mMonitor)
     {
-        bool result =  mMonitor->onRemoveEndpoint(*i);
+        bool result =  mMonitor->onRemoveEndpoint(i->endpoint);
         mLogger.getDebugStream() << __FUNCTION__ << "onRemoveEndpoint() returned " << result << std::endl;
     }
-    mEvents->endpointRemoved(*i);
+    mEvents->endpointRemoved(i->endpoint);
+    //
+    // XXX: Exceptions?
+    //
+    i->connector->unplug();
     mEndpoints.erase(i);
 
     mLogger.getDebugStream() << __FUNCTION__ << ": bridge " << current.adapter->getCommunicator()->identityToString(current.id) <<
@@ -216,14 +236,14 @@ Hydra::Core::Endpoint::V1::EndpointSeq Hydra::BridgeService::BridgeImpl::listEnd
     mLogger.getDebugStream() << __FUNCTION__ << ": working with " << mEndpoints.size() << " endpoints." << std::endl;
 
     Hydra::Core::Endpoint::V1::EndpointSeq eps;
-    if(mAdminEndpointInList && mAdminEndpoint != 0)
+    if(mAdminEndpointInList && mAdminEndpoint.get() != 0)
     {
         mLogger.getDebugStream() << __FUNCTION__ << ": adding admin endpoint to result set." << std::endl;
-        eps.push_back(mAdminEndpoint);
+        eps.push_back(mAdminEndpoint->endpoint);
     }
-    for(Hydra::Session::V1::SessionEndpointSeq::const_iterator i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
+    for(std::vector<Hydra::BridgeService::BridgeImpl::BridgeEndpoint>::const_iterator i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
     {
-        eps.push_back(*i);
+        eps.push_back(i->endpoint);
     }
     if(mMonitor)
     {
@@ -262,9 +282,9 @@ void Hydra::BridgeService::BridgeImpl::shutdown(const Ice::Current& current)
     // TODO: Source ids for bridge generated operations should come from configuration, etc.
     //
     Hydra::Core::Endpoint::V1::EndpointIdPtr sourceId;
-    if(mAdminEndpoint)
+    if(mAdminEndpoint.get() != 0 )
     {
-        sourceId = mAdminEndpoint->id;
+        sourceId = mAdminEndpoint->endpoint->id;
     }
     //
     // TODO: Response code for termination messages for bridges shutting down should come from configuration
@@ -325,12 +345,12 @@ void Hydra::BridgeService::BridgeImpl::statePreCheck()
     }
 }
 
-Hydra::Session::V1::SessionEndpointSeq::iterator Hydra::BridgeService::BridgeImpl::find(const Core::Endpoint::V1::EndpointIdPtr& e)
+std::vector<Hydra::BridgeService::BridgeImpl::BridgeEndpoint>::iterator Hydra::BridgeService::BridgeImpl::find(const Core::Endpoint::V1::EndpointIdPtr& e)
 {
     mLogger.getDebugStream() << __FUNCTION__ << ": searching endpoints for " << e->endpointManagerId << ":" << e->destinationId << "." << std::endl;
-    for(Hydra::Session::V1::SessionEndpointSeq::iterator i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
+    for(std::vector<Hydra::BridgeService::BridgeImpl::BridgeEndpoint>::iterator i = mEndpoints.begin(); i != mEndpoints.end(); ++i)
     {
-        if(e->endpointManagerId == (*i)->id->endpointManagerId && e->destinationId == (*i)->id->destinationId)
+        if(e->endpointManagerId == i->endpoint->id->endpointManagerId && e->destinationId == i->endpoint->id->destinationId)
         {
             return i;
         }
diff --git a/src/BridgeImpl.h b/src/BridgeImpl.h
index 08d21c5..9261a9a 100644
--- a/src/BridgeImpl.h
+++ b/src/BridgeImpl.h
@@ -8,6 +8,7 @@
 #include <boost/thread/shared_mutex.hpp>
 #include <vector>
 #include "Logger.h"
+#include "MediaSplicer.h"
 
 namespace Hydra
 {
@@ -30,6 +31,18 @@ namespace BridgeService
    class BridgeImpl : public Core::Bridging::V1::Bridge
    {
    public:
+      struct BridgeEndpoint
+      {
+          Session::V1::SessionEndpointPtr endpoint;
+          MediaConnectorPtr connector;
+
+          BridgeEndpoint(const Session::V1::SessionEndpointPtr& ep, const MediaConnectorPtr& con) :
+              endpoint(ep),
+              connector(con)
+          {
+          }
+      };
+
       BridgeImpl(const Session::V1::SessionEndpointPtr& adminEp, const Session::V1::SessionEndpointSeq& initialEndpoints,
         const Core::Bridging::V1::BridgeMonitorPrx& manager, const Core::Bridging::V1::BridgeEventsPrx& ev);
 
@@ -48,6 +61,7 @@ namespace BridgeService
       bool destroyed();
 
    private:
+
       boost::shared_mutex mLock;
       enum ServiceStates
       { 
@@ -57,11 +71,13 @@ namespace BridgeService
       };
       ServiceStates mState;
 
-      Core::Endpoint::V1::BaseEndpointPtr mAdminEndpoint;
-      Session::V1::SessionEndpointSeq mEndpoints;
+      std::auto_ptr<BridgeEndpoint> mAdminEndpoint;
+      std::vector<BridgeEndpoint> mEndpoints;
       Core::Bridging::V1::BridgeMonitorPrx mMonitor;
       std::auto_ptr<EventTopicWrapper> mEvents;
 
+      MediaSplicer mSplicer;
+
       //
       // Policy values.
       //
@@ -69,7 +85,7 @@ namespace BridgeService
       Logger mLogger;
 
       void statePreCheck();
-      Session::V1::SessionEndpointSeq::iterator find(const Core::Endpoint::V1::EndpointIdPtr& e);
+      std::vector<BridgeEndpoint>::iterator find(const Core::Endpoint::V1::EndpointIdPtr& e);
    };
 
    typedef IceUtil::Handle<BridgeImpl> BridgeImplPtr;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 42a7295..f383dad 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -8,6 +8,7 @@ hydra_component_add_slice(bridgeservice ServiceLocatorIf)
 hydra_component_add_file(bridgeservice Service.cpp)
 hydra_component_add_file(bridgeservice BridgeImpl.cpp)
 hydra_component_add_file(bridgeservice BridgeFactoryImpl.cpp)
+hydra_component_add_file(bridgeservice MediaSplicer.cpp)
 hydra_component_add_ice_libraries(bridgeservice IceStorm)
 hydra_component_add_boost_libraries(bridgeservice thread)
 hydra_component_build_standalone(bridgeservice)
diff --git a/src/MediaSplicer.cpp b/src/MediaSplicer.cpp
new file mode 100644
index 0000000..10eae57
--- /dev/null
+++ b/src/MediaSplicer.cpp
@@ -0,0 +1,241 @@
+#include "MediaSplicer.h"
+#include <IceUtil/Shared.h>
+#include <IceUtil/Handle.h>
+
+namespace Hydra
+{
+namespace BridgeService
+{
+    //
+    // Forward declarations.
+    //
+    class MediaSplicerI;
+    class MedixMixerPtr;
+
+    typedef std::pair<Media::V1::StreamSinkPrx, Media::V1::StreamSourcePrx> OutgoingPairing;
+    typedef std::pair<Media::V1::StreamSourcePrx, Media::V1::StreamSinkPrx> IncomingPairing;
+
+    class MediaConnectorI : public MediaConnector
+    {
+    public:
+
+        MediaConnectorI(const std::vector<OutgoingPairing>& outgoing, const std::vector<IncomingPairing>& incoming):
+            mOutgoing(outgoing),
+            mIncoming(incoming)
+        {
+            for(std::vector<OutgoingPairing>::iterator i = mOutgoing.begin(); i != mOutgoing.end(); ++i)
+            {
+                i->second->setSink(i->first);
+                i->first->setSource(i->second);
+            }
+            for(std::vector<IncomingPairing>::iterator i = mIncoming.begin(); i != mIncoming.end(); ++i)
+            {
+                i->first->setSink(i->second);
+                i->second->setSource(i->first);
+            }
+        }
+
+        void unplug()
+        {
+            for(std::vector<OutgoingPairing>::iterator i = mOutgoing.begin(); i != mOutgoing.end(); ++i)
+            {
+                i->second->setSink(0);
+                i->first->setSource(0);
+            }
+            for(std::vector<IncomingPairing>::iterator i = mIncoming.begin(); i != mIncoming.end(); ++i)
+            {
+                i->first->setSink(0);
+                i->second->setSource(0);
+            }
+        }
+
+    private:
+        std::vector<OutgoingPairing> mOutgoing;
+        std::vector<IncomingPairing> mIncoming;
+    };
+
+    //
+    // TODO: This needs to register the streams with an active threaded mixing element.
+    // 
+    class MediaSplicerI : public IceUtil::Shared
+    {
+
+    public:
+
+        MediaConnectorPtr connect(const std::string& id, const Media::V1::SessionPrx& session)
+        {
+            if(!session)
+            {
+                return 0;
+            }
+
+            MediaSessionMap::iterator existing = mSessionMap.find(id);
+            if(existing!= mSessionMap.end())
+            {
+                //
+                // TODO: Needs to throw some kind of media connect error. For now, we will simply return the connector
+                //
+                return existing->second.connector;
+            }
+
+            //
+            // Idiom-wise, it is best to defer calling getSources() until after the sinks have all been
+            // processed. However, we do not want to do the sink linkup if the getSources fails so we
+            // do both calls up here.
+            //
+            Media::V1::StreamSinkSeq sinks = session->getSinks();
+            Media::V1::StreamSourceSeq sources = session->getSources();
+
+            std::vector<OutgoingPairing> outgoingPairings(findCompatiblePairings(sinks));
+            std::vector<IncomingPairing> incomingPairings(findCompatiblePairings(sources));
+
+            MediaConnectorPtr result(new MediaConnectorI(outgoingPairings, incomingPairings));
+            mSessionMap.insert(std::pair<std::string, MediaSessionStruct>(id, MediaSessionStruct(session, result)));
+            return result;
+        }
+
+    private:
+
+        struct MediaSessionStruct 
+        {
+            Media::V1::SessionPrx mediaSession;
+            MediaConnectorPtr connector;
+
+            MediaSessionStruct(const Media::V1::SessionPrx& session, const MediaConnectorPtr& con) :
+                mediaSession(session),
+                connector(con)
+            {
+            }
+        };
+
+        typedef std::map<std::string, MediaSessionStruct> MediaSessionMap;
+
+        MediaSessionMap mSessionMap;
+
+        bool needMixing()
+        {
+            //
+            // XXX:
+            // We are only supporting single stream with two endpoints for the Alpha, so no mixing will 
+            // be required.
+            //
+            return false;
+        }
+
+        bool hasPreferredCodecOverride()
+        {
+            //
+            // XXX: In some configurations, transcoding might be forced even if there is only two call 
+            // participants and they can communicate with common codecs. This will not be supported for the
+            // alpha.
+            //
+            return false;
+        }
+
+        bool canAdapt(const Media::V1::StreamSourcePrx& source, const Media::V1::StreamSinkPrx& sink)
+        {
+            //
+            // For the moment we are assuming two streams that can definitely talk to each other.
+            //
+            return true;
+        }
+
+        bool canAdapt(const Media::V1::StreamSinkPrx& source, const Media::V1::StreamSourcePrx& sink)
+        {
+            //
+            // For the moment we are assuming two streams that can definitely talk to each other.
+            //
+            return true;
+        }
+
+        std::vector<OutgoingPairing> findCompatiblePairings(const Media::V1::StreamSinkSeq& sinks)
+        {
+            std::vector<Hydra::Media::V1::StreamSourceSeq> allSources;
+            for(MediaSessionMap::iterator i = mSessionMap.begin(); i != mSessionMap.end(); ++i)
+            {
+                allSources.push_back(i->second.mediaSession->getSources());
+            }
+
+            std::vector<OutgoingPairing> result;
+            for(Media::V1::StreamSinkSeq::const_iterator i = sinks.begin(); i != sinks.end(); ++i)
+            {
+                bool connected = false;
+                for(std::vector<Hydra::Media::V1::StreamSourceSeq>::iterator j = allSources.begin(); j != allSources.end() && !connected; ++j)
+                {
+                    for(Hydra::Media::V1::StreamSourceSeq::iterator k = j->begin(); k != j->end(); ++k)
+                    {
+                        if(canAdapt(*i, *k))
+                        {
+                            result.push_back(OutgoingPairing(*i, *k));
+                            connected = true;
+                            Media::V1::StreamSourceSeq::iterator t = k;
+                            j->erase(t);
+                            break;
+                        }
+                    }
+                }
+                if(!connected)
+                {
+                    //
+                    // TODO: We couldn't establish a proper connection for this sink. What happens
+                    // here is probably a policy thing.
+                    //
+                }
+            }
+            return result;
+        }
+
+        std::vector<IncomingPairing> findCompatiblePairings(const Media::V1::StreamSourceSeq& sources)
+        {
+            std::vector<Hydra::Media::V1::StreamSinkSeq> allSinks;
+            for(MediaSessionMap::iterator i = mSessionMap.begin(); i != mSessionMap.end(); ++i)
+            {
+                allSinks.push_back(i->second.mediaSession->getSinks());
+            }
+
+            std::vector<IncomingPairing> result;
+            for(Media::V1::StreamSourceSeq::const_iterator i = sources.begin(); i != sources.end(); ++i)
+            {
+                bool connected = false;
+                for(std::vector<Hydra::Media::V1::StreamSinkSeq>::iterator j = allSinks.begin(); j != allSinks.end() && !connected; ++j)
+                {
+                    for(Hydra::Media::V1::StreamSinkSeq::iterator k = j->begin(); k != j->end(); ++k)
+                    {
+                        if(canAdapt(*i, *k))
+                        {
+                            result.push_back(IncomingPairing(*i, *k));
+                            Hydra::Media::V1::StreamSinkSeq::iterator t = k;
+                            j->erase(t);
+                            connected = true;
+                            break;
+                        }
+                    }
+                }
+                if(!connected)
+                {
+                    //
+                    // TODO: We couldn't establish a proper connection for this source! What happens now
+                    // should be a matter of policy.
+                    //
+                }
+            }
+            return result;
+        }
+    };
+
+    typedef IceUtil::Handle<MediaSplicerI> MediaSplicerPtr;
+
+} // End of namespace BridgeService
+} // End of namespace Hydra
+
+Hydra::BridgeService::MediaSplicer::MediaSplicer() :
+    mImpl(new MediaSplicerI)
+{
+}
+
+Hydra::BridgeService::MediaConnectorPtr Hydra::BridgeService::MediaSplicer::connect(
+  const std::string& id,
+  const Hydra::Media::V1::SessionPrx& session)
+{
+    return mImpl->connect(id, session);
+}
diff --git a/src/MediaSplicer.h b/src/MediaSplicer.h
new file mode 100644
index 0000000..f93c8b1
--- /dev/null
+++ b/src/MediaSplicer.h
@@ -0,0 +1,32 @@
+#pragma once
+
+#include <IceUtil/Shared.h>
+#include <Media/MediaIf.h>
+#include <memory>
+
+namespace Hydra
+{
+namespace BridgeService
+{
+    class MediaConnector : public IceUtil::Shared
+    {
+    public:
+        virtual ~MediaConnector() {}
+        virtual void unplug() = 0;
+    };
+
+    typedef IceUtil::Handle<MediaConnector> MediaConnectorPtr;
+
+    class MediaSplicerI;
+
+    class MediaSplicer
+    {
+    public:
+        MediaSplicer();
+        MediaConnectorPtr connect(const std::string& id, const Media::V1::SessionPrx& mediaSession); 
+
+    private:
+        std::auto_ptr<MediaSplicerI> mImpl;
+    };
+} // End of namespace BridgeService
+} // End of namespace Hydra
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index d98e1e1..2fe4d83 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -8,6 +8,7 @@ hydra_component_add_slice(bridging_unit_test BridgeServiceEventsIf)
 hydra_component_add_file(bridging_unit_test TestBridging.cpp)
 hydra_component_add_file(bridging_unit_test "../src/BridgeImpl.cpp")
 hydra_component_add_file(bridging_unit_test "../src/BridgeFactoryImpl.cpp")
+hydra_component_add_file(bridging_unit_test "../src/MediaSplicer.cpp")
 hydra_component_add_boost_libraries(bridging_unit_test unit_test_framework)
 hydra_component_add_boost_libraries(bridging_unit_test thread)
 hydra_component_build_standalone(bridging_unit_test)
diff --git a/test/TestBridging.cpp b/test/TestBridging.cpp
index c4d0d2b..8f0cdad 100644
--- a/test/TestBridging.cpp
+++ b/test/TestBridging.cpp
@@ -8,6 +8,7 @@
 #include <boost/test/unit_test.hpp>
 #include <boost/test/debug.hpp>
 #include <Session/SessionIf.h>
+#include <Media/MediaIf.h>
 
 #include <Ice/Ice.h>
 
@@ -19,6 +20,123 @@ public:
    char **argv;
 };
 
+class SourceI : public Hydra::Media::V1::StreamSource
+{
+public:
+
+    SourceI(const std::string& id) :
+        mId(id)
+    {
+    }
+
+    void write(const Hydra::Media::V1::FrameSeq& frames, const Ice::Current&)
+    {
+    }
+
+    void setSource(const Hydra::Media::V1::StreamSourcePrx source, const Ice::Current&)
+    {
+        mSource = source;
+    }
+
+    Hydra::Media::V1::StreamSourcePrx getSource(const Ice::Current&)
+    {
+        return mSource;
+    }
+
+    Hydra::Media::V1::FormatSeq getFormats(const Ice::Current&)
+    {
+        return mFormats;
+    }
+
+    std::string getId(const Ice::Current&)
+    {
+        return mId;
+    }
+
+    void requestFormat(const Hydra::Media::V1::FormatPtr& format, const Ice::Current&)
+    {
+        // XXX
+    }
+
+private:
+    Hydra::Media::V1::StreamSourcePrx mSource;
+    Hydra::Media::V1::FormatSeq mFormats;
+
+    std::string mId;
+};
+
+class SinkI : public Hydra::Media::V1::StreamSink
+{
+public:
+
+    SinkI(const std::string& id) :
+        mId(id)
+    {
+    }
+
+    void setSink(const Hydra::Media::V1::StreamSinkPrx destination, const Ice::Current&)
+    {
+        mSink = destination;
+    }
+
+    Hydra::Media::V1::StreamSinkPrx getSink(const Ice::Current&)
+    {
+        return mSink;
+    }
+
+    Hydra::Media::V1::FormatSeq getFormats(const Ice::Current&)
+    {
+        return mFormats;
+    }
+
+    std::string getId(const Ice::Current&)
+    {
+        return mId;
+    }
+
+    void requestFormat(const Hydra::Media::V1::FormatPtr& format, const Ice::Current&)
+    {
+        // XXX
+    }
+
+private:
+    Hydra::Media::V1::StreamSinkPrx mSink;
+    Hydra::Media::V1::FormatSeq mFormats;
+
+    std::string mId;
+};
+
+class SessionI : public Hydra::Media::V1::Session
+{
+public:
+
+    SessionI(const std::string& id) :
+        mId(id)
+    {
+    }
+
+    Hydra::Media::V1::StreamSourceSeq getSources(const Ice::Current&)
+    {
+        return mSources;
+    }
+
+    Hydra::Media::V1::StreamSinkSeq getSinks(const Ice::Current&)
+    {
+        return mSinks;
+    }
+
+    std::string getId(const Ice::Current&)
+    {
+        return mId;
+    }
+
+private:
+    std::string mId;
+
+    Hydra::Media::V1::StreamSourceSeq mSources;
+    Hydra::Media::V1::StreamSinkSeq mSinks;
+};
+
 class BridgeEventSubscriberI : public Hydra::Core::Bridging::V1::BridgeEvents
 {
 public:
@@ -79,6 +197,14 @@ private:
     bool mStopped;
 };
 
+typedef IceUtil::Handle<SessionI> SessionIPtr;
+
+static Hydra::Media::V1::SessionPrx createTestSession(const Ice::ObjectAdapterPtr& p, const std::string& id)
+{
+    SessionIPtr session = new SessionI(id);
+    return Hydra::Media::V1::SessionPrx::uncheckedCast(p->addWithUUID(session));
+}
+
 typedef IceUtil::Handle<BridgeEventSubscriberI> BridgeEventSubscriberIPtr;
 
 class BridgeMonitorI : public Hydra::Core::Bridging::V1::BridgeMonitor
@@ -238,6 +364,7 @@ BOOST_AUTO_TEST_CASE(BridgeEndpointValidationAddValidTypeNullId)
         try
         {
             Hydra::Session::V1::SessionEndpointPtr p(new Hydra::Session::V1::SessionEndpoint);
+            p->mediaSession = createTestSession(adapter, "testsession");
             b->addEndpoint(p, dummy);
             BOOST_CHECK("Should not have succeeded" == 0);
         }
@@ -273,6 +400,7 @@ BOOST_AUTO_TEST_CASE(BridgeEndpointValidationAddValidTypeInvalidId)
             p->id = new Hydra::Core::Endpoint::V1::EndpointId;
             p->id->endpointManagerId = "";
             p->id->destinationId = "";
+            p->mediaSession = createTestSession(adapter, "testsession");
             b->addEndpoint(p, dummy);
             BOOST_CHECK("Should not have succeeded" == 0);
         }
@@ -309,6 +437,7 @@ BOOST_AUTO_TEST_CASE(BridgeEndpointAddValidTypeValidValue)
             p->id = new Hydra::Core::Endpoint::V1::EndpointId;
             p->id->endpointManagerId = "foo";
             p->id->destinationId = "bar";
+            p->mediaSession = createTestSession(adapter, "testsession");
             b->addEndpoint(p, dummy);
             BOOST_CHECK(true);
         }
@@ -344,6 +473,7 @@ BOOST_AUTO_TEST_CASE(BridgeEndpointListEp)
             p->id = new Hydra::Core::Endpoint::V1::EndpointId;
             p->id->endpointManagerId = "foo";
             p->id->destinationId = "bar";
+            p->mediaSession = createTestSession(adapter, "testsession");
             b->addEndpoint(p, dummy);
             Hydra::Core::Endpoint::V1::EndpointSeq endpoints = b->listEndpoints(dummy);
             BOOST_CHECK(endpoints.size() == 1);
@@ -418,6 +548,8 @@ BOOST_AUTO_TEST_CASE(BridgeFactoryCreateBridgeWithInvalidAdminEndpointId)
             p->id = new Hydra::Core::Endpoint::V1::EndpointId;
             p->id->endpointManagerId = "";
             p->id->destinationId = "";
+
+            Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
             Hydra::Core::Bridging::V1::BridgeMonitorPrx monitor;
             Hydra::Core::Bridging::V1::BridgePrx b = factory->createBridge(p, Hydra::Core::Endpoint::V1::EndpointSeq(), 0, dummy);
             BOOST_CHECK("Should not have succeeded" == 0);
@@ -452,6 +584,7 @@ BOOST_AUTO_TEST_CASE(BridgeFactoryCreateBridgeWithValidAdminEndpoint)
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         Hydra::Core::Bridging::V1::BridgePrx b =  factory->createBridge(p, Hydra::Core::Endpoint::V1::EndpointSeq(), 0, dummy);
         BOOST_CHECK(b);
         Hydra::Core::Endpoint::V1::EndpointSeq endpoints = b->listEndpoints();
@@ -615,6 +748,7 @@ BOOST_AUTO_TEST_CASE(BridgeFactoryCreateBridgeWithValidEndpoint)
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         Hydra::Core::Endpoint::V1::EndpointSeq eps;
         eps.push_back(p);
         Hydra::Core::Bridging::V1::BridgePrx b =  factory->createBridge(0, eps, 0, dummy);
@@ -648,12 +782,14 @@ BOOST_AUTO_TEST_CASE(BridgeFactoryCreateBridgeWithCollidingAdminAndInitialEndpoi
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         Hydra::Core::Endpoint::V1::EndpointSeq eps;
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession1");
         Hydra::Core::Bridging::V1::BridgePrx b =  factory->createBridge(p, eps, 0, dummy);
         BOOST_CHECK("Should not have succeeded." == 0);
     }
@@ -687,12 +823,14 @@ BOOST_AUTO_TEST_CASE(BridgeFactoryCreateBridgeWithCollisions)
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         Hydra::Core::Endpoint::V1::EndpointSeq eps;
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession1");
         eps.push_back(p);
         Hydra::Core::Bridging::V1::BridgePrx b =  factory->createBridge(0, eps, 0, dummy);
         BOOST_CHECK("Should not have succeeded." == 0);
@@ -727,22 +865,26 @@ BOOST_AUTO_TEST_CASE(BridgeFactoryCreateBridgeWithValidInitialSet)
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         Hydra::Core::Endpoint::V1::EndpointSeq eps;
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo1";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession1");
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar1";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession2");
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "fooa";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession3");
         Hydra::Core::Bridging::V1::BridgePrx b =  factory->createBridge(p, eps, 0, dummy);
         BOOST_CHECK(b);
         Hydra::Core::Endpoint::V1::EndpointSeq endpoints = b->listEndpoints();
@@ -791,28 +933,33 @@ BOOST_AUTO_TEST_CASE(BridgeAddEndpoint)
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         Hydra::Session::V1::SessionEndpointSeq eps;
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo1";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession1");
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar1";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession2");
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "fooa";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession3");
         Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(p, eps, 0, 0));
         eps.insert(eps.begin(), p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo2";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession4");
         bridge->addEndpoint(p, dummy);
         eps.push_back(p);
         Hydra::Core::Endpoint::V1::EndpointSeq endpoints = bridge->listEndpoints(dummy);
@@ -855,22 +1002,26 @@ BOOST_AUTO_TEST_CASE(BridgeAddEndpointAlreadyRegistered)
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         Hydra::Session::V1::SessionEndpointSeq eps;
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo1";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession1");
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar1";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession2");
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "fooa";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession3");
         Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(p, eps, 0, 0));
         eps.insert(eps.begin(), p);
         p = new Hydra::Session::V1::SessionEndpoint;
@@ -961,6 +1112,7 @@ BOOST_AUTO_TEST_CASE(BridgeAddInvalidId1)
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "";
         p->id->destinationId = "";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         bridge->addEndpoint(p, dummy);
         BOOST_CHECK("Should not have succeeded." == 0);
     }
@@ -991,6 +1143,7 @@ BOOST_AUTO_TEST_CASE(BridgeAddInvalidId2)
         Hydra::Session::V1::SessionEndpointSeq eps;
         Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(0, eps, 0, 0));
         Hydra::Core::Endpoint::V1::BaseEndpointPtr p(new Hydra::Session::V1::SessionEndpoint);
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         bridge->addEndpoint(p, dummy);
         BOOST_CHECK("Should not have succeeded." == 0);
     }
@@ -1022,22 +1175,26 @@ BOOST_AUTO_TEST_CASE(BridgeRemoveEndpoint)
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         Hydra::Session::V1::SessionEndpointSeq eps;
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo1";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession1");
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar1";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession2");
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "fooa";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession3");
         Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(p, eps, 0, 0));
         eps.insert(eps.begin(), p);
         Hydra::Core::Endpoint::V1::EndpointIdPtr id(new Hydra::Core::Endpoint::V1::EndpointId);
@@ -1083,22 +1240,26 @@ BOOST_AUTO_TEST_CASE(BridgeRemoveEndpointUnknownEndpoint)
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         Hydra::Session::V1::SessionEndpointSeq eps;
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo1";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession1");
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar1";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession2");
         eps.push_back(p);
         p = new Hydra::Session::V1::SessionEndpoint;
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "fooa";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession3");
         Hydra::BridgeService::BridgeImplPtr bridge(new Hydra::BridgeService::BridgeImpl(p, eps, 0, 0 ));
         Hydra::Core::Endpoint::V1::EndpointIdPtr id(new Hydra::Core::Endpoint::V1::EndpointId);
         id->endpointManagerId = "foo1";
@@ -1218,6 +1379,7 @@ BOOST_AUTO_TEST_CASE(BridgeOperationsAfterShutdown)
             p->id = new Hydra::Core::Endpoint::V1::EndpointId;
             p->id->endpointManagerId = "foo";
             p->id->destinationId = "bar";
+            Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
             bridge->addEndpoint(p, dummy);
             BOOST_CHECK("should not have succeeded." == 0);
         }
@@ -1322,6 +1484,7 @@ BOOST_AUTO_TEST_CASE(BridgeOperationsAfterDestroy)
             p->id = new Hydra::Core::Endpoint::V1::EndpointId;
             p->id->endpointManagerId = "foo";
             p->id->destinationId = "bar";
+            Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
             bridge->addEndpoint(p, dummy);
             BOOST_CHECK("should not have succeeded." == 0);
         }
@@ -1504,6 +1667,7 @@ BOOST_AUTO_TEST_CASE(BridgeEvents)
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         bridge->addEndpoint(p);
         BOOST_CHECK(subServant->getLastAdded() != 0 && subServant->getLastAdded()->id->endpointManagerId == "foo");
         bridge->removeEndpoint(p->id);
@@ -1543,6 +1707,7 @@ BOOST_AUTO_TEST_CASE(BridgeMonitor)
         p->id = new Hydra::Core::Endpoint::V1::EndpointId;
         p->id->endpointManagerId = "foo";
         p->id->destinationId = "bar";
+        Hydra::Session::V1::SessionEndpointPtr::dynamicCast(p)->mediaSession = createTestSession(adapter, "testsession");
         bridge->addEndpoint(p);
         bridge->removeEndpoint(p->id);
         bridge->shutdown();
@@ -1556,3 +1721,4 @@ BOOST_AUTO_TEST_CASE(BridgeMonitor)
     }
     adapter->destroy();
 }
+

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


-- 
asterisk-scf/integration/bridging.git



More information about the asterisk-scf-commits mailing list