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

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

Issue 1952923005: Refactor before implementing per stream suspension. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // for instance EnforceMinBitrate() is enabled. 46 // for instance EnforceMinBitrate() is enabled.
47 uint32_t OnNetworkChanged(uint32_t target_bitrate, 47 uint32_t OnNetworkChanged(uint32_t target_bitrate,
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 // Returns bitrate allocated for the bitrate observer. 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
58 // the observer if BWE doesn't allow |min_bitrate_bps|.
59 // Returns bitrate allocated for |observer|.
57 int AddObserver(BitrateAllocatorObserver* observer, 60 int AddObserver(BitrateAllocatorObserver* observer,
58 uint32_t min_bitrate_bps, 61 uint32_t min_bitrate_bps,
59 uint32_t max_bitrate_bps); 62 uint32_t max_bitrate_bps,
63 bool enforce_min_bitrate);
60 64
61 void RemoveObserver(BitrateAllocatorObserver* observer); 65 void RemoveObserver(BitrateAllocatorObserver* observer);
62 66
67 private:
68 struct ObserverConfig {
69 ObserverConfig(BitrateAllocatorObserver* observer,
70 uint32_t min_bitrate_bps,
71 uint32_t max_bitrate_bps,
72 bool enforce_min_bitrate)
73 : observer(observer),
74 min_bitrate_bps(min_bitrate_bps),
75 max_bitrate_bps(max_bitrate_bps),
76 enforce_min_bitrate(enforce_min_bitrate) {}
77 BitrateAllocatorObserver* const observer;
78 uint32_t min_bitrate_bps;
79 uint32_t max_bitrate_bps;
80 bool enforce_min_bitrate;
81 };
82
63 // This method controls the behavior when the available bitrate is lower than 83 // This method controls the behavior when the available bitrate is lower than
64 // the minimum bitrate, or the sum of minimum bitrates. 84 // the minimum bitrate, or the sum of minimum bitrates.
65 // When true, the bitrate will never be set lower than the minimum bitrate(s). 85 // When true, the bitrate will never be set lower than the minimum bitrate(s).
66 // When false, the bitrate observers will be allocated rates up to their 86 // When false, the bitrate observers will be allocated rates up to their
67 // respective minimum bitrate, satisfying one observer after the other. 87 // respective minimum bitrate, satisfying one observer after the other.
68 void EnforceMinBitrate(bool enforce_min_bitrate); 88 void EnforceMinBitrate(bool enforce_min_bitrate)
89 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
69 90
70 private: 91 typedef std::list<ObserverConfig> ObserverConfigList;
71 struct BitrateConfiguration { 92 ObserverConfigList::iterator FindObserverConfig(
72 BitrateConfiguration(uint32_t min_bitrate, uint32_t max_bitrate)
73 : min_bitrate(min_bitrate), max_bitrate(max_bitrate) {}
74 uint32_t min_bitrate;
75 uint32_t max_bitrate;
76 };
77 struct ObserverConfiguration {
78 ObserverConfiguration(BitrateAllocatorObserver* observer, uint32_t bitrate)
79 : observer(observer), min_bitrate(bitrate) {}
80 BitrateAllocatorObserver* const observer;
81 uint32_t min_bitrate;
82 };
83 typedef std::pair<BitrateAllocatorObserver*, BitrateConfiguration>
84 BitrateObserverConfiguration;
85 typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList;
86 typedef std::multimap<uint32_t, ObserverConfiguration> ObserverSortingMap;
87 typedef std::map<BitrateAllocatorObserver*, int> ObserverBitrateMap;
88
89 BitrateObserverConfList::iterator FindObserverConfigurationPair(
90 const BitrateAllocatorObserver* observer) 93 const BitrateAllocatorObserver* observer)
91 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 94 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
92 ObserverBitrateMap AllocateBitrates() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 95
93 ObserverBitrateMap NormalRateAllocation(uint32_t bitrate, 96 typedef std::multimap<uint32_t, const ObserverConfig*> ObserverSortingMap;
97 typedef std::map<BitrateAllocatorObserver*, int> ObserverAllocation;
98
99 ObserverAllocation AllocateBitrates() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
100 ObserverAllocation NormalRateAllocation(uint32_t bitrate,
94 uint32_t sum_min_bitrates) 101 uint32_t sum_min_bitrates)
95 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 102 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
96 103
97 ObserverBitrateMap ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 104 ObserverAllocation ZeroRateAllocation() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
98 ObserverBitrateMap LowRateAllocation(uint32_t bitrate) 105 ObserverAllocation LowRateAllocation(uint32_t bitrate)
99 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 106 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
100 107
101 rtc::CriticalSection crit_sect_; 108 rtc::CriticalSection crit_sect_;
102 // Stored in a list to keep track of the insertion order. 109 // Stored in a list to keep track of the insertion order.
103 BitrateObserverConfList bitrate_observers_ GUARDED_BY(crit_sect_); 110 ObserverConfigList bitrate_observer_configs_;
104 bool bitrate_observers_modified_ GUARDED_BY(crit_sect_);
105 bool enforce_min_bitrate_ GUARDED_BY(crit_sect_); 111 bool enforce_min_bitrate_ GUARDED_BY(crit_sect_);
106 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); 112 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_);
107 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); 113 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_);
108 int64_t last_rtt_ GUARDED_BY(crit_sect_); 114 int64_t last_rtt_ GUARDED_BY(crit_sect_);
109 }; 115 };
110 } // namespace webrtc 116 } // namespace webrtc
111 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ 117 #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