aboutsummaryrefslogtreecommitdiff
path: root/webrtc/modules/bitrate_controller
diff options
context:
space:
mode:
Diffstat (limited to 'webrtc/modules/bitrate_controller')
-rw-r--r--webrtc/modules/bitrate_controller/BUILD.gn1
-rw-r--r--webrtc/modules/bitrate_controller/bitrate_allocator.cc190
-rw-r--r--webrtc/modules/bitrate_controller/bitrate_allocator_unittest.cc212
-rw-r--r--webrtc/modules/bitrate_controller/bitrate_controller.gypi2
-rw-r--r--webrtc/modules/bitrate_controller/bitrate_controller_impl.cc7
-rw-r--r--webrtc/modules/bitrate_controller/bitrate_controller_impl.h2
-rw-r--r--webrtc/modules/bitrate_controller/bitrate_controller_unittest.cc2
-rw-r--r--webrtc/modules/bitrate_controller/include/bitrate_allocator.h99
-rw-r--r--webrtc/modules/bitrate_controller/include/bitrate_controller.h7
-rw-r--r--webrtc/modules/bitrate_controller/include/mock/mock_bitrate_controller.h30
-rw-r--r--webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.cc44
-rw-r--r--webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h8
12 files changed, 80 insertions, 524 deletions
diff --git a/webrtc/modules/bitrate_controller/BUILD.gn b/webrtc/modules/bitrate_controller/BUILD.gn
index 4ef536b572..5e3741ba93 100644
--- a/webrtc/modules/bitrate_controller/BUILD.gn
+++ b/webrtc/modules/bitrate_controller/BUILD.gn
@@ -10,7 +10,6 @@ import("../../build/webrtc.gni")
source_set("bitrate_controller") {
sources = [
- "bitrate_allocator.cc",
"bitrate_controller_impl.cc",
"bitrate_controller_impl.h",
"include/bitrate_allocator.h",
diff --git a/webrtc/modules/bitrate_controller/bitrate_allocator.cc b/webrtc/modules/bitrate_controller/bitrate_allocator.cc
deleted file mode 100644
index 0aec528cde..0000000000
--- a/webrtc/modules/bitrate_controller/bitrate_allocator.cc
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- *
- */
-
-#include "webrtc/modules/bitrate_controller/include/bitrate_allocator.h"
-
-#include <algorithm>
-#include <utility>
-
-#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
-
-namespace webrtc {
-
-// Allow packets to be transmitted in up to 2 times max video bitrate if the
-// bandwidth estimate allows it.
-const int kTransmissionMaxBitrateMultiplier = 2;
-const int kDefaultBitrateBps = 300000;
-
-BitrateAllocator::BitrateAllocator()
- : crit_sect_(CriticalSectionWrapper::CreateCriticalSection()),
- bitrate_observers_(),
- enforce_min_bitrate_(true),
- last_bitrate_bps_(kDefaultBitrateBps),
- last_fraction_loss_(0),
- last_rtt_(0) {
-}
-
-
-void BitrateAllocator::OnNetworkChanged(uint32_t bitrate,
- uint8_t fraction_loss,
- int64_t rtt) {
- CriticalSectionScoped lock(crit_sect_.get());
- last_bitrate_bps_ = bitrate;
- last_fraction_loss_ = fraction_loss;
- last_rtt_ = rtt;
- ObserverBitrateMap allocation = AllocateBitrates();
- for (const auto& kv : allocation)
- kv.first->OnNetworkChanged(kv.second, last_fraction_loss_, last_rtt_);
-}
-
-BitrateAllocator::ObserverBitrateMap BitrateAllocator::AllocateBitrates() {
- if (bitrate_observers_.empty())
- return ObserverBitrateMap();
-
- uint32_t sum_min_bitrates = 0;
- for (const auto& observer : bitrate_observers_)
- sum_min_bitrates += observer.second.min_bitrate;
- if (last_bitrate_bps_ <= sum_min_bitrates)
- return LowRateAllocation(last_bitrate_bps_);
- else
- return NormalRateAllocation(last_bitrate_bps_, sum_min_bitrates);
-}
-
-int BitrateAllocator::AddBitrateObserver(BitrateObserver* observer,
- uint32_t min_bitrate_bps,
- uint32_t max_bitrate_bps) {
- CriticalSectionScoped lock(crit_sect_.get());
-
- BitrateObserverConfList::iterator it =
- FindObserverConfigurationPair(observer);
-
- // Allow the max bitrate to be exceeded for FEC and retransmissions.
- // TODO(holmer): We have to get rid of this hack as it makes it difficult to
- // properly allocate bitrate. The allocator should instead distribute any
- // extra bitrate after all streams have maxed out.
- max_bitrate_bps *= kTransmissionMaxBitrateMultiplier;
- if (it != bitrate_observers_.end()) {
- // Update current configuration.
- it->second.min_bitrate = min_bitrate_bps;
- it->second.max_bitrate = max_bitrate_bps;
- } else {
- // Add new settings.
- bitrate_observers_.push_back(BitrateObserverConfiguration(
- observer, BitrateConfiguration(min_bitrate_bps, max_bitrate_bps)));
- bitrate_observers_modified_ = true;
- }
-
- ObserverBitrateMap allocation = AllocateBitrates();
- int new_observer_bitrate_bps = 0;
- for (auto& kv : allocation) {
- kv.first->OnNetworkChanged(kv.second, last_fraction_loss_, last_rtt_);
- if (kv.first == observer)
- new_observer_bitrate_bps = kv.second;
- }
- return new_observer_bitrate_bps;
-}
-
-void BitrateAllocator::RemoveBitrateObserver(BitrateObserver* observer) {
- CriticalSectionScoped lock(crit_sect_.get());
- BitrateObserverConfList::iterator it =
- FindObserverConfigurationPair(observer);
- if (it != bitrate_observers_.end()) {
- bitrate_observers_.erase(it);
- bitrate_observers_modified_ = true;
- }
-}
-
-void BitrateAllocator::GetMinMaxBitrateSumBps(int* min_bitrate_sum_bps,
- int* max_bitrate_sum_bps) const {
- *min_bitrate_sum_bps = 0;
- *max_bitrate_sum_bps = 0;
-
- CriticalSectionScoped lock(crit_sect_.get());
- for (const auto& observer : bitrate_observers_) {
- *min_bitrate_sum_bps += observer.second.min_bitrate;
- *max_bitrate_sum_bps += observer.second.max_bitrate;
- }
-}
-
-BitrateAllocator::BitrateObserverConfList::iterator
-BitrateAllocator::FindObserverConfigurationPair(
- const BitrateObserver* observer) {
- for (auto it = bitrate_observers_.begin(); it != bitrate_observers_.end();
- ++it) {
- if (it->first == observer)
- return it;
- }
- return bitrate_observers_.end();
-}
-
-void BitrateAllocator::EnforceMinBitrate(bool enforce_min_bitrate) {
- CriticalSectionScoped lock(crit_sect_.get());
- enforce_min_bitrate_ = enforce_min_bitrate;
-}
-
-BitrateAllocator::ObserverBitrateMap BitrateAllocator::NormalRateAllocation(
- uint32_t bitrate,
- uint32_t sum_min_bitrates) {
- uint32_t number_of_observers = bitrate_observers_.size();
- uint32_t bitrate_per_observer =
- (bitrate - sum_min_bitrates) / number_of_observers;
- // Use map to sort list based on max bitrate.
- ObserverSortingMap list_max_bitrates;
- for (const auto& observer : bitrate_observers_) {
- list_max_bitrates.insert(std::pair<uint32_t, ObserverConfiguration>(
- observer.second.max_bitrate,
- ObserverConfiguration(observer.first, observer.second.min_bitrate)));
- }
- ObserverBitrateMap allocation;
- ObserverSortingMap::iterator max_it = list_max_bitrates.begin();
- while (max_it != list_max_bitrates.end()) {
- number_of_observers--;
- uint32_t observer_allowance =
- max_it->second.min_bitrate + bitrate_per_observer;
- if (max_it->first < observer_allowance) {
- // We have more than enough for this observer.
- // Carry the remainder forward.
- uint32_t remainder = observer_allowance - max_it->first;
- if (number_of_observers != 0) {
- bitrate_per_observer += remainder / number_of_observers;
- }
- allocation[max_it->second.observer] = max_it->first;
- } else {
- allocation[max_it->second.observer] = observer_allowance;
- }
- list_max_bitrates.erase(max_it);
- // Prepare next iteration.
- max_it = list_max_bitrates.begin();
- }
- return allocation;
-}
-
-BitrateAllocator::ObserverBitrateMap BitrateAllocator::LowRateAllocation(
- uint32_t bitrate) {
- ObserverBitrateMap allocation;
- if (enforce_min_bitrate_) {
- // Min bitrate to all observers.
- for (const auto& observer : bitrate_observers_)
- allocation[observer.first] = observer.second.min_bitrate;
- } else {
- // Allocate up to |min_bitrate| to one observer at a time, until
- // |bitrate| is depleted.
- uint32_t remainder = bitrate;
- for (const auto& observer : bitrate_observers_) {
- uint32_t allocated_bitrate =
- std::min(remainder, observer.second.min_bitrate);
- allocation[observer.first] = allocated_bitrate;
- remainder -= allocated_bitrate;
- }
- }
- return allocation;
-}
-} // namespace webrtc
diff --git a/webrtc/modules/bitrate_controller/bitrate_allocator_unittest.cc b/webrtc/modules/bitrate_controller/bitrate_allocator_unittest.cc
deleted file mode 100644
index 4fc7e83b5b..0000000000
--- a/webrtc/modules/bitrate_controller/bitrate_allocator_unittest.cc
+++ /dev/null
@@ -1,212 +0,0 @@
-/*
- * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#include <algorithm>
-#include <vector>
-
-#include "testing/gtest/include/gtest/gtest.h"
-#include "webrtc/modules/bitrate_controller/include/bitrate_allocator.h"
-#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
-
-namespace webrtc {
-
-class TestBitrateObserver : public BitrateObserver {
- public:
- TestBitrateObserver()
- : last_bitrate_(0), last_fraction_loss_(0), last_rtt_(0) {}
-
- virtual void OnNetworkChanged(uint32_t bitrate,
- uint8_t fraction_loss,
- int64_t rtt) {
- last_bitrate_ = bitrate;
- last_fraction_loss_ = fraction_loss;
- last_rtt_ = rtt;
- }
- uint32_t last_bitrate_;
- uint8_t last_fraction_loss_;
- int64_t last_rtt_;
-};
-
-class BitrateAllocatorTest : public ::testing::Test {
- protected:
- BitrateAllocatorTest() : allocator_(new BitrateAllocator()) {
- allocator_->OnNetworkChanged(300000u, 0, 0);
- }
- ~BitrateAllocatorTest() {}
-
- rtc::scoped_ptr<BitrateAllocator> allocator_;
-};
-
-TEST_F(BitrateAllocatorTest, UpdatingBitrateObserver) {
- TestBitrateObserver bitrate_observer;
- int start_bitrate =
- allocator_->AddBitrateObserver(&bitrate_observer, 100000, 1500000);
- EXPECT_EQ(300000, start_bitrate);
- allocator_->OnNetworkChanged(200000, 0, 0);
- EXPECT_EQ(200000u, bitrate_observer.last_bitrate_);
-
- // TODO(pbos): Expect capping to 1.5M instead of 3M when not boosting the max
- // bitrate for FEC/retransmissions (see TODO in BitrateAllocator).
- allocator_->OnNetworkChanged(4000000, 0, 0);
- EXPECT_EQ(3000000u, bitrate_observer.last_bitrate_);
- start_bitrate =
- allocator_->AddBitrateObserver(&bitrate_observer, 100000, 4000000);
- EXPECT_EQ(4000000, start_bitrate);
-
- start_bitrate =
- allocator_->AddBitrateObserver(&bitrate_observer, 100000, 1500000);
- EXPECT_EQ(3000000, start_bitrate);
- EXPECT_EQ(3000000u, bitrate_observer.last_bitrate_);
- allocator_->OnNetworkChanged(1500000, 0, 0);
- EXPECT_EQ(1500000u, bitrate_observer.last_bitrate_);
-}
-
-TEST_F(BitrateAllocatorTest, TwoBitrateObserversOneRtcpObserver) {
- TestBitrateObserver bitrate_observer_1;
- TestBitrateObserver bitrate_observer_2;
- int start_bitrate =
- allocator_->AddBitrateObserver(&bitrate_observer_1, 100000, 300000);
- EXPECT_EQ(300000, start_bitrate);
- start_bitrate =
- allocator_->AddBitrateObserver(&bitrate_observer_2, 200000, 300000);
- EXPECT_EQ(200000, start_bitrate);
-
- // Test too low start bitrate, hence lower than sum of min. Min bitrates will
- // be allocated to all observers.
- allocator_->OnNetworkChanged(200000, 0, 50);
- EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_);
- EXPECT_EQ(0, bitrate_observer_1.last_fraction_loss_);
- EXPECT_EQ(50, bitrate_observer_1.last_rtt_);
- EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_);
- EXPECT_EQ(0, bitrate_observer_2.last_fraction_loss_);
- EXPECT_EQ(50, bitrate_observer_2.last_rtt_);
-
- // Test a bitrate which should be distributed equally.
- allocator_->OnNetworkChanged(500000, 0, 50);
- const uint32_t kBitrateToShare = 500000 - 200000 - 100000;
- EXPECT_EQ(100000u + kBitrateToShare / 2, bitrate_observer_1.last_bitrate_);
- EXPECT_EQ(200000u + kBitrateToShare / 2, bitrate_observer_2.last_bitrate_);
-
- // Limited by 2x max bitrates since we leave room for FEC and retransmissions.
- allocator_->OnNetworkChanged(1500000, 0, 50);
- EXPECT_EQ(600000u, bitrate_observer_1.last_bitrate_);
- EXPECT_EQ(600000u, bitrate_observer_2.last_bitrate_);
-}
-
-class BitrateAllocatorTestNoEnforceMin : public ::testing::Test {
- protected:
- BitrateAllocatorTestNoEnforceMin() : allocator_(new BitrateAllocator()) {
- allocator_->EnforceMinBitrate(false);
- allocator_->OnNetworkChanged(300000u, 0, 0);
- }
- ~BitrateAllocatorTestNoEnforceMin() {}
-
- rtc::scoped_ptr<BitrateAllocator> allocator_;
-};
-
-// The following three tests verify that the EnforceMinBitrate() method works
-// as intended.
-TEST_F(BitrateAllocatorTestNoEnforceMin, OneBitrateObserver) {
- TestBitrateObserver bitrate_observer_1;
- int start_bitrate =
- allocator_->AddBitrateObserver(&bitrate_observer_1, 100000, 400000);
- EXPECT_EQ(300000, start_bitrate);
-
- // High REMB.
- allocator_->OnNetworkChanged(150000, 0, 0);
- EXPECT_EQ(150000u, bitrate_observer_1.last_bitrate_);
-
- // Low REMB.
- allocator_->OnNetworkChanged(10000, 0, 0);
- EXPECT_EQ(10000u, bitrate_observer_1.last_bitrate_);
-
- allocator_->RemoveBitrateObserver(&bitrate_observer_1);
-}
-
-TEST_F(BitrateAllocatorTestNoEnforceMin, ThreeBitrateObservers) {
- TestBitrateObserver bitrate_observer_1;
- TestBitrateObserver bitrate_observer_2;
- TestBitrateObserver bitrate_observer_3;
- // Set up the observers with min bitrates at 100000, 200000, and 300000.
- int start_bitrate =
- allocator_->AddBitrateObserver(&bitrate_observer_1, 100000, 400000);
- EXPECT_EQ(300000, start_bitrate);
-
- start_bitrate =
- allocator_->AddBitrateObserver(&bitrate_observer_2, 200000, 400000);
- EXPECT_EQ(200000, start_bitrate);
- EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_);
-
- start_bitrate =
- allocator_->AddBitrateObserver(&bitrate_observer_3, 300000, 400000);
- EXPECT_EQ(0, start_bitrate);
- EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_);
- EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_);
-
- // High REMB. Make sure the controllers get a fair share of the surplus
- // (i.e., what is left after each controller gets its min rate).
- allocator_->OnNetworkChanged(690000, 0, 0);
- // Verify that each observer gets its min rate (sum of min rates is 600000),
- // and that the remaining 90000 is divided equally among the three.
- uint32_t bitrate_to_share = 690000u - 100000u - 200000u - 300000u;
- EXPECT_EQ(100000u + bitrate_to_share / 3, bitrate_observer_1.last_bitrate_);
- EXPECT_EQ(200000u + bitrate_to_share / 3, bitrate_observer_2.last_bitrate_);
- EXPECT_EQ(300000u + bitrate_to_share / 3, bitrate_observer_3.last_bitrate_);
-
- // High REMB, but below the sum of min bitrates.
- allocator_->OnNetworkChanged(500000, 0, 0);
- // Verify that the first and second observers get their min bitrates, and the
- // third gets the remainder.
- EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_); // Min bitrate.
- EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_); // Min bitrate.
- EXPECT_EQ(200000u, bitrate_observer_3.last_bitrate_); // Remainder.
-
- // Low REMB.
- allocator_->OnNetworkChanged(10000, 0, 0);
- // Verify that the first observer gets all the rate, and the rest get zero.
- EXPECT_EQ(10000u, bitrate_observer_1.last_bitrate_);
- EXPECT_EQ(0u, bitrate_observer_2.last_bitrate_);
- EXPECT_EQ(0u, bitrate_observer_3.last_bitrate_);
-
- allocator_->RemoveBitrateObserver(&bitrate_observer_1);
- allocator_->RemoveBitrateObserver(&bitrate_observer_2);
- allocator_->RemoveBitrateObserver(&bitrate_observer_3);
-}
-
-TEST_F(BitrateAllocatorTest, ThreeBitrateObserversLowRembEnforceMin) {
- TestBitrateObserver bitrate_observer_1;
- TestBitrateObserver bitrate_observer_2;
- TestBitrateObserver bitrate_observer_3;
- int start_bitrate =
- allocator_->AddBitrateObserver(&bitrate_observer_1, 100000, 400000);
- EXPECT_EQ(300000, start_bitrate);
-
- start_bitrate =
- allocator_->AddBitrateObserver(&bitrate_observer_2, 200000, 400000);
- EXPECT_EQ(200000, start_bitrate);
- EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_);
-
- start_bitrate =
- allocator_->AddBitrateObserver(&bitrate_observer_3, 300000, 400000);
- EXPECT_EQ(300000, start_bitrate);
- EXPECT_EQ(100000, static_cast<int>(bitrate_observer_1.last_bitrate_));
- EXPECT_EQ(200000, static_cast<int>(bitrate_observer_2.last_bitrate_));
-
- // Low REMB. Verify that all observers still get their respective min bitrate.
- allocator_->OnNetworkChanged(1000, 0, 0);
- EXPECT_EQ(100000u, bitrate_observer_1.last_bitrate_); // Min cap.
- EXPECT_EQ(200000u, bitrate_observer_2.last_bitrate_); // Min cap.
- EXPECT_EQ(300000u, bitrate_observer_3.last_bitrate_); // Min cap.
-
- allocator_->RemoveBitrateObserver(&bitrate_observer_1);
- allocator_->RemoveBitrateObserver(&bitrate_observer_2);
- allocator_->RemoveBitrateObserver(&bitrate_observer_3);
-}
-} // namespace webrtc
diff --git a/webrtc/modules/bitrate_controller/bitrate_controller.gypi b/webrtc/modules/bitrate_controller/bitrate_controller.gypi
index 44c1b89ef2..3d86f2e32a 100644
--- a/webrtc/modules/bitrate_controller/bitrate_controller.gypi
+++ b/webrtc/modules/bitrate_controller/bitrate_controller.gypi
@@ -15,11 +15,9 @@
'<(webrtc_root)/system_wrappers/system_wrappers.gyp:system_wrappers',
],
'sources': [
- 'bitrate_allocator.cc',
'bitrate_controller_impl.cc',
'bitrate_controller_impl.h',
'include/bitrate_controller.h',
- 'include/bitrate_allocator.h',
'send_side_bandwidth_estimation.cc',
'send_side_bandwidth_estimation.h',
],
diff --git a/webrtc/modules/bitrate_controller/bitrate_controller_impl.cc b/webrtc/modules/bitrate_controller/bitrate_controller_impl.cc
index 8857ee4b4a..f8fd2bb987 100644
--- a/webrtc/modules/bitrate_controller/bitrate_controller_impl.cc
+++ b/webrtc/modules/bitrate_controller/bitrate_controller_impl.cc
@@ -14,7 +14,7 @@
#include <algorithm>
#include <utility>
-#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
+#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
namespace webrtc {
@@ -129,6 +129,11 @@ void BitrateControllerImpl::SetReservedBitrate(uint32_t reserved_bitrate_bps) {
MaybeTriggerOnNetworkChanged();
}
+void BitrateControllerImpl::SetEventLog(RtcEventLog* event_log) {
+ rtc::CritScope cs(&critsect_);
+ bandwidth_estimation_.SetEventLog(event_log);
+}
+
void BitrateControllerImpl::OnReceivedEstimatedBitrate(uint32_t bitrate) {
{
rtc::CritScope cs(&critsect_);
diff --git a/webrtc/modules/bitrate_controller/bitrate_controller_impl.h b/webrtc/modules/bitrate_controller/bitrate_controller_impl.h
index a33a0e6f04..b601899631 100644
--- a/webrtc/modules/bitrate_controller/bitrate_controller_impl.h
+++ b/webrtc/modules/bitrate_controller/bitrate_controller_impl.h
@@ -41,6 +41,8 @@ class BitrateControllerImpl : public BitrateController {
void SetReservedBitrate(uint32_t reserved_bitrate_bps) override;
+ void SetEventLog(RtcEventLog* event_log) override;
+
int64_t TimeUntilNextProcess() override;
int32_t Process() override;
diff --git a/webrtc/modules/bitrate_controller/bitrate_controller_unittest.cc b/webrtc/modules/bitrate_controller/bitrate_controller_unittest.cc
index 72831c78d6..2b9e589fbd 100644
--- a/webrtc/modules/bitrate_controller/bitrate_controller_unittest.cc
+++ b/webrtc/modules/bitrate_controller/bitrate_controller_unittest.cc
@@ -14,7 +14,7 @@
#include <vector>
#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
-#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
+#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
using webrtc::RtcpBandwidthObserver;
using webrtc::BitrateObserver;
diff --git a/webrtc/modules/bitrate_controller/include/bitrate_allocator.h b/webrtc/modules/bitrate_controller/include/bitrate_allocator.h
deleted file mode 100644
index 34b9ed5328..0000000000
--- a/webrtc/modules/bitrate_controller/include/bitrate_allocator.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- *
- * Usage: this class will register multiple RtcpBitrateObserver's one at each
- * RTCP module. It will aggregate the results and run one bandwidth estimation
- * and push the result to the encoders via BitrateObserver(s).
- */
-
-#ifndef WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_ALLOCATOR_H_
-#define WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_ALLOCATOR_H_
-
-#include <list>
-#include <map>
-#include <utility>
-
-#include "webrtc/base/scoped_ptr.h"
-#include "webrtc/base/thread_annotations.h"
-#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
-
-namespace webrtc {
-
-class BitrateObserver;
-
-class BitrateAllocator {
- public:
- BitrateAllocator();
-
- void OnNetworkChanged(uint32_t target_bitrate,
- uint8_t fraction_loss,
- int64_t rtt);
-
- // Set the start and max send bitrate used by the bandwidth management.
- //
- // |observer| updates bitrates if already in use.
- // |min_bitrate_bps| = 0 equals no min bitrate.
- // |max_bitrate_bps| = 0 equals no max bitrate.
- // Returns bitrate allocated for the bitrate observer.
- int AddBitrateObserver(BitrateObserver* observer,
- uint32_t min_bitrate_bps,
- uint32_t max_bitrate_bps);
-
- void RemoveBitrateObserver(BitrateObserver* observer);
-
- void GetMinMaxBitrateSumBps(int* min_bitrate_sum_bps,
- int* max_bitrate_sum_bps) const;
-
- // This method controls the behavior when the available bitrate is lower than
- // the minimum bitrate, or the sum of minimum bitrates.
- // When true, the bitrate will never be set lower than the minimum bitrate(s).
- // When false, the bitrate observers will be allocated rates up to their
- // respective minimum bitrate, satisfying one observer after the other.
- void EnforceMinBitrate(bool enforce_min_bitrate);
-
- private:
- struct BitrateConfiguration {
- BitrateConfiguration(uint32_t min_bitrate, uint32_t max_bitrate)
- : min_bitrate(min_bitrate), max_bitrate(max_bitrate) {}
- uint32_t min_bitrate;
- uint32_t max_bitrate;
- };
- struct ObserverConfiguration {
- ObserverConfiguration(BitrateObserver* observer, uint32_t bitrate)
- : observer(observer), min_bitrate(bitrate) {}
- BitrateObserver* const observer;
- uint32_t min_bitrate;
- };
- typedef std::pair<BitrateObserver*, BitrateConfiguration>
- BitrateObserverConfiguration;
- typedef std::list<BitrateObserverConfiguration> BitrateObserverConfList;
- typedef std::multimap<uint32_t, ObserverConfiguration> ObserverSortingMap;
- typedef std::map<BitrateObserver*, int> ObserverBitrateMap;
-
- BitrateObserverConfList::iterator FindObserverConfigurationPair(
- const BitrateObserver* observer) EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
- ObserverBitrateMap AllocateBitrates() EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
- ObserverBitrateMap NormalRateAllocation(uint32_t bitrate,
- uint32_t sum_min_bitrates)
- EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
-
- ObserverBitrateMap LowRateAllocation(uint32_t bitrate)
- EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
-
- rtc::scoped_ptr<CriticalSectionWrapper> crit_sect_;
- // Stored in a list to keep track of the insertion order.
- BitrateObserverConfList bitrate_observers_ GUARDED_BY(crit_sect_);
- bool bitrate_observers_modified_ GUARDED_BY(crit_sect_);
- bool enforce_min_bitrate_ GUARDED_BY(crit_sect_);
- uint32_t last_bitrate_bps_ GUARDED_BY(crit_sect_);
- uint8_t last_fraction_loss_ GUARDED_BY(crit_sect_);
- int64_t last_rtt_ GUARDED_BY(crit_sect_);
-};
-} // namespace webrtc
-#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_ALLOCATOR_H_
diff --git a/webrtc/modules/bitrate_controller/include/bitrate_controller.h b/webrtc/modules/bitrate_controller/include/bitrate_controller.h
index bb532886c7..d1eca8e0fe 100644
--- a/webrtc/modules/bitrate_controller/include/bitrate_controller.h
+++ b/webrtc/modules/bitrate_controller/include/bitrate_controller.h
@@ -17,12 +17,13 @@
#include <map>
-#include "webrtc/modules/interface/module.h"
-#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
+#include "webrtc/modules/include/module.h"
+#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
namespace webrtc {
class CriticalSectionWrapper;
+class RtcEventLog;
struct PacketInfo;
class BitrateObserver {
@@ -56,6 +57,8 @@ class BitrateController : public Module {
virtual void SetStartBitrate(int start_bitrate_bps) = 0;
virtual void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) = 0;
+ virtual void SetEventLog(RtcEventLog* event_log) = 0;
+
// Gets the available payload bandwidth in bits per second. Note that
// this bandwidth excludes packet headers.
virtual bool AvailableBandwidth(uint32_t* bandwidth) const = 0;
diff --git a/webrtc/modules/bitrate_controller/include/mock/mock_bitrate_controller.h b/webrtc/modules/bitrate_controller/include/mock/mock_bitrate_controller.h
new file mode 100644
index 0000000000..7a7d2e406b
--- /dev/null
+++ b/webrtc/modules/bitrate_controller/include/mock/mock_bitrate_controller.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_MOCK_MOCK_BITRATE_CONTROLLER_H_
+#define WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_MOCK_MOCK_BITRATE_CONTROLLER_H_
+
+#include "testing/gmock/include/gmock/gmock.h"
+#include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
+
+namespace webrtc {
+namespace test {
+
+class MockBitrateObserver : public BitrateObserver {
+ public:
+ MOCK_METHOD3(OnNetworkChanged,
+ void(uint32_t bitrate_bps,
+ uint8_t fraction_loss,
+ int64_t rtt_ms));
+};
+} // namespace test
+} // namespace webrtc
+
+#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_INCLUDE_MOCK_MOCK_BITRATE_CONTROLLER_H_
diff --git a/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.cc b/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.cc
index 9fa7b0dfc0..258c4d94de 100644
--- a/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.cc
+++ b/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.cc
@@ -13,9 +13,10 @@
#include <cmath>
#include "webrtc/base/checks.h"
+#include "webrtc/base/logging.h"
#include "webrtc/system_wrappers/include/field_trial.h"
-#include "webrtc/system_wrappers/include/logging.h"
#include "webrtc/system_wrappers/include/metrics.h"
+#include "webrtc/call/rtc_event_log.h"
namespace webrtc {
namespace {
@@ -59,7 +60,8 @@ SendSideBandwidthEstimation::SendSideBandwidthEstimation()
initially_lost_packets_(0),
bitrate_at_2_seconds_kbps_(0),
uma_update_state_(kNoUpdate),
- rampup_uma_stats_updated_(kNumUmaRampupMetrics, false) {}
+ rampup_uma_stats_updated_(kNumUmaRampupMetrics, false),
+ event_log_(nullptr) {}
SendSideBandwidthEstimation::~SendSideBandwidthEstimation() {}
@@ -144,8 +146,8 @@ void SendSideBandwidthEstimation::UpdateUmaStats(int64_t now_ms,
for (size_t i = 0; i < kNumUmaRampupMetrics; ++i) {
if (!rampup_uma_stats_updated_[i] &&
bitrate_kbps >= kUmaRampupMetrics[i].bitrate_kbps) {
- RTC_HISTOGRAM_COUNTS_100000(kUmaRampupMetrics[i].metric_name,
- now_ms - first_report_time_ms_);
+ RTC_HISTOGRAM_COUNTS_SPARSE_100000(kUmaRampupMetrics[i].metric_name,
+ now_ms - first_report_time_ms_);
rampup_uma_stats_updated_[i] = true;
}
}
@@ -154,22 +156,19 @@ void SendSideBandwidthEstimation::UpdateUmaStats(int64_t now_ms,
} else if (uma_update_state_ == kNoUpdate) {
uma_update_state_ = kFirstDone;
bitrate_at_2_seconds_kbps_ = bitrate_kbps;
- RTC_HISTOGRAM_COUNTS(
- "WebRTC.BWE.InitiallyLostPackets", initially_lost_packets_, 0, 100, 50);
- RTC_HISTOGRAM_COUNTS(
- "WebRTC.BWE.InitialRtt", static_cast<int>(rtt), 0, 2000, 50);
- RTC_HISTOGRAM_COUNTS("WebRTC.BWE.InitialBandwidthEstimate",
- bitrate_at_2_seconds_kbps_,
- 0,
- 2000,
- 50);
+ RTC_HISTOGRAM_COUNTS_SPARSE("WebRTC.BWE.InitiallyLostPackets",
+ initially_lost_packets_, 0, 100, 50);
+ RTC_HISTOGRAM_COUNTS_SPARSE("WebRTC.BWE.InitialRtt", static_cast<int>(rtt),
+ 0, 2000, 50);
+ RTC_HISTOGRAM_COUNTS_SPARSE("WebRTC.BWE.InitialBandwidthEstimate",
+ bitrate_at_2_seconds_kbps_, 0, 2000, 50);
} else if (uma_update_state_ == kFirstDone &&
now_ms - first_report_time_ms_ >= kBweConverganceTimeMs) {
uma_update_state_ = kDone;
int bitrate_diff_kbps =
std::max(bitrate_at_2_seconds_kbps_ - bitrate_kbps, 0);
- RTC_HISTOGRAM_COUNTS(
- "WebRTC.BWE.InitialVsConvergedDiff", bitrate_diff_kbps, 0, 2000, 50);
+ RTC_HISTOGRAM_COUNTS_SPARSE("WebRTC.BWE.InitialVsConvergedDiff",
+ bitrate_diff_kbps, 0, 2000, 50);
}
}
@@ -206,6 +205,11 @@ void SendSideBandwidthEstimation::UpdateEstimate(int64_t now_ms) {
// rates).
bitrate_ += 1000;
+ if (event_log_) {
+ event_log_->LogBwePacketLossEvent(
+ bitrate_, last_fraction_loss_,
+ expected_packets_since_last_loss_update_);
+ }
} else if (last_fraction_loss_ <= 26) {
// Loss between 2% - 10%: Do nothing.
} else {
@@ -224,6 +228,11 @@ void SendSideBandwidthEstimation::UpdateEstimate(int64_t now_ms) {
512.0);
has_decreased_since_last_fraction_loss_ = true;
}
+ if (event_log_) {
+ event_log_->LogBwePacketLossEvent(
+ bitrate_, last_fraction_loss_,
+ expected_packets_since_last_loss_update_);
+ }
}
}
bitrate_ = CapBitrateToThresholds(now_ms, bitrate_);
@@ -274,4 +283,9 @@ uint32_t SendSideBandwidthEstimation::CapBitrateToThresholds(
}
return bitrate;
}
+
+void SendSideBandwidthEstimation::SetEventLog(RtcEventLog* event_log) {
+ event_log_ = event_log;
+}
+
} // namespace webrtc
diff --git a/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h b/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h
index 40061d3ee7..7ffb42cb54 100644
--- a/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h
+++ b/webrtc/modules/bitrate_controller/send_side_bandwidth_estimation.h
@@ -15,10 +15,13 @@
#include <deque>
-#include "webrtc/modules/rtp_rtcp/interface/rtp_rtcp_defines.h"
+#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/system_wrappers/include/critical_section_wrapper.h"
namespace webrtc {
+
+class RtcEventLog;
+
class SendSideBandwidthEstimation {
public:
SendSideBandwidthEstimation();
@@ -42,6 +45,8 @@ class SendSideBandwidthEstimation {
void SetMinMaxBitrate(int min_bitrate, int max_bitrate);
int GetMinBitrate() const;
+ void SetEventLog(RtcEventLog* event_log);
+
private:
enum UmaState { kNoUpdate, kFirstDone, kDone };
@@ -81,6 +86,7 @@ class SendSideBandwidthEstimation {
int bitrate_at_2_seconds_kbps_;
UmaState uma_update_state_;
std::vector<bool> rampup_uma_stats_updated_;
+ RtcEventLog* event_log_;
};
} // namespace webrtc
#endif // WEBRTC_MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_