From 537b7fed9a2925140f7d6bfc671547fe5b9016ed Mon Sep 17 00:00:00 2001 From: Artem Titov Date: Thu, 16 Aug 2018 11:20:45 +0200 Subject: [PATCH] Add FakeNetworkPipe ctor from NetworkSimulationInterface. Add FakeNetworkPipe ctor from NetworkSimulationInterface to be able to inject different implementations of simulated networks. If user requires to do something with injected simulation he can keep raw reference, or introduce some proxy, that will hide shared ownership from FakeNetworkPipe. Also FakeNetworkPipe guarantee to keep simulation object alive while it is alive itself. Bug: webrtc:9630 Change-Id: Ie00ea1d47bf7658b0c6433cf2efbf364f885c8a0 Reviewed-on: https://webrtc-review.googlesource.com/94153 Reviewed-by: Sebastian Jansson Commit-Queue: Artem Titov Cr-Commit-Position: refs/heads/master@{#24312} --- call/fake_network_pipe.cc | 15 +++++++++++++++ call/fake_network_pipe.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/call/fake_network_pipe.cc b/call/fake_network_pipe.cc index e2fa2f4e99..dd8d5d7552 100644 --- a/call/fake_network_pipe.cc +++ b/call/fake_network_pipe.cc @@ -43,6 +43,7 @@ NetworkPacket::NetworkPacket(rtc::CopyOnWriteBuffer packet, is_rtcp_(is_rtcp), media_type_(media_type), packet_time_us_(packet_time_us) {} + NetworkPacket::NetworkPacket(rtc::CopyOnWriteBuffer packet, int64_t send_time, int64_t arrival_time, @@ -87,6 +88,20 @@ FakeNetworkPipe::FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config) : FakeNetworkPipe(clock, config, nullptr, 1) {} +FakeNetworkPipe::FakeNetworkPipe( + Clock* clock, + std::unique_ptr network_simulation) + : clock_(clock), + network_simulation_(std::move(network_simulation)), + receiver_(nullptr), + transport_(nullptr), + clock_offset_ms_(0), + dropped_packets_(0), + sent_packets_(0), + total_packet_delay_us_(0), + next_process_time_us_(clock_->TimeInMicroseconds()), + last_log_time_us_(clock_->TimeInMicroseconds()) {} + FakeNetworkPipe::FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config, PacketReceiver* receiver) diff --git a/call/fake_network_pipe.h b/call/fake_network_pipe.h index 531329ee72..6a2ff3548d 100644 --- a/call/fake_network_pipe.h +++ b/call/fake_network_pipe.h @@ -105,6 +105,10 @@ class FakeNetworkPipe : public Transport, public PacketReceiver, public Module { // Use these constructors if you plan to insert packets using DeliverPacket(). FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config); + // Will keep |network_simulation| alive while pipe is alive itself. + FakeNetworkPipe( + Clock* clock, + std::unique_ptr network_simulation); FakeNetworkPipe(Clock* clock, const FakeNetworkPipe::Config& config, PacketReceiver* receiver);