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

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Fri Aug 19 11:48:55 CDT 2011


branch "master" has been updated
       via  6a344b3b59137bd15ec4bd60dcfb631a6f8e020b (commit)
       via  181a81f9dbbcaeeb83b0f11d474db22ee3893287 (commit)
       via  f148c511a92b2b5626a60cde02d5928449b209a3 (commit)
      from  df280d228311779edaa3fb6ec64d05d754539f93 (commit)

Summary of changes:
 src/CMakeLists.txt                            |    6 +
 src/MediaOperationStateReplicatorListener.cpp |   16 +--
 src/Translator.cpp                            |   52 ++++++
 src/Translator.h                              |   66 +++++++
 src/TranslatorSink.cpp                        |   71 ++++++++
 test/TestStreamSink.h => src/TranslatorSink.h |   52 +++---
 src/TranslatorSource.cpp                      |  101 +++++++++++
 src/TranslatorSource.h                        |   60 +++++++
 src/ulaw_alaw.cpp                             |  227 +++++++------------------
 test/TestMediaOperations.cpp                  |    7 +
 10 files changed, 450 insertions(+), 208 deletions(-)
 create mode 100644 src/Translator.cpp
 create mode 100644 src/Translator.h
 create mode 100644 src/TranslatorSink.cpp
 copy test/TestStreamSink.h => src/TranslatorSink.h (52%)
 create mode 100644 src/TranslatorSource.cpp
 create mode 100644 src/TranslatorSource.h


- Log -----------------------------------------------------------------
commit 6a344b3b59137bd15ec4bd60dcfb631a6f8e020b
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Aug 19 11:46:52 2011 -0500

    Add some generic translator stuff to make it easier to add new ones later.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index acdcd12..fafe1f2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -6,6 +6,12 @@ astscf_component_add_files(MediaOperationsCore ulaw_alaw.h)
 astscf_component_add_files(MediaOperationsCore ulaw_alaw.cpp)
 astscf_component_add_files(MediaOperationsCore MediaOperationFactoryImpl.h)
 astscf_component_add_files(MediaOperationsCore MediaOperationFactoryImpl.cpp)
+astscf_component_add_files(MediaOperationsCore Translator.cpp)
+astscf_component_add_files(MediaOperationsCore Translator.h)
+astscf_component_add_files(MediaOperationsCore TranslatorSink.cpp)
+astscf_component_add_files(MediaOperationsCore TranslatorSink.h)
+astscf_component_add_files(MediaOperationsCore TranslatorSource.cpp)
+astscf_component_add_files(MediaOperationsCore TranslatorSource.h)
 astscf_component_add_files(MediaOperationsCore MediaOperationsCore.cpp)
 astscf_component_add_files(MediaOperationsCore MediaOperationStateReplicatorListener.cpp)
 astscf_component_add_files(MediaOperationsCore MediaOperationReplicationContext.h)
diff --git a/src/Translator.cpp b/src/Translator.cpp
new file mode 100644
index 0000000..3e12631
--- /dev/null
+++ b/src/Translator.cpp
@@ -0,0 +1,52 @@
+/*
+ * 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 "Translator.h"
+
+namespace AsteriskSCF
+{
+
+namespace MediaOperationsCore
+{
+
+using namespace AsteriskSCF::Media::V1;
+using namespace AsteriskSCF::System::Logging;
+
+Translator::Translator(const TranslatorSourcePtr& source,
+        const FormatPtr& inputFormat,
+        const FormatPtr& outputFormat,
+        const Logger& logger)
+    : mSource(source),
+    mInputFormat(inputFormat),
+    mOutputFormat(outputFormat),
+    mLogger(logger)
+{
+}
+
+Translator::~Translator()
+{
+}
+
+void Translator::translateFrames(const FrameSeq& frames)
+{
+    FrameSeq translated;
+    translated.resize(frames.size());
+    std::transform(frames.begin(), frames.end(), translated.begin(), std::bind1st(std::mem_fun(&Translator::translate), this));
+    mSource->distributeToSinks(translated);
+}
+
+}
+}
diff --git a/src/Translator.h b/src/Translator.h
new file mode 100644
index 0000000..2884875
--- /dev/null
+++ b/src/Translator.h
@@ -0,0 +1,66 @@
+/*
+ * 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 <AsteriskSCF/Media/MediaIf.h>
+#include <AsteriskSCF/logger.h>
+
+#include "TranslatorSource.h"
+
+namespace AsteriskSCF
+{
+
+namespace MediaOperationsCore
+{
+
+class Translator : public IceUtil::Shared
+{
+public:
+    Translator(const TranslatorSourcePtr& source,
+            const AsteriskSCF::Media::V1::FormatPtr& inputFormat,
+            const AsteriskSCF::Media::V1::FormatPtr& outputFormat,
+            const AsteriskSCF::System::Logging::Logger& logger);
+    
+    virtual ~Translator();
+
+    /**
+     * Translate each frame from the input format into the
+     * output format.
+     *
+     * Note that implementors of this function should perform
+     * a check to be certain that the format of the frame
+     * being translated is what is expected for this translator
+     */
+    virtual AsteriskSCF::Media::V1::FramePtr translate(const AsteriskSCF::Media::V1::FramePtr inFrame) = 0;
+
+    /**
+     * Feeds each of the frames in the
+     * sequence into the translate() function
+     */
+    void translateFrames(const AsteriskSCF::Media::V1::FrameSeq& frames);
+
+protected:
+    TranslatorSourcePtr mSource;
+    AsteriskSCF::Media::V1::FormatPtr mInputFormat;
+    AsteriskSCF::Media::V1::FormatPtr mOutputFormat;
+    AsteriskSCF::System::Logging::Logger mLogger;
+};
+
+typedef IceUtil::Handle<Translator> TranslatorPtr;
+
+}
+}
diff --git a/src/TranslatorSink.cpp b/src/TranslatorSink.cpp
new file mode 100644
index 0000000..25bf231
--- /dev/null
+++ b/src/TranslatorSink.cpp
@@ -0,0 +1,71 @@
+/*
+ * 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 "TranslatorSink.h"
+
+namespace AsteriskSCF
+{
+
+namespace MediaOperationsCore
+{
+
+using namespace AsteriskSCF::Media::V1;
+using namespace AsteriskSCF::System::Logging;
+
+TranslatorSink::TranslatorSink(const Logger& logger,
+        const FormatPtr& supportedFormat,
+        const TranslatorPtr& translator)
+    : mLogger(logger),
+    mId(IceUtil::generateUUID()),
+    mTranslator(translator)
+{
+    mSupportedFormats.push_back(supportedFormat);
+}
+
+TranslatorSink::~TranslatorSink()
+{
+    mLogger(Debug) << "TranslatorSink destructor called";
+}
+
+void TranslatorSink::write(const FrameSeq& frames, const Ice::Current&)
+{
+    mTranslator->translateFrames(frames);
+}
+
+void TranslatorSink::setSource(const StreamSourcePrx& source, const Ice::Current&)
+{
+    mSource = source;
+}
+
+StreamSourcePrx TranslatorSink::getSource(const Ice::Current&)
+{
+    return mSource;
+}
+
+FormatSeq TranslatorSink::getFormats(const Ice::Current&)
+{
+    return mSupportedFormats;
+}
+
+std::string TranslatorSink::getId(const Ice::Current&)
+{
+    return mId;
+}
+
+}
+}
diff --git a/src/TranslatorSink.h b/src/TranslatorSink.h
new file mode 100644
index 0000000..fa5bee5
--- /dev/null
+++ b/src/TranslatorSink.h
@@ -0,0 +1,60 @@
+/*
+ * 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 <AsteriskSCF/Media/MediaIf.h>
+#include <AsteriskSCF/logger.h>
+
+#include "Translator.h"
+
+namespace AsteriskSCF
+{
+
+namespace MediaOperationsCore
+{
+
+class TranslatorSink : public AsteriskSCF::Media::V1::StreamSink
+{
+public:
+    TranslatorSink(const AsteriskSCF::System::Logging::Logger& logger,
+            const AsteriskSCF::Media::V1::FormatPtr& supportedFormat,
+            const TranslatorPtr& translator);
+
+    ~TranslatorSink();
+    
+    void write(const AsteriskSCF::Media::V1::FrameSeq& frames, const Ice::Current&);
+
+    void setSource(const AsteriskSCF::Media::V1::StreamSourcePrx& source, const Ice::Current&);
+
+    AsteriskSCF::Media::V1::StreamSourcePrx getSource(const Ice::Current&);
+
+    AsteriskSCF::Media::V1::FormatSeq getFormats(const Ice::Current&);
+
+    std::string getId(const Ice::Current&);
+
+private:
+    AsteriskSCF::System::Logging::Logger mLogger;
+    AsteriskSCF::Media::V1::FormatSeq mSupportedFormats;
+    AsteriskSCF::Media::V1::StreamSourcePrx mSource;
+    std::string mId;
+    TranslatorPtr mTranslator;
+};
+
+typedef IceUtil::Handle<TranslatorSink> TranslatorSinkPtr;
+
+}
+}
diff --git a/src/TranslatorSource.cpp b/src/TranslatorSource.cpp
new file mode 100644
index 0000000..b24cc68
--- /dev/null
+++ b/src/TranslatorSource.cpp
@@ -0,0 +1,101 @@
+/*
+ * 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 "TranslatorSource.h"
+
+namespace AsteriskSCF
+{
+
+namespace MediaOperationsCore
+{
+
+using namespace AsteriskSCF::Media::V1;
+using namespace AsteriskSCF::System::Logging;
+
+TranslatorSource::TranslatorSource(const Logger& logger,
+            const FormatPtr& format)
+        : mLogger(logger),
+        mId(IceUtil::generateUUID())
+{
+    mSupportedFormats.push_back(format);
+}
+
+TranslatorSource::~TranslatorSource()
+{
+    mLogger(Debug) << "TranslatorSource destructor called";
+}
+
+void TranslatorSource::addSink(const StreamSinkPrx& sink, const Ice::Current&)
+{
+    if (std::find(mSinks.begin(), mSinks.end(), sink) == mSinks.end())
+    {
+        mSinks.push_back(sink);
+    }
+}
+
+void TranslatorSource::removeSink(const StreamSinkPrx& sink, const Ice::Current&)
+{
+    mSinks.erase(std::remove(mSinks.begin(), mSinks.end(), sink), mSinks.end());
+}
+
+StreamSinkSeq TranslatorSource::getSinks(const Ice::Current&)
+{
+    return mSinks;
+}
+
+FormatSeq TranslatorSource::getFormats(const Ice::Current&)
+{
+    return mSupportedFormats;
+}
+
+std::string TranslatorSource::getId(const Ice::Current&)
+{
+    return mId;
+}
+
+//XXX
+//I interpreted this to essentially be a check to make sure that
+//the format we actually are using matches what is expected.
+void TranslatorSource::requestFormat(const FormatPtr& format, const Ice::Current&)
+{
+    FormatPtr supportedFormat = mSupportedFormats.front();
+
+    if (supportedFormat->name != format->name)
+    {
+        mLogger(Error) << "Format requested is not the one supported by this source";
+        throw MediaFormatSwitchException();
+    }
+}
+
+void TranslatorSource::distributeToSinks(const FrameSeq& translatedFrames)
+{
+    for (StreamSinkSeq::iterator iter = mSinks.begin();
+            iter != mSinks.end(); ++iter)
+    {
+        try
+        {
+            (*iter)->write(translatedFrames);
+        }
+        catch (Ice::Exception& ex)
+        {
+            mLogger(Error) << "Error attempting to write frames to a sink: " << ex.what();
+        }
+    }
+}
+
+}
+}
diff --git a/src/TranslatorSource.h b/src/TranslatorSource.h
new file mode 100644
index 0000000..f17515a
--- /dev/null
+++ b/src/TranslatorSource.h
@@ -0,0 +1,60 @@
+/*
+ * 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 <AsteriskSCF/Media/MediaIf.h>
+#include <AsteriskSCF/logger.h>
+
+namespace AsteriskSCF
+{
+
+namespace MediaOperationsCore
+{
+
+class TranslatorSource : public AsteriskSCF::Media::V1::StreamSource
+{
+public:
+    TranslatorSource(const AsteriskSCF::System::Logging::Logger& logger,
+            const AsteriskSCF::Media::V1::FormatPtr& format);
+
+    ~TranslatorSource();
+
+    void addSink(const AsteriskSCF::Media::V1::StreamSinkPrx& sink, const Ice::Current&);
+    
+    void removeSink(const AsteriskSCF::Media::V1::StreamSinkPrx& sink, const Ice::Current&);
+    
+    AsteriskSCF::Media::V1::StreamSinkSeq getSinks(const Ice::Current&);
+
+    AsteriskSCF::Media::V1::FormatSeq getFormats(const Ice::Current&);
+
+    std::string getId(const Ice::Current&);
+
+    void requestFormat(const AsteriskSCF::Media::V1::FormatPtr& format, const Ice::Current&);
+
+    void distributeToSinks(const AsteriskSCF::Media::V1::FrameSeq& translatedFrames);
+
+private:
+    AsteriskSCF::System::Logging::Logger mLogger;
+    AsteriskSCF::Media::V1::StreamSinkSeq mSinks;
+    AsteriskSCF::Media::V1::FormatSeq mSupportedFormats;
+    std::string mId;
+};
+
+typedef IceUtil::Handle<TranslatorSource> TranslatorSourcePtr;
+
+}
+}
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 708fee1..b27bf7a 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -14,13 +14,16 @@
  * at the top of the source tree.
  */
 
-#include "ulaw_alaw.h"
-
 #include <AsteriskSCF/Media/Formats/AudioFormats.h>
 #include <AsteriskSCF/Replication/MediaOperationsCore/MediaOperationsCoreIf.h>
 #include <IceUtil/UUID.h>
 #include <pjmedia.h>
 
+#include "ulaw_alaw.h"
+#include "TranslatorSource.h"
+#include "Translator.h"
+#include "TranslatorSink.h"
+
 namespace AsteriskSCF
 {
 
@@ -33,107 +36,17 @@ using namespace AsteriskSCF::Media::Formats::Audio::V1;
 using namespace AsteriskSCF::System::Logging;
 using namespace AsteriskSCF::Replication::MediaOperationsCore::V1;
 
-class UlawAlawOperation;
-typedef IceUtil::Handle<UlawAlawOperation> UlawAlawOperationPtr;
-
 class UlawAlawOperation : public MediaOperation
 {
 private:
-
-    class UlawAlawSource : public StreamSource
+    class UlawAlawTranslator : public Translator
     {
     public:
-    
-        UlawAlawSource(const Logger& logger,
-                const FormatPtr& format)
-            : mLogger(logger),
-            mId(IceUtil::generateUUID())
-        {
-            mSupportedFormats.push_back(format);
-        }
-
-        ~UlawAlawSource()
-        {
-            mLogger(Debug) << "UlawAlawSource destructor called";
-        }
-    
-        void addSink(const StreamSinkPrx& sink, const Ice::Current&)
-        {
-            if (std::find(mSinks.begin(), mSinks.end(), sink) == mSinks.end())
-            {
-                mSinks.push_back(sink);
-            }
-        }
-    
-        void removeSink(const StreamSinkPrx& sink, const Ice::Current&)
-        {
-            mSinks.erase(std::remove(mSinks.begin(), mSinks.end(), sink), mSinks.end());
-        }
-    
-        StreamSinkSeq getSinks(const Ice::Current&)
-        {
-            return mSinks;
-        }
-    
-        FormatSeq getFormats(const Ice::Current&)
-        {
-            return mSupportedFormats;
-        }
-    
-        std::string getId(const Ice::Current&)
-        {
-            return mId;
-        }
-    
-        //XXX
-        //I interpreted this to essentially be a check to make sure that
-        //the format we actually are using matches what is expected.
-        void requestFormat(const FormatPtr& format, const Ice::Current&)
-        {
-            FormatPtr supportedFormat = mSupportedFormats.front();
-    
-            if (supportedFormat->name != format->name)
-            {
-                mLogger(Error) << "Format requested is not the one supported by this source";
-                throw MediaFormatSwitchException();
-            }
-        }
-    
-        void distributeToSinks(const FrameSeq& translatedFrames)
-        {
-            for (StreamSinkSeq::iterator iter = mSinks.begin();
-                    iter != mSinks.end(); ++iter)
-            {
-                try
-                {
-                    (*iter)->write(translatedFrames);
-                }
-                catch (Ice::Exception& ex)
-                {
-                    mLogger(Error) << "Error attempting to write frames to a sink: " << ex.what();
-                }
-            }
-        }
-    
-        Logger mLogger;
-        StreamSinkSeq mSinks;
-        FormatSeq mSupportedFormats;
-        std::string mId;
-    };
-    
-    typedef IceUtil::Handle<UlawAlawSource> UlawAlawSourcePtr;
-
-    class UlawAlawTranslator : public IceUtil::Shared
-    {
-    public:
-        UlawAlawTranslator(const UlawAlawSourcePtr source,
+        UlawAlawTranslator(const TranslatorSourcePtr source,
                 const FormatPtr& inputFormat,
                 const FormatPtr& outputFormat,
                 const Logger& logger)
-            : mSource(source),
-            mInputFormat(inputFormat),
-            mOutputFormat(outputFormat),
-            mLogger(logger)
+            : Translator(source, inputFormat, outputFormat, logger)
         {
         }
  
@@ -147,6 +60,9 @@ private:
             return pjmedia_alaw2ulaw(alaw);
         }
         
+        /**
+         * Override of Translator's translate function.
+         */
         FramePtr translate(const FramePtr inFrame)
         {
             if (inFrame->mediaFormat->name != mInputFormat->name)
@@ -171,76 +87,8 @@ private:
             outFrame = new Frame(mOutputFormat, outPayload);
             return outFrame;
         }
-
-        void translateFrames(const FrameSeq& frames)
-        {
-            FrameSeq translated;
-            translated.resize(frames.size());
-            std::transform(frames.begin(), frames.end(), translated.begin(), std::bind1st(std::mem_fun(&UlawAlawTranslator::translate), this));
-            mSource->distributeToSinks(translated);
-        }
-
-    private:
-        UlawAlawSourcePtr mSource;
-        FormatPtr mInputFormat;
-        FormatPtr mOutputFormat;
-        Logger mLogger;
     };
 
-    typedef IceUtil::Handle<UlawAlawTranslator> UlawAlawTranslatorPtr;
-
-    class UlawAlawSink : public StreamSink
-    {
-    public:
-        UlawAlawSink(const Logger& logger,
-                const FormatPtr& supportedFormat,
-                const UlawAlawTranslatorPtr& translator)
-            : mLogger(logger),
-            mId(IceUtil::generateUUID()),
-            mTranslator(translator)
-        {
-            mSupportedFormats.push_back(supportedFormat);
-        }
-    
-        ~UlawAlawSink()
-        {
-            mLogger(Debug) << "UlawAlawSink destructor called";
-        }
-        
-        void write(const FrameSeq& frames, const Ice::Current&)
-        {
-            mTranslator->translateFrames(frames);
-        }
-    
-        void setSource(const StreamSourcePrx& source, const Ice::Current&)
-        {
-            mSource = source;
-        }
-    
-        StreamSourcePrx getSource(const Ice::Current&)
-        {
-            return mSource;
-        }
-    
-        FormatSeq getFormats(const Ice::Current&)
-        {
-            return mSupportedFormats;
-        }
-    
-        std::string getId(const Ice::Current&)
-        {
-            return mId;
-        }
-    
-        Logger mLogger;
-        FormatSeq mSupportedFormats;
-        StreamSourcePrx mSource;
-        std::string mId;
-        UlawAlawTranslatorPtr mTranslator;
-    };
-
-    typedef IceUtil::Handle<UlawAlawSink> UlawAlawSinkPtr;
-
 public:
     UlawAlawOperation(const Ice::ObjectAdapterPtr& adapter,
             const Logger& logger,
@@ -251,8 +99,8 @@ public:
         : mAdapter(adapter),
         mLogger(logger),
         mStateItem(new UlawAlawMediaOperationStateItem),
-        mSource(new UlawAlawSource(mLogger, sourceFormat)),
-        mSink(new UlawAlawSink(mLogger, sinkFormat, new UlawAlawTranslator(mSource, sinkFormat, sourceFormat, mLogger))),
+        mSource(new TranslatorSource(mLogger, sourceFormat)),
+        mSink(new TranslatorSink(mLogger, sinkFormat, new UlawAlawTranslator(mSource, sinkFormat, sourceFormat, mLogger))),
         mReplicationContext(replicationContext)
     {
         mStateItem->sourceFormat = sourceFormat;
@@ -356,13 +204,15 @@ private:
     Logger mLogger;
     MediaOperationPrx mProxy;
     UlawAlawMediaOperationStateItemPtr mStateItem;
-    UlawAlawSourcePtr mSource;
+    TranslatorSourcePtr mSource;
     StreamSourcePrx mSourceProxy;
-    UlawAlawSinkPtr mSink;
+    TranslatorSinkPtr mSink;
     StreamSinkPrx mSinkProxy;
     MediaOperationReplicationContextPtr mReplicationContext;
 };
 
+typedef IceUtil::Handle<UlawAlawOperation> UlawAlawOperationPtr;
+
 UlawAlawFactory::UlawAlawFactory(const Ice::ObjectAdapterPtr& adapter,
         const Logger& logger,
         const MediaOperationReplicationContextPtr& replicationContext)
@@ -443,7 +293,6 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
         }
     }
 
-    UlawAlawOperationPtr operation;
     if (sourceUlaw && sinkAlaw)
     {
         //Their source is ulaw and their sink is alaw.

commit 181a81f9dbbcaeeb83b0f11d474db22ee3893287
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Aug 19 10:43:15 2011 -0500

    Resolve a circular reference.

diff --git a/src/MediaOperationStateReplicatorListener.cpp b/src/MediaOperationStateReplicatorListener.cpp
index 66acaca..7cfb0f0 100644
--- a/src/MediaOperationStateReplicatorListener.cpp
+++ b/src/MediaOperationStateReplicatorListener.cpp
@@ -49,8 +49,6 @@ void MediaOperationStateReplicatorListenerImpl::stateRemovedForItems(
     private:
         void visitUlawAlawMediaOperationStateItem(const UlawAlawMediaOperationStateItemPtr& ulawAlaw)
         {
-            mAdapter->remove(mAdapter->getCommunicator()->stringToIdentity(ulawAlaw->operationId + ".Source"));
-            mAdapter->remove(mAdapter->getCommunicator()->stringToIdentity(ulawAlaw->operationId + ".Sink"));
             mAdapter->remove(mAdapter->getCommunicator()->stringToIdentity(ulawAlaw->operationId));
         }
         Ice::ObjectAdapterPtr mAdapter;
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 6d80960..708fee1 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -51,6 +51,11 @@ private:
         {
             mSupportedFormats.push_back(format);
         }
+
+        ~UlawAlawSource()
+        {
+            mLogger(Debug) << "UlawAlawSource destructor called";
+        }
     
         void addSink(const StreamSinkPrx& sink, const Ice::Current&)
         {
@@ -118,12 +123,78 @@ private:
     
     typedef IceUtil::Handle<UlawAlawSource> UlawAlawSourcePtr;
 
+    class UlawAlawTranslator : public IceUtil::Shared
+    {
+    public:
+        UlawAlawTranslator(const UlawAlawSourcePtr source,
+                const FormatPtr& inputFormat,
+                const FormatPtr& outputFormat,
+                const Logger& logger)
+            : mSource(source),
+            mInputFormat(inputFormat),
+            mOutputFormat(outputFormat),
+            mLogger(logger)
+        {
+        }
+ 
+        unsigned char ulaw2alaw(unsigned char ulaw)
+        {
+            return pjmedia_ulaw2alaw(ulaw);
+        }
+        
+        unsigned char alaw2ulaw(unsigned char alaw)
+        {
+            return pjmedia_alaw2ulaw(alaw);
+        }
+        
+        FramePtr translate(const FramePtr inFrame)
+        {
+            if (inFrame->mediaFormat->name != mInputFormat->name)
+            {
+                mLogger(Error) << "Cannot translate frame because the format is not what we expect.";
+                throw UnsupportedMediaFormatException();
+            }
+        
+            FramePtr outFrame;
+            Ice::ByteSeq outPayload;
+            outPayload.resize(inFrame->payload.size());
+        
+            if (inFrame->mediaFormat->name == G711uLAWName)
+            {
+                std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawTranslator::ulaw2alaw), this));
+            }
+            else
+            {
+                std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawTranslator::alaw2ulaw), this));
+            }
+        
+            outFrame = new Frame(mOutputFormat, outPayload);
+            return outFrame;
+        }
+
+        void translateFrames(const FrameSeq& frames)
+        {
+            FrameSeq translated;
+            translated.resize(frames.size());
+            std::transform(frames.begin(), frames.end(), translated.begin(), std::bind1st(std::mem_fun(&UlawAlawTranslator::translate), this));
+            mSource->distributeToSinks(translated);
+        }
+
+    private:
+        UlawAlawSourcePtr mSource;
+        FormatPtr mInputFormat;
+        FormatPtr mOutputFormat;
+        Logger mLogger;
+    };
+
+    typedef IceUtil::Handle<UlawAlawTranslator> UlawAlawTranslatorPtr;
+
     class UlawAlawSink : public StreamSink
     {
     public:
         UlawAlawSink(const Logger& logger,
                 const FormatPtr& supportedFormat,
-                const UlawAlawOperationPtr& translator)
+                const UlawAlawTranslatorPtr& translator)
             : mLogger(logger),
             mId(IceUtil::generateUUID()),
             mTranslator(translator)
@@ -131,6 +202,11 @@ private:
             mSupportedFormats.push_back(supportedFormat);
         }
     
+        ~UlawAlawSink()
+        {
+            mLogger(Debug) << "UlawAlawSink destructor called";
+        }
+        
         void write(const FrameSeq& frames, const Ice::Current&)
         {
             mTranslator->translateFrames(frames);
@@ -160,7 +236,7 @@ private:
         FormatSeq mSupportedFormats;
         StreamSourcePrx mSource;
         std::string mId;
-        UlawAlawOperationPtr mTranslator;
+        UlawAlawTranslatorPtr mTranslator;
     };
 
     typedef IceUtil::Handle<UlawAlawSink> UlawAlawSinkPtr;
@@ -176,7 +252,7 @@ public:
         mLogger(logger),
         mStateItem(new UlawAlawMediaOperationStateItem),
         mSource(new UlawAlawSource(mLogger, sourceFormat)),
-        mSink(new UlawAlawSink(mLogger, sinkFormat, this)),
+        mSink(new UlawAlawSink(mLogger, sinkFormat, new UlawAlawTranslator(mSource, sinkFormat, sourceFormat, mLogger))),
         mReplicationContext(replicationContext)
     {
         mStateItem->sourceFormat = sourceFormat;
@@ -184,6 +260,21 @@ public:
         mStateItem->factoryId = factoryId;
     }
 
+    ~UlawAlawOperation()
+    {
+        mLogger(Debug) << "UlawAlawOperation destructor called";
+
+        try
+        {
+            mAdapter->remove(mSourceProxy->ice_getIdentity());
+            mAdapter->remove(mSinkProxy->ice_getIdentity());
+        }
+        catch (const Ice::Exception& ex)
+        {
+            mLogger(Error) << "Exception caught while trying to remove source and sink from object adapter";
+        }
+    }
+
     void setState()
     {
         if (mReplicationContext->isReplicating() == false)
@@ -252,57 +343,12 @@ public:
     {
         try
         {
-            mAdapter->remove(mSourceProxy->ice_getIdentity());
-            mAdapter->remove(mSinkProxy->ice_getIdentity());
             mAdapter->remove(mProxy->ice_getIdentity());
         }
         catch (Ice::Exception& ex)
         {
-            mLogger(Error) << "Exception caught attempting to remove objects from adapter: " << ex.what();
-        }
-    }
-    
-    unsigned char ulaw2alaw(unsigned char ulaw)
-    {
-        return pjmedia_ulaw2alaw(ulaw);
-    }
-    
-    unsigned char alaw2ulaw(unsigned char alaw)
-    {
-        return pjmedia_alaw2ulaw(alaw);
-    }
-    
-    FramePtr translate(const FramePtr inFrame)
-    {
-        if (inFrame->mediaFormat->name != mStateItem->sinkFormat->name)
-        {
-            mLogger(Error) << "Cannot translate frame because the format is not what we expect.";
-            throw UnsupportedMediaFormatException();
-        }
-    
-        FramePtr outFrame;
-        Ice::ByteSeq outPayload;
-        outPayload.resize(inFrame->payload.size());
-    
-        if (inFrame->mediaFormat->name == G711uLAWName)
-        {
-            std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawOperation::ulaw2alaw), this));
-        }
-        else
-        {
-            std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawOperation::alaw2ulaw), this));
+            mLogger(Error) << "Exception caught attempting to remove media operation from adapter: " << ex.what();
         }
-    
-        outFrame = new Frame(mStateItem->sourceFormat, outPayload);
-        return outFrame;
-    }
-
-    void translateFrames(const FrameSeq& frames)
-    {
-        FrameSeq translated;
-        translated.resize(frames.size());
-        std::transform(frames.begin(), frames.end(), translated.begin(), std::bind1st(std::mem_fun(&UlawAlawOperation::translate), this));
-        mSource->distributeToSinks(translated);
     }
 
 private:

commit f148c511a92b2b5626a60cde02d5928449b209a3
Author: Mark Michelson <mmichelson at digium.com>
Date:   Fri Aug 19 10:28:15 2011 -0500

    * Add state replication listener operation for removing state
    * Be sure to destroy media operations in our tests.
    
    There is a circular reference I must take care of.

diff --git a/src/MediaOperationStateReplicatorListener.cpp b/src/MediaOperationStateReplicatorListener.cpp
index 59ff82d..66acaca 100644
--- a/src/MediaOperationStateReplicatorListener.cpp
+++ b/src/MediaOperationStateReplicatorListener.cpp
@@ -34,10 +34,11 @@ void MediaOperationStateReplicatorListenerImpl::stateRemoved(
         const Ice::StringSeq&,
         const Ice::Current&)
 {
+    //unimplemented
 }
 
 void MediaOperationStateReplicatorListenerImpl::stateRemovedForItems(
-        const MediaOperationStateItemSeq&,
+        const MediaOperationStateItemSeq& items,
         const Ice::Current&)
 {
     class Visitor : public MediaOperationStateItemVisitor
@@ -46,20 +47,11 @@ void MediaOperationStateReplicatorListenerImpl::stateRemovedForItems(
         Visitor(const Ice::ObjectAdapterPtr& adapter)
             : mAdapter(adapter) { }
     private:
-        //XXX VISIT HERE THURSDAY FRIDAY MORNING
         void visitUlawAlawMediaOperationStateItem(const UlawAlawMediaOperationStateItemPtr& ulawAlaw)
         {
-            UlawAlawFactoryPtr factory = UlawAlawFactoryPtr::dynamicCast(mAdapter->find(ulawAlaw->factoryId));
-
-            if (!factory)
-            {
-                return;
-            }
-
-            factory->createMediaOperation(
-                    ulawAlaw->sourceFormat,
-                    ulawAlaw->sinkFormat,
-                    ulawAlaw->operationId);
+            mAdapter->remove(mAdapter->getCommunicator()->stringToIdentity(ulawAlaw->operationId + ".Source"));
+            mAdapter->remove(mAdapter->getCommunicator()->stringToIdentity(ulawAlaw->operationId + ".Sink"));
+            mAdapter->remove(mAdapter->getCommunicator()->stringToIdentity(ulawAlaw->operationId));
         }
         Ice::ObjectAdapterPtr mAdapter;
     };
diff --git a/test/TestMediaOperations.cpp b/test/TestMediaOperations.cpp
index ecb8869..0b5371d 100644
--- a/test/TestMediaOperations.cpp
+++ b/test/TestMediaOperations.cpp
@@ -325,6 +325,9 @@ BOOST_FIXTURE_TEST_CASE(createMediaOperations, PerTestFixture)
 
         BOOST_CHECK(alaw2ulawTranslator != 0);
         BOOST_CHECK(ulaw2alawTranslator != 0);
+
+        alaw2ulawTranslator->destroy();
+        ulaw2alawTranslator->destroy();
     }
     catch (const Ice::Exception& ex)
     {
@@ -387,6 +390,8 @@ BOOST_FIXTURE_TEST_CASE(translateAlawToUlaw, PerTestFixture)
         //same size as the frame read in.
         BOOST_CHECK((*iter)->payload.size() == Testbed.sampleAlawFrame->payload.size());
     }
+
+    alaw2ulawTranslator->destroy();
 }
 
 BOOST_FIXTURE_TEST_CASE(translateUlawToAlaw, PerTestFixture)
@@ -442,4 +447,6 @@ BOOST_FIXTURE_TEST_CASE(translateUlawToAlaw, PerTestFixture)
         //same size as the frame read in.
         BOOST_CHECK((*iter)->payload.size() == Testbed.sampleUlawFrame->payload.size());
     }
+
+    ulaw2alawTranslator->destroy();
 }

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


-- 
asterisk-scf/release/media_operations_core.git



More information about the asterisk-scf-commits mailing list