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

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

Issue 2060403002: Add task queue to Call. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@move_getpadding
Patch Set: Revert changes to gypi. Created 4 years, 6 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
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 16 matching lines...) Expand all
27 // Require a bitrate increase of max(10%, 20kbps) to resume paused streams. 27 // Require a bitrate increase of max(10%, 20kbps) to resume paused streams.
28 const double kToggleFactor = 0.1; 28 const double kToggleFactor = 0.1;
29 const uint32_t kMinToggleBitrateBps = 20000; 29 const uint32_t kMinToggleBitrateBps = 20000;
30 30
31 BitrateAllocator::BitrateAllocator(LimitObserver* limit_observer) 31 BitrateAllocator::BitrateAllocator(LimitObserver* limit_observer)
32 : limit_observer_(limit_observer), 32 : limit_observer_(limit_observer),
33 bitrate_observer_configs_(), 33 bitrate_observer_configs_(),
34 last_bitrate_bps_(kDefaultBitrateBps), 34 last_bitrate_bps_(kDefaultBitrateBps),
35 last_non_zero_bitrate_bps_(kDefaultBitrateBps), 35 last_non_zero_bitrate_bps_(kDefaultBitrateBps),
36 last_fraction_loss_(0), 36 last_fraction_loss_(0),
37 last_rtt_(0) {} 37 last_rtt_(0) {
38 thread_checker_.DetachFromThread();
39 }
38 40
39 void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps, 41 void BitrateAllocator::OnNetworkChanged(uint32_t target_bitrate_bps,
40 uint8_t fraction_loss, 42 uint8_t fraction_loss,
41 int64_t rtt) { 43 int64_t rtt) {
42 rtc::CritScope lock(&crit_sect_); 44 RTC_DCHECK_RUN_ON(&thread_checker_);
43 last_bitrate_bps_ = target_bitrate_bps; 45 last_bitrate_bps_ = target_bitrate_bps;
44 last_non_zero_bitrate_bps_ = 46 last_non_zero_bitrate_bps_ =
45 target_bitrate_bps > 0 ? target_bitrate_bps : last_non_zero_bitrate_bps_; 47 target_bitrate_bps > 0 ? target_bitrate_bps : last_non_zero_bitrate_bps_;
46 last_fraction_loss_ = fraction_loss; 48 last_fraction_loss_ = fraction_loss;
47 last_rtt_ = rtt; 49 last_rtt_ = rtt;
48 50
49 ObserverAllocation allocation = AllocateBitrates(target_bitrate_bps); 51 ObserverAllocation allocation = AllocateBitrates(target_bitrate_bps);
50 for (const auto& kv : allocation) { 52 for (const auto& kv : allocation) {
51 kv.first->OnBitrateUpdated(kv.second, last_fraction_loss_, last_rtt_); 53 kv.first->OnBitrateUpdated(kv.second, last_fraction_loss_, last_rtt_);
52 } 54 }
53 last_allocation_ = allocation; 55 last_allocation_ = allocation;
54 } 56 }
55 57
56 int BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, 58 int BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer,
57 uint32_t min_bitrate_bps, 59 uint32_t min_bitrate_bps,
58 uint32_t max_bitrate_bps, 60 uint32_t max_bitrate_bps,
59 uint32_t pad_up_bitrate_bps, 61 uint32_t pad_up_bitrate_bps,
60 bool enforce_min_bitrate) { 62 bool enforce_min_bitrate) {
61 rtc::CritScope lock(&crit_sect_); 63 RTC_DCHECK_RUN_ON(&thread_checker_);
62 auto it = FindObserverConfig(observer); 64 auto it = FindObserverConfig(observer);
63 65
64 // Update settings if the observer already exists, create a new one otherwise. 66 // Update settings if the observer already exists, create a new one otherwise.
65 if (it != bitrate_observer_configs_.end()) { 67 if (it != bitrate_observer_configs_.end()) {
66 it->min_bitrate_bps = min_bitrate_bps; 68 it->min_bitrate_bps = min_bitrate_bps;
67 it->max_bitrate_bps = max_bitrate_bps; 69 it->max_bitrate_bps = max_bitrate_bps;
68 it->pad_up_bitrate_bps = pad_up_bitrate_bps; 70 it->pad_up_bitrate_bps = pad_up_bitrate_bps;
69 it->enforce_min_bitrate = enforce_min_bitrate; 71 it->enforce_min_bitrate = enforce_min_bitrate;
70 } else { 72 } else {
71 bitrate_observer_configs_.push_back( 73 bitrate_observer_configs_.push_back(
(...skipping 14 matching lines...) Expand all
86 allocation = AllocateBitrates(last_non_zero_bitrate_bps_); 88 allocation = AllocateBitrates(last_non_zero_bitrate_bps_);
87 observer->OnBitrateUpdated(0, last_fraction_loss_, last_rtt_); 89 observer->OnBitrateUpdated(0, last_fraction_loss_, last_rtt_);
88 } 90 }
89 UpdateAllocationLimits(); 91 UpdateAllocationLimits();
90 92
91 last_allocation_ = allocation; 93 last_allocation_ = allocation;
92 return allocation[observer]; 94 return allocation[observer];
93 } 95 }
94 96
95 void BitrateAllocator::UpdateAllocationLimits() { 97 void BitrateAllocator::UpdateAllocationLimits() {
98 RTC_DCHECK_RUN_ON(&thread_checker_);
96 uint32_t total_requested_padding_bitrate = 0; 99 uint32_t total_requested_padding_bitrate = 0;
97 uint32_t total_requested_min_bitrate = 0; 100 uint32_t total_requested_min_bitrate = 0;
98 101
99 {
100 rtc::CritScope lock(&crit_sect_);
101 for (const auto& config : bitrate_observer_configs_) { 102 for (const auto& config : bitrate_observer_configs_) {
102 if (config.enforce_min_bitrate) { 103 if (config.enforce_min_bitrate) {
103 total_requested_min_bitrate += config.min_bitrate_bps; 104 total_requested_min_bitrate += config.min_bitrate_bps;
104 } 105 }
105 total_requested_padding_bitrate += config.pad_up_bitrate_bps; 106 total_requested_padding_bitrate += config.pad_up_bitrate_bps;
106 } 107 }
107 }
108 108
109 limit_observer_->OnAllocationLimitsChanged(total_requested_min_bitrate, 109 limit_observer_->OnAllocationLimitsChanged(total_requested_min_bitrate,
110 total_requested_padding_bitrate); 110 total_requested_padding_bitrate);
111 } 111 }
112 112
113 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) { 113 void BitrateAllocator::RemoveObserver(BitrateAllocatorObserver* observer) {
114 { 114 RTC_DCHECK_RUN_ON(&thread_checker_);
115 rtc::CritScope lock(&crit_sect_); 115 auto it = FindObserverConfig(observer);
116 auto it = FindObserverConfig(observer); 116 if (it != bitrate_observer_configs_.end()) {
117 if (it != bitrate_observer_configs_.end()) { 117 bitrate_observer_configs_.erase(it);
118 bitrate_observer_configs_.erase(it);
119 } 118 }
tommi 2016/06/17 07:59:01 run git cl format
perkj_webrtc 2016/06/27 14:34:34 Done.
120 } 119
121 UpdateAllocationLimits(); 120 UpdateAllocationLimits();
122 } 121 }
123 122
124 BitrateAllocator::ObserverConfigList::iterator 123 BitrateAllocator::ObserverConfigList::iterator
125 BitrateAllocator::FindObserverConfig( 124 BitrateAllocator::FindObserverConfig(
126 const BitrateAllocatorObserver* observer) { 125 const BitrateAllocatorObserver* observer) {
127 for (auto it = bitrate_observer_configs_.begin(); 126 for (auto it = bitrate_observer_configs_.begin();
128 it != bitrate_observer_configs_.end(); ++it) { 127 it != bitrate_observer_configs_.end(); ++it) {
129 if (it->observer == observer) 128 if (it->observer == observer)
130 return it; 129 return it;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 uint32_t extra_bitrate_per_observer = (bitrate - sum_min_bitrates) / 313 uint32_t extra_bitrate_per_observer = (bitrate - sum_min_bitrates) /
315 static_cast<uint32_t>(bitrate_observer_configs_.size()); 314 static_cast<uint32_t>(bitrate_observer_configs_.size());
316 for (const auto& observer_config : bitrate_observer_configs_) { 315 for (const auto& observer_config : bitrate_observer_configs_) {
317 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < 316 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer <
318 MinBitrateWithHysteresis(observer_config)) 317 MinBitrateWithHysteresis(observer_config))
319 return false; 318 return false;
320 } 319 }
321 return true; 320 return true;
322 } 321 }
323 } // namespace webrtc 322 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/call/bitrate_allocator.h ('k') | webrtc/call/call.cc » ('j') | webrtc/call/call.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698