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

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

Issue 1993113003: Refactor how padding is calculated. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Self review Created 4 years, 7 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') | no next file with comments »
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
(...skipping 13 matching lines...) Expand all
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:
stefan-webrtc 2016/06/08 09:25:13 Why is this needed?
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 (might be higher than target_bitrate if 59 void OnNetworkChanged(uint32_t target_bitrate,
46 // for instance EnforceMinBitrate() is enabled. 60 uint8_t fraction_loss,
47 uint32_t OnNetworkChanged(uint32_t target_bitrate, 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 void RemoveObserver(BitrateAllocatorObserver* observer); 82 void RemoveObserver(BitrateAllocatorObserver* observer);
70 83
84 // Called by a BitrateAllocatorObserver when it is inactive, ie not producing
85 // encoded frames for one reason or the other.
86 // The observer will still be allocated a target bitrate but padding will
87 // not be sent.
88 void NotifyObserverInactive(BitrateAllocatorObserver* observer,
89 bool inactive);
90
71 private: 91 private:
72 struct ObserverConfig { 92 struct ObserverConfig {
73 ObserverConfig(BitrateAllocatorObserver* observer, 93 ObserverConfig(BitrateAllocatorObserver* observer,
74 uint32_t min_bitrate_bps, 94 uint32_t min_bitrate_bps,
75 uint32_t max_bitrate_bps, 95 uint32_t max_bitrate_bps,
96 uint32_t pad_up_bitrate_bps,
76 bool enforce_min_bitrate) 97 bool enforce_min_bitrate)
77 : observer(observer), 98 : observer(observer),
99 active(true),
78 min_bitrate_bps(min_bitrate_bps), 100 min_bitrate_bps(min_bitrate_bps),
79 max_bitrate_bps(max_bitrate_bps), 101 max_bitrate_bps(max_bitrate_bps),
102 pad_up_bitrate_bps(pad_up_bitrate_bps),
80 enforce_min_bitrate(enforce_min_bitrate) {} 103 enforce_min_bitrate(enforce_min_bitrate) {}
81 BitrateAllocatorObserver* const observer; 104 BitrateAllocatorObserver* const observer;
105 bool active;
82 uint32_t min_bitrate_bps; 106 uint32_t min_bitrate_bps;
83 uint32_t max_bitrate_bps; 107 uint32_t max_bitrate_bps;
108 uint32_t pad_up_bitrate_bps;
84 bool enforce_min_bitrate; 109 bool enforce_min_bitrate;
85 }; 110 };
86 111
112 // Calculates the minimum requested send bitrate and max padding bitrate and
113 // calls LimitObserver::OnAllocationLimitsChanged.
114 void UpdateAllocationLimits() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
115
87 // This method controls the behavior when the available bitrate is lower than 116 // This method controls the behavior when the available bitrate is lower than
88 // the minimum bitrate, or the sum of minimum bitrates. 117 // the minimum bitrate, or the sum of minimum bitrates.
89 // When true, the bitrate will never be set lower than the minimum bitrate(s). 118 // 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 119 // When false, the bitrate observers will be allocated rates up to their
91 // respective minimum bitrate, satisfying one observer after the other. 120 // respective minimum bitrate, satisfying one observer after the other.
92 void EnforceMinBitrate(bool enforce_min_bitrate) 121 void EnforceMinBitrate(bool enforce_min_bitrate)
93 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 122 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
94 123
95 typedef std::list<ObserverConfig> ObserverConfigList; 124 typedef std::list<ObserverConfig> ObserverConfigList;
96 ObserverConfigList::iterator FindObserverConfig( 125 ObserverConfigList::iterator FindObserverConfig(
97 const BitrateAllocatorObserver* observer) 126 const BitrateAllocatorObserver* observer)
98 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 127 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
99 128
100 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap; 129 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap;
101 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation; 130 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation;
102 131
103 ObserverAllocation AllocateBitrates(uint32_t bitrate) 132 ObserverAllocation AllocateBitrates(uint32_t bitrate)
104 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 133 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
105 ObserverAllocation NormalRateAllocation(uint32_t bitrate, 134 ObserverAllocation NormalRateAllocation(uint32_t bitrate,
106 uint32_t sum_min_bitrates) 135 uint32_t sum_min_bitrates)
107 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 136 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
108 137
109 ObserverAllocation ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 138 ObserverAllocation ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
110 ObserverAllocation LowRateAllocation(uint32_t bitrate) 139 ObserverAllocation LowRateAllocation(uint32_t bitrate)
111 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 140 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
112 141
142 LimitObserver* const limit_observer_;
143
113 rtc::CriticalSection crit_sect_; 144 rtc::CriticalSection crit_sect_;
114 // Stored in a list to keep track of the insertion order. 145 // Stored in a list to keep track of the insertion order.
115 ObserverConfigList bitrate_observer_configs_ GUARDED_BY(crit_sect_); 146 ObserverConfigList bitrate_observer_configs_ GUARDED_BY(crit_sect_);
116 bool enforce_min_bitrate_ GUARDED_BY(crit_sect_); 147 bool enforce_min_bitrate_ GUARDED_BY(crit_sect_);
117 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); 148 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_);
118 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(crit_sect_); 149 uint32_t last_non_zero_bitrate_bps_ GUARDED_BY(crit_sect_);
119 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); 150 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_);
120 int64_t last_rtt_ GUARDED_BY(crit_sect_); 151 int64_t last_rtt_ GUARDED_BY(crit_sect_);
121 }; 152 };
122 } // namespace webrtc 153 } // namespace webrtc
123 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ 154 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_
OLDNEW
« no previous file with comments | « no previous file | webrtc/call/bitrate_allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698