mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-19 00:27:51 +01:00

This CL was generated by running git ls-files | grep -P "(\.h|\.cc)$" | grep -v 'sdk/' | grep -v 'rtc_base/ssl_' | \ grep -v 'fake_rtc_certificate_generator.h' | grep -v 'modules/audio_device/win/' | \ grep -v 'system_wrappers/source/clock.cc' | grep -v 'rtc_base/trace_event.h' | \ grep -v 'modules/audio_coding/codecs/ilbc/' | grep -v 'screen_capturer_mac.h' | \ grep -v 'spl_inl_mips.h' | grep -v 'data_size_unittest.cc' | grep -v 'timestamp_unittest.cc' \ | xargs clang-format -i ; git cl format Most of these changes are clang-format grouping and reordering includes differently. Bug: webrtc:9340 Change-Id: Ic83ddbc169bfacd21883e381b5181c3dd4fe8a63 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/144051 Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#28505}
119 lines
4.2 KiB
C++
119 lines
4.2 KiB
C++
/*
|
|
* Copyright (c) 2016 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/include/receive_side_congestion_controller.h"
|
|
|
|
#include "modules/pacing/packet_router.h"
|
|
#include "system_wrappers/include/clock.h"
|
|
#include "test/gmock.h"
|
|
#include "test/gtest.h"
|
|
#include "test/scenario/scenario.h"
|
|
|
|
using ::testing::_;
|
|
using ::testing::AtLeast;
|
|
using ::testing::NiceMock;
|
|
using ::testing::Return;
|
|
using ::testing::SaveArg;
|
|
using ::testing::StrictMock;
|
|
|
|
namespace webrtc {
|
|
|
|
namespace {
|
|
|
|
// Helper to convert some time format to resolution used in absolute send time
|
|
// header extension, rounded upwards. |t| is the time to convert, in some
|
|
// resolution. |denom| is the value to divide |t| by to get whole seconds,
|
|
// e.g. |denom| = 1000 if |t| is in milliseconds.
|
|
uint32_t AbsSendTime(int64_t t, int64_t denom) {
|
|
return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful;
|
|
}
|
|
|
|
class MockPacketRouter : public PacketRouter {
|
|
public:
|
|
MOCK_METHOD2(OnReceiveBitrateChanged,
|
|
void(const std::vector<uint32_t>& ssrcs, uint32_t bitrate));
|
|
};
|
|
|
|
const uint32_t kInitialBitrateBps = 60000;
|
|
|
|
} // namespace
|
|
|
|
namespace test {
|
|
|
|
TEST(ReceiveSideCongestionControllerTest, OnReceivedPacketWithAbsSendTime) {
|
|
StrictMock<MockPacketRouter> packet_router;
|
|
SimulatedClock clock_(123456);
|
|
|
|
ReceiveSideCongestionController controller(&clock_, &packet_router);
|
|
|
|
size_t payload_size = 1000;
|
|
RTPHeader header;
|
|
header.ssrc = 0x11eb21c;
|
|
header.extension.hasAbsoluteSendTime = true;
|
|
|
|
std::vector<unsigned int> ssrcs;
|
|
EXPECT_CALL(packet_router, OnReceiveBitrateChanged(_, _))
|
|
.WillRepeatedly(SaveArg<0>(&ssrcs));
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
clock_.AdvanceTimeMilliseconds((1000 * payload_size) / kInitialBitrateBps);
|
|
int64_t now_ms = clock_.TimeInMilliseconds();
|
|
header.extension.absoluteSendTime = AbsSendTime(now_ms, 1000);
|
|
controller.OnReceivedPacket(now_ms, payload_size, header);
|
|
}
|
|
|
|
ASSERT_EQ(1u, ssrcs.size());
|
|
EXPECT_EQ(header.ssrc, ssrcs[0]);
|
|
}
|
|
|
|
TEST(ReceiveSideCongestionControllerTest, ConvergesToCapacity) {
|
|
Scenario s("recieve_cc_unit/converge");
|
|
NetworkSimulationConfig net_conf;
|
|
net_conf.bandwidth = DataRate::kbps(1000);
|
|
net_conf.delay = TimeDelta::ms(50);
|
|
auto* client = s.CreateClient("send", [&](CallClientConfig* c) {
|
|
c->transport.rates.start_rate = DataRate::kbps(300);
|
|
});
|
|
|
|
auto* route = s.CreateRoutes(client, {s.CreateSimulationNode(net_conf)},
|
|
s.CreateClient("return", CallClientConfig()),
|
|
{s.CreateSimulationNode(net_conf)});
|
|
VideoStreamConfig video;
|
|
video.stream.packet_feedback = false;
|
|
s.CreateVideoStream(route->forward(), video);
|
|
s.RunFor(TimeDelta::seconds(30));
|
|
EXPECT_NEAR(client->send_bandwidth().kbps(), 900, 150);
|
|
}
|
|
|
|
TEST(ReceiveSideCongestionControllerTest, IsFairToTCP) {
|
|
Scenario s("recieve_cc_unit/tcp_fairness");
|
|
NetworkSimulationConfig net_conf;
|
|
net_conf.bandwidth = DataRate::kbps(1000);
|
|
net_conf.delay = TimeDelta::ms(50);
|
|
auto* client = s.CreateClient("send", [&](CallClientConfig* c) {
|
|
c->transport.rates.start_rate = DataRate::kbps(1000);
|
|
});
|
|
auto send_net = {s.CreateSimulationNode(net_conf)};
|
|
auto ret_net = {s.CreateSimulationNode(net_conf)};
|
|
auto* route = s.CreateRoutes(
|
|
client, send_net, s.CreateClient("return", CallClientConfig()), ret_net);
|
|
VideoStreamConfig video;
|
|
video.stream.packet_feedback = false;
|
|
s.CreateVideoStream(route->forward(), video);
|
|
s.net()->StartFakeTcpCrossTraffic(s.net()->CreateRoute(send_net),
|
|
s.net()->CreateRoute(ret_net),
|
|
FakeTcpConfig());
|
|
s.RunFor(TimeDelta::seconds(30));
|
|
// For some reason we get outcompeted by TCP here, this should probably be
|
|
// fixed and a lower bound should be added to the test.
|
|
EXPECT_LT(client->send_bandwidth().kbps(), 750);
|
|
}
|
|
} // namespace test
|
|
} // namespace webrtc
|