| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 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 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 uint32_t AbsSendTime(int64_t t, int64_t denom) { | 27 uint32_t AbsSendTime(int64_t t, int64_t denom) { |
| 28 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; | 28 return (((t << 18) + (denom >> 1)) / denom) & 0x00fffffful; |
| 29 } | 29 } |
| 30 | 30 |
| 31 void IncomingPacket(uint32_t ssrc, | 31 void IncomingPacket(uint32_t ssrc, |
| 32 size_t payload_size, | 32 size_t payload_size, |
| 33 int64_t arrival_time, | 33 int64_t arrival_time, |
| 34 uint32_t rtp_timestamp, | 34 uint32_t rtp_timestamp, |
| 35 uint32_t absolute_send_time, | 35 uint32_t absolute_send_time, |
| 36 bool was_paced, |
| 36 int probe_cluster_id) { | 37 int probe_cluster_id) { |
| 37 RTPHeader header; | 38 RTPHeader header; |
| 38 memset(&header, 0, sizeof(header)); | 39 memset(&header, 0, sizeof(header)); |
| 39 header.ssrc = ssrc; | 40 header.ssrc = ssrc; |
| 40 header.timestamp = rtp_timestamp; | 41 header.timestamp = rtp_timestamp; |
| 41 header.extension.hasAbsoluteSendTime = true; | 42 header.extension.hasAbsoluteSendTime = true; |
| 42 header.extension.absoluteSendTime = absolute_send_time; | 43 header.extension.absoluteSendTime = absolute_send_time; |
| 43 bwe_.IncomingPacket(arrival_time + kArrivalTimeClockOffsetMs, payload_size, | 44 bwe_.IncomingPacket(arrival_time + kArrivalTimeClockOffsetMs, payload_size, |
| 44 header, probe_cluster_id); | 45 header, was_paced, probe_cluster_id); |
| 45 } | 46 } |
| 46 | 47 |
| 47 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, | 48 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs, |
| 48 uint32_t bitrate) { | 49 uint32_t bitrate) { |
| 49 bitrate_updated_ = true; | 50 bitrate_updated_ = true; |
| 50 latest_bitrate_ = bitrate; | 51 latest_bitrate_ = bitrate; |
| 51 } | 52 } |
| 52 | 53 |
| 53 bool bitrate_updated() { | 54 bool bitrate_updated() { |
| 54 bool res = bitrate_updated_; | 55 bool res = bitrate_updated_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 66 int latest_bitrate_; | 67 int latest_bitrate_; |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 TEST_F(TestDelayBasedBwe, ProbeDetection) { | 70 TEST_F(TestDelayBasedBwe, ProbeDetection) { |
| 70 int64_t now_ms = clock_.TimeInMilliseconds(); | 71 int64_t now_ms = clock_.TimeInMilliseconds(); |
| 71 | 72 |
| 72 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 73 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
| 73 for (int i = 0; i < kNumProbes; ++i) { | 74 for (int i = 0; i < kNumProbes; ++i) { |
| 74 clock_.AdvanceTimeMilliseconds(10); | 75 clock_.AdvanceTimeMilliseconds(10); |
| 75 now_ms = clock_.TimeInMilliseconds(); | 76 now_ms = clock_.TimeInMilliseconds(); |
| 76 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 0); | 77 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), |
| 78 true, 0); |
| 77 } | 79 } |
| 78 EXPECT_TRUE(bitrate_updated()); | 80 EXPECT_TRUE(bitrate_updated()); |
| 79 | 81 |
| 80 // Second burst sent at 8 * 1000 / 5 = 1600 kbps. | 82 // Second burst sent at 8 * 1000 / 5 = 1600 kbps. |
| 81 for (int i = 0; i < kNumProbes; ++i) { | 83 for (int i = 0; i < kNumProbes; ++i) { |
| 82 clock_.AdvanceTimeMilliseconds(5); | 84 clock_.AdvanceTimeMilliseconds(5); |
| 83 now_ms = clock_.TimeInMilliseconds(); | 85 now_ms = clock_.TimeInMilliseconds(); |
| 84 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 1); | 86 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), |
| 87 true, 1); |
| 85 } | 88 } |
| 86 | 89 |
| 87 EXPECT_TRUE(bitrate_updated()); | 90 EXPECT_TRUE(bitrate_updated()); |
| 88 EXPECT_GT(latest_bitrate(), 1500000); | 91 EXPECT_GT(latest_bitrate(), 1500000); |
| 89 } | 92 } |
| 90 | 93 |
| 91 TEST_F(TestDelayBasedBwe, ProbeDetectionNonPacedPackets) { | 94 TEST_F(TestDelayBasedBwe, ProbeDetectionNonPacedPackets) { |
| 92 int64_t now_ms = clock_.TimeInMilliseconds(); | 95 int64_t now_ms = clock_.TimeInMilliseconds(); |
| 93 // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet | 96 // First burst sent at 8 * 1000 / 10 = 800 kbps, but with every other packet |
| 94 // not being paced which could mess things up. | 97 // not being paced which could mess things up. |
| 95 for (int i = 0; i < kNumProbes; ++i) { | 98 for (int i = 0; i < kNumProbes; ++i) { |
| 96 clock_.AdvanceTimeMilliseconds(5); | 99 clock_.AdvanceTimeMilliseconds(5); |
| 97 now_ms = clock_.TimeInMilliseconds(); | 100 now_ms = clock_.TimeInMilliseconds(); |
| 98 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 0); | 101 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), |
| 102 true, 0); |
| 99 // Non-paced packet, arriving 5 ms after. | 103 // Non-paced packet, arriving 5 ms after. |
| 100 clock_.AdvanceTimeMilliseconds(5); | 104 clock_.AdvanceTimeMilliseconds(5); |
| 101 IncomingPacket(0, PacedSender::kMinProbePacketSize + 1, now_ms, 90 * now_ms, | 105 IncomingPacket(0, PacedSender::kMinProbePacketSize + 1, now_ms, 90 * now_ms, |
| 102 AbsSendTime(now_ms, 1000), PacketInfo::kNotAProbe); | 106 AbsSendTime(now_ms, 1000), false, PacketInfo::kNotAProbe); |
| 103 } | 107 } |
| 104 | 108 |
| 105 EXPECT_TRUE(bitrate_updated()); | 109 EXPECT_TRUE(bitrate_updated()); |
| 106 EXPECT_GT(latest_bitrate(), 800000); | 110 EXPECT_GT(latest_bitrate(), 800000); |
| 107 } | 111 } |
| 108 | 112 |
| 109 // Packets will require 5 ms to be transmitted to the receiver, causing packets | 113 // Packets will require 5 ms to be transmitted to the receiver, causing packets |
| 110 // of the second probe to be dispersed. | 114 // of the second probe to be dispersed. |
| 111 TEST_F(TestDelayBasedBwe, ProbeDetectionTooHighBitrate) { | 115 TEST_F(TestDelayBasedBwe, ProbeDetectionTooHighBitrate) { |
| 112 int64_t now_ms = clock_.TimeInMilliseconds(); | 116 int64_t now_ms = clock_.TimeInMilliseconds(); |
| 113 int64_t send_time_ms = 0; | 117 int64_t send_time_ms = 0; |
| 114 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 118 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
| 115 for (int i = 0; i < kNumProbes; ++i) { | 119 for (int i = 0; i < kNumProbes; ++i) { |
| 116 clock_.AdvanceTimeMilliseconds(10); | 120 clock_.AdvanceTimeMilliseconds(10); |
| 117 now_ms = clock_.TimeInMilliseconds(); | 121 now_ms = clock_.TimeInMilliseconds(); |
| 118 send_time_ms += 10; | 122 send_time_ms += 10; |
| 119 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 123 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
| 120 AbsSendTime(send_time_ms, 1000), 0); | 124 AbsSendTime(send_time_ms, 1000), true, 0); |
| 121 } | 125 } |
| 122 | 126 |
| 123 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 = | 127 // Second burst sent at 8 * 1000 / 5 = 1600 kbps, arriving at 8 * 1000 / 8 = |
| 124 // 1000 kbps. | 128 // 1000 kbps. |
| 125 for (int i = 0; i < kNumProbes; ++i) { | 129 for (int i = 0; i < kNumProbes; ++i) { |
| 126 clock_.AdvanceTimeMilliseconds(8); | 130 clock_.AdvanceTimeMilliseconds(8); |
| 127 now_ms = clock_.TimeInMilliseconds(); | 131 now_ms = clock_.TimeInMilliseconds(); |
| 128 send_time_ms += 5; | 132 send_time_ms += 5; |
| 129 IncomingPacket(0, 1000, now_ms, send_time_ms, | 133 IncomingPacket(0, 1000, now_ms, send_time_ms, |
| 130 AbsSendTime(send_time_ms, 1000), 1); | 134 AbsSendTime(send_time_ms, 1000), true, 1); |
| 131 } | 135 } |
| 132 | 136 |
| 133 EXPECT_TRUE(bitrate_updated()); | 137 EXPECT_TRUE(bitrate_updated()); |
| 134 EXPECT_NEAR(latest_bitrate(), 800000, 10000); | 138 EXPECT_NEAR(latest_bitrate(), 800000, 10000); |
| 135 } | 139 } |
| 136 | 140 |
| 137 TEST_F(TestDelayBasedBwe, ProbeDetectionSlightlyFasterArrival) { | 141 TEST_F(TestDelayBasedBwe, ProbeDetectionSlightlyFasterArrival) { |
| 138 int64_t now_ms = clock_.TimeInMilliseconds(); | 142 int64_t now_ms = clock_.TimeInMilliseconds(); |
| 139 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 143 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
| 140 // Arriving at 8 * 1000 / 5 = 1600 kbps. | 144 // Arriving at 8 * 1000 / 5 = 1600 kbps. |
| 141 int64_t send_time_ms = 0; | 145 int64_t send_time_ms = 0; |
| 142 for (int i = 0; i < kNumProbes; ++i) { | 146 for (int i = 0; i < kNumProbes; ++i) { |
| 143 clock_.AdvanceTimeMilliseconds(5); | 147 clock_.AdvanceTimeMilliseconds(5); |
| 144 send_time_ms += 10; | 148 send_time_ms += 10; |
| 145 now_ms = clock_.TimeInMilliseconds(); | 149 now_ms = clock_.TimeInMilliseconds(); |
| 146 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 150 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
| 147 AbsSendTime(send_time_ms, 1000), 23); | 151 AbsSendTime(send_time_ms, 1000), true, 23); |
| 148 } | 152 } |
| 149 | 153 |
| 150 EXPECT_TRUE(bitrate_updated()); | 154 EXPECT_TRUE(bitrate_updated()); |
| 151 EXPECT_GT(latest_bitrate(), 800000); | 155 EXPECT_GT(latest_bitrate(), 800000); |
| 152 } | 156 } |
| 153 | 157 |
| 154 TEST_F(TestDelayBasedBwe, ProbeDetectionFasterArrival) { | 158 TEST_F(TestDelayBasedBwe, ProbeDetectionFasterArrival) { |
| 155 int64_t now_ms = clock_.TimeInMilliseconds(); | 159 int64_t now_ms = clock_.TimeInMilliseconds(); |
| 156 // First burst sent at 8 * 1000 / 10 = 800 kbps. | 160 // First burst sent at 8 * 1000 / 10 = 800 kbps. |
| 157 // Arriving at 8 * 1000 / 5 = 1600 kbps. | 161 // Arriving at 8 * 1000 / 5 = 1600 kbps. |
| 158 int64_t send_time_ms = 0; | 162 int64_t send_time_ms = 0; |
| 159 for (int i = 0; i < kNumProbes; ++i) { | 163 for (int i = 0; i < kNumProbes; ++i) { |
| 160 clock_.AdvanceTimeMilliseconds(1); | 164 clock_.AdvanceTimeMilliseconds(1); |
| 161 send_time_ms += 10; | 165 send_time_ms += 10; |
| 162 now_ms = clock_.TimeInMilliseconds(); | 166 now_ms = clock_.TimeInMilliseconds(); |
| 163 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 167 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
| 164 AbsSendTime(send_time_ms, 1000), 0); | 168 AbsSendTime(send_time_ms, 1000), true, 0); |
| 165 } | 169 } |
| 166 | 170 |
| 167 EXPECT_FALSE(bitrate_updated()); | 171 EXPECT_FALSE(bitrate_updated()); |
| 168 } | 172 } |
| 169 | 173 |
| 170 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrival) { | 174 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrival) { |
| 171 int64_t now_ms = clock_.TimeInMilliseconds(); | 175 int64_t now_ms = clock_.TimeInMilliseconds(); |
| 172 // First burst sent at 8 * 1000 / 5 = 1600 kbps. | 176 // First burst sent at 8 * 1000 / 5 = 1600 kbps. |
| 173 // Arriving at 8 * 1000 / 7 = 1142 kbps. | 177 // Arriving at 8 * 1000 / 7 = 1142 kbps. |
| 174 int64_t send_time_ms = 0; | 178 int64_t send_time_ms = 0; |
| 175 for (int i = 0; i < kNumProbes; ++i) { | 179 for (int i = 0; i < kNumProbes; ++i) { |
| 176 clock_.AdvanceTimeMilliseconds(7); | 180 clock_.AdvanceTimeMilliseconds(7); |
| 177 send_time_ms += 5; | 181 send_time_ms += 5; |
| 178 now_ms = clock_.TimeInMilliseconds(); | 182 now_ms = clock_.TimeInMilliseconds(); |
| 179 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 183 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
| 180 AbsSendTime(send_time_ms, 1000), 1); | 184 AbsSendTime(send_time_ms, 1000), true, 1); |
| 181 } | 185 } |
| 182 | 186 |
| 183 EXPECT_TRUE(bitrate_updated()); | 187 EXPECT_TRUE(bitrate_updated()); |
| 184 EXPECT_NEAR(latest_bitrate(), 1140000, 10000); | 188 EXPECT_NEAR(latest_bitrate(), 1140000, 10000); |
| 185 } | 189 } |
| 186 | 190 |
| 187 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrivalHighBitrate) { | 191 TEST_F(TestDelayBasedBwe, ProbeDetectionSlowerArrivalHighBitrate) { |
| 188 int64_t now_ms = clock_.TimeInMilliseconds(); | 192 int64_t now_ms = clock_.TimeInMilliseconds(); |
| 189 // Burst sent at 8 * 1000 / 1 = 8000 kbps. | 193 // Burst sent at 8 * 1000 / 1 = 8000 kbps. |
| 190 // Arriving at 8 * 1000 / 2 = 4000 kbps. | 194 // Arriving at 8 * 1000 / 2 = 4000 kbps. |
| 191 int64_t send_time_ms = 0; | 195 int64_t send_time_ms = 0; |
| 192 for (int i = 0; i < kNumProbes; ++i) { | 196 for (int i = 0; i < kNumProbes; ++i) { |
| 193 clock_.AdvanceTimeMilliseconds(2); | 197 clock_.AdvanceTimeMilliseconds(2); |
| 194 send_time_ms += 1; | 198 send_time_ms += 1; |
| 195 now_ms = clock_.TimeInMilliseconds(); | 199 now_ms = clock_.TimeInMilliseconds(); |
| 196 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, | 200 IncomingPacket(0, 1000, now_ms, 90 * send_time_ms, |
| 197 AbsSendTime(send_time_ms, 1000), 1); | 201 AbsSendTime(send_time_ms, 1000), true, 1); |
| 198 } | 202 } |
| 199 | 203 |
| 200 EXPECT_TRUE(bitrate_updated()); | 204 EXPECT_TRUE(bitrate_updated()); |
| 201 EXPECT_NEAR(latest_bitrate(), 4000000u, 10000); | 205 EXPECT_NEAR(latest_bitrate(), 4000000u, 10000); |
| 202 } | 206 } |
| 203 | 207 |
| 204 TEST_F(TestDelayBasedBwe, ProbingIgnoresSmallPackets) { | 208 TEST_F(TestDelayBasedBwe, ProbingIgnoresSmallPackets) { |
| 205 int64_t now_ms = clock_.TimeInMilliseconds(); | 209 int64_t now_ms = clock_.TimeInMilliseconds(); |
| 206 // Probing with 200 bytes every 10 ms, should be ignored by the probe | 210 // Probing with 200 bytes every 10 ms, should be ignored by the probe |
| 207 // detection. | 211 // detection. |
| 208 for (int i = 0; i < kNumProbes; ++i) { | 212 for (int i = 0; i < kNumProbes; ++i) { |
| 209 clock_.AdvanceTimeMilliseconds(10); | 213 clock_.AdvanceTimeMilliseconds(10); |
| 210 now_ms = clock_.TimeInMilliseconds(); | 214 now_ms = clock_.TimeInMilliseconds(); |
| 211 IncomingPacket(0, PacedSender::kMinProbePacketSize, now_ms, 90 * now_ms, | 215 IncomingPacket(0, PacedSender::kMinProbePacketSize, now_ms, 90 * now_ms, |
| 212 AbsSendTime(now_ms, 1000), 1); | 216 AbsSendTime(now_ms, 1000), true, 1); |
| 213 } | 217 } |
| 214 | 218 |
| 215 EXPECT_FALSE(bitrate_updated()); | 219 EXPECT_FALSE(bitrate_updated()); |
| 216 | 220 |
| 217 // Followed by a probe with 1000 bytes packets, should be detected as a | 221 // Followed by a probe with 1000 bytes packets, should be detected as a |
| 218 // probe. | 222 // probe. |
| 219 for (int i = 0; i < kNumProbes; ++i) { | 223 for (int i = 0; i < kNumProbes; ++i) { |
| 220 clock_.AdvanceTimeMilliseconds(10); | 224 clock_.AdvanceTimeMilliseconds(10); |
| 221 now_ms = clock_.TimeInMilliseconds(); | 225 now_ms = clock_.TimeInMilliseconds(); |
| 222 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), 1); | 226 IncomingPacket(0, 1000, now_ms, 90 * now_ms, AbsSendTime(now_ms, 1000), |
| 227 true, 1); |
| 223 } | 228 } |
| 224 | 229 |
| 225 // Wait long enough so that we can call Process again. | 230 // Wait long enough so that we can call Process again. |
| 226 clock_.AdvanceTimeMilliseconds(1000); | 231 clock_.AdvanceTimeMilliseconds(1000); |
| 227 | 232 |
| 228 EXPECT_TRUE(bitrate_updated()); | 233 EXPECT_TRUE(bitrate_updated()); |
| 229 EXPECT_NEAR(latest_bitrate(), 800000u, 10000); | 234 EXPECT_NEAR(latest_bitrate(), 800000u, 10000); |
| 230 } | 235 } |
| 231 } // namespace webrtc | 236 } // namespace webrtc |
| OLD | NEW |