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 |
11 #ifndef WEBRTC_CALL_BITRATE_ALLOCATOR_H_ | 11 #ifndef WEBRTC_CALL_BITRATE_ALLOCATOR_H_ |
12 #define WEBRTC_CALL_BITRATE_ALLOCATOR_H_ | 12 #define WEBRTC_CALL_BITRATE_ALLOCATOR_H_ |
13 | 13 |
14 #include <stdint.h> | 14 #include <stdint.h> |
15 | 15 |
16 #include <map> | 16 #include <map> |
17 #include <utility> | 17 #include <utility> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "webrtc/base/sequenced_task_checker.h" | 20 #include "webrtc/base/criticalsection.h" |
| 21 #include "webrtc/base/thread_annotations.h" |
21 | 22 |
22 namespace webrtc { | 23 namespace webrtc { |
23 | 24 |
24 class Clock; | 25 class Clock; |
25 | 26 |
26 // Used by all send streams with adaptive bitrate, to get the currently | 27 // Used by all send streams with adaptive bitrate, to get the currently |
27 // allocated bitrate for the send stream. The current network properties are | 28 // allocated bitrate for the send stream. The current network properties are |
28 // given at the same time, to let the send stream decide about possible loss | 29 // given at the same time, to let the send stream decide about possible loss |
29 // protection. | 30 // protection. |
30 class BitrateAllocatorObserver { | 31 class BitrateAllocatorObserver { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 int64_t allocated_bitrate_bps; | 114 int64_t allocated_bitrate_bps; |
114 double media_ratio; // Part of the total bitrate used for media [0.0, 1.0]. | 115 double media_ratio; // Part of the total bitrate used for media [0.0, 1.0]. |
115 }; | 116 }; |
116 | 117 |
117 // Calculates the minimum requested send bitrate and max padding bitrate and | 118 // Calculates the minimum requested send bitrate and max padding bitrate and |
118 // calls LimitObserver::OnAllocationLimitsChanged. | 119 // calls LimitObserver::OnAllocationLimitsChanged. |
119 void UpdateAllocationLimits(); | 120 void UpdateAllocationLimits(); |
120 | 121 |
121 typedef std::vector<ObserverConfig> ObserverConfigs; | 122 typedef std::vector<ObserverConfig> ObserverConfigs; |
122 ObserverConfigs::iterator FindObserverConfig( | 123 ObserverConfigs::iterator FindObserverConfig( |
123 const BitrateAllocatorObserver* observer); | 124 const BitrateAllocatorObserver* observer) |
| 125 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
124 | 126 |
125 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; | 127 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; |
126 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; | 128 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; |
127 | 129 |
128 ObserverAllocation AllocateBitrates(uint32_t bitrate); | 130 ObserverAllocation AllocateBitrates(uint32_t bitrate) |
| 131 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
129 | 132 |
130 ObserverAllocation ZeroRateAllocation(); | 133 ObserverAllocation ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
131 ObserverAllocation LowRateAllocation(uint32_t bitrate); | 134 ObserverAllocation LowRateAllocation(uint32_t bitrate) |
| 135 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
132 ObserverAllocation NormalRateAllocation(uint32_t bitrate, | 136 ObserverAllocation NormalRateAllocation(uint32_t bitrate, |
133 uint32_t sum_min_bitrates); | 137 uint32_t sum_min_bitrates) |
| 138 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
134 ObserverAllocation MaxRateAllocation(uint32_t bitrate, | 139 ObserverAllocation MaxRateAllocation(uint32_t bitrate, |
135 uint32_t sum_max_bitrates); | 140 uint32_t sum_max_bitrates) |
| 141 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
136 | 142 |
137 uint32_t LastAllocatedBitrate(const ObserverConfig& observer_config); | 143 uint32_t LastAllocatedBitrate(const ObserverConfig& observer_config) |
| 144 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
138 // The minimum bitrate required by this observer, including enable-hysteresis | 145 // The minimum bitrate required by this observer, including enable-hysteresis |
139 // if the observer is in a paused state. | 146 // if the observer is in a paused state. |
140 uint32_t MinBitrateWithHysteresis(const ObserverConfig& observer_config); | 147 uint32_t MinBitrateWithHysteresis(const ObserverConfig& observer_config) |
| 148 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
141 // Splits |bitrate| evenly to observers already in |allocation|. | 149 // Splits |bitrate| evenly to observers already in |allocation|. |
142 // |include_zero_allocations| decides if zero allocations should be part of | 150 // |include_zero_allocations| decides if zero allocations should be part of |
143 // the distribution or not. The allowed max bitrate is |max_multiplier| x | 151 // the distribution or not. The allowed max bitrate is |max_multiplier| x |
144 // observer max bitrate. | 152 // observer max bitrate. |
145 void DistributeBitrateEvenly(uint32_t bitrate, | 153 void DistributeBitrateEvenly(uint32_t bitrate, |
146 bool include_zero_allocations, | 154 bool include_zero_allocations, |
147 int max_multiplier, | 155 int max_multiplier, |
148 ObserverAllocation* allocation); | 156 ObserverAllocation* allocation) |
149 bool EnoughBitrateForAllObservers(uint32_t bitrate, | 157 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
150 uint32_t sum_min_bitrates); | 158 bool EnoughBitrateForAllObservers(uint32_t bitrate, uint32_t sum_min_bitrates) |
| 159 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
151 | 160 |
152 rtc::SequencedTaskChecker sequenced_checker_; | 161 LimitObserver* const limit_observer_; |
153 LimitObserver* const limit_observer_ GUARDED_BY(&sequenced_checker_); | 162 |
| 163 rtc::CriticalSection crit_sect_; |
154 // Stored in a list to keep track of the insertion order. | 164 // Stored in a list to keep track of the insertion order. |
155 ObserverConfigs bitrate_observer_configs_ GUARDED_BY(&sequenced_checker_); | 165 ObserverConfigs bitrate_observer_configs_ GUARDED_BY(crit_sect_); |
156 uint32_t last_bitrate_bps_ GUARDED_BY(&sequenced_checker_); | 166 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); |
157 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(&sequenced_checker_); | 167 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(crit_sect_); |
158 uint8_t last_fraction_loss_ GUARDED_BY(&sequenced_checker_); | 168 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); |
159 int64_t last_rtt_ GUARDED_BY(&sequenced_checker_); | 169 int64_t last_rtt_ GUARDED_BY(crit_sect_); |
160 // Number of mute events based on too low BWE, not network up/down. | 170 // Number of mute events based on too low BWE, not network up/down. |
161 int num_pause_events_ GUARDED_BY(&sequenced_checker_); | 171 int num_pause_events_ GUARDED_BY(crit_sect_); |
162 Clock* const clock_ GUARDED_BY(&sequenced_checker_); | 172 Clock* const clock_; |
163 int64_t last_bwe_log_time_ GUARDED_BY(&sequenced_checker_); | 173 int64_t last_bwe_log_time_; |
164 }; | 174 }; |
165 } // namespace webrtc | 175 } // namespace webrtc |
166 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ | 176 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ |
OLD | NEW |