summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordknn <yoann.blein@free.fr>2012-06-02 15:31:42 (GMT)
committerdknn <yoann.blein@free.fr>2012-09-22 08:39:46 (GMT)
commitfa9b881e10e7cab8495909818cc61519d24d6117 (patch)
tree944261259bbece0bb1027a83c6a30e5ec44738a8 /Swiften/Serializer
parent21719e2ca06b12d214c32ed24b3ecc2227c8dd07 (diff)
downloadswift-contrib-fa9b881e10e7cab8495909818cc61519d24d6117.zip
swift-contrib-fa9b881e10e7cab8495909818cc61519d24d6117.tar.bz2
Payload, serializer and parser for the "payload-type" XML node
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.cpp54
-rw-r--r--Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.h23
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp39
3 files changed, 116 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.cpp b/Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.cpp
new file mode 100644
index 0000000..db21146
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2011 Yoann Blein
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.h>
+
+#include <boost/shared_ptr.hpp>
+#include <boost/smart_ptr/make_shared.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include <Swiften/Serializer/XML/XMLElement.h>
+
+
+
+namespace Swift {
+
+RTPPayloadTypeSerializer::RTPPayloadTypeSerializer() {
+}
+
+std::string RTPPayloadTypeSerializer::serializePayload(boost::shared_ptr<RTPPayloadType> payloadType) const {
+ XMLElement payloadTypeElement("payload-type");
+
+ if (payloadType->getChannels() != 1) {
+ payloadTypeElement.setAttribute("channels", boost::lexical_cast<std::string>(payloadType->getChannels()));
+ }
+ if (payloadType->getClockrate() != 0) {
+ payloadTypeElement.setAttribute("clockrate", boost::lexical_cast<std::string>(payloadType->getClockrate()));
+ }
+ payloadTypeElement.setAttribute("id", boost::lexical_cast<std::string>(static_cast<int>(payloadType->getID())));
+ if (payloadType->getMaxptime() != 0) {
+ payloadTypeElement.setAttribute("maxptime", boost::lexical_cast<std::string>(payloadType->getMaxptime()));
+ }
+ if (!payloadType->getName().empty()) {
+ payloadTypeElement.setAttribute("name", payloadType->getName());
+ }
+ if (payloadType->getPTime() != 0) {
+ payloadTypeElement.setAttribute("ptime", boost::lexical_cast<std::string>( payloadType->getPTime()));
+ }
+
+ const RTPPayloadType::ParameterMap &parameters = payloadType->getParameters();
+ RTPPayloadType::ParameterMap::const_iterator it;
+ for (it = parameters.begin(); it != parameters.end(); ++it) {
+ boost::shared_ptr<XMLElement> parameterElement = boost::make_shared<XMLElement>("parameter");
+ parameterElement->setAttribute("name", it->first);
+ parameterElement->setAttribute("value", it->second);
+ payloadTypeElement.addNode(parameterElement);
+ }
+
+ return payloadTypeElement.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.h b/Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.h
new file mode 100644
index 0000000..dda40ea
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.h
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2011 Yoann Blein
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+#include <Swiften/Elements/RTPPayloadType.h>
+
+#include <Swiften/Serializer/XML/XMLElement.h>
+
+namespace Swift {
+ class PayloadSerializerCollection; // NEEDED ?
+
+ class RTPPayloadTypeSerializer : public GenericPayloadSerializer<RTPPayloadType> {
+ public:
+ RTPPayloadTypeSerializer();
+
+ virtual std::string serializePayload(boost::shared_ptr<RTPPayloadType>) const;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp
index e3ec8fc..a1526fc 100644
--- a/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp
@@ -14,6 +14,7 @@
#include <Swiften/Serializer/PayloadSerializers/StreamInitiationFileInfoSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+#include <Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.h>
#include <Swiften/Elements/JingleFileTransferDescription.h>
#include <Swiften/Elements/StreamInitiationFileInfo.h>
#include <Swiften/Elements/JingleIBBTransportPayload.h>
@@ -21,12 +22,14 @@
#include <Swiften/Elements/JingleFileTransferHash.h>
#include <Swiften/Elements/JinglePayload.h>
#include <Swiften/Elements/JingleFileTransferReceived.h>
+#include <Swiften/Elements/RTPPayloadType.h>
#include <Swiften/Base/DateTime.h>
using namespace Swift;
class JingleSerializersTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(JingleSerializersTest);
+
CPPUNIT_TEST(testSerialize_StreamInitiationFileInfo);
CPPUNIT_TEST(testSerialize_StreamInitiationFileInfoRange);
@@ -43,6 +46,9 @@ class JingleSerializersTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testSerialize_Xep0260_Example1);
+ CPPUNIT_TEST(testSerialize_RTPPayloadType_Simple);
+ CPPUNIT_TEST(testSerialize_RTPPayloadType_WithSub);
+
CPPUNIT_TEST_SUITE_END();
boost::shared_ptr<JinglePayloadSerializer> createTestling() {
@@ -504,6 +510,39 @@ class JingleSerializersTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload));
}
+ void testSerialize_RTPPayloadType_Simple() {
+ std::string expected = "<payload-type clockrate=\"16000\" id=\"96\" name=\"speex\"/>";
+
+ RTPPayloadType::ref payloadType = boost::make_shared<RTPPayloadType>(96);
+ payloadType->setName("speex");
+ payloadType->setClockrate(16000);
+
+ boost::shared_ptr<RTPPayloadTypeSerializer> serializer = boost::make_shared<RTPPayloadTypeSerializer>();
+ CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(payloadType));
+ }
+
+ void testSerialize_RTPPayloadType_WithSub() {
+ std::string expected = "<payload-type clockrate=\"90000\" id=\"98\" name=\"theora\">"
+ "<parameter name=\"configuration\" value=\"somebase16string\"/>"
+ "<parameter name=\"delivery-method\" value=\"inline\"/>"
+ "<parameter name=\"height\" value=\"600\"/>"
+ "<parameter name=\"sampling\" value=\"YCbCr-4:2:2\"/>"
+ "<parameter name=\"width\" value=\"800\"/>"
+ "</payload-type>";
+
+ RTPPayloadType::ref payloadType = boost::make_shared<RTPPayloadType>(98);
+ payloadType->setName("theora");
+ payloadType->setClockrate(90000);
+ payloadType->addParameter("height", "600");
+ payloadType->addParameter("width", "800");
+ payloadType->addParameter("delivery-method", "inline");
+ payloadType->addParameter("configuration", "somebase16string");
+ payloadType->addParameter("sampling", "YCbCr-4:2:2");
+
+ boost::shared_ptr<RTPPayloadTypeSerializer> serializer = boost::make_shared<RTPPayloadTypeSerializer>();
+ CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(payloadType));
+ }
+
private:
FullPayloadSerializerCollection collection;
};