Introduce SimulatedNetworkReceiverInterface.

Introduce SimulatedNetworkReceiverInterface and switch DirectTransport
on this interface. Also switch part of related users on
DefaultNetworkSimulationConfig.

This two changes united into single CL to prevent work duplication.
Most changes were done because of stop including fake_network_pipe.h
into direct_transport.h, so splitting this into 2 CLs will require
first fix all imports of fake_network_pipe.h and then replace them
on new API imports again.

Bug: webrtc:9630
Change-Id: I87d4a6ff1bab72d04a9871a40441f4fbe028f4e6
Reviewed-on: https://webrtc-review.googlesource.com/94762
Commit-Queue: Patrik Höglund <phoglund@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Reviewed-by: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Patrik Höglund <phoglund@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24336}
diff --git a/call/BUILD.gn b/call/BUILD.gn
index 7965097..3ec2a2c 100644
--- a/call/BUILD.gn
+++ b/call/BUILD.gn
@@ -261,6 +261,17 @@
   ]
 }
 
+rtc_source_set("simulated_packet_receiver") {
+  sources = [
+    "simulated_packet_receiver.h",
+  ]
+  deps = [
+    ":call_interfaces",
+    "../api:simulated_network_api",
+    "../modules:module_api",
+  ]
+}
+
 rtc_source_set("fake_network") {
   sources = [
     "fake_network_pipe.cc",
@@ -269,6 +280,7 @@
   deps = [
     ":call_interfaces",
     ":simulated_network",
+    ":simulated_packet_receiver",
     "..:webrtc_common",
     "../api:simulated_network_api",
     "../api:transport_api",
@@ -360,6 +372,7 @@
       ":call_interfaces",
       ":video_stream_api",
       "..:webrtc_common",
+      "../api:simulated_network_api",
       "../api/audio_codecs:builtin_audio_encoder_factory",
       "../api/video:video_bitrate_allocation",
       "../api/video_codecs:video_codecs_api",
diff --git a/call/call_perf_tests.cc b/call/call_perf_tests.cc
index 54e01b1..00cfada 100644
--- a/call/call_perf_tests.cc
+++ b/call/call_perf_tests.cc
@@ -15,6 +15,7 @@
 
 #include "absl/memory/memory.h"
 #include "api/audio_codecs/builtin_audio_encoder_factory.h"
+#include "api/test/simulated_network.h"
 #include "api/video/video_bitrate_allocation.h"
 #include "api/video_codecs/video_encoder_config.h"
 #include "call/call.h"
@@ -60,7 +61,7 @@
 
   void TestMinTransmitBitrate(bool pad_to_min_bitrate);
 
-  void TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config,
+  void TestCaptureNtpTime(const DefaultNetworkSimulationConfig& net_config,
                           int threshold_ms,
                           int start_time_ms,
                           int run_time_ms);
@@ -148,7 +149,7 @@
   const uint32_t kAudioSendSsrc = 1234;
   const uint32_t kAudioRecvSsrc = 5678;
 
-  FakeNetworkPipe::Config audio_net_config;
+  DefaultNetworkSimulationConfig audio_net_config;
   audio_net_config.queue_delay_ms = 500;
   audio_net_config.loss_percent = 5;
 
@@ -207,13 +208,13 @@
     video_send_transport = absl::make_unique<test::PacketTransport>(
         &task_queue_, sender_call_.get(), &observer,
         test::PacketTransport::kSender, video_pt_map,
-        FakeNetworkPipe::Config());
+        DefaultNetworkSimulationConfig());
     video_send_transport->SetReceiver(receiver_call_->Receiver());
 
     receive_transport = absl::make_unique<test::PacketTransport>(
         &task_queue_, receiver_call_.get(), &observer,
         test::PacketTransport::kReceiver, payload_type_map_,
-        FakeNetworkPipe::Config());
+        DefaultNetworkSimulationConfig());
     receive_transport->SetReceiver(sender_call_->Receiver());
 
     CreateSendConfig(1, 0, 0, video_send_transport.get());
@@ -323,14 +324,15 @@
                      DriftingClock::PercentsSlower(30.0f), "_video_faster");
 }
 
-void CallPerfTest::TestCaptureNtpTime(const FakeNetworkPipe::Config& net_config,
-                                      int threshold_ms,
-                                      int start_time_ms,
-                                      int run_time_ms) {
+void CallPerfTest::TestCaptureNtpTime(
+    const DefaultNetworkSimulationConfig& net_config,
+    int threshold_ms,
+    int start_time_ms,
+    int run_time_ms) {
   class CaptureNtpTimeObserver : public test::EndToEndTest,
                                  public rtc::VideoSinkInterface<VideoFrame> {
    public:
-    CaptureNtpTimeObserver(const FakeNetworkPipe::Config& net_config,
+    CaptureNtpTimeObserver(const DefaultNetworkSimulationConfig& net_config,
                            int threshold_ms,
                            int start_time_ms,
                            int run_time_ms)
@@ -441,7 +443,7 @@
     }
 
     rtc::CriticalSection crit_;
-    const FakeNetworkPipe::Config net_config_;
+    const DefaultNetworkSimulationConfig net_config_;
     Clock* const clock_;
     int threshold_ms_;
     int start_time_ms_;
@@ -461,7 +463,7 @@
 // Flaky tests, disabled on Mac due to webrtc:8291.
 #if !(defined(WEBRTC_MAC))
 TEST_F(CallPerfTest, CaptureNtpTimeWithNetworkDelay) {
-  FakeNetworkPipe::Config net_config;
+  DefaultNetworkSimulationConfig net_config;
   net_config.queue_delay_ms = 100;
   // TODO(wu): lower the threshold as the calculation/estimatation becomes more
   // accurate.
@@ -472,7 +474,7 @@
 }
 
 TEST_F(CallPerfTest, CaptureNtpTimeWithNetworkJitter) {
-  FakeNetworkPipe::Config net_config;
+  DefaultNetworkSimulationConfig net_config;
   net_config.queue_delay_ms = 100;
   net_config.delay_standard_deviation_ms = 10;
   // TODO(wu): lower the threshold as the calculation/estimatation becomes more
@@ -828,8 +830,8 @@
           max_bwe_(max_bwe) {}
 
    protected:
-    FakeNetworkPipe::Config GetFakeNetworkPipeConfig() {
-      FakeNetworkPipe::Config pipe_config;
+    DefaultNetworkSimulationConfig GetFakeNetworkPipeConfig() {
+      DefaultNetworkSimulationConfig pipe_config;
       pipe_config.link_capacity_kbps = test_bitrate_from_;
       return pipe_config;
     }
@@ -856,7 +858,7 @@
                ? test_bitrate <= test_bitrate_to_
                : test_bitrate >= test_bitrate_to_;
            test_bitrate += test_bitrate_step_) {
-        FakeNetworkPipe::Config pipe_config;
+        DefaultNetworkSimulationConfig pipe_config;
         pipe_config.link_capacity_kbps = test_bitrate;
         send_transport_->SetConfig(pipe_config);
         receive_transport_->SetConfig(pipe_config);
diff --git a/call/fake_network_pipe.h b/call/fake_network_pipe.h
index a46cd75..546014d 100644
--- a/call/fake_network_pipe.h
+++ b/call/fake_network_pipe.h
@@ -22,8 +22,8 @@
 #include "api/call/transport.h"
 #include "api/test/simulated_network.h"
 #include "call/call.h"
+#include "call/simulated_packet_receiver.h"
 #include "common_types.h"  // NOLINT(build/include)
-#include "modules/include/module.h"
 #include "rtc_base/constructormagic.h"
 #include "rtc_base/criticalsection.h"
 #include "rtc_base/thread_annotations.h"
@@ -87,7 +87,8 @@
 
 // Class faking a network link, internally is uses an implementation of a
 // SimulatedNetworkInterface to simulate network behavior.
-class FakeNetworkPipe : public Transport, public PacketReceiver, public Module {
+class FakeNetworkPipe : public webrtc::SimulatedPacketReceiverInterface,
+                        public Transport {
  public:
   using Config = NetworkSimulationInterface::SimulatedNetworkConfig;
 
@@ -135,15 +136,16 @@
 
   ~FakeNetworkPipe() override;
 
-  void SetClockOffset(int64_t offset_ms);
+  // Deprecated. DO NOT USE. Will be removed soon.
+  void SetClockOffset(int64_t offset_ms) override;
 
   // Deprecated. DO NOT USE. Hold direct reference on NetworkSimulationInterface
   // instead and call SetConfig on that object directly. Will be removed soon.
   // Sets a new configuration. This won't affect packets already in the pipe.
-  void SetConfig(const FakeNetworkPipe::Config& config);
+  void SetConfig(const DefaultNetworkSimulationConfig& config) override;
 
   // Must not be called in parallel with DeliverPacket or Process.
-  void SetReceiver(PacketReceiver* receiver);
+  void SetReceiver(PacketReceiver* receiver) override;
 
   // Implements Transport interface. When/if packets are delivered, they will
   // be passed to the transport instance given in SetReceiverTransport(). These
@@ -174,7 +176,7 @@
 
   // Get statistics.
   float PercentageLoss();
-  int AverageDelay();
+  int AverageDelay() override;
   size_t DroppedPackets();
   size_t SentPackets();
   void ResetStats();
diff --git a/call/rampup_tests.h b/call/rampup_tests.h
index a22dfc9..5fd089f 100644
--- a/call/rampup_tests.h
+++ b/call/rampup_tests.h
@@ -15,6 +15,7 @@
 #include <string>
 #include <vector>
 
+#include "api/test/simulated_network.h"
 #include "call/call.h"
 #include "logging/rtc_event_log/rtc_event_log.h"
 #include "rtc_base/event.h"
@@ -64,7 +65,7 @@
 
   rtc::Event stop_event_;
   Clock* const clock_;
-  FakeNetworkPipe::Config forward_transport_config_;
+  DefaultNetworkSimulationConfig forward_transport_config_;
   const size_t num_video_streams_;
   const size_t num_audio_streams_;
   const size_t num_flexfec_streams_;
diff --git a/call/simulated_packet_receiver.h b/call/simulated_packet_receiver.h
new file mode 100644
index 0000000..6630427
--- /dev/null
+++ b/call/simulated_packet_receiver.h
@@ -0,0 +1,44 @@
+/*
+ *  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.
+ */
+
+#ifndef CALL_SIMULATED_PACKET_RECEIVER_H_
+#define CALL_SIMULATED_PACKET_RECEIVER_H_
+
+#include "api/test/simulated_network.h"
+#include "call/packet_receiver.h"
+#include "modules/include/module.h"
+
+namespace webrtc {
+
+// Private API that is fixing surface between DirectTransport and underlying
+// network conditions simulation implementation.
+class SimulatedPacketReceiverInterface : public PacketReceiver, public Module {
+ public:
+  // Must not be called in parallel with DeliverPacket or Process.
+  // Destination receiver will be injected with this method
+  virtual void SetReceiver(PacketReceiver* receiver) = 0;
+
+  // Reports average packet delay.
+  virtual int AverageDelay() = 0;
+
+  // Deprecated. DO NOT USE. Temporary added to be able to introduce
+  // SimulatedPacketReceiverInterface into DirectTransport instead of
+  // FakeNetworkPipe, will be removed soon.
+  virtual void SetClockOffset(int64_t offset_ms) = 0;
+
+  // Deprecated. DO NOT USE. Temporary added to be able to introduce
+  // SimulatedPacketReceiverInterface into DirectTransport instead of
+  // FakeNetworkPipe, will be removed soon.
+  virtual void SetConfig(const DefaultNetworkSimulationConfig& config) = 0;
+};
+
+}  // namespace webrtc
+
+#endif  // CALL_SIMULATED_PACKET_RECEIVER_H_