From 2cb7b5ebefa6337ea7e57b8da0b20c7092f72133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=B6ller?= Date: Thu, 19 Apr 2018 10:02:26 +0200 Subject: [PATCH] Convert BitrateAdjuster from webrtc::Clock to rtc::TimeMillis. We can then also drop the system_wrappers dependency from the common_video build target. Bug: webrtc:6733 Change-Id: I501113d100322d1ebc51b2286970697a24b70a43 Reviewed-on: https://webrtc-review.googlesource.com/70381 Commit-Queue: Niels Moller Reviewed-by: Magnus Jedvert Cr-Commit-Position: refs/heads/master@{#22934} --- common_video/BUILD.gn | 3 +-- common_video/bitrate_adjuster.cc | 12 +++++------- common_video/bitrate_adjuster_unittest.cc | 9 ++++----- common_video/include/bitrate_adjuster.h | 12 +++++++++--- sdk/BUILD.gn | 1 - .../Classes/VideoToolbox/RTCVideoEncoderH264.mm | 4 +--- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/common_video/BUILD.gn b/common_video/BUILD.gn index bd4c5f7503..3bbbde92d2 100644 --- a/common_video/BUILD.gn +++ b/common_video/BUILD.gn @@ -66,7 +66,6 @@ rtc_static_library("common_video") { "../rtc_base:rtc_base", "../rtc_base:rtc_task_queue", "../rtc_base:safe_minmax", - "../system_wrappers", "//third_party/libyuv", ] } @@ -114,7 +113,7 @@ if (rtc_include_tests) { "../modules/video_capture:video_capture", "../rtc_base:rtc_base", "../rtc_base:rtc_base_approved", - "../system_wrappers:system_wrappers", + "../rtc_base:rtc_base_tests_utils", "../test:fileutils", "../test:test_main", "../test:video_test_common", diff --git a/common_video/bitrate_adjuster.cc b/common_video/bitrate_adjuster.cc index 0d3458c6c8..3bb06944f2 100644 --- a/common_video/bitrate_adjuster.cc +++ b/common_video/bitrate_adjuster.cc @@ -15,7 +15,7 @@ #include "rtc_base/checks.h" #include "rtc_base/logging.h" -#include "system_wrappers/include/clock.h" +#include "rtc_base/timeutils.h" namespace webrtc { @@ -30,11 +30,9 @@ const float BitrateAdjuster::kBitrateTolerancePct = .1f; const float BitrateAdjuster::kBytesPerMsToBitsPerSecond = 8 * 1000; -BitrateAdjuster::BitrateAdjuster(Clock* clock, - float min_adjusted_bitrate_pct, +BitrateAdjuster::BitrateAdjuster(float min_adjusted_bitrate_pct, float max_adjusted_bitrate_pct) - : clock_(clock), - min_adjusted_bitrate_pct_(min_adjusted_bitrate_pct), + : min_adjusted_bitrate_pct_(min_adjusted_bitrate_pct), max_adjusted_bitrate_pct_(max_adjusted_bitrate_pct), bitrate_tracker_(1.5 * kBitrateUpdateIntervalMs, kBytesPerMsToBitsPerSecond) { @@ -72,12 +70,12 @@ uint32_t BitrateAdjuster::GetAdjustedBitrateBps() const { rtc::Optional BitrateAdjuster::GetEstimatedBitrateBps() { rtc::CritScope cs(&crit_); - return bitrate_tracker_.Rate(clock_->TimeInMilliseconds()); + return bitrate_tracker_.Rate(rtc::TimeMillis()); } void BitrateAdjuster::Update(size_t frame_size) { rtc::CritScope cs(&crit_); - uint32_t current_time_ms = clock_->TimeInMilliseconds(); + uint32_t current_time_ms = rtc::TimeMillis(); bitrate_tracker_.Update(frame_size, current_time_ms); UpdateBitrate(current_time_ms); } diff --git a/common_video/bitrate_adjuster_unittest.cc b/common_video/bitrate_adjuster_unittest.cc index b75f184cf2..b0b8f6da4a 100644 --- a/common_video/bitrate_adjuster_unittest.cc +++ b/common_video/bitrate_adjuster_unittest.cc @@ -9,7 +9,7 @@ */ #include "common_video/include/bitrate_adjuster.h" -#include "system_wrappers/include/clock.h" +#include "rtc_base/fakeclock.h" #include "test/gtest.h" namespace webrtc { @@ -17,8 +17,7 @@ namespace webrtc { class BitrateAdjusterTest : public ::testing::Test { public: BitrateAdjusterTest() - : clock_(0), - adjuster_(&clock_, kMinAdjustedBitratePct, kMaxAdjustedBitratePct) {} + : adjuster_(kMinAdjustedBitratePct, kMaxAdjustedBitratePct) {} // Simulate an output bitrate for one update cycle of BitrateAdjuster. void SimulateBitrateBps(uint32_t bitrate_bps) { @@ -33,7 +32,7 @@ class BitrateAdjusterTest : public ::testing::Test { const size_t frame_size_bytes = (bitrate_bps * frame_interval_ms) / (8 * 1000); for (size_t i = 0; i < update_frame_interval; ++i) { - clock_.AdvanceTimeMilliseconds(frame_interval_ms); + clock_.AdvanceTime(rtc::TimeDelta::FromMilliseconds(frame_interval_ms)); adjuster_.Update(frame_size_bytes); } } @@ -63,7 +62,7 @@ class BitrateAdjusterTest : public ::testing::Test { protected: static const float kMinAdjustedBitratePct; static const float kMaxAdjustedBitratePct; - SimulatedClock clock_; + rtc::ScopedFakeClock clock_; BitrateAdjuster adjuster_; }; diff --git a/common_video/include/bitrate_adjuster.h b/common_video/include/bitrate_adjuster.h index fd83555469..0567365621 100644 --- a/common_video/include/bitrate_adjuster.h +++ b/common_video/include/bitrate_adjuster.h @@ -18,6 +18,8 @@ namespace webrtc { +// TODO(nisse): Delete, together with the corresponding deprecated +// constructor. class Clock; // Certain hardware encoders tend to consistently overshoot the bitrate that @@ -28,9 +30,14 @@ class BitrateAdjuster { // min_adjusted_bitrate_pct and max_adjusted_bitrate_pct are the lower and // upper bound outputted adjusted bitrates as a percentage of the target // bitrate. - BitrateAdjuster(Clock* clock, - float min_adjusted_bitrate_pct, + BitrateAdjuster(float min_adjusted_bitrate_pct, float max_adjusted_bitrate_pct); + // TODO(bugs.webrtc.org/6733): Deprecated, only for compatibility + // with old code. Delete as soon as all users are updated. + BitrateAdjuster(Clock*, + float min_adjusted_bitrate_pct, + float max_adjusted_bitrate_pct) + : BitrateAdjuster(min_adjusted_bitrate_pct, max_adjusted_bitrate_pct) {} virtual ~BitrateAdjuster() {} static const uint32_t kBitrateUpdateIntervalMs; @@ -68,7 +75,6 @@ class BitrateAdjuster { RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); rtc::CriticalSection crit_; - Clock* const clock_; const float min_adjusted_bitrate_pct_; const float max_adjusted_bitrate_pct_; // The bitrate we want. diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 3e7f28d7b9..62e42861e3 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -1093,7 +1093,6 @@ if (is_ios || is_mac) { "../modules/video_coding:video_coding_utility", "../rtc_base:checks", "../rtc_base:rtc_base_approved", - "../system_wrappers", "//third_party/libyuv", ] diff --git a/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm b/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm index a0b6d78179..3289f0187a 100644 --- a/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm +++ b/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm @@ -32,7 +32,6 @@ #include "rtc_base/logging.h" #include "rtc_base/timeutils.h" #include "sdk/objc/Framework/Classes/VideoToolbox/nalu_rewriter.h" -#include "system_wrappers/include/clock.h" #include "third_party/libyuv/include/libyuv/convert_from.h" @interface RTCVideoEncoderH264 () @@ -302,8 +301,7 @@ CFStringRef ExtractProfile(webrtc::SdpVideoFormat videoFormat) { - (instancetype)initWithCodecInfo:(RTCVideoCodecInfo *)codecInfo { if (self = [super init]) { _codecInfo = codecInfo; - _bitrateAdjuster.reset(new webrtc::BitrateAdjuster( - webrtc::Clock::GetRealTimeClock(), .5, .95)); + _bitrateAdjuster.reset(new webrtc::BitrateAdjuster(.5, .95)); _packetizationMode = RTCH264PacketizationModeNonInterleaved; _profile = ExtractProfile([codecInfo nativeSdpVideoFormat]); RTC_LOG(LS_INFO) << "Using profile " << CFStringToString(_profile);