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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Sun Sep 4 11:41:14 CDT 2011


branch "master" has been updated
       via  7af97676c33ca5f32dbcf924bd02c2b31c230d4a (commit)
      from  7ae703dcaf863f700b577ec6796e3ef81bbb0ebf (commit)

Summary of changes:
 src/BridgeImpl.cpp        |   48 ++++++++++++++++++++++++++++++
 src/MediaSplicer.cpp      |   71 +++++++++++++++++++++++++++++++++++++++++++-
 src/SessionOperations.cpp |   10 ++++++
 src/SessionOperations.h   |   16 ++++++++++
 4 files changed, 143 insertions(+), 2 deletions(-)


- Log -----------------------------------------------------------------
commit 7af97676c33ca5f32dbcf924bd02c2b31c230d4a
Author: Joshua Colp <jcolp at digium.com>
Date:   Sun Sep 4 13:45:54 2011 -0300

    Add support for establishing direct media connections.

diff --git a/src/BridgeImpl.cpp b/src/BridgeImpl.cpp
index a7b2feb..42d4b18 100755
--- a/src/BridgeImpl.cpp
+++ b/src/BridgeImpl.cpp
@@ -514,6 +514,48 @@ private:
     Logger mLogger;
 };
 
+class UnplugMedia : public QueuedTask
+{
+public:
+    UnplugMedia(const BridgeImplPtr& bridge) :
+        QueuedTask("UnplugMedia"),
+        mBridge(bridge)
+        {
+        }
+
+protected:
+    bool executeImpl()
+    {
+        UnplugMediaOperation op;
+        mBridge->getSessions()->visitSessions(op);
+        return true;
+    }
+
+private:
+    BridgeImplPtr mBridge;
+};
+
+class SetupMedia : public QueuedTask
+{
+public:
+    SetupMedia(const BridgeImplPtr& bridge) :
+        QueuedTask("SetupMedia"),
+        mBridge(bridge)
+        {
+        }
+
+protected:
+    bool executeImpl()
+    {
+        SetupMediaOperation op;
+        mBridge->getSessions()->visitSessions(op);
+        return true;
+    }
+
+private:
+    BridgeImplPtr mBridge;
+};
+
 class AddToListeners : public QueuedTask
 {
 public:
@@ -694,10 +736,12 @@ void BridgeImpl::addSessions_async(const AMD_Bridge_addSessionsPtr& callback, co
 
         SessionsTrackerPtr tracker(new SessionsTracker);
         QueuedTasks tasks;
+        tasks.push_back(new UnplugMedia(this));
         tasks.push_back(new SetBridgeTask(mSessions, mPrx, mSessionListenerPrx, sessions, tracker));
         tasks.push_back(new AddToListeners(mListeners, tracker, getCookies()));
 	tasks.push_back(new SetAndGetSessionControllerTask(mObjAdapter, mSessions, sessions, this, mLogger));
         tasks.push_back(new GenericAMDCallback<AMD_Bridge_addSessionsPtr>(callback, tracker));
+        tasks.push_back(new SetupMedia(this));
         tasks.push_back(new UpdateTask(this));
         ExecutorPtr executor(new Executor(tasks, mLogger));
         executor->start();
@@ -959,10 +1003,12 @@ void BridgeImpl::replaceSession_async(const AMD_Bridge_replaceSessionPtr& callba
             cookies = getCookies();
         }
         tasks.push_back(new RemoveSessionsNotify(mListeners, removeTracker, cookies));
+        tasks.push_back(new UnplugMedia(this));
         tasks.push_back(new SetBridgeTask(mSessions, mPrx, mSessionListenerPrx, newSessions, tracker));
         tasks.push_back(new AddToListeners(mListeners, tracker, cookies));
 	tasks.push_back(new SetAndGetSessionControllerTask(mObjAdapter, mSessions, newSessions, this, mLogger));
         tasks.push_back(new GenericAMDCallback<AMD_Bridge_replaceSessionPtr>(callback, tracker));
+        tasks.push_back(new SetupMedia(this));
         tasks.push_back(new UpdateTask(this));
         ExecutorPtr executor(new Executor(tasks, mLogger));
         executor->start();
@@ -1170,9 +1216,11 @@ void BridgeImpl::getAddSessionsTasks(QueuedTasks& tasks,
         const AsteriskSCF::SessionCommunications::V1::SessionSeq& sessions)
 {
     SessionsTrackerPtr tracker(new SessionsTracker);
+    tasks.push_back(new UnplugMedia(this));
     tasks.push_back(new SetBridgeTask(mSessions, mPrx, mSessionListenerPrx, sessions, tracker));
     tasks.push_back(new AddToListeners(mListeners, tracker, getCookies()));
     tasks.push_back(new SetAndGetSessionControllerTask(mObjAdapter, mSessions, sessions, this, mLogger));
+    tasks.push_back(new SetupMedia(this));
     tasks.push_back(new UpdateTask(this));
 }
 
diff --git a/src/MediaSplicer.cpp b/src/MediaSplicer.cpp
index a6a0a1e..2cde267 100755
--- a/src/MediaSplicer.cpp
+++ b/src/MediaSplicer.cpp
@@ -74,6 +74,7 @@ struct MediaConnectorBuilder : public IceUtil::Shared
     OutgoingPairings outgoingPairings;
     IncomingPairings incomingPairings;
     std::map<std::string, std::string> connections;
+    DirectMediaConnectionDict directConnections;
 };
 typedef IceUtil::Handle<MediaConnectorBuilder> MediaConnectorBuilderPtr;
 
@@ -495,7 +496,8 @@ public:
     void findCompatiblePairings(const StreamInformationDict& streams, vector<OutgoingPairing>& outgoing,
                                 vector<IncomingPairing>& incoming,
                                 MediaConnectorIPtr connector,
-                                std::map<std::string, std::string>& connections)
+                                std::map<std::string, std::string>& connections,
+                                DirectMediaConnectionDict& directConnections)
     {
         // If no streams are present we can not establish any pairings
         if (streams.empty())
@@ -549,6 +551,9 @@ public:
 		    StreamSinkSeq sinks = stream->second->sinks;
 		    StreamSourceSeq sources = stream->second->sources;
 
+                    // Attempt to establish a direct connection later
+                    directConnections.insert(make_pair(stream->first, theirStream->second->sinks.front()));
+
 		    while (!sinks.empty() && !theirStream->second->sources.empty())
 		    {
                         outgoing.push_back(OutgoingPairing(sinks.back(), theirStream->second->sources.back()));
@@ -682,7 +687,7 @@ protected:
     bool executeImpl()
     {
 	mSplicer->findCompatiblePairings(mMaterials->streams, mMaterials->outgoingPairings, mMaterials->incomingPairings,
-                                         mMaterials->connector, mMaterials->connections);
+                                         mMaterials->connector, mMaterials->connections, mMaterials->directConnections);
         return true;
     }
 
@@ -919,6 +924,67 @@ private:
     MediaConnectorBuilderPtr mMaterials;
 };
 
+class MakeDirectConnections : public QueuedTask
+{
+public:
+    MakeDirectConnections(const MediaConnectorBuilderPtr& materials) :
+        QueuedTask("MakeDirectConnections"),
+        mMaterials(materials)
+        {
+        }
+
+protected:
+    bool executeImpl()
+    {
+        mDirectConnection = DirectMediaConnectionPrx::checkedCast(mMaterials->sessionPrx, directMediaConnectionFacet);
+
+        if (!mDirectConnection)
+        {
+            return true;
+        }
+
+        mDirectConnection->begin_checkDirectConnections(mMaterials->directConnections, newCallback_DirectMediaConnection_checkDirectConnections(
+                                                            this, &MakeDirectConnections::accepted, &MakeDirectConnections::failed));
+
+        return false;
+    }
+
+    void accepted(const Ice::StringSeq& streams)
+    {
+        if (streams.empty())
+        {
+            mListener->succeeded();
+            return;
+        }
+
+        DirectMediaConnectionDict directConnections;
+
+        for (Ice::StringSeq::const_iterator stream = streams.begin();
+             stream != streams.end();
+             ++stream)
+        {
+            directConnections.insert(make_pair(*stream, mMaterials->directConnections.find(*stream)->second));
+        }
+
+        mDirectConnection->begin_connectStreams(directConnections, newCallback_DirectMediaConnection_connectStreams(this,
+                                                                                                                    &MakeDirectConnections::done,
+                                                                                                                    &MakeDirectConnections::failed));
+    }
+
+    void done()
+    {
+        mListener->succeeded();
+    }
+
+    void failed(const Ice::Exception&)
+    {
+        mListener->failed();
+    }
+private:
+    MediaConnectorBuilderPtr mMaterials;
+    DirectMediaConnectionPrx mDirectConnection;
+};
+
 QueuedTasks createMediaConnectTasks(const SessionWrapperPtr& session, 
     const AsteriskSCF::SessionCommunications::V1::SessionPrx& sessionPrx, 
     const MediaConnectorIPtr& peer, const MediaSplicerIPtr& splicer)
@@ -931,6 +997,7 @@ QueuedTasks createMediaConnectTasks(const SessionWrapperPtr& session,
     tasks.push_back(new CreateAndRegisterConnector(session, splicer, materials));
     tasks.push_back(new GetCompatiblePairings(splicer, materials));
     tasks.push_back(new MakeConnections(materials));
+    tasks.push_back(new MakeDirectConnections(materials));
     return tasks;
 }
 
diff --git a/src/SessionOperations.cpp b/src/SessionOperations.cpp
index f7f8508..e6bf5f8 100644
--- a/src/SessionOperations.cpp
+++ b/src/SessionOperations.cpp
@@ -23,6 +23,16 @@ using namespace AsteriskSCF::Replication::BridgeService::V1;
 using namespace AsteriskSCF;
 using namespace std;
 
+void UnplugMediaOperation::operator()(const SessionWrapperPtr& s)
+{
+    s->unplugMedia();
+}
+
+void SetupMediaOperation::operator()(const SessionWrapperPtr& s)
+{
+    s->setupMedia();
+}
+
 ConnectSessionOperation::ConnectSessionOperation(const SessionPrx& exclude, const Logger& logger) :
     mExclude(exclude->ice_getIdentity()),
     mLogger(logger)
diff --git a/src/SessionOperations.h b/src/SessionOperations.h
index ce73388..a4e2c29 100644
--- a/src/SessionOperations.h
+++ b/src/SessionOperations.h
@@ -27,6 +27,22 @@ namespace AsteriskSCF
 namespace BridgeService
 {
 
+class UnplugMediaOperation : public std::unary_function<SessionWrapperPtr, void>
+{
+public:
+    void operator()(const SessionWrapperPtr& wrapper);
+
+private:
+};
+
+class SetupMediaOperation : public std::unary_function<SessionWrapperPtr, void>
+{
+public:
+    void operator()(const SessionWrapperPtr& wrapper);
+
+private:
+};
+
 class ConnectSessionOperation : public std::unary_function<SessionWrapperPtr, void>
 {
 public:

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


-- 
asterisk-scf/release/bridging.git



More information about the asterisk-scf-commits mailing list