diff --git a/call/BUILD.gn b/call/BUILD.gn index 838728ad78..d09ae35f3a 100644 --- a/call/BUILD.gn +++ b/call/BUILD.gn @@ -190,9 +190,11 @@ rtc_static_library("call") { ":rtp_interfaces", ":rtp_receiver", ":rtp_sender", + ":simulated_network", ":video_stream_api", "..:webrtc_common", "../api:callfactory_api", + "../api:simulated_network_api", "../api:transport_api", "../api/transport:network_control", "../audio", diff --git a/call/degraded_call.cc b/call/degraded_call.cc index f24ef59414..fd289ebb9a 100644 --- a/call/degraded_call.cc +++ b/call/degraded_call.cc @@ -17,8 +17,8 @@ namespace webrtc { DegradedCall::DegradedCall( std::unique_ptr call, - absl::optional send_config, - absl::optional receive_config) + absl::optional send_config, + absl::optional receive_config) : clock_(Clock::GetRealTimeClock()), call_(std::move(call)), send_config_(send_config), @@ -27,8 +27,10 @@ DegradedCall::DegradedCall( num_send_streams_(0), receive_config_(receive_config) { if (receive_config_) { + auto network = absl::make_unique(*receive_config_); + receive_simulated_network_ = network.get(); receive_pipe_ = - absl::make_unique(clock_, *receive_config_); + absl::make_unique(clock_, std::move(network)); receive_pipe_->SetReceiver(call_->Receiver()); } if (send_process_thread_) { @@ -68,7 +70,9 @@ VideoSendStream* DegradedCall::CreateVideoSendStream( VideoSendStream::Config config, VideoEncoderConfig encoder_config) { if (send_config_ && !send_pipe_) { - send_pipe_ = absl::make_unique(clock_, *send_config_, + auto network = absl::make_unique(*send_config_); + send_simulated_network_ = network.get(); + send_pipe_ = absl::make_unique(clock_, std::move(network), config.send_transport); config.send_transport = this; send_process_thread_->RegisterModule(send_pipe_.get(), RTC_FROM_HERE); @@ -83,7 +87,9 @@ VideoSendStream* DegradedCall::CreateVideoSendStream( VideoEncoderConfig encoder_config, std::unique_ptr fec_controller) { if (send_config_ && !send_pipe_) { - send_pipe_ = absl::make_unique(clock_, *send_config_, + auto network = absl::make_unique(*send_config_); + send_simulated_network_ = network.get(); + send_pipe_ = absl::make_unique(clock_, std::move(network), config.send_transport); config.send_transport = this; send_process_thread_->RegisterModule(send_pipe_.get(), RTC_FROM_HERE); diff --git a/call/degraded_call.h b/call/degraded_call.h index b1e2249587..257ee0be25 100644 --- a/call/degraded_call.h +++ b/call/degraded_call.h @@ -15,8 +15,10 @@ #include "absl/types/optional.h" #include "api/call/transport.h" +#include "api/test/simulated_network.h" #include "call/call.h" #include "call/fake_network_pipe.h" +#include "call/simulated_network.h" #include "modules/utility/include/process_thread.h" #include "system_wrappers/include/clock.h" @@ -24,9 +26,10 @@ namespace webrtc { class DegradedCall : public Call, private Transport, private PacketReceiver { public: - explicit DegradedCall(std::unique_ptr call, - absl::optional send_config, - absl::optional receive_config); + explicit DegradedCall( + std::unique_ptr call, + absl::optional send_config, + absl::optional receive_config); ~DegradedCall() override; // Implements Call. @@ -90,12 +93,14 @@ class DegradedCall : public Call, private Transport, private PacketReceiver { Clock* const clock_; const std::unique_ptr call_; - const absl::optional send_config_; + const absl::optional send_config_; const std::unique_ptr send_process_thread_; + SimulatedNetwork* send_simulated_network_; std::unique_ptr send_pipe_; size_t num_send_streams_; - const absl::optional receive_config_; + const absl::optional receive_config_; + SimulatedNetwork* receive_simulated_network_; std::unique_ptr receive_pipe_; }; diff --git a/call/simulated_network.h b/call/simulated_network.h index 0ddd1f85fc..2758843b43 100644 --- a/call/simulated_network.h +++ b/call/simulated_network.h @@ -28,7 +28,7 @@ namespace webrtc { // capacity introduced delay. class SimulatedNetwork : public NetworkSimulationInterface { public: - using Config = NetworkSimulationInterface::SimulatedNetworkConfig; + using Config = DefaultNetworkSimulationConfig; explicit SimulatedNetwork(Config config, uint64_t random_seed = 1); ~SimulatedNetwork() override; diff --git a/call/test/fake_network_pipe_unittest.cc b/call/test/fake_network_pipe_unittest.cc index 0578f33191..8bf3dad454 100644 --- a/call/test/fake_network_pipe_unittest.cc +++ b/call/test/fake_network_pipe_unittest.cc @@ -73,12 +73,13 @@ class FakeNetworkPipeTest : public ::testing::Test { // Test the capacity link and verify we get as many packets as we expect. TEST_F(FakeNetworkPipeTest, CapacityTest) { - FakeNetworkPipe::Config config; + DefaultNetworkSimulationConfig config; config.queue_length_packets = 20; config.link_capacity_kbps = 80; MockReceiver receiver; - std::unique_ptr pipe( - new FakeNetworkPipe(&fake_clock_, config, &receiver)); + auto simulated_network = absl::make_unique(config); + std::unique_ptr pipe(new FakeNetworkPipe( + &fake_clock_, std::move(simulated_network), &receiver)); // Add 10 packets of 1000 bytes, = 80 kb, and verify it takes one second to // get through the pipe. @@ -112,13 +113,14 @@ TEST_F(FakeNetworkPipeTest, CapacityTest) { // Test the extra network delay. TEST_F(FakeNetworkPipeTest, ExtraDelayTest) { - FakeNetworkPipe::Config config; + DefaultNetworkSimulationConfig config; config.queue_length_packets = 20; config.queue_delay_ms = 100; config.link_capacity_kbps = 80; MockReceiver receiver; - std::unique_ptr pipe( - new FakeNetworkPipe(&fake_clock_, config, &receiver)); + auto simulated_network = absl::make_unique(config); + std::unique_ptr pipe(new FakeNetworkPipe( + &fake_clock_, std::move(simulated_network), &receiver)); const int kNumPackets = 2; const int kPacketSize = 1000; @@ -147,12 +149,13 @@ TEST_F(FakeNetworkPipeTest, ExtraDelayTest) { // Test the number of buffers and packets are dropped when sending too many // packets too quickly. TEST_F(FakeNetworkPipeTest, QueueLengthTest) { - FakeNetworkPipe::Config config; + DefaultNetworkSimulationConfig config; config.queue_length_packets = 2; config.link_capacity_kbps = 80; MockReceiver receiver; - std::unique_ptr pipe( - new FakeNetworkPipe(&fake_clock_, config, &receiver)); + auto simulated_network = absl::make_unique(config); + std::unique_ptr pipe(new FakeNetworkPipe( + &fake_clock_, std::move(simulated_network), &receiver)); const int kPacketSize = 1000; const int kPacketTimeMs = @@ -170,13 +173,14 @@ TEST_F(FakeNetworkPipeTest, QueueLengthTest) { // Test we get statistics as expected. TEST_F(FakeNetworkPipeTest, StatisticsTest) { - FakeNetworkPipe::Config config; + DefaultNetworkSimulationConfig config; config.queue_length_packets = 2; config.queue_delay_ms = 20; config.link_capacity_kbps = 80; MockReceiver receiver; - std::unique_ptr pipe( - new FakeNetworkPipe(&fake_clock_, config, &receiver)); + auto simulated_network = absl::make_unique(config); + std::unique_ptr pipe(new FakeNetworkPipe( + &fake_clock_, std::move(simulated_network), &receiver)); const int kPacketSize = 1000; const int kPacketTimeMs = @@ -201,7 +205,7 @@ TEST_F(FakeNetworkPipeTest, StatisticsTest) { // Change the link capacity half-way through the test and verify that the // delivery times change accordingly. TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { - FakeNetworkPipe::Config config; + DefaultNetworkSimulationConfig config; config.queue_length_packets = 20; config.link_capacity_kbps = 80; MockReceiver receiver; @@ -262,7 +266,7 @@ TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) { // Change the link capacity half-way through the test and verify that the // delivery times change accordingly. TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { - FakeNetworkPipe::Config config; + DefaultNetworkSimulationConfig config; config.queue_length_packets = 20; config.link_capacity_kbps = 80; MockReceiver receiver; @@ -317,7 +321,7 @@ TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) { // At first disallow reordering and then allow reordering. TEST_F(FakeNetworkPipeTest, DisallowReorderingThenAllowReordering) { - FakeNetworkPipe::Config config; + DefaultNetworkSimulationConfig config; config.queue_length_packets = 1000; config.link_capacity_kbps = 800; config.queue_delay_ms = 100; @@ -370,13 +374,14 @@ TEST_F(FakeNetworkPipeTest, BurstLoss) { const int kNumPackets = 10000; const int kPacketSize = 10; - FakeNetworkPipe::Config config; + DefaultNetworkSimulationConfig config; config.queue_length_packets = kNumPackets; config.loss_percent = kLossPercent; config.avg_burst_loss_length = kAvgBurstLength; ReorderTestReceiver receiver; + auto simulated_network = absl::make_unique(config); std::unique_ptr pipe( - new FakeNetworkPipe(&fake_clock_, config, &receiver)); + new FakeNetworkPipe(&fake_clock_, std::move(config), &receiver)); SendPackets(pipe.get(), kNumPackets, kPacketSize); fake_clock_.AdvanceTimeMilliseconds(1000); @@ -404,11 +409,12 @@ TEST_F(FakeNetworkPipeTest, BurstLoss) { } TEST_F(FakeNetworkPipeTest, SetReceiver) { - FakeNetworkPipe::Config config; + DefaultNetworkSimulationConfig config; config.link_capacity_kbps = 800; MockReceiver receiver; - std::unique_ptr pipe( - new FakeNetworkPipe(&fake_clock_, config, &receiver)); + auto simulated_network = absl::make_unique(config); + std::unique_ptr pipe(new FakeNetworkPipe( + &fake_clock_, std::move(simulated_network), &receiver)); const int kPacketSize = 1000; const int kPacketTimeMs =