Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: webrtc/modules/congestion_controller/delay_based_bwe_unittest_helper.h

Issue 2126793002: Reset InterArrival if arrival time clock makes a jump. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix a few test issues. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 int64_t next_rtp_time() const;
83
84 // Generates an RTCP packet.
85 RtcpPacket* Rtcp(int64_t time_now_us);
86 60
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; 79 StreamGenerator(int capacity, int64_t time_now);
114
115 StreamGenerator(int capacity, double time_now);
116
117 ~StreamGenerator();
118 80
119 // Add a new stream. 81 // Add a new stream.
120 void AddStream(RtpStream* stream); 82 void AddStream(RtpStream* stream);
121 83
122 // Set the link capacity. 84 // Set the link capacity.
123 void set_capacity_bps(int capacity_bps); 85 void set_capacity_bps(int capacity_bps);
124 86
125 // Divides |bitrate_bps| among all streams. The allocated bitrate per stream 87 // Divides |bitrate_bps| among all streams. The allocated bitrate per stream
126 // is decided by the initial allocation ratios. 88 // is decided by the initial allocation ratios.
127 void SetBitrateBps(int bitrate_bps); 89 void SetBitrateBps(int bitrate_bps);
128 90
129 // Set the RTP timestamp offset for the stream identified by |ssrc|. 91 // Set the RTP timestamp offset for the stream identified by |ssrc|.
130 void set_rtp_timestamp_offset(uint32_t ssrc, uint32_t offset); 92 void set_rtp_timestamp_offset(uint32_t ssrc, uint32_t offset);
131 93
132 // TODO(holmer): Break out the channel simulation part from this class to make 94 // TODO(holmer): Break out the channel simulation part from this class to make
133 // it possible to simulate different types of channels. 95 // it possible to simulate different types of channels.
134 int64_t GenerateFrame(RtpStream::PacketList* packets, int64_t time_now_us); 96 int64_t GenerateFrame(std::vector<PacketInfo>* packets, int64_t time_now_us);
135 97
136 private: 98 private:
137 typedef std::map<uint32_t, RtpStream*> StreamMap;
138
139 // Capacity of the simulated channel in bits per second. 99 // Capacity of the simulated channel in bits per second.
140 int capacity_; 100 int capacity_;
141 // The time when the last packet arrived. 101 // The time when the last packet arrived.
142 int64_t prev_arrival_time_us_; 102 int64_t prev_arrival_time_us_;
143 // All streams being transmitted on this simulated channel. 103 // All streams being transmitted on this simulated channel.
144 StreamMap streams_; 104 std::vector<std::unique_ptr<RtpStream>> streams_;
145 105
146 RTC_DISALLOW_COPY_AND_ASSIGN(StreamGenerator); 106 RTC_DISALLOW_COPY_AND_ASSIGN(StreamGenerator);
147 }; 107 };
148 } // namespace testing 108 } // namespace test
149 109
150 class RemoteBitrateEstimatorTest : public ::testing::Test { 110 class DelayBasedBweTest : public ::testing::Test {
151 public: 111 public:
152 RemoteBitrateEstimatorTest(); 112 DelayBasedBweTest();
153 virtual ~RemoteBitrateEstimatorTest(); 113 virtual ~DelayBasedBweTest();
154 114
155 protected: 115 protected:
156 virtual void SetUp() = 0;
157
158 void AddDefaultStream(); 116 void AddDefaultStream();
159 117
160 // Helper to convert some time format to resolution used in absolute send time 118 // Helpers to insert a single packet into the delay-based BWE.
161 // header extension, rounded upwards. |t| is the time to convert, in some 119 void IncomingFeedback(int64_t arrival_time_ms,
162 // resolution. |denom| is the value to divide |t| by to get whole seconds, 120 int64_t send_time_ms,
163 // e.g. |denom| = 1000 if |t| is in milliseconds. 121 uint16_t sequence_number,
164 static uint32_t AbsSendTime(int64_t t, int64_t denom); 122 size_t payload_size);
165 123 void IncomingFeedback(int64_t arrival_time_ms,
166 // Helper to add two absolute send time values and keep it less than 1<<24. 124 int64_t send_time_ms,
167 static uint32_t AddAbsSendTime(uint32_t t1, uint32_t t2); 125 uint16_t sequence_number,
168 126 size_t payload_size,
169 // Helper to create a WebRtcRTPHeader containing the relevant data for the 127 int probe_cluster_id);
170 // estimator (all other fields are cleared) and call IncomingPacket on the
171 // estimator.
172 void IncomingPacket(uint32_t ssrc,
173 size_t payload_size,
174 int64_t arrival_time,
175 uint32_t rtp_timestamp,
176 uint32_t absolute_send_time);
177 128
178 // Generates a frame of packets belonging to a stream at a given bitrate and 129 // 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 130 // 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. 131 // network, and is then given to the receive-side bandwidth estimator.
181 // Returns true if an over-use was seen, false otherwise. 132 // Returns true if an over-use was seen, false otherwise.
182 // The StreamGenerator::updated() should be used to check for any changes in 133 // The StreamGenerator::updated() should be used to check for any changes in
183 // target bitrate after the call to this function. 134 // target bitrate after the call to this function.
184 bool GenerateAndProcessFrame(uint32_t ssrc, uint32_t bitrate_bps); 135 bool GenerateAndProcessFrame(uint32_t ssrc, uint32_t bitrate_bps);
185 136
186 // Run the bandwidth estimator with a stream of |number_of_frames| frames, or 137 // Run the bandwidth estimator with a stream of |number_of_frames| frames, or
187 // until it reaches |target_bitrate|. 138 // until it reaches |target_bitrate|.
188 // Can for instance be used to run the estimator for some time to get it 139 // Can for instance be used to run the estimator for some time to get it
189 // into a steady state. 140 // into a steady state.
190 uint32_t SteadyStateRun(uint32_t ssrc, 141 uint32_t SteadyStateRun(uint32_t ssrc,
191 int number_of_frames, 142 int number_of_frames,
192 uint32_t start_bitrate, 143 uint32_t start_bitrate,
193 uint32_t min_bitrate, 144 uint32_t min_bitrate,
194 uint32_t max_bitrate, 145 uint32_t max_bitrate,
195 uint32_t target_bitrate); 146 uint32_t target_bitrate);
196 147
197 void TestTimestampGroupingTestHelper(); 148 void TestTimestampGroupingTestHelper();
198 149
199 void TestWrappingHelper(int silence_time_s); 150 void TestWrappingHelper(int silence_time_s);
200 151
201 void InitialBehaviorTestHelper(uint32_t expected_converge_bitrate); 152 void InitialBehaviorTestHelper(uint32_t expected_converge_bitrate);
202 void RateIncreaseReorderingTestHelper(uint32_t expected_bitrate); 153 void RateIncreaseReorderingTestHelper(uint32_t expected_bitrate);
203 void RateIncreaseRtpTimestampsTestHelper(int expected_iterations); 154 void RateIncreaseRtpTimestampsTestHelper(int expected_iterations);
204 void CapacityDropTestHelper(int number_of_streams, 155 void CapacityDropTestHelper(int number_of_streams,
205 bool wrap_time_stamp, 156 bool wrap_time_stamp,
206 uint32_t expected_bitrate_drop_delta); 157 uint32_t expected_bitrate_drop_delta,
158 int64_t receiver_clock_offset_change_ms);
207 159
208 static const uint32_t kDefaultSsrc; 160 static const uint32_t kDefaultSsrc;
209 static const int kArrivalTimeClockOffsetMs = 60000;
210 161
211 SimulatedClock clock_; // Time at the receiver. 162 SimulatedClock clock_; // Time at the receiver.
212 std::unique_ptr<testing::TestBitrateObserver> bitrate_observer_; 163 std::unique_ptr<test::TestBitrateObserver> bitrate_observer_;
213 std::unique_ptr<RemoteBitrateEstimator> bitrate_estimator_; 164 std::unique_ptr<RemoteBitrateEstimator> bitrate_estimator_;
214 std::unique_ptr<testing::StreamGenerator> stream_generator_; 165 std::unique_ptr<test::StreamGenerator> stream_generator_;
166 int64_t arrival_time_offset_ms_;
215 167
216 RTC_DISALLOW_COPY_AND_ASSIGN(RemoteBitrateEstimatorTest); 168 RTC_DISALLOW_COPY_AND_ASSIGN(DelayBasedBweTest);
217 }; 169 };
218 } // namespace webrtc 170 } // namespace webrtc
219 171
220 #endif // WEBRTC_MODULES_REMOTE_BITRATE_ESTIMATOR_REMOTE_BITRATE_ESTIMATOR_UNIT TEST_HELPER_H_ 172 #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_UNITTEST_HELPER_ H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698