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

Side by Side Diff: webrtc/call/bitrate_allocator.cc

Issue 2060403002: Add task queue to Call. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@move_getpadding
Patch Set: Use SequencedTaskChecker in i420_buffer_pool.cc Created 4 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 BitrateAllocator::BitrateAllocator(LimitObserver* limit_observer) 48 BitrateAllocator::BitrateAllocator(LimitObserver* limit_observer)
49 : limit_observer_(limit_observer), 49 : limit_observer_(limit_observer),
50 bitrate_observer_configs_(), 50 bitrate_observer_configs_(),
51 last_bitrate_bps_(kDefaultBitrateBps), 51 last_bitrate_bps_(kDefaultBitrateBps),
52 last_non_zero_bitrate_bps_(kDefaultBitrateBps), 52 last_non_zero_bitrate_bps_(kDefaultBitrateBps),
53 last_fraction_loss_(0), 53 last_fraction_loss_(0),
54 last_rtt_(0), 54 last_rtt_(0),
55 num_pause_events_(0), 55 num_pause_events_(0),
56 clock_(Clock::GetRealTimeClock()), 56 clock_(Clock::GetRealTimeClock()),
57 last_bwe_log_time_(0) {} 57 last_bwe_log_time_(0) {
58 sequenced_checker_.Detach();
59 }
58 60
59 BitrateAllocator::~BitrateAllocator() { 61 BitrateAllocator::~BitrateAllocator() {
60 RTC_LOGGED_HISTOGRAM_COUNTS_100("WebRTC.Call.NumberOfPauseEvents", 62 RTC_LOGGED_HISTOGRAM_COUNTS_100("WebRTC.Call.NumberOfPauseEvents",
61 num_pause_events_); 63 num_pause_events_);
62 } 64 }
63 65
64 void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps, 66 void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps,
65 uint8_t fraction_loss, 67 uint8_t fraction_loss,
66 int64_t rtt) { 68 int64_t rtt) {
67 rtc::CritScope lock(&crit_sect_); 69 RTC_DCHECK(sequenced_checker_.CalledSequentially());
68 last_bitrate_bps_ = target_bitrate_bps; 70 last_bitrate_bps_ = target_bitrate_bps;
69 last_non_zero_bitrate_bps_ = 71 last_non_zero_bitrate_bps_ =
70 target_bitrate_bps > 0 ? target_bitrate_bps : last_non_zero_bitrate_bps_; 72 target_bitrate_bps > 0 ? target_bitrate_bps : last_non_zero_bitrate_bps_;
71 last_fraction_loss_ = fraction_loss; 73 last_fraction_loss_ = fraction_loss;
72 last_rtt_ = rtt; 74 last_rtt_ = rtt;
73 75
74 // Periodically log the incoming BWE. 76 // Periodically log the incoming BWE.
75 int64_t now = clock_->TimeInMilliseconds(); 77 int64_t now = clock_->TimeInMilliseconds();
76 if (now > last_bwe_log_time_ + kBweLogIntervalMs) { 78 if (now > last_bwe_log_time_ + kBweLogIntervalMs) {
77 LOG(LS_INFO) << "Current BWE " << target_bitrate_bps; 79 LOG(LS_INFO) << "Current BWE " << target_bitrate_bps;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 config.media_ratio = MediaRatio(allocated_bitrate, protection_bitrate); 112 config.media_ratio = MediaRatio(allocated_bitrate, protection_bitrate);
111 config.allocated_bitrate_bps = allocated_bitrate; 113 config.allocated_bitrate_bps = allocated_bitrate;
112 } 114 }
113 } 115 }
114 116
115 void BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, 117 void BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer,
116 uint32_t min_bitrate_bps, 118 uint32_t min_bitrate_bps,
117 uint32_t max_bitrate_bps, 119 uint32_t max_bitrate_bps,
118 uint32_t pad_up_bitrate_bps, 120 uint32_t pad_up_bitrate_bps,
119 bool enforce_min_bitrate) { 121 bool enforce_min_bitrate) {
120 rtc::CritScope lock(&crit_sect_); 122 RTC_DCHECK(sequenced_checker_.CalledSequentially());
121 auto it = FindObserverConfig(observer); 123 auto it = FindObserverConfig(observer);
122 124
123 // Update settings if the observer already exists, create a new one otherwise. 125 // Update settings if the observer already exists, create a new one otherwise.
124 if (it != bitrate_observer_configs_.end()) { 126 if (it != bitrate_observer_configs_.end()) {
125 it->min_bitrate_bps = min_bitrate_bps; 127 it->min_bitrate_bps = min_bitrate_bps;
126 it->max_bitrate_bps = max_bitrate_bps; 128 it->max_bitrate_bps = max_bitrate_bps;
127 it->pad_up_bitrate_bps = pad_up_bitrate_bps; 129 it->pad_up_bitrate_bps = pad_up_bitrate_bps;
128 it->enforce_min_bitrate = enforce_min_bitrate; 130 it->enforce_min_bitrate = enforce_min_bitrate;
129 } else { 131 } else {
130 bitrate_observer_configs_.push_back( 132 bitrate_observer_configs_.push_back(
(...skipping 17 matching lines...) Expand all
148 // Currently, an encoder is not allowed to produce frames. 150 // Currently, an encoder is not allowed to produce frames.
149 // But we still have to return the initial config bitrate + let the 151 // But we still have to return the initial config bitrate + let the
150 // observer know that it can not produce frames. 152 // observer know that it can not produce frames.
151 allocation = AllocateBitrates(last_non_zero_bitrate_bps_); 153 allocation = AllocateBitrates(last_non_zero_bitrate_bps_);
152 observer->OnBitrateUpdated(0, last_fraction_loss_, last_rtt_); 154 observer->OnBitrateUpdated(0, last_fraction_loss_, last_rtt_);
153 } 155 }
154 UpdateAllocationLimits(); 156 UpdateAllocationLimits();
155 } 157 }
156 158
157 void BitrateAllocator::UpdateAllocationLimits() { 159 void BitrateAllocator::UpdateAllocationLimits() {
160 RTC_DCHECK(sequenced_checker_.CalledSequentially());
158 uint32_t total_requested_padding_bitrate = 0; 161 uint32_t total_requested_padding_bitrate = 0;
159 uint32_t total_requested_min_bitrate = 0; 162 uint32_t total_requested_min_bitrate = 0;
160 163
161 {
162 rtc::CritScope lock(&crit_sect_);
163 for (const auto& config : bitrate_observer_configs_) { 164 for (const auto& config : bitrate_observer_configs_) {
164 if (config.enforce_min_bitrate) { 165 if (config.enforce_min_bitrate) {
165 total_requested_min_bitrate += config.min_bitrate_bps; 166 total_requested_min_bitrate += config.min_bitrate_bps;
166 } 167 }
167 total_requested_padding_bitrate += config.pad_up_bitrate_bps; 168 total_requested_padding_bitrate += config.pad_up_bitrate_bps;
168 } 169 }
169 }
170 170
171 LOG(LS_INFO) << "UpdateAllocationLimits : total_requested_min_bitrate: " 171 LOG(LS_INFO) << "UpdateAllocationLimits : total_requested_min_bitrate: "
172 << total_requested_min_bitrate 172 << total_requested_min_bitrate
173 << "bps, total_requested_padding_bitrate: " 173 << "bps, total_requested_padding_bitrate: "
174 << total_requested_padding_bitrate << "bps"; 174 << total_requested_padding_bitrate << "bps";
175 limit_observer_->OnAllocationLimitsChanged(total_requested_min_bitrate, 175 limit_observer_->OnAllocationLimitsChanged(total_requested_min_bitrate,
176 total_requested_padding_bitrate); 176 total_requested_padding_bitrate);
177 } 177 }
178 178
179 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { 179 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) {
180 { 180 RTC_DCHECK(sequenced_checker_.CalledSequentially());
181 rtc::CritScope lock(&crit_sect_); 181 auto it = FindObserverConfig(observer);
182 auto it = FindObserverConfig(observer); 182 if (it != bitrate_observer_configs_.end()) {
183 if (it != bitrate_observer_configs_.end()) { 183 bitrate_observer_configs_.erase(it);
184 bitrate_observer_configs_.erase(it);
185 } 184 }
186 } 185
187 UpdateAllocationLimits(); 186 UpdateAllocationLimits();
188 } 187 }
189 188
190 int BitrateAllocator::GetStartBitrate(BitrateAllocatorObserver* observer) { 189 int BitrateAllocator::GetStartBitrate(BitrateAllocatorObserver* observer) {
191 rtc::CritScope lock(&crit_sect_); 190 RTC_DCHECK(sequenced_checker_.CalledSequentially());
192 const auto& it = FindObserverConfig(observer); 191 const auto& it = FindObserverConfig(observer);
193 if (it == bitrate_observer_configs_.end()) { 192 if (it == bitrate_observer_configs_.end()) {
194 // This observer hasn't been added yet, just give it its fair share. 193 // This observer hasn't been added yet, just give it its fair share.
195 return last_non_zero_bitrate_bps_ / 194 return last_non_zero_bitrate_bps_ /
196 static_cast<int>((bitrate_observer_configs_.size() + 1)); 195 static_cast<int>((bitrate_observer_configs_.size() + 1));
197 } else if (it->allocated_bitrate_bps == -1) { 196 } else if (it->allocated_bitrate_bps == -1) {
198 // This observer hasn't received an allocation yet, so do the same. 197 // This observer hasn't received an allocation yet, so do the same.
199 return last_non_zero_bitrate_bps_ / 198 return last_non_zero_bitrate_bps_ /
200 static_cast<int>(bitrate_observer_configs_.size()); 199 static_cast<int>(bitrate_observer_configs_.size());
201 } else { 200 } else {
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 uint32_t extra_bitrate_per_observer = (bitrate - sum_min_bitrates) / 403 uint32_t extra_bitrate_per_observer = (bitrate - sum_min_bitrates) /
405 static_cast<uint32_t>(bitrate_observer_configs_.size()); 404 static_cast<uint32_t>(bitrate_observer_configs_.size());
406 for (const auto& observer_config : bitrate_observer_configs_) { 405 for (const auto& observer_config : bitrate_observer_configs_) {
407 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < 406 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer <
408 MinBitrateWithHysteresis(observer_config)) 407 MinBitrateWithHysteresis(observer_config))
409 return false; 408 return false;
410 } 409 }
411 return true; 410 return true;
412 } 411 }
413 } // namespace webrtc 412 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698