[asterisk-scf-commits] asterisk-scf/integration/mediaformatgeneric.git branch "master" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Mon Jun 13 15:43:36 CDT 2011
branch "master" has been created
at 424f6070ba77f654b30bf835e093f2921a7d80a4 (commit)
- Log -----------------------------------------------------------------
commit 424f6070ba77f654b30bf835e093f2921a7d80a4
Author: Joshua Colp <jcolp at digium.com>
Date: Mon Jun 13 17:43:43 2011 -0300
Initial import of the generic media format component.
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..edca8f3
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,4 @@
+asterisk_scf_project(mediaformatgeneric 3.4)
+
+add_subdirectory(src)
+add_subdirectory(test)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
new file mode 100644
index 0000000..fb48104
--- /dev/null
+++ b/src/CMakeLists.txt
@@ -0,0 +1,13 @@
+include_directories(${API_INCLUDE_DIR})
+include_directories(${ice-util-cpp_dir}/include)
+include_directories(${logger_dir}/include)
+
+asterisk_scf_slice_include_directories(${API_SLICE_DIR})
+
+asterisk_scf_component_init(mediaformatgenetic)
+asterisk_scf_component_add_file(mediaformatgeneric MediaFormatGeneric.cpp)
+asterisk_scf_component_add_boost_libraries(mediaformatgeneric core thread)
+asterisk_scf_component_build_icebox(mediaformatgeneric)
+target_link_libraries(mediaformatgeneric logging-client)
+target_link_libraries(mediaformatgeneric asterisk-scf-api)
+asterisk_scf_component_install(mediaformatgeneric)
diff --git a/src/MediaFormatGeneric.cpp b/src/MediaFormatGeneric.cpp
new file mode 100644
index 0000000..1db9884
--- /dev/null
+++ b/src/MediaFormatGeneric.cpp
@@ -0,0 +1,313 @@
+/*
+ * 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>
+#include <IceUtil/UUID.h>
+
+#include <boost/shared_ptr.hpp>
+
+#include <AsteriskSCF/Core/Discovery/ServiceLocatorIf.h>
+#include <AsteriskSCF/Media/MediaIf.h>
+#include <AsteriskSCF/Media/SDP/MediaSDPIf.h>
+#include <AsteriskSCF/Media/Formats/AudioFormats.h>
+#include <AsteriskSCF/System/Component/ComponentServiceIf.h>
+#include <AsteriskSCF/Logger/IceLogger.h>
+#include <AsteriskSCF/logger.h>
+
+using namespace std;
+using namespace AsteriskSCF::Core::Discovery::V1;
+using namespace AsteriskSCF::Media::V1;
+using namespace AsteriskSCF::Media::SDP::V1;
+using namespace AsteriskSCF::Media::Formats::Audio::V1;
+using namespace AsteriskSCF::System::Component::V1;
+using namespace AsteriskSCF::System::Logging;
+
+namespace
+{
+Logger lg = getLoggerFactory().getLogger("AsteriskSCF.MediaFormatGeneric");
+}
+
+/**
+ * Implementation of the ServiceLocatorParamsCompare class
+ */
+class SDPDescriptorCompareServiceImpl : public ServiceLocatorParamsCompare
+{
+public:
+ bool isSupported(const ServiceLocatorParamsPtr& params, const Ice::Current&)
+ {
+ SDPDescriptorServiceLocatorParamsPtr descriptorParams = SDPDescriptorServiceLocatorParamsPtr::dynamicCast(params);
+
+ if (descriptorParams == 0)
+ {
+ return false;
+ }
+
+ Ice::StringSeq::const_iterator format = std::find(mSupportedFormats.begin(), mSupportedFormats.end(), descriptorParams->name);
+
+ if (format == mSupportedFormats.end())
+ {
+ return false;
+ }
+
+ return true;
+ };
+
+ void addFormat(const std::string& name)
+ {
+ mSupportedFormats.push_back(name);
+ };
+
+private:
+ /**
+ * Supported formats in named form
+ */
+ Ice::StringSeq mSupportedFormats;
+};
+
+/**
+ * Smart pointer for the SDPDescriptorCompareServiceImpl class
+ */
+typedef IceUtil::Handle<SDPDescriptorCompareServiceImpl> SDPDescriptorCompareServiceImplPtr;
+
+/**
+ * Implementation of the SDPDescriptorService class
+ *
+ * Note that this does not have a lock on purpose because the supported formats will not
+ * be changed once the service goes into operation.
+ */
+class SDPDescriptorServiceImpl : public SDPDescriptorService
+{
+public:
+ FormatPtr getNamedFormat(const std::string& name, const Ice::Current&)
+ {
+ std::map<std::string, FormatPtr>::const_iterator format = mNamedFormats.find(name);
+
+ if (format == mNamedFormats.end())
+ {
+ return 0;
+ }
+
+ return format->second;
+ };
+
+ FormatPtr getDescribedFormat(const SDPDescriptorPtr& descriptor, const Ice::Current&)
+ {
+ if (descriptor->payload < 96)
+ {
+ std::map<int, FormatPtr>::iterator format = mPayloadNumberFormats.find(descriptor->payload);
+
+ if (format == mPayloadNumberFormats.end())
+ {
+ return 0;
+ }
+
+ return format->second;
+ }
+ else
+ {
+ std::map<std::string, FormatPtr>::iterator format = mPayloadNameFormats.find(descriptor->subtype);
+
+ if (format == mPayloadNameFormats.end())
+ {
+ return 0;
+ }
+
+ return format->second;
+ }
+
+ // This will never get reached but just in case the compiler is silly...
+ return 0;
+ };
+
+ SDPDescriptorPtr getDescriptor(const FormatPtr& format, const Ice::Current&)
+ {
+ std::map<std::string, SDPDescriptorPtr>::const_iterator descriptor = mFormatDescriptors.find(format->ice_id());
+
+ if (descriptor == mFormatDescriptors.end())
+ {
+ return 0;
+ }
+
+ return descriptor->second;
+ };
+
+ /**
+ * Implementation specific function which adds a format to this descriptor service
+ */
+ void addFormat(const std::string& name, const FormatPtr& format, const SDPDescriptorPtr& descriptor)
+ {
+ mNamedFormats.insert(make_pair(name, format));
+ mFormatDescriptors.insert(make_pair(format->ice_id(), descriptor));
+
+ if (descriptor->payload < 96)
+ {
+ /*
+ * If this is a static payload we store solely on the payload number itself
+ * since some endpoints do not provide a payload name.
+ */
+ mPayloadNumberFormats.insert(make_pair(descriptor->payload, format));
+ }
+ else
+ {
+ /*
+ * If this is a dynamic payload we store based on the payload name since the
+ * payload number itself is not assigned to it.
+ */
+ mPayloadNameFormats.insert(make_pair(descriptor->subtype, format));
+ }
+ };
+
+private:
+ /**
+ * Mapping for named formats
+ */
+ std::map<std::string, FormatPtr> mNamedFormats;
+
+ /**
+ * Mapping for described formats using static payload number
+ */
+ std::map<int, FormatPtr> mPayloadNumberFormats;
+
+ /**
+ * Mapping for described formats using payload name
+ */
+ std::map<std::string, FormatPtr> mPayloadNameFormats;
+
+ /**
+ * Mapping for format descriptors
+ */
+ std::map<std::string, SDPDescriptorPtr> mFormatDescriptors;
+};
+
+/**
+ * Smart pointer for the SDPDescriptorServiceImpl class
+ */
+typedef IceUtil::Handle<SDPDescriptorServiceImpl> SDPDescriptorServiceImplPtr;
+
+/**
+ * Implementation of the IceBox::Service class
+ */
+class MediaFormatGenericApp : public IceBox::Service
+{
+public:
+ void start(const std::string&, const Ice::CommunicatorPtr&, const Ice::StringSeq&);
+ void stop();
+
+private:
+ /**
+ * Ice Communicator used for this service.
+ */
+ Ice::CommunicatorPtr mCommunicator;
+
+ /**
+ * Object adapter that stuff is associated with.
+ */
+ Ice::ObjectAdapterPtr mAdapter;
+
+ /**
+ * A proxy to the service locator manager for our SDP descriptor service.
+ */
+ ServiceManagementPrx mServiceManagement;
+
+ /**
+ * A proxy to the service locator management service.
+ */
+ ServiceLocatorManagementPrx mManagement;
+
+ /**
+ * Unique guid for SDP descriptor service name comparator.
+ */
+ std::string mCompareGuid;
+};
+
+/**
+ * Implementation of the IceBox::Service::start method.
+ */
+void MediaFormatGenericApp::start(const std::string&, const Ice::CommunicatorPtr& communicator,
+ const Ice::StringSeq&)
+{
+ // Use the configured value for the service locator management to create a proxy
+ mManagement = ServiceLocatorManagementPrx::checkedCast(communicator->propertyToProxy("ServiceLocatorManagementProxy"));
+
+ mAdapter = communicator->createObjectAdapter("MediaFormatGenericAdapter");
+
+ // Create an instance of our SDP descriptor service
+ SDPDescriptorServiceImplPtr descriptorService = new SDPDescriptorServiceImpl();
+
+ // Create an instance of our custom comparator service
+ SDPDescriptorCompareServiceImplPtr comparatorService = new SDPDescriptorCompareServiceImpl();
+
+ // Add the ulaw audio format
+ ULAWPtr ulaw = new ULAW();
+ SDPDescriptorPtr ulawSDP = new SDPDescriptor();
+ ulawSDP->payload = 0;
+ ulawSDP->type = "audio";
+ ulawSDP->subtype = "PCMU";
+ ulawSDP->samplerate = 8000;
+ descriptorService->addFormat("ulaw", ulaw, ulawSDP);
+ comparatorService->addFormat("ulaw");
+
+ // Add the alaw audio format
+ ALAWPtr alaw = new ALAW();
+ SDPDescriptorPtr alawSDP = new SDPDescriptor();
+ alawSDP->payload = 8;
+ alawSDP->type = "audio";
+ alawSDP->subtype = "PCMA";
+ alawSDP->samplerate = 8000;
+ descriptorService->addFormat("alaw", alaw, alawSDP);
+ comparatorService->addFormat("alaw");
+
+ // Register our custom comparator with the service locator
+ ServiceLocatorParamsComparePrx comparatorServicePrx = ServiceLocatorParamsComparePrx::uncheckedCast(
+ mAdapter->addWithUUID(comparatorService));
+ mCompareGuid = IceUtil::generateUUID();
+ mManagement->addCompare(mCompareGuid, comparatorServicePrx);
+
+ // Add ourselves to the service locator
+ Ice::ObjectPrx descriptorServicePrx = mAdapter->addWithUUID(descriptorService);
+ mServiceManagement = ServiceManagementPrx::uncheckedCast(
+ mManagement->addService(descriptorServicePrx, "Media/SDP_Descriptor"));
+
+ // Populate some locator parameters so we can be found
+ SDPDescriptorServiceLocatorParamsPtr params = new SDPDescriptorServiceLocatorParams();
+ params->category = "Media/SDP_Descriptor";
+
+ // Now we can add these parameters and tada we shall be found
+ mServiceManagement->addLocatorParams(params, mCompareGuid);
+
+ mAdapter->activate();
+}
+
+/**
+ * Implementation of the IceBox::Service::stop method.
+ */
+void MediaFormatGenericApp::stop()
+{
+ // Remove our comparator from the service locator
+ mManagement->removeCompare(mCompareGuid);
+
+ // Remove our SDP descriptor service from the service locator
+ mServiceManagement->unregister();
+}
+
+extern "C"
+{
+ASTERISK_SCF_ICEBOX_EXPORT IceBox::Service* create(Ice::CommunicatorPtr)
+{
+ return new MediaFormatGenericApp;
+}
+}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..e69de29
-----------------------------------------------------------------------
--
asterisk-scf/integration/mediaformatgeneric.git
More information about the asterisk-scf-commits
mailing list