Use Abseil container algorithms in video/
Bug: None
Change-Id: Ia1419e14004d4a849dc0960a0501c25e6e50aeee
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/129560
Reviewed-by: Åsa Persson <asapersson@webrtc.org>
Commit-Queue: Steve Anton <steveanton@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27362}
diff --git a/video/BUILD.gn b/video/BUILD.gn
index 8f89e22..c793134 100644
--- a/video/BUILD.gn
+++ b/video/BUILD.gn
@@ -110,6 +110,7 @@
"../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/types:optional",
]
@@ -211,6 +212,7 @@
"../rtc_base/system:fallthrough",
"../rtc_base/task_utils:repeating_task",
"../system_wrappers:field_trial",
+ "//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/types:optional",
]
@@ -282,6 +284,7 @@
"../test:test_support_test_artifacts",
"../test:video_test_common",
"../test:video_test_support",
+ "//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory",
]
@@ -580,6 +583,7 @@
"../test:test_support",
"../test:video_test_common",
"//testing/gtest",
+ "//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/types:optional",
]
diff --git a/video/call_stats.cc b/video/call_stats.cc
index cfa066f..034bf08 100644
--- a/video/call_stats.cc
+++ b/video/call_stats.cc
@@ -13,6 +13,7 @@
#include <algorithm>
#include <memory>
+#include "absl/algorithm/container.h"
#include "modules/utility/include/process_thread.h"
#include "rtc_base/checks.h"
#include "rtc_base/location.h"
@@ -158,8 +159,7 @@
TemporaryDeregistration deregister(this, process_thread_,
process_thread_running_);
- auto it = std::find(observers_.begin(), observers_.end(), observer);
- if (it == observers_.end())
+ if (!absl::c_linear_search(observers_, observer))
observers_.push_back(observer);
}
diff --git a/video/end_to_end_tests/fec_tests.cc b/video/end_to_end_tests/fec_tests.cc
index dbf0b2c..29917a3 100644
--- a/video/end_to_end_tests/fec_tests.cc
+++ b/video/end_to_end_tests/fec_tests.cc
@@ -18,9 +18,13 @@
#include "modules/video_coding/codecs/vp8/include/vp8.h"
#include "test/call_test.h"
#include "test/field_trial.h"
+#include "test/gmock.h"
#include "test/gtest.h"
#include "test/rtcp_packet_parser.h"
+using ::testing::Contains;
+using ::testing::Not;
+
namespace webrtc {
namespace {
enum : int { // The first valid value is 1.
@@ -416,8 +420,7 @@
test::RtcpPacketParser rtcp_parser;
rtcp_parser.Parse(packet, length);
const std::vector<uint16_t>& nacks = rtcp_parser.nack()->packet_ids();
- EXPECT_TRUE(std::find(nacks.begin(), nacks.end(),
- ulpfec_sequence_number_) == nacks.end())
+ EXPECT_THAT(nacks, Not(Contains(ulpfec_sequence_number_)))
<< "Got nack for ULPFEC packet";
if (!nacks.empty() &&
IsNewerSequenceNumber(nacks.back(), ulpfec_sequence_number_)) {
diff --git a/video/end_to_end_tests/multi_codec_receive_tests.cc b/video/end_to_end_tests/multi_codec_receive_tests.cc
index 078ac22..140c4e1 100644
--- a/video/end_to_end_tests/multi_codec_receive_tests.cc
+++ b/video/end_to_end_tests/multi_codec_receive_tests.cc
@@ -17,8 +17,11 @@
#include "modules/video_coding/codecs/vp8/include/vp8.h"
#include "modules/video_coding/codecs/vp9/include/vp9.h"
#include "test/call_test.h"
+#include "test/gmock.h"
#include "test/gtest.h"
+using ::testing::Contains;
+
namespace webrtc {
namespace {
constexpr int kWidth = 1280;
@@ -98,9 +101,7 @@
// Verifies that all sent frames are decoded and rendered.
void OnFrame(const VideoFrame& rendered_frame) override {
rtc::CritScope lock(&crit_);
- EXPECT_NE(std::find(sent_timestamps_.begin(), sent_timestamps_.end(),
- rendered_frame.timestamp()),
- sent_timestamps_.end());
+ EXPECT_THAT(sent_timestamps_, Contains(rendered_frame.timestamp()));
// Remove old timestamps too, only the newest decoded frame is rendered.
num_rendered_frames_ +=
diff --git a/video/end_to_end_tests/retransmission_tests.cc b/video/end_to_end_tests/retransmission_tests.cc
index 49c3fb4..5c83ad4 100644
--- a/video/end_to_end_tests/retransmission_tests.cc
+++ b/video/end_to_end_tests/retransmission_tests.cc
@@ -8,6 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "api/test/simulated_network.h"
#include "api/test/video/function_video_encoder_factory.h"
@@ -370,8 +371,8 @@
// This should be the only dropped packet.
EXPECT_EQ(0u, retransmitted_timestamp_);
retransmitted_timestamp_ = header.timestamp;
- if (std::find(rendered_timestamps_.begin(), rendered_timestamps_.end(),
- retransmitted_timestamp_) != rendered_timestamps_.end()) {
+ if (absl::c_linear_search(rendered_timestamps_,
+ retransmitted_timestamp_)) {
// Frame was rendered before last packet was scheduled for sending.
// This is extremly rare but possible scenario because prober able to
// resend packet before it was send.
diff --git a/video/end_to_end_tests/stats_tests.cc b/video/end_to_end_tests/stats_tests.cc
index 14160f7..3717c76 100644
--- a/video/end_to_end_tests/stats_tests.cc
+++ b/video/end_to_end_tests/stats_tests.cc
@@ -8,6 +8,7 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "api/test/simulated_network.h"
#include "api/test/video/function_video_encoder_factory.h"
@@ -628,8 +629,7 @@
test::RtcpPacketParser rtcp_parser;
rtcp_parser.Parse(packet, length);
const std::vector<uint16_t>& nacks = rtcp_parser.nack()->packet_ids();
- if (!nacks.empty() && std::find(nacks.begin(), nacks.end(),
- dropped_rtp_packet_) != nacks.end()) {
+ if (!nacks.empty() && absl::c_linear_search(nacks, dropped_rtp_packet_)) {
dropped_rtp_packet_requested_ = true;
}
return SEND_PACKET;
diff --git a/video/rtp_video_stream_receiver.cc b/video/rtp_video_stream_receiver.cc
index 39c5478..a24b68d 100644
--- a/video/rtp_video_stream_receiver.cc
+++ b/video/rtp_video_stream_receiver.cc
@@ -10,10 +10,10 @@
#include "video/rtp_video_stream_receiver.h"
-#include <algorithm>
#include <utility>
#include <vector>
+#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "media/base/media_constants.h"
#include "modules/pacing/packet_router.h"
@@ -468,15 +468,14 @@
void RtpVideoStreamReceiver::AddSecondarySink(RtpPacketSinkInterface* sink) {
RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_task_checker_);
- RTC_DCHECK(std::find(secondary_sinks_.cbegin(), secondary_sinks_.cend(),
- sink) == secondary_sinks_.cend());
+ RTC_DCHECK(!absl::c_linear_search(secondary_sinks_, sink));
secondary_sinks_.push_back(sink);
}
void RtpVideoStreamReceiver::RemoveSecondarySink(
const RtpPacketSinkInterface* sink) {
RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_task_checker_);
- auto it = std::find(secondary_sinks_.begin(), secondary_sinks_.end(), sink);
+ auto it = absl::c_find(secondary_sinks_, sink);
if (it == secondary_sinks_.end()) {
// We might be rolling-back a call whose setup failed mid-way. In such a
// case, it's simpler to remove "everything" rather than remember what
diff --git a/video/send_statistics_proxy.cc b/video/send_statistics_proxy.cc
index 5c99a76..20e5449 100644
--- a/video/send_statistics_proxy.cc
+++ b/video/send_statistics_proxy.cc
@@ -15,6 +15,7 @@
#include <limits>
#include <utility>
+#include "absl/algorithm/container.h"
#include "modules/video_coding/include/video_codec_interface.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
@@ -749,13 +750,10 @@
if (it != stats_.substreams.end())
return &it->second;
- bool is_media = std::find(rtp_config_.ssrcs.begin(), rtp_config_.ssrcs.end(),
- ssrc) != rtp_config_.ssrcs.end();
+ bool is_media = absl::c_linear_search(rtp_config_.ssrcs, ssrc);
bool is_flexfec = rtp_config_.flexfec.payload_type != -1 &&
ssrc == rtp_config_.flexfec.ssrc;
- bool is_rtx =
- std::find(rtp_config_.rtx.ssrcs.begin(), rtp_config_.rtx.ssrcs.end(),
- ssrc) != rtp_config_.rtx.ssrcs.end();
+ bool is_rtx = absl::c_linear_search(rtp_config_.rtx.ssrcs, ssrc);
if (!is_media && !is_flexfec && !is_rtx)
return nullptr;
diff --git a/video/send_statistics_proxy_unittest.cc b/video/send_statistics_proxy_unittest.cc
index 586d57f..1e36795 100644
--- a/video/send_statistics_proxy_unittest.cc
+++ b/video/send_statistics_proxy_unittest.cc
@@ -10,11 +10,13 @@
#include "video/send_statistics_proxy.h"
+#include <algorithm>
#include <map>
#include <memory>
#include <string>
#include <vector>
+#include "absl/algorithm/container.h"
#include "system_wrappers/include/metrics.h"
#include "test/field_trial.h"
#include "test/gtest.h"
@@ -1685,10 +1687,8 @@
TEST_F(SendStatisticsProxyTest, NoSubstreams) {
uint32_t excluded_ssrc =
- std::max(
- *std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()),
- *std::max_element(config_.rtp.rtx.ssrcs.begin(),
- config_.rtp.rtx.ssrcs.end())) +
+ std::max(*absl::c_max_element(config_.rtp.ssrcs),
+ *absl::c_max_element(config_.rtp.rtx.ssrcs)) +
1;
// From RtcpStatisticsCallback.
RtcpStatistics rtcp_stats;
diff --git a/video/video_analyzer.cc b/video/video_analyzer.cc
index 6535133..b72048e 100644
--- a/video/video_analyzer.cc
+++ b/video/video_analyzer.cc
@@ -12,6 +12,7 @@
#include <algorithm>
#include <utility>
+#include "absl/algorithm/container.h"
#include "common_video/libyuv/include/webrtc_libyuv.h"
#include "modules/rtp_rtcp/source/rtp_format.h"
#include "modules/rtp_rtcp/source/rtp_utility.h"
@@ -738,10 +739,9 @@
void VideoAnalyzer::PrintSamplesToFile() {
FILE* out = graph_data_output_file_;
rtc::CritScope crit(&comparison_lock_);
- std::sort(samples_.begin(), samples_.end(),
- [](const Sample& A, const Sample& B) -> bool {
- return A.input_time_ms < B.input_time_ms;
- });
+ absl::c_sort(samples_, [](const Sample& A, const Sample& B) -> bool {
+ return A.input_time_ms < B.input_time_ms;
+ });
fprintf(out, "%s\n", graph_title_.c_str());
fprintf(out, "%" PRIuS "\n", samples_.size());
diff --git a/video/video_receive_stream.cc b/video/video_receive_stream.cc
index f6f601e..ec841ef 100644
--- a/video/video_receive_stream.cc
+++ b/video/video_receive_stream.cc
@@ -17,6 +17,7 @@
#include <string>
#include <utility>
+#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "absl/types/optional.h"
#include "api/array_view.h"
@@ -351,8 +352,7 @@
field_trial::FindFullName("WebRTC-DecoderDataDumpDirectory");
// Because '/' can't be used inside a field trial parameter, we use ':'
// instead.
- std::replace(decoded_output_file.begin(), decoded_output_file.end(), ':',
- '/');
+ absl::c_replace(decoded_output_file, ':', '/');
if (!decoded_output_file.empty()) {
char filename_buffer[256];
rtc::SimpleStringBuilder ssb(filename_buffer);
diff --git a/video/video_send_stream_impl.cc b/video/video_send_stream_impl.cc
index ae905df..100524d 100644
--- a/video/video_send_stream_impl.cc
+++ b/video/video_send_stream_impl.cc
@@ -15,6 +15,7 @@
#include <string>
#include <utility>
+#include "absl/algorithm/container.h"
#include "api/crypto/crypto_options.h"
#include "api/rtp_parameters.h"
#include "api/scoped_refptr.h"
@@ -48,10 +49,9 @@
bool TransportSeqNumExtensionConfigured(const VideoSendStream::Config& config) {
const std::vector<RtpExtension>& extensions = config.rtp.extensions;
- return std::find_if(
- extensions.begin(), extensions.end(), [](const RtpExtension& ext) {
- return ext.uri == RtpExtension::kTransportSequenceNumberUri;
- }) != extensions.end();
+ return absl::c_any_of(extensions, [](const RtpExtension& ext) {
+ return ext.uri == RtpExtension::kTransportSequenceNumberUri;
+ });
}
const char kForcedFallbackFieldTrial[] =
@@ -320,12 +320,10 @@
// side doesn't support the rotation extension. This allows us to prepare the
// encoder in the expectation that rotation is supported - which is the common
// case.
- bool rotation_applied =
- std::find_if(config_->rtp.extensions.begin(),
- config_->rtp.extensions.end(),
- [](const RtpExtension& extension) {
- return extension.uri == RtpExtension::kVideoRotationUri;
- }) == config_->rtp.extensions.end();
+ bool rotation_applied = absl::c_none_of(
+ config_->rtp.extensions, [](const RtpExtension& extension) {
+ return extension.uri == RtpExtension::kVideoRotationUri;
+ });
video_stream_encoder_->SetSink(this, rotation_applied);
}
diff --git a/video/video_send_stream_tests.cc b/video/video_send_stream_tests.cc
index c852f86..39406c6 100644
--- a/video/video_send_stream_tests.cc
+++ b/video/video_send_stream_tests.cc
@@ -11,6 +11,7 @@
#include <memory>
#include <vector>
+#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "api/task_queue/default_task_queue_factory.h"
#include "api/test/simulated_network.h"
@@ -935,8 +936,7 @@
sequence_number = (rtx_header[0] << 8) + rtx_header[1];
}
- auto found = std::find(nacked_sequence_numbers_.begin(),
- nacked_sequence_numbers_.end(), sequence_number);
+ auto found = absl::c_find(nacked_sequence_numbers_, sequence_number);
if (found != nacked_sequence_numbers_.end()) {
nacked_sequence_numbers_.erase(found);
diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc
index fcae1d6..d9bae1a 100644
--- a/video/video_stream_encoder.cc
+++ b/video/video_stream_encoder.cc
@@ -15,6 +15,7 @@
#include <numeric>
#include <utility>
+#include "absl/algorithm/container.h"
#include "absl/memory/memory.h"
#include "api/video/encoded_image.h"
#include "api/video/i420_buffer.h"
@@ -642,9 +643,8 @@
// Stream dimensions may be not equal to given because of a simulcast
// restrictions.
- auto highest_stream = std::max_element(
- streams.begin(), streams.end(),
- [](const webrtc::VideoStream& a, const webrtc::VideoStream& b) {
+ auto highest_stream = absl::c_max_element(
+ streams, [](const webrtc::VideoStream& a, const webrtc::VideoStream& b) {
return std::tie(a.width, a.height) < std::tie(b.width, b.height);
});
int highest_stream_width = static_cast<int>(highest_stream->width);
@@ -1898,7 +1898,7 @@
DecrementFramerate(reason);
// Reset if at max fps (i.e. in case of fewer steps up than down).
if (cur_fps == std::numeric_limits<int>::max())
- std::fill(fps_counters_.begin(), fps_counters_.end(), 0);
+ absl::c_fill(fps_counters_, 0);
}
int VideoStreamEncoder::AdaptCounter::FramerateCount() const {
@@ -1923,7 +1923,7 @@
int VideoStreamEncoder::AdaptCounter::Count(
const std::vector<int>& counters) const {
- return std::accumulate(counters.begin(), counters.end(), 0);
+ return absl::c_accumulate(counters, 0);
}
void VideoStreamEncoder::AdaptCounter::MoveCount(std::vector<int>* counters,