blob: 68893c7ae9b003df871fcb38aeafb856efea984d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*
* Copyright (c) 2012 Yoann Blein
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
#include <Swiften/Parser/PayloadParsers/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) {
if (media == "audio") {
return JingleRTPDescription::Audio;
} else if (media == "video") {
return JingleRTPDescription::Video;
} else {
return JingleRTPDescription::Unknown;
}
}
}
|