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

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

Issue 1669623004: Use CallStats for RTT in Call, rather than VideoSendStream::GetRtt() (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Addressed comment, rebase Created 4 years, 10 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/call_stats.h ('k') | webrtc/video/call_stats_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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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/call_stats.h" 11 #include "webrtc/video/call_stats.h"
12 12
13 #include <assert.h>
14
15 #include <algorithm> 13 #include <algorithm>
16 14
15 #include "webrtc/base/checks.h"
17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 16 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
17 #include "webrtc/system_wrappers/include/metrics.h"
18 #include "webrtc/system_wrappers/include/tick_util.h" 18 #include "webrtc/system_wrappers/include/tick_util.h"
19 19
20 namespace webrtc { 20 namespace webrtc {
21 namespace { 21 namespace {
22 // Time interval for updating the observers. 22 // Time interval for updating the observers.
23 const int64_t kUpdateIntervalMs = 1000; 23 const int64_t kUpdateIntervalMs = 1000;
24 // Weight factor to apply to the average rtt. 24 // Weight factor to apply to the average rtt.
25 const float kWeightFactor = 0.3f; 25 const float kWeightFactor = 0.3f;
26 26
27 void RemoveOldReports(int64_t now, std::list<CallStats::RttTime>* reports) { 27 void RemoveOldReports(int64_t now, std::list<CallStats::RttTime>* reports) {
28 // A rtt report is considered valid for this long. 28 // A rtt report is considered valid for this long.
29 const int64_t kRttTimeoutMs = 1500; 29 const int64_t kRttTimeoutMs = 1500;
30 while (!reports->empty() && 30 while (!reports->empty() &&
31 (now - reports->front().time) > kRttTimeoutMs) { 31 (now - reports->front().time) > kRttTimeoutMs) {
32 reports->pop_front(); 32 reports->pop_front();
33 } 33 }
34 } 34 }
35 35
36 int64_t GetMaxRttMs(std::list<CallStats::RttTime>* reports) { 36 int64_t GetMaxRttMs(std::list<CallStats::RttTime>* reports) {
37 if (reports->empty())
38 return -1;
37 int64_t max_rtt_ms = 0; 39 int64_t max_rtt_ms = 0;
38 for (std::list<CallStats::RttTime>::const_iterator it = reports->begin(); 40 for (const CallStats::RttTime& rtt_time : *reports)
39 it != reports->end(); ++it) { 41 max_rtt_ms = std::max(rtt_time.rtt, max_rtt_ms);
40 max_rtt_ms = std::max(it->rtt, max_rtt_ms);
41 }
42 return max_rtt_ms; 42 return max_rtt_ms;
43 } 43 }
44 44
45 int64_t GetAvgRttMs(std::list<CallStats::RttTime>* reports) { 45 int64_t GetAvgRttMs(std::list<CallStats::RttTime>* reports) {
46 if (reports->empty()) { 46 if (reports->empty()) {
47 return 0; 47 return -1;
48 } 48 }
49 int64_t sum = 0; 49 int64_t sum = 0;
50 for (std::list<CallStats::RttTime>::const_iterator it = reports->begin(); 50 for (std::list<CallStats::RttTime>::const_iterator it = reports->begin();
51 it != reports->end(); ++it) { 51 it != reports->end(); ++it) {
52 sum += it->rtt; 52 sum += it->rtt;
53 } 53 }
54 return sum / reports->size(); 54 return sum / reports->size();
55 } 55 }
56 56
57 void UpdateAvgRttMs(std::list<CallStats::RttTime>* reports, int64_t* avg_rtt) { 57 void UpdateAvgRttMs(std::list<CallStats::RttTime>* reports, int64_t* avg_rtt) {
58 uint32_t cur_rtt_ms = GetAvgRttMs(reports); 58 int64_t cur_rtt_ms = GetAvgRttMs(reports);
59 if (cur_rtt_ms == 0) { 59 if (cur_rtt_ms == -1) {
60 // Reset. 60 // Reset.
61 *avg_rtt = 0; 61 *avg_rtt = -1;
62 return; 62 return;
63 } 63 }
64 if (*avg_rtt == 0) { 64 if (*avg_rtt == -1) {
65 // Initialize. 65 // Initialize.
66 *avg_rtt = cur_rtt_ms; 66 *avg_rtt = cur_rtt_ms;
67 return; 67 return;
68 } 68 }
69 *avg_rtt = *avg_rtt * (1.0f - kWeightFactor) + cur_rtt_ms * kWeightFactor; 69 *avg_rtt = *avg_rtt * (1.0f - kWeightFactor) + cur_rtt_ms * kWeightFactor;
70 } 70 }
71 } // namespace 71 } // namespace
72 72
73 class RtcpObserver : public RtcpRttStats { 73 class RtcpObserver : public RtcpRttStats {
74 public: 74 public:
(...skipping 12 matching lines...) Expand all
87 private: 87 private:
88 CallStats* owner_; 88 CallStats* owner_;
89 89
90 RTC_DISALLOW_COPY_AND_ASSIGN(RtcpObserver); 90 RTC_DISALLOW_COPY_AND_ASSIGN(RtcpObserver);
91 }; 91 };
92 92
93 CallStats::CallStats(Clock* clock) 93 CallStats::CallStats(Clock* clock)
94 : clock_(clock), 94 : clock_(clock),
95 rtcp_rtt_stats_(new RtcpObserver(this)), 95 rtcp_rtt_stats_(new RtcpObserver(this)),
96 last_process_time_(clock_->TimeInMilliseconds()), 96 last_process_time_(clock_->TimeInMilliseconds()),
97 max_rtt_ms_(0), 97 max_rtt_ms_(-1),
98 avg_rtt_ms_(0) {} 98 avg_rtt_ms_(-1),
99 sum_avg_rtt_ms_(0),
100 num_avg_rtt_(0),
101 time_of_first_rtt_ms_(-1) {}
99 102
100 CallStats::~CallStats() { 103 CallStats::~CallStats() {
101 assert(observers_.empty()); 104 RTC_DCHECK(observers_.empty());
105 UpdateHistograms();
102 } 106 }
103 107
104 int64_t CallStats::TimeUntilNextProcess() { 108 int64_t CallStats::TimeUntilNextProcess() {
105 return last_process_time_ + kUpdateIntervalMs - clock_->TimeInMilliseconds(); 109 return last_process_time_ + kUpdateIntervalMs - clock_->TimeInMilliseconds();
106 } 110 }
107 111
108 int32_t CallStats::Process() { 112 int32_t CallStats::Process() {
109 rtc::CritScope cs(&crit_); 113 rtc::CritScope cs(&crit_);
110 int64_t now = clock_->TimeInMilliseconds(); 114 int64_t now = clock_->TimeInMilliseconds();
111 if (now < last_process_time_ + kUpdateIntervalMs) 115 if (now < last_process_time_ + kUpdateIntervalMs)
112 return 0; 116 return 0;
113 117
114 last_process_time_ = now; 118 last_process_time_ = now;
115 119
116 RemoveOldReports(now, &reports_); 120 RemoveOldReports(now, &reports_);
117 max_rtt_ms_ = GetMaxRttMs(&reports_); 121 max_rtt_ms_ = GetMaxRttMs(&reports_);
118 UpdateAvgRttMs(&reports_, &avg_rtt_ms_); 122 UpdateAvgRttMs(&reports_, &avg_rtt_ms_);
119 123
120 // If there is a valid rtt, update all observers with the max rtt. 124 // If there is a valid rtt, update all observers with the max rtt.
121 // TODO(asapersson): Consider changing this to report the average rtt. 125 if (max_rtt_ms_ >= 0) {
122 if (max_rtt_ms_ > 0) { 126 RTC_DCHECK_GE(avg_rtt_ms_, 0);
123 for (std::list<CallStatsObserver*>::iterator it = observers_.begin(); 127 for (std::list<CallStatsObserver*>::iterator it = observers_.begin();
124 it != observers_.end(); ++it) { 128 it != observers_.end(); ++it) {
125 (*it)->OnRttUpdate(avg_rtt_ms_, max_rtt_ms_); 129 (*it)->OnRttUpdate(avg_rtt_ms_, max_rtt_ms_);
126 } 130 }
131 // Sum for Histogram of average RTT reported over the entire call.
132 sum_avg_rtt_ms_ += avg_rtt_ms_;
133 ++num_avg_rtt_;
127 } 134 }
128 return 0; 135 return 0;
129 } 136 }
130 137
131 int64_t CallStats::avg_rtt_ms() const { 138 int64_t CallStats::avg_rtt_ms() const {
132 rtc::CritScope cs(&crit_); 139 rtc::CritScope cs(&crit_);
133 return avg_rtt_ms_; 140 return avg_rtt_ms_;
134 } 141 }
135 142
136 RtcpRttStats* CallStats::rtcp_rtt_stats() const { 143 RtcpRttStats* CallStats::rtcp_rtt_stats() const {
(...skipping 16 matching lines...) Expand all
153 it != observers_.end(); ++it) { 160 it != observers_.end(); ++it) {
154 if (*it == observer) { 161 if (*it == observer) {
155 observers_.erase(it); 162 observers_.erase(it);
156 return; 163 return;
157 } 164 }
158 } 165 }
159 } 166 }
160 167
161 void CallStats::OnRttUpdate(int64_t rtt) { 168 void CallStats::OnRttUpdate(int64_t rtt) {
162 rtc::CritScope cs(&crit_); 169 rtc::CritScope cs(&crit_);
163 reports_.push_back(RttTime(rtt, clock_->TimeInMilliseconds())); 170 int64_t now_ms = clock_->TimeInMilliseconds();
171 reports_.push_back(RttTime(rtt, now_ms));
172 if (time_of_first_rtt_ms_ == -1)
173 time_of_first_rtt_ms_ = now_ms;
174 }
175
176 void CallStats::UpdateHistograms() {
177 rtc::CritScope cs(&crit_);
178 if (time_of_first_rtt_ms_ == -1 || num_avg_rtt_ < 1)
179 return;
180
181 int64_t elapsed_sec =
182 (clock_->TimeInMilliseconds() - time_of_first_rtt_ms_) / 1000;
183 if (elapsed_sec >= metrics::kMinRunTimeInSeconds) {
184 int64_t avg_rtt_ms = (sum_avg_rtt_ms_ + num_avg_rtt_ / 2) / num_avg_rtt_;
185 RTC_HISTOGRAM_COUNTS_10000(
186 "WebRTC.Video.AverageRoundTripTimeInMilliseconds", avg_rtt_ms);
187 }
164 } 188 }
165 189
166 } // namespace webrtc 190 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/call_stats.h ('k') | webrtc/video/call_stats_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698