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 13 matching lines...) Expand all Loading... |
24 | 24 |
25 // Used by all send streams with adaptive bitrate, to get the currently | 25 // Used by all send streams with adaptive bitrate, to get the currently |
26 // allocated bitrate for the send stream. The current network properties are | 26 // 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 | 27 // given at the same time, to let the send stream decide about possible loss |
28 // protection. | 28 // protection. |
29 class BitrateAllocatorObserver { | 29 class BitrateAllocatorObserver { |
30 public: | 30 public: |
31 virtual void OnBitrateUpdated(uint32_t bitrate_bps, | 31 virtual void OnBitrateUpdated(uint32_t bitrate_bps, |
32 uint8_t fraction_loss, | 32 uint8_t fraction_loss, |
33 int64_t rtt) = 0; | 33 int64_t rtt) = 0; |
| 34 |
| 35 protected: |
34 virtual ~BitrateAllocatorObserver() {} | 36 virtual ~BitrateAllocatorObserver() {} |
35 }; | 37 }; |
36 | 38 |
37 // Usage: this class will register multiple RtcpBitrateObserver's one at each | 39 // Usage: this class will register multiple RtcpBitrateObserver's one at each |
38 // RTCP module. It will aggregate the results and run one bandwidth estimation | 40 // RTCP module. It will aggregate the results and run one bandwidth estimation |
39 // and push the result to the encoders via BitrateAllocatorObserver(s). | 41 // and push the result to the encoders via BitrateAllocatorObserver(s). |
40 class BitrateAllocator { | 42 class BitrateAllocator { |
41 public: | 43 public: |
42 BitrateAllocator(); | 44 // Used to get notified when send stream limits such as the minimum send |
| 45 // bitrate and max padding bitrate is changed. |
| 46 class LimitObserver { |
| 47 public: |
| 48 virtual void OnAllocationLimitsChanged( |
| 49 uint32_t min_send_bitrate_bps, |
| 50 uint32_t max_padding_bitrate_bps) = 0; |
| 51 |
| 52 protected: |
| 53 virtual ~LimitObserver() {} |
| 54 }; |
| 55 |
| 56 explicit BitrateAllocator(LimitObserver* limit_observer); |
43 | 57 |
44 // Allocate target_bitrate across the registered BitrateAllocatorObservers. | 58 // Allocate target_bitrate across the registered BitrateAllocatorObservers. |
45 // Returns actual bitrate allocated, which might be higher than target_bitrate | 59 void OnNetworkChanged(uint32_t target_bitrate_bps, |
46 // if for instance EnforceMinBitrate() is enabled. | 60 uint8_t fraction_loss, |
47 uint32_t OnNetworkChanged(uint32_t target_bitrate_bps, | 61 int64_t rtt); |
48 uint8_t fraction_loss, | |
49 int64_t rtt); | |
50 | 62 |
51 // Set the start and max send bitrate used by the bandwidth management. | 63 // Set the start and max send bitrate used by the bandwidth management. |
52 // | 64 // |
53 // |observer| updates bitrates if already in use. | 65 // |observer| updates bitrates if already in use. |
54 // |min_bitrate_bps| = 0 equals no min bitrate. | 66 // |min_bitrate_bps| = 0 equals no min bitrate. |
55 // |max_bitrate_bps| = 0 equals no max bitrate. | 67 // |max_bitrate_bps| = 0 equals no max bitrate. |
56 // |enforce_min_bitrate| = 'true' will allocate at least |min_bitrate_bps| for | 68 // |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 | 69 // 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|. | 70 // the observer if BWE doesn't allow |min_bitrate_bps|. |
59 // Returns initial bitrate allocated for |observer|. | 71 // Returns initial bitrate allocated for |observer|. |
60 // Note that |observer|->OnBitrateUpdated() will be called within the scope of | 72 // Note that |observer|->OnBitrateUpdated() will be called within the scope of |
61 // this method with the current rtt, fraction_loss and available bitrate and | 73 // 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 | 74 // that the bitrate in OnBitrateUpdated will be zero if the |observer| is |
63 // currently not allowed to send data. | 75 // currently not allowed to send data. |
64 int AddObserver(BitrateAllocatorObserver* observer, | 76 int AddObserver(BitrateAllocatorObserver* observer, |
65 uint32_t min_bitrate_bps, | 77 uint32_t min_bitrate_bps, |
66 uint32_t max_bitrate_bps, | 78 uint32_t max_bitrate_bps, |
| 79 uint32_t pad_up_bitrate_bps, |
67 bool enforce_min_bitrate); | 80 bool enforce_min_bitrate); |
68 | 81 |
69 // Removes a previously added observer, but will not trigger a new bitrate | 82 // Removes a previously added observer, but will not trigger a new bitrate |
70 // allocation. | 83 // allocation. |
71 void RemoveObserver(BitrateAllocatorObserver* observer); | 84 void RemoveObserver(BitrateAllocatorObserver* observer); |
72 | 85 |
73 private: | 86 private: |
74 // Note: All bitrates for member variables and methods are in bps. | 87 // Note: All bitrates for member variables and methods are in bps. |
75 struct ObserverConfig { | 88 struct ObserverConfig { |
76 ObserverConfig(BitrateAllocatorObserver* observer, | 89 ObserverConfig(BitrateAllocatorObserver* observer, |
77 uint32_t min_bitrate_bps, | 90 uint32_t min_bitrate_bps, |
78 uint32_t max_bitrate_bps, | 91 uint32_t max_bitrate_bps, |
| 92 uint32_t pad_up_bitrate_bps, |
79 bool enforce_min_bitrate) | 93 bool enforce_min_bitrate) |
80 : observer(observer), | 94 : observer(observer), |
81 min_bitrate_bps(min_bitrate_bps), | 95 min_bitrate_bps(min_bitrate_bps), |
82 max_bitrate_bps(max_bitrate_bps), | 96 max_bitrate_bps(max_bitrate_bps), |
| 97 pad_up_bitrate_bps(pad_up_bitrate_bps), |
83 enforce_min_bitrate(enforce_min_bitrate) {} | 98 enforce_min_bitrate(enforce_min_bitrate) {} |
84 BitrateAllocatorObserver* const observer; | 99 BitrateAllocatorObserver* const observer; |
85 uint32_t min_bitrate_bps; | 100 uint32_t min_bitrate_bps; |
86 uint32_t max_bitrate_bps; | 101 uint32_t max_bitrate_bps; |
| 102 uint32_t pad_up_bitrate_bps; |
87 bool enforce_min_bitrate; | 103 bool enforce_min_bitrate; |
88 }; | 104 }; |
89 | 105 |
| 106 // Calculates the minimum requested send bitrate and max padding bitrate and |
| 107 // calls LimitObserver::OnAllocationLimitsChanged. |
| 108 void UpdateAllocationLimits(); |
| 109 |
90 typedef std::list<ObserverConfig> ObserverConfigList; | 110 typedef std::list<ObserverConfig> ObserverConfigList; |
91 ObserverConfigList::iterator FindObserverConfig( | 111 ObserverConfigList::iterator FindObserverConfig( |
92 const BitrateAllocatorObserver* observer) | 112 const BitrateAllocatorObserver* observer) |
93 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 113 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
94 | 114 |
95 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; | 115 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; |
96 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; | 116 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; |
97 | 117 |
98 ObserverAllocation AllocateBitrates(uint32_t bitrate) | 118 ObserverAllocation AllocateBitrates(uint32_t bitrate) |
99 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 119 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
(...skipping 19 matching lines...) Expand all Loading... |
119 // the distribution or not. The allowed max bitrate is |max_multiplier| x | 139 // the distribution or not. The allowed max bitrate is |max_multiplier| x |
120 // observer max bitrate. | 140 // observer max bitrate. |
121 void DistributeBitrateEvenly(uint32_t bitrate, | 141 void DistributeBitrateEvenly(uint32_t bitrate, |
122 bool include_zero_allocations, | 142 bool include_zero_allocations, |
123 int max_multiplier, | 143 int max_multiplier, |
124 ObserverAllocation* allocation) | 144 ObserverAllocation* allocation) |
125 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 145 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
126 bool EnoughBitrateForAllObservers(uint32_t bitrate, uint32_t sum_min_bitrates) | 146 bool EnoughBitrateForAllObservers(uint32_t bitrate, uint32_t sum_min_bitrates) |
127 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 147 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
128 | 148 |
| 149 LimitObserver* const limit_observer_; |
129 | 150 |
130 rtc::CriticalSection crit_sect_; | 151 rtc::CriticalSection crit_sect_; |
131 // Stored in a list to keep track of the insertion order. | 152 // Stored in a list to keep track of the insertion order. |
132 ObserverConfigList bitrate_observer_configs_ GUARDED_BY(crit_sect_); | 153 ObserverConfigList bitrate_observer_configs_ GUARDED_BY(crit_sect_); |
133 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); | 154 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); |
134 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(crit_sect_); | 155 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(crit_sect_); |
135 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); | 156 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); |
136 int64_t last_rtt_ GUARDED_BY(crit_sect_); | 157 int64_t last_rtt_ GUARDED_BY(crit_sect_); |
137 ObserverAllocation last_allocation_ GUARDED_BY(crit_sect_); | 158 ObserverAllocation last_allocation_ GUARDED_BY(crit_sect_); |
138 }; | 159 }; |
139 } // namespace webrtc | 160 } // namespace webrtc |
140 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ | 161 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ |
OLD | NEW |