diff --git a/modules/rtp_rtcp/BUILD.gn b/modules/rtp_rtcp/BUILD.gn index 9bef2eef8e..4f621847f5 100644 --- a/modules/rtp_rtcp/BUILD.gn +++ b/modules/rtp_rtcp/BUILD.gn @@ -225,6 +225,7 @@ rtc_static_library("rtp_rtcp") { "../video_coding:codec_globals_headers", "//third_party/abseil-cpp/absl/container:inlined_vector", "//third_party/abseil-cpp/absl/memory", + "//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/source/rtp_sender.cc b/modules/rtp_rtcp/source/rtp_sender.cc index 5b952d0343..8afc2de985 100644 --- a/modules/rtp_rtcp/source/rtp_sender.cc +++ b/modules/rtp_rtcp/source/rtp_sender.cc @@ -16,6 +16,7 @@ #include #include "absl/memory/memory.h" +#include "absl/strings/match.h" #include "logging/rtc_event_log/events/rtc_event_rtp_packet_outgoing.h" #include "logging/rtc_event_log/rtc_event_log.h" #include "modules/remote_bitrate_estimator/test/bwe_test_logging.h" @@ -272,12 +273,11 @@ int32_t RTPSender::DeregisterRtpHeaderExtension(RTPExtensionType type) { return rtp_header_extension_map_.Deregister(type); } -int32_t RTPSender::RegisterPayload( - const char payload_name[RTP_PAYLOAD_NAME_SIZE], - int8_t payload_number, - uint32_t frequency, - size_t channels, - uint32_t rate) { +int32_t RTPSender::RegisterPayload(const char* payload_name, + int8_t payload_number, + uint32_t frequency, + size_t channels, + uint32_t rate) { RTC_DCHECK_LT(strlen(payload_name), RTP_PAYLOAD_NAME_SIZE); rtc::CritScope lock(&send_critsect_); @@ -290,8 +290,7 @@ int32_t RTPSender::RegisterPayload( RTC_DCHECK(payload); // Check if it's the same as we already have. - if (RtpUtility::StringCompare(payload->name, payload_name, - RTP_PAYLOAD_NAME_SIZE - 1)) { + if (absl::EqualsIgnoreCase(payload->name, payload_name)) { if (audio_configured_ && payload->typeSpecific.is_audio()) { auto& p = payload->typeSpecific.audio_payload(); if (rtc::SafeEq(p.format.clockrate_hz, frequency) && diff --git a/modules/rtp_rtcp/source/rtp_sender_audio.cc b/modules/rtp_rtcp/source/rtp_sender_audio.cc index 7941d916f0..6cf9a17e30 100644 --- a/modules/rtp_rtcp/source/rtp_sender_audio.cc +++ b/modules/rtp_rtcp/source/rtp_sender_audio.cc @@ -14,6 +14,7 @@ #include #include +#include "absl/strings/match.h" #include "api/audio_codecs/audio_format.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "modules/rtp_rtcp/source/byte_io.h" @@ -31,14 +32,13 @@ RTPSenderAudio::RTPSenderAudio(Clock* clock, RTPSender* rtp_sender) RTPSenderAudio::~RTPSenderAudio() {} -int32_t RTPSenderAudio::RegisterAudioPayload( - const char payloadName[RTP_PAYLOAD_NAME_SIZE], - const int8_t payload_type, - const uint32_t frequency, - const size_t channels, - const uint32_t rate, - RtpUtility::Payload** payload) { - if (RtpUtility::StringCompare(payloadName, "cn", 2)) { +int32_t RTPSenderAudio::RegisterAudioPayload(const char* payloadName, + const int8_t payload_type, + const uint32_t frequency, + const size_t channels, + const uint32_t rate, + RtpUtility::Payload** payload) { + if (absl::EqualsIgnoreCase(payloadName, "cn")) { rtc::CritScope cs(&send_audio_critsect_); // we can have multiple CNG payload types switch (frequency) { @@ -57,7 +57,7 @@ int32_t RTPSenderAudio::RegisterAudioPayload( default: return -1; } - } else if (RtpUtility::StringCompare(payloadName, "telephone-event", 15)) { + } else if (absl::EqualsIgnoreCase(payloadName, "telephone-event")) { rtc::CritScope cs(&send_audio_critsect_); // Don't add it to the list // we dont want to allow send with a DTMF payloadtype diff --git a/modules/rtp_rtcp/source/rtp_sender_audio.h b/modules/rtp_rtcp/source/rtp_sender_audio.h index a1e760bfbf..2c4c60c0ee 100644 --- a/modules/rtp_rtcp/source/rtp_sender_audio.h +++ b/modules/rtp_rtcp/source/rtp_sender_audio.h @@ -31,7 +31,7 @@ class RTPSenderAudio { RTPSenderAudio(Clock* clock, RTPSender* rtp_sender); ~RTPSenderAudio(); - int32_t RegisterAudioPayload(const char payloadName[RTP_PAYLOAD_NAME_SIZE], + int32_t RegisterAudioPayload(const char* payloadName, int8_t payload_type, uint32_t frequency, size_t channels, diff --git a/modules/rtp_rtcp/source/rtp_sender_video.cc b/modules/rtp_rtcp/source/rtp_sender_video.cc index ff14a2794b..2f7b440834 100644 --- a/modules/rtp_rtcp/source/rtp_sender_video.cc +++ b/modules/rtp_rtcp/source/rtp_sender_video.cc @@ -19,6 +19,7 @@ #include #include "absl/memory/memory.h" +#include "absl/strings/match.h" #include "api/crypto/frameencryptorinterface.h" #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" #include "modules/rtp_rtcp/source/byte_io.h" @@ -152,18 +153,18 @@ VideoCodecType RTPSenderVideo::VideoCodecType() const { // Static. RtpUtility::Payload* RTPSenderVideo::CreateVideoPayload( - const char payload_name[RTP_PAYLOAD_NAME_SIZE], + const char* payload_name, int8_t payload_type) { enum VideoCodecType video_type = kVideoCodecGeneric; - if (RtpUtility::StringCompare(payload_name, "VP8", 3)) { + if (absl::EqualsIgnoreCase(payload_name, "VP8")) { video_type = kVideoCodecVP8; - } else if (RtpUtility::StringCompare(payload_name, "VP9", 3)) { + } else if (absl::EqualsIgnoreCase(payload_name, "VP9")) { video_type = kVideoCodecVP9; - } else if (RtpUtility::StringCompare(payload_name, "H264", 4)) { + } else if (absl::EqualsIgnoreCase(payload_name, "H264")) { video_type = kVideoCodecH264; - } else if (RtpUtility::StringCompare(payload_name, "I420", 4)) { + } else if (absl::EqualsIgnoreCase(payload_name, "I420")) { video_type = kVideoCodecGeneric; - } else if (RtpUtility::StringCompare(payload_name, "stereo", 6)) { + } else if (absl::EqualsIgnoreCase(payload_name, "stereo")) { video_type = kVideoCodecGeneric; } else { video_type = kVideoCodecGeneric; diff --git a/modules/rtp_rtcp/source/rtp_utility.cc b/modules/rtp_rtcp/source/rtp_utility.cc index a75c8cffb6..53a006d4f9 100644 --- a/modules/rtp_rtcp/source/rtp_utility.cc +++ b/modules/rtp_rtcp/source/rtp_utility.cc @@ -43,10 +43,6 @@ enum { * Misc utility routines */ -bool StringCompare(const char* str1, const char* str2, const uint32_t length) { - return _strnicmp(str1, str2, length) == 0; -} - size_t Word32Align(size_t size) { uint32_t remainder = size % 4; if (remainder != 0) diff --git a/modules/rtp_rtcp/source/rtp_utility.h b/modules/rtp_rtcp/source/rtp_utility.h index 533a0dd2c1..07ef102b67 100644 --- a/modules/rtp_rtcp/source/rtp_utility.h +++ b/modules/rtp_rtcp/source/rtp_utility.h @@ -34,8 +34,6 @@ struct Payload { PayloadUnion typeSpecific; }; -bool StringCompare(const char* str1, const char* str2, const uint32_t length); - // Round up to the nearest size that is a multiple of 4. size_t Word32Align(size_t size); diff --git a/modules/video_capture/BUILD.gn b/modules/video_capture/BUILD.gn index 6ec38fe3c4..44db2eb477 100644 --- a/modules/video_capture/BUILD.gn +++ b/modules/video_capture/BUILD.gn @@ -38,6 +38,7 @@ rtc_static_library("video_capture_module") { "../../rtc_base:stringutils", "../../rtc_base/synchronization:rw_lock_wrapper", "../../system_wrappers", + "//third_party/abseil-cpp/absl/strings", "//third_party/libyuv", ] } diff --git a/modules/video_capture/device_info_impl.cc b/modules/video_capture/device_info_impl.cc index 2f0a39f296..cdcb5ddc4a 100644 --- a/modules/video_capture/device_info_impl.cc +++ b/modules/video_capture/device_info_impl.cc @@ -11,6 +11,7 @@ #include #include +#include "absl/strings/match.h" #include "modules/video_capture/device_info_impl.h" #include "modules/video_capture/video_capture_config.h" #include "rtc_base/logging.h" @@ -42,14 +43,12 @@ int32_t DeviceInfoImpl::NumberOfCapabilities(const char* deviceUniqueIdUTF8) { _apiLock.AcquireLockShared(); - if (_lastUsedDeviceNameLength == strlen((char*)deviceUniqueIdUTF8)) { - // Is it the same device that is asked for again. - if (_strnicmp((char*)_lastUsedDeviceName, (char*)deviceUniqueIdUTF8, - _lastUsedDeviceNameLength) == 0) { - // yes - _apiLock.ReleaseLockShared(); - return static_cast(_captureCapabilities.size()); - } + // Is it the same device that is asked for again. + if (absl::EqualsIgnoreCase( + deviceUniqueIdUTF8, + absl::string_view(_lastUsedDeviceName, _lastUsedDeviceNameLength))) { + _apiLock.ReleaseLockShared(); + return static_cast(_captureCapabilities.size()); } // Need to get exclusive rights to create the new capability map. _apiLock.ReleaseLockShared(); @@ -66,9 +65,9 @@ int32_t DeviceInfoImpl::GetCapability(const char* deviceUniqueIdUTF8, ReadLockScoped cs(_apiLock); - if ((_lastUsedDeviceNameLength != strlen((char*)deviceUniqueIdUTF8)) || - (_strnicmp((char*)_lastUsedDeviceName, (char*)deviceUniqueIdUTF8, - _lastUsedDeviceNameLength) != 0)) { + if (!absl::EqualsIgnoreCase( + deviceUniqueIdUTF8, + absl::string_view(_lastUsedDeviceName, _lastUsedDeviceNameLength))) { _apiLock.ReleaseLockShared(); _apiLock.AcquireLockExclusive(); if (-1 == CreateCapabilityMap(deviceUniqueIdUTF8)) { @@ -100,9 +99,9 @@ int32_t DeviceInfoImpl::GetBestMatchedCapability( return -1; ReadLockScoped cs(_apiLock); - if ((_lastUsedDeviceNameLength != strlen((char*)deviceUniqueIdUTF8)) || - (_strnicmp((char*)_lastUsedDeviceName, (char*)deviceUniqueIdUTF8, - _lastUsedDeviceNameLength) != 0)) { + if (!absl::EqualsIgnoreCase( + deviceUniqueIdUTF8, + absl::string_view(_lastUsedDeviceName, _lastUsedDeviceNameLength))) { _apiLock.ReleaseLockShared(); _apiLock.AcquireLockExclusive(); if (-1 == CreateCapabilityMap(deviceUniqueIdUTF8)) { diff --git a/rtc_base/socketadapters.cc b/rtc_base/socketadapters.cc index 45e002a6c7..9451928891 100644 --- a/rtc_base/socketadapters.cc +++ b/rtc_base/socketadapters.cc @@ -29,6 +29,7 @@ #include +#include "absl/strings/match.h" #include "rtc_base/buffer.h" #include "rtc_base/bytebuffer.h" #include "rtc_base/checks.h" @@ -461,7 +462,7 @@ void AsyncHttpsProxySocket::ProcessLine(char* data, size_t len) { return; } } else if ((state_ == PS_AUTHENTICATE) && - (_strnicmp(data, "Proxy-Authenticate:", 19) == 0)) { + absl::StartsWithIgnoreCase(data, "Proxy-Authenticate:")) { std::string response, auth_method; switch (HttpAuthenticate(data + 19, len - 19, proxy_, "CONNECT", "/", user_, pass_, context_, response, auth_method)) { @@ -489,12 +490,12 @@ void AsyncHttpsProxySocket::ProcessLine(char* data, size_t len) { unknown_mechanisms_.clear(); break; } - } else if (_strnicmp(data, "Content-Length:", 15) == 0) { + } else if (absl::StartsWithIgnoreCase(data, "Content-Length:")) { content_length_ = strtoul(data + 15, 0, 0); - } else if (_strnicmp(data, "Proxy-Connection: Keep-Alive", 28) == 0) { + } else if (absl::StartsWithIgnoreCase(data, "Proxy-Connection: Keep-Alive")) { expect_close_ = false; /* - } else if (_strnicmp(data, "Connection: close", 17) == 0) { + } else if (absl::StartsWithIgnoreCase(data, "Connection: close") { expect_close_ = true; */ } diff --git a/rtc_base/stringutils.h b/rtc_base/stringutils.h index 45f3a3acd0..702bc67b79 100644 --- a/rtc_base/stringutils.h +++ b/rtc_base/stringutils.h @@ -42,15 +42,6 @@ #define STACK_ARRAY(TYPE, LEN) \ static_cast(::alloca((LEN) * sizeof(TYPE))) - -#if defined(WEBRTC_POSIX) - -inline int _strnicmp(const char* s1, const char* s2, size_t n) { - return strncasecmp(s1, s2, n); -} - -#endif // WEBRTC_POSIX - /////////////////////////////////////////////////////////////////////////////// // Traits simplifies porting string functions to be CTYPE-agnostic ///////////////////////////////////////////////////////////////////////////////