pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | |
Jonas Olsson | a4d8737 | 2019-07-05 17:08:33 | [diff] [blame] | 11 | #include "modules/remote_bitrate_estimator/inter_arrival.h" |
| 12 | |
kwiberg | 92931b1 | 2016-03-01 13:32:29 | [diff] [blame] | 13 | #include <memory> |
| 14 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 15 | #include "test/gtest.h" |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | namespace testing { |
| 19 | |
| 20 | enum { |
| 21 | kTimestampGroupLengthUs = 5000, |
| 22 | kMinStep = 20, |
| 23 | kTriggerNewGroupUs = kTimestampGroupLengthUs + kMinStep, |
| 24 | kBurstThresholdMs = 5, |
| 25 | kAbsSendTimeFraction = 18, |
| 26 | kAbsSendTimeInterArrivalUpshift = 8, |
| 27 | kInterArrivalShift = kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift, |
| 28 | }; |
| 29 | |
| 30 | const double kRtpTimestampToMs = 1.0 / 90.0; |
| 31 | const double kAstToMs = 1000.0 / static_cast<double>(1 << kInterArrivalShift); |
| 32 | |
| 33 | class InterArrivalTest : public ::testing::Test { |
| 34 | protected: |
| 35 | virtual void SetUp() { |
Danil Chapovalov | bbc926d | 2023-03-21 19:46:39 | [diff] [blame] | 36 | inter_arrival_.reset(new InterArrival(kTimestampGroupLengthUs / 1000, 1.0)); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 37 | inter_arrival_rtp_.reset(new InterArrival( |
Danil Chapovalov | bbc926d | 2023-03-21 19:46:39 | [diff] [blame] | 38 | MakeRtpTimestamp(kTimestampGroupLengthUs), kRtpTimestampToMs)); |
| 39 | inter_arrival_ast_.reset( |
| 40 | new InterArrival(MakeAbsSendTime(kTimestampGroupLengthUs), kAstToMs)); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | // Test that neither inter_arrival instance complete the timestamp group from |
| 44 | // the given data. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 45 | void ExpectFalse(int64_t timestamp_us, |
| 46 | int64_t arrival_time_ms, |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 47 | size_t packet_size) { |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 48 | InternalExpectFalse(inter_arrival_rtp_.get(), |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 49 | MakeRtpTimestamp(timestamp_us), arrival_time_ms, |
| 50 | packet_size); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 51 | InternalExpectFalse(inter_arrival_ast_.get(), MakeAbsSendTime(timestamp_us), |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 52 | arrival_time_ms, packet_size); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | // Test that both inter_arrival instances complete the timestamp group from |
| 56 | // the given data and that all returned deltas are as expected (except |
| 57 | // timestamp delta, which is rounded from us to different ranges and must |
| 58 | // match within an interval, given in |timestamp_near]. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 59 | void ExpectTrue(int64_t timestamp_us, |
| 60 | int64_t arrival_time_ms, |
| 61 | size_t packet_size, |
| 62 | int64_t expected_timestamp_delta_us, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 63 | int64_t expected_arrival_time_delta_ms, |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 64 | int expected_packet_size_delta, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 65 | uint32_t timestamp_near) { |
| 66 | InternalExpectTrue(inter_arrival_rtp_.get(), MakeRtpTimestamp(timestamp_us), |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 67 | arrival_time_ms, packet_size, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 68 | MakeRtpTimestamp(expected_timestamp_delta_us), |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 69 | expected_arrival_time_delta_ms, |
| 70 | expected_packet_size_delta, timestamp_near); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 71 | InternalExpectTrue(inter_arrival_ast_.get(), MakeAbsSendTime(timestamp_us), |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 72 | arrival_time_ms, packet_size, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 73 | MakeAbsSendTime(expected_timestamp_delta_us), |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 74 | expected_arrival_time_delta_ms, |
| 75 | expected_packet_size_delta, timestamp_near << 8); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 76 | } |
| 77 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 78 | void WrapTestHelper(int64_t wrap_start_us, |
| 79 | uint32_t timestamp_near, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 80 | bool unorderly_within_group) { |
| 81 | // Step through the range of a 32 bit int, 1/4 at a time to not cause |
| 82 | // packets close to wraparound to be judged as out of order. |
| 83 | |
| 84 | // G1 |
| 85 | int64_t arrival_time = 17; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 86 | ExpectFalse(0, arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 87 | |
| 88 | // G2 |
| 89 | arrival_time += kBurstThresholdMs + 1; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 90 | ExpectFalse(wrap_start_us / 4, arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 91 | |
| 92 | // G3 |
| 93 | arrival_time += kBurstThresholdMs + 1; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 94 | ExpectTrue(wrap_start_us / 2, arrival_time, 1, wrap_start_us / 4, 6, |
| 95 | 0, // Delta G2-G1 |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 96 | 0); |
| 97 | |
| 98 | // G4 |
| 99 | arrival_time += kBurstThresholdMs + 1; |
| 100 | int64_t g4_arrival_time = arrival_time; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 101 | ExpectTrue(wrap_start_us / 2 + wrap_start_us / 4, arrival_time, 1, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 102 | wrap_start_us / 4, 6, 0, // Delta G3-G2 |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 103 | timestamp_near); |
| 104 | |
| 105 | // G5 |
| 106 | arrival_time += kBurstThresholdMs + 1; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 107 | ExpectTrue(wrap_start_us, arrival_time, 2, wrap_start_us / 4, 6, |
| 108 | 0, // Delta G4-G3 |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 109 | timestamp_near); |
| 110 | for (int i = 0; i < 10; ++i) { |
| 111 | // Slowly step across the wrap point. |
| 112 | arrival_time += kBurstThresholdMs + 1; |
| 113 | if (unorderly_within_group) { |
| 114 | // These packets arrive with timestamps in decreasing order but are |
| 115 | // nevertheless accumulated to group because their timestamps are higher |
| 116 | // than the initial timestamp of the group. |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 117 | ExpectFalse(wrap_start_us + kMinStep * (9 - i), arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 118 | } else { |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 119 | ExpectFalse(wrap_start_us + kMinStep * i, arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | int64_t g5_arrival_time = arrival_time; |
| 123 | |
| 124 | // This packet is out of order and should be dropped. |
| 125 | arrival_time += kBurstThresholdMs + 1; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 126 | ExpectFalse(wrap_start_us - 100, arrival_time, 100); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 127 | |
| 128 | // G6 |
| 129 | arrival_time += kBurstThresholdMs + 1; |
| 130 | int64_t g6_arrival_time = arrival_time; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 131 | ExpectTrue(wrap_start_us + kTriggerNewGroupUs, arrival_time, 10, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 132 | wrap_start_us / 4 + 9 * kMinStep, |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 133 | g5_arrival_time - g4_arrival_time, |
| 134 | (2 + 10) - 1, // Delta G5-G4 |
| 135 | timestamp_near); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 136 | |
| 137 | // This packet is out of order and should be dropped. |
| 138 | arrival_time += kBurstThresholdMs + 1; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 139 | ExpectFalse(wrap_start_us + kTimestampGroupLengthUs, arrival_time, 100); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 140 | |
| 141 | // G7 |
| 142 | arrival_time += kBurstThresholdMs + 1; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 143 | ExpectTrue(wrap_start_us + 2 * kTriggerNewGroupUs, arrival_time, 100, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 144 | // Delta G6-G5 |
| 145 | kTriggerNewGroupUs - 9 * kMinStep, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 146 | g6_arrival_time - g5_arrival_time, 10 - (2 + 10), |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 147 | timestamp_near); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 148 | } |
| 149 | |
stefan | 5e12d36 | 2016-07-11 08:44:02 | [diff] [blame] | 150 | std::unique_ptr<InterArrival> inter_arrival_; |
| 151 | |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 152 | private: |
| 153 | static uint32_t MakeRtpTimestamp(int64_t us) { |
| 154 | return static_cast<uint32_t>(static_cast<uint64_t>(us * 90 + 500) / 1000); |
| 155 | } |
| 156 | |
| 157 | static uint32_t MakeAbsSendTime(int64_t us) { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 158 | uint32_t absolute_send_time = |
| 159 | static_cast<uint32_t>(((static_cast<uint64_t>(us) << 18) + 500000) / |
| 160 | 1000000) & |
| 161 | 0x00FFFFFFul; |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 162 | return absolute_send_time << 8; |
| 163 | } |
| 164 | |
| 165 | static void InternalExpectFalse(InterArrival* inter_arrival, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 166 | uint32_t timestamp, |
| 167 | int64_t arrival_time_ms, |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 168 | size_t packet_size) { |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 169 | uint32_t dummy_timestamp = 101; |
| 170 | int64_t dummy_arrival_time_ms = 303; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 171 | int dummy_packet_size = 909; |
stefan | 5e12d36 | 2016-07-11 08:44:02 | [diff] [blame] | 172 | bool computed = inter_arrival->ComputeDeltas( |
| 173 | timestamp, arrival_time_ms, arrival_time_ms, packet_size, |
| 174 | &dummy_timestamp, &dummy_arrival_time_ms, &dummy_packet_size); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 175 | EXPECT_EQ(computed, false); |
| 176 | EXPECT_EQ(101ul, dummy_timestamp); |
| 177 | EXPECT_EQ(303, dummy_arrival_time_ms); |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 178 | EXPECT_EQ(909, dummy_packet_size); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static void InternalExpectTrue(InterArrival* inter_arrival, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 182 | uint32_t timestamp, |
| 183 | int64_t arrival_time_ms, |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 184 | size_t packet_size, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 185 | uint32_t expected_timestamp_delta, |
| 186 | int64_t expected_arrival_time_delta_ms, |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 187 | int expected_packet_size_delta, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 188 | uint32_t timestamp_near) { |
| 189 | uint32_t delta_timestamp = 101; |
| 190 | int64_t delta_arrival_time_ms = 303; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 191 | int delta_packet_size = 909; |
stefan | 5e12d36 | 2016-07-11 08:44:02 | [diff] [blame] | 192 | bool computed = inter_arrival->ComputeDeltas( |
| 193 | timestamp, arrival_time_ms, arrival_time_ms, packet_size, |
| 194 | &delta_timestamp, &delta_arrival_time_ms, &delta_packet_size); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 195 | EXPECT_EQ(true, computed); |
| 196 | EXPECT_NEAR(expected_timestamp_delta, delta_timestamp, timestamp_near); |
| 197 | EXPECT_EQ(expected_arrival_time_delta_ms, delta_arrival_time_ms); |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 198 | EXPECT_EQ(expected_packet_size_delta, delta_packet_size); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 199 | } |
| 200 | |
kwiberg | 92931b1 | 2016-03-01 13:32:29 | [diff] [blame] | 201 | std::unique_ptr<InterArrival> inter_arrival_rtp_; |
| 202 | std::unique_ptr<InterArrival> inter_arrival_ast_; |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | TEST_F(InterArrivalTest, FirstPacket) { |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 206 | ExpectFalse(0, 17, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | TEST_F(InterArrivalTest, FirstGroup) { |
| 210 | // G1 |
| 211 | int64_t arrival_time = 17; |
| 212 | int64_t g1_arrival_time = arrival_time; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 213 | ExpectFalse(0, arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 214 | |
| 215 | // G2 |
| 216 | arrival_time += kBurstThresholdMs + 1; |
| 217 | int64_t g2_arrival_time = arrival_time; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 218 | ExpectFalse(kTriggerNewGroupUs, arrival_time, 2); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 219 | |
| 220 | // G3 |
| 221 | // Only once the first packet of the third group arrives, do we see the deltas |
| 222 | // between the first two. |
| 223 | arrival_time += kBurstThresholdMs + 1; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 224 | ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 1, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 225 | // Delta G2-G1 |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 226 | kTriggerNewGroupUs, g2_arrival_time - g1_arrival_time, 1, 0); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | TEST_F(InterArrivalTest, SecondGroup) { |
| 230 | // G1 |
| 231 | int64_t arrival_time = 17; |
| 232 | int64_t g1_arrival_time = arrival_time; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 233 | ExpectFalse(0, arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 234 | |
| 235 | // G2 |
| 236 | arrival_time += kBurstThresholdMs + 1; |
| 237 | int64_t g2_arrival_time = arrival_time; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 238 | ExpectFalse(kTriggerNewGroupUs, arrival_time, 2); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 239 | |
| 240 | // G3 |
| 241 | arrival_time += kBurstThresholdMs + 1; |
| 242 | int64_t g3_arrival_time = arrival_time; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 243 | ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 1, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 244 | // Delta G2-G1 |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 245 | kTriggerNewGroupUs, g2_arrival_time - g1_arrival_time, 1, 0); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 246 | |
| 247 | // G4 |
| 248 | // First packet of 4th group yields deltas between group 2 and 3. |
| 249 | arrival_time += kBurstThresholdMs + 1; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 250 | ExpectTrue(3 * kTriggerNewGroupUs, arrival_time, 2, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 251 | // Delta G3-G2 |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 252 | kTriggerNewGroupUs, g3_arrival_time - g2_arrival_time, -1, 0); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | TEST_F(InterArrivalTest, AccumulatedGroup) { |
| 256 | // G1 |
| 257 | int64_t arrival_time = 17; |
| 258 | int64_t g1_arrival_time = arrival_time; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 259 | ExpectFalse(0, arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 260 | |
| 261 | // G2 |
| 262 | arrival_time += kBurstThresholdMs + 1; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 263 | ExpectFalse(kTriggerNewGroupUs, 28, 2); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 264 | int64_t timestamp = kTriggerNewGroupUs; |
| 265 | for (int i = 0; i < 10; ++i) { |
| 266 | // A bunch of packets arriving within the same group. |
| 267 | arrival_time += kBurstThresholdMs + 1; |
| 268 | timestamp += kMinStep; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 269 | ExpectFalse(timestamp, arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 270 | } |
| 271 | int64_t g2_arrival_time = arrival_time; |
| 272 | int64_t g2_timestamp = timestamp; |
| 273 | |
| 274 | // G3 |
| 275 | arrival_time = 500; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 276 | ExpectTrue(2 * kTriggerNewGroupUs, arrival_time, 100, g2_timestamp, |
| 277 | g2_arrival_time - g1_arrival_time, |
| 278 | (2 + 10) - 1, // Delta G2-G1 |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 279 | 0); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | TEST_F(InterArrivalTest, OutOfOrderPacket) { |
| 283 | // G1 |
| 284 | int64_t arrival_time = 17; |
| 285 | int64_t timestamp = 0; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 286 | ExpectFalse(timestamp, arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 287 | int64_t g1_timestamp = timestamp; |
| 288 | int64_t g1_arrival_time = arrival_time; |
| 289 | |
| 290 | // G2 |
| 291 | arrival_time += 11; |
| 292 | timestamp += kTriggerNewGroupUs; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 293 | ExpectFalse(timestamp, 28, 2); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 294 | for (int i = 0; i < 10; ++i) { |
| 295 | arrival_time += kBurstThresholdMs + 1; |
| 296 | timestamp += kMinStep; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 297 | ExpectFalse(timestamp, arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 298 | } |
| 299 | int64_t g2_timestamp = timestamp; |
| 300 | int64_t g2_arrival_time = arrival_time; |
| 301 | |
| 302 | // This packet is out of order and should be dropped. |
| 303 | arrival_time = 281; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 304 | ExpectFalse(g1_timestamp, arrival_time, 100); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 305 | |
| 306 | // G3 |
| 307 | arrival_time = 500; |
| 308 | timestamp = 2 * kTriggerNewGroupUs; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 309 | ExpectTrue(timestamp, arrival_time, 100, |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 310 | // Delta G2-G1 |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 311 | g2_timestamp - g1_timestamp, g2_arrival_time - g1_arrival_time, |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 312 | (2 + 10) - 1, 0); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | TEST_F(InterArrivalTest, OutOfOrderWithinGroup) { |
| 316 | // G1 |
| 317 | int64_t arrival_time = 17; |
| 318 | int64_t timestamp = 0; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 319 | ExpectFalse(timestamp, arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 320 | int64_t g1_timestamp = timestamp; |
| 321 | int64_t g1_arrival_time = arrival_time; |
| 322 | |
| 323 | // G2 |
| 324 | timestamp += kTriggerNewGroupUs; |
| 325 | arrival_time += 11; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 326 | ExpectFalse(kTriggerNewGroupUs, 28, 2); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 327 | timestamp += 10 * kMinStep; |
| 328 | int64_t g2_timestamp = timestamp; |
| 329 | for (int i = 0; i < 10; ++i) { |
| 330 | // These packets arrive with timestamps in decreasing order but are |
| 331 | // nevertheless accumulated to group because their timestamps are higher |
| 332 | // than the initial timestamp of the group. |
| 333 | arrival_time += kBurstThresholdMs + 1; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 334 | ExpectFalse(timestamp, arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 335 | timestamp -= kMinStep; |
| 336 | } |
| 337 | int64_t g2_arrival_time = arrival_time; |
| 338 | |
| 339 | // However, this packet is deemed out of order and should be dropped. |
| 340 | arrival_time = 281; |
| 341 | timestamp = g1_timestamp; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 342 | ExpectFalse(timestamp, arrival_time, 100); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 343 | |
| 344 | // G3 |
| 345 | timestamp = 2 * kTriggerNewGroupUs; |
| 346 | arrival_time = 500; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 347 | ExpectTrue(timestamp, arrival_time, 100, g2_timestamp - g1_timestamp, |
| 348 | g2_arrival_time - g1_arrival_time, (2 + 10) - 1, 0); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | TEST_F(InterArrivalTest, TwoBursts) { |
| 352 | // G1 |
| 353 | int64_t g1_arrival_time = 17; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 354 | ExpectFalse(0, g1_arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 355 | |
| 356 | // G2 |
| 357 | int64_t timestamp = kTriggerNewGroupUs; |
| 358 | int64_t arrival_time = 100; // Simulate no packets arriving for 100 ms. |
| 359 | for (int i = 0; i < 10; ++i) { |
| 360 | // A bunch of packets arriving in one burst (within 5 ms apart). |
| 361 | timestamp += 30000; |
| 362 | arrival_time += kBurstThresholdMs; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 363 | ExpectFalse(timestamp, arrival_time, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 364 | } |
| 365 | int64_t g2_arrival_time = arrival_time; |
| 366 | int64_t g2_timestamp = timestamp; |
| 367 | |
| 368 | // G3 |
| 369 | timestamp += 30000; |
| 370 | arrival_time += kBurstThresholdMs + 1; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 371 | ExpectTrue(timestamp, arrival_time, 100, g2_timestamp, |
| 372 | g2_arrival_time - g1_arrival_time, |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 373 | 10 - 1, // Delta G2-G1 |
| 374 | 0); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 375 | } |
| 376 | |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 377 | TEST_F(InterArrivalTest, NoBursts) { |
| 378 | // G1 |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 379 | ExpectFalse(0, 17, 1); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 380 | |
| 381 | // G2 |
| 382 | int64_t timestamp = kTriggerNewGroupUs; |
| 383 | int64_t arrival_time = 28; |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 384 | ExpectFalse(timestamp, arrival_time, 2); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 385 | |
| 386 | // G3 |
| 387 | ExpectTrue(kTriggerNewGroupUs + 30000, arrival_time + kBurstThresholdMs + 1, |
stefan | 64c0a0a | 2015-11-27 09:02:31 | [diff] [blame] | 388 | 100, timestamp - 0, arrival_time - 17, |
| 389 | 2 - 1, // Delta G2-G1 |
| 390 | 0); |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | // Yields 0xfffffffe when converted to internal representation in |
| 394 | // inter_arrival_rtp_ and inter_arrival_ast_ respectively. |
| 395 | static const int64_t kStartRtpTimestampWrapUs = 47721858827; |
| 396 | static const int64_t kStartAbsSendTimeWrapUs = 63999995; |
| 397 | |
| 398 | TEST_F(InterArrivalTest, RtpTimestampWrap) { |
| 399 | WrapTestHelper(kStartRtpTimestampWrapUs, 1, false); |
| 400 | } |
| 401 | |
| 402 | TEST_F(InterArrivalTest, AbsSendTimeWrap) { |
| 403 | WrapTestHelper(kStartAbsSendTimeWrapUs, 1, false); |
| 404 | } |
| 405 | |
| 406 | TEST_F(InterArrivalTest, RtpTimestampWrapOutOfOrderWithinGroup) { |
| 407 | WrapTestHelper(kStartRtpTimestampWrapUs, 1, true); |
| 408 | } |
| 409 | |
| 410 | TEST_F(InterArrivalTest, AbsSendTimeWrapOutOfOrderWithinGroup) { |
| 411 | WrapTestHelper(kStartAbsSendTimeWrapUs, 1, true); |
| 412 | } |
stefan | 5e12d36 | 2016-07-11 08:44:02 | [diff] [blame] | 413 | |
| 414 | TEST_F(InterArrivalTest, PositiveArrivalTimeJump) { |
| 415 | const size_t kPacketSize = 1000; |
| 416 | uint32_t send_time_ms = 10000; |
| 417 | int64_t arrival_time_ms = 20000; |
| 418 | int64_t system_time_ms = 30000; |
| 419 | |
| 420 | uint32_t send_delta; |
| 421 | int64_t arrival_delta; |
| 422 | int size_delta; |
| 423 | EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 424 | send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 425 | &arrival_delta, &size_delta)); |
| 426 | |
| 427 | const int kTimeDeltaMs = 30; |
| 428 | send_time_ms += kTimeDeltaMs; |
| 429 | arrival_time_ms += kTimeDeltaMs; |
| 430 | system_time_ms += kTimeDeltaMs; |
| 431 | EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 432 | send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 433 | &arrival_delta, &size_delta)); |
| 434 | |
| 435 | send_time_ms += kTimeDeltaMs; |
| 436 | arrival_time_ms += kTimeDeltaMs + InterArrival::kArrivalTimeOffsetThresholdMs; |
| 437 | system_time_ms += kTimeDeltaMs; |
| 438 | EXPECT_TRUE(inter_arrival_->ComputeDeltas( |
| 439 | send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 440 | &arrival_delta, &size_delta)); |
| 441 | EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta)); |
| 442 | EXPECT_EQ(kTimeDeltaMs, arrival_delta); |
| 443 | EXPECT_EQ(size_delta, 0); |
| 444 | |
| 445 | send_time_ms += kTimeDeltaMs; |
| 446 | arrival_time_ms += kTimeDeltaMs; |
| 447 | system_time_ms += kTimeDeltaMs; |
| 448 | // The previous arrival time jump should now be detected and cause a reset. |
| 449 | EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 450 | send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 451 | &arrival_delta, &size_delta)); |
| 452 | |
| 453 | // The two next packets will not give a valid delta since we're in the initial |
| 454 | // state. |
| 455 | for (int i = 0; i < 2; ++i) { |
| 456 | send_time_ms += kTimeDeltaMs; |
| 457 | arrival_time_ms += kTimeDeltaMs; |
| 458 | system_time_ms += kTimeDeltaMs; |
| 459 | EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 460 | send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 461 | &arrival_delta, &size_delta)); |
| 462 | } |
| 463 | |
| 464 | send_time_ms += kTimeDeltaMs; |
| 465 | arrival_time_ms += kTimeDeltaMs; |
| 466 | system_time_ms += kTimeDeltaMs; |
| 467 | EXPECT_TRUE(inter_arrival_->ComputeDeltas( |
| 468 | send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 469 | &arrival_delta, &size_delta)); |
| 470 | EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta)); |
| 471 | EXPECT_EQ(kTimeDeltaMs, arrival_delta); |
| 472 | EXPECT_EQ(size_delta, 0); |
| 473 | } |
| 474 | |
| 475 | TEST_F(InterArrivalTest, NegativeArrivalTimeJump) { |
| 476 | const size_t kPacketSize = 1000; |
| 477 | uint32_t send_time_ms = 10000; |
| 478 | int64_t arrival_time_ms = 20000; |
| 479 | int64_t system_time_ms = 30000; |
| 480 | |
| 481 | uint32_t send_delta; |
| 482 | int64_t arrival_delta; |
| 483 | int size_delta; |
| 484 | EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 485 | send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 486 | &arrival_delta, &size_delta)); |
| 487 | |
| 488 | const int kTimeDeltaMs = 30; |
| 489 | send_time_ms += kTimeDeltaMs; |
| 490 | arrival_time_ms += kTimeDeltaMs; |
| 491 | system_time_ms += kTimeDeltaMs; |
| 492 | EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 493 | send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 494 | &arrival_delta, &size_delta)); |
| 495 | |
| 496 | send_time_ms += kTimeDeltaMs; |
| 497 | arrival_time_ms += kTimeDeltaMs; |
| 498 | system_time_ms += kTimeDeltaMs; |
| 499 | EXPECT_TRUE(inter_arrival_->ComputeDeltas( |
| 500 | send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 501 | &arrival_delta, &size_delta)); |
| 502 | EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta)); |
| 503 | EXPECT_EQ(kTimeDeltaMs, arrival_delta); |
| 504 | EXPECT_EQ(size_delta, 0); |
| 505 | |
| 506 | // Three out of order will fail, after that we will be reset and two more will |
| 507 | // fail before we get our first valid delta after the reset. |
| 508 | arrival_time_ms -= 1000; |
| 509 | for (int i = 0; i < InterArrival::kReorderedResetThreshold + 3; ++i) { |
| 510 | send_time_ms += kTimeDeltaMs; |
| 511 | arrival_time_ms += kTimeDeltaMs; |
| 512 | system_time_ms += kTimeDeltaMs; |
| 513 | // The previous arrival time jump should now be detected and cause a reset. |
| 514 | EXPECT_FALSE(inter_arrival_->ComputeDeltas( |
| 515 | send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 516 | &arrival_delta, &size_delta)); |
| 517 | } |
| 518 | |
| 519 | send_time_ms += kTimeDeltaMs; |
| 520 | arrival_time_ms += kTimeDeltaMs; |
| 521 | system_time_ms += kTimeDeltaMs; |
| 522 | EXPECT_TRUE(inter_arrival_->ComputeDeltas( |
| 523 | send_time_ms, arrival_time_ms, system_time_ms, kPacketSize, &send_delta, |
| 524 | &arrival_delta, &size_delta)); |
| 525 | EXPECT_EQ(kTimeDeltaMs, static_cast<int>(send_delta)); |
| 526 | EXPECT_EQ(kTimeDeltaMs, arrival_delta); |
| 527 | EXPECT_EQ(size_delta, 0); |
| 528 | } |
pbos@webrtc.org | 9f79fe6 | 2014-12-04 15:34:06 | [diff] [blame] | 529 | } // namespace testing |
| 530 | } // namespace webrtc |