sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +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 | |
| 11 | #include "webrtc/video/send_statistics_proxy.h" |
| 12 | |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 13 | #include <algorithm> |
Tim Psiaki | ad13d2f | 2015-11-10 16:34:50 -0800 | [diff] [blame] | 14 | #include <cmath> |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 15 | #include <map> |
asapersson | 58d992e | 2016-03-29 02:15:06 -0700 | [diff] [blame] | 16 | #include <vector> |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 17 | |
pbos@webrtc.org | 49096de | 2015-02-24 22:37:52 +0000 | [diff] [blame] | 18 | #include "webrtc/base/checks.h" |
Peter Boström | 415d2cd | 2015-10-26 11:35:17 +0100 | [diff] [blame] | 19 | #include "webrtc/base/logging.h" |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 20 | #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 21 | #include "webrtc/system_wrappers/include/metrics.h" |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
asapersson | 2a0a2a4 | 2015-10-27 01:32:00 -0700 | [diff] [blame] | 24 | namespace { |
asapersson | 1aa420b | 2015-12-07 03:12:22 -0800 | [diff] [blame] | 25 | const float kEncodeTimeWeigthFactor = 0.5f; |
| 26 | |
asapersson | 2a0a2a4 | 2015-10-27 01:32:00 -0700 | [diff] [blame] | 27 | // Used by histograms. Values of entries should not be changed. |
| 28 | enum HistogramCodecType { |
| 29 | kVideoUnknown = 0, |
| 30 | kVideoVp8 = 1, |
| 31 | kVideoVp9 = 2, |
| 32 | kVideoH264 = 3, |
| 33 | kVideoMax = 64, |
| 34 | }; |
| 35 | |
asapersson | c2148a5 | 2016-02-04 00:33:21 -0800 | [diff] [blame] | 36 | const char* kRealtimePrefix = "WebRTC.Video."; |
| 37 | const char* kScreenPrefix = "WebRTC.Video.Screenshare."; |
| 38 | |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 39 | const char* GetUmaPrefix(VideoEncoderConfig::ContentType content_type) { |
| 40 | switch (content_type) { |
| 41 | case VideoEncoderConfig::ContentType::kRealtimeVideo: |
asapersson | c2148a5 | 2016-02-04 00:33:21 -0800 | [diff] [blame] | 42 | return kRealtimePrefix; |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 43 | case VideoEncoderConfig::ContentType::kScreen: |
asapersson | c2148a5 | 2016-02-04 00:33:21 -0800 | [diff] [blame] | 44 | return kScreenPrefix; |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 45 | } |
| 46 | RTC_NOTREACHED(); |
| 47 | return nullptr; |
| 48 | } |
| 49 | |
asapersson | 2a0a2a4 | 2015-10-27 01:32:00 -0700 | [diff] [blame] | 50 | HistogramCodecType PayloadNameToHistogramCodecType( |
| 51 | const std::string& payload_name) { |
| 52 | if (payload_name == "VP8") { |
| 53 | return kVideoVp8; |
| 54 | } else if (payload_name == "VP9") { |
| 55 | return kVideoVp9; |
| 56 | } else if (payload_name == "H264") { |
| 57 | return kVideoH264; |
| 58 | } else { |
| 59 | return kVideoUnknown; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | void UpdateCodecTypeHistogram(const std::string& payload_name) { |
asapersson | 28ba927 | 2016-01-25 05:58:23 -0800 | [diff] [blame] | 64 | RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.Encoder.CodecType", |
| 65 | PayloadNameToHistogramCodecType(payload_name), |
| 66 | kVideoMax); |
asapersson | 2a0a2a4 | 2015-10-27 01:32:00 -0700 | [diff] [blame] | 67 | } |
| 68 | } // namespace |
| 69 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 70 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 71 | const int SendStatisticsProxy::kStatsTimeoutMs = 5000; |
| 72 | |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 73 | SendStatisticsProxy::SendStatisticsProxy( |
| 74 | Clock* clock, |
| 75 | const VideoSendStream::Config& config, |
| 76 | VideoEncoderConfig::ContentType content_type) |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 77 | : clock_(clock), |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 78 | payload_name_(config.encoder_settings.payload_name), |
| 79 | rtp_config_(config.rtp), |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 80 | content_type_(content_type), |
asapersson | 4374a09 | 2016-07-27 00:39:09 -0700 | [diff] [blame] | 81 | start_ms_(clock->TimeInMilliseconds()), |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 82 | last_sent_frame_timestamp_(0), |
asapersson | 1aa420b | 2015-12-07 03:12:22 -0800 | [diff] [blame] | 83 | encode_time_(kEncodeTimeWeigthFactor), |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 84 | uma_container_( |
| 85 | new UmaSamplesContainer(GetUmaPrefix(content_type_), stats_, clock)) { |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 86 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 87 | |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 88 | SendStatisticsProxy::~SendStatisticsProxy() { |
| 89 | rtc::CritScope lock(&crit_); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 90 | uma_container_->UpdateHistograms(rtp_config_, stats_); |
asapersson | 4374a09 | 2016-07-27 00:39:09 -0700 | [diff] [blame] | 91 | |
| 92 | int64_t elapsed_sec = (clock_->TimeInMilliseconds() - start_ms_) / 1000; |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 93 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Video.SendStreamLifetimeInSeconds", |
| 94 | elapsed_sec); |
asapersson | 4374a09 | 2016-07-27 00:39:09 -0700 | [diff] [blame] | 95 | |
| 96 | if (elapsed_sec >= metrics::kMinRunTimeInSeconds) |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 97 | UpdateCodecTypeHistogram(payload_name_); |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 98 | } |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 99 | |
| 100 | SendStatisticsProxy::UmaSamplesContainer::UmaSamplesContainer( |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 101 | const char* prefix, |
| 102 | const VideoSendStream::Stats& stats, |
| 103 | Clock* const clock) |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 104 | : uma_prefix_(prefix), |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 105 | clock_(clock), |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 106 | max_sent_width_per_timestamp_(0), |
| 107 | max_sent_height_per_timestamp_(0), |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 108 | input_frame_rate_tracker_(100, 10u), |
| 109 | sent_frame_rate_tracker_(100, 10u), |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 110 | first_rtcp_stats_time_ms_(-1), |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 111 | first_rtp_stats_time_ms_(-1), |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 112 | start_stats_(stats) {} |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 113 | |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 114 | SendStatisticsProxy::UmaSamplesContainer::~UmaSamplesContainer() {} |
Åsa Persson | 24b4eda | 2015-06-16 10:17:01 +0200 | [diff] [blame] | 115 | |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 116 | void AccumulateRtxStats(const VideoSendStream::Stats& stats, |
| 117 | const std::vector<uint32_t>& rtx_ssrcs, |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 118 | StreamDataCounters* total_rtp_stats, |
| 119 | StreamDataCounters* rtx_stats) { |
| 120 | for (auto it : stats.substreams) { |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 121 | if (std::find(rtx_ssrcs.begin(), rtx_ssrcs.end(), it.first) != |
| 122 | rtx_ssrcs.end()) { |
| 123 | rtx_stats->Add(it.second.rtp_stats); |
| 124 | } else { |
| 125 | total_rtp_stats->Add(it.second.rtp_stats); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 130 | void SendStatisticsProxy::UmaSamplesContainer::UpdateHistograms( |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 131 | const VideoSendStream::Config::Rtp& rtp_config, |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 132 | const VideoSendStream::Stats& current_stats) { |
asapersson | c2148a5 | 2016-02-04 00:33:21 -0800 | [diff] [blame] | 133 | RTC_DCHECK(uma_prefix_ == kRealtimePrefix || uma_prefix_ == kScreenPrefix); |
| 134 | const int kIndex = uma_prefix_ == kScreenPrefix ? 1 : 0; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 135 | int in_width = input_width_counter_.Avg(kMinRequiredMetricsSamples); |
| 136 | int in_height = input_height_counter_.Avg(kMinRequiredMetricsSamples); |
asapersson | 6f14be8 | 2015-11-16 00:40:49 -0800 | [diff] [blame] | 137 | int in_fps = round(input_frame_rate_tracker_.ComputeTotalRate()); |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 138 | if (in_width != -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 139 | RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "InputWidthInPixels", |
| 140 | in_width); |
| 141 | RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "InputHeightInPixels", |
| 142 | in_height); |
| 143 | RTC_HISTOGRAMS_COUNTS_100(kIndex, uma_prefix_ + "InputFramesPerSecond", |
| 144 | in_fps); |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 145 | } |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 146 | int sent_width = sent_width_counter_.Avg(kMinRequiredMetricsSamples); |
| 147 | int sent_height = sent_height_counter_.Avg(kMinRequiredMetricsSamples); |
asapersson | 6f14be8 | 2015-11-16 00:40:49 -0800 | [diff] [blame] | 148 | int sent_fps = round(sent_frame_rate_tracker_.ComputeTotalRate()); |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 149 | if (sent_width != -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 150 | RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "SentWidthInPixels", |
| 151 | sent_width); |
| 152 | RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "SentHeightInPixels", |
| 153 | sent_height); |
| 154 | RTC_HISTOGRAMS_COUNTS_100(kIndex, uma_prefix_ + "SentFramesPerSecond", |
| 155 | sent_fps); |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 156 | } |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 157 | int encode_ms = encode_time_counter_.Avg(kMinRequiredMetricsSamples); |
asapersson | c2148a5 | 2016-02-04 00:33:21 -0800 | [diff] [blame] | 158 | if (encode_ms != -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 159 | RTC_HISTOGRAMS_COUNTS_1000(kIndex, uma_prefix_ + "EncodeTimeInMs", |
| 160 | encode_ms); |
asapersson | c2148a5 | 2016-02-04 00:33:21 -0800 | [diff] [blame] | 161 | } |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 162 | int key_frames_permille = |
| 163 | key_frame_counter_.Permille(kMinRequiredMetricsSamples); |
asapersson | dec5ebf | 2015-10-05 02:36:17 -0700 | [diff] [blame] | 164 | if (key_frames_permille != -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 165 | RTC_HISTOGRAMS_COUNTS_1000(kIndex, uma_prefix_ + "KeyFramesSentInPermille", |
| 166 | key_frames_permille); |
asapersson | dec5ebf | 2015-10-05 02:36:17 -0700 | [diff] [blame] | 167 | } |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 168 | int quality_limited = |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 169 | quality_limited_frame_counter_.Percent(kMinRequiredMetricsSamples); |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 170 | if (quality_limited != -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 171 | RTC_HISTOGRAMS_PERCENTAGE(kIndex, |
| 172 | uma_prefix_ + "QualityLimitedResolutionInPercent", |
| 173 | quality_limited); |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 174 | } |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 175 | int downscales = quality_downscales_counter_.Avg(kMinRequiredMetricsSamples); |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 176 | if (downscales != -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 177 | RTC_HISTOGRAMS_ENUMERATION( |
asapersson | c2148a5 | 2016-02-04 00:33:21 -0800 | [diff] [blame] | 178 | kIndex, uma_prefix_ + "QualityLimitedResolutionDownscales", downscales, |
| 179 | 20); |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 180 | } |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 181 | int cpu_limited = |
| 182 | cpu_limited_frame_counter_.Percent(kMinRequiredMetricsSamples); |
| 183 | if (cpu_limited != -1) { |
| 184 | RTC_HISTOGRAMS_PERCENTAGE( |
| 185 | kIndex, uma_prefix_ + "CpuLimitedResolutionInPercent", cpu_limited); |
| 186 | } |
| 187 | int bw_limited = |
| 188 | bw_limited_frame_counter_.Percent(kMinRequiredMetricsSamples); |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 189 | if (bw_limited != -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 190 | RTC_HISTOGRAMS_PERCENTAGE( |
asapersson | c2148a5 | 2016-02-04 00:33:21 -0800 | [diff] [blame] | 191 | kIndex, uma_prefix_ + "BandwidthLimitedResolutionInPercent", |
| 192 | bw_limited); |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 193 | } |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 194 | int num_disabled = |
| 195 | bw_resolutions_disabled_counter_.Avg(kMinRequiredMetricsSamples); |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 196 | if (num_disabled != -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 197 | RTC_HISTOGRAMS_ENUMERATION( |
asapersson | c2148a5 | 2016-02-04 00:33:21 -0800 | [diff] [blame] | 198 | kIndex, uma_prefix_ + "BandwidthLimitedResolutionsDisabled", |
| 199 | num_disabled, 10); |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 200 | } |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 201 | int delay_ms = delay_counter_.Avg(kMinRequiredMetricsSamples); |
asapersson | f040b23 | 2015-11-04 00:59:03 -0800 | [diff] [blame] | 202 | if (delay_ms != -1) |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 203 | RTC_HISTOGRAMS_COUNTS_100000(kIndex, uma_prefix_ + "SendSideDelayInMs", |
| 204 | delay_ms); |
asapersson | f040b23 | 2015-11-04 00:59:03 -0800 | [diff] [blame] | 205 | |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 206 | int max_delay_ms = max_delay_counter_.Avg(kMinRequiredMetricsSamples); |
asapersson | f040b23 | 2015-11-04 00:59:03 -0800 | [diff] [blame] | 207 | if (max_delay_ms != -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 208 | RTC_HISTOGRAMS_COUNTS_100000(kIndex, uma_prefix_ + "SendSideDelayMaxInMs", |
| 209 | max_delay_ms); |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 210 | } |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 211 | |
asapersson | 118ef00 | 2016-03-31 00:00:19 -0700 | [diff] [blame] | 212 | for (const auto& it : qp_counters_) { |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 213 | int qp_vp8 = it.second.vp8.Avg(kMinRequiredMetricsSamples); |
asapersson | 5265fed | 2016-04-18 02:58:47 -0700 | [diff] [blame] | 214 | if (qp_vp8 != -1) { |
asapersson | 118ef00 | 2016-03-31 00:00:19 -0700 | [diff] [blame] | 215 | int spatial_idx = it.first; |
| 216 | if (spatial_idx == -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 217 | RTC_HISTOGRAMS_COUNTS_200(kIndex, uma_prefix_ + "Encoded.Qp.Vp8", |
| 218 | qp_vp8); |
asapersson | 118ef00 | 2016-03-31 00:00:19 -0700 | [diff] [blame] | 219 | } else if (spatial_idx == 0) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 220 | RTC_HISTOGRAMS_COUNTS_200(kIndex, uma_prefix_ + "Encoded.Qp.Vp8.S0", |
| 221 | qp_vp8); |
asapersson | 118ef00 | 2016-03-31 00:00:19 -0700 | [diff] [blame] | 222 | } else if (spatial_idx == 1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 223 | RTC_HISTOGRAMS_COUNTS_200(kIndex, uma_prefix_ + "Encoded.Qp.Vp8.S1", |
| 224 | qp_vp8); |
asapersson | 118ef00 | 2016-03-31 00:00:19 -0700 | [diff] [blame] | 225 | } else if (spatial_idx == 2) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 226 | RTC_HISTOGRAMS_COUNTS_200(kIndex, uma_prefix_ + "Encoded.Qp.Vp8.S2", |
| 227 | qp_vp8); |
asapersson | 118ef00 | 2016-03-31 00:00:19 -0700 | [diff] [blame] | 228 | } else { |
| 229 | LOG(LS_WARNING) << "QP stats not recorded for VP8 spatial idx " |
| 230 | << spatial_idx; |
| 231 | } |
| 232 | } |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 233 | int qp_vp9 = it.second.vp9.Avg(kMinRequiredMetricsSamples); |
asapersson | 5265fed | 2016-04-18 02:58:47 -0700 | [diff] [blame] | 234 | if (qp_vp9 != -1) { |
| 235 | int spatial_idx = it.first; |
| 236 | if (spatial_idx == -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 237 | RTC_HISTOGRAMS_COUNTS_500(kIndex, uma_prefix_ + "Encoded.Qp.Vp9", |
| 238 | qp_vp9); |
asapersson | 5265fed | 2016-04-18 02:58:47 -0700 | [diff] [blame] | 239 | } else if (spatial_idx == 0) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 240 | RTC_HISTOGRAMS_COUNTS_500(kIndex, uma_prefix_ + "Encoded.Qp.Vp9.S0", |
| 241 | qp_vp9); |
asapersson | 5265fed | 2016-04-18 02:58:47 -0700 | [diff] [blame] | 242 | } else if (spatial_idx == 1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 243 | RTC_HISTOGRAMS_COUNTS_500(kIndex, uma_prefix_ + "Encoded.Qp.Vp9.S1", |
| 244 | qp_vp9); |
asapersson | 5265fed | 2016-04-18 02:58:47 -0700 | [diff] [blame] | 245 | } else if (spatial_idx == 2) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 246 | RTC_HISTOGRAMS_COUNTS_500(kIndex, uma_prefix_ + "Encoded.Qp.Vp9.S2", |
| 247 | qp_vp9); |
asapersson | 5265fed | 2016-04-18 02:58:47 -0700 | [diff] [blame] | 248 | } else { |
| 249 | LOG(LS_WARNING) << "QP stats not recorded for VP9 spatial layer " |
| 250 | << spatial_idx; |
| 251 | } |
| 252 | } |
asapersson | 827cab3 | 2016-11-02 09:08:47 -0700 | [diff] [blame] | 253 | int qp_h264 = it.second.h264.Avg(kMinRequiredMetricsSamples); |
| 254 | if (qp_h264 != -1) { |
| 255 | int spatial_idx = it.first; |
| 256 | RTC_DCHECK_EQ(-1, spatial_idx); |
| 257 | RTC_HISTOGRAMS_COUNTS_100(kIndex, uma_prefix_ + "Encoded.Qp.H264", |
| 258 | qp_h264); |
| 259 | } |
asapersson | 118ef00 | 2016-03-31 00:00:19 -0700 | [diff] [blame] | 260 | } |
| 261 | |
sprang | e2d83d6 | 2016-02-19 09:03:26 -0800 | [diff] [blame] | 262 | if (first_rtcp_stats_time_ms_ != -1) { |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 263 | int64_t elapsed_sec = |
| 264 | (clock_->TimeInMilliseconds() - first_rtcp_stats_time_ms_) / 1000; |
| 265 | if (elapsed_sec >= metrics::kMinRunTimeInSeconds) { |
| 266 | int fraction_lost = report_block_stats_.FractionLostInPercent(); |
| 267 | if (fraction_lost != -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 268 | RTC_HISTOGRAMS_PERCENTAGE( |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 269 | kIndex, uma_prefix_ + "SentPacketsLostInPercent", fraction_lost); |
| 270 | } |
| 271 | |
| 272 | // The RTCP packet type counters, delivered via the |
| 273 | // RtcpPacketTypeCounterObserver interface, are aggregates over the entire |
| 274 | // life of the send stream and are not reset when switching content type. |
| 275 | // For the purpose of these statistics though, we want new counts when |
| 276 | // switching since we switch histogram name. On every reset of the |
| 277 | // UmaSamplesContainer, we save the initial state of the counters, so that |
| 278 | // we can calculate the delta here and aggregate over all ssrcs. |
| 279 | RtcpPacketTypeCounter counters; |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 280 | for (uint32_t ssrc : rtp_config.ssrcs) { |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 281 | auto kv = current_stats.substreams.find(ssrc); |
| 282 | if (kv == current_stats.substreams.end()) |
| 283 | continue; |
| 284 | |
| 285 | RtcpPacketTypeCounter stream_counters = |
| 286 | kv->second.rtcp_packet_type_counts; |
| 287 | kv = start_stats_.substreams.find(ssrc); |
| 288 | if (kv != start_stats_.substreams.end()) |
| 289 | stream_counters.Subtract(kv->second.rtcp_packet_type_counts); |
| 290 | |
| 291 | counters.Add(stream_counters); |
| 292 | } |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 293 | RTC_HISTOGRAMS_COUNTS_10000(kIndex, |
| 294 | uma_prefix_ + "NackPacketsReceivedPerMinute", |
| 295 | counters.nack_packets * 60 / elapsed_sec); |
| 296 | RTC_HISTOGRAMS_COUNTS_10000(kIndex, |
| 297 | uma_prefix_ + "FirPacketsReceivedPerMinute", |
| 298 | counters.fir_packets * 60 / elapsed_sec); |
| 299 | RTC_HISTOGRAMS_COUNTS_10000(kIndex, |
| 300 | uma_prefix_ + "PliPacketsReceivedPerMinute", |
| 301 | counters.pli_packets * 60 / elapsed_sec); |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 302 | if (counters.nack_requests > 0) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 303 | RTC_HISTOGRAMS_PERCENTAGE( |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 304 | kIndex, uma_prefix_ + "UniqueNackRequestsReceivedInPercent", |
| 305 | counters.UniqueNackRequestsInPercent()); |
| 306 | } |
sprang | e2d83d6 | 2016-02-19 09:03:26 -0800 | [diff] [blame] | 307 | } |
| 308 | } |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 309 | |
| 310 | if (first_rtp_stats_time_ms_ != -1) { |
| 311 | int64_t elapsed_sec = |
| 312 | (clock_->TimeInMilliseconds() - first_rtp_stats_time_ms_) / 1000; |
| 313 | if (elapsed_sec >= metrics::kMinRunTimeInSeconds) { |
| 314 | StreamDataCounters rtp; |
| 315 | StreamDataCounters rtx; |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 316 | AccumulateRtxStats(current_stats, rtp_config.rtx.ssrcs, &rtp, &rtx); |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 317 | StreamDataCounters start_rtp; |
| 318 | StreamDataCounters start_rtx; |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 319 | AccumulateRtxStats(start_stats_, rtp_config.rtx.ssrcs, &start_rtp, |
| 320 | &start_rtx); |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 321 | rtp.Subtract(start_rtp); |
| 322 | rtx.Subtract(start_rtx); |
| 323 | StreamDataCounters rtp_rtx = rtp; |
| 324 | rtp_rtx.Add(rtx); |
| 325 | |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 326 | RTC_HISTOGRAMS_COUNTS_10000( |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 327 | kIndex, uma_prefix_ + "BitrateSentInKbps", |
| 328 | static_cast<int>(rtp_rtx.transmitted.TotalBytes() * 8 / elapsed_sec / |
| 329 | 1000)); |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 330 | RTC_HISTOGRAMS_COUNTS_10000( |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 331 | kIndex, uma_prefix_ + "MediaBitrateSentInKbps", |
| 332 | static_cast<int>(rtp.MediaPayloadBytes() * 8 / elapsed_sec / 1000)); |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 333 | RTC_HISTOGRAMS_COUNTS_10000( |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 334 | kIndex, uma_prefix_ + "PaddingBitrateSentInKbps", |
| 335 | static_cast<int>(rtp_rtx.transmitted.padding_bytes * 8 / elapsed_sec / |
| 336 | 1000)); |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 337 | RTC_HISTOGRAMS_COUNTS_10000( |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 338 | kIndex, uma_prefix_ + "RetransmittedBitrateSentInKbps", |
| 339 | static_cast<int>(rtp_rtx.retransmitted.TotalBytes() * 8 / |
| 340 | elapsed_sec / 1000)); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 341 | if (!rtp_config.rtx.ssrcs.empty()) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 342 | RTC_HISTOGRAMS_COUNTS_10000( |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 343 | kIndex, uma_prefix_ + "RtxBitrateSentInKbps", |
| 344 | static_cast<int>(rtx.transmitted.TotalBytes() * 8 / elapsed_sec / |
| 345 | 1000)); |
| 346 | } |
brandtr | cd188f6 | 2016-11-15 08:21:52 -0800 | [diff] [blame] | 347 | if (rtp_config.flexfec.flexfec_payload_type != -1 || |
| 348 | rtp_config.ulpfec.red_payload_type != -1) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 349 | RTC_HISTOGRAMS_COUNTS_10000(kIndex, |
| 350 | uma_prefix_ + "FecBitrateSentInKbps", |
| 351 | static_cast<int>(rtp_rtx.fec.TotalBytes() * |
| 352 | 8 / elapsed_sec / 1000)); |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | } |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 356 | } |
| 357 | |
Per | a48ddb7 | 2016-09-29 11:48:50 +0200 | [diff] [blame] | 358 | void SendStatisticsProxy::OnEncoderReconfigured( |
| 359 | const VideoEncoderConfig& config, |
| 360 | uint32_t preferred_bitrate_bps) { |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 361 | rtc::CritScope lock(&crit_); |
Per | a48ddb7 | 2016-09-29 11:48:50 +0200 | [diff] [blame] | 362 | stats_.preferred_media_bitrate_bps = preferred_bitrate_bps; |
| 363 | |
| 364 | if (content_type_ != config.content_type) { |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 365 | uma_container_->UpdateHistograms(rtp_config_, stats_); |
Per | a48ddb7 | 2016-09-29 11:48:50 +0200 | [diff] [blame] | 366 | uma_container_.reset(new UmaSamplesContainer( |
| 367 | GetUmaPrefix(config.content_type), stats_, clock_)); |
| 368 | content_type_ = config.content_type; |
asapersson | f040b23 | 2015-11-04 00:59:03 -0800 | [diff] [blame] | 369 | } |
Åsa Persson | 24b4eda | 2015-06-16 10:17:01 +0200 | [diff] [blame] | 370 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 371 | |
perkj | 275afc5 | 2016-09-01 00:21:16 -0700 | [diff] [blame] | 372 | void SendStatisticsProxy::OnEncoderStatsUpdate(uint32_t framerate, |
| 373 | uint32_t bitrate) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 374 | rtc::CritScope lock(&crit_); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 375 | stats_.encode_frame_rate = framerate; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 376 | stats_.media_bitrate_bps = bitrate; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 379 | void SendStatisticsProxy::OnEncodedFrameTimeMeasured( |
| 380 | int encode_time_ms, |
pbos@webrtc.org | 3e6e271 | 2015-02-26 12:19:31 +0000 | [diff] [blame] | 381 | const CpuOveruseMetrics& metrics) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 382 | rtc::CritScope lock(&crit_); |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 383 | uma_container_->encode_time_counter_.Add(encode_time_ms); |
| 384 | encode_time_.Apply(1.0f, encode_time_ms); |
| 385 | stats_.avg_encode_time_ms = round(encode_time_.filtered()); |
pbos@webrtc.org | 3e6e271 | 2015-02-26 12:19:31 +0000 | [diff] [blame] | 386 | stats_.encode_usage_percent = metrics.encode_usage_percent; |
| 387 | } |
| 388 | |
Peter Boström | 7083e11 | 2015-09-22 16:28:51 +0200 | [diff] [blame] | 389 | void SendStatisticsProxy::OnSuspendChange(bool is_suspended) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 390 | rtc::CritScope lock(&crit_); |
henrik.lundin@webrtc.org | b10363f | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 391 | stats_.suspended = is_suspended; |
| 392 | } |
| 393 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 394 | VideoSendStream::Stats SendStatisticsProxy::GetStats() { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 395 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 396 | PurgeOldStats(); |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 397 | stats_.input_frame_rate = |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 398 | round(uma_container_->input_frame_rate_tracker_.ComputeRate()); |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 399 | return stats_; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 400 | } |
| 401 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 402 | void SendStatisticsProxy::PurgeOldStats() { |
Peter Boström | 20f3f94 | 2015-05-15 11:33:39 +0200 | [diff] [blame] | 403 | int64_t old_stats_ms = clock_->TimeInMilliseconds() - kStatsTimeoutMs; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 404 | for (std::map<uint32_t, VideoSendStream::StreamStats>::iterator it = |
| 405 | stats_.substreams.begin(); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 406 | it != stats_.substreams.end(); ++it) { |
| 407 | uint32_t ssrc = it->first; |
Peter Boström | 20f3f94 | 2015-05-15 11:33:39 +0200 | [diff] [blame] | 408 | if (update_times_[ssrc].resolution_update_ms <= old_stats_ms) { |
| 409 | it->second.width = 0; |
| 410 | it->second.height = 0; |
| 411 | } |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 415 | VideoSendStream::StreamStats* SendStatisticsProxy::GetStatsEntry( |
| 416 | uint32_t ssrc) { |
| 417 | std::map<uint32_t, VideoSendStream::StreamStats>::iterator it = |
| 418 | stats_.substreams.find(ssrc); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 419 | if (it != stats_.substreams.end()) |
| 420 | return &it->second; |
| 421 | |
brandtr | cd188f6 | 2016-11-15 08:21:52 -0800 | [diff] [blame] | 422 | bool is_media = std::find(rtp_config_.ssrcs.begin(), rtp_config_.ssrcs.end(), |
| 423 | ssrc) != rtp_config_.ssrcs.end(); |
| 424 | bool is_flexfec = rtp_config_.flexfec.flexfec_payload_type != -1 && |
| 425 | ssrc == rtp_config_.flexfec.flexfec_ssrc; |
| 426 | bool is_rtx = |
| 427 | std::find(rtp_config_.rtx.ssrcs.begin(), rtp_config_.rtx.ssrcs.end(), |
| 428 | ssrc) != rtp_config_.rtx.ssrcs.end(); |
| 429 | if (!is_media && !is_flexfec && !is_rtx) |
| 430 | return nullptr; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 431 | |
asapersson | 2e5cfcd | 2016-08-11 08:41:18 -0700 | [diff] [blame] | 432 | // Insert new entry and return ptr. |
| 433 | VideoSendStream::StreamStats* entry = &stats_.substreams[ssrc]; |
| 434 | entry->is_rtx = is_rtx; |
asapersson | a6a699a | 2016-11-25 03:52:46 -0800 | [diff] [blame^] | 435 | entry->is_flexfec = is_flexfec; |
asapersson | 2e5cfcd | 2016-08-11 08:41:18 -0700 | [diff] [blame] | 436 | |
| 437 | return entry; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 438 | } |
| 439 | |
Peter Boström | 20f3f94 | 2015-05-15 11:33:39 +0200 | [diff] [blame] | 440 | void SendStatisticsProxy::OnInactiveSsrc(uint32_t ssrc) { |
| 441 | rtc::CritScope lock(&crit_); |
| 442 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 443 | if (!stats) |
Peter Boström | 20f3f94 | 2015-05-15 11:33:39 +0200 | [diff] [blame] | 444 | return; |
| 445 | |
| 446 | stats->total_bitrate_bps = 0; |
| 447 | stats->retransmit_bitrate_bps = 0; |
| 448 | stats->height = 0; |
| 449 | stats->width = 0; |
| 450 | } |
| 451 | |
perkj | f5b2e51 | 2016-07-05 08:34:04 -0700 | [diff] [blame] | 452 | void SendStatisticsProxy::OnSetEncoderTargetRate(uint32_t bitrate_bps) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 453 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 454 | stats_.target_media_bitrate_bps = bitrate_bps; |
| 455 | } |
| 456 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 457 | void SendStatisticsProxy::OnSendEncodedImage( |
| 458 | const EncodedImage& encoded_image, |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 459 | const CodecSpecificInfo* codec_info) { |
| 460 | size_t simulcast_idx = 0; |
| 461 | |
perkj | 275afc5 | 2016-09-01 00:21:16 -0700 | [diff] [blame] | 462 | rtc::CritScope lock(&crit_); |
sakal | 43536c3 | 2016-10-24 01:46:43 -0700 | [diff] [blame] | 463 | ++stats_.frames_encoded; |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 464 | if (codec_info) { |
| 465 | if (codec_info->codecType == kVideoCodecVP8) { |
| 466 | simulcast_idx = codec_info->codecSpecific.VP8.simulcastIdx; |
| 467 | } else if (codec_info->codecType == kVideoCodecGeneric) { |
| 468 | simulcast_idx = codec_info->codecSpecific.generic.simulcast_idx; |
| 469 | } |
perkj | 275afc5 | 2016-09-01 00:21:16 -0700 | [diff] [blame] | 470 | if (codec_info->codec_name) { |
| 471 | stats_.encoder_implementation_name = codec_info->codec_name; |
| 472 | } |
kjellander | 02b3d27 | 2016-04-20 05:05:54 -0700 | [diff] [blame] | 473 | } |
| 474 | |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 475 | if (simulcast_idx >= rtp_config_.ssrcs.size()) { |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 476 | LOG(LS_ERROR) << "Encoded image outside simulcast range (" << simulcast_idx |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 477 | << " >= " << rtp_config_.ssrcs.size() << ")."; |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 478 | return; |
| 479 | } |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 480 | uint32_t ssrc = rtp_config_.ssrcs[simulcast_idx]; |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 481 | |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 482 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 483 | if (!stats) |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 484 | return; |
| 485 | |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 486 | stats->width = encoded_image._encodedWidth; |
| 487 | stats->height = encoded_image._encodedHeight; |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 488 | update_times_[ssrc].resolution_update_ms = clock_->TimeInMilliseconds(); |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 489 | |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 490 | uma_container_->key_frame_counter_.Add(encoded_image._frameType == |
| 491 | kVideoFrameKey); |
asapersson | dec5ebf | 2015-10-05 02:36:17 -0700 | [diff] [blame] | 492 | |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 493 | stats_.bw_limited_resolution = |
| 494 | encoded_image.adapt_reason_.quality_resolution_downscales > 0 || |
| 495 | encoded_image.adapt_reason_.bw_resolutions_disabled > 0; |
| 496 | |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 497 | if (encoded_image.adapt_reason_.quality_resolution_downscales != -1) { |
| 498 | bool downscaled = |
| 499 | encoded_image.adapt_reason_.quality_resolution_downscales > 0; |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 500 | uma_container_->quality_limited_frame_counter_.Add(downscaled); |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 501 | if (downscaled) { |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 502 | uma_container_->quality_downscales_counter_.Add( |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 503 | encoded_image.adapt_reason_.quality_resolution_downscales); |
| 504 | } |
| 505 | } |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 506 | if (encoded_image.adapt_reason_.bw_resolutions_disabled != -1) { |
| 507 | bool bw_limited = encoded_image.adapt_reason_.bw_resolutions_disabled > 0; |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 508 | uma_container_->bw_limited_frame_counter_.Add(bw_limited); |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 509 | if (bw_limited) { |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 510 | uma_container_->bw_resolutions_disabled_counter_.Add( |
| 511 | encoded_image.adapt_reason_.bw_resolutions_disabled); |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 512 | } |
| 513 | } |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 514 | |
sakal | 87da404 | 2016-10-31 06:53:47 -0700 | [diff] [blame] | 515 | if (encoded_image.qp_ != -1) { |
| 516 | if (!stats_.qp_sum) |
| 517 | stats_.qp_sum = rtc::Optional<uint64_t>(0); |
| 518 | *stats_.qp_sum += encoded_image.qp_; |
| 519 | |
| 520 | if (codec_info) { |
| 521 | if (codec_info->codecType == kVideoCodecVP8) { |
| 522 | int spatial_idx = (rtp_config_.ssrcs.size() == 1) |
| 523 | ? -1 |
| 524 | : static_cast<int>(simulcast_idx); |
| 525 | uma_container_->qp_counters_[spatial_idx].vp8.Add(encoded_image.qp_); |
| 526 | } else if (codec_info->codecType == kVideoCodecVP9) { |
| 527 | int spatial_idx = |
| 528 | (codec_info->codecSpecific.VP9.num_spatial_layers == 1) |
| 529 | ? -1 |
| 530 | : codec_info->codecSpecific.VP9.spatial_idx; |
| 531 | uma_container_->qp_counters_[spatial_idx].vp9.Add(encoded_image.qp_); |
asapersson | 827cab3 | 2016-11-02 09:08:47 -0700 | [diff] [blame] | 532 | } else if (codec_info->codecType == kVideoCodecH264) { |
| 533 | int spatial_idx = -1; |
| 534 | uma_container_->qp_counters_[spatial_idx].h264.Add(encoded_image.qp_); |
sakal | 87da404 | 2016-10-31 06:53:47 -0700 | [diff] [blame] | 535 | } |
asapersson | 5265fed | 2016-04-18 02:58:47 -0700 | [diff] [blame] | 536 | } |
asapersson | 118ef00 | 2016-03-31 00:00:19 -0700 | [diff] [blame] | 537 | } |
| 538 | |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 539 | // TODO(asapersson): This is incorrect if simulcast layers are encoded on |
| 540 | // different threads and there is no guarantee that one frame of all layers |
| 541 | // are encoded before the next start. |
| 542 | if (last_sent_frame_timestamp_ > 0 && |
| 543 | encoded_image._timeStamp != last_sent_frame_timestamp_) { |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 544 | uma_container_->sent_frame_rate_tracker_.AddSamples(1); |
| 545 | uma_container_->sent_width_counter_.Add( |
| 546 | uma_container_->max_sent_width_per_timestamp_); |
| 547 | uma_container_->sent_height_counter_.Add( |
| 548 | uma_container_->max_sent_height_per_timestamp_); |
| 549 | uma_container_->max_sent_width_per_timestamp_ = 0; |
| 550 | uma_container_->max_sent_height_per_timestamp_ = 0; |
Åsa Persson | 24b4eda | 2015-06-16 10:17:01 +0200 | [diff] [blame] | 551 | } |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 552 | last_sent_frame_timestamp_ = encoded_image._timeStamp; |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 553 | uma_container_->max_sent_width_per_timestamp_ = |
| 554 | std::max(uma_container_->max_sent_width_per_timestamp_, |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 555 | static_cast<int>(encoded_image._encodedWidth)); |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 556 | uma_container_->max_sent_height_per_timestamp_ = |
| 557 | std::max(uma_container_->max_sent_height_per_timestamp_, |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 558 | static_cast<int>(encoded_image._encodedHeight)); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 559 | } |
| 560 | |
Per | 69b332d | 2016-06-02 15:45:42 +0200 | [diff] [blame] | 561 | int SendStatisticsProxy::GetSendFrameRate() const { |
| 562 | rtc::CritScope lock(&crit_); |
| 563 | return stats_.encode_frame_rate; |
| 564 | } |
| 565 | |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 566 | void SendStatisticsProxy::OnIncomingFrame(int width, int height) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 567 | rtc::CritScope lock(&crit_); |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 568 | uma_container_->input_frame_rate_tracker_.AddSamples(1); |
| 569 | uma_container_->input_width_counter_.Add(width); |
| 570 | uma_container_->input_height_counter_.Add(height); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 571 | uma_container_->cpu_limited_frame_counter_.Add(stats_.cpu_limited_resolution); |
| 572 | } |
| 573 | |
| 574 | void SendStatisticsProxy::SetCpuRestrictedResolution( |
| 575 | bool cpu_restricted_resolution) { |
| 576 | rtc::CritScope lock(&crit_); |
| 577 | stats_.cpu_limited_resolution = cpu_restricted_resolution; |
| 578 | } |
| 579 | |
| 580 | void SendStatisticsProxy::OnCpuRestrictedResolutionChanged( |
| 581 | bool cpu_restricted_resolution) { |
| 582 | rtc::CritScope lock(&crit_); |
| 583 | stats_.cpu_limited_resolution = cpu_restricted_resolution; |
| 584 | ++stats_.number_of_cpu_adapt_changes; |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 585 | } |
| 586 | |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 587 | void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( |
| 588 | uint32_t ssrc, |
| 589 | const RtcpPacketTypeCounter& packet_counter) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 590 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 591 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 592 | if (!stats) |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 593 | return; |
| 594 | |
| 595 | stats->rtcp_packet_type_counts = packet_counter; |
sprang | 07fb9be | 2016-02-24 07:55:00 -0800 | [diff] [blame] | 596 | if (uma_container_->first_rtcp_stats_time_ms_ == -1) |
| 597 | uma_container_->first_rtcp_stats_time_ms_ = clock_->TimeInMilliseconds(); |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 598 | } |
| 599 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 600 | void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, |
| 601 | uint32_t ssrc) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 602 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 603 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 604 | if (!stats) |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 605 | return; |
| 606 | |
| 607 | stats->rtcp_stats = statistics; |
sprang | e2d83d6 | 2016-02-19 09:03:26 -0800 | [diff] [blame] | 608 | uma_container_->report_block_stats_.Store(statistics, 0, ssrc); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Peter Boström | d1d66ba | 2016-02-08 14:07:14 +0100 | [diff] [blame] | 611 | void SendStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {} |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 612 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 613 | void SendStatisticsProxy::DataCountersUpdated( |
| 614 | const StreamDataCounters& counters, |
| 615 | uint32_t ssrc) { |
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 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 618 | RTC_DCHECK(stats) << "DataCountersUpdated reported for unknown ssrc: " |
| 619 | << ssrc; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 620 | |
asapersson | a6a699a | 2016-11-25 03:52:46 -0800 | [diff] [blame^] | 621 | if (stats->is_flexfec) { |
| 622 | // The same counters are reported for both the media ssrc and flexfec ssrc. |
| 623 | // Bitrate stats are summed for all SSRCs. Use fec stats from media update. |
| 624 | return; |
| 625 | } |
| 626 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 627 | stats->rtp_stats = counters; |
Erik Språng | 22c2b48 | 2016-03-01 09:40:42 +0100 | [diff] [blame] | 628 | if (uma_container_->first_rtp_stats_time_ms_ == -1) |
| 629 | uma_container_->first_rtp_stats_time_ms_ = clock_->TimeInMilliseconds(); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 630 | } |
| 631 | |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 632 | void SendStatisticsProxy::Notify(uint32_t total_bitrate_bps, |
| 633 | uint32_t retransmit_bitrate_bps, |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 634 | uint32_t ssrc) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 635 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 636 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 637 | if (!stats) |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 638 | return; |
| 639 | |
sprang | cd349d9 | 2016-07-13 09:11:28 -0700 | [diff] [blame] | 640 | stats->total_bitrate_bps = total_bitrate_bps; |
| 641 | stats->retransmit_bitrate_bps = retransmit_bitrate_bps; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 642 | } |
| 643 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 644 | void SendStatisticsProxy::FrameCountUpdated(const FrameCounts& frame_counts, |
| 645 | uint32_t ssrc) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 646 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 647 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 648 | if (!stats) |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 649 | return; |
| 650 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 651 | stats->frame_counts = frame_counts; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 652 | } |
| 653 | |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 654 | void SendStatisticsProxy::SendSideDelayUpdated(int avg_delay_ms, |
| 655 | int max_delay_ms, |
| 656 | uint32_t ssrc) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 657 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 658 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
Peter Boström | 74f6e9e | 2016-04-04 17:56:10 +0200 | [diff] [blame] | 659 | if (!stats) |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 660 | return; |
| 661 | stats->avg_delay_ms = avg_delay_ms; |
| 662 | stats->max_delay_ms = max_delay_ms; |
asapersson | f040b23 | 2015-11-04 00:59:03 -0800 | [diff] [blame] | 663 | |
sprang | b4a1ae5 | 2015-12-03 08:10:08 -0800 | [diff] [blame] | 664 | uma_container_->delay_counter_.Add(avg_delay_ms); |
| 665 | uma_container_->max_delay_counter_.Add(max_delay_ms); |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 666 | } |
| 667 | |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 668 | void SendStatisticsProxy::SampleCounter::Add(int sample) { |
| 669 | sum += sample; |
| 670 | ++num_samples; |
| 671 | } |
| 672 | |
| 673 | int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { |
| 674 | if (num_samples < min_required_samples || num_samples == 0) |
| 675 | return -1; |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 676 | return (sum + (num_samples / 2)) / num_samples; |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 677 | } |
| 678 | |
asapersson | dec5ebf | 2015-10-05 02:36:17 -0700 | [diff] [blame] | 679 | void SendStatisticsProxy::BoolSampleCounter::Add(bool sample) { |
| 680 | if (sample) |
| 681 | ++sum; |
| 682 | ++num_samples; |
| 683 | } |
| 684 | |
| 685 | int SendStatisticsProxy::BoolSampleCounter::Percent( |
| 686 | int min_required_samples) const { |
| 687 | return Fraction(min_required_samples, 100.0f); |
| 688 | } |
| 689 | |
| 690 | int SendStatisticsProxy::BoolSampleCounter::Permille( |
| 691 | int min_required_samples) const { |
| 692 | return Fraction(min_required_samples, 1000.0f); |
| 693 | } |
| 694 | |
| 695 | int SendStatisticsProxy::BoolSampleCounter::Fraction( |
| 696 | int min_required_samples, float multiplier) const { |
| 697 | if (num_samples < min_required_samples || num_samples == 0) |
| 698 | return -1; |
| 699 | return static_cast<int>((sum * multiplier / num_samples) + 0.5f); |
| 700 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 701 | } // namespace webrtc |