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}
This commit is contained in:
Steve Anton 2019-03-28 10:51:27 -07:00 committed by Commit Bot
parent 91c2606ca1
commit bd631a00c0
14 changed files with 51 additions and 47 deletions

View File

@ -110,6 +110,7 @@ rtc_static_library("video") {
"../system_wrappers", "../system_wrappers",
"../system_wrappers:field_trial", "../system_wrappers:field_trial",
"../system_wrappers:metrics", "../system_wrappers:metrics",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",
] ]
@ -211,6 +212,7 @@ rtc_source_set("video_stream_encoder_impl") {
"../rtc_base/system:fallthrough", "../rtc_base/system:fallthrough",
"../rtc_base/task_utils:repeating_task", "../rtc_base/task_utils:repeating_task",
"../system_wrappers:field_trial", "../system_wrappers:field_trial",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",
] ]
@ -282,6 +284,7 @@ if (rtc_include_tests) {
"../test:test_support_test_artifacts", "../test:test_support_test_artifacts",
"../test:video_test_common", "../test:video_test_common",
"../test:video_test_support", "../test:video_test_support",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
] ]
@ -580,6 +583,7 @@ if (rtc_include_tests) {
"../test:test_support", "../test:test_support",
"../test:video_test_common", "../test:video_test_common",
"//testing/gtest", "//testing/gtest",
"//third_party/abseil-cpp/absl/algorithm:container",
"//third_party/abseil-cpp/absl/memory", "//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/types:optional", "//third_party/abseil-cpp/absl/types:optional",
] ]

View File

@ -13,6 +13,7 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include "absl/algorithm/container.h"
#include "modules/utility/include/process_thread.h" #include "modules/utility/include/process_thread.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/location.h" #include "rtc_base/location.h"
@ -158,8 +159,7 @@ void CallStats::RegisterStatsObserver(CallStatsObserver* observer) {
TemporaryDeregistration deregister(this, process_thread_, TemporaryDeregistration deregister(this, process_thread_,
process_thread_running_); process_thread_running_);
auto it = std::find(observers_.begin(), observers_.end(), observer); if (!absl::c_linear_search(observers_, observer))
if (it == observers_.end())
observers_.push_back(observer); observers_.push_back(observer);
} }

View File

@ -18,9 +18,13 @@
#include "modules/video_coding/codecs/vp8/include/vp8.h" #include "modules/video_coding/codecs/vp8/include/vp8.h"
#include "test/call_test.h" #include "test/call_test.h"
#include "test/field_trial.h" #include "test/field_trial.h"
#include "test/gmock.h"
#include "test/gtest.h" #include "test/gtest.h"
#include "test/rtcp_packet_parser.h" #include "test/rtcp_packet_parser.h"
using ::testing::Contains;
using ::testing::Not;
namespace webrtc { namespace webrtc {
namespace { namespace {
enum : int { // The first valid value is 1. enum : int { // The first valid value is 1.
@ -416,8 +420,7 @@ TEST_F(FecEndToEndTest, ReceivedUlpfecPacketsNotNacked) {
test::RtcpPacketParser rtcp_parser; test::RtcpPacketParser rtcp_parser;
rtcp_parser.Parse(packet, length); rtcp_parser.Parse(packet, length);
const std::vector<uint16_t>& nacks = rtcp_parser.nack()->packet_ids(); const std::vector<uint16_t>& nacks = rtcp_parser.nack()->packet_ids();
EXPECT_TRUE(std::find(nacks.begin(), nacks.end(), EXPECT_THAT(nacks, Not(Contains(ulpfec_sequence_number_)))
ulpfec_sequence_number_) == nacks.end())
<< "Got nack for ULPFEC packet"; << "Got nack for ULPFEC packet";
if (!nacks.empty() && if (!nacks.empty() &&
IsNewerSequenceNumber(nacks.back(), ulpfec_sequence_number_)) { IsNewerSequenceNumber(nacks.back(), ulpfec_sequence_number_)) {

View File

@ -17,8 +17,11 @@
#include "modules/video_coding/codecs/vp8/include/vp8.h" #include "modules/video_coding/codecs/vp8/include/vp8.h"
#include "modules/video_coding/codecs/vp9/include/vp9.h" #include "modules/video_coding/codecs/vp9/include/vp9.h"
#include "test/call_test.h" #include "test/call_test.h"
#include "test/gmock.h"
#include "test/gtest.h" #include "test/gtest.h"
using ::testing::Contains;
namespace webrtc { namespace webrtc {
namespace { namespace {
constexpr int kWidth = 1280; constexpr int kWidth = 1280;
@ -98,9 +101,7 @@ class FrameObserver : public test::RtpRtcpObserver,
// Verifies that all sent frames are decoded and rendered. // Verifies that all sent frames are decoded and rendered.
void OnFrame(const VideoFrame& rendered_frame) override { void OnFrame(const VideoFrame& rendered_frame) override {
rtc::CritScope lock(&crit_); rtc::CritScope lock(&crit_);
EXPECT_NE(std::find(sent_timestamps_.begin(), sent_timestamps_.end(), EXPECT_THAT(sent_timestamps_, Contains(rendered_frame.timestamp()));
rendered_frame.timestamp()),
sent_timestamps_.end());
// Remove old timestamps too, only the newest decoded frame is rendered. // Remove old timestamps too, only the newest decoded frame is rendered.
num_rendered_frames_ += num_rendered_frames_ +=

View File

@ -8,6 +8,7 @@
* 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 "absl/algorithm/container.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "api/test/simulated_network.h" #include "api/test/simulated_network.h"
#include "api/test/video/function_video_encoder_factory.h" #include "api/test/video/function_video_encoder_factory.h"
@ -370,8 +371,8 @@ void RetransmissionEndToEndTest::DecodesRetransmittedFrame(bool enable_rtx,
// This should be the only dropped packet. // This should be the only dropped packet.
EXPECT_EQ(0u, retransmitted_timestamp_); EXPECT_EQ(0u, retransmitted_timestamp_);
retransmitted_timestamp_ = header.timestamp; retransmitted_timestamp_ = header.timestamp;
if (std::find(rendered_timestamps_.begin(), rendered_timestamps_.end(), if (absl::c_linear_search(rendered_timestamps_,
retransmitted_timestamp_) != rendered_timestamps_.end()) { retransmitted_timestamp_)) {
// Frame was rendered before last packet was scheduled for sending. // Frame was rendered before last packet was scheduled for sending.
// This is extremly rare but possible scenario because prober able to // This is extremly rare but possible scenario because prober able to
// resend packet before it was send. // resend packet before it was send.

View File

@ -8,6 +8,7 @@
* 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 "absl/algorithm/container.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "api/test/simulated_network.h" #include "api/test/simulated_network.h"
#include "api/test/video/function_video_encoder_factory.h" #include "api/test/video/function_video_encoder_factory.h"
@ -628,8 +629,7 @@ TEST_F(StatsEndToEndTest, VerifyNackStats) {
test::RtcpPacketParser rtcp_parser; test::RtcpPacketParser rtcp_parser;
rtcp_parser.Parse(packet, length); rtcp_parser.Parse(packet, length);
const std::vector<uint16_t>& nacks = rtcp_parser.nack()->packet_ids(); const std::vector<uint16_t>& nacks = rtcp_parser.nack()->packet_ids();
if (!nacks.empty() && std::find(nacks.begin(), nacks.end(), if (!nacks.empty() && absl::c_linear_search(nacks, dropped_rtp_packet_)) {
dropped_rtp_packet_) != nacks.end()) {
dropped_rtp_packet_requested_ = true; dropped_rtp_packet_requested_ = true;
} }
return SEND_PACKET; return SEND_PACKET;

View File

@ -10,10 +10,10 @@
#include "video/rtp_video_stream_receiver.h" #include "video/rtp_video_stream_receiver.h"
#include <algorithm>
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "media/base/media_constants.h" #include "media/base/media_constants.h"
#include "modules/pacing/packet_router.h" #include "modules/pacing/packet_router.h"
@ -468,15 +468,14 @@ absl::optional<int64_t> RtpVideoStreamReceiver::LastReceivedKeyframePacketMs()
void RtpVideoStreamReceiver::AddSecondarySink(RtpPacketSinkInterface* sink) { void RtpVideoStreamReceiver::AddSecondarySink(RtpPacketSinkInterface* sink) {
RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_task_checker_); RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_task_checker_);
RTC_DCHECK(std::find(secondary_sinks_.cbegin(), secondary_sinks_.cend(), RTC_DCHECK(!absl::c_linear_search(secondary_sinks_, sink));
sink) == secondary_sinks_.cend());
secondary_sinks_.push_back(sink); secondary_sinks_.push_back(sink);
} }
void RtpVideoStreamReceiver::RemoveSecondarySink( void RtpVideoStreamReceiver::RemoveSecondarySink(
const RtpPacketSinkInterface* sink) { const RtpPacketSinkInterface* sink) {
RTC_DCHECK_CALLED_SEQUENTIALLY(&worker_task_checker_); 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()) { if (it == secondary_sinks_.end()) {
// We might be rolling-back a call whose setup failed mid-way. In such a // 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 // case, it's simpler to remove "everything" rather than remember what

View File

@ -15,6 +15,7 @@
#include <limits> #include <limits>
#include <utility> #include <utility>
#include "absl/algorithm/container.h"
#include "modules/video_coding/include/video_codec_interface.h" #include "modules/video_coding/include/video_codec_interface.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
@ -749,13 +750,10 @@ VideoSendStream::StreamStats* SendStatisticsProxy::GetStatsEntry(
if (it != stats_.substreams.end()) if (it != stats_.substreams.end())
return &it->second; return &it->second;
bool is_media = std::find(rtp_config_.ssrcs.begin(), rtp_config_.ssrcs.end(), bool is_media = absl::c_linear_search(rtp_config_.ssrcs, ssrc);
ssrc) != rtp_config_.ssrcs.end();
bool is_flexfec = rtp_config_.flexfec.payload_type != -1 && bool is_flexfec = rtp_config_.flexfec.payload_type != -1 &&
ssrc == rtp_config_.flexfec.ssrc; ssrc == rtp_config_.flexfec.ssrc;
bool is_rtx = bool is_rtx = absl::c_linear_search(rtp_config_.rtx.ssrcs, ssrc);
std::find(rtp_config_.rtx.ssrcs.begin(), rtp_config_.rtx.ssrcs.end(),
ssrc) != rtp_config_.rtx.ssrcs.end();
if (!is_media && !is_flexfec && !is_rtx) if (!is_media && !is_flexfec && !is_rtx)
return nullptr; return nullptr;

View File

@ -10,11 +10,13 @@
#include "video/send_statistics_proxy.h" #include "video/send_statistics_proxy.h"
#include <algorithm>
#include <map> #include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
#include "absl/algorithm/container.h"
#include "system_wrappers/include/metrics.h" #include "system_wrappers/include/metrics.h"
#include "test/field_trial.h" #include "test/field_trial.h"
#include "test/gtest.h" #include "test/gtest.h"
@ -1685,10 +1687,8 @@ TEST_F(SendStatisticsProxyTest, GetStatsReportsTargetMediaBitrate) {
TEST_F(SendStatisticsProxyTest, NoSubstreams) { TEST_F(SendStatisticsProxyTest, NoSubstreams) {
uint32_t excluded_ssrc = uint32_t excluded_ssrc =
std::max( std::max(*absl::c_max_element(config_.rtp.ssrcs),
*std::max_element(config_.rtp.ssrcs.begin(), config_.rtp.ssrcs.end()), *absl::c_max_element(config_.rtp.rtx.ssrcs)) +
*std::max_element(config_.rtp.rtx.ssrcs.begin(),
config_.rtp.rtx.ssrcs.end())) +
1; 1;
// From RtcpStatisticsCallback. // From RtcpStatisticsCallback.
RtcpStatistics rtcp_stats; RtcpStatistics rtcp_stats;

View File

@ -12,6 +12,7 @@
#include <algorithm> #include <algorithm>
#include <utility> #include <utility>
#include "absl/algorithm/container.h"
#include "common_video/libyuv/include/webrtc_libyuv.h" #include "common_video/libyuv/include/webrtc_libyuv.h"
#include "modules/rtp_rtcp/source/rtp_format.h" #include "modules/rtp_rtcp/source/rtp_format.h"
#include "modules/rtp_rtcp/source/rtp_utility.h" #include "modules/rtp_rtcp/source/rtp_utility.h"
@ -738,10 +739,9 @@ void VideoAnalyzer::PrintResult(const char* result_type,
void VideoAnalyzer::PrintSamplesToFile() { void VideoAnalyzer::PrintSamplesToFile() {
FILE* out = graph_data_output_file_; FILE* out = graph_data_output_file_;
rtc::CritScope crit(&comparison_lock_); rtc::CritScope crit(&comparison_lock_);
std::sort(samples_.begin(), samples_.end(), absl::c_sort(samples_, [](const Sample& A, const Sample& B) -> bool {
[](const Sample& A, const Sample& B) -> bool { return A.input_time_ms < B.input_time_ms;
return A.input_time_ms < B.input_time_ms; });
});
fprintf(out, "%s\n", graph_title_.c_str()); fprintf(out, "%s\n", graph_title_.c_str());
fprintf(out, "%" PRIuS "\n", samples_.size()); fprintf(out, "%" PRIuS "\n", samples_.size());

View File

@ -17,6 +17,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "absl/types/optional.h" #include "absl/types/optional.h"
#include "api/array_view.h" #include "api/array_view.h"
@ -351,8 +352,7 @@ void VideoReceiveStream::Start() {
field_trial::FindFullName("WebRTC-DecoderDataDumpDirectory"); field_trial::FindFullName("WebRTC-DecoderDataDumpDirectory");
// Because '/' can't be used inside a field trial parameter, we use ':' // Because '/' can't be used inside a field trial parameter, we use ':'
// instead. // instead.
std::replace(decoded_output_file.begin(), decoded_output_file.end(), ':', absl::c_replace(decoded_output_file, ':', '/');
'/');
if (!decoded_output_file.empty()) { if (!decoded_output_file.empty()) {
char filename_buffer[256]; char filename_buffer[256];
rtc::SimpleStringBuilder ssb(filename_buffer); rtc::SimpleStringBuilder ssb(filename_buffer);

View File

@ -15,6 +15,7 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "absl/algorithm/container.h"
#include "api/crypto/crypto_options.h" #include "api/crypto/crypto_options.h"
#include "api/rtp_parameters.h" #include "api/rtp_parameters.h"
#include "api/scoped_refptr.h" #include "api/scoped_refptr.h"
@ -48,10 +49,9 @@ constexpr TimeDelta kEncoderTimeOut = TimeDelta::Seconds<2>();
bool TransportSeqNumExtensionConfigured(const VideoSendStream::Config& config) { bool TransportSeqNumExtensionConfigured(const VideoSendStream::Config& config) {
const std::vector<RtpExtension>& extensions = config.rtp.extensions; const std::vector<RtpExtension>& extensions = config.rtp.extensions;
return std::find_if( return absl::c_any_of(extensions, [](const RtpExtension& ext) {
extensions.begin(), extensions.end(), [](const RtpExtension& ext) { return ext.uri == RtpExtension::kTransportSequenceNumberUri;
return ext.uri == RtpExtension::kTransportSequenceNumberUri; });
}) != extensions.end();
} }
const char kForcedFallbackFieldTrial[] = const char kForcedFallbackFieldTrial[] =
@ -320,12 +320,10 @@ VideoSendStreamImpl::VideoSendStreamImpl(
// side doesn't support the rotation extension. This allows us to prepare the // 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 // encoder in the expectation that rotation is supported - which is the common
// case. // case.
bool rotation_applied = bool rotation_applied = absl::c_none_of(
std::find_if(config_->rtp.extensions.begin(), config_->rtp.extensions, [](const RtpExtension& extension) {
config_->rtp.extensions.end(), return extension.uri == RtpExtension::kVideoRotationUri;
[](const RtpExtension& extension) { });
return extension.uri == RtpExtension::kVideoRotationUri;
}) == config_->rtp.extensions.end();
video_stream_encoder_->SetSink(this, rotation_applied); video_stream_encoder_->SetSink(this, rotation_applied);
} }

View File

@ -11,6 +11,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "api/task_queue/default_task_queue_factory.h" #include "api/task_queue/default_task_queue_factory.h"
#include "api/test/simulated_network.h" #include "api/test/simulated_network.h"
@ -935,8 +936,7 @@ void VideoSendStreamTest::TestNackRetransmission(
sequence_number = (rtx_header[0] << 8) + rtx_header[1]; sequence_number = (rtx_header[0] << 8) + rtx_header[1];
} }
auto found = std::find(nacked_sequence_numbers_.begin(), auto found = absl::c_find(nacked_sequence_numbers_, sequence_number);
nacked_sequence_numbers_.end(), sequence_number);
if (found != nacked_sequence_numbers_.end()) { if (found != nacked_sequence_numbers_.end()) {
nacked_sequence_numbers_.erase(found); nacked_sequence_numbers_.erase(found);

View File

@ -15,6 +15,7 @@
#include <numeric> #include <numeric>
#include <utility> #include <utility>
#include "absl/algorithm/container.h"
#include "absl/memory/memory.h" #include "absl/memory/memory.h"
#include "api/video/encoded_image.h" #include "api/video/encoded_image.h"
#include "api/video/i420_buffer.h" #include "api/video/i420_buffer.h"
@ -642,9 +643,8 @@ void VideoStreamEncoder::ReconfigureEncoder() {
// Stream dimensions may be not equal to given because of a simulcast // Stream dimensions may be not equal to given because of a simulcast
// restrictions. // restrictions.
auto highest_stream = std::max_element( auto highest_stream = absl::c_max_element(
streams.begin(), streams.end(), streams, [](const webrtc::VideoStream& a, const webrtc::VideoStream& b) {
[](const webrtc::VideoStream& a, const webrtc::VideoStream& b) {
return std::tie(a.width, a.height) < std::tie(b.width, b.height); return std::tie(a.width, a.height) < std::tie(b.width, b.height);
}); });
int highest_stream_width = static_cast<int>(highest_stream->width); int highest_stream_width = static_cast<int>(highest_stream->width);
@ -1898,7 +1898,7 @@ void VideoStreamEncoder::AdaptCounter::DecrementFramerate(int reason,
DecrementFramerate(reason); DecrementFramerate(reason);
// Reset if at max fps (i.e. in case of fewer steps up than down). // Reset if at max fps (i.e. in case of fewer steps up than down).
if (cur_fps == std::numeric_limits<int>::max()) 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 { int VideoStreamEncoder::AdaptCounter::FramerateCount() const {
@ -1923,7 +1923,7 @@ int VideoStreamEncoder::AdaptCounter::TotalCount(int reason) const {
int VideoStreamEncoder::AdaptCounter::Count( int VideoStreamEncoder::AdaptCounter::Count(
const std::vector<int>& counters) const { 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, void VideoStreamEncoder::AdaptCounter::MoveCount(std::vector<int>* counters,