| 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 * Usage: this class will register multiple RtcpBitrateObserver's one at each | 10 * Usage: this class will register multiple RtcpBitrateObserver's one at each |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 class BitrateAllocator { | 30 class BitrateAllocator { |
| 31 public: | 31 public: |
| 32 BitrateAllocator(); | 32 BitrateAllocator(); |
| 33 | 33 |
| 34 void OnNetworkChanged(uint32_t target_bitrate, | 34 void OnNetworkChanged(uint32_t target_bitrate, |
| 35 uint8_t fraction_loss, | 35 uint8_t fraction_loss, |
| 36 int64_t rtt); | 36 int64_t rtt); |
| 37 | 37 |
| 38 // Set the start and max send bitrate used by the bandwidth management. | 38 // Set the start and max send bitrate used by the bandwidth management. |
| 39 // | 39 // |
| 40 // observer, updates bitrates if already in use. | 40 // |observer| updates bitrates if already in use. |
| 41 // min_bitrate_bps = 0 equals no min bitrate. | 41 // |min_bitrate_bps| = 0 equals no min bitrate. |
| 42 // max_bitrate_bps = 0 equals no max bitrate. | 42 // |max_bitrate_bps| = 0 equals no max bitrate. |
| 43 // TODO(holmer): Remove start_bitrate_bps when old API is gone. | 43 // Returns bitrate allocated for the bitrate observer. |
| 44 int AddBitrateObserver(BitrateObserver* observer, | 44 int AddBitrateObserver(BitrateObserver* observer, |
| 45 uint32_t start_bitrate_bps, | |
| 46 uint32_t min_bitrate_bps, | 45 uint32_t min_bitrate_bps, |
| 47 uint32_t max_bitrate_bps, | 46 uint32_t max_bitrate_bps); |
| 48 int* new_observer_bitrate_bps); | |
| 49 | 47 |
| 50 void RemoveBitrateObserver(BitrateObserver* observer); | 48 void RemoveBitrateObserver(BitrateObserver* observer); |
| 51 | 49 |
| 52 void GetMinMaxBitrateSumBps(int* min_bitrate_sum_bps, | 50 void GetMinMaxBitrateSumBps(int* min_bitrate_sum_bps, |
| 53 int* max_bitrate_sum_bps) const; | 51 int* max_bitrate_sum_bps) const; |
| 54 | 52 |
| 55 // This method controls the behavior when the available bitrate is lower than | 53 // This method controls the behavior when the available bitrate is lower than |
| 56 // the minimum bitrate, or the sum of minimum bitrates. | 54 // the minimum bitrate, or the sum of minimum bitrates. |
| 57 // When true, the bitrate will never be set lower than the minimum bitrate(s). | 55 // When true, the bitrate will never be set lower than the minimum bitrate(s). |
| 58 // When false, the bitrate observers will be allocated rates up to their | 56 // When false, the bitrate observers will be allocated rates up to their |
| 59 // respective minimum bitrate, satisfying one observer after the other. | 57 // respective minimum bitrate, satisfying one observer after the other. |
| 60 void EnforceMinBitrate(bool enforce_min_bitrate); | 58 void EnforceMinBitrate(bool enforce_min_bitrate); |
| 61 | 59 |
| 62 private: | 60 private: |
| 63 struct BitrateConfiguration { | 61 struct BitrateConfiguration { |
| 64 BitrateConfiguration(uint32_t start_bitrate, | 62 BitrateConfiguration(uint32_t min_bitrate, uint32_t max_bitrate) |
| 65 uint32_t min_bitrate, | 63 : min_bitrate(min_bitrate), max_bitrate(max_bitrate) {} |
| 66 uint32_t max_bitrate) | 64 uint32_t min_bitrate; |
| 67 : start_bitrate_(start_bitrate), | 65 uint32_t max_bitrate; |
| 68 min_bitrate_(min_bitrate), | |
| 69 max_bitrate_(max_bitrate) {} | |
| 70 uint32_t start_bitrate_; | |
| 71 uint32_t min_bitrate_; | |
| 72 uint32_t max_bitrate_; | |
| 73 }; | 66 }; |
| 74 struct ObserverConfiguration { | 67 struct ObserverConfiguration { |
| 75 ObserverConfiguration(BitrateObserver* observer, uint32_t bitrate) | 68 ObserverConfiguration(BitrateObserver* observer, uint32_t bitrate) |
| 76 : observer_(observer), min_bitrate_(bitrate) {} | 69 : observer(observer), min_bitrate(bitrate) {} |
| 77 BitrateObserver* observer_; | 70 BitrateObserver* const observer; |
| 78 uint32_t min_bitrate_; | 71 uint32_t min_bitrate; |
| 79 }; | 72 }; |
| 80 typedef std::pair<BitrateObserver*, BitrateConfiguration> | 73 typedef std::pair<BitrateObserver*, BitrateConfiguration> |
| 81 BitrateObserverConfiguration; | 74 BitrateObserverConfiguration; |
| 82 typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList; | 75 typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList; |
| 83 typedef std::multimap<uint32_t, ObserverConfiguration> ObserverSortingMap; | 76 typedef std::multimap<uint32_t, ObserverConfiguration> ObserverSortingMap; |
| 84 typedef std::map<BitrateObserver*, int> ObserverBitrateMap; | 77 typedef std::map<BitrateObserver*, int> ObserverBitrateMap; |
| 85 | 78 |
| 86 BitrateObserverConfList::iterator FindObserverConfigurationPair( | 79 BitrateObserverConfList::iterator FindObserverConfigurationPair( |
| 87 const BitrateObserver* observer) EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 80 const BitrateObserver* observer) EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 88 ObserverBitrateMap AllocateBitrates() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 81 ObserverBitrateMap AllocateBitrates() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 89 ObserverBitrateMap NormalRateAllocation(uint32_t bitrate, | 82 ObserverBitrateMap NormalRateAllocation(uint32_t bitrate, |
| 90 uint32_t sum_min_bitrates) | 83 uint32_t sum_min_bitrates) |
| 91 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 84 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 92 | 85 |
| 93 ObserverBitrateMap LowRateAllocation(uint32_t bitrate) | 86 ObserverBitrateMap LowRateAllocation(uint32_t bitrate) |
| 94 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 87 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
| 95 | 88 |
| 96 rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_; | 89 rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_; |
| 97 // Stored in a list to keep track of the insertion order. | 90 // Stored in a list to keep track of the insertion order. |
| 98 BitrateObserverConfList bitrate_observers_ GUARDED_BY(crit_sect_); | 91 BitrateObserverConfList bitrate_observers_ GUARDED_BY(crit_sect_); |
| 99 bool bitrate_observers_modified_ GUARDED_BY(crit_sect_); | 92 bool bitrate_observers_modified_ GUARDED_BY(crit_sect_); |
| 100 bool enforce_min_bitrate_ GUARDED_BY(crit_sect_); | 93 bool enforce_min_bitrate_ GUARDED_BY(crit_sect_); |
| 101 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); | 94 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); |
| 102 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); | 95 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); |
| 103 int64_t last_rtt_ GUARDED_BY(crit_sect_); | 96 int64_t last_rtt_ GUARDED_BY(crit_sect_); |
| 104 }; | 97 }; |
| 105 } // namespace webrtc | 98 } // namespace webrtc |
| 106 #endif // WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_ALLOCATOR_H_ | 99 #endif // WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_ALLOCATOR_H_ |
| OLD | NEW |