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

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

Issue 1613053003: Swap use of CriticalSectionWrapper for rtc::CriticalSection in webrtc/video. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase? Created 4 years, 11 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/encoder_state_feedback.h » ('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> 13 #include <assert.h>
14 14
15 #include <algorithm> 15 #include <algorithm>
16 16
17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
18 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
19 #include "webrtc/system_wrappers/include/tick_util.h" 18 #include "webrtc/system_wrappers/include/tick_util.h"
20 19
21 namespace webrtc { 20 namespace webrtc {
22 namespace { 21 namespace {
23 // Time interval for updating the observers. 22 // Time interval for updating the observers.
24 const int64_t kUpdateIntervalMs = 1000; 23 const int64_t kUpdateIntervalMs = 1000;
25 // Weight factor to apply to the average rtt. 24 // Weight factor to apply to the average rtt.
26 const float kWeightFactor = 0.3f; 25 const float kWeightFactor = 0.3f;
27 26
28 void RemoveOldReports(int64_t now, std::list<CallStats::RttTime>* reports) { 27 void RemoveOldReports(int64_t now, std::list<CallStats::RttTime>* reports) {
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 85 }
87 86
88 private: 87 private:
89 CallStats* owner_; 88 CallStats* owner_;
90 89
91 RTC_DISALLOW_COPY_AND_ASSIGN(RtcpObserver); 90 RTC_DISALLOW_COPY_AND_ASSIGN(RtcpObserver);
92 }; 91 };
93 92
94 CallStats::CallStats(Clock* clock) 93 CallStats::CallStats(Clock* clock)
95 : clock_(clock), 94 : clock_(clock),
96 crit_(CriticalSectionWrapper::CreateCriticalSection()),
97 rtcp_rtt_stats_(new RtcpObserver(this)), 95 rtcp_rtt_stats_(new RtcpObserver(this)),
98 last_process_time_(clock_->TimeInMilliseconds()), 96 last_process_time_(clock_->TimeInMilliseconds()),
99 max_rtt_ms_(0), 97 max_rtt_ms_(0),
100 avg_rtt_ms_(0) {} 98 avg_rtt_ms_(0) {}
101 99
102 CallStats::~CallStats() { 100 CallStats::~CallStats() {
103 assert(observers_.empty()); 101 assert(observers_.empty());
104 } 102 }
105 103
106 int64_t CallStats::TimeUntilNextProcess() { 104 int64_t CallStats::TimeUntilNextProcess() {
107 return last_process_time_ + kUpdateIntervalMs - clock_->TimeInMilliseconds(); 105 return last_process_time_ + kUpdateIntervalMs - clock_->TimeInMilliseconds();
108 } 106 }
109 107
110 int32_t CallStats::Process() { 108 int32_t CallStats::Process() {
111 CriticalSectionScoped cs(crit_.get()); 109 rtc::CritScope cs(&crit_);
112 int64_t now = clock_->TimeInMilliseconds(); 110 int64_t now = clock_->TimeInMilliseconds();
113 if (now < last_process_time_ + kUpdateIntervalMs) 111 if (now < last_process_time_ + kUpdateIntervalMs)
114 return 0; 112 return 0;
115 113
116 last_process_time_ = now; 114 last_process_time_ = now;
117 115
118 RemoveOldReports(now, &reports_); 116 RemoveOldReports(now, &reports_);
119 max_rtt_ms_ = GetMaxRttMs(&reports_); 117 max_rtt_ms_ = GetMaxRttMs(&reports_);
120 UpdateAvgRttMs(&reports_, &avg_rtt_ms_); 118 UpdateAvgRttMs(&reports_, &avg_rtt_ms_);
121 119
122 // If there is a valid rtt, update all observers with the max rtt. 120 // If there is a valid rtt, update all observers with the max rtt.
123 // TODO(asapersson): Consider changing this to report the average rtt. 121 // TODO(asapersson): Consider changing this to report the average rtt.
124 if (max_rtt_ms_ > 0) { 122 if (max_rtt_ms_ > 0) {
125 for (std::list<CallStatsObserver*>::iterator it = observers_.begin(); 123 for (std::list<CallStatsObserver*>::iterator it = observers_.begin();
126 it != observers_.end(); ++it) { 124 it != observers_.end(); ++it) {
127 (*it)->OnRttUpdate(avg_rtt_ms_, max_rtt_ms_); 125 (*it)->OnRttUpdate(avg_rtt_ms_, max_rtt_ms_);
128 } 126 }
129 } 127 }
130 return 0; 128 return 0;
131 } 129 }
132 130
133 int64_t CallStats::avg_rtt_ms() const { 131 int64_t CallStats::avg_rtt_ms() const {
134 CriticalSectionScoped cs(crit_.get()); 132 rtc::CritScope cs(&crit_);
135 return avg_rtt_ms_; 133 return avg_rtt_ms_;
136 } 134 }
137 135
138 RtcpRttStats* CallStats::rtcp_rtt_stats() const { 136 RtcpRttStats* CallStats::rtcp_rtt_stats() const {
139 return rtcp_rtt_stats_.get(); 137 return rtcp_rtt_stats_.get();
140 } 138 }
141 139
142 void CallStats::RegisterStatsObserver(CallStatsObserver* observer) { 140 void CallStats::RegisterStatsObserver(CallStatsObserver* observer) {
143 CriticalSectionScoped cs(crit_.get()); 141 rtc::CritScope cs(&crit_);
144 for (std::list<CallStatsObserver*>::iterator it = observers_.begin(); 142 for (std::list<CallStatsObserver*>::iterator it = observers_.begin();
145 it != observers_.end(); ++it) { 143 it != observers_.end(); ++it) {
146 if (*it == observer) 144 if (*it == observer)
147 return; 145 return;
148 } 146 }
149 observers_.push_back(observer); 147 observers_.push_back(observer);
150 } 148 }
151 149
152 void CallStats::DeregisterStatsObserver(CallStatsObserver* observer) { 150 void CallStats::DeregisterStatsObserver(CallStatsObserver* observer) {
153 CriticalSectionScoped cs(crit_.get()); 151 rtc::CritScope cs(&crit_);
154 for (std::list<CallStatsObserver*>::iterator it = observers_.begin(); 152 for (std::list<CallStatsObserver*>::iterator it = observers_.begin();
155 it != observers_.end(); ++it) { 153 it != observers_.end(); ++it) {
156 if (*it == observer) { 154 if (*it == observer) {
157 observers_.erase(it); 155 observers_.erase(it);
158 return; 156 return;
159 } 157 }
160 } 158 }
161 } 159 }
162 160
163 void CallStats::OnRttUpdate(int64_t rtt) { 161 void CallStats::OnRttUpdate(int64_t rtt) {
164 CriticalSectionScoped cs(crit_.get()); 162 rtc::CritScope cs(&crit_);
165 reports_.push_back(RttTime(rtt, clock_->TimeInMilliseconds())); 163 reports_.push_back(RttTime(rtt, clock_->TimeInMilliseconds()));
166 } 164 }
167 165
168 } // namespace webrtc 166 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/call_stats.h ('k') | webrtc/video/encoder_state_feedback.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698