summaryrefslogtreecommitdiffstats
blob: bddf96a5c33621ace3bbd769ad1b8acc33aace35 (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
/*
 * 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;
}

}