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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 render_fps_tracker_.AddSamples(1); | 278 render_fps_tracker_.AddSamples(1); |
269 render_pixel_tracker_.AddSamples(sqrt(width * height)); | 279 render_pixel_tracker_.AddSamples(sqrt(width * height)); |
270 | 280 |
271 if (frame.ntp_time_ms() > 0) { | 281 if (frame.ntp_time_ms() > 0) { |
272 int64_t delay_ms = clock_->CurrentNtpInMilliseconds() - frame.ntp_time_ms(); | 282 int64_t delay_ms = clock_->CurrentNtpInMilliseconds() - frame.ntp_time_ms(); |
273 if (delay_ms >= 0) | 283 if (delay_ms >= 0) |
274 e2e_delay_counter_.Add(delay_ms); | 284 e2e_delay_counter_.Add(delay_ms); |
275 } | 285 } |
276 } | 286 } |
277 | 287 |
278 void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t sync_offset_ms) { | 288 void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t sync_offset_ms, |
| 289 double estimated_freq_khz) { |
279 rtc::CritScope lock(&crit_); | 290 rtc::CritScope lock(&crit_); |
280 sync_offset_counter_.Add(std::abs(sync_offset_ms)); | 291 sync_offset_counter_.Add(std::abs(sync_offset_ms)); |
281 stats_.sync_offset_ms = sync_offset_ms; | 292 stats_.sync_offset_ms = sync_offset_ms; |
| 293 |
| 294 const double kMaxFreqKhz = 10000.0; |
| 295 int offset_khz = kMaxFreqKhz; |
| 296 // Should not be zero or negative. If so, report max. |
| 297 if (estimated_freq_khz < kMaxFreqKhz && estimated_freq_khz > 0.0) |
| 298 offset_khz = static_cast<int>(std::fabs(estimated_freq_khz - 90.0) + 0.5); |
| 299 |
| 300 freq_offset_counter_.Add(offset_khz); |
282 } | 301 } |
283 | 302 |
284 void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate, | 303 void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate, |
285 uint32_t frameRate) { | 304 uint32_t frameRate) { |
286 } | 305 } |
287 | 306 |
288 void ReceiveStatisticsProxy::OnFrameCountsUpdated( | 307 void ReceiveStatisticsProxy::OnFrameCountsUpdated( |
289 const FrameCounts& frame_counts) { | 308 const FrameCounts& frame_counts) { |
290 rtc::CritScope lock(&crit_); | 309 rtc::CritScope lock(&crit_); |
291 stats_.frame_counts = frame_counts; | 310 stats_.frame_counts = frame_counts; |
(...skipping 20 matching lines...) Expand all Loading... |
312 ++num_samples; | 331 ++num_samples; |
313 } | 332 } |
314 | 333 |
315 int ReceiveStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { | 334 int ReceiveStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { |
316 if (num_samples < min_required_samples || num_samples == 0) | 335 if (num_samples < min_required_samples || num_samples == 0) |
317 return -1; | 336 return -1; |
318 return sum / num_samples; | 337 return sum / num_samples; |
319 } | 338 } |
320 | 339 |
321 } // namespace webrtc | 340 } // namespace webrtc |
OLD | NEW |