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 <list> | 16 #include <list> |
17 #include <map> | 17 #include <map> |
18 #include <utility> | 18 #include <utility> |
19 | 19 |
20 #include "webrtc/base/criticalsection.h" | 20 #include "webrtc/base/thread_checker.h" |
21 #include "webrtc/base/thread_annotations.h" | |
22 | 21 |
23 namespace webrtc { | 22 namespace webrtc { |
24 | 23 |
25 // Used by all send streams with adaptive bitrate, to get the currently | 24 // Used by all send streams with adaptive bitrate, to get the currently |
26 // allocated bitrate for the send stream. The current network properties are | 25 // allocated bitrate for the send stream. The current network properties are |
27 // given at the same time, to let the send stream decide about possible loss | 26 // given at the same time, to let the send stream decide about possible loss |
28 // protection. | 27 // protection. |
29 class BitrateAllocatorObserver { | 28 class BitrateAllocatorObserver { |
30 public: | 29 public: |
31 virtual void OnBitrateUpdated(uint32_t bitrate_bps, | 30 virtual void OnBitrateUpdated(uint32_t bitrate_bps, |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 uint32_t pad_up_bitrate_bps; | 101 uint32_t pad_up_bitrate_bps; |
103 bool enforce_min_bitrate; | 102 bool enforce_min_bitrate; |
104 }; | 103 }; |
105 | 104 |
106 // Calculates the minimum requested send bitrate and max padding bitrate and | 105 // Calculates the minimum requested send bitrate and max padding bitrate and |
107 // calls LimitObserver::OnAllocationLimitsChanged. | 106 // calls LimitObserver::OnAllocationLimitsChanged. |
108 void UpdateAllocationLimits(); | 107 void UpdateAllocationLimits(); |
109 | 108 |
110 typedef std::list<ObserverConfig> ObserverConfigList; | 109 typedef std::list<ObserverConfig> ObserverConfigList; |
111 ObserverConfigList::iterator FindObserverConfig( | 110 ObserverConfigList::iterator FindObserverConfig( |
112 const BitrateAllocatorObserver* observer) | 111 const BitrateAllocatorObserver* observer); |
113 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
114 | 112 |
115 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; | 113 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; |
116 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; | 114 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; |
117 | 115 |
118 ObserverAllocation AllocateBitrates(uint32_t bitrate) | 116 ObserverAllocation AllocateBitrates(uint32_t bitrate); |
119 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
120 | 117 |
121 ObserverAllocation ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 118 ObserverAllocation ZeroRateAllocation(); |
122 ObserverAllocation LowRateAllocation(uint32_t bitrate) | 119 ObserverAllocation LowRateAllocation(uint32_t bitrate); |
123 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
124 ObserverAllocation NormalRateAllocation(uint32_t bitrate, | 120 ObserverAllocation NormalRateAllocation(uint32_t bitrate, |
125 uint32_t sum_min_bitrates) | 121 uint32_t sum_min_bitrates); |
126 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
127 ObserverAllocation MaxRateAllocation(uint32_t bitrate, | 122 ObserverAllocation MaxRateAllocation(uint32_t bitrate, |
128 uint32_t sum_max_bitrates) | 123 uint32_t sum_max_bitrates); |
129 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
130 | 124 |
131 uint32_t LastAllocatedBitrate(const ObserverConfig& observer_config) | 125 uint32_t LastAllocatedBitrate(const ObserverConfig& observer_config); |
132 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
133 // The minimum bitrate required by this observer, including enable-hysteresis | 126 // The minimum bitrate required by this observer, including enable-hysteresis |
134 // if the observer is in a paused state. | 127 // if the observer is in a paused state. |
135 uint32_t MinBitrateWithHysteresis(const ObserverConfig& observer_config) | 128 uint32_t MinBitrateWithHysteresis(const ObserverConfig& observer_config); |
136 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
137 // Splits |bitrate| evenly to observers already in |allocation|. | 129 // Splits |bitrate| evenly to observers already in |allocation|. |
138 // |include_zero_allocations| decides if zero allocations should be part of | 130 // |include_zero_allocations| decides if zero allocations should be part of |
139 // the distribution or not. The allowed max bitrate is |max_multiplier| x | 131 // the distribution or not. The allowed max bitrate is |max_multiplier| x |
140 // observer max bitrate. | 132 // observer max bitrate. |
141 void DistributeBitrateEvenly(uint32_t bitrate, | 133 void DistributeBitrateEvenly(uint32_t bitrate, |
142 bool include_zero_allocations, | 134 bool include_zero_allocations, |
143 int max_multiplier, | 135 int max_multiplier, |
144 ObserverAllocation* allocation) | 136 ObserverAllocation* allocation); |
145 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 137 |
146 bool EnoughBitrateForAllObservers(uint32_t bitrate, uint32_t sum_min_bitrates) | 138 bool EnoughBitrateForAllObservers(uint32_t bitrate, |
147 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 139 uint32_t sum_min_bitrates); |
148 | 140 |
149 LimitObserver* const limit_observer_; | 141 LimitObserver* const limit_observer_; |
150 | 142 rtc::ThreadChecker thread_checker_; |
151 rtc::CriticalSection crit_sect_; | |
152 // Stored in a list to keep track of the insertion order. | 143 // Stored in a list to keep track of the insertion order. |
153 ObserverConfigList bitrate_observer_configs_ GUARDED_BY(crit_sect_); | 144 ObserverConfigList bitrate_observer_configs_; |
154 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); | 145 uint32_t last_bitrate_bps_; |
155 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(crit_sect_); | 146 uint32_t last_non_zero_bitrate_bps_; |
156 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); | 147 uint8_t last_fraction_loss_; |
157 int64_t last_rtt_ GUARDED_BY(crit_sect_); | 148 int64_t last_rtt_; |
158 ObserverAllocation last_allocation_ GUARDED_BY(crit_sect_); | 149 ObserverAllocation last_allocation_; |
159 }; | 150 }; |
160 } // namespace webrtc | 151 } // namespace webrtc |
161 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ | 152 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ |
OLD | NEW |