Home | History | Annotate | Download | only in remote_bitrate_estimator
      1 /*
      2  *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include "testing/gtest/include/gtest/gtest.h"
     12 #include "webrtc/base/scoped_ptr.h"
     13 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
     14 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test.h"
     15 #include "webrtc/modules/remote_bitrate_estimator/test/packet_receiver.h"
     16 #include "webrtc/modules/remote_bitrate_estimator/test/packet_sender.h"
     17 #include "webrtc/test/testsupport/fileutils.h"
     18 
     19 
     20 namespace webrtc {
     21 namespace testing {
     22 namespace bwe {
     23 #if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
     24 // This test fixture is used to instantiate tests running with adaptive video
     25 // senders.
     26 class BweSimulation : public BweTest,
     27                       public ::testing::TestWithParam<BandwidthEstimatorType> {
     28  public:
     29   BweSimulation()
     30       : BweTest(), random_(Clock::GetRealTimeClock()->TimeInMicroseconds()) {}
     31   virtual ~BweSimulation() {}
     32 
     33  protected:
     34   void SetUp() override {
     35     BweTest::SetUp();
     36     VerboseLogging(true);
     37   }
     38 
     39   Random random_;
     40 
     41  private:
     42   RTC_DISALLOW_COPY_AND_ASSIGN(BweSimulation);
     43 };
     44 
     45 INSTANTIATE_TEST_CASE_P(VideoSendersTest,
     46                         BweSimulation,
     47                         ::testing::Values(kRembEstimator,
     48                                           kFullSendSideEstimator,
     49                                           kNadaEstimator));
     50 
     51 TEST_P(BweSimulation, SprintUplinkTest) {
     52   AdaptiveVideoSource source(0, 30, 300, 0, 0);
     53   VideoSender sender(&uplink_, &source, GetParam());
     54   RateCounterFilter counter1(&uplink_, 0, "sender_output",
     55                              bwe_names[GetParam()]);
     56   TraceBasedDeliveryFilter filter(&uplink_, 0, "link_capacity");
     57   RateCounterFilter counter2(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
     58   PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
     59   ASSERT_TRUE(filter.Init(test::ResourcePath("sprint-uplink", "rx")));
     60   RunFor(60 * 1000);
     61 }
     62 
     63 TEST_P(BweSimulation, Verizon4gDownlinkTest) {
     64   AdaptiveVideoSource source(0, 30, 300, 0, 0);
     65   VideoSender sender(&downlink_, &source, GetParam());
     66   RateCounterFilter counter1(&downlink_, 0, "sender_output",
     67                              bwe_names[GetParam()] + "_up");
     68   TraceBasedDeliveryFilter filter(&downlink_, 0, "link_capacity");
     69   RateCounterFilter counter2(&downlink_, 0, "Receiver",
     70                              bwe_names[GetParam()] + "_down");
     71   PacketReceiver receiver(&downlink_, 0, GetParam(), true, true);
     72   ASSERT_TRUE(filter.Init(test::ResourcePath("verizon4g-downlink", "rx")));
     73   RunFor(22 * 60 * 1000);
     74 }
     75 
     76 TEST_P(BweSimulation, Choke1000kbps500kbps1000kbpsBiDirectional) {
     77   const int kFlowIds[] = {0, 1};
     78   const size_t kNumFlows = sizeof(kFlowIds) / sizeof(kFlowIds[0]);
     79 
     80   AdaptiveVideoSource source(kFlowIds[0], 30, 300, 0, 0);
     81   VideoSender sender(&uplink_, &source, GetParam());
     82   ChokeFilter choke(&uplink_, kFlowIds[0]);
     83   RateCounterFilter counter(&uplink_, kFlowIds[0], "Receiver_0",
     84                             bwe_names[GetParam()]);
     85   PacketReceiver receiver(&uplink_, kFlowIds[0], GetParam(), true, false);
     86 
     87   AdaptiveVideoSource source2(kFlowIds[1], 30, 300, 0, 0);
     88   VideoSender sender2(&downlink_, &source2, GetParam());
     89   ChokeFilter choke2(&downlink_, kFlowIds[1]);
     90   DelayFilter delay(&downlink_, CreateFlowIds(kFlowIds, kNumFlows));
     91   RateCounterFilter counter2(&downlink_, kFlowIds[1], "Receiver_1",
     92                              bwe_names[GetParam()]);
     93   PacketReceiver receiver2(&downlink_, kFlowIds[1], GetParam(), true, false);
     94 
     95   choke2.set_capacity_kbps(500);
     96   delay.SetOneWayDelayMs(0);
     97 
     98   choke.set_capacity_kbps(1000);
     99   choke.set_max_delay_ms(500);
    100   RunFor(60 * 1000);
    101   choke.set_capacity_kbps(500);
    102   RunFor(60 * 1000);
    103   choke.set_capacity_kbps(1000);
    104   RunFor(60 * 1000);
    105 }
    106 
    107 TEST_P(BweSimulation, Choke1000kbps500kbps1000kbps) {
    108   AdaptiveVideoSource source(0, 30, 300, 0, 0);
    109   VideoSender sender(&uplink_, &source, GetParam());
    110   ChokeFilter choke(&uplink_, 0);
    111   RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
    112   PacketReceiver receiver(&uplink_, 0, GetParam(), true, false);
    113 
    114   choke.set_capacity_kbps(1000);
    115   choke.set_max_delay_ms(500);
    116   RunFor(60 * 1000);
    117   choke.set_capacity_kbps(500);
    118   RunFor(60 * 1000);
    119   choke.set_capacity_kbps(1000);
    120   RunFor(60 * 1000);
    121 }
    122 
    123 TEST_P(BweSimulation, PacerChoke1000kbps500kbps1000kbps) {
    124   AdaptiveVideoSource source(0, 30, 300, 0, 0);
    125   PacedVideoSender sender(&uplink_, &source, GetParam());
    126   ChokeFilter filter(&uplink_, 0);
    127   RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
    128   PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
    129   filter.set_capacity_kbps(1000);
    130   filter.set_max_delay_ms(500);
    131   RunFor(60 * 1000);
    132   filter.set_capacity_kbps(500);
    133   RunFor(60 * 1000);
    134   filter.set_capacity_kbps(1000);
    135   RunFor(60 * 1000);
    136 }
    137 
    138 TEST_P(BweSimulation, PacerChoke10000kbps) {
    139   PeriodicKeyFrameSource source(0, 30, 300, 0, 0, 1000);
    140   PacedVideoSender sender(&uplink_, &source, GetParam());
    141   ChokeFilter filter(&uplink_, 0);
    142   RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
    143   PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
    144   filter.set_capacity_kbps(10000);
    145   filter.set_max_delay_ms(500);
    146   RunFor(60 * 1000);
    147 }
    148 
    149 TEST_P(BweSimulation, PacerChoke200kbps30kbps200kbps) {
    150   AdaptiveVideoSource source(0, 30, 300, 0, 0);
    151   PacedVideoSender sender(&uplink_, &source, GetParam());
    152   ChokeFilter filter(&uplink_, 0);
    153   RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
    154   PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
    155   filter.set_capacity_kbps(200);
    156   filter.set_max_delay_ms(500);
    157   RunFor(60 * 1000);
    158   filter.set_capacity_kbps(30);
    159   RunFor(60 * 1000);
    160   filter.set_capacity_kbps(200);
    161   RunFor(60 * 1000);
    162 }
    163 
    164 TEST_P(BweSimulation, Choke200kbps30kbps200kbps) {
    165   AdaptiveVideoSource source(0, 30, 300, 0, 0);
    166   VideoSender sender(&uplink_, &source, GetParam());
    167   ChokeFilter filter(&uplink_, 0);
    168   RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
    169   PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
    170   filter.set_capacity_kbps(200);
    171   filter.set_max_delay_ms(500);
    172   RunFor(60 * 1000);
    173   filter.set_capacity_kbps(30);
    174   RunFor(60 * 1000);
    175   filter.set_capacity_kbps(200);
    176   RunFor(60 * 1000);
    177 }
    178 
    179 TEST_P(BweSimulation, GoogleWifiTrace3Mbps) {
    180   AdaptiveVideoSource source(0, 30, 300, 0, 0);
    181   VideoSender sender(&uplink_, &source, GetParam());
    182   RateCounterFilter counter1(&uplink_, 0, "sender_output",
    183                              bwe_names[GetParam()]);
    184   TraceBasedDeliveryFilter filter(&uplink_, 0, "link_capacity");
    185   filter.set_max_delay_ms(500);
    186   RateCounterFilter counter2(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
    187   PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
    188   ASSERT_TRUE(filter.Init(test::ResourcePath("google-wifi-3mbps", "rx")));
    189   RunFor(300 * 1000);
    190 }
    191 
    192 TEST_P(BweSimulation, LinearIncreasingCapacity) {
    193   PeriodicKeyFrameSource source(0, 30, 300, 0, 0, 1000000);
    194   PacedVideoSender sender(&uplink_, &source, GetParam());
    195   ChokeFilter filter(&uplink_, 0);
    196   RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
    197   PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
    198   filter.set_max_delay_ms(500);
    199   const int kStartingCapacityKbps = 150;
    200   const int kEndingCapacityKbps = 1500;
    201   const int kStepKbps = 5;
    202   const int kStepTimeMs = 1000;
    203 
    204   for (int i = kStartingCapacityKbps; i <= kEndingCapacityKbps;
    205        i += kStepKbps) {
    206     filter.set_capacity_kbps(i);
    207     RunFor(kStepTimeMs);
    208   }
    209 }
    210 
    211 TEST_P(BweSimulation, LinearDecreasingCapacity) {
    212   PeriodicKeyFrameSource source(0, 30, 300, 0, 0, 1000000);
    213   PacedVideoSender sender(&uplink_, &source, GetParam());
    214   ChokeFilter filter(&uplink_, 0);
    215   RateCounterFilter counter(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
    216   PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
    217   filter.set_max_delay_ms(500);
    218   const int kStartingCapacityKbps = 1500;
    219   const int kEndingCapacityKbps = 150;
    220   const int kStepKbps = -5;
    221   const int kStepTimeMs = 1000;
    222 
    223   for (int i = kStartingCapacityKbps; i >= kEndingCapacityKbps;
    224        i += kStepKbps) {
    225     filter.set_capacity_kbps(i);
    226     RunFor(kStepTimeMs);
    227   }
    228 }
    229 
    230 TEST_P(BweSimulation, PacerGoogleWifiTrace3Mbps) {
    231   PeriodicKeyFrameSource source(0, 30, 300, 0, 0, 1000);
    232   PacedVideoSender sender(&uplink_, &source, GetParam());
    233   RateCounterFilter counter1(&uplink_, 0, "sender_output",
    234                              bwe_names[GetParam()]);
    235   TraceBasedDeliveryFilter filter(&uplink_, 0, "link_capacity");
    236   filter.set_max_delay_ms(500);
    237   RateCounterFilter counter2(&uplink_, 0, "Receiver", bwe_names[GetParam()]);
    238   PacketReceiver receiver(&uplink_, 0, GetParam(), true, true);
    239   ASSERT_TRUE(filter.Init(test::ResourcePath("google-wifi-3mbps", "rx")));
    240   RunFor(300 * 1000);
    241 }
    242 
    243 TEST_P(BweSimulation, SelfFairnessTest) {
    244   Random prng(Clock::GetRealTimeClock()->TimeInMicroseconds());
    245   const int kAllFlowIds[] = {0, 1, 2, 3};
    246   const size_t kNumFlows = sizeof(kAllFlowIds) / sizeof(kAllFlowIds[0]);
    247   rtc::scoped_ptr<VideoSource> sources[kNumFlows];
    248   rtc::scoped_ptr<VideoSender> senders[kNumFlows];
    249   for (size_t i = 0; i < kNumFlows; ++i) {
    250     // Streams started 20 seconds apart to give them different advantage when
    251     // competing for the bandwidth.
    252     sources[i].reset(new AdaptiveVideoSource(kAllFlowIds[i], 30, 300, 0,
    253                                              i * prng.Rand(39999)));
    254     senders[i].reset(new VideoSender(&uplink_, sources[i].get(), GetParam()));
    255   }
    256 
    257   ChokeFilter choke(&uplink_, CreateFlowIds(kAllFlowIds, kNumFlows));
    258   choke.set_capacity_kbps(1000);
    259 
    260   rtc::scoped_ptr<RateCounterFilter> rate_counters[kNumFlows];
    261   for (size_t i = 0; i < kNumFlows; ++i) {
    262     rate_counters[i].reset(
    263         new RateCounterFilter(&uplink_, CreateFlowIds(&kAllFlowIds[i], 1),
    264                               "Receiver", bwe_names[GetParam()]));
    265   }
    266 
    267   RateCounterFilter total_utilization(
    268       &uplink_, CreateFlowIds(kAllFlowIds, kNumFlows), "total_utilization",
    269       "Total_link_utilization");
    270 
    271   rtc::scoped_ptr<PacketReceiver> receivers[kNumFlows];
    272   for (size_t i = 0; i < kNumFlows; ++i) {
    273     receivers[i].reset(new PacketReceiver(&uplink_, kAllFlowIds[i], GetParam(),
    274                                           i == 0, false));
    275   }
    276 
    277   RunFor(30 * 60 * 1000);
    278 }
    279 
    280 TEST_P(BweSimulation, PacedSelfFairness50msTest) {
    281   const int64_t kAverageOffsetMs = 20 * 1000;
    282   const int kNumRmcatFlows = 4;
    283   int64_t offsets_ms[kNumRmcatFlows];
    284   offsets_ms[0] = random_.Rand(2 * kAverageOffsetMs);
    285   for (int i = 1; i < kNumRmcatFlows; ++i) {
    286     offsets_ms[i] = offsets_ms[i - 1] + random_.Rand(2 * kAverageOffsetMs);
    287   }
    288   RunFairnessTest(GetParam(), kNumRmcatFlows, 0, 1000, 3000, 50, 50, 0,
    289                   offsets_ms);
    290 }
    291 
    292 TEST_P(BweSimulation, PacedSelfFairness500msTest) {
    293   const int64_t kAverageOffsetMs = 20 * 1000;
    294   const int kNumRmcatFlows = 4;
    295   int64_t offsets_ms[kNumRmcatFlows];
    296   offsets_ms[0] = random_.Rand(2 * kAverageOffsetMs);
    297   for (int i = 1; i < kNumRmcatFlows; ++i) {
    298     offsets_ms[i] = offsets_ms[i - 1] + random_.Rand(2 * kAverageOffsetMs);
    299   }
    300   RunFairnessTest(GetParam(), kNumRmcatFlows, 0, 1000, 3000, 500, 50, 0,
    301                   offsets_ms);
    302 }
    303 
    304 TEST_P(BweSimulation, PacedSelfFairness1000msTest) {
    305   const int64_t kAverageOffsetMs = 20 * 1000;
    306   const int kNumRmcatFlows = 4;
    307   int64_t offsets_ms[kNumRmcatFlows];
    308   offsets_ms[0] = random_.Rand(2 * kAverageOffsetMs);
    309   for (int i = 1; i < kNumRmcatFlows; ++i) {
    310     offsets_ms[i] = offsets_ms[i - 1] + random_.Rand(2 * kAverageOffsetMs);
    311   }
    312   RunFairnessTest(GetParam(), 4, 0, 1000, 3000, 1000, 50, 0, offsets_ms);
    313 }
    314 
    315 TEST_P(BweSimulation, TcpFairness50msTest) {
    316   const int64_t kAverageOffsetMs = 20 * 1000;
    317   int64_t offset_ms[] = {random_.Rand(2 * kAverageOffsetMs), 0};
    318   RunFairnessTest(GetParam(), 1, 1, 1000, 2000, 50, 50, 0, offset_ms);
    319 }
    320 
    321 TEST_P(BweSimulation, TcpFairness500msTest) {
    322   const int64_t kAverageOffsetMs = 20 * 1000;
    323   int64_t offset_ms[] = {random_.Rand(2 * kAverageOffsetMs), 0};
    324   RunFairnessTest(GetParam(), 1, 1, 1000, 2000, 500, 50, 0, offset_ms);
    325 }
    326 
    327 TEST_P(BweSimulation, TcpFairness1000msTest) {
    328   const int kAverageOffsetMs = 20 * 1000;
    329   int64_t offset_ms[] = {random_.Rand(2 * kAverageOffsetMs), 0};
    330   RunFairnessTest(GetParam(), 1, 1, 1000, 2000, 1000, 50, 0, offset_ms);
    331 }
    332 
    333 // The following test cases begin with "Evaluation" as a referrence to the
    334 // Internet draft https://tools.ietf.org/html/draft-ietf-rmcat-eval-test-01.
    335 
    336 TEST_P(BweSimulation, Evaluation1) {
    337   RunVariableCapacity1SingleFlow(GetParam());
    338 }
    339 
    340 TEST_P(BweSimulation, Evaluation2) {
    341   const size_t kNumFlows = 2;
    342   RunVariableCapacity2MultipleFlows(GetParam(), kNumFlows);
    343 }
    344 
    345 TEST_P(BweSimulation, Evaluation3) {
    346   RunBidirectionalFlow(GetParam());
    347 }
    348 
    349 TEST_P(BweSimulation, Evaluation4) {
    350   RunSelfFairness(GetParam());
    351 }
    352 
    353 TEST_P(BweSimulation, Evaluation5) {
    354   RunRoundTripTimeFairness(GetParam());
    355 }
    356 
    357 TEST_P(BweSimulation, Evaluation6) {
    358   RunLongTcpFairness(GetParam());
    359 }
    360 
    361 // Different calls to the Evaluation7 will create the same FileSizes
    362 // and StartingTimes as long as the seeds remain unchanged. This is essential
    363 // when calling it with multiple estimators for comparison purposes.
    364 TEST_P(BweSimulation, Evaluation7) {
    365   const int kNumTcpFiles = 10;
    366   RunMultipleShortTcpFairness(GetParam(),
    367                               BweTest::GetFileSizesBytes(kNumTcpFiles),
    368                               BweTest::GetStartingTimesMs(kNumTcpFiles));
    369 }
    370 
    371 TEST_P(BweSimulation, Evaluation8) {
    372   RunPauseResumeFlows(GetParam());
    373 }
    374 
    375 // Following test cases begin with "GccComparison" run the
    376 // evaluation test cases for both GCC and other calling RMCAT.
    377 
    378 TEST_P(BweSimulation, GccComparison1) {
    379   RunVariableCapacity1SingleFlow(GetParam());
    380   BweTest gcc_test(false);
    381   gcc_test.RunVariableCapacity1SingleFlow(kFullSendSideEstimator);
    382 }
    383 
    384 TEST_P(BweSimulation, GccComparison2) {
    385   const size_t kNumFlows = 2;
    386   RunVariableCapacity2MultipleFlows(GetParam(), kNumFlows);
    387   BweTest gcc_test(false);
    388   gcc_test.RunVariableCapacity2MultipleFlows(kFullSendSideEstimator, kNumFlows);
    389 }
    390 
    391 TEST_P(BweSimulation, GccComparison3) {
    392   RunBidirectionalFlow(GetParam());
    393   BweTest gcc_test(false);
    394   gcc_test.RunBidirectionalFlow(kFullSendSideEstimator);
    395 }
    396 
    397 TEST_P(BweSimulation, GccComparison4) {
    398   RunSelfFairness(GetParam());
    399   BweTest gcc_test(false);
    400   gcc_test.RunSelfFairness(GetParam());
    401 }
    402 
    403 TEST_P(BweSimulation, GccComparison5) {
    404   RunRoundTripTimeFairness(GetParam());
    405   BweTest gcc_test(false);
    406   gcc_test.RunRoundTripTimeFairness(kFullSendSideEstimator);
    407 }
    408 
    409 TEST_P(BweSimulation, GccComparison6) {
    410   RunLongTcpFairness(GetParam());
    411   BweTest gcc_test(false);
    412   gcc_test.RunLongTcpFairness(kFullSendSideEstimator);
    413 }
    414 
    415 TEST_P(BweSimulation, GccComparison7) {
    416   const int kNumTcpFiles = 10;
    417 
    418   std::vector<int> tcp_file_sizes_bytes =
    419       BweTest::GetFileSizesBytes(kNumTcpFiles);
    420   std::vector<int64_t> tcp_starting_times_ms =
    421       BweTest::GetStartingTimesMs(kNumTcpFiles);
    422 
    423   RunMultipleShortTcpFairness(GetParam(), tcp_file_sizes_bytes,
    424                               tcp_starting_times_ms);
    425 
    426   BweTest gcc_test(false);
    427   gcc_test.RunMultipleShortTcpFairness(
    428       kFullSendSideEstimator, tcp_file_sizes_bytes, tcp_starting_times_ms);
    429 }
    430 
    431 TEST_P(BweSimulation, GccComparison8) {
    432   RunPauseResumeFlows(GetParam());
    433   BweTest gcc_test(false);
    434   gcc_test.RunPauseResumeFlows(kFullSendSideEstimator);
    435 }
    436 
    437 TEST_P(BweSimulation, GccComparisonChoke) {
    438   int array[] = {1000, 500, 1000};
    439   std::vector<int> capacities_kbps(array, array + 3);
    440   RunChoke(GetParam(), capacities_kbps);
    441 
    442   BweTest gcc_test(false);
    443   gcc_test.RunChoke(kFullSendSideEstimator, capacities_kbps);
    444 }
    445 
    446 #endif  // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
    447 }  // namespace bwe
    448 }  // namespace testing
    449 }  // namespace webrtc
    450 
    451