| 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 24 matching lines...) Expand all Loading... |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 // Usage: this class will register multiple RtcpBitrateObserver's one at each | 37 // Usage: this class will register multiple RtcpBitrateObserver's one at each |
| 38 // RTCP module. It will aggregate the results and run one bandwidth estimation | 38 // RTCP module. It will aggregate the results and run one bandwidth estimation |
| 39 // and push the result to the encoders via BitrateAllocatorObserver(s). | 39 // and push the result to the encoders via BitrateAllocatorObserver(s). |
| 40 class BitrateAllocator { | 40 class BitrateAllocator { |
| 41 public: | 41 public: |
| 42 BitrateAllocator(); | 42 BitrateAllocator(); |
| 43 | 43 |
| 44 // Allocate target_bitrate across the registered BitrateAllocatorObservers. | 44 // Allocate target_bitrate across the registered BitrateAllocatorObservers. |
| 45 // Returns actual bitrate allocated (might be higher than target_bitrate if | 45 void OnNetworkChanged(uint32_t target_bitrate, |
| 46 // for instance EnforceMinBitrate() is enabled. | 46 uint8_t fraction_loss, |
| 47 uint32_t OnNetworkChanged(uint32_t target_bitrate, | 47 int64_t rtt); |
| 48 uint8_t fraction_loss, | |
| 49 int64_t rtt); | |
| 50 | 48 |
| 51 // Set the start and max send bitrate used by the bandwidth management. | 49 // Set the start and max send bitrate used by the bandwidth management. |
| 52 // | 50 // |
| 53 // |observer| updates bitrates if already in use. | 51 // |observer| updates bitrates if already in use. |
| 54 // |min_bitrate_bps| = 0 equals no min bitrate. | 52 // |min_bitrate_bps| = 0 equals no min bitrate. |
| 55 // |max_bitrate_bps| = 0 equals no max bitrate. | 53 // |max_bitrate_bps| = 0 equals no max bitrate. |
| 56 // Returns bitrate allocated for the bitrate observer. | 54 // Returns bitrate allocated for the bitrate observer. |
| 57 int AddObserver(BitrateAllocatorObserver* observer, | 55 int AddObserver(BitrateAllocatorObserver* observer, |
| 58 uint32_t min_bitrate_bps, | 56 uint32_t min_bitrate_bps, |
| 59 uint32_t max_bitrate_bps); | 57 uint32_t max_bitrate_bps); |
| 60 | 58 |
| 61 void RemoveObserver(BitrateAllocatorObserver* observer); | 59 void RemoveObserver(BitrateAllocatorObserver* observer); |
| 62 | 60 |
| 63 void GetMinMaxBitrateSumBps(int* min_bitrate_sum_bps, | |
| 64 int* max_bitrate_sum_bps) const; | |
| 65 | |
| 66 // This method controls the behavior when the available bitrate is lower than | 61 // This method controls the behavior when the available bitrate is lower than |
| 67 // the minimum bitrate, or the sum of minimum bitrates. | 62 // the minimum bitrate, or the sum of minimum bitrates. |
| 68 // When true, the bitrate will never be set lower than the minimum bitrate(s). | 63 // When true, the bitrate will never be set lower than the minimum bitrate(s). |
| 69 // When false, the bitrate observers will be allocated rates up to their | 64 // When false, the bitrate observers will be allocated rates up to their |
| 70 // respective minimum bitrate, satisfying one observer after the other. | 65 // respective minimum bitrate, satisfying one observer after the other. |
| 71 void EnforceMinBitrate(bool enforce_min_bitrate); | 66 void EnforceMinBitrate(bool enforce_min_bitrate); |
| 72 | 67 |
| 68 // Returns the minimum send bitrate. Zero if EnforceMinBitrate(false) |
| 69 // has been called. |
| 70 int GetMinSendBitrate() const; |
| 71 |
| 73 private: | 72 private: |
| 74 struct BitrateConfiguration { | 73 struct BitrateConfiguration { |
| 75 BitrateConfiguration(uint32_t min_bitrate, uint32_t max_bitrate) | 74 BitrateConfiguration(uint32_t min_bitrate, uint32_t max_bitrate) |
| 76 : min_bitrate(min_bitrate), max_bitrate(max_bitrate) {} | 75 : min_bitrate(min_bitrate), max_bitrate(max_bitrate) {} |
| 77 uint32_t min_bitrate; | 76 uint32_t min_bitrate; |
| 78 uint32_t max_bitrate; | 77 uint32_t max_bitrate; |
| 79 }; | 78 }; |
| 80 struct ObserverConfiguration { | 79 struct ObserverConfiguration { |
| 81 ObserverConfiguration(BitrateAllocatorObserver* observer, uint32_t bitrate) | 80 ObserverConfiguration(BitrateAllocatorObserver* observer, uint32_t bitrate) |
| 82 : observer(observer), min_bitrate(bitrate) {} | 81 : observer(observer), min_bitrate(bitrate) {} |
| 83 BitrateAllocatorObserver* const observer; | 82 BitrateAllocatorObserver* const observer; |
| 84 uint32_t min_bitrate; | 83 uint32_t min_bitrate; |
| 85 }; | 84 }; |
| 86 typedef std::pair<BitrateAllocatorObserver*, BitrateConfiguration> | 85 typedef std::pair<BitrateAllocatorObserver*, BitrateConfiguration> |
| 87 BitrateObserverConfiguration; | 86 BitrateObserverConfiguration; |
| 88 typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList; | 87 typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList; |
| 89 typedef std::multimap<uint32_t, ObserverConfiguration> ObserverSortingMap; | 88 typedef std::multimap<uint32_t, ObserverConfiguration> ObserverSortingMap; |
| 90 typedef std::map<BitrateAllocatorObserver*, int> ObserverBitrateMap; | 89 typedef std::map<BitrateAllocatorObserver*, int> ObserverBitrateMap; |
| 91 | 90 |
| 92 BitrateObserverConfList::iterator FindObserverConfigurationPair( | 91 BitrateObserverConfList::iterator FindObserverConfigurationPair( |
| 93 const BitrateAllocatorObserver* observer) | 92 const BitrateAllocatorObserver* observer) |
| 94 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 93 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 95 ObserverBitrateMap AllocateBitrates() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 94 ObserverBitrateMap AllocateBitrates() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 96 ObserverBitrateMap NormalRateAllocation(uint32_t bitrate, | 95 ObserverBitrateMap NormalRateAllocation(uint32_t bitrate, |
| 97 uint32_t sum_min_bitrates) | 96 uint32_t sum_min_bitrates) |
| 98 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 97 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 99 | 98 |
| 99 ObserverBitrateMap ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 100 ObserverBitrateMap LowRateAllocation(uint32_t bitrate) | 100 ObserverBitrateMap LowRateAllocation(uint32_t bitrate) |
| 101 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 101 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 102 | 102 |
| 103 rtc::CriticalSection crit_sect_; | 103 rtc::CriticalSection crit_sect_; |
| 104 // Stored in a list to keep track of the insertion order. | 104 // Stored in a list to keep track of the insertion order. |
| 105 BitrateObserverConfList bitrate_observers_ GUARDED_BY(crit_sect_); | 105 BitrateObserverConfList bitrate_observers_ GUARDED_BY(crit_sect_); |
| 106 bool bitrate_observers_modified_ GUARDED_BY(crit_sect_); | 106 bool bitrate_observers_modified_ GUARDED_BY(crit_sect_); |
| 107 bool enforce_min_bitrate_ GUARDED_BY(crit_sect_); | 107 bool enforce_min_bitrate_ GUARDED_BY(crit_sect_); |
| 108 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); | 108 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); |
| 109 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); | 109 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); |
| 110 int64_t last_rtt_ GUARDED_BY(crit_sect_); | 110 int64_t last_rtt_ GUARDED_BY(crit_sect_); |
| 111 }; | 111 }; |
| 112 } // namespace webrtc | 112 } // namespace webrtc |
| 113 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ | 113 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ |
| OLD | NEW |