forked from webrtc-sdk/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
media_protocol_names.cc
55 lines (46 loc) · 1.74 KB
/
media_protocol_names.cc
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
/*
* Copyright 2019 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "pc/media_protocol_names.h"
namespace cricket {
// There are multiple variants of the RTP protocol stack, including
// UDP/TLS/RTP/SAVPF (WebRTC default), RTP/AVP, RTP/AVPF, RTP/SAVPF,
// TCP/DTLS/RTP/SAVPF and so on. We accept anything that has RTP/
// embedded in it somewhere as being an RTP protocol.
const char kMediaProtocolRtpPrefix[] = "RTP/";
const char kMediaProtocolSctp[] = "SCTP";
const char kMediaProtocolDtlsSctp[] = "DTLS/SCTP";
const char kMediaProtocolUdpDtlsSctp[] = "UDP/DTLS/SCTP";
const char kMediaProtocolTcpDtlsSctp[] = "TCP/DTLS/SCTP";
bool IsDtlsSctp(const std::string& protocol) {
return protocol == kMediaProtocolDtlsSctp ||
protocol == kMediaProtocolUdpDtlsSctp ||
protocol == kMediaProtocolTcpDtlsSctp;
}
bool IsPlainSctp(const std::string& protocol) {
return protocol == kMediaProtocolSctp;
}
bool IsRtpProtocol(const std::string& protocol) {
if (protocol.empty()) {
return true;
}
size_t pos = protocol.find(cricket::kMediaProtocolRtpPrefix);
if (pos == std::string::npos) {
return false;
}
// RTP must be at the beginning of a string or not preceded by alpha
if (pos == 0 || !isalpha(protocol[pos - 1])) {
return true;
}
return false;
}
bool IsSctpProtocol(const std::string& protocol) {
return IsPlainSctp(protocol) || IsDtlsSctp(protocol);
}
} // namespace cricket