| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 #include "webrtc/modules/audio_coding/neteq/nack.h" | 11 #include "webrtc/modules/audio_coding/neteq/nack_tracker.h" |
| 12 | 12 |
| 13 #include <stdint.h> | 13 #include <stdint.h> |
| 14 | 14 |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 #include <memory> | 16 #include <memory> |
| 17 | 17 |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "webrtc/typedefs.h" | 19 #include "webrtc/typedefs.h" |
| 20 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" | 20 #include "webrtc/modules/audio_coding/include/audio_coding_module_typedefs.h" |
| 21 | 21 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 if (!seq_num_matched) | 49 if (!seq_num_matched) |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 return true; | 52 return true; |
| 53 } | 53 } |
| 54 | 54 |
| 55 } // namespace | 55 } // namespace |
| 56 | 56 |
| 57 TEST(NackTest, EmptyListWhenNoPacketLoss) { | 57 TEST(NackTrackerTest, EmptyListWhenNoPacketLoss) { |
| 58 std::unique_ptr<Nack> nack(Nack::Create(kNackThreshold)); | 58 std::unique_ptr<NackTracker> nack(NackTracker::Create(kNackThreshold)); |
| 59 nack->UpdateSampleRate(kSampleRateHz); | 59 nack->UpdateSampleRate(kSampleRateHz); |
| 60 | 60 |
| 61 int seq_num = 1; | 61 int seq_num = 1; |
| 62 uint32_t timestamp = 0; | 62 uint32_t timestamp = 0; |
| 63 | 63 |
| 64 std::vector<uint16_t> nack_list; | 64 std::vector<uint16_t> nack_list; |
| 65 for (int n = 0; n < 100; n++) { | 65 for (int n = 0; n < 100; n++) { |
| 66 nack->UpdateLastReceivedPacket(seq_num, timestamp); | 66 nack->UpdateLastReceivedPacket(seq_num, timestamp); |
| 67 nack_list = nack->GetNackList(kShortRoundTripTimeMs); | 67 nack_list = nack->GetNackList(kShortRoundTripTimeMs); |
| 68 seq_num++; | 68 seq_num++; |
| 69 timestamp += kTimestampIncrement; | 69 timestamp += kTimestampIncrement; |
| 70 nack_list = nack->GetNackList(kShortRoundTripTimeMs); | 70 nack_list = nack->GetNackList(kShortRoundTripTimeMs); |
| 71 EXPECT_TRUE(nack_list.empty()); | 71 EXPECT_TRUE(nack_list.empty()); |
| 72 } | 72 } |
| 73 } | 73 } |
| 74 | 74 |
| 75 TEST(NackTest, NoNackIfReorderWithinNackThreshold) { | 75 TEST(NackTrackerTest, NoNackIfReorderWithinNackThreshold) { |
| 76 std::unique_ptr<Nack> nack(Nack::Create(kNackThreshold)); | 76 std::unique_ptr<NackTracker> nack(NackTracker::Create(kNackThreshold)); |
| 77 nack->UpdateSampleRate(kSampleRateHz); | 77 nack->UpdateSampleRate(kSampleRateHz); |
| 78 | 78 |
| 79 int seq_num = 1; | 79 int seq_num = 1; |
| 80 uint32_t timestamp = 0; | 80 uint32_t timestamp = 0; |
| 81 std::vector<uint16_t> nack_list; | 81 std::vector<uint16_t> nack_list; |
| 82 | 82 |
| 83 nack->UpdateLastReceivedPacket(seq_num, timestamp); | 83 nack->UpdateLastReceivedPacket(seq_num, timestamp); |
| 84 nack_list = nack->GetNackList(kShortRoundTripTimeMs); | 84 nack_list = nack->GetNackList(kShortRoundTripTimeMs); |
| 85 EXPECT_TRUE(nack_list.empty()); | 85 EXPECT_TRUE(nack_list.empty()); |
| 86 int num_late_packets = kNackThreshold + 1; | 86 int num_late_packets = kNackThreshold + 1; |
| 87 | 87 |
| 88 // Push in reverse order | 88 // Push in reverse order |
| 89 while (num_late_packets > 0) { | 89 while (num_late_packets > 0) { |
| 90 nack->UpdateLastReceivedPacket( | 90 nack->UpdateLastReceivedPacket( |
| 91 seq_num + num_late_packets, | 91 seq_num + num_late_packets, |
| 92 timestamp + num_late_packets * kTimestampIncrement); | 92 timestamp + num_late_packets * kTimestampIncrement); |
| 93 nack_list = nack->GetNackList(kShortRoundTripTimeMs); | 93 nack_list = nack->GetNackList(kShortRoundTripTimeMs); |
| 94 EXPECT_TRUE(nack_list.empty()); | 94 EXPECT_TRUE(nack_list.empty()); |
| 95 num_late_packets--; | 95 num_late_packets--; |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 TEST(NackTest, LatePacketsMovedToNackThenNackListDoesNotChange) { | 99 TEST(NackTrackerTest, LatePacketsMovedToNackThenNackListDoesNotChange) { |
| 100 const uint16_t kSequenceNumberLostPackets[] = {2, 3, 4, 5, 6, 7, 8, 9}; | 100 const uint16_t kSequenceNumberLostPackets[] = {2, 3, 4, 5, 6, 7, 8, 9}; |
| 101 static const int kNumAllLostPackets = sizeof(kSequenceNumberLostPackets) / | 101 static const int kNumAllLostPackets = sizeof(kSequenceNumberLostPackets) / |
| 102 sizeof(kSequenceNumberLostPackets[0]); | 102 sizeof(kSequenceNumberLostPackets[0]); |
| 103 | 103 |
| 104 for (int k = 0; k < 2; k++) { // Two iteration with/without wrap around. | 104 for (int k = 0; k < 2; k++) { // Two iteration with/without wrap around. |
| 105 std::unique_ptr<Nack> nack(Nack::Create(kNackThreshold)); | 105 std::unique_ptr<NackTracker> nack(NackTracker::Create(kNackThreshold)); |
| 106 nack->UpdateSampleRate(kSampleRateHz); | 106 nack->UpdateSampleRate(kSampleRateHz); |
| 107 | 107 |
| 108 uint16_t sequence_num_lost_packets[kNumAllLostPackets]; | 108 uint16_t sequence_num_lost_packets[kNumAllLostPackets]; |
| 109 for (int n = 0; n < kNumAllLostPackets; n++) { | 109 for (int n = 0; n < kNumAllLostPackets; n++) { |
| 110 sequence_num_lost_packets[n] = | 110 sequence_num_lost_packets[n] = |
| 111 kSequenceNumberLostPackets[n] + | 111 kSequenceNumberLostPackets[n] + |
| 112 k * 65531; // Have wrap around in sequence numbers for |k == 1|. | 112 k * 65531; // Have wrap around in sequence numbers for |k == 1|. |
| 113 } | 113 } |
| 114 uint16_t seq_num = sequence_num_lost_packets[0] - 1; | 114 uint16_t seq_num = sequence_num_lost_packets[0] - 1; |
| 115 | 115 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 138 nack->UpdateLastReceivedPacket(seq_num, timestamp); | 138 nack->UpdateLastReceivedPacket(seq_num, timestamp); |
| 139 nack_list = nack->GetNackList(kShortRoundTripTimeMs); | 139 nack_list = nack->GetNackList(kShortRoundTripTimeMs); |
| 140 EXPECT_TRUE(IsNackListCorrect(nack_list, sequence_num_lost_packets, | 140 EXPECT_TRUE(IsNackListCorrect(nack_list, sequence_num_lost_packets, |
| 141 kNumAllLostPackets)); | 141 kNumAllLostPackets)); |
| 142 seq_num++; | 142 seq_num++; |
| 143 timestamp += kTimestampIncrement; | 143 timestamp += kTimestampIncrement; |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 TEST(NackTest, ArrivedPacketsAreRemovedFromNackList) { | 148 TEST(NackTrackerTest, ArrivedPacketsAreRemovedFromNackList) { |
| 149 const uint16_t kSequenceNumberLostPackets[] = {2, 3, 4, 5, 6, 7, 8, 9}; | 149 const uint16_t kSequenceNumberLostPackets[] = {2, 3, 4, 5, 6, 7, 8, 9}; |
| 150 static const int kNumAllLostPackets = sizeof(kSequenceNumberLostPackets) / | 150 static const int kNumAllLostPackets = sizeof(kSequenceNumberLostPackets) / |
| 151 sizeof(kSequenceNumberLostPackets[0]); | 151 sizeof(kSequenceNumberLostPackets[0]); |
| 152 | 152 |
| 153 for (int k = 0; k < 2; ++k) { // Two iteration with/without wrap around. | 153 for (int k = 0; k < 2; ++k) { // Two iteration with/without wrap around. |
| 154 std::unique_ptr<Nack> nack(Nack::Create(kNackThreshold)); | 154 std::unique_ptr<NackTracker> nack(NackTracker::Create(kNackThreshold)); |
| 155 nack->UpdateSampleRate(kSampleRateHz); | 155 nack->UpdateSampleRate(kSampleRateHz); |
| 156 | 156 |
| 157 uint16_t sequence_num_lost_packets[kNumAllLostPackets]; | 157 uint16_t sequence_num_lost_packets[kNumAllLostPackets]; |
| 158 for (int n = 0; n < kNumAllLostPackets; ++n) { | 158 for (int n = 0; n < kNumAllLostPackets; ++n) { |
| 159 sequence_num_lost_packets[n] = kSequenceNumberLostPackets[n] + | 159 sequence_num_lost_packets[n] = kSequenceNumberLostPackets[n] + |
| 160 k * 65531; // Wrap around for |k == 1|. | 160 k * 65531; // Wrap around for |k == 1|. |
| 161 } | 161 } |
| 162 | 162 |
| 163 uint16_t seq_num = sequence_num_lost_packets[0] - 1; | 163 uint16_t seq_num = sequence_num_lost_packets[0] - 1; |
| 164 uint32_t timestamp = 0; | 164 uint32_t timestamp = 0; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 EXPECT_TRUE(IsNackListCorrect( | 199 EXPECT_TRUE(IsNackListCorrect( |
| 200 nack_list, &sequence_num_lost_packets[index_retransmitted_rtp], | 200 nack_list, &sequence_num_lost_packets[index_retransmitted_rtp], |
| 201 num_lost_packets - 1)); // One less lost packet in the list. | 201 num_lost_packets - 1)); // One less lost packet in the list. |
| 202 } | 202 } |
| 203 ASSERT_TRUE(nack_list.empty()); | 203 ASSERT_TRUE(nack_list.empty()); |
| 204 } | 204 } |
| 205 } | 205 } |
| 206 | 206 |
| 207 // Assess if estimation of timestamps and time-to-play is correct. Introduce all | 207 // Assess if estimation of timestamps and time-to-play is correct. Introduce all |
| 208 // combinations that timestamps and sequence numbers might have wrap around. | 208 // combinations that timestamps and sequence numbers might have wrap around. |
| 209 TEST(NackTest, EstimateTimestampAndTimeToPlay) { | 209 TEST(NackTrackerTest, EstimateTimestampAndTimeToPlay) { |
| 210 const uint16_t kLostPackets[] = {2, 3, 4, 5, 6, 7, 8, | 210 const uint16_t kLostPackets[] = {2, 3, 4, 5, 6, 7, 8, |
| 211 9, 10, 11, 12, 13, 14, 15}; | 211 9, 10, 11, 12, 13, 14, 15}; |
| 212 static const int kNumAllLostPackets = | 212 static const int kNumAllLostPackets = |
| 213 sizeof(kLostPackets) / sizeof(kLostPackets[0]); | 213 sizeof(kLostPackets) / sizeof(kLostPackets[0]); |
| 214 | 214 |
| 215 for (int k = 0; k < 4; ++k) { | 215 for (int k = 0; k < 4; ++k) { |
| 216 std::unique_ptr<Nack> nack(Nack::Create(kNackThreshold)); | 216 std::unique_ptr<NackTracker> nack(NackTracker::Create(kNackThreshold)); |
| 217 nack->UpdateSampleRate(kSampleRateHz); | 217 nack->UpdateSampleRate(kSampleRateHz); |
| 218 | 218 |
| 219 // Sequence number wrap around if |k| is 2 or 3; | 219 // Sequence number wrap around if |k| is 2 or 3; |
| 220 int seq_num_offset = (k < 2) ? 0 : 65531; | 220 int seq_num_offset = (k < 2) ? 0 : 65531; |
| 221 | 221 |
| 222 // Timestamp wrap around if |k| is 1 or 3. | 222 // Timestamp wrap around if |k| is 1 or 3. |
| 223 uint32_t timestamp_offset = | 223 uint32_t timestamp_offset = |
| 224 (k & 0x1) ? static_cast<uint32_t>(0xffffffff) - 6 : 0; | 224 (k & 0x1) ? static_cast<uint32_t>(0xffffffff) - 6 : 0; |
| 225 | 225 |
| 226 uint32_t timestamp_lost_packets[kNumAllLostPackets]; | 226 uint32_t timestamp_lost_packets[kNumAllLostPackets]; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 243 seq_num++; | 243 seq_num++; |
| 244 timestamp += kTimestampIncrement; | 244 timestamp += kTimestampIncrement; |
| 245 nack->UpdateLastReceivedPacket(seq_num, timestamp); | 245 nack->UpdateLastReceivedPacket(seq_num, timestamp); |
| 246 | 246 |
| 247 // A packet after the last one which is supposed to be lost. | 247 // A packet after the last one which is supposed to be lost. |
| 248 seq_num = seq_num_lost_packets[kNumAllLostPackets - 1] + 1; | 248 seq_num = seq_num_lost_packets[kNumAllLostPackets - 1] + 1; |
| 249 timestamp = | 249 timestamp = |
| 250 timestamp_lost_packets[kNumAllLostPackets - 1] + kTimestampIncrement; | 250 timestamp_lost_packets[kNumAllLostPackets - 1] + kTimestampIncrement; |
| 251 nack->UpdateLastReceivedPacket(seq_num, timestamp); | 251 nack->UpdateLastReceivedPacket(seq_num, timestamp); |
| 252 | 252 |
| 253 Nack::NackList nack_list = nack->GetNackList(); | 253 NackTracker::NackList nack_list = nack->GetNackList(); |
| 254 EXPECT_EQ(static_cast<size_t>(kNumAllLostPackets), nack_list.size()); | 254 EXPECT_EQ(static_cast<size_t>(kNumAllLostPackets), nack_list.size()); |
| 255 | 255 |
| 256 // Pretend the first packet is decoded. | 256 // Pretend the first packet is decoded. |
| 257 nack->UpdateLastDecodedPacket(first_seq_num, first_timestamp); | 257 nack->UpdateLastDecodedPacket(first_seq_num, first_timestamp); |
| 258 nack_list = nack->GetNackList(); | 258 nack_list = nack->GetNackList(); |
| 259 | 259 |
| 260 Nack::NackList::iterator it = nack_list.begin(); | 260 NackTracker::NackList::iterator it = nack_list.begin(); |
| 261 while (it != nack_list.end()) { | 261 while (it != nack_list.end()) { |
| 262 seq_num = it->first - seq_num_offset; | 262 seq_num = it->first - seq_num_offset; |
| 263 int index = seq_num - kLostPackets[0]; | 263 int index = seq_num - kLostPackets[0]; |
| 264 EXPECT_EQ(timestamp_lost_packets[index], it->second.estimated_timestamp); | 264 EXPECT_EQ(timestamp_lost_packets[index], it->second.estimated_timestamp); |
| 265 EXPECT_EQ((index + 2) * kPacketSizeMs, it->second.time_to_play_ms); | 265 EXPECT_EQ((index + 2) * kPacketSizeMs, it->second.time_to_play_ms); |
| 266 ++it; | 266 ++it; |
| 267 } | 267 } |
| 268 | 268 |
| 269 // Pretend 10 ms is passed, and we had pulled audio from NetEq, it still | 269 // Pretend 10 ms is passed, and we had pulled audio from NetEq, it still |
| 270 // reports the same sequence number as decoded, time-to-play should be | 270 // reports the same sequence number as decoded, time-to-play should be |
| 271 // updated by 10 ms. | 271 // updated by 10 ms. |
| 272 nack->UpdateLastDecodedPacket(first_seq_num, first_timestamp); | 272 nack->UpdateLastDecodedPacket(first_seq_num, first_timestamp); |
| 273 nack_list = nack->GetNackList(); | 273 nack_list = nack->GetNackList(); |
| 274 it = nack_list.begin(); | 274 it = nack_list.begin(); |
| 275 while (it != nack_list.end()) { | 275 while (it != nack_list.end()) { |
| 276 seq_num = it->first - seq_num_offset; | 276 seq_num = it->first - seq_num_offset; |
| 277 int index = seq_num - kLostPackets[0]; | 277 int index = seq_num - kLostPackets[0]; |
| 278 EXPECT_EQ((index + 2) * kPacketSizeMs - 10, it->second.time_to_play_ms); | 278 EXPECT_EQ((index + 2) * kPacketSizeMs - 10, it->second.time_to_play_ms); |
| 279 ++it; | 279 ++it; |
| 280 } | 280 } |
| 281 } | 281 } |
| 282 } | 282 } |
| 283 | 283 |
| 284 TEST(NackTest, MissingPacketsPriorToLastDecodedRtpShouldNotBeInNackList) { | 284 TEST(NackTrackerTest, |
| 285 MissingPacketsPriorToLastDecodedRtpShouldNotBeInNackList) { |
| 285 for (int m = 0; m < 2; ++m) { | 286 for (int m = 0; m < 2; ++m) { |
| 286 uint16_t seq_num_offset = (m == 0) ? 0 : 65531; // Wrap around if |m| is 1. | 287 uint16_t seq_num_offset = (m == 0) ? 0 : 65531; // Wrap around if |m| is 1. |
| 287 std::unique_ptr<Nack> nack(Nack::Create(kNackThreshold)); | 288 std::unique_ptr<NackTracker> nack(NackTracker::Create(kNackThreshold)); |
| 288 nack->UpdateSampleRate(kSampleRateHz); | 289 nack->UpdateSampleRate(kSampleRateHz); |
| 289 | 290 |
| 290 // Two consecutive packets to have a correct estimate of timestamp increase. | 291 // Two consecutive packets to have a correct estimate of timestamp increase. |
| 291 uint16_t seq_num = 0; | 292 uint16_t seq_num = 0; |
| 292 nack->UpdateLastReceivedPacket(seq_num_offset + seq_num, | 293 nack->UpdateLastReceivedPacket(seq_num_offset + seq_num, |
| 293 seq_num * kTimestampIncrement); | 294 seq_num * kTimestampIncrement); |
| 294 seq_num++; | 295 seq_num++; |
| 295 nack->UpdateLastReceivedPacket(seq_num_offset + seq_num, | 296 nack->UpdateLastReceivedPacket(seq_num_offset + seq_num, |
| 296 seq_num * kTimestampIncrement); | 297 seq_num * kTimestampIncrement); |
| 297 | 298 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 327 for (int n = 0; n < kNackThreshold + 10; ++n) { | 328 for (int n = 0; n < kNackThreshold + 10; ++n) { |
| 328 seq_num++; | 329 seq_num++; |
| 329 nack->UpdateLastReceivedPacket(seq_num_offset + seq_num, | 330 nack->UpdateLastReceivedPacket(seq_num_offset + seq_num, |
| 330 seq_num * kTimestampIncrement); | 331 seq_num * kTimestampIncrement); |
| 331 nack_list = nack->GetNackList(kShortRoundTripTimeMs); | 332 nack_list = nack->GetNackList(kShortRoundTripTimeMs); |
| 332 EXPECT_TRUE(nack_list.empty()); | 333 EXPECT_TRUE(nack_list.empty()); |
| 333 } | 334 } |
| 334 } | 335 } |
| 335 } | 336 } |
| 336 | 337 |
| 337 TEST(NackTest, Reset) { | 338 TEST(NackTrackerTest, Reset) { |
| 338 std::unique_ptr<Nack> nack(Nack::Create(kNackThreshold)); | 339 std::unique_ptr<NackTracker> nack(NackTracker::Create(kNackThreshold)); |
| 339 nack->UpdateSampleRate(kSampleRateHz); | 340 nack->UpdateSampleRate(kSampleRateHz); |
| 340 | 341 |
| 341 // Two consecutive packets to have a correct estimate of timestamp increase. | 342 // Two consecutive packets to have a correct estimate of timestamp increase. |
| 342 uint16_t seq_num = 0; | 343 uint16_t seq_num = 0; |
| 343 nack->UpdateLastReceivedPacket(seq_num, seq_num * kTimestampIncrement); | 344 nack->UpdateLastReceivedPacket(seq_num, seq_num * kTimestampIncrement); |
| 344 seq_num++; | 345 seq_num++; |
| 345 nack->UpdateLastReceivedPacket(seq_num, seq_num * kTimestampIncrement); | 346 nack->UpdateLastReceivedPacket(seq_num, seq_num * kTimestampIncrement); |
| 346 | 347 |
| 347 // Skip 10 packets (larger than NACK threshold). | 348 // Skip 10 packets (larger than NACK threshold). |
| 348 const int kNumLostPackets = 10; | 349 const int kNumLostPackets = 10; |
| 349 seq_num += kNumLostPackets + 1; | 350 seq_num += kNumLostPackets + 1; |
| 350 nack->UpdateLastReceivedPacket(seq_num, seq_num * kTimestampIncrement); | 351 nack->UpdateLastReceivedPacket(seq_num, seq_num * kTimestampIncrement); |
| 351 | 352 |
| 352 const size_t kExpectedListSize = kNumLostPackets - kNackThreshold; | 353 const size_t kExpectedListSize = kNumLostPackets - kNackThreshold; |
| 353 std::vector<uint16_t> nack_list = nack->GetNackList(kShortRoundTripTimeMs); | 354 std::vector<uint16_t> nack_list = nack->GetNackList(kShortRoundTripTimeMs); |
| 354 EXPECT_EQ(kExpectedListSize, nack_list.size()); | 355 EXPECT_EQ(kExpectedListSize, nack_list.size()); |
| 355 | 356 |
| 356 nack->Reset(); | 357 nack->Reset(); |
| 357 nack_list = nack->GetNackList(kShortRoundTripTimeMs); | 358 nack_list = nack->GetNackList(kShortRoundTripTimeMs); |
| 358 EXPECT_TRUE(nack_list.empty()); | 359 EXPECT_TRUE(nack_list.empty()); |
| 359 } | 360 } |
| 360 | 361 |
| 361 TEST(NackTest, ListSizeAppliedFromBeginning) { | 362 TEST(NackTrackerTest, ListSizeAppliedFromBeginning) { |
| 362 const size_t kNackListSize = 10; | 363 const size_t kNackListSize = 10; |
| 363 for (int m = 0; m < 2; ++m) { | 364 for (int m = 0; m < 2; ++m) { |
| 364 uint16_t seq_num_offset = (m == 0) ? 0 : 65525; // Wrap around if |m| is 1. | 365 uint16_t seq_num_offset = (m == 0) ? 0 : 65525; // Wrap around if |m| is 1. |
| 365 std::unique_ptr<Nack> nack(Nack::Create(kNackThreshold)); | 366 std::unique_ptr<NackTracker> nack(NackTracker::Create(kNackThreshold)); |
| 366 nack->UpdateSampleRate(kSampleRateHz); | 367 nack->UpdateSampleRate(kSampleRateHz); |
| 367 nack->SetMaxNackListSize(kNackListSize); | 368 nack->SetMaxNackListSize(kNackListSize); |
| 368 | 369 |
| 369 uint16_t seq_num = seq_num_offset; | 370 uint16_t seq_num = seq_num_offset; |
| 370 uint32_t timestamp = 0x12345678; | 371 uint32_t timestamp = 0x12345678; |
| 371 nack->UpdateLastReceivedPacket(seq_num, timestamp); | 372 nack->UpdateLastReceivedPacket(seq_num, timestamp); |
| 372 | 373 |
| 373 // Packet lost more than NACK-list size limit. | 374 // Packet lost more than NACK-list size limit. |
| 374 uint16_t num_lost_packets = kNackThreshold + kNackListSize + 5; | 375 uint16_t num_lost_packets = kNackThreshold + kNackListSize + 5; |
| 375 | 376 |
| 376 seq_num += num_lost_packets + 1; | 377 seq_num += num_lost_packets + 1; |
| 377 timestamp += (num_lost_packets + 1) * kTimestampIncrement; | 378 timestamp += (num_lost_packets + 1) * kTimestampIncrement; |
| 378 nack->UpdateLastReceivedPacket(seq_num, timestamp); | 379 nack->UpdateLastReceivedPacket(seq_num, timestamp); |
| 379 | 380 |
| 380 std::vector<uint16_t> nack_list = nack->GetNackList(kShortRoundTripTimeMs); | 381 std::vector<uint16_t> nack_list = nack->GetNackList(kShortRoundTripTimeMs); |
| 381 EXPECT_EQ(kNackListSize - kNackThreshold, nack_list.size()); | 382 EXPECT_EQ(kNackListSize - kNackThreshold, nack_list.size()); |
| 382 } | 383 } |
| 383 } | 384 } |
| 384 | 385 |
| 385 TEST(NackTest, ChangeOfListSizeAppliedAndOldElementsRemoved) { | 386 TEST(NackTrackerTest, ChangeOfListSizeAppliedAndOldElementsRemoved) { |
| 386 const size_t kNackListSize = 10; | 387 const size_t kNackListSize = 10; |
| 387 for (int m = 0; m < 2; ++m) { | 388 for (int m = 0; m < 2; ++m) { |
| 388 uint16_t seq_num_offset = (m == 0) ? 0 : 65525; // Wrap around if |m| is 1. | 389 uint16_t seq_num_offset = (m == 0) ? 0 : 65525; // Wrap around if |m| is 1. |
| 389 std::unique_ptr<Nack> nack(Nack::Create(kNackThreshold)); | 390 std::unique_ptr<NackTracker> nack(NackTracker::Create(kNackThreshold)); |
| 390 nack->UpdateSampleRate(kSampleRateHz); | 391 nack->UpdateSampleRate(kSampleRateHz); |
| 391 | 392 |
| 392 uint16_t seq_num = seq_num_offset; | 393 uint16_t seq_num = seq_num_offset; |
| 393 uint32_t timestamp = 0x87654321; | 394 uint32_t timestamp = 0x87654321; |
| 394 nack->UpdateLastReceivedPacket(seq_num, timestamp); | 395 nack->UpdateLastReceivedPacket(seq_num, timestamp); |
| 395 | 396 |
| 396 // Packet lost more than NACK-list size limit. | 397 // Packet lost more than NACK-list size limit. |
| 397 uint16_t num_lost_packets = kNackThreshold + kNackListSize + 5; | 398 uint16_t num_lost_packets = kNackThreshold + kNackListSize + 5; |
| 398 | 399 |
| 399 std::unique_ptr<uint16_t[]> seq_num_lost(new uint16_t[num_lost_packets]); | 400 std::unique_ptr<uint16_t[]> seq_num_lost(new uint16_t[num_lost_packets]); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 | 444 |
| 444 // After this packet, NACK list should be empty. | 445 // After this packet, NACK list should be empty. |
| 445 ++seq_num; | 446 ++seq_num; |
| 446 timestamp += kTimestampIncrement; | 447 timestamp += kTimestampIncrement; |
| 447 nack->UpdateLastReceivedPacket(seq_num, timestamp); | 448 nack->UpdateLastReceivedPacket(seq_num, timestamp); |
| 448 nack_list = nack->GetNackList(kShortRoundTripTimeMs); | 449 nack_list = nack->GetNackList(kShortRoundTripTimeMs); |
| 449 EXPECT_TRUE(nack_list.empty()); | 450 EXPECT_TRUE(nack_list.empty()); |
| 450 } | 451 } |
| 451 } | 452 } |
| 452 | 453 |
| 453 TEST(NackTest, RoudTripTimeIsApplied) { | 454 TEST(NackTrackerTest, RoudTripTimeIsApplied) { |
| 454 const int kNackListSize = 200; | 455 const int kNackListSize = 200; |
| 455 std::unique_ptr<Nack> nack(Nack::Create(kNackThreshold)); | 456 std::unique_ptr<NackTracker> nack(NackTracker::Create(kNackThreshold)); |
| 456 nack->UpdateSampleRate(kSampleRateHz); | 457 nack->UpdateSampleRate(kSampleRateHz); |
| 457 nack->SetMaxNackListSize(kNackListSize); | 458 nack->SetMaxNackListSize(kNackListSize); |
| 458 | 459 |
| 459 uint16_t seq_num = 0; | 460 uint16_t seq_num = 0; |
| 460 uint32_t timestamp = 0x87654321; | 461 uint32_t timestamp = 0x87654321; |
| 461 nack->UpdateLastReceivedPacket(seq_num, timestamp); | 462 nack->UpdateLastReceivedPacket(seq_num, timestamp); |
| 462 | 463 |
| 463 // Packet lost more than NACK-list size limit. | 464 // Packet lost more than NACK-list size limit. |
| 464 uint16_t kNumLostPackets = kNackThreshold + 5; | 465 uint16_t kNumLostPackets = kNackThreshold + 5; |
| 465 | 466 |
| 466 seq_num += (1 + kNumLostPackets); | 467 seq_num += (1 + kNumLostPackets); |
| 467 timestamp += (1 + kNumLostPackets) * kTimestampIncrement; | 468 timestamp += (1 + kNumLostPackets) * kTimestampIncrement; |
| 468 nack->UpdateLastReceivedPacket(seq_num, timestamp); | 469 nack->UpdateLastReceivedPacket(seq_num, timestamp); |
| 469 | 470 |
| 470 // Expected time-to-play are: | 471 // Expected time-to-play are: |
| 471 // kPacketSizeMs - 10, 2*kPacketSizeMs - 10, 3*kPacketSizeMs - 10, ... | 472 // kPacketSizeMs - 10, 2*kPacketSizeMs - 10, 3*kPacketSizeMs - 10, ... |
| 472 // | 473 // |
| 473 // sequence number: 1, 2, 3, 4, 5 | 474 // sequence number: 1, 2, 3, 4, 5 |
| 474 // time-to-play: 20, 50, 80, 110, 140 | 475 // time-to-play: 20, 50, 80, 110, 140 |
| 475 // | 476 // |
| 476 std::vector<uint16_t> nack_list = nack->GetNackList(100); | 477 std::vector<uint16_t> nack_list = nack->GetNackList(100); |
| 477 ASSERT_EQ(2u, nack_list.size()); | 478 ASSERT_EQ(2u, nack_list.size()); |
| 478 EXPECT_EQ(4, nack_list[0]); | 479 EXPECT_EQ(4, nack_list[0]); |
| 479 EXPECT_EQ(5, nack_list[1]); | 480 EXPECT_EQ(5, nack_list[1]); |
| 480 } | 481 } |
| 481 | 482 |
| 482 } // namespace webrtc | 483 } // namespace webrtc |
| OLD | NEW |