| 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 <set> |
| 18 #include <string> |
| 17 #include <utility> | 19 #include <utility> |
| 18 #include <vector> | 20 #include <vector> |
| 19 #include <string> | |
| 20 | 21 |
| 22 #include "webrtc/rtc_base/bitrateallocationstrategy.h" |
| 23 #include "webrtc/rtc_base/scoped_ref_ptr.h" |
| 21 #include "webrtc/rtc_base/sequenced_task_checker.h" | 24 #include "webrtc/rtc_base/sequenced_task_checker.h" |
| 22 | 25 |
| 23 namespace webrtc { | 26 namespace webrtc { |
| 24 | 27 |
| 25 class Clock; | 28 class Clock; |
| 26 | 29 |
| 27 // Used by all send streams with adaptive bitrate, to get the currently | 30 // Used by all send streams with adaptive bitrate, to get the currently |
| 28 // allocated bitrate for the send stream. The current network properties are | 31 // allocated bitrate for the send stream. The current network properties are |
| 29 // given at the same time, to let the send stream decide about possible loss | 32 // given at the same time, to let the send stream decide about possible loss |
| 30 // protection. | 33 // protection. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 std::string track_id); | 90 std::string track_id); |
| 88 | 91 |
| 89 // Removes a previously added observer, but will not trigger a new bitrate | 92 // Removes a previously added observer, but will not trigger a new bitrate |
| 90 // allocation. | 93 // allocation. |
| 91 void RemoveObserver(BitrateAllocatorObserver* observer); | 94 void RemoveObserver(BitrateAllocatorObserver* observer); |
| 92 | 95 |
| 93 // Returns initial bitrate allocated for |observer|. If |observer| is not in | 96 // Returns initial bitrate allocated for |observer|. If |observer| is not in |
| 94 // the list of added observers, a best guess is returned. | 97 // the list of added observers, a best guess is returned. |
| 95 int GetStartBitrate(BitrateAllocatorObserver* observer); | 98 int GetStartBitrate(BitrateAllocatorObserver* observer); |
| 96 | 99 |
| 100 // Sets external allocation strategy. If strategy is not set default WEBRTC |
| 101 // allocation mechanism will be used. The strategy may be changed during call. |
| 102 // Setting NULL value will restore default WEBRTC allocation strategy. |
| 103 void SetBitrateAllocationStrategy( |
| 104 rtc::scoped_refptr<rtc::BitrateAllocationStrategy> |
| 105 bitrate_allocation_strategy); |
| 106 |
| 97 private: | 107 private: |
| 98 // Note: All bitrates for member variables and methods are in bps. | 108 // Note: All bitrates for member variables and methods are in bps. |
| 99 struct ObserverConfig { | 109 struct ObserverConfig : rtc::BitrateAllocationStrategy::TrackConfig { |
| 100 ObserverConfig(BitrateAllocatorObserver* observer, | 110 ObserverConfig(BitrateAllocatorObserver* observer, |
| 101 uint32_t min_bitrate_bps, | 111 uint32_t min_bitrate_bps, |
| 102 uint32_t max_bitrate_bps, | 112 uint32_t max_bitrate_bps, |
| 103 uint32_t pad_up_bitrate_bps, | 113 uint32_t pad_up_bitrate_bps, |
| 104 bool enforce_min_bitrate, | 114 bool enforce_min_bitrate, |
| 105 std::string track_id) | 115 std::string track_id) |
| 106 : observer(observer), | 116 : TrackConfig(min_bitrate_bps, |
| 107 min_bitrate_bps(min_bitrate_bps), | 117 max_bitrate_bps, |
| 108 max_bitrate_bps(max_bitrate_bps), | 118 enforce_min_bitrate, |
| 119 track_id), |
| 120 observer(observer), |
| 109 pad_up_bitrate_bps(pad_up_bitrate_bps), | 121 pad_up_bitrate_bps(pad_up_bitrate_bps), |
| 110 enforce_min_bitrate(enforce_min_bitrate), | |
| 111 allocated_bitrate_bps(-1), | 122 allocated_bitrate_bps(-1), |
| 112 media_ratio(1.0), | 123 media_ratio(1.0) {} |
| 113 track_id(track_id) {} | |
| 114 | 124 |
| 115 BitrateAllocatorObserver* observer; | 125 BitrateAllocatorObserver* observer; |
| 116 uint32_t min_bitrate_bps; | |
| 117 uint32_t max_bitrate_bps; | |
| 118 uint32_t pad_up_bitrate_bps; | 126 uint32_t pad_up_bitrate_bps; |
| 119 bool enforce_min_bitrate; | |
| 120 int64_t allocated_bitrate_bps; | 127 int64_t allocated_bitrate_bps; |
| 121 double media_ratio; // Part of the total bitrate used for media [0.0, 1.0]. | 128 double media_ratio; // Part of the total bitrate used for media [0.0, 1.0]. |
| 122 std::string track_id; | |
| 123 }; | 129 }; |
| 124 | 130 |
| 125 // Calculates the minimum requested send bitrate and max padding bitrate and | 131 // Calculates the minimum requested send bitrate and max padding bitrate and |
| 126 // calls LimitObserver::OnAllocationLimitsChanged. | 132 // calls LimitObserver::OnAllocationLimitsChanged. |
| 127 void UpdateAllocationLimits(); | 133 void UpdateAllocationLimits(); |
| 128 | 134 |
| 129 typedef std::vector<ObserverConfig> ObserverConfigs; | 135 rtc::BitrateAllocationStrategy::TrackConfigs::iterator FindObserverConfig( |
| 130 ObserverConfigs::iterator FindObserverConfig( | |
| 131 const BitrateAllocatorObserver* observer); | 136 const BitrateAllocatorObserver* observer); |
| 132 | 137 |
| 133 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; | 138 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; |
| 134 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; | 139 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; |
| 135 | 140 |
| 136 ObserverAllocation AllocateBitrates(uint32_t bitrate); | 141 ObserverAllocation AllocateBitrates(uint32_t bitrate); |
| 137 | 142 |
| 138 ObserverAllocation ZeroRateAllocation(); | 143 ObserverAllocation ZeroRateAllocation(); |
| 139 ObserverAllocation LowRateAllocation(uint32_t bitrate); | 144 ObserverAllocation LowRateAllocation(uint32_t bitrate); |
| 140 ObserverAllocation NormalRateAllocation(uint32_t bitrate, | 145 ObserverAllocation NormalRateAllocation(uint32_t bitrate, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 153 void DistributeBitrateEvenly(uint32_t bitrate, | 158 void DistributeBitrateEvenly(uint32_t bitrate, |
| 154 bool include_zero_allocations, | 159 bool include_zero_allocations, |
| 155 int max_multiplier, | 160 int max_multiplier, |
| 156 ObserverAllocation* allocation); | 161 ObserverAllocation* allocation); |
| 157 bool EnoughBitrateForAllObservers(uint32_t bitrate, | 162 bool EnoughBitrateForAllObservers(uint32_t bitrate, |
| 158 uint32_t sum_min_bitrates); | 163 uint32_t sum_min_bitrates); |
| 159 | 164 |
| 160 rtc::SequencedTaskChecker sequenced_checker_; | 165 rtc::SequencedTaskChecker sequenced_checker_; |
| 161 LimitObserver* const limit_observer_ GUARDED_BY(&sequenced_checker_); | 166 LimitObserver* const limit_observer_ GUARDED_BY(&sequenced_checker_); |
| 162 // Stored in a list to keep track of the insertion order. | 167 // Stored in a list to keep track of the insertion order. |
| 163 ObserverConfigs bitrate_observer_configs_ GUARDED_BY(&sequenced_checker_); | 168 rtc::BitrateAllocationStrategy::TrackConfigs bitrate_observer_configs_ |
| 169 GUARDED_BY(&sequenced_checker_); |
| 170 std::set<std::string> track_ids GUARDED_BY(&sequenced_checker_); |
| 164 uint32_t last_bitrate_bps_ GUARDED_BY(&sequenced_checker_); | 171 uint32_t last_bitrate_bps_ GUARDED_BY(&sequenced_checker_); |
| 165 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(&sequenced_checker_); | 172 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(&sequenced_checker_); |
| 166 uint8_t last_fraction_loss_ GUARDED_BY(&sequenced_checker_); | 173 uint8_t last_fraction_loss_ GUARDED_BY(&sequenced_checker_); |
| 167 int64_t last_rtt_ GUARDED_BY(&sequenced_checker_); | 174 int64_t last_rtt_ GUARDED_BY(&sequenced_checker_); |
| 168 int64_t last_bwe_period_ms_ GUARDED_BY(&sequenced_checker_); | 175 int64_t last_bwe_period_ms_ GUARDED_BY(&sequenced_checker_); |
| 169 // Number of mute events based on too low BWE, not network up/down. | 176 // Number of mute events based on too low BWE, not network up/down. |
| 170 int num_pause_events_ GUARDED_BY(&sequenced_checker_); | 177 int num_pause_events_ GUARDED_BY(&sequenced_checker_); |
| 171 Clock* const clock_ GUARDED_BY(&sequenced_checker_); | 178 Clock* const clock_ GUARDED_BY(&sequenced_checker_); |
| 172 int64_t last_bwe_log_time_ GUARDED_BY(&sequenced_checker_); | 179 int64_t last_bwe_log_time_ GUARDED_BY(&sequenced_checker_); |
| 173 uint32_t total_requested_padding_bitrate_ GUARDED_BY(&sequenced_checker_); | 180 uint32_t total_requested_padding_bitrate_ GUARDED_BY(&sequenced_checker_); |
| 174 uint32_t total_requested_min_bitrate_ GUARDED_BY(&sequenced_checker_); | 181 uint32_t total_requested_min_bitrate_ GUARDED_BY(&sequenced_checker_); |
| 182 rtc::scoped_refptr<rtc::BitrateAllocationStrategy> |
| 183 bitrate_allocation_strategy_ GUARDED_BY(&sequenced_checker_); |
| 175 }; | 184 }; |
| 176 } // namespace webrtc | 185 } // namespace webrtc |
| 177 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ | 186 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ |
| OLD | NEW |