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> |
| 16 | |
pbos@webrtc.org | 49096de | 2015-02-24 22:37:52 +0000 | [diff] [blame] | 17 | #include "webrtc/base/checks.h" |
| 18 | |
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/critical_section_wrapper.h" |
| 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 { |
| 25 | // Used by histograms. Values of entries should not be changed. |
| 26 | enum HistogramCodecType { |
| 27 | kVideoUnknown = 0, |
| 28 | kVideoVp8 = 1, |
| 29 | kVideoVp9 = 2, |
| 30 | kVideoH264 = 3, |
| 31 | kVideoMax = 64, |
| 32 | }; |
| 33 | |
| 34 | HistogramCodecType PayloadNameToHistogramCodecType( |
| 35 | const std::string& payload_name) { |
| 36 | if (payload_name == "VP8") { |
| 37 | return kVideoVp8; |
| 38 | } else if (payload_name == "VP9") { |
| 39 | return kVideoVp9; |
| 40 | } else if (payload_name == "H264") { |
| 41 | return kVideoH264; |
| 42 | } else { |
| 43 | return kVideoUnknown; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void UpdateCodecTypeHistogram(const std::string& payload_name) { |
| 48 | RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.Encoder.CodecType", |
| 49 | PayloadNameToHistogramCodecType(payload_name), kVideoMax); |
| 50 | } |
| 51 | } // namespace |
| 52 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 53 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 54 | const int SendStatisticsProxy::kStatsTimeoutMs = 5000; |
| 55 | |
| 56 | SendStatisticsProxy::SendStatisticsProxy(Clock* clock, |
| 57 | const VideoSendStream::Config& config) |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 58 | : clock_(clock), |
| 59 | config_(config), |
Tim Psiaki | 6304626 | 2015-09-14 10:38:08 -0700 | [diff] [blame] | 60 | input_frame_rate_tracker_(100u, 10u), |
| 61 | sent_frame_rate_tracker_(100u, 10u), |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 62 | last_sent_frame_timestamp_(0), |
| 63 | max_sent_width_per_timestamp_(0), |
| 64 | max_sent_height_per_timestamp_(0) { |
asapersson | 2a0a2a4 | 2015-10-27 01:32:00 -0700 | [diff] [blame] | 65 | UpdateCodecTypeHistogram(config_.encoder_settings.payload_name); |
pbos@webrtc.org | de1429e | 2014-04-28 13:00:21 +0000 | [diff] [blame] | 66 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 67 | |
Åsa Persson | 24b4eda | 2015-06-16 10:17:01 +0200 | [diff] [blame] | 68 | SendStatisticsProxy::~SendStatisticsProxy() { |
| 69 | UpdateHistograms(); |
| 70 | } |
| 71 | |
| 72 | void SendStatisticsProxy::UpdateHistograms() { |
| 73 | int input_fps = |
Tim Psiaki | ad13d2f | 2015-11-10 16:34:50 -0800 | [diff] [blame^] | 74 | round(input_frame_rate_tracker_.ComputeTotalRate()); |
Åsa Persson | 24b4eda | 2015-06-16 10:17:01 +0200 | [diff] [blame] | 75 | if (input_fps > 0) |
| 76 | RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.InputFramesPerSecond", input_fps); |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 77 | int sent_fps = |
Tim Psiaki | ad13d2f | 2015-11-10 16:34:50 -0800 | [diff] [blame^] | 78 | round(sent_frame_rate_tracker_.ComputeTotalRate()); |
Åsa Persson | 24b4eda | 2015-06-16 10:17:01 +0200 | [diff] [blame] | 79 | if (sent_fps > 0) |
| 80 | RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.SentFramesPerSecond", sent_fps); |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 81 | |
asapersson | 6718e97 | 2015-07-24 00:20:58 -0700 | [diff] [blame] | 82 | const int kMinRequiredSamples = 200; |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 83 | int in_width = input_width_counter_.Avg(kMinRequiredSamples); |
| 84 | int in_height = input_height_counter_.Avg(kMinRequiredSamples); |
| 85 | if (in_width != -1) { |
| 86 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.InputWidthInPixels", in_width); |
| 87 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.InputHeightInPixels", in_height); |
| 88 | } |
| 89 | int sent_width = sent_width_counter_.Avg(kMinRequiredSamples); |
| 90 | int sent_height = sent_height_counter_.Avg(kMinRequiredSamples); |
| 91 | if (sent_width != -1) { |
| 92 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.SentWidthInPixels", sent_width); |
| 93 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.SentHeightInPixels", sent_height); |
| 94 | } |
asapersson | 6718e97 | 2015-07-24 00:20:58 -0700 | [diff] [blame] | 95 | int encode_ms = encode_time_counter_.Avg(kMinRequiredSamples); |
| 96 | if (encode_ms != -1) |
| 97 | RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.EncodeTimeInMs", encode_ms); |
asapersson | dec5ebf | 2015-10-05 02:36:17 -0700 | [diff] [blame] | 98 | |
| 99 | int key_frames_permille = key_frame_counter_.Permille(kMinRequiredSamples); |
| 100 | if (key_frames_permille != -1) { |
| 101 | RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.KeyFramesSentInPermille", |
| 102 | key_frames_permille); |
| 103 | } |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 104 | int quality_limited = |
| 105 | quality_limited_frame_counter_.Percent(kMinRequiredSamples); |
| 106 | if (quality_limited != -1) { |
| 107 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.QualityLimitedResolutionInPercent", |
| 108 | quality_limited); |
| 109 | } |
| 110 | int downscales = quality_downscales_counter_.Avg(kMinRequiredSamples); |
| 111 | if (downscales != -1) { |
| 112 | RTC_HISTOGRAM_ENUMERATION("WebRTC.Video.QualityLimitedResolutionDownscales", |
| 113 | downscales, 20); |
| 114 | } |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 115 | int bw_limited = bw_limited_frame_counter_.Percent(kMinRequiredSamples); |
| 116 | if (bw_limited != -1) { |
| 117 | RTC_HISTOGRAM_PERCENTAGE("WebRTC.Video.BandwidthLimitedResolutionInPercent", |
| 118 | bw_limited); |
| 119 | } |
| 120 | int num_disabled = bw_resolutions_disabled_counter_.Avg(kMinRequiredSamples); |
| 121 | if (num_disabled != -1) { |
| 122 | RTC_HISTOGRAM_ENUMERATION( |
| 123 | "WebRTC.Video.BandwidthLimitedResolutionsDisabled", num_disabled, 10); |
| 124 | } |
asapersson | f040b23 | 2015-11-04 00:59:03 -0800 | [diff] [blame] | 125 | int delay_ms = delay_counter_.Avg(kMinRequiredSamples); |
| 126 | if (delay_ms != -1) |
| 127 | RTC_HISTOGRAM_COUNTS_100000("WebRTC.Video.SendSideDelayInMs", delay_ms); |
| 128 | |
| 129 | int max_delay_ms = max_delay_counter_.Avg(kMinRequiredSamples); |
| 130 | if (max_delay_ms != -1) { |
| 131 | RTC_HISTOGRAM_COUNTS_100000( |
| 132 | "WebRTC.Video.SendSideDelayMaxInMs", max_delay_ms); |
| 133 | } |
Åsa Persson | 24b4eda | 2015-06-16 10:17:01 +0200 | [diff] [blame] | 134 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 135 | |
Peter Boström | 7083e11 | 2015-09-22 16:28:51 +0200 | [diff] [blame] | 136 | void SendStatisticsProxy::OnOutgoingRate(uint32_t framerate, uint32_t bitrate) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 137 | rtc::CritScope lock(&crit_); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 138 | stats_.encode_frame_rate = framerate; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 139 | stats_.media_bitrate_bps = bitrate; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 140 | } |
| 141 | |
pbos@webrtc.org | 3e6e271 | 2015-02-26 12:19:31 +0000 | [diff] [blame] | 142 | void SendStatisticsProxy::CpuOveruseMetricsUpdated( |
| 143 | const CpuOveruseMetrics& metrics) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 144 | rtc::CritScope lock(&crit_); |
asapersson | 6718e97 | 2015-07-24 00:20:58 -0700 | [diff] [blame] | 145 | // TODO(asapersson): Change to use OnEncodedFrame() for avg_encode_time_ms. |
pbos@webrtc.org | 3e6e271 | 2015-02-26 12:19:31 +0000 | [diff] [blame] | 146 | stats_.avg_encode_time_ms = metrics.avg_encode_time_ms; |
| 147 | stats_.encode_usage_percent = metrics.encode_usage_percent; |
| 148 | } |
| 149 | |
Peter Boström | 7083e11 | 2015-09-22 16:28:51 +0200 | [diff] [blame] | 150 | void SendStatisticsProxy::OnSuspendChange(bool is_suspended) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 151 | rtc::CritScope lock(&crit_); |
henrik.lundin@webrtc.org | b10363f | 2014-03-13 13:31:21 +0000 | [diff] [blame] | 152 | stats_.suspended = is_suspended; |
| 153 | } |
| 154 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 155 | VideoSendStream::Stats SendStatisticsProxy::GetStats() { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 156 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 157 | PurgeOldStats(); |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 158 | stats_.input_frame_rate = |
Tim Psiaki | ad13d2f | 2015-11-10 16:34:50 -0800 | [diff] [blame^] | 159 | round(input_frame_rate_tracker_.ComputeRate()); |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 160 | return stats_; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 161 | } |
| 162 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 163 | void SendStatisticsProxy::PurgeOldStats() { |
Peter Boström | 20f3f94 | 2015-05-15 11:33:39 +0200 | [diff] [blame] | 164 | int64_t old_stats_ms = clock_->TimeInMilliseconds() - kStatsTimeoutMs; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 165 | for (std::map<uint32_t, VideoSendStream::StreamStats>::iterator it = |
| 166 | stats_.substreams.begin(); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 167 | it != stats_.substreams.end(); ++it) { |
| 168 | uint32_t ssrc = it->first; |
Peter Boström | 20f3f94 | 2015-05-15 11:33:39 +0200 | [diff] [blame] | 169 | if (update_times_[ssrc].resolution_update_ms <= old_stats_ms) { |
| 170 | it->second.width = 0; |
| 171 | it->second.height = 0; |
| 172 | } |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 176 | VideoSendStream::StreamStats* SendStatisticsProxy::GetStatsEntry( |
| 177 | uint32_t ssrc) { |
| 178 | std::map<uint32_t, VideoSendStream::StreamStats>::iterator it = |
| 179 | stats_.substreams.find(ssrc); |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 180 | if (it != stats_.substreams.end()) |
| 181 | return &it->second; |
| 182 | |
| 183 | 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] | 184 | config_.rtp.ssrcs.end() && |
| 185 | std::find(config_.rtp.rtx.ssrcs.begin(), |
| 186 | config_.rtp.rtx.ssrcs.end(), |
| 187 | ssrc) == config_.rtp.rtx.ssrcs.end()) { |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 188 | return nullptr; |
stefan@webrtc.org | 58e2d26 | 2014-08-14 15:10:49 +0000 | [diff] [blame] | 189 | } |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 190 | |
| 191 | return &stats_.substreams[ssrc]; // Insert new entry and return ptr. |
| 192 | } |
| 193 | |
Peter Boström | 20f3f94 | 2015-05-15 11:33:39 +0200 | [diff] [blame] | 194 | void SendStatisticsProxy::OnInactiveSsrc(uint32_t ssrc) { |
| 195 | rtc::CritScope lock(&crit_); |
| 196 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
| 197 | if (stats == nullptr) |
| 198 | return; |
| 199 | |
| 200 | stats->total_bitrate_bps = 0; |
| 201 | stats->retransmit_bitrate_bps = 0; |
| 202 | stats->height = 0; |
| 203 | stats->width = 0; |
| 204 | } |
| 205 | |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 206 | void SendStatisticsProxy::OnSetRates(uint32_t bitrate_bps, int framerate) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 207 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 208 | stats_.target_media_bitrate_bps = bitrate_bps; |
| 209 | } |
| 210 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 211 | void SendStatisticsProxy::OnSendEncodedImage( |
| 212 | const EncodedImage& encoded_image, |
| 213 | const RTPVideoHeader* rtp_video_header) { |
| 214 | size_t simulcast_idx = |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 215 | rtp_video_header != nullptr ? rtp_video_header->simulcastIdx : 0; |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 216 | if (simulcast_idx >= config_.rtp.ssrcs.size()) { |
| 217 | LOG(LS_ERROR) << "Encoded image outside simulcast range (" << simulcast_idx |
| 218 | << " >= " << config_.rtp.ssrcs.size() << ")."; |
| 219 | return; |
| 220 | } |
| 221 | uint32_t ssrc = config_.rtp.ssrcs[simulcast_idx]; |
| 222 | |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 223 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 224 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 225 | if (stats == nullptr) |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 226 | return; |
| 227 | |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 228 | stats->width = encoded_image._encodedWidth; |
| 229 | stats->height = encoded_image._encodedHeight; |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 230 | update_times_[ssrc].resolution_update_ms = clock_->TimeInMilliseconds(); |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 231 | |
Peter Boström | 49e196a | 2015-10-23 15:58:18 +0200 | [diff] [blame] | 232 | key_frame_counter_.Add(encoded_image._frameType == kVideoFrameKey); |
asapersson | dec5ebf | 2015-10-05 02:36:17 -0700 | [diff] [blame] | 233 | |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 234 | if (encoded_image.adapt_reason_.quality_resolution_downscales != -1) { |
| 235 | bool downscaled = |
| 236 | encoded_image.adapt_reason_.quality_resolution_downscales > 0; |
| 237 | quality_limited_frame_counter_.Add(downscaled); |
| 238 | if (downscaled) { |
| 239 | quality_downscales_counter_.Add( |
| 240 | encoded_image.adapt_reason_.quality_resolution_downscales); |
| 241 | } |
| 242 | } |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 243 | if (encoded_image.adapt_reason_.bw_resolutions_disabled != -1) { |
| 244 | bool bw_limited = encoded_image.adapt_reason_.bw_resolutions_disabled > 0; |
| 245 | bw_limited_frame_counter_.Add(bw_limited); |
| 246 | if (bw_limited) { |
| 247 | bw_resolutions_disabled_counter_.Add( |
| 248 | encoded_image.adapt_reason_.bw_resolutions_disabled); |
| 249 | } |
| 250 | } |
asapersson | 4306fc7 | 2015-10-19 00:35:21 -0700 | [diff] [blame] | 251 | |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 252 | // TODO(asapersson): This is incorrect if simulcast layers are encoded on |
| 253 | // different threads and there is no guarantee that one frame of all layers |
| 254 | // are encoded before the next start. |
| 255 | if (last_sent_frame_timestamp_ > 0 && |
| 256 | encoded_image._timeStamp != last_sent_frame_timestamp_) { |
Tim Psiaki | 6304626 | 2015-09-14 10:38:08 -0700 | [diff] [blame] | 257 | sent_frame_rate_tracker_.AddSamples(1); |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 258 | sent_width_counter_.Add(max_sent_width_per_timestamp_); |
| 259 | sent_height_counter_.Add(max_sent_height_per_timestamp_); |
| 260 | max_sent_width_per_timestamp_ = 0; |
| 261 | max_sent_height_per_timestamp_ = 0; |
Åsa Persson | 24b4eda | 2015-06-16 10:17:01 +0200 | [diff] [blame] | 262 | } |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 263 | last_sent_frame_timestamp_ = encoded_image._timeStamp; |
| 264 | max_sent_width_per_timestamp_ = |
| 265 | std::max(max_sent_width_per_timestamp_, |
| 266 | static_cast<int>(encoded_image._encodedWidth)); |
| 267 | max_sent_height_per_timestamp_ = |
| 268 | std::max(max_sent_height_per_timestamp_, |
| 269 | static_cast<int>(encoded_image._encodedHeight)); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 270 | } |
| 271 | |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 272 | void SendStatisticsProxy::OnIncomingFrame(int width, int height) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 273 | rtc::CritScope lock(&crit_); |
Tim Psiaki | 6304626 | 2015-09-14 10:38:08 -0700 | [diff] [blame] | 274 | input_frame_rate_tracker_.AddSamples(1); |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 275 | input_width_counter_.Add(width); |
| 276 | input_height_counter_.Add(height); |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 277 | } |
| 278 | |
asapersson | 6718e97 | 2015-07-24 00:20:58 -0700 | [diff] [blame] | 279 | void SendStatisticsProxy::OnEncodedFrame(int encode_time_ms) { |
| 280 | rtc::CritScope lock(&crit_); |
| 281 | encode_time_counter_.Add(encode_time_ms); |
| 282 | } |
| 283 | |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 284 | void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( |
| 285 | uint32_t ssrc, |
| 286 | const RtcpPacketTypeCounter& packet_counter) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 287 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 288 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 289 | if (stats == nullptr) |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 290 | return; |
| 291 | |
| 292 | stats->rtcp_packet_type_counts = packet_counter; |
| 293 | } |
| 294 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 295 | void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, |
| 296 | uint32_t ssrc) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 297 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 298 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 299 | if (stats == nullptr) |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 300 | return; |
| 301 | |
| 302 | stats->rtcp_stats = statistics; |
| 303 | } |
| 304 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 305 | void SendStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) { |
| 306 | } |
| 307 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 308 | void SendStatisticsProxy::DataCountersUpdated( |
| 309 | const StreamDataCounters& counters, |
| 310 | uint32_t ssrc) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 311 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 312 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 313 | RTC_DCHECK(stats != nullptr) |
| 314 | << "DataCountersUpdated reported for unknown ssrc: " << ssrc; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 315 | |
| 316 | stats->rtp_stats = counters; |
| 317 | } |
| 318 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 319 | void SendStatisticsProxy::Notify(const BitrateStatistics& total_stats, |
| 320 | const BitrateStatistics& retransmit_stats, |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 321 | uint32_t ssrc) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 322 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 323 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 324 | if (stats == nullptr) |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 325 | return; |
| 326 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 327 | stats->total_bitrate_bps = total_stats.bitrate_bps; |
| 328 | stats->retransmit_bitrate_bps = retransmit_stats.bitrate_bps; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 329 | } |
| 330 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 331 | void SendStatisticsProxy::FrameCountUpdated(const FrameCounts& frame_counts, |
| 332 | uint32_t ssrc) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 333 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 334 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 335 | if (stats == nullptr) |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 336 | return; |
| 337 | |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 338 | stats->frame_counts = frame_counts; |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 339 | } |
| 340 | |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 341 | void SendStatisticsProxy::SendSideDelayUpdated(int avg_delay_ms, |
| 342 | int max_delay_ms, |
| 343 | uint32_t ssrc) { |
Peter Boström | f2f8283 | 2015-05-01 13:00:41 +0200 | [diff] [blame] | 344 | rtc::CritScope lock(&crit_); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 345 | VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
pbos@webrtc.org | 2b4ce3a | 2015-03-23 13:12:24 +0000 | [diff] [blame] | 346 | if (stats == nullptr) |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 347 | return; |
| 348 | stats->avg_delay_ms = avg_delay_ms; |
| 349 | stats->max_delay_ms = max_delay_ms; |
asapersson | f040b23 | 2015-11-04 00:59:03 -0800 | [diff] [blame] | 350 | |
| 351 | delay_counter_.Add(avg_delay_ms); |
| 352 | max_delay_counter_.Add(max_delay_ms); |
stefan@webrtc.org | 168f23f | 2014-07-11 13:44:02 +0000 | [diff] [blame] | 353 | } |
| 354 | |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 355 | void SendStatisticsProxy::SampleCounter::Add(int sample) { |
| 356 | sum += sample; |
| 357 | ++num_samples; |
| 358 | } |
| 359 | |
| 360 | int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { |
| 361 | if (num_samples < min_required_samples || num_samples == 0) |
| 362 | return -1; |
asapersson | da535c4 | 2015-10-19 23:32:41 -0700 | [diff] [blame] | 363 | return (sum + (num_samples / 2)) / num_samples; |
asapersson | d89920b | 2015-07-22 06:52:00 -0700 | [diff] [blame] | 364 | } |
| 365 | |
asapersson | dec5ebf | 2015-10-05 02:36:17 -0700 | [diff] [blame] | 366 | void SendStatisticsProxy::BoolSampleCounter::Add(bool sample) { |
| 367 | if (sample) |
| 368 | ++sum; |
| 369 | ++num_samples; |
| 370 | } |
| 371 | |
| 372 | int SendStatisticsProxy::BoolSampleCounter::Percent( |
| 373 | int min_required_samples) const { |
| 374 | return Fraction(min_required_samples, 100.0f); |
| 375 | } |
| 376 | |
| 377 | int SendStatisticsProxy::BoolSampleCounter::Permille( |
| 378 | int min_required_samples) const { |
| 379 | return Fraction(min_required_samples, 1000.0f); |
| 380 | } |
| 381 | |
| 382 | int SendStatisticsProxy::BoolSampleCounter::Fraction( |
| 383 | int min_required_samples, float multiplier) const { |
| 384 | if (num_samples < min_required_samples || num_samples == 0) |
| 385 | return -1; |
| 386 | return static_cast<int>((sum * multiplier / num_samples) + 0.5f); |
| 387 | } |
| 388 | |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 389 | } // namespace webrtc |