Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: webrtc/call/bitrate_allocator.h

Issue 2117493002: Auto pause video streams based on encoder target bitrate. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | webrtc/call/bitrate_allocator.cc » ('j') | webrtc/call/bitrate_allocator.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 virtual uint32_t OnBitrateUpdated(uint32_t bitrate_bps,
32 uint8_t fraction_loss, 34 uint8_t fraction_loss,
33 int64_t rtt) = 0; 35 int64_t rtt) = 0;
34
35 protected: 36 protected:
36 virtual ~BitrateAllocatorObserver() {} 37 virtual ~BitrateAllocatorObserver() {}
37 }; 38 };
38 39
39 // Usage: this class will register multiple RtcpBitrateObserver's one at each 40 // Usage: this class will register multiple RtcpBitrateObserver's one at each
40 // RTCP module. It will aggregate the results and run one bandwidth estimation 41 // RTCP module. It will aggregate the results and run one bandwidth estimation
41 // and push the result to the encoders via BitrateAllocatorObserver(s). 42 // and push the result to the encoders via BitrateAllocatorObserver(s).
42 class BitrateAllocator { 43 class BitrateAllocator {
43 public: 44 public:
44 // Used to get notified when send stream limits such as the minimum send 45 // Used to get notified when send stream limits such as the minimum send
45 // bitrate and max padding bitrate is changed. 46 // bitrate and max padding bitrate is changed.
46 class LimitObserver { 47 class LimitObserver {
47 public: 48 public:
48 virtual void OnAllocationLimitsChanged( 49 virtual void OnAllocationLimitsChanged(
49 uint32_t min_send_bitrate_bps, 50 uint32_t min_send_bitrate_bps,
50 uint32_t max_padding_bitrate_bps) = 0; 51 uint32_t max_padding_bitrate_bps) = 0;
51 52
52 protected: 53 protected:
53 virtual ~LimitObserver() {} 54 virtual ~LimitObserver() {}
54 }; 55 };
55 56
56 explicit BitrateAllocator(LimitObserver* limit_observer); 57 explicit BitrateAllocator(LimitObserver* limit_observer);
58 ~BitrateAllocator();
57 59
58 // Allocate target_bitrate across the registered BitrateAllocatorObservers. 60 // Allocate target_bitrate across the registered BitrateAllocatorObservers.
59 void OnNetworkChanged(uint32_t target_bitrate_bps, 61 void OnNetworkChanged(uint32_t target_bitrate_bps,
60 uint8_t fraction_loss, 62 uint8_t fraction_loss,
61 int64_t rtt); 63 int64_t rtt);
62 64
63 // Set the start and max send bitrate used by the bandwidth management. 65 // Set the start and max send bitrate used by the bandwidth management.
64 // 66 //
65 // |observer| updates bitrates if already in use. 67 // |observer| updates bitrates if already in use.
66 // |min_bitrate_bps| = 0 equals no min bitrate. 68 // |min_bitrate_bps| = 0 equals no min bitrate.
(...skipping 24 matching lines...) Expand all
91 struct ObserverConfig { 93 struct ObserverConfig {
92 ObserverConfig(BitrateAllocatorObserver* observer, 94 ObserverConfig(BitrateAllocatorObserver* observer,
93 uint32_t min_bitrate_bps, 95 uint32_t min_bitrate_bps,
94 uint32_t max_bitrate_bps, 96 uint32_t max_bitrate_bps,
95 uint32_t pad_up_bitrate_bps, 97 uint32_t pad_up_bitrate_bps,
96 bool enforce_min_bitrate) 98 bool enforce_min_bitrate)
97 : observer(observer), 99 : observer(observer),
98 min_bitrate_bps(min_bitrate_bps), 100 min_bitrate_bps(min_bitrate_bps),
99 max_bitrate_bps(max_bitrate_bps), 101 max_bitrate_bps(max_bitrate_bps),
100 pad_up_bitrate_bps(pad_up_bitrate_bps), 102 pad_up_bitrate_bps(pad_up_bitrate_bps),
101 enforce_min_bitrate(enforce_min_bitrate) {} 103 enforce_min_bitrate(enforce_min_bitrate),
102 BitrateAllocatorObserver* const observer; 104 allocated_bitrate_bps(-1),
105 media_ratio(1.0) {}
106
107 BitrateAllocatorObserver* observer;
103 uint32_t min_bitrate_bps; 108 uint32_t min_bitrate_bps;
104 uint32_t max_bitrate_bps; 109 uint32_t max_bitrate_bps;
105 uint32_t pad_up_bitrate_bps; 110 uint32_t pad_up_bitrate_bps;
106 bool enforce_min_bitrate; 111 bool enforce_min_bitrate;
112 int64_t allocated_bitrate_bps;
113 double media_ratio; // Part of the total bitrate used for media [0.0, 1.0].
107 }; 114 };
108 115
109 // Calculates the minimum requested send bitrate and max padding bitrate and 116 // Calculates the minimum requested send bitrate and max padding bitrate and
110 // calls LimitObserver::OnAllocationLimitsChanged. 117 // calls LimitObserver::OnAllocationLimitsChanged.
111 void UpdateAllocationLimits(); 118 void UpdateAllocationLimits();
112 119
113 typedef std::list<ObserverConfig> ObserverConfigList; 120 typedef std::vector<ObserverConfig> ObserverConfigs;
114 ObserverConfigList::iterator FindObserverConfig( 121 ObserverConfigs::iterator FindObserverConfig(
115 const BitrateAllocatorObserver* observer) 122 const BitrateAllocatorObserver* observer)
116 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 123 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
117 124
118 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; 125 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap;
119 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; 126 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation;
120 127
121 ObserverAllocation AllocateBitrates(uint32_t bitrate) 128 ObserverAllocation AllocateBitrates(uint32_t bitrate)
122 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 129 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
123 130
124 ObserverAllocation ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 131 ObserverAllocation ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
(...skipping 21 matching lines...) Expand all
146 int max_multiplier, 153 int max_multiplier,
147 ObserverAllocation* allocation) 154 ObserverAllocation* allocation)
148 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 155 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
149 bool EnoughBitrateForAllObservers(uint32_t bitrate, uint32_t sum_min_bitrates) 156 bool EnoughBitrateForAllObservers(uint32_t bitrate, uint32_t sum_min_bitrates)
150 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 157 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
151 158
152 LimitObserver* const limit_observer_; 159 LimitObserver* const limit_observer_;
153 160
154 rtc::CriticalSection crit_sect_; 161 rtc::CriticalSection crit_sect_;
155 // Stored in a list to keep track of the insertion order. 162 // Stored in a list to keep track of the insertion order.
156 ObserverConfigList bitrate_observer_configs_ GUARDED_BY(crit_sect_); 163 ObserverConfigs bitrate_observer_configs_ GUARDED_BY(crit_sect_);
157 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); 164 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_);
158 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(crit_sect_); 165 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(crit_sect_);
159 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); 166 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_);
160 int64_t last_rtt_ GUARDED_BY(crit_sect_); 167 int64_t last_rtt_ GUARDED_BY(crit_sect_);
161 ObserverAllocation last_allocation_ GUARDED_BY(crit_sect_); 168 // Number of mute events based on too low BWE, not network up/down.
169 int num_pause_events_ GUARDED_BY(crit_sect_);
170 Clock* const clock_;
171 int64_t last_bwe_log_time_;
162 }; 172 };
163 } // namespace webrtc 173 } // namespace webrtc
164 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ 174 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/call/bitrate_allocator.cc » ('j') | webrtc/call/bitrate_allocator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698