[asterisk-scf-commits] asterisk-scf/integration/media_operations_core.git branch "resample" updated.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Wed Aug 24 16:47:24 CDT 2011


branch "resample" has been updated
       via  3fe2706694e96e4ee54388d760b05c8dfd49b49f (commit)
       via  f7e2554a21910cd7bb82dec98b6d570c4609fdd3 (commit)
       via  8be55cd4446e1a67bdc530d9d2febe66e46e61cf (commit)
       via  e6d1ada2b2baea7581ad1e181ae6a2f41d2ccc26 (commit)
      from  3ba249204e625f7172c74bffab0748c736fe5d21 (commit)

Summary of changes:
 .../MediaOperationsCore/MediaOperationsCoreIf.ice  |    4 +-
 src/Translator.cpp                                 |    4 +-
 src/Translator.h                                   |    8 +-
 src/resample.cpp                                   |  380 ++++++++++++++++++++
 src/{ulaw_alaw.h => resample.h}                    |   28 +-
 src/ulaw_alaw.cpp                                  |   12 +-
 src/ulaw_alaw.h                                    |    8 +-
 test/TestMediaOperations.cpp                       |   95 +++++-
 8 files changed, 507 insertions(+), 32 deletions(-)
 create mode 100644 src/resample.cpp
 copy src/{ulaw_alaw.h => resample.h} (63%)


- Log -----------------------------------------------------------------
commit 3fe2706694e96e4ee54388d760b05c8dfd49b49f
Author: Mark Michelson <mmichelson at digium.com>
Date:   Wed Aug 24 16:39:26 2011 -0500

    Release the pj_pool when we're done with it.

diff --git a/src/resample.cpp b/src/resample.cpp
index f0ed567..5c60df8 100644
--- a/src/resample.cpp
+++ b/src/resample.cpp
@@ -77,6 +77,11 @@ private:
                     &mResample);
         }
 
+        ~Resampler()
+        {
+            pj_pool_release(mPool);
+        }
+
         FramePtr translate(const FramePtr inFrame)
         {
             if (!formatCompare(inFrame->mediaFormat, mInputFormat))

commit f7e2554a21910cd7bb82dec98b6d570c4609fdd3
Author: Mark Michelson <mmichelson at digium.com>
Date:   Wed Aug 24 16:23:39 2011 -0500

    I just noticed that I never committed the resampler. Oops.

diff --git a/src/resample.cpp b/src/resample.cpp
new file mode 100644
index 0000000..f0ed567
--- /dev/null
+++ b/src/resample.cpp
@@ -0,0 +1,375 @@
+/*
+ * 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 <AsteriskSCF/Media/Formats/AudioFormats.h>
+#include <AsteriskSCF/Replication/MediaOperationsCore/MediaOperationsCoreIf.h>
+#include <IceUtil/UUID.h>
+
+#include "resample.h"
+#include "TranslatorSource.h"
+#include "Translator.h"
+#include "TranslatorSink.h"
+
+using namespace AsteriskSCF::Media::V1;
+
+namespace
+{
+
+bool formatCompare(const FormatPtr& format1, const FormatPtr& format2)
+{
+    return format1->name == format2->name;
+}
+
+};
+
+namespace AsteriskSCF
+{
+
+namespace MediaOperationsCore
+{
+
+using namespace AsteriskSCF::Core::Discovery::V1;
+using namespace AsteriskSCF::Media::Formats::Audio::V1;
+using namespace AsteriskSCF::System::Logging;
+using namespace AsteriskSCF::Replication::MediaOperationsCore::V1;
+
+class ResampleOperation : public MediaOperation
+{
+private:
+    class Resampler : public Translator
+    {
+    public:
+        Resampler(const TranslatorSourcePtr& source,
+                const FormatPtr& inputFormat,
+                const FormatPtr& outputFormat,
+                const Logger& logger,
+                pj_caching_pool *caching_pool)
+            : Translator(source, inputFormat, outputFormat, logger)
+        {
+            mPool = pj_pool_create(&caching_pool->factory, "Who cares", 256, 256, NULL);
+
+            AudioFormatPtr inputAudio = AudioFormatPtr::dynamicCast(inputFormat);
+            AudioFormatPtr outputAudio = AudioFormatPtr::dynamicCast(outputFormat);
+
+            mOutputFrameSize = (outputAudio->sampleRate * inputAudio->frameSize) / inputAudio->sampleRate;
+            mLogger(Debug) << "Output frames for resampler will contain " << mOutputFrameSize << " samples";
+
+            pjmedia_resample_create(mPool,
+                    true,
+                    true,
+                    1,
+                    inputAudio->sampleRate,
+                    outputAudio->sampleRate,
+                    inputAudio->frameSize,
+                    &mResample);
+        }
+
+        FramePtr translate(const FramePtr inFrame)
+        {
+            if (!formatCompare(inFrame->mediaFormat, mInputFormat))
+            {
+                mLogger(Error) << "Cannot resample frame because the format is not what was expected";
+                throw UnsupportedMediaFormatException();
+            }
+
+            AudioFormatPtr inFormat = AudioFormatPtr::dynamicCast(inFrame->mediaFormat);
+            AudioFormatPtr outFormat = AudioFormatPtr::dynamicCast(mOutputFormat);
+            outFormat->frameSize = mOutputFrameSize;
+
+            if (inFormat == 0)
+            {
+                //This should be impossible since the format check above succeeded.
+                mLogger(Error) << "Cannot resample frame because the input format is not an audio format";
+                throw UnsupportedMediaFormatException();
+            }
+
+            if (inFormat->frameSize != (int) pjmedia_resample_get_input_size(mResample))
+            {
+                mLogger(Error) << "Cannot resample frame because the frame size is incorrect";
+                throw UnsupportedMediaFormatException();
+            }
+
+            ShortSeqPayloadPtr inPayload = ShortSeqPayloadPtr::dynamicCast(inFrame->payload);
+            ShortSeqPayloadPtr outPayload = new ShortSeqPayload(Ice::ShortSeq(outFormat->frameSize));
+
+            pjmedia_resample_run(mResample, &inPayload->payload.front(), &outPayload->payload.front());
+
+            return new Frame(outFormat, outPayload);
+        }
+    private:
+        pj_pool_t *mPool;
+        pjmedia_resample *mResample;
+        int mOutputFrameSize;
+    };
+
+public:
+    ResampleOperation(const Ice::ObjectAdapterPtr& adapter,
+            const Logger& logger,
+            const FormatPtr& sourceFormat,
+            const FormatPtr& sinkFormat,
+            const Ice::Identity& factoryId,
+            const MediaOperationReplicationContextPtr& replicationContext,
+            pj_caching_pool *cachingPool)
+        : mAdapter(adapter),
+        mLogger(logger),
+        mStateItem(new ResamplerMediaOperationStateItem),
+        mSource(new TranslatorSource(mLogger, sourceFormat)),
+        mSink(new TranslatorSink(mLogger, sinkFormat, new Resampler(mSource, sinkFormat, sourceFormat, mLogger, cachingPool))),
+        mReplicationContext(replicationContext)
+    {
+        mStateItem->sourceFormat = sourceFormat;
+        mStateItem->sinkFormat = sinkFormat;
+        mStateItem->factoryId = factoryId;
+    }
+
+    //XXX Almost all of this is copied and pasted from the ulaw<->alaw translator.
+    //This should probably extracted into a base class...
+    ~ResampleOperation()
+    {
+        mLogger(Debug) << "ResampleOperation 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)
+        {
+            return;
+        }
+
+        try
+        {
+            MediaOperationStateItemSeq seq;
+            seq.push_back(mStateItem);
+            mReplicationContext->getReplicator().tryOneWay()->setState(seq);
+        }
+        catch (const Ice::Exception& ex)
+        {
+            mLogger(Error) << "Exception caught while attempting to replicate state: " << ex.what();
+        }
+    }
+
+    void removeState()
+    {
+        if (mReplicationContext->isReplicating() == false)
+        {
+            return;
+        }
+
+        try
+        {
+            MediaOperationStateItemSeq seq;
+            seq.push_back(mStateItem);
+            mReplicationContext->getReplicator().tryOneWay()->removeStateForItems(seq);
+        }
+        catch (const Ice::Exception& ex)
+        {
+            mLogger(Error) << "Exception caught while attempting to replicate state: " << ex.what();
+        }
+    }
+
+    MediaOperationPrx activate(const std::string& id)
+    {
+        mProxy =
+            MediaOperationPrx::uncheckedCast(mAdapter->add(this, mAdapter->getCommunicator()->stringToIdentity(id)));
+        mSinkProxy =
+            StreamSinkPrx::uncheckedCast(mAdapter->add(mSink, mAdapter->getCommunicator()->stringToIdentity(id + ".Sink")));
+        mSourceProxy =
+            StreamSourcePrx::uncheckedCast(mAdapter->add(mSource, mAdapter->getCommunicator()->stringToIdentity(id +".Source")));
+
+        mStateItem->operationId = mProxy->ice_getIdentity().name;
+
+        setState();
+
+        return mProxy;
+    }
+
+    StreamSourcePrx getSource(const Ice::Current&)
+    {
+        return mSourceProxy;
+    }
+
+    StreamSinkPrx getSink(const Ice::Current&)
+    {
+        return mSinkProxy;
+    }
+
+    void destroy(const Ice::Current&)
+    {
+        try
+        {
+            mAdapter->remove(mProxy->ice_getIdentity());
+        }
+        catch (Ice::Exception& ex)
+        {
+            mLogger(Error) << "Exception caught attempting to remove media operation from adapter: " << ex.what();
+        }
+    }
+
+private:
+    Ice::ObjectAdapterPtr mAdapter;
+    Logger mLogger;
+    MediaOperationPrx mProxy;
+    ResamplerMediaOperationStateItemPtr mStateItem;
+    TranslatorSourcePtr mSource;
+    StreamSourcePrx mSourceProxy;
+    TranslatorSinkPtr mSink;
+    StreamSinkPrx mSinkProxy;
+    MediaOperationReplicationContextPtr mReplicationContext;
+};
+
+typedef IceUtil::Handle<ResampleOperation> ResampleOperationPtr;
+
+ResampleFactory::ResampleFactory(const Ice::ObjectAdapterPtr& adapter,
+        const AsteriskSCF::System::Logging::Logger& logger,
+        const MediaOperationReplicationContextPtr& replicationContext)
+    : MediaOperationFactoryImpl(adapter, logger, replicationContext, "ResampleFactory")
+{
+    pj_memset(&mCachingPool, 0, sizeof(mCachingPool));
+    pj_caching_pool_init(&mCachingPool, NULL, 1024 * 1024);
+    buildSupportedFormats();
+    populateLocatorParams();
+}
+
+MediaOperationPrx ResampleFactory::createMediaOperation(
+        const StreamSourcePrx& source,
+        const StreamSinkPrx& sink,
+        const Ice::Current&)
+{
+    //Since we're expected to do a translation, we'd better
+    //be given both a source and a sink.
+    if (sink == 0 || source == 0)
+    {
+        mLogger(Error) << "Cannot create resampler because of a missing source or sink";
+        throw UnsupportedMediaFormatException();
+    }
+
+    FormatSeq sourceFormats = source->getFormats();
+    FormatSeq sinkFormats = sink->getFormats();
+
+    FormatSeq::iterator supportedInput =
+        std::find_first_of(sourceFormats.begin(),
+                sourceFormats.end(),
+                mSupportedInputFormats.begin(),
+                mSupportedInputFormats.end(),
+                formatCompare);
+
+    FormatSeq::iterator supportedOutput =
+        std::find_first_of(sinkFormats.begin(),
+                sinkFormats.end(),
+                mSupportedOutputFormats.begin(),
+                mSupportedOutputFormats.end(),
+                formatCompare);
+
+    if (supportedInput == sourceFormats.end()
+            || supportedOutput == sinkFormats.end())
+    {
+        mLogger(Error) << "Cannot create resampler because of unsupported formats";
+        throw UnsupportedMediaFormatException();
+    }
+
+    FormatPtr inputFormat = AudioFormatPtr::dynamicCast(*supportedInput);
+    FormatPtr outputFormat = AudioFormatPtr::dynamicCast(*supportedOutput);
+
+    //We've extracted the formats we give a @#$* about from
+    //the source and sink. Now, we have to determine which
+    //formats to actually use for creating the resampler. For
+    //now, we go with the lazy approach of taking whatever
+    //supported input and whatever supported output we found
+    //and using that.
+    mLogger(Debug) << "Creating a resampler from " << (*supportedInput)->name
+        << " to " << (*supportedOutput)->name;
+
+    return createMediaOperation(
+            *supportedOutput,
+            *supportedInput,
+            IceUtil::generateUUID());
+}
+
+MediaOperationPrx ResampleFactory::createMediaOperation(
+        const FormatPtr& sourceFormat,
+        const FormatPtr& sinkFormat,
+        const std::string& operationId)
+{
+    ResampleOperationPtr operation(
+            new ResampleOperation(
+                mAdapter,
+                mLogger,
+                sourceFormat,
+                sinkFormat,
+                getProxy()->ice_getIdentity(),
+                mReplicationContext,
+                &mCachingPool));
+
+    MediaOperationPrx proxy = operation->activate(operationId);
+    return proxy;
+}
+void ResampleFactory::buildSupportedFormats()
+{
+    FormatPtr slin8 = new SignedLinear();
+    slin8->name = SignedLinear8Name;
+
+    mSupportedInputFormats.push_back(slin8);
+    mSupportedOutputFormats.push_back(slin8);
+
+    FormatPtr slin16 = new SignedLinear();
+    slin16->name = SignedLinear16Name;
+
+    mSupportedInputFormats.push_back(slin16);
+    mSupportedOutputFormats.push_back(slin16);
+}
+
+void ResampleFactory::populateLocatorParams()
+{
+    mLocatorParams->category = MediaOperationDiscoveryCategory;
+    mLocatorParams->service = MediaOperationDiscoveryTranslatorService;
+
+    for (FormatSeq::iterator inIter = mSupportedInputFormats.begin();
+            inIter != mSupportedInputFormats.end(); ++inIter)
+    {
+        for (FormatSeq::iterator outIter = mSupportedOutputFormats.begin();
+                outIter != mSupportedOutputFormats.end(); ++outIter)
+        {
+            //Don't create a resampler between the same format!
+            if (formatCompare(*inIter, *outIter))
+            {
+                continue;
+            }
+
+            mLogger(Debug) << "Creating resampler attributes from " << (*inIter)->name
+                << " to " << (*outIter)->name;
+
+            MediaOperationAttributes attrs;
+            attrs.inputFormat = *inIter;
+            attrs.outputFormat = *outIter;
+            attrs.cost = 100; //XXX COST?
+
+            mLocatorParams->attributes.push_back(attrs);
+        }
+    }
+}
+
+}
+}
diff --git a/src/resample.h b/src/resample.h
new file mode 100644
index 0000000..c0a5549
--- /dev/null
+++ b/src/resample.h
@@ -0,0 +1,62 @@
+/*
+ * 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 <pjmedia.h>
+
+#include "MediaOperationFactoryImpl.h"
+
+namespace AsteriskSCF
+{
+
+namespace MediaOperationsCore
+{
+
+class ResampleFactory : public MediaOperationFactoryImpl
+{
+public:
+    ResampleFactory(const Ice::ObjectAdapterPtr&,
+            const AsteriskSCF::System::Logging::Logger& logger,
+            const MediaOperationReplicationContextPtr& replicationContext);
+
+    void replicateState(const AsteriskSCF::Media::V1::MediaOperationPrx& proxy,
+            const AsteriskSCF::Media::V1::FormatPtr& sourceFormat,
+            const AsteriskSCF::Media::V1::FormatPtr& sinkFormat);
+
+    AsteriskSCF::Media::V1::MediaOperationPrx createMediaOperation(
+            const AsteriskSCF::Media::V1::StreamSourcePrx& source,
+            const AsteriskSCF::Media::V1::StreamSinkPrx& sink,
+            const Ice::Current&);
+
+    AsteriskSCF::Media::V1::MediaOperationPrx createMediaOperation(
+            const AsteriskSCF::Media::V1::FormatPtr& sourceFormat,
+            const AsteriskSCF::Media::V1::FormatPtr& sinkFormat,
+            const std::string& operationId);
+private:
+    void buildSupportedFormats();
+    void populateLocatorParams();
+
+    AsteriskSCF::Media::V1::FormatSeq mSupportedInputFormats;
+    AsteriskSCF::Media::V1::FormatSeq mSupportedOutputFormats;
+
+    pj_caching_pool mCachingPool;
+};
+
+typedef IceUtil::Handle<ResampleFactory> ResampleFactoryPtr;
+
+}
+}

commit 8be55cd4446e1a67bdc530d9d2febe66e46e61cf
Author: Mark Michelson <mmichelson at digium.com>
Date:   Wed Aug 24 16:23:11 2011 -0500

    Add a test to downsample from 16 kHz to 8 kHz slin.

diff --git a/test/TestMediaOperations.cpp b/test/TestMediaOperations.cpp
index 5344ac9..2df6731 100644
--- a/test/TestMediaOperations.cpp
+++ b/test/TestMediaOperations.cpp
@@ -103,6 +103,10 @@ public:
     FramePtr sampleSlin8Frame;
 
     size_t sampleSlin8FrameSize;
+
+    FramePtr sampleSlin16Frame;
+
+    size_t sampleSlin16FrameSize;
 };
 
 static SharedTestData Testbed;
@@ -151,6 +155,21 @@ static uint16_t sampleSlin8[] = {
     0x90c0, 0xc3c6, 0xc9cc, 0xcfd2,
 };
 
+//Generated by combining 8-bit samples from sampleUlaw
+//into 16-bit samples.
+static uint16_t sampleSlin16[] = {
+    0x0003, 0x0609, 0x0c0f, 0x1215,
+    0x1018, 0x1b1e, 0x2124, 0x272a,
+    0x202d, 0x3033, 0x3639, 0x3c3f,
+    0x3042, 0x4548, 0x4b4e, 0x5154,
+    0x4057, 0x5a5d, 0x6063, 0x6669,
+    0x506c, 0x6f72, 0x7578, 0x7b7e,
+    0x6081, 0x8487, 0x8a8d, 0x9093,
+    0x7096, 0x999c, 0x9fa2, 0xa5a8,
+    0x80ab, 0xaeb1, 0xb4b7, 0xbabd,
+    0x90c0, 0xc3c6, 0xc9cc, 0xcfd2,
+};
+
 /**
  * Wrapper class around pj_thread_desc.
  * (copied from PJSipManager.h in the sip repo)
@@ -264,6 +283,10 @@ struct GlobalIceFixture
             ShortSeqPayloadPtr slin8Payload(new ShortSeqPayload(Ice::ShortSeq(sampleSlin8, sampleSlin8 + (sizeof(sampleSlin8) / 2))));
             Testbed.sampleSlin8Frame = new Frame(Testbed.slin8, slin8Payload);
             Testbed.sampleSlin8FrameSize = slin8Payload->payload.size();
+
+            ShortSeqPayloadPtr slin16Payload(new ShortSeqPayload(Ice::ShortSeq(sampleSlin16, sampleSlin16 + (sizeof(sampleSlin16) / 2))));
+            Testbed.sampleSlin16Frame = new Frame(Testbed.slin16, slin16Payload);
+            Testbed.sampleSlin16FrameSize = slin16Payload->payload.size();
         }
         catch (const Ice::Exception& ex)
         {
@@ -457,7 +480,7 @@ BOOST_FIXTURE_TEST_CASE(translateAlawToUlaw, PerTestFixture)
 
         ByteSeqPayloadPtr payload = ByteSeqPayloadPtr::dynamicCast((*iter)->payload);
 
-        BOOST_CHECK(payload != 0);
+        BOOST_REQUIRE(payload != 0);
         //Each frame written by the translator should be the
         //same size as the frame read in.
         BOOST_CHECK(payload->payload.size() == Testbed.sampleAlawFrameSize);
@@ -517,7 +540,7 @@ BOOST_FIXTURE_TEST_CASE(translateUlawToAlaw, PerTestFixture)
 
         ByteSeqPayloadPtr payload = ByteSeqPayloadPtr::dynamicCast((*iter)->payload);
 
-        BOOST_CHECK(payload != 0);
+        BOOST_REQUIRE(payload != 0);
 
         //Each frame written by the translator should be the
         //same size as the frame read in.
@@ -534,7 +557,6 @@ BOOST_FIXTURE_TEST_CASE(resample8To16, PerTestFixture)
     //For this test, we have to base the resultant frame on the size of the input frame.
 
     Testbed.slin8->frameSize = Testbed.sampleSlin8FrameSize;
-    Testbed.slin16->frameSize = Testbed.slin8->frameSize * 2;
 
     MediaOperationServiceLocatorParamsPtr eightToSixteenParams = createLocatorParams(Testbed.slin8, Testbed.slin16);
 
@@ -577,8 +599,71 @@ BOOST_FIXTURE_TEST_CASE(resample8To16, PerTestFixture)
 
         ShortSeqPayloadPtr payload = ShortSeqPayloadPtr::dynamicCast((*iter)->payload);
 
-        BOOST_CHECK(payload != 0);
+        BOOST_REQUIRE(payload != 0);
+
+        AudioFormatPtr audio = AudioFormatPtr::dynamicCast((*iter)->mediaFormat);
+
+        BOOST_REQUIRE(audio != 0);
+
+        BOOST_CHECK((int) payload->payload.size() == audio->frameSize);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(resample16To8, PerTestFixture)
+{
+    size_t numFramesToTranslate = 10;
+
+    //For this test, we have to base the resultant frame on the size of the input frame.
+
+    Testbed.slin16->frameSize = Testbed.sampleSlin16FrameSize;
+
+    MediaOperationServiceLocatorParamsPtr sixteenToEightParams = createLocatorParams(Testbed.slin16, Testbed.slin8);
+
+    MediaOperationFactoryPrx sixteenToEightFactory =
+        MediaOperationFactoryPrx::checkedCast(Testbed.locator->locate(sixteenToEightParams));
+
+    MediaOperationPrx sixteenToEightResampler =
+        sixteenToEightFactory->createMediaOperation(Testbed.slin16SourceProxy, Testbed.slin8SinkProxy);
+
+    StreamSinkPrx resampleSink = sixteenToEightResampler->getSink();
+    StreamSourcePrx resampleSource = sixteenToEightResampler->getSource();
+
+    Testbed.slin16SourceProxy->addSink(resampleSink);
+    Testbed.slin8SinkProxy->setSource(resampleSource);
+
+    resampleSource->addSink(Testbed.slin8SinkProxy);
+    resampleSink->setSource(Testbed.slin16SourceProxy);
+
+    FrameSeq slin16Frames(numFramesToTranslate, Testbed.sampleSlin16Frame);
+
+    try
+    {
+        Testbed.slin16Source->feedFramesToTranslator(slin16Frames);
+    }
+    catch (const Ice::Exception& ex)
+    {
+        std::stringstream str;
+        str << "Exception caught trying to resample slin8 frames: " << ex.what();
+        BOOST_FAIL(str.str());
+    }
+
+    FrameSeq framesWritten = Testbed.slin8Sink->getFrames();
+
+    BOOST_CHECK(framesWritten.size() == numFramesToTranslate);
+
+    for (FrameSeq::iterator iter = framesWritten.begin();
+            iter != framesWritten.end(); ++iter)
+    {
+        BOOST_CHECK(SignedLinearPtr::dynamicCast((*iter)->mediaFormat) != 0);
+
+        ShortSeqPayloadPtr payload = ShortSeqPayloadPtr::dynamicCast((*iter)->payload);
+
+        BOOST_REQUIRE(payload != 0);
+
+        AudioFormatPtr audio = AudioFormatPtr::dynamicCast((*iter)->mediaFormat);
+
+        BOOST_REQUIRE(audio != 0);
 
-        BOOST_CHECK((int) payload->payload.size() == Testbed.slin16->frameSize);
+        BOOST_CHECK((int) payload->payload.size() == audio->frameSize);
     }
 }

commit e6d1ada2b2baea7581ad1e181ae6a2f41d2ccc26
Author: Mark Michelson <mmichelson at digium.com>
Date:   Wed Aug 24 15:13:37 2011 -0500

    Undo previous change to make everything use Audio formats.
    
    I like for the translators to be more flexible. Individual translators
    can either store their own separate audio formats or do as I have and
    just dynamic cast when needed.

diff --git a/slice/AsteriskSCF/Replication/MediaOperationsCore/MediaOperationsCoreIf.ice b/slice/AsteriskSCF/Replication/MediaOperationsCore/MediaOperationsCoreIf.ice
index e68a547..02a4f63 100644
--- a/slice/AsteriskSCF/Replication/MediaOperationsCore/MediaOperationsCoreIf.ice
+++ b/slice/AsteriskSCF/Replication/MediaOperationsCore/MediaOperationsCoreIf.ice
@@ -78,11 +78,11 @@ class TranslatorMediaOperationStateItem extends MediaOperationStateItem
      /**
      * The format to use for the source of the media operation
      */
-    AsteriskSCF::Media::V1::AudioFormat sourceFormat;
+    AsteriskSCF::Media::V1::Format sourceFormat;
     /**
      * The format to use for the sink of the media operation
      */
-    AsteriskSCF::Media::V1::AudioFormat sinkFormat;
+    AsteriskSCF::Media::V1::Format sinkFormat;
 };
 
 /**
diff --git a/src/Translator.cpp b/src/Translator.cpp
index 4fb069c..3e12631 100644
--- a/src/Translator.cpp
+++ b/src/Translator.cpp
@@ -26,8 +26,8 @@ using namespace AsteriskSCF::Media::V1;
 using namespace AsteriskSCF::System::Logging;
 
 Translator::Translator(const TranslatorSourcePtr& source,
-        const AudioFormatPtr& inputFormat,
-        const AudioFormatPtr& outputFormat,
+        const FormatPtr& inputFormat,
+        const FormatPtr& outputFormat,
         const Logger& logger)
     : mSource(source),
     mInputFormat(inputFormat),
diff --git a/src/Translator.h b/src/Translator.h
index 31dc1b0..2884875 100644
--- a/src/Translator.h
+++ b/src/Translator.h
@@ -31,8 +31,8 @@ class Translator : public IceUtil::Shared
 {
 public:
     Translator(const TranslatorSourcePtr& source,
-            const AsteriskSCF::Media::V1::AudioFormatPtr& inputFormat,
-            const AsteriskSCF::Media::V1::AudioFormatPtr& outputFormat,
+            const AsteriskSCF::Media::V1::FormatPtr& inputFormat,
+            const AsteriskSCF::Media::V1::FormatPtr& outputFormat,
             const AsteriskSCF::System::Logging::Logger& logger);
     
     virtual ~Translator();
@@ -55,8 +55,8 @@ public:
 
 protected:
     TranslatorSourcePtr mSource;
-    AsteriskSCF::Media::V1::AudioFormatPtr mInputFormat;
-    AsteriskSCF::Media::V1::AudioFormatPtr mOutputFormat;
+    AsteriskSCF::Media::V1::FormatPtr mInputFormat;
+    AsteriskSCF::Media::V1::FormatPtr mOutputFormat;
     AsteriskSCF::System::Logging::Logger mLogger;
 };
 
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 3286864..d5a140d 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -43,8 +43,8 @@ private:
     {
     public:
         UlawAlawTranslator(const TranslatorSourcePtr source,
-                const AudioFormatPtr& inputFormat,
-                const AudioFormatPtr& outputFormat,
+                const FormatPtr& inputFormat,
+                const FormatPtr& outputFormat,
                 const Logger& logger)
             : Translator(source, inputFormat, outputFormat, logger)
         {
@@ -103,8 +103,8 @@ private:
 public:
     UlawAlawOperation(const Ice::ObjectAdapterPtr& adapter,
             const Logger& logger,
-            const AudioFormatPtr& sourceFormat,
-            const AudioFormatPtr& sinkFormat,
+            const FormatPtr& sourceFormat,
+            const FormatPtr& sinkFormat,
             const Ice::Identity& factoryId,
             const MediaOperationReplicationContextPtr& replicationContext)
         : mAdapter(adapter),
@@ -333,8 +333,8 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
 }
 
 MediaOperationPrx UlawAlawFactory::createMediaOperation(
-        const AudioFormatPtr& sourceFormat,
-        const AudioFormatPtr& sinkFormat,
+        const FormatPtr& sourceFormat,
+        const FormatPtr& sinkFormat,
         const std::string& operationId)
 {
     UlawAlawOperationPtr operation(
diff --git a/src/ulaw_alaw.h b/src/ulaw_alaw.h
index abcea86..4d4c56c 100644
--- a/src/ulaw_alaw.h
+++ b/src/ulaw_alaw.h
@@ -32,8 +32,8 @@ public:
             const MediaOperationReplicationContextPtr& replicationContext);
 
     void replicateState(const AsteriskSCF::Media::V1::MediaOperationPrx& proxy,
-            const AsteriskSCF::Media::V1::AudioFormatPtr& sourceFormat,
-            const AsteriskSCF::Media::V1::AudioFormatPtr& sinkFormat);
+            const AsteriskSCF::Media::V1::FormatPtr& sourceFormat,
+            const AsteriskSCF::Media::V1::FormatPtr& sinkFormat);
 
     AsteriskSCF::Media::V1::MediaOperationPrx createMediaOperation(
             const AsteriskSCF::Media::V1::StreamSourcePrx& source,
@@ -41,8 +41,8 @@ public:
             const Ice::Current&);
 
     AsteriskSCF::Media::V1::MediaOperationPrx createMediaOperation(
-            const AsteriskSCF::Media::V1::AudioFormatPtr& sourceFormat,
-            const AsteriskSCF::Media::V1::AudioFormatPtr& sinkFormat,
+            const AsteriskSCF::Media::V1::FormatPtr& sourceFormat,
+            const AsteriskSCF::Media::V1::FormatPtr& sinkFormat,
             const std::string& operationId);
 };
 

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


-- 
asterisk-scf/integration/media_operations_core.git



More information about the asterisk-scf-commits mailing list