mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Fix rate statistic when time window running out of samples
Current rate statistic tracker has assumption, the tracking window will always be full after first filled up. This assumption looks not always true. One example is the input_framerate_ tracker inside video_stream_sender.cc which is used for setup frame droper and encoder. Whenever there is a gap in video stream, like mute/unmute, pacer pause/unpause etc. The fps detected from the rate_statistics becomes samples_filled_partial_window / full_window_size, which could be extremely low for a while. This creates a misalignment between the fps we told encoder/frame dropper, and the real fps we fed into them, which causes short-term serious overshot and very bad experience on delay, avsync, congestion etc. This may also depends on how fast encoder could react to the gap between set fps and real fps, but libvpx and openh264 at least cannot handle this well. So propose a fix to update first timestamp after tracker window drained. This will give more accurate fps estimate similar based on active window after sample gets drained Bug: webrtc:13403 Change-Id: I96792c11091fe8bfa63e669f4360a3b3e95593e1 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/237720 Reviewed-by: Harald Alvestrand <hta@webrtc.org> Reviewed-by: Stefan Holmer <stefan@webrtc.org> Commit-Queue: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#35447}
This commit is contained in:
parent
f0290eb6fd
commit
4774a9fcb8
2 changed files with 12 additions and 4 deletions
|
@ -58,7 +58,7 @@ void RateStatistics::Update(int64_t count, int64_t now_ms) {
|
|||
RTC_DCHECK_GE(count, 0);
|
||||
|
||||
EraseOld(now_ms);
|
||||
if (first_timestamp_ == -1) {
|
||||
if (first_timestamp_ == -1 || num_samples_ == 0) {
|
||||
first_timestamp_ = now_ms;
|
||||
}
|
||||
|
||||
|
|
|
@ -148,14 +148,15 @@ TEST_F(RateStatisticsTest, ResetAfterSilence) {
|
|||
|
||||
now_ms += kWindowMs + 1;
|
||||
EXPECT_FALSE(static_cast<bool>(stats_.Rate(now_ms)));
|
||||
// Silence over window size should trigger auto reset for coming sample.
|
||||
stats_.Update(1000, now_ms);
|
||||
++now_ms;
|
||||
stats_.Update(1000, now_ms);
|
||||
// We expect two samples of 1000 bytes, and that the bitrate is measured over
|
||||
// 500 ms, i.e. 2 * 8 * 1000 / 0.500 = 32000.
|
||||
EXPECT_EQ(32000u, *stats_.Rate(now_ms));
|
||||
// active window instead of full window, which is now_ms - first_timestamp + 1
|
||||
EXPECT_EQ(kExpectedBitrate, *stats_.Rate(now_ms));
|
||||
|
||||
// Reset, add the same samples again.
|
||||
// Manual reset, add the same samples again.
|
||||
stats_.Reset();
|
||||
EXPECT_FALSE(static_cast<bool>(stats_.Rate(now_ms)));
|
||||
stats_.Update(1000, now_ms);
|
||||
|
@ -272,9 +273,16 @@ TEST_F(RateStatisticsTest, HandlesQuietPeriods) {
|
|||
EXPECT_FALSE(static_cast<bool>(stats_.Rate(now_ms)));
|
||||
|
||||
// Move window a long way out.
|
||||
// This will cause an automatic reset of the window
|
||||
// First data point won't give a valid result
|
||||
now_ms += 2 * kWindowMs;
|
||||
stats_.Update(0, now_ms);
|
||||
bitrate = stats_.Rate(now_ms);
|
||||
EXPECT_FALSE(static_cast<bool>(stats_.Rate(now_ms)));
|
||||
// Second data point gives valid result
|
||||
++now_ms;
|
||||
stats_.Update(0, now_ms);
|
||||
bitrate = stats_.Rate(now_ms);
|
||||
EXPECT_TRUE(static_cast<bool>(bitrate));
|
||||
EXPECT_EQ(0u, *bitrate);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue