blob: 52d676daf5990c88f6fc81801c53f8abe18c4cc1 [file] [log] [blame]
Harald Alvestrand5fc28b12019-05-13 11:36:161/*
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
Harald Alvestrand5761e7b2021-01-29 14:45:0813#include <ctype.h>
14#include <stddef.h>
15
Niels Möllerd4aa3a32021-09-29 11:23:0116#include <string>
17
Harald Alvestrand5fc28b12019-05-13 11:36:1618namespace cricket {
19
Harald Alvestrand1bffe9e2021-11-02 10:39:5920// The official registry of RTP parameters is at
21// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml
22// The UDP/DTLS and TCP/DTLS prefixes are not registered there.
23
Harald Alvestrand5fc28b12019-05-13 11:36:1624// There are multiple variants of the RTP protocol stack, including
25// UDP/TLS/RTP/SAVPF (WebRTC default), RTP/AVP, RTP/AVPF, RTP/SAVPF,
26// TCP/DTLS/RTP/SAVPF and so on. We accept anything that has RTP/
27// embedded in it somewhere as being an RTP protocol.
28const char kMediaProtocolRtpPrefix[] = "RTP/";
29
Harald Alvestrand1bffe9e2021-11-02 10:39:5930// Protocol names generated by WebRTC
Harald Alvestrand5fc28b12019-05-13 11:36:1631const char kMediaProtocolSctp[] = "SCTP";
Harald Alvestrand5fc28b12019-05-13 11:36:1632const char kMediaProtocolUdpDtlsSctp[] = "UDP/DTLS/SCTP";
Harald Alvestrand1bffe9e2021-11-02 10:39:5933const char kMediaProtocolDtlsSctp[] = "DTLS/SCTP";
Harald Alvestrand5fc28b12019-05-13 11:36:1634const char kMediaProtocolTcpDtlsSctp[] = "TCP/DTLS/SCTP";
Harald Alvestrand1bffe9e2021-11-02 10:39:5935// RFC5124
36const char kMediaProtocolDtlsSavpf[] = "UDP/TLS/RTP/SAVPF";
37const char kMediaProtocolSavpf[] = "RTP/SAVPF";
38const char kMediaProtocolAvpf[] = "RTP/AVPF";
39
40namespace {
41
42// Protocol names that we tolerate, but do not generate.
43// We always generate offers with "UDP/TLS/RTP/SAVPF" when using DTLS-SRTP,
44// but we tolerate "RTP/SAVPF" and "RTP/SAVP" and the "UDP/TLS" and "TCP/TLS"
45// prefixes in offers we receive, for compatibility.
46// RFC4585
47const char kMediaProtocolSavp[] = "RTP/SAVP";
48const char kMediaProtocolAvp[] = "RTP/AVP";
49
50const char kMediaProtocolTcpTlsSavpf[] = "TCP/TLS/RTP/SAVPF";
51const char kMediaProtocolUdpTlsSavpf[] = "UDP/TLS/RTP/SAVPF";
52const char kMediaProtocolTcpTlsSavp[] = "TCP/TLS/RTP/SAVP";
53const char kMediaProtocolUdpTlsSavp[] = "UDP/TLS/RTP/SAVP";
54
55} // namespace
Harald Alvestrand5fc28b12019-05-13 11:36:1656
Niels Möllerd4aa3a32021-09-29 11:23:0157bool IsDtlsSctp(absl::string_view protocol) {
Harald Alvestrand5fc28b12019-05-13 11:36:1658 return protocol == kMediaProtocolDtlsSctp ||
59 protocol == kMediaProtocolUdpDtlsSctp ||
60 protocol == kMediaProtocolTcpDtlsSctp;
61}
62
Niels Möllerd4aa3a32021-09-29 11:23:0163bool IsPlainSctp(absl::string_view protocol) {
Harald Alvestrand5fc28b12019-05-13 11:36:1664 return protocol == kMediaProtocolSctp;
65}
66
Harald Alvestrand1bffe9e2021-11-02 10:39:5967bool IsSctpProtocol(absl::string_view protocol) {
68 return IsPlainSctp(protocol) || IsDtlsSctp(protocol);
69}
70
Niels Möllerd4aa3a32021-09-29 11:23:0171bool IsRtpProtocol(absl::string_view protocol) {
Harald Alvestrand5fc28b12019-05-13 11:36:1672 if (protocol.empty()) {
73 return true;
74 }
75 size_t pos = protocol.find(cricket::kMediaProtocolRtpPrefix);
76 if (pos == std::string::npos) {
77 return false;
78 }
79 // RTP must be at the beginning of a string or not preceded by alpha
Niels Möllere66b83f2022-05-30 10:57:4180 if (pos == 0 || !isalpha(static_cast<unsigned char>(protocol[pos - 1]))) {
Harald Alvestrand5fc28b12019-05-13 11:36:1681 return true;
82 }
83 return false;
84}
85
Harald Alvestrand1bffe9e2021-11-02 10:39:5986// Note that the below functions support some protocol strings purely for
87// legacy compatibility, as required by JSEP in Section 5.1.2, Profile Names
88// and Interoperability.
89
90bool IsDtlsRtp(absl::string_view protocol) {
91 // Most-likely values first.
92 return protocol == kMediaProtocolDtlsSavpf ||
93 protocol == kMediaProtocolTcpTlsSavpf ||
94 protocol == kMediaProtocolUdpTlsSavpf ||
95 protocol == kMediaProtocolUdpTlsSavp ||
96 protocol == kMediaProtocolTcpTlsSavp;
97}
98
99bool IsPlainRtp(absl::string_view protocol) {
100 // Most-likely values first.
101 return protocol == kMediaProtocolSavpf || protocol == kMediaProtocolAvpf ||
102 protocol == kMediaProtocolSavp || protocol == kMediaProtocolAvp;
Harald Alvestrand5fc28b12019-05-13 11:36:16103}
104
105} // namespace cricket