[asterisk-scf-commits] asterisk-scf/release/media_operations_core.git branch "master" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Mon Aug 15 17:12:46 CDT 2011
branch "master" has been created
at b7163f64c77deaa71cfaeacaee00e70d9e53c474 (commit)
- Log -----------------------------------------------------------------
commit b7163f64c77deaa71cfaeacaee00e70d9e53c474
Author: Mark Michelson <mmichelson at digium.com>
Date: Mon Aug 15 14:56:30 2011 -0500
Add namespaces.
diff --git a/src/MediaOperationsCore.cpp b/src/MediaOperationsCore.cpp
index 00e3919..0567bf9 100644
--- a/src/MediaOperationsCore.cpp
+++ b/src/MediaOperationsCore.cpp
@@ -30,6 +30,12 @@ namespace
Logger lg = getLoggerFactory().getLogger("AsteriskSCF.MediaOperationsCore");
};
+namespace AsteriskSCF
+{
+
+namespace MediaOperationsCore
+{
+
using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::Media::V1;
@@ -96,3 +102,6 @@ ASTSCF_DLL_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
return new MediaOperationsCoreApp;
}
}
+
+} //end namespace MediaOperationsCore
+} //end namespace AsteriskSCF
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 72b2e37..75e32d3 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -20,6 +20,12 @@
#include <IceUtil/UUID.h>
#include <pjmedia.h>
+namespace AsteriskSCF
+{
+
+namespace MediaOperationsCore
+{
+
using namespace AsteriskSCF::Media::V1;
using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::Media::Formats::Audio::V1;
@@ -227,10 +233,10 @@ public:
typedef IceUtil::Handle<UlawAlawSink> UlawAlawSinkPtr;
-class UlawAlaw : public MediaOperation
+class UlawAlawOperation : public MediaOperation
{
public:
- UlawAlaw(const Ice::ObjectAdapterPtr& adapter,
+ UlawAlawOperation(const Ice::ObjectAdapterPtr& adapter,
const Logger& logger,
const FormatPtr& sourceFormat,
const FormatPtr& sinkFormat)
@@ -284,7 +290,7 @@ public:
StreamSinkPrx mSinkProxy;
};
-typedef IceUtil::Handle<UlawAlaw> UlawAlawPtr;
+typedef IceUtil::Handle<UlawAlawOperation> UlawAlawOperationPtr;
UlawAlawFactory::UlawAlawFactory(const Ice::ObjectAdapterPtr& adapter,
const Logger& logger)
@@ -354,16 +360,16 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
}
}
- UlawAlawPtr operation;
+ UlawAlawOperationPtr operation;
if (sourceUlaw && sinkAlaw)
{
mLogger(Debug) << "Creating ulaw to alaw translator";
- operation = new UlawAlaw(mAdapter, mLogger, sourceUlaw, sinkAlaw);
+ operation = new UlawAlawOperation(mAdapter, mLogger, sourceUlaw, sinkAlaw);
}
else if (sourceAlaw && sinkUlaw)
{
mLogger(Debug) << "Creating alaw to ulaw translator";
- operation = new UlawAlaw(mAdapter, mLogger, sourceAlaw, sinkUlaw);
+ operation = new UlawAlawOperation(mAdapter, mLogger, sourceAlaw, sinkUlaw);
}
else
{
@@ -383,3 +389,6 @@ ServiceLocatorParamsPtr UlawAlawFactory::getLocatorParams()
{
return mLocatorParams;
}
+
+} //end namespace MediaOperationsCore
+} //end namespace AsteriskSCF
diff --git a/src/ulaw_alaw.h b/src/ulaw_alaw.h
index 564fccf..b748ed1 100644
--- a/src/ulaw_alaw.h
+++ b/src/ulaw_alaw.h
@@ -21,6 +21,12 @@
#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
#include <AsteriskSCF/logger.h>
+namespace AsteriskSCF
+{
+
+namespace MediaOperationsCore
+{
+
class UlawAlawFactory : public AsteriskSCF::Media::V1::MediaOperationFactory
{
public:
@@ -53,3 +59,6 @@ private:
};
typedef IceUtil::Handle<UlawAlawFactory> UlawAlawFactoryPtr;
+
+} //end namespace MediaOperationsCore
+} //end namespace AsteriskSCF
commit f5d236af30e1e965ab9753b5ba18734d7c846208
Author: Mark Michelson <mmichelson at digium.com>
Date: Mon Aug 15 14:41:16 2011 -0500
Some cleanup.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 29968f8..72b2e37 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -35,6 +35,14 @@ 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&)
@@ -65,16 +73,29 @@ public:
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();
+ 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();
+ }
- //Translation:
- //If our supported format and the format requested are not the same, then
- //we throw an exception.
- if (!(G711aLAWPtr::dynamicCast(supportedFormat) && G711aLAWPtr::dynamicCast(format)) &&
- !(G711uLAWPtr::dynamicCast(supportedFormat) && G711uLAWPtr::dynamicCast(format)))
+ if ((mUlawSource && !ulawRequested) || (!mUlawSource && ulawRequested))
{
+ mLogger(Error) << "Format requested is not the one supported by this source";
throw MediaFormatSwitchException();
}
}
@@ -99,6 +120,11 @@ 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;
@@ -113,6 +139,14 @@ public:
mBuddySource(buddySource)
{
mSupportedFormats.push_back(format);
+ if (G711uLAWPtr::dynamicCast(format))
+ {
+ mUlawSink = true;
+ }
+ else
+ {
+ mUlawSink = false;
+ }
}
unsigned char ulaw2alaw(unsigned char ulaw)
@@ -132,27 +166,23 @@ public:
FramePtr outFrame;
Ice::ByteSeq outPayload;
outPayload.reserve(inFrame->payload.size());
- if (G711uLAWPtr::dynamicCast(supportedFormat) && G711uLAWPtr::dynamicCast(inFrame->mediaFormat))
+
+ if (mUlawSink && G711uLAWPtr::dynamicCast(inFrame->mediaFormat))
{
- //XXX I wanted to be able to do something like
- //std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), pjmedia_ulaw2alaw);
- //or
- //std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::ptr_fun(&pjmedia_ulaw2alaw));
- //but in both cases, the compiler complains that pjmedia_ulaw2alaw was not declared in this scope. This is why
- //I've used the somewhat odd method I have.
std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::ulaw2alaw), this));
- outFrame = new Frame(new G711aLAW(), outPayload);
+ outFrame = new Frame(supportedFormat, outPayload);
}
- else if (G711aLAWPtr::dynamicCast(supportedFormat) && G711aLAWPtr::dynamicCast(inFrame->mediaFormat))
+ 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));
- outFrame = new Frame(new G711uLAW(), outPayload);
+ outFrame = new Frame(supportedFormat, outPayload);
}
else
{
mLogger(Error) << "Cannot translate frame because the format is not what we expect.";
throw UnsupportedMediaFormatException();
}
+
return outFrame;
}
@@ -188,6 +218,11 @@ public:
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;
diff --git a/src/ulaw_alaw.h b/src/ulaw_alaw.h
index 45f0c31..564fccf 100644
--- a/src/ulaw_alaw.h
+++ b/src/ulaw_alaw.h
@@ -39,7 +39,16 @@ public:
private:
Ice::ObjectAdapterPtr mAdapter;
AsteriskSCF::System::Logging::Logger mLogger;
+ /**
+ * The name of the factory. Used as a GUID for the service locator params
+ * that we register.
+ */
const std::string mName;
+ /**
+ * Attributes of this factory.
+ * Let's the service locator know that we can translate from ulaw to alaw and
+ * from alaw to ulaw.
+ */
AsteriskSCF::Media::V1::MediaOperationServiceLocatorParamsPtr mLocatorParams;
};
commit 0ff7491d56db16677ba9f47e2ff53224192b2bc0
Author: Mark Michelson <mmichelson at digium.com>
Date: Mon Aug 15 13:04:53 2011 -0500
Add logging.
diff --git a/src/MediaOperationsCore.cpp b/src/MediaOperationsCore.cpp
index 8c359b5..00e3919 100644
--- a/src/MediaOperationsCore.cpp
+++ b/src/MediaOperationsCore.cpp
@@ -19,9 +19,17 @@
#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
#include <AsteriskSCF/Media/MediaOperationIf.h>
+#include <AsteriskSCF/logger.h>
#include "ulaw_alaw.h"
+using namespace AsteriskSCF::System::Logging;
+
+namespace
+{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.MediaOperationsCore");
+};
+
using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::Media::V1;
@@ -48,7 +56,8 @@ private:
void MediaOperationsCoreApp::createOperationFactories()
{
- mUlawAlawFactory = new UlawAlawFactory(mAdapter);
+ lg(Debug) << "Creating UlawAlawFactory";
+ mUlawAlawFactory = new UlawAlawFactory(mAdapter, lg);
mUlawAlawFactoryProxy =
MediaOperationFactoryPrx::uncheckedCast(mAdapter->addWithUUID(mUlawAlawFactory));
@@ -74,8 +83,9 @@ void MediaOperationsCoreApp::stop()
{
mAdapter->remove(mUlawAlawFactoryProxy->ice_getIdentity());
}
- catch (const Ice::Exception&)
+ catch (const Ice::Exception& ex)
{
+ lg(Error) << "Error attempting to remove a factory from the adapter" << ex.what();
}
}
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index c67711c..29968f8 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -23,12 +23,16 @@
using namespace AsteriskSCF::Media::V1;
using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::Media::Formats::Audio::V1;
+using namespace AsteriskSCF::System::Logging;
class UlawAlawSource : public StreamSource
{
public:
- UlawAlawSource(const FormatPtr& format) : mId(IceUtil::generateUUID())
+ UlawAlawSource(const Logger& logger,
+ const FormatPtr& format)
+ : mLogger(logger),
+ mId(IceUtil::generateUUID())
{
mSupportedFormats.push_back(format);
}
@@ -80,10 +84,18 @@ public:
for (StreamSinkSeq::iterator iter = mSinks.begin();
iter != mSinks.end(); ++iter)
{
- (*iter)->write(translatedFrames);
+ 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;
@@ -94,9 +106,10 @@ typedef IceUtil::Handle<UlawAlawSource> UlawAlawSourcePtr;
class UlawAlawSink : public StreamSink
{
public:
- UlawAlawSink(const FormatPtr& format,
+ UlawAlawSink(const Logger& logger,
+ const FormatPtr& format,
const UlawAlawSourcePtr& buddySource)
- : mId(IceUtil::generateUUID()),
+ : mLogger(logger), mId(IceUtil::generateUUID()),
mBuddySource(buddySource)
{
mSupportedFormats.push_back(format);
@@ -137,6 +150,7 @@ public:
}
else
{
+ mLogger(Error) << "Cannot translate frame because the format is not what we expect.";
throw UnsupportedMediaFormatException();
}
return outFrame;
@@ -169,6 +183,7 @@ public:
return mId;
}
+ Logger mLogger;
FormatSeq mSupportedFormats;
StreamSourcePrx mSource;
std::string mId;
@@ -181,11 +196,13 @@ class UlawAlaw : public MediaOperation
{
public:
UlawAlaw(const Ice::ObjectAdapterPtr& adapter,
+ const Logger& logger,
const FormatPtr& sourceFormat,
const FormatPtr& sinkFormat)
: mAdapter(adapter),
- mSource(new UlawAlawSource(sourceFormat)),
- mSink(new UlawAlawSink(sinkFormat, mSource))
+ mLogger(logger),
+ mSource(new UlawAlawSource(mLogger, sourceFormat)),
+ mSink(new UlawAlawSink(mLogger, sinkFormat, mSource))
{
}
@@ -217,12 +234,14 @@ public:
mAdapter->remove(mSinkProxy->ice_getIdentity());
mAdapter->remove(mProxy->ice_getIdentity());
}
- catch (Ice::Exception&)
+ catch (Ice::Exception& ex)
{
+ mLogger(Error) << "Exception caught attempting to remove objects from adapter: " << ex.what();
}
}
Ice::ObjectAdapterPtr mAdapter;
+ Logger mLogger;
MediaOperationPrx mProxy;
UlawAlawSourcePtr mSource;
StreamSourcePrx mSourceProxy;
@@ -232,8 +251,10 @@ public:
typedef IceUtil::Handle<UlawAlaw> UlawAlawPtr;
-UlawAlawFactory::UlawAlawFactory(const Ice::ObjectAdapterPtr& adapter)
+UlawAlawFactory::UlawAlawFactory(const Ice::ObjectAdapterPtr& adapter,
+ const Logger& logger)
: mAdapter(adapter),
+ mLogger(logger),
mName("UlawAlawFactory"),
mLocatorParams(new MediaOperationServiceLocatorParams)
{
@@ -301,14 +322,17 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
UlawAlawPtr operation;
if (sourceUlaw && sinkAlaw)
{
- operation = new UlawAlaw(mAdapter, sourceUlaw, sinkAlaw);
+ mLogger(Debug) << "Creating ulaw to alaw translator";
+ operation = new UlawAlaw(mAdapter, mLogger, sourceUlaw, sinkAlaw);
}
else if (sourceAlaw && sinkUlaw)
{
- operation = new UlawAlaw(mAdapter, sourceAlaw, sinkUlaw);
+ mLogger(Debug) << "Creating alaw to ulaw translator";
+ operation = new UlawAlaw(mAdapter, mLogger, sourceAlaw, sinkUlaw);
}
else
{
+ mLogger(Error) << "Cannot create translator because source and sink do not have supported formats";
throw UnsupportedMediaFormatException();
}
operation->activate();
diff --git a/src/ulaw_alaw.h b/src/ulaw_alaw.h
index 9ba163a..45f0c31 100644
--- a/src/ulaw_alaw.h
+++ b/src/ulaw_alaw.h
@@ -19,11 +19,13 @@
#include <Ice/Ice.h>
#include <AsteriskSCF/Media/MediaOperationIf.h>
#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+#include <AsteriskSCF/logger.h>
class UlawAlawFactory : public AsteriskSCF::Media::V1::MediaOperationFactory
{
public:
- UlawAlawFactory(const Ice::ObjectAdapterPtr&);
+ UlawAlawFactory(const Ice::ObjectAdapterPtr&,
+ const AsteriskSCF::System::Logging::Logger& logger);
AsteriskSCF::Media::V1::MediaOperationPrx createMediaOperation(
const AsteriskSCF::Media::V1::StreamSourcePrx& source,
@@ -36,6 +38,7 @@ public:
private:
Ice::ObjectAdapterPtr mAdapter;
+ AsteriskSCF::System::Logging::Logger mLogger;
const std::string mName;
AsteriskSCF::Media::V1::MediaOperationServiceLocatorParamsPtr mLocatorParams;
};
commit d159c91b3543e138d70c49cc49d78a624c79b742
Author: Mark Michelson <mmichelson at digium.com>
Date: Mon Aug 15 11:59:16 2011 -0500
Throw an exception in createMediaOperation.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index d1e3fc9..c67711c 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -309,7 +309,7 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
}
else
{
- //XXX ummmmm throw an exception?
+ throw UnsupportedMediaFormatException();
}
operation->activate();
return operation->mProxy;
commit 5209f94968f413c94416553fc43eeb3aa183ab70
Author: Mark Michelson <mmichelson at digium.com>
Date: Mon Aug 15 11:37:20 2011 -0500
Deal with the fact that sources and sinks passed into createMediaOperation may have multiple formats.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 49e5aef..d1e3fc9 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -256,30 +256,63 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
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.
+ assert (sink != 0 && source != 0);
+
FormatSeq sourceFormats = source->getFormats();
FormatSeq sinkFormats = sink->getFormats();
- //The goal here is to determine if we're going to translate
- //from ulaw to alaw or from alaw to ulaw.
- //
- //Presumably the source formats should contain one and the
- //sink formats should contain the other.
- //
- //XXX Just to get things compiling for now, we'll assume
- //a single format on the source and sink.
+ G711uLAWPtr sourceUlaw = 0;
+ G711aLAWPtr sourceAlaw = 0;
+ G711uLAWPtr sinkUlaw = 0;
+ G711aLAWPtr sinkAlaw = 0;
- FormatPtr sourceFormat = sourceFormats.front();
- FormatPtr sinkFormat = sinkFormats.front();
+ for (FormatSeq::iterator sourceIter = sourceFormats.begin();
+ sourceIter != sourceFormats.end(); ++sourceIter)
+ {
+ G711uLAWPtr ulaw;
+ G711aLAWPtr alaw;
+ if ((ulaw = G711uLAWPtr::dynamicCast(*sourceIter)))
+ {
+ sourceUlaw = ulaw;
+ }
+ else if ((alaw = G711aLAWPtr::dynamicCast(*sourceIter)))
+ {
+ sourceAlaw = alaw;
+ }
+ }
- if (!(G711aLAWPtr::dynamicCast(sourceFormat) && G711uLAWPtr::dynamicCast(sinkFormat)) &&
- !(G711uLAWPtr::dynamicCast(sourceFormat) && G711aLAWPtr::dynamicCast(sinkFormat)))
+ for (FormatSeq::iterator sinkIter = sinkFormats.begin();
+ sinkIter != sinkFormats.end(); ++sinkIter)
{
- //XXX invalid...what do we do?
+ G711uLAWPtr ulaw;
+ G711aLAWPtr alaw;
+ if ((ulaw = G711uLAWPtr::dynamicCast(*sinkIter)))
+ {
+ sinkUlaw = ulaw;
+ }
+ else if ((alaw = G711aLAWPtr::dynamicCast(*sinkIter)))
+ {
+ sinkAlaw = alaw;
+ }
}
- UlawAlawPtr uToA(new UlawAlaw(mAdapter, sourceFormat, sinkFormat));
- uToA->activate();
- return uToA->mProxy;
+ UlawAlawPtr operation;
+ if (sourceUlaw && sinkAlaw)
+ {
+ operation = new UlawAlaw(mAdapter, sourceUlaw, sinkAlaw);
+ }
+ else if (sourceAlaw && sinkUlaw)
+ {
+ operation = new UlawAlaw(mAdapter, sourceAlaw, sinkUlaw);
+ }
+ else
+ {
+ //XXX ummmmm throw an exception?
+ }
+ operation->activate();
+ return operation->mProxy;
}
const std::string& UlawAlawFactory::getName()
commit 9409cacadf22a183be6f9b695c094ece990a8942
Author: Mark Michelson <mmichelson at digium.com>
Date: Mon Aug 15 11:00:41 2011 -0500
Now we can translate in both directions.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 0ec37bf..49e5aef 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -24,13 +24,13 @@ using namespace AsteriskSCF::Media::V1;
using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::Media::Formats::Audio::V1;
-class AlawSource : public StreamSource
+class UlawAlawSource : public StreamSource
{
public:
- AlawSource() : mId(IceUtil::generateUUID())
+ UlawAlawSource(const FormatPtr& format) : mId(IceUtil::generateUUID())
{
- mSupportedFormats.push_back(new G711aLAW());
+ mSupportedFormats.push_back(format);
}
void addSink(const StreamSinkPrx& sink, const Ice::Current&)
@@ -63,9 +63,13 @@ public:
void requestFormat(const FormatPtr& format, const Ice::Current&)
{
- //We can only support a single format.
- G711aLAWPtr alaw = G711aLAWPtr::dynamicCast(format);
- if (!alaw)
+ FormatPtr supportedFormat = mSupportedFormats.front();
+
+ //Translation:
+ //If our supported format and the format requested are not the same, then
+ //we throw an exception.
+ if (!(G711aLAWPtr::dynamicCast(supportedFormat) && G711aLAWPtr::dynamicCast(format)) &&
+ !(G711uLAWPtr::dynamicCast(supportedFormat) && G711uLAWPtr::dynamicCast(format)))
{
throw MediaFormatSwitchException();
}
@@ -85,16 +89,17 @@ public:
std::string mId;
};
-typedef IceUtil::Handle<AlawSource> AlawSourcePtr;
+typedef IceUtil::Handle<UlawAlawSource> UlawAlawSourcePtr;
-class UlawSink : public StreamSink
+class UlawAlawSink : public StreamSink
{
public:
- UlawSink(const AlawSourcePtr& buddySource)
+ UlawAlawSink(const FormatPtr& format,
+ const UlawAlawSourcePtr& buddySource)
: mId(IceUtil::generateUUID()),
- mAlawSource(buddySource)
+ mBuddySource(buddySource)
{
- mSupportedFormats.push_back(new G711uLAW());
+ mSupportedFormats.push_back(format);
}
unsigned char ulaw2alaw(unsigned char ulaw)
@@ -102,26 +107,46 @@ public:
return pjmedia_ulaw2alaw(ulaw);
}
- FramePtr translate(FramePtr ulaw)
+ unsigned char alaw2ulaw(unsigned char alaw)
+ {
+ return pjmedia_alaw2ulaw(alaw);
+ }
+
+ FramePtr translate(FramePtr inFrame)
{
- Ice::ByteSeq alawPayload;
- //XXX I wanted to be able to do something like
- //std::transform(ulaw->payload.begin(), ulaw->payload.end(), alawPayload.begin(), pjmedia_ulaw2alaw);
- //or
- //std::transform(ulaw->payload.begin(), ulaw->payload.end(), alawPayload.begin(), std::ptr_fun(&pjmedia_ulaw2alaw));
- //but in both cases, the compiler complains that pjmedia_ulaw2alaw was not declared in this scope. This is why
- //I've used the somewhat odd method I have.
- std::transform(ulaw->payload.begin(), ulaw->payload.end(), alawPayload.begin(), std::bind1st(std::mem_fun(&UlawSink::ulaw2alaw), this));
-
- FramePtr alaw(new Frame(new G711aLAW(), alawPayload));
- return alaw;
+ FormatPtr supportedFormat = mSupportedFormats.front();
+
+ FramePtr outFrame;
+ Ice::ByteSeq outPayload;
+ outPayload.reserve(inFrame->payload.size());
+ if (G711uLAWPtr::dynamicCast(supportedFormat) && G711uLAWPtr::dynamicCast(inFrame->mediaFormat))
+ {
+ //XXX I wanted to be able to do something like
+ //std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), pjmedia_ulaw2alaw);
+ //or
+ //std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::ptr_fun(&pjmedia_ulaw2alaw));
+ //but in both cases, the compiler complains that pjmedia_ulaw2alaw was not declared in this scope. This is why
+ //I've used the somewhat odd method I have.
+ std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::ulaw2alaw), this));
+ outFrame = new Frame(new G711aLAW(), outPayload);
+ }
+ else if (G711aLAWPtr::dynamicCast(supportedFormat) && G711aLAWPtr::dynamicCast(inFrame->mediaFormat))
+ {
+ std::transform(inFrame->payload.begin(), inFrame->payload.end(), outPayload.begin(), std::bind1st(std::mem_fun(&UlawAlawSink::alaw2ulaw), this));
+ outFrame = new Frame(new G711uLAW(), outPayload);
+ }
+ else
+ {
+ throw UnsupportedMediaFormatException();
+ }
+ return outFrame;
}
void write(const FrameSeq& frames, const Ice::Current&)
{
FrameSeq translated;
- std::transform(frames.begin(), frames.end(), translated.begin(), std::bind1st(std::mem_fun(&UlawSink::translate), this));
- mAlawSource->distributeToSinks(translated);
+ 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&)
@@ -147,18 +172,20 @@ public:
FormatSeq mSupportedFormats;
StreamSourcePrx mSource;
std::string mId;
- AlawSourcePtr mAlawSource;
+ UlawAlawSourcePtr mBuddySource;
};
-typedef IceUtil::Handle<UlawSink> UlawSinkPtr;
+typedef IceUtil::Handle<UlawAlawSink> UlawAlawSinkPtr;
class UlawAlaw : public MediaOperation
{
public:
- UlawAlaw(const Ice::ObjectAdapterPtr& adapter)
+ UlawAlaw(const Ice::ObjectAdapterPtr& adapter,
+ const FormatPtr& sourceFormat,
+ const FormatPtr& sinkFormat)
: mAdapter(adapter),
- mSource(new AlawSource),
- mSink(new UlawSink(mSource))
+ mSource(new UlawAlawSource(sourceFormat)),
+ mSink(new UlawAlawSink(sinkFormat, mSource))
{
}
@@ -197,41 +224,14 @@ public:
Ice::ObjectAdapterPtr mAdapter;
MediaOperationPrx mProxy;
- AlawSourcePtr mSource;
+ UlawAlawSourcePtr mSource;
StreamSourcePrx mSourceProxy;
- UlawSinkPtr mSink;
+ UlawAlawSinkPtr mSink;
StreamSinkPrx mSinkProxy;
};
typedef IceUtil::Handle<UlawAlaw> UlawAlawPtr;
-class AlawToUlaw : public MediaOperation
-{
-public:
- AlawToUlaw(const Ice::ObjectAdapterPtr& adapter)
- : mAdapter(adapter) { }
-
- StreamSourcePrx getSource(const Ice::Current&)
- {
- //stub
- return 0;
- }
- StreamSinkPrx getSink(const Ice::Current&)
- {
- //stub
- return 0;
- }
- void destroy(const Ice::Current&)
- {
- //stub
- }
-
- Ice::ObjectAdapterPtr mAdapter;
- MediaOperationPrx mProxy;
-};
-
-typedef IceUtil::Handle<AlawToUlaw> AlawToUlawPtr;
-
UlawAlawFactory::UlawAlawFactory(const Ice::ObjectAdapterPtr& adapter)
: mAdapter(adapter),
mName("UlawAlawFactory"),
@@ -252,11 +252,32 @@ UlawAlawFactory::UlawAlawFactory(const Ice::ObjectAdapterPtr& adapter)
}
MediaOperationPrx UlawAlawFactory::createMediaOperation(
- const StreamSourcePrx&,
- const StreamSinkPrx&,
+ const StreamSourcePrx& source,
+ const StreamSinkPrx& sink,
const Ice::Current&)
{
- UlawAlawPtr uToA(new UlawAlaw(mAdapter));
+ FormatSeq sourceFormats = source->getFormats();
+ FormatSeq sinkFormats = sink->getFormats();
+
+ //The goal here is to determine if we're going to translate
+ //from ulaw to alaw or from alaw to ulaw.
+ //
+ //Presumably the source formats should contain one and the
+ //sink formats should contain the other.
+ //
+ //XXX Just to get things compiling for now, we'll assume
+ //a single format on the source and sink.
+
+ FormatPtr sourceFormat = sourceFormats.front();
+ FormatPtr sinkFormat = sinkFormats.front();
+
+ if (!(G711aLAWPtr::dynamicCast(sourceFormat) && G711uLAWPtr::dynamicCast(sinkFormat)) &&
+ !(G711uLAWPtr::dynamicCast(sourceFormat) && G711aLAWPtr::dynamicCast(sinkFormat)))
+ {
+ //XXX invalid...what do we do?
+ }
+
+ UlawAlawPtr uToA(new UlawAlaw(mAdapter, sourceFormat, sinkFormat));
uToA->activate();
return uToA->mProxy;
}
commit 95c7d73e1f459d95b185adaae3fbdfd6fbe39983
Author: Mark Michelson <mmichelson at digium.com>
Date: Mon Aug 15 09:36:00 2011 -0500
Resolve compiler error when trying to use std::transform to translate samples.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 63519a1..0ec37bf 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -97,10 +97,21 @@ public:
mSupportedFormats.push_back(new G711uLAW());
}
+ unsigned char ulaw2alaw(unsigned char ulaw)
+ {
+ return pjmedia_ulaw2alaw(ulaw);
+ }
+
FramePtr translate(FramePtr ulaw)
{
Ice::ByteSeq alawPayload;
- std::transform(ulaw->payload.begin(), ulaw->payload.end(), alawPayload.begin(), pjmedia_ulaw2alaw);
+ //XXX I wanted to be able to do something like
+ //std::transform(ulaw->payload.begin(), ulaw->payload.end(), alawPayload.begin(), pjmedia_ulaw2alaw);
+ //or
+ //std::transform(ulaw->payload.begin(), ulaw->payload.end(), alawPayload.begin(), std::ptr_fun(&pjmedia_ulaw2alaw));
+ //but in both cases, the compiler complains that pjmedia_ulaw2alaw was not declared in this scope. This is why
+ //I've used the somewhat odd method I have.
+ std::transform(ulaw->payload.begin(), ulaw->payload.end(), alawPayload.begin(), std::bind1st(std::mem_fun(&UlawSink::ulaw2alaw), this));
FramePtr alaw(new Frame(new G711aLAW(), alawPayload));
return alaw;
commit 6367cfc4226269ba02793021cc0f91d22f9ccb17
Author: Mark Michelson <mmichelson at digium.com>
Date: Fri Aug 12 17:18:26 2011 -0500
Resolve some compiler errors.
It still complains about the use of pjmedia_ulaw2alaw in a std::transform call...
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 47d0054..3daa16d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -7,4 +7,9 @@ astscf_component_add_files(media_operations_core MediaOperationsCore.cpp)
astscf_component_add_slice_collection_libraries(media_operations_core ASTSCF)
astscf_component_build_icebox(media_operations_core)
target_link_libraries(media_operations_core logging-client)
+
+pjproject_link(media_operations_core pjlib)
+pjproject_link(media_operations_core pjlib-util)
+pjproject_link(media_operations_core pjmedia)
+pjproject_link(media_operations_core pjnath)
astscf_component_install(media_operations_core)
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 0e9d85d..63519a1 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -18,64 +18,12 @@
#include <AsteriskSCF/Media/Formats/AudioFormats.h>
#include <IceUtil/UUID.h>
+#include <pjmedia.h>
using namespace AsteriskSCF::Media::V1;
using namespace AsteriskSCF::Core::Discovery::V1;
using namespace AsteriskSCF::Media::Formats::Audio::V1;
-class UlawSink : public StreamSink
-{
-public:
- UlawSink(const AlawSourcePtr& buddySource)
- : mId(IceUtil::generateUUID()),
- mAlawSource(buddySource)
- {
- mSupportedFormats.push_back(new G711uLaw());
- }
-
- FramePtr translate(FramePtr ulaw)
- {
- Ice::ByteSeq alawPayload;
- std::transform(ulaw->payload.begin(), ulaw->payload.end(), alawPayload.begin(), pjmedia_ulaw2alaw);
-
- FramePtr alaw(new Frame(new G711aLAW(), alawPayload));
- return alaw;
- }
-
- void write(const FrameSeq& frames, const Ice::Current&)
- {
- FrameSeq translated;
- std::transform(frames.begin(), frames.end(), translated.begin(), translate);
- mAlawSource->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;
- }
-
- FormatSeq mSupportedFormats;
- StreamSourcePrx mSource;
- std::string mId;
-};
-
-typedef IceUtil::Handle<UlawSink> UlawSinkPtr;
-
class AlawSource : public StreamSource
{
public:
@@ -119,7 +67,7 @@ public:
G711aLAWPtr alaw = G711aLAWPtr::dynamicCast(format);
if (!alaw)
{
- throw MediaFormatSwitchException;
+ throw MediaFormatSwitchException();
}
}
@@ -139,20 +87,74 @@ public:
typedef IceUtil::Handle<AlawSource> AlawSourcePtr;
+class UlawSink : public StreamSink
+{
+public:
+ UlawSink(const AlawSourcePtr& buddySource)
+ : mId(IceUtil::generateUUID()),
+ mAlawSource(buddySource)
+ {
+ mSupportedFormats.push_back(new G711uLAW());
+ }
+
+ FramePtr translate(FramePtr ulaw)
+ {
+ Ice::ByteSeq alawPayload;
+ std::transform(ulaw->payload.begin(), ulaw->payload.end(), alawPayload.begin(), pjmedia_ulaw2alaw);
+
+ FramePtr alaw(new Frame(new G711aLAW(), alawPayload));
+ return alaw;
+ }
+
+ void write(const FrameSeq& frames, const Ice::Current&)
+ {
+ FrameSeq translated;
+ std::transform(frames.begin(), frames.end(), translated.begin(), std::bind1st(std::mem_fun(&UlawSink::translate), this));
+ mAlawSource->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;
+ }
+
+ FormatSeq mSupportedFormats;
+ StreamSourcePrx mSource;
+ std::string mId;
+ AlawSourcePtr mAlawSource;
+};
+
+typedef IceUtil::Handle<UlawSink> UlawSinkPtr;
+
class UlawAlaw : public MediaOperation
{
public:
UlawAlaw(const Ice::ObjectAdapterPtr& adapter)
: mAdapter(adapter),
- mSink(new UlawSink(this)),
- mSource(new AlawSource)
+ mSource(new AlawSource),
+ mSink(new UlawSink(mSource))
{
}
void activate()
{
mProxy =
- MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(this))
+ MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(this));
mSinkProxy =
StreamSinkPrx::uncheckedCast(mAdapter->addWithUUID(mSink));
mSourceProxy =
@@ -184,10 +186,10 @@ public:
Ice::ObjectAdapterPtr mAdapter;
MediaOperationPrx mProxy;
- UlawSinkPtr mSink;
- StreamSinkPrx mSinkProxy;
AlawSourcePtr mSource;
StreamSourcePrx mSourceProxy;
+ UlawSinkPtr mSink;
+ StreamSinkPrx mSinkProxy;
};
typedef IceUtil::Handle<UlawAlaw> UlawAlawPtr;
commit 3fee67b7a7e0bbbbbfe685c0c9e6180da4e26e06
Author: Mark Michelson <mmichelson at digium.com>
Date: Fri Aug 12 16:51:47 2011 -0500
Implement translation from ulaw to alaw using pjmedia.
This code does not compile at the moment. I shall get it into a working
state some time soon though.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 020d50c..0e9d85d 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -17,6 +17,7 @@
#include "ulaw_alaw.h"
#include <AsteriskSCF/Media/Formats/AudioFormats.h>
+#include <IceUtil/UUID.h>
using namespace AsteriskSCF::Media::V1;
using namespace AsteriskSCF::Core::Discovery::V1;
@@ -25,33 +26,52 @@ using namespace AsteriskSCF::Media::Formats::Audio::V1;
class UlawSink : public StreamSink
{
public:
- void write(const FrameSeq&, const Ice::Current&)
+ UlawSink(const AlawSourcePtr& buddySource)
+ : mId(IceUtil::generateUUID()),
+ mAlawSource(buddySource)
{
- //stub
+ mSupportedFormats.push_back(new G711uLaw());
}
- void setSource(const StreamSourcePrx&, const Ice::Current&)
+ FramePtr translate(FramePtr ulaw)
{
- //stub
+ Ice::ByteSeq alawPayload;
+ std::transform(ulaw->payload.begin(), ulaw->payload.end(), alawPayload.begin(), pjmedia_ulaw2alaw);
+
+ FramePtr alaw(new Frame(new G711aLAW(), alawPayload));
+ return alaw;
+ }
+
+ void write(const FrameSeq& frames, const Ice::Current&)
+ {
+ FrameSeq translated;
+ std::transform(frames.begin(), frames.end(), translated.begin(), translate);
+ mAlawSource->distributeToSinks(translated);
+ }
+
+ void setSource(const StreamSourcePrx& source, const Ice::Current&)
+ {
+ mSource = source;
}
StreamSourcePrx getSource(const Ice::Current&)
{
- //stub
- return 0;
+ return mSource;
}
FormatSeq getFormats(const Ice::Current&)
{
- //stub
- return FormatSeq();
+ return mSupportedFormats;
}
std::string getId(const Ice::Current&)
{
- //stub
- return std::string();
+ return mId;
}
+
+ FormatSeq mSupportedFormats;
+ StreamSourcePrx mSource;
+ std::string mId;
};
typedef IceUtil::Handle<UlawSink> UlawSinkPtr;
@@ -59,38 +79,62 @@ typedef IceUtil::Handle<UlawSink> UlawSinkPtr;
class AlawSource : public StreamSource
{
public:
- void addSink(const StreamSinkPrx&, const Ice::Current&)
+
+ AlawSource() : mId(IceUtil::generateUUID())
{
- //stub
+ mSupportedFormats.push_back(new G711aLAW());
}
- void removeSink(const StreamSinkPrx&, const Ice::Current&)
+ void addSink(const StreamSinkPrx& sink, const Ice::Current&)
{
- //stub
+ 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&)
{
- //stub
- return StreamSinkSeq();
+ return mSinks;
}
FormatSeq getFormats(const Ice::Current&)
{
- //stub
- return FormatSeq();
+ return mSupportedFormats;
}
std::string getId(const Ice::Current&)
{
- //stub
- return std::string();
+ return mId;
}
- void requestFormat(const FormatPtr&, const Ice::Current&)
+ void requestFormat(const FormatPtr& format, const Ice::Current&)
{
- //stub
+ //We can only support a single format.
+ G711aLAWPtr alaw = G711aLAWPtr::dynamicCast(format);
+ if (!alaw)
+ {
+ throw MediaFormatSwitchException;
+ }
+ }
+
+ void distributeToSinks(const FrameSeq& translatedFrames)
+ {
+ for (StreamSinkSeq::iterator iter = mSinks.begin();
+ iter != mSinks.end(); ++iter)
+ {
+ (*iter)->write(translatedFrames);
+ }
}
+
+ StreamSinkSeq mSinks;
+ FormatSeq mSupportedFormats;
+ std::string mId;
};
typedef IceUtil::Handle<AlawSource> AlawSourcePtr;
@@ -99,27 +143,51 @@ class UlawAlaw : public MediaOperation
{
public:
UlawAlaw(const Ice::ObjectAdapterPtr& adapter)
- : mAdapter(adapter) { }
+ : mAdapter(adapter),
+ mSink(new UlawSink(this)),
+ mSource(new AlawSource)
+ {
+ }
+
+ void activate()
+ {
+ mProxy =
+ MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(this))
+ mSinkProxy =
+ StreamSinkPrx::uncheckedCast(mAdapter->addWithUUID(mSink));
+ mSourceProxy =
+ StreamSourcePrx::uncheckedCast(mAdapter->addWithUUID(mSource));
+ }
StreamSourcePrx getSource(const Ice::Current&)
{
- //stub
- return 0;
+ return mSourceProxy;
}
+
StreamSinkPrx getSink(const Ice::Current&)
{
- //stub
- return 0;
+ return mSinkProxy;
}
+
void destroy(const Ice::Current&)
{
- //stub
+ try
+ {
+ mAdapter->remove(mSourceProxy->ice_getIdentity());
+ mAdapter->remove(mSinkProxy->ice_getIdentity());
+ mAdapter->remove(mProxy->ice_getIdentity());
+ }
+ catch (Ice::Exception&)
+ {
+ }
}
Ice::ObjectAdapterPtr mAdapter;
MediaOperationPrx mProxy;
UlawSinkPtr mSink;
+ StreamSinkPrx mSinkProxy;
AlawSourcePtr mSource;
+ StreamSourcePrx mSourceProxy;
};
typedef IceUtil::Handle<UlawAlaw> UlawAlawPtr;
@@ -176,7 +244,7 @@ MediaOperationPrx UlawAlawFactory::createMediaOperation(
const Ice::Current&)
{
UlawAlawPtr uToA(new UlawAlaw(mAdapter));
- uToA->mProxy = MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(uToA));
+ uToA->activate();
return uToA->mProxy;
}
commit 350c33692f653250f4adde32bfff007bed776234
Author: Mark Michelson <mmichelson at digium.com>
Date: Fri Aug 12 11:19:36 2011 -0500
Stub out UlawSink and AlawSource.
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 823682a..020d50c 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -16,8 +16,84 @@
#include "ulaw_alaw.h"
+#include <AsteriskSCF/Media/Formats/AudioFormats.h>
+
using namespace AsteriskSCF::Media::V1;
using namespace AsteriskSCF::Core::Discovery::V1;
+using namespace AsteriskSCF::Media::Formats::Audio::V1;
+
+class UlawSink : public StreamSink
+{
+public:
+ void write(const FrameSeq&, const Ice::Current&)
+ {
+ //stub
+ }
+
+ void setSource(const StreamSourcePrx&, const Ice::Current&)
+ {
+ //stub
+ }
+
+ StreamSourcePrx getSource(const Ice::Current&)
+ {
+ //stub
+ return 0;
+ }
+
+ FormatSeq getFormats(const Ice::Current&)
+ {
+ //stub
+ return FormatSeq();
+ }
+
+ std::string getId(const Ice::Current&)
+ {
+ //stub
+ return std::string();
+ }
+};
+
+typedef IceUtil::Handle<UlawSink> UlawSinkPtr;
+
+class AlawSource : public StreamSource
+{
+public:
+ void addSink(const StreamSinkPrx&, const Ice::Current&)
+ {
+ //stub
+ }
+
+ void removeSink(const StreamSinkPrx&, const Ice::Current&)
+ {
+ //stub
+ }
+
+ StreamSinkSeq getSinks(const Ice::Current&)
+ {
+ //stub
+ return StreamSinkSeq();
+ }
+
+ FormatSeq getFormats(const Ice::Current&)
+ {
+ //stub
+ return FormatSeq();
+ }
+
+ std::string getId(const Ice::Current&)
+ {
+ //stub
+ return std::string();
+ }
+
+ void requestFormat(const FormatPtr&, const Ice::Current&)
+ {
+ //stub
+ }
+};
+
+typedef IceUtil::Handle<AlawSource> AlawSourcePtr;
class UlawAlaw : public MediaOperation
{
@@ -42,6 +118,8 @@ public:
Ice::ObjectAdapterPtr mAdapter;
MediaOperationPrx mProxy;
+ UlawSinkPtr mSink;
+ AlawSourcePtr mSource;
};
typedef IceUtil::Handle<UlawAlaw> UlawAlawPtr;
@@ -74,7 +152,23 @@ public:
typedef IceUtil::Handle<AlawToUlaw> AlawToUlawPtr;
UlawAlawFactory::UlawAlawFactory(const Ice::ObjectAdapterPtr& adapter)
- : mAdapter(adapter), mName("UlawAlawFactory") { }
+ : mAdapter(adapter),
+ mName("UlawAlawFactory"),
+ mLocatorParams(new MediaOperationServiceLocatorParams)
+{
+ MediaOperationAttributes ulawToAlaw;
+ ulawToAlaw.inputFormat = new G711uLAW();
+ ulawToAlaw.outputFormat = new G711aLAW();
+ ulawToAlaw.cost = 100; //XXX COST?
+
+ MediaOperationAttributes alawToUlaw;
+ alawToUlaw.inputFormat = new G711aLAW();
+ alawToUlaw.outputFormat = new G711uLAW();
+ alawToUlaw.cost = 100; //XXX COST?
+
+ mLocatorParams->attributes.push_back(ulawToAlaw);
+ mLocatorParams->attributes.push_back(alawToUlaw);
+}
MediaOperationPrx UlawAlawFactory::createMediaOperation(
const StreamSourcePrx&,
commit 6cd6052bd0f9989d0e8d74ac300121ef9b25c6f3
Author: Mark Michelson <mmichelson at digium.com>
Date: Thu Aug 11 17:56:58 2011 -0500
Reduce ulaw<->alaw conversion to one factory that can produce two types of operations.
diff --git a/src/MediaOperationsCore.cpp b/src/MediaOperationsCore.cpp
index 8fd4af8..8c359b5 100644
--- a/src/MediaOperationsCore.cpp
+++ b/src/MediaOperationsCore.cpp
@@ -41,26 +41,20 @@ private:
ServiceLocatorManagementPrx mManagement;
Ice::ObjectAdapterPtr mAdapter;
- UlawToAlawFactoryPtr mUlawToAlawFactory;
- MediaOperationFactoryPrx mUlawToAlawFactoryProxy;
-
- AlawToUlawFactoryPtr mAlawToUlawFactory;
- MediaOperationFactoryPrx mAlawToUlawFactoryProxy;
+ UlawAlawFactoryPtr mUlawAlawFactory;
+ MediaOperationFactoryPrx mUlawAlawFactoryProxy;
+ ServiceManagementPrx mUlawAlawServiceManagement;
};
void MediaOperationsCoreApp::createOperationFactories()
{
- mUlawToAlawFactory = new UlawToAlawFactory(mAdapter);
- mUlawToAlawFactoryProxy =
- MediaOperationFactoryPrx::uncheckedCast(mAdapter->addWithUUID(mUlawToAlawFactory));
-
- mManagement->addService(mUlawToAlawFactoryProxy, mUlawToAlawFactory->getName());
-
- mAlawToUlawFactory = new AlawToUlawFactory(mAdapter);
- mAlawToUlawFactoryProxy =
- MediaOperationFactoryPrx::uncheckedCast(mAdapter->addWithUUID(mAlawToUlawFactory));
+ mUlawAlawFactory = new UlawAlawFactory(mAdapter);
+ mUlawAlawFactoryProxy =
+ MediaOperationFactoryPrx::uncheckedCast(mAdapter->addWithUUID(mUlawAlawFactory));
- mManagement->addService(mAlawToUlawFactoryProxy, mAlawToUlawFactory->getName());
+ mUlawAlawServiceManagement =
+ mManagement->addService(mUlawAlawFactoryProxy, mUlawAlawFactory->getName());
+ mUlawAlawServiceManagement->addLocatorParams(mUlawAlawFactory->getLocatorParams(), mUlawAlawFactory->getName());
}
void MediaOperationsCoreApp::start(
@@ -78,8 +72,7 @@ void MediaOperationsCoreApp::stop()
{
try
{
- mAdapter->remove(mUlawToAlawFactoryProxy->ice_getIdentity());
- mAdapter->remove(mAlawToUlawFactoryProxy->ice_getIdentity());
+ mAdapter->remove(mUlawAlawFactoryProxy->ice_getIdentity());
}
catch (const Ice::Exception&)
{
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index bead256..823682a 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -17,11 +17,12 @@
#include "ulaw_alaw.h"
using namespace AsteriskSCF::Media::V1;
+using namespace AsteriskSCF::Core::Discovery::V1;
-class UlawToAlaw : public MediaOperation
+class UlawAlaw : public MediaOperation
{
public:
- UlawToAlaw(const Ice::ObjectAdapterPtr& adapter)
+ UlawAlaw(const Ice::ObjectAdapterPtr& adapter)
: mAdapter(adapter) { }
StreamSourcePrx getSource(const Ice::Current&)
@@ -43,25 +44,7 @@ public:
MediaOperationPrx mProxy;
};
-typedef IceUtil::Handle<UlawToAlaw> UlawToAlawPtr;
-
-UlawToAlawFactory::UlawToAlawFactory(const Ice::ObjectAdapterPtr& adapter)
- : mAdapter(adapter), mName("UlawToAlawFactory") { }
-
-MediaOperationPrx UlawToAlawFactory::createMediaOperation(
- const StreamSourcePrx&,
- const StreamSinkPrx&,
- const Ice::Current&)
-{
- UlawToAlawPtr uToA(new UlawToAlaw(mAdapter));
- uToA->mProxy = MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(uToA));
- return uToA->mProxy;
-}
-
-const std::string& UlawToAlawFactory::getName()
-{
- return mName;
-}
+typedef IceUtil::Handle<UlawAlaw> UlawAlawPtr;
class AlawToUlaw : public MediaOperation
{
@@ -90,20 +73,25 @@ public:
typedef IceUtil::Handle<AlawToUlaw> AlawToUlawPtr;
-AlawToUlawFactory::AlawToUlawFactory(const Ice::ObjectAdapterPtr& adapter)
- : mAdapter(adapter), mName("AlawToUlawFactory") { }
+UlawAlawFactory::UlawAlawFactory(const Ice::ObjectAdapterPtr& adapter)
+ : mAdapter(adapter), mName("UlawAlawFactory") { }
-MediaOperationPrx AlawToUlawFactory::createMediaOperation(
+MediaOperationPrx UlawAlawFactory::createMediaOperation(
const StreamSourcePrx&,
const StreamSinkPrx&,
const Ice::Current&)
{
- AlawToUlawPtr aToU(new AlawToUlaw(mAdapter));
- aToU->mProxy = MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(aToU));
- return aToU->mProxy;
+ UlawAlawPtr uToA(new UlawAlaw(mAdapter));
+ uToA->mProxy = MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(uToA));
+ return uToA->mProxy;
}
-const std::string& AlawToUlawFactory::getName()
+const std::string& UlawAlawFactory::getName()
{
return mName;
}
+
+ServiceLocatorParamsPtr UlawAlawFactory::getLocatorParams()
+{
+ return mLocatorParams;
+}
diff --git a/src/ulaw_alaw.h b/src/ulaw_alaw.h
index c87ffac..9ba163a 100644
--- a/src/ulaw_alaw.h
+++ b/src/ulaw_alaw.h
@@ -18,11 +18,12 @@
#include <Ice/Ice.h>
#include <AsteriskSCF/Media/MediaOperationIf.h>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
-class UlawToAlawFactory : public AsteriskSCF::Media::V1::MediaOperationFactory
+class UlawAlawFactory : public AsteriskSCF::Media::V1::MediaOperationFactory
{
public:
- UlawToAlawFactory(const Ice::ObjectAdapterPtr&);
+ UlawAlawFactory(const Ice::ObjectAdapterPtr&);
AsteriskSCF::Media::V1::MediaOperationPrx createMediaOperation(
const AsteriskSCF::Media::V1::StreamSourcePrx& source,
@@ -31,28 +32,12 @@ public:
const std::string& getName();
-private:
- Ice::ObjectAdapterPtr mAdapter;
- const std::string mName;
-};
-
-typedef IceUtil::Handle<UlawToAlawFactory> UlawToAlawFactoryPtr;
-
-class AlawToUlawFactory : public AsteriskSCF::Media::V1::MediaOperationFactory
-{
-public:
- AlawToUlawFactory(const Ice::ObjectAdapterPtr&);
-
- AsteriskSCF::Media::V1::MediaOperationPrx createMediaOperation(
- const AsteriskSCF::Media::V1::StreamSourcePrx& source,
- const AsteriskSCF::Media::V1::StreamSinkPrx& sink,
- const Ice::Current&);
-
- const std::string& getName();
+ AsteriskSCF::Core::Discovery::V1::ServiceLocatorParamsPtr getLocatorParams();
private:
Ice::ObjectAdapterPtr mAdapter;
const std::string mName;
+ AsteriskSCF::Media::V1::MediaOperationServiceLocatorParamsPtr mLocatorParams;
};
-typedef IceUtil::Handle<AlawToUlawFactory> AlawToUlawFactoryPtr;
+typedef IceUtil::Handle<UlawAlawFactory> UlawAlawFactoryPtr;
commit 5bc5eac64311343b11c1cbf7cb2997a013d465c2
Author: Mark Michelson <mmichelson at digium.com>
Date: Thu Aug 11 17:38:29 2011 -0500
Add service to the service locator.
diff --git a/src/MediaOperationsCore.cpp b/src/MediaOperationsCore.cpp
index d5101b4..8fd4af8 100644
--- a/src/MediaOperationsCore.cpp
+++ b/src/MediaOperationsCore.cpp
@@ -54,9 +54,13 @@ void MediaOperationsCoreApp::createOperationFactories()
mUlawToAlawFactoryProxy =
MediaOperationFactoryPrx::uncheckedCast(mAdapter->addWithUUID(mUlawToAlawFactory));
+ mManagement->addService(mUlawToAlawFactoryProxy, mUlawToAlawFactory->getName());
+
mAlawToUlawFactory = new AlawToUlawFactory(mAdapter);
mAlawToUlawFactoryProxy =
MediaOperationFactoryPrx::uncheckedCast(mAdapter->addWithUUID(mAlawToUlawFactory));
+
+ mManagement->addService(mAlawToUlawFactoryProxy, mAlawToUlawFactory->getName());
}
void MediaOperationsCoreApp::start(
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index f873f72..bead256 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -46,7 +46,7 @@ public:
typedef IceUtil::Handle<UlawToAlaw> UlawToAlawPtr;
UlawToAlawFactory::UlawToAlawFactory(const Ice::ObjectAdapterPtr& adapter)
- : mAdapter(adapter) { }
+ : mAdapter(adapter), mName("UlawToAlawFactory") { }
MediaOperationPrx UlawToAlawFactory::createMediaOperation(
const StreamSourcePrx&,
@@ -58,6 +58,11 @@ MediaOperationPrx UlawToAlawFactory::createMediaOperation(
return uToA->mProxy;
}
+const std::string& UlawToAlawFactory::getName()
+{
+ return mName;
+}
+
class AlawToUlaw : public MediaOperation
{
public:
@@ -86,7 +91,7 @@ public:
typedef IceUtil::Handle<AlawToUlaw> AlawToUlawPtr;
AlawToUlawFactory::AlawToUlawFactory(const Ice::ObjectAdapterPtr& adapter)
- : mAdapter(adapter) { }
+ : mAdapter(adapter), mName("AlawToUlawFactory") { }
MediaOperationPrx AlawToUlawFactory::createMediaOperation(
const StreamSourcePrx&,
@@ -97,3 +102,8 @@ MediaOperationPrx AlawToUlawFactory::createMediaOperation(
aToU->mProxy = MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(aToU));
return aToU->mProxy;
}
+
+const std::string& AlawToUlawFactory::getName()
+{
+ return mName;
+}
diff --git a/src/ulaw_alaw.h b/src/ulaw_alaw.h
index 205b790..c87ffac 100644
--- a/src/ulaw_alaw.h
+++ b/src/ulaw_alaw.h
@@ -29,8 +29,11 @@ public:
const AsteriskSCF::Media::V1::StreamSinkPrx& sink,
const Ice::Current&);
+ const std::string& getName();
+
private:
Ice::ObjectAdapterPtr mAdapter;
+ const std::string mName;
};
typedef IceUtil::Handle<UlawToAlawFactory> UlawToAlawFactoryPtr;
@@ -45,8 +48,11 @@ public:
const AsteriskSCF::Media::V1::StreamSinkPrx& sink,
const Ice::Current&);
+ const std::string& getName();
+
private:
Ice::ObjectAdapterPtr mAdapter;
+ const std::string mName;
};
typedef IceUtil::Handle<AlawToUlawFactory> AlawToUlawFactoryPtr;
commit 761a011617a4b8b80fce91d6e21e9680ae940e42
Author: Mark Michelson <mmichelson at digium.com>
Date: Thu Aug 11 17:22:28 2011 -0500
Get classes set up correctly.
diff --git a/src/MediaOperationsCore.cpp b/src/MediaOperationsCore.cpp
index 20c34d8..d5101b4 100644
--- a/src/MediaOperationsCore.cpp
+++ b/src/MediaOperationsCore.cpp
@@ -17,6 +17,14 @@
#include <Ice/Ice.h>
#include <IceBox/IceBox.h>
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+#include <AsteriskSCF/Media/MediaOperationIf.h>
+
+#include "ulaw_alaw.h"
+
+using namespace AsteriskSCF::Core::Discovery::V1;
+using namespace AsteriskSCF::Media::V1;
+
class MediaOperationsCoreApp : public IceBox::Service
{
public:
@@ -25,19 +33,53 @@ public:
const Ice::CommunicatorPtr&,
const Ice::StringSeq&);
void stop();
+
+private:
+
+ void createOperationFactories();
+
+ ServiceLocatorManagementPrx mManagement;
+ Ice::ObjectAdapterPtr mAdapter;
+
+ UlawToAlawFactoryPtr mUlawToAlawFactory;
+ MediaOperationFactoryPrx mUlawToAlawFactoryProxy;
+
+ AlawToUlawFactoryPtr mAlawToUlawFactory;
+ MediaOperationFactoryPrx mAlawToUlawFactoryProxy;
};
+void MediaOperationsCoreApp::createOperationFactories()
+{
+ mUlawToAlawFactory = new UlawToAlawFactory(mAdapter);
+ mUlawToAlawFactoryProxy =
+ MediaOperationFactoryPrx::uncheckedCast(mAdapter->addWithUUID(mUlawToAlawFactory));
+
+ mAlawToUlawFactory = new AlawToUlawFactory(mAdapter);
+ mAlawToUlawFactoryProxy =
+ MediaOperationFactoryPrx::uncheckedCast(mAdapter->addWithUUID(mAlawToUlawFactory));
+}
+
void MediaOperationsCoreApp::start(
const std::string&,
- const Ice::CommunicatorPtr&,
+ const Ice::CommunicatorPtr& communicator,
const Ice::StringSeq&)
{
- //stub
+ mManagement = ServiceLocatorManagementPrx::checkedCast(communicator->propertyToProxy("ServiceLocatorManagementProxy"));
+ mAdapter = communicator->createObjectAdapter("MediaOperationsCoreAdapter");
+
+ createOperationFactories();
}
void MediaOperationsCoreApp::stop()
{
- //stub
+ try
+ {
+ mAdapter->remove(mUlawToAlawFactoryProxy->ice_getIdentity());
+ mAdapter->remove(mAlawToUlawFactoryProxy->ice_getIdentity());
+ }
+ catch (const Ice::Exception&)
+ {
+ }
}
extern "C"
diff --git a/src/ulaw_alaw.cpp b/src/ulaw_alaw.cpp
index 4a82644..f873f72 100644
--- a/src/ulaw_alaw.cpp
+++ b/src/ulaw_alaw.cpp
@@ -20,52 +20,80 @@ using namespace AsteriskSCF::Media::V1;
class UlawToAlaw : public MediaOperation
{
- StreamSourcePrx getSource()
+public:
+ UlawToAlaw(const Ice::ObjectAdapterPtr& adapter)
+ : mAdapter(adapter) { }
+
+ StreamSourcePrx getSource(const Ice::Current&)
{
//stub
return 0;
}
- StreamSinkPrx getSink()
+ StreamSinkPrx getSink(const Ice::Current&)
{
//stub
return 0;
}
- void destroy()
+ void destroy(const Ice::Current&)
{
//stub
}
+
+ Ice::ObjectAdapterPtr mAdapter;
+ MediaOperationPrx mProxy;
};
+typedef IceUtil::Handle<UlawToAlaw> UlawToAlawPtr;
+
+UlawToAlawFactory::UlawToAlawFactory(const Ice::ObjectAdapterPtr& adapter)
+ : mAdapter(adapter) { }
+
MediaOperationPrx UlawToAlawFactory::createMediaOperation(
const StreamSourcePrx&,
- const StreamSinkPrx&)
+ const StreamSinkPrx&,
+ const Ice::Current&)
{
- //stub
- return 0;
+ UlawToAlawPtr uToA(new UlawToAlaw(mAdapter));
+ uToA->mProxy = MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(uToA));
+ return uToA->mProxy;
}
-class AlawToUlaw
+class AlawToUlaw : public MediaOperation
{
- StreamSourcePrx getSource()
+public:
+ AlawToUlaw(const Ice::ObjectAdapterPtr& adapter)
+ : mAdapter(adapter) { }
+
+ StreamSourcePrx getSource(const Ice::Current&)
{
//stub
return 0;
}
- StreamSinkPrx getSink()
+ StreamSinkPrx getSink(const Ice::Current&)
{
//stub
return 0;
}
- void destroy()
+ void destroy(const Ice::Current&)
{
//stub
}
+
+ Ice::ObjectAdapterPtr mAdapter;
+ MediaOperationPrx mProxy;
};
+typedef IceUtil::Handle<AlawToUlaw> AlawToUlawPtr;
+
+AlawToUlawFactory::AlawToUlawFactory(const Ice::ObjectAdapterPtr& adapter)
+ : mAdapter(adapter) { }
+
MediaOperationPrx AlawToUlawFactory::createMediaOperation(
const StreamSourcePrx&,
- const StreamSinkPrx&)
+ const StreamSinkPrx&,
+ const Ice::Current&)
{
- //stub
- return 0;
+ AlawToUlawPtr aToU(new AlawToUlaw(mAdapter));
+ aToU->mProxy = MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(aToU));
+ return aToU->mProxy;
}
diff --git a/src/ulaw_alaw.h b/src/ulaw_alaw.h
index 3beec41..205b790 100644
--- a/src/ulaw_alaw.h
+++ b/src/ulaw_alaw.h
@@ -16,18 +16,37 @@
#pragma once
+#include <Ice/Ice.h>
#include <AsteriskSCF/Media/MediaOperationIf.h>
class UlawToAlawFactory : public AsteriskSCF::Media::V1::MediaOperationFactory
{
+public:
+ UlawToAlawFactory(const Ice::ObjectAdapterPtr&);
+
AsteriskSCF::Media::V1::MediaOperationPrx createMediaOperation(
const AsteriskSCF::Media::V1::StreamSourcePrx& source,
- const AsteriskSCF::Media::V1::StreamSinkPrx& sink);
+ const AsteriskSCF::Media::V1::StreamSinkPrx& sink,
+ const Ice::Current&);
+
+private:
+ Ice::ObjectAdapterPtr mAdapter;
};
+typedef IceUtil::Handle<UlawToAlawFactory> UlawToAlawFactoryPtr;
+
class AlawToUlawFactory : public AsteriskSCF::Media::V1::MediaOperationFactory
{
+public:
+ AlawToUlawFactory(const Ice::ObjectAdapterPtr&);
+
AsteriskSCF::Media::V1::MediaOperationPrx createMediaOperation(
const AsteriskSCF::Media::V1::StreamSourcePrx& source,
- const AsteriskSCF::Media::V1::StreamSinkPrx& sink);
+ const AsteriskSCF::Media::V1::StreamSinkPrx& sink,
+ const Ice::Current&);
+
+private:
+ Ice::ObjectAdapterPtr mAdapter;
};
+
+typedef IceUtil::Handle<AlawToUlawFactory> AlawToUlawFactoryPtr;
commit b4b8b1426afd7926d4e96e686ce83fa6a67b38b3
Author: Mark Michelson <mmichelson at digium.com>
Date: Thu Aug 11 16:01:09 2011 -0500
Adding some initial stubbed out stuff.
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..4fe7212
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,3 @@
+astscf_project(media_operations_core 3.4)
+
+add_subdirectory(src)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..47d0054
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,10 @@
+include_directories(${logger_dir}/include)
+
+astscf_component_init(media_operations_core)
+astscf_component_add_files(media_operations_core ulaw_alaw.h)
+astscf_component_add_files(media_operations_core ulaw_alaw.cpp)
+astscf_component_add_files(media_operations_core MediaOperationsCore.cpp)
+astscf_component_add_slice_collection_libraries(media_operations_core ASTSCF)
+astscf_component_build_icebox(media_operations_core)
+target_link_libraries(media_operations_core logging-client)
+astscf_component_install(media_operations_core)
diff --git a/src/MediaOperationsCore.cpp b/src/MediaOperationsCore.cpp
new file mode 100644
index 0000000..20c34d8
--- /dev/null
+++ b/src/MediaOperationsCore.cpp
@@ -0,0 +1,49 @@
+/*
+ * 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 <Ice/Ice.h>
+#include <IceBox/IceBox.h>
+
+class MediaOperationsCoreApp : public IceBox::Service
+{
+public:
+ void start(
+ const std::string&,
+ const Ice::CommunicatorPtr&,
+ const Ice::StringSeq&);
+ void stop();
+};
+
+void MediaOperationsCoreApp::start(
+ const std::string&,
+ const Ice::CommunicatorPtr&,
+ const Ice::StringSeq&)
... 134 lines suppressed ...
--
asterisk-scf/release/media_operations_core.git
More information about the asterisk-scf-commits
mailing list