Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Unified Diff: webrtc/video/vie_encoder_unittest.cc

Issue 2398963003: Move usage of QualityScaler to ViEEncoder. (Closed)
Patch Set: prevent data race Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/video/vie_encoder_unittest.cc
diff --git a/webrtc/video/vie_encoder_unittest.cc b/webrtc/video/vie_encoder_unittest.cc
index f6046be652c0f5e3fdc0df8f7df82057560224e6..11f352f22cfdcb229ccbd1cc685909f88f81327f 100644
--- a/webrtc/video/vie_encoder_unittest.cc
+++ b/webrtc/video/vie_encoder_unittest.cc
@@ -22,6 +22,9 @@
namespace webrtc {
+using DegredationPreference = VideoSendStream::DegradationPreference;
+using ScaleReason = ScalingObserverInterface::ScaleReason;
+
namespace {
class TestBuffer : public webrtc::I420Buffer {
public:
@@ -39,32 +42,30 @@ class TestBuffer : public webrtc::I420Buffer {
class ViEEncoderUnderTest : public ViEEncoder {
public:
- ViEEncoderUnderTest(
- SendStatisticsProxy* stats_proxy,
- const webrtc::VideoSendStream::Config::EncoderSettings& settings)
+ ViEEncoderUnderTest(SendStatisticsProxy* stats_proxy,
+ const VideoSendStream::Config::EncoderSettings& settings)
: ViEEncoder(1 /* number_of_cores */,
stats_proxy,
settings,
nullptr /* pre_encode_callback */,
nullptr /* encoder_timing */) {}
- void TriggerCpuOveruse() {
+ void PostTaskAndWait(bool down, ScaleReason reason) {
rtc::Event event(false, false);
- encoder_queue()->PostTask([this, &event] {
- OveruseDetected();
+ encoder_queue()->PostTask([this, &event, reason, down] {
+ down ? ScaleDown(reason) : ScaleUp(reason);
event.Set();
});
- event.Wait(rtc::Event::kForever);
+ RTC_DCHECK(event.Wait(5000));
}
- void TriggerCpuNormalUsage() {
- rtc::Event event(false, false);
- encoder_queue()->PostTask([this, &event] {
- NormalUsage();
- event.Set();
- });
- event.Wait(rtc::Event::kForever);
- }
+ void TriggerCpuOveruse() { PostTaskAndWait(true, ScaleReason::kCpu); }
+
+ void TriggerCpuNormalUsage() { PostTaskAndWait(false, ScaleReason::kCpu); }
+
+ void TriggerQualityLow() { PostTaskAndWait(true, ScaleReason::kQuality); }
+
+ void TriggerQualityHigh() { PostTaskAndWait(false, ScaleReason::kQuality); }
};
} // namespace
@@ -135,6 +136,10 @@ class ViEEncoderTest : public ::testing::Test {
block_next_encode_ = true;
}
+ VideoEncoder::ScalingSettings GetScalingSettings() const override {
+ return VideoEncoder::ScalingSettings(true, 1, 2);
+ }
+
void ContinueEncode() { continue_encode_event_.Set(); }
void CheckLastTimeStampsMatch(int64_t ntp_time_ms,
@@ -429,7 +434,7 @@ TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) {
frame_height /= 2;
}
- // Trigger CPU overuse a one more time. This should not trigger request for
+ // Trigger CPU overuse one more time. This should not trigger a request for
// lower resolution.
rtc::VideoSinkWants current_wants = video_source_.sink_wants();
video_source_.IncomingCapturedFrame(CreateFrame(
@@ -535,22 +540,20 @@ TEST_F(ViEEncoderTest, StatsTracksAdaptationStats) {
vie_encoder_->Stop();
}
-TEST_F(ViEEncoderTest, StatsTracksAdaptationStatsWhenSwitchingSource) {
+TEST_F(ViEEncoderTest, SwitchingSourceKeepsAdaptation) {
const int kTargetBitrateBps = 100000;
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
- // Trigger CPU overuse.
- vie_encoder_->TriggerCpuOveruse();
int frame_width = 1280;
int frame_height = 720;
-
video_source_.IncomingCapturedFrame(
CreateFrame(1, frame_width, frame_height));
sink_.WaitForEncodedFrame(1);
VideoSendStream::Stats stats = stats_proxy_->GetStats();
- EXPECT_TRUE(stats.cpu_limited_resolution);
- EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
+ EXPECT_FALSE(stats.cpu_limited_resolution);
perkj_webrtc 2016/11/17 21:23:38 Why these changes? Now you dont test that switchin
kthelgason 2016/11/21 13:06:53 Sorry, this must've gotten lost somewhere in the r
+ EXPECT_FALSE(stats.bw_limited_resolution);
+ EXPECT_EQ(0, stats.number_of_cpu_adapt_changes);
// Set new source with adaptation still enabled.
test::FrameForwarder new_video_source;
@@ -561,38 +564,40 @@ TEST_F(ViEEncoderTest, StatsTracksAdaptationStatsWhenSwitchingSource) {
CreateFrame(2, frame_width, frame_height));
sink_.WaitForEncodedFrame(2);
stats = stats_proxy_->GetStats();
- EXPECT_TRUE(stats.cpu_limited_resolution);
- EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
+ EXPECT_FALSE(stats.cpu_limited_resolution);
+ EXPECT_FALSE(stats.bw_limited_resolution);
+ EXPECT_EQ(0, stats.number_of_cpu_adapt_changes);
+
+ vie_encoder_->TriggerQualityLow();
- // Set adaptation disabled.
- vie_encoder_->SetSource(
- &new_video_source,
- VideoSendStream::DegradationPreference::kMaintainResolution);
new_video_source.IncomingCapturedFrame(
CreateFrame(3, frame_width, frame_height));
sink_.WaitForEncodedFrame(3);
stats = stats_proxy_->GetStats();
EXPECT_FALSE(stats.cpu_limited_resolution);
- EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
+ EXPECT_TRUE(stats.bw_limited_resolution);
- // Switch back the source with adaptation enabled.
- vie_encoder_->SetSource(&video_source_,
perkj_webrtc 2016/11/17 21:23:38 and this?
kthelgason 2016/11/21 13:06:53 Done.
+ vie_encoder_->SetSource(&new_video_source,
VideoSendStream::DegradationPreference::kBalanced);
- video_source_.IncomingCapturedFrame(
+
+ new_video_source.IncomingCapturedFrame(
CreateFrame(4, frame_width, frame_height));
sink_.WaitForEncodedFrame(4);
stats = stats_proxy_->GetStats();
- EXPECT_TRUE(stats.cpu_limited_resolution);
- EXPECT_EQ(1, stats.number_of_cpu_adapt_changes);
+ EXPECT_FALSE(stats.cpu_limited_resolution);
+ EXPECT_TRUE(stats.bw_limited_resolution);
- // Trigger CPU normal usage.
- vie_encoder_->TriggerCpuNormalUsage();
- video_source_.IncomingCapturedFrame(
+ // Set adaptation disabled.
+ vie_encoder_->SetSource(
+ &new_video_source,
+ VideoSendStream::DegradationPreference::kMaintainResolution);
+
+ new_video_source.IncomingCapturedFrame(
CreateFrame(5, frame_width, frame_height));
sink_.WaitForEncodedFrame(5);
stats = stats_proxy_->GetStats();
EXPECT_FALSE(stats.cpu_limited_resolution);
- EXPECT_EQ(2, stats.number_of_cpu_adapt_changes);
perkj_webrtc 2016/11/17 21:23:38 and this?
kthelgason 2016/11/21 13:06:53 Done.
+ EXPECT_FALSE(stats.bw_limited_resolution);
vie_encoder_->Stop();
}
@@ -611,6 +616,57 @@ TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) {
vie_encoder_->Stop();
}
+TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) {
perkj_webrtc 2016/11/17 21:23:38 LowQualityWhenScalingDisabled?
kthelgason 2016/11/21 13:06:53 I think the current name better describes what thi
+ const int kTargetBitrateBps = 100000;
+ int frame_width = 1280;
+ int frame_height = 720;
+ vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
+
+ // Expect no scaling to begin with
+ EXPECT_FALSE(video_source_.sink_wants().max_pixel_count);
+ EXPECT_FALSE(video_source_.sink_wants().max_pixel_count_step_up);
+
+ // Trigger scale down
+ vie_encoder_->TriggerQualityLow();
+
+ video_source_.IncomingCapturedFrame(
+ CreateFrame(1, frame_width, frame_height));
+ sink_.WaitForEncodedFrame(1);
+ // Expect a scale down.
+ EXPECT_TRUE(video_source_.sink_wants().max_pixel_count);
+ EXPECT_LT(*video_source_.sink_wants().max_pixel_count,
+ frame_width * frame_height);
+ const auto last_pixel_count = *video_source_.sink_wants().max_pixel_count;
perkj_webrtc 2016/11/17 21:23:38 nit const int last_pix...
kthelgason 2016/11/21 13:06:53 Done.
+
+ // Set adaptation disabled.
+ test::FrameForwarder new_video_source;
+ vie_encoder_->SetSource(
+ &new_video_source,
+ VideoSendStream::DegradationPreference::kMaintainResolution);
+
+ // Trigger scale down
+ vie_encoder_->TriggerQualityLow();
+
+ new_video_source.IncomingCapturedFrame(
+ CreateFrame(2, frame_width, frame_height));
+ sink_.WaitForEncodedFrame(2);
+
+ // Expect nothing to change
+ EXPECT_EQ(video_source_.sink_wants().max_pixel_count, last_pixel_count);
+
+ // Trigger scale up
+ vie_encoder_->TriggerQualityHigh();
+
+ new_video_source.IncomingCapturedFrame(
+ CreateFrame(3, frame_width, frame_height));
+ sink_.WaitForEncodedFrame(3);
+
+ // Expect nothing to change
+ EXPECT_EQ(video_source_.sink_wants().max_pixel_count, last_pixel_count);
+
+ vie_encoder_->Stop();
+}
+
TEST_F(ViEEncoderTest, UMACpuLimitedResolutionInPercent) {
const int kTargetBitrateBps = 100000;
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);

Powered by Google App Engine
This is Rietveld 408576698