[asterisk-scf-commits] asterisk-scf/integration/media_operations_core.git branch "g722" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Thu Sep 1 11:10:01 CDT 2011
branch "g722" has been updated
via dc1598b75cca6711f9bd233ac477031fb39dbca1 (commit)
from 6a39d3d26db6669fee7ea19d9aa9dbc9310923fb (commit)
Summary of changes:
src/TranslatorOperation.h | 48 ++++++++++++++++++++++++++++++++-
src/TranslatorOperationFactory.cpp | 10 ++++---
src/TranslatorOperationFactory.h | 52 +++++++++++++++++++++++++++++++-----
src/g722.cpp | 2 +-
src/resample.cpp | 12 +-------
5 files changed, 100 insertions(+), 24 deletions(-)
- Log -----------------------------------------------------------------
commit dc1598b75cca6711f9bd233ac477031fb39dbca1
Author: Mark Michelson <mmichelson at digium.com>
Date: Thu Sep 1 11:03:06 2011 -0500
Add documentation and change some bad function names.
diff --git a/src/TranslatorOperation.h b/src/TranslatorOperation.h
index bb9f4c7..152a469 100644
--- a/src/TranslatorOperation.h
+++ b/src/TranslatorOperation.h
@@ -30,6 +30,9 @@ namespace AsteriskSCF
namespace MediaOperationsCore
{
+/**
+ * Base class for Media operations that translate between formats
+ */
class TranslatorOperation : public AsteriskSCF::Media::V1::MediaOperation
{
public:
@@ -43,16 +46,59 @@ public:
virtual ~TranslatorOperation();
+ /**
+ * Set state in the state replicator.
+ *
+ * The only reason that subclasses should override this is if they have
+ * any specific state they need to replicate in addition to the common
+ * traits all translators replicate.
+ *
+ * If this is overridden, the best approach to take is to set fields within
+ * your state item and then call TranslatorOperation::setState().
+ */
virtual void setState();
+ /**
+ * Remove state in the state replicator.
+ *
+ * The only reason that subclasses should override this is if they have
+ * specific state they need to replicate in addition to the common
+ * traits all translators replicate.
+ *
+ * If this is overridden, the best approach to take is to set fields within
+ * your state item and then call TranslatorOperation::removeState().
+ */
virtual void removeState();
+ /**
+ * Add objects to the object adapter.
+ *
+ * The only reason to override this would be if additional servants should
+ * be added to the object adapter. Be sure to call TranslatorOperation::activate(id)
+ * in your override.
+ *
+ * This will add the operation, along with its source and sink to the object adapter.
+ */
virtual AsteriskSCF::Media::V1::MediaOperationPrx activate(const std::string& id);
- virtual void destroy(const Ice::Current&);
+ /**
+ * Remove items from the object adapter.
+ *
+ * NOTE: It may seem like this should be virtual, so that custom servants added
+ * during activate() could be removed here. However, this should be done in an
+ * overridden destructor instead. Otherwise, replicated TranslatorOperations
+ * would not properly remove servants from their object adapter.
+ */
+ void destroy(const Ice::Current&);
+ /**
+ * Get the stream source for this operation.
+ */
AsteriskSCF::Media::V1::StreamSourcePrx getSource(const Ice::Current&);
+ /**
+ * Get the stream sink for this operation
+ */
AsteriskSCF::Media::V1::StreamSinkPrx getSink(const Ice::Current&);
protected:
diff --git a/src/TranslatorOperationFactory.cpp b/src/TranslatorOperationFactory.cpp
index bce48d7..82137fb 100644
--- a/src/TranslatorOperationFactory.cpp
+++ b/src/TranslatorOperationFactory.cpp
@@ -38,6 +38,8 @@ TranslatorOperationFactory::TranslatorOperationFactory(
mLocatorParams->service = MediaOperationDiscoveryTranslatorService;
}
+TranslatorOperationFactory::~TranslatorOperationFactory() { }
+
MediaOperationPrx TranslatorOperationFactory::createMediaOperation(
const StreamSourcePrx& source,
const StreamSinkPrx& sink,
@@ -56,7 +58,7 @@ MediaOperationPrx TranslatorOperationFactory::createMediaOperation(
sourceFormats.end(),
mTranslations.begin(),
mTranslations.end(),
- TranslatorOperationFactory::formatsEqual2);
+ TranslatorOperationFactory::formatsEqualMap);
if (supportedInput == sourceFormats.end())
{
@@ -76,7 +78,7 @@ MediaOperationPrx TranslatorOperationFactory::createMediaOperation(
sinkFormats.end(),
mTranslations[(*supportedInput)->name].begin(),
mTranslations[(*supportedInput)->name].end(),
- TranslatorOperationFactory::formatsEqual1);
+ TranslatorOperationFactory::formatsEqual);
if (supportedOutput == sinkFormats.end())
{
@@ -108,14 +110,14 @@ void TranslatorOperationFactory::addTranslation(
mLocatorParams->attributes.push_back(attrs);
}
-bool TranslatorOperationFactory::formatsEqual1(
+bool TranslatorOperationFactory::formatsEqual(
const FormatPtr& lhs,
const FormatPtr& rhs)
{
return lhs->name == rhs->name;
}
-bool TranslatorOperationFactory::formatsEqual2(
+bool TranslatorOperationFactory::formatsEqualMap(
const FormatPtr& lhs,
const std::pair<std::string, FormatSeq>& rhs)
{
diff --git a/src/TranslatorOperationFactory.h b/src/TranslatorOperationFactory.h
index d95389f..ee2a279 100644
--- a/src/TranslatorOperationFactory.h
+++ b/src/TranslatorOperationFactory.h
@@ -24,6 +24,10 @@ namespace AsteriskSCF
namespace MediaOperationsCore
{
+/**
+ * Base class for Media Operation Factories that
+ * produce translators.
+ */
class TranslatorOperationFactory : public MediaOperationFactoryImpl
{
public:
@@ -34,32 +38,66 @@ public:
const MediaOperationReplicationContextPtr& replicationContext,
const std::string& name);
+ virtual ~TranslatorOperationFactory();
+
+ /**
+ * Overload of the slice MediaOperationFactory::createMediaOperation
+ * method.
+ *
+ * This will use the translation map in order to determine if the source
+ * and sink parameters support formats that this factory knows about.
+ * It will then call the below createMediaOperation() method once
+ * the formats have been determined.
+ */
AsteriskSCF::Media::V1::MediaOperationPrx createMediaOperation(
const AsteriskSCF::Media::V1::StreamSourcePrx& source,
const AsteriskSCF::Media::V1::StreamSinkPrx& sink,
const Ice::Current&);
+ /**
+ * Pure virtual function to create a media operation.
+ *
+ * Create a media operation with the given formats.
+ *
+ * @param sourceFormat The format for the media operation's source to use.
+ * @param sinkFormat The format for the media operation's sink to use.
+ * @param operationId The Ice identification string to use when adding the operation
+ * to the object adapter.
+ * @return A proxy to the newly created media operation
+ */
virtual AsteriskSCF::Media::V1::MediaOperationPrx createMediaOperation(
const AsteriskSCF::Media::V1::FormatPtr& sourceFormat,
const AsteriskSCF::Media::V1::FormatPtr& sinkFormat,
const std::string& operationId) = 0;
+ /**
+ * Add a translation supported by the factory.
+ *
+ * @param inFormat The input format for translation
+ * @param outFormat The output format for translation
+ * @param cost The cost of the translation. Units for cost are
+ * undetermined at this time. A higher cost implies a
+ */
void addTranslation(
- const AsteriskSCF::Media::V1::FormatPtr&,
- const AsteriskSCF::Media::V1::FormatPtr&,
+ const AsteriskSCF::Media::V1::FormatPtr& inFormat,
+ const AsteriskSCF::Media::V1::FormatPtr& outFormat,
int cost);
- static bool formatsEqual1(
+ /**
+ * Handy function to compare two formats. Useful for predicates
+ * in STL algorithms. Returns true if the formats are the same.
+ */
+ static bool formatsEqual(
const AsteriskSCF::Media::V1::FormatPtr& lhs,
const AsteriskSCF::Media::V1::FormatPtr& rhs);
- static bool formatsEqual2(
- const AsteriskSCF::Media::V1::FormatPtr& lhs,
- const std::pair<std::string, AsteriskSCF::Media::V1::FormatSeq>& rhs);
-
private:
typedef std::map<std::string, AsteriskSCF::Media::V1::FormatSeq> TranslationMap;
+ static bool formatsEqualMap(
+ const AsteriskSCF::Media::V1::FormatPtr& lhs,
+ const std::pair<std::string, AsteriskSCF::Media::V1::FormatSeq>& rhs);
+
TranslationMap mTranslations;
};
diff --git a/src/g722.cpp b/src/g722.cpp
index 112bbec..038110d 100644
--- a/src/g722.cpp
+++ b/src/g722.cpp
@@ -112,7 +112,7 @@ private:
FramePtr translate(const FramePtr inFrame)
{
- if (!TranslatorOperationFactory::formatsEqual1(inFrame->mediaFormat, mInputFormat))
+ if (!TranslatorOperationFactory::formatsEqual(inFrame->mediaFormat, mInputFormat))
{
mLogger(Error) << "Cannot translate frame because the format is not what we expect.";
throw UnsupportedMediaFormatException();
diff --git a/src/resample.cpp b/src/resample.cpp
index de4cb64..572bc1a 100644
--- a/src/resample.cpp
+++ b/src/resample.cpp
@@ -26,16 +26,6 @@
using namespace AsteriskSCF::Media::V1;
-namespace
-{
-
-bool formatCompare(const FormatPtr& format1, const FormatPtr& format2)
-{
- return format1->name == format2->name;
-}
-
-};
-
namespace AsteriskSCF
{
@@ -85,7 +75,7 @@ private:
FramePtr translate(const FramePtr inFrame)
{
- if (!formatCompare(inFrame->mediaFormat, mInputFormat))
+ if (!TranslatorOperationFactory::formatsEqual(inFrame->mediaFormat, mInputFormat))
{
mLogger(Error) << "Cannot resample frame because the format is not what was expected";
throw UnsupportedMediaFormatException();
-----------------------------------------------------------------------
--
asterisk-scf/integration/media_operations_core.git
More information about the asterisk-scf-commits
mailing list