blob: 3def3f0f2014412837b766039a87c9fde76ee600 [file] [log] [blame]
Harald Alvestrand5fc28b12019-05-13 13:36:16 +02001/*
2 * Copyright 2019 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include "pc/media_protocol_names.h"
12
13namespace cricket {
14
15// There are multiple variants of the RTP protocol stack, including
16// UDP/TLS/RTP/SAVPF (WebRTC default), RTP/AVP, RTP/AVPF, RTP/SAVPF,
17// TCP/DTLS/RTP/SAVPF and so on. We accept anything that has RTP/
18// embedded in it somewhere as being an RTP protocol.
19const char kMediaProtocolRtpPrefix[] = "RTP/";
20
21const char kMediaProtocolSctp[] = "SCTP";
22const char kMediaProtocolDtlsSctp[] = "DTLS/SCTP";
23const char kMediaProtocolUdpDtlsSctp[] = "UDP/DTLS/SCTP";
24const char kMediaProtocolTcpDtlsSctp[] = "TCP/DTLS/SCTP";
25
26bool IsDtlsSctp(const std::string& protocol) {
27 return protocol == kMediaProtocolDtlsSctp ||
28 protocol == kMediaProtocolUdpDtlsSctp ||
29 protocol == kMediaProtocolTcpDtlsSctp;
30}
31
32bool IsPlainSctp(const std::string& protocol) {
33 return protocol == kMediaProtocolSctp;
34}
35
36bool IsRtpProtocol(const std::string& protocol) {
37 if (protocol.empty()) {
38 return true;
39 }
40 size_t pos = protocol.find(cricket::kMediaProtocolRtpPrefix);
41 if (pos == std::string::npos) {
42 return false;
43 }
44 // RTP must be at the beginning of a string or not preceded by alpha
45 if (pos == 0 || !isalpha(protocol[pos - 1])) {
46 return true;
47 }
48 return false;
49}
50
51bool IsSctpProtocol(const std::string& protocol) {
52 return IsPlainSctp(protocol) || IsDtlsSctp(protocol);
53}
54
55} // namespace cricket