sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "video/receive_statistics_proxy.h" |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 12 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 13 | #include <algorithm> |
asapersson | f839dcc | 2015-10-08 00:41:59 -0700 | [diff] [blame] | 14 | #include <cmath> |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 15 | #include <utility> |
asapersson | f839dcc | 2015-10-08 00:41:59 -0700 | [diff] [blame] | 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/video_coding/include/video_codec_interface.h" |
| 18 | #include "rtc_base/checks.h" |
| 19 | #include "rtc_base/logging.h" |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 20 | #include "rtc_base/strings/string_builder.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 21 | #include "rtc_base/time_utils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "system_wrappers/include/clock.h" |
| 23 | #include "system_wrappers/include/metrics.h" |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 26 | namespace { |
| 27 | // Periodic time interval for processing samples for |freq_offset_counter_|. |
| 28 | const int64_t kFreqOffsetProcessIntervalMs = 40000; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 29 | |
| 30 | // Configuration for bad call detection. |
palmkvist | a40672a | 2017-01-13 05:58:34 -0800 | [diff] [blame] | 31 | const int kBadCallMinRequiredSamples = 10; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 32 | const int kMinSampleLengthMs = 990; |
| 33 | const int kNumMeasurements = 10; |
| 34 | const int kNumMeasurementsVariance = kNumMeasurements * 1.5; |
| 35 | const float kBadFraction = 0.8f; |
| 36 | // For fps: |
| 37 | // Low means low enough to be bad, high means high enough to be good |
| 38 | const int kLowFpsThreshold = 12; |
| 39 | const int kHighFpsThreshold = 14; |
| 40 | // For qp and fps variance: |
| 41 | // Low means low enough to be good, high means high enough to be bad |
| 42 | const int kLowQpThresholdVp8 = 60; |
| 43 | const int kHighQpThresholdVp8 = 70; |
| 44 | const int kLowVarianceThreshold = 1; |
| 45 | const int kHighVarianceThreshold = 2; |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 46 | |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 47 | // Some metrics are reported as a maximum over this period. |
Ilya Nikolaevskiy | b06b358 | 2017-10-16 17:59:12 +0200 | [diff] [blame] | 48 | // This should be synchronized with a typical getStats polling interval in |
| 49 | // the clients. |
| 50 | const int kMovingMaxWindowMs = 1000; |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 51 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 52 | // How large window we use to calculate the framerate/bitrate. |
| 53 | const int kRateStatisticsWindowSizeMs = 1000; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 54 | |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 55 | // Some sane ballpark estimate for maximum common value of inter-frame delay. |
| 56 | // Values below that will be stored explicitly in the array, |
| 57 | // values above - in the map. |
| 58 | const int kMaxCommonInterframeDelayMs = 500; |
| 59 | |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 60 | const char* UmaPrefixForContentType(VideoContentType content_type) { |
| 61 | if (videocontenttypehelpers::IsScreenshare(content_type)) |
| 62 | return "WebRTC.Video.Screenshare"; |
| 63 | return "WebRTC.Video"; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | std::string UmaSuffixForContentType(VideoContentType content_type) { |
Karl Wiberg | 881f168 | 2018-03-08 15:03:23 +0100 | [diff] [blame] | 67 | char ss_buf[1024]; |
| 68 | rtc::SimpleStringBuilder ss(ss_buf); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 69 | int simulcast_id = videocontenttypehelpers::GetSimulcastId(content_type); |
| 70 | if (simulcast_id > 0) { |
| 71 | ss << ".S" << simulcast_id - 1; |
| 72 | } |
| 73 | int experiment_id = videocontenttypehelpers::GetExperimentId(content_type); |
| 74 | if (experiment_id > 0) { |
| 75 | ss << ".ExperimentGroup" << experiment_id - 1; |
| 76 | } |
| 77 | return ss.str(); |
| 78 | } |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 79 | |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 80 | } // namespace |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 81 | |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 82 | ReceiveStatisticsProxy::ReceiveStatisticsProxy( |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 83 | const VideoReceiveStream::Config* config, |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 84 | Clock* clock) |
pbos@webrtc.org | 5570769 | 2014-12-19 15:45:03 +0000 | [diff] [blame] | 85 | : clock_(clock), |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 86 | config_(*config), |
asapersson | 4374a09 | 2016-07-27 00:39:09 -0700 | [diff] [blame] | 87 | start_ms_(clock->TimeInMilliseconds()), |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 88 | last_sample_time_(clock->TimeInMilliseconds()), |
| 89 | fps_threshold_(kLowFpsThreshold, |
| 90 | kHighFpsThreshold, |
| 91 | kBadFraction, |
| 92 | kNumMeasurements), |
| 93 | qp_threshold_(kLowQpThresholdVp8, |
| 94 | kHighQpThresholdVp8, |
| 95 | kBadFraction, |
| 96 | kNumMeasurements), |
| 97 | variance_threshold_(kLowVarianceThreshold, |
| 98 | kHighVarianceThreshold, |
| 99 | kBadFraction, |
| 100 | kNumMeasurementsVariance), |
palmkvist | a40672a | 2017-01-13 05:58:34 -0800 | [diff] [blame] | 101 | num_bad_states_(0), |
| 102 | num_certain_states_(0), |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 103 | // 1000ms window, scale 1000 for ms to s. |
| 104 | decode_fps_estimator_(1000, 1000), |
Tim Psiaki | 6304626 | 2015-09-14 10:38:08 -0700 | [diff] [blame] | 105 | renders_fps_estimator_(1000, 1000), |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 106 | render_fps_tracker_(100, 10u), |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 107 | render_pixel_tracker_(100, 10u), |
asapersson | 0255acb | 2017-03-28 02:44:58 -0700 | [diff] [blame] | 108 | total_byte_tracker_(100, 10u), // bucket_interval_ms, bucket_count |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 109 | video_quality_observer_( |
| 110 | new VideoQualityObserver(VideoContentType::UNSPECIFIED)), |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 111 | interframe_delay_max_moving_(kMovingMaxWindowMs), |
asapersson | 0c43f77 | 2016-11-30 01:42:26 -0800 | [diff] [blame] | 112 | freq_offset_counter_(clock, nullptr, kFreqOffsetProcessIntervalMs), |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 113 | first_report_block_time_ms_(-1), |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 114 | avg_rtt_ms_(0), |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 115 | last_content_type_(VideoContentType::UNSPECIFIED), |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 116 | last_codec_type_(kVideoCodecVP8), |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 117 | num_delayed_frames_rendered_(0), |
| 118 | sum_missed_render_deadline_ms_(0), |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 119 | timing_frame_info_counter_(kMovingMaxWindowMs) { |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 120 | decode_thread_.DetachFromThread(); |
| 121 | network_thread_.DetachFromThread(); |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 122 | stats_.ssrc = config_.rtp.remote_ssrc; |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 123 | // TODO(brandtr): Replace |rtx_stats_| with a single instance of |
| 124 | // StreamDataCounters. |
| 125 | if (config_.rtp.rtx_ssrc) { |
| 126 | rtx_stats_[config_.rtp.rtx_ssrc] = StreamDataCounters(); |
| 127 | } |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 128 | } |
| 129 | |
Åsa Persson | 3c391cb | 2015-04-27 10:09:49 +0200 | [diff] [blame] | 130 | ReceiveStatisticsProxy::~ReceiveStatisticsProxy() { |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 131 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 132 | // In case you're reading this wondering "hmm... we're on the main thread but |
| 133 | // calling a method that needs to be called on the decoder thread...", then |
| 134 | // here's what's going on: |
| 135 | // - The decoder thread has been stopped and DecoderThreadStopped() has been |
| 136 | // called. |
| 137 | // - The decode_thread_ thread checker has been detached, and will now become |
| 138 | // attached to the current thread, which is OK since we're in the dtor. |
Åsa Persson | 3c391cb | 2015-04-27 10:09:49 +0200 | [diff] [blame] | 139 | UpdateHistograms(); |
| 140 | } |
| 141 | |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 142 | void ReceiveStatisticsProxy::UpdateHistograms() { |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 143 | RTC_DCHECK_RUN_ON(&decode_thread_); |
Karl Wiberg | 881f168 | 2018-03-08 15:03:23 +0100 | [diff] [blame] | 144 | char log_stream_buf[8 * 1024]; |
| 145 | rtc::SimpleStringBuilder log_stream(log_stream_buf); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 146 | int stream_duration_sec = (clock_->TimeInMilliseconds() - start_ms_) / 1000; |
| 147 | if (stats_.frame_counts.key_frames > 0 || |
| 148 | stats_.frame_counts.delta_frames > 0) { |
| 149 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Video.ReceiveStreamLifetimeInSeconds", |
| 150 | stream_duration_sec); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 151 | log_stream << "WebRTC.Video.ReceiveStreamLifetimeInSeconds " |
| 152 | << stream_duration_sec << '\n'; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 153 | } |
asapersson | 4374a09 | 2016-07-27 00:39:09 -0700 | [diff] [blame] | 154 | |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 155 | log_stream << "Frames decoded " << stats_.frames_decoded << '\n'; |
Ilya Nikolaevskiy | d397a0d | 2018-02-21 15:57:09 +0100 | [diff] [blame] | 156 | |
| 157 | if (num_unique_frames_) { |
| 158 | int num_dropped_frames = *num_unique_frames_ - stats_.frames_decoded; |
| 159 | RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DroppedFrames.Receiver", |
| 160 | num_dropped_frames); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 161 | log_stream << "WebRTC.Video.DroppedFrames.Receiver " << num_dropped_frames |
| 162 | << '\n'; |
Ilya Nikolaevskiy | d397a0d | 2018-02-21 15:57:09 +0100 | [diff] [blame] | 163 | } |
| 164 | |
asapersson | 0c43f77 | 2016-11-30 01:42:26 -0800 | [diff] [blame] | 165 | if (first_report_block_time_ms_ != -1 && |
| 166 | ((clock_->TimeInMilliseconds() - first_report_block_time_ms_) / 1000) >= |
| 167 | metrics::kMinRunTimeInSeconds) { |
| 168 | int fraction_lost = report_block_stats_.FractionLostInPercent(); |
| 169 | if (fraction_lost != -1) { |
| 170 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.ReceivedPacketsLostInPercent", |
| 171 | fraction_lost); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 172 | log_stream << "WebRTC.Video.ReceivedPacketsLostInPercent " |
| 173 | << fraction_lost << '\n'; |
asapersson | 0c43f77 | 2016-11-30 01:42:26 -0800 | [diff] [blame] | 174 | } |
Åsa Persson | 3c391cb | 2015-04-27 10:09:49 +0200 | [diff] [blame] | 175 | } |
asapersson | 0c43f77 | 2016-11-30 01:42:26 -0800 | [diff] [blame] | 176 | |
Åsa Persson | b9b07ea | 2018-01-24 17:04:07 +0100 | [diff] [blame] | 177 | if (first_decoded_frame_time_ms_) { |
| 178 | const int64_t elapsed_ms = |
| 179 | (clock_->TimeInMilliseconds() - *first_decoded_frame_time_ms_); |
| 180 | if (elapsed_ms >= |
| 181 | metrics::kMinRunTimeInSeconds * rtc::kNumMillisecsPerSec) { |
| 182 | RTC_HISTOGRAM_COUNTS_100( |
| 183 | "WebRTC.Video.DecodedFramesPerSecond", |
| 184 | static_cast<int>((stats_.frames_decoded * 1000.0f / elapsed_ms) + |
| 185 | 0.5f)); |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 186 | |
| 187 | const uint32_t frames_rendered = stats_.frames_rendered; |
| 188 | if (frames_rendered > 0) { |
| 189 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.DelayedFramesToRenderer", |
| 190 | static_cast<int>(num_delayed_frames_rendered_ * |
| 191 | 100 / frames_rendered)); |
| 192 | if (num_delayed_frames_rendered_ > 0) { |
| 193 | RTC_HISTOGRAM_COUNTS_1000( |
| 194 | "WebRTC.Video.DelayedFramesToRenderer_AvgDelayInMs", |
| 195 | static_cast<int>(sum_missed_render_deadline_ms_ / |
| 196 | num_delayed_frames_rendered_)); |
| 197 | } |
| 198 | } |
Åsa Persson | b9b07ea | 2018-01-24 17:04:07 +0100 | [diff] [blame] | 199 | } |
| 200 | } |
| 201 | |
asapersson | 6718e97 | 2015-07-24 00:20:58 -0700 | [diff] [blame] | 202 | const int kMinRequiredSamples = 200; |
asapersson | f839dcc | 2015-10-08 00:41:59 -0700 | [diff] [blame] | 203 | int samples = static_cast<int>(render_fps_tracker_.TotalSampleCount()); |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 204 | if (samples >= kMinRequiredSamples) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 205 | RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.RenderFramesPerSecond", |
| 206 | round(render_fps_tracker_.ComputeTotalRate())); |
| 207 | RTC_HISTOGRAM_COUNTS_100000( |
asapersson | 28ba927 | 2016-01-25 05:58:23 -0800 | [diff] [blame] | 208 | "WebRTC.Video.RenderSqrtPixelsPerSecond", |
Tim Psiaki | ad13d2f | 2015-11-10 16:34:50 -0800 | [diff] [blame] | 209 | round(render_pixel_tracker_.ComputeTotalRate())); |
asapersson | f839dcc | 2015-10-08 00:41:59 -0700 | [diff] [blame] | 210 | } |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 211 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 212 | absl::optional<int> sync_offset_ms = |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 213 | sync_offset_counter_.Avg(kMinRequiredSamples); |
| 214 | if (sync_offset_ms) { |
| 215 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.AVSyncOffsetInMs", |
| 216 | *sync_offset_ms); |
| 217 | log_stream << "WebRTC.Video.AVSyncOffsetInMs " << *sync_offset_ms << '\n'; |
pbos | 35fdb2a | 2016-05-03 03:32:10 -0700 | [diff] [blame] | 218 | } |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 219 | AggregatedStats freq_offset_stats = freq_offset_counter_.GetStats(); |
| 220 | if (freq_offset_stats.num_samples > 0) { |
| 221 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.RtpToNtpFreqOffsetInKhz", |
| 222 | freq_offset_stats.average); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 223 | log_stream << "WebRTC.Video.RtpToNtpFreqOffsetInKhz " |
| 224 | << freq_offset_stats.ToString() << '\n'; |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 225 | } |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 226 | |
asapersson | b99baf8 | 2017-04-20 04:05:43 -0700 | [diff] [blame] | 227 | int num_total_frames = |
| 228 | stats_.frame_counts.key_frames + stats_.frame_counts.delta_frames; |
| 229 | if (num_total_frames >= kMinRequiredSamples) { |
| 230 | int num_key_frames = stats_.frame_counts.key_frames; |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 231 | int key_frames_permille = |
asapersson | b99baf8 | 2017-04-20 04:05:43 -0700 | [diff] [blame] | 232 | (num_key_frames * 1000 + num_total_frames / 2) / num_total_frames; |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 233 | RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.KeyFramesReceivedInPermille", |
| 234 | key_frames_permille); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 235 | log_stream << "WebRTC.Video.KeyFramesReceivedInPermille " |
| 236 | << key_frames_permille << '\n'; |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 239 | absl::optional<int> qp = qp_counters_.vp8.Avg(kMinRequiredSamples); |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 240 | if (qp) { |
| 241 | RTC_HISTOGRAM_COUNTS_200("WebRTC.Video.Decoded.Vp8.Qp", *qp); |
| 242 | log_stream << "WebRTC.Video.Decoded.Vp8.Qp " << *qp << '\n'; |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 243 | } |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 244 | absl::optional<int> decode_ms = decode_time_counter_.Avg(kMinRequiredSamples); |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 245 | if (decode_ms) { |
| 246 | RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.DecodeTimeInMs", *decode_ms); |
| 247 | log_stream << "WebRTC.Video.DecodeTimeInMs " << *decode_ms << '\n'; |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 248 | } |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 249 | absl::optional<int> jb_delay_ms = |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 250 | jitter_buffer_delay_counter_.Avg(kMinRequiredSamples); |
| 251 | if (jb_delay_ms) { |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 252 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs", |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 253 | *jb_delay_ms); |
| 254 | log_stream << "WebRTC.Video.JitterBufferDelayInMs " << *jb_delay_ms << '\n'; |
asapersson | 8688a4e | 2016-04-27 23:42:35 -0700 | [diff] [blame] | 255 | } |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 256 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 257 | absl::optional<int> target_delay_ms = |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 258 | target_delay_counter_.Avg(kMinRequiredSamples); |
| 259 | if (target_delay_ms) { |
| 260 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.TargetDelayInMs", |
| 261 | *target_delay_ms); |
| 262 | log_stream << "WebRTC.Video.TargetDelayInMs " << *target_delay_ms << '\n'; |
asapersson | 8688a4e | 2016-04-27 23:42:35 -0700 | [diff] [blame] | 263 | } |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 264 | absl::optional<int> current_delay_ms = |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 265 | current_delay_counter_.Avg(kMinRequiredSamples); |
| 266 | if (current_delay_ms) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 267 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.CurrentDelayInMs", |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 268 | *current_delay_ms); |
| 269 | log_stream << "WebRTC.Video.CurrentDelayInMs " << *current_delay_ms << '\n'; |
asapersson | 8688a4e | 2016-04-27 23:42:35 -0700 | [diff] [blame] | 270 | } |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 271 | absl::optional<int> delay_ms = delay_counter_.Avg(kMinRequiredSamples); |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 272 | if (delay_ms) |
| 273 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.OnewayDelayInMs", *delay_ms); |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 274 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 275 | // Aggregate content_specific_stats_ by removing experiment or simulcast |
| 276 | // information; |
| 277 | std::map<VideoContentType, ContentSpecificStats> aggregated_stats; |
| 278 | for (auto it : content_specific_stats_) { |
| 279 | // Calculate simulcast specific metrics (".S0" ... ".S2" suffixes). |
| 280 | VideoContentType content_type = it.first; |
| 281 | if (videocontenttypehelpers::GetSimulcastId(content_type) > 0) { |
| 282 | // Aggregate on experiment id. |
| 283 | videocontenttypehelpers::SetExperimentId(&content_type, 0); |
| 284 | aggregated_stats[content_type].Add(it.second); |
| 285 | } |
| 286 | // Calculate experiment specific metrics (".ExperimentGroup[0-7]" suffixes). |
| 287 | content_type = it.first; |
| 288 | if (videocontenttypehelpers::GetExperimentId(content_type) > 0) { |
| 289 | // Aggregate on simulcast id. |
| 290 | videocontenttypehelpers::SetSimulcastId(&content_type, 0); |
| 291 | aggregated_stats[content_type].Add(it.second); |
| 292 | } |
| 293 | // Calculate aggregated metrics (no suffixes. Aggregated on everything). |
| 294 | content_type = it.first; |
| 295 | videocontenttypehelpers::SetSimulcastId(&content_type, 0); |
| 296 | videocontenttypehelpers::SetExperimentId(&content_type, 0); |
| 297 | aggregated_stats[content_type].Add(it.second); |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 298 | } |
| 299 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 300 | for (auto it : aggregated_stats) { |
| 301 | // For the metric Foo we report the following slices: |
| 302 | // WebRTC.Video.Foo, |
| 303 | // WebRTC.Video.Screenshare.Foo, |
| 304 | // WebRTC.Video.Foo.S[0-3], |
| 305 | // WebRTC.Video.Foo.ExperimentGroup[0-7], |
| 306 | // WebRTC.Video.Screenshare.Foo.S[0-3], |
| 307 | // WebRTC.Video.Screenshare.Foo.ExperimentGroup[0-7]. |
| 308 | auto content_type = it.first; |
| 309 | auto stats = it.second; |
| 310 | std::string uma_prefix = UmaPrefixForContentType(content_type); |
| 311 | std::string uma_suffix = UmaSuffixForContentType(content_type); |
| 312 | // Metrics can be sliced on either simulcast id or experiment id but not |
| 313 | // both. |
| 314 | RTC_DCHECK(videocontenttypehelpers::GetExperimentId(content_type) == 0 || |
| 315 | videocontenttypehelpers::GetSimulcastId(content_type) == 0); |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 316 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 317 | absl::optional<int> e2e_delay_ms = |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 318 | stats.e2e_delay_counter.Avg(kMinRequiredSamples); |
| 319 | if (e2e_delay_ms) { |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 320 | RTC_HISTOGRAM_COUNTS_SPARSE_10000( |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 321 | uma_prefix + ".EndToEndDelayInMs" + uma_suffix, *e2e_delay_ms); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 322 | log_stream << uma_prefix << ".EndToEndDelayInMs" << uma_suffix << " " |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 323 | << *e2e_delay_ms << '\n'; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 324 | } |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 325 | absl::optional<int> e2e_delay_max_ms = stats.e2e_delay_counter.Max(); |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 326 | if (e2e_delay_max_ms && e2e_delay_ms) { |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 327 | RTC_HISTOGRAM_COUNTS_SPARSE_100000( |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 328 | uma_prefix + ".EndToEndDelayMaxInMs" + uma_suffix, *e2e_delay_max_ms); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 329 | log_stream << uma_prefix << ".EndToEndDelayMaxInMs" << uma_suffix << " " |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 330 | << *e2e_delay_max_ms << '\n'; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 331 | } |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 332 | absl::optional<int> interframe_delay_ms = |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 333 | stats.interframe_delay_counter.Avg(kMinRequiredSamples); |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 334 | if (interframe_delay_ms) { |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 335 | RTC_HISTOGRAM_COUNTS_SPARSE_10000( |
| 336 | uma_prefix + ".InterframeDelayInMs" + uma_suffix, |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 337 | *interframe_delay_ms); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 338 | log_stream << uma_prefix << ".InterframeDelayInMs" << uma_suffix << " " |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 339 | << *interframe_delay_ms << '\n'; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 340 | } |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 341 | absl::optional<int> interframe_delay_max_ms = |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 342 | stats.interframe_delay_counter.Max(); |
| 343 | if (interframe_delay_max_ms && interframe_delay_ms) { |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 344 | RTC_HISTOGRAM_COUNTS_SPARSE_10000( |
| 345 | uma_prefix + ".InterframeDelayMaxInMs" + uma_suffix, |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 346 | *interframe_delay_max_ms); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 347 | log_stream << uma_prefix << ".InterframeDelayMaxInMs" << uma_suffix << " " |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 348 | << *interframe_delay_max_ms << '\n'; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 349 | } |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 350 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 351 | absl::optional<uint32_t> interframe_delay_95p_ms = |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 352 | stats.interframe_delay_percentiles.GetPercentile(0.95f); |
| 353 | if (interframe_delay_95p_ms && interframe_delay_ms != -1) { |
| 354 | RTC_HISTOGRAM_COUNTS_SPARSE_10000( |
| 355 | uma_prefix + ".InterframeDelay95PercentileInMs" + uma_suffix, |
| 356 | *interframe_delay_95p_ms); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 357 | log_stream << uma_prefix << ".InterframeDelay95PercentileInMs" |
| 358 | << uma_suffix << " " << *interframe_delay_95p_ms << '\n'; |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 359 | } |
| 360 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 361 | absl::optional<int> width = stats.received_width.Avg(kMinRequiredSamples); |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 362 | if (width) { |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 363 | RTC_HISTOGRAM_COUNTS_SPARSE_10000( |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 364 | uma_prefix + ".ReceivedWidthInPixels" + uma_suffix, *width); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 365 | log_stream << uma_prefix << ".ReceivedWidthInPixels" << uma_suffix << " " |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 366 | << *width << '\n'; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 367 | } |
asapersson | 1490f7a | 2016-09-23 02:09:46 -0700 | [diff] [blame] | 368 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 369 | absl::optional<int> height = stats.received_height.Avg(kMinRequiredSamples); |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 370 | if (height) { |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 371 | RTC_HISTOGRAM_COUNTS_SPARSE_10000( |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 372 | uma_prefix + ".ReceivedHeightInPixels" + uma_suffix, *height); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 373 | log_stream << uma_prefix << ".ReceivedHeightInPixels" << uma_suffix << " " |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 374 | << *height << '\n'; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 375 | } |
ilnik | 4257ab2 | 2017-07-03 01:15:58 -0700 | [diff] [blame] | 376 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 377 | if (content_type != VideoContentType::UNSPECIFIED) { |
| 378 | // Don't report these 3 metrics unsliced, as more precise variants |
| 379 | // are reported separately in this method. |
| 380 | float flow_duration_sec = stats.flow_duration_ms / 1000.0; |
| 381 | if (flow_duration_sec >= metrics::kMinRunTimeInSeconds) { |
| 382 | int media_bitrate_kbps = static_cast<int>(stats.total_media_bytes * 8 / |
| 383 | flow_duration_sec / 1000); |
| 384 | RTC_HISTOGRAM_COUNTS_SPARSE_10000( |
| 385 | uma_prefix + ".MediaBitrateReceivedInKbps" + uma_suffix, |
| 386 | media_bitrate_kbps); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 387 | log_stream << uma_prefix << ".MediaBitrateReceivedInKbps" << uma_suffix |
| 388 | << " " << media_bitrate_kbps << '\n'; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | int num_total_frames = |
| 392 | stats.frame_counts.key_frames + stats.frame_counts.delta_frames; |
| 393 | if (num_total_frames >= kMinRequiredSamples) { |
| 394 | int num_key_frames = stats.frame_counts.key_frames; |
| 395 | int key_frames_permille = |
| 396 | (num_key_frames * 1000 + num_total_frames / 2) / num_total_frames; |
| 397 | RTC_HISTOGRAM_COUNTS_SPARSE_1000( |
| 398 | uma_prefix + ".KeyFramesReceivedInPermille" + uma_suffix, |
| 399 | key_frames_permille); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 400 | log_stream << uma_prefix << ".KeyFramesReceivedInPermille" << uma_suffix |
| 401 | << " " << key_frames_permille << '\n'; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 402 | } |
| 403 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 404 | absl::optional<int> qp = stats.qp_counter.Avg(kMinRequiredSamples); |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 405 | if (qp) { |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 406 | RTC_HISTOGRAM_COUNTS_SPARSE_200( |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 407 | uma_prefix + ".Decoded.Vp8.Qp" + uma_suffix, *qp); |
| 408 | log_stream << uma_prefix << ".Decoded.Vp8.Qp" << uma_suffix << " " |
| 409 | << *qp << '\n'; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 410 | } |
| 411 | } |
ilnik | 4257ab2 | 2017-07-03 01:15:58 -0700 | [diff] [blame] | 412 | } |
| 413 | |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 414 | StreamDataCounters rtp = stats_.rtp_stats; |
| 415 | StreamDataCounters rtx; |
| 416 | for (auto it : rtx_stats_) |
| 417 | rtx.Add(it.second); |
| 418 | StreamDataCounters rtp_rtx = rtp; |
| 419 | rtp_rtx.Add(rtx); |
| 420 | int64_t elapsed_sec = |
| 421 | rtp_rtx.TimeSinceFirstPacketInMs(clock_->TimeInMilliseconds()) / 1000; |
asapersson | 2077f2f | 2017-05-11 05:37:35 -0700 | [diff] [blame] | 422 | if (elapsed_sec >= metrics::kMinRunTimeInSeconds) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 423 | RTC_HISTOGRAM_COUNTS_10000( |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 424 | "WebRTC.Video.BitrateReceivedInKbps", |
| 425 | static_cast<int>(rtp_rtx.transmitted.TotalBytes() * 8 / elapsed_sec / |
| 426 | 1000)); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 427 | int media_bitrate_kbs = |
| 428 | static_cast<int>(rtp.MediaPayloadBytes() * 8 / elapsed_sec / 1000); |
| 429 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.MediaBitrateReceivedInKbps", |
| 430 | media_bitrate_kbs); |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 431 | log_stream << "WebRTC.Video.MediaBitrateReceivedInKbps " |
| 432 | << media_bitrate_kbs << '\n'; |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 433 | RTC_HISTOGRAM_COUNTS_10000( |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 434 | "WebRTC.Video.PaddingBitrateReceivedInKbps", |
| 435 | static_cast<int>(rtp_rtx.transmitted.padding_bytes * 8 / elapsed_sec / |
| 436 | 1000)); |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 437 | RTC_HISTOGRAM_COUNTS_10000( |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 438 | "WebRTC.Video.RetransmittedBitrateReceivedInKbps", |
| 439 | static_cast<int>(rtp_rtx.retransmitted.TotalBytes() * 8 / elapsed_sec / |
| 440 | 1000)); |
| 441 | if (!rtx_stats_.empty()) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 442 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.RtxBitrateReceivedInKbps", |
| 443 | static_cast<int>(rtx.transmitted.TotalBytes() * |
| 444 | 8 / elapsed_sec / 1000)); |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 445 | } |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 446 | if (config_.rtp.ulpfec_payload_type != -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 447 | RTC_HISTOGRAM_COUNTS_10000( |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 448 | "WebRTC.Video.FecBitrateReceivedInKbps", |
| 449 | static_cast<int>(rtp_rtx.fec.TotalBytes() * 8 / elapsed_sec / 1000)); |
| 450 | } |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 451 | const RtcpPacketTypeCounter& counters = stats_.rtcp_packet_type_counts; |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 452 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.NackPacketsSentPerMinute", |
| 453 | counters.nack_packets * 60 / elapsed_sec); |
| 454 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.FirPacketsSentPerMinute", |
| 455 | counters.fir_packets * 60 / elapsed_sec); |
| 456 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.PliPacketsSentPerMinute", |
| 457 | counters.pli_packets * 60 / elapsed_sec); |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 458 | if (counters.nack_requests > 0) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 459 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.UniqueNackRequestsSentInPercent", |
| 460 | counters.UniqueNackRequestsInPercent()); |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 461 | } |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 462 | } |
palmkvist | a40672a | 2017-01-13 05:58:34 -0800 | [diff] [blame] | 463 | |
| 464 | if (num_certain_states_ >= kBadCallMinRequiredSamples) { |
| 465 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.BadCall.Any", |
| 466 | 100 * num_bad_states_ / num_certain_states_); |
| 467 | } |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 468 | absl::optional<double> fps_fraction = |
palmkvist | a40672a | 2017-01-13 05:58:34 -0800 | [diff] [blame] | 469 | fps_threshold_.FractionHigh(kBadCallMinRequiredSamples); |
| 470 | if (fps_fraction) { |
| 471 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.BadCall.FrameRate", |
| 472 | static_cast<int>(100 * (1 - *fps_fraction))); |
| 473 | } |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 474 | absl::optional<double> variance_fraction = |
palmkvist | a40672a | 2017-01-13 05:58:34 -0800 | [diff] [blame] | 475 | variance_threshold_.FractionHigh(kBadCallMinRequiredSamples); |
| 476 | if (variance_fraction) { |
| 477 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.BadCall.FrameRateVariance", |
| 478 | static_cast<int>(100 * *variance_fraction)); |
| 479 | } |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 480 | absl::optional<double> qp_fraction = |
palmkvist | a40672a | 2017-01-13 05:58:34 -0800 | [diff] [blame] | 481 | qp_threshold_.FractionHigh(kBadCallMinRequiredSamples); |
| 482 | if (qp_fraction) { |
| 483 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.BadCall.Qp", |
| 484 | static_cast<int>(100 * *qp_fraction)); |
| 485 | } |
Tommi | fef0500 | 2018-02-27 13:51:08 +0100 | [diff] [blame] | 486 | |
| 487 | RTC_LOG(LS_INFO) << log_stream.str(); |
Åsa Persson | 3c391cb | 2015-04-27 10:09:49 +0200 | [diff] [blame] | 488 | } |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 489 | |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 490 | void ReceiveStatisticsProxy::QualitySample() { |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 491 | RTC_DCHECK_RUN_ON(&network_thread_); |
| 492 | |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 493 | int64_t now = clock_->TimeInMilliseconds(); |
| 494 | if (last_sample_time_ + kMinSampleLengthMs > now) |
| 495 | return; |
| 496 | |
| 497 | double fps = |
| 498 | render_fps_tracker_.ComputeRateForInterval(now - last_sample_time_); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 499 | absl::optional<int> qp = qp_sample_.Avg(1); |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 500 | |
| 501 | bool prev_fps_bad = !fps_threshold_.IsHigh().value_or(true); |
| 502 | bool prev_qp_bad = qp_threshold_.IsHigh().value_or(false); |
| 503 | bool prev_variance_bad = variance_threshold_.IsHigh().value_or(false); |
| 504 | bool prev_any_bad = prev_fps_bad || prev_qp_bad || prev_variance_bad; |
| 505 | |
| 506 | fps_threshold_.AddMeasurement(static_cast<int>(fps)); |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 507 | if (qp) |
| 508 | qp_threshold_.AddMeasurement(*qp); |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 509 | absl::optional<double> fps_variance_opt = fps_threshold_.CalculateVariance(); |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 510 | double fps_variance = fps_variance_opt.value_or(0); |
| 511 | if (fps_variance_opt) { |
| 512 | variance_threshold_.AddMeasurement(static_cast<int>(fps_variance)); |
| 513 | } |
| 514 | |
| 515 | bool fps_bad = !fps_threshold_.IsHigh().value_or(true); |
| 516 | bool qp_bad = qp_threshold_.IsHigh().value_or(false); |
| 517 | bool variance_bad = variance_threshold_.IsHigh().value_or(false); |
| 518 | bool any_bad = fps_bad || qp_bad || variance_bad; |
| 519 | |
| 520 | if (!prev_any_bad && any_bad) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 521 | RTC_LOG(LS_INFO) << "Bad call (any) start: " << now; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 522 | } else if (prev_any_bad && !any_bad) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 523 | RTC_LOG(LS_INFO) << "Bad call (any) end: " << now; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | if (!prev_fps_bad && fps_bad) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 527 | RTC_LOG(LS_INFO) << "Bad call (fps) start: " << now; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 528 | } else if (prev_fps_bad && !fps_bad) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 529 | RTC_LOG(LS_INFO) << "Bad call (fps) end: " << now; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | if (!prev_qp_bad && qp_bad) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 533 | RTC_LOG(LS_INFO) << "Bad call (qp) start: " << now; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 534 | } else if (prev_qp_bad && !qp_bad) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 535 | RTC_LOG(LS_INFO) << "Bad call (qp) end: " << now; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | if (!prev_variance_bad && variance_bad) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 539 | RTC_LOG(LS_INFO) << "Bad call (variance) start: " << now; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 540 | } else if (prev_variance_bad && !variance_bad) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 541 | RTC_LOG(LS_INFO) << "Bad call (variance) end: " << now; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 542 | } |
| 543 | |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 544 | RTC_LOG(LS_VERBOSE) << "SAMPLE: sample_length: " << (now - last_sample_time_) |
| 545 | << " fps: " << fps << " fps_bad: " << fps_bad |
Ilya Nikolaevskiy | 0beed5d | 2018-05-22 10:54:30 +0200 | [diff] [blame] | 546 | << " qp: " << qp.value_or(-1) << " qp_bad: " << qp_bad |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 547 | << " variance_bad: " << variance_bad |
| 548 | << " fps_variance: " << fps_variance; |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 549 | |
| 550 | last_sample_time_ = now; |
| 551 | qp_sample_.Reset(); |
palmkvist | a40672a | 2017-01-13 05:58:34 -0800 | [diff] [blame] | 552 | |
| 553 | if (fps_threshold_.IsHigh() || variance_threshold_.IsHigh() || |
| 554 | qp_threshold_.IsHigh()) { |
| 555 | if (any_bad) |
| 556 | ++num_bad_states_; |
| 557 | ++num_certain_states_; |
| 558 | } |
palmkvist | 349092b | 2016-12-13 02:45:57 -0800 | [diff] [blame] | 559 | } |
| 560 | |
asapersson | 0255acb | 2017-03-28 02:44:58 -0700 | [diff] [blame] | 561 | void ReceiveStatisticsProxy::UpdateFramerate(int64_t now_ms) const { |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 562 | int64_t old_frames_ms = now_ms - kRateStatisticsWindowSizeMs; |
| 563 | while (!frame_window_.empty() && |
| 564 | frame_window_.begin()->first < old_frames_ms) { |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 565 | frame_window_.erase(frame_window_.begin()); |
| 566 | } |
| 567 | |
| 568 | size_t framerate = |
| 569 | (frame_window_.size() * 1000 + 500) / kRateStatisticsWindowSizeMs; |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 570 | stats_.network_frame_rate = static_cast<int>(framerate); |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 571 | } |
| 572 | |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 573 | VideoReceiveStream::Stats ReceiveStatisticsProxy::GetStats() const { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 574 | rtc::CritScope lock(&crit_); |
sprang | 948b275 | 2017-05-04 02:47:13 -0700 | [diff] [blame] | 575 | // Get current frame rates here, as only updating them on new frames prevents |
| 576 | // us from ever correctly displaying frame rate of 0. |
| 577 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 578 | UpdateFramerate(now_ms); |
| 579 | stats_.render_frame_rate = renders_fps_estimator_.Rate(now_ms).value_or(0); |
| 580 | stats_.decode_frame_rate = decode_fps_estimator_.Rate(now_ms).value_or(0); |
asapersson | 0255acb | 2017-03-28 02:44:58 -0700 | [diff] [blame] | 581 | stats_.total_bitrate_bps = |
| 582 | static_cast<int>(total_byte_tracker_.ComputeRate() * 8); |
ilnik | a79cc28 | 2017-08-23 05:24:10 -0700 | [diff] [blame] | 583 | stats_.interframe_delay_max_ms = |
| 584 | interframe_delay_max_moving_.Max(now_ms).value_or(-1); |
ilnik | 75204c5 | 2017-09-04 03:35:40 -0700 | [diff] [blame] | 585 | stats_.timing_frame_info = timing_frame_info_counter_.Max(now_ms); |
ilnik | 2e1b40b | 2017-09-04 07:57:17 -0700 | [diff] [blame] | 586 | stats_.content_type = last_content_type_; |
pbos@webrtc.org | 5570769 | 2014-12-19 15:45:03 +0000 | [diff] [blame] | 587 | return stats_; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 588 | } |
| 589 | |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 590 | void ReceiveStatisticsProxy::OnIncomingPayloadType(int payload_type) { |
| 591 | rtc::CritScope lock(&crit_); |
| 592 | stats_.current_payload_type = payload_type; |
| 593 | } |
| 594 | |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 595 | void ReceiveStatisticsProxy::OnDecoderImplementationName( |
| 596 | const char* implementation_name) { |
| 597 | rtc::CritScope lock(&crit_); |
| 598 | stats_.decoder_implementation_name = implementation_name; |
| 599 | } |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 600 | void ReceiveStatisticsProxy::OnIncomingRate(unsigned int framerate, |
| 601 | unsigned int bitrate_bps) { |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 602 | RTC_DCHECK_RUN_ON(&network_thread_); |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 603 | rtc::CritScope lock(&crit_); |
palmkvist | a40672a | 2017-01-13 05:58:34 -0800 | [diff] [blame] | 604 | if (stats_.rtp_stats.first_packet_time_ms != -1) |
| 605 | QualitySample(); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 606 | } |
| 607 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 608 | void ReceiveStatisticsProxy::OnFrameBufferTimingsUpdated( |
| 609 | int decode_ms, |
| 610 | int max_decode_ms, |
| 611 | int current_delay_ms, |
| 612 | int target_delay_ms, |
| 613 | int jitter_buffer_ms, |
| 614 | int min_playout_delay_ms, |
| 615 | int render_delay_ms) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 616 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 617 | stats_.decode_ms = decode_ms; |
| 618 | stats_.max_decode_ms = max_decode_ms; |
| 619 | stats_.current_delay_ms = current_delay_ms; |
| 620 | stats_.target_delay_ms = target_delay_ms; |
| 621 | stats_.jitter_buffer_ms = jitter_buffer_ms; |
| 622 | stats_.min_playout_delay_ms = min_playout_delay_ms; |
| 623 | stats_.render_delay_ms = render_delay_ms; |
asapersson | 6718e97 | 2015-07-24 00:20:58 -0700 | [diff] [blame] | 624 | decode_time_counter_.Add(decode_ms); |
asapersson | 8688a4e | 2016-04-27 23:42:35 -0700 | [diff] [blame] | 625 | jitter_buffer_delay_counter_.Add(jitter_buffer_ms); |
| 626 | target_delay_counter_.Add(target_delay_ms); |
| 627 | current_delay_counter_.Add(current_delay_ms); |
asapersson | a186288 | 2016-04-18 00:41:05 -0700 | [diff] [blame] | 628 | // Network delay (rtt/2) + target_delay_ms (jitter delay + decode time + |
| 629 | // render delay). |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 630 | delay_counter_.Add(target_delay_ms + avg_rtt_ms_ / 2); |
pbos@webrtc.org | 98c04b3 | 2014-12-18 13:12:52 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Ilya Nikolaevskiy | d397a0d | 2018-02-21 15:57:09 +0100 | [diff] [blame] | 633 | void ReceiveStatisticsProxy::OnUniqueFramesCounted(int num_unique_frames) { |
| 634 | rtc::CritScope lock(&crit_); |
| 635 | num_unique_frames_.emplace(num_unique_frames); |
| 636 | } |
| 637 | |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 638 | void ReceiveStatisticsProxy::OnTimingFrameInfoUpdated( |
| 639 | const TimingFrameInfo& info) { |
| 640 | rtc::CritScope lock(&crit_); |
Benjamin Wright | 3f10ca8 | 2018-12-07 03:45:19 -0800 | [diff] [blame] | 641 | if (info.flags != VideoSendTiming::kInvalid) { |
| 642 | int64_t now_ms = clock_->TimeInMilliseconds(); |
| 643 | timing_frame_info_counter_.Add(info, now_ms); |
| 644 | } |
Benjamin Wright | 514f084 | 2018-12-10 09:55:17 -0800 | [diff] [blame] | 645 | |
| 646 | // Measure initial decoding latency between the first frame arriving and the |
| 647 | // first frame being decoded. |
| 648 | if (!first_frame_received_time_ms_.has_value()) { |
| 649 | first_frame_received_time_ms_ = info.receive_finish_ms; |
| 650 | } |
| 651 | if (stats_.first_frame_received_to_decoded_ms == -1 && |
| 652 | first_decoded_frame_time_ms_) { |
| 653 | stats_.first_frame_received_to_decoded_ms = |
| 654 | *first_decoded_frame_time_ms_ - *first_frame_received_time_ms_; |
| 655 | } |
ilnik | 2edc684 | 2017-07-06 03:06:50 -0700 | [diff] [blame] | 656 | } |
| 657 | |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 658 | void ReceiveStatisticsProxy::RtcpPacketTypesCounterUpdated( |
| 659 | uint32_t ssrc, |
| 660 | const RtcpPacketTypeCounter& packet_counter) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 661 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 662 | if (stats_.ssrc != ssrc) |
| 663 | return; |
| 664 | stats_.rtcp_packet_type_counts = packet_counter; |
| 665 | } |
| 666 | |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 667 | void ReceiveStatisticsProxy::StatisticsUpdated( |
| 668 | const webrtc::RtcpStatistics& statistics, |
| 669 | uint32_t ssrc) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 670 | rtc::CritScope lock(&crit_); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 671 | // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 672 | // receive stats from one of them. |
| 673 | if (stats_.ssrc != ssrc) |
| 674 | return; |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 675 | stats_.rtcp_stats = statistics; |
Åsa Persson | 3c391cb | 2015-04-27 10:09:49 +0200 | [diff] [blame] | 676 | report_block_stats_.Store(statistics, ssrc, 0); |
asapersson | 0c43f77 | 2016-11-30 01:42:26 -0800 | [diff] [blame] | 677 | |
| 678 | if (first_report_block_time_ms_ == -1) |
| 679 | first_report_block_time_ms_ = clock_->TimeInMilliseconds(); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 680 | } |
| 681 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 682 | void ReceiveStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 683 | rtc::CritScope lock(&crit_); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 684 | // TODO(pbos): Handle both local and remote ssrcs here and RTC_DCHECK that we |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 685 | // receive stats from one of them. |
| 686 | if (stats_.ssrc != ssrc) |
| 687 | return; |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 688 | stats_.c_name = cname; |
| 689 | } |
| 690 | |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 691 | void ReceiveStatisticsProxy::DataCountersUpdated( |
| 692 | const webrtc::StreamDataCounters& counters, |
| 693 | uint32_t ssrc) { |
asapersson | 0255acb | 2017-03-28 02:44:58 -0700 | [diff] [blame] | 694 | size_t last_total_bytes = 0; |
| 695 | size_t total_bytes = 0; |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 696 | rtc::CritScope lock(&crit_); |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 697 | if (ssrc == stats_.ssrc) { |
asapersson | 0255acb | 2017-03-28 02:44:58 -0700 | [diff] [blame] | 698 | last_total_bytes = stats_.rtp_stats.transmitted.TotalBytes(); |
| 699 | total_bytes = counters.transmitted.TotalBytes(); |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 700 | stats_.rtp_stats = counters; |
| 701 | } else { |
| 702 | auto it = rtx_stats_.find(ssrc); |
| 703 | if (it != rtx_stats_.end()) { |
asapersson | 0255acb | 2017-03-28 02:44:58 -0700 | [diff] [blame] | 704 | last_total_bytes = it->second.transmitted.TotalBytes(); |
| 705 | total_bytes = counters.transmitted.TotalBytes(); |
sprang | 0ab8e81 | 2016-02-24 01:35:40 -0800 | [diff] [blame] | 706 | it->second = counters; |
| 707 | } else { |
| 708 | RTC_NOTREACHED() << "Unexpected stream ssrc: " << ssrc; |
| 709 | } |
| 710 | } |
asapersson | 0255acb | 2017-03-28 02:44:58 -0700 | [diff] [blame] | 711 | if (total_bytes > last_total_bytes) |
| 712 | total_byte_tracker_.AddSamples(total_bytes - last_total_bytes); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 713 | } |
| 714 | |
Sergey Silkin | 278f825 | 2019-01-09 14:37:40 +0100 | [diff] [blame] | 715 | void ReceiveStatisticsProxy::OnDecodedFrame(const VideoFrame& frame, |
| 716 | absl::optional<uint8_t> qp, |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 717 | VideoContentType content_type) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 718 | rtc::CritScope lock(&crit_); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 719 | |
Sergey Silkin | 278f825 | 2019-01-09 14:37:40 +0100 | [diff] [blame] | 720 | uint64_t now_ms = clock_->TimeInMilliseconds(); |
Ilya Nikolaevskiy | 3f670e0 | 2017-10-10 11:18:49 +0200 | [diff] [blame] | 721 | |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 722 | if (videocontenttypehelpers::IsScreenshare(content_type) != |
| 723 | videocontenttypehelpers::IsScreenshare(last_content_type_)) { |
| 724 | // Reset the quality observer if content type is switched. This will |
| 725 | // report stats for the previous part of the call. |
| 726 | video_quality_observer_.reset(new VideoQualityObserver(content_type)); |
| 727 | } |
| 728 | |
Sergey Silkin | 278f825 | 2019-01-09 14:37:40 +0100 | [diff] [blame] | 729 | video_quality_observer_->OnDecodedFrame(frame, qp, last_codec_type_); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 730 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 731 | ContentSpecificStats* content_specific_stats = |
| 732 | &content_specific_stats_[content_type]; |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 733 | ++stats_.frames_decoded; |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 734 | if (qp) { |
| 735 | if (!stats_.qp_sum) { |
| 736 | if (stats_.frames_decoded != 1) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 737 | RTC_LOG(LS_WARNING) |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 738 | << "Frames decoded was not 1 when first qp value was received."; |
| 739 | stats_.frames_decoded = 1; |
| 740 | } |
Oskar Sundbom | 8e07c13 | 2018-01-08 16:45:42 +0100 | [diff] [blame] | 741 | stats_.qp_sum = 0; |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 742 | } |
| 743 | *stats_.qp_sum += *qp; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 744 | content_specific_stats->qp_counter.Add(*qp); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 745 | } else if (stats_.qp_sum) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 746 | RTC_LOG(LS_WARNING) |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 747 | << "QP sum was already set and no QP was given for a frame."; |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 748 | stats_.qp_sum = absl::nullopt; |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 749 | } |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 750 | last_content_type_ = content_type; |
Sergey Silkin | 278f825 | 2019-01-09 14:37:40 +0100 | [diff] [blame] | 751 | decode_fps_estimator_.Update(1, now_ms); |
ilnik | 4257ab2 | 2017-07-03 01:15:58 -0700 | [diff] [blame] | 752 | if (last_decoded_frame_time_ms_) { |
Sergey Silkin | 278f825 | 2019-01-09 14:37:40 +0100 | [diff] [blame] | 753 | int64_t interframe_delay_ms = now_ms - *last_decoded_frame_time_ms_; |
ilnik | 4257ab2 | 2017-07-03 01:15:58 -0700 | [diff] [blame] | 754 | RTC_DCHECK_GE(interframe_delay_ms, 0); |
Sergey Silkin | 278f825 | 2019-01-09 14:37:40 +0100 | [diff] [blame] | 755 | interframe_delay_max_moving_.Add(interframe_delay_ms, now_ms); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 756 | content_specific_stats->interframe_delay_counter.Add(interframe_delay_ms); |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 757 | content_specific_stats->interframe_delay_percentiles.Add( |
| 758 | interframe_delay_ms); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 759 | content_specific_stats->flow_duration_ms += interframe_delay_ms; |
ilnik | 4257ab2 | 2017-07-03 01:15:58 -0700 | [diff] [blame] | 760 | } |
Benjamin Wright | 514f084 | 2018-12-10 09:55:17 -0800 | [diff] [blame] | 761 | if (stats_.frames_decoded == 1) { |
Sergey Silkin | 278f825 | 2019-01-09 14:37:40 +0100 | [diff] [blame] | 762 | first_decoded_frame_time_ms_.emplace(now_ms); |
Benjamin Wright | 514f084 | 2018-12-10 09:55:17 -0800 | [diff] [blame] | 763 | } |
Sergey Silkin | 278f825 | 2019-01-09 14:37:40 +0100 | [diff] [blame] | 764 | last_decoded_frame_time_ms_.emplace(now_ms); |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 765 | } |
| 766 | |
asapersson | 1490f7a | 2016-09-23 02:09:46 -0700 | [diff] [blame] | 767 | void ReceiveStatisticsProxy::OnRenderedFrame(const VideoFrame& frame) { |
| 768 | int width = frame.width(); |
| 769 | int height = frame.height(); |
asapersson | f839dcc | 2015-10-08 00:41:59 -0700 | [diff] [blame] | 770 | RTC_DCHECK_GT(width, 0); |
| 771 | RTC_DCHECK_GT(height, 0); |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 772 | int64_t now_ms = clock_->TimeInMilliseconds(); |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 773 | rtc::CritScope lock(&crit_); |
Ilya Nikolaevskiy | cdc959f | 2018-10-10 13:15:09 +0200 | [diff] [blame] | 774 | |
Sergey Silkin | 278f825 | 2019-01-09 14:37:40 +0100 | [diff] [blame] | 775 | video_quality_observer_->OnRenderedFrame(frame, now_ms); |
Ilya Nikolaevskiy | cdc959f | 2018-10-10 13:15:09 +0200 | [diff] [blame] | 776 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 777 | ContentSpecificStats* content_specific_stats = |
| 778 | &content_specific_stats_[last_content_type_]; |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 779 | renders_fps_estimator_.Update(1, now_ms); |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 780 | ++stats_.frames_rendered; |
asapersson | 2e5cfcd | 2016-08-11 08:41:18 -0700 | [diff] [blame] | 781 | stats_.width = width; |
| 782 | stats_.height = height; |
Tim Psiaki | 6304626 | 2015-09-14 10:38:08 -0700 | [diff] [blame] | 783 | render_fps_tracker_.AddSamples(1); |
asapersson | f839dcc | 2015-10-08 00:41:59 -0700 | [diff] [blame] | 784 | render_pixel_tracker_.AddSamples(sqrt(width * height)); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 785 | content_specific_stats->received_width.Add(width); |
| 786 | content_specific_stats->received_height.Add(height); |
asapersson | 1490f7a | 2016-09-23 02:09:46 -0700 | [diff] [blame] | 787 | |
Åsa Persson | 81327d5 | 2018-06-05 13:34:33 +0200 | [diff] [blame] | 788 | // Consider taking stats_.render_delay_ms into account. |
| 789 | const int64_t time_until_rendering_ms = frame.render_time_ms() - now_ms; |
| 790 | if (time_until_rendering_ms < 0) { |
| 791 | sum_missed_render_deadline_ms_ += -time_until_rendering_ms; |
| 792 | ++num_delayed_frames_rendered_; |
| 793 | } |
| 794 | |
asapersson | 1490f7a | 2016-09-23 02:09:46 -0700 | [diff] [blame] | 795 | if (frame.ntp_time_ms() > 0) { |
| 796 | int64_t delay_ms = clock_->CurrentNtpInMilliseconds() - frame.ntp_time_ms(); |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 797 | if (delay_ms >= 0) { |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 798 | content_specific_stats->e2e_delay_counter.Add(delay_ms); |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 799 | } |
asapersson | 1490f7a | 2016-09-23 02:09:46 -0700 | [diff] [blame] | 800 | } |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 801 | } |
| 802 | |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 803 | void ReceiveStatisticsProxy::OnSyncOffsetUpdated(int64_t sync_offset_ms, |
| 804 | double estimated_freq_khz) { |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 805 | rtc::CritScope lock(&crit_); |
| 806 | sync_offset_counter_.Add(std::abs(sync_offset_ms)); |
| 807 | stats_.sync_offset_ms = sync_offset_ms; |
asapersson | de9e5ff | 2016-11-02 07:14:03 -0700 | [diff] [blame] | 808 | |
| 809 | const double kMaxFreqKhz = 10000.0; |
| 810 | int offset_khz = kMaxFreqKhz; |
| 811 | // Should not be zero or negative. If so, report max. |
| 812 | if (estimated_freq_khz < kMaxFreqKhz && estimated_freq_khz > 0.0) |
| 813 | offset_khz = static_cast<int>(std::fabs(estimated_freq_khz - 90.0) + 0.5); |
| 814 | |
| 815 | freq_offset_counter_.Add(offset_khz); |
asapersson | f8cdd18 | 2016-03-15 01:00:47 -0700 | [diff] [blame] | 816 | } |
| 817 | |
pbos@webrtc.org | 5570769 | 2014-12-19 15:45:03 +0000 | [diff] [blame] | 818 | void ReceiveStatisticsProxy::OnReceiveRatesUpdated(uint32_t bitRate, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 819 | uint32_t frameRate) {} |
pbos@webrtc.org | 5570769 | 2014-12-19 15:45:03 +0000 | [diff] [blame] | 820 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 821 | void ReceiveStatisticsProxy::OnCompleteFrame(bool is_keyframe, |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 822 | size_t size_bytes, |
| 823 | VideoContentType content_type) { |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 824 | rtc::CritScope lock(&crit_); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 825 | if (is_keyframe) { |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 826 | ++stats_.frame_counts.key_frames; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 827 | } else { |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 828 | ++stats_.frame_counts.delta_frames; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 829 | } |
| 830 | |
Ilya Nikolaevskiy | f203d73 | 2018-10-17 14:41:52 +0200 | [diff] [blame] | 831 | // Content type extension is set only for keyframes and should be propagated |
| 832 | // for all the following delta frames. Here we may receive frames out of order |
| 833 | // and miscategorise some delta frames near the layer switch. |
| 834 | // This may slightly offset calculated bitrate and keyframes permille metrics. |
| 835 | VideoContentType propagated_content_type = |
| 836 | is_keyframe ? content_type : last_content_type_; |
| 837 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 838 | ContentSpecificStats* content_specific_stats = |
Ilya Nikolaevskiy | f203d73 | 2018-10-17 14:41:52 +0200 | [diff] [blame] | 839 | &content_specific_stats_[propagated_content_type]; |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 840 | |
| 841 | content_specific_stats->total_media_bytes += size_bytes; |
| 842 | if (is_keyframe) { |
| 843 | ++content_specific_stats->frame_counts.key_frames; |
| 844 | } else { |
| 845 | ++content_specific_stats->frame_counts.delta_frames; |
| 846 | } |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 847 | |
| 848 | int64_t now_ms = clock_->TimeInMilliseconds(); |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 849 | frame_window_.insert(std::make_pair(now_ms, size_bytes)); |
asapersson | 0255acb | 2017-03-28 02:44:58 -0700 | [diff] [blame] | 850 | UpdateFramerate(now_ms); |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 851 | } |
| 852 | |
pbos@webrtc.org | 5570769 | 2014-12-19 15:45:03 +0000 | [diff] [blame] | 853 | void ReceiveStatisticsProxy::OnFrameCountsUpdated( |
| 854 | const FrameCounts& frame_counts) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 855 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 856 | stats_.frame_counts = frame_counts; |
| 857 | } |
| 858 | |
pbos@webrtc.org | 5570769 | 2014-12-19 15:45:03 +0000 | [diff] [blame] | 859 | void ReceiveStatisticsProxy::OnDiscardedPacketsUpdated(int discarded_packets) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 860 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 5570769 | 2014-12-19 15:45:03 +0000 | [diff] [blame] | 861 | stats_.discarded_packets = discarded_packets; |
| 862 | } |
| 863 | |
Niels Möller | 147013a | 2018-10-01 15:56:33 +0200 | [diff] [blame] | 864 | void ReceiveStatisticsProxy::OnPreDecode(VideoCodecType codec_type, int qp) { |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 865 | RTC_DCHECK_RUN_ON(&decode_thread_); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 866 | rtc::CritScope lock(&crit_); |
Niels Möller | 147013a | 2018-10-01 15:56:33 +0200 | [diff] [blame] | 867 | last_codec_type_ = codec_type; |
| 868 | if (last_codec_type_ == kVideoCodecVP8 && qp != -1) { |
| 869 | qp_counters_.vp8.Add(qp); |
| 870 | qp_sample_.Add(qp); |
asapersson | 86b0160 | 2015-10-20 23:55:26 -0700 | [diff] [blame] | 871 | } |
| 872 | } |
| 873 | |
sprang | 3e86e7e | 2017-08-22 09:23:28 -0700 | [diff] [blame] | 874 | void ReceiveStatisticsProxy::OnStreamInactive() { |
| 875 | // TODO(sprang): Figure out any other state that should be reset. |
| 876 | |
| 877 | rtc::CritScope lock(&crit_); |
| 878 | // Don't report inter-frame delay if stream was paused. |
| 879 | last_decoded_frame_time_ms_.reset(); |
Ilya Nikolaevskiy | 94150ee | 2018-05-23 11:53:19 +0200 | [diff] [blame] | 880 | video_quality_observer_->OnStreamInactive(); |
sprang | 3e86e7e | 2017-08-22 09:23:28 -0700 | [diff] [blame] | 881 | } |
| 882 | |
philipel | a45102f | 2017-02-22 05:30:39 -0800 | [diff] [blame] | 883 | void ReceiveStatisticsProxy::OnRttUpdate(int64_t avg_rtt_ms, |
| 884 | int64_t max_rtt_ms) { |
| 885 | rtc::CritScope lock(&crit_); |
| 886 | avg_rtt_ms_ = avg_rtt_ms; |
| 887 | } |
| 888 | |
Tommi | 132e28e | 2018-02-24 17:57:33 +0100 | [diff] [blame] | 889 | void ReceiveStatisticsProxy::DecoderThreadStarting() { |
| 890 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 891 | } |
| 892 | |
| 893 | void ReceiveStatisticsProxy::DecoderThreadStopped() { |
| 894 | RTC_DCHECK_RUN_ON(&main_thread_); |
| 895 | decode_thread_.DetachFromThread(); |
| 896 | } |
| 897 | |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 898 | ReceiveStatisticsProxy::ContentSpecificStats::ContentSpecificStats() |
| 899 | : interframe_delay_percentiles(kMaxCommonInterframeDelayMs) {} |
| 900 | |
Mirko Bonadei | 8fdcac3 | 2018-08-28 16:30:18 +0200 | [diff] [blame] | 901 | ReceiveStatisticsProxy::ContentSpecificStats::~ContentSpecificStats() = default; |
| 902 | |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 903 | void ReceiveStatisticsProxy::ContentSpecificStats::Add( |
| 904 | const ContentSpecificStats& other) { |
| 905 | e2e_delay_counter.Add(other.e2e_delay_counter); |
| 906 | interframe_delay_counter.Add(other.interframe_delay_counter); |
| 907 | flow_duration_ms += other.flow_duration_ms; |
| 908 | total_media_bytes += other.total_media_bytes; |
| 909 | received_height.Add(other.received_height); |
| 910 | received_width.Add(other.received_width); |
| 911 | qp_counter.Add(other.qp_counter); |
| 912 | frame_counts.key_frames += other.frame_counts.key_frames; |
| 913 | frame_counts.delta_frames += other.frame_counts.delta_frames; |
Ilya Nikolaevskiy | daa4f7a | 2017-10-06 12:29:47 +0200 | [diff] [blame] | 914 | interframe_delay_percentiles.Add(other.interframe_delay_percentiles); |
ilnik | 6d5b4d6 | 2017-08-30 03:32:14 -0700 | [diff] [blame] | 915 | } |
sprang@webrtc.org | 0931570 | 2014-02-07 12:06:29 +0000 | [diff] [blame] | 916 | } // namespace webrtc |