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 <list> | |
17 #include <map> | 16 #include <map> |
18 #include <utility> | 17 #include <utility> |
| 18 #include <vector> |
19 | 19 |
20 #include "webrtc/base/criticalsection.h" | 20 #include "webrtc/base/criticalsection.h" |
21 #include "webrtc/base/thread_annotations.h" | 21 #include "webrtc/base/thread_annotations.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 | 24 |
| 25 class Clock; |
| 26 |
25 // Used by all send streams with adaptive bitrate, to get the currently | 27 // Used by all send streams with adaptive bitrate, to get the currently |
26 // allocated bitrate for the send stream. The current network properties are | 28 // 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 | 29 // given at the same time, to let the send stream decide about possible loss |
28 // protection. | 30 // protection. |
29 class BitrateAllocatorObserver { | 31 class BitrateAllocatorObserver { |
30 public: | 32 public: |
31 virtual void OnBitrateUpdated(uint32_t bitrate_bps, | 33 // Returns the amount of protection used by the BitrateAllocatorObserver |
32 uint8_t fraction_loss, | 34 // implementation, as bitrate in bps. |
33 int64_t rtt) = 0; | 35 virtual uint32_t OnBitrateUpdated(uint32_t bitrate_bps, |
34 | 36 uint8_t fraction_loss, |
| 37 int64_t rtt) = 0; |
35 protected: | 38 protected: |
36 virtual ~BitrateAllocatorObserver() {} | 39 virtual ~BitrateAllocatorObserver() {} |
37 }; | 40 }; |
38 | 41 |
39 // Usage: this class will register multiple RtcpBitrateObserver's one at each | 42 // Usage: this class will register multiple RtcpBitrateObserver's one at each |
40 // RTCP module. It will aggregate the results and run one bandwidth estimation | 43 // RTCP module. It will aggregate the results and run one bandwidth estimation |
41 // and push the result to the encoders via BitrateAllocatorObserver(s). | 44 // and push the result to the encoders via BitrateAllocatorObserver(s). |
42 class BitrateAllocator { | 45 class BitrateAllocator { |
43 public: | 46 public: |
44 // Used to get notified when send stream limits such as the minimum send | 47 // Used to get notified when send stream limits such as the minimum send |
45 // bitrate and max padding bitrate is changed. | 48 // bitrate and max padding bitrate is changed. |
46 class LimitObserver { | 49 class LimitObserver { |
47 public: | 50 public: |
48 virtual void OnAllocationLimitsChanged( | 51 virtual void OnAllocationLimitsChanged( |
49 uint32_t min_send_bitrate_bps, | 52 uint32_t min_send_bitrate_bps, |
50 uint32_t max_padding_bitrate_bps) = 0; | 53 uint32_t max_padding_bitrate_bps) = 0; |
51 | 54 |
52 protected: | 55 protected: |
53 virtual ~LimitObserver() {} | 56 virtual ~LimitObserver() {} |
54 }; | 57 }; |
55 | 58 |
56 explicit BitrateAllocator(LimitObserver* limit_observer); | 59 explicit BitrateAllocator(LimitObserver* limit_observer); |
| 60 ~BitrateAllocator(); |
57 | 61 |
58 // Allocate target_bitrate across the registered BitrateAllocatorObservers. | 62 // Allocate target_bitrate across the registered BitrateAllocatorObservers. |
59 void OnNetworkChanged(uint32_t target_bitrate_bps, | 63 void OnNetworkChanged(uint32_t target_bitrate_bps, |
60 uint8_t fraction_loss, | 64 uint8_t fraction_loss, |
61 int64_t rtt); | 65 int64_t rtt); |
62 | 66 |
63 // Set the start and max send bitrate used by the bandwidth management. | 67 // Set the start and max send bitrate used by the bandwidth management. |
64 // | 68 // |
65 // |observer| updates bitrates if already in use. | 69 // |observer| updates bitrates if already in use. |
66 // |min_bitrate_bps| = 0 equals no min bitrate. | 70 // |min_bitrate_bps| = 0 equals no min bitrate. |
(...skipping 24 matching lines...) Expand all Loading... |
91 struct ObserverConfig { | 95 struct ObserverConfig { |
92 ObserverConfig(BitrateAllocatorObserver* observer, | 96 ObserverConfig(BitrateAllocatorObserver* observer, |
93 uint32_t min_bitrate_bps, | 97 uint32_t min_bitrate_bps, |
94 uint32_t max_bitrate_bps, | 98 uint32_t max_bitrate_bps, |
95 uint32_t pad_up_bitrate_bps, | 99 uint32_t pad_up_bitrate_bps, |
96 bool enforce_min_bitrate) | 100 bool enforce_min_bitrate) |
97 : observer(observer), | 101 : observer(observer), |
98 min_bitrate_bps(min_bitrate_bps), | 102 min_bitrate_bps(min_bitrate_bps), |
99 max_bitrate_bps(max_bitrate_bps), | 103 max_bitrate_bps(max_bitrate_bps), |
100 pad_up_bitrate_bps(pad_up_bitrate_bps), | 104 pad_up_bitrate_bps(pad_up_bitrate_bps), |
101 enforce_min_bitrate(enforce_min_bitrate) {} | 105 enforce_min_bitrate(enforce_min_bitrate), |
102 BitrateAllocatorObserver* const observer; | 106 allocated_bitrate_bps(-1), |
| 107 media_ratio(1.0) {} |
| 108 |
| 109 BitrateAllocatorObserver* observer; |
103 uint32_t min_bitrate_bps; | 110 uint32_t min_bitrate_bps; |
104 uint32_t max_bitrate_bps; | 111 uint32_t max_bitrate_bps; |
105 uint32_t pad_up_bitrate_bps; | 112 uint32_t pad_up_bitrate_bps; |
106 bool enforce_min_bitrate; | 113 bool enforce_min_bitrate; |
| 114 int64_t allocated_bitrate_bps; |
| 115 double media_ratio; // Part of the total bitrate used for media [0.0, 1.0]. |
107 }; | 116 }; |
108 | 117 |
109 // Calculates the minimum requested send bitrate and max padding bitrate and | 118 // Calculates the minimum requested send bitrate and max padding bitrate and |
110 // calls LimitObserver::OnAllocationLimitsChanged. | 119 // calls LimitObserver::OnAllocationLimitsChanged. |
111 void UpdateAllocationLimits(); | 120 void UpdateAllocationLimits(); |
112 | 121 |
113 typedef std::list<ObserverConfig> ObserverConfigList; | 122 typedef std::vector<ObserverConfig> ObserverConfigs; |
114 ObserverConfigList::iterator FindObserverConfig( | 123 ObserverConfigs::iterator FindObserverConfig( |
115 const BitrateAllocatorObserver* observer) | 124 const BitrateAllocatorObserver* observer) |
116 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 125 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
117 | 126 |
118 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; | 127 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; |
119 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; | 128 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; |
120 | 129 |
121 ObserverAllocation AllocateBitrates(uint32_t bitrate) | 130 ObserverAllocation AllocateBitrates(uint32_t bitrate) |
122 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 131 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
123 | 132 |
124 ObserverAllocation ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 133 ObserverAllocation ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
(...skipping 21 matching lines...) Expand all Loading... |
146 int max_multiplier, | 155 int max_multiplier, |
147 ObserverAllocation* allocation) | 156 ObserverAllocation* allocation) |
148 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 157 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
149 bool EnoughBitrateForAllObservers(uint32_t bitrate, uint32_t sum_min_bitrates) | 158 bool EnoughBitrateForAllObservers(uint32_t bitrate, uint32_t sum_min_bitrates) |
150 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); | 159 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); |
151 | 160 |
152 LimitObserver* const limit_observer_; | 161 LimitObserver* const limit_observer_; |
153 | 162 |
154 rtc::CriticalSection crit_sect_; | 163 rtc::CriticalSection crit_sect_; |
155 // Stored in a list to keep track of the insertion order. | 164 // Stored in a list to keep track of the insertion order. |
156 ObserverConfigList bitrate_observer_configs_ GUARDED_BY(crit_sect_); | 165 ObserverConfigs bitrate_observer_configs_ GUARDED_BY(crit_sect_); |
157 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); | 166 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); |
158 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(crit_sect_); | 167 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(crit_sect_); |
159 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); | 168 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); |
160 int64_t last_rtt_ GUARDED_BY(crit_sect_); | 169 int64_t last_rtt_ GUARDED_BY(crit_sect_); |
161 ObserverAllocation last_allocation_ GUARDED_BY(crit_sect_); | 170 // Number of mute events based on too low BWE, not network up/down. |
| 171 int num_pause_events_ GUARDED_BY(crit_sect_); |
| 172 Clock* const clock_; |
| 173 int64_t last_bwe_log_time_; |
162 }; | 174 }; |
163 } // namespace webrtc | 175 } // namespace webrtc |
164 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ | 176 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ |
OLD | NEW |