From 06d3559b794a29ff3abfb3b5def71f39ea781f4b Mon Sep 17 00:00:00 2001 From: Mirko Bonadei Date: Wed, 1 Apr 2020 13:43:08 +0200 Subject: [PATCH] Replace std::string::find() == 0 with absl::StartsWith (part 2). This CL has been generated using clang-tidy [1] except for changes to BUILD.gn files. [1] - https://clang.llvm.org/extra/clang-tidy/checks/abseil-string-find-startswith.html Bug: None Change-Id: Ibf75601065a53bde28623b8eef57bec067235640 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/172586 Reviewed-by: Karl Wiberg Commit-Queue: Mirko Bonadei Cr-Commit-Position: refs/heads/master@{#30984} --- api/video_codecs/BUILD.gn | 1 + ...video_encoder_software_fallback_wrapper.cc | 3 ++- call/rtp_transport_controller_send.cc | 3 ++- modules/pacing/BUILD.gn | 1 + modules/pacing/paced_sender.cc | 19 +++++++++---------- modules/pacing/pacing_controller.cc | 5 +++-- modules/pacing/round_robin_packet_queue.cc | 3 ++- modules/remote_bitrate_estimator/BUILD.gn | 1 + .../aimd_rate_control.cc | 5 +++-- modules/rtp_rtcp/source/rtp_sender_video.cc | 17 ++++++++--------- rtc_base/experiments/BUILD.gn | 1 + rtc_base/experiments/rate_control_settings.cc | 3 ++- rtc_base/network_unittest.cc | 5 +++-- test/BUILD.gn | 1 + test/frame_generator_capturer.cc | 3 ++- test/scenario/BUILD.gn | 1 + test/scenario/video_stream.cc | 3 ++- video/BUILD.gn | 1 + video/send_statistics_proxy.cc | 11 +++++++---- 19 files changed, 52 insertions(+), 35 deletions(-) diff --git a/api/video_codecs/BUILD.gn b/api/video_codecs/BUILD.gn index cb5ede02f6..21a5f6faa0 100644 --- a/api/video_codecs/BUILD.gn +++ b/api/video_codecs/BUILD.gn @@ -149,6 +149,7 @@ rtc_library("rtc_software_fallback_wrappers") { "../video:video_frame", "../video:video_rtp_headers", "//third_party/abseil-cpp/absl/base:core_headers", + "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", ] } diff --git a/api/video_codecs/video_encoder_software_fallback_wrapper.cc b/api/video_codecs/video_encoder_software_fallback_wrapper.cc index 3b2ad4f18f..354e8c25ac 100644 --- a/api/video_codecs/video_encoder_software_fallback_wrapper.cc +++ b/api/video_codecs/video_encoder_software_fallback_wrapper.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/strings/match.h" #include "absl/types/optional.h" #include "api/fec_controller_override.h" #include "api/video/i420_buffer.h" @@ -71,7 +72,7 @@ absl::optional ParseFallbackParamsFromFieldTrials( const VideoEncoder& main_encoder) { const std::string field_trial = webrtc::field_trial::FindFullName(kVp8ForceFallbackEncoderFieldTrial); - if (field_trial.find("Enabled") != 0) { + if (!absl::StartsWith(field_trial, "Enabled")) { return absl::nullopt; } diff --git a/call/rtp_transport_controller_send.cc b/call/rtp_transport_controller_send.cc index 3147a2886f..56c5e55ca1 100644 --- a/call/rtp_transport_controller_send.cc +++ b/call/rtp_transport_controller_send.cc @@ -13,6 +13,7 @@ #include #include +#include "absl/strings/match.h" #include "absl/types/optional.h" #include "api/transport/goog_cc_factory.h" #include "api/transport/network_types.h" @@ -60,7 +61,7 @@ TargetRateConstraints ConvertConstraints(const BitrateConstraints& contraints, bool IsEnabled(const WebRtcKeyValueConfig* trials, absl::string_view key) { RTC_DCHECK(trials != nullptr); - return trials->Lookup(key).find("Enabled") == 0; + return absl::StartsWith(trials->Lookup(key), "Enabled"); } bool IsRelayed(const rtc::NetworkRoute& route) { diff --git a/modules/pacing/BUILD.gn b/modules/pacing/BUILD.gn index d59d2b93a4..6f65c33942 100644 --- a/modules/pacing/BUILD.gn +++ b/modules/pacing/BUILD.gn @@ -58,6 +58,7 @@ rtc_library("pacing") { "../rtp_rtcp:rtp_rtcp_format", "../utility", "//third_party/abseil-cpp/absl/memory", + "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", ] } diff --git a/modules/pacing/paced_sender.cc b/modules/pacing/paced_sender.cc index 3646952728..cd298f9b0b 100644 --- a/modules/pacing/paced_sender.cc +++ b/modules/pacing/paced_sender.cc @@ -15,6 +15,7 @@ #include #include "absl/memory/memory.h" +#include "absl/strings/match.h" #include "api/rtc_event_log/rtc_event_log.h" #include "modules/utility/include/process_thread.h" #include "rtc_base/checks.h" @@ -27,21 +28,19 @@ namespace webrtc { const int64_t PacedSender::kMaxQueueLengthMs = 2000; const float PacedSender::kDefaultPaceMultiplier = 2.5f; -PacedSender::PacedSender(Clock* clock, - PacketRouter* packet_router, +PacedSender::PacedSender(Clock* clock, PacketRouter* packet_router, RtcEventLog* event_log, const WebRtcKeyValueConfig* field_trials, ProcessThread* process_thread) - : process_mode_((field_trials != nullptr && - field_trials->Lookup("WebRTC-Pacer-DynamicProcess") - .find("Enabled") == 0) - ? PacingController::ProcessMode::kDynamic - : PacingController::ProcessMode::kPeriodic), + : process_mode_( + (field_trials != nullptr && + absl::StartsWith(field_trials->Lookup("WebRTC-Pacer-DynamicProcess"), + "Enabled")) + ? PacingController::ProcessMode::kDynamic + : PacingController::ProcessMode::kPeriodic), pacing_controller_(clock, static_cast(this), - event_log, - field_trials, - process_mode_), + event_log, field_trials, process_mode_), clock_(clock), packet_router_(packet_router), process_thread_(process_thread) { diff --git a/modules/pacing/pacing_controller.cc b/modules/pacing/pacing_controller.cc index 7b84877c04..f9ca408eee 100644 --- a/modules/pacing/pacing_controller.cc +++ b/modules/pacing/pacing_controller.cc @@ -15,6 +15,7 @@ #include #include +#include "absl/strings/match.h" #include "modules/pacing/bitrate_prober.h" #include "modules/pacing/interval_budget.h" #include "modules/utility/include/process_thread.h" @@ -42,12 +43,12 @@ constexpr int kFirstPriority = 0; bool IsDisabled(const WebRtcKeyValueConfig& field_trials, absl::string_view key) { - return field_trials.Lookup(key).find("Disabled") == 0; + return absl::StartsWith(field_trials.Lookup(key), "Disabled"); } bool IsEnabled(const WebRtcKeyValueConfig& field_trials, absl::string_view key) { - return field_trials.Lookup(key).find("Enabled") == 0; + return absl::StartsWith(field_trials.Lookup(key), "Enabled"); } int GetPriorityForType(RtpPacketMediaType type) { diff --git a/modules/pacing/round_robin_packet_queue.cc b/modules/pacing/round_robin_packet_queue.cc index d61d441934..6e4efb0799 100644 --- a/modules/pacing/round_robin_packet_queue.cc +++ b/modules/pacing/round_robin_packet_queue.cc @@ -14,6 +14,7 @@ #include #include +#include "absl/strings/match.h" #include "rtc_base/checks.h" namespace webrtc { @@ -105,7 +106,7 @@ bool IsEnabled(const WebRtcKeyValueConfig* field_trials, const char* name) { if (!field_trials) { return false; } - return field_trials->Lookup(name).find("Enabled") == 0; + return absl::StartsWith(field_trials->Lookup(name), "Enabled"); } RoundRobinPacketQueue::RoundRobinPacketQueue( diff --git a/modules/remote_bitrate_estimator/BUILD.gn b/modules/remote_bitrate_estimator/BUILD.gn index 08233da02d..d7b0397ea5 100644 --- a/modules/remote_bitrate_estimator/BUILD.gn +++ b/modules/remote_bitrate_estimator/BUILD.gn @@ -59,6 +59,7 @@ rtc_library("remote_bitrate_estimator") { "../../system_wrappers", "../../system_wrappers:field_trial", "../../system_wrappers:metrics", + "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", ] } diff --git a/modules/remote_bitrate_estimator/aimd_rate_control.cc b/modules/remote_bitrate_estimator/aimd_rate_control.cc index 95e0a33741..da13176645 100644 --- a/modules/remote_bitrate_estimator/aimd_rate_control.cc +++ b/modules/remote_bitrate_estimator/aimd_rate_control.cc @@ -18,6 +18,7 @@ #include #include +#include "absl/strings/match.h" #include "api/transport/network_types.h" #include "api/units/data_rate.h" #include "modules/remote_bitrate_estimator/include/bwe_defines.h" @@ -37,12 +38,12 @@ constexpr char kBweBackOffFactorExperiment[] = "WebRTC-BweBackOffFactor"; bool IsEnabled(const WebRtcKeyValueConfig& field_trials, absl::string_view key) { - return field_trials.Lookup(key).find("Enabled") == 0; + return absl::StartsWith(field_trials.Lookup(key), "Enabled"); } bool IsNotDisabled(const WebRtcKeyValueConfig& field_trials, absl::string_view key) { - return field_trials.Lookup(key).find("Disabled") != 0; + return !absl::StartsWith(field_trials.Lookup(key), "Disabled"); } double ReadBackoffFactor(const WebRtcKeyValueConfig& key_value_config) { diff --git a/modules/rtp_rtcp/source/rtp_sender_video.cc b/modules/rtp_rtcp/source/rtp_sender_video.cc index 3c07eb5d97..26512c440b 100644 --- a/modules/rtp_rtcp/source/rtp_sender_video.cc +++ b/modules/rtp_rtcp/source/rtp_sender_video.cc @@ -148,20 +148,19 @@ RTPSenderVideo::RTPSenderVideo(const Config& config) packetization_overhead_bitrate_(1000, RateStatistics::kBpsScale), frame_encryptor_(config.frame_encryptor), require_frame_encryption_(config.require_frame_encryption), - generic_descriptor_auth_experiment_( - config.field_trials->Lookup("WebRTC-GenericDescriptorAuth") - .find("Disabled") != 0), - exclude_transport_sequence_number_from_fec_experiment_( - config.field_trials - ->Lookup(kExcludeTransportSequenceNumberFromFecFieldTrial) - .find("Enabled") == 0), + generic_descriptor_auth_experiment_(!absl::StartsWith( + config.field_trials->Lookup("WebRTC-GenericDescriptorAuth"), + "Disabled")), + exclude_transport_sequence_number_from_fec_experiment_(absl::StartsWith( + config.field_trials->Lookup( + kExcludeTransportSequenceNumberFromFecFieldTrial), + "Enabled")), absolute_capture_time_sender_(config.clock), frame_transformer_delegate_( config.frame_transformer ? new rtc::RefCountedObject< RTPSenderVideoFrameTransformerDelegate>( - this, - std::move(config.frame_transformer)) + this, std::move(config.frame_transformer)) : nullptr) { if (frame_transformer_delegate_) frame_transformer_delegate_->Init(); diff --git a/rtc_base/experiments/BUILD.gn b/rtc_base/experiments/BUILD.gn index 058e9b7f20..f557526945 100644 --- a/rtc_base/experiments/BUILD.gn +++ b/rtc_base/experiments/BUILD.gn @@ -164,6 +164,7 @@ rtc_library("rate_control_settings") { "../../api/units:data_size", "../../api/video_codecs:video_codecs_api", "../../system_wrappers:field_trial", + "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", ] } diff --git a/rtc_base/experiments/rate_control_settings.cc b/rtc_base/experiments/rate_control_settings.cc index ce77c9e631..ff5bb650ba 100644 --- a/rtc_base/experiments/rate_control_settings.cc +++ b/rtc_base/experiments/rate_control_settings.cc @@ -15,6 +15,7 @@ #include +#include "absl/strings/match.h" #include "api/transport/field_trial_based_config.h" #include "rtc_base/logging.h" #include "rtc_base/numerics/safe_conversions.h" @@ -42,7 +43,7 @@ const char* kScreenshareHysteresisFieldTrialname = bool IsEnabled(const WebRtcKeyValueConfig* const key_value_config, absl::string_view key) { - return key_value_config->Lookup(key).find("Enabled") == 0; + return absl::StartsWith(key_value_config->Lookup(key), "Enabled"); } void ParseHysteresisFactor(const WebRtcKeyValueConfig* const key_value_config, diff --git a/rtc_base/network_unittest.cc b/rtc_base/network_unittest.cc index 41358646fe..d5aa8ac317 100644 --- a/rtc_base/network_unittest.cc +++ b/rtc_base/network_unittest.cc @@ -15,6 +15,7 @@ #include #include +#include "absl/strings/match.h" #include "rtc_base/checks.h" #include "rtc_base/net_helpers.h" #include "rtc_base/network_monitor.h" @@ -47,10 +48,10 @@ class FakeNetworkMonitor : public NetworkMonitorBase { AdapterType GetAdapterType(const std::string& if_name) override { // Note that the name matching rules are different from the // GetAdapterTypeFromName in NetworkManager. - if (if_name.find("wifi") == 0) { + if (absl::StartsWith(if_name, "wifi")) { return ADAPTER_TYPE_WIFI; } - if (if_name.find("cellular") == 0) { + if (absl::StartsWith(if_name, "cellular")) { return ADAPTER_TYPE_CELLULAR; } return ADAPTER_TYPE_UNKNOWN; diff --git a/test/BUILD.gn b/test/BUILD.gn index 29d5d6d883..2e22476c80 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -128,6 +128,7 @@ rtc_library("video_test_common") { "../rtc_base:timeutils", "../rtc_base/task_utils:repeating_task", "../system_wrappers", + "//third_party/abseil-cpp/absl/strings", ] } diff --git a/test/frame_generator_capturer.cc b/test/frame_generator_capturer.cc index 3a298cc528..9806c83d83 100644 --- a/test/frame_generator_capturer.cc +++ b/test/frame_generator_capturer.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/strings/match.h" #include "api/test/create_frame_generator.h" #include "rtc_base/checks.h" #include "rtc_base/critical_section.h" @@ -34,7 +35,7 @@ std::string TransformFilePath(std::string path) { int ext_pos = path.rfind("."); if (ext_pos < 0) { return test::ResourcePath(path, "yuv"); - } else if (path.find(resource_prefix) == 0) { + } else if (absl::StartsWith(path, resource_prefix)) { std::string name = path.substr(resource_prefix.length(), ext_pos); std::string ext = path.substr(ext_pos, path.size()); return test::ResourcePath(name, ext); diff --git a/test/scenario/BUILD.gn b/test/scenario/BUILD.gn index ed66936f3e..e2e5f8cef2 100644 --- a/test/scenario/BUILD.gn +++ b/test/scenario/BUILD.gn @@ -144,6 +144,7 @@ if (rtc_include_tests) { "//third_party/abseil-cpp/absl/flags:flag", "//third_party/abseil-cpp/absl/flags:parse", "//third_party/abseil-cpp/absl/memory", + "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", ] if (is_android) { diff --git a/test/scenario/video_stream.cc b/test/scenario/video_stream.cc index d842b1cc31..4bea740074 100644 --- a/test/scenario/video_stream.cc +++ b/test/scenario/video_stream.cc @@ -13,6 +13,7 @@ #include #include +#include "absl/strings/match.h" #include "api/test/create_frame_generator.h" #include "api/test/frame_generator_interface.h" #include "api/test/video/function_video_encoder_factory.h" @@ -112,7 +113,7 @@ std::string TransformFilePath(std::string path) { int ext_pos = path.rfind("."); if (ext_pos < 0) { return test::ResourcePath(path, "yuv"); - } else if (path.find(resource_prefix) == 0) { + } else if (absl::StartsWith(path, resource_prefix)) { std::string name = path.substr(resource_prefix.length(), ext_pos); std::string ext = path.substr(ext_pos, path.size()); return test::ResourcePath(name, ext); diff --git a/video/BUILD.gn b/video/BUILD.gn index a12cc036fc..14109c3494 100644 --- a/video/BUILD.gn +++ b/video/BUILD.gn @@ -124,6 +124,7 @@ rtc_library("video") { "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/base:core_headers", "//third_party/abseil-cpp/absl/memory", + "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", ] diff --git a/video/send_statistics_proxy.cc b/video/send_statistics_proxy.cc index 1464605c45..e75b955b20 100644 --- a/video/send_statistics_proxy.cc +++ b/video/send_statistics_proxy.cc @@ -16,6 +16,7 @@ #include #include +#include "absl/strings/match.h" #include "api/video/video_codec_constants.h" #include "api/video/video_codec_type.h" #include "api/video_codecs/video_codec.h" @@ -112,15 +113,17 @@ absl::optional GetFallbackMaxPixels(const std::string& group) { absl::optional GetFallbackMaxPixelsIfFieldTrialEnabled() { std::string group = webrtc::field_trial::FindFullName(kVp8ForcedFallbackEncoderFieldTrial); - return (group.find("Enabled") == 0) ? GetFallbackMaxPixels(group.substr(7)) - : absl::optional(); + return (absl::StartsWith(group, "Enabled")) + ? GetFallbackMaxPixels(group.substr(7)) + : absl::optional(); } absl::optional GetFallbackMaxPixelsIfFieldTrialDisabled() { std::string group = webrtc::field_trial::FindFullName(kVp8ForcedFallbackEncoderFieldTrial); - return (group.find("Disabled") == 0) ? GetFallbackMaxPixels(group.substr(8)) - : absl::optional(); + return (absl::StartsWith(group, "Disabled")) + ? GetFallbackMaxPixels(group.substr(8)) + : absl::optional(); } } // namespace