Nagram/TMessagesProj/jni/voip/webrtc/pc/media_protocol_names.cc

106 lines
3.5 KiB
C++
Raw Normal View History

2020-08-14 16:58:22 +00:00
/*
* 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"
2021-06-25 00:43:10 +00:00
#include <ctype.h>
#include <stddef.h>
2022-03-11 16:49:54 +00:00
#include <string>
2020-08-14 16:58:22 +00:00
namespace cricket {
2022-03-11 16:49:54 +00:00
// The official registry of RTP parameters is at
// http://www.iana.org/assignments/rtp-parameters/rtp-parameters.xml
// The UDP/DTLS and TCP/DTLS prefixes are not registered there.
2020-08-14 16:58:22 +00:00
// 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/";
2022-03-11 16:49:54 +00:00
// Protocol names generated by WebRTC
2020-08-14 16:58:22 +00:00
const char kMediaProtocolSctp[] = "SCTP";
const char kMediaProtocolUdpDtlsSctp[] = "UDP/DTLS/SCTP";
2022-03-11 16:49:54 +00:00
const char kMediaProtocolDtlsSctp[] = "DTLS/SCTP";
2020-08-14 16:58:22 +00:00
const char kMediaProtocolTcpDtlsSctp[] = "TCP/DTLS/SCTP";
2022-03-11 16:49:54 +00:00
// RFC5124
const char kMediaProtocolDtlsSavpf[] = "UDP/TLS/RTP/SAVPF";
const char kMediaProtocolSavpf[] = "RTP/SAVPF";
const char kMediaProtocolAvpf[] = "RTP/AVPF";
namespace {
// Protocol names that we tolerate, but do not generate.
// We always generate offers with "UDP/TLS/RTP/SAVPF" when using DTLS-SRTP,
// but we tolerate "RTP/SAVPF" and "RTP/SAVP" and the "UDP/TLS" and "TCP/TLS"
// prefixes in offers we receive, for compatibility.
// RFC4585
const char kMediaProtocolSavp[] = "RTP/SAVP";
const char kMediaProtocolAvp[] = "RTP/AVP";
const char kMediaProtocolTcpTlsSavpf[] = "TCP/TLS/RTP/SAVPF";
const char kMediaProtocolUdpTlsSavpf[] = "UDP/TLS/RTP/SAVPF";
const char kMediaProtocolTcpTlsSavp[] = "TCP/TLS/RTP/SAVP";
const char kMediaProtocolUdpTlsSavp[] = "UDP/TLS/RTP/SAVP";
} // namespace
2020-08-14 16:58:22 +00:00
2022-03-11 16:49:54 +00:00
bool IsDtlsSctp(absl::string_view protocol) {
2020-08-14 16:58:22 +00:00
return protocol == kMediaProtocolDtlsSctp ||
protocol == kMediaProtocolUdpDtlsSctp ||
protocol == kMediaProtocolTcpDtlsSctp;
}
2022-03-11 16:49:54 +00:00
bool IsPlainSctp(absl::string_view protocol) {
2020-08-14 16:58:22 +00:00
return protocol == kMediaProtocolSctp;
}
2022-03-11 16:49:54 +00:00
bool IsSctpProtocol(absl::string_view protocol) {
return IsPlainSctp(protocol) || IsDtlsSctp(protocol);
}
bool IsRtpProtocol(absl::string_view protocol) {
2020-08-14 16:58:22 +00:00
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;
}
2022-03-11 16:49:54 +00:00
// Note that the below functions support some protocol strings purely for
// legacy compatibility, as required by JSEP in Section 5.1.2, Profile Names
// and Interoperability.
bool IsDtlsRtp(absl::string_view protocol) {
// Most-likely values first.
return protocol == kMediaProtocolDtlsSavpf ||
protocol == kMediaProtocolTcpTlsSavpf ||
protocol == kMediaProtocolUdpTlsSavpf ||
protocol == kMediaProtocolUdpTlsSavp ||
protocol == kMediaProtocolTcpTlsSavp;
}
bool IsPlainRtp(absl::string_view protocol) {
// Most-likely values first.
return protocol == kMediaProtocolSavpf || protocol == kMediaProtocolAvpf ||
protocol == kMediaProtocolSavp || protocol == kMediaProtocolAvp;
2020-08-14 16:58:22 +00:00
}
} // namespace cricket