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 3f23c0047a51bf80f81c2aa01e658e9e487a9167..46c97a3cf417b96751710f1cf747af4575a0830f 100644 |
| --- a/webrtc/video/receive_statistics_proxy.cc |
| +++ b/webrtc/video/receive_statistics_proxy.cc |
| @@ -10,7 +10,9 @@ |
| #include "webrtc/video/receive_statistics_proxy.h" |
| +#include <algorithm> |
| #include <cmath> |
| +#include <utility> |
| #include "webrtc/base/checks.h" |
| #include "webrtc/base/logging.h" |
| @@ -39,6 +41,9 @@ const int kLowQpThresholdVp8 = 60; |
| const int kHighQpThresholdVp8 = 70; |
| const int kLowVarianceThreshold = 1; |
| const int kHighVarianceThreshold = 2; |
| + |
| +// How large window we use to calculate the framerate/bitrate. |
| +const int kRateStatisticsWindowSizeMs = 1000; |
| } // namespace |
| ReceiveStatisticsProxy::ReceiveStatisticsProxy( |
| @@ -66,7 +71,8 @@ ReceiveStatisticsProxy::ReceiveStatisticsProxy( |
| render_fps_tracker_(100, 10u), |
| render_pixel_tracker_(100, 10u), |
| freq_offset_counter_(clock, nullptr, kFreqOffsetProcessIntervalMs), |
| - first_report_block_time_ms_(-1) { |
| + first_report_block_time_ms_(-1), |
| + avg_rtt_ms_(0) { |
| stats_.ssrc = config_.rtp.remote_ssrc; |
| for (auto it : config_.rtp.rtx) |
| rtx_stats_[it.second.ssrc] = StreamDataCounters(); |
| @@ -118,6 +124,17 @@ void ReceiveStatisticsProxy::UpdateHistograms() { |
| << freq_offset_stats.ToString(); |
| } |
| + if (stats_.frame_counts.key_frames > 0 || |
| + stats_.frame_counts.delta_frames > 0) { |
| + float num_key_frames = stats_.frame_counts.key_frames; |
| + float num_total_frames = |
| + stats_.frame_counts.key_frames + stats_.frame_counts.delta_frames; |
| + int key_frames_permille = |
| + (num_key_frames * 1000.0f / num_total_frames + 0.5f); |
| + RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.KeyFramesReceivedInPermille", |
| + key_frames_permille); |
| + } |
| + |
| int qp = qp_counters_.vp8.Avg(kMinRequiredSamples); |
| if (qp != -1) |
| RTC_HISTOGRAM_COUNTS_200("WebRTC.Video.Decoded.Vp8.Qp", qp); |
| @@ -129,15 +146,12 @@ void ReceiveStatisticsProxy::UpdateHistograms() { |
| if (decode_ms != -1) |
| RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DecodeTimeInMs", decode_ms); |
| - if (field_trial::FindFullName("WebRTC-NewVideoJitterBuffer") != |
| - "Enabled") { |
| - int jb_delay_ms = |
| - jitter_buffer_delay_counter_.Avg(kMinRequiredDecodeSamples); |
| - if (jb_delay_ms != -1) { |
| - RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs", |
| - jb_delay_ms); |
| - } |
| + int jb_delay_ms = jitter_buffer_delay_counter_.Avg(kMinRequiredDecodeSamples); |
| + if (jb_delay_ms != -1) { |
| + RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs", |
| + jb_delay_ms); |
| } |
| + |
| int target_delay_ms = target_delay_counter_.Avg(kMinRequiredDecodeSamples); |
| if (target_delay_ms != -1) { |
| RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.TargetDelayInMs", target_delay_ms); |
| @@ -264,8 +278,25 @@ void ReceiveStatisticsProxy::QualitySample() { |
| qp_sample_.Reset(); |
| } |
| +void ReceiveStatisticsProxy::UpdateFrameAndBitrate(int64_t now_ms) const { |
| + int64_t old_frames_ms = now_ms - kRateStatisticsWindowSizeMs; |
| + while (!frame_window_.empty() && |
| + frame_window_.begin()->first < old_frames_ms) { |
| + frame_window_accumulated_bytes_ -= frame_window_.begin()->second; |
| + frame_window_.erase(frame_window_.begin()); |
| + } |
| + |
| + int framerate = |
| + (frame_window_.size() * 1000 + 500) / kRateStatisticsWindowSizeMs; |
| + size_t bitrate_bps = |
| + frame_window_accumulated_bytes_ * 8000 / kRateStatisticsWindowSizeMs; |
| + stats_.network_frame_rate = framerate; |
| + stats_.total_bitrate_bps = bitrate_bps; |
| +} |
| + |
| VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const { |
| rtc::CritScope lock(&crit_); |
| + UpdateFrameAndBitrate(clock_->TimeInMilliseconds()); |
| return stats_; |
| } |
| @@ -283,8 +314,6 @@ void ReceiveStatisticsProxy::OnIncomingRate(unsigned int framerate, |
| unsigned int bitrate_bps) { |
| rtc::CritScope lock(&crit_); |
| QualitySample(); |
|
philipel
2017/01/11 16:12:34
This function is still called about every second f
stefan-webrtc
2017/01/12 14:16:15
Ouch... Why is it called here? Can we move it to s
philipel
2017/01/12 16:41:35
I will take a look at it in one of my clean up CLs
|
| - stats_.network_frame_rate = framerate; |
| - stats_.total_bitrate_bps = bitrate_bps; |
| } |
| void ReceiveStatisticsProxy::OnDecoderTiming(int decode_ms, |
| @@ -293,8 +322,7 @@ void ReceiveStatisticsProxy::OnDecoderTiming(int decode_ms, |
| int target_delay_ms, |
| int jitter_buffer_ms, |
| int min_playout_delay_ms, |
| - int render_delay_ms, |
| - int64_t rtt_ms) { |
| + int render_delay_ms) { |
| rtc::CritScope lock(&crit_); |
| stats_.decode_ms = decode_ms; |
| stats_.max_decode_ms = max_decode_ms; |
| @@ -309,7 +337,7 @@ void ReceiveStatisticsProxy::OnDecoderTiming(int decode_ms, |
| current_delay_counter_.Add(current_delay_ms); |
| // Network delay (rtt/2) + target_delay_ms (jitter delay + decode time + |
| // render delay). |
| - delay_counter_.Add(target_delay_ms + rtt_ms / 2); |
| + delay_counter_.Add(target_delay_ms + avg_rtt_ms_ / 2); |
| } |
| void ReceiveStatisticsProxy::RtcpPacketTypesCounterUpdated( |
| @@ -413,6 +441,20 @@ void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate, |
| uint32_t frameRate) { |
| } |
| +void ReceiveStatisticsProxy::OnCompleteFrame(bool is_keyframe, |
| + size_t size_bytes) { |
| + rtc::CritScope lock(&crit_); |
| + if (is_keyframe) |
| + ++stats_.frame_counts.key_frames; |
| + else |
| + ++stats_.frame_counts.delta_frames; |
| + |
| + int64_t now_ms = clock_->TimeInMilliseconds(); |
| + frame_window_accumulated_bytes_ += size_bytes; |
| + frame_window_.insert(std::make_pair(now_ms, size_bytes)); |
| + UpdateFrameAndBitrate(now_ms); |
| +} |
| + |
| void ReceiveStatisticsProxy::OnFrameCountsUpdated( |
| const FrameCounts& frame_counts) { |
| rtc::CritScope lock(&crit_); |
| @@ -454,4 +496,10 @@ void ReceiveStatisticsProxy::SampleCounter::Reset() { |
| sum = 0; |
| } |
| +void ReceiveStatisticsProxy::OnRttUpdate(int64_t avg_rtt_ms, |
| + int64_t max_rtt_ms) { |
| + rtc::CritScope lock(&crit_); |
| + avg_rtt_ms_ = avg_rtt_ms; |
| +} |
| + |
| } // namespace webrtc |