Chromium Code Reviews| Index: webrtc/video/receive_statistics_proxy.cc |
| diff --git a/webrtc/video/receive_statistics_proxy.cc b/webrtc/video/receive_statistics_proxy.cc |
| index 7852a059134c47e17a198612385afd0ed35d2fa2..e51315bed5526c297a2ffeddd4e8c8e8b82aa478 100644 |
| --- a/webrtc/video/receive_statistics_proxy.cc |
| +++ b/webrtc/video/receive_statistics_proxy.cc |
| @@ -43,6 +43,9 @@ const int kHighQpThresholdVp8 = 70; |
| const int kLowVarianceThreshold = 1; |
| const int kHighVarianceThreshold = 2; |
| +// Some metrics are reported as a maximum over this period. |
| +const int kMovingMaxWindowMs = 5000; |
|
sprang_webrtc
2017/08/18 09:06:49
I think this interval needs to be longer. At least
ilnik
2017/08/18 11:43:01
Done.
|
| + |
| // How large window we use to calculate the framerate/bitrate. |
| const int kRateStatisticsWindowSizeMs = 1000; |
| } // namespace |
| @@ -78,6 +81,7 @@ ReceiveStatisticsProxy::ReceiveStatisticsProxy( |
| e2e_delay_max_ms_screenshare_(-1), |
| interframe_delay_max_ms_video_(-1), |
| interframe_delay_max_ms_screenshare_(-1), |
| + interframe_delay_max_moving_(kMovingMaxWindowMs), |
| freq_offset_counter_(clock, nullptr, kFreqOffsetProcessIntervalMs), |
| first_report_block_time_ms_(-1), |
| avg_rtt_ms_(0), |
| @@ -394,6 +398,8 @@ VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const { |
| stats_.decode_frame_rate = decode_fps_estimator_.Rate(now_ms).value_or(0); |
| stats_.total_bitrate_bps = |
| static_cast<int>(total_byte_tracker_.ComputeRate() * 8); |
| + stats_.interframe_delay_max_ms = |
| + interframe_delay_max_moving_.MovingMax(now_ms).value_or(0); |
| return stats_; |
| } |
| @@ -544,7 +550,7 @@ void ReceiveStatisticsProxy::OnDecodedFrame(rtc::Optional<uint8_t> qp, |
| if (last_decoded_frame_time_ms_) { |
| int64_t interframe_delay_ms = now - *last_decoded_frame_time_ms_; |
| RTC_DCHECK_GE(interframe_delay_ms, 0); |
| - stats_.interframe_delay_sum_ms += interframe_delay_ms; |
| + interframe_delay_max_moving_.Add(interframe_delay_ms, now); |
| if (last_content_type_ == VideoContentType::SCREENSHARE) { |
| interframe_delay_counter_screenshare_.Add(interframe_delay_ms); |
| if (interframe_delay_max_ms_screenshare_ < interframe_delay_ms) { |
| @@ -665,6 +671,45 @@ void ReceiveStatisticsProxy::SampleCounter::Reset() { |
| sum = 0; |
| } |
| +void ReceiveStatisticsProxy::MovingMaxCounter::Add(int sample, |
| + int64_t time_ms) { |
| + int64_t window_begin_ms = time_ms - window_length_ms_; |
| + // Throw out obsolete samples. |
| + while (!samples_.empty() && samples_.front().first < window_begin_ms) { |
| + samples_.pop_front(); |
| + } |
| + // Remove samples what will never be maximum in any window: newly added sample |
| + // will always be in all windows the previous samples are. Thus, smaller |
| + // samples could be removed. This will maintain the invariant - deque contains |
| + // non-increasing sequence of values. |
| + while (!samples_.empty() && samples_.back().second < sample) { |
| + samples_.pop_back(); |
| + } |
| + samples_.push_back(std::make_pair(time_ms, sample)); |
|
sprang_webrtc
2017/08/18 09:06:49
emplace_back even?
ilnik
2017/08/18 11:43:01
Done.
|
| +} |
| + |
| +rtc::Optional<int> ReceiveStatisticsProxy::MovingMaxCounter::MovingMax( |
| + int64_t time_ms) const { |
| + rtc::Optional<int> res; |
| + if (samples_.empty()) { |
| + return res; |
| + } |
| + int64_t window_begin_ms = time_ms - window_length_ms_; |
| + auto it = samples_.begin(); |
| + while (it != samples_.end() && it->first < window_begin_ms) { |
| + ++it; |
| + } |
| + if (it != samples_.end()) { |
| + res.emplace(it->second); |
| + } |
| + return res; |
| +} |
| + |
| +void ReceiveStatisticsProxy::MovingMaxCounter::Reset() { |
| + samples_.clear(); |
| +} |
| + |
| + |
| void ReceiveStatisticsProxy::OnRttUpdate(int64_t avg_rtt_ms, |
| int64_t max_rtt_ms) { |
| rtc::CritScope lock(&crit_); |