| OLD | NEW |
| 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 Loading... |
| 46 last_fraction_loss_ = fraction_loss; | 46 last_fraction_loss_ = fraction_loss; |
| 47 last_rtt_ = rtt; | 47 last_rtt_ = rtt; |
| 48 | 48 |
| 49 ObserverAllocation allocation = AllocateBitrates(target_bitrate_bps); | 49 ObserverAllocation allocation = AllocateBitrates(target_bitrate_bps); |
| 50 for (const auto& kv : allocation) { | 50 for (const auto& kv : allocation) { |
| 51 kv.first->OnBitrateUpdated(kv.second, last_fraction_loss_, last_rtt_); | 51 kv.first->OnBitrateUpdated(kv.second, last_fraction_loss_, last_rtt_); |
| 52 } | 52 } |
| 53 last_allocation_ = allocation; | 53 last_allocation_ = allocation; |
| 54 } | 54 } |
| 55 | 55 |
| 56 int BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, | 56 void BitrateAllocator::AddObserver(BitrateAllocatorObserver* observer, |
| 57 uint32_t min_bitrate_bps, | 57 uint32_t min_bitrate_bps, |
| 58 uint32_t max_bitrate_bps, | 58 uint32_t max_bitrate_bps, |
| 59 uint32_t pad_up_bitrate_bps, | 59 uint32_t pad_up_bitrate_bps, |
| 60 bool enforce_min_bitrate) { | 60 bool enforce_min_bitrate) { |
| 61 rtc::CritScope lock(&crit_sect_); | 61 rtc::CritScope lock(&crit_sect_); |
| 62 auto it = FindObserverConfig(observer); | 62 auto it = FindObserverConfig(observer); |
| 63 | 63 |
| 64 // Update settings if the observer already exists, create a new one otherwise. | 64 // Update settings if the observer already exists, create a new one otherwise. |
| 65 if (it != bitrate_observer_configs_.end()) { | 65 if (it != bitrate_observer_configs_.end()) { |
| 66 it->min_bitrate_bps = min_bitrate_bps; | 66 it->min_bitrate_bps = min_bitrate_bps; |
| 67 it->max_bitrate_bps = max_bitrate_bps; | 67 it->max_bitrate_bps = max_bitrate_bps; |
| 68 it->pad_up_bitrate_bps = pad_up_bitrate_bps; | 68 it->pad_up_bitrate_bps = pad_up_bitrate_bps; |
| 69 it->enforce_min_bitrate = enforce_min_bitrate; | 69 it->enforce_min_bitrate = enforce_min_bitrate; |
| 70 } else { | 70 } else { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 82 } else { | 82 } else { |
| 83 // Currently, an encoder is not allowed to produce frames. | 83 // Currently, an encoder is not allowed to produce frames. |
| 84 // But we still have to return the initial config bitrate + let the | 84 // But we still have to return the initial config bitrate + let the |
| 85 // observer know that it can not produce frames. | 85 // observer know that it can not produce frames. |
| 86 allocation = AllocateBitrates(last_non_zero_bitrate_bps_); | 86 allocation = AllocateBitrates(last_non_zero_bitrate_bps_); |
| 87 observer->OnBitrateUpdated(0, last_fraction_loss_, last_rtt_); | 87 observer->OnBitrateUpdated(0, last_fraction_loss_, last_rtt_); |
| 88 } | 88 } |
| 89 UpdateAllocationLimits(); | 89 UpdateAllocationLimits(); |
| 90 | 90 |
| 91 last_allocation_ = allocation; | 91 last_allocation_ = allocation; |
| 92 return allocation[observer]; | |
| 93 } | 92 } |
| 94 | 93 |
| 95 void BitrateAllocator::UpdateAllocationLimits() { | 94 void BitrateAllocator::UpdateAllocationLimits() { |
| 96 uint32_t total_requested_padding_bitrate = 0; | 95 uint32_t total_requested_padding_bitrate = 0; |
| 97 uint32_t total_requested_min_bitrate = 0; | 96 uint32_t total_requested_min_bitrate = 0; |
| 98 | 97 |
| 99 { | 98 { |
| 100 rtc::CritScope lock(&crit_sect_); | 99 rtc::CritScope lock(&crit_sect_); |
| 101 for (const auto& config : bitrate_observer_configs_) { | 100 for (const auto& config : bitrate_observer_configs_) { |
| 102 if (config.enforce_min_bitrate) { | 101 if (config.enforce_min_bitrate) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 114 { | 113 { |
| 115 rtc::CritScope lock(&crit_sect_); | 114 rtc::CritScope lock(&crit_sect_); |
| 116 auto it = FindObserverConfig(observer); | 115 auto it = FindObserverConfig(observer); |
| 117 if (it != bitrate_observer_configs_.end()) { | 116 if (it != bitrate_observer_configs_.end()) { |
| 118 bitrate_observer_configs_.erase(it); | 117 bitrate_observer_configs_.erase(it); |
| 119 } | 118 } |
| 120 } | 119 } |
| 121 UpdateAllocationLimits(); | 120 UpdateAllocationLimits(); |
| 122 } | 121 } |
| 123 | 122 |
| 123 int BitrateAllocator::GetStartBitrate(BitrateAllocatorObserver* observer) { |
| 124 rtc::CritScope lock(&crit_sect_); |
| 125 const auto& it = last_allocation_.find(observer); |
| 126 if (it != last_allocation_.end()) |
| 127 return it->second; |
| 128 |
| 129 // This is a new observer that has not yet been started. Assume that if it is |
| 130 // added, all observers would split the available bitrate evenly. |
| 131 return last_non_zero_bitrate_bps_ / |
| 132 static_cast<int>((bitrate_observer_configs_.size() + 1)); |
| 133 } |
| 134 |
| 124 BitrateAllocator::ObserverConfigList::iterator | 135 BitrateAllocator::ObserverConfigList::iterator |
| 125 BitrateAllocator::FindObserverConfig( | 136 BitrateAllocator::FindObserverConfig( |
| 126 const BitrateAllocatorObserver* observer) { | 137 const BitrateAllocatorObserver* observer) { |
| 127 for (auto it = bitrate_observer_configs_.begin(); | 138 for (auto it = bitrate_observer_configs_.begin(); |
| 128 it != bitrate_observer_configs_.end(); ++it) { | 139 it != bitrate_observer_configs_.end(); ++it) { |
| 129 if (it->observer == observer) | 140 if (it->observer == observer) |
| 130 return it; | 141 return it; |
| 131 } | 142 } |
| 132 return bitrate_observer_configs_.end(); | 143 return bitrate_observer_configs_.end(); |
| 133 } | 144 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 uint32_t extra_bitrate_per_observer = (bitrate - sum_min_bitrates) / | 325 uint32_t extra_bitrate_per_observer = (bitrate - sum_min_bitrates) / |
| 315 static_cast<uint32_t>(bitrate_observer_configs_.size()); | 326 static_cast<uint32_t>(bitrate_observer_configs_.size()); |
| 316 for (const auto& observer_config : bitrate_observer_configs_) { | 327 for (const auto& observer_config : bitrate_observer_configs_) { |
| 317 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < | 328 if (observer_config.min_bitrate_bps + extra_bitrate_per_observer < |
| 318 MinBitrateWithHysteresis(observer_config)) | 329 MinBitrateWithHysteresis(observer_config)) |
| 319 return false; | 330 return false; |
| 320 } | 331 } |
| 321 return true; | 332 return true; |
| 322 } | 333 } |
| 323 } // namespace webrtc | 334 } // namespace webrtc |
| OLD | NEW |