OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_BITRATE_ESTIMATOR_UNITTES T_HELPER_H_ | 11 #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_UNITTEST_HELPER_H_ |
12 #define WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_BITRATE_ESTIMATOR_UNITTES T_HELPER_H_ | 12 #define WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_UNITTEST_HELPER_H_ |
13 | 13 |
14 #include <list> | 14 #include <list> |
15 #include <map> | 15 #include <map> |
16 #include <memory> | 16 #include <memory> |
17 #include <utility> | 17 #include <utility> |
18 #include <vector> | 18 #include <vector> |
19 | 19 |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "webrtc/base/constructormagic.h" | 21 #include "webrtc/base/constructormagic.h" |
22 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h" | 22 #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimat or.h" |
23 #include "webrtc/system_wrappers/include/clock.h" | 23 #include "webrtc/system_wrappers/include/clock.h" |
24 | 24 |
25 namespace webrtc { | 25 namespace webrtc { |
26 namespace testing { | 26 namespace test { |
27 | 27 |
28 class TestBitrateObserver : public RemoteBitrateObserver { | 28 class TestBitrateObserver : public RemoteBitrateObserver { |
29 public: | 29 public: |
30 TestBitrateObserver() : updated_(false), latest_bitrate_(0) {} | 30 TestBitrateObserver() : updated_(false), latest_bitrate_(0) {} |
31 virtual ~TestBitrateObserver() {} | 31 virtual ~TestBitrateObserver() {} |
32 | 32 |
33 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, | 33 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
34 uint32_t bitrate) override; | 34 uint32_t bitrate) override; |
35 | 35 |
36 void Reset() { updated_ = false; } | 36 void Reset() { updated_ = false; } |
37 | 37 |
38 bool updated() const { return updated_; } | 38 bool updated() const { return updated_; } |
39 | 39 |
40 uint32_t latest_bitrate() const { return latest_bitrate_; } | 40 uint32_t latest_bitrate() const { return latest_bitrate_; } |
41 | 41 |
42 private: | 42 private: |
43 bool updated_; | 43 bool updated_; |
44 uint32_t latest_bitrate_; | 44 uint32_t latest_bitrate_; |
45 }; | 45 }; |
46 | 46 |
47 class RtpStream { | 47 class RtpStream { |
48 public: | 48 public: |
49 struct RtpPacket { | |
50 int64_t send_time; | |
51 int64_t arrival_time; | |
52 uint32_t rtp_timestamp; | |
53 size_t size; | |
54 uint32_t ssrc; | |
55 }; | |
56 | |
57 struct RtcpPacket { | |
58 uint32_t ntp_secs; | |
59 uint32_t ntp_frac; | |
60 uint32_t timestamp; | |
61 uint32_t ssrc; | |
62 }; | |
63 | |
64 typedef std::list<RtpPacket*> PacketList; | |
65 | |
66 enum { kSendSideOffsetUs = 1000000 }; | 49 enum { kSendSideOffsetUs = 1000000 }; |
67 | 50 |
68 RtpStream(int fps, | 51 RtpStream(int fps, int bitrate_bps); |
69 int bitrate_bps, | |
70 uint32_t ssrc, | |
71 uint32_t frequency, | |
72 uint32_t timestamp_offset, | |
73 int64_t rtcp_receive_time); | |
74 void set_rtp_timestamp_offset(uint32_t offset); | |
75 | 52 |
76 // Generates a new frame for this stream. If called too soon after the | 53 // Generates a new frame for this stream. If called too soon after the |
77 // previous frame, no frame will be generated. The frame is split into | 54 // previous frame, no frame will be generated. The frame is split into |
78 // packets. | 55 // packets. |
79 int64_t GenerateFrame(int64_t time_now_us, PacketList* packets); | 56 int64_t GenerateFrame(int64_t time_now_us, std::vector<PacketInfo>* packets); |
80 | 57 |
81 // The send-side time when the next frame can be generated. | 58 // The send-side time when the next frame can be generated. |
82 double next_rtp_time() const; | 59 double next_rtp_time() const; |
83 | 60 |
84 // Generates an RTCP packet. | |
85 RtcpPacket* Rtcp(int64_t time_now_us); | |
86 | |
87 void set_bitrate_bps(int bitrate_bps); | 61 void set_bitrate_bps(int bitrate_bps); |
88 | 62 |
89 int bitrate_bps() const; | 63 int bitrate_bps() const; |
90 | 64 |
91 uint32_t ssrc() const; | 65 static bool Compare(const std::unique_ptr<RtpStream>& lhs, |
92 | 66 const std::unique_ptr<RtpStream>& rhs); |
93 static bool Compare(const std::pair<uint32_t, RtpStream*>& left, | |
94 const std::pair<uint32_t, RtpStream*>& right); | |
95 | 67 |
96 private: | 68 private: |
97 enum { kRtcpIntervalUs = 1000000 }; | |
98 | |
99 int fps_; | 69 int fps_; |
100 int bitrate_bps_; | 70 int bitrate_bps_; |
101 uint32_t ssrc_; | |
102 uint32_t frequency_; | |
103 int64_t next_rtp_time_; | 71 int64_t next_rtp_time_; |
104 int64_t next_rtcp_time_; | 72 uint16_t sequence_number_; |
105 uint32_t rtp_timestamp_offset_; | |
106 const double kNtpFracPerMs; | |
107 | 73 |
108 RTC_DISALLOW_COPY_AND_ASSIGN(RtpStream); | 74 RTC_DISALLOW_COPY_AND_ASSIGN(RtpStream); |
109 }; | 75 }; |
110 | 76 |
111 class StreamGenerator { | 77 class StreamGenerator { |
112 public: | 78 public: |
113 typedef std::list<RtpStream::RtcpPacket*> RtcpList; | |
114 | |
115 StreamGenerator(int capacity, double time_now); | 79 StreamGenerator(int capacity, double time_now); |
116 | 80 |
117 ~StreamGenerator(); | 81 ~StreamGenerator(); |
118 | 82 |
119 // Add a new stream. | 83 // Add a new stream. |
120 void AddStream(RtpStream* stream); | 84 void AddStream(RtpStream* stream); |
121 | 85 |
122 // Set the link capacity. | 86 // Set the link capacity. |
123 void set_capacity_bps(int capacity_bps); | 87 void set_capacity_bps(int capacity_bps); |
124 | 88 |
125 // Divides |bitrate_bps| among all streams. The allocated bitrate per stream | 89 // Divides |bitrate_bps| among all streams. The allocated bitrate per stream |
126 // is decided by the initial allocation ratios. | 90 // is decided by the initial allocation ratios. |
127 void SetBitrateBps(int bitrate_bps); | 91 void SetBitrateBps(int bitrate_bps); |
128 | 92 |
129 // Set the RTP timestamp offset for the stream identified by |ssrc|. | 93 // Set the RTP timestamp offset for the stream identified by |ssrc|. |
130 void set_rtp_timestamp_offset(uint32_t ssrc, uint32_t offset); | 94 void set_rtp_timestamp_offset(uint32_t ssrc, uint32_t offset); |
131 | 95 |
132 // TODO(holmer): Break out the channel simulation part from this class to make | 96 // TODO(holmer): Break out the channel simulation part from this class to make |
133 // it possible to simulate different types of channels. | 97 // it possible to simulate different types of channels. |
134 int64_t GenerateFrame(RtpStream::PacketList* packets, int64_t time_now_us); | 98 int64_t GenerateFrame(std::vector<PacketInfo>* packets, int64_t time_now_us); |
135 | 99 |
136 private: | 100 private: |
137 typedef std::map<uint32_t, RtpStream*> StreamMap; | |
138 | |
139 // Capacity of the simulated channel in bits per second. | 101 // Capacity of the simulated channel in bits per second. |
140 int capacity_; | 102 int capacity_; |
141 // The time when the last packet arrived. | 103 // The time when the last packet arrived. |
142 int64_t prev_arrival_time_us_; | 104 int64_t prev_arrival_time_us_; |
143 // All streams being transmitted on this simulated channel. | 105 // All streams being transmitted on this simulated channel. |
144 StreamMap streams_; | 106 std::vector<std::unique_ptr<RtpStream>> streams_; |
145 | 107 |
146 RTC_DISALLOW_COPY_AND_ASSIGN(StreamGenerator); | 108 RTC_DISALLOW_COPY_AND_ASSIGN(StreamGenerator); |
147 }; | 109 }; |
148 } // namespace testing | 110 } // namespace test |
149 | 111 |
150 class RemoteBitrateEstimatorTest : public ::testing::Test { | 112 class DelayBasedBweTest : public ::testing::Test { |
philipel
2016/07/06 13:36:36
Can we rename this to something else? The problem
stefan-webrtc
2016/07/06 14:53:24
I'm removing the existing test class the existing
philipel
2016/07/07 08:11:38
Acknowledged.
| |
151 public: | 113 public: |
152 RemoteBitrateEstimatorTest(); | 114 DelayBasedBweTest(); |
153 virtual ~RemoteBitrateEstimatorTest(); | 115 virtual ~DelayBasedBweTest(); |
154 | 116 |
155 protected: | 117 protected: |
156 virtual void SetUp() = 0; | |
157 | |
158 void AddDefaultStream(); | 118 void AddDefaultStream(); |
159 | 119 |
160 // Helper to convert some time format to resolution used in absolute send time | 120 // Helper to convert some time format to resolution used in absolute send time |
161 // header extension, rounded upwards. |t| is the time to convert, in some | 121 // header extension, rounded upwards. |t| is the time to convert, in some |
162 // resolution. |denom| is the value to divide |t| by to get whole seconds, | 122 // resolution. |denom| is the value to divide |t| by to get whole seconds, |
163 // e.g. |denom| = 1000 if |t| is in milliseconds. | 123 // e.g. |denom| = 1000 if |t| is in milliseconds. |
164 static uint32_t AbsSendTime(int64_t t, int64_t denom); | 124 static uint32_t AbsSendTime(int64_t t, int64_t denom); |
165 | 125 |
166 // Helper to add two absolute send time values and keep it less than 1<<24. | 126 // Helper to add two absolute send time values and keep it less than 1<<24. |
167 static uint32_t AddAbsSendTime(uint32_t t1, uint32_t t2); | 127 static uint32_t AddAbsSendTime(uint32_t t1, uint32_t t2); |
168 | 128 |
169 // Helper to create a WebRtcRTPHeader containing the relevant data for the | 129 // Helpers to insert a single packet into the delay-based BWE. |
170 // estimator (all other fields are cleared) and call IncomingPacket on the | 130 void IncomingPacket(size_t payload_size, |
171 // estimator. | 131 int64_t arrival_time_ms, |
172 void IncomingPacket(uint32_t ssrc, | 132 int64_t send_time_ms, |
173 size_t payload_size, | 133 uint16_t sequence_number); |
174 int64_t arrival_time, | 134 void IncomingPacket(size_t payload_size, |
175 uint32_t rtp_timestamp, | 135 int64_t arrival_time_ms, |
176 uint32_t absolute_send_time); | 136 int64_t send_time_ms, |
137 uint16_t sequence_number, | |
138 int probe_cluster_id); | |
177 | 139 |
178 // Generates a frame of packets belonging to a stream at a given bitrate and | 140 // Generates a frame of packets belonging to a stream at a given bitrate and |
179 // with a given ssrc. The stream is pushed through a very simple simulated | 141 // with a given ssrc. The stream is pushed through a very simple simulated |
180 // network, and is then given to the receive-side bandwidth estimator. | 142 // network, and is then given to the receive-side bandwidth estimator. |
181 // Returns true if an over-use was seen, false otherwise. | 143 // Returns true if an over-use was seen, false otherwise. |
182 // The StreamGenerator::updated() should be used to check for any changes in | 144 // The StreamGenerator::updated() should be used to check for any changes in |
183 // target bitrate after the call to this function. | 145 // target bitrate after the call to this function. |
184 bool GenerateAndProcessFrame(uint32_t ssrc, uint32_t bitrate_bps); | 146 bool GenerateAndProcessFrame(uint32_t ssrc, uint32_t bitrate_bps); |
185 | 147 |
186 // Run the bandwidth estimator with a stream of |number_of_frames| frames, or | 148 // Run the bandwidth estimator with a stream of |number_of_frames| frames, or |
187 // until it reaches |target_bitrate|. | 149 // until it reaches |target_bitrate|. |
188 // Can for instance be used to run the estimator for some time to get it | 150 // Can for instance be used to run the estimator for some time to get it |
189 // into a steady state. | 151 // into a steady state. |
190 uint32_t SteadyStateRun(uint32_t ssrc, | 152 uint32_t SteadyStateRun(uint32_t ssrc, |
191 int number_of_frames, | 153 int number_of_frames, |
192 uint32_t start_bitrate, | 154 uint32_t start_bitrate, |
193 uint32_t min_bitrate, | 155 uint32_t min_bitrate, |
194 uint32_t max_bitrate, | 156 uint32_t max_bitrate, |
195 uint32_t target_bitrate); | 157 uint32_t target_bitrate); |
196 | 158 |
197 void TestTimestampGroupingTestHelper(); | 159 void TestTimestampGroupingTestHelper(); |
198 | 160 |
199 void TestWrappingHelper(int silence_time_s); | 161 void TestWrappingHelper(int silence_time_s); |
200 | 162 |
201 void InitialBehaviorTestHelper(uint32_t expected_converge_bitrate); | 163 void InitialBehaviorTestHelper(uint32_t expected_converge_bitrate); |
202 void RateIncreaseReorderingTestHelper(uint32_t expected_bitrate); | 164 void RateIncreaseReorderingTestHelper(uint32_t expected_bitrate); |
203 void RateIncreaseRtpTimestampsTestHelper(int expected_iterations); | 165 void RateIncreaseRtpTimestampsTestHelper(int expected_iterations); |
204 void CapacityDropTestHelper(int number_of_streams, | 166 void CapacityDropTestHelper(int number_of_streams, |
205 bool wrap_time_stamp, | 167 bool wrap_time_stamp, |
206 uint32_t expected_bitrate_drop_delta); | 168 uint32_t expected_bitrate_drop_delta, |
169 int64_t receiver_clock_offset_change_ms); | |
207 | 170 |
208 static const uint32_t kDefaultSsrc; | 171 static const uint32_t kDefaultSsrc; |
209 static const int kArrivalTimeClockOffsetMs = 60000; | |
210 | 172 |
211 SimulatedClock clock_; // Time at the receiver. | 173 SimulatedClock clock_; // Time at the receiver. |
212 std::unique_ptr<testing::TestBitrateObserver> bitrate_observer_; | 174 std::unique_ptr<test::TestBitrateObserver> bitrate_observer_; |
213 std::unique_ptr<RemoteBitrateEstimator> bitrate_estimator_; | 175 std::unique_ptr<RemoteBitrateEstimator> bitrate_estimator_; |
214 std::unique_ptr<testing::StreamGenerator> stream_generator_; | 176 std::unique_ptr<test::StreamGenerator> stream_generator_; |
177 int64_t arrival_time_offset_ms_; | |
215 | 178 |
216 RTC_DISALLOW_COPY_AND_ASSIGN(RemoteBitrateEstimatorTest); | 179 RTC_DISALLOW_COPY_AND_ASSIGN(DelayBasedBweTest); |
217 }; | 180 }; |
218 } // namespace webrtc | 181 } // namespace webrtc |
219 | 182 |
220 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_BITRATE_ESTIMATOR_UNIT TEST_HELPER_H_ | 183 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_UNITTEST_HELPER_ H_ |
OLD | NEW |