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

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

Issue 1785283002: Move BitrateAllocator reference from ViEEncoder to VideoSendStream. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Comment changes. Created 4 years, 9 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 *
10 * Usage: this class will register multiple RtcpBitrateObserver's one at each
11 * RTCP module. It will aggregate the results and run one bandwidth estimation
12 * and push the result to the encoders via BitrateObserver(s).
13 */ 9 */
14 10
15 #ifndef WEBRTC_CALL_BITRATE_ALLOCATOR_H_ 11 #ifndef WEBRTC_CALL_BITRATE_ALLOCATOR_H_
16 #define WEBRTC_CALL_BITRATE_ALLOCATOR_H_ 12 #define WEBRTC_CALL_BITRATE_ALLOCATOR_H_
17 13
18 #include <list> 14 #include <list>
19 #include <map> 15 #include <map>
20 #include <utility> 16 #include <utility>
21 17
22 #include "webrtc/base/criticalsection.h" 18 #include "webrtc/base/criticalsection.h"
23 #include "webrtc/base/scoped_ptr.h" 19 #include "webrtc/base/scoped_ptr.h"
24 #include "webrtc/base/thread_annotations.h" 20 #include "webrtc/base/thread_annotations.h"
25 21
26 namespace webrtc { 22 namespace webrtc {
27 23
28 class BitrateObserver; 24 // Used by all send streams with adaptive bitrate, to get the currently
25 // allocated bitrate for the send stream. The current network properties are
26 // given at the same time, to let the send stream decide about possible loss
27 // protection.
28 class BitrateAllocatorObserver {
29 public:
30 virtual void OnBitrateUpdated(uint32_t bitrate_bps,
31 uint8_t fraction_loss,
32 int64_t rtt) = 0;
33 virtual ~BitrateAllocatorObserver() {}
34 };
29 35
36 // Usage: this class will register multiple RtcpBitrateObserver's one at each
37 // RTCP module. It will aggregate the results and run one bandwidth estimation
38 // and push the result to the encoders via BitrateAllocatorObserver(s).
30 class BitrateAllocator { 39 class BitrateAllocator {
31 public: 40 public:
32 BitrateAllocator(); 41 BitrateAllocator();
33 42
34 // Allocate target_bitrate across the registered BitrateObservers. 43 // Allocate target_bitrate across the registered BitrateAllocatorObservers.
35 // Returns actual bitrate allocated (might be higher than target_bitrate if 44 // Returns actual bitrate allocated (might be higher than target_bitrate if
36 // for instance EnforceMinBitrate() is enabled. 45 // for instance EnforceMinBitrate() is enabled.
37 uint32_t OnNetworkChanged(uint32_t target_bitrate, 46 uint32_t OnNetworkChanged(uint32_t target_bitrate,
38 uint8_t fraction_loss, 47 uint8_t fraction_loss,
39 int64_t rtt); 48 int64_t rtt);
40 49
41 // Set the start and max send bitrate used by the bandwidth management. 50 // Set the start and max send bitrate used by the bandwidth management.
42 // 51 //
43 // |observer| updates bitrates if already in use. 52 // |observer| updates bitrates if already in use.
44 // |min_bitrate_bps| = 0 equals no min bitrate. 53 // |min_bitrate_bps| = 0 equals no min bitrate.
45 // |max_bitrate_bps| = 0 equals no max bitrate. 54 // |max_bitrate_bps| = 0 equals no max bitrate.
46 // Returns bitrate allocated for the bitrate observer. 55 // Returns bitrate allocated for the bitrate observer.
47 int AddBitrateObserver(BitrateObserver* observer, 56 int AddObserver(BitrateAllocatorObserver* observer,
48 uint32_t min_bitrate_bps, 57 uint32_t min_bitrate_bps,
49 uint32_t max_bitrate_bps); 58 uint32_t max_bitrate_bps);
50 59
51 void RemoveBitrateObserver(BitrateObserver* observer); 60 void RemoveObserver(BitrateAllocatorObserver* observer);
52 61
53 void GetMinMaxBitrateSumBps(int* min_bitrate_sum_bps, 62 void GetMinMaxBitrateSumBps(int* min_bitrate_sum_bps,
54 int* max_bitrate_sum_bps) const; 63 int* max_bitrate_sum_bps) const;
55 64
56 // This method controls the behavior when the available bitrate is lower than 65 // This method controls the behavior when the available bitrate is lower than
57 // the minimum bitrate, or the sum of minimum bitrates. 66 // the minimum bitrate, or the sum of minimum bitrates.
58 // When true, the bitrate will never be set lower than the minimum bitrate(s). 67 // When true, the bitrate will never be set lower than the minimum bitrate(s).
59 // When false, the bitrate observers will be allocated rates up to their 68 // When false, the bitrate observers will be allocated rates up to their
60 // respective minimum bitrate, satisfying one observer after the other. 69 // respective minimum bitrate, satisfying one observer after the other.
61 void EnforceMinBitrate(bool enforce_min_bitrate); 70 void EnforceMinBitrate(bool enforce_min_bitrate);
62 71
63 private: 72 private:
64 struct BitrateConfiguration { 73 struct BitrateConfiguration {
65 BitrateConfiguration(uint32_t min_bitrate, uint32_t max_bitrate) 74 BitrateConfiguration(uint32_t min_bitrate, uint32_t max_bitrate)
66 : min_bitrate(min_bitrate), max_bitrate(max_bitrate) {} 75 : min_bitrate(min_bitrate), max_bitrate(max_bitrate) {}
67 uint32_t min_bitrate; 76 uint32_t min_bitrate;
68 uint32_t max_bitrate; 77 uint32_t max_bitrate;
69 }; 78 };
70 struct ObserverConfiguration { 79 struct ObserverConfiguration {
71 ObserverConfiguration(BitrateObserver* observer, uint32_t bitrate) 80 ObserverConfiguration(BitrateAllocatorObserver* observer, uint32_t bitrate)
72 : observer(observer), min_bitrate(bitrate) {} 81 : observer(observer), min_bitrate(bitrate) {}
73 BitrateObserver* const observer; 82 BitrateAllocatorObserver* const observer;
74 uint32_t min_bitrate; 83 uint32_t min_bitrate;
75 }; 84 };
76 typedef std::pair<BitrateObserver*, BitrateConfiguration> 85 typedef std::pair<BitrateAllocatorObserver*, BitrateConfiguration>
77 BitrateObserverConfiguration; 86 BitrateObserverConfiguration;
78 typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList; 87 typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList;
79 typedef std::multimap<uint32_t, ObserverConfiguration> ObserverSortingMap; 88 typedef std::multimap<uint32_t, ObserverConfiguration> ObserverSortingMap;
80 typedef std::map<BitrateObserver*, int> ObserverBitrateMap; 89 typedef std::map<BitrateAllocatorObserver*, int> ObserverBitrateMap;
81 90
82 BitrateObserverConfList::iterator FindObserverConfigurationPair( 91 BitrateObserverConfList::iterator FindObserverConfigurationPair(
83 const BitrateObserver* observer) EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 92 const BitrateAllocatorObserver* observer)
93 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
84 ObserverBitrateMap AllocateBitrates() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 94 ObserverBitrateMap AllocateBitrates() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
85 ObserverBitrateMap NormalRateAllocation(uint32_t bitrate, 95 ObserverBitrateMap NormalRateAllocation(uint32_t bitrate,
86 uint32_t sum_min_bitrates) 96 uint32_t sum_min_bitrates)
87 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 97 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
88 98
89 ObserverBitrateMap LowRateAllocation(uint32_t bitrate) 99 ObserverBitrateMap LowRateAllocation(uint32_t bitrate)
90 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_); 100 EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
91 101
92 rtc::CriticalSection crit_sect_; 102 rtc::CriticalSection crit_sect_;
93 // Stored in a list to keep track of the insertion order. 103 // Stored in a list to keep track of the insertion order.
94 BitrateObserverConfList bitrate_observers_ GUARDED_BY(crit_sect_); 104 BitrateObserverConfList bitrate_observers_ GUARDED_BY(crit_sect_);
95 bool bitrate_observers_modified_ GUARDED_BY(crit_sect_); 105 bool bitrate_observers_modified_ GUARDED_BY(crit_sect_);
96 bool enforce_min_bitrate_ GUARDED_BY(crit_sect_); 106 bool enforce_min_bitrate_ GUARDED_BY(crit_sect_);
97 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_); 107 uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_);
98 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_); 108 uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_);
99 int64_t last_rtt_ GUARDED_BY(crit_sect_); 109 int64_t last_rtt_ GUARDED_BY(crit_sect_);
100 }; 110 };
101 } // namespace webrtc 111 } // namespace webrtc
102 #endif // WEBRTC_CALL_BITRATE_ALLOCATOR_H_ 112 #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