webrtc_m130/modules/congestion_controller/pcc/bitrate_controller_unittest.cc

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

304 lines
14 KiB
C++
Raw Normal View History

/*
* 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.
*/
#include "modules/congestion_controller/pcc/bitrate_controller.h"
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
#include <memory>
#include <utility>
#include "modules/congestion_controller/pcc/monitor_interval.h"
#include "test/gmock.h"
#include "test/gtest.h"
namespace webrtc {
namespace pcc {
namespace test {
namespace {
constexpr double kInitialConversionFactor = 1;
constexpr double kInitialDynamicBoundary = 0.05;
constexpr double kDynamicBoundaryIncrement = 0.1;
constexpr double kDelayGradientCoefficient = 900;
constexpr double kLossCoefficient = 11.35;
constexpr double kThroughputCoefficient = 500 * 1000;
constexpr double kThroughputPower = 0.99;
constexpr double kDelayGradientThreshold = 0.01;
constexpr double kDelayGradientNegativeBound = 10;
const DataRate kTargetSendingRate = DataRate::KilobitsPerSec(300);
const double kEpsilon = 0.05;
Use newer version of TimeDelta and TimeStamp factories in modules/ This change generated with following commands: find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/TimeDelta::Micros<\(.*\)>()/TimeDelta::Micros(\1)/g" find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/TimeDelta::Millis<\(.*\)>()/TimeDelta::Millis(\1)/g" find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/TimeDelta::Seconds<\(.*\)>()/TimeDelta::Seconds(\1)/g" find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/TimeDelta::us/TimeDelta::Micros/g" find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/TimeDelta::ms/TimeDelta::Millis/g" find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/TimeDelta::seconds/TimeDelta::Seconds/g" find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/Timestamp::Micros<\(.*\)>()/Timestamp::Micros(\1)/g" find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/Timestamp::Millis<\(.*\)>()/Timestamp::Millis(\1)/g" find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/Timestamp::Seconds<\(.*\)>()/Timestamp::Seconds(\1)/g" find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/Timestamp::us/Timestamp::Micros/g" find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/Timestamp::ms/Timestamp::Millis/g" find modules -type f \( -name "*.h" -o -name "*.cc" \) | xargs sed -i -e "s/Timestamp::seconds/Timestamp::Seconds/g" git cl format Bug: None Change-Id: I117d64a54950be040d996035c54bc0043310943a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168340 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30489}
2020-02-07 14:53:52 +01:00
const Timestamp kStartTime = Timestamp::Micros(0);
const TimeDelta kPacketsDelta = TimeDelta::Millis(1);
const TimeDelta kIntervalDuration = TimeDelta::Millis(1000);
const TimeDelta kDefaultRtt = TimeDelta::Millis(1000);
const DataSize kDefaultDataSize = DataSize::Bytes(100);
std::vector<PacketResult> CreatePacketResults(
const std::vector<Timestamp>& packets_send_times,
const std::vector<Timestamp>& packets_received_times = {},
const std::vector<DataSize>& packets_sizes = {}) {
std::vector<PacketResult> packet_results;
PacketResult packet_result;
SentPacket sent_packet;
for (size_t i = 0; i < packets_send_times.size(); ++i) {
sent_packet.send_time = packets_send_times[i];
if (packets_sizes.empty()) {
sent_packet.size = kDefaultDataSize;
} else {
sent_packet.size = packets_sizes[i];
}
packet_result.sent_packet = sent_packet;
if (packets_received_times.empty()) {
packet_result.receive_time = packets_send_times[i] + kDefaultRtt;
} else {
packet_result.receive_time = packets_received_times[i];
}
packet_results.push_back(packet_result);
}
return packet_results;
}
class MockUtilityFunction : public PccUtilityFunctionInterface {
public:
MOCK_METHOD(double,
Compute,
(const PccMonitorInterval& monitor_interval),
(const, override));
};
} // namespace
TEST(PccBitrateControllerTest, IncreaseRateWhenNoChangesForTestBitrates) {
PccBitrateController bitrate_controller(
kInitialConversionFactor, kInitialDynamicBoundary,
kDynamicBoundaryIncrement, kDelayGradientCoefficient, kLossCoefficient,
kThroughputCoefficient, kThroughputPower, kDelayGradientThreshold,
kDelayGradientNegativeBound);
VivaceUtilityFunction utility_function(
kDelayGradientCoefficient, kLossCoefficient, kThroughputCoefficient,
kThroughputPower, kDelayGradientThreshold, kDelayGradientNegativeBound);
std::vector<PccMonitorInterval> monitor_block{
PccMonitorInterval(kTargetSendingRate * (1 + kEpsilon), kStartTime,
kIntervalDuration),
PccMonitorInterval(kTargetSendingRate * (1 - kEpsilon),
kStartTime + kIntervalDuration, kIntervalDuration)};
monitor_block[0].OnPacketsFeedback(
CreatePacketResults({kStartTime + kPacketsDelta,
kStartTime + kIntervalDuration + kPacketsDelta,
kStartTime + 3 * kIntervalDuration},
{}, {}));
monitor_block[1].OnPacketsFeedback(
CreatePacketResults({kStartTime + kPacketsDelta,
kStartTime + kIntervalDuration + kPacketsDelta,
kStartTime + 3 * kIntervalDuration},
{}, {}));
// For both of the monitor intervals there were no change in rtt gradient
// and in packet loss. Since the only difference is in the sending rate,
// the higher sending rate should be chosen by congestion controller.
EXPECT_GT(bitrate_controller
.ComputeRateUpdateForOnlineLearningMode(monitor_block,
kTargetSendingRate)
.bps(),
kTargetSendingRate.bps());
}
TEST(PccBitrateControllerTest, NoChangesWhenUtilityFunctionDoesntChange) {
std::unique_ptr<MockUtilityFunction> mock_utility_function =
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
std::make_unique<MockUtilityFunction>();
EXPECT_CALL(*mock_utility_function, Compute(::testing::_))
.Times(2)
.WillOnce(::testing::Return(100))
.WillOnce(::testing::Return(100));
PccBitrateController bitrate_controller(
kInitialConversionFactor, kInitialDynamicBoundary,
kDynamicBoundaryIncrement, std::move(mock_utility_function));
std::vector<PccMonitorInterval> monitor_block{
PccMonitorInterval(kTargetSendingRate * (1 + kEpsilon), kStartTime,
kIntervalDuration),
PccMonitorInterval(kTargetSendingRate * (1 - kEpsilon),
kStartTime + kIntervalDuration, kIntervalDuration)};
// To complete collecting feedback within monitor intervals.
monitor_block[0].OnPacketsFeedback(
CreatePacketResults({kStartTime + 3 * kIntervalDuration}, {}, {}));
monitor_block[1].OnPacketsFeedback(
CreatePacketResults({kStartTime + 3 * kIntervalDuration}, {}, {}));
// Because we don't have any packets inside of monitor intervals, utility
// function should be zero for both of them and the sending rate should not
// change.
EXPECT_EQ(bitrate_controller
.ComputeRateUpdateForOnlineLearningMode(monitor_block,
kTargetSendingRate)
.bps(),
kTargetSendingRate.bps());
}
TEST(PccBitrateControllerTest, NoBoundaryWhenSmallGradient) {
std::unique_ptr<MockUtilityFunction> mock_utility_function =
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
std::make_unique<MockUtilityFunction>();
constexpr double kFirstMonitorIntervalUtility = 0;
const double kSecondMonitorIntervalUtility =
2 * kTargetSendingRate.bps() * kEpsilon;
EXPECT_CALL(*mock_utility_function, Compute(::testing::_))
.Times(2)
.WillOnce(::testing::Return(kFirstMonitorIntervalUtility))
.WillOnce(::testing::Return(kSecondMonitorIntervalUtility));
PccBitrateController bitrate_controller(
kInitialConversionFactor, kInitialDynamicBoundary,
kDynamicBoundaryIncrement, std::move(mock_utility_function));
std::vector<PccMonitorInterval> monitor_block{
PccMonitorInterval(kTargetSendingRate * (1 + kEpsilon), kStartTime,
kIntervalDuration),
PccMonitorInterval(kTargetSendingRate * (1 - kEpsilon),
kStartTime + kIntervalDuration, kIntervalDuration)};
// To complete collecting feedback within monitor intervals.
monitor_block[0].OnPacketsFeedback(
CreatePacketResults({kStartTime + 3 * kIntervalDuration}, {}, {}));
monitor_block[1].OnPacketsFeedback(
CreatePacketResults({kStartTime + 3 * kIntervalDuration}, {}, {}));
double gradient =
(kFirstMonitorIntervalUtility - kSecondMonitorIntervalUtility) /
(kTargetSendingRate.bps() * 2 * kEpsilon);
// When the gradient is small we don't hit the dynamic boundary.
EXPECT_EQ(bitrate_controller
.ComputeRateUpdateForOnlineLearningMode(monitor_block,
kTargetSendingRate)
.bps(),
kTargetSendingRate.bps() + kInitialConversionFactor * gradient);
}
TEST(PccBitrateControllerTest, FaceBoundaryWhenLargeGradient) {
std::unique_ptr<MockUtilityFunction> mock_utility_function =
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
std::make_unique<MockUtilityFunction>();
constexpr double kFirstMonitorIntervalUtility = 0;
const double kSecondMonitorIntervalUtility =
10 * kInitialDynamicBoundary * kTargetSendingRate.bps() * 2 *
kTargetSendingRate.bps() * kEpsilon;
EXPECT_CALL(*mock_utility_function, Compute(::testing::_))
.Times(4)
.WillOnce(::testing::Return(kFirstMonitorIntervalUtility))
.WillOnce(::testing::Return(kSecondMonitorIntervalUtility))
.WillOnce(::testing::Return(kFirstMonitorIntervalUtility))
.WillOnce(::testing::Return(kSecondMonitorIntervalUtility));
PccBitrateController bitrate_controller(
kInitialConversionFactor, kInitialDynamicBoundary,
kDynamicBoundaryIncrement, std::move(mock_utility_function));
std::vector<PccMonitorInterval> monitor_block{
PccMonitorInterval(kTargetSendingRate * (1 + kEpsilon), kStartTime,
kIntervalDuration),
PccMonitorInterval(kTargetSendingRate * (1 - kEpsilon),
kStartTime + kIntervalDuration, kIntervalDuration)};
// To complete collecting feedback within monitor intervals.
monitor_block[0].OnPacketsFeedback(
CreatePacketResults({kStartTime + 3 * kIntervalDuration}, {}, {}));
monitor_block[1].OnPacketsFeedback(
CreatePacketResults({kStartTime + 3 * kIntervalDuration}, {}, {}));
// The utility function gradient is too big and we hit the dynamic boundary.
EXPECT_EQ(bitrate_controller.ComputeRateUpdateForOnlineLearningMode(
monitor_block, kTargetSendingRate),
kTargetSendingRate * (1 - kInitialDynamicBoundary));
// For the second time we hit the dynamic boundary in the same direction, the
// boundary should increase.
EXPECT_EQ(bitrate_controller
.ComputeRateUpdateForOnlineLearningMode(monitor_block,
kTargetSendingRate)
.bps(),
kTargetSendingRate.bps() *
(1 - kInitialDynamicBoundary - kDynamicBoundaryIncrement));
}
TEST(PccBitrateControllerTest, SlowStartMode) {
std::unique_ptr<MockUtilityFunction> mock_utility_function =
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
std::make_unique<MockUtilityFunction>();
constexpr double kFirstUtilityFunction = 1000;
EXPECT_CALL(*mock_utility_function, Compute(::testing::_))
.Times(4)
// For first 3 calls we expect to stay in the SLOW_START mode and double
// the sending rate since the utility function increases its value. For
// the last call utility function decreases its value, this means that
// we should not double the sending rate and exit SLOW_START mode.
.WillOnce(::testing::Return(kFirstUtilityFunction))
.WillOnce(::testing::Return(kFirstUtilityFunction + 1))
.WillOnce(::testing::Return(kFirstUtilityFunction + 2))
.WillOnce(::testing::Return(kFirstUtilityFunction + 1));
PccBitrateController bitrate_controller(
kInitialConversionFactor, kInitialDynamicBoundary,
kDynamicBoundaryIncrement, std::move(mock_utility_function));
std::vector<PccMonitorInterval> monitor_block{PccMonitorInterval(
2 * kTargetSendingRate, kStartTime, kIntervalDuration)};
// To complete collecting feedback within monitor intervals.
monitor_block[0].OnPacketsFeedback(
CreatePacketResults({kStartTime + 3 * kIntervalDuration}, {}, {}));
EXPECT_EQ(
bitrate_controller.ComputeRateUpdateForSlowStartMode(monitor_block[0]),
kTargetSendingRate * 2);
EXPECT_EQ(
bitrate_controller.ComputeRateUpdateForSlowStartMode(monitor_block[0]),
kTargetSendingRate * 2);
EXPECT_EQ(
bitrate_controller.ComputeRateUpdateForSlowStartMode(monitor_block[0]),
kTargetSendingRate * 2);
EXPECT_EQ(
bitrate_controller.ComputeRateUpdateForSlowStartMode(monitor_block[0]),
absl::nullopt);
}
TEST(PccBitrateControllerTest, StepSizeIncrease) {
std::unique_ptr<MockUtilityFunction> mock_utility_function =
Use std::make_unique instead of absl::make_unique. WebRTC is now using C++14 so there is no need to use the Abseil version of std::make_unique. This CL has been created with the following steps: git grep -l absl::make_unique | sort | uniq > /tmp/make_unique.txt git grep -l absl::WrapUnique | sort | uniq > /tmp/wrap_unique.txt git grep -l "#include <memory>" | sort | uniq > /tmp/memory.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/make_unique.txt /tmp/wrap_unique.txt | sort | \ uniq > /tmp/only_make_unique.txt diff --new-line-format="" --unchanged-line-format="" \ /tmp/only_make_unique.txt /tmp/memory.txt | \ xargs grep -l "absl/memory" > /tmp/add-memory.txt git grep -l "\babsl::make_unique\b" | \ xargs sed -i "s/\babsl::make_unique\b/std::make_unique/g" git checkout PRESUBMIT.py abseil-in-webrtc.md cat /tmp/add-memory.txt | \ xargs sed -i \ 's/#include "absl\/memory\/memory.h"/#include <memory>/g' git cl format # Manual fix order of the new inserted #include <memory> cat /tmp/only_make_unique | xargs grep -l "#include <memory>" | \ xargs sed -i '/#include "absl\/memory\/memory.h"/d' git ls-files | grep BUILD.gn | \ xargs sed -i '/\/\/third_party\/abseil-cpp\/absl\/memory/d' python tools_webrtc/gn_check_autofix.py \ -m tryserver.webrtc -b linux_rel # Repead the gn_check_autofix step for other platforms git ls-files | grep BUILD.gn | \ xargs sed -i 's/absl\/memory:memory/absl\/memory/g' git cl format Bug: webrtc:10945 Change-Id: I3fe28ea80f4dd3ba3cf28effd151d5e1f19aff89 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/153221 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29209}
2019-09-17 17:06:18 +02:00
std::make_unique<MockUtilityFunction>();
constexpr double kFirstMiUtilityFunction = 0;
const double kSecondMiUtilityFunction =
2 * kTargetSendingRate.bps() * kEpsilon;
EXPECT_CALL(*mock_utility_function, Compute(::testing::_))
.Times(4)
.WillOnce(::testing::Return(kFirstMiUtilityFunction))
.WillOnce(::testing::Return(kSecondMiUtilityFunction))
.WillOnce(::testing::Return(kFirstMiUtilityFunction))
.WillOnce(::testing::Return(kSecondMiUtilityFunction));
std::vector<PccMonitorInterval> monitor_block{
PccMonitorInterval(kTargetSendingRate * (1 + kEpsilon), kStartTime,
kIntervalDuration),
PccMonitorInterval(kTargetSendingRate * (1 - kEpsilon),
kStartTime + kIntervalDuration, kIntervalDuration)};
// To complete collecting feedback within monitor intervals.
monitor_block[0].OnPacketsFeedback(
CreatePacketResults({kStartTime + 3 * kIntervalDuration}, {}, {}));
monitor_block[1].OnPacketsFeedback(
CreatePacketResults({kStartTime + 3 * kIntervalDuration}, {}, {}));
double gradient = (kFirstMiUtilityFunction - kSecondMiUtilityFunction) /
(kTargetSendingRate.bps() * 2 * kEpsilon);
PccBitrateController bitrate_controller(
kInitialConversionFactor, kInitialDynamicBoundary,
kDynamicBoundaryIncrement, std::move(mock_utility_function));
// If we are moving in the same direction - the step size should increase.
EXPECT_EQ(bitrate_controller
.ComputeRateUpdateForOnlineLearningMode(monitor_block,
kTargetSendingRate)
.bps(),
kTargetSendingRate.bps() + kInitialConversionFactor * gradient);
EXPECT_EQ(bitrate_controller
.ComputeRateUpdateForOnlineLearningMode(monitor_block,
kTargetSendingRate)
.bps(),
kTargetSendingRate.bps() + 2 * kInitialConversionFactor * gradient);
}
} // namespace test
} // namespace pcc
} // namespace webrtc