Use Abseil container algorithms in media/

Bug: None
Change-Id: I292e3401bbf19a66271dd5ef2b3ca4f8dcfd155d
Reviewed-on: https://webrtc-review.googlesource.com/c/120003
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Reviewed-by: Seth Hampson <shampson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26434}
This commit is contained in:
Steve Anton 2019-01-28 17:27:58 -08:00 committed by Commit Bot
parent 64b626b03f
commit 2c9ebefb44
16 changed files with 93 additions and 133 deletions

View file

@ -136,6 +136,7 @@ rtc_static_library("libjingle_peerconnection_api") {
"units:data_rate", "units:data_rate",
"video:encoded_image", "video:encoded_image",
"video:video_frame", "video:video_frame",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",

View file

@ -143,6 +143,7 @@ rtc_static_library("rtc_media_base") {
"../rtc_base:rtc_base_approved", "../rtc_base:rtc_base_approved",
"../rtc_base/system:rtc_export", "../rtc_base/system:rtc_export",
"../rtc_base/third_party/sigslot", "../rtc_base/third_party/sigslot",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional", "//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:field_trial_parser",
"../rtc_base/experiments:normalize_simulcast_size_experiment", "../rtc_base/experiments:normalize_simulcast_size_experiment",
"../system_wrappers", "../system_wrappers",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/strings",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",
@ -416,6 +418,7 @@ rtc_static_library("rtc_data") {
"../rtc_base:rtc_base_approved", "../rtc_base:rtc_base_approved",
"../rtc_base/third_party/sigslot", "../rtc_base/third_party/sigslot",
"../system_wrappers", "../system_wrappers",
"//third_party/abseil-cpp/absl/algorithm:container",
] ]
} }
@ -453,6 +456,7 @@ if (rtc_include_tests) {
"../rtc_base:gunit_helpers", "../rtc_base:gunit_helpers",
"../rtc_base:rtc_task_queue", "../rtc_base:rtc_task_queue",
"../rtc_base:stringutils", "../rtc_base:stringutils",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/strings", "//third_party/abseil-cpp/absl/strings",
] ]
@ -652,6 +656,7 @@ if (rtc_include_tests) {
"../test:audio_codec_mocks", "../test:audio_codec_mocks",
"../test:test_support", "../test:test_support",
"../test:video_test_common", "../test:video_test_common",
"//third_party/abseil-cpp/absl/algorithm:container",
] ]
} }
} }

View file

@ -10,8 +10,7 @@
#include "media/base/codec.h" #include "media/base/codec.h"
#include <algorithm> #include "absl/algorithm/container.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "media/base/h264_profile_level_id.h" #include "media/base/h264_profile_level_id.h"
#include "media/base/vp9_profile.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 { 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) { void FeedbackParams::Add(const FeedbackParam& param) {

View file

@ -12,6 +12,7 @@
#include <utility> #include <utility>
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
@ -482,7 +483,7 @@ FakeVoiceMediaChannel* FakeVoiceEngine::GetChannel(size_t index) {
return (channels_.size() > index) ? channels_[index] : NULL; return (channels_.size() > index) ? channels_[index] : NULL;
} }
void FakeVoiceEngine::UnregisterChannel(VoiceMediaChannel* channel) { void FakeVoiceEngine::UnregisterChannel(VoiceMediaChannel* channel) {
channels_.erase(std::find(channels_.begin(), channels_.end(), channel)); channels_.erase(absl::c_find(channels_, channel));
} }
const std::vector<AudioCodec>& FakeVoiceEngine::send_codecs() const { const std::vector<AudioCodec>& FakeVoiceEngine::send_codecs() const {
return codecs_; return codecs_;
@ -537,7 +538,7 @@ FakeVideoMediaChannel* FakeVideoEngine::GetChannel(size_t index) {
return (channels_.size() > index) ? channels_[index] : nullptr; return (channels_.size() > index) ? channels_[index] : nullptr;
} }
void FakeVideoEngine::UnregisterChannel(VideoMediaChannel* channel) { 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()); RTC_DCHECK(it != channels_.end());
channels_.erase(it); channels_.erase(it);
} }
@ -586,7 +587,7 @@ FakeDataMediaChannel* FakeDataEngine::GetChannel(size_t index) {
return (channels_.size() > index) ? channels_[index] : NULL; return (channels_.size() > index) ? channels_[index] : NULL;
} }
void FakeDataEngine::UnregisterChannel(DataMediaChannel* channel) { 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<DataCodec>& data_codecs) { void FakeDataEngine::SetDataCodecs(const std::vector<DataCodec>& data_codecs) {
data_codecs_ = data_codecs; data_codecs_ = data_codecs;

View file

@ -19,6 +19,7 @@
#include <tuple> #include <tuple>
#include <vector> #include <vector>
#include "absl/algorithm/container.h"
#include "api/call/audio_sink.h" #include "api/call/audio_sink.h"
#include "media/base/audio_source.h" #include "media/base/audio_source.h"
#include "media/base/media_engine.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_send_codecs(bool fail) { fail_set_send_codecs_ = fail; }
void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; } void set_fail_set_recv_codecs(bool fail) { fail_set_recv_codecs_ = fail; }
virtual bool AddSendStream(const StreamParams& sp) { virtual bool AddSendStream(const StreamParams& sp) {
if (std::find(send_streams_.begin(), send_streams_.end(), sp) != if (absl::c_linear_search(send_streams_, sp)) {
send_streams_.end()) {
return false; return false;
} }
send_streams_.push_back(sp); send_streams_.push_back(sp);
@ -118,8 +118,7 @@ class RtpHelper : public Base {
return RemoveStreamBySsrc(&send_streams_, ssrc); return RemoveStreamBySsrc(&send_streams_, ssrc);
} }
virtual bool AddRecvStream(const StreamParams& sp) { virtual bool AddRecvStream(const StreamParams& sp) {
if (std::find(receive_streams_.begin(), receive_streams_.end(), sp) != if (absl::c_linear_search(receive_streams_, sp)) {
receive_streams_.end()) {
return false; return false;
} }
receive_streams_.push_back(sp); receive_streams_.push_back(sp);

View file

@ -10,8 +10,8 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <algorithm>
#include "absl/algorithm/container.h"
#include "media/base/fake_rtp.h" #include "media/base/fake_rtp.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "test/gtest.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 // The header extension doesn't get encrypted if the id is not in the
// list of header extensions to encrypt. // list of header extensions to encrypt.
if (expect_equal || if (expect_equal || !absl::c_linear_search(encrypted_headers, id)) {
std::find(encrypted_headers.begin(), encrypted_headers.end(), id) ==
encrypted_headers.end()) {
EXPECT_EQ(0, memcmp(extension_data1, extension_data2, len)); EXPECT_EQ(0, memcmp(extension_data1, extension_data2, len));
} else { } else {
EXPECT_NE(0, memcmp(extension_data1, extension_data2, len)); EXPECT_NE(0, memcmp(extension_data1, extension_data2, len));

View file

@ -11,9 +11,9 @@
#include "media/base/stream_params.h" #include "media/base/stream_params.h"
#include <stdint.h> #include <stdint.h>
#include <algorithm>
#include <list> #include <list>
#include "absl/algorithm/container.h"
#include "api/array_view.h" #include "api/array_view.h"
#include "rtc_base/strings/string_builder.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 && ssrc_groups == other.ssrc_groups && cname == other.cname &&
stream_ids_ == other.stream_ids_ && stream_ids_ == other.stream_ids_ &&
// RIDs are not required to be in the same order for equality. // RIDs are not required to be in the same order for equality.
rids_.size() == other.rids_.size() && absl::c_is_permutation(rids_, other.rids_));
std::is_permutation(rids_.begin(), rids_.end(), other.rids_.begin()));
} }
std::string StreamParams::ToString() const { std::string StreamParams::ToString() const {
@ -328,8 +327,7 @@ bool IsOneSsrcStream(const StreamParams& sp) {
namespace { namespace {
void RemoveFirst(std::list<uint32_t>* ssrcs, uint32_t value) { void RemoveFirst(std::list<uint32_t>* ssrcs, uint32_t value) {
std::list<uint32_t>::iterator it = auto it = absl::c_find(*ssrcs, value);
std::find(ssrcs->begin(), ssrcs->end(), value);
if (it != ssrcs->end()) { if (it != ssrcs->end()) {
ssrcs->erase(it); ssrcs->erase(it);
} }

View file

@ -47,11 +47,11 @@
#define MEDIA_BASE_STREAM_PARAMS_H_ #define MEDIA_BASE_STREAM_PARAMS_H_
#include <stddef.h> #include <stddef.h>
#include <algorithm>
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/algorithm/container.h"
#include "media/base/rid_description.h" #include "media/base/rid_description.h"
#include "rtc_base/constructor_magic.h" #include "rtc_base/constructor_magic.h"
#include "rtc_base/unique_id_generator.h" #include "rtc_base/unique_id_generator.h"
@ -114,7 +114,7 @@ struct StreamParams {
} }
bool has_ssrcs() const { return !ssrcs.empty(); } bool has_ssrcs() const { return !ssrcs.empty(); }
bool has_ssrc(uint32_t ssrc) const { 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); } void add_ssrc(uint32_t ssrc) { ssrcs.push_back(ssrc); }
bool has_ssrc_groups() const { return !ssrc_groups.empty(); } bool has_ssrc_groups() const { return !ssrc_groups.empty(); }
@ -296,15 +296,13 @@ struct MediaStreams {
template <class Condition> template <class Condition>
const StreamParams* GetStream(const StreamParamsVec& streams, const StreamParams* GetStream(const StreamParamsVec& streams,
Condition condition) { Condition condition) {
StreamParamsVec::const_iterator found = auto found = absl::c_find_if(streams, condition);
std::find_if(streams.begin(), streams.end(), condition);
return found == streams.end() ? nullptr : &(*found); return found == streams.end() ? nullptr : &(*found);
} }
template <class Condition> template <class Condition>
StreamParams* GetStream(StreamParamsVec& streams, Condition condition) { StreamParams* GetStream(StreamParamsVec& streams, Condition condition) {
StreamParamsVec::iterator found = auto found = absl::c_find_if(streams, condition);
std::find_if(streams.begin(), streams.end(), condition);
return found == streams.end() ? nullptr : &(*found); return found == streams.end() ? nullptr : &(*found);
} }

View file

@ -10,8 +10,7 @@
#include "media/base/video_source_base.h" #include "media/base/video_source_base.h"
#include <algorithm> #include "absl/algorithm/container.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
namespace rtc { namespace rtc {
@ -44,8 +43,8 @@ void VideoSourceBase::RemoveSink(VideoSinkInterface<webrtc::VideoFrame>* sink) {
VideoSourceBase::SinkPair* VideoSourceBase::FindSinkPair( VideoSourceBase::SinkPair* VideoSourceBase::FindSinkPair(
const VideoSinkInterface<webrtc::VideoFrame>* sink) { const VideoSinkInterface<webrtc::VideoFrame>* sink) {
auto sink_pair_it = std::find_if( auto sink_pair_it = absl::c_find_if(
sinks_.begin(), sinks_.end(), sinks_,
[sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; }); [sink](const SinkPair& sink_pair) { return sink_pair.sink == sink; });
if (sink_pair_it != sinks_.end()) { if (sink_pair_it != sinks_.end()) {
return &*sink_pair_it; return &*sink_pair_it;

View file

@ -10,9 +10,9 @@
#include "media/engine/fake_webrtc_call.h" #include "media/engine/fake_webrtc_call.h"
#include <algorithm>
#include <utility> #include <utility>
#include "absl/algorithm/container.h"
#include "api/call/audio_sink.h" #include "api/call/audio_sink.h"
#include "media/base/rtp_utils.h" #include "media/base/rtp_utils.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
@ -467,9 +467,8 @@ webrtc::AudioSendStream* FakeCall::CreateAudioSendStream(
} }
void FakeCall::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) { void FakeCall::DestroyAudioSendStream(webrtc::AudioSendStream* send_stream) {
auto it = std::find(audio_send_streams_.begin(), auto it = absl::c_find(audio_send_streams_,
audio_send_streams_.end(), static_cast<FakeAudioSendStream*>(send_stream));
static_cast<FakeAudioSendStream*>(send_stream));
if (it == audio_send_streams_.end()) { if (it == audio_send_streams_.end()) {
ADD_FAILURE() << "DestroyAudioSendStream called with unknown parameter."; ADD_FAILURE() << "DestroyAudioSendStream called with unknown parameter.";
} else { } else {
@ -488,9 +487,8 @@ webrtc::AudioReceiveStream* FakeCall::CreateAudioReceiveStream(
void FakeCall::DestroyAudioReceiveStream( void FakeCall::DestroyAudioReceiveStream(
webrtc::AudioReceiveStream* receive_stream) { webrtc::AudioReceiveStream* receive_stream) {
auto it = std::find(audio_receive_streams_.begin(), auto it = absl::c_find(audio_receive_streams_,
audio_receive_streams_.end(), static_cast<FakeAudioReceiveStream*>(receive_stream));
static_cast<FakeAudioReceiveStream*>(receive_stream));
if (it == audio_receive_streams_.end()) { if (it == audio_receive_streams_.end()) {
ADD_FAILURE() << "DestroyAudioReceiveStream called with unknown parameter."; ADD_FAILURE() << "DestroyAudioReceiveStream called with unknown parameter.";
} else { } else {
@ -510,9 +508,8 @@ webrtc::VideoSendStream* FakeCall::CreateVideoSendStream(
} }
void FakeCall::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { void FakeCall::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) {
auto it = std::find(video_send_streams_.begin(), auto it = absl::c_find(video_send_streams_,
video_send_streams_.end(), static_cast<FakeVideoSendStream*>(send_stream));
static_cast<FakeVideoSendStream*>(send_stream));
if (it == video_send_streams_.end()) { if (it == video_send_streams_.end()) {
ADD_FAILURE() << "DestroyVideoSendStream called with unknown parameter."; ADD_FAILURE() << "DestroyVideoSendStream called with unknown parameter.";
} else { } else {
@ -531,9 +528,8 @@ webrtc::VideoReceiveStream* FakeCall::CreateVideoReceiveStream(
void FakeCall::DestroyVideoReceiveStream( void FakeCall::DestroyVideoReceiveStream(
webrtc::VideoReceiveStream* receive_stream) { webrtc::VideoReceiveStream* receive_stream) {
auto it = std::find(video_receive_streams_.begin(), auto it = absl::c_find(video_receive_streams_,
video_receive_streams_.end(), static_cast<FakeVideoReceiveStream*>(receive_stream));
static_cast<FakeVideoReceiveStream*>(receive_stream));
if (it == video_receive_streams_.end()) { if (it == video_receive_streams_.end()) {
ADD_FAILURE() << "DestroyVideoReceiveStream called with unknown parameter."; ADD_FAILURE() << "DestroyVideoReceiveStream called with unknown parameter.";
} else { } else {
@ -552,9 +548,9 @@ webrtc::FlexfecReceiveStream* FakeCall::CreateFlexfecReceiveStream(
void FakeCall::DestroyFlexfecReceiveStream( void FakeCall::DestroyFlexfecReceiveStream(
webrtc::FlexfecReceiveStream* receive_stream) { webrtc::FlexfecReceiveStream* receive_stream) {
auto it = std::find(flexfec_receive_streams_.begin(), auto it =
flexfec_receive_streams_.end(), absl::c_find(flexfec_receive_streams_,
static_cast<FakeFlexfecReceiveStream*>(receive_stream)); static_cast<FakeFlexfecReceiveStream*>(receive_stream));
if (it == flexfec_receive_streams_.end()) { if (it == flexfec_receive_streams_.end()) {
ADD_FAILURE() ADD_FAILURE()
<< "DestroyFlexfecReceiveStream called with unknown parameter."; << "DestroyFlexfecReceiveStream called with unknown parameter.";

View file

@ -10,9 +10,9 @@
#include "media/engine/webrtc_media_engine.h" #include "media/engine/webrtc_media_engine.h"
#include <algorithm>
#include <utility> #include <utility>
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "api/video/builtin_video_bitrate_allocator_factory.h" #include "api/video/builtin_video_bitrate_allocator_factory.h"
#include "api/video_codecs/video_decoder_factory.h" #include "api/video_codecs/video_decoder_factory.h"
@ -82,8 +82,8 @@ void DiscardRedundantExtensions(
RTC_DCHECK(extensions); RTC_DCHECK(extensions);
bool found = false; bool found = false;
for (const char* uri : extensions_decreasing_prio) { for (const char* uri : extensions_decreasing_prio) {
auto it = std::find_if( auto it = absl::c_find_if(
extensions->begin(), extensions->end(), *extensions,
[uri](const webrtc::RtpExtension& rhs) { return rhs.uri == uri; }); [uri](const webrtc::RtpExtension& rhs) { return rhs.uri == uri; });
if (it != extensions->end()) { if (it != extensions->end()) {
if (found) { if (found) {
@ -135,8 +135,8 @@ std::vector<webrtc::RtpExtension> FilterRtpExtensions(
// Sort by name, ascending (prioritise encryption), so that we don't reset // Sort by name, ascending (prioritise encryption), so that we don't reset
// extensions if they were specified in a different order (also allows us // extensions if they were specified in a different order (also allows us
// to use std::unique below). // to use std::unique below).
std::sort( absl::c_sort(
result.begin(), result.end(), result,
[](const webrtc::RtpExtension& rhs, const webrtc::RtpExtension& lhs) { [](const webrtc::RtpExtension& rhs, const webrtc::RtpExtension& lhs) {
return rhs.encrypt == lhs.encrypt ? rhs.uri < lhs.uri return rhs.encrypt == lhs.encrypt ? rhs.uri < lhs.uri
: rhs.encrypt > lhs.encrypt; : rhs.encrypt > lhs.encrypt;

View file

@ -560,10 +560,6 @@ WebRtcVideoChannel::SelectSendVideoCodec(
bool WebRtcVideoChannel::NonFlexfecReceiveCodecsHaveChanged( bool WebRtcVideoChannel::NonFlexfecReceiveCodecsHaveChanged(
std::vector<VideoCodecSettings> before, std::vector<VideoCodecSettings> before,
std::vector<VideoCodecSettings> after) { std::vector<VideoCodecSettings> after) {
if (before.size() != after.size()) {
return true;
}
// The receive codec order doesn't matter, so we sort the codecs before // The receive codec order doesn't matter, so we sort the codecs before
// comparing. This is necessary because currently the // comparing. This is necessary because currently the
// only way to change the send codec is to munge SDP, which causes // only way to change the send codec is to munge SDP, which causes
@ -576,14 +572,14 @@ bool WebRtcVideoChannel::NonFlexfecReceiveCodecsHaveChanged(
const VideoCodecSettings& codec2) { const VideoCodecSettings& codec2) {
return codec1.codec.id > codec2.codec.id; return codec1.codec.id > codec2.codec.id;
}; };
std::sort(before.begin(), before.end(), comparison); absl::c_sort(before, comparison);
std::sort(after.begin(), after.end(), comparison); absl::c_sort(after, comparison);
// Changes in FlexFEC payload type are handled separately in // Changes in FlexFEC payload type are handled separately in
// WebRtcVideoChannel::GetChangedRecvParameters, so disregard FlexFEC in the // WebRtcVideoChannel::GetChangedRecvParameters, so disregard FlexFEC in the
// comparison here. // comparison here.
return !std::equal(before.begin(), before.end(), after.begin(), return !absl::c_equal(before, after,
VideoCodecSettings::EqualsDisregardingFlexfec); VideoCodecSettings::EqualsDisregardingFlexfec);
} }
bool WebRtcVideoChannel::GetChangedSendParameters( bool WebRtcVideoChannel::GetChangedSendParameters(

View file

@ -8,12 +8,12 @@
* be found in the AUTHORS file in the root of the source tree. * be found in the AUTHORS file in the root of the source tree.
*/ */
#include <algorithm>
#include <map> #include <map>
#include <memory> #include <memory>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "api/rtp_parameters.h" #include "api/rtp_parameters.h"
@ -681,8 +681,7 @@ WebRtcVideoEngineTest::SetSendParamsWithAllSupportedCodecs() {
for (const webrtc::SdpVideoFormat& format : for (const webrtc::SdpVideoFormat& format :
encoder_factory_->GetSupportedFormats()) { encoder_factory_->GetSupportedFormats()) {
cricket::VideoCodec engine_codec = GetEngineCodec(format.name); cricket::VideoCodec engine_codec = GetEngineCodec(format.name);
if (std::find(parameters.codecs.begin(), parameters.codecs.end(), if (!absl::c_linear_search(parameters.codecs, engine_codec)) {
engine_codec) == parameters.codecs.end()) {
parameters.codecs.push_back(engine_codec); parameters.codecs.push_back(engine_codec);
} }
} }
@ -878,23 +877,15 @@ TEST_F(WebRtcVideoEngineTest,
Flexfec03SupportedAsInternalCodecBehindFieldTrial) { Flexfec03SupportedAsInternalCodecBehindFieldTrial) {
encoder_factory_->AddSupportedVideoCodecType("VP8"); encoder_factory_->AddSupportedVideoCodecType("VP8");
auto is_flexfec = [](const VideoCodec& codec) { auto flexfec = Field("name", &VideoCodec::name, "flexfec-03");
if (codec.name == "flexfec-03")
return true;
return false;
};
// FlexFEC is not active without field trial. // FlexFEC is not active without field trial.
const std::vector<VideoCodec> codecs_before = engine_.codecs(); EXPECT_THAT(engine_.codecs(), Not(Contains(flexfec)));
EXPECT_EQ(codecs_before.end(), std::find_if(codecs_before.begin(),
codecs_before.end(), is_flexfec));
// FlexFEC is active with field trial. // FlexFEC is active with field trial.
webrtc::test::ScopedFieldTrials override_field_trials_( webrtc::test::ScopedFieldTrials override_field_trials_(
"WebRTC-FlexFEC-03-Advertised/Enabled/"); "WebRTC-FlexFEC-03-Advertised/Enabled/");
const std::vector<VideoCodec> codecs_after = engine_.codecs(); EXPECT_THAT(engine_.codecs(), Contains(flexfec));
EXPECT_NE(codecs_after.end(),
std::find_if(codecs_after.begin(), codecs_after.end(), is_flexfec));
} }
// Test that codecs are added in the order they are reported from the factory. // 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 // Setting the same extensions (even if in different order) shouldn't
// reallocate the stream. // reallocate the stream.
std::reverse(send_parameters_.extensions.begin(), absl::c_reverse(send_parameters_.extensions);
send_parameters_.extensions.end());
EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); 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 // Setting the same extensions (even if in different order) shouldn't
// reallocate the stream. // reallocate the stream.
std::reverse(recv_parameters_.extensions.begin(), absl::c_reverse(recv_parameters_.extensions);
recv_parameters_.extensions.end());
EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_));
EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams());
@ -6869,16 +6858,12 @@ TEST_F(WebRtcVideoChannelTestWithClock, GetContributingSources) {
std::vector<webrtc::RtpSource> sources = channel_->GetSources(kSsrc); std::vector<webrtc::RtpSource> sources = channel_->GetSources(kSsrc);
EXPECT_EQ(sources[0].timestamp_ms(), sources[1].timestamp_ms()); EXPECT_EQ(sources[0].timestamp_ms(), sources[1].timestamp_ms());
// 1 SSRC and 1 CSRC. // 1 SSRC and 1 CSRC.
EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), EXPECT_EQ(1, absl::c_count_if(sources, [](const webrtc::RtpSource& source) {
[](const webrtc::RtpSource& source) { return source.source_type() == webrtc::RtpSourceType::SSRC;
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;
EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), }));
[](const webrtc::RtpSource& source) {
return source.source_type() ==
webrtc::RtpSourceType::CSRC;
}));
} }
int64_t timestamp1 = channel_->GetSources(kSsrc)[0].timestamp_ms(); int64_t timestamp1 = channel_->GetSources(kSsrc)[0].timestamp_ms();
@ -6898,22 +6883,18 @@ TEST_F(WebRtcVideoChannelTestWithClock, GetContributingSources) {
std::vector<webrtc::RtpSource> sources = channel_->GetSources(kSsrc); std::vector<webrtc::RtpSource> sources = channel_->GetSources(kSsrc);
EXPECT_NE(sources[0].timestamp_ms(), sources[1].timestamp_ms()); EXPECT_NE(sources[0].timestamp_ms(), sources[1].timestamp_ms());
// 1 SSRC and 1 CSRC. // 1 SSRC and 1 CSRC.
EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), EXPECT_EQ(1, absl::c_count_if(sources, [](const webrtc::RtpSource& source) {
[](const webrtc::RtpSource& source) { return source.source_type() == webrtc::RtpSourceType::SSRC;
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;
EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), }));
[](const webrtc::RtpSource& source) { auto ssrcSource =
return source.source_type() == absl::c_find_if(sources, [](const webrtc::RtpSource& source) {
webrtc::RtpSourceType::CSRC;
}));
auto ssrcSource = std::find_if(
sources.begin(), sources.end(), [](const webrtc::RtpSource& source) {
return source.source_type() == webrtc::RtpSourceType::SSRC; return source.source_type() == webrtc::RtpSourceType::SSRC;
}); });
auto csrcSource = std::find_if( auto csrcSource =
sources.begin(), sources.end(), [](const webrtc::RtpSource& source) { absl::c_find_if(sources, [](const webrtc::RtpSource& source) {
return source.source_type() == webrtc::RtpSourceType::CSRC; return source.source_type() == webrtc::RtpSourceType::CSRC;
}); });
@ -6928,16 +6909,12 @@ TEST_F(WebRtcVideoChannelTestWithClock, GetContributingSources) {
ASSERT_EQ(1u, channel_->GetSources(kSsrc).size()); ASSERT_EQ(1u, channel_->GetSources(kSsrc).size());
EXPECT_EQ(0u, channel_->GetSources(kCsrc).size()); EXPECT_EQ(0u, channel_->GetSources(kCsrc).size());
std::vector<webrtc::RtpSource> sources = channel_->GetSources(kSsrc); std::vector<webrtc::RtpSource> sources = channel_->GetSources(kSsrc);
EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), EXPECT_EQ(1, absl::c_count_if(sources, [](const webrtc::RtpSource& source) {
[](const webrtc::RtpSource& source) { return source.source_type() == webrtc::RtpSourceType::SSRC;
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;
EXPECT_EQ(0, std::count_if(sources.begin(), sources.end(), }));
[](const webrtc::RtpSource& source) {
return source.source_type() ==
webrtc::RtpSourceType::CSRC;
}));
} }
fake_clock_.AdvanceTime(webrtc::TimeDelta::ms(1)); fake_clock_.AdvanceTime(webrtc::TimeDelta::ms(1));

View file

@ -19,6 +19,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "absl/algorithm/container.h"
#include "absl/strings/match.h" #include "absl/strings/match.h"
#include "api/audio_codecs/audio_codec_pair_id.h" #include "api/audio_codecs/audio_codec_pair_id.h"
#include "api/call/audio_sink.h" #include "api/call/audio_sink.h"
@ -125,12 +126,10 @@ bool VerifyUniquePayloadTypes(const std::vector<AudioCodec>& codecs) {
return true; return true;
} }
std::vector<int> payload_types; std::vector<int> payload_types;
for (const AudioCodec& codec : codecs) { absl::c_transform(codecs, std::back_inserter(payload_types),
payload_types.push_back(codec.id); [](const AudioCodec& codec) { return codec.id; });
} absl::c_sort(payload_types);
std::sort(payload_types.begin(), payload_types.end()); return absl::c_adjacent_find(payload_types) == payload_types.end();
auto it = std::unique(payload_types.begin(), payload_types.end());
return it == payload_types.end();
} }
absl::optional<std::string> GetAudioNetworkAdaptorConfig( absl::optional<std::string> GetAudioNetworkAdaptorConfig(
@ -579,7 +578,7 @@ void WebRtcVoiceEngine::RegisterChannel(WebRtcVoiceMediaChannel* channel) {
void WebRtcVoiceEngine::UnregisterChannel(WebRtcVoiceMediaChannel* channel) { void WebRtcVoiceEngine::UnregisterChannel(WebRtcVoiceMediaChannel* channel) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); 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()); RTC_DCHECK(it != channels_.end());
channels_.erase(it); channels_.erase(it);
} }
@ -2029,9 +2028,7 @@ void WebRtcVoiceMediaChannel::OnPacketReceived(rtc::CopyOnWriteBuffer* packet,
if (!GetRtpSsrc(packet->cdata(), packet->size(), &ssrc)) { if (!GetRtpSsrc(packet->cdata(), packet->size(), &ssrc)) {
return; return;
} }
RTC_DCHECK(std::find(unsignaled_recv_ssrcs_.begin(), RTC_DCHECK(!absl::c_linear_search(unsignaled_recv_ssrcs_, ssrc));
unsignaled_recv_ssrcs_.end(),
ssrc) == unsignaled_recv_ssrcs_.end());
// Add new stream. // Add new stream.
StreamParams sp = unsignaled_stream_params_; 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 // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=8158
if (!unsignaled_recv_ssrcs_.empty()) { if (!unsignaled_recv_ssrcs_.empty()) {
auto end_it = --unsignaled_recv_ssrcs_.end(); 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; continue;
} }
} }
@ -2280,8 +2277,7 @@ std::vector<webrtc::RtpSource> WebRtcVoiceMediaChannel::GetSources(
bool WebRtcVoiceMediaChannel::MaybeDeregisterUnsignaledRecvStream( bool WebRtcVoiceMediaChannel::MaybeDeregisterUnsignaledRecvStream(
uint32_t ssrc) { uint32_t ssrc) {
RTC_DCHECK(worker_thread_checker_.CalledOnValidThread()); RTC_DCHECK(worker_thread_checker_.CalledOnValidThread());
auto it = std::find(unsignaled_recv_ssrcs_.begin(), auto it = absl::c_find(unsignaled_recv_ssrcs_, ssrc);
unsignaled_recv_ssrcs_.end(), ssrc);
if (it != unsignaled_recv_ssrcs_.end()) { if (it != unsignaled_recv_ssrcs_.end()) {
unsignaled_recv_ssrcs_.erase(it); unsignaled_recv_ssrcs_.erase(it);
return true; return true;

View file

@ -23,9 +23,9 @@ enum PreservedErrno {
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <algorithm>
#include <memory> #include <memory>
#include "absl/algorithm/container.h"
#include "media/base/codec.h" #include "media/base/codec.h"
#include "media/base/media_constants.h" #include "media/base/media_constants.h"
#include "media/base/stream_params.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 // 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. // allocate the right amount of memory for the sctp_reset_streams structure.
size_t num_streams = std::count_if( size_t num_streams = absl::c_count_if(
stream_status_by_sid_.begin(), stream_status_by_sid_.end(), stream_status_by_sid_,
[](const std::map<uint32_t, StreamStatus>::value_type& stream) { [](const std::map<uint32_t, StreamStatus>::value_type& stream) {
return stream.second.need_outgoing_reset(); return stream.second.need_outgoing_reset();
}); });

View file

@ -10,11 +10,11 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <algorithm>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/algorithm/container.h"
#include "media/sctp/sctp_transport.h" #include "media/sctp/sctp_transport.h"
#include "p2p/base/fake_dtls_transport.h" #include "p2p/base/fake_dtls_transport.h"
#include "rtc_base/copy_on_write_buffer.h" #include "rtc_base/copy_on_write_buffer.h"
@ -75,12 +75,11 @@ class SctpTransportObserver : public sigslot::has_slots<> {
} }
int StreamCloseCount(int stream) { 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) { bool WasStreamClosed(int stream) {
return std::find(closed_streams_.begin(), closed_streams_.end(), stream) != return absl::c_linear_search(closed_streams_, stream);
closed_streams_.end();
} }
bool ReadyToSend() { return ready_to_send_; } bool ReadyToSend() { return ready_to_send_; }
@ -102,9 +101,7 @@ class SignalTransportClosedReopener : public sigslot::has_slots<> {
SignalTransportClosedReopener(SctpTransport* transport, SctpTransport* peer) SignalTransportClosedReopener(SctpTransport* transport, SctpTransport* peer)
: transport_(transport), peer_(peer) {} : transport_(transport), peer_(peer) {}
int StreamCloseCount(int stream) { int StreamCloseCount(int stream) { return absl::c_count(streams_, stream); }
return std::count(streams_.begin(), streams_.end(), stream);
}
private: private:
void OnStreamClosed(int stream) { void OnStreamClosed(int stream) {