| Index: webrtc/call/bitrate_allocator.cc
|
| diff --git a/webrtc/call/bitrate_allocator.cc b/webrtc/call/bitrate_allocator.cc
|
| index cfb726adc91889be0589eb6d240841cbc98aed19..4331dae6745eeeb01dfe2266913f4687be408c55 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,56 @@ 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() <<
|
| + static_cast<const void*>(observer_config.observer)).str();
|
| + }
|
| + track_configs[observer_config.track_id] =
|
| + 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();
|
|
|
|
|