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

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: win64 fix Created 5 years, 4 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 const size_t SendStatisticsProxy::kFrameRateTrackerInterval =
26 kStatsTimeoutMs / 1000;
25 27
26 SendStatisticsProxy::SendStatisticsProxy(Clock* clock, 28 SendStatisticsProxy::SendStatisticsProxy(Clock* clock,
27 const VideoSendStream::Config& config) 29 const VideoSendStream::Config& config)
28 : clock_(clock), 30 : clock_(clock),
29 config_(config), 31 config_(config),
32 input_frame_rate_tracker_(kFrameRateTrackerInterval),
33 input_frame_rate_tracker_total_(kFrameRateTrackerInterval),
34 sent_frame_rate_tracker_total_(kFrameRateTrackerInterval),
30 last_sent_frame_timestamp_(0), 35 last_sent_frame_timestamp_(0),
31 max_sent_width_per_timestamp_(0), 36 max_sent_width_per_timestamp_(0),
32 max_sent_height_per_timestamp_(0) { 37 max_sent_height_per_timestamp_(0) {
33 } 38 }
34 39
35 SendStatisticsProxy::~SendStatisticsProxy() { 40 SendStatisticsProxy::~SendStatisticsProxy() {
36 UpdateHistograms(); 41 UpdateHistograms();
37 } 42 }
38 43
39 void SendStatisticsProxy::UpdateHistograms() { 44 void SendStatisticsProxy::UpdateHistograms() {
40 int input_fps = 45 int input_fps =
41 static_cast<int>(input_frame_rate_tracker_total_.units_second()); 46 static_cast<int>(input_frame_rate_tracker_total_.ComputeCurrentRate(
47 kFrameRateTrackerInterval * 1000u));
åsapersson 2015/08/28 08:12:47 input_fps and sent_fps below are an average over t
pbos-webrtc 2015/08/28 12:47:55 Can you add support for a ComputeTotalRate() or so
tpsiaki 2015/09/01 20:59:17 Done.
42 if (input_fps > 0) 48 if (input_fps > 0)
43 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.InputFramesPerSecond", input_fps); 49 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.InputFramesPerSecond", input_fps);
44 int sent_fps = 50 int sent_fps =
45 static_cast<int>(sent_frame_rate_tracker_total_.units_second()); 51 static_cast<int>(sent_frame_rate_tracker_total_.ComputeCurrentRate(
52 kFrameRateTrackerInterval * 1000u));
46 if (sent_fps > 0) 53 if (sent_fps > 0)
47 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.SentFramesPerSecond", sent_fps); 54 RTC_HISTOGRAM_COUNTS_100("WebRTC.Video.SentFramesPerSecond", sent_fps);
48 55
49 const int kMinRequiredSamples = 200; 56 const int kMinRequiredSamples = 200;
50 int in_width = input_width_counter_.Avg(kMinRequiredSamples); 57 int in_width = input_width_counter_.Avg(kMinRequiredSamples);
51 int in_height = input_height_counter_.Avg(kMinRequiredSamples); 58 int in_height = input_height_counter_.Avg(kMinRequiredSamples);
52 if (in_width != -1) { 59 if (in_width != -1) {
53 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.InputWidthInPixels", in_width); 60 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.InputWidthInPixels", in_width);
54 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.InputHeightInPixels", in_height); 61 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.InputHeightInPixels", in_height);
55 } 62 }
(...skipping 26 matching lines...) Expand all
82 89
83 void SendStatisticsProxy::SuspendChange(int video_channel, bool is_suspended) { 90 void SendStatisticsProxy::SuspendChange(int video_channel, bool is_suspended) {
84 rtc::CritScope lock(&crit_); 91 rtc::CritScope lock(&crit_);
85 stats_.suspended = is_suspended; 92 stats_.suspended = is_suspended;
86 } 93 }
87 94
88 VideoSendStream::Stats SendStatisticsProxy::GetStats() { 95 VideoSendStream::Stats SendStatisticsProxy::GetStats() {
89 rtc::CritScope lock(&crit_); 96 rtc::CritScope lock(&crit_);
90 PurgeOldStats(); 97 PurgeOldStats();
91 stats_.input_frame_rate = 98 stats_.input_frame_rate =
92 static_cast<int>(input_frame_rate_tracker_.units_second()); 99 static_cast<int>(input_frame_rate_tracker_.ComputeCurrentRate(
100 kFrameRateTrackerInterval * 1000u));
93 return stats_; 101 return stats_;
94 } 102 }
95 103
96 void SendStatisticsProxy::PurgeOldStats() { 104 void SendStatisticsProxy::PurgeOldStats() {
97 int64_t old_stats_ms = clock_->TimeInMilliseconds() - kStatsTimeoutMs; 105 int64_t old_stats_ms = clock_->TimeInMilliseconds() - kStatsTimeoutMs;
98 for (std::map<uint32_t, VideoSendStream::StreamStats>::iterator it = 106 for (std::map<uint32_t, VideoSendStream::StreamStats>::iterator it =
99 stats_.substreams.begin(); 107 stats_.substreams.begin();
100 it != stats_.substreams.end(); ++it) { 108 it != stats_.substreams.end(); ++it) {
101 uint32_t ssrc = it->first; 109 uint32_t ssrc = it->first;
102 if (update_times_[ssrc].resolution_update_ms <= old_stats_ms) { 110 if (update_times_[ssrc].resolution_update_ms <= old_stats_ms) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 168
161 stats->width = encoded_image._encodedWidth; 169 stats->width = encoded_image._encodedWidth;
162 stats->height = encoded_image._encodedHeight; 170 stats->height = encoded_image._encodedHeight;
163 update_times_[ssrc].resolution_update_ms = clock_->TimeInMilliseconds(); 171 update_times_[ssrc].resolution_update_ms = clock_->TimeInMilliseconds();
164 172
165 // TODO(asapersson): This is incorrect if simulcast layers are encoded on 173 // 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 174 // different threads and there is no guarantee that one frame of all layers
167 // are encoded before the next start. 175 // are encoded before the next start.
168 if (last_sent_frame_timestamp_ > 0 && 176 if (last_sent_frame_timestamp_ > 0 &&
169 encoded_image._timeStamp != last_sent_frame_timestamp_) { 177 encoded_image._timeStamp != last_sent_frame_timestamp_) {
170 sent_frame_rate_tracker_total_.Update(1); 178 sent_frame_rate_tracker_total_.AddSamples(1);
171 sent_width_counter_.Add(max_sent_width_per_timestamp_); 179 sent_width_counter_.Add(max_sent_width_per_timestamp_);
172 sent_height_counter_.Add(max_sent_height_per_timestamp_); 180 sent_height_counter_.Add(max_sent_height_per_timestamp_);
173 max_sent_width_per_timestamp_ = 0; 181 max_sent_width_per_timestamp_ = 0;
174 max_sent_height_per_timestamp_ = 0; 182 max_sent_height_per_timestamp_ = 0;
175 } 183 }
176 last_sent_frame_timestamp_ = encoded_image._timeStamp; 184 last_sent_frame_timestamp_ = encoded_image._timeStamp;
177 max_sent_width_per_timestamp_ = 185 max_sent_width_per_timestamp_ =
178 std::max(max_sent_width_per_timestamp_, 186 std::max(max_sent_width_per_timestamp_,
179 static_cast<int>(encoded_image._encodedWidth)); 187 static_cast<int>(encoded_image._encodedWidth));
180 max_sent_height_per_timestamp_ = 188 max_sent_height_per_timestamp_ =
181 std::max(max_sent_height_per_timestamp_, 189 std::max(max_sent_height_per_timestamp_,
182 static_cast<int>(encoded_image._encodedHeight)); 190 static_cast<int>(encoded_image._encodedHeight));
183 } 191 }
184 192
185 void SendStatisticsProxy::OnIncomingFrame(int width, int height) { 193 void SendStatisticsProxy::OnIncomingFrame(int width, int height) {
186 rtc::CritScope lock(&crit_); 194 rtc::CritScope lock(&crit_);
187 input_frame_rate_tracker_.Update(1); 195 input_frame_rate_tracker_.AddSamples(1);
188 input_frame_rate_tracker_total_.Update(1); 196 input_frame_rate_tracker_total_.AddSamples(1);
189 input_width_counter_.Add(width); 197 input_width_counter_.Add(width);
190 input_height_counter_.Add(height); 198 input_height_counter_.Add(height);
191 } 199 }
192 200
193 void SendStatisticsProxy::OnEncodedFrame(int encode_time_ms) { 201 void SendStatisticsProxy::OnEncodedFrame(int encode_time_ms) {
194 rtc::CritScope lock(&crit_); 202 rtc::CritScope lock(&crit_);
195 encode_time_counter_.Add(encode_time_ms); 203 encode_time_counter_.Add(encode_time_ms);
196 } 204 }
197 205
198 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated( 206 void SendStatisticsProxy::RtcpPacketTypesCounterUpdated(
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 ++num_samples; 276 ++num_samples;
269 } 277 }
270 278
271 int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const { 279 int SendStatisticsProxy::SampleCounter::Avg(int min_required_samples) const {
272 if (num_samples < min_required_samples || num_samples == 0) 280 if (num_samples < min_required_samples || num_samples == 0)
273 return -1; 281 return -1;
274 return sum / num_samples; 282 return sum / num_samples;
275 } 283 }
276 284
277 } // namespace webrtc 285 } // 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