diff options
author | dknn <yoann.blein@free.fr> | 2012-06-03 13:11:35 (GMT) |
---|---|---|
committer | dknn <yoann.blein@free.fr> | 2012-09-22 08:53:12 (GMT) |
commit | 931b52184bf37f298f9c967883a3b71c912f834b (patch) | |
tree | df2b6d80fb76d3ccbe1c721d3e574d0f2491c90a /Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp | |
parent | 174d01d9812694d201f6f3939fc7b8bf4650cfa2 (diff) | |
download | swift-contrib-931b52184bf37f298f9c967883a3b71c912f834b.zip swift-contrib-931b52184bf37f298f9c967883a3b71c912f834b.tar.bz2 |
Add parsing add related tests for RTP description
Diffstat (limited to 'Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp')
-rw-r--r-- | Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp b/Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp new file mode 100644 index 0000000..7429b39 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2012 Yoann Blein + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include "JingleRTPDescriptionParser.h" + +#include <Swiften/Parser/PayloadParserFactoryCollection.h> +#include <Swiften/Parser/PayloadParserFactory.h> + +#include <boost/optional.hpp> + +namespace Swift { + +JingleRTPDescriptionParser::JingleRTPDescriptionParser(PayloadParserFactoryCollection* factories) : + factories(factories), level(0), parsingBandwidth(false) { + +} + +void JingleRTPDescriptionParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { + if (level == 0) { + const std::string& media = attributes.getAttributeValue("media").get_value_or(""); + getPayloadInternal()->setMedia(mediaTypeFromString(media)); + } + + if (level == 1) { + if (element == "bandwidth") { + parsingBandwidth = true; + bandwidthType = attributes.getAttributeValue("type").get_value_or(""); + } else { + PayloadParserFactory* payloadParserFactory = factories->getPayloadParserFactory(element, ns, attributes); + if (payloadParserFactory) { + currentPayloadParser.reset(payloadParserFactory->createPayloadParser()); + } + } + } + + if (level >= 1 && currentPayloadParser && !parsingBandwidth) { + currentPayloadParser->handleStartElement(element, ns, attributes); + } + + ++level; +} + +void JingleRTPDescriptionParser::handleEndElement(const std::string& element, const std::string& ns) { + --level; + if (element == "bandwidth") { + parsingBandwidth = false; + getPayloadInternal()->setBandwidth(bandwidthType, bandwidthValue); + } else if (currentPayloadParser) { + if (level >= 1) { + currentPayloadParser->handleEndElement(element, ns); + } + if (level == 1) { + RTPPayloadType::ref payloadType = boost::dynamic_pointer_cast<RTPPayloadType>(currentPayloadParser->getPayload()); + if (payloadType) { + getPayloadInternal()->addPayloadType(*payloadType); + } + } + } +} + +void JingleRTPDescriptionParser::handleCharacterData(const std::string& data) { + if (level == 2 && parsingBandwidth) { + bandwidthValue += data; + } +} + +JingleRTPDescription::MediaType JingleRTPDescriptionParser::mediaTypeFromString(const std::string& media) const { + if (media == "audio") { + return JingleRTPDescription::Audio; + } else if (media == "video") { + return JingleRTPDescription::Video; + } else { + return JingleRTPDescription::Unknown; + } +} + +} |