OLD | NEW |
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 23 matching lines...) Expand all Loading... |
34 uint32_t BitrateAllocator::OnNetworkChanged(uint32_t bitrate, | 34 uint32_t BitrateAllocator::OnNetworkChanged(uint32_t bitrate, |
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; | 41 uint32_t allocated_bitrate_bps = 0; |
42 ObserverBitrateMap allocation = AllocateBitrates(); | 42 ObserverBitrateMap allocation = AllocateBitrates(); |
43 for (const auto& kv : allocation) { | 43 for (const auto& kv : allocation) { |
44 kv.first->OnNetworkChanged(kv.second, last_fraction_loss_, last_rtt_); | 44 kv.first->OnBitrateUpdated(kv.second, last_fraction_loss_, last_rtt_); |
45 allocated_bitrate_bps += kv.second; | 45 allocated_bitrate_bps += kv.second; |
46 } | 46 } |
47 return allocated_bitrate_bps; | 47 return allocated_bitrate_bps; |
48 } | 48 } |
49 | 49 |
50 BitrateAllocator::ObserverBitrateMap BitrateAllocator::AllocateBitrates() { | 50 BitrateAllocator::ObserverBitrateMap BitrateAllocator::AllocateBitrates() { |
51 if (bitrate_observers_.empty()) | 51 if (bitrate_observers_.empty()) |
52 return ObserverBitrateMap(); | 52 return ObserverBitrateMap(); |
53 | 53 |
54 uint32_t sum_min_bitrates = 0; | 54 uint32_t sum_min_bitrates = 0; |
55 for (const auto& observer : bitrate_observers_) | 55 for (const auto& observer : bitrate_observers_) |
56 sum_min_bitrates += observer.second.min_bitrate; | 56 sum_min_bitrates += observer.second.min_bitrate; |
57 if (last_bitrate_bps_ <= sum_min_bitrates) | 57 if (last_bitrate_bps_ <= sum_min_bitrates) |
58 return LowRateAllocation(last_bitrate_bps_); | 58 return LowRateAllocation(last_bitrate_bps_); |
59 else | 59 else |
60 return NormalRateAllocation(last_bitrate_bps_, sum_min_bitrates); | 60 return NormalRateAllocation(last_bitrate_bps_, sum_min_bitrates); |
61 } | 61 } |
62 | 62 |
63 int BitrateAllocator::AddBitrateObserver(BitrateObserver* observer, | 63 int BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, |
64 uint32_t min_bitrate_bps, | 64 uint32_t min_bitrate_bps, |
65 uint32_t max_bitrate_bps) { | 65 uint32_t max_bitrate_bps) { |
66 rtc::CritScope lock(&crit_sect_); | 66 rtc::CritScope lock(&crit_sect_); |
67 | 67 |
68 BitrateObserverConfList::iterator it = | 68 BitrateObserverConfList::iterator it = |
69 FindObserverConfigurationPair(observer); | 69 FindObserverConfigurationPair(observer); |
70 | 70 |
71 // Allow the max bitrate to be exceeded for FEC and retransmissions. | 71 // Allow the max bitrate to be exceeded for FEC and retransmissions. |
72 // TODO(holmer): We have to get rid of this hack as it makes it difficult to | 72 // TODO(holmer): We have to get rid of this hack as it makes it difficult to |
73 // properly allocate bitrate. The allocator should instead distribute any | 73 // properly allocate bitrate. The allocator should instead distribute any |
74 // extra bitrate after all streams have maxed out. | 74 // extra bitrate after all streams have maxed out. |
75 max_bitrate_bps *= kTransmissionMaxBitrateMultiplier; | 75 max_bitrate_bps *= kTransmissionMaxBitrateMultiplier; |
76 if (it != bitrate_observers_.end()) { | 76 if (it != bitrate_observers_.end()) { |
77 // Update current configuration. | 77 // Update current configuration. |
78 it->second.min_bitrate = min_bitrate_bps; | 78 it->second.min_bitrate = min_bitrate_bps; |
79 it->second.max_bitrate = max_bitrate_bps; | 79 it->second.max_bitrate = max_bitrate_bps; |
80 } else { | 80 } else { |
81 // Add new settings. | 81 // Add new settings. |
82 bitrate_observers_.push_back(BitrateObserverConfiguration( | 82 bitrate_observers_.push_back(BitrateObserverConfiguration( |
83 observer, BitrateConfiguration(min_bitrate_bps, max_bitrate_bps))); | 83 observer, BitrateConfiguration(min_bitrate_bps, max_bitrate_bps))); |
84 bitrate_observers_modified_ = true; | 84 bitrate_observers_modified_ = true; |
85 } | 85 } |
86 | 86 |
87 ObserverBitrateMap allocation = AllocateBitrates(); | 87 ObserverBitrateMap allocation = AllocateBitrates(); |
88 int new_observer_bitrate_bps = 0; | 88 int new_observer_bitrate_bps = 0; |
89 for (auto& kv : allocation) { | 89 for (auto& kv : allocation) { |
90 kv.first->OnNetworkChanged(kv.second, last_fraction_loss_, last_rtt_); | 90 kv.first->OnBitrateUpdated(kv.second, last_fraction_loss_, last_rtt_); |
91 if (kv.first == observer) | 91 if (kv.first == observer) |
92 new_observer_bitrate_bps = kv.second; | 92 new_observer_bitrate_bps = kv.second; |
93 } | 93 } |
94 return new_observer_bitrate_bps; | 94 return new_observer_bitrate_bps; |
95 } | 95 } |
96 | 96 |
97 void BitrateAllocator::RemoveBitrateObserver(BitrateObserver* observer) { | 97 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { |
98 rtc::CritScope lock(&crit_sect_); | 98 rtc::CritScope lock(&crit_sect_); |
99 BitrateObserverConfList::iterator it = | 99 BitrateObserverConfList::iterator it = |
100 FindObserverConfigurationPair(observer); | 100 FindObserverConfigurationPair(observer); |
101 if (it != bitrate_observers_.end()) { | 101 if (it != bitrate_observers_.end()) { |
102 bitrate_observers_.erase(it); | 102 bitrate_observers_.erase(it); |
103 bitrate_observers_modified_ = true; | 103 bitrate_observers_modified_ = true; |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 void BitrateAllocator::GetMinMaxBitrateSumBps(int* min_bitrate_sum_bps, | 107 void BitrateAllocator::GetMinMaxBitrateSumBps(int* min_bitrate_sum_bps, |
108 int* max_bitrate_sum_bps) const { | 108 int* max_bitrate_sum_bps) const { |
109 *min_bitrate_sum_bps = 0; | 109 *min_bitrate_sum_bps = 0; |
110 *max_bitrate_sum_bps = 0; | 110 *max_bitrate_sum_bps = 0; |
111 | 111 |
112 rtc::CritScope lock(&crit_sect_); | 112 rtc::CritScope lock(&crit_sect_); |
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_sum_bps += observer.second.min_bitrate; |
115 *max_bitrate_sum_bps += observer.second.max_bitrate; | 115 *max_bitrate_sum_bps += observer.second.max_bitrate; |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 BitrateAllocator::BitrateObserverConfList::iterator | 119 BitrateAllocator::BitrateObserverConfList::iterator |
120 BitrateAllocator::FindObserverConfigurationPair( | 120 BitrateAllocator::FindObserverConfigurationPair( |
121 const BitrateObserver* 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 } |
127 return bitrate_observers_.end(); | 127 return bitrate_observers_.end(); |
128 } | 128 } |
129 | 129 |
130 void BitrateAllocator::EnforceMinBitrate(bool enforce_min_bitrate) { | 130 void BitrateAllocator::EnforceMinBitrate(bool enforce_min_bitrate) { |
131 rtc::CritScope lock(&crit_sect_); | 131 rtc::CritScope lock(&crit_sect_); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 for (const auto& observer : bitrate_observers_) { | 184 for (const auto& observer : bitrate_observers_) { |
185 uint32_t allocated_bitrate = | 185 uint32_t allocated_bitrate = |
186 std::min(remainder, observer.second.min_bitrate); | 186 std::min(remainder, observer.second.min_bitrate); |
187 allocation[observer.first] = allocated_bitrate; | 187 allocation[observer.first] = allocated_bitrate; |
188 remainder -= allocated_bitrate; | 188 remainder -= allocated_bitrate; |
189 } | 189 } |
190 } | 190 } |
191 return allocation; | 191 return allocation; |
192 } | 192 } |
193 } // namespace webrtc | 193 } // namespace webrtc |
OLD | NEW |