blob: f9d9bb32484c2b44a64b29af0cf4ef44681b6e5f (
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
|
/*
* Copyright (c) 2012 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 <boost/numeric/conversion/cast.hpp>
namespace Swift {
RTPPayloadTypeParser::RTPPayloadTypeParser() : level(0) {
}
void RTPPayloadTypeParser::handleStartElement(const std::string& element, const std::string&, const AttributeMap& attributes) {
if (level == 0) {
// channels
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::numeric_cast<boost::uint8_t>(boost::lexical_cast<int>(attributes.getAttributeValue("id").get_value_or("0"))));
} catch (boost::bad_lexical_cast &) {
getPayloadInternal()->setID(151);
}
// 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 && element == "parameter") {
getPayloadInternal()->addParameter(attributes.getAttributeValue("name").get_value_or(""),
attributes.getAttributeValue("value").get_value_or(""));
}
++level;
}
void RTPPayloadTypeParser::handleEndElement(const std::string&, const std::string&) {
--level;
}
}
|