diff --git a/PRESUBMIT.py b/PRESUBMIT.py index dbbdb6aaa0..7c423c8666 100755 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -75,7 +75,6 @@ LEGACY_API_DIRS = ( 'common_audio/include', 'modules/audio_coding/include', 'modules/audio_processing/include', - 'modules/bitrate_controller/include', 'modules/congestion_controller/include', 'modules/include', 'modules/remote_bitrate_estimator/include', diff --git a/modules/bitrate_controller/BUILD.gn b/modules/bitrate_controller/BUILD.gn index 5f6d95a8d5..f5af0d148d 100644 --- a/modules/bitrate_controller/BUILD.gn +++ b/modules/bitrate_controller/BUILD.gn @@ -11,10 +11,6 @@ import("../../webrtc.gni") rtc_static_library("bitrate_controller") { visibility = [ "*" ] sources = [ - "bitrate_controller.cc", - "bitrate_controller_impl.cc", - "bitrate_controller_impl.h", - "include/bitrate_controller.h", "loss_based_bandwidth_estimation.cc", "loss_based_bandwidth_estimation.h", "send_side_bandwidth_estimation.cc", @@ -28,7 +24,6 @@ rtc_static_library("bitrate_controller") { } deps = [ - "..:module_api", "../../api/transport:network_control", "../../api/units:data_rate", "../../api/units:time_delta", @@ -36,14 +31,10 @@ rtc_static_library("bitrate_controller") { "../../logging:rtc_event_bwe", "../../logging:rtc_event_log_api", "../../rtc_base:checks", - "../../rtc_base:deprecation", - "../../rtc_base:rtc_base_approved", + "../../rtc_base:logging", "../../rtc_base/experiments:field_trial_parser", - "../../system_wrappers", "../../system_wrappers:field_trial", "../../system_wrappers:metrics", - "../congestion_controller/goog_cc:delay_based_bwe", - "../pacing", "../remote_bitrate_estimator", "../rtp_rtcp", "../rtp_rtcp:rtp_rtcp_format", @@ -57,7 +48,6 @@ if (rtc_include_tests) { testonly = true sources = [ - "bitrate_controller_unittest.cc", "send_side_bandwidth_estimation_unittest.cc", ] deps = [ @@ -65,14 +55,7 @@ if (rtc_include_tests) { "../../logging:mocks", "../../logging:rtc_event_bwe", "../../logging:rtc_event_log_api", - "../../system_wrappers", - "../../test:field_trial", "../../test:test_support", - "../congestion_controller/goog_cc:delay_based_bwe", - "../pacing", - "../pacing:mock_paced_sender", - "../remote_bitrate_estimator", - "../rtp_rtcp:rtp_rtcp_format", ] } } diff --git a/modules/bitrate_controller/bitrate_controller.cc b/modules/bitrate_controller/bitrate_controller.cc deleted file mode 100644 index 46e908be27..0000000000 --- a/modules/bitrate_controller/bitrate_controller.cc +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2018 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). - */ - -#include "modules/bitrate_controller/include/bitrate_controller.h" - -namespace webrtc { - -size_t BitrateObserver::pacer_queue_size_in_bytes() { - return 0; -} - -} // namespace webrtc diff --git a/modules/bitrate_controller/bitrate_controller_impl.cc b/modules/bitrate_controller/bitrate_controller_impl.cc deleted file mode 100644 index 9a57dc9d85..0000000000 --- a/modules/bitrate_controller/bitrate_controller_impl.cc +++ /dev/null @@ -1,292 +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 "modules/bitrate_controller/bitrate_controller_impl.h" - -#include -#include - -#include "modules/remote_bitrate_estimator/test/bwe_test_logging.h" -#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" -#include "rtc_base/checks.h" -#include "rtc_base/logging.h" - -namespace webrtc { -namespace { -absl::optional ToOptionalDataRate(int send_bitrate_bps) { - if (send_bitrate_bps > 0) - return DataRate::bps(send_bitrate_bps); - return absl::nullopt; -} -DataRate MaxRate(int max_bitrate_bps) { - if (max_bitrate_bps == -1) - return DataRate::Infinity(); - return DataRate::bps(max_bitrate_bps); -} -} // namespace -class BitrateControllerImpl::RtcpBandwidthObserverImpl - : public RtcpBandwidthObserver { - public: - explicit RtcpBandwidthObserverImpl(BitrateControllerImpl* owner) - : owner_(owner) {} - ~RtcpBandwidthObserverImpl() override = default; - // Received RTCP REMB or TMMBR. - void OnReceivedEstimatedBitrate(uint32_t bitrate) override { - owner_->OnReceivedEstimatedBitrate(bitrate); - } - // Received RTCP receiver block. - void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks, - int64_t rtt, - int64_t now_ms) override { - owner_->OnReceivedRtcpReceiverReport(report_blocks, rtt, now_ms); - } - - private: - BitrateControllerImpl* const owner_; -}; - -BitrateController* BitrateController::CreateBitrateController( - Clock* clock, - BitrateObserver* observer, - RtcEventLog* event_log) { - return new BitrateControllerImpl(clock, observer, event_log); -} - -BitrateController* BitrateController::CreateBitrateController( - Clock* clock, - RtcEventLog* event_log) { - return CreateBitrateController(clock, nullptr, event_log); -} - -BitrateControllerImpl::BitrateControllerImpl(Clock* clock, - BitrateObserver* observer, - RtcEventLog* event_log) - : clock_(clock), - observer_(observer), - last_bitrate_update_ms_(clock_->TimeInMilliseconds()), - event_log_(event_log), - bandwidth_estimation_(event_log), - last_bitrate_bps_(0), - last_fraction_loss_(0), - last_rtt_ms_(0) { - // This calls the observer_ if set, which means that the observer provided by - // the user must be ready to accept a bitrate update when it constructs the - // controller. We do this to avoid having to keep synchronized initial values - // in both the controller and the allocator. - MaybeTriggerOnNetworkChanged(); -} - -RtcpBandwidthObserver* BitrateControllerImpl::CreateRtcpBandwidthObserver() { - return new RtcpBandwidthObserverImpl(this); -} - -void BitrateControllerImpl::SetStartBitrate(int start_bitrate_bps) { - { - rtc::CritScope cs(&critsect_); - bandwidth_estimation_.SetSendBitrate( - DataRate::bps(start_bitrate_bps), - Timestamp::ms(clock_->TimeInMilliseconds())); - } - MaybeTriggerOnNetworkChanged(); -} - -void BitrateControllerImpl::SetMinMaxBitrate(int min_bitrate_bps, - int max_bitrate_bps) { - { - rtc::CritScope cs(&critsect_); - bandwidth_estimation_.SetMinMaxBitrate(DataRate::bps(min_bitrate_bps), - DataRate::bps(max_bitrate_bps)); - } - MaybeTriggerOnNetworkChanged(); -} - -void BitrateControllerImpl::SetBitrates(int start_bitrate_bps, - int min_bitrate_bps, - int max_bitrate_bps) { - { - rtc::CritScope cs(&critsect_); - bandwidth_estimation_.SetBitrates( - ToOptionalDataRate(start_bitrate_bps), DataRate::bps(min_bitrate_bps), - MaxRate(max_bitrate_bps), Timestamp::ms(clock_->TimeInMilliseconds())); - } - MaybeTriggerOnNetworkChanged(); -} - -void BitrateControllerImpl::ResetBitrates(int bitrate_bps, - int min_bitrate_bps, - int max_bitrate_bps) { - { - rtc::CritScope cs(&critsect_); - bandwidth_estimation_ = SendSideBandwidthEstimation(event_log_); - bandwidth_estimation_.SetBitrates( - ToOptionalDataRate(bitrate_bps), DataRate::bps(min_bitrate_bps), - MaxRate(max_bitrate_bps), Timestamp::ms(clock_->TimeInMilliseconds())); - } - MaybeTriggerOnNetworkChanged(); -} - -// This is called upon reception of REMB or TMMBR. -void BitrateControllerImpl::OnReceivedEstimatedBitrate(uint32_t bitrate) { - { - rtc::CritScope cs(&critsect_); - bandwidth_estimation_.UpdateReceiverEstimate( - Timestamp::ms(clock_->TimeInMilliseconds()), DataRate::bps(bitrate)); - BWE_TEST_LOGGING_PLOT(1, "REMB_kbps", clock_->TimeInMilliseconds(), - bitrate / 1000); - } - MaybeTriggerOnNetworkChanged(); -} - -void BitrateControllerImpl::OnDelayBasedBweResult( - const DelayBasedBwe::Result& result) { - if (!result.updated) - return; - { - rtc::CritScope cs(&critsect_); - if (result.probe) { - bandwidth_estimation_.SetSendBitrate( - result.target_bitrate, Timestamp::ms(clock_->TimeInMilliseconds())); - } - // Since SetSendBitrate now resets the delay-based estimate, we have to call - // UpdateDelayBasedEstimate after SetSendBitrate. - bandwidth_estimation_.UpdateDelayBasedEstimate( - Timestamp::ms(clock_->TimeInMilliseconds()), result.target_bitrate); - } - MaybeTriggerOnNetworkChanged(); -} - -int64_t BitrateControllerImpl::TimeUntilNextProcess() { - const int64_t kBitrateControllerUpdateIntervalMs = 25; - rtc::CritScope cs(&critsect_); - int64_t time_since_update_ms = - clock_->TimeInMilliseconds() - last_bitrate_update_ms_; - return std::max( - kBitrateControllerUpdateIntervalMs - time_since_update_ms, 0); -} - -void BitrateControllerImpl::Process() { - { - rtc::CritScope cs(&critsect_); - bandwidth_estimation_.UpdateEstimate( - Timestamp::ms(clock_->TimeInMilliseconds())); - } - MaybeTriggerOnNetworkChanged(); - last_bitrate_update_ms_ = clock_->TimeInMilliseconds(); -} - -void BitrateControllerImpl::OnReceivedRtcpReceiverReport( - const ReportBlockList& report_blocks, - int64_t rtt, - int64_t now_ms) { - if (report_blocks.empty()) - return; - - { - rtc::CritScope cs(&critsect_); - int fraction_lost_aggregate = 0; - int total_number_of_packets = 0; - - // Compute the a weighted average of the fraction loss from all report - // blocks. - for (const RTCPReportBlock& report_block : report_blocks) { - std::map::iterator seq_num_it = - ssrc_to_last_received_extended_high_seq_num_.find( - report_block.source_ssrc); - - int number_of_packets = 0; - if (seq_num_it != ssrc_to_last_received_extended_high_seq_num_.end()) { - number_of_packets = - report_block.extended_highest_sequence_number - seq_num_it->second; - } - - fraction_lost_aggregate += number_of_packets * report_block.fraction_lost; - total_number_of_packets += number_of_packets; - - // Update last received for this SSRC. - ssrc_to_last_received_extended_high_seq_num_[report_block.source_ssrc] = - report_block.extended_highest_sequence_number; - } - if (total_number_of_packets < 0) { - RTC_LOG(LS_WARNING) - << "Received report block where extended high sequence " - "number goes backwards, ignoring."; - return; - } - if (total_number_of_packets == 0) - fraction_lost_aggregate = 0; - else - fraction_lost_aggregate = - (fraction_lost_aggregate + total_number_of_packets / 2) / - total_number_of_packets; - if (fraction_lost_aggregate > 255) - return; - - RTC_DCHECK_GE(total_number_of_packets, 0); - - bandwidth_estimation_.UpdateReceiverBlock( - fraction_lost_aggregate, TimeDelta::ms(rtt), total_number_of_packets, - Timestamp::ms(now_ms)); - } - MaybeTriggerOnNetworkChanged(); -} - -void BitrateControllerImpl::MaybeTriggerOnNetworkChanged() { - if (!observer_) - return; - - uint32_t bitrate_bps; - uint8_t fraction_loss; - int64_t rtt; - - if (GetNetworkParameters(&bitrate_bps, &fraction_loss, &rtt)) - observer_->OnNetworkChanged(bitrate_bps, fraction_loss, rtt); -} - -bool BitrateControllerImpl::GetNetworkParameters(uint32_t* bitrate, - uint8_t* fraction_loss, - int64_t* rtt) { - rtc::CritScope cs(&critsect_); - int current_bitrate; - bandwidth_estimation_.CurrentEstimate(¤t_bitrate, fraction_loss, rtt); - *bitrate = current_bitrate; - - bool new_bitrate = false; - if (*bitrate != last_bitrate_bps_ || *fraction_loss != last_fraction_loss_ || - *rtt != last_rtt_ms_) { - last_bitrate_bps_ = *bitrate; - last_fraction_loss_ = *fraction_loss; - last_rtt_ms_ = *rtt; - new_bitrate = true; - } - - BWE_TEST_LOGGING_PLOT(1, "fraction_loss_%", clock_->TimeInMilliseconds(), - (last_fraction_loss_ * 100) / 256); - BWE_TEST_LOGGING_PLOT(1, "rtt_ms", clock_->TimeInMilliseconds(), - last_rtt_ms_); - BWE_TEST_LOGGING_PLOT(1, "Target_bitrate_kbps", clock_->TimeInMilliseconds(), - last_bitrate_bps_ / 1000); - - return new_bitrate; -} - -bool BitrateControllerImpl::AvailableBandwidth(uint32_t* bandwidth) const { - rtc::CritScope cs(&critsect_); - int bitrate; - uint8_t fraction_loss; - int64_t rtt; - bandwidth_estimation_.CurrentEstimate(&bitrate, &fraction_loss, &rtt); - if (bitrate > 0) { - *bandwidth = bitrate; - return true; - } - return false; -} -} // namespace webrtc diff --git a/modules/bitrate_controller/bitrate_controller_impl.h b/modules/bitrate_controller/bitrate_controller_impl.h deleted file mode 100644 index 28dcc03f99..0000000000 --- a/modules/bitrate_controller/bitrate_controller_impl.h +++ /dev/null @@ -1,103 +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. - * - * 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 encoder via VideoEncoderCallback. - */ - -#ifndef MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_ -#define MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_ - -#include "modules/bitrate_controller/include/bitrate_controller.h" - -#include -#include -#include -#include - -#include "modules/bitrate_controller/send_side_bandwidth_estimation.h" -#include "rtc_base/constructor_magic.h" -#include "rtc_base/critical_section.h" - -namespace webrtc { - -class BitrateControllerImpl : public BitrateController { - public: - // TODO(perkj): BitrateObserver has been deprecated and is not used in WebRTC. - // |observer| is left for project that is not yet updated. - BitrateControllerImpl(Clock* clock, - BitrateObserver* observer, - RtcEventLog* event_log); - virtual ~BitrateControllerImpl() {} - - bool AvailableBandwidth(uint32_t* bandwidth) const override; - - RTC_DEPRECATED RtcpBandwidthObserver* CreateRtcpBandwidthObserver() override; - - // Deprecated - void SetStartBitrate(int start_bitrate_bps) override; - // Deprecated - void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) override; - - void SetBitrates(int start_bitrate_bps, - int min_bitrate_bps, - int max_bitrate_bps) override; - - void ResetBitrates(int bitrate_bps, - int min_bitrate_bps, - int max_bitrate_bps) override; - - // Returns true if the parameters have changed since the last call. - bool GetNetworkParameters(uint32_t* bitrate, - uint8_t* fraction_loss, - int64_t* rtt) override; - - void OnDelayBasedBweResult(const DelayBasedBwe::Result& result) override; - - int64_t TimeUntilNextProcess() override; - void Process() override; - - private: - class RtcpBandwidthObserverImpl; - - // Called by BitrateObserver's direct from the RTCP module. - // Implements RtcpBandwidthObserver. - void OnReceivedEstimatedBitrate(uint32_t bitrate) override; - - void OnReceivedRtcpReceiverReport(const ReportBlockList& report_blocks, - int64_t rtt, - int64_t now_ms) override; - - // Deprecated - void MaybeTriggerOnNetworkChanged(); - - void OnNetworkChanged(uint32_t bitrate, - uint8_t fraction_loss, // 0 - 255. - int64_t rtt) RTC_EXCLUSIVE_LOCKS_REQUIRED(critsect_); - - // Used by process thread. - Clock* const clock_; - BitrateObserver* const observer_; - int64_t last_bitrate_update_ms_; - RtcEventLog* const event_log_; - - rtc::CriticalSection critsect_; - std::map ssrc_to_last_received_extended_high_seq_num_ - RTC_GUARDED_BY(critsect_); - SendSideBandwidthEstimation bandwidth_estimation_ RTC_GUARDED_BY(critsect_); - - uint32_t last_bitrate_bps_ RTC_GUARDED_BY(critsect_); - uint8_t last_fraction_loss_ RTC_GUARDED_BY(critsect_); - int64_t last_rtt_ms_ RTC_GUARDED_BY(critsect_); - - RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(BitrateControllerImpl); -}; -} // namespace webrtc -#endif // MODULES_BITRATE_CONTROLLER_BITRATE_CONTROLLER_IMPL_H_ diff --git a/modules/bitrate_controller/bitrate_controller_unittest.cc b/modules/bitrate_controller/bitrate_controller_unittest.cc deleted file mode 100644 index 0f8621048f..0000000000 --- a/modules/bitrate_controller/bitrate_controller_unittest.cc +++ /dev/null @@ -1,461 +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 -#include - -#include "logging/rtc_event_log/mock/mock_rtc_event_log.h" -#include "modules/bitrate_controller/include/bitrate_controller.h" -#include "modules/congestion_controller/goog_cc/delay_based_bwe.h" -#include "modules/pacing/paced_sender.h" -#include "modules/remote_bitrate_estimator/include/bwe_defines.h" -#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" -#include "system_wrappers/include/clock.h" -#include "test/field_trial.h" -#include "test/gmock.h" -#include "test/gtest.h" - -using ::testing::Exactly; -using ::testing::Return; - -using webrtc::BitrateController; -using webrtc::BitrateObserver; -using webrtc::PacedSender; -using webrtc::RtcpBandwidthObserver; - -uint8_t WeightedLoss(int num_packets1, - uint8_t fraction_loss1, - int num_packets2, - uint8_t fraction_loss2) { - int weighted_sum = - num_packets1 * fraction_loss1 + num_packets2 * fraction_loss2; - int total_num_packets = num_packets1 + num_packets2; - return (weighted_sum + total_num_packets / 2) / total_num_packets; -} - -webrtc::RTCPReportBlock CreateReportBlock( - uint32_t remote_ssrc, - uint32_t source_ssrc, - uint8_t fraction_lost, - uint32_t extended_high_sequence_number) { - return webrtc::RTCPReportBlock(remote_ssrc, source_ssrc, fraction_lost, 0, - extended_high_sequence_number, 0, 0, 0); -} - -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_ = static_cast(bitrate); - last_fraction_loss_ = fraction_loss; - last_rtt_ = rtt; - } - int last_bitrate_; - uint8_t last_fraction_loss_; - int64_t last_rtt_; -}; - -class BitrateControllerTest : public ::testing::Test { - protected: - BitrateControllerTest() : clock_(0) {} - ~BitrateControllerTest() {} - - virtual void SetUp() { - controller_.reset(BitrateController::CreateBitrateController( - &clock_, &bitrate_observer_, &event_log_)); - controller_->SetStartBitrate(kStartBitrateBps); - EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); - controller_->SetMinMaxBitrate(kMinBitrateBps, kMaxBitrateBps); - EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); - bandwidth_observer_ = controller_.get(); - } - - virtual void TearDown() {} - - const int kMinBitrateBps = 100000; - const int kStartBitrateBps = 200000; - const int kMaxBitrateBps = 300000; - - const int kDefaultMinBitrateBps = 10000; - const int kDefaultMaxBitrateBps = 1000000000; - - webrtc::SimulatedClock clock_; - TestBitrateObserver bitrate_observer_; - std::unique_ptr controller_; - RtcpBandwidthObserver* bandwidth_observer_; - ::testing::NiceMock event_log_; -}; - -TEST_F(BitrateControllerTest, DefaultMinMaxBitrate) { - // Receive successively lower REMBs, verify the reserved bitrate is deducted. - controller_->SetMinMaxBitrate(0, 0); - EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); - bandwidth_observer_->OnReceivedEstimatedBitrate(kDefaultMinBitrateBps / 2); - EXPECT_EQ(webrtc::congestion_controller::GetMinBitrateBps(), - bitrate_observer_.last_bitrate_); - bandwidth_observer_->OnReceivedEstimatedBitrate(2 * kDefaultMaxBitrateBps); - clock_.AdvanceTimeMilliseconds(1000); - controller_->Process(); - EXPECT_EQ(kDefaultMaxBitrateBps, bitrate_observer_.last_bitrate_); -} - -TEST_F(BitrateControllerTest, OneBitrateObserverOneRtcpObserver) { - // First REMB applies immediately. - int64_t time_ms = 1001; - webrtc::ReportBlockList report_blocks; - report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); - bandwidth_observer_->OnReceivedEstimatedBitrate(200000); - EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); - EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); - EXPECT_EQ(0, bitrate_observer_.last_rtt_); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - report_blocks.clear(); - time_ms += 2000; - - // Receive a high remb, test bitrate inc. - bandwidth_observer_->OnReceivedEstimatedBitrate(400000); - - // Test bitrate increase 8% per second. - report_blocks.push_back(CreateReportBlock(1, 2, 0, 21)); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - EXPECT_EQ(217000, bitrate_observer_.last_bitrate_); - EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); - EXPECT_EQ(50, bitrate_observer_.last_rtt_); - time_ms += 1000; - - report_blocks.clear(); - report_blocks.push_back(CreateReportBlock(1, 2, 0, 41)); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - EXPECT_EQ(235360, bitrate_observer_.last_bitrate_); - EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); - EXPECT_EQ(50, bitrate_observer_.last_rtt_); - time_ms += 1000; - - report_blocks.clear(); - report_blocks.push_back(CreateReportBlock(1, 2, 0, 61)); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - EXPECT_EQ(255189, bitrate_observer_.last_bitrate_); - time_ms += 1000; - - report_blocks.clear(); - report_blocks.push_back(CreateReportBlock(1, 2, 0, 81)); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - EXPECT_EQ(276604, bitrate_observer_.last_bitrate_); - time_ms += 1000; - - report_blocks.clear(); - report_blocks.push_back(CreateReportBlock(1, 2, 0, 101)); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - EXPECT_EQ(299732, bitrate_observer_.last_bitrate_); - time_ms += 1000; - - // Reach max cap. - report_blocks.clear(); - report_blocks.push_back(CreateReportBlock(1, 2, 0, 121)); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - EXPECT_EQ(300000, bitrate_observer_.last_bitrate_); - time_ms += 1000; - - report_blocks.clear(); - report_blocks.push_back(CreateReportBlock(1, 2, 0, 141)); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - EXPECT_EQ(300000, bitrate_observer_.last_bitrate_); - - // Test that a low delay-based estimate limits the combined estimate. - webrtc::DelayBasedBwe::Result result(false, webrtc::DataRate::kbps(280)); - controller_->OnDelayBasedBweResult(result); - EXPECT_EQ(280000, bitrate_observer_.last_bitrate_); - - // Test that a low REMB limits the combined estimate. - bandwidth_observer_->OnReceivedEstimatedBitrate(250000); - EXPECT_EQ(250000, bitrate_observer_.last_bitrate_); - EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); - EXPECT_EQ(50, bitrate_observer_.last_rtt_); - - bandwidth_observer_->OnReceivedEstimatedBitrate(1000); - EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); -} - -TEST_F(BitrateControllerTest, OneBitrateObserverTwoRtcpObservers) { - const uint32_t kSenderSsrc1 = 1; - const uint32_t kSenderSsrc2 = 2; - const uint32_t kMediaSsrc1 = 3; - const uint32_t kMediaSsrc2 = 4; - - int64_t time_ms = 1; - webrtc::ReportBlockList report_blocks; - report_blocks = {CreateReportBlock(kSenderSsrc1, kMediaSsrc1, 0, 1)}; - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - time_ms += 500; - - RtcpBandwidthObserver* second_bandwidth_observer = controller_.get(); - report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 21)}; - second_bandwidth_observer->OnReceivedRtcpReceiverReport(report_blocks, 100, - time_ms); - - // Test start bitrate. - EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); - EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); - EXPECT_EQ(100, bitrate_observer_.last_rtt_); - time_ms += 500; - - // Test bitrate increase 8% per second. - report_blocks = {CreateReportBlock(kSenderSsrc1, kMediaSsrc1, 0, 21)}; - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - time_ms += 500; - - report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 21)}; - second_bandwidth_observer->OnReceivedRtcpReceiverReport(report_blocks, 100, - time_ms); - EXPECT_EQ(217000, bitrate_observer_.last_bitrate_); - EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); - EXPECT_EQ(100, bitrate_observer_.last_rtt_); - time_ms += 500; - - // Extra report should not change estimate. - report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 31)}; - second_bandwidth_observer->OnReceivedRtcpReceiverReport(report_blocks, 100, - time_ms); - EXPECT_EQ(217000, bitrate_observer_.last_bitrate_); - time_ms += 500; - - report_blocks = {CreateReportBlock(kSenderSsrc1, kMediaSsrc1, 0, 41)}; - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - EXPECT_EQ(235360, bitrate_observer_.last_bitrate_); - - // Second report should not change estimate. - report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 41)}; - second_bandwidth_observer->OnReceivedRtcpReceiverReport(report_blocks, 100, - time_ms); - EXPECT_EQ(235360, bitrate_observer_.last_bitrate_); - time_ms += 1000; - - // Reports from only one bandwidth observer is ok. - report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 61)}; - second_bandwidth_observer->OnReceivedRtcpReceiverReport(report_blocks, 50, - time_ms); - EXPECT_EQ(255189, bitrate_observer_.last_bitrate_); - time_ms += 1000; - - report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 81)}; - second_bandwidth_observer->OnReceivedRtcpReceiverReport(report_blocks, 50, - time_ms); - EXPECT_EQ(276604, bitrate_observer_.last_bitrate_); - time_ms += 1000; - - report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 121)}; - second_bandwidth_observer->OnReceivedRtcpReceiverReport(report_blocks, 50, - time_ms); - EXPECT_EQ(299732, bitrate_observer_.last_bitrate_); - time_ms += 1000; - - // Reach max cap. - report_blocks = {CreateReportBlock(kSenderSsrc2, kMediaSsrc2, 0, 141)}; - second_bandwidth_observer->OnReceivedRtcpReceiverReport(report_blocks, 50, - time_ms); - EXPECT_EQ(300000, bitrate_observer_.last_bitrate_); - - // Test that a low REMB trigger immediately. - // We don't care which bandwidth observer that delivers the REMB. - second_bandwidth_observer->OnReceivedEstimatedBitrate(250000); - EXPECT_EQ(250000, bitrate_observer_.last_bitrate_); - EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); - EXPECT_EQ(50, bitrate_observer_.last_rtt_); - - // Min cap. - bandwidth_observer_->OnReceivedEstimatedBitrate(1000); - EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); -} - -TEST_F(BitrateControllerTest, OneBitrateObserverMultipleReportBlocks) { - uint32_t sequence_number[2] = {0, 0xFF00}; - const int kStartBitrate = 200000; - const int kMinBitrate = 100000; - const int kMaxBitrate = 300000; - controller_->SetStartBitrate(kStartBitrate); - controller_->SetMinMaxBitrate(kMinBitrate, kMaxBitrate); - - // REMBs during the first 2 seconds apply immediately. - int64_t time_ms = 1001; - webrtc::ReportBlockList report_blocks; - report_blocks.push_back(CreateReportBlock(1, 2, 0, sequence_number[0])); - bandwidth_observer_->OnReceivedEstimatedBitrate(kStartBitrate); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - report_blocks.clear(); - time_ms += 2000; - - // Receive a high REMB, test bitrate increase. - bandwidth_observer_->OnReceivedEstimatedBitrate(400000); - - int last_bitrate = 0; - // Ramp up to max bitrate. - for (int i = 0; i < 7; ++i) { - report_blocks.push_back(CreateReportBlock(1, 2, 0, sequence_number[0])); - report_blocks.push_back(CreateReportBlock(1, 3, 0, sequence_number[1])); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, - time_ms); - EXPECT_GT(bitrate_observer_.last_bitrate_, last_bitrate); - EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); - EXPECT_EQ(50, bitrate_observer_.last_rtt_); - last_bitrate = bitrate_observer_.last_bitrate_; - time_ms += 1000; - sequence_number[0] += 20; - sequence_number[1] += 1; - report_blocks.clear(); - } - - EXPECT_EQ(kMaxBitrate, bitrate_observer_.last_bitrate_); - - // Packet loss on the first stream. Verify that bitrate decreases. - report_blocks.push_back(CreateReportBlock(1, 2, 50, sequence_number[0])); - report_blocks.push_back(CreateReportBlock(1, 3, 0, sequence_number[1])); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - EXPECT_LT(bitrate_observer_.last_bitrate_, last_bitrate); - EXPECT_EQ(WeightedLoss(20, 50, 1, 0), bitrate_observer_.last_fraction_loss_); - EXPECT_EQ(50, bitrate_observer_.last_rtt_); - last_bitrate = bitrate_observer_.last_bitrate_; - sequence_number[0] += 20; - sequence_number[1] += 20; - time_ms += 1000; - report_blocks.clear(); - - // Packet loss on the second stream. Verify that bitrate decreases. - report_blocks.push_back(CreateReportBlock(1, 2, 0, sequence_number[0])); - report_blocks.push_back(CreateReportBlock(1, 3, 75, sequence_number[1])); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - EXPECT_LT(bitrate_observer_.last_bitrate_, last_bitrate); - EXPECT_EQ(WeightedLoss(20, 0, 20, 75), bitrate_observer_.last_fraction_loss_); - EXPECT_EQ(50, bitrate_observer_.last_rtt_); - last_bitrate = bitrate_observer_.last_bitrate_; - sequence_number[0] += 20; - sequence_number[1] += 1; - time_ms += 1000; - report_blocks.clear(); - - // All packets lost on stream with few packets, no back-off. - report_blocks.push_back(CreateReportBlock(1, 2, 0, sequence_number[0])); - report_blocks.push_back(CreateReportBlock(1, 3, 255, sequence_number[1])); - bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); - EXPECT_EQ(bitrate_observer_.last_bitrate_, last_bitrate); - EXPECT_EQ(WeightedLoss(20, 0, 1, 255), bitrate_observer_.last_fraction_loss_); - EXPECT_EQ(50, bitrate_observer_.last_rtt_); - last_bitrate = bitrate_observer_.last_bitrate_; - sequence_number[0] += 20; - sequence_number[1] += 1; - report_blocks.clear(); -} - -TEST_F(BitrateControllerTest, TimeoutsWithoutFeedback) { - { - webrtc::test::ScopedFieldTrials override_field_trials( - "WebRTC-FeedbackTimeout/Enabled/"); - SetUp(); - int expected_bitrate_bps = 300000; - controller_->SetBitrates(300000, kDefaultMinBitrateBps, - kDefaultMaxBitrateBps); - - webrtc::ReportBlockList report_blocks; - report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); - bandwidth_observer_->OnReceivedRtcpReceiverReport( - report_blocks, 50, clock_.TimeInMilliseconds()); - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - clock_.AdvanceTimeMilliseconds(500); - - report_blocks.push_back(CreateReportBlock(1, 2, 0, 21)); - bandwidth_observer_->OnReceivedRtcpReceiverReport( - report_blocks, 50, clock_.TimeInMilliseconds()); - report_blocks.clear(); - expected_bitrate_bps = expected_bitrate_bps * 1.08 + 1000; - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - clock_.AdvanceTimeMilliseconds(1500); - - report_blocks.push_back(CreateReportBlock(1, 2, 0, 41)); - bandwidth_observer_->OnReceivedRtcpReceiverReport( - report_blocks, 50, clock_.TimeInMilliseconds()); - expected_bitrate_bps = expected_bitrate_bps * 1.08 + 1000; - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - clock_.AdvanceTimeMilliseconds(4000); - - // 4 seconds since feedback, expect increase. - controller_->Process(); - expected_bitrate_bps = expected_bitrate_bps * 1.08 + 1000; - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - clock_.AdvanceTimeMilliseconds(2000); - - // 6 seconds since feedback, expect no increase. - controller_->Process(); - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - clock_.AdvanceTimeMilliseconds(9001); - - // More than 15 seconds since feedback, expect decrease. - controller_->Process(); - expected_bitrate_bps *= 0.8; - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - clock_.AdvanceTimeMilliseconds(500); - - // Only one timeout every second. - controller_->Process(); - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - clock_.AdvanceTimeMilliseconds(501); - - // New timeout allowed. - controller_->Process(); - expected_bitrate_bps *= 0.8; - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - } -} - -TEST_F(BitrateControllerTest, StopIncreaseWithoutPacketReports) { - int expected_bitrate_bps = 300000; - controller_->SetBitrates(300000, kDefaultMinBitrateBps, - kDefaultMaxBitrateBps); - - webrtc::ReportBlockList report_blocks; - report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); - bandwidth_observer_->OnReceivedRtcpReceiverReport( - report_blocks, 50, clock_.TimeInMilliseconds()); - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - clock_.AdvanceTimeMilliseconds(500); - - report_blocks.push_back(CreateReportBlock(1, 2, 0, 21)); - bandwidth_observer_->OnReceivedRtcpReceiverReport( - report_blocks, 50, clock_.TimeInMilliseconds()); - report_blocks.clear(); - expected_bitrate_bps = expected_bitrate_bps * 1.08 + 1000; - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - clock_.AdvanceTimeMilliseconds(1500); - - // 1.2 seconds without packets reported as received, no increase. - report_blocks.push_back(CreateReportBlock(1, 2, 0, 21)); - bandwidth_observer_->OnReceivedRtcpReceiverReport( - report_blocks, 50, clock_.TimeInMilliseconds()); - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - clock_.AdvanceTimeMilliseconds(1000); - - // 5 packets reported as received since last, too few, no increase. - report_blocks.push_back(CreateReportBlock(1, 2, 0, 26)); - bandwidth_observer_->OnReceivedRtcpReceiverReport( - report_blocks, 50, clock_.TimeInMilliseconds()); - report_blocks.clear(); - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - clock_.AdvanceTimeMilliseconds(100); - - // 15 packets reported as received since last, enough to increase. - report_blocks.push_back(CreateReportBlock(1, 2, 0, 41)); - bandwidth_observer_->OnReceivedRtcpReceiverReport( - report_blocks, 50, clock_.TimeInMilliseconds()); - expected_bitrate_bps = expected_bitrate_bps * 1.08 + 1000; - EXPECT_EQ(expected_bitrate_bps, bitrate_observer_.last_bitrate_); - clock_.AdvanceTimeMilliseconds(1000); -} diff --git a/modules/bitrate_controller/include/bitrate_controller.h b/modules/bitrate_controller/include/bitrate_controller.h deleted file mode 100644 index c203d90cae..0000000000 --- a/modules/bitrate_controller/include/bitrate_controller.h +++ /dev/null @@ -1,102 +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. - * - * 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 MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_ -#define MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_ - -#include -#include - -#include "modules/congestion_controller/goog_cc/delay_based_bwe.h" -#include "modules/include/module.h" -#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" -#include "rtc_base/deprecation.h" - -namespace webrtc { - -class Clock; -class RtcEventLog; - -// Deprecated -// TODO(perkj): Remove BitrateObserver when no implementations use it. -class BitrateObserver { - // Observer class for bitrate changes announced due to change in bandwidth - // estimate or due to bitrate allocation changes. Fraction loss and rtt is - // also part of this callback to allow the obsevrer to optimize its settings - // for different types of network environments. The bitrate does not include - // packet headers and is measured in bits per second. - public: - virtual void OnNetworkChanged(uint32_t bitrate_bps, - uint8_t fraction_loss, // 0 - 255. - int64_t rtt_ms) = 0; - // TODO(gnish): Merge these two into one function. - virtual void OnNetworkChanged(uint32_t bitrate_for_encoder_bps, - uint32_t bitrate_for_pacer_bps, - bool in_probe_rtt, - int64_t target_set_time, - uint64_t congestion_window) {} - virtual void OnBytesAcked(size_t bytes) {} - virtual size_t pacer_queue_size_in_bytes(); - virtual ~BitrateObserver() {} -}; - -class BitrateController : public Module, public RtcpBandwidthObserver { - // This class collects feedback from all streams sent to a peer (via - // RTCPBandwidthObservers). It does one aggregated send side bandwidth - // estimation and divide the available bitrate between all its registered - // BitrateObservers. - public: - static const int kDefaultStartBitratebps = 300000; - - // Deprecated: - // TODO(perkj): BitrateObserver has been deprecated and is not used in WebRTC. - // Remove this method once other other projects does not use it. - static BitrateController* CreateBitrateController(Clock* clock, - BitrateObserver* observer, - RtcEventLog* event_log); - - static BitrateController* CreateBitrateController(Clock* clock, - RtcEventLog* event_log); - - ~BitrateController() override {} - - // Deprecated, use raw pointer to BitrateController instance instead. - // Creates RtcpBandwidthObserver caller responsible to delete. - RTC_DEPRECATED virtual RtcpBandwidthObserver* - CreateRtcpBandwidthObserver() = 0; - - // Deprecated - virtual void SetStartBitrate(int start_bitrate_bps) = 0; - // Deprecated - virtual void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) = 0; - virtual void SetBitrates(int start_bitrate_bps, - int min_bitrate_bps, - int max_bitrate_bps) = 0; - - virtual void ResetBitrates(int bitrate_bps, - int min_bitrate_bps, - int max_bitrate_bps) = 0; - - virtual void OnDelayBasedBweResult(const DelayBasedBwe::Result& result) = 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; - - virtual bool GetNetworkParameters(uint32_t* bitrate, - uint8_t* fraction_loss, - int64_t* rtt) = 0; -}; -} // namespace webrtc -#endif // MODULES_BITRATE_CONTROLLER_INCLUDE_BITRATE_CONTROLLER_H_