[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
Wed Aug 17 13:57:14 CDT 2011
branch "master" has been updated
via 1c0eba48c860531621a3c0d5318361867199f2bf (commit)
via 94c397f3ba890a646190c8ea4a0ca965e14459a0 (commit)
via 6007d9bd2f54386088b77f179395ae59633e1fb3 (commit)
via ca64b6e453a80cc818eb864279c6c8423ba65d9a (commit)
via e0e4a4b1255f4c6c9638bc90c386125f2b14d609 (commit)
via 009368e35449285f5c20d8151407bb23b1e57281 (commit)
via aa8e6a3a0c209cae9efd059ce2d2134b00cc255c (commit)
via 17bf150b5a86989922a70bfe3208bbe4a2671fc7 (commit)
via adcc9988cb7eb283dcd2ecda5974d3a06290a3fc (commit)
via 7b168b92fe152d79259fb404b84263a8362fbfad (commit)
via e5e68464d21a287a86f439a00bb16900df297b4a (commit)
via b8ea848130764caa518ee2ca602b8fc8dacc126c (commit)
via b4c89ab73ab53c53d69fb123ca79ea569fd9470f (commit)
via 7a8157804e045cc8e6d847dce5dd14da760225df (commit)
via c743c632b4a513a673bb0526a3bbc3e6417c6749 (commit)
from 575aada840ad67ff474824e90dc440db0a3abc69 (commit)
Summary of changes:
CMakeLists.txt | 3 +
src/MediaOperationsCore.cpp | 12 +-
src/ulaw_alaw.cpp | 358 ++++++++++++++++++-------------------
test/CMakeLists.txt | 21 +++
test/TestMediaOperations.cpp | 400 +++++++++++++++++++++++++++++++++++++-----
test/TestStreamSink.cpp | 68 +++++++
test/TestStreamSink.h | 66 +++++++
test/TestStreamSource.cpp | 80 +++++++++
test/TestStreamSource.h | 71 ++++++++
9 files changed, 847 insertions(+), 232 deletions(-)
create mode 100644 test/CMakeLists.txt
create mode 100644 test/TestStreamSink.cpp
create mode 100644 test/TestStreamSink.h
create mode 100644 test/TestStreamSource.cpp
create mode 100644 test/TestStreamSource.h
- Log -----------------------------------------------------------------
commit 1c0eba48c860531621a3c0d5318361867199f2bf
Author: Mark Michelson <mmichelson at digium.com>
Date: Wed Aug 17 13:57:51 2011 -0500
Use constants for locating media operations.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index dd7ecc6..ae9a84a 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -286,8 +286,8 @@ UlawAlawFactory::UlawAlawFactory(const Ice::ObjectAdapterPtr& adapter,
alawToUlaw.outputFormat->name = G711uLAWName;
alawToUlaw.cost = 100; //XXX COST?
- mLocatorParams->category = "MediaOperation";
- mLocatorParams->service = "translator";
+ mLocatorParams->category = MediaOperationDiscoveryCategory;
+ mLocatorParams->service = MediaOperationDiscoveryTranslatorService;
mLocatorParams->attributes.push_back(ulawToAlaw);
mLocatorParams->attributes.push_back(alawToUlaw);
}
diff --git a/test/TestMediaOperations.cpp b/test/TestMediaOperations.cpp
index 75153e8..ecb8869 100644
--- a/test/TestMediaOperations.cpp
+++ b/test/TestMediaOperations.cpp
@@ -273,8 +273,8 @@ MediaOperationServiceLocatorParamsPtr createLocatorParams(
attrs.inputFormat = inputFormat;
attrs.outputFormat = outputFormat;
MediaOperationServiceLocatorParamsPtr params = new MediaOperationServiceLocatorParams();
- params->category = "MediaOperation";
- params->service = "translator";
+ params->category = MediaOperationDiscoveryCategory;
+ params->service = MediaOperationDiscoveryTranslatorService;
params->attributes.push_back(attrs);
return params;
commit 94c397f3ba890a646190c8ea4a0ca965e14459a0
Author: Mark Michelson <mmichelson at digium.com>
Date: Wed Aug 17 13:48:53 2011 -0500
A couple more cleanup things.
diff --git a/src/MediaOperationsCore.cpp b/src/MediaOperationsCore.cpp
index 2f03cdc..12684d3 100644
--- a/src/MediaOperationsCore.cpp
+++ b/src/MediaOperationsCore.cpp
@@ -119,7 +119,7 @@ private:
void MediaOperationsCoreApp::createAndRegisterFactory(const MediaOperationFactoryImplPtr& factory)
{
MediaOperationFactoryPrx factoryProxy =
- MediaOperationFactoryPrx::uncheckedCast(mAdapter->addWithUUID(factory));
+ MediaOperationFactoryPrx::uncheckedCast(mAdapter->add(factory, mAdapter->getCommunicator()->stringToIdentity(factory->getName())));
mFactories.push_back(std::make_pair(factory, factoryProxy));
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 312b76e..dd7ecc6 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -177,7 +177,7 @@ public:
{
}
- void activate()
+ MediaOperationPrx activate()
{
mProxy =
MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(this));
@@ -185,6 +185,8 @@ public:
StreamSinkPrx::uncheckedCast(mAdapter->addWithUUID(mSink));
mSourceProxy =
StreamSourcePrx::uncheckedCast(mAdapter->addWithUUID(mSource));
+
+ return mProxy;
}
StreamSourcePrx getSource(const Ice::Current&)
@@ -254,6 +256,7 @@ public:
mSource->distributeToSinks(translated);
}
+private:
Ice::ObjectAdapterPtr mAdapter;
Logger mLogger;
MediaOperationPrx mProxy;
@@ -321,12 +324,10 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
G711aLAWPtr alaw;
if ((ulaw = G711uLAWPtr::dynamicCast(*sourceIter)))
{
- mLogger(Debug) << "Set source Ulaw...";
sourceUlaw = ulaw;
}
else if ((alaw = G711aLAWPtr::dynamicCast(*sourceIter)))
{
- mLogger(Debug) << "Set source Alaw...";
sourceAlaw = alaw;
}
}
@@ -338,12 +339,10 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
G711aLAWPtr alaw;
if ((ulaw = G711uLAWPtr::dynamicCast(*sinkIter)))
{
- mLogger(Debug) << "Set sink ulaw...";
sinkUlaw = ulaw;
}
else if ((alaw = G711aLAWPtr::dynamicCast(*sinkIter)))
{
- mLogger(Debug) << "Set sink alaw...";
sinkAlaw = alaw;
}
}
@@ -354,6 +353,8 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
//Their source is ulaw and their sink is alaw.
//This means we are translating from ulaw to alaw.
//This means that we need a ulaw sink and an alaw source.
+ //This accounts for what may seem to be a bit of backwardness
+ //regarding the parameters passed into the constructor.
mLogger(Debug) << "Creating ulaw to alaw translator";
operation = new UlawAlawOperation(mAdapter, mLogger, sinkAlaw, sourceUlaw);
}
@@ -367,8 +368,7 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
mLogger(Error) << "Cannot create translator because source and sink do not have supported formats";
throw UnsupportedMediaFormatException();
}
- operation->activate();
- return operation->mProxy;
+ return operation->activate();
}
} //end namespace MediaOperationsCore
commit 6007d9bd2f54386088b77f179395ae59633e1fb3
Author: Mark Michelson <mmichelson at digium.com>
Date: Wed Aug 17 13:39:16 2011 -0500
Use constant for ulaw and alaw format names.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index bb870cb..312b76e 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -233,7 +233,7 @@ public:
Ice::ByteSeq outPayload;
outPayload.resize(inFrame->payload.size());
- if (inFrame->mediaFormat->name == "ulaw")
+ if (inFrame->mediaFormat->name == G711uLAWName)
{
std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawOperation::ulaw2alaw), this));
}
@@ -271,16 +271,16 @@ UlawAlawFactory::UlawAlawFactory(const Ice::ObjectAdapterPtr& adapter,
{
MediaOperationAttributes ulawToAlaw;
ulawToAlaw.inputFormat = new G711uLAW();
- ulawToAlaw.inputFormat->name = "ulaw";
+ ulawToAlaw.inputFormat->name = G711uLAWName;
ulawToAlaw.outputFormat = new G711aLAW();
- ulawToAlaw.outputFormat->name = "alaw";
+ ulawToAlaw.outputFormat->name = G711aLAWName;
ulawToAlaw.cost = 100; //XXX COST?
MediaOperationAttributes alawToUlaw;
alawToUlaw.inputFormat = new G711aLAW();
- alawToUlaw.inputFormat->name = "alaw";
+ alawToUlaw.inputFormat->name = G711aLAWName;
alawToUlaw.outputFormat = new G711uLAW();
- alawToUlaw.outputFormat->name = "ulaw";
+ alawToUlaw.outputFormat->name = G711uLAWName;
alawToUlaw.cost = 100; //XXX COST?
mLocatorParams->category = "MediaOperation";
diff --git a/test/TestMediaOperations.cpp b/test/TestMediaOperations.cpp
index 8f51761..75153e8 100644
--- a/test/TestMediaOperations.cpp
+++ b/test/TestMediaOperations.cpp
@@ -199,10 +199,10 @@ struct GlobalIceFixture
}
Testbed.ulaw = new G711uLAW();
- Testbed.ulaw->name = "ulaw";
+ Testbed.ulaw->name = G711uLAWName;
Testbed.alaw = new G711aLAW();
- Testbed.alaw->name = "alaw";
+ Testbed.alaw->name = G711aLAWName;
Testbed.sampleAlawFrame = new Frame(Testbed.alaw, Ice::ByteSeq(sampleAlaw, sampleAlaw + sizeof(sampleAlaw)));
commit ca64b6e453a80cc818eb864279c6c8423ba65d9a
Author: Mark Michelson <mmichelson at digium.com>
Date: Wed Aug 17 13:29:26 2011 -0500
Remove translation logic from the sink and into the media operation.
This feels much much much nicer :)
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 3f213d9..bb870cb 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -31,6 +31,9 @@ using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::Media::Formats::Audio::V1;
using namespace AsteriskSCF::System::Logging;
+class UlawAlawOperation;
+typedef IceUtil::Handle<UlawAlawOperation> UlawAlawOperationPtr;
+
class UlawAlawOperation : public MediaOperation
{
private:
@@ -118,60 +121,17 @@ private:
public:
UlawAlawSink(const Logger& logger,
const FormatPtr& supportedFormat,
- const FormatPtr& translatedFormat,
- const UlawAlawSourcePtr& buddySource)
+ const UlawAlawOperationPtr& translator)
: mLogger(logger),
- mTranslatedFormat(translatedFormat),
mId(IceUtil::generateUUID()),
- mBuddySource(buddySource)
+ mTranslator(translator)
{
mSupportedFormats.push_back(supportedFormat);
- mUlawSink = supportedFormat->name == "ulaw" ? true : false;
- }
-
- 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)
- {
- FormatPtr supportedFormat = mSupportedFormats.front();
-
- if (inFrame->mediaFormat->name != supportedFormat->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 (mUlawSink)
- {
- std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::ulaw2alaw), this));
- }
- else
- {
- std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::alaw2ulaw), this));
- }
-
- outFrame = new Frame(mTranslatedFormat, outPayload);
- return outFrame;
}
void write(const FrameSeq& frames, const Ice::Current&)
{
- FrameSeq translated;
- translated.resize(frames.size());
- std::transform(frames.begin(), frames.end(), translated.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::translate), this));
- mBuddySource->distributeToSinks(translated);
+ mTranslator->translateFrames(frames);
}
void setSource(const StreamSourcePrx& source, const Ice::Current&)
@@ -196,15 +156,9 @@ private:
Logger mLogger;
FormatSeq mSupportedFormats;
- FormatPtr mTranslatedFormat;
StreamSourcePrx mSource;
std::string mId;
- UlawAlawSourcePtr mBuddySource;
- /**
- * Tells if we are operating as a ulaw sink.
- * If false, then we are operating as an alaw sink.
- */
- bool mUlawSink;
+ UlawAlawOperationPtr mTranslator;
};
typedef IceUtil::Handle<UlawAlawSink> UlawAlawSinkPtr;
@@ -216,8 +170,10 @@ public:
const FormatPtr& sinkFormat)
: mAdapter(adapter),
mLogger(logger),
- mSource(new UlawAlawSource(mLogger, sourceFormat)),
- mSink(new UlawAlawSink(mLogger, sinkFormat, sourceFormat, mSource))
+ mSourceFormat(sourceFormat),
+ mSinkFormat(sinkFormat),
+ mSource(new UlawAlawSource(mLogger, mSourceFormat)),
+ mSink(new UlawAlawSink(mLogger, mSinkFormat, this))
{
}
@@ -254,18 +210,61 @@ public:
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 != mSinkFormat->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 == "ulaw")
+ {
+ 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));
+ }
+
+ outFrame = new Frame(mSourceFormat, 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);
+ }
Ice::ObjectAdapterPtr mAdapter;
Logger mLogger;
MediaOperationPrx mProxy;
+ FormatPtr mSourceFormat;
+ FormatPtr mSinkFormat;
UlawAlawSourcePtr mSource;
StreamSourcePrx mSourceProxy;
UlawAlawSinkPtr mSink;
StreamSinkPrx mSinkProxy;
};
-typedef IceUtil::Handle<UlawAlawOperation> UlawAlawOperationPtr;
-
UlawAlawFactory::UlawAlawFactory(const Ice::ObjectAdapterPtr& adapter,
const Logger& logger)
: MediaOperationFactoryImpl(adapter, logger, "UlawAlawFactory")
commit e0e4a4b1255f4c6c9638bc90c386125f2b14d609
Author: Mark Michelson <mmichelson at digium.com>
Date: Wed Aug 17 13:03:19 2011 -0500
Nest the UlawAlawSink and UlawAlawSource classes in the UlawAlawOperation class.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 5fa2276..3f213d9 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -31,182 +31,184 @@ using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::Media::Formats::Audio::V1;
using namespace AsteriskSCF::System::Logging;
-class UlawAlawSource : public StreamSource
+class UlawAlawOperation : public MediaOperation
{
-public:
+private:
- UlawAlawSource(const Logger& logger,
- const FormatPtr& format)
- : mLogger(logger),
- mId(IceUtil::generateUUID())
+ class UlawAlawSource : public StreamSource
{
- mSupportedFormats.push_back(format);
- }
-
- void addSink(const StreamSinkPrx& sink, const Ice::Current&)
- {
- if (std::find(mSinks.begin(), mSinks.end(), sink) == mSinks.end())
+ public:
+
+ UlawAlawSource(const Logger& logger,
+ const FormatPtr& format)
+ : mLogger(logger),
+ mId(IceUtil::generateUUID())
{
- mSinks.push_back(sink);
+ mSupportedFormats.push_back(format);
}
- }
-
- 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)
+
+ void addSink(const StreamSinkPrx& sink, const Ice::Current&)
{
- mLogger(Error) << "Format requested is not the one supported by this source";
- throw MediaFormatSwitchException();
+ if (std::find(mSinks.begin(), mSinks.end(), sink) == mSinks.end())
+ {
+ mSinks.push_back(sink);
+ }
}
- }
-
- void distributeToSinks(const FrameSeq& translatedFrames)
- {
- for (StreamSinkSeq::iterator iter = mSinks.begin();
- iter != mSinks.end(); ++iter)
+
+ 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&)
{
- try
+ FormatPtr supportedFormat = mSupportedFormats.front();
+
+ if (supportedFormat->name != format->name)
{
- (*iter)->write(translatedFrames);
+ mLogger(Error) << "Format requested is not the one supported by this source";
+ throw MediaFormatSwitchException();
}
- catch (Ice::Exception& ex)
+ }
+
+ void distributeToSinks(const FrameSeq& translatedFrames)
+ {
+ for (StreamSinkSeq::iterator iter = mSinks.begin();
+ iter != mSinks.end(); ++iter)
{
- mLogger(Error) << "Error attempting to write frames to a sink: " << ex.what();
+ 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 UlawAlawSink : public StreamSink
-{
-public:
- UlawAlawSink(const Logger& logger,
- const FormatPtr& supportedFormat,
- const FormatPtr& translatedFormat,
- const UlawAlawSourcePtr& buddySource)
- : mLogger(logger),
- mTranslatedFormat(translatedFormat),
- mId(IceUtil::generateUUID()),
- mBuddySource(buddySource)
- {
- mSupportedFormats.push_back(supportedFormat);
- mUlawSink = supportedFormat->name == "ulaw" ? true : false;
- }
-
- 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)
+
+ Logger mLogger;
+ StreamSinkSeq mSinks;
+ FormatSeq mSupportedFormats;
+ std::string mId;
+ };
+
+ typedef IceUtil::Handle<UlawAlawSource> UlawAlawSourcePtr;
+
+ class UlawAlawSink : public StreamSink
{
- FormatPtr supportedFormat = mSupportedFormats.front();
-
- if (inFrame->mediaFormat->name != supportedFormat->name)
+ public:
+ UlawAlawSink(const Logger& logger,
+ const FormatPtr& supportedFormat,
+ const FormatPtr& translatedFormat,
+ const UlawAlawSourcePtr& buddySource)
+ : mLogger(logger),
+ mTranslatedFormat(translatedFormat),
+ mId(IceUtil::generateUUID()),
+ mBuddySource(buddySource)
{
- mLogger(Error) << "Cannot translate frame because the format is not what we expect.";
- throw UnsupportedMediaFormatException();
+ mSupportedFormats.push_back(supportedFormat);
+ mUlawSink = supportedFormat->name == "ulaw" ? true : false;
}
-
- FramePtr outFrame;
- Ice::ByteSeq outPayload;
- outPayload.resize(inFrame->payload.size());
-
- if (mUlawSink)
+
+ unsigned char ulaw2alaw(unsigned char ulaw)
{
- std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::ulaw2alaw), this));
+ return pjmedia_ulaw2alaw(ulaw);
}
- else
+
+ unsigned char alaw2ulaw(unsigned char alaw)
{
- std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::alaw2ulaw), this));
+ return pjmedia_alaw2ulaw(alaw);
}
+
+ FramePtr translate(const FramePtr inFrame)
+ {
+ FormatPtr supportedFormat = mSupportedFormats.front();
+
+ if (inFrame->mediaFormat->name != supportedFormat->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 (mUlawSink)
+ {
+ std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::ulaw2alaw), this));
+ }
+ else
+ {
+ std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::alaw2ulaw), this));
+ }
+
+ outFrame = new Frame(mTranslatedFormat, outPayload);
+ return outFrame;
+ }
+
+ void write(const FrameSeq& frames, const Ice::Current&)
+ {
+ FrameSeq translated;
+ translated.resize(frames.size());
+ std::transform(frames.begin(), frames.end(), translated.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::translate), this));
+ mBuddySource->distributeToSinks(translated);
+ }
+
+ 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;
+ FormatPtr mTranslatedFormat;
+ StreamSourcePrx mSource;
+ std::string mId;
+ UlawAlawSourcePtr mBuddySource;
+ /**
+ * Tells if we are operating as a ulaw sink.
+ * If false, then we are operating as an alaw sink.
+ */
+ bool mUlawSink;
+ };
+
+ typedef IceUtil::Handle<UlawAlawSink> UlawAlawSinkPtr;
- outFrame = new Frame(mTranslatedFormat, outPayload);
- return outFrame;
- }
-
- void write(const FrameSeq& frames, const Ice::Current&)
- {
- FrameSeq translated;
- translated.resize(frames.size());
- std::transform(frames.begin(), frames.end(), translated.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::translate), this));
- mBuddySource->distributeToSinks(translated);
- }
-
- 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;
- FormatPtr mTranslatedFormat;
- StreamSourcePrx mSource;
- std::string mId;
- UlawAlawSourcePtr mBuddySource;
- /**
- * Tells if we are operating as a ulaw sink.
- * If false, then we are operating as an alaw sink.
- */
- bool mUlawSink;
-};
-
-typedef IceUtil::Handle<UlawAlawSink> UlawAlawSinkPtr;
-
-class UlawAlawOperation : public MediaOperation
-{
public:
UlawAlawOperation(const Ice::ObjectAdapterPtr& adapter,
const Logger& logger,
commit 009368e35449285f5c20d8151407bb23b1e57281
Author: Mark Michelson <mmichelson at digium.com>
Date: Wed Aug 17 11:37:21 2011 -0500
Get rid of a bit more cruft and add a comment talking about how a format visitor would be handy.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 413e1a3..5fa2276 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -122,14 +122,7 @@ public:
mBuddySource(buddySource)
{
mSupportedFormats.push_back(supportedFormat);
- if (G711uLAWPtr::dynamicCast(supportedFormat))
- {
- mUlawSink = true;
- }
- else
- {
- mUlawSink = false;
- }
+ mUlawSink = supportedFormat->name == "ulaw" ? true : false;
}
unsigned char ulaw2alaw(unsigned char ulaw)
@@ -316,6 +309,10 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
G711uLAWPtr sinkUlaw = 0;
G711aLAWPtr sinkAlaw = 0;
+ //XXX This would be an opportune time to use the
+ //format visitor. Currently, I cannot do this because
+ //the various slice-defined formats reside in a different
+ //file from the format visitor declaration.
for (FormatSeq::iterator sourceIter = sourceFormats.begin();
sourceIter != sourceFormats.end(); ++sourceIter)
{
commit aa8e6a3a0c209cae9efd059ce2d2134b00cc255c
Author: Mark Michelson <mmichelson at digium.com>
Date: Wed Aug 17 11:19:36 2011 -0500
Get rid of some cruft in the Source.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index fd2b758..413e1a3 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -41,14 +41,6 @@ public:
mId(IceUtil::generateUUID())
{
mSupportedFormats.push_back(format);
- if (G711uLAWPtr::dynamicCast(format))
- {
- mUlawSource = true;
- }
- else
- {
- mUlawSource = false;
- }
}
void addSink(const StreamSinkPrx& sink, const Ice::Current&)
@@ -84,22 +76,9 @@ public:
//the format we actually are using matches what is expected.
void requestFormat(const FormatPtr& format, const Ice::Current&)
{
- bool ulawRequested;
- if (G711uLAWPtr::dynamicCast(format))
- {
- ulawRequested = true;
- }
- else if (G711aLAWPtr::dynamicCast(format))
- {
- ulawRequested = false;
- }
- else
- {
- mLogger(Error) << "Format requested is not one supported by this source";
- throw MediaFormatSwitchException();
- }
+ FormatPtr supportedFormat = mSupportedFormats.front();
- if ((mUlawSource && !ulawRequested) || (!mUlawSource && ulawRequested))
+ if (supportedFormat->name != format->name)
{
mLogger(Error) << "Format requested is not the one supported by this source";
throw MediaFormatSwitchException();
@@ -126,11 +105,6 @@ public:
StreamSinkSeq mSinks;
FormatSeq mSupportedFormats;
std::string mId;
- /**
- * Tells if we are operating as a ulaw source.
- * If false, then we are operating as an alaw source.
- */
- bool mUlawSource;
};
typedef IceUtil::Handle<UlawAlawSource> UlawAlawSourcePtr;
commit 17bf150b5a86989922a70bfe3208bbe4a2671fc7
Author: Mark Michelson <mmichelson at digium.com>
Date: Wed Aug 17 11:13:24 2011 -0500
Change an assertion to an exception since it fits this way better.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index a33fa58..fd2b758 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -328,7 +328,11 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
{
//Since we're expected to do a translation, we'd better
//be given both a source and a sink.
- assert (sink != 0 && source != 0);
+ if (sink == 0 || source == 0)
+ {
+ mLogger(Error) << "Cannot create translator because or a missing source or sink";
+ throw UnsupportedMediaFormatException();
+ }
FormatSeq sourceFormats = source->getFormats();
FormatSeq sinkFormats = sink->getFormats();
commit adcc9988cb7eb283dcd2ecda5974d3a06290a3fc
Author: Mark Michelson <mmichelson at digium.com>
Date: Wed Aug 17 11:09:31 2011 -0500
* Fix up the setup of translators. I had it backwards.
* Add a ulaw2alaw translation test.
* Make the sources and sinks a per-test fixture.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 82593a6..a33fa58 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -139,13 +139,16 @@ class UlawAlawSink : public StreamSink
{
public:
UlawAlawSink(const Logger& logger,
- const FormatPtr& format,
+ const FormatPtr& supportedFormat,
+ const FormatPtr& translatedFormat,
const UlawAlawSourcePtr& buddySource)
- : mLogger(logger), mId(IceUtil::generateUUID()),
+ : mLogger(logger),
+ mTranslatedFormat(translatedFormat),
+ mId(IceUtil::generateUUID()),
mBuddySource(buddySource)
{
- mSupportedFormats.push_back(format);
- if (G711uLAWPtr::dynamicCast(format))
+ mSupportedFormats.push_back(supportedFormat);
+ if (G711uLAWPtr::dynamicCast(supportedFormat))
{
mUlawSink = true;
}
@@ -169,33 +172,33 @@ public:
{
FormatPtr supportedFormat = mSupportedFormats.front();
+ if (inFrame->mediaFormat->name != supportedFormat->name)
+ {
+ mLogger(Error) << "Cannot translate frame because the format is not what we expect.";
+ throw UnsupportedMediaFormatException();
+ }
+
FramePtr outFrame;
Ice::ByteSeq outPayload;
- outPayload.reserve(inFrame->payload.size());
+ outPayload.resize(inFrame->payload.size());
- mLogger(Debug) << "Are we a ulaw sink? " << (mUlawSink ? "yes" : "no");
-
- if (mUlawSink && G711uLAWPtr::dynamicCast(inFrame->mediaFormat))
+ if (mUlawSink)
{
std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::ulaw2alaw), this));
}
- else if (!mUlawSink && G711aLAWPtr::dynamicCast(inFrame->mediaFormat))
- {
- std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::alaw2ulaw), this));
- }
else
{
- mLogger(Error) << "Cannot translate frame because the format is not what we expect.";
- throw UnsupportedMediaFormatException();
+ std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::alaw2ulaw), this));
}
- outFrame = new Frame(supportedFormat, outPayload);
+ outFrame = new Frame(mTranslatedFormat, outPayload);
return outFrame;
}
void write(const FrameSeq& frames, const Ice::Current&)
{
FrameSeq translated;
+ translated.resize(frames.size());
std::transform(frames.begin(), frames.end(), translated.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::translate), this));
mBuddySource->distributeToSinks(translated);
}
@@ -222,6 +225,7 @@ public:
Logger mLogger;
FormatSeq mSupportedFormats;
+ FormatPtr mTranslatedFormat;
StreamSourcePrx mSource;
std::string mId;
UlawAlawSourcePtr mBuddySource;
@@ -244,7 +248,7 @@ public:
: mAdapter(adapter),
mLogger(logger),
mSource(new UlawAlawSource(mLogger, sourceFormat)),
- mSink(new UlawAlawSink(mLogger, sinkFormat, mSource))
+ mSink(new UlawAlawSink(mLogger, sinkFormat, sourceFormat, mSource))
{
}
@@ -373,13 +377,14 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
{
//Their source is ulaw and their sink is alaw.
//This means we are translating from ulaw to alaw.
+ //This means that we need a ulaw sink and an alaw source.
mLogger(Debug) << "Creating ulaw to alaw translator";
- operation = new UlawAlawOperation(mAdapter, mLogger, sourceUlaw, sinkAlaw);
+ operation = new UlawAlawOperation(mAdapter, mLogger, sinkAlaw, sourceUlaw);
}
else if (sourceAlaw && sinkUlaw)
{
mLogger(Debug) << "Creating alaw to ulaw translator";
- operation = new UlawAlawOperation(mAdapter, mLogger, sourceAlaw, sinkUlaw);
+ operation = new UlawAlawOperation(mAdapter, mLogger, sinkUlaw, sourceAlaw);
}
else
{
diff --git a/test/TestMediaOperations.cpp b/test/TestMediaOperations.cpp
index 2d1e64e..8f51761 100644
--- a/test/TestMediaOperations.cpp
+++ b/test/TestMediaOperations.cpp
@@ -73,10 +73,13 @@ public:
StreamSourcePrx ulawSourceProxy;
FramePtr sampleAlawFrame;
+
+ FramePtr sampleUlawFrame;
};
static SharedTestData Testbed;
+//Copied from Asterisk's ex_alaw.h file
static uint8_t sampleAlaw[] =
{
0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15,
@@ -91,6 +94,20 @@ static uint8_t sampleAlaw[] =
0x90, 0xc0, 0xc3, 0xc6, 0xc9, 0xcc, 0xcf, 0xd2,
};
+//Copied from Asterisk's ex_ulaw.h file
+static uint8_t sampleUlaw[] = {
+ 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15,
+ 0x10, 0x18, 0x1b, 0x1e, 0x21, 0x24, 0x27, 0x2a,
+ 0x20, 0x2d, 0x30, 0x33, 0x36, 0x39, 0x3c, 0x3f,
+ 0x30, 0x42, 0x45, 0x48, 0x4b, 0x4e, 0x51, 0x54,
+ 0x40, 0x57, 0x5a, 0x5d, 0x60, 0x63, 0x66, 0x69,
+ 0x50, 0x6c, 0x6f, 0x72, 0x75, 0x78, 0x7b, 0x7e,
+ 0x60, 0x81, 0x84, 0x87, 0x8a, 0x8d, 0x90, 0x93,
+ 0x70, 0x96, 0x99, 0x9c, 0x9f, 0xa2, 0xa5, 0xa8,
+ 0x80, 0xab, 0xae, 0xb1, 0xb4, 0xb7, 0xba, 0xbd,
+ 0x90, 0xc0, 0xc3, 0xc6, 0xc9, 0xcc, 0xcf, 0xd2,
+};
+
/**
* Wrapper class around pj_thread_desc.
* (copied from PJSipManager.h in the sip repo)
@@ -187,19 +204,9 @@ struct GlobalIceFixture
Testbed.alaw = new G711aLAW();
Testbed.alaw->name = "alaw";
- Testbed.ulawSink = new TestStreamSink(Testbed.ulaw);
- Testbed.ulawSinkProxy = StreamSinkPrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.ulawSink));
-
- Testbed.alawSink = new TestStreamSink(Testbed.alaw);
- Testbed.alawSinkProxy = StreamSinkPrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.alawSink));
-
- Testbed.ulawSource = new TestStreamSource(Testbed.ulaw);
- Testbed.ulawSourceProxy = StreamSourcePrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.ulawSource));
-
- Testbed.alawSource = new TestStreamSource(Testbed.alaw);
- Testbed.alawSourceProxy = StreamSourcePrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.alawSource));
Testbed.sampleAlawFrame = new Frame(Testbed.alaw, Ice::ByteSeq(sampleAlaw, sampleAlaw + sizeof(sampleAlaw)));
+ Testbed.sampleUlawFrame = new Frame(Testbed.ulaw, Ice::ByteSeq(sampleUlaw, sampleUlaw + sizeof(sampleUlaw)));
}
catch (const Ice::Exception& ex)
{
@@ -227,6 +234,37 @@ struct GlobalIceFixture
BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
+struct PerTestFixture
+{
+public:
+ PerTestFixture()
+ {
+ std::cerr << "Per test fixture constructor called" << std::endl;
+
+ Testbed.ulawSink = new TestStreamSink(Testbed.ulaw);
+ Testbed.ulawSinkProxy = StreamSinkPrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.ulawSink));
+
+ Testbed.alawSink = new TestStreamSink(Testbed.alaw);
+ Testbed.alawSinkProxy = StreamSinkPrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.alawSink));
+
+ Testbed.ulawSource = new TestStreamSource(Testbed.ulaw);
+ Testbed.ulawSourceProxy = StreamSourcePrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.ulawSource));
+
+ Testbed.alawSource = new TestStreamSource(Testbed.alaw);
+ Testbed.alawSourceProxy = StreamSourcePrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.alawSource));
+ }
+ ~PerTestFixture()
+ {
+
+ std::cerr << "Per test fixture destructor called" << std::endl;
+
+ Testbed.adapter->remove(Testbed.ulawSinkProxy->ice_getIdentity());
+ Testbed.adapter->remove(Testbed.alawSinkProxy->ice_getIdentity());
+ Testbed.adapter->remove(Testbed.ulawSourceProxy->ice_getIdentity());
+ Testbed.adapter->remove(Testbed.alawSourceProxy->ice_getIdentity());
+ }
+};
+
MediaOperationServiceLocatorParamsPtr createLocatorParams(
const FormatPtr& inputFormat,
const FormatPtr& outputFormat)
@@ -267,7 +305,7 @@ BOOST_AUTO_TEST_CASE(FindUlawAlawFactory)
}
}
-BOOST_AUTO_TEST_CASE(createMediaOperations)
+BOOST_FIXTURE_TEST_CASE(createMediaOperations, PerTestFixture)
{
MediaOperationServiceLocatorParamsPtr ulawAlawParams = createLocatorParams(Testbed.alaw, Testbed.ulaw);
@@ -296,7 +334,7 @@ BOOST_AUTO_TEST_CASE(createMediaOperations)
}
}
-BOOST_AUTO_TEST_CASE(translateAlawToUlaw)
+BOOST_FIXTURE_TEST_CASE(translateAlawToUlaw, PerTestFixture)
{
size_t numFramesToTranslate = 10;
MediaOperationServiceLocatorParamsPtr alaw2ulawParams = createLocatorParams(Testbed.alaw, Testbed.ulaw);
@@ -331,7 +369,7 @@ BOOST_AUTO_TEST_CASE(translateAlawToUlaw)
}
//Since everything is synchronous, the Testbed's ulawSink should
- //have a frame in it now. We need to make sure that it got
+ //have frames in it now. We need to make sure that it got
//the right number of frames and that the payloads are the
//proper size...we can't reliably check for accuracy though.
FrameSeq framesWritten = Testbed.ulawSink->getFrames();
@@ -343,10 +381,65 @@ BOOST_AUTO_TEST_CASE(translateAlawToUlaw)
iter != framesWritten.end(); ++iter)
{
//Each frame written by the translator should be ulaw
- BOOST_CHECK(G711uLAWPtr::dynamicCast(*iter) != 0);
+ BOOST_CHECK(G711uLAWPtr::dynamicCast((*iter)->mediaFormat) != 0);
//Each frame written by the translator should be the
//same size as the frame read in.
BOOST_CHECK((*iter)->payload.size() == Testbed.sampleAlawFrame->payload.size());
}
}
+
+BOOST_FIXTURE_TEST_CASE(translateUlawToAlaw, PerTestFixture)
+{
+ size_t numFramesToTranslate = 10;
+ MediaOperationServiceLocatorParamsPtr ulaw2alawParams = createLocatorParams(Testbed.ulaw, Testbed.alaw);
+
+ MediaOperationFactoryPrx ulaw2alawFactory =
+ MediaOperationFactoryPrx::checkedCast(Testbed.locator->locate(ulaw2alawParams));
+
+ MediaOperationPrx ulaw2alawTranslator =
+ ulaw2alawFactory->createMediaOperation(Testbed.ulawSourceProxy, Testbed.alawSinkProxy);
+
+ StreamSinkPrx translateSink = ulaw2alawTranslator->getSink();
+ StreamSourcePrx translateSource = ulaw2alawTranslator->getSource();
+
+ Testbed.ulawSourceProxy->addSink(translateSink);
+ Testbed.alawSinkProxy->setSource(translateSource);
+
+ translateSource->addSink(Testbed.alawSinkProxy);
+ translateSink->setSource(Testbed.ulawSourceProxy);
+
+ //We'll feed a few of the sample frames in.
+ FrameSeq ulawFrames(numFramesToTranslate, Testbed.sampleUlawFrame);
+
+ try
+ {
+ Testbed.ulawSource->feedFramesToTranslator(ulawFrames);
+ }
+ catch (const Ice::Exception& ex)
+ {
+ std::stringstream str;
+ str << "Exception caught trying to translate ulaw frames: " << ex.what();
+ BOOST_FAIL(str.str());
+ }
+
+ //Since everything is synchronous, the Testbed's ulawSink should
+ //have frames in it now. We need to make sure that it got
+ //the right number of frames and that the payloads are the
+ //proper size...we can't reliably check for accuracy though.
+ FrameSeq framesWritten = Testbed.alawSink->getFrames();
+
+ //There should be an equal number of frames written as was read
+ BOOST_CHECK(framesWritten.size() == numFramesToTranslate);
+
+ for (FrameSeq::iterator iter = framesWritten.begin();
+ iter != framesWritten.end(); ++iter)
+ {
+ //Each frame written by the translator should be ulaw
+ BOOST_CHECK(G711aLAWPtr::dynamicCast((*iter)->mediaFormat) != 0);
+
+ //Each frame written by the translator should be the
+ //same size as the frame read in.
+ BOOST_CHECK((*iter)->payload.size() == Testbed.sampleUlawFrame->payload.size());
+ }
+}
commit 7b168b92fe152d79259fb404b84263a8362fbfad
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Aug 16 18:42:10 2011 -0500
Add more tests.
Translation test is failing now.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index e95660d..82593a6 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -173,6 +173,8 @@ public:
Ice::ByteSeq outPayload;
outPayload.reserve(inFrame->payload.size());
+ mLogger(Debug) << "Are we a ulaw sink? " << (mUlawSink ? "yes" : "no");
+
if (mUlawSink && G711uLAWPtr::dynamicCast(inFrame->mediaFormat))
{
std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::ulaw2alaw), this));
@@ -339,10 +341,12 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
G711aLAWPtr alaw;
if ((ulaw = G711uLAWPtr::dynamicCast(*sourceIter)))
{
+ mLogger(Debug) << "Set source Ulaw...";
sourceUlaw = ulaw;
}
else if ((alaw = G711aLAWPtr::dynamicCast(*sourceIter)))
{
+ mLogger(Debug) << "Set source Alaw...";
sourceAlaw = alaw;
}
}
@@ -354,10 +358,12 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
G711aLAWPtr alaw;
if ((ulaw = G711uLAWPtr::dynamicCast(*sinkIter)))
{
+ mLogger(Debug) << "Set sink ulaw...";
sinkUlaw = ulaw;
}
else if ((alaw = G711aLAWPtr::dynamicCast(*sinkIter)))
{
+ mLogger(Debug) << "Set sink alaw...";
sinkAlaw = alaw;
}
}
@@ -365,6 +371,8 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
UlawAlawOperationPtr operation;
if (sourceUlaw && sinkAlaw)
{
+ //Their source is ulaw and their sink is alaw.
+ //This means we are translating from ulaw to alaw.
mLogger(Debug) << "Creating ulaw to alaw translator";
operation = new UlawAlawOperation(mAdapter, mLogger, sourceUlaw, sinkAlaw);
}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 760e20c..d30992f 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -12,3 +12,10 @@ astscf_component_build_icebox(media_operations_core_test)
astscf_test_icebox(media_operations_core_test config/test_component.config)
target_link_libraries(media_operations_core_test astscf-ice-util-cpp)
+
+pjproject_link(media_operations_core_test pjsip)
+pjproject_link(media_operations_core_test pjmedia)
+pjproject_link(media_operations_core_test pjnath)
+pjproject_link(media_operations_core_test pjlib-util)
+pjproject_link(media_operations_core_test pjlib)
+
diff --git a/test/TestMediaOperations.cpp b/test/TestMediaOperations.cpp
index a23f116..2d1e64e 100644
--- a/test/TestMediaOperations.cpp
+++ b/test/TestMediaOperations.cpp
@@ -18,6 +18,11 @@
#define BOOST_TEST_NO_MAIN
+//including this (on my system) throws an
+//error saying that we have to enable C++0x
+//support. So for now I'm just including stdint.h
+//#include <cstdint>
+#include <stdint.h>
#include <Ice/Ice.h>
#include <IceBox/IceBox.h>
@@ -28,6 +33,8 @@
#include <AsteriskSCF/Media/Formats/AudioFormats.h>
#include <boost/test/debug.hpp>
+#include <boost/thread/mutex.hpp>
+#include <pjlib.h>
#include "TestStreamSink.h"
#include "TestStreamSource.h"
@@ -64,10 +71,88 @@ public:
TestStreamSourcePtr ulawSource;
StreamSourcePrx ulawSourceProxy;
+
+ FramePtr sampleAlawFrame;
};
static SharedTestData Testbed;
+static uint8_t sampleAlaw[] =
+{
+ 0x00, 0x03, 0x06, 0x09, 0x0c, 0x0f, 0x12, 0x15,
+ 0x10, 0x18, 0x1b, 0x1e, 0x21, 0x24, 0x27, 0x2a,
+ 0x20, 0x2d, 0x30, 0x33, 0x36, 0x39, 0x3c, 0x3f,
+ 0x30, 0x42, 0x45, 0x48, 0x4b, 0x4e, 0x51, 0x54,
+ 0x40, 0x57, 0x5a, 0x5d, 0x60, 0x63, 0x66, 0x69,
+ 0x50, 0x6c, 0x6f, 0x72, 0x75, 0x78, 0x7b, 0x7e,
+ 0x60, 0x81, 0x84, 0x87, 0x8a, 0x8d, 0x90, 0x93,
+ 0x70, 0x96, 0x99, 0x9c, 0x9f, 0xa2, 0xa5, 0xa8,
+ 0x80, 0xab, 0xae, 0xb1, 0xb4, 0xb7, 0xba, 0xbd,
+ 0x90, 0xc0, 0xc3, 0xc6, 0xc9, 0xcc, 0xcf, 0xd2,
+};
+
+/**
+ * Wrapper class around pj_thread_desc.
+ * (copied from PJSipManager.h in the sip repo)
+ */
+class ThreadDescWrapper
+{
+public:
+ /**
+ * pjthread thread description information, must persist for the life of the thread
+ */
+ pj_thread_desc mDesc;
+};
+
+/**
+ * Type definition used to create a smart pointer for the above.
+ */
+typedef boost::shared_ptr<ThreadDescWrapper> ThreadDescWrapperPtr;
+
+/**
+ * Implementation of the Ice::ThreadNotification class.
+ * (copied from PJSipManager.h in the sip repo)
+ */
+class pjlibHook : public Ice::ThreadNotification
+{
+public:
+ /**
+ * Implementation of the start function which is called when a thread starts.
+ */
+ void start()
+ {
+ ThreadDescWrapperPtr wrapper = ThreadDescWrapperPtr(new ThreadDescWrapper());
+ pj_thread_t *thread;
+ pj_thread_register("ICE Thread", wrapper->mDesc, &thread);
+ {
+ boost::lock_guard<boost::mutex> lock(mLock);
+ pjThreads.insert(std::make_pair(thread, wrapper));
+ }
+ }
+
+ /**
+ * Implementation of the stop function which is called when a thread stops.
+ */
+ void stop()
+ {
+ if (pj_thread_is_registered())
+ {
+ boost::lock_guard<boost::mutex> lock(mLock);
+ pjThreads.erase(pj_thread_this());
+ }
+ }
+
+private:
+ /**
+ * A map containing thread lifetime persistent data.
+ */
+ std::map<pj_thread_t*, ThreadDescWrapperPtr> pjThreads;
+ /**
+ * Mutex to protect the map
+ */
+ boost::mutex mLock;
+};
+
struct GlobalIceFixture
{
GlobalIceFixture()
@@ -80,7 +165,13 @@ struct GlobalIceFixture
int status = 0;
try
{
- Testbed.communicator = IceBoxTestEnv.communicator;
+ //Since our translator makes calls to pjlib, we have to
+ //register our threads with pjlib
+ Ice::InitializationData id;
+ id.threadHook = new pjlibHook();
+ id.properties = IceBoxTestEnv.communicator->getProperties();
+ Testbed.communicator = Ice::initialize(id);
+
Testbed.adapter =
Testbed.communicator->createObjectAdapterWithEndpoints("Adapter", "default");
Testbed.adapter->activate();
@@ -107,6 +198,8 @@ struct GlobalIceFixture
Testbed.alawSource = new TestStreamSource(Testbed.alaw);
Testbed.alawSourceProxy = StreamSourcePrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.alawSource));
+
+ Testbed.sampleAlawFrame = new Frame(Testbed.alaw, Ice::ByteSeq(sampleAlaw, sampleAlaw + sizeof(sampleAlaw)));
}
catch (const Ice::Exception& ex)
{
@@ -184,7 +277,7 @@ BOOST_AUTO_TEST_CASE(createMediaOperations)
try
{
//The factory we got from the service locator is capable of creating both alaw to ulaw
- //translators and ulaw to alaw translators, even though we searched for the factory with
+ //translators and ulaw to alaw translators even though we searched for the factory with
//an input of alaw and an output of ulaw.
MediaOperationPrx alaw2ulawTranslator =
ulawAlawFactory->createMediaOperation(Testbed.alawSourceProxy, Testbed.ulawSinkProxy);
@@ -203,8 +296,9 @@ BOOST_AUTO_TEST_CASE(createMediaOperations)
}
}
-BOOST_AUTO_TEST_CASE(translateUlawToAlaw)
+BOOST_AUTO_TEST_CASE(translateAlawToUlaw)
{
+ size_t numFramesToTranslate = 10;
MediaOperationServiceLocatorParamsPtr alaw2ulawParams = createLocatorParams(Testbed.alaw, Testbed.ulaw);
MediaOperationFactoryPrx alaw2ulawFactory =
@@ -212,4 +306,47 @@ BOOST_AUTO_TEST_CASE(translateUlawToAlaw)
MediaOperationPrx alaw2ulawTranslator =
alaw2ulawFactory->createMediaOperation(Testbed.alawSourceProxy, Testbed.ulawSinkProxy);
+
+ StreamSinkPrx translateSink = alaw2ulawTranslator->getSink();
+ StreamSourcePrx translateSource = alaw2ulawTranslator->getSource();
+
+ Testbed.alawSourceProxy->addSink(translateSink);
+ Testbed.ulawSinkProxy->setSource(translateSource);
+
+ translateSource->addSink(Testbed.ulawSinkProxy);
+ translateSink->setSource(Testbed.alawSourceProxy);
+
+ //We'll feed a few of the sample frames in.
+ FrameSeq alawFrames(numFramesToTranslate, Testbed.sampleAlawFrame);
+
+ try
+ {
+ Testbed.alawSource->feedFramesToTranslator(alawFrames);
+ }
+ catch (const Ice::Exception& ex)
+ {
+ std::stringstream str;
+ str << "Exception caught trying to translate alaw frames: " << ex.what();
+ BOOST_FAIL(str.str());
+ }
+
+ //Since everything is synchronous, the Testbed's ulawSink should
+ //have a frame in it now. We need to make sure that it got
+ //the right number of frames and that the payloads are the
+ //proper size...we can't reliably check for accuracy though.
+ FrameSeq framesWritten = Testbed.ulawSink->getFrames();
+
+ //There should be an equal number of frames written as was read
+ BOOST_CHECK(framesWritten.size() == numFramesToTranslate);
+
+ for (FrameSeq::iterator iter = framesWritten.begin();
+ iter != framesWritten.end(); ++iter)
+ {
+ //Each frame written by the translator should be ulaw
+ BOOST_CHECK(G711uLAWPtr::dynamicCast(*iter) != 0);
+
+ //Each frame written by the translator should be the
+ //same size as the frame read in.
+ BOOST_CHECK((*iter)->payload.size() == Testbed.sampleAlawFrame->payload.size());
+ }
}
diff --git a/test/TestStreamSink.cpp b/test/TestStreamSink.cpp
index 9e9ceb7..1abf36c 100644
--- a/test/TestStreamSink.cpp
+++ b/test/TestStreamSink.cpp
@@ -25,15 +25,15 @@ TestStreamSink::TestStreamSink(const FormatPtr& format)
/**
* Implementation of the write method which doesn't really do anything yet.
*/
-void TestStreamSink::write(const AsteriskSCF::Media::V1::FrameSeq&, const Ice::Current&)
+void TestStreamSink::write(const FrameSeq& frames, const Ice::Current&)
{
- //XXX Figure out what to do here...
+ mFrames.insert(mFrames.end(), frames.begin(), frames.end());
}
/**
* Implementation of the setSource method which just stores the source away for later retrieval.
*/
-void TestStreamSink::setSource(const AsteriskSCF::Media::V1::StreamSourcePrx& source, const Ice::Current&)
+void TestStreamSink::setSource(const StreamSourcePrx& source, const Ice::Current&)
{
mSource = source;
}
@@ -61,3 +61,8 @@ std::string TestStreamSink::getId(const Ice::Current&)
{
return "TestStreamSink";
}
+
+FrameSeq TestStreamSink::getFrames()
+{
+ return mFrames;
+}
diff --git a/test/TestStreamSink.h b/test/TestStreamSink.h
index 33f5f24..4278950 100644
--- a/test/TestStreamSink.h
+++ b/test/TestStreamSink.h
@@ -46,12 +46,21 @@ public:
* Implementation of the getId which currently returns a hardcoded value.
*/
std::string getId(const Ice::Current&);
+
+ /**
+ * Get all frames that have been written to the sink
+ */
+ AsteriskSCF::Media::V1::FrameSeq getFrames();
private:
AsteriskSCF::Media::V1::FormatSeq mSupportedFormats;
/**
* The source that is sending us media.
*/
AsteriskSCF::Media::V1::StreamSourcePrx mSource;
+ /**
+ * The frames that have been written to the sink
+ */
+ AsteriskSCF::Media::V1::FrameSeq mFrames;
};
typedef IceUtil::Handle<TestStreamSink> TestStreamSinkPtr;
diff --git a/test/TestStreamSource.cpp b/test/TestStreamSource.cpp
index 9c1f764..456b107 100644
--- a/test/TestStreamSource.cpp
+++ b/test/TestStreamSource.cpp
@@ -69,3 +69,12 @@ std::string TestStreamSource::getId(const Ice::Current&)
void TestStreamSource::requestFormat(const FormatPtr&, const Ice::Current&)
{
}
+
+void TestStreamSource::feedFramesToTranslator(const FrameSeq frames)
+{
+ for (StreamSinkSeq::iterator iter = mSinks.begin();
+ iter != mSinks.end(); ++iter)
+ {
+ (*iter)->write(frames);
+ }
+}
diff --git a/test/TestStreamSource.h b/test/TestStreamSource.h
index 58b4828..782db7b 100644
--- a/test/TestStreamSource.h
+++ b/test/TestStreamSource.h
@@ -51,6 +51,15 @@ public:
* Does nothing. Don't call this you silly head!
*/
void requestFormat(const AsteriskSCF::Media::V1::FormatPtr&, const Ice::Current&);
+
+ /**
+ * Writes the given frame to all its sinks. Presumably, there will
+ * be only one sink, and it will be a translator
+ *
+ * Since this writes to sinks, the caller of this function needs to be
+ * prepared to catch potential exceptions.
+ */
+ void feedFramesToTranslator(const AsteriskSCF::Media::V1::FrameSeq frames);
private:
AsteriskSCF::Media::V1::FormatSeq mSupportedFormats;
/**
commit e5e68464d21a287a86f439a00bb16900df297b4a
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Aug 16 17:13:16 2011 -0500
Expand the test to find a translator to find translators in both directions.
diff --git a/test/TestMediaOperations.cpp b/test/TestMediaOperations.cpp
index 89d2d91..a23f116 100644
--- a/test/TestMediaOperations.cpp
+++ b/test/TestMediaOperations.cpp
@@ -53,9 +53,17 @@ public:
StreamSinkPrx ulawSinkProxy;
+ TestStreamSinkPtr alawSink;
+
+ StreamSinkPrx alawSinkProxy;
+
TestStreamSourcePtr alawSource;
StreamSourcePrx alawSourceProxy;
+
+ TestStreamSourcePtr ulawSource;
+
+ StreamSourcePrx ulawSourceProxy;
};
static SharedTestData Testbed;
@@ -91,6 +99,12 @@ struct GlobalIceFixture
Testbed.ulawSink = new TestStreamSink(Testbed.ulaw);
Testbed.ulawSinkProxy = StreamSinkPrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.ulawSink));
+ Testbed.alawSink = new TestStreamSink(Testbed.alaw);
+ Testbed.alawSinkProxy = StreamSinkPrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.alawSink));
+
+ Testbed.ulawSource = new TestStreamSource(Testbed.ulaw);
+ Testbed.ulawSourceProxy = StreamSourcePrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.ulawSource));
+
Testbed.alawSource = new TestStreamSource(Testbed.alaw);
Testbed.alawSourceProxy = StreamSourcePrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.alawSource));
}
@@ -162,17 +176,24 @@ BOOST_AUTO_TEST_CASE(FindUlawAlawFactory)
BOOST_AUTO_TEST_CASE(createMediaOperations)
{
- MediaOperationServiceLocatorParamsPtr alaw2ulawParams = createLocatorParams(Testbed.alaw, Testbed.ulaw);
+ MediaOperationServiceLocatorParamsPtr ulawAlawParams = createLocatorParams(Testbed.alaw, Testbed.ulaw);
- MediaOperationFactoryPrx alaw2ulawFactory =
- MediaOperationFactoryPrx::checkedCast(Testbed.locator->locate(alaw2ulawParams));
+ MediaOperationFactoryPrx ulawAlawFactory =
+ MediaOperationFactoryPrx::checkedCast(Testbed.locator->locate(ulawAlawParams));
try
{
+ //The factory we got from the service locator is capable of creating both alaw to ulaw
+ //translators and ulaw to alaw translators, even though we searched for the factory with
+ //an input of alaw and an output of ulaw.
MediaOperationPrx alaw2ulawTranslator =
- alaw2ulawFactory->createMediaOperation(Testbed.alawSourceProxy, Testbed.ulawSinkProxy);
+ ulawAlawFactory->createMediaOperation(Testbed.alawSourceProxy, Testbed.ulawSinkProxy);
+
+ MediaOperationPrx ulaw2alawTranslator =
+ ulawAlawFactory->createMediaOperation(Testbed.ulawSourceProxy, Testbed.alawSinkProxy);
BOOST_CHECK(alaw2ulawTranslator != 0);
+ BOOST_CHECK(ulaw2alawTranslator != 0);
}
catch (const Ice::Exception& ex)
{
@@ -182,9 +203,13 @@ BOOST_AUTO_TEST_CASE(createMediaOperations)
}
}
-#if 0
BOOST_AUTO_TEST_CASE(translateUlawToAlaw)
- TestStreamSinkPtr ulawSink(new TestStreamSink(Testbed.ulaw));
- TestStreamSourcePtr alawSource(new TestStreamSource(Testbed.alaw));
+{
+ MediaOperationServiceLocatorParamsPtr alaw2ulawParams = createLocatorParams(Testbed.alaw, Testbed.ulaw);
+
+ MediaOperationFactoryPrx alaw2ulawFactory =
+ MediaOperationFactoryPrx::checkedCast(Testbed.locator->locate(alaw2ulawParams));
+
+ MediaOperationPrx alaw2ulawTranslator =
+ alaw2ulawFactory->createMediaOperation(Testbed.alawSourceProxy, Testbed.ulawSinkProxy);
}
-#endif
commit b8ea848130764caa518ee2ca602b8fc8dacc126c
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Aug 16 17:03:05 2011 -0500
Add some more items to the global shared data:
* Ulaw and Alaw formats
* Ulaw sink and its proxy
* Alaw source and its proxy
diff --git a/test/TestMediaOperations.cpp b/test/TestMediaOperations.cpp
index 4550461..89d2d91 100644
--- a/test/TestMediaOperations.cpp
+++ b/test/TestMediaOperations.cpp
@@ -40,8 +40,22 @@ struct SharedTestData
{
public:
Ice::CommunicatorPtr communicator;
+
Ice::ObjectAdapterPtr adapter;
+
ServiceLocatorPrx locator;
+
+ FormatPtr ulaw;
+
+ FormatPtr alaw;
+
+ TestStreamSinkPtr ulawSink;
+
+ StreamSinkPrx ulawSinkProxy;
+
+ TestStreamSourcePtr alawSource;
+
+ StreamSourcePrx alawSourceProxy;
};
static SharedTestData Testbed;
@@ -67,6 +81,18 @@ struct GlobalIceFixture
if (!Testbed.locator) {
throw "Invalid service locator proxy";
}
+
+ Testbed.ulaw = new G711uLAW();
+ Testbed.ulaw->name = "ulaw";
+
+ Testbed.alaw = new G711aLAW();
+ Testbed.alaw->name = "alaw";
+
+ Testbed.ulawSink = new TestStreamSink(Testbed.ulaw);
+ Testbed.ulawSinkProxy = StreamSinkPrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.ulawSink));
+
+ Testbed.alawSource = new TestStreamSource(Testbed.alaw);
+ Testbed.alawSourceProxy = StreamSourcePrx::uncheckedCast(Testbed.adapter->addWithUUID(Testbed.alawSource));
}
catch (const Ice::Exception& ex)
{
@@ -94,34 +120,29 @@ struct GlobalIceFixture
BOOST_GLOBAL_FIXTURE(GlobalIceFixture);
+MediaOperationServiceLocatorParamsPtr createLocatorParams(
+ const FormatPtr& inputFormat,
+ const FormatPtr& outputFormat)
+{
+ MediaOperationAttributes attrs;
+ attrs.inputFormat = inputFormat;
+ attrs.outputFormat = outputFormat;
+ MediaOperationServiceLocatorParamsPtr params = new MediaOperationServiceLocatorParams();
+ params->category = "MediaOperation";
+ params->service = "translator";
+ params->attributes.push_back(attrs);
+
+ return params;
+}
+
BOOST_AUTO_TEST_CASE(FindUlawAlawFactory)
{
try
{
- FormatPtr ulaw = new G711uLAW();
- ulaw->name = "ulaw";
- FormatPtr alaw = new G711aLAW();
- alaw->name = "alaw";
-
- MediaOperationAttributes ulaw2alaw;
- ulaw2alaw.inputFormat = ulaw;
- ulaw2alaw.outputFormat = alaw;
- MediaOperationServiceLocatorParamsPtr ulaw2alawParams = new MediaOperationServiceLocatorParams();
- ulaw2alawParams->category = "MediaOperation";
- ulaw2alawParams->service = "translator";
- ulaw2alawParams->attributes.push_back(ulaw2alaw);
-
- MediaOperationAttributes alaw2ulaw;
- alaw2ulaw.inputFormat = alaw;
- alaw2ulaw.outputFormat = ulaw;
- MediaOperationServiceLocatorParamsPtr alaw2ulawParams = new MediaOperationServiceLocatorParams();
- alaw2ulawParams->category = "MediaOperation";
- alaw2ulawParams->service = "translator";
- alaw2ulawParams->attributes.push_back(alaw2ulaw);
-
- //Okay, so both of these should result in our factory being returned...
-
- std::cerr << "Calling locate?" << std::endl;
+ MediaOperationServiceLocatorParamsPtr ulaw2alawParams = createLocatorParams(Testbed.ulaw, Testbed.alaw);
+ MediaOperationServiceLocatorParamsPtr alaw2ulawParams = createLocatorParams(Testbed.alaw, Testbed.ulaw);
+
+ // Both of these should result in our factory being returned...
MediaOperationFactoryPrx ulaw2alawFactory =
MediaOperationFactoryPrx::checkedCast(Testbed.locator->locate(ulaw2alawParams));
@@ -133,17 +154,37 @@ BOOST_AUTO_TEST_CASE(FindUlawAlawFactory)
}
catch (const std::exception& ex)
{
- std::cerr << "Exception caught while attempting to locate the UlawAlawFactory: " << ex.what() << std::endl;
- BOOST_FAIL("Exception caught while attempting to locate the UlawAlawFactory");
+ std::stringstream str;
+ str << "Exception caught while attempting to locate the UlawAlawFactory: " << ex.what();
+ BOOST_FAIL(str.str());
}
}
-BOOST_AUTO_TEST_CASE(translateUlawToAlaw)
+BOOST_AUTO_TEST_CASE(createMediaOperations)
{
- FormatPtr ulaw(new G711uLAW);
- ulaw->name = "ulaw";
- FormatPtr alaw(new G711aLAW);
- alaw->name = "alaw";
- TestStreamSinkPtr ulawSink(new TestStreamSink(ulaw));
- TestStreamSourcePtr alawSource(new TestStreamSource(alaw));
+ MediaOperationServiceLocatorParamsPtr alaw2ulawParams = createLocatorParams(Testbed.alaw, Testbed.ulaw);
+
+ MediaOperationFactoryPrx alaw2ulawFactory =
+ MediaOperationFactoryPrx::checkedCast(Testbed.locator->locate(alaw2ulawParams));
+
+ try
+ {
+ MediaOperationPrx alaw2ulawTranslator =
+ alaw2ulawFactory->createMediaOperation(Testbed.alawSourceProxy, Testbed.ulawSinkProxy);
+
+ BOOST_CHECK(alaw2ulawTranslator != 0);
+ }
+ catch (const Ice::Exception& ex)
+ {
+ std::stringstream str;
+ str << "Exception caught while attempting to create an alaw to ulaw translator: " << ex.what();
+ BOOST_FAIL(str.str());
+ }
+}
+
+#if 0
+BOOST_AUTO_TEST_CASE(translateUlawToAlaw)
+ TestStreamSinkPtr ulawSink(new TestStreamSink(Testbed.ulaw));
+ TestStreamSourcePtr alawSource(new TestStreamSource(Testbed.alaw));
}
+#endif
commit b4c89ab73ab53c53d69fb123ca79ea569fd9470f
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Aug 16 16:43:10 2011 -0500
Add a test source and sink to use so I can try some translation tests.
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index b1e5189..760e20c 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -2,6 +2,10 @@ include_directories(${astscf-ice-util-cpp_dir}/include)
astscf_component_init(media_operations_core_test)
astscf_component_add_files(media_operations_core_test TestMediaOperations.cpp)
+astscf_component_add_files(media_operations_core_test TestStreamSource.cpp)
+astscf_component_add_files(media_operations_core_test TestStreamSource.h)
+astscf_component_add_files(media_operations_core_test TestStreamSink.cpp)
+astscf_component_add_files(media_operations_core_test TestStreamSink.h)
astscf_component_add_boost_libraries(media_operations_core_test unit_test_framework)
astscf_component_add_slice_collection_libraries(media_operations_core_test ASTSCF)
astscf_component_build_icebox(media_operations_core_test)
diff --git a/test/TestMediaOperations.cpp b/test/TestMediaOperations.cpp
index 5bd2d68..4550461 100644
--- a/test/TestMediaOperations.cpp
+++ b/test/TestMediaOperations.cpp
@@ -1,7 +1,7 @@
/*
* Asterisk SCF -- An open-source communications framework.
*
- * Copyright (C) 2010, Digium, Inc.
+ * Copyright (C) 2011, Digium, Inc.
*
* See http://www.asterisk.org for more information about
* the Asterisk SCF project. Please do not directly contact
@@ -29,6 +29,9 @@
#include <boost/test/debug.hpp>
+#include "TestStreamSink.h"
+#include "TestStreamSource.h"
+
using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::Media::V1;
using namespace AsteriskSCF::Media::Formats::Audio::V1;
@@ -134,3 +137,13 @@ BOOST_AUTO_TEST_CASE(FindUlawAlawFactory)
BOOST_FAIL("Exception caught while attempting to locate the UlawAlawFactory");
}
}
+
+BOOST_AUTO_TEST_CASE(translateUlawToAlaw)
+{
+ FormatPtr ulaw(new G711uLAW);
+ ulaw->name = "ulaw";
+ FormatPtr alaw(new G711aLAW);
+ alaw->name = "alaw";
+ TestStreamSinkPtr ulawSink(new TestStreamSink(ulaw));
+ TestStreamSourcePtr alawSource(new TestStreamSource(alaw));
+}
diff --git a/test/TestStreamSink.cpp b/test/TestStreamSink.cpp
new file mode 100644
index 0000000..9e9ceb7
--- /dev/null
+++ b/test/TestStreamSink.cpp
@@ -0,0 +1,63 @@
+/*
+ * 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 "TestStreamSink.h"
+
+using namespace AsteriskSCF::Media::V1;
+
+TestStreamSink::TestStreamSink(const FormatPtr& format)
+{
+ mSupportedFormats.push_back(format);
+}
+/**
+ * Implementation of the write method which doesn't really do anything yet.
+ */
+void TestStreamSink::write(const AsteriskSCF::Media::V1::FrameSeq&, const Ice::Current&)
+{
+ //XXX Figure out what to do here...
+}
+
+/**
+ * Implementation of the setSource method which just stores the source away for later retrieval.
+ */
+void TestStreamSink::setSource(const AsteriskSCF::Media::V1::StreamSourcePrx& source, const Ice::Current&)
+{
+ mSource = source;
+}
+
+/**
+ * Implementation of the getSource method which just pulls the source back out.
+ */
+StreamSourcePrx TestStreamSink::getSource(const Ice::Current&)
+{
+ return mSource;
+}
+
+/**
+ * Implementation of the getFormats method which returns... wait for it... no methods!
+ */
+FormatSeq TestStreamSink::getFormats(const Ice::Current&)
+{
+ return mSupportedFormats;
+}
+
+/**
+ * Implementation of the getId which currently returns a hardcoded value.
+ */
+std::string TestStreamSink::getId(const Ice::Current&)
+{
+ return "TestStreamSink";
+}
diff --git a/test/TestStreamSink.h b/test/TestStreamSink.h
new file mode 100644
index 0000000..33f5f24
--- /dev/null
+++ b/test/TestStreamSink.h
@@ -0,0 +1,57 @@
+/*
+ * 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>
+
+class TestStreamSink : public AsteriskSCF::Media::V1::StreamSink
+{
+public:
+ TestStreamSink(const AsteriskSCF::Media::V1::FormatPtr& format);
+
+ /**
+ * Implementation of the write method which doesn't really do anything yet.
+ */
+ void write(const AsteriskSCF::Media::V1::FrameSeq& frames, const Ice::Current&);
+
+ /**
+ * Implementation of the setSource method which just stores the source away for later retrieval.
+ */
+ void setSource(const AsteriskSCF::Media::V1::StreamSourcePrx& source, const Ice::Current&);
+
+ /**
+ * Implementation of the getSource method which just pulls the source back out.
+ */
+ AsteriskSCF::Media::V1::StreamSourcePrx getSource(const Ice::Current&);
+
+ /**
+ * Implementation of the getFormats method which returns... wait for it... no methods!
+ */
+ AsteriskSCF::Media::V1::FormatSeq getFormats(const Ice::Current&);
+
+ /**
+ * Implementation of the getId which currently returns a hardcoded value.
+ */
+ std::string getId(const Ice::Current&);
+private:
+ AsteriskSCF::Media::V1::FormatSeq mSupportedFormats;
+ /**
+ * The source that is sending us media.
+ */
+ AsteriskSCF::Media::V1::StreamSourcePrx mSource;
+};
+
+typedef IceUtil::Handle<TestStreamSink> TestStreamSinkPtr;
diff --git a/test/TestStreamSource.cpp b/test/TestStreamSource.cpp
new file mode 100644
index 0000000..9c1f764
... 424 lines suppressed ...
--
asterisk-scf/release/media_operations_core.git
More information about the asterisk-scf-commits
mailing list