diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index f563f4fee4..168b267580 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -884,6 +884,9 @@ void VideoStreamEncoder::MaybeEncodeVideoFrame(const VideoFrame& video_frame, // InitialFrameDropOffWhenEncoderDisabledScaling, the return value // from GetScalingSettings should enable or disable the frame drop. + // Update input frame rate before we start using it. If we update it after + // any potential frame drop we are going to artifically increase frame sizes. + input_framerate_.Update(1u, clock_->TimeInMilliseconds()); uint32_t framerate_fps = GetInputFramerateFps(); int64_t now_ms = clock_->TimeInMilliseconds(); @@ -1016,8 +1019,6 @@ void VideoStreamEncoder::EncodeVideoFrame(const VideoFrame& video_frame, } encoder_info_ = info; - - input_framerate_.Update(1u, clock_->TimeInMilliseconds()); video_sender_.AddVideoFrame(out_frame, nullptr, encoder_info_); } diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc index 68a30a170d..3497db842e 100644 --- a/video/video_stream_encoder_unittest.cc +++ b/video/video_stream_encoder_unittest.cc @@ -3295,8 +3295,11 @@ TEST_F(VideoStreamEncoderTest, DropsFramesWhenEncoderOvershoots) { timestamp_ms += 1000 / kFps; } - // Frame drops should be less than 5% - EXPECT_LT(num_dropped, 5 * kNumFramesInRun / 100); + // Framerate should be measured to be near the expected target rate. + EXPECT_NEAR(fake_encoder_.GetLastFramerate(), kFps, 1); + + // Frame drops should be within 5% of expected 0%. + EXPECT_NEAR(num_dropped, 0, 5 * kNumFramesInRun / 100); // Make encoder produce frames at double the expected bitrate during 3 seconds // of video, verify number of drops. Rate needs to be slightly changed in @@ -3320,8 +3323,14 @@ TEST_F(VideoStreamEncoderTest, DropsFramesWhenEncoderOvershoots) { timestamp_ms += 1000 / kFps; } - // Frame drops should be more than 40%. - EXPECT_GT(num_dropped, 40 * kNumFramesInRun / 100); + video_stream_encoder_->OnBitrateUpdated(kTargetBitrateBps, 0, 0); + + // Target framerate should be still be near the expected target, despite + // the frame drops. + EXPECT_NEAR(fake_encoder_.GetLastFramerate(), kFps, 1); + + // Frame drops should be within 5% of expected 50%. + EXPECT_NEAR(num_dropped, kNumFramesInRun / 2, 5 * kNumFramesInRun / 100); video_stream_encoder_->Stop(); }