From 2c9ebefb44c48d0d01d392aadcf04b4003b09fbe Mon Sep 17 00:00:00 2001 From: Steve Anton Date: Mon, 28 Jan 2019 17:27:58 -0800 Subject: [PATCH] Use Abseil container algorithms in media/ Bug: None Change-Id: I292e3401bbf19a66271dd5ef2b3ca4f8dcfd155d Reviewed-on: https://webrtc-review.googlesource.com/c/120003 Commit-Queue: Steve Anton Reviewed-by: Seth Hampson Cr-Commit-Position: refs/heads/master@{#26434} --- api/BUILD.gn | 1 + media/BUILD.gn | 5 ++ media/base/codec.cc | 5 +- media/base/fake_media_engine.cc | 7 +- media/base/fake_media_engine.h | 7 +- media/base/fake_rtp.cc | 6 +- media/base/stream_params.cc | 8 +- media/base/stream_params.h | 10 +-- media/base/video_source_base.cc | 7 +- media/engine/fake_webrtc_call.cc | 28 +++---- media/engine/webrtc_media_engine.cc | 10 +-- media/engine/webrtc_video_engine.cc | 12 +-- media/engine/webrtc_video_engine_unittest.cc | 81 +++++++------------- media/engine/webrtc_voice_engine.cc | 22 +++--- media/sctp/sctp_transport.cc | 6 +- media/sctp/sctp_transport_unittest.cc | 11 +-- 16 files changed, 93 insertions(+), 133 deletions(-) diff --git a/api/BUILD.gn b/api/BUILD.gn index 2359ebc99f..6a24abacf5 100644 --- a/api/BUILD.gn +++ b/api/BUILD.gn @@ -136,6 +136,7 @@ rtc_static_library("libjingle_peerconnection_api") { "units:data_rate", "video:encoded_image", "video:video_frame", + "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", diff --git a/media/BUILD.gn b/media/BUILD.gn index 8c05cc58fc..e703abb164 100644 --- a/media/BUILD.gn +++ b/media/BUILD.gn @@ -143,6 +143,7 @@ rtc_static_library("rtc_media_base") { "../rtc_base:rtc_base_approved", "../rtc_base/system:rtc_export", "../rtc_base/third_party/sigslot", + "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/types:optional", ] @@ -369,6 +370,7 @@ rtc_static_library("rtc_audio_video") { "../rtc_base/experiments:field_trial_parser", "../rtc_base/experiments:normalize_simulcast_size_experiment", "../system_wrappers", + "//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", @@ -416,6 +418,7 @@ rtc_static_library("rtc_data") { "../rtc_base:rtc_base_approved", "../rtc_base/third_party/sigslot", "../system_wrappers", + "//third_party/abseil-cpp/absl/algorithm:container", ] } @@ -453,6 +456,7 @@ if (rtc_include_tests) { "../rtc_base:gunit_helpers", "../rtc_base:rtc_task_queue", "../rtc_base:stringutils", + "//third_party/abseil-cpp/absl/algorithm:container", "//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/strings", ] @@ -652,6 +656,7 @@ if (rtc_include_tests) { "../test:audio_codec_mocks", "../test:test_support", "../test:video_test_common", + "//third_party/abseil-cpp/absl/algorithm:container", ] } } diff --git a/media/base/codec.cc b/media/base/codec.cc index 805a79ea20..16ef65dff5 100644 --- a/media/base/codec.cc +++ b/media/base/codec.cc @@ -10,8 +10,7 @@ #include "media/base/codec.h" -#include - +#include "absl/algorithm/container.h" #include "absl/strings/match.h" #include "media/base/h264_profile_level_id.h" #include "media/base/vp9_profile.h" @@ -35,7 +34,7 @@ bool FeedbackParams::operator==(const FeedbackParams& other) const { } bool FeedbackParams::Has(const FeedbackParam& param) const { - return std::find(params_.begin(), params_.end(), param) != params_.end(); + return absl::c_linear_search(params_, param); } void FeedbackParams::Add(const FeedbackParam& param) { diff --git a/media/base/fake_media_engine.cc b/media/base/fake_media_engine.cc index ab8ce9926b..70fabc53cd 100644 --- a/media/base/fake_media_engine.cc +++ b/media/base/fake_media_engine.cc @@ -12,6 +12,7 @@ #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "rtc_base/checks.h" @@ -482,7 +483,7 @@ FakeVoiceMediaChannel* FakeVoiceEngine::GetChannel(size_t index) { return (channels_.size() > index) ? channels_[index] : NULL; } void FakeVoiceEngine::UnregisterChannel(VoiceMediaChannel* channel) { - channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); + channels_.erase(absl::c_find(channels_, channel)); } const std::vector& FakeVoiceEngine::send_codecs() const { return codecs_; @@ -537,7 +538,7 @@ FakeVideoMediaChannel* FakeVideoEngine::GetChannel(size_t index) { return (channels_.size() > index) ? channels_[index] : nullptr; } void FakeVideoEngine::UnregisterChannel(VideoMediaChannel* channel) { - auto it = std::find(channels_.begin(), channels_.end(), channel); + auto it = absl::c_find(channels_, channel); RTC_DCHECK(it != channels_.end()); channels_.erase(it); } @@ -586,7 +587,7 @@ FakeDataMediaChannel* FakeDataEngine::GetChannel(size_t index) { return (channels_.size() > index) ? channels_[index] : NULL; } void FakeDataEngine::UnregisterChannel(DataMediaChannel* channel) { - channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); + channels_.erase(absl::c_find(channels_, channel)); } void FakeDataEngine::SetDataCodecs(const std::vector& data_codecs) { data_codecs_ = data_codecs; diff --git a/media/base/fake_media_engine.h b/media/base/fake_media_engine.h index ff8f44d78a..564b0dae78 100644 --- a/media/base/fake_media_engine.h +++ b/media/base/fake_media_engine.h @@ -19,6 +19,7 @@ #include #include +#include "absl/algorithm/container.h" #include "api/call/audio_sink.h" #include "media/base/audio_source.h" #include "media/base/media_engine.h" @@ -101,8 +102,7 @@ class RtpHelper : public Base { void set_fail_set_send_codecs(bool fail) { fail_set_send_codecs_ = fail; } void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; } virtual bool AddSendStream(const StreamParams& sp) { - if (std::find(send_streams_.begin(), send_streams_.end(), sp) != - send_streams_.end()) { + if (absl::c_linear_search(send_streams_, sp)) { return false; } send_streams_.push_back(sp); @@ -118,8 +118,7 @@ class RtpHelper : public Base { return RemoveStreamBySsrc(&send_streams_, ssrc); } virtual bool AddRecvStream(const StreamParams& sp) { - if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) != - receive_streams_.end()) { + if (absl::c_linear_search(receive_streams_, sp)) { return false; } receive_streams_.push_back(sp); diff --git a/media/base/fake_rtp.cc b/media/base/fake_rtp.cc index 751766e8fe..175de6f140 100644 --- a/media/base/fake_rtp.cc +++ b/media/base/fake_rtp.cc @@ -10,8 +10,8 @@ #include #include -#include +#include "absl/algorithm/container.h" #include "media/base/fake_rtp.h" #include "rtc_base/checks.h" #include "test/gtest.h" @@ -53,9 +53,7 @@ void CompareHeaderExtensions(const char* packet1, // The header extension doesn't get encrypted if the id is not in the // list of header extensions to encrypt. - if (expect_equal || - std::find(encrypted_headers.begin(), encrypted_headers.end(), id) == - encrypted_headers.end()) { + if (expect_equal || !absl::c_linear_search(encrypted_headers, id)) { EXPECT_EQ(0, memcmp(extension_data1, extension_data2, len)); } else { EXPECT_NE(0, memcmp(extension_data1, extension_data2, len)); diff --git a/media/base/stream_params.cc b/media/base/stream_params.cc index 329aa30574..0545f75893 100644 --- a/media/base/stream_params.cc +++ b/media/base/stream_params.cc @@ -11,9 +11,9 @@ #include "media/base/stream_params.h" #include -#include #include +#include "absl/algorithm/container.h" #include "api/array_view.h" #include "rtc_base/strings/string_builder.h" @@ -153,8 +153,7 @@ bool StreamParams::operator==(const StreamParams& other) const { ssrc_groups == other.ssrc_groups && cname == other.cname && stream_ids_ == other.stream_ids_ && // RIDs are not required to be in the same order for equality. - rids_.size() == other.rids_.size() && - std::is_permutation(rids_.begin(), rids_.end(), other.rids_.begin())); + absl::c_is_permutation(rids_, other.rids_)); } std::string StreamParams::ToString() const { @@ -328,8 +327,7 @@ bool IsOneSsrcStream(const StreamParams& sp) { namespace { void RemoveFirst(std::list* ssrcs, uint32_t value) { - std::list::iterator it = - std::find(ssrcs->begin(), ssrcs->end(), value); + auto it = absl::c_find(*ssrcs, value); if (it != ssrcs->end()) { ssrcs->erase(it); } diff --git a/media/base/stream_params.h b/media/base/stream_params.h index de567d0b4d..c69f4237c1 100644 --- a/media/base/stream_params.h +++ b/media/base/stream_params.h @@ -47,11 +47,11 @@ #define MEDIA_BASE_STREAM_PARAMS_H_ #include -#include #include #include #include +#include "absl/algorithm/container.h" #include "media/base/rid_description.h" #include "rtc_base/constructor_magic.h" #include "rtc_base/unique_id_generator.h" @@ -114,7 +114,7 @@ struct StreamParams { } bool has_ssrcs() const { return !ssrcs.empty(); } bool has_ssrc(uint32_t ssrc) const { - return std::find(ssrcs.begin(), ssrcs.end(), ssrc) != ssrcs.end(); + return absl::c_linear_search(ssrcs, ssrc); } void add_ssrc(uint32_t ssrc) { ssrcs.push_back(ssrc); } bool has_ssrc_groups() const { return !ssrc_groups.empty(); } @@ -296,15 +296,13 @@ struct MediaStreams { template const StreamParams* GetStream(const StreamParamsVec& streams, Condition condition) { - StreamParamsVec::const_iterator found = - std::find_if(streams.begin(), streams.end(), condition); + auto found = absl::c_find_if(streams, condition); return found == streams.end() ? nullptr : &(*found); } template StreamParams* GetStream(StreamParamsVec& streams, Condition condition) { - StreamParamsVec::iterator found = - std::find_if(streams.begin(), streams.end(), condition); + auto found = absl::c_find_if(streams, condition); return found == streams.end() ? nullptr : &(*found); } diff --git a/media/base/video_source_base.cc b/media/base/video_source_base.cc index 71b4276eaf..d057a24ad8 100644 --- a/media/base/video_source_base.cc +++ b/media/base/video_source_base.cc @@ -10,8 +10,7 @@ #include "media/base/video_source_base.h" -#include - +#include "absl/algorithm/container.h" #include "rtc_base/checks.h" namespace rtc { @@ -44,8 +43,8 @@ void VideoSourceBase::RemoveSink(VideoSinkInterface* sink) { VideoSourceBase::SinkPair* VideoSourceBase::FindSinkPair( const VideoSinkInterface* sink) { - auto sink_pair_it = std::find_if( - sinks_.begin(), sinks_.end(), + auto sink_pair_it = absl::c_find_if( + sinks_, [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; }); if (sink_pair_it != sinks_.end()) { return &*sink_pair_it; diff --git a/media/engine/fake_webrtc_call.cc b/media/engine/fake_webrtc_call.cc index c2230649cc..4dd3b39bb0 100644 --- a/media/engine/fake_webrtc_call.cc +++ b/media/engine/fake_webrtc_call.cc @@ -10,9 +10,9 @@ #include "media/engine/fake_webrtc_call.h" -#include #include +#include "absl/algorithm/container.h" #include "api/call/audio_sink.h" #include "media/base/rtp_utils.h" #include "rtc_base/checks.h" @@ -467,9 +467,8 @@ webrtc::AudioSendStream* FakeCall::CreateAudioSendStream( } void FakeCall::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { - auto it = std::find(audio_send_streams_.begin(), - audio_send_streams_.end(), - static_cast(send_stream)); + auto it = absl::c_find(audio_send_streams_, + static_cast(send_stream)); if (it == audio_send_streams_.end()) { ADD_FAILURE() << "DestroyAudioSendStream called with unknown parameter."; } else { @@ -488,9 +487,8 @@ webrtc::AudioReceiveStream* FakeCall::CreateAudioReceiveStream( void FakeCall::DestroyAudioReceiveStream( webrtc::AudioReceiveStream* receive_stream) { - auto it = std::find(audio_receive_streams_.begin(), - audio_receive_streams_.end(), - static_cast(receive_stream)); + auto it = absl::c_find(audio_receive_streams_, + static_cast(receive_stream)); if (it == audio_receive_streams_.end()) { ADD_FAILURE() << "DestroyAudioReceiveStream called with unknown parameter."; } else { @@ -510,9 +508,8 @@ webrtc::VideoSendStream* FakeCall::CreateVideoSendStream( } void FakeCall::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { - auto it = std::find(video_send_streams_.begin(), - video_send_streams_.end(), - static_cast(send_stream)); + auto it = absl::c_find(video_send_streams_, + static_cast(send_stream)); if (it == video_send_streams_.end()) { ADD_FAILURE() << "DestroyVideoSendStream called with unknown parameter."; } else { @@ -531,9 +528,8 @@ webrtc::VideoReceiveStream* FakeCall::CreateVideoReceiveStream( void FakeCall::DestroyVideoReceiveStream( webrtc::VideoReceiveStream* receive_stream) { - auto it = std::find(video_receive_streams_.begin(), - video_receive_streams_.end(), - static_cast(receive_stream)); + auto it = absl::c_find(video_receive_streams_, + static_cast(receive_stream)); if (it == video_receive_streams_.end()) { ADD_FAILURE() << "DestroyVideoReceiveStream called with unknown parameter."; } else { @@ -552,9 +548,9 @@ webrtc::FlexfecReceiveStream* FakeCall::CreateFlexfecReceiveStream( void FakeCall::DestroyFlexfecReceiveStream( webrtc::FlexfecReceiveStream* receive_stream) { - auto it = std::find(flexfec_receive_streams_.begin(), - flexfec_receive_streams_.end(), - static_cast(receive_stream)); + auto it = + absl::c_find(flexfec_receive_streams_, + static_cast(receive_stream)); if (it == flexfec_receive_streams_.end()) { ADD_FAILURE() << "DestroyFlexfecReceiveStream called with unknown parameter."; diff --git a/media/engine/webrtc_media_engine.cc b/media/engine/webrtc_media_engine.cc index 5ea99b6e41..5de0927a52 100644 --- a/media/engine/webrtc_media_engine.cc +++ b/media/engine/webrtc_media_engine.cc @@ -10,9 +10,9 @@ #include "media/engine/webrtc_media_engine.h" -#include #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "api/video/builtin_video_bitrate_allocator_factory.h" #include "api/video_codecs/video_decoder_factory.h" @@ -82,8 +82,8 @@ void DiscardRedundantExtensions( RTC_DCHECK(extensions); bool found = false; for (const char* uri : extensions_decreasing_prio) { - auto it = std::find_if( - extensions->begin(), extensions->end(), + auto it = absl::c_find_if( + *extensions, [uri](const webrtc::RtpExtension& rhs) { return rhs.uri == uri; }); if (it != extensions->end()) { if (found) { @@ -135,8 +135,8 @@ std::vector FilterRtpExtensions( // Sort by name, ascending (prioritise encryption), so that we don't reset // extensions if they were specified in a different order (also allows us // to use std::unique below). - std::sort( - result.begin(), result.end(), + absl::c_sort( + result, [](const webrtc::RtpExtension& rhs, const webrtc::RtpExtension& lhs) { return rhs.encrypt == lhs.encrypt ? rhs.uri < lhs.uri : rhs.encrypt > lhs.encrypt; diff --git a/media/engine/webrtc_video_engine.cc b/media/engine/webrtc_video_engine.cc index f26e5dd654..756bc561a0 100644 --- a/media/engine/webrtc_video_engine.cc +++ b/media/engine/webrtc_video_engine.cc @@ -560,10 +560,6 @@ WebRtcVideoChannel::SelectSendVideoCodec( bool WebRtcVideoChannel::NonFlexfecReceiveCodecsHaveChanged( std::vector before, std::vector after) { - if (before.size() != after.size()) { - return true; - } - // The receive codec order doesn't matter, so we sort the codecs before // comparing. This is necessary because currently the // only way to change the send codec is to munge SDP, which causes @@ -576,14 +572,14 @@ bool WebRtcVideoChannel::NonFlexfecReceiveCodecsHaveChanged( const VideoCodecSettings& codec2) { return codec1.codec.id > codec2.codec.id; }; - std::sort(before.begin(), before.end(), comparison); - std::sort(after.begin(), after.end(), comparison); + absl::c_sort(before, comparison); + absl::c_sort(after, comparison); // Changes in FlexFEC payload type are handled separately in // WebRtcVideoChannel::GetChangedRecvParameters, so disregard FlexFEC in the // comparison here. - return !std::equal(before.begin(), before.end(), after.begin(), - VideoCodecSettings::EqualsDisregardingFlexfec); + return !absl::c_equal(before, after, + VideoCodecSettings::EqualsDisregardingFlexfec); } bool WebRtcVideoChannel::GetChangedSendParameters( diff --git a/media/engine/webrtc_video_engine_unittest.cc b/media/engine/webrtc_video_engine_unittest.cc index a4bb932381..14b4232236 100644 --- a/media/engine/webrtc_video_engine_unittest.cc +++ b/media/engine/webrtc_video_engine_unittest.cc @@ -8,12 +8,12 @@ * be found in the AUTHORS file in the root of the source tree. */ -#include #include #include #include #include +#include "absl/algorithm/container.h" #include "absl/memory/memory.h" #include "absl/strings/match.h" #include "api/rtp_parameters.h" @@ -681,8 +681,7 @@ WebRtcVideoEngineTest::SetSendParamsWithAllSupportedCodecs() { for (const webrtc::SdpVideoFormat& format : encoder_factory_->GetSupportedFormats()) { cricket::VideoCodec engine_codec = GetEngineCodec(format.name); - if (std::find(parameters.codecs.begin(), parameters.codecs.end(), - engine_codec) == parameters.codecs.end()) { + if (!absl::c_linear_search(parameters.codecs, engine_codec)) { parameters.codecs.push_back(engine_codec); } } @@ -878,23 +877,15 @@ TEST_F(WebRtcVideoEngineTest, Flexfec03SupportedAsInternalCodecBehindFieldTrial) { encoder_factory_->AddSupportedVideoCodecType("VP8"); - auto is_flexfec = [](const VideoCodec& codec) { - if (codec.name == "flexfec-03") - return true; - return false; - }; + auto flexfec = Field("name", &VideoCodec::name, "flexfec-03"); // FlexFEC is not active without field trial. - const std::vector codecs_before = engine_.codecs(); - EXPECT_EQ(codecs_before.end(), std::find_if(codecs_before.begin(), - codecs_before.end(), is_flexfec)); + EXPECT_THAT(engine_.codecs(), Not(Contains(flexfec))); // FlexFEC is active with field trial. webrtc::test::ScopedFieldTrials override_field_trials_( "WebRTC-FlexFEC-03-Advertised/Enabled/"); - const std::vector codecs_after = engine_.codecs(); - EXPECT_NE(codecs_after.end(), - std::find_if(codecs_after.begin(), codecs_after.end(), is_flexfec)); + EXPECT_THAT(engine_.codecs(), Contains(flexfec)); } // Test that codecs are added in the order they are reported from the factory. @@ -2461,8 +2452,7 @@ TEST_F(WebRtcVideoChannelTest, IdenticalSendExtensionsDoesntRecreateStream) { // Setting the same extensions (even if in different order) shouldn't // reallocate the stream. - std::reverse(send_parameters_.extensions.begin(), - send_parameters_.extensions.end()); + absl::c_reverse(send_parameters_.extensions); EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); @@ -2494,8 +2484,7 @@ TEST_F(WebRtcVideoChannelTest, IdenticalRecvExtensionsDoesntRecreateStream) { // Setting the same extensions (even if in different order) shouldn't // reallocate the stream. - std::reverse(recv_parameters_.extensions.begin(), - recv_parameters_.extensions.end()); + absl::c_reverse(recv_parameters_.extensions); EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); @@ -6869,16 +6858,12 @@ TEST_F(WebRtcVideoChannelTestWithClock, GetContributingSources) { std::vector sources = channel_->GetSources(kSsrc); EXPECT_EQ(sources[0].timestamp_ms(), sources[1].timestamp_ms()); // 1 SSRC and 1 CSRC. - EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), - [](const webrtc::RtpSource& source) { - return source.source_type() == - webrtc::RtpSourceType::SSRC; - })); - EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), - [](const webrtc::RtpSource& source) { - return source.source_type() == - webrtc::RtpSourceType::CSRC; - })); + EXPECT_EQ(1, absl::c_count_if(sources, [](const webrtc::RtpSource& source) { + return source.source_type() == webrtc::RtpSourceType::SSRC; + })); + EXPECT_EQ(1, absl::c_count_if(sources, [](const webrtc::RtpSource& source) { + return source.source_type() == webrtc::RtpSourceType::CSRC; + })); } int64_t timestamp1 = channel_->GetSources(kSsrc)[0].timestamp_ms(); @@ -6898,22 +6883,18 @@ TEST_F(WebRtcVideoChannelTestWithClock, GetContributingSources) { std::vector sources = channel_->GetSources(kSsrc); EXPECT_NE(sources[0].timestamp_ms(), sources[1].timestamp_ms()); // 1 SSRC and 1 CSRC. - EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), - [](const webrtc::RtpSource& source) { - return source.source_type() == - webrtc::RtpSourceType::SSRC; - })); - EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), - [](const webrtc::RtpSource& source) { - return source.source_type() == - webrtc::RtpSourceType::CSRC; - })); - auto ssrcSource = std::find_if( - sources.begin(), sources.end(), [](const webrtc::RtpSource& source) { + EXPECT_EQ(1, absl::c_count_if(sources, [](const webrtc::RtpSource& source) { + return source.source_type() == webrtc::RtpSourceType::SSRC; + })); + EXPECT_EQ(1, absl::c_count_if(sources, [](const webrtc::RtpSource& source) { + return source.source_type() == webrtc::RtpSourceType::CSRC; + })); + auto ssrcSource = + absl::c_find_if(sources, [](const webrtc::RtpSource& source) { return source.source_type() == webrtc::RtpSourceType::SSRC; }); - auto csrcSource = std::find_if( - sources.begin(), sources.end(), [](const webrtc::RtpSource& source) { + auto csrcSource = + absl::c_find_if(sources, [](const webrtc::RtpSource& source) { return source.source_type() == webrtc::RtpSourceType::CSRC; }); @@ -6928,16 +6909,12 @@ TEST_F(WebRtcVideoChannelTestWithClock, GetContributingSources) { ASSERT_EQ(1u, channel_->GetSources(kSsrc).size()); EXPECT_EQ(0u, channel_->GetSources(kCsrc).size()); std::vector sources = channel_->GetSources(kSsrc); - EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), - [](const webrtc::RtpSource& source) { - return source.source_type() == - webrtc::RtpSourceType::SSRC; - })); - EXPECT_EQ(0, std::count_if(sources.begin(), sources.end(), - [](const webrtc::RtpSource& source) { - return source.source_type() == - webrtc::RtpSourceType::CSRC; - })); + EXPECT_EQ(1, absl::c_count_if(sources, [](const webrtc::RtpSource& source) { + return source.source_type() == webrtc::RtpSourceType::SSRC; + })); + EXPECT_EQ(0, absl::c_count_if(sources, [](const webrtc::RtpSource& source) { + return source.source_type() == webrtc::RtpSourceType::CSRC; + })); } fake_clock_.AdvanceTime(webrtc::TimeDelta::ms(1)); diff --git a/media/engine/webrtc_voice_engine.cc b/media/engine/webrtc_voice_engine.cc index 8089a0f267..67d89fdc29 100644 --- a/media/engine/webrtc_voice_engine.cc +++ b/media/engine/webrtc_voice_engine.cc @@ -19,6 +19,7 @@ #include #include +#include "absl/algorithm/container.h" #include "absl/strings/match.h" #include "api/audio_codecs/audio_codec_pair_id.h" #include "api/call/audio_sink.h" @@ -125,12 +126,10 @@ bool VerifyUniquePayloadTypes(const std::vector& codecs) { return true; } std::vector payload_types; - for (const AudioCodec& codec : codecs) { - payload_types.push_back(codec.id); - } - std::sort(payload_types.begin(), payload_types.end()); - auto it = std::unique(payload_types.begin(), payload_types.end()); - return it == payload_types.end(); + absl::c_transform(codecs, std::back_inserter(payload_types), + [](const AudioCodec& codec) { return codec.id; }); + absl::c_sort(payload_types); + return absl::c_adjacent_find(payload_types) == payload_types.end(); } absl::optional GetAudioNetworkAdaptorConfig( @@ -579,7 +578,7 @@ void WebRtcVoiceEngine::RegisterChannel(WebRtcVoiceMediaChannel* channel) { void WebRtcVoiceEngine::UnregisterChannel(WebRtcVoiceMediaChannel* channel) { RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); - auto it = std::find(channels_.begin(), channels_.end(), channel); + auto it = absl::c_find(channels_, channel); RTC_DCHECK(it != channels_.end()); channels_.erase(it); } @@ -2029,9 +2028,7 @@ void WebRtcVoiceMediaChannel::OnPacketReceived(rtc::CopyOnWriteBuffer* packet, if (!GetRtpSsrc(packet->cdata(), packet->size(), &ssrc)) { return; } - RTC_DCHECK(std::find(unsignaled_recv_ssrcs_.begin(), - unsignaled_recv_ssrcs_.end(), - ssrc) == unsignaled_recv_ssrcs_.end()); + RTC_DCHECK(!absl::c_linear_search(unsignaled_recv_ssrcs_, ssrc)); // Add new stream. StreamParams sp = unsignaled_stream_params_; @@ -2181,7 +2178,7 @@ bool WebRtcVoiceMediaChannel::GetStats(VoiceMediaInfo* info) { // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=8158 if (!unsignaled_recv_ssrcs_.empty()) { auto end_it = --unsignaled_recv_ssrcs_.end(); - if (std::find(unsignaled_recv_ssrcs_.begin(), end_it, ssrc) != end_it) { + if (absl::linear_search(unsignaled_recv_ssrcs_.begin(), end_it, ssrc)) { continue; } } @@ -2280,8 +2277,7 @@ std::vector WebRtcVoiceMediaChannel::GetSources( bool WebRtcVoiceMediaChannel::MaybeDeregisterUnsignaledRecvStream( uint32_t ssrc) { RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); - auto it = std::find(unsignaled_recv_ssrcs_.begin(), - unsignaled_recv_ssrcs_.end(), ssrc); + auto it = absl::c_find(unsignaled_recv_ssrcs_, ssrc); if (it != unsignaled_recv_ssrcs_.end()) { unsignaled_recv_ssrcs_.erase(it); return true; diff --git a/media/sctp/sctp_transport.cc b/media/sctp/sctp_transport.cc index 65c21819d7..b6560180a4 100644 --- a/media/sctp/sctp_transport.cc +++ b/media/sctp/sctp_transport.cc @@ -23,9 +23,9 @@ enum PreservedErrno { #include #include -#include #include +#include "absl/algorithm/container.h" #include "media/base/codec.h" #include "media/base/media_constants.h" #include "media/base/stream_params.h" @@ -779,8 +779,8 @@ bool SctpTransport::SendQueuedStreamResets() { // Figure out how many streams need to be reset. We need to do this so we can // allocate the right amount of memory for the sctp_reset_streams structure. - size_t num_streams = std::count_if( - stream_status_by_sid_.begin(), stream_status_by_sid_.end(), + size_t num_streams = absl::c_count_if( + stream_status_by_sid_, [](const std::map::value_type& stream) { return stream.second.need_outgoing_reset(); }); diff --git a/media/sctp/sctp_transport_unittest.cc b/media/sctp/sctp_transport_unittest.cc index 0170785491..c86b62b578 100644 --- a/media/sctp/sctp_transport_unittest.cc +++ b/media/sctp/sctp_transport_unittest.cc @@ -10,11 +10,11 @@ #include #include -#include #include #include #include +#include "absl/algorithm/container.h" #include "media/sctp/sctp_transport.h" #include "p2p/base/fake_dtls_transport.h" #include "rtc_base/copy_on_write_buffer.h" @@ -75,12 +75,11 @@ class SctpTransportObserver : public sigslot::has_slots<> { } int StreamCloseCount(int stream) { - return std::count(closed_streams_.begin(), closed_streams_.end(), stream); + return absl::c_count(closed_streams_, stream); } bool WasStreamClosed(int stream) { - return std::find(closed_streams_.begin(), closed_streams_.end(), stream) != - closed_streams_.end(); + return absl::c_linear_search(closed_streams_, stream); } bool ReadyToSend() { return ready_to_send_; } @@ -102,9 +101,7 @@ class SignalTransportClosedReopener : public sigslot::has_slots<> { SignalTransportClosedReopener(SctpTransport* transport, SctpTransport* peer) : transport_(transport), peer_(peer) {} - int StreamCloseCount(int stream) { - return std::count(streams_.begin(), streams_.end(), stream); - } + int StreamCloseCount(int stream) { return absl::c_count(streams_, stream); } private: void OnStreamClosed(int stream) {