Index: webrtc/call/bitrate_allocator.cc |
diff --git a/webrtc/call/bitrate_allocator.cc b/webrtc/call/bitrate_allocator.cc |
index 2eb40b0670813c008b1b594541fc1e12147e47e9..ee7726c259af3cc30e0d13b18ed5da5d4ee80df9 100644 |
--- a/webrtc/call/bitrate_allocator.cc |
+++ b/webrtc/call/bitrate_allocator.cc |
@@ -56,7 +56,8 @@ BitrateAllocator::BitrateAllocator(LimitObserver* limit_observer) |
clock_(Clock::GetRealTimeClock()), |
last_bwe_log_time_(0), |
total_requested_padding_bitrate_(0), |
- total_requested_min_bitrate_(0) { |
+ total_requested_min_bitrate_(0), |
+ bitrate_allocation_strategy_(nullptr) { |
sequenced_checker_.Detach(); |
} |
@@ -224,6 +225,12 @@ int BitrateAllocator::GetStartBitrate(BitrateAllocatorObserver* observer) { |
} |
} |
+void BitrateAllocator::SetBitrateAllocationStrategy( |
+ rtc::BitrateAllocationStrategy* bitrate_allocation_strategy) { |
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
+ bitrate_allocation_strategy_ = bitrate_allocation_strategy; |
+} |
+ |
BitrateAllocator::ObserverConfigs::iterator |
BitrateAllocator::FindObserverConfig(const BitrateAllocatorObserver* observer) { |
RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
@@ -235,12 +242,57 @@ BitrateAllocator::FindObserverConfig(const BitrateAllocatorObserver* observer) { |
return bitrate_observer_configs_.end(); |
} |
+BitrateAllocator::ObserverConfigs::iterator |
+BitrateAllocator::FindObserverConfig(const std::string track_id) { |
+ RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
+ for (auto it = bitrate_observer_configs_.begin(); |
+ it != bitrate_observer_configs_.end(); ++it) { |
+ if (it->track_id == track_id) |
+ return it; |
+ } |
+ return bitrate_observer_configs_.end(); |
+} |
+ |
BitrateAllocator::ObserverAllocation BitrateAllocator::AllocateBitrates( |
uint32_t bitrate) { |
RTC_DCHECK_CALLED_SEQUENTIALLY(&sequenced_checker_); |
if (bitrate_observer_configs_.empty()) |
return ObserverAllocation(); |
+ if (bitrate_allocation_strategy_ != nullptr) { |
+ rtc::BitrateAllocationStrategy::TrackConfigs track_configs; |
+ for (auto& observer_config : bitrate_observer_configs_) { |
+ // The strategy will not be able to handle track without ID specifically |
+ // but it will be able to handle it in some general way. For example a |
+ // strategy giving priotiry to audio streams will consider a stream |
+ // without an ID as a non-audio streams and will allocate bitrate for it |
+ // after required minimum allocated for audio. |
+ if (observer_config.track_id.size() == 0) { |
+ observer_config.track_id = |
+ (std::stringstream() |
nisse-webrtc
2017/08/22 15:23:33
Converting a pointer to a string and using it as i
alexnarest
2017/08/31 18:40:26
Track ID should not be empty because strategies do
|
+ << static_cast<const void*>(observer_config.observer)) |
+ .str(); |
+ } |
+ track_configs[observer_config.track_id] = |
nisse-webrtc
2017/08/22 15:23:33
Could we rearrange the code to eliminate this copy
alexnarest
2017/08/31 18:40:26
Done.
|
+ rtc::BitrateAllocationStrategy::TrackConfig( |
+ observer_config.min_bitrate_bps, observer_config.max_bitrate_bps, |
+ observer_config.enforce_min_bitrate, observer_config.track_id); |
+ } |
+ rtc::BitrateAllocationStrategy::TrackAllocations track_allocations = |
+ bitrate_allocation_strategy_->AllocateBitrates(bitrate, track_configs); |
+ ObserverAllocation allocation; |
+ for (const auto& observer_config : bitrate_observer_configs_) { |
+ // The strategy should return allocation for all tracks. |
+ // In release builds still may be better to use zero allocation |
+ // rathen than crash |
+ RTC_DCHECK(track_allocations.find(observer_config.track_id) != |
+ track_allocations.end()); |
+ allocation[observer_config.observer] = |
+ track_allocations[observer_config.track_id]; |
+ } |
+ return allocation; |
+ } |
+ |
if (bitrate == 0) |
return ZeroRateAllocation(); |