Fix RateCounter to don't fail if there are too small amount of events

Bug: webrtc:10138
Change-Id: Iac26e4948b92810245c16b8c46b4b3e70850505e
Reviewed-on: https://webrtc-review.googlesource.com/c/123193
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Commit-Queue: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26712}
This commit is contained in:
Artem Titov
2019-02-15 16:04:32 +01:00
committed by Commit Bot
parent efa72a1312
commit 6255af99a8

View File

@ -25,6 +25,7 @@ namespace {
constexpr int kMaxActiveComparisons = 10; constexpr int kMaxActiveComparisons = 10;
constexpr int kFreezeThresholdMs = 150; constexpr int kFreezeThresholdMs = 150;
constexpr int kMicrosPerSecond = 1000000;
} // namespace } // namespace
@ -38,8 +39,11 @@ void RateCounter::AddEvent(Timestamp event_time) {
double RateCounter::GetEventsPerSecond() const { double RateCounter::GetEventsPerSecond() const {
RTC_DCHECK(!IsEmpty()); RTC_DCHECK(!IsEmpty());
// Divide on us and multiply on kMicrosPerSecond to correctly process cases
// where there were too small amount of events, so difference is less then 1
// sec. We can use us here, because Timestamp has us resolution.
return static_cast<double>(event_count_) / return static_cast<double>(event_count_) /
(event_last_time_ - event_first_time_).seconds(); (event_last_time_ - event_first_time_).us() * kMicrosPerSecond;
} }
DefaultVideoQualityAnalyzer::DefaultVideoQualityAnalyzer(std::string test_label) DefaultVideoQualityAnalyzer::DefaultVideoQualityAnalyzer(std::string test_label)