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/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
13#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test.h"
14#include "webrtc/test/testsupport/fileutils.h"
15
16using std::string;
17
18namespace webrtc {
19namespace testing {
20namespace bwe {
21#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
22BweTestConfig::EstimatorConfig CreateEstimatorConfig(
23    int flow_id, bool plot_delay, bool plot_estimate) {
24  static const AbsoluteSendTimeRemoteBitrateEstimatorFactory factory =
25      AbsoluteSendTimeRemoteBitrateEstimatorFactory();
26
27  return BweTestConfig::EstimatorConfig("AST", flow_id, &factory, kAimdControl,
28                                        plot_delay, plot_estimate);
29}
30
31BweTestConfig MakeAdaptiveBweTestConfig() {
32  BweTestConfig result;
33  result.estimator_configs.push_back(CreateEstimatorConfig(0, true, true));
34  return result;
35}
36
37BweTestConfig MakeMultiFlowBweTestConfig(int flow_count) {
38  BweTestConfig result;
39  for (int i = 0; i < flow_count; ++i) {
40    result.estimator_configs.push_back(CreateEstimatorConfig(i, false, true));
41  }
42  return result;
43}
44
45// This test fixture is used to instantiate tests running with adaptive video
46// senders.
47class BweSimulation : public BweTest,
48                      public ::testing::TestWithParam<BweTestConfig> {
49 public:
50  BweSimulation() : BweTest() {}
51  virtual ~BweSimulation() {}
52
53  virtual void SetUp() {
54    const BweTestConfig& config = GetParam();
55    SetupTestFromConfig(config);
56  }
57
58 private:
59  DISALLOW_COPY_AND_ASSIGN(BweSimulation);
60};
61
62INSTANTIATE_TEST_CASE_P(VideoSendersTest, BweSimulation,
63    ::testing::Values(MakeAdaptiveBweTestConfig()));
64
65TEST_P(BweSimulation, SprintUplinkTest) {
66  VerboseLogging(true);
67  AdaptiveVideoSender sender(0, this, 30, 300, 0, 0);
68  RateCounterFilter counter1(this, "sender_output");
69  TraceBasedDeliveryFilter filter(this, "link_capacity");
70  RateCounterFilter counter2(this, "receiver_input");
71  ASSERT_TRUE(filter.Init(test::ResourcePath("sprint-uplink", "rx")));
72  RunFor(60 * 1000);
73}
74
75TEST_P(BweSimulation, Verizon4gDownlinkTest) {
76  VerboseLogging(true);
77  AdaptiveVideoSender sender(0, this, 30, 300, 0, 0);
78  RateCounterFilter counter1(this, "sender_output");
79  TraceBasedDeliveryFilter filter(this, "link_capacity");
80  RateCounterFilter counter2(this, "receiver_input");
81  ASSERT_TRUE(filter.Init(test::ResourcePath("verizon4g-downlink", "rx")));
82  RunFor(22 * 60 * 1000);
83}
84
85TEST_P(BweSimulation, Choke1000kbps500kbps1000kbps) {
86  VerboseLogging(true);
87  AdaptiveVideoSender sender(0, this, 30, 300, 0, 0);
88  ChokeFilter filter(this);
89  RateCounterFilter counter(this, "receiver_input");
90  filter.SetCapacity(1000);
91  filter.SetMaxDelay(500);
92  RunFor(60 * 1000);
93  filter.SetCapacity(500);
94  RunFor(60 * 1000);
95  filter.SetCapacity(1000);
96  RunFor(60 * 1000);
97}
98
99TEST_P(BweSimulation, PacerChoke1000kbps500kbps1000kbps) {
100  VerboseLogging(true);
101  AdaptiveVideoSender source(0, NULL, 30, 300, 0, 0);
102  PacedVideoSender sender(this, 300, &source);
103  ChokeFilter filter(this);
104  RateCounterFilter counter(this, "receiver_input");
105  filter.SetCapacity(1000);
106  filter.SetMaxDelay(500);
107  RunFor(60 * 1000);
108  filter.SetCapacity(500);
109  RunFor(60 * 1000);
110  filter.SetCapacity(1000);
111  RunFor(60 * 1000);
112}
113
114TEST_P(BweSimulation, PacerChoke200kbps30kbps200kbps) {
115  VerboseLogging(true);
116  AdaptiveVideoSender source(0, NULL, 30, 300, 0, 0);
117  PacedVideoSender sender(this, 300, &source);
118  ChokeFilter filter(this);
119  RateCounterFilter counter(this, "receiver_input");
120  filter.SetCapacity(200);
121  filter.SetMaxDelay(500);
122  RunFor(60 * 1000);
123  filter.SetCapacity(30);
124  RunFor(60 * 1000);
125  filter.SetCapacity(200);
126  RunFor(60 * 1000);
127}
128
129TEST_P(BweSimulation, Choke200kbps30kbps200kbps) {
130  VerboseLogging(true);
131  AdaptiveVideoSender sender(0, this, 30, 300, 0, 0);
132  ChokeFilter filter(this);
133  RateCounterFilter counter(this, "receiver_input");
134  filter.SetCapacity(200);
135  filter.SetMaxDelay(500);
136  RunFor(60 * 1000);
137  filter.SetCapacity(30);
138  RunFor(60 * 1000);
139  filter.SetCapacity(200);
140  RunFor(60 * 1000);
141}
142
143TEST_P(BweSimulation, GoogleWifiTrace3Mbps) {
144  VerboseLogging(true);
145  AdaptiveVideoSender sender(0, this, 30, 300, 0, 0);
146  RateCounterFilter counter1(this, "sender_output");
147  TraceBasedDeliveryFilter filter(this, "link_capacity");
148  filter.SetMaxDelay(500);
149  RateCounterFilter counter2(this, "receiver_input");
150  ASSERT_TRUE(filter.Init(test::ResourcePath("google-wifi-3mbps", "rx")));
151  RunFor(300 * 1000);
152}
153
154class MultiFlowBweSimulation : public BweSimulation {
155 public:
156  MultiFlowBweSimulation() : BweSimulation() {}
157  virtual ~MultiFlowBweSimulation() {}
158
159 private:
160  DISALLOW_COPY_AND_ASSIGN(MultiFlowBweSimulation);
161};
162
163INSTANTIATE_TEST_CASE_P(VideoSendersTest, MultiFlowBweSimulation,
164    ::testing::Values(MakeMultiFlowBweTestConfig(3)));
165
166TEST_P(MultiFlowBweSimulation, SelfFairnessTest) {
167  VerboseLogging(true);
168  const int kAllFlowIds[] = {0, 1, 2};
169  const size_t kNumFlows = sizeof(kAllFlowIds) / sizeof(kAllFlowIds[0]);
170  scoped_ptr<AdaptiveVideoSender> senders[kNumFlows];
171  for (size_t i = 0; i < kNumFlows; ++i) {
172    senders[i].reset(new AdaptiveVideoSender(kAllFlowIds[i], this, 30, 300, 0,
173                                             0));
174  }
175  // Second and third flow.
176  ChokeFilter choke(this, CreateFlowIds(&kAllFlowIds[1], 2));
177  choke.SetCapacity(1500);
178  // First flow.
179  ChokeFilter choke2(this, CreateFlowIds(&kAllFlowIds[0], 1));
180  choke2.SetCapacity(1000);
181
182  scoped_ptr<RateCounterFilter> rate_counters[kNumFlows];
183  for (size_t i = 0; i < kNumFlows; ++i) {
184    rate_counters[i].reset(new RateCounterFilter(
185        this, CreateFlowIds(&kAllFlowIds[i], 1), "receiver_input"));
186  }
187  RunFor(30 * 60 * 1000);
188}
189#endif  // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
190}  // namespace bwe
191}  // namespace testing
192}  // namespace webrtc
193