Add full stack test cases with a fake network pipe.

R=pbos@webrtc.org
BUG=1872

Review URL: https://webrtc-codereview.appspot.com/20889004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@6634 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/test/fake_network_pipe.cc b/webrtc/test/fake_network_pipe.cc
index c5caef2..06bf062 100644
--- a/webrtc/test/fake_network_pipe.cc
+++ b/webrtc/test/fake_network_pipe.cc
@@ -104,8 +104,8 @@
   if (packet_receiver_ == NULL)
     return;
   CriticalSectionScoped crit(lock_.get());
-  if (config_.queue_length > 0 &&
-      capacity_link_.size() >= config_.queue_length) {
+  if (config_.queue_length_packets > 0 &&
+      capacity_link_.size() >= config_.queue_length_packets) {
     // Too many packet on the link, drop this one.
     ++dropped_packets_;
     return;
diff --git a/webrtc/test/fake_network_pipe.h b/webrtc/test/fake_network_pipe.h
index b9690e7..c741501 100644
--- a/webrtc/test/fake_network_pipe.h
+++ b/webrtc/test/fake_network_pipe.h
@@ -33,14 +33,14 @@
  public:
   struct Config {
     Config()
-        : queue_length(0),
+        : queue_length_packets(0),
           queue_delay_ms(0),
           delay_standard_deviation_ms(0),
           link_capacity_kbps(0),
           loss_percent(0) {
     }
     // Queue length in number of packets.
-    size_t queue_length;
+    size_t queue_length_packets;
     // Delay in addition to capacity induced delay.
     int queue_delay_ms;
     // Standard deviation of the extra delay.
diff --git a/webrtc/test/fake_network_pipe_unittest.cc b/webrtc/test/fake_network_pipe_unittest.cc
index 0399688..d429fce 100644
--- a/webrtc/test/fake_network_pipe_unittest.cc
+++ b/webrtc/test/fake_network_pipe_unittest.cc
@@ -65,7 +65,7 @@
 // Test the capacity link and verify we get as many packets as we expect.
 TEST_F(FakeNetworkPipeTest, CapacityTest) {
   FakeNetworkPipe::Config config;
-  config.queue_length = 20;
+  config.queue_length_packets = 20;
   config.link_capacity_kbps = 80;
   scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
   pipe->SetReceiver(receiver_.get());
@@ -107,7 +107,7 @@
 // Test the extra network delay.
 TEST_F(FakeNetworkPipeTest, ExtraDelayTest) {
   FakeNetworkPipe::Config config;
-  config.queue_length = 20;
+  config.queue_length_packets = 20;
   config.queue_delay_ms = 100;
   config.link_capacity_kbps = 80;
   scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
@@ -144,7 +144,7 @@
 // packets too quickly.
 TEST_F(FakeNetworkPipeTest, QueueLengthTest) {
   FakeNetworkPipe::Config config;
-  config.queue_length = 2;
+  config.queue_length_packets = 2;
   config.link_capacity_kbps = 80;
   scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
   pipe->SetReceiver(receiver_.get());
@@ -167,7 +167,7 @@
 // Test we get statistics as expected.
 TEST_F(FakeNetworkPipeTest, StatisticsTest) {
   FakeNetworkPipe::Config config;
-  config.queue_length = 2;
+  config.queue_length_packets = 2;
   config.queue_delay_ms = 20;
   config.link_capacity_kbps = 80;
   scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
@@ -197,7 +197,7 @@
 // delivery times change accordingly.
 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithEmptyPipeTest) {
   FakeNetworkPipe::Config config;
-  config.queue_length = 20;
+  config.queue_length_packets = 20;
   config.link_capacity_kbps = 80;
   scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
   pipe->SetReceiver(receiver_.get());
@@ -255,7 +255,7 @@
 // delivery times change accordingly.
 TEST_F(FakeNetworkPipeTest, ChangingCapacityWithPacketsInPipeTest) {
   FakeNetworkPipe::Config config;
-  config.queue_length = 20;
+  config.queue_length_packets = 20;
   config.link_capacity_kbps = 80;
   scoped_ptr<FakeNetworkPipe> pipe(new FakeNetworkPipe(config));
   pipe->SetReceiver(receiver_.get());
diff --git a/webrtc/video/full_stack.cc b/webrtc/video/full_stack.cc
index 284efe2..a9ddd2c 100644
--- a/webrtc/video/full_stack.cc
+++ b/webrtc/video/full_stack.cc
@@ -35,7 +35,7 @@
 
 namespace webrtc {
 
-static const int kFullStackTestDurationSecs = 10;
+static const int kFullStackTestDurationSecs = 60;
 
 struct FullStackTestParams {
   const char* test_label;
@@ -44,14 +44,17 @@
     size_t width, height;
     int fps;
   } clip;
-  unsigned int bitrate;
+  int min_bitrate_bps;
+  int target_bitrate_bps;
+  int max_bitrate_bps;
   double avg_psnr_threshold;
   double avg_ssim_threshold;
+  FakeNetworkPipe::Config link;
 };
 
 class FullStackTest : public test::CallTest {
  protected:
-  void TestWithoutPacketLoss(const FullStackTestParams& params);
+  void RunTest(const FullStackTestParams& params);
 };
 
 class VideoAnalyzer : public PacketReceiver,
@@ -367,19 +370,21 @@
   const scoped_ptr<EventWrapper> done_;
 };
 
-void FullStackTest::TestWithoutPacketLoss(const FullStackTestParams& params) {
-  test::DirectTransport transport;
+void FullStackTest::RunTest(const FullStackTestParams& params) {
+  test::DirectTransport send_transport(params.link);
+  test::DirectTransport recv_transport(params.link);
   VideoAnalyzer analyzer(NULL,
-                         &transport,
+                         &send_transport,
                          params.test_label,
                          params.avg_psnr_threshold,
                          params.avg_ssim_threshold,
                          kFullStackTestDurationSecs * params.clip.fps);
 
-  CreateCalls(Call::Config(&analyzer), Call::Config(&analyzer));
+  CreateCalls(Call::Config(&analyzer), Call::Config(&recv_transport));
 
   analyzer.SetReceiver(receiver_call_->Receiver());
-  transport.SetReceiver(&analyzer);
+  send_transport.SetReceiver(&analyzer);
+  recv_transport.SetReceiver(sender_call_->Receiver());
 
   CreateSendConfig(1);
 
@@ -391,8 +396,9 @@
   VideoStream* stream = &video_streams_[0];
   stream->width = params.clip.width;
   stream->height = params.clip.height;
-  stream->min_bitrate_bps = stream->target_bitrate_bps =
-      stream->max_bitrate_bps = params.bitrate * 1000;
+  stream->min_bitrate_bps = params.min_bitrate_bps;
+  stream->target_bitrate_bps = params.target_bitrate_bps;
+  stream->max_bitrate_bps = params.max_bitrate_bps;
   stream->max_framerate = params.clip.fps;
 
   CreateMatchingReceiveConfigs();
@@ -418,32 +424,111 @@
 
   analyzer.Wait();
 
-  transport.StopSending();
+  send_transport.StopSending();
+  recv_transport.StopSending();
 
   Stop();
 
   DestroyStreams();
 }
 
-FullStackTestParams paris_qcif = {"net_delay_0_0_plr_0",
-                                  {"paris_qcif", 176, 144, 30},
-                                  300,
-                                  36.0,
-                                  0.96};
-
-// TODO(pbos): Decide on psnr/ssim thresholds for foreman_cif.
-FullStackTestParams foreman_cif = {"foreman_cif_net_delay_0_0_plr_0",
-                                   {"foreman_cif", 352, 288, 30},
-                                   700,
-                                   0.0,
-                                   0.0};
-
 TEST_F(FullStackTest, ParisQcifWithoutPacketLoss) {
-  TestWithoutPacketLoss(paris_qcif);
+  FullStackTestParams paris_qcif = {"net_delay_0_0_plr_0",
+                                    {"paris_qcif", 176, 144, 30},
+                                    300000,
+                                    300000,
+                                    300000,
+                                    36.0,
+                                    0.96
+                                   };
+  RunTest(paris_qcif);
 }
 
 TEST_F(FullStackTest, ForemanCifWithoutPacketLoss) {
-  TestWithoutPacketLoss(foreman_cif);
+  // TODO(pbos): Decide on psnr/ssim thresholds for foreman_cif.
+  FullStackTestParams foreman_cif = {"foreman_cif_net_delay_0_0_plr_0",
+                                     {"foreman_cif", 352, 288, 30},
+                                     700000,
+                                     700000,
+                                     700000,
+                                     0.0,
+                                     0.0
+                                    };
+  RunTest(foreman_cif);
 }
 
+TEST_F(FullStackTest, ForemanCif500kbps) {
+  FullStackTestParams foreman_cif = {"foreman_cif_500kbps",
+                                     {"foreman_cif", 352, 288, 30},
+                                     30000,
+                                     500000,
+                                     2000000,
+                                     0.0,
+                                     0.0
+                                    };
+  foreman_cif.link.queue_length_packets = 0;
+  foreman_cif.link.queue_delay_ms = 0;
+  foreman_cif.link.link_capacity_kbps = 500;
+  RunTest(foreman_cif);
+}
+
+TEST_F(FullStackTest, ForemanCif500kbpsLimitedQueue) {
+  FullStackTestParams foreman_cif = {"foreman_cif_500kbps_32pkts_queue",
+                                     {"foreman_cif", 352, 288, 30},
+                                     30000,
+                                     500000,
+                                     2000000,
+                                     0.0,
+                                     0.0
+                                    };
+  foreman_cif.link.queue_length_packets = 32;
+  foreman_cif.link.queue_delay_ms = 0;
+  foreman_cif.link.link_capacity_kbps = 500;
+  RunTest(foreman_cif);
+}
+
+TEST_F(FullStackTest, ForemanCif500kbps100ms) {
+  FullStackTestParams foreman_cif = {"foreman_cif_500kbps_100ms",
+                                     {"foreman_cif", 352, 288, 30},
+                                     30000,
+                                     500000,
+                                     2000000,
+                                     0.0,
+                                     0.0
+                                    };
+  foreman_cif.link.queue_length_packets = 0;
+  foreman_cif.link.queue_delay_ms = 100;
+  foreman_cif.link.link_capacity_kbps = 500;
+  RunTest(foreman_cif);
+}
+
+TEST_F(FullStackTest, ForemanCif500kbps100msLimitedQueue) {
+  FullStackTestParams foreman_cif = {"foreman_cif_500kbps_100ms_32pkts_queue",
+                                     {"foreman_cif", 352, 288, 30},
+                                     30000,
+                                     500000,
+                                     2000000,
+                                     0.0,
+                                     0.0
+                                    };
+  foreman_cif.link.queue_length_packets = 32;
+  foreman_cif.link.queue_delay_ms = 100;
+  foreman_cif.link.link_capacity_kbps = 500;
+  RunTest(foreman_cif);
+}
+
+TEST_F(FullStackTest, ForemanCif1000kbps100msLimitedQueue) {
+  FullStackTestParams foreman_cif = {"foreman_cif_1000kbps_100ms_32pkts_queue",
+                                     {"foreman_cif", 352, 288, 30},
+                                     30000,
+                                     2000000,
+                                     2000000,
+                                     0.0,
+                                     0.0
+                                    };
+  foreman_cif.link.queue_length_packets = 32;
+  foreman_cif.link.queue_delay_ms = 100;
+  foreman_cif.link.link_capacity_kbps = 1000;
+  RunTest(foreman_cif);
+}
 }  // namespace webrtc
diff --git a/webrtc/video/rampup_tests.cc b/webrtc/video/rampup_tests.cc
index b6f6381..af3be86 100644
--- a/webrtc/video/rampup_tests.cc
+++ b/webrtc/video/rampup_tests.cc
@@ -220,7 +220,7 @@
                          kRemoteBitrateEstimatorMinBitrateBps));
   forward_transport_config_.link_capacity_kbps =
       kHighBandwidthLimitBps / 1000;
-  forward_transport_config_.queue_length = 100;  // Something large.
+  forward_transport_config_.queue_length_packets = 100;  // Something large.
   test::DirectTransport::SetConfig(forward_transport_config_);
   test::DirectTransport::SetReceiver(this);
 }