[asterisk-scf-commits] asterisk-scf/integration/media_operations_core.git branch "inband-events" updated.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Oct 25 17:38:13 CDT 2011
branch "inband-events" has been updated
via 0ddc4b71b09c3a7aa39d13870e38f03749744755 (commit)
via 678d5dd75bc91fa4d77bfa0e23db4898388b3bf8 (commit)
via 60bec36782e48e7a68179763169c3df7b5a9b3ce (commit)
via b5d108ce693a470cefbdb2a787dbf7d05cdaf6a7 (commit)
from cc2e607e6edafffc17fc05e0daf63ba68f635d2f (commit)
Summary of changes:
.../MediaOperationsCore/MediaOperationsCoreIf.ice | 2 +
src/InbandTelephonyEvents.cpp | 194 ++++++++++++++++----
src/InbandTelephonyEvents.h | 26 +++-
src/MediaOperationStateReplicatorListener.cpp | 15 ++
src/MediaOperationsCore.cpp | 5 +
5 files changed, 201 insertions(+), 41 deletions(-)
- Log -----------------------------------------------------------------
commit 0ddc4b71b09c3a7aa39d13870e38f03749744755
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Oct 25 17:20:33 2011 -0500
Add some documentation.
diff --git a/src/InbandTelephonyEvents.cpp b/src/InbandTelephonyEvents.cpp
index 5c427ea..2cd64b8 100644
--- a/src/InbandTelephonyEvents.cpp
+++ b/src/InbandTelephonyEvents.cpp
@@ -78,6 +78,7 @@ class InbandTelephonyEventOperation : public TranslatorOperation
}
cb->ice_response();
}
+
void removeSinks_async(const AMD_TelephonyEventSource_removeSinksPtr& cb,
const TelephonyEventSinkSeq& sinks,
const Ice::Current&)
@@ -168,6 +169,16 @@ class InbandTelephonyEventOperation : public TranslatorOperation
throw UnsupportedMediaFormatException();
}
+ //This requires some explanation...
+ //The DSP will detect the presence of certain tones. The DSP is essentially
+ //edge-triggered. In other words, it will report the beginning and end of
+ //a specific tone and let us know what it detected.
+ //
+ //The problem here is that the DSP will always report what it has found as
+ //a "Begin" event of the appropriate type. It is up to us to maintain state
+ //from the DSP's process. Thus we can properly turn the event into an end
+ //event if it is appropriate to do so.
+
TelephonyEventPtr detectedEvent = mDSP->process(inAudio);
if (!detectedEvent)
@@ -283,6 +294,10 @@ class InbandTelephonyEventOperation : public TranslatorOperation
mStateItem = newState;
}
private:
+ /**
+ * Convenience method to send along a begin event as detected by the
+ * DSP.
+ */
void forwardBeginEvent(const TelephonyEventPtr& event, bool &eventBegin)
{
mStateItem->eventBeginTime = IceUtil::Time::now().toMilliSeconds();
@@ -290,6 +305,9 @@ class InbandTelephonyEventOperation : public TranslatorOperation
eventBegin = true;
}
+ /**
+ * Convenience method to copy our current state to any replicas.
+ */
void replicateState()
{
if (mReplicationContext->isReplicating())
commit 678d5dd75bc91fa4d77bfa0e23db4898388b3bf8
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Oct 25 17:08:35 2011 -0500
Some cleanup mostly.
diff --git a/src/InbandTelephonyEvents.cpp b/src/InbandTelephonyEvents.cpp
index c13460a..5c427ea 100644
--- a/src/InbandTelephonyEvents.cpp
+++ b/src/InbandTelephonyEvents.cpp
@@ -120,14 +120,13 @@ class InbandTelephonyEventOperation : public TranslatorOperation
{
public:
InbandTelephonyEventDetector(const TranslatorSourcePtr source,
- const FormatPtr& inputFormat,
- const FormatPtr& outputFormat,
+ const AudioFormatPtr& inputFormat,
+ const AudioFormatPtr& outputFormat,
const Logger& logger,
const MediaOperationReplicationContextPtr& replicationContext,
const Ice::ObjectAdapterPtr& adapter)
: Translator(source, inputFormat, outputFormat, logger),
- //XXX We can work out the sample rate from the input format.
- mDSP(new DSP(logger)),
+ mDSP(new DSP(logger, inputFormat->sampleRate)),
mTelephonySource(new InbandTelephonyEventSource(logger)),
mReplicationContext(replicationContext),
mAdapter(adapter)
@@ -328,9 +327,7 @@ public:
replicationContext,
new InbandTelephonyEventOperationStateItem)
{
- mDetector = new InbandTelephonyEventDetector(mSource, sinkFormat, sourceFormat, mLogger, replicationContext, adapter);
- TelephonyEventSourcePrx source = mDetector->activateSource(mProxy->ice_getIdentity().name);
- mSink->setTranslator(mDetector);
+ commonConstruction(sourceFormat, sinkFormat);
}
InbandTelephonyEventOperation(
@@ -349,9 +346,7 @@ public:
replicationContext,
item)
{
- mDetector = new InbandTelephonyEventDetector(mSource, sinkFormat, sourceFormat, mLogger, replicationContext, adapter);
- TelephonyEventSourcePrx source = mDetector->activateSource(mProxy->ice_getIdentity().name);
- mSink->setTranslator(mDetector);
+ commonConstruction(sourceFormat, sinkFormat);
}
~InbandTelephonyEventOperation()
@@ -365,6 +360,19 @@ public:
}
private:
+ void commonConstruction(const FormatPtr& sourceFormat, const FormatPtr& sinkFormat)
+ {
+ AudioFormatPtr sourceAudio = AudioFormatPtr::dynamicCast(sourceFormat);
+ AudioFormatPtr sinkAudio = AudioFormatPtr::dynamicCast(sinkFormat);
+ if (!sourceAudio || !sinkAudio)
+ {
+ throw UnsupportedMediaFormatException();
+ }
+ mDetector = new InbandTelephonyEventDetector(mSource, sinkAudio, sourceAudio, mLogger, mReplicationContext, mAdapter);
+ TelephonyEventSourcePrx source = mDetector->activateSource(mProxy->ice_getIdentity().name);
+ mSink->setTranslator(mDetector);
+ }
+
InbandTelephonyEventDetectorPtr mDetector;
};
@@ -396,50 +404,47 @@ MediaOperationPrx InbandTelephonyEventOperationFactory::createMediaOperation(
FormatSeq sourceFormats = source->getFormats();
FormatSeq sinkFormats = sink->getFormats();
- FormatSeq::iterator inSlin8 = std::find_if(sourceFormats.begin(),
- sourceFormats.end(), FormatNameEqual(SignedLinear8Name));
+ MediaOperationPrx proxy = tryFormat(sourceFormats, sinkFormats, SignedLinear8Name);
- FormatSeq::iterator outSlin8 = std::find_if(sinkFormats.begin(),
- sinkFormats.end(), FormatNameEqual(SignedLinear8Name));
-
- InbandTelephonyEventOperationPtr operation;
- MediaOperationPrx proxy;
- if (inSlin8 != sourceFormats.end() && outSlin8 != sinkFormats.end())
+ if (!proxy)
{
- operation = new InbandTelephonyEventOperation(
- mAdapter,
- mLogger,
- *outSlin8,
- *inSlin8,
- getProxy()->ice_getIdentity(),
- mReplicationContext);
- proxy = MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(operation));
- return proxy;
+ proxy = tryFormat(sourceFormats, sinkFormats, SignedLinear16Name);
}
- FormatSeq::iterator inSlin16 = std::find_if(sourceFormats.begin(),
- sourceFormats.end(), FormatNameEqual(SignedLinear16Name));
-
- FormatSeq::iterator outSlin16 = std::find_if(sinkFormats.begin(),
- sinkFormats.end(), FormatNameEqual(SignedLinear16Name));
-
- if (inSlin16 == sourceFormats.end() || outSlin16 == sinkFormats.end())
+ if (!proxy)
{
throw UnsupportedMediaFormatException();
}
- operation = new InbandTelephonyEventOperation(
- mAdapter,
- mLogger,
- *outSlin16,
- *inSlin16,
- getProxy()->ice_getIdentity(),
- mReplicationContext);
-
- proxy = MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(operation));
return proxy;
}
+MediaOperationPrx InbandTelephonyEventOperationFactory::tryFormat(const FormatSeq& sourceFormats,
+ const FormatSeq& sinkFormats,
+ const std::string& name)
+{
+ FormatSeq::const_iterator inFormat = std::find_if(sourceFormats.begin(),
+ sourceFormats.end(), FormatNameEqual(name));
+
+ FormatSeq::const_iterator outFormat = std::find_if(sinkFormats.begin(),
+ sinkFormats.end(), FormatNameEqual(name));
+
+ if (inFormat != sourceFormats.end() && outFormat != sinkFormats.end())
+ {
+ InbandTelephonyEventOperationPtr operation(
+ new InbandTelephonyEventOperation(
+ mAdapter,
+ mLogger,
+ *outFormat,
+ *inFormat,
+ getProxy()->ice_getIdentity(),
+ mReplicationContext));
+ MediaOperationPrx proxy(MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(operation)));
+ return proxy;
+ }
+ return 0;
+}
+
void InbandTelephonyEventOperationFactory::createOrUpdateMediaOperation(
const InbandTelephonyEventOperationStateItemPtr& item)
{
diff --git a/src/InbandTelephonyEvents.h b/src/InbandTelephonyEvents.h
index 8fb44e0..da2f636 100644
--- a/src/InbandTelephonyEvents.h
+++ b/src/InbandTelephonyEvents.h
@@ -48,6 +48,18 @@ public:
* state item does not yet exist, then we will create it.
*/
void createOrUpdateMediaOperation(const AsteriskSCF::Replication::MediaOperationsCore::V1::InbandTelephonyEventOperationStateItemPtr& item);
+private:
+
+ /**
+ * Internal method to create an operation using a specific format
+ *
+ * This method takes the supported formats from a source and a sink and checks
+ * if the name specified in formatName is supported by both the source and sink.
+ * If so, then a media operation is created using the specified format.
+ */
+ AsteriskSCF::Media::V1::MediaOperationPrx tryFormat(const AsteriskSCF::Media::V1::FormatSeq& sourceFormats,
+ const AsteriskSCF::Media::V1::FormatSeq& sinkFormats,
+ const std::string& formatName);
};
typedef IceUtil::Handle<InbandTelephonyEventOperationFactory> InbandTelephonyEventOperationFactoryPtr;
commit 60bec36782e48e7a68179763169c3df7b5a9b3ce
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Oct 25 16:07:51 2011 -0500
Create the operation factory for inband telephony events.
diff --git a/src/InbandTelephonyEvents.cpp b/src/InbandTelephonyEvents.cpp
index ae8b4f2..c13460a 100644
--- a/src/InbandTelephonyEvents.cpp
+++ b/src/InbandTelephonyEvents.cpp
@@ -373,12 +373,11 @@ typedef IceUtil::Handle<InbandTelephonyEventOperation> InbandTelephonyEventOpera
InbandTelephonyEventOperationFactory::InbandTelephonyEventOperationFactory(
const Ice::ObjectAdapterPtr& adapter,
const Logger& logger,
- const MediaOperationReplicationContextPtr& replicationContext,
- const std::string& name)
+ const MediaOperationReplicationContextPtr& replicationContext)
: MediaOperationFactoryImpl(adapter,
logger,
replicationContext,
- name)
+ "InbandTelephonyEventFactory")
{
mLocatorParams->category = MediaOperationDiscoveryCategory;
mLocatorParams->service = InbandTelephonyEventsDiscoveryCategory;
diff --git a/src/InbandTelephonyEvents.h b/src/InbandTelephonyEvents.h
index 42dceae..8fb44e0 100644
--- a/src/InbandTelephonyEvents.h
+++ b/src/InbandTelephonyEvents.h
@@ -33,16 +33,21 @@ public:
InbandTelephonyEventOperationFactory(
const Ice::ObjectAdapterPtr& adapter,
const AsteriskSCF::System::Logging::Logger& logger,
- const MediaOperationReplicationContextPtr& replicationContext,
- const std::string& name);
+ const MediaOperationReplicationContextPtr& replicationContext);
AsteriskSCF::Media::V1::MediaOperationPrx createMediaOperation(
const AsteriskSCF::Media::V1::StreamSourcePrx& source,
const AsteriskSCF::Media::V1::StreamSinkPrx& sink,
const Ice::Current&);
- void createOrUpdateMediaOperation(
- const AsteriskSCF::Replication::MediaOperationsCore::V1::InbandTelephonyEventOperationStateItemPtr& item);
+ /**
+ * Called from the state replicator listener.
+ *
+ * When state gets updated, we have to update the internal
+ * state of the operation. If the operation described by the
+ * state item does not yet exist, then we will create it.
+ */
+ void createOrUpdateMediaOperation(const AsteriskSCF::Replication::MediaOperationsCore::V1::InbandTelephonyEventOperationStateItemPtr& item);
};
typedef IceUtil::Handle<InbandTelephonyEventOperationFactory> InbandTelephonyEventOperationFactoryPtr;
diff --git a/src/MediaOperationStateReplicatorListener.cpp b/src/MediaOperationStateReplicatorListener.cpp
index 01dc0f2..d6e1d5c 100644
--- a/src/MediaOperationStateReplicatorListener.cpp
+++ b/src/MediaOperationStateReplicatorListener.cpp
@@ -63,6 +63,10 @@ void MediaOperationStateReplicatorListenerImpl::stateRemovedForItems(
{
mAdapter->remove(mAdapter->getCommunicator()->stringToIdentity(g722->operationId));
}
+ void visitInbandTelephonyEventOperationStateItem(const InbandTelephonyEventOperationStateItemPtr& inband)
+ {
+ mAdapter->remove(mAdapter->getCommunicator()->stringToIdentity(inband->operationId));
+ }
Ice::ObjectAdapterPtr mAdapter;
};
diff --git a/src/MediaOperationsCore.cpp b/src/MediaOperationsCore.cpp
index 296d41b..91b33c0 100644
--- a/src/MediaOperationsCore.cpp
+++ b/src/MediaOperationsCore.cpp
@@ -26,6 +26,7 @@
#include "ulaw_alaw.h"
#include "resample.h"
#include "g722.h"
+#include "InbandTelephonyEvents.h"
using namespace AsteriskSCF::System::Logging;
@@ -195,6 +196,10 @@ private:
lg(Debug) << "Creating G.722 Factory";
createAndRegisterFactory(new G722Factory(getServiceAdapter(), lg,
boost::static_pointer_cast<MediaOperationReplicationContext>(getReplicationContext())));
+
+ lg(Debug) << "Creating Inband Telephony Event Detector Factory";
+ createAndRegisterFactory(new InbandTelephonyEventOperationFactory(getServiceAdapter(), lg,
+ boost::static_pointer_cast<MediaOperationReplicationContext>(getReplicationContext())));
}
void locateStateReplicator()
commit b5d108ce693a470cefbdb2a787dbf7d05cdaf6a7
Author: Mark Michelson <mmichelson at digium.com>
Date: Tue Oct 25 14:31:54 2011 -0500
Work towards proper state replication in place.
diff --git a/slice/AsteriskSCF/Replication/MediaOperationsCore/MediaOperationsCoreIf.ice b/slice/AsteriskSCF/Replication/MediaOperationsCore/MediaOperationsCoreIf.ice
index 4a65e41..4227098 100644
--- a/slice/AsteriskSCF/Replication/MediaOperationsCore/MediaOperationsCoreIf.ice
+++ b/slice/AsteriskSCF/Replication/MediaOperationsCore/MediaOperationsCoreIf.ice
@@ -36,6 +36,8 @@ module V1
const string StateReplicatorComponentCategory = "SipStateReplicatorComponent";
const string StateReplicatorDiscoveryCategory = "SipStateReplicator";
+const string InbandTelephonyEventsDiscoveryCategory = "InbandTelephonyEvents";
+
["visitor"] local class MediaOperationStateItemVisitor
{
};
diff --git a/src/InbandTelephonyEvents.cpp b/src/InbandTelephonyEvents.cpp
index 9c7b014..ae8b4f2 100644
--- a/src/InbandTelephonyEvents.cpp
+++ b/src/InbandTelephonyEvents.cpp
@@ -123,17 +123,37 @@ class InbandTelephonyEventOperation : public TranslatorOperation
const FormatPtr& inputFormat,
const FormatPtr& outputFormat,
const Logger& logger,
- const MediaOperationReplicationContextPtr& replicationContext)
+ const MediaOperationReplicationContextPtr& replicationContext,
+ const Ice::ObjectAdapterPtr& adapter)
: Translator(source, inputFormat, outputFormat, logger),
//XXX We can work out the sample rate from the input format.
mDSP(new DSP(logger)),
mTelephonySource(new InbandTelephonyEventSource(logger)),
- mReplicationContext(replicationContext)
+ mReplicationContext(replicationContext),
+ mAdapter(adapter)
{
mDSP->setFeatures(DSP_FEATURE_DIGIT_DETECT | DSP_FEATURE_FAX_DETECT);
mDSP->setDigitmode(DSP_DIGITMODE_DTMF);
}
+ TelephonyEventSourcePrx activateSource(const std::string& id)
+ {
+ std::string ourID = id + ".TelephonyEventSource";
+ mProxy = TelephonyEventSourcePrx::uncheckedCast(mAdapter->add(mTelephonySource, mAdapter->getCommunicator()->stringToIdentity(ourID)));
+ return mProxy;
+ };
+
+ void deactivateSource()
+ {
+ try
+ {
+ mAdapter->remove(mProxy->ice_getIdentity());
+ }
+ catch (const std::exception&)
+ {
+ }
+ };
+
FramePtr translate(const FramePtr inFrame)
{
if (inFrame->mediaFormat->name != mInputFormat->name)
@@ -252,6 +272,17 @@ class InbandTelephonyEventOperation : public TranslatorOperation
//audio on to the next set of stuff
return inAudio;
};
+
+ /**
+ * Update the state for the operation
+ *
+ * This is called by the state replicator listener when state for the
+ * primary operation changes.
+ */
+ void updateState(const InbandTelephonyEventOperationStateItemPtr& newState)
+ {
+ mStateItem = newState;
+ }
private:
void forwardBeginEvent(const TelephonyEventPtr& event, bool &eventBegin)
{
@@ -274,8 +305,12 @@ class InbandTelephonyEventOperation : public TranslatorOperation
InbandTelephonyEventSourcePtr mTelephonySource;
InbandTelephonyEventOperationStateItemPtr mStateItem;
MediaOperationReplicationContextPtr mReplicationContext;
+ Ice::ObjectAdapterPtr mAdapter;
+ TelephonyEventSourcePrx mProxy;
};
+ typedef IceUtil::Handle<InbandTelephonyEventDetector> InbandTelephonyEventDetectorPtr;
+
public:
InbandTelephonyEventOperation(
const Ice::ObjectAdapterPtr& adapter,
@@ -293,8 +328,44 @@ public:
replicationContext,
new InbandTelephonyEventOperationStateItem)
{
- mSink->setTranslator(new InbandTelephonyEventDetector(mSource, sinkFormat, sourceFormat, mLogger, replicationContext));
+ mDetector = new InbandTelephonyEventDetector(mSource, sinkFormat, sourceFormat, mLogger, replicationContext, adapter);
+ TelephonyEventSourcePrx source = mDetector->activateSource(mProxy->ice_getIdentity().name);
+ mSink->setTranslator(mDetector);
+ }
+
+ InbandTelephonyEventOperation(
+ const Ice::ObjectAdapterPtr& adapter,
+ const Logger& logger,
+ const FormatPtr& sourceFormat,
+ const FormatPtr& sinkFormat,
+ const MediaOperationReplicationContextPtr& replicationContext,
+ const InbandTelephonyEventOperationStateItemPtr& item)
+ : TranslatorOperation(
+ adapter,
+ logger,
+ sourceFormat,
+ sinkFormat,
+ item->factoryId,
+ replicationContext,
+ item)
+ {
+ mDetector = new InbandTelephonyEventDetector(mSource, sinkFormat, sourceFormat, mLogger, replicationContext, adapter);
+ TelephonyEventSourcePrx source = mDetector->activateSource(mProxy->ice_getIdentity().name);
+ mSink->setTranslator(mDetector);
}
+
+ ~InbandTelephonyEventOperation()
+ {
+ mDetector->deactivateSource();
+ }
+
+ void updateState(const InbandTelephonyEventOperationStateItemPtr& newState)
+ {
+ mDetector->updateState(newState);
+ }
+
+private:
+ InbandTelephonyEventDetectorPtr mDetector;
};
typedef IceUtil::Handle<InbandTelephonyEventOperation> InbandTelephonyEventOperationPtr;
@@ -310,8 +381,7 @@ InbandTelephonyEventOperationFactory::InbandTelephonyEventOperationFactory(
name)
{
mLocatorParams->category = MediaOperationDiscoveryCategory;
- //XXX This should be some named constant
- mLocatorParams->service = "InbandTelephonyEvents";
+ mLocatorParams->service = InbandTelephonyEventsDiscoveryCategory;
};
MediaOperationPrx InbandTelephonyEventOperationFactory::createMediaOperation(
@@ -371,5 +441,29 @@ MediaOperationPrx InbandTelephonyEventOperationFactory::createMediaOperation(
return proxy;
}
+void InbandTelephonyEventOperationFactory::createOrUpdateMediaOperation(
+ const InbandTelephonyEventOperationStateItemPtr& item)
+{
+ InbandTelephonyEventOperationPtr operation;
+
+ operation = InbandTelephonyEventOperationPtr::dynamicCast(mAdapter->find(mAdapter->getCommunicator()->stringToIdentity(item->operationId)));
+
+ if (operation != 0)
+ {
+ operation->updateState(item);
+ return;
+ }
+
+ operation = new InbandTelephonyEventOperation(
+ mAdapter,
+ mLogger,
+ item->sourceFormat,
+ item->sinkFormat,
+ mReplicationContext,
+ item);
+
+ MediaOperationPrx proxy = MediaOperationPrx::uncheckedCast(mAdapter->addWithUUID(operation));
+}
+
} //end MediaOperationsCore
} //end AsteriskSCF
diff --git a/src/InbandTelephonyEvents.h b/src/InbandTelephonyEvents.h
index e76e47d..42dceae 100644
--- a/src/InbandTelephonyEvents.h
+++ b/src/InbandTelephonyEvents.h
@@ -40,7 +40,12 @@ public:
const AsteriskSCF::Media::V1::StreamSourcePrx& source,
const AsteriskSCF::Media::V1::StreamSinkPrx& sink,
const Ice::Current&);
+
+ void createOrUpdateMediaOperation(
+ const AsteriskSCF::Replication::MediaOperationsCore::V1::InbandTelephonyEventOperationStateItemPtr& item);
};
+typedef IceUtil::Handle<InbandTelephonyEventOperationFactory> InbandTelephonyEventOperationFactoryPtr;
+
} // end MediaOperationsCore
} // end AsteriskSCF
diff --git a/src/MediaOperationStateReplicatorListener.cpp b/src/MediaOperationStateReplicatorListener.cpp
index 2943d21..01dc0f2 100644
--- a/src/MediaOperationStateReplicatorListener.cpp
+++ b/src/MediaOperationStateReplicatorListener.cpp
@@ -19,6 +19,7 @@
#include "ulaw_alaw.h"
#include "resample.h"
#include "g722.h"
+#include "InbandTelephonyEvents.h"
namespace AsteriskSCF
{
@@ -105,6 +106,16 @@ void MediaOperationStateReplicatorListenerImpl::stateSet(
createTranslationMediaOperation(factory, g722);
}
+ void visitInbandTelephonyEventOperationStateItemPtr(const InbandTelephonyEventOperationStateItemPtr& inband)
+ {
+ InbandTelephonyEventOperationFactoryPtr factory = InbandTelephonyEventOperationFactoryPtr::dynamicCast(mAdapter->find(inband->factoryId));
+ if (!factory)
+ {
+ return;
+ }
+ factory->createOrUpdateMediaOperation(inband);
+ }
+
void createTranslationMediaOperation(const TranslatorOperationFactoryPtr& factory,
const TranslatorMediaOperationStateItemPtr& item)
{
-----------------------------------------------------------------------
--
asterisk-scf/integration/media_operations_core.git
More information about the asterisk-scf-commits
mailing list