From 64b626b03f578c936da1e48ccc172ee3b6487fba Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Mon, 28 Jan 2019 17:25:26 -0800 Subject: [PATCH] Use Abseil container algorithms in pc/ Bug: None Change-Id: If784461b54d95bdc6f8a7d4e5d1bbfa52d1a390e Reviewed-on: https://webrtc-review.googlesource.com/c/119862 Commit-Queue: Steve Anton Reviewed-by: Amit Hilbuch Cr-Commit-Position: refs/heads/master@{#26433} --- pc/BUILD.gn | 4 ++ pc/channel.cc | 11 ++- pc/channel_manager.cc | 26 +++---- pc/jsep_transport_controller.cc | 9 +-- pc/media_session.cc | 66 ++++++++--------- pc/media_session.h | 1 - pc/media_session_unittest.cc | 70 +++++++----------- pc/media_stream_observer.cc | 47 ++++++------ pc/peer_connection.cc | 4 +- pc/peer_connection_integrationtest.cc | 57 +++++++-------- pc/peer_connection_media_unittest.cc | 5 +- pc/remote_audio_source.cc | 7 +- pc/rtc_stats_integrationtest.cc | 14 ++-- pc/rtp_parameters_conversion_unittest.cc | 22 +++--- pc/rtp_transceiver.cc | 12 ++-- pc/sdp_serializer.cc | 5 +- pc/session_description.cc | 8 +-- pc/stats_collector_unittest.cc | 4 +- pc/test/fake_audio_capture_module_unittest.cc | 5 +- pc/webrtc_sdp.cc | 71 +++++++++---------- pc/webrtc_sdp_unittest.cc | 16 ++--- pc/webrtc_session_description_factory.cc | 25 +++---- 22 files changed, 214 insertions(+), 275 deletions(-) diff --git a/pc/BUILD.gn b/pc/BUILD.gn index 8dab052145..87d7bd37fa 100644 --- a/pc/BUILD.gn +++ b/pc/BUILD.gn @@ -95,6 +95,7 @@ rtc_static_library("rtc_pc_base") { "../rtc_base/third_party/base64", "../rtc_base/third_party/sigslot", "../system_wrappers:metrics", + "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", @@ -219,6 +220,7 @@ rtc_static_library("peerconnection") { "../system_wrappers", "../system_wrappers:field_trial", "../system_wrappers:metrics", + "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", @@ -294,6 +296,7 @@ if (rtc_include_tests) { "../rtc_base/third_party/sigslot", "../system_wrappers:metrics", "../test:test_support", + "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/memory", ] @@ -523,6 +526,7 @@ if (rtc_include_tests) { "../rtc_base/third_party/sigslot:sigslot", "../system_wrappers:metrics", "../test:fileutils", + "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings", ] diff --git a/pc/channel.cc b/pc/channel.cc index 049e9506ce..e5b6bb0b96 100644 --- a/pc/channel.cc +++ b/pc/channel.cc @@ -8,12 +8,12 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include #include #include #include "pc/channel.h" +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "api/call/audio_sink.h" #include "media/base/media_constants.h" @@ -746,11 +746,10 @@ RtpHeaderExtensions BaseChannel::GetFilteredRtpHeaderExtensions( RTC_DCHECK(rtp_transport_); if (crypto_options_.srtp.enable_encrypted_rtp_header_extensions) { RtpHeaderExtensions filtered; - auto pred = [](const webrtc::RtpExtension& extension) { - return !extension.encrypt; - }; - std::copy_if(extensions.begin(), extensions.end(), - std::back_inserter(filtered), pred); + absl::c_copy_if(extensions, std::back_inserter(filtered), + [](const webrtc::RtpExtension& extension) { + return !extension.encrypt; + }); return filtered; } diff --git a/pc/channel_manager.cc b/pc/channel_manager.cc index f5798a253d..49da430297 100644 --- a/pc/channel_manager.cc +++ b/pc/channel_manager.cc @@ -10,9 +10,9 @@ #include "pc/channel_manager.h" -#include #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "media/base/media_constants.h" @@ -211,10 +211,10 @@ void ChannelManager::DestroyVoiceChannel(VoiceChannel* voice_channel) { RTC_DCHECK(initialized_); - auto it = std::find_if(voice_channels_.begin(), voice_channels_.end(), - [&](const std::unique_ptr& p) { - return p.get() == voice_channel; - }); + auto it = absl::c_find_if(voice_channels_, + [&](const std::unique_ptr& p) { + return p.get() == voice_channel; + }); RTC_DCHECK(it != voice_channels_.end()); if (it == voice_channels_.end()) { return; @@ -280,10 +280,10 @@ void ChannelManager::DestroyVideoChannel(VideoChannel* video_channel) { RTC_DCHECK(initialized_); - auto it = std::find_if(video_channels_.begin(), video_channels_.end(), - [&](const std::unique_ptr& p) { - return p.get() == video_channel; - }); + auto it = absl::c_find_if(video_channels_, + [&](const std::unique_ptr& p) { + return p.get() == video_channel; + }); RTC_DCHECK(it != video_channels_.end()); if (it == video_channels_.end()) { return; @@ -340,10 +340,10 @@ void ChannelManager::DestroyRtpDataChannel(RtpDataChannel* data_channel) { RTC_DCHECK(initialized_); - auto it = std::find_if(data_channels_.begin(), data_channels_.end(), - [&](const std::unique_ptr& p) { - return p.get() == data_channel; - }); + auto it = absl::c_find_if(data_channels_, + [&](const std::unique_ptr& p) { + return p.get() == data_channel; + }); RTC_DCHECK(it != data_channels_.end()); if (it == data_channels_.end()) { return; diff --git a/pc/jsep_transport_controller.cc b/pc/jsep_transport_controller.cc index fa0aa7d7f1..7020c6cbb7 100644 --- a/pc/jsep_transport_controller.cc +++ b/pc/jsep_transport_controller.cc @@ -10,10 +10,10 @@ #include "pc/jsep_transport_controller.h" -#include #include #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "p2p/base/ice_transport_internal.h" #include "p2p/base/no_op_dtls_transport.h" @@ -885,9 +885,7 @@ std::vector JsepTransportController::GetEncryptedHeaderExtensionIds( if (!extension.encrypt) { continue; } - auto it = std::find(encrypted_header_extension_ids.begin(), - encrypted_header_extension_ids.end(), extension.id); - if (it == encrypted_header_extension_ids.end()) { + if (!absl::c_linear_search(encrypted_header_extension_ids, extension.id)) { encrypted_header_extension_ids.push_back(extension.id); } } @@ -907,8 +905,7 @@ JsepTransportController::MergeEncryptedHeaderExtensionIdsForBundle( std::vector extension_ids = GetEncryptedHeaderExtensionIds(content_info); for (int id : extension_ids) { - auto it = std::find(merged_ids.begin(), merged_ids.end(), id); - if (it == merged_ids.end()) { + if (!absl::c_linear_search(merged_ids, id)) { merged_ids.push_back(id); } } diff --git a/pc/media_session.cc b/pc/media_session.cc index e840b33fc1..e18c86a249 100644 --- a/pc/media_session.cc +++ b/pc/media_session.cc @@ -10,7 +10,6 @@ #include "pc/media_session.h" -#include // For std::find_if, std::sort. #include #include #include @@ -18,6 +17,7 @@ #include #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "absl/types/optional.h" @@ -185,9 +185,8 @@ const CryptoParamsVec* GetCryptos(const ContentInfo* content) { bool FindMatchingCrypto(const CryptoParamsVec& cryptos, const CryptoParams& crypto, CryptoParams* crypto_out) { - auto it = std::find_if( - cryptos.begin(), cryptos.end(), - [&crypto](const CryptoParams& c) { return crypto.Matches(c); }); + auto it = absl::c_find_if( + cryptos, [&crypto](const CryptoParams& c) { return crypto.Matches(c); }); if (it == cryptos.end()) { return false; } @@ -417,14 +416,12 @@ static StreamParams CreateStreamParamsForNewSenderWithSsrcs( static bool ValidateSimulcastLayers( const std::vector& rids, const SimulcastLayerList& simulcast_layers) { - std::vector all_layers = simulcast_layers.GetAllLayers(); - return std::all_of(all_layers.begin(), all_layers.end(), - [&rids](const SimulcastLayer& layer) { - return std::find_if(rids.begin(), rids.end(), - [&layer](const RidDescription& rid) { - return rid.rid == layer.rid; - }) != rids.end(); - }); + return absl::c_all_of( + simulcast_layers.GetAllLayers(), [&rids](const SimulcastLayer& layer) { + return absl::c_any_of(rids, [&layer](const RidDescription& rid) { + return rid.rid == layer.rid; + }); + }); } static StreamParams CreateStreamParamsForNewSenderWithRids( @@ -455,9 +452,9 @@ static void AddSimulcastToMediaDescription( RTC_DCHECK(description); // Check if we are using RIDs in this scenario. - if (std::all_of( - description->streams().begin(), description->streams().end(), - [](const StreamParams& params) { return !params.has_rids(); })) { + if (absl::c_all_of(description->streams(), [](const StreamParams& params) { + return !params.has_rids(); + })) { return; } @@ -833,11 +830,10 @@ static void NegotiateCodecs(const std::vector& local_codecs, for (const C& codec : offered_codecs) { payload_type_preferences[codec.id] = preference--; } - std::sort(negotiated_codecs->begin(), negotiated_codecs->end(), - [&payload_type_preferences](const C& a, const C& b) { - return payload_type_preferences[a.id] > - payload_type_preferences[b.id]; - }); + absl::c_sort( + *negotiated_codecs, [&payload_type_preferences](const C& a, const C& b) { + return payload_type_preferences[a.id] > payload_type_preferences[b.id]; + }); } // Finds a codec in |codecs2| that matches |codec_to_match|, which is @@ -850,10 +846,9 @@ static bool FindMatchingCodec(const std::vector& codecs1, C* found_codec) { // |codec_to_match| should be a member of |codecs1|, in order to look up RTX // codecs' associated codecs correctly. If not, that's a programming error. - RTC_DCHECK(std::find_if(codecs1.begin(), codecs1.end(), - [&codec_to_match](const C& codec) { - return &codec == &codec_to_match; - }) != codecs1.end()); + RTC_DCHECK(absl::c_any_of(codecs1, [&codec_to_match](const C& codec) { + return &codec == &codec_to_match; + })); for (const C& potential_match : codecs2) { if (potential_match.Matches(codec_to_match)) { if (IsRtxCodec(codec_to_match)) { @@ -960,14 +955,13 @@ static void MergeCodecs(const std::vector& reference_codecs, static bool FindByUriAndEncryption(const RtpHeaderExtensions& extensions, const webrtc::RtpExtension& ext_to_match, webrtc::RtpExtension* found_extension) { - auto it = - std::find_if(extensions.begin(), extensions.end(), - [&ext_to_match](const webrtc::RtpExtension& extension) { - // We assume that all URIs are given in a canonical - // format. - return extension.uri == ext_to_match.uri && - extension.encrypt == ext_to_match.encrypt; - }); + auto it = absl::c_find_if( + extensions, [&ext_to_match](const webrtc::RtpExtension& extension) { + // We assume that all URIs are given in a canonical + // format. + return extension.uri == ext_to_match.uri && + extension.encrypt == ext_to_match.encrypt; + }); if (it == extensions.end()) { return false; } @@ -1303,11 +1297,9 @@ void MediaDescriptionOptions::AddSenderInternal( } bool MediaSessionOptions::HasMediaDescription(MediaType type) const { - return std::find_if(media_description_options.begin(), - media_description_options.end(), - [type](const MediaDescriptionOptions& t) { - return t.type == type; - }) != media_description_options.end(); + return absl::c_any_of( + media_description_options, + [type](const MediaDescriptionOptions& t) { return t.type == type; }); } MediaSessionDescriptionFactory::MediaSessionDescriptionFactory( diff --git a/pc/media_session.h b/pc/media_session.h index 54fa7daec9..a459c4c07c 100644 --- a/pc/media_session.h +++ b/pc/media_session.h @@ -13,7 +13,6 @@ #ifndef PC_MEDIA_SESSION_H_ #define PC_MEDIA_SESSION_H_ -#include #include #include #include diff --git a/pc/media_session_unittest.cc b/pc/media_session_unittest.cc index d1a151f9c2..534e4fc839 100644 --- a/pc/media_session_unittest.cc +++ b/pc/media_session_unittest.cc @@ -13,6 +13,7 @@ #include #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "media/base/codec.h" #include "media/base/test_utils.h" @@ -81,6 +82,7 @@ using rtc::CS_AEAD_AES_256_GCM; using rtc::CS_AES_CM_128_HMAC_SHA1_32; using rtc::CS_AES_CM_128_HMAC_SHA1_80; using rtc::UniqueRandomIdGenerator; +using testing::Contains; using testing::Each; using testing::ElementsAreArray; using testing::Eq; @@ -88,6 +90,7 @@ using testing::Field; using testing::IsEmpty; using testing::IsFalse; using testing::Ne; +using testing::Not; using testing::Pointwise; using testing::SizeIs; using webrtc::RtpExtension; @@ -275,18 +278,16 @@ static std::vector GetCodecNames(const std::vector& codecs) { std::vector::iterator FindFirstMediaDescriptionByMid( const std::string& mid, MediaSessionOptions* opts) { - return std::find_if( - opts->media_description_options.begin(), - opts->media_description_options.end(), + return absl::c_find_if( + opts->media_description_options, [&mid](const MediaDescriptionOptions& t) { return t.mid == mid; }); } std::vector::const_iterator FindFirstMediaDescriptionByMid(const std::string& mid, const MediaSessionOptions& opts) { - return std::find_if( - opts.media_description_options.begin(), - opts.media_description_options.end(), + return absl::c_find_if( + opts.media_description_options, [&mid](const MediaDescriptionOptions& t) { return t.mid == mid; }); } @@ -360,10 +361,10 @@ static void DetachSenderFromMediaSection(const std::string& mid, std::vector& sender_options_list = FindFirstMediaDescriptionByMid(mid, session_options)->sender_options; auto sender_it = - std::find_if(sender_options_list.begin(), sender_options_list.end(), - [track_id](const cricket::SenderOptions& sender_options) { - return sender_options.track_id == track_id; - }); + absl::c_find_if(sender_options_list, + [track_id](const cricket::SenderOptions& sender_options) { + return sender_options.track_id == track_id; + }); RTC_DCHECK(sender_it != sender_options_list.end()); sender_options_list.erase(sender_it); } @@ -442,11 +443,8 @@ class MediaSessionDescriptionFactoryTest : public testing::Test { // Returns true if the transport info contains "renomination" as an // ICE option. bool GetIceRenomination(const TransportInfo* transport_info) { - const std::vector& ice_options = - transport_info->description.transport_options; - auto iter = - std::find(ice_options.begin(), ice_options.end(), "renomination"); - return iter != ice_options.end(); + return absl::c_linear_search(transport_info->description.transport_options, + "renomination"); } void TestTransportInfo(bool offer, @@ -2741,10 +2739,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, RtxWithoutApt) { std::unique_ptr answer = f2_.CreateAnswer(offer.get(), opts, NULL); - std::vector codec_names = - GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()); - EXPECT_EQ(codec_names.end(), std::find(codec_names.begin(), codec_names.end(), - cricket::kRtxCodecName)); + EXPECT_THAT( + GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()), + Not(Contains(cricket::kRtxCodecName))); } // Test that RTX will be filtered out in the answer if its associated payload @@ -2771,10 +2768,9 @@ TEST_F(MediaSessionDescriptionFactoryTest, FilterOutRtxIfAptDoesntMatch) { std::unique_ptr answer = f2_.CreateAnswer(offer.get(), opts, NULL); - std::vector codec_names = - GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()); - EXPECT_EQ(codec_names.end(), std::find(codec_names.begin(), codec_names.end(), - cricket::kRtxCodecName)); + EXPECT_THAT( + GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()), + Not(Contains(cricket::kRtxCodecName))); } // Test that when multiple RTX codecs are offered, only the matched RTX codec @@ -4121,16 +4117,10 @@ TEST_F(MediaSessionDescriptionFactoryTest, VideoHasRidExtensionsInUnifiedPlan) { cricket::RtpHeaderExtensions result = sf.video_rtp_header_extensions(); // Check to see that RID extensions were added to the extension list EXPECT_GE(result.size(), 2u); - auto rid_extension = std::find_if( - result.begin(), result.end(), [](const RtpExtension& extension) { - return extension.uri == webrtc::RtpExtension::kRidUri; - }); - EXPECT_NE(rid_extension, extensions.end()); - auto repaired_rid_extension = std::find_if( - result.begin(), result.end(), [](const RtpExtension& extension) { - return extension.uri == webrtc::RtpExtension::kRepairedRidUri; - }); - EXPECT_NE(repaired_rid_extension, extensions.end()); + EXPECT_THAT(result, Contains(Field("uri", &RtpExtension::uri, + RtpExtension::kRidUri))); + EXPECT_THAT(result, Contains(Field("uri", &RtpExtension::uri, + RtpExtension::kRepairedRidUri))); } // Checks that the RID extensions are added to the audio RTP header extensions. @@ -4147,16 +4137,10 @@ TEST_F(MediaSessionDescriptionFactoryTest, AudioHasRidExtensionsInUnifiedPlan) { cricket::RtpHeaderExtensions result = sf.audio_rtp_header_extensions(); // Check to see that RID extensions were added to the extension list EXPECT_GE(result.size(), 2u); - auto rid_extension = std::find_if( - result.begin(), result.end(), [](const RtpExtension& extension) { - return extension.uri == webrtc::RtpExtension::kRidUri; - }); - EXPECT_NE(rid_extension, extensions.end()); - auto repaired_rid_extension = std::find_if( - result.begin(), result.end(), [](const RtpExtension& extension) { - return extension.uri == webrtc::RtpExtension::kRepairedRidUri; - }); - EXPECT_NE(repaired_rid_extension, extensions.end()); + EXPECT_THAT(result, Contains(Field("uri", &RtpExtension::uri, + RtpExtension::kRidUri))); + EXPECT_THAT(result, Contains(Field("uri", &RtpExtension::uri, + RtpExtension::kRepairedRidUri))); } namespace { diff --git a/pc/media_stream_observer.cc b/pc/media_stream_observer.cc index e3ef3c75a5..e66634ad25 100644 --- a/pc/media_stream_observer.cc +++ b/pc/media_stream_observer.cc @@ -10,10 +10,11 @@ #include "pc/media_stream_observer.h" -#include #include #include +#include "absl/algorithm/container.h" + namespace webrtc { MediaStreamObserver::MediaStreamObserver(MediaStreamInterface* stream) @@ -33,48 +34,44 @@ void MediaStreamObserver::OnChanged() { // Find removed audio tracks. for (const auto& cached_track : cached_audio_tracks_) { - auto it = std::find_if( - new_audio_tracks.begin(), new_audio_tracks.end(), - [cached_track](const AudioTrackVector::value_type& new_track) { - return new_track->id().compare(cached_track->id()) == 0; - }); - if (it == new_audio_tracks.end()) { + if (absl::c_none_of( + new_audio_tracks, + [cached_track](const AudioTrackVector::value_type& new_track) { + return new_track->id() == cached_track->id(); + })) { SignalAudioTrackRemoved(cached_track.get(), stream_); } } // Find added audio tracks. for (const auto& new_track : new_audio_tracks) { - auto it = std::find_if( - cached_audio_tracks_.begin(), cached_audio_tracks_.end(), - [new_track](const AudioTrackVector::value_type& cached_track) { - return new_track->id().compare(cached_track->id()) == 0; - }); - if (it == cached_audio_tracks_.end()) { + if (absl::c_none_of( + cached_audio_tracks_, + [new_track](const AudioTrackVector::value_type& cached_track) { + return new_track->id() == cached_track->id(); + })) { SignalAudioTrackAdded(new_track.get(), stream_); } } // Find removed video tracks. for (const auto& cached_track : cached_video_tracks_) { - auto it = std::find_if( - new_video_tracks.begin(), new_video_tracks.end(), - [cached_track](const VideoTrackVector::value_type& new_track) { - return new_track->id().compare(cached_track->id()) == 0; - }); - if (it == new_video_tracks.end()) { + if (absl::c_none_of( + new_video_tracks, + [cached_track](const VideoTrackVector::value_type& new_track) { + return new_track->id() == cached_track->id(); + })) { SignalVideoTrackRemoved(cached_track.get(), stream_); } } // Find added video tracks. for (const auto& new_track : new_video_tracks) { - auto it = std::find_if( - cached_video_tracks_.begin(), cached_video_tracks_.end(), - [new_track](const VideoTrackVector::value_type& cached_track) { - return new_track->id().compare(cached_track->id()) == 0; - }); - if (it == cached_video_tracks_.end()) { + if (absl::c_none_of( + cached_video_tracks_, + [new_track](const VideoTrackVector::value_type& cached_track) { + return new_track->id() == cached_track->id(); + })) { SignalVideoTrackAdded(new_track.get(), stream_); } } diff --git a/pc/peer_connection.cc b/pc/peer_connection.cc index 393526d11b..22cd60a4de 100644 --- a/pc/peer_connection.cc +++ b/pc/peer_connection.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "api/jsep_ice_candidate.h" @@ -4828,8 +4829,7 @@ void PeerConnection::UpdateClosingRtpDataChannels( auto it = rtp_data_channels_.begin(); while (it != rtp_data_channels_.end()) { DataChannel* data_channel = it->second; - if (std::find(active_channels.begin(), active_channels.end(), - data_channel->label()) != active_channels.end()) { + if (absl::c_linear_search(active_channels, data_channel->label())) { ++it; continue; } diff --git a/pc/peer_connection_integrationtest.cc b/pc/peer_connection_integrationtest.cc index c28f0de187..54af495a34 100644 --- a/pc/peer_connection_integrationtest.cc +++ b/pc/peer_connection_integrationtest.cc @@ -14,7 +14,6 @@ #include -#include #include #include #include @@ -22,6 +21,7 @@ #include #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "api/audio_codecs/builtin_audio_decoder_factory.h" #include "api/audio_codecs/builtin_audio_encoder_factory.h" @@ -78,9 +78,10 @@ using ::cricket::StreamParams; using ::rtc::SocketAddress; using ::testing::_; using ::testing::Combine; +using ::testing::Contains; using ::testing::ElementsAre; -using ::testing::Return; using ::testing::NiceMock; +using ::testing::Return; using ::testing::SetArgPointee; using ::testing::UnorderedElementsAreArray; using ::testing::Values; @@ -1639,18 +1640,16 @@ TEST_P(PeerConnectionIntegrationTest, EXPECT_EQ(2U, callee()->rtp_receiver_observers().size()); // Wait for all "first packet received" callbacks to be fired. EXPECT_TRUE_WAIT( - std::all_of(caller()->rtp_receiver_observers().begin(), - caller()->rtp_receiver_observers().end(), - [](const std::unique_ptr& o) { - return o->first_packet_received(); - }), + absl::c_all_of(caller()->rtp_receiver_observers(), + [](const std::unique_ptr& o) { + return o->first_packet_received(); + }), kMaxWaitForFramesMs); EXPECT_TRUE_WAIT( - std::all_of(callee()->rtp_receiver_observers().begin(), - callee()->rtp_receiver_observers().end(), - [](const std::unique_ptr& o) { - return o->first_packet_received(); - }), + absl::c_all_of(callee()->rtp_receiver_observers(), + [](const std::unique_ptr& o) { + return o->first_packet_received(); + }), kMaxWaitForFramesMs); // If new observers are set after the first packet was already received, the // callback should still be invoked. @@ -1659,17 +1658,15 @@ TEST_P(PeerConnectionIntegrationTest, EXPECT_EQ(2U, caller()->rtp_receiver_observers().size()); EXPECT_EQ(2U, callee()->rtp_receiver_observers().size()); EXPECT_TRUE( - std::all_of(caller()->rtp_receiver_observers().begin(), - caller()->rtp_receiver_observers().end(), - [](const std::unique_ptr& o) { - return o->first_packet_received(); - })); + absl::c_all_of(caller()->rtp_receiver_observers(), + [](const std::unique_ptr& o) { + return o->first_packet_received(); + })); EXPECT_TRUE( - std::all_of(callee()->rtp_receiver_observers().begin(), - callee()->rtp_receiver_observers().end(), - [](const std::unique_ptr& o) { - return o->first_packet_received(); - })); + absl::c_all_of(callee()->rtp_receiver_observers(), + [](const std::unique_ptr& o) { + return o->first_packet_received(); + })); } class DummyDtmfObserver : public DtmfSenderObserverInterface { @@ -3364,9 +3361,9 @@ TEST_P(PeerConnectionIntegrationTest, StressTestUnorderedSctpDataChannel) { caller()->data_observer()->messages(); std::vector callee_received_messages = callee()->data_observer()->messages(); - std::sort(sent_messages.begin(), sent_messages.end()); - std::sort(caller_received_messages.begin(), caller_received_messages.end()); - std::sort(callee_received_messages.begin(), callee_received_messages.end()); + absl::c_sort(sent_messages); + absl::c_sort(caller_received_messages); + absl::c_sort(callee_received_messages); EXPECT_EQ(sent_messages, caller_received_messages); EXPECT_EQ(sent_messages, callee_received_messages); } @@ -4049,17 +4046,11 @@ TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithIceRenomination) { const cricket::SessionDescription* desc = caller()->pc()->local_description()->description(); for (const cricket::TransportInfo& info : desc->transport_infos()) { - ASSERT_NE( - info.description.transport_options.end(), - std::find(info.description.transport_options.begin(), - info.description.transport_options.end(), "renomination")); + ASSERT_THAT(info.description.transport_options, Contains("renomination")); } desc = callee()->pc()->local_description()->description(); for (const cricket::TransportInfo& info : desc->transport_infos()) { - ASSERT_NE( - info.description.transport_options.end(), - std::find(info.description.transport_options.begin(), - info.description.transport_options.end(), "renomination")); + ASSERT_THAT(info.description.transport_options, Contains("renomination")); } MediaExpectations media_expectations; media_expectations.ExpectBidirectionalAudioAndVideo(); diff --git a/pc/peer_connection_media_unittest.cc b/pc/peer_connection_media_unittest.cc index 3115eb6c24..ca036568ff 100644 --- a/pc/peer_connection_media_unittest.cc +++ b/pc/peer_connection_media_unittest.cc @@ -14,6 +14,7 @@ #include +#include "absl/algorithm/container.h" #include "api/call/call_factory_interface.h" #include "api/test/fake_media_transport.h" #include "logging/rtc_event_log/rtc_event_log_factory.h" @@ -812,8 +813,8 @@ void RenameVideoContent(cricket::SessionDescription* desc) { } void ReverseMediaContent(cricket::SessionDescription* desc) { - std::reverse(desc->contents().begin(), desc->contents().end()); - std::reverse(desc->transport_infos().begin(), desc->transport_infos().end()); + absl::c_reverse(desc->contents()); + absl::c_reverse(desc->transport_infos()); } void ChangeMediaTypeAudioToVideo(cricket::SessionDescription* desc) { diff --git a/pc/remote_audio_source.cc b/pc/remote_audio_source.cc index c789d4565e..9f599bb8b5 100644 --- a/pc/remote_audio_source.cc +++ b/pc/remote_audio_source.cc @@ -11,9 +11,9 @@ #include "pc/remote_audio_source.h" #include -#include #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "api/scoped_refptr.h" #include "rtc_base/checks.h" @@ -101,8 +101,7 @@ void RemoteAudioSource::SetVolume(double volume) { void RemoteAudioSource::RegisterAudioObserver(AudioObserver* observer) { RTC_DCHECK(observer != NULL); - RTC_DCHECK(std::find(audio_observers_.begin(), audio_observers_.end(), - observer) == audio_observers_.end()); + RTC_DCHECK(!absl::c_linear_search(audio_observers_, observer)); audio_observers_.push_back(observer); } @@ -121,7 +120,7 @@ void RemoteAudioSource::AddSink(AudioTrackSinkInterface* sink) { } rtc::CritScope lock(&sink_lock_); - RTC_DCHECK(std::find(sinks_.begin(), sinks_.end(), sink) == sinks_.end()); + RTC_DCHECK(absl::c_linear_search(sinks_, sink)); sinks_.push_back(sink); } diff --git a/pc/rtc_stats_integrationtest.cc b/pc/rtc_stats_integrationtest.cc index 14fd36617a..afe7649562 100644 --- a/pc/rtc_stats_integrationtest.cc +++ b/pc/rtc_stats_integrationtest.cc @@ -16,6 +16,7 @@ #include #include +#include "absl/algorithm/container.h" #include "absl/strings/match.h" #include "api/audio_codecs/audio_decoder_factory.h" #include "api/audio_codecs/audio_encoder_factory.h" @@ -41,8 +42,11 @@ #include "rtc_base/thread.h" #include "rtc_base/trace_event.h" #include "rtc_base/virtual_socket_server.h" +#include "test/gmock.h" #include "test/gtest.h" +using ::testing::Contains; + namespace webrtc { namespace { @@ -402,8 +406,7 @@ class RTCStatsReportVerifier { } } for (const char* missing : missing_stats) { - if (std::find(allowed_missing_stats.begin(), allowed_missing_stats.end(), - missing) == allowed_missing_stats.end()) { + if (!absl::c_linear_search(allowed_missing_stats, missing)) { verify_successful = false; EXPECT_TRUE(false) << "Missing expected stats type: " << missing; } @@ -897,13 +900,10 @@ TEST_F(RTCStatsIntegrationTest, GetStatsReferencedIds) { std::vector neighbor_ids = GetStatsReferencedIds(stats); EXPECT_EQ(neighbor_ids.size(), expected_ids.size()); for (const std::string* neighbor_id : neighbor_ids) { - EXPECT_TRUE(expected_ids.find(neighbor_id) != expected_ids.end()) - << "Unexpected neighbor ID: " << *neighbor_id; + EXPECT_THAT(expected_ids, Contains(neighbor_id)); } for (const std::string* expected_id : expected_ids) { - EXPECT_TRUE(std::find(neighbor_ids.begin(), neighbor_ids.end(), - expected_id) != neighbor_ids.end()) - << "Missing expected neighbor ID: " << *expected_id; + EXPECT_THAT(neighbor_ids, Contains(expected_id)); } } } diff --git a/pc/rtp_parameters_conversion_unittest.cc b/pc/rtp_parameters_conversion_unittest.cc index 27708cc883..9874ed328b 100644 --- a/pc/rtp_parameters_conversion_unittest.cc +++ b/pc/rtp_parameters_conversion_unittest.cc @@ -12,6 +12,9 @@ #include "pc/rtp_parameters_conversion.h" #include "rtc_base/gunit.h" +#include "test/gmock.h" + +using ::testing::UnorderedElementsAre; namespace webrtc { @@ -601,24 +604,15 @@ TEST(RtpParametersConversionTest, ToRtpCapabilities) { capabilities = ToRtpCapabilities( {vp8, red, ulpfec, rtx}, cricket::RtpHeaderExtensions()); EXPECT_EQ(4u, capabilities.codecs.size()); - EXPECT_EQ(2u, capabilities.fec.size()); - EXPECT_NE(capabilities.fec.end(), - std::find(capabilities.fec.begin(), capabilities.fec.end(), - FecMechanism::RED)); - EXPECT_NE(capabilities.fec.end(), - std::find(capabilities.fec.begin(), capabilities.fec.end(), - FecMechanism::RED_AND_ULPFEC)); + EXPECT_THAT( + capabilities.fec, + UnorderedElementsAre(FecMechanism::RED, FecMechanism::RED_AND_ULPFEC)); capabilities = ToRtpCapabilities( {vp8, red, flexfec}, cricket::RtpHeaderExtensions()); EXPECT_EQ(3u, capabilities.codecs.size()); - EXPECT_EQ(2u, capabilities.fec.size()); - EXPECT_NE(capabilities.fec.end(), - std::find(capabilities.fec.begin(), capabilities.fec.end(), - FecMechanism::RED)); - EXPECT_NE(capabilities.fec.end(), - std::find(capabilities.fec.begin(), capabilities.fec.end(), - FecMechanism::FLEXFEC)); + EXPECT_THAT(capabilities.fec, + UnorderedElementsAre(FecMechanism::RED, FecMechanism::FLEXFEC)); } TEST(RtpParametersConversionTest, ToRtpParameters) { diff --git a/pc/rtp_transceiver.cc b/pc/rtp_transceiver.cc index 8c7b575a4b..a000b5809d 100644 --- a/pc/rtp_transceiver.cc +++ b/pc/rtp_transceiver.cc @@ -10,9 +10,9 @@ #include "pc/rtp_transceiver.h" -#include #include +#include "absl/algorithm/container.h" #include "pc/rtp_media_utils.h" #include "rtc_base/checks.h" #include "rtc_base/logging.h" @@ -83,8 +83,7 @@ void RtpTransceiver::AddSender( RTC_DCHECK(!unified_plan_); RTC_DCHECK(sender); RTC_DCHECK_EQ(media_type(), sender->media_type()); - RTC_DCHECK(std::find(senders_.begin(), senders_.end(), sender) == - senders_.end()); + RTC_DCHECK(!absl::c_linear_search(senders_, sender)); senders_.push_back(sender); } @@ -93,7 +92,7 @@ bool RtpTransceiver::RemoveSender(RtpSenderInterface* sender) { if (sender) { RTC_DCHECK_EQ(media_type(), sender->media_type()); } - auto it = std::find(senders_.begin(), senders_.end(), sender); + auto it = absl::c_find(senders_, sender); if (it == senders_.end()) { return false; } @@ -109,8 +108,7 @@ void RtpTransceiver::AddReceiver( RTC_DCHECK(!unified_plan_); RTC_DCHECK(receiver); RTC_DCHECK_EQ(media_type(), receiver->media_type()); - RTC_DCHECK(std::find(receivers_.begin(), receivers_.end(), receiver) == - receivers_.end()); + RTC_DCHECK(!absl::c_linear_search(receivers_, receiver)); receivers_.push_back(receiver); } @@ -119,7 +117,7 @@ bool RtpTransceiver::RemoveReceiver(RtpReceiverInterface* receiver) { if (receiver) { RTC_DCHECK_EQ(media_type(), receiver->media_type()); } - auto it = std::find(receivers_.begin(), receivers_.end(), receiver); + auto it = absl::c_find(receivers_, receiver); if (it == receivers_.end()) { return false; } diff --git a/pc/sdp_serializer.cc b/pc/sdp_serializer.cc index 8b0d69685b..482dd07cdc 100644 --- a/pc/sdp_serializer.cc +++ b/pc/sdp_serializer.cc @@ -10,11 +10,11 @@ #include "pc/sdp_serializer.h" -#include #include #include #include +#include "absl/algorithm/container.h" #include "api/jsep.h" #include "rtc_base/checks.h" #include "rtc_base/string_encode.h" @@ -166,8 +166,7 @@ webrtc::RTCError ParseRidPayloadList(const std::string& payload_list, } // Check if the value already appears in the payload list. - if (std::find(payload_types.begin(), payload_types.end(), value.value()) != - payload_types.end()) { + if (absl::c_linear_search(payload_types, value.value())) { return ParseError("Duplicate payload type in list: " + payload_type); } payload_types.push_back(value.value()); diff --git a/pc/session_description.cc b/pc/session_description.cc index 1029ee8d0b..a081f8a3ed 100644 --- a/pc/session_description.cc +++ b/pc/session_description.cc @@ -10,9 +10,9 @@ #include "pc/session_description.h" -#include #include +#include "absl/algorithm/container.h" #include "rtc_base/checks.h" namespace cricket { @@ -66,8 +66,7 @@ const std::string* ContentGroup::FirstContentName() const { } bool ContentGroup::HasContentName(const std::string& content_name) const { - return (std::find(content_names_.begin(), content_names_.end(), - content_name) != content_names_.end()); + return absl::c_linear_search(content_names_, content_name); } void ContentGroup::AddContentName(const std::string& content_name) { @@ -77,8 +76,7 @@ void ContentGroup::AddContentName(const std::string& content_name) { } bool ContentGroup::RemoveContentName(const std::string& content_name) { - ContentNames::iterator iter = - std::find(content_names_.begin(), content_names_.end(), content_name); + ContentNames::iterator iter = absl::c_find(content_names_, content_name); if (iter == content_names_.end()) { return false; } diff --git a/pc/stats_collector_unittest.cc b/pc/stats_collector_unittest.cc index dc5a47a8d9..3fe6a9e287 100644 --- a/pc/stats_collector_unittest.cc +++ b/pc/stats_collector_unittest.cc @@ -9,9 +9,9 @@ */ #include -#include #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "absl/types/optional.h" #include "api/audio_codecs/audio_encoder.h" @@ -235,7 +235,7 @@ std::string DerToPem(const std::string& der) { std::vector DersToPems(const std::vector& ders) { std::vector pems(ders.size()); - std::transform(ders.begin(), ders.end(), pems.begin(), DerToPem); + absl::c_transform(ders, pems.begin(), DerToPem); return pems; } diff --git a/pc/test/fake_audio_capture_module_unittest.cc b/pc/test/fake_audio_capture_module_unittest.cc index 250953f3ad..0130af1f1d 100644 --- a/pc/test/fake_audio_capture_module_unittest.cc +++ b/pc/test/fake_audio_capture_module_unittest.cc @@ -18,8 +18,6 @@ #include "rtc_base/gunit.h" #include "test/gtest.h" -using std::min; - class FakeAdmTest : public testing::Test, public webrtc::AudioTransport { protected: static const int kMsInSecond = 1000; @@ -110,7 +108,8 @@ class FakeAdmTest : public testing::Test, public webrtc::AudioTransport { } size_t CopyFromRecBuffer(void* audio_buffer, size_t audio_buffer_size) { EXPECT_EQ(audio_buffer_size, rec_buffer_bytes_); - const size_t min_buffer_size = min(audio_buffer_size, rec_buffer_bytes_); + const size_t min_buffer_size = + std::min(audio_buffer_size, rec_buffer_bytes_); memcpy(audio_buffer, rec_buffer_, min_buffer_size); return min_buffer_size; } diff --git a/pc/webrtc_sdp.cc b/pc/webrtc_sdp.cc index 97f2455d7a..736122b7f2 100644 --- a/pc/webrtc_sdp.cc +++ b/pc/webrtc_sdp.cc @@ -23,6 +23,7 @@ #include #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "api/candidate.h" @@ -611,8 +612,8 @@ static bool GetValue(const std::string& message, } static bool CaseInsensitiveFind(std::string str1, std::string str2) { - std::transform(str1.begin(), str1.end(), str1.begin(), ::tolower); - std::transform(str2.begin(), str2.end(), str2.begin(), ::tolower); + absl::c_transform(str1, str1.begin(), ::tolower); + absl::c_transform(str2, str2.begin(), ::tolower); return str1.find(str2) != std::string::npos; } @@ -699,8 +700,8 @@ void CreateTracksFromSsrcInfos(const SsrcInfoVec& ssrc_infos, track_id = rtc::CreateRandomString(8); } - auto track_it = std::find_if( - tracks->begin(), tracks->end(), + auto track_it = absl::c_find_if( + *tracks, [track_id](const StreamParams& track) { return track.id == track_id; }); if (track_it == tracks->end()) { // If we don't find an existing track, create a new one. @@ -1803,9 +1804,8 @@ bool GetMinValue(const std::vector& values, int* value) { if (values.empty()) { return false; } - std::vector::const_iterator found = - std::min_element(values.begin(), values.end()); - *value = *found; + auto it = absl::c_min_element(values); + *value = *it; return true; } @@ -2252,8 +2252,7 @@ static bool ParseFingerprintAttribute( // Downcase the algorithm. Note that we don't need to downcase the // fingerprint because hex_decode can handle upper-case. - std::transform(algorithm.begin(), algorithm.end(), algorithm.begin(), - ::tolower); + absl::c_transform(algorithm, algorithm.begin(), ::tolower); // The second field is the digest value. De-hexify it. *fingerprint = @@ -2360,8 +2359,7 @@ static void RemoveInvalidRidDescriptions(const std::vector& payload_types, // Media section does not handle duplicates either. std::set removed_formats; for (int payload_type : rid.payload_types) { - if (std::find(payload_types.begin(), payload_types.end(), payload_type) == - payload_types.end()) { + if (!absl::c_linear_search(payload_types, payload_type)) { removed_formats.insert(payload_type); } } @@ -2430,30 +2428,29 @@ static void RemoveInvalidRidsFromSimulcast( // This algorithm runs in O(n^2) time, but for small n (as is the case with // simulcast layers) it should still perform well. for (const SimulcastLayer& send_layer : all_send_layers) { - if (std::find_if(all_receive_layers.begin(), all_receive_layers.end(), - [&send_layer](const SimulcastLayer& layer) { - return layer.rid == send_layer.rid; - }) != all_receive_layers.end()) { + if (absl::c_any_of(all_receive_layers, + [&send_layer](const SimulcastLayer& layer) { + return layer.rid == send_layer.rid; + })) { to_remove.insert(send_layer.rid); } } // Add any rid that is not in the valid list to the remove set. for (const SimulcastLayer& send_layer : all_send_layers) { - if (std::find_if(valid_rids.begin(), valid_rids.end(), - [&send_layer](const RidDescription& rid) { - return send_layer.rid == rid.rid; - }) == valid_rids.end()) { + if (absl::c_none_of(valid_rids, [&send_layer](const RidDescription& rid) { + return send_layer.rid == rid.rid; + })) { to_remove.insert(send_layer.rid); } } // Add any rid that is not in the valid list to the remove set. for (const SimulcastLayer& receive_layer : all_receive_layers) { - if (std::find_if(valid_rids.begin(), valid_rids.end(), - [&receive_layer](const RidDescription& rid) { - return receive_layer.rid == rid.rid; - }) == valid_rids.end()) { + if (absl::c_none_of(valid_rids, + [&receive_layer](const RidDescription& rid) { + return receive_layer.rid == rid.rid; + })) { to_remove.insert(receive_layer.rid); } } @@ -2550,12 +2547,11 @@ static std::unique_ptr ParseContentDescription( payload_type_preferences[pt] = preference--; } std::vector codecs = media_desc->codecs(); - std::sort(codecs.begin(), codecs.end(), - [&payload_type_preferences](const typename C::CodecType& a, - const typename C::CodecType& b) { - return payload_type_preferences[a.id] > - payload_type_preferences[b.id]; - }); + absl::c_sort( + codecs, [&payload_type_preferences](const typename C::CodecType& a, + const typename C::CodecType& b) { + return payload_type_preferences[a.id] > payload_type_preferences[b.id]; + }); media_desc->set_codecs(codecs); return media_desc; } @@ -2739,13 +2735,11 @@ bool VerifyCodec(const cricket::Codec& codec) { } bool VerifyAudioCodecs(const AudioContentDescription* audio_desc) { - const std::vector& codecs = audio_desc->codecs(); - return std::all_of(codecs.begin(), codecs.end(), &VerifyCodec); + return absl::c_all_of(audio_desc->codecs(), &VerifyCodec); } bool VerifyVideoCodecs(const VideoContentDescription* video_desc) { - const std::vector& codecs = video_desc->codecs(); - return std::all_of(codecs.begin(), codecs.end(), &VerifyCodec); + return absl::c_all_of(video_desc->codecs(), &VerifyCodec); } void AddParameters(const cricket::CodecParameterMap& parameters, @@ -3301,10 +3295,10 @@ bool ParseSsrcAttribute(const std::string& line, // Check if there's already an item for this |ssrc_id|. Create a new one if // there isn't. - auto ssrc_info_it = std::find_if(ssrc_infos->begin(), ssrc_infos->end(), - [ssrc_id](const SsrcInfo& ssrc_info) { - return ssrc_info.ssrc_id == ssrc_id; - }); + auto ssrc_info_it = + absl::c_find_if(*ssrc_infos, [ssrc_id](const SsrcInfo& ssrc_info) { + return ssrc_info.ssrc_id == ssrc_id; + }); if (ssrc_info_it == ssrc_infos->end()) { SsrcInfo info; info.ssrc_id = ssrc_id; @@ -3459,8 +3453,7 @@ bool ParseRtpmapAttribute(const std::string& line, return false; } - if (std::find(payload_types.begin(), payload_types.end(), payload_type) == - payload_types.end()) { + if (!absl::c_linear_search(payload_types, payload_type)) { RTC_LOG(LS_WARNING) << "Ignore rtpmap line that did not appear in the " " of the m-line: " << line; diff --git a/pc/webrtc_sdp_unittest.cc b/pc/webrtc_sdp_unittest.cc index 654246e243..b1ecf7eb79 100644 --- a/pc/webrtc_sdp_unittest.cc +++ b/pc/webrtc_sdp_unittest.cc @@ -17,6 +17,7 @@ #include #include +#include "absl/algorithm/container.h" #include "api/array_view.h" #include "api/crypto_params.h" #include "api/jsep_session_description.h" @@ -1431,10 +1432,9 @@ class WebRtcSdpTest : public testing::Test { // Order of elements does not matter, only equivalence of sets. EXPECT_EQ(rids.size(), ids.size()); for (const std::string& id : ids) { - EXPECT_EQ(1l, std::count_if(rids.begin(), rids.end(), - [id](const RidDescription& rid) { - return rid.rid == id; - })); + EXPECT_EQ(1l, absl::c_count_if(rids, [id](const RidDescription& rid) { + return rid.rid == id; + })); } } @@ -4105,10 +4105,10 @@ TEST_F(WebRtcSdpTest, TestDeserializeSimulcastAttributeRemovesUnknownRids) { std::vector all_send_layers = simulcast.send_layers().GetAllLayers(); EXPECT_EQ(2ul, all_send_layers.size()); - EXPECT_EQ(0, std::count_if(all_send_layers.begin(), all_send_layers.end(), - [](const SimulcastLayer& layer) { - return layer.rid == "2"; - })); + EXPECT_EQ(0, + absl::c_count_if(all_send_layers, [](const SimulcastLayer& layer) { + return layer.rid == "2"; + })); std::vector all_receive_layers = simulcast.receive_layers().GetAllLayers(); diff --git a/pc/webrtc_session_description_factory.cc b/pc/webrtc_session_description_factory.cc index d859559f48..ad7a0c19fd 100644 --- a/pc/webrtc_session_description_factory.cc +++ b/pc/webrtc_session_description_factory.cc @@ -11,11 +11,11 @@ #include "pc/webrtc_session_description_factory.h" #include -#include #include #include #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "absl/types/optional.h" #include "api/jsep.h" @@ -42,16 +42,6 @@ static const char kFailedDueToSessionShutdown[] = static const uint64_t kInitSessionVersion = 2; -static bool CompareSenderOptions(const cricket::SenderOptions& sender1, - const cricket::SenderOptions& sender2) { - return sender1.track_id < sender2.track_id; -} - -static bool SameId(const cricket::SenderOptions& sender1, - const cricket::SenderOptions& sender2) { - return sender1.track_id == sender2.track_id; -} - // Check that each sender has a unique ID. static bool ValidMediaSessionOptions( const cricket::MediaSessionOptions& session_options) { @@ -62,10 +52,15 @@ static bool ValidMediaSessionOptions( media_description_options.sender_options.begin(), media_description_options.sender_options.end()); } - std::sort(sorted_senders.begin(), sorted_senders.end(), CompareSenderOptions); - std::vector::iterator it = - std::adjacent_find(sorted_senders.begin(), sorted_senders.end(), SameId); - return it == sorted_senders.end(); + absl::c_sort(sorted_senders, [](const cricket::SenderOptions& sender1, + const cricket::SenderOptions& sender2) { + return sender1.track_id < sender2.track_id; + }); + return absl::c_adjacent_find(sorted_senders, + [](const cricket::SenderOptions& sender1, + const cricket::SenderOptions& sender2) { + return sender1.track_id == sender2.track_id; + }) == sorted_senders.end(); } enum {