| Index: webrtc/video/vie_encoder_unittest.cc
|
| diff --git a/webrtc/video/vie_encoder_unittest.cc b/webrtc/video/vie_encoder_unittest.cc
|
| index 427796ed5eb41afefe9202c0d442a22ae90e7b5c..09d9a97d8c5d1d44ceb0fa432835fae6ebfb69a0 100644
|
| --- a/webrtc/video/vie_encoder_unittest.cc
|
| +++ b/webrtc/video/vie_encoder_unittest.cc
|
| @@ -44,7 +44,9 @@ using ::testing::Return;
|
|
|
| namespace {
|
| const size_t kMaxPayloadLength = 1440;
|
| -const int kTargetBitrateBps = 100000;
|
| +const int kTargetBitrateBps = 1000000;
|
| +const int kLowTargetBitrateBps = kTargetBitrateBps / 10;
|
| +const int kMaxInitialFramedrop = 4;
|
|
|
| class TestBuffer : public webrtc::I420Buffer {
|
| public:
|
| @@ -196,7 +198,7 @@ class ViEEncoderTest : public ::testing::Test {
|
| vie_encoder_->SetSink(&sink_, false /* rotation_applied */);
|
| vie_encoder_->SetSource(&video_source_,
|
| VideoSendStream::DegradationPreference::kBalanced);
|
| - vie_encoder_->SetStartBitrate(10000);
|
| + vie_encoder_->SetStartBitrate(kTargetBitrateBps);
|
| vie_encoder_->ConfigureEncoder(std::move(video_encoder_config),
|
| kMaxPayloadLength, nack_enabled);
|
| }
|
| @@ -209,7 +211,7 @@ class ViEEncoderTest : public ::testing::Test {
|
|
|
| VideoEncoderConfig video_encoder_config;
|
| video_encoder_config.number_of_streams = num_streams;
|
| - video_encoder_config.max_bitrate_bps = 1000000;
|
| + video_encoder_config.max_bitrate_bps = kTargetBitrateBps;
|
| video_encoder_config.video_stream_factory =
|
| new rtc::RefCountedObject<VideoStreamFactory>(num_temporal_layers);
|
| ConfigureEncoder(std::move(video_encoder_config), nack_enabled);
|
| @@ -324,6 +326,8 @@ class ViEEncoderTest : public ::testing::Test {
|
| EXPECT_EQ(expected_width, width);
|
| }
|
|
|
| + void ExpectDroppedFrame() { EXPECT_FALSE(encoded_frame_event_.Wait(20)); }
|
| +
|
| void SetExpectNoFrames() {
|
| rtc::CritScope lock(&crit_);
|
| expect_frames_ = false;
|
| @@ -744,7 +748,6 @@ TEST_F(ViEEncoderTest, StatsTracksAdaptationStats) {
|
| }
|
|
|
| TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) {
|
| - const int kTargetBitrateBps = 100000;
|
| vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
|
|
|
| int frame_width = 1280;
|
| @@ -814,7 +817,6 @@ TEST_F(ViEEncoderTest, SwitchingSourceKeepsCpuAdaptation) {
|
| }
|
|
|
| TEST_F(ViEEncoderTest, SwitchingSourceKeepsQualityAdaptation) {
|
| - const int kTargetBitrateBps = 100000;
|
| vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
|
|
|
| int frame_width = 1280;
|
| @@ -950,7 +952,6 @@ TEST_F(ViEEncoderTest, StatsTracksPreferredBitrate) {
|
| }
|
|
|
| TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) {
|
| - const int kTargetBitrateBps = 100000;
|
| int frame_width = 1280;
|
| int frame_height = 720;
|
| vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
|
| @@ -1003,7 +1004,6 @@ TEST_F(ViEEncoderTest, ScalingUpAndDownDoesNothingWithMaintainResolution) {
|
| }
|
|
|
| TEST_F(ViEEncoderTest, DoesNotScaleBelowSetLimit) {
|
| - const int kTargetBitrateBps = 100000;
|
| int frame_width = 1280;
|
| int frame_height = 720;
|
| vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
|
| @@ -1060,12 +1060,12 @@ TEST_F(ViEEncoderTest, CallsBitrateObserver) {
|
| const int kDefaultFps = 30;
|
| const BitrateAllocation expected_bitrate =
|
| DefaultVideoBitrateAllocator(fake_encoder_.codec_config())
|
| - .GetAllocation(kTargetBitrateBps, kDefaultFps);
|
| + .GetAllocation(kLowTargetBitrateBps, kDefaultFps);
|
|
|
| // First called on bitrate updated, then again on first frame.
|
| EXPECT_CALL(bitrate_observer, OnBitrateAllocationUpdated(expected_bitrate))
|
| .Times(2);
|
| - vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
|
| + vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0);
|
|
|
| const int64_t kStartTimeMs = 1;
|
| video_source_.IncomingCapturedFrame(
|
| @@ -1094,6 +1094,78 @@ TEST_F(ViEEncoderTest, CallsBitrateObserver) {
|
| vie_encoder_->Stop();
|
| }
|
|
|
| +TEST_F(ViEEncoderTest, DropsFramesAndScalesWhenBitrateIsTooLow) {
|
| + vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0);
|
| + int frame_width = 640;
|
| + int frame_height = 360;
|
| +
|
| + video_source_.IncomingCapturedFrame(
|
| + CreateFrame(1, frame_width, frame_height));
|
| +
|
| + // Expect to drop this frame, the wait should time out.
|
| + 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);
|
| +
|
| + int last_pixel_count = *video_source_.sink_wants().max_pixel_count;
|
| +
|
| + // 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);
|
| +
|
| + vie_encoder_->Stop();
|
| +}
|
| +
|
| +TEST_F(ViEEncoderTest, NrOfDroppedFramesLimited) {
|
| + // 1kbps. This can never be achieved.
|
| + vie_encoder_->OnBitrateUpdated(1000, 0, 0);
|
| + int frame_width = 640;
|
| + int frame_height = 360;
|
| +
|
| + // We expect the n initial frames to get dropped.
|
| + int i;
|
| + for (i = 1; i <= kMaxInitialFramedrop; ++i) {
|
| + video_source_.IncomingCapturedFrame(
|
| + CreateFrame(i, frame_width, frame_height));
|
| + sink_.ExpectDroppedFrame();
|
| + }
|
| + // The n+1th frame should not be dropped, even though it's size is too large.
|
| + video_source_.IncomingCapturedFrame(
|
| + CreateFrame(i, frame_width, frame_height));
|
| + 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);
|
| +
|
| + vie_encoder_->Stop();
|
| +}
|
| +
|
| +TEST_F(ViEEncoderTest, InitialFrameDropOffWithMaintainResolutionPreference) {
|
| + int frame_width = 640;
|
| + int frame_height = 360;
|
| + vie_encoder_->OnBitrateUpdated(kLowTargetBitrateBps, 0, 0);
|
| +
|
| + // Set degradation preference.
|
| + vie_encoder_->SetSource(
|
| + &video_source_,
|
| + VideoSendStream::DegradationPreference::kMaintainResolution);
|
| +
|
| + video_source_.IncomingCapturedFrame(
|
| + CreateFrame(1, frame_width, frame_height));
|
| + // Frame should not be dropped, even if it's too large.
|
| + sink_.WaitForEncodedFrame(1);
|
| +
|
| + vie_encoder_->Stop();
|
| +}
|
| +
|
| // TODO(sprang): Extend this with fps throttling and any "balanced" extensions.
|
| TEST_F(ViEEncoderTest, AdaptsResolutionOnOveruse) {
|
| vie_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0);
|
|
|