[asterisk-scf-commits] asterisk-scf/integration/mediaformatgeneric.git branch "resampling" created.

Commits to the Asterisk SCF project code repositories asterisk-scf-commits at lists.digium.com
Mon Aug 22 16:52:38 CDT 2011


branch "resampling" has been created
        at  3865e464a88d7aa5d23465000568af11b2c182be (commit)

- Log -----------------------------------------------------------------
commit 3865e464a88d7aa5d23465000568af11b2c182be
Author: Mark Michelson <mmichelson at digium.com>
Date:   Mon Aug 22 15:23:56 2011 -0500

    Add some generic media format operation services.

diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e216ea7..f96a9fb 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -5,8 +5,10 @@ astscf_component_add_files(mediaformatgeneric MediaFormatGeneric.cpp)
 astscf_component_add_files(mediaformatgeneric MediaFormatGeneric.h)
 astscf_component_add_files(mediaformatgeneric MediaFormatGenericConfiguration.cpp)
 astscf_component_add_files(mediaformatgeneric MediaFormatGenericConfiguration.h)
+astscf_component_add_files(mediaformatgeneric GenericFormatOperations.cpp)
+astscf_component_add_files(mediaformatgeneric GenericFormatOperations.h)
 astscf_component_add_slices(mediaformatgeneric PROJECT AsteriskSCF/Configuration/MediaFormatGeneric/MediaFormatGenericConfigurationIf.ice)
-astscf_component_add_boost_libraries(mediaformatgeneric core thread)
+astscf_component_add_boost_libraries(mediaformatgeneric core thread system)
 astscf_component_add_slice_collection_libraries(mediaformatgeneric ASTSCF)
 astscf_component_build_icebox(mediaformatgeneric)
 target_link_libraries(mediaformatgeneric logging-client)
diff --git a/src/GenericFormatOperations.cpp b/src/GenericFormatOperations.cpp
new file mode 100644
index 0000000..78b92c9
--- /dev/null
+++ b/src/GenericFormatOperations.cpp
@@ -0,0 +1,95 @@
+/*
+ * 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 <boost/asio/detail/socket_ops.hpp>
+
+#include "GenericFormatOperations.h"
+
+using namespace AsteriskSCF::Media::V1;
+
+bool Generic8BitFormatOperationsService::checkCompatible(
+        const FormatPtr& format1,
+        const FormatPtr& format2,
+        const Ice::Current&)
+{
+    return format1->name == format2->name;
+}
+
+FramePayloadPtr Generic8BitFormatOperationsService::decodePayload(
+        const Ice::ByteSeq& toDecode,
+        const Ice::Current&)
+{
+    Ice::ByteSeq bytePayload;
+    copy(toDecode.begin(), toDecode.end(), std::back_inserter(bytePayload));
+    return new ByteSeqPayload(bytePayload);
+}
+
+Ice::ByteSeq Generic8BitFormatOperationsService::encodePayload(
+        const FramePayloadPtr& toEncode,
+        const Ice::Current&)
+{
+    ByteSeqPayloadPtr bytePayload = ByteSeqPayloadPtr::dynamicCast(toEncode);
+
+    if (!bytePayload)
+    {
+        //XXX Maybe throw an exception
+        return Ice::ByteSeq();
+    }
+
+    return bytePayload->payload;
+}
+
+bool Generic16BitFormatOperationsService::checkCompatible(
+        const FormatPtr& format1,
+        const FormatPtr& format2,
+        const Ice::Current&)
+{
+    return format1->name == format2->name;
+}
+
+FramePayloadPtr Generic16BitFormatOperationsService::decodePayload(
+        const Ice::ByteSeq& toDecode,
+        const Ice::Current&)
+{
+    Ice::ShortSeq shortPayload((Ice::Short*) &toDecode.front(),
+            (Ice::Short*) &toDecode[toDecode.size()]);
+
+    std::transform(shortPayload.begin(), shortPayload.end(),
+            shortPayload.begin(), boost::asio::detail::socket_ops::network_to_host_short);
+
+    return new ShortSeqPayload(shortPayload);
+}
+
+Ice::ByteSeq Generic16BitFormatOperationsService::encodePayload(
+        const FramePayloadPtr& toEncode,
+        const Ice::Current&)
+{
+    ShortSeqPayloadPtr shortPayload = ShortSeqPayloadPtr::dynamicCast(toEncode);
+
+    if (!shortPayload)
+    {
+        //XXX Maybe throw an exception
+        return Ice::ByteSeq();
+    }
+
+    std::transform(shortPayload->payload.begin(), shortPayload->payload.end(),
+            shortPayload->payload.begin(), boost::asio::detail::socket_ops::host_to_network_short);
+
+    Ice::ByteSeq bytes((Ice::Byte*) &shortPayload->payload.front(),
+            (Ice::Byte*) &shortPayload->payload[shortPayload->payload.size()]);
+
+    return bytes;
+}
diff --git a/src/GenericFormatOperations.h b/src/GenericFormatOperations.h
new file mode 100644
index 0000000..2b9871c
--- /dev/null
+++ b/src/GenericFormatOperations.h
@@ -0,0 +1,53 @@
+/*
+ * 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 <AsteriskSCF/Media/MediaIf.h>
+
+class Generic8BitFormatOperationsService : public AsteriskSCF::Media::V1::FormatOperationsService
+{
+    bool checkCompatible(
+            const AsteriskSCF::Media::V1::FormatPtr& format1,
+            const AsteriskSCF::Media::V1::FormatPtr& format2,
+            const Ice::Current&);
+
+    AsteriskSCF::Media::V1::FramePayloadPtr decodePayload(
+            const Ice::ByteSeq& toDecode,
+            const Ice::Current&);
+
+    Ice::ByteSeq encodePayload(
+            const AsteriskSCF::Media::V1::FramePayloadPtr& toEncode,
+            const Ice::Current&);
+};
+
+typedef IceUtil::Handle<Generic8BitFormatOperationsService> Generic8BitFormatOperationsServicePtr;
+
+class Generic16BitFormatOperationsService : public AsteriskSCF::Media::V1::FormatOperationsService
+{
+    bool checkCompatible(
+            const AsteriskSCF::Media::V1::FormatPtr& format1,
+            const AsteriskSCF::Media::V1::FormatPtr& format2,
+            const Ice::Current&);
+
+    AsteriskSCF::Media::V1::FramePayloadPtr decodePayload(
+            const Ice::ByteSeq& toDecode,
+            const Ice::Current&);
+
+    Ice::ByteSeq encodePayload(
+            const AsteriskSCF::Media::V1::FramePayloadPtr& toEncode,
+            const Ice::Current&);
+};
+
+typedef IceUtil::Handle<Generic16BitFormatOperationsService> Generic16BitFormatOperationsServicePtr;
diff --git a/src/MediaFormatGeneric.cpp b/src/MediaFormatGeneric.cpp
index 33c84e6..9bffa97 100644
--- a/src/MediaFormatGeneric.cpp
+++ b/src/MediaFormatGeneric.cpp
@@ -29,6 +29,7 @@
 #include "MediaFormatGeneric.h"
 #include "MediaFormatGenericConfiguration.h"
 #include "MediaFormatGenericConfigurationIf.h"
+#include "GenericFormatOperations.h"
 
 using namespace std;
 using namespace AsteriskSCF::Core::Discovery::V1;
@@ -80,6 +81,16 @@ private:
     ServiceLocatorManagementPrx mManagement;
 
     /**
+     * Proxy for the generic 8-bit audio format operations
+     */
+    FormatOperationsServicePrx m8BitFormatOperationsProxy;
+
+    /**
+     * Proxy for the generic 16-bit audio format operations
+     */
+    FormatOperationsServicePrx m16BitFormatOperationsProxy;
+
+    /**
      * Unique guid for SDP descriptor service name comparator.
      */
     std::string mCompareGuid;
@@ -270,25 +281,34 @@ void MediaFormatGenericApp::start(const std::string&, const Ice::CommunicatorPtr
     // Create an instance of our configuration service
     ConfigurationServiceImplPtr configurationService = new ConfigurationServiceImpl(descriptorService, comparatorService);
 
+    //Generic8BitFormatOperationsServicePtr eightBitService(new Generic8BitFormatOperationsService);
+    //Generic16BitFormatOperationsServicePtr sixteenBitService(new Generic16BitFormatOperationsService);
+    m8BitFormatOperationsProxy = FormatOperationsServicePrx::uncheckedCast(mAdapter->add(new Generic8BitFormatOperationsService, communicator->stringToIdentity("8BitAudio")));
+    m16BitFormatOperationsProxy = FormatOperationsServicePrx::uncheckedCast(mAdapter->add(new Generic16BitFormatOperationsService, communicator->stringToIdentity("16BitAudio")));
+
     // Add the ulaw audio format
     G711uLAWPtr ulaw = new G711uLAW();
     ulaw->name = "ulaw";
+    ulaw->sampleSize = 8;
+    ulaw->operations = m8BitFormatOperationsProxy;
     SDPDescriptorPtr ulawSDP = new SDPDescriptor();
     ulawSDP->payload = 0;
     ulawSDP->type = "audio";
     ulawSDP->subtype = "PCMU";
-    ulawSDP->samplerate = 8000;
+    ulawSDP->samplerate = ulaw->sampleRate = 8000;
     descriptorService->addFormat(ulaw->name, ulaw, ulawSDP);
     comparatorService->addFormat(ulaw->name);
 
     // Add the alaw audio format
     G711aLAWPtr alaw = new G711aLAW();
     alaw->name = "alaw";
+    alaw->sampleSize = 8;
+    alaw->operations = m8BitFormatOperationsProxy;
     SDPDescriptorPtr alawSDP = new SDPDescriptor();
     alawSDP->payload = 8;
     alawSDP->type = "audio";
     alawSDP->subtype = "PCMA";
-    alawSDP->samplerate = 8000;
+    alawSDP->samplerate = alaw->sampleRate = 8000;
     descriptorService->addFormat(alaw->name, alaw, alawSDP);
     comparatorService->addFormat(alaw->name);
 

-----------------------------------------------------------------------


-- 
asterisk-scf/integration/mediaformatgeneric.git



More information about the asterisk-scf-commits mailing list