diff options
author | dknn <yoann.blein@free.fr> | 2012-06-02 22:41:35 (GMT) |
---|---|---|
committer | dknn <yoann.blein@free.fr> | 2012-09-22 08:49:55 (GMT) |
commit | 174d01d9812694d201f6f3939fc7b8bf4650cfa2 (patch) | |
tree | 2662370404afd5027afea8dd8f990a81d9df83b2 /Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.cpp | |
parent | ed95bc3cb17285a16a201f8ffe26ac38a4403f47 (diff) | |
download | swift-contrib-174d01d9812694d201f6f3939fc7b8bf4650cfa2.zip swift-contrib-174d01d9812694d201f6f3939fc7b8bf4650cfa2.tar.bz2 |
Major part of a RTP description element
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 ""; +} + +} |