OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/video/receive_statistics_proxy.h" | 11 #include "webrtc/video/receive_statistics_proxy.h" |
12 | 12 |
13 #include "webrtc/system_wrappers/interface/clock.h" | 13 #include "webrtc/system_wrappers/interface/clock.h" |
14 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 14 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
15 #include "webrtc/system_wrappers/interface/metrics.h" | 15 #include "webrtc/system_wrappers/interface/metrics.h" |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
18 | 18 |
19 ReceiveStatisticsProxy::ReceiveStatisticsProxy(uint32_t ssrc, Clock* clock) | 19 ReceiveStatisticsProxy::ReceiveStatisticsProxy(uint32_t ssrc, Clock* clock) |
20 : clock_(clock), | 20 : clock_(clock), |
21 // 1000ms window, scale 1000 for ms to s. | 21 // 1000ms window, scale 1000 for ms to s. |
22 decode_fps_estimator_(1000, 1000), | 22 decode_fps_estimator_(1000, 1000), |
23 renders_fps_estimator_(1000, 1000) { | 23 renders_fps_estimator_(1000, 1000), |
| 24 render_fps_tracker_(100u, 10u) { |
24 stats_.ssrc = ssrc; | 25 stats_.ssrc = ssrc; |
25 } | 26 } |
26 | 27 |
27 ReceiveStatisticsProxy::~ReceiveStatisticsProxy() { | 28 ReceiveStatisticsProxy::~ReceiveStatisticsProxy() { |
28 UpdateHistograms(); | 29 UpdateHistograms(); |
29 } | 30 } |
30 | 31 |
31 void ReceiveStatisticsProxy::UpdateHistograms() { | 32 void ReceiveStatisticsProxy::UpdateHistograms() { |
32 int fraction_lost = report_block_stats_.FractionLostInPercent(); | 33 int fraction_lost = report_block_stats_.FractionLostInPercent(); |
33 if (fraction_lost != -1) { | 34 if (fraction_lost != -1) { |
34 RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.ReceivedPacketsLostInPercent", | 35 RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.ReceivedPacketsLostInPercent", |
35 fraction_lost); | 36 fraction_lost); |
36 } | 37 } |
37 | 38 |
38 int render_fps = static_cast<int>(render_fps_tracker_total_.units_second()); | 39 int render_fps = static_cast<int>(render_fps_tracker_.ComputeTotalRate()); |
39 if (render_fps > 0) | 40 if (render_fps > 0) |
40 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.RenderFramesPerSecond", render_fps); | 41 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.RenderFramesPerSecond", render_fps); |
41 | 42 |
42 const int kMinRequiredSamples = 200; | 43 const int kMinRequiredSamples = 200; |
43 int width = render_width_counter_.Avg(kMinRequiredSamples); | 44 int width = render_width_counter_.Avg(kMinRequiredSamples); |
44 int height = render_height_counter_.Avg(kMinRequiredSamples); | 45 int height = render_height_counter_.Avg(kMinRequiredSamples); |
45 if (width != -1) { | 46 if (width != -1) { |
46 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedWidthInPixels", width); | 47 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedWidthInPixels", width); |
47 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedHeightInPixels", height); | 48 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedHeightInPixels", height); |
48 } | 49 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 134 } |
134 | 135 |
135 void ReceiveStatisticsProxy::OnRenderedFrame(int width, int height) { | 136 void ReceiveStatisticsProxy::OnRenderedFrame(int width, int height) { |
136 uint64_t now = clock_->TimeInMilliseconds(); | 137 uint64_t now = clock_->TimeInMilliseconds(); |
137 | 138 |
138 rtc::CritScope lock(&crit_); | 139 rtc::CritScope lock(&crit_); |
139 renders_fps_estimator_.Update(1, now); | 140 renders_fps_estimator_.Update(1, now); |
140 stats_.render_frame_rate = renders_fps_estimator_.Rate(now); | 141 stats_.render_frame_rate = renders_fps_estimator_.Rate(now); |
141 render_width_counter_.Add(width); | 142 render_width_counter_.Add(width); |
142 render_height_counter_.Add(height); | 143 render_height_counter_.Add(height); |
143 render_fps_tracker_total_.Update(1); | 144 render_fps_tracker_.AddSamples(1); |
144 } | 145 } |
145 | 146 |
146 void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate, | 147 void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate, |
147 uint32_t frameRate) { | 148 uint32_t frameRate) { |
148 } | 149 } |
149 | 150 |
150 void ReceiveStatisticsProxy::OnFrameCountsUpdated( | 151 void ReceiveStatisticsProxy::OnFrameCountsUpdated( |
151 const FrameCounts& frame_counts) { | 152 const FrameCounts& frame_counts) { |
152 rtc::CritScope lock(&crit_); | 153 rtc::CritScope lock(&crit_); |
153 stats_.frame_counts = frame_counts; | 154 stats_.frame_counts = frame_counts; |
154 } | 155 } |
155 | 156 |
156 void ReceiveStatisticsProxy::OnDiscardedPacketsUpdated(int discarded_packets) { | 157 void ReceiveStatisticsProxy::OnDiscardedPacketsUpdated(int discarded_packets) { |
157 rtc::CritScope lock(&crit_); | 158 rtc::CritScope lock(&crit_); |
158 stats_.discarded_packets = discarded_packets; | 159 stats_.discarded_packets = discarded_packets; |
159 } | 160 } |
160 | 161 |
161 void ReceiveStatisticsProxy::SampleCounter::Add(int sample) { | 162 void ReceiveStatisticsProxy::SampleCounter::Add(int sample) { |
162 sum += sample; | 163 sum += sample; |
163 ++num_samples; | 164 ++num_samples; |
164 } | 165 } |
165 | 166 |
166 int ReceiveStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { | 167 int ReceiveStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { |
167 if (num_samples < min_required_samples || num_samples == 0) | 168 if (num_samples < min_required_samples || num_samples == 0) |
168 return -1; | 169 return -1; |
169 return sum / num_samples; | 170 return sum / num_samples; |
170 } | 171 } |
171 | 172 |
172 } // namespace webrtc | 173 } // namespace webrtc |
OLD | NEW |