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