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

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

Issue 1279433006: Add a rate tracker that tracks rate over a given interval split up into buckets that accumulate uni… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: New tests and readability fixes. Created 5 years, 3 months 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') | no next file » | 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
11 #include "webrtc/video/send_statistics_proxy.h" 11 #include "webrtc/video/send_statistics_proxy.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <map> 14 #include <map>
15 15
16 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 17
18 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" 18 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
19 #include "webrtc/system_wrappers/interface/logging.h" 19 #include "webrtc/system_wrappers/interface/logging.h"
20 #include "webrtc/system_wrappers/interface/metrics.h" 20 #include "webrtc/system_wrappers/interface/metrics.h"
21 21
22 namespace webrtc { 22 namespace webrtc {
23 23
24 const int SendStatisticsProxy::kStatsTimeoutMs = 5000; 24 const int SendStatisticsProxy::kStatsTimeoutMs = 5000;
25 25
26 SendStatisticsProxy::SendStatisticsProxy(Clock* clock, 26 SendStatisticsProxy::SendStatisticsProxy(Clock* clock,
27 const VideoSendStream::Config& config) 27 const VideoSendStream::Config& config)
28 : clock_(clock), 28 : clock_(clock),
29 config_(config), 29 config_(config),
30 input_frame_rate_tracker_(100u, 10u),
31 sent_frame_rate_tracker_(100u, 10u),
30 last_sent_frame_timestamp_(0), 32 last_sent_frame_timestamp_(0),
31 max_sent_width_per_timestamp_(0), 33 max_sent_width_per_timestamp_(0),
32 max_sent_height_per_timestamp_(0) { 34 max_sent_height_per_timestamp_(0) {
33 } 35 }
34 36
35 SendStatisticsProxy::~SendStatisticsProxy() { 37 SendStatisticsProxy::~SendStatisticsProxy() {
36 UpdateHistograms(); 38 UpdateHistograms();
37 } 39 }
38 40
39 void SendStatisticsProxy::UpdateHistograms() { 41 void SendStatisticsProxy::UpdateHistograms() {
40 int input_fps = 42 int input_fps =
41 static_cast<int>(input_frame_rate_tracker_total_.units_second()); 43 static_cast<int>(input_frame_rate_tracker_.ComputeTotalRate());
42 if (input_fps > 0) 44 if (input_fps > 0)
43 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.InputFramesPerSecond", input_fps); 45 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.InputFramesPerSecond", input_fps);
44 int sent_fps = 46 int sent_fps =
45 static_cast<int>(sent_frame_rate_tracker_total_.units_second()); 47 static_cast<int>(sent_frame_rate_tracker_.ComputeTotalRate());
46 if (sent_fps > 0) 48 if (sent_fps > 0)
47 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.SentFramesPerSecond", sent_fps); 49 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.SentFramesPerSecond", sent_fps);
48 50
49 const int kMinRequiredSamples = 200; 51 const int kMinRequiredSamples = 200;
50 int in_width = input_width_counter_.Avg(kMinRequiredSamples); 52 int in_width = input_width_counter_.Avg(kMinRequiredSamples);
51 int in_height = input_height_counter_.Avg(kMinRequiredSamples); 53 int in_height = input_height_counter_.Avg(kMinRequiredSamples);
52 if (in_width != -1) { 54 if (in_width != -1) {
53 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.InputWidthInPixels", in_width); 55 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.InputWidthInPixels", in_width);
54 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.InputHeightInPixels", in_height); 56 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.InputHeightInPixels", in_height);
55 } 57 }
(...skipping 26 matching lines...) Expand all
82 84
83 void SendStatisticsProxy::SuspendChange(int video_channel, bool is_suspended) { 85 void SendStatisticsProxy::SuspendChange(int video_channel, bool is_suspended) {
84 rtc::CritScope lock(&crit_); 86 rtc::CritScope lock(&crit_);
85 stats_.suspended = is_suspended; 87 stats_.suspended = is_suspended;
86 } 88 }
87 89
88 VideoSendStream::Stats SendStatisticsProxy::GetStats() { 90 VideoSendStream::Stats SendStatisticsProxy::GetStats() {
89 rtc::CritScope lock(&crit_); 91 rtc::CritScope lock(&crit_);
90 PurgeOldStats(); 92 PurgeOldStats();
91 stats_.input_frame_rate = 93 stats_.input_frame_rate =
92 static_cast<int>(input_frame_rate_tracker_.units_second()); 94 static_cast<int>(input_frame_rate_tracker_.ComputeRate());
93 return stats_; 95 return stats_;
94 } 96 }
95 97
96 void SendStatisticsProxy::PurgeOldStats() { 98 void SendStatisticsProxy::PurgeOldStats() {
97 int64_t old_stats_ms = clock_->TimeInMilliseconds() - kStatsTimeoutMs; 99 int64_t old_stats_ms = clock_->TimeInMilliseconds() - kStatsTimeoutMs;
98 for (std::map<uint32_t, VideoSendStream::StreamStats>::iterator it = 100 for (std::map<uint32_t, VideoSendStream::StreamStats>::iterator it =
99 stats_.substreams.begin(); 101 stats_.substreams.begin();
100 it != stats_.substreams.end(); ++it) { 102 it != stats_.substreams.end(); ++it) {
101 uint32_t ssrc = it->first; 103 uint32_t ssrc = it->first;
102 if (update_times_[ssrc].resolution_update_ms <= old_stats_ms) { 104 if (update_times_[ssrc].resolution_update_ms <= old_stats_ms) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 162
161 stats->width = encoded_image._encodedWidth; 163 stats->width = encoded_image._encodedWidth;
162 stats->height = encoded_image._encodedHeight; 164 stats->height = encoded_image._encodedHeight;
163 update_times_[ssrc].resolution_update_ms = clock_->TimeInMilliseconds(); 165 update_times_[ssrc].resolution_update_ms = clock_->TimeInMilliseconds();
164 166
165 // TODO(asapersson): This is incorrect if simulcast layers are encoded on 167 // TODO(asapersson): This is incorrect if simulcast layers are encoded on
166 // different threads and there is no guarantee that one frame of all layers 168 // different threads and there is no guarantee that one frame of all layers
167 // are encoded before the next start. 169 // are encoded before the next start.
168 if (last_sent_frame_timestamp_ > 0 && 170 if (last_sent_frame_timestamp_ > 0 &&
169 encoded_image._timeStamp != last_sent_frame_timestamp_) { 171 encoded_image._timeStamp != last_sent_frame_timestamp_) {
170 sent_frame_rate_tracker_total_.Update(1); 172 sent_frame_rate_tracker_.AddSamples(1);
171 sent_width_counter_.Add(max_sent_width_per_timestamp_); 173 sent_width_counter_.Add(max_sent_width_per_timestamp_);
172 sent_height_counter_.Add(max_sent_height_per_timestamp_); 174 sent_height_counter_.Add(max_sent_height_per_timestamp_);
173 max_sent_width_per_timestamp_ = 0; 175 max_sent_width_per_timestamp_ = 0;
174 max_sent_height_per_timestamp_ = 0; 176 max_sent_height_per_timestamp_ = 0;
175 } 177 }
176 last_sent_frame_timestamp_ = encoded_image._timeStamp; 178 last_sent_frame_timestamp_ = encoded_image._timeStamp;
177 max_sent_width_per_timestamp_ = 179 max_sent_width_per_timestamp_ =
178 std::max(max_sent_width_per_timestamp_, 180 std::max(max_sent_width_per_timestamp_,
179 static_cast<int>(encoded_image._encodedWidth)); 181 static_cast<int>(encoded_image._encodedWidth));
180 max_sent_height_per_timestamp_ = 182 max_sent_height_per_timestamp_ =
181 std::max(max_sent_height_per_timestamp_, 183 std::max(max_sent_height_per_timestamp_,
182 static_cast<int>(encoded_image._encodedHeight)); 184 static_cast<int>(encoded_image._encodedHeight));
183 } 185 }
184 186
185 void SendStatisticsProxy::OnIncomingFrame(int width, int height) { 187 void SendStatisticsProxy::OnIncomingFrame(int width, int height) {
186 rtc::CritScope lock(&crit_); 188 rtc::CritScope lock(&crit_);
187 input_frame_rate_tracker_.Update(1); 189 input_frame_rate_tracker_.AddSamples(1);
188 input_frame_rate_tracker_total_.Update(1);
189 input_width_counter_.Add(width); 190 input_width_counter_.Add(width);
190 input_height_counter_.Add(height); 191 input_height_counter_.Add(height);
191 } 192 }
192 193
193 void SendStatisticsProxy::OnEncodedFrame(int encode_time_ms) { 194 void SendStatisticsProxy::OnEncodedFrame(int encode_time_ms) {
194 rtc::CritScope lock(&crit_); 195 rtc::CritScope lock(&crit_);
195 encode_time_counter_.Add(encode_time_ms); 196 encode_time_counter_.Add(encode_time_ms);
196 } 197 }
197 198
198 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( 199 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 ++num_samples; 269 ++num_samples;
269 } 270 }
270 271
271 int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { 272 int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const {
272 if (num_samples < min_required_samples || num_samples == 0) 273 if (num_samples < min_required_samples || num_samples == 0)
273 return -1; 274 return -1;
274 return sum / num_samples; 275 return sum / num_samples;
275 } 276 }
276 277
277 } // namespace webrtc 278 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/send_statistics_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698