webrtc_m130/pc/media_protocol_names.cc
Niels Möller d4aa3a3196 Use absl::string_view in SDP-related utilities
A step towards reduced copying in SDP parsing.

Bug: None
Change-Id: I3a5d89f483c1809929b7160b563c67b040c9df41
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/233080
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#35122}
2021-09-30 07:44:09 +00:00

61 lines
1.8 KiB
C++

/*
* 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"
#include <ctype.h>
#include <stddef.h>
#include <string>
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(absl::string_view protocol) {
return protocol == kMediaProtocolDtlsSctp ||
protocol == kMediaProtocolUdpDtlsSctp ||
protocol == kMediaProtocolTcpDtlsSctp;
}
bool IsPlainSctp(absl::string_view protocol) {
return protocol == kMediaProtocolSctp;
}
bool IsRtpProtocol(absl::string_view 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(absl::string_view protocol) {
return IsPlainSctp(protocol) || IsDtlsSctp(protocol);
}
} // namespace cricket