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