Chromium Code Reviews

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

Issue 1917793002: Remove SendPacer from ViEEncoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebased Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
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 13 matching lines...)
24 const int kDefaultBitrateBps = 300000; 24 const int kDefaultBitrateBps = 300000;
25 25
26 BitrateAllocator::BitrateAllocator() 26 BitrateAllocator::BitrateAllocator()
27 : bitrate_observers_(), 27 : bitrate_observers_(),
28 bitrate_observers_modified_(false), 28 bitrate_observers_modified_(false),
29 enforce_min_bitrate_(true), 29 enforce_min_bitrate_(true),
30 last_bitrate_bps_(kDefaultBitrateBps), 30 last_bitrate_bps_(kDefaultBitrateBps),
31 last_fraction_loss_(0), 31 last_fraction_loss_(0),
32 last_rtt_(0) {} 32 last_rtt_(0) {}
33 33
34 uint32_t BitrateAllocator::OnNetworkChanged(uint32_t bitrate, 34 void BitrateAllocator::OnNetworkChanged(uint32_t bitrate,
stefan-webrtc 2016/04/29 10:48:38 Is there a point in changing this method?
perkj_webrtc 2016/05/02 11:29:09 Reverting as discussed.
35 uint8_t fraction_loss, 35 uint8_t fraction_loss,
36 int64_t rtt) { 36 int64_t rtt) {
37 rtc::CritScope lock(&crit_sect_); 37 rtc::CritScope lock(&crit_sect_);
38 last_bitrate_bps_ = bitrate; 38 last_bitrate_bps_ = bitrate;
39 last_fraction_loss_ = fraction_loss; 39 last_fraction_loss_ = fraction_loss;
40 last_rtt_ = rtt; 40 last_rtt_ = rtt;
41 uint32_t allocated_bitrate_bps = 0;
42 ObserverBitrateMap allocation = AllocateBitrates(); 41 ObserverBitrateMap allocation = AllocateBitrates();
43 for (const auto& kv : allocation) { 42 for (const auto& kv : allocation) {
44 kv.first->OnBitrateUpdated(kv.second, last_fraction_loss_, last_rtt_); 43 kv.first->OnBitrateUpdated(kv.second, last_fraction_loss_, last_rtt_);
45 allocated_bitrate_bps += kv.second;
46 } 44 }
47 return allocated_bitrate_bps;
48 } 45 }
49 46
50 BitrateAllocator::ObserverBitrateMap BitrateAllocator::AllocateBitrates() { 47 BitrateAllocator::ObserverBitrateMap BitrateAllocator::AllocateBitrates() {
51 if (bitrate_observers_.empty()) 48 if (bitrate_observers_.empty())
52 return ObserverBitrateMap(); 49 return ObserverBitrateMap();
53 50
54 uint32_t sum_min_bitrates = 0; 51 uint32_t sum_min_bitrates = 0;
55 for (const auto& observer : bitrate_observers_) 52 for (const auto& observer : bitrate_observers_)
56 sum_min_bitrates += observer.second.min_bitrate; 53 sum_min_bitrates += observer.second.min_bitrate;
57 if (last_bitrate_bps_ <= sum_min_bitrates) 54 if (last_bitrate_bps_ == 0)
55 return ZeroRateAllocation();
56 else if (last_bitrate_bps_ <= sum_min_bitrates)
58 return LowRateAllocation(last_bitrate_bps_); 57 return LowRateAllocation(last_bitrate_bps_);
59 else 58 else
60 return NormalRateAllocation(last_bitrate_bps_, sum_min_bitrates); 59 return NormalRateAllocation(last_bitrate_bps_, sum_min_bitrates);
61 } 60 }
62 61
63 int BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, 62 int BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer,
64 uint32_t min_bitrate_bps, 63 uint32_t min_bitrate_bps,
65 uint32_t max_bitrate_bps) { 64 uint32_t max_bitrate_bps) {
66 rtc::CritScope lock(&crit_sect_); 65 rtc::CritScope lock(&crit_sect_);
67 66
(...skipping 29 matching lines...)
97 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { 96 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) {
98 rtc::CritScope lock(&crit_sect_); 97 rtc::CritScope lock(&crit_sect_);
99 BitrateObserverConfList::iterator it = 98 BitrateObserverConfList::iterator it =
100 FindObserverConfigurationPair(observer); 99 FindObserverConfigurationPair(observer);
101 if (it != bitrate_observers_.end()) { 100 if (it != bitrate_observers_.end()) {
102 bitrate_observers_.erase(it); 101 bitrate_observers_.erase(it);
103 bitrate_observers_modified_ = true; 102 bitrate_observers_modified_ = true;
104 } 103 }
105 } 104 }
106 105
107 void BitrateAllocator::GetMinMaxBitrateSumBps(int* min_bitrate_sum_bps, 106 int BitrateAllocator::GetMinSendBitrate() const {
108 int* max_bitrate_sum_bps) const { 107 rtc::CritScope lock(&crit_sect_);
109 *min_bitrate_sum_bps = 0; 108 int min_bitrate = 0;
110 *max_bitrate_sum_bps = 0;
111 109
112 rtc::CritScope lock(&crit_sect_); 110 if (!enforce_min_bitrate_)
111 return 0;
112
113 for (const auto& observer : bitrate_observers_) { 113 for (const auto& observer : bitrate_observers_) {
114 *min_bitrate_sum_bps += observer.second.min_bitrate; 114 min_bitrate += observer.second.min_bitrate;
115 *max_bitrate_sum_bps += observer.second.max_bitrate;
116 } 115 }
116 return min_bitrate;
117 } 117 }
118 118
119 BitrateAllocator::BitrateObserverConfList::iterator 119 BitrateAllocator::BitrateObserverConfList::iterator
120 BitrateAllocator::FindObserverConfigurationPair( 120 BitrateAllocator::FindObserverConfigurationPair(
121 const BitrateAllocatorObserver* observer) { 121 const BitrateAllocatorObserver* observer) {
122 for (auto it = bitrate_observers_.begin(); it != bitrate_observers_.end(); 122 for (auto it = bitrate_observers_.begin(); it != bitrate_observers_.end();
123 ++it) { 123 ++it) {
124 if (it->first == observer) 124 if (it->first == observer)
125 return it; 125 return it;
126 } 126 }
(...skipping 36 matching lines...)
163 } else { 163 } else {
164 allocation[max_it->second.observer] = observer_allowance; 164 allocation[max_it->second.observer] = observer_allowance;
165 } 165 }
166 list_max_bitrates.erase(max_it); 166 list_max_bitrates.erase(max_it);
167 // Prepare next iteration. 167 // Prepare next iteration.
168 max_it = list_max_bitrates.begin(); 168 max_it = list_max_bitrates.begin();
169 } 169 }
170 return allocation; 170 return allocation;
171 } 171 }
172 172
173 BitrateAllocator::ObserverBitrateMap BitrateAllocator::ZeroRateAllocation() {
174 ObserverBitrateMap allocation;
175 // Zero bitrate to all observers.
176 for (const auto& observer : bitrate_observers_)
177 allocation[observer.first] = 0;
178 return allocation;
179 }
180
173 BitrateAllocator::ObserverBitrateMap BitrateAllocator::LowRateAllocation( 181 BitrateAllocator::ObserverBitrateMap BitrateAllocator::LowRateAllocation(
174 uint32_t bitrate) { 182 uint32_t bitrate) {
175 ObserverBitrateMap allocation; 183 ObserverBitrateMap allocation;
176 if (enforce_min_bitrate_) { 184 if (enforce_min_bitrate_) {
177 // Min bitrate to all observers. 185 // Min bitrate to all observers.
178 for (const auto& observer : bitrate_observers_) 186 for (const auto& observer : bitrate_observers_)
179 allocation[observer.first] = observer.second.min_bitrate; 187 allocation[observer.first] = observer.second.min_bitrate;
180 } else { 188 } else {
181 // Allocate up to |min_bitrate| to one observer at a time, until 189 // Allocate up to |min_bitrate| to one observer at a time, until
182 // |bitrate| is depleted. 190 // |bitrate| is depleted.
183 uint32_t remainder = bitrate; 191 uint32_t remainder = bitrate;
184 for (const auto& observer : bitrate_observers_) { 192 for (const auto& observer : bitrate_observers_) {
185 uint32_t allocated_bitrate = 193 uint32_t allocated_bitrate =
186 std::min(remainder, observer.second.min_bitrate); 194 std::min(remainder, observer.second.min_bitrate);
187 allocation[observer.first] = allocated_bitrate; 195 allocation[observer.first] = allocated_bitrate;
188 remainder -= allocated_bitrate; 196 remainder -= allocated_bitrate;
189 } 197 }
190 } 198 }
191 return allocation; 199 return allocation;
192 } 200 }
193 } // namespace webrtc 201 } // namespace webrtc
OLDNEW

Powered by Google App Engine