diff options
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.cpp')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.cpp new file mode 100644 index 0000000..475142b --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.h> + +#include <boost/shared_ptr.hpp> +#include <boost/smart_ptr/make_shared.hpp> +#include <boost/lexical_cast.hpp> + +#include <Swiften/Base/foreach.h> +#include <Swiften/Serializer/XML/XMLElement.h> +#include <Swiften/Serializer/XML/XMLRawTextNode.h> +#include <Swiften/Serializer/XML/XMLTextNode.h> + +#include <Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.h> + +namespace Swift { + +JingleRTPDescriptionSerializer::JingleRTPDescriptionSerializer() { +} + +std::string JingleRTPDescriptionSerializer::serializePayload(boost::shared_ptr<JingleRTPDescription> payload) const { + XMLElement description("description", "urn:xmpp:jingle:apps:rtp:1"); + description.setAttribute("media", mediaTypeToString(payload->getMediaType())); + if (payload->getSSRC()) { + description.setAttribute("ssrc", boost::lexical_cast<std::string>(payload->getSSRC())); + } + + if (!payload->getPayloadTypes().empty()) { + RTPPayloadTypeSerializer payloadTypeSerializer; + foreach(RTPPayloadType payloadType, payload->getPayloadTypes()) { + description.addNode(boost::make_shared<XMLRawTextNode>(payloadTypeSerializer.serialize(boost::make_shared<RTPPayloadType>(payloadType)))); + } + } + + std::string type, value; + payload->getBandwidth(type, value); + if (!type.empty()) { + XMLElement::ref bandwidth = boost::make_shared<XMLElement>("bandwidth"); + bandwidth->setAttribute("type", type); + bandwidth->addNode(XMLTextNode::create(value)); + description.addNode(bandwidth); + } + + return description.serialize(); +} + +std::string JingleRTPDescriptionSerializer::mediaTypeToString(JingleRTPDescription::MediaType mediaType) const { + switch (mediaType) { + case JingleRTPDescription::Audio: + return "audio"; + case JingleRTPDescription::Video: + return "video"; + case JingleRTPDescription::Unknown: + default: + std::cerr << "Serializing unknown media type." << std::endl; + return ""; + } + assert(false); + return ""; +} + +} |