summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.cpp')
-rw-r--r--Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.cpp b/Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.cpp
new file mode 100644
index 0000000..bddf96a
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/RTPPayloadTypeParser.cpp
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2011 Yoann Blein
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include "RTPPayloadTypeParser.h"
+
+#include <boost/optional.hpp>
+#include <boost/lexical_cast.hpp>
+
+//#include <Swiften/Base/DateTime.h>
+//#include <Swiften/Base/Log.h>
+
+namespace Swift {
+
+RTPPayloadTypeParser::RTPPayloadTypeParser() : level(0) {
+
+}
+
+void RTPPayloadTypeParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) {
+ if (level == 0) {
+ // channel
+ try {
+ getPayloadInternal()->setChannels(boost::lexical_cast<boost::uint32_t>(attributes.getAttributeValue("channels").get_value_or("1")));
+ } catch (boost::bad_lexical_cast &) {
+ getPayloadInternal()->setChannels(1);
+ }
+ // clockrate
+ try {
+ getPayloadInternal()->setClockrate(boost::lexical_cast<boost::uint32_t>(attributes.getAttributeValue("clockrate").get_value_or("0")));
+ } catch (boost::bad_lexical_cast &) {
+ getPayloadInternal()->setClockrate(0);
+ }
+ // ID
+ try {
+ getPayloadInternal()->setID(boost::lexical_cast<boost::uint8_t>(attributes.getAttributeValue("id").get_value_or("0")));
+ } catch (boost::bad_lexical_cast &) {
+ getPayloadInternal()->setID(0);
+ }
+ // maxptime
+ try {
+ getPayloadInternal()->setMaxptime(boost::lexical_cast<boost::uint32_t>(attributes.getAttributeValue("maxptime").get_value_or("0")));
+ } catch (boost::bad_lexical_cast &) {
+ getPayloadInternal()->setMaxptime(0);
+ }
+ // name
+ getPayloadInternal()->setName(attributes.getAttributeValue("name").get_value_or(""));
+ // ptime
+ try {
+ getPayloadInternal()->setPTime(boost::lexical_cast<boost::uint32_t>(attributes.getAttributeValue("ptime").get_value_or("0")));
+ } catch (boost::bad_lexical_cast &) {
+ getPayloadInternal()->setPTime(0);
+ }
+ } else if (level == 1) {
+ getPayloadInternal()->addParameter(attributes.getAttributeValue("name").get_value_or(""),
+ attributes.getAttributeValue("value").get_value_or(""));
+ }
+ ++level;
+}
+
+void RTPPayloadTypeParser::handleEndElement(const std::string& element, const std::string&) {
+ --level;
+}
+
+}