summaryrefslogtreecommitdiffstats
blob: 475142b64faf74dd2b1103db46497c090aef30d1 (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) 2012 Yoann Blein
 * Licensed under the simplified BSD license.
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 */

#include <Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.h>

#include <boost/shared_ptr.hpp>
#include <boost/smart_ptr/make_shared.hpp>
#include <boost/lexical_cast.hpp>

#include <Swiften/Base/foreach.h>
#include <Swiften/Serializer/XML/XMLElement.h>
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
#include <Swiften/Serializer/XML/XMLTextNode.h>

#include <Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.h>

namespace Swift {

JingleRTPDescriptionSerializer::JingleRTPDescriptionSerializer() {
}

std::string JingleRTPDescriptionSerializer::serializePayload(boost::shared_ptr<JingleRTPDescription> payload) const {
	XMLElement description("description", "urn:xmpp:jingle:apps:rtp:1");
	description.setAttribute("media", mediaTypeToString(payload->getMediaType()));
	if (payload->getSSRC()) {
		description.setAttribute("ssrc", boost::lexical_cast<std::string>(payload->getSSRC()));
	}

	if (!payload->getPayloadTypes().empty()) {
		RTPPayloadTypeSerializer payloadTypeSerializer;
		foreach(RTPPayloadType payloadType, payload->getPayloadTypes()) {
			description.addNode(boost::make_shared<XMLRawTextNode>(payloadTypeSerializer.serialize(boost::make_shared<RTPPayloadType>(payloadType))));
		}
	}

	std::string type, value;
	payload->getBandwidth(type, value);
	if (!type.empty()) {
		XMLElement::ref bandwidth = boost::make_shared<XMLElement>("bandwidth");
		bandwidth->setAttribute("type", type);
		bandwidth->addNode(XMLTextNode::create(value));
		description.addNode(bandwidth);
	}

	return description.serialize();
}

std::string JingleRTPDescriptionSerializer::mediaTypeToString(JingleRTPDescription::MediaType mediaType) const {
	switch (mediaType) {
		case JingleRTPDescription::Audio:
			return "audio";
		case JingleRTPDescription::Video:
			return "video";
		case JingleRTPDescription::Unknown:
		default:
			std::cerr << "Serializing unknown media type." << std::endl;
			return "";
	}
	assert(false);
	return "";
}

}