| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 SendStatisticsProxy::SendStatisticsProxy( | 71 SendStatisticsProxy::SendStatisticsProxy( |
| 72 Clock* clock, | 72 Clock* clock, |
| 73 const VideoSendStream::Config& config, | 73 const VideoSendStream::Config& config, |
| 74 VideoEncoderConfig::ContentType content_type) | 74 VideoEncoderConfig::ContentType content_type) |
| 75 : clock_(clock), | 75 : clock_(clock), |
| 76 config_(config), | 76 config_(config), |
| 77 content_type_(content_type), | 77 content_type_(content_type), |
| 78 last_sent_frame_timestamp_(0), | 78 last_sent_frame_timestamp_(0), |
| 79 encode_time_(kEncodeTimeWeigthFactor), | 79 encode_time_(kEncodeTimeWeigthFactor), |
| 80 uma_container_(new UmaSamplesContainer(GetUmaPrefix(content_type_))) { | 80 uma_container_( |
| 81 new UmaSamplesContainer(GetUmaPrefix(content_type_), stats_, clock)) { |
| 81 UpdateCodecTypeHistogram(config_.encoder_settings.payload_name); | 82 UpdateCodecTypeHistogram(config_.encoder_settings.payload_name); |
| 82 } | 83 } |
| 83 | 84 |
| 84 SendStatisticsProxy::~SendStatisticsProxy() {} | 85 SendStatisticsProxy::~SendStatisticsProxy() { |
| 86 rtc::CritScope lock(&crit_); |
| 87 uma_container_->UpdateHistograms(config_, stats_); |
| 88 } |
| 85 | 89 |
| 86 SendStatisticsProxy::UmaSamplesContainer::UmaSamplesContainer( | 90 SendStatisticsProxy::UmaSamplesContainer::UmaSamplesContainer( |
| 87 const char* prefix) | 91 const char* prefix, |
| 92 const VideoSendStream::Stats& stats, |
| 93 Clock* const clock) |
| 88 : uma_prefix_(prefix), | 94 : uma_prefix_(prefix), |
| 95 clock_(clock), |
| 89 max_sent_width_per_timestamp_(0), | 96 max_sent_width_per_timestamp_(0), |
| 90 max_sent_height_per_timestamp_(0), | 97 max_sent_height_per_timestamp_(0), |
| 91 input_frame_rate_tracker_(100u, 10u), | 98 input_frame_rate_tracker_(100u, 10u), |
| 92 sent_frame_rate_tracker_(100u, 10u), | 99 sent_frame_rate_tracker_(100u, 10u), |
| 93 first_rtcp_stats_time_ms_(-1) {} | 100 first_rtcp_stats_time_ms_(-1), |
| 101 start_stats_(stats) {} |
| 94 | 102 |
| 95 SendStatisticsProxy::UmaSamplesContainer::~UmaSamplesContainer() { | 103 SendStatisticsProxy::UmaSamplesContainer::~UmaSamplesContainer() {} |
| 96 UpdateHistograms(); | |
| 97 } | |
| 98 | 104 |
| 99 void SendStatisticsProxy::UmaSamplesContainer::UpdateHistograms() { | 105 void SendStatisticsProxy::UmaSamplesContainer::UpdateHistograms( |
| 106 const VideoSendStream::Config& config, |
| 107 const VideoSendStream::Stats& current_stats) { |
| 100 RTC_DCHECK(uma_prefix_ == kRealtimePrefix || uma_prefix_ == kScreenPrefix); | 108 RTC_DCHECK(uma_prefix_ == kRealtimePrefix || uma_prefix_ == kScreenPrefix); |
| 101 const int kIndex = uma_prefix_ == kScreenPrefix ? 1 : 0; | 109 const int kIndex = uma_prefix_ == kScreenPrefix ? 1 : 0; |
| 102 const int kMinRequiredSamples = 200; | 110 const int kMinRequiredSamples = 200; |
| 103 int in_width = input_width_counter_.Avg(kMinRequiredSamples); | 111 int in_width = input_width_counter_.Avg(kMinRequiredSamples); |
| 104 int in_height = input_height_counter_.Avg(kMinRequiredSamples); | 112 int in_height = input_height_counter_.Avg(kMinRequiredSamples); |
| 105 int in_fps = round(input_frame_rate_tracker_.ComputeTotalRate()); | 113 int in_fps = round(input_frame_rate_tracker_.ComputeTotalRate()); |
| 106 if (in_width != -1) { | 114 if (in_width != -1) { |
| 107 RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "InputWidthInPixels", | 115 RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "InputWidthInPixels", |
| 108 in_width); | 116 in_width); |
| 109 RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "InputHeightInPixels", | 117 RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "InputHeightInPixels", |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 int delay_ms = delay_counter_.Avg(kMinRequiredSamples); | 168 int delay_ms = delay_counter_.Avg(kMinRequiredSamples); |
| 161 if (delay_ms != -1) | 169 if (delay_ms != -1) |
| 162 RTC_HISTOGRAMS_COUNTS_100000(kIndex, uma_prefix_ + "SendSideDelayInMs", | 170 RTC_HISTOGRAMS_COUNTS_100000(kIndex, uma_prefix_ + "SendSideDelayInMs", |
| 163 delay_ms); | 171 delay_ms); |
| 164 | 172 |
| 165 int max_delay_ms = max_delay_counter_.Avg(kMinRequiredSamples); | 173 int max_delay_ms = max_delay_counter_.Avg(kMinRequiredSamples); |
| 166 if (max_delay_ms != -1) { | 174 if (max_delay_ms != -1) { |
| 167 RTC_HISTOGRAMS_COUNTS_100000(kIndex, uma_prefix_ + "SendSideDelayMaxInMs", | 175 RTC_HISTOGRAMS_COUNTS_100000(kIndex, uma_prefix_ + "SendSideDelayMaxInMs", |
| 168 max_delay_ms); | 176 max_delay_ms); |
| 169 } | 177 } |
| 170 int fraction_lost = report_block_stats_.FractionLostInPercent(); | 178 |
| 171 if (first_rtcp_stats_time_ms_ != -1) { | 179 if (first_rtcp_stats_time_ms_ != -1) { |
| 172 int64_t elapsed_time_ms = Clock::GetRealTimeClock()->TimeInMilliseconds() - | 180 int64_t elapsed_sec = |
| 173 first_rtcp_stats_time_ms_; | 181 (clock_->TimeInMilliseconds() - first_rtcp_stats_time_ms_) / 1000; |
| 174 if (elapsed_time_ms / 1000 >= metrics::kMinRunTimeInSeconds && | 182 if (elapsed_sec >= metrics::kMinRunTimeInSeconds) { |
| 175 fraction_lost != -1) { | 183 int fraction_lost = report_block_stats_.FractionLostInPercent(); |
| 176 RTC_HISTOGRAMS_PERCENTAGE( | 184 if (fraction_lost != -1) { |
| 177 kIndex, uma_prefix_ + "SentPacketsLostInPercent", fraction_lost); | 185 RTC_HISTOGRAMS_PERCENTAGE( |
| 186 kIndex, uma_prefix_ + "SentPacketsLostInPercent", fraction_lost); |
| 187 } |
| 188 |
| 189 // The RTCP packet type counters, delivered via the |
| 190 // RtcpPacketTypeCounterObserver interface, are aggregates over the entire |
| 191 // life of the send stream and are not reset when switching content type. |
| 192 // For the purpose of these statistics though, we want new counts when |
| 193 // switching since we switch histogram name. On every reset of the |
| 194 // UmaSamplesContainer, we save the initial state of the counters, so that |
| 195 // we can calculate the delta here and aggregate over all ssrcs. |
| 196 RtcpPacketTypeCounter counters; |
| 197 for (uint32_t ssrc : config.rtp.ssrcs) { |
| 198 auto kv = current_stats.substreams.find(ssrc); |
| 199 if (kv == current_stats.substreams.end()) |
| 200 continue; |
| 201 |
| 202 RtcpPacketTypeCounter stream_counters = |
| 203 kv->second.rtcp_packet_type_counts; |
| 204 kv = start_stats_.substreams.find(ssrc); |
| 205 if (kv != start_stats_.substreams.end()) |
| 206 stream_counters.Subtract(kv->second.rtcp_packet_type_counts); |
| 207 |
| 208 counters.Add(stream_counters); |
| 209 } |
| 210 RTC_HISTOGRAMS_COUNTS_10000(kIndex, |
| 211 uma_prefix_ + "NackPacketsReceivedPerMinute", |
| 212 counters.nack_packets * 60 / elapsed_sec); |
| 213 RTC_HISTOGRAMS_COUNTS_10000(kIndex, |
| 214 uma_prefix_ + "FirPacketsReceivedPerMinute", |
| 215 counters.fir_packets * 60 / elapsed_sec); |
| 216 RTC_HISTOGRAMS_COUNTS_10000(kIndex, |
| 217 uma_prefix_ + "PliPacketsReceivedPerMinute", |
| 218 counters.pli_packets * 60 / elapsed_sec); |
| 219 if (counters.nack_requests > 0) { |
| 220 RTC_HISTOGRAMS_PERCENTAGE( |
| 221 kIndex, uma_prefix_ + "UniqueNackRequestsReceivedInPercent", |
| 222 counters.UniqueNackRequestsInPercent()); |
| 223 } |
| 178 } | 224 } |
| 179 } | 225 } |
| 180 } | 226 } |
| 181 | 227 |
| 182 void SendStatisticsProxy::SetContentType( | 228 void SendStatisticsProxy::SetContentType( |
| 183 VideoEncoderConfig::ContentType content_type) { | 229 VideoEncoderConfig::ContentType content_type) { |
| 184 rtc::CritScope lock(&crit_); | 230 rtc::CritScope lock(&crit_); |
| 185 if (content_type_ != content_type) { | 231 if (content_type_ != content_type) { |
| 186 uma_container_.reset(new UmaSamplesContainer(GetUmaPrefix(content_type))); | 232 uma_container_->UpdateHistograms(config_, stats_); |
| 233 uma_container_.reset( |
| 234 new UmaSamplesContainer(GetUmaPrefix(content_type), stats_, clock_)); |
| 187 content_type_ = content_type; | 235 content_type_ = content_type; |
| 188 } | 236 } |
| 189 } | 237 } |
| 190 | 238 |
| 191 void SendStatisticsProxy::OnEncoderImplementationName( | 239 void SendStatisticsProxy::OnEncoderImplementationName( |
| 192 const char* implementation_name) { | 240 const char* implementation_name) { |
| 193 rtc::CritScope lock(&crit_); | 241 rtc::CritScope lock(&crit_); |
| 194 stats_.encoder_implementation_name = implementation_name; | 242 stats_.encoder_implementation_name = implementation_name; |
| 195 } | 243 } |
| 196 | 244 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 396 |
| 349 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( | 397 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( |
| 350 uint32_t ssrc, | 398 uint32_t ssrc, |
| 351 const RtcpPacketTypeCounter& packet_counter) { | 399 const RtcpPacketTypeCounter& packet_counter) { |
| 352 rtc::CritScope lock(&crit_); | 400 rtc::CritScope lock(&crit_); |
| 353 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 401 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
| 354 if (stats == nullptr) | 402 if (stats == nullptr) |
| 355 return; | 403 return; |
| 356 | 404 |
| 357 stats->rtcp_packet_type_counts = packet_counter; | 405 stats->rtcp_packet_type_counts = packet_counter; |
| 406 if (uma_container_->first_rtcp_stats_time_ms_ == -1) |
| 407 uma_container_->first_rtcp_stats_time_ms_ = clock_->TimeInMilliseconds(); |
| 358 } | 408 } |
| 359 | 409 |
| 360 void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, | 410 void SendStatisticsProxy::StatisticsUpdated(const RtcpStatistics& statistics, |
| 361 uint32_t ssrc) { | 411 uint32_t ssrc) { |
| 362 rtc::CritScope lock(&crit_); | 412 rtc::CritScope lock(&crit_); |
| 363 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 413 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
| 364 if (stats == nullptr) | 414 if (stats == nullptr) |
| 365 return; | 415 return; |
| 366 | 416 |
| 367 stats->rtcp_stats = statistics; | 417 stats->rtcp_stats = statistics; |
| 368 uma_container_->report_block_stats_.Store(statistics, 0, ssrc); | 418 uma_container_->report_block_stats_.Store(statistics, 0, ssrc); |
| 369 if (uma_container_->first_rtcp_stats_time_ms_ == -1) | |
| 370 uma_container_->first_rtcp_stats_time_ms_ = clock_->TimeInMilliseconds(); | |
| 371 } | 419 } |
| 372 | 420 |
| 373 void SendStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {} | 421 void SendStatisticsProxy::CNameChanged(const char* cname, uint32_t ssrc) {} |
| 374 | 422 |
| 375 void SendStatisticsProxy::DataCountersUpdated( | 423 void SendStatisticsProxy::DataCountersUpdated( |
| 376 const StreamDataCounters& counters, | 424 const StreamDataCounters& counters, |
| 377 uint32_t ssrc) { | 425 uint32_t ssrc) { |
| 378 rtc::CritScope lock(&crit_); | 426 rtc::CritScope lock(&crit_); |
| 379 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); | 427 VideoSendStream::StreamStats* stats = GetStatsEntry(ssrc); |
| 380 RTC_DCHECK(stats != nullptr) | 428 RTC_DCHECK(stats != nullptr) |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 return Fraction(min_required_samples, 1000.0f); | 494 return Fraction(min_required_samples, 1000.0f); |
| 447 } | 495 } |
| 448 | 496 |
| 449 int SendStatisticsProxy::BoolSampleCounter::Fraction( | 497 int SendStatisticsProxy::BoolSampleCounter::Fraction( |
| 450 int min_required_samples, float multiplier) const { | 498 int min_required_samples, float multiplier) const { |
| 451 if (num_samples < min_required_samples || num_samples == 0) | 499 if (num_samples < min_required_samples || num_samples == 0) |
| 452 return -1; | 500 return -1; |
| 453 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); | 501 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); |
| 454 } | 502 } |
| 455 } // namespace webrtc | 503 } // namespace webrtc |
| OLD | NEW |