Index: webrtc/video/vie_encoder_unittest.cc |
diff --git a/webrtc/video/vie_encoder_unittest.cc b/webrtc/video/vie_encoder_unittest.cc |
index 4d72a826f2241b22ff4d919877c2ef28bcbc0797..7a54fbe925f2fe75fe277b1d0cf4d6781ca29532 100644 |
--- a/webrtc/video/vie_encoder_unittest.cc |
+++ b/webrtc/video/vie_encoder_unittest.cc |
@@ -218,7 +218,6 @@ |
: video_send_config_(VideoSendStream::Config(nullptr)), |
codec_width_(320), |
codec_height_(240), |
- max_framerate_(30), |
fake_encoder_(), |
stats_proxy_(new MockableSendStatisticsProxy( |
Clock::GetRealTimeClock(), |
@@ -235,17 +234,7 @@ |
VideoEncoderConfig video_encoder_config; |
test::FillEncoderConfiguration(1, &video_encoder_config); |
- video_encoder_config.video_stream_factory = |
- new rtc::RefCountedObject<VideoStreamFactory>(1); |
video_encoder_config_ = video_encoder_config.Copy(); |
- |
- // Framerate limit is specified by the VideoStreamFactory. |
- std::vector<VideoStream> streams = |
- video_encoder_config.video_stream_factory->CreateEncoderStreams( |
- codec_width_, codec_height_, video_encoder_config); |
- max_framerate_ = streams[0].max_framerate; |
- fake_clock_.SetTimeMicros(1234); |
- |
ConfigureEncoder(std::move(video_encoder_config), true /* nack_enabled */); |
} |
@@ -268,8 +257,7 @@ |
void ResetEncoder(const std::string& payload_name, |
size_t num_streams, |
size_t num_temporal_layers, |
- bool nack_enabled, |
- bool screenshare) { |
+ bool nack_enabled) { |
video_send_config_.encoder_settings.payload_name = payload_name; |
VideoEncoderConfig video_encoder_config; |
@@ -277,9 +265,6 @@ |
video_encoder_config.max_bitrate_bps = kTargetBitrateBps; |
video_encoder_config.video_stream_factory = |
new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers); |
- video_encoder_config.content_type = |
- screenshare ? VideoEncoderConfig::ContentType::kScreen |
- : VideoEncoderConfig::ContentType::kRealtimeVideo; |
ConfigureEncoder(std::move(video_encoder_config), nack_enabled); |
} |
@@ -337,33 +322,6 @@ |
EXPECT_LT(wants.max_framerate_fps, fps); |
EXPECT_EQ(std::numeric_limits<int>::max(), wants.max_pixel_count); |
EXPECT_FALSE(wants.target_pixel_count); |
- } |
- |
- void WaitForEncodedFrame(int64_t expected_ntp_time) { |
- sink_.WaitForEncodedFrame(expected_ntp_time); |
- fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
- } |
- |
- bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, int64_t timeout_ms) { |
- bool ok = sink_.TimedWaitForEncodedFrame(expected_ntp_time, timeout_ms); |
- fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
- return ok; |
- } |
- |
- void WaitForEncodedFrame(uint32_t expected_width, uint32_t expected_height) { |
- sink_.WaitForEncodedFrame(expected_width, expected_height); |
- fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
- } |
- |
- void ExpectDroppedFrame() { |
- sink_.ExpectDroppedFrame(); |
- fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
- } |
- |
- bool WaitForFrame(int64_t timeout_ms) { |
- bool ok = sink_.WaitForFrame(timeout_ms); |
- fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerSec / max_framerate_); |
- return ok; |
} |
class TestEncoder : public test::FakeEncoder { |
@@ -474,21 +432,13 @@ |
: test_encoder_(test_encoder), encoded_frame_event_(false, false) {} |
void WaitForEncodedFrame(int64_t expected_ntp_time) { |
- EXPECT_TRUE( |
- TimedWaitForEncodedFrame(expected_ntp_time, kDefaultTimeoutMs)); |
- } |
- |
- bool TimedWaitForEncodedFrame(int64_t expected_ntp_time, |
- int64_t timeout_ms) { |
uint32_t timestamp = 0; |
- if (!encoded_frame_event_.Wait(timeout_ms)) |
- return false; |
+ EXPECT_TRUE(encoded_frame_event_.Wait(kDefaultTimeoutMs)); |
{ |
rtc::CritScope lock(&crit_); |
timestamp = last_timestamp_; |
} |
test_encoder_->CheckLastTimeStampsMatch(expected_ntp_time, timestamp); |
- return true; |
} |
void WaitForEncodedFrame(uint32_t expected_width, |
@@ -567,20 +517,18 @@ |
VideoEncoderConfig video_encoder_config_; |
int codec_width_; |
int codec_height_; |
- int max_framerate_; |
TestEncoder fake_encoder_; |
std::unique_ptr<MockableSendStatisticsProxy> stats_proxy_; |
TestSink sink_; |
AdaptingFrameForwarder video_source_; |
std::unique_ptr<ViEEncoderUnderTest> vie_encoder_; |
- rtc::ScopedFakeClock fake_clock_; |
}; |
TEST_F(ViEEncoderTest, EncodeOneFrame) { |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
rtc::Event frame_destroyed_event(false, false); |
video_source_.IncomingCapturedFrame(CreateFrame(1, &frame_destroyed_event)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
EXPECT_TRUE(frame_destroyed_event.Wait(kDefaultTimeoutMs)); |
vie_encoder_->Stop(); |
} |
@@ -594,14 +542,14 @@ |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
vie_encoder_->Stop(); |
} |
TEST_F(ViEEncoderTest, DropsFramesWhenRateSetToZero) { |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
vie_encoder_->OnBitrateUpdated(0, 0, 0); |
// Dropped since bitrate is zero. |
@@ -609,20 +557,20 @@ |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); |
- WaitForEncodedFrame(3); |
+ sink_.WaitForEncodedFrame(3); |
vie_encoder_->Stop(); |
} |
TEST_F(ViEEncoderTest, DropsFramesWithSameOrOldNtpTimestamp) { |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
// This frame will be dropped since it has the same ntp timestamp. |
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
vie_encoder_->Stop(); |
} |
@@ -630,7 +578,7 @@ |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
vie_encoder_->Stop(); |
sink_.SetExpectNoFrames(); |
@@ -644,13 +592,13 @@ |
fake_encoder_.BlockNextEncode(); |
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
// Here, the encoder thread will be blocked in the TestEncoder waiting for a |
// call to ContinueEncode. |
video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
video_source_.IncomingCapturedFrame(CreateFrame(3, nullptr)); |
fake_encoder_.ContinueEncode(); |
- WaitForEncodedFrame(3); |
+ sink_.WaitForEncodedFrame(3); |
vie_encoder_->Stop(); |
} |
@@ -661,7 +609,7 @@ |
// Capture a frame and wait for it to synchronize with the encoder thread. |
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
// The encoder will have been configured once when the first frame is |
// received. |
EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
@@ -674,7 +622,7 @@ |
// Capture a frame and wait for it to synchronize with the encoder thread. |
video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
EXPECT_EQ(9999, sink_.last_min_transmit_bitrate()); |
@@ -686,7 +634,7 @@ |
// Capture a frame and wait for it to synchronize with the encoder thread. |
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
// The encoder will have been configured once. |
EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
@@ -697,7 +645,7 @@ |
// Capture a frame with a higher resolution and wait for it to synchronize |
// with the encoder thread. |
video_source_.IncomingCapturedFrame(CreateFrame(2, nullptr)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
EXPECT_EQ(codec_width_, fake_encoder_.codec_config().width); |
EXPECT_EQ(codec_height_, fake_encoder_.codec_config().height); |
EXPECT_EQ(2, sink_.number_of_reconfigurations()); |
@@ -709,12 +657,12 @@ |
const bool kNackEnabled = true; |
const size_t kNumStreams = 1; |
const size_t kNumTl = 1; |
- ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
+ ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
// Capture a frame and wait for it to synchronize with the encoder thread. |
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
// The encoder have been configured once when the first frame is received. |
EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
@@ -729,12 +677,12 @@ |
const bool kNackEnabled = true; |
const size_t kNumStreams = 2; |
const size_t kNumTl = 1; |
- ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
+ ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
// Capture a frame and wait for it to synchronize with the encoder thread. |
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
// The encoder have been configured once when the first frame is received. |
EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
@@ -749,12 +697,12 @@ |
const bool kNackEnabled = false; |
const size_t kNumStreams = 1; |
const size_t kNumTl = 1; |
- ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
+ ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
// Capture a frame and wait for it to synchronize with the encoder thread. |
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
// The encoder have been configured once when the first frame is received. |
EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
@@ -769,12 +717,12 @@ |
const bool kNackEnabled = true; |
const size_t kNumStreams = 1; |
const size_t kNumTl = 2; |
- ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled, false); |
+ ResetEncoder("VP8", kNumStreams, kNumTl, kNackEnabled); |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
// Capture a frame and wait for it to synchronize with the encoder thread. |
video_source_.IncomingCapturedFrame(CreateFrame(1, nullptr)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
// The encoder have been configured once when the first frame is received. |
EXPECT_EQ(1, sink_.number_of_reconfigurations()); |
EXPECT_EQ(kVideoCodecVP8, fake_encoder_.codec_config().codecType); |
@@ -818,7 +766,7 @@ |
for (int i = 1; i <= kMaxDowngrades; ++i) { |
video_source_.IncomingCapturedFrame( |
CreateFrame(i, frame_width, frame_height)); |
- WaitForEncodedFrame(i); |
+ sink_.WaitForEncodedFrame(i); |
vie_encoder_->TriggerCpuOveruse(); |
@@ -837,7 +785,7 @@ |
rtc::VideoSinkWants current_wants = video_source_.sink_wants(); |
video_source_.IncomingCapturedFrame( |
CreateFrame(kMaxDowngrades + 1, frame_width, frame_height)); |
- WaitForEncodedFrame(kMaxDowngrades + 1); |
+ sink_.WaitForEncodedFrame(kMaxDowngrades + 1); |
vie_encoder_->TriggerCpuOveruse(); |
EXPECT_EQ(video_source_.sink_wants().target_pixel_count, |
current_wants.target_pixel_count); |
@@ -872,14 +820,14 @@ |
video_source_.IncomingCapturedFrame( |
CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
- WaitForEncodedFrame(frame_timestamp); |
+ sink_.WaitForEncodedFrame(frame_timestamp); |
frame_timestamp += kFrameIntervalMs; |
// Trigger CPU overuse. |
vie_encoder_->TriggerCpuOveruse(); |
video_source_.IncomingCapturedFrame( |
CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
- WaitForEncodedFrame(frame_timestamp); |
+ sink_.WaitForEncodedFrame(frame_timestamp); |
frame_timestamp += kFrameIntervalMs; |
// Default degradation preference is maintain-framerate, so will lower max |
@@ -909,7 +857,7 @@ |
vie_encoder_->TriggerCpuOveruse(); |
new_video_source.IncomingCapturedFrame( |
CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
- WaitForEncodedFrame(frame_timestamp); |
+ sink_.WaitForEncodedFrame(frame_timestamp); |
frame_timestamp += kFrameIntervalMs; |
// Some framerate constraint should be set. |
@@ -927,7 +875,7 @@ |
vie_encoder_->TriggerCpuOveruse(); |
new_video_source.IncomingCapturedFrame( |
CreateFrame(frame_timestamp, kFrameWidth, kFrameHeight)); |
- WaitForEncodedFrame(frame_timestamp); |
+ sink_.WaitForEncodedFrame(frame_timestamp); |
frame_timestamp += kFrameIntervalMs; |
// Still no degradation. |
@@ -961,7 +909,7 @@ |
const int kWidth = 1280; |
const int kHeight = 720; |
video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.bw_limited_resolution); |
EXPECT_EQ(0, stats.number_of_quality_adapt_changes); |
@@ -969,7 +917,7 @@ |
// Trigger adapt down. |
vie_encoder_->TriggerQualityLow(); |
video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
stats = stats_proxy_->GetStats(); |
EXPECT_TRUE(stats.bw_limited_resolution); |
@@ -978,7 +926,7 @@ |
// Trigger adapt up. |
vie_encoder_->TriggerQualityHigh(); |
video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
- WaitForEncodedFrame(3); |
+ sink_.WaitForEncodedFrame(3); |
stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.bw_limited_resolution); |
@@ -994,7 +942,7 @@ |
const int kWidth = 1280; |
const int kHeight = 720; |
video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.cpu_limited_resolution); |
EXPECT_EQ(0, stats.number_of_cpu_adapt_changes); |
@@ -1002,7 +950,7 @@ |
// Trigger CPU overuse. |
vie_encoder_->TriggerCpuOveruse(); |
video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
stats = stats_proxy_->GetStats(); |
EXPECT_TRUE(stats.cpu_limited_resolution); |
@@ -1011,7 +959,7 @@ |
// Trigger CPU normal use. |
vie_encoder_->TriggerCpuNormalUsage(); |
video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
- WaitForEncodedFrame(3); |
+ sink_.WaitForEncodedFrame(3); |
stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.cpu_limited_resolution); |
@@ -1027,7 +975,7 @@ |
const int kWidth = 1280; |
const int kHeight = 720; |
video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.bw_limited_resolution); |
EXPECT_FALSE(stats.cpu_limited_resolution); |
@@ -1036,7 +984,7 @@ |
// Trigger CPU overuse. |
vie_encoder_->TriggerCpuOveruse(); |
video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.bw_limited_resolution); |
EXPECT_TRUE(stats.cpu_limited_resolution); |
@@ -1049,7 +997,7 @@ |
VideoSendStream::DegradationPreference::kMaintainFramerate); |
new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
- WaitForEncodedFrame(3); |
+ sink_.WaitForEncodedFrame(3); |
stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.bw_limited_resolution); |
EXPECT_TRUE(stats.cpu_limited_resolution); |
@@ -1061,7 +1009,7 @@ |
VideoSendStream::DegradationPreference::kDegradationDisabled); |
new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
- WaitForEncodedFrame(4); |
+ sink_.WaitForEncodedFrame(4); |
stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.bw_limited_resolution); |
EXPECT_FALSE(stats.cpu_limited_resolution); |
@@ -1073,7 +1021,7 @@ |
VideoSendStream::DegradationPreference::kMaintainFramerate); |
new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
- WaitForEncodedFrame(5); |
+ sink_.WaitForEncodedFrame(5); |
stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.bw_limited_resolution); |
EXPECT_TRUE(stats.cpu_limited_resolution); |
@@ -1082,7 +1030,7 @@ |
// Trigger CPU normal use. |
vie_encoder_->TriggerCpuNormalUsage(); |
new_video_source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); |
- WaitForEncodedFrame(6); |
+ sink_.WaitForEncodedFrame(6); |
stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.bw_limited_resolution); |
EXPECT_FALSE(stats.cpu_limited_resolution); |
@@ -1098,7 +1046,7 @@ |
const int kWidth = 1280; |
const int kHeight = 720; |
video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.bw_limited_resolution); |
EXPECT_FALSE(stats.bw_limited_framerate); |
@@ -1110,7 +1058,7 @@ |
VideoSendStream::DegradationPreference::kBalanced); |
new_video_source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.bw_limited_resolution); |
EXPECT_FALSE(stats.bw_limited_framerate); |
@@ -1119,7 +1067,7 @@ |
// Trigger adapt down. |
vie_encoder_->TriggerQualityLow(); |
new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
- WaitForEncodedFrame(3); |
+ sink_.WaitForEncodedFrame(3); |
stats = stats_proxy_->GetStats(); |
EXPECT_TRUE(stats.bw_limited_resolution); |
EXPECT_FALSE(stats.bw_limited_framerate); |
@@ -1130,7 +1078,7 @@ |
VideoSendStream::DegradationPreference::kBalanced); |
new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
- WaitForEncodedFrame(4); |
+ sink_.WaitForEncodedFrame(4); |
stats = stats_proxy_->GetStats(); |
EXPECT_TRUE(stats.bw_limited_resolution); |
EXPECT_FALSE(stats.bw_limited_framerate); |
@@ -1142,7 +1090,7 @@ |
VideoSendStream::DegradationPreference::kMaintainResolution); |
new_video_source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
- WaitForEncodedFrame(5); |
+ sink_.WaitForEncodedFrame(5); |
stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.bw_limited_resolution); |
EXPECT_FALSE(stats.bw_limited_framerate); |
@@ -1159,7 +1107,7 @@ |
const int kHeight = 720; |
video_source_.set_adaptation_enabled(true); |
video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
@@ -1167,7 +1115,7 @@ |
// Trigger adapt down. |
vie_encoder_->TriggerQualityLow(); |
video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
@@ -1175,7 +1123,7 @@ |
// Trigger overuse. |
vie_encoder_->TriggerCpuOveruse(); |
video_source_.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
- WaitForEncodedFrame(3); |
+ sink_.WaitForEncodedFrame(3); |
EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
@@ -1187,7 +1135,7 @@ |
VideoSendStream::DegradationPreference::kMaintainFramerate); |
video_source_.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
- WaitForEncodedFrame(4); |
+ sink_.WaitForEncodedFrame(4); |
EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
@@ -1203,7 +1151,7 @@ |
int sequence = 1; |
video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
- WaitForEncodedFrame(sequence++); |
+ sink_.WaitForEncodedFrame(sequence++); |
VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.cpu_limited_resolution); |
EXPECT_FALSE(stats.cpu_limited_framerate); |
@@ -1212,7 +1160,7 @@ |
// Trigger CPU overuse, should now adapt down. |
vie_encoder_->TriggerCpuOveruse(); |
video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
- WaitForEncodedFrame(sequence++); |
+ sink_.WaitForEncodedFrame(sequence++); |
stats = stats_proxy_->GetStats(); |
EXPECT_TRUE(stats.cpu_limited_resolution); |
EXPECT_FALSE(stats.cpu_limited_framerate); |
@@ -1226,7 +1174,7 @@ |
new_video_source.IncomingCapturedFrame( |
CreateFrame(sequence, kWidth, kHeight)); |
- WaitForEncodedFrame(sequence++); |
+ sink_.WaitForEncodedFrame(sequence++); |
stats = stats_proxy_->GetStats(); |
EXPECT_TRUE(stats.cpu_limited_resolution); |
EXPECT_FALSE(stats.cpu_limited_framerate); |
@@ -1238,7 +1186,7 @@ |
VideoSendStream::DegradationPreference::kMaintainResolution); |
new_video_source.IncomingCapturedFrame( |
CreateFrame(sequence, kWidth, kHeight)); |
- WaitForEncodedFrame(sequence++); |
+ sink_.WaitForEncodedFrame(sequence++); |
stats = stats_proxy_->GetStats(); |
// Not adapted at first. |
EXPECT_FALSE(stats.cpu_limited_resolution); |
@@ -1255,7 +1203,7 @@ |
new_video_source.IncomingCapturedFrame( |
CreateFrame(sequence, kWidth, kHeight)); |
- WaitForEncodedFrame(sequence++); |
+ sink_.WaitForEncodedFrame(sequence++); |
// Framerate now adapted. |
stats = stats_proxy_->GetStats(); |
@@ -1269,7 +1217,7 @@ |
VideoSendStream::DegradationPreference::kDegradationDisabled); |
new_video_source.IncomingCapturedFrame( |
CreateFrame(sequence, kWidth, kHeight)); |
- WaitForEncodedFrame(sequence++); |
+ sink_.WaitForEncodedFrame(sequence++); |
stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.cpu_limited_resolution); |
@@ -1291,7 +1239,7 @@ |
&video_source_, |
VideoSendStream::DegradationPreference::kMaintainFramerate); |
video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
- WaitForEncodedFrame(sequence++); |
+ sink_.WaitForEncodedFrame(sequence++); |
stats = stats_proxy_->GetStats(); |
EXPECT_TRUE(stats.cpu_limited_resolution); |
EXPECT_FALSE(stats.cpu_limited_framerate); |
@@ -1300,7 +1248,7 @@ |
// Trigger CPU normal usage. |
vie_encoder_->TriggerCpuNormalUsage(); |
video_source_.IncomingCapturedFrame(CreateFrame(sequence, kWidth, kHeight)); |
- WaitForEncodedFrame(sequence++); |
+ sink_.WaitForEncodedFrame(sequence++); |
stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.cpu_limited_resolution); |
EXPECT_FALSE(stats.cpu_limited_framerate); |
@@ -1312,7 +1260,7 @@ |
VideoSendStream::DegradationPreference::kMaintainResolution); |
new_video_source.IncomingCapturedFrame( |
CreateFrame(sequence, kWidth, kHeight)); |
- WaitForEncodedFrame(sequence++); |
+ sink_.WaitForEncodedFrame(sequence++); |
stats = stats_proxy_->GetStats(); |
// Disabled, since we previously switched the source to disabled. |
EXPECT_FALSE(stats.cpu_limited_resolution); |
@@ -1323,7 +1271,7 @@ |
vie_encoder_->TriggerCpuNormalUsage(); |
new_video_source.IncomingCapturedFrame( |
CreateFrame(sequence, kWidth, kHeight)); |
- WaitForEncodedFrame(sequence++); |
+ sink_.WaitForEncodedFrame(sequence++); |
stats = stats_proxy_->GetStats(); |
EXPECT_FALSE(stats.cpu_limited_resolution); |
EXPECT_FALSE(stats.cpu_limited_framerate); |
@@ -1339,7 +1287,7 @@ |
const int kWidth = 1280; |
const int kHeight = 720; |
video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
VideoSendStream::Stats stats = stats_proxy_->GetStats(); |
EXPECT_EQ(video_encoder_config_.max_bitrate_bps, |
@@ -1357,13 +1305,13 @@ |
VerifyNoLimitation(video_source_.sink_wants()); |
video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
// Trigger scale down. |
vie_encoder_->TriggerQualityLow(); |
video_source_.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
// Expect a scale down. |
EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
@@ -1378,7 +1326,7 @@ |
// Trigger scale down. |
vie_encoder_->TriggerQualityLow(); |
new_video_source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
- WaitForEncodedFrame(3); |
+ sink_.WaitForEncodedFrame(3); |
// Expect no scaling. |
EXPECT_EQ(std::numeric_limits<int>::max(), |
@@ -1387,7 +1335,7 @@ |
// Trigger scale up. |
vie_encoder_->TriggerQualityHigh(); |
new_video_source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
- WaitForEncodedFrame(4); |
+ sink_.WaitForEncodedFrame(4); |
// Expect nothing to change, still no scaling. |
EXPECT_EQ(std::numeric_limits<int>::max(), |
@@ -1407,7 +1355,7 @@ |
&source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
VerifyNoLimitation(source.sink_wants()); |
EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
@@ -1439,7 +1387,7 @@ |
&source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(kWidth, kHeight); |
+ sink_.WaitForEncodedFrame(kWidth, kHeight); |
VerifyNoLimitation(source.sink_wants()); |
EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
@@ -1464,7 +1412,7 @@ |
&source, VideoSendStream::DegradationPreference::kMaintainResolution); |
source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(kWidth, kHeight); |
+ sink_.WaitForEncodedFrame(kWidth, kHeight); |
VerifyNoLimitation(source.sink_wants()); |
EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_framerate); |
EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
@@ -1517,7 +1465,7 @@ |
&source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
VerifyNoLimitation(source.sink_wants()); |
EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
EXPECT_EQ(0, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
@@ -1525,7 +1473,7 @@ |
// Trigger adapt down, expect scaled down resolution. |
vie_encoder_->TriggerQualityLow(); |
source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
EXPECT_EQ(1, stats_proxy_->GetStats().number_of_quality_adapt_changes); |
@@ -1598,7 +1546,7 @@ |
int downscales = 0; |
for (size_t i = 1; i <= kNumFrames; i++) { |
video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
- WaitForEncodedFrame(i); |
+ sink_.WaitForEncodedFrame(i); |
// Trigger scale down. |
rtc::VideoSinkWants last_wants = video_source_.sink_wants(); |
@@ -1629,7 +1577,7 @@ |
&source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(kWidth, kHeight); |
+ sink_.WaitForEncodedFrame(kWidth, kHeight); |
VerifyNoLimitation(source.sink_wants()); |
EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_EQ(0, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
@@ -1637,7 +1585,7 @@ |
// Trigger adapt down, expect scaled down resolution. |
vie_encoder_->TriggerCpuOveruse(); |
source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_EQ(1, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
@@ -1645,7 +1593,7 @@ |
// Trigger adapt up, expect no restriction. |
vie_encoder_->TriggerCpuNormalUsage(); |
source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
- WaitForEncodedFrame(kWidth, kHeight); |
+ sink_.WaitForEncodedFrame(kWidth, kHeight); |
VerifyNoLimitation(source.sink_wants()); |
EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_EQ(2, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
@@ -1653,7 +1601,7 @@ |
// Trigger adapt down, expect scaled down resolution. |
vie_encoder_->TriggerCpuOveruse(); |
source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
- WaitForEncodedFrame(4); |
+ sink_.WaitForEncodedFrame(4); |
VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_EQ(3, stats_proxy_->GetStats().number_of_cpu_adapt_changes); |
@@ -1682,7 +1630,7 @@ |
&source, VideoSendStream::DegradationPreference::kMaintainFramerate); |
source.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
- WaitForEncodedFrame(kWidth, kHeight); |
+ sink_.WaitForEncodedFrame(kWidth, kHeight); |
VerifyNoLimitation(source.sink_wants()); |
EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
@@ -1692,7 +1640,7 @@ |
// Trigger cpu adapt down, expect scaled down resolution (960x540). |
vie_encoder_->TriggerCpuOveruse(); |
source.IncomingCapturedFrame(CreateFrame(2, kWidth, kHeight)); |
- WaitForEncodedFrame(2); |
+ sink_.WaitForEncodedFrame(2); |
VerifyFpsMaxResolutionLt(source.sink_wants(), kWidth * kHeight); |
EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
@@ -1702,7 +1650,7 @@ |
// Trigger cpu adapt down, expect scaled down resolution (640x360). |
vie_encoder_->TriggerCpuOveruse(); |
source.IncomingCapturedFrame(CreateFrame(3, kWidth, kHeight)); |
- WaitForEncodedFrame(3); |
+ sink_.WaitForEncodedFrame(3); |
VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
rtc::VideoSinkWants last_wants = source.sink_wants(); |
EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
@@ -1713,7 +1661,7 @@ |
// Trigger cpu adapt down, max cpu downgrades reached, expect no change. |
vie_encoder_->TriggerCpuOveruse(); |
source.IncomingCapturedFrame(CreateFrame(4, kWidth, kHeight)); |
- WaitForEncodedFrame(4); |
+ sink_.WaitForEncodedFrame(4); |
VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_FALSE(stats_proxy_->GetStats().bw_limited_resolution); |
@@ -1723,7 +1671,7 @@ |
// Trigger quality adapt down, expect scaled down resolution (480x270). |
vie_encoder_->TriggerQualityLow(); |
source.IncomingCapturedFrame(CreateFrame(5, kWidth, kHeight)); |
- WaitForEncodedFrame(5); |
+ sink_.WaitForEncodedFrame(5); |
VerifyFpsMaxResolutionLt(source.sink_wants(), source.last_wants()); |
EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
@@ -1733,7 +1681,7 @@ |
// Trigger cpu adapt up, expect upscaled resolution (640x360). |
vie_encoder_->TriggerCpuNormalUsage(); |
source.IncomingCapturedFrame(CreateFrame(6, kWidth, kHeight)); |
- WaitForEncodedFrame(6); |
+ sink_.WaitForEncodedFrame(6); |
VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
EXPECT_TRUE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
@@ -1743,7 +1691,7 @@ |
// Trigger cpu adapt up, expect upscaled resolution (960x540). |
vie_encoder_->TriggerCpuNormalUsage(); |
source.IncomingCapturedFrame(CreateFrame(7, kWidth, kHeight)); |
- WaitForEncodedFrame(7); |
+ sink_.WaitForEncodedFrame(7); |
VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
last_wants = source.sink_wants(); |
EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
@@ -1754,7 +1702,7 @@ |
// Trigger cpu adapt up, no cpu downgrades, expect no change (960x540). |
vie_encoder_->TriggerCpuNormalUsage(); |
source.IncomingCapturedFrame(CreateFrame(8, kWidth, kHeight)); |
- WaitForEncodedFrame(8); |
+ sink_.WaitForEncodedFrame(8); |
VerifyFpsEqResolutionEq(source.sink_wants(), last_wants); |
EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
EXPECT_TRUE(stats_proxy_->GetStats().bw_limited_resolution); |
@@ -1764,7 +1712,7 @@ |
// Trigger quality adapt up, expect no restriction (1280x720). |
vie_encoder_->TriggerQualityHigh(); |
source.IncomingCapturedFrame(CreateFrame(9, kWidth, kHeight)); |
- WaitForEncodedFrame(kWidth, kHeight); |
+ sink_.WaitForEncodedFrame(kWidth, kHeight); |
VerifyFpsMaxResolutionGt(source.sink_wants(), source.last_wants()); |
VerifyNoLimitation(source.sink_wants()); |
EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
@@ -1776,21 +1724,21 @@ |
} |
TEST_F(ViEEncoderTest, CpuLimitedHistogramIsReported) { |
+ vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
const int kWidth = 640; |
const int kHeight = 360; |
- vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
- |
for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
- WaitForEncodedFrame(i); |
+ sink_.WaitForEncodedFrame(i); |
} |
vie_encoder_->TriggerCpuOveruse(); |
for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
video_source_.IncomingCapturedFrame(CreateFrame( |
SendStatisticsProxy::kMinRequiredMetricsSamples + i, kWidth, kHeight)); |
- WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + i); |
+ sink_.WaitForEncodedFrame(SendStatisticsProxy::kMinRequiredMetricsSamples + |
+ i); |
} |
vie_encoder_->Stop(); |
@@ -1814,7 +1762,7 @@ |
for (int i = 1; i <= SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) { |
video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
- WaitForEncodedFrame(i); |
+ sink_.WaitForEncodedFrame(i); |
} |
vie_encoder_->Stop(); |
@@ -1845,25 +1793,26 @@ |
const int64_t kStartTimeMs = 1; |
video_source_.IncomingCapturedFrame( |
CreateFrame(kStartTimeMs, codec_width_, codec_height_)); |
- WaitForEncodedFrame(kStartTimeMs); |
+ sink_.WaitForEncodedFrame(kStartTimeMs); |
// Not called on second frame. |
EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
.Times(0); |
video_source_.IncomingCapturedFrame( |
CreateFrame(kStartTimeMs + 1, codec_width_, codec_height_)); |
- WaitForEncodedFrame(kStartTimeMs + 1); |
+ sink_.WaitForEncodedFrame(kStartTimeMs + 1); |
// Called after a process interval. |
const int64_t kProcessIntervalMs = |
vcm::VCMProcessTimer::kDefaultProcessIntervalMs; |
- fake_clock_.AdvanceTimeMicros(rtc::kNumMicrosecsPerMillisec * |
- (kProcessIntervalMs + (1000 / kDefaultFps))); |
+ // TODO(sprang): ViEEncoder should die and/or get injectable clock. |
+ // Sleep for one processing interval plus one frame to avoid flakiness. |
+ SleepMs(kProcessIntervalMs + 1000 / kDefaultFps); |
EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate)) |
.Times(1); |
video_source_.IncomingCapturedFrame(CreateFrame( |
kStartTimeMs + kProcessIntervalMs, codec_width_, codec_height_)); |
- WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); |
+ sink_.WaitForEncodedFrame(kStartTimeMs + kProcessIntervalMs); |
vie_encoder_->Stop(); |
} |
@@ -1877,7 +1826,7 @@ |
video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
// Expect to drop this frame, the wait should time out. |
- ExpectDroppedFrame(); |
+ sink_.ExpectDroppedFrame(); |
// Expect the sink_wants to specify a scaled frame. |
EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
@@ -1889,7 +1838,7 @@ |
CreateFrame(2, kWidth * 3 / 4, kHeight * 3 / 4)); |
// Expect to drop this frame, the wait should time out. |
- ExpectDroppedFrame(); |
+ sink_.ExpectDroppedFrame(); |
EXPECT_LT(video_source_.sink_wants().max_pixel_count, last_pixel_count); |
@@ -1906,11 +1855,11 @@ |
int i; |
for (i = 1; i <= kMaxInitialFramedrop; ++i) { |
video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
- ExpectDroppedFrame(); |
+ sink_.ExpectDroppedFrame(); |
} |
// The n+1th frame should not be dropped, even though it's size is too large. |
video_source_.IncomingCapturedFrame(CreateFrame(i, kWidth, kHeight)); |
- WaitForEncodedFrame(i); |
+ sink_.WaitForEncodedFrame(i); |
// Expect the sink_wants to specify a scaled frame. |
EXPECT_LT(video_source_.sink_wants().max_pixel_count, kWidth * kHeight); |
@@ -1930,7 +1879,7 @@ |
video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
// Frame should not be dropped, even if it's too large. |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
vie_encoder_->Stop(); |
} |
@@ -1947,7 +1896,7 @@ |
video_source_.IncomingCapturedFrame(CreateFrame(1, kWidth, kHeight)); |
// Frame should not be dropped, even if it's too large. |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
vie_encoder_->Stop(); |
fake_encoder_.SetQualityScaling(true); |
@@ -1968,7 +1917,7 @@ |
// Trigger adapt down, too small frame, expect no change. |
source.IncomingCapturedFrame(CreateFrame(1, kTooSmallWidth, kTooSmallHeight)); |
- WaitForEncodedFrame(1); |
+ sink_.WaitForEncodedFrame(1); |
vie_encoder_->TriggerCpuOveruse(); |
VerifyNoLimitation(source.sink_wants()); |
EXPECT_FALSE(stats_proxy_->GetStats().cpu_limited_resolution); |
@@ -1980,12 +1929,12 @@ |
TEST_F(ViEEncoderTest, FailingInitEncodeDoesntCauseCrash) { |
fake_encoder_.ForceInitEncodeFailure(true); |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
- ResetEncoder("VP8", 2, 1, true, false); |
+ ResetEncoder("VP8", 2, 1, true); |
const int kFrameWidth = 1280; |
const int kFrameHeight = 720; |
video_source_.IncomingCapturedFrame( |
CreateFrame(1, kFrameWidth, kFrameHeight)); |
- ExpectDroppedFrame(); |
+ sink_.ExpectDroppedFrame(); |
vie_encoder_->Stop(); |
} |
@@ -2001,28 +1950,29 @@ |
video_source_.IncomingCapturedFrame( |
CreateFrame(1, kFrameWidth, kFrameHeight)); |
- WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
+ sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
// Trigger CPU overuse, downscale by 3/4. |
vie_encoder_->TriggerCpuOveruse(); |
video_source_.IncomingCapturedFrame( |
CreateFrame(2, kFrameWidth, kFrameHeight)); |
- WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); |
+ sink_.WaitForEncodedFrame((kFrameWidth * 3) / 4, (kFrameHeight * 3) / 4); |
// Trigger CPU normal use, return to original resolution. |
vie_encoder_->TriggerCpuNormalUsage(); |
video_source_.IncomingCapturedFrame( |
CreateFrame(3, kFrameWidth, kFrameHeight)); |
- WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
+ sink_.WaitForEncodedFrame(kFrameWidth, kFrameHeight); |
vie_encoder_->Stop(); |
} |
TEST_F(ViEEncoderTest, AdaptsFramerateOnOveruse_MaintainResolutionMode) { |
- // const int kDefaultFramerateFps = 30; |
+ const int kDefaultFramerateFps = 30; |
+ const int kFrameIntervalMs = rtc::kNumMillisecsPerSec / kDefaultFramerateFps; |
const int kFrameWidth = 1280; |
const int kFrameHeight = 720; |
- int kFrameIntervalMs = rtc::kNumMillisecsPerSec / max_framerate_; |
+ rtc::ScopedFakeClock fake_clock; |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
vie_encoder_->SetSource( |
@@ -2030,82 +1980,93 @@ |
VideoSendStream::DegradationPreference::kMaintainResolution); |
video_source_.set_adaptation_enabled(true); |
- int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
+ fake_clock.SetTimeMicros(kFrameIntervalMs * 1000); |
+ int64_t timestamp_ms = kFrameIntervalMs; |
video_source_.IncomingCapturedFrame( |
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
- WaitForEncodedFrame(timestamp_ms); |
+ sink_.WaitForEncodedFrame(timestamp_ms); |
// Try to trigger overuse. No fps estimate available => no effect. |
vie_encoder_->TriggerCpuOveruse(); |
// Insert frames for one second to get a stable estimate. |
- for (int i = 0; i < max_framerate_; ++i) { |
+ for (int i = 0; i < kDefaultFramerateFps; ++i) { |
timestamp_ms += kFrameIntervalMs; |
+ fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); |
video_source_.IncomingCapturedFrame( |
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
- WaitForEncodedFrame(timestamp_ms); |
+ sink_.WaitForEncodedFrame(timestamp_ms); |
} |
// Trigger CPU overuse, reduce framerate by 2/3. |
vie_encoder_->TriggerCpuOveruse(); |
int num_frames_dropped = 0; |
- for (int i = 0; i < max_framerate_; ++i) { |
+ for (int i = 0; i < kDefaultFramerateFps; ++i) { |
timestamp_ms += kFrameIntervalMs; |
+ fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); |
video_source_.IncomingCapturedFrame( |
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
- if (!WaitForFrame(kFrameTimeoutMs)) { |
+ if (!sink_.WaitForFrame(kFrameTimeoutMs)) { |
++num_frames_dropped; |
} else { |
sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
} |
} |
- // Add some slack to account for frames dropped by the frame dropper. |
- const int kErrorMargin = 1; |
- EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 2 / 3), |
+ // TODO(sprang): Find where there's rounding errors or stuff causing the |
+ // margin here to be a little larger than we'd like (input fps estimate is |
+ // off) and the frame dropping is a little too aggressive. |
+ const int kErrorMargin = 5; |
+ EXPECT_NEAR(num_frames_dropped, |
+ kDefaultFramerateFps - (kDefaultFramerateFps * 2 / 3), |
kErrorMargin); |
// Trigger CPU overuse, reduce framerate by 2/3 again. |
vie_encoder_->TriggerCpuOveruse(); |
num_frames_dropped = 0; |
- for (int i = 0; i < max_framerate_; ++i) { |
+ for (int i = 0; i < kDefaultFramerateFps; ++i) { |
timestamp_ms += kFrameIntervalMs; |
+ fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); |
video_source_.IncomingCapturedFrame( |
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
- if (!WaitForFrame(kFrameTimeoutMs)) { |
+ if (!sink_.WaitForFrame(kFrameTimeoutMs)) { |
++num_frames_dropped; |
} else { |
sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
} |
} |
- EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 4 / 9), |
+ EXPECT_NEAR(num_frames_dropped, |
+ kDefaultFramerateFps - (kDefaultFramerateFps * 4 / 9), |
kErrorMargin); |
// Go back up one step. |
vie_encoder_->TriggerCpuNormalUsage(); |
num_frames_dropped = 0; |
- for (int i = 0; i < max_framerate_; ++i) { |
+ for (int i = 0; i < kDefaultFramerateFps; ++i) { |
timestamp_ms += kFrameIntervalMs; |
+ fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); |
video_source_.IncomingCapturedFrame( |
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
- if (!WaitForFrame(kFrameTimeoutMs)) { |
+ if (!sink_.WaitForFrame(kFrameTimeoutMs)) { |
++num_frames_dropped; |
} else { |
sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
} |
} |
- EXPECT_NEAR(num_frames_dropped, max_framerate_ - (max_framerate_ * 2 / 3), |
+ EXPECT_NEAR(num_frames_dropped, |
+ kDefaultFramerateFps - (kDefaultFramerateFps * 2 / 3), |
kErrorMargin); |
// Go back up to original mode. |
vie_encoder_->TriggerCpuNormalUsage(); |
num_frames_dropped = 0; |
- for (int i = 0; i < max_framerate_; ++i) { |
+ for (int i = 0; i < kDefaultFramerateFps; ++i) { |
timestamp_ms += kFrameIntervalMs; |
+ fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); |
video_source_.IncomingCapturedFrame( |
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
- if (!WaitForFrame(kFrameTimeoutMs)) { |
+ if (!sink_.WaitForFrame(kFrameTimeoutMs)) { |
++num_frames_dropped; |
} else { |
sink_.CheckLastFrameSizeMathces(kFrameWidth, kFrameHeight); |
@@ -2123,17 +2084,15 @@ |
const int kFrameWidth = 1280; |
const int kFrameHeight = 720; |
- // Reconfigure encoder with two temporal layers and screensharing, which will |
- // disable frame dropping and make testing easier. |
- ResetEncoder("VP8", 1, 2, true, true); |
- |
+ rtc::ScopedFakeClock fake_clock; |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
vie_encoder_->SetSource( |
&video_source_, |
VideoSendStream::DegradationPreference::kMaintainResolution); |
video_source_.set_adaptation_enabled(true); |
- int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
+ fake_clock.SetTimeMicros(kFrameIntervalMs * 1000); |
+ int64_t timestamp_ms = kFrameIntervalMs; |
// Trigger overuse as much as we can. |
for (int i = 0; i < ViEEncoder::kMaxCpuResolutionDowngrades; ++i) { |
@@ -2142,72 +2101,23 @@ |
video_source_.IncomingCapturedFrame( |
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
timestamp_ms += kFrameIntervalMs; |
+ fake_clock.AdvanceTimeMicros(kFrameIntervalMs * 1000); |
} |
// ...and then try to adapt again. |
vie_encoder_->TriggerCpuOveruse(); |
} |
// Drain any frame in the pipeline. |
- WaitForFrame(kDefaultTimeoutMs); |
+ sink_.WaitForFrame(kDefaultTimeoutMs); |
// Insert frames at min fps, all should go through. |
for (int i = 0; i < 10; ++i) { |
timestamp_ms += kMinFpsFrameInterval; |
+ fake_clock.AdvanceTimeMicros(kMinFpsFrameInterval * 1000); |
video_source_.IncomingCapturedFrame( |
CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
- WaitForEncodedFrame(timestamp_ms); |
- } |
- vie_encoder_->Stop(); |
-} |
- |
-TEST_F(ViEEncoderTest, PriodicallyUpdatesChannelParameters) { |
- const int kFrameWidth = 1280; |
- const int kFrameHeight = 720; |
- const int kLowFps = 2; |
- const int kHighFps = 30; |
- |
- vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
- |
- int64_t timestamp_ms = fake_clock_.TimeNanos() / rtc::kNumNanosecsPerMillisec; |
- max_framerate_ = kLowFps; |
- |
- // Insert 2 seconds of 2fps video. |
- for (int i = 0; i < kLowFps * 2; ++i) { |
- video_source_.IncomingCapturedFrame( |
- CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
- WaitForEncodedFrame(timestamp_ms); |
- timestamp_ms += 1000 / kLowFps; |
- } |
- |
- // Make sure encoder is updated with new target. |
- vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
- video_source_.IncomingCapturedFrame( |
- CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
- WaitForEncodedFrame(timestamp_ms); |
- timestamp_ms += 1000 / kLowFps; |
- |
- EXPECT_EQ(kLowFps, fake_encoder_.GetConfiguredInputFramerate()); |
- |
- // Insert 30fps frames for just a little more than the forced update period. |
- const int kVcmTimerIntervalFrames = |
- (vcm::VCMProcessTimer::kDefaultProcessIntervalMs * kHighFps) / 1000; |
- const int kFrameIntervalMs = 1000 / kHighFps; |
- max_framerate_ = kHighFps; |
- for (int i = 0; i < kVcmTimerIntervalFrames + 2; ++i) { |
- video_source_.IncomingCapturedFrame( |
- CreateFrame(timestamp_ms, kFrameWidth, kFrameHeight)); |
- // Wait for encoded frame, but skip ahead if it doesn't arrive as it might |
- // be dropped if the encoder hans't been updated with the new higher target |
- // framerate yet, causing it to overshoot the target bitrate and then |
- // suffering the wrath of the media optimizer. |
- TimedWaitForEncodedFrame(timestamp_ms, 2 * kFrameIntervalMs); |
- timestamp_ms += kFrameIntervalMs; |
- } |
- |
- // Don expect correct measurement just yet, but it should be higher than |
- // before. |
- EXPECT_GT(fake_encoder_.GetConfiguredInputFramerate(), kLowFps); |
- |
+ sink_.WaitForEncodedFrame(timestamp_ms); |
+ } |
vie_encoder_->Stop(); |
} |
} // namespace webrtc |