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 <cmath> | 13 #include <cmath> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 16 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
17 #include "webrtc/system_wrappers/include/clock.h" | 17 #include "webrtc/system_wrappers/include/clock.h" |
18 #include "webrtc/system_wrappers/include/metrics.h" | 18 #include "webrtc/system_wrappers/include/metrics.h" |
19 | 19 |
20 namespace webrtc { | 20 namespace webrtc { |
| 21 namespace { |
| 22 // Periodic time interval for processing samples for |freq_offset_counter_|. |
| 23 const int64_t kFreqOffsetProcessIntervalMs = 40000; |
| 24 } // namespace |
21 | 25 |
22 ReceiveStatisticsProxy::ReceiveStatisticsProxy( | 26 ReceiveStatisticsProxy::ReceiveStatisticsProxy( |
23 const VideoReceiveStream::Config* config, | 27 const VideoReceiveStream::Config* config, |
24 Clock* clock) | 28 Clock* clock) |
25 : clock_(clock), | 29 : clock_(clock), |
26 config_(*config), | 30 config_(*config), |
27 start_ms_(clock->TimeInMilliseconds()), | 31 start_ms_(clock->TimeInMilliseconds()), |
28 // 1000ms window, scale 1000 for ms to s. | 32 // 1000ms window, scale 1000 for ms to s. |
29 decode_fps_estimator_(1000, 1000), | 33 decode_fps_estimator_(1000, 1000), |
30 renders_fps_estimator_(1000, 1000), | 34 renders_fps_estimator_(1000, 1000), |
31 render_fps_tracker_(100, 10u), | 35 render_fps_tracker_(100, 10u), |
32 render_pixel_tracker_(100, 10u) { | 36 render_pixel_tracker_(100, 10u), |
| 37 freq_offset_counter_(clock, nullptr, kFreqOffsetProcessIntervalMs) { |
33 stats_.ssrc = config_.rtp.remote_ssrc; | 38 stats_.ssrc = config_.rtp.remote_ssrc; |
34 for (auto it : config_.rtp.rtx) | 39 for (auto it : config_.rtp.rtx) |
35 rtx_stats_[it.second.ssrc] = StreamDataCounters(); | 40 rtx_stats_[it.second.ssrc] = StreamDataCounters(); |
36 } | 41 } |
37 | 42 |
38 ReceiveStatisticsProxy::~ReceiveStatisticsProxy() { | 43 ReceiveStatisticsProxy::~ReceiveStatisticsProxy() { |
39 UpdateHistograms(); | 44 UpdateHistograms(); |
40 } | 45 } |
41 | 46 |
42 void ReceiveStatisticsProxy::UpdateHistograms() { | 47 void ReceiveStatisticsProxy::UpdateHistograms() { |
(...skipping 18 matching lines...) Expand all Loading... |
61 int width = render_width_counter_.Avg(kMinRequiredSamples); | 66 int width = render_width_counter_.Avg(kMinRequiredSamples); |
62 int height = render_height_counter_.Avg(kMinRequiredSamples); | 67 int height = render_height_counter_.Avg(kMinRequiredSamples); |
63 if (width != -1) { | 68 if (width != -1) { |
64 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedWidthInPixels", width); | 69 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedWidthInPixels", width); |
65 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedHeightInPixels", height); | 70 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.ReceivedHeightInPixels", height); |
66 } | 71 } |
67 int sync_offset_ms = sync_offset_counter_.Avg(kMinRequiredSamples); | 72 int sync_offset_ms = sync_offset_counter_.Avg(kMinRequiredSamples); |
68 if (sync_offset_ms != -1) { | 73 if (sync_offset_ms != -1) { |
69 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.AVSyncOffsetInMs", sync_offset_ms); | 74 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.AVSyncOffsetInMs", sync_offset_ms); |
70 } | 75 } |
| 76 AggregatedStats freq_offset_stats = freq_offset_counter_.GetStats(); |
| 77 if (freq_offset_stats.num_samples > 0) { |
| 78 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.RtpToNtpFreqOffsetInKhz", |
| 79 freq_offset_stats.average); |
| 80 } |
71 | 81 |
72 int qp = qp_counters_.vp8.Avg(kMinRequiredSamples); | 82 int qp = qp_counters_.vp8.Avg(kMinRequiredSamples); |
73 if (qp != -1) | 83 if (qp != -1) |
74 RTC_HISTOGRAM_COUNTS_200("WebRTC.Video.Decoded.Vp8.Qp", qp); | 84 RTC_HISTOGRAM_COUNTS_200("WebRTC.Video.Decoded.Vp8.Qp", qp); |
75 | 85 |
76 // TODO(asapersson): DecoderTiming() is call periodically (each 1000ms) and | 86 // TODO(asapersson): DecoderTiming() is call periodically (each 1000ms) and |
77 // not per frame. Change decode time to include every frame. | 87 // not per frame. Change decode time to include every frame. |
78 const int kMinRequiredDecodeSamples = 5; | 88 const int kMinRequiredDecodeSamples = 5; |
79 int decode_ms = decode_time_counter_.Avg(kMinRequiredDecodeSamples); | 89 int decode_ms = decode_time_counter_.Avg(kMinRequiredDecodeSamples); |
80 if (decode_ms != -1) | 90 if (decode_ms != -1) |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 render_fps_tracker_.AddSamples(1); | 279 render_fps_tracker_.AddSamples(1); |
270 render_pixel_tracker_.AddSamples(sqrt(width * height)); | 280 render_pixel_tracker_.AddSamples(sqrt(width * height)); |
271 | 281 |
272 if (frame.ntp_time_ms() > 0) { | 282 if (frame.ntp_time_ms() > 0) { |
273 int64_t delay_ms = clock_->CurrentNtpInMilliseconds() - frame.ntp_time_ms(); | 283 int64_t delay_ms = clock_->CurrentNtpInMilliseconds() - frame.ntp_time_ms(); |
274 if (delay_ms >= 0) | 284 if (delay_ms >= 0) |
275 e2e_delay_counter_.Add(delay_ms); | 285 e2e_delay_counter_.Add(delay_ms); |
276 } | 286 } |
277 } | 287 } |
278 | 288 |
279 void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t sync_offset_ms) { | 289 void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t sync_offset_ms, |
| 290 double estimated_freq_khz) { |
280 rtc::CritScope lock(&crit_); | 291 rtc::CritScope lock(&crit_); |
281 sync_offset_counter_.Add(std::abs(sync_offset_ms)); | 292 sync_offset_counter_.Add(std::abs(sync_offset_ms)); |
282 stats_.sync_offset_ms = sync_offset_ms; | 293 stats_.sync_offset_ms = sync_offset_ms; |
| 294 |
| 295 const double kMaxFreqKhz = 10000.0; |
| 296 int offset_khz = kMaxFreqKhz; |
| 297 // Should not be zero or negative. If so, report max. |
| 298 if (estimated_freq_khz < kMaxFreqKhz && estimated_freq_khz > 0.0) |
| 299 offset_khz = static_cast<int>(std::fabs(estimated_freq_khz - 90.0) + 0.5); |
| 300 |
| 301 freq_offset_counter_.Add(offset_khz); |
283 } | 302 } |
284 | 303 |
285 void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate, | 304 void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate, |
286 uint32_t frameRate) { | 305 uint32_t frameRate) { |
287 } | 306 } |
288 | 307 |
289 void ReceiveStatisticsProxy::OnFrameCountsUpdated( | 308 void ReceiveStatisticsProxy::OnFrameCountsUpdated( |
290 const FrameCounts& frame_counts) { | 309 const FrameCounts& frame_counts) { |
291 rtc::CritScope lock(&crit_); | 310 rtc::CritScope lock(&crit_); |
292 stats_.frame_counts = frame_counts; | 311 stats_.frame_counts = frame_counts; |
(...skipping 20 matching lines...) Expand all Loading... |
313 ++num_samples; | 332 ++num_samples; |
314 } | 333 } |
315 | 334 |
316 int ReceiveStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { | 335 int ReceiveStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { |
317 if (num_samples < min_required_samples || num_samples == 0) | 336 if (num_samples < min_required_samples || num_samples == 0) |
318 return -1; | 337 return -1; |
319 return sum / num_samples; | 338 return sum / num_samples; |
320 } | 339 } |
321 | 340 |
322 } // namespace webrtc | 341 } // namespace webrtc |
OLD | NEW |