Replacing Clock in ScreenshareLayers.

there's no easy way to inject the Clock in ScreenshareLayers under
normal use. To allow faking the clock, rtc::TimeMillis is used instead.

Bug: webrtc:10365
Change-Id: I46c7f76514672190a0f0f5816a2c858bc6c76fa4
Reviewed-on: https://webrtc-review.googlesource.com/c/125189
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26946}
This commit is contained in:
Sebastian Jansson 2019-03-01 18:04:07 +01:00 committed by Commit Bot
parent c130d42aab
commit e64a688167
4 changed files with 18 additions and 24 deletions

View File

@ -13,7 +13,6 @@
#include "api/video_codecs/vp8_temporal_layers.h" #include "api/video_codecs/vp8_temporal_layers.h"
#include "modules/video_coding/codecs/vp8/default_temporal_layers.h" #include "modules/video_coding/codecs/vp8/default_temporal_layers.h"
#include "modules/video_coding/codecs/vp8/screenshare_layers.h" #include "modules/video_coding/codecs/vp8/screenshare_layers.h"
#include "system_wrappers/include/clock.h"
namespace webrtc { namespace webrtc {
@ -25,8 +24,7 @@ std::unique_ptr<Vp8TemporalLayers> CreateVp8TemporalLayers(
return absl::make_unique<DefaultTemporalLayers>(num_temporal_layers); return absl::make_unique<DefaultTemporalLayers>(num_temporal_layers);
case Vp8TemporalLayersType::kBitrateDynamic: case Vp8TemporalLayersType::kBitrateDynamic:
// Conference mode temporal layering for screen content in base stream. // Conference mode temporal layering for screen content in base stream.
return absl::make_unique<ScreenshareLayers>(num_temporal_layers, return absl::make_unique<ScreenshareLayers>(num_temporal_layers);
Clock::GetRealTimeClock());
} }
} }

View File

@ -18,7 +18,7 @@
#include "rtc_base/arraysize.h" #include "rtc_base/arraysize.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "system_wrappers/include/clock.h" #include "rtc_base/time_utils.h"
#include "system_wrappers/include/metrics.h" #include "system_wrappers/include/metrics.h"
namespace webrtc { namespace webrtc {
@ -48,9 +48,8 @@ constexpr int ScreenshareLayers::kMaxNumTemporalLayers;
// been exceeded. This prevents needless keyframe requests. // been exceeded. This prevents needless keyframe requests.
const int ScreenshareLayers::kMaxFrameIntervalMs = 2750; const int ScreenshareLayers::kMaxFrameIntervalMs = 2750;
ScreenshareLayers::ScreenshareLayers(int num_temporal_layers, Clock* clock) ScreenshareLayers::ScreenshareLayers(int num_temporal_layers)
: clock_(clock), : number_of_temporal_layers_(
number_of_temporal_layers_(
std::min(kMaxNumTemporalLayers, num_temporal_layers)), std::min(kMaxNumTemporalLayers, num_temporal_layers)),
active_layer_(-1), active_layer_(-1),
last_timestamp_(-1), last_timestamp_(-1),
@ -94,7 +93,7 @@ Vp8FrameConfig ScreenshareLayers::UpdateLayerConfig(uint32_t timestamp) {
return tl_config; return tl_config;
} }
const int64_t now_ms = clock_->TimeInMilliseconds(); const int64_t now_ms = rtc::TimeMillis();
int64_t unwrapped_timestamp = time_wrap_handler_.Unwrap(timestamp); int64_t unwrapped_timestamp = time_wrap_handler_.Unwrap(timestamp);
int64_t ts_diff; int64_t ts_diff;
@ -326,7 +325,7 @@ void ScreenshareLayers::OnEncodeDone(uint32_t rtp_timestamp,
} }
} }
encode_framerate_.Update(1, clock_->TimeInMilliseconds()); encode_framerate_.Update(1, rtc::TimeMillis());
if (number_of_temporal_layers_ == 1) if (number_of_temporal_layers_ == 1)
return; return;
@ -496,7 +495,7 @@ void ScreenshareLayers::UpdateHistograms() {
if (stats_.first_frame_time_ms_ == -1) if (stats_.first_frame_time_ms_ == -1)
return; return;
int64_t duration_sec = int64_t duration_sec =
(clock_->TimeInMilliseconds() - stats_.first_frame_time_ms_ + 500) / 1000; (rtc::TimeMillis() - stats_.first_frame_time_ms_ + 500) / 1000;
if (duration_sec >= metrics::kMinRunTimeInSeconds) { if (duration_sec >= metrics::kMinRunTimeInSeconds) {
RTC_HISTOGRAM_COUNTS_10000( RTC_HISTOGRAM_COUNTS_10000(
"WebRTC.Video.Screenshare.Layer0.FrameRate", "WebRTC.Video.Screenshare.Layer0.FrameRate",

View File

@ -31,8 +31,7 @@ class ScreenshareLayers : public Vp8TemporalLayers {
static const double kAcceptableTargetOvershoot; static const double kAcceptableTargetOvershoot;
static const int kMaxFrameIntervalMs; static const int kMaxFrameIntervalMs;
ScreenshareLayers(int num_temporal_layers, explicit ScreenshareLayers(int num_temporal_layers);
Clock* clock);
~ScreenshareLayers() override; ~ScreenshareLayers() override;
bool SupportsEncoderFrameDropping() const override; bool SupportsEncoderFrameDropping() const override;
@ -61,8 +60,6 @@ class ScreenshareLayers : public Vp8TemporalLayers {
bool TimeToSync(int64_t timestamp) const; bool TimeToSync(int64_t timestamp) const;
uint32_t GetCodecTargetBitrateKbps() const; uint32_t GetCodecTargetBitrateKbps() const;
Clock* const clock_;
int number_of_temporal_layers_; int number_of_temporal_layers_;
int active_layer_; int active_layer_;
int64_t last_timestamp_; int64_t last_timestamp_;

View File

@ -21,7 +21,7 @@
#include "modules/video_coding/codecs/vp8/screenshare_layers.h" #include "modules/video_coding/codecs/vp8/screenshare_layers.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 "system_wrappers/include/clock.h" #include "rtc_base/fake_clock.h"
#include "system_wrappers/include/metrics.h" #include "system_wrappers/include/metrics.h"
#include "test/gmock.h" #include "test/gmock.h"
#include "test/gtest.h" #include "test/gtest.h"
@ -62,13 +62,12 @@ class ScreenshareLayerTest : public ::testing::Test {
: min_qp_(2), : min_qp_(2),
max_qp_(kDefaultQp), max_qp_(kDefaultQp),
frame_size_(-1), frame_size_(-1),
clock_(1),
timestamp_(90), timestamp_(90),
config_updated_(false) {} config_updated_(false) {}
virtual ~ScreenshareLayerTest() {} virtual ~ScreenshareLayerTest() {}
void SetUp() override { void SetUp() override {
layers_.reset(new ScreenshareLayers(2, &clock_)); layers_.reset(new ScreenshareLayers(2));
cfg_ = ConfigureBitrates(); cfg_ = ConfigureBitrates();
} }
@ -103,7 +102,7 @@ class ScreenshareLayerTest : public ::testing::Test {
Vp8FrameConfig UpdateLayerConfig(uint32_t timestamp) { Vp8FrameConfig UpdateLayerConfig(uint32_t timestamp) {
int64_t timestamp_ms = timestamp / 90; int64_t timestamp_ms = timestamp / 90;
clock_.AdvanceTimeMilliseconds(timestamp_ms - clock_.TimeInMilliseconds()); clock_.AdvanceTime(TimeDelta::ms(timestamp_ms - rtc::TimeMillis()));
return layers_->UpdateLayerConfig(timestamp); return layers_->UpdateLayerConfig(timestamp);
} }
@ -181,7 +180,7 @@ class ScreenshareLayerTest : public ::testing::Test {
int min_qp_; int min_qp_;
uint32_t max_qp_; uint32_t max_qp_;
int frame_size_; int frame_size_;
SimulatedClock clock_; rtc::ScopedFakeClock clock_;
std::unique_ptr<ScreenshareLayers> layers_; std::unique_ptr<ScreenshareLayers> layers_;
uint32_t timestamp_; uint32_t timestamp_;
@ -199,7 +198,7 @@ class ScreenshareLayerTest : public ::testing::Test {
}; };
TEST_F(ScreenshareLayerTest, 1Layer) { TEST_F(ScreenshareLayerTest, 1Layer) {
layers_.reset(new ScreenshareLayers(1, &clock_)); layers_.reset(new ScreenshareLayers(1));
ConfigureBitrates(); ConfigureBitrates();
// One layer screenshare should not use the frame dropper as all frames will // One layer screenshare should not use the frame dropper as all frames will
// belong to the base layer. // belong to the base layer.
@ -554,7 +553,7 @@ TEST_F(ScreenshareLayerTest, UpdatesHistograms) {
} else { } else {
RTC_NOTREACHED() << "Unexpected flags"; RTC_NOTREACHED() << "Unexpected flags";
} }
clock_.AdvanceTimeMilliseconds(1000 / 5); clock_.AdvanceTime(TimeDelta::ms(1000 / 5));
} }
EXPECT_TRUE(overshoot); EXPECT_TRUE(overshoot);
@ -594,7 +593,7 @@ TEST_F(ScreenshareLayerTest, UpdatesHistograms) {
} }
TEST_F(ScreenshareLayerTest, AllowsUpdateConfigBeforeSetRates) { TEST_F(ScreenshareLayerTest, AllowsUpdateConfigBeforeSetRates) {
layers_.reset(new ScreenshareLayers(2, &clock_)); layers_.reset(new ScreenshareLayers(2));
// New layer instance, OnRatesUpdated() never called. // New layer instance, OnRatesUpdated() never called.
// UpdateConfiguration() call should not cause crash. // UpdateConfiguration() call should not cause crash.
layers_->UpdateConfiguration(&cfg_); layers_->UpdateConfiguration(&cfg_);
@ -618,7 +617,8 @@ TEST_F(ScreenshareLayerTest, RespectsConfiguredFramerate) {
IgnoredCodecSpecificInfoVp8()); IgnoredCodecSpecificInfoVp8());
} }
timestamp += kFrameIntervalsMs * 90; timestamp += kFrameIntervalsMs * 90;
clock_.AdvanceTimeMilliseconds(kFrameIntervalsMs); clock_.AdvanceTime(TimeDelta::ms(kFrameIntervalsMs));
++num_input_frames; ++num_input_frames;
} }
EXPECT_EQ(0, num_discarded_frames); EXPECT_EQ(0, num_discarded_frames);
@ -635,7 +635,7 @@ TEST_F(ScreenshareLayerTest, RespectsConfiguredFramerate) {
IgnoredCodecSpecificInfoVp8()); IgnoredCodecSpecificInfoVp8());
} }
timestamp += kFrameIntervalsMs * 90 / 2; timestamp += kFrameIntervalsMs * 90 / 2;
clock_.AdvanceTimeMilliseconds(kFrameIntervalsMs / 2); clock_.AdvanceTime(TimeDelta::ms(kFrameIntervalsMs));
++num_input_frames; ++num_input_frames;
} }