summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp')
-rw-r--r--Swiften/Parser/PayloadParsers/JingleRTPDescriptionParser.cpp80
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;
+ }
+}
+
+}