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 // Returns actual bitrate allocated, which might be higher than target_bitrate |
46 // for instance EnforceMinBitrate() is enabled. | 46 // if for instance EnforceMinBitrate() is enabled. |
47 uint32_t OnNetworkChanged(uint32_t target_bitrate, | 47 uint32_t OnNetworkChanged(uint32_t target_bitrate_bps, |
48 uint8_t fraction_loss, | 48 uint8_t fraction_loss, |
49 int64_t rtt); | 49 int64_t rtt); |
50 | 50 |
51 // Set the start and max send bitrate used by the bandwidth management. | 51 // Set the start and max send bitrate used by the bandwidth management. |
52 // | 52 // |
53 // |observer| updates bitrates if already in use. | 53 // |observer| updates bitrates if already in use. |
54 // |min_bitrate_bps| = 0 equals no min bitrate. | 54 // |min_bitrate_bps| = 0 equals no min bitrate. |
55 // |max_bitrate_bps| = 0 equals no max bitrate. | 55 // |max_bitrate_bps| = 0 equals no max bitrate. |
56 // |enforce_min_bitrate| = 'true' will allocate at least |min_bitrate_bps| for | 56 // |enforce_min_bitrate| = 'true' will allocate at least |min_bitrate_bps| for |
57 // this observer, even if the BWE is too low, 'false' will allocate 0 to | 57 // this observer, even if the BWE is too low, 'false' will allocate 0 to |
58 // the observer if BWE doesn't allow |min_bitrate_bps|. | 58 // the observer if BWE doesn't allow |min_bitrate_bps|. |
59 // Returns initial bitrate allocated for |observer|. | 59 // Returns initial bitrate allocated for |observer|. |
60 // Note that |observer|->OnBitrateUpdated() will be called within the scope of | 60 // Note that |observer|->OnBitrateUpdated() will be called within the scope of |
61 // this method with the current rtt, fraction_loss and available bitrate and | 61 // this method with the current rtt, fraction_loss and available bitrate and |
62 // that the bitrate in OnBitrateUpdated will be zero if the |observer| is | 62 // that the bitrate in OnBitrateUpdated will be zero if the |observer| is |
63 // currently not allowed to send data. | 63 // currently not allowed to send data. |
64 int AddObserver(BitrateAllocatorObserver* observer, | 64 int AddObserver(BitrateAllocatorObserver* observer, |
65 uint32_t min_bitrate_bps, | 65 uint32_t min_bitrate_bps, |
66 uint32_t max_bitrate_bps, | 66 uint32_t max_bitrate_bps, |
67 bool enforce_min_bitrate); | 67 bool enforce_min_bitrate); |
68 | 68 |
69 // Removes a previously added observer, but will not trigger a new bitrate | |
pbos-webrtc
2016/06/06 15:26:28
Should this not trigger a new bitrate allocation?
mflodman
2016/06/09 13:23:13
It has never done it and there is no urgency to ac
pbos-webrtc
2016/06/09 13:37:21
Is there a guarantee that a new estimate will come
| |
70 // allocation. | |
69 void RemoveObserver(BitrateAllocatorObserver* observer); | 71 void RemoveObserver(BitrateAllocatorObserver* observer); |
70 | 72 |
71 private: | 73 private: |
74 // Note: All bitrates for member variables and methods are in bps. | |
72 struct ObserverConfig { | 75 struct ObserverConfig { |
73 ObserverConfig(BitrateAllocatorObserver* observer, | 76 ObserverConfig(BitrateAllocatorObserver* observer, |
74 uint32_t min_bitrate_bps, | 77 uint32_t min_bitrate_bps, |
75 uint32_t max_bitrate_bps, | 78 uint32_t max_bitrate_bps, |
76 bool enforce_min_bitrate) | 79 bool enforce_min_bitrate) |
77 : observer(observer), | 80 : observer(observer), |
78 min_bitrate_bps(min_bitrate_bps), | 81 min_bitrate_bps(min_bitrate_bps), |
79 max_bitrate_bps(max_bitrate_bps), | 82 max_bitrate_bps(max_bitrate_bps), |
80 enforce_min_bitrate(enforce_min_bitrate) {} | 83 enforce_min_bitrate(enforce_min_bitrate) {} |
81 BitrateAllocatorObserver* const observer; | 84 BitrateAllocatorObserver* const observer; |
82 uint32_t min_bitrate_bps; | 85 uint32_t min_bitrate_bps; |
83 uint32_t max_bitrate_bps; | 86 uint32_t max_bitrate_bps; |
84 bool enforce_min_bitrate; | 87 bool enforce_min_bitrate; |
85 }; | 88 }; |
86 | 89 |
87 // This method controls the behavior when the available bitrate is lower than | |
88 // the minimum bitrate, or the sum of minimum bitrates. | |
89 // When true, the bitrate will never be set lower than the minimum bitrate(s). | |
90 // When false, the bitrate observers will be allocated rates up to their | |
91 // respective minimum bitrate, satisfying one observer after the other. | |
92 void EnforceMinBitrate(bool enforce_min_bitrate) | |
93 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
94 | |
95 typedef std::list<ObserverConfig> ObserverConfigList; | 90 typedef std::list<ObserverConfig> ObserverConfigList; |
96 ObserverConfigList::iterator FindObserverConfig( | 91 ObserverConfigList::iterator FindObserverConfig( |
97 const BitrateAllocatorObserver* observer) | 92 const BitrateAllocatorObserver* observer) |
98 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 93 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
99 | 94 |
100 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; | 95 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; |
101 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; | 96 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; |
102 | 97 |
103 ObserverAllocation AllocateBitrates(uint32_t bitrate) | 98 ObserverAllocation AllocateBitrates(uint32_t bitrate) |
104 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 99 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
105 ObserverAllocation NormalRateAllocation(uint32_t bitrate, | |
106 uint32_t sum_min_bitrates) | |
107 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
108 | 100 |
109 ObserverAllocation ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 101 ObserverAllocation ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
110 ObserverAllocation LowRateAllocation(uint32_t bitrate) | 102 ObserverAllocation LowRateAllocation(uint32_t bitrate) |
111 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 103 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
104 ObserverAllocation NormalRateAllocation(uint32_t bitrate, | |
pbos-webrtc
2016/06/06 15:26:28
_bps on everything here please
mflodman
2016/06/09 13:23:13
See my previous reply.
| |
105 uint32_t sum_min_bitrates) | |
106 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
107 ObserverAllocation MaxRateAllocation(uint32_t bitrate, | |
108 uint32_t sum_max_bitrates) | |
109 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
110 | |
111 uint32_t LastAllocatedBitrate(const ObserverConfig& observer_config) | |
112 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
113 // The minimum bitrate required by this observer, including enable-hysteresis | |
114 // if the observer is in a paused state. | |
115 uint32_t MinBitrateForObserver(const ObserverConfig& observer_config) | |
116 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
117 // Splits |bitrate| evenly to all observers with a non-zero bitrate in | |
118 // |allocation|. The allowed max bitrate is |max_multiplier| x observer max | |
119 // bitrate. | |
120 void DistributeBitrateEvenly( | |
121 uint32_t bitrate, int max_multiplier, ObserverAllocation* allocation) | |
122 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
123 bool ShouldDoLowRateAllocation(uint32_t bitrate, uint32_t sum_min_bitrates) | |
124 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | |
125 | |
112 | 126 |
113 rtc::CriticalSection crit_sect_; | 127 rtc::CriticalSection crit_sect_; |
114 // Stored in a list to keep track of the insertion order. | 128 // Stored in a list to keep track of the insertion order. |
115 ObserverConfigList bitrate_observer_configs_ GUARDED_BY(crit_sect_); | 129 ObserverConfigList bitrate_observer_configs_ GUARDED_BY(crit_sect_); |
116 bool enforce_min_bitrate_ GUARDED_BY(crit_sect_); | |
117 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); | 130 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); |
118 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(crit_sect_); | 131 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(crit_sect_); |
119 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); | 132 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); |
120 int64_t last_rtt_ GUARDED_BY(crit_sect_); | 133 int64_t last_rtt_ GUARDED_BY(crit_sect_); |
134 ObserverAllocation last_allocation_ GUARDED_BY(crit_sect_); | |
121 }; | 135 }; |
122 } // namespace webrtc | 136 } // namespace webrtc |
123 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ | 137 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ |
OLD | NEW |