| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 Clock* clock, | 82 Clock* clock, |
| 83 const VideoSendStream::Config& config, | 83 const VideoSendStream::Config& config, |
| 84 VideoEncoderConfig::ContentType content_type) | 84 VideoEncoderConfig::ContentType content_type) |
| 85 : clock_(clock), | 85 : clock_(clock), |
| 86 payload_name_(config.encoder_settings.payload_name), | 86 payload_name_(config.encoder_settings.payload_name), |
| 87 rtp_config_(config.rtp), | 87 rtp_config_(config.rtp), |
| 88 content_type_(content_type), | 88 content_type_(content_type), |
| 89 start_ms_(clock->TimeInMilliseconds()), | 89 start_ms_(clock->TimeInMilliseconds()), |
| 90 last_sent_frame_timestamp_(0), | 90 last_sent_frame_timestamp_(0), |
| 91 encode_time_(kEncodeTimeWeigthFactor), | 91 encode_time_(kEncodeTimeWeigthFactor), |
| 92 quality_downscales_(-1), |
| 93 cpu_downscales_(-1), |
| 92 uma_container_( | 94 uma_container_( |
| 93 new UmaSamplesContainer(GetUmaPrefix(content_type_), stats_, clock)) { | 95 new UmaSamplesContainer(GetUmaPrefix(content_type_), stats_, clock)) { |
| 94 } | 96 } |
| 95 | 97 |
| 96 SendStatisticsProxy::~SendStatisticsProxy() { | 98 SendStatisticsProxy::~SendStatisticsProxy() { |
| 97 rtc::CritScope lock(&crit_); | 99 rtc::CritScope lock(&crit_); |
| 98 uma_container_->UpdateHistograms(rtp_config_, stats_); | 100 uma_container_->UpdateHistograms(rtp_config_, stats_); |
| 99 | 101 |
| 100 int64_t elapsed_sec = (clock_->TimeInMilliseconds() - start_ms_) / 1000; | 102 int64_t elapsed_sec = (clock_->TimeInMilliseconds() - start_ms_) / 1000; |
| 101 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Video.SendStreamLifetimeInSeconds", | 103 RTC_HISTOGRAM_COUNTS_100000("WebRTC.Video.SendStreamLifetimeInSeconds", |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } | 288 } |
| 287 int qp_h264 = it.second.h264.Avg(kMinRequiredMetricsSamples); | 289 int qp_h264 = it.second.h264.Avg(kMinRequiredMetricsSamples); |
| 288 if (qp_h264 != -1) { | 290 if (qp_h264 != -1) { |
| 289 int spatial_idx = it.first; | 291 int spatial_idx = it.first; |
| 290 RTC_DCHECK_EQ(-1, spatial_idx); | 292 RTC_DCHECK_EQ(-1, spatial_idx); |
| 291 RTC_HISTOGRAMS_COUNTS_100(kIndex, uma_prefix_ + "Encoded.Qp.H264", | 293 RTC_HISTOGRAMS_COUNTS_100(kIndex, uma_prefix_ + "Encoded.Qp.H264", |
| 292 qp_h264); | 294 qp_h264); |
| 293 } | 295 } |
| 294 } | 296 } |
| 295 | 297 |
| 296 quality_scaling_timer_.Stop(clock_->TimeInMilliseconds()); | 298 if (first_rtp_stats_time_ms_ != -1) { |
| 297 int64_t elapsed_sec = quality_scaling_timer_.total_ms / 1000; | 299 quality_scaling_timer_.Stop(clock_->TimeInMilliseconds()); |
| 298 if (elapsed_sec >= metrics::kMinRunTimeInSeconds) { | 300 int64_t elapsed_sec = quality_scaling_timer_.total_ms / 1000; |
| 299 int quality_changes = current_stats.number_of_quality_adapt_changes - | 301 if (elapsed_sec >= metrics::kMinRunTimeInSeconds) { |
| 300 start_stats_.number_of_quality_adapt_changes; | 302 int quality_changes = current_stats.number_of_quality_adapt_changes - |
| 301 RTC_HISTOGRAMS_COUNTS_100(kIndex, | 303 start_stats_.number_of_quality_adapt_changes; |
| 302 uma_prefix_ + "AdaptChangesPerMinute.Quality", | 304 RTC_HISTOGRAMS_COUNTS_100(kIndex, |
| 303 quality_changes * 60 / elapsed_sec); | 305 uma_prefix_ + "AdaptChangesPerMinute.Quality", |
| 304 } | 306 quality_changes * 60 / elapsed_sec); |
| 305 cpu_scaling_timer_.Stop(clock_->TimeInMilliseconds()); | 307 } |
| 306 elapsed_sec = cpu_scaling_timer_.total_ms / 1000; | 308 cpu_scaling_timer_.Stop(clock_->TimeInMilliseconds()); |
| 307 if (elapsed_sec >= metrics::kMinRunTimeInSeconds) { | 309 elapsed_sec = cpu_scaling_timer_.total_ms / 1000; |
| 308 int cpu_changes = current_stats.number_of_cpu_adapt_changes - | 310 if (elapsed_sec >= metrics::kMinRunTimeInSeconds) { |
| 309 start_stats_.number_of_cpu_adapt_changes; | 311 int cpu_changes = current_stats.number_of_cpu_adapt_changes - |
| 310 RTC_HISTOGRAMS_COUNTS_100(kIndex, uma_prefix_ + "AdaptChangesPerMinute.Cpu", | 312 start_stats_.number_of_cpu_adapt_changes; |
| 311 cpu_changes * 60 / elapsed_sec); | 313 RTC_HISTOGRAMS_COUNTS_100(kIndex, |
| 314 uma_prefix_ + "AdaptChangesPerMinute.Cpu", |
| 315 cpu_changes * 60 / elapsed_sec); |
| 316 } |
| 312 } | 317 } |
| 313 | 318 |
| 314 if (first_rtcp_stats_time_ms_ != -1) { | 319 if (first_rtcp_stats_time_ms_ != -1) { |
| 315 int64_t elapsed_sec = | 320 int64_t elapsed_sec = |
| 316 (clock_->TimeInMilliseconds() - first_rtcp_stats_time_ms_) / 1000; | 321 (clock_->TimeInMilliseconds() - first_rtcp_stats_time_ms_) / 1000; |
| 317 if (elapsed_sec >= metrics::kMinRunTimeInSeconds) { | 322 if (elapsed_sec >= metrics::kMinRunTimeInSeconds) { |
| 318 int fraction_lost = report_block_stats_.FractionLostInPercent(); | 323 int fraction_lost = report_block_stats_.FractionLostInPercent(); |
| 319 if (fraction_lost != -1) { | 324 if (fraction_lost != -1) { |
| 320 RTC_HISTOGRAMS_PERCENTAGE( | 325 RTC_HISTOGRAMS_PERCENTAGE( |
| 321 kIndex, uma_prefix_ + "SentPacketsLostInPercent", fraction_lost); | 326 kIndex, uma_prefix_ + "SentPacketsLostInPercent", fraction_lost); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 stats_.encode_usage_percent = metrics.encode_usage_percent; | 471 stats_.encode_usage_percent = metrics.encode_usage_percent; |
| 467 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.EncodeTimeInMs", | 472 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.EncodeTimeInMs", |
| 468 "encode_time_ms", stats_.avg_encode_time_ms, | 473 "encode_time_ms", stats_.avg_encode_time_ms, |
| 469 "ssrc", rtp_config_.ssrcs[0]); | 474 "ssrc", rtp_config_.ssrcs[0]); |
| 470 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.EncodeUsagePercent", | 475 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.EncodeUsagePercent", |
| 471 "encode_usage_percent", stats_.encode_usage_percent, | 476 "encode_usage_percent", stats_.encode_usage_percent, |
| 472 "ssrc", rtp_config_.ssrcs[0]); | 477 "ssrc", rtp_config_.ssrcs[0]); |
| 473 } | 478 } |
| 474 | 479 |
| 475 void SendStatisticsProxy::OnSuspendChange(bool is_suspended) { | 480 void SendStatisticsProxy::OnSuspendChange(bool is_suspended) { |
| 481 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 476 rtc::CritScope lock(&crit_); | 482 rtc::CritScope lock(&crit_); |
| 477 stats_.suspended = is_suspended; | 483 stats_.suspended = is_suspended; |
| 478 if (is_suspended) { | 484 if (is_suspended) { |
| 479 // Pause framerate (add min pause time since there may be frames/packets | 485 // Pause framerate (add min pause time since there may be frames/packets |
| 480 // that are not yet sent). | 486 // that are not yet sent). |
| 481 const int64_t kMinMs = 500; | 487 const int64_t kMinMs = 500; |
| 482 uma_container_->input_fps_counter_.ProcessAndPauseForDuration(kMinMs); | 488 uma_container_->input_fps_counter_.ProcessAndPauseForDuration(kMinMs); |
| 483 uma_container_->sent_fps_counter_.ProcessAndPauseForDuration(kMinMs); | 489 uma_container_->sent_fps_counter_.ProcessAndPauseForDuration(kMinMs); |
| 484 // Pause bitrate stats. | 490 // Pause bitrate stats. |
| 485 uma_container_->total_byte_counter_.ProcessAndPauseForDuration(kMinMs); | 491 uma_container_->total_byte_counter_.ProcessAndPauseForDuration(kMinMs); |
| 486 uma_container_->media_byte_counter_.ProcessAndPauseForDuration(kMinMs); | 492 uma_container_->media_byte_counter_.ProcessAndPauseForDuration(kMinMs); |
| 487 uma_container_->rtx_byte_counter_.ProcessAndPauseForDuration(kMinMs); | 493 uma_container_->rtx_byte_counter_.ProcessAndPauseForDuration(kMinMs); |
| 488 uma_container_->padding_byte_counter_.ProcessAndPauseForDuration(kMinMs); | 494 uma_container_->padding_byte_counter_.ProcessAndPauseForDuration(kMinMs); |
| 489 uma_container_->retransmit_byte_counter_.ProcessAndPauseForDuration(kMinMs); | 495 uma_container_->retransmit_byte_counter_.ProcessAndPauseForDuration(kMinMs); |
| 490 uma_container_->fec_byte_counter_.ProcessAndPauseForDuration(kMinMs); | 496 uma_container_->fec_byte_counter_.ProcessAndPauseForDuration(kMinMs); |
| 497 // Stop adaptation stats. |
| 498 uma_container_->cpu_scaling_timer_.Stop(now_ms); |
| 499 uma_container_->quality_scaling_timer_.Stop(now_ms); |
| 491 } else { | 500 } else { |
| 501 // Start adaptation stats if scaling is enabled. |
| 502 if (cpu_downscales_ >= 0) |
| 503 uma_container_->cpu_scaling_timer_.Start(now_ms); |
| 504 if (quality_downscales_ >= 0) |
| 505 uma_container_->quality_scaling_timer_.Start(now_ms); |
| 492 // Stop pause explicitly for stats that may be zero/not updated for some | 506 // Stop pause explicitly for stats that may be zero/not updated for some |
| 493 // time. | 507 // time. |
| 494 uma_container_->rtx_byte_counter_.ProcessAndStopPause(); | 508 uma_container_->rtx_byte_counter_.ProcessAndStopPause(); |
| 495 uma_container_->padding_byte_counter_.ProcessAndStopPause(); | 509 uma_container_->padding_byte_counter_.ProcessAndStopPause(); |
| 496 uma_container_->retransmit_byte_counter_.ProcessAndStopPause(); | 510 uma_container_->retransmit_byte_counter_.ProcessAndStopPause(); |
| 497 uma_container_->fec_byte_counter_.ProcessAndStopPause(); | 511 uma_container_->fec_byte_counter_.ProcessAndStopPause(); |
| 498 } | 512 } |
| 499 } | 513 } |
| 500 | 514 |
| 501 VideoSendStream::Stats SendStatisticsProxy::GetStats() { | 515 VideoSendStream::Stats SendStatisticsProxy::GetStats() { |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 uma_container_->input_height_counter_.Add(height); | 711 uma_container_->input_height_counter_.Add(height); |
| 698 uma_container_->cpu_limited_frame_counter_.Add(stats_.cpu_limited_resolution); | 712 uma_container_->cpu_limited_frame_counter_.Add(stats_.cpu_limited_resolution); |
| 699 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.InputFrameRate", | 713 TRACE_EVENT_INSTANT2("webrtc_stats", "WebRTC.Video.InputFrameRate", |
| 700 "frame_rate", round( | 714 "frame_rate", round( |
| 701 uma_container_->input_frame_rate_tracker_.ComputeRate()), | 715 uma_container_->input_frame_rate_tracker_.ComputeRate()), |
| 702 "ssrc", rtp_config_.ssrcs[0]); | 716 "ssrc", rtp_config_.ssrcs[0]); |
| 703 } | 717 } |
| 704 | 718 |
| 705 void SendStatisticsProxy::SetCpuScalingStats(int num_cpu_downscales) { | 719 void SendStatisticsProxy::SetCpuScalingStats(int num_cpu_downscales) { |
| 706 rtc::CritScope lock(&crit_); | 720 rtc::CritScope lock(&crit_); |
| 721 cpu_downscales_ = num_cpu_downscales; |
| 707 stats_.cpu_limited_resolution = num_cpu_downscales > 0; | 722 stats_.cpu_limited_resolution = num_cpu_downscales > 0; |
| 708 | 723 |
| 709 if (num_cpu_downscales >= 0) { | 724 if (num_cpu_downscales >= 0) { |
| 710 // Scaling enabled. | 725 // Scaling enabled. |
| 711 uma_container_->cpu_scaling_timer_.Start(clock_->TimeInMilliseconds()); | 726 if (!stats_.suspended) |
| 712 } else { | 727 uma_container_->cpu_scaling_timer_.Start(clock_->TimeInMilliseconds()); |
| 713 uma_container_->cpu_scaling_timer_.Stop(clock_->TimeInMilliseconds()); | 728 return; |
| 714 } | 729 } |
| 730 uma_container_->cpu_scaling_timer_.Stop(clock_->TimeInMilliseconds()); |
| 715 } | 731 } |
| 716 | 732 |
| 717 void SendStatisticsProxy::SetQualityScalingStats(int num_quality_downscales) { | 733 void SendStatisticsProxy::SetQualityScalingStats(int num_quality_downscales) { |
| 718 rtc::CritScope lock(&crit_); | 734 rtc::CritScope lock(&crit_); |
| 719 quality_downscales_ = num_quality_downscales; | 735 quality_downscales_ = num_quality_downscales; |
| 720 stats_.bw_limited_resolution = quality_downscales_ > 0; | 736 stats_.bw_limited_resolution = quality_downscales_ > 0; |
| 721 | 737 |
| 722 if (num_quality_downscales >= 0) { | 738 if (num_quality_downscales >= 0) { |
| 723 // Scaling enabled. | 739 // Scaling enabled. |
| 724 uma_container_->quality_scaling_timer_.Start(clock_->TimeInMilliseconds()); | 740 if (!stats_.suspended) { |
| 725 } else { | 741 uma_container_->quality_scaling_timer_.Start( |
| 726 uma_container_->quality_scaling_timer_.Stop(clock_->TimeInMilliseconds()); | 742 clock_->TimeInMilliseconds()); |
| 743 } |
| 744 return; |
| 727 } | 745 } |
| 746 uma_container_->quality_scaling_timer_.Stop(clock_->TimeInMilliseconds()); |
| 728 } | 747 } |
| 729 | 748 |
| 730 void SendStatisticsProxy::OnCpuRestrictedResolutionChanged( | 749 void SendStatisticsProxy::OnCpuRestrictedResolutionChanged( |
| 731 bool cpu_restricted_resolution) { | 750 bool cpu_restricted_resolution) { |
| 732 rtc::CritScope lock(&crit_); | 751 rtc::CritScope lock(&crit_); |
| 733 stats_.cpu_limited_resolution = cpu_restricted_resolution; | 752 stats_.cpu_limited_resolution = cpu_restricted_resolution; |
| 734 ++stats_.number_of_cpu_adapt_changes; | 753 ++stats_.number_of_cpu_adapt_changes; |
| 735 TRACE_EVENT_INSTANT0("webrtc_stats", "WebRTC.Video.CpuAdaptationChanges"); | 754 TRACE_EVENT_INSTANT0("webrtc_stats", "WebRTC.Video.CpuAdaptationChanges"); |
| 736 } | 755 } |
| 737 | 756 |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 906 } | 925 } |
| 907 | 926 |
| 908 int SendStatisticsProxy::BoolSampleCounter::Fraction( | 927 int SendStatisticsProxy::BoolSampleCounter::Fraction( |
| 909 int64_t min_required_samples, | 928 int64_t min_required_samples, |
| 910 float multiplier) const { | 929 float multiplier) const { |
| 911 if (num_samples < min_required_samples || num_samples == 0) | 930 if (num_samples < min_required_samples || num_samples == 0) |
| 912 return -1; | 931 return -1; |
| 913 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); | 932 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); |
| 914 } | 933 } |
| 915 } // namespace webrtc | 934 } // namespace webrtc |
| OLD | NEW |