Index: webrtc/video/vie_encoder_unittest.cc |
diff --git a/webrtc/video/vie_encoder_unittest.cc b/webrtc/video/vie_encoder_unittest.cc |
index faa48330aa9984b967deaafe453d9f3c20f4fb91..755f10a61e350eeba97392f4a044210750792028 100644 |
--- a/webrtc/video/vie_encoder_unittest.cc |
+++ b/webrtc/video/vie_encoder_unittest.cc |
@@ -29,9 +29,9 @@ namespace { |
#if defined(WEBRTC_ANDROID) |
// TODO(kthelgason): Lower this limit when better testing |
// on MediaCodec and fallback implementations are in place. |
-const int kMinPixelsPerFrame = 320 * 180; |
+const uint32_t kMinPixelsPerFrame = 320 * 180; |
#else |
-const int kMinPixelsPerFrame = 120 * 90; |
+const uint32_t kMinPixelsPerFrame = 120 * 90; |
#endif |
} |
@@ -151,8 +151,8 @@ class AdaptingFrameForwarder : public test::FrameForwarder { |
void AddOrUpdateSink(rtc::VideoSinkInterface<VideoFrame>* sink, |
const rtc::VideoSinkWants& wants) override { |
rtc::CritScope cs(&crit_); |
- adapter_.OnResolutionRequest(wants.target_pixel_count, |
- wants.max_pixel_count); |
+ adapter_.OnResolutionFramerateRequest(wants.pixel_count, |
+ wants.framerate_fps_); |
test::FrameForwarder::AddOrUpdateSink(sink, wants); |
} |
@@ -621,8 +621,7 @@ TEST_F(ViEEncoderTest, SinkWantsRotationApplied) { |
TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
- EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
- EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
+ EXPECT_FALSE(video_source_.sink_wants().pixel_count); |
int frame_width = 1280; |
int frame_height = 720; |
@@ -636,10 +635,9 @@ TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { |
vie_encoder_->TriggerCpuOveruse(); |
- EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
- EXPECT_LT(video_source_.sink_wants().max_pixel_count.value_or( |
- std::numeric_limits<int>::max()), |
- frame_width * frame_height); |
+ ASSERT_TRUE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
+ EXPECT_LT(video_source_.sink_wants().pixel_count->max, |
+ static_cast<uint32_t>(frame_width * frame_height)); |
frame_width /= 2; |
frame_height /= 2; |
@@ -652,17 +650,24 @@ TEST_F(ViEEncoderTest, SinkWantsFromOveruseDetector) { |
ViEEncoder::kMaxCpuDowngrades + 1, frame_width, frame_height)); |
sink_.WaitForEncodedFrame(ViEEncoder::kMaxCpuDowngrades + 1); |
vie_encoder_->TriggerCpuOveruse(); |
- EXPECT_EQ(video_source_.sink_wants().target_pixel_count, |
- current_wants.target_pixel_count); |
- EXPECT_EQ(video_source_.sink_wants().max_pixel_count, |
- current_wants.max_pixel_count); |
+ ASSERT_TRUE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
+ ASSERT_TRUE(static_cast<bool>(current_wants.pixel_count)); |
+ EXPECT_EQ(video_source_.sink_wants().pixel_count->min, |
+ current_wants.pixel_count->min); |
+ EXPECT_EQ(video_source_.sink_wants().pixel_count->target, |
+ current_wants.pixel_count->target); |
+ EXPECT_EQ(video_source_.sink_wants().pixel_count->max, |
+ current_wants.pixel_count->max); |
// Trigger CPU normal use. |
vie_encoder_->TriggerCpuNormalUsage(); |
- EXPECT_EQ(frame_width * frame_height * 5 / 3, |
- video_source_.sink_wants().target_pixel_count.value_or(0)); |
- EXPECT_EQ(frame_width * frame_height * 4, |
- video_source_.sink_wants().max_pixel_count.value_or(0)); |
+ EXPECT_GT(video_source_.sink_wants().pixel_count->min, 0U); |
+ EXPECT_LE(video_source_.sink_wants().pixel_count->min, |
+ video_source_.sink_wants().pixel_count->target); |
+ EXPECT_EQ(static_cast<uint32_t>(frame_width * frame_height * 5 / 3), |
+ video_source_.sink_wants().pixel_count->target); |
+ EXPECT_EQ(static_cast<uint32_t>(frame_width * frame_height * 4), |
+ video_source_.sink_wants().pixel_count->max); |
vie_encoder_->Stop(); |
} |
@@ -671,8 +676,7 @@ TEST_F(ViEEncoderTest, |
ResolutionSinkWantsResetOnSetSourceWithDisabledResolutionScaling) { |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
- EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
- EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
+ EXPECT_FALSE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
int frame_width = 1280; |
int frame_height = 720; |
@@ -686,10 +690,9 @@ TEST_F(ViEEncoderTest, |
video_source_.IncomingCapturedFrame( |
CreateFrame(2, frame_width, frame_height)); |
sink_.WaitForEncodedFrame(2); |
- EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
- EXPECT_LT(video_source_.sink_wants().max_pixel_count.value_or( |
- std::numeric_limits<int>::max()), |
- frame_width * frame_height); |
+ ASSERT_TRUE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
+ EXPECT_LT(video_source_.sink_wants().pixel_count->max, |
+ static_cast<uint32_t>(frame_width * frame_height)); |
// Set new source. |
test::FrameForwarder new_video_source; |
@@ -697,22 +700,19 @@ TEST_F(ViEEncoderTest, |
&new_video_source, |
VideoSendStream::DegradationPreference::kMaintainResolution); |
- EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
- EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
+ EXPECT_FALSE(static_cast<bool>(new_video_source.sink_wants().pixel_count)); |
new_video_source.IncomingCapturedFrame( |
CreateFrame(3, frame_width, frame_height)); |
sink_.WaitForEncodedFrame(3); |
- EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
- EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
+ EXPECT_FALSE(static_cast<bool>(new_video_source.sink_wants().pixel_count)); |
// Calling SetSource with resolution scaling enabled apply the old SinkWants. |
vie_encoder_->SetSource(&new_video_source, |
VideoSendStream::DegradationPreference::kBalanced); |
- EXPECT_LT(new_video_source.sink_wants().max_pixel_count.value_or( |
- std::numeric_limits<int>::max()), |
- frame_width * frame_height); |
- EXPECT_FALSE(new_video_source.sink_wants().target_pixel_count); |
+ ASSERT_TRUE(static_cast<bool>(new_video_source.sink_wants().pixel_count)); |
+ EXPECT_LT(new_video_source.sink_wants().pixel_count->max, |
+ static_cast<uint32_t>(frame_width * frame_height)); |
vie_encoder_->Stop(); |
} |
@@ -971,15 +971,14 @@ TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { |
int frame_height = 720; |
vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); |
- // Expect no scaling to begin with |
- EXPECT_FALSE(video_source_.sink_wants().target_pixel_count); |
- EXPECT_FALSE(video_source_.sink_wants().max_pixel_count); |
+ // Expect no scaling to begin with. |
+ EXPECT_FALSE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
video_source_.IncomingCapturedFrame( |
CreateFrame(1, frame_width, frame_height)); |
sink_.WaitForEncodedFrame(1); |
- // Trigger scale down |
+ // Trigger scale down. |
vie_encoder_->TriggerQualityLow(); |
video_source_.IncomingCapturedFrame( |
@@ -987,9 +986,9 @@ TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { |
sink_.WaitForEncodedFrame(2); |
// 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); |
+ ASSERT_TRUE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
+ EXPECT_LT(video_source_.sink_wants().pixel_count->max, |
+ static_cast<uint32_t>(frame_width * frame_height)); |
// Set adaptation disabled. |
test::FrameForwarder new_video_source; |
@@ -997,23 +996,23 @@ TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) { |
&new_video_source, |
VideoSendStream::DegradationPreference::kMaintainResolution); |
- // Trigger scale down |
+ // Trigger scale down. |
vie_encoder_->TriggerQualityLow(); |
new_video_source.IncomingCapturedFrame( |
CreateFrame(3, frame_width, frame_height)); |
sink_.WaitForEncodedFrame(3); |
- // Expect no scaling |
- EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
+ // Expect no scaling. |
+ EXPECT_FALSE(static_cast<bool>(new_video_source.sink_wants().pixel_count)); |
- // Trigger scale up |
+ // Trigger scale up. |
vie_encoder_->TriggerQualityHigh(); |
new_video_source.IncomingCapturedFrame( |
CreateFrame(4, frame_width, frame_height)); |
sink_.WaitForEncodedFrame(4); |
- // Expect nothing to change, still no scaling |
- EXPECT_FALSE(new_video_source.sink_wants().max_pixel_count); |
+ // Expect nothing to change, still no scaling. |
+ EXPECT_FALSE(static_cast<bool>(new_video_source.sink_wants().pixel_count)); |
vie_encoder_->Stop(); |
} |
@@ -1029,7 +1028,9 @@ TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) { |
sink_.WaitForEncodedFrame(i); |
// Trigger scale down |
vie_encoder_->TriggerQualityLow(); |
- EXPECT_GE(*video_source_.sink_wants().max_pixel_count, kMinPixelsPerFrame); |
+ ASSERT_TRUE(video_source_.sink_wants().pixel_count); |
+ EXPECT_GE(video_source_.sink_wants().pixel_count->min, kMinPixelsPerFrame); |
+ EXPECT_GE(video_source_.sink_wants().pixel_count->max, kMinPixelsPerFrame); |
} |
vie_encoder_->Stop(); |
@@ -1121,19 +1122,21 @@ TEST_F(ViEEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) { |
sink_.ExpectDroppedFrame(); |
// Expect the sink_wants to specify a scaled frame. |
- EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
- EXPECT_LT(*video_source_.sink_wants().max_pixel_count, 1000 * 1000); |
+ ASSERT_TRUE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
+ EXPECT_LT(video_source_.sink_wants().pixel_count->max, |
+ static_cast<uint32_t>(1000 * 1000)); |
- int last_pixel_count = *video_source_.sink_wants().max_pixel_count; |
+ int last_pixel_count = video_source_.sink_wants().pixel_count->max; |
- // Next frame is scaled |
+ // Next frame is scaled. |
video_source_.IncomingCapturedFrame( |
CreateFrame(2, frame_width * 3 / 4, frame_height * 3 / 4)); |
// Expect to drop this frame, the wait should time out. |
sink_.ExpectDroppedFrame(); |
- EXPECT_LT(*video_source_.sink_wants().max_pixel_count, last_pixel_count); |
+ EXPECT_LT(video_source_.sink_wants().pixel_count->max, |
+ static_cast<uint32_t>(last_pixel_count)); |
vie_encoder_->Stop(); |
} |
@@ -1157,8 +1160,9 @@ TEST_F(ViEEncoderTest, NrOfDroppedFramesLimited) { |
sink_.WaitForEncodedFrame(i); |
// Expect the sink_wants to specify a scaled frame. |
- EXPECT_TRUE(video_source_.sink_wants().max_pixel_count); |
- EXPECT_LT(*video_source_.sink_wants().max_pixel_count, 1000 * 1000); |
+ ASSERT_TRUE(static_cast<bool>(video_source_.sink_wants().pixel_count)); |
+ EXPECT_LT(video_source_.sink_wants().pixel_count->max, |
+ static_cast<uint32_t>(1000 * 1000)); |
vie_encoder_->Stop(); |
} |