Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: webrtc/video/send_statistics_proxy.cc

Issue 2536743002: Use RateCounter for input/sent fps stats. Reports average of periodically computed stats over a cal… (Closed)
Patch Set: moved from https://codereview.webrtc.org/2283693002/ Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/send_statistics_proxy.h ('k') | webrtc/video/send_statistics_proxy_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 SendStatisticsProxy::UmaSamplesContainer::UmaSamplesContainer( 100 SendStatisticsProxy::UmaSamplesContainer::UmaSamplesContainer(
101 const char* prefix, 101 const char* prefix,
102 const VideoSendStream::Stats& stats, 102 const VideoSendStream::Stats& stats,
103 Clock* const clock) 103 Clock* const clock)
104 : uma_prefix_(prefix), 104 : uma_prefix_(prefix),
105 clock_(clock), 105 clock_(clock),
106 max_sent_width_per_timestamp_(0), 106 max_sent_width_per_timestamp_(0),
107 max_sent_height_per_timestamp_(0), 107 max_sent_height_per_timestamp_(0),
108 input_frame_rate_tracker_(100, 10u), 108 input_frame_rate_tracker_(100, 10u),
109 sent_frame_rate_tracker_(100, 10u), 109 input_fps_counter_(clock, nullptr, true),
110 sent_fps_counter_(clock, nullptr, true),
110 first_rtcp_stats_time_ms_(-1), 111 first_rtcp_stats_time_ms_(-1),
111 first_rtp_stats_time_ms_(-1), 112 first_rtp_stats_time_ms_(-1),
112 start_stats_(stats) {} 113 start_stats_(stats) {}
113 114
114 SendStatisticsProxy::UmaSamplesContainer::~UmaSamplesContainer() {} 115 SendStatisticsProxy::UmaSamplesContainer::~UmaSamplesContainer() {}
115 116
116 void AccumulateRtxStats(const VideoSendStream::Stats& stats, 117 void AccumulateRtxStats(const VideoSendStream::Stats& stats,
117 const std::vector<uint32_t>& rtx_ssrcs, 118 const std::vector<uint32_t>& rtx_ssrcs,
118 StreamDataCounters* total_rtp_stats, 119 StreamDataCounters* total_rtp_stats,
119 StreamDataCounters* rtx_stats) { 120 StreamDataCounters* rtx_stats) {
120 for (auto it : stats.substreams) { 121 for (auto it : stats.substreams) {
121 if (std::find(rtx_ssrcs.begin(), rtx_ssrcs.end(), it.first) != 122 if (std::find(rtx_ssrcs.begin(), rtx_ssrcs.end(), it.first) !=
122 rtx_ssrcs.end()) { 123 rtx_ssrcs.end()) {
123 rtx_stats->Add(it.second.rtp_stats); 124 rtx_stats->Add(it.second.rtp_stats);
124 } else { 125 } else {
125 total_rtp_stats->Add(it.second.rtp_stats); 126 total_rtp_stats->Add(it.second.rtp_stats);
126 } 127 }
127 } 128 }
128 } 129 }
129 130
130 void SendStatisticsProxy::UmaSamplesContainer::UpdateHistograms( 131 void SendStatisticsProxy::UmaSamplesContainer::UpdateHistograms(
131 const VideoSendStream::Config::Rtp& rtp_config, 132 const VideoSendStream::Config::Rtp& rtp_config,
132 const VideoSendStream::Stats& current_stats) { 133 const VideoSendStream::Stats& current_stats) {
133 RTC_DCHECK(uma_prefix_ == kRealtimePrefix || uma_prefix_ == kScreenPrefix); 134 RTC_DCHECK(uma_prefix_ == kRealtimePrefix || uma_prefix_ == kScreenPrefix);
134 const int kIndex = uma_prefix_ == kScreenPrefix ? 1 : 0; 135 const int kIndex = uma_prefix_ == kScreenPrefix ? 1 : 0;
136 const int kMinRequiredPeriodicSamples = 6;
135 int in_width = input_width_counter_.Avg(kMinRequiredMetricsSamples); 137 int in_width = input_width_counter_.Avg(kMinRequiredMetricsSamples);
136 int in_height = input_height_counter_.Avg(kMinRequiredMetricsSamples); 138 int in_height = input_height_counter_.Avg(kMinRequiredMetricsSamples);
137 int in_fps = round(input_frame_rate_tracker_.ComputeTotalRate());
138 if (in_width != -1) { 139 if (in_width != -1) {
139 RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "InputWidthInPixels", 140 RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "InputWidthInPixels",
140 in_width); 141 in_width);
141 RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "InputHeightInPixels", 142 RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "InputHeightInPixels",
142 in_height); 143 in_height);
144 }
145 AggregatedStats in_fps = input_fps_counter_.GetStats();
146 if (in_fps.num_samples >= kMinRequiredPeriodicSamples) {
143 RTC_HISTOGRAMS_COUNTS_100(kIndex, uma_prefix_ + "InputFramesPerSecond", 147 RTC_HISTOGRAMS_COUNTS_100(kIndex, uma_prefix_ + "InputFramesPerSecond",
144 in_fps); 148 in_fps.average);
149 LOG(LS_INFO) << uma_prefix_ + "InputFramesPerSecond, " << in_fps.ToString();
145 } 150 }
151
146 int sent_width = sent_width_counter_.Avg(kMinRequiredMetricsSamples); 152 int sent_width = sent_width_counter_.Avg(kMinRequiredMetricsSamples);
147 int sent_height = sent_height_counter_.Avg(kMinRequiredMetricsSamples); 153 int sent_height = sent_height_counter_.Avg(kMinRequiredMetricsSamples);
148 int sent_fps = round(sent_frame_rate_tracker_.ComputeTotalRate());
149 if (sent_width != -1) { 154 if (sent_width != -1) {
150 RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "SentWidthInPixels", 155 RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "SentWidthInPixels",
151 sent_width); 156 sent_width);
152 RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "SentHeightInPixels", 157 RTC_HISTOGRAMS_COUNTS_10000(kIndex, uma_prefix_ + "SentHeightInPixels",
153 sent_height); 158 sent_height);
159 }
160 AggregatedStats sent_fps = sent_fps_counter_.GetStats();
161 if (sent_fps.num_samples >= kMinRequiredPeriodicSamples) {
154 RTC_HISTOGRAMS_COUNTS_100(kIndex, uma_prefix_ + "SentFramesPerSecond", 162 RTC_HISTOGRAMS_COUNTS_100(kIndex, uma_prefix_ + "SentFramesPerSecond",
155 sent_fps); 163 sent_fps.average);
164 LOG(LS_INFO) << uma_prefix_ + "SentFramesPerSecond, "
165 << sent_fps.ToString();
156 } 166 }
167
157 int encode_ms = encode_time_counter_.Avg(kMinRequiredMetricsSamples); 168 int encode_ms = encode_time_counter_.Avg(kMinRequiredMetricsSamples);
158 if (encode_ms != -1) { 169 if (encode_ms != -1) {
159 RTC_HISTOGRAMS_COUNTS_1000(kIndex, uma_prefix_ + "EncodeTimeInMs", 170 RTC_HISTOGRAMS_COUNTS_1000(kIndex, uma_prefix_ + "EncodeTimeInMs",
160 encode_ms); 171 encode_ms);
161 } 172 }
162 int key_frames_permille = 173 int key_frames_permille =
163 key_frame_counter_.Permille(kMinRequiredMetricsSamples); 174 key_frame_counter_.Permille(kMinRequiredMetricsSamples);
164 if (key_frames_permille != -1) { 175 if (key_frames_permille != -1) {
165 RTC_HISTOGRAMS_COUNTS_1000(kIndex, uma_prefix_ + "KeyFramesSentInPermille", 176 RTC_HISTOGRAMS_COUNTS_1000(kIndex, uma_prefix_ + "KeyFramesSentInPermille",
166 key_frames_permille); 177 key_frames_permille);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 rtc::CritScope lock(&crit_); 393 rtc::CritScope lock(&crit_);
383 uma_container_->encode_time_counter_.Add(encode_time_ms); 394 uma_container_->encode_time_counter_.Add(encode_time_ms);
384 encode_time_.Apply(1.0f, encode_time_ms); 395 encode_time_.Apply(1.0f, encode_time_ms);
385 stats_.avg_encode_time_ms = round(encode_time_.filtered()); 396 stats_.avg_encode_time_ms = round(encode_time_.filtered());
386 stats_.encode_usage_percent = metrics.encode_usage_percent; 397 stats_.encode_usage_percent = metrics.encode_usage_percent;
387 } 398 }
388 399
389 void SendStatisticsProxy::OnSuspendChange(bool is_suspended) { 400 void SendStatisticsProxy::OnSuspendChange(bool is_suspended) {
390 rtc::CritScope lock(&crit_); 401 rtc::CritScope lock(&crit_);
391 stats_.suspended = is_suspended; 402 stats_.suspended = is_suspended;
403 // Pause framerate stats.
404 if (is_suspended) {
405 uma_container_->input_fps_counter_.ProcessAndPause();
406 uma_container_->sent_fps_counter_.ProcessAndPause();
407 }
392 } 408 }
393 409
394 VideoSendStream::Stats SendStatisticsProxy::GetStats() { 410 VideoSendStream::Stats SendStatisticsProxy::GetStats() {
395 rtc::CritScope lock(&crit_); 411 rtc::CritScope lock(&crit_);
396 PurgeOldStats(); 412 PurgeOldStats();
397 stats_.input_frame_rate = 413 stats_.input_frame_rate =
398 round(uma_container_->input_frame_rate_tracker_.ComputeRate()); 414 round(uma_container_->input_frame_rate_tracker_.ComputeRate());
399 return stats_; 415 return stats_;
400 } 416 }
401 417
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 uma_container_->qp_counters_[spatial_idx].h264.Add(encoded_image.qp_); 550 uma_container_->qp_counters_[spatial_idx].h264.Add(encoded_image.qp_);
535 } 551 }
536 } 552 }
537 } 553 }
538 554
539 // TODO(asapersson): This is incorrect if simulcast layers are encoded on 555 // TODO(asapersson): This is incorrect if simulcast layers are encoded on
540 // different threads and there is no guarantee that one frame of all layers 556 // different threads and there is no guarantee that one frame of all layers
541 // are encoded before the next start. 557 // are encoded before the next start.
542 if (last_sent_frame_timestamp_ > 0 && 558 if (last_sent_frame_timestamp_ > 0 &&
543 encoded_image._timeStamp != last_sent_frame_timestamp_) { 559 encoded_image._timeStamp != last_sent_frame_timestamp_) {
544 uma_container_->sent_frame_rate_tracker_.AddSamples(1); 560 uma_container_->sent_fps_counter_.Add(1);
545 uma_container_->sent_width_counter_.Add( 561 uma_container_->sent_width_counter_.Add(
546 uma_container_->max_sent_width_per_timestamp_); 562 uma_container_->max_sent_width_per_timestamp_);
547 uma_container_->sent_height_counter_.Add( 563 uma_container_->sent_height_counter_.Add(
548 uma_container_->max_sent_height_per_timestamp_); 564 uma_container_->max_sent_height_per_timestamp_);
549 uma_container_->max_sent_width_per_timestamp_ = 0; 565 uma_container_->max_sent_width_per_timestamp_ = 0;
550 uma_container_->max_sent_height_per_timestamp_ = 0; 566 uma_container_->max_sent_height_per_timestamp_ = 0;
551 } 567 }
552 last_sent_frame_timestamp_ = encoded_image._timeStamp; 568 last_sent_frame_timestamp_ = encoded_image._timeStamp;
553 uma_container_->max_sent_width_per_timestamp_ = 569 uma_container_->max_sent_width_per_timestamp_ =
554 std::max(uma_container_->max_sent_width_per_timestamp_, 570 std::max(uma_container_->max_sent_width_per_timestamp_,
555 static_cast<int>(encoded_image._encodedWidth)); 571 static_cast<int>(encoded_image._encodedWidth));
556 uma_container_->max_sent_height_per_timestamp_ = 572 uma_container_->max_sent_height_per_timestamp_ =
557 std::max(uma_container_->max_sent_height_per_timestamp_, 573 std::max(uma_container_->max_sent_height_per_timestamp_,
558 static_cast<int>(encoded_image._encodedHeight)); 574 static_cast<int>(encoded_image._encodedHeight));
559 } 575 }
560 576
561 int SendStatisticsProxy::GetSendFrameRate() const { 577 int SendStatisticsProxy::GetSendFrameRate() const {
562 rtc::CritScope lock(&crit_); 578 rtc::CritScope lock(&crit_);
563 return stats_.encode_frame_rate; 579 return stats_.encode_frame_rate;
564 } 580 }
565 581
566 void SendStatisticsProxy::OnIncomingFrame(int width, int height) { 582 void SendStatisticsProxy::OnIncomingFrame(int width, int height) {
567 rtc::CritScope lock(&crit_); 583 rtc::CritScope lock(&crit_);
568 uma_container_->input_frame_rate_tracker_.AddSamples(1); 584 uma_container_->input_frame_rate_tracker_.AddSamples(1);
585 uma_container_->input_fps_counter_.Add(1);
569 uma_container_->input_width_counter_.Add(width); 586 uma_container_->input_width_counter_.Add(width);
570 uma_container_->input_height_counter_.Add(height); 587 uma_container_->input_height_counter_.Add(height);
571 uma_container_->cpu_limited_frame_counter_.Add(stats_.cpu_limited_resolution); 588 uma_container_->cpu_limited_frame_counter_.Add(stats_.cpu_limited_resolution);
572 } 589 }
573 590
574 void SendStatisticsProxy::SetCpuRestrictedResolution( 591 void SendStatisticsProxy::SetCpuRestrictedResolution(
575 bool cpu_restricted_resolution) { 592 bool cpu_restricted_resolution) {
576 rtc::CritScope lock(&crit_); 593 rtc::CritScope lock(&crit_);
577 stats_.cpu_limited_resolution = cpu_restricted_resolution; 594 stats_.cpu_limited_resolution = cpu_restricted_resolution;
578 } 595 }
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 return Fraction(min_required_samples, 1000.0f); 709 return Fraction(min_required_samples, 1000.0f);
693 } 710 }
694 711
695 int SendStatisticsProxy::BoolSampleCounter::Fraction( 712 int SendStatisticsProxy::BoolSampleCounter::Fraction(
696 int min_required_samples, float multiplier) const { 713 int min_required_samples, float multiplier) const {
697 if (num_samples < min_required_samples || num_samples == 0) 714 if (num_samples < min_required_samples || num_samples == 0)
698 return -1; 715 return -1;
699 return static_cast<int>((sum * multiplier / num_samples) + 0.5f); 716 return static_cast<int>((sum * multiplier / num_samples) + 0.5f);
700 } 717 }
701 } // namespace webrtc 718 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/send_statistics_proxy.h ('k') | webrtc/video/send_statistics_proxy_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698