Add functions IsLegalMidName and IsLegalRsidName
This is a preparation for deleting the class StringRtpHeaderExtension.
Bug: webrtc:10440
Change-Id: I3480e58d96e67d10c4d78597c8ab7f01b63e37ca
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/128761
Commit-Queue: Niels Moller <nisse@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27228}
diff --git a/call/rtcp_demuxer.cc b/call/rtcp_demuxer.cc
index e181d3a..d35548d 100644
--- a/call/rtcp_demuxer.cc
+++ b/call/rtcp_demuxer.cc
@@ -18,6 +18,7 @@
#include "api/rtp_headers.h"
#include "call/rtcp_packet_sink_interface.h"
#include "call/rtp_rtcp_demuxer_helper.h"
+#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "rtc_base/checks.h"
namespace webrtc {
@@ -39,7 +40,7 @@
void RtcpDemuxer::AddSink(const std::string& rsid,
RtcpPacketSinkInterface* sink) {
- RTC_DCHECK(StreamId::IsLegalRsidName(rsid));
+ RTC_DCHECK(IsLegalRsidName(rsid));
RTC_DCHECK(sink);
RTC_DCHECK(!ContainerHasKey(broadcast_sinks_, sink));
RTC_DCHECK(!MultimapAssociationExists(rsid_sinks_, rsid, sink));
diff --git a/call/rtp_demuxer.cc b/call/rtp_demuxer.cc
index 8f0e2e5..23f605d 100644
--- a/call/rtp_demuxer.cc
+++ b/call/rtp_demuxer.cc
@@ -38,8 +38,8 @@
RtpPacketSinkInterface* sink) {
RTC_DCHECK(!criteria.payload_types.empty() || !criteria.ssrcs.empty() ||
!criteria.mid.empty() || !criteria.rsid.empty());
- RTC_DCHECK(criteria.mid.empty() || Mid::IsLegalMidName(criteria.mid));
- RTC_DCHECK(criteria.rsid.empty() || StreamId::IsLegalRsidName(criteria.rsid));
+ RTC_DCHECK(criteria.mid.empty() || IsLegalMidName(criteria.mid));
+ RTC_DCHECK(criteria.rsid.empty() || IsLegalRsidName(criteria.rsid));
RTC_DCHECK(sink);
// We return false instead of DCHECKing for logical conflicts with the new
diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn
index 9fe7fdc..2cabd1e 100644
--- a/modules/rtp_rtcp/BUILD.gn
+++ b/modules/rtp_rtcp/BUILD.gn
@@ -104,6 +104,7 @@
"../../rtc_base/system:unused",
"../../system_wrappers",
"../video_coding:codec_globals_headers",
+ "//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional",
"//third_party/abseil-cpp/absl/types:variant",
]
diff --git a/modules/rtp_rtcp/include/rtp_rtcp_defines.cc b/modules/rtp_rtcp/include/rtp_rtcp_defines.cc
index d23d82d..20bd1e7 100644
--- a/modules/rtp_rtcp/include/rtp_rtcp_defines.cc
+++ b/modules/rtp_rtcp/include/rtp_rtcp_defines.cc
@@ -20,9 +20,8 @@
namespace webrtc {
-StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {}
-
-constexpr size_t StreamId::kMaxSize;
+namespace {
+constexpr size_t kMidRsidMaxSize = 16;
// Check if passed character is a "token-char" from RFC 4566.
static bool IsTokenChar(char ch) {
@@ -31,16 +30,30 @@
(ch >= 0x41 && ch <= 0x5a) || (ch >= 0x5e && ch <= 0x7e);
}
-bool StreamId::IsLegalMidName(rtc::ArrayView<const char> name) {
- return (name.size() <= kMaxSize && name.size() > 0 &&
+} // namespace
+
+StreamDataCounters::StreamDataCounters() : first_packet_time_ms(-1) {}
+
+constexpr size_t StreamId::kMaxSize;
+
+bool IsLegalMidName(absl::string_view name) {
+ return (name.size() <= kMidRsidMaxSize && name.size() > 0 &&
std::all_of(name.data(), name.data() + name.size(), IsTokenChar));
}
-bool StreamId::IsLegalRsidName(rtc::ArrayView<const char> name) {
- return (name.size() <= kMaxSize && name.size() > 0 &&
+bool StreamId::IsLegalMidName(rtc::ArrayView<const char> name) {
+ return ::webrtc::IsLegalMidName(absl::string_view(name.data(), name.size()));
+}
+
+bool IsLegalRsidName(absl::string_view name) {
+ return (name.size() <= kMidRsidMaxSize && name.size() > 0 &&
std::all_of(name.data(), name.data() + name.size(), isalnum));
}
+bool StreamId::IsLegalRsidName(rtc::ArrayView<const char> name) {
+ return ::webrtc::IsLegalRsidName(absl::string_view(name.data(), name.size()));
+}
+
void StreamId::Set(const char* data, size_t size) {
// If |data| contains \0, the stream id size might become less than |size|.
RTC_CHECK_LE(size, kMaxSize);
diff --git a/modules/rtp_rtcp/include/rtp_rtcp_defines.h b/modules/rtp_rtcp/include/rtp_rtcp_defines.h
index a4e75ba..d339ecb 100644
--- a/modules/rtp_rtcp/include/rtp_rtcp_defines.h
+++ b/modules/rtp_rtcp/include/rtp_rtcp_defines.h
@@ -15,6 +15,7 @@
#include <list>
#include <vector>
+#include "absl/strings/string_view.h"
#include "absl/types/variant.h"
#include "api/audio_codecs/audio_format.h"
#include "api/rtp_headers.h"
@@ -45,6 +46,9 @@
enum StorageType { kDontRetransmit, kAllowRetransmission };
+bool IsLegalMidName(absl::string_view name);
+bool IsLegalRsidName(absl::string_view name);
+
// This enum must not have any gaps, i.e., all integers between
// kRtpExtensionNone and kRtpExtensionNumberOfExtensions must be valid enum
// entries.