OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 12 matching lines...) Expand all Loading... | |
23 using ::testing::_; | 23 using ::testing::_; |
24 | 24 |
25 namespace webrtc { | 25 namespace webrtc { |
26 | 26 |
27 // Helper class to generate packets. Packets must be deleted by the user. | 27 // Helper class to generate packets. Packets must be deleted by the user. |
28 class PacketGenerator { | 28 class PacketGenerator { |
29 public: | 29 public: |
30 PacketGenerator(uint16_t seq_no, uint32_t ts, uint8_t pt, int frame_size); | 30 PacketGenerator(uint16_t seq_no, uint32_t ts, uint8_t pt, int frame_size); |
31 virtual ~PacketGenerator() {} | 31 virtual ~PacketGenerator() {} |
32 void Reset(uint16_t seq_no, uint32_t ts, uint8_t pt, int frame_size); | 32 void Reset(uint16_t seq_no, uint32_t ts, uint8_t pt, int frame_size); |
33 Packet* NextPacket(int payload_size_bytes); | 33 Packet NextPacket(int payload_size_bytes); |
34 | 34 |
35 uint16_t seq_no_; | 35 uint16_t seq_no_; |
36 uint32_t ts_; | 36 uint32_t ts_; |
37 uint8_t pt_; | 37 uint8_t pt_; |
38 int frame_size_; | 38 int frame_size_; |
39 }; | 39 }; |
40 | 40 |
41 PacketGenerator::PacketGenerator(uint16_t seq_no, uint32_t ts, uint8_t pt, | 41 PacketGenerator::PacketGenerator(uint16_t seq_no, uint32_t ts, uint8_t pt, |
42 int frame_size) { | 42 int frame_size) { |
43 Reset(seq_no, ts, pt, frame_size); | 43 Reset(seq_no, ts, pt, frame_size); |
44 } | 44 } |
45 | 45 |
46 void PacketGenerator::Reset(uint16_t seq_no, uint32_t ts, uint8_t pt, | 46 void PacketGenerator::Reset(uint16_t seq_no, uint32_t ts, uint8_t pt, |
47 int frame_size) { | 47 int frame_size) { |
48 seq_no_ = seq_no; | 48 seq_no_ = seq_no; |
49 ts_ = ts; | 49 ts_ = ts; |
50 pt_ = pt; | 50 pt_ = pt; |
51 frame_size_ = frame_size; | 51 frame_size_ = frame_size; |
52 } | 52 } |
53 | 53 |
54 Packet* PacketGenerator::NextPacket(int payload_size_bytes) { | 54 Packet PacketGenerator::NextPacket(int payload_size_bytes) { |
55 Packet* packet = new Packet; | 55 Packet packet; |
56 packet->sequence_number = seq_no_; | 56 packet.sequence_number = seq_no_; |
57 packet->timestamp = ts_; | 57 packet.timestamp = ts_; |
58 packet->payload_type = pt_; | 58 packet.payload_type = pt_; |
59 packet->payload.SetSize(payload_size_bytes); | 59 packet.payload.SetSize(payload_size_bytes); |
60 ++seq_no_; | 60 ++seq_no_; |
61 ts_ += frame_size_; | 61 ts_ += frame_size_; |
62 return packet; | 62 return packet; |
63 } | 63 } |
64 | 64 |
65 struct PacketsToInsert { | 65 struct PacketsToInsert { |
66 uint16_t sequence_number; | 66 uint16_t sequence_number; |
67 uint32_t timestamp; | 67 uint32_t timestamp; |
68 uint8_t payload_type; | 68 uint8_t payload_type; |
69 bool primary; | 69 bool primary; |
(...skipping 11 matching lines...) Expand all Loading... | |
81 EXPECT_TRUE(buffer->Empty()); | 81 EXPECT_TRUE(buffer->Empty()); |
82 delete buffer; | 82 delete buffer; |
83 } | 83 } |
84 | 84 |
85 TEST(PacketBuffer, InsertPacket) { | 85 TEST(PacketBuffer, InsertPacket) { |
86 TickTimer tick_timer; | 86 TickTimer tick_timer; |
87 PacketBuffer buffer(10, &tick_timer); // 10 packets. | 87 PacketBuffer buffer(10, &tick_timer); // 10 packets. |
88 PacketGenerator gen(17u, 4711u, 0, 10); | 88 PacketGenerator gen(17u, 4711u, 0, 10); |
89 | 89 |
90 const int payload_len = 100; | 90 const int payload_len = 100; |
91 Packet* packet = gen.NextPacket(payload_len); | 91 Packet packet = gen.NextPacket(payload_len); |
kwiberg-webrtc
2016/10/20 22:39:23
const?
ossu
2016/10/21 12:54:41
Done.
| |
92 | 92 EXPECT_EQ(0, buffer.InsertPacket(packet.Clone())); |
93 EXPECT_EQ(0, buffer.InsertPacket(packet)); | |
94 uint32_t next_ts; | 93 uint32_t next_ts; |
95 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); | 94 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); |
96 EXPECT_EQ(4711u, next_ts); | 95 EXPECT_EQ(4711u, next_ts); |
97 EXPECT_FALSE(buffer.Empty()); | 96 EXPECT_FALSE(buffer.Empty()); |
98 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); | 97 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); |
99 const Packet* next_packet = buffer.PeekNextPacket(); | 98 const Packet* next_packet = buffer.PeekNextPacket(); |
100 EXPECT_EQ(packet, next_packet); // Compare pointer addresses. | 99 EXPECT_EQ(packet, *next_packet); // Compare contents. |
101 | 100 |
102 // Do not explicitly flush buffer or delete packet to test that it is deleted | 101 // Do not explicitly flush buffer or delete packet to test that it is deleted |
103 // with the buffer. (Tested with Valgrind or similar tool.) | 102 // with the buffer. (Tested with Valgrind or similar tool.) |
104 } | 103 } |
105 | 104 |
106 // Test to flush buffer. | 105 // Test to flush buffer. |
107 TEST(PacketBuffer, FlushBuffer) { | 106 TEST(PacketBuffer, FlushBuffer) { |
108 TickTimer tick_timer; | 107 TickTimer tick_timer; |
109 PacketBuffer buffer(10, &tick_timer); // 10 packets. | 108 PacketBuffer buffer(10, &tick_timer); // 10 packets. |
110 PacketGenerator gen(0, 0, 0, 10); | 109 PacketGenerator gen(0, 0, 0, 10); |
111 const int payload_len = 10; | 110 const int payload_len = 10; |
112 | 111 |
113 // Insert 10 small packets; should be ok. | 112 // Insert 10 small packets; should be ok. |
114 for (int i = 0; i < 10; ++i) { | 113 for (int i = 0; i < 10; ++i) { |
115 Packet* packet = gen.NextPacket(payload_len); | 114 EXPECT_EQ(PacketBuffer::kOK, |
116 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet)); | 115 buffer.InsertPacket(gen.NextPacket(payload_len))); |
117 } | 116 } |
118 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); | 117 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); |
119 EXPECT_FALSE(buffer.Empty()); | 118 EXPECT_FALSE(buffer.Empty()); |
120 | 119 |
121 buffer.Flush(); | 120 buffer.Flush(); |
122 // Buffer should delete the payloads itself. | 121 // Buffer should delete the payloads itself. |
123 EXPECT_EQ(0u, buffer.NumPacketsInBuffer()); | 122 EXPECT_EQ(0u, buffer.NumPacketsInBuffer()); |
124 EXPECT_TRUE(buffer.Empty()); | 123 EXPECT_TRUE(buffer.Empty()); |
125 } | 124 } |
126 | 125 |
127 // Test to fill the buffer over the limits, and verify that it flushes. | 126 // Test to fill the buffer over the limits, and verify that it flushes. |
128 TEST(PacketBuffer, OverfillBuffer) { | 127 TEST(PacketBuffer, OverfillBuffer) { |
129 TickTimer tick_timer; | 128 TickTimer tick_timer; |
130 PacketBuffer buffer(10, &tick_timer); // 10 packets. | 129 PacketBuffer buffer(10, &tick_timer); // 10 packets. |
131 PacketGenerator gen(0, 0, 0, 10); | 130 PacketGenerator gen(0, 0, 0, 10); |
132 | 131 |
133 // Insert 10 small packets; should be ok. | 132 // Insert 10 small packets; should be ok. |
134 const int payload_len = 10; | 133 const int payload_len = 10; |
135 int i; | 134 int i; |
136 for (i = 0; i < 10; ++i) { | 135 for (i = 0; i < 10; ++i) { |
137 Packet* packet = gen.NextPacket(payload_len); | 136 EXPECT_EQ(PacketBuffer::kOK, |
138 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet)); | 137 buffer.InsertPacket(gen.NextPacket(payload_len))); |
139 } | 138 } |
140 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); | 139 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); |
141 uint32_t next_ts; | 140 uint32_t next_ts; |
142 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); | 141 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); |
143 EXPECT_EQ(0u, next_ts); // Expect first inserted packet to be first in line. | 142 EXPECT_EQ(0u, next_ts); // Expect first inserted packet to be first in line. |
144 | 143 |
144 Packet packet = gen.NextPacket(payload_len); | |
kwiberg-webrtc
2016/10/20 22:39:23
const?
ossu
2016/10/21 12:54:42
Done.
| |
145 // Insert 11th packet; should flush the buffer and insert it after flushing. | 145 // Insert 11th packet; should flush the buffer and insert it after flushing. |
146 Packet* packet = gen.NextPacket(payload_len); | 146 EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacket(packet.Clone())); |
147 EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacket(packet)); | |
148 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); | 147 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); |
149 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); | 148 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&next_ts)); |
150 // Expect last inserted packet to be first in line. | 149 // Expect last inserted packet to be first in line. |
151 EXPECT_EQ(packet->timestamp, next_ts); | 150 EXPECT_EQ(packet.timestamp, next_ts); |
152 | 151 |
153 // Flush buffer to delete all packets. | 152 // Flush buffer to delete all packets. |
154 buffer.Flush(); | 153 buffer.Flush(); |
155 } | 154 } |
156 | 155 |
157 // Test inserting a list of packets. | 156 // Test inserting a list of packets. |
158 TEST(PacketBuffer, InsertPacketList) { | 157 TEST(PacketBuffer, InsertPacketList) { |
159 TickTimer tick_timer; | 158 TickTimer tick_timer; |
160 PacketBuffer buffer(10, &tick_timer); // 10 packets. | 159 PacketBuffer buffer(10, &tick_timer); // 10 packets. |
161 PacketGenerator gen(0, 0, 0, 10); | 160 PacketGenerator gen(0, 0, 0, 10); |
162 PacketList list; | 161 PacketList list; |
163 const int payload_len = 10; | 162 const int payload_len = 10; |
164 | 163 |
165 // Insert 10 small packets. | 164 // Insert 10 small packets. |
166 for (int i = 0; i < 10; ++i) { | 165 for (int i = 0; i < 10; ++i) { |
167 Packet* packet = gen.NextPacket(payload_len); | 166 list.push_back(gen.NextPacket(payload_len)); |
168 list.push_back(packet); | |
169 } | 167 } |
170 | 168 |
171 MockDecoderDatabase decoder_database; | 169 MockDecoderDatabase decoder_database; |
172 auto factory = CreateBuiltinAudioDecoderFactory(); | 170 auto factory = CreateBuiltinAudioDecoderFactory(); |
173 const DecoderDatabase::DecoderInfo info(NetEqDecoder::kDecoderPCMu, factory); | 171 const DecoderDatabase::DecoderInfo info(NetEqDecoder::kDecoderPCMu, factory); |
174 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) | 172 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) |
175 .WillRepeatedly(Return(&info)); | 173 .WillRepeatedly(Return(&info)); |
176 rtc::Optional<uint8_t> current_pt; | 174 rtc::Optional<uint8_t> current_pt; |
177 rtc::Optional<uint8_t> current_cng_pt; | 175 rtc::Optional<uint8_t> current_cng_pt; |
178 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, | 176 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, |
(...skipping 16 matching lines...) Expand all Loading... | |
195 // TODO(hlundin): Remove this test when legacy operation is no longer needed. | 193 // TODO(hlundin): Remove this test when legacy operation is no longer needed. |
196 TEST(PacketBuffer, InsertPacketListChangePayloadType) { | 194 TEST(PacketBuffer, InsertPacketListChangePayloadType) { |
197 TickTimer tick_timer; | 195 TickTimer tick_timer; |
198 PacketBuffer buffer(10, &tick_timer); // 10 packets. | 196 PacketBuffer buffer(10, &tick_timer); // 10 packets. |
199 PacketGenerator gen(0, 0, 0, 10); | 197 PacketGenerator gen(0, 0, 0, 10); |
200 PacketList list; | 198 PacketList list; |
201 const int payload_len = 10; | 199 const int payload_len = 10; |
202 | 200 |
203 // Insert 10 small packets. | 201 // Insert 10 small packets. |
204 for (int i = 0; i < 10; ++i) { | 202 for (int i = 0; i < 10; ++i) { |
205 Packet* packet = gen.NextPacket(payload_len); | 203 list.push_back(gen.NextPacket(payload_len)); |
206 list.push_back(packet); | |
207 } | 204 } |
208 // Insert 11th packet of another payload type (not CNG). | 205 // Insert 11th packet of another payload type (not CNG). |
209 Packet* packet = gen.NextPacket(payload_len); | 206 { |
210 packet->payload_type = 1; | 207 Packet packet = gen.NextPacket(payload_len); |
211 list.push_back(packet); | 208 packet.payload_type = 1; |
212 | 209 list.push_back(std::move(packet)); |
210 } | |
213 | 211 |
214 MockDecoderDatabase decoder_database; | 212 MockDecoderDatabase decoder_database; |
215 auto factory = CreateBuiltinAudioDecoderFactory(); | 213 auto factory = CreateBuiltinAudioDecoderFactory(); |
216 const DecoderDatabase::DecoderInfo info0(NetEqDecoder::kDecoderPCMu, factory); | 214 const DecoderDatabase::DecoderInfo info0(NetEqDecoder::kDecoderPCMu, factory); |
217 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) | 215 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) |
218 .WillRepeatedly(Return(&info0)); | 216 .WillRepeatedly(Return(&info0)); |
219 const DecoderDatabase::DecoderInfo info1(NetEqDecoder::kDecoderPCMa, factory); | 217 const DecoderDatabase::DecoderInfo info1(NetEqDecoder::kDecoderPCMa, factory); |
220 EXPECT_CALL(decoder_database, GetDecoderInfo(1)) | 218 EXPECT_CALL(decoder_database, GetDecoderInfo(1)) |
221 .WillRepeatedly(Return(&info1)); | 219 .WillRepeatedly(Return(&info1)); |
222 rtc::Optional<uint8_t> current_pt; | 220 rtc::Optional<uint8_t> current_pt; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 {0x0004, 0x0000001E, 0, true, 7}, | 257 {0x0004, 0x0000001E, 0, true, 7}, |
260 {0x0004, 0x00000014, 1, false, 6}, | 258 {0x0004, 0x00000014, 1, false, 6}, |
261 {0x0005, 0x0000001E, 0, true, -1}, | 259 {0x0005, 0x0000001E, 0, true, -1}, |
262 {0x0005, 0x00000014, 1, false, -1}, | 260 {0x0005, 0x00000014, 1, false, -1}, |
263 {0x0006, 0x00000028, 0, true, 8}, | 261 {0x0006, 0x00000028, 0, true, 8}, |
264 {0x0006, 0x0000001E, 1, false, -1}, | 262 {0x0006, 0x0000001E, 1, false, -1}, |
265 }; | 263 }; |
266 | 264 |
267 const size_t kExpectPacketsInBuffer = 9; | 265 const size_t kExpectPacketsInBuffer = 9; |
268 | 266 |
269 std::vector<Packet*> expect_order(kExpectPacketsInBuffer); | 267 std::vector<Packet> expect_order(kExpectPacketsInBuffer); |
270 | 268 |
271 PacketGenerator gen(0, 0, 0, kFrameSize); | 269 PacketGenerator gen(0, 0, 0, kFrameSize); |
272 | 270 |
273 for (int i = 0; i < kPackets; ++i) { | 271 for (int i = 0; i < kPackets; ++i) { |
274 gen.Reset(packet_facts[i].sequence_number, | 272 gen.Reset(packet_facts[i].sequence_number, |
275 packet_facts[i].timestamp, | 273 packet_facts[i].timestamp, |
276 packet_facts[i].payload_type, | 274 packet_facts[i].payload_type, |
277 kFrameSize); | 275 kFrameSize); |
278 Packet* packet = gen.NextPacket(kPayloadLength); | 276 Packet packet = gen.NextPacket(kPayloadLength); |
279 packet->priority.red_level = packet_facts[i].primary ? 0 : 1; | 277 packet.priority.red_level = packet_facts[i].primary ? 0 : 1; |
280 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet)); | 278 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacket(packet.Clone())); |
281 if (packet_facts[i].extract_order >= 0) { | 279 if (packet_facts[i].extract_order >= 0) { |
282 expect_order[packet_facts[i].extract_order] = packet; | 280 expect_order[packet_facts[i].extract_order] = std::move(packet); |
283 } | 281 } |
284 } | 282 } |
285 | 283 |
286 EXPECT_EQ(kExpectPacketsInBuffer, buffer.NumPacketsInBuffer()); | 284 EXPECT_EQ(kExpectPacketsInBuffer, buffer.NumPacketsInBuffer()); |
287 | 285 |
288 size_t drop_count; | |
289 for (size_t i = 0; i < kExpectPacketsInBuffer; ++i) { | 286 for (size_t i = 0; i < kExpectPacketsInBuffer; ++i) { |
290 Packet* packet = buffer.GetNextPacket(&drop_count); | 287 rtc::Optional<Packet> packet = buffer.GetNextPacket(); |
kwiberg-webrtc
2016/10/20 22:39:23
const?
ossu
2016/10/21 12:54:42
Done.
| |
291 EXPECT_EQ(0u, drop_count); | 288 EXPECT_TRUE(packet); |
292 EXPECT_EQ(packet, expect_order[i]); // Compare pointer addresses. | 289 if (packet) { |
293 delete packet; | 290 EXPECT_EQ(*packet, expect_order[i]); // Compare contents. |
291 } | |
294 } | 292 } |
295 EXPECT_TRUE(buffer.Empty()); | 293 EXPECT_TRUE(buffer.Empty()); |
296 } | 294 } |
297 | 295 |
298 TEST(PacketBuffer, DiscardPackets) { | 296 TEST(PacketBuffer, DiscardPackets) { |
299 TickTimer tick_timer; | 297 TickTimer tick_timer; |
300 PacketBuffer buffer(100, &tick_timer); // 100 packets. | 298 PacketBuffer buffer(100, &tick_timer); // 100 packets. |
301 const uint16_t start_seq_no = 17; | 299 const uint16_t start_seq_no = 17; |
302 const uint32_t start_ts = 4711; | 300 const uint32_t start_ts = 4711; |
303 const uint32_t ts_increment = 10; | 301 const uint32_t ts_increment = 10; |
304 PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); | 302 PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); |
305 PacketList list; | 303 PacketList list; |
306 const int payload_len = 10; | 304 const int payload_len = 10; |
307 | 305 |
308 // Insert 10 small packets. | 306 // Insert 10 small packets. |
309 for (int i = 0; i < 10; ++i) { | 307 for (int i = 0; i < 10; ++i) { |
310 Packet* packet = gen.NextPacket(payload_len); | 308 buffer.InsertPacket(gen.NextPacket(payload_len)); |
311 buffer.InsertPacket(packet); | |
312 } | 309 } |
313 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); | 310 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); |
314 | 311 |
315 // Discard them one by one and make sure that the right packets are at the | 312 // Discard them one by one and make sure that the right packets are at the |
316 // front of the buffer. | 313 // front of the buffer. |
317 uint32_t current_ts = start_ts; | 314 uint32_t current_ts = start_ts; |
318 for (int i = 0; i < 10; ++i) { | 315 for (int i = 0; i < 10; ++i) { |
319 uint32_t ts; | 316 uint32_t ts; |
320 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&ts)); | 317 EXPECT_EQ(PacketBuffer::kOK, buffer.NextTimestamp(&ts)); |
321 EXPECT_EQ(current_ts, ts); | 318 EXPECT_EQ(current_ts, ts); |
(...skipping 10 matching lines...) Expand all Loading... | |
332 const uint32_t start_ts = 4711; | 329 const uint32_t start_ts = 4711; |
333 const uint32_t ts_increment = 10; | 330 const uint32_t ts_increment = 10; |
334 PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); | 331 PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); |
335 const int payload_len = 10; | 332 const int payload_len = 10; |
336 | 333 |
337 // Generate 10 small packets and insert them into a PacketList. Insert every | 334 // Generate 10 small packets and insert them into a PacketList. Insert every |
338 // odd packet to the front, and every even packet to the back, thus creating | 335 // odd packet to the front, and every even packet to the back, thus creating |
339 // a (rather strange) reordering. | 336 // a (rather strange) reordering. |
340 PacketList list; | 337 PacketList list; |
341 for (int i = 0; i < 10; ++i) { | 338 for (int i = 0; i < 10; ++i) { |
342 Packet* packet = gen.NextPacket(payload_len); | 339 Packet packet = gen.NextPacket(payload_len); |
343 if (i % 2) { | 340 if (i % 2) { |
344 list.push_front(packet); | 341 list.push_front(std::move(packet)); |
345 } else { | 342 } else { |
346 list.push_back(packet); | 343 list.push_back(std::move(packet)); |
347 } | 344 } |
348 } | 345 } |
349 | 346 |
350 MockDecoderDatabase decoder_database; | 347 MockDecoderDatabase decoder_database; |
351 auto factory = CreateBuiltinAudioDecoderFactory(); | 348 auto factory = CreateBuiltinAudioDecoderFactory(); |
352 const DecoderDatabase::DecoderInfo info(NetEqDecoder::kDecoderPCMu, factory); | 349 const DecoderDatabase::DecoderInfo info(NetEqDecoder::kDecoderPCMu, factory); |
353 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) | 350 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) |
354 .WillRepeatedly(Return(&info)); | 351 .WillRepeatedly(Return(&info)); |
355 rtc::Optional<uint8_t> current_pt; | 352 rtc::Optional<uint8_t> current_pt; |
356 rtc::Optional<uint8_t> current_cng_pt; | 353 rtc::Optional<uint8_t> current_cng_pt; |
357 | 354 |
358 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, | 355 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, |
359 decoder_database, | 356 decoder_database, |
360 ¤t_pt, | 357 ¤t_pt, |
361 ¤t_cng_pt)); | 358 ¤t_cng_pt)); |
362 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); | 359 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); |
363 | 360 |
364 // Extract them and make sure that come out in the right order. | 361 // Extract them and make sure that come out in the right order. |
365 uint32_t current_ts = start_ts; | 362 uint32_t current_ts = start_ts; |
366 for (int i = 0; i < 10; ++i) { | 363 for (int i = 0; i < 10; ++i) { |
367 Packet* packet = buffer.GetNextPacket(NULL); | 364 rtc::Optional<Packet> packet = buffer.GetNextPacket(); |
kwiberg-webrtc
2016/10/20 22:39:23
const
ossu
2016/10/21 12:54:42
Done.
| |
368 ASSERT_FALSE(packet == NULL); | 365 ASSERT_TRUE(packet); |
369 EXPECT_EQ(current_ts, packet->timestamp); | 366 EXPECT_EQ(current_ts, packet->timestamp); |
370 current_ts += ts_increment; | 367 current_ts += ts_increment; |
371 delete packet; | |
372 } | 368 } |
373 EXPECT_TRUE(buffer.Empty()); | 369 EXPECT_TRUE(buffer.Empty()); |
374 | 370 |
375 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. | 371 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. |
376 } | 372 } |
377 | 373 |
378 // The test first inserts a packet with narrow-band CNG, then a packet with | 374 // The test first inserts a packet with narrow-band CNG, then a packet with |
379 // wide-band speech. The expected behavior of the packet buffer is to detect a | 375 // wide-band speech. The expected behavior of the packet buffer is to detect a |
380 // change in sample rate, even though no speech packet has been inserted before, | 376 // change in sample rate, even though no speech packet has been inserted before, |
381 // and flush out the CNG packet. | 377 // and flush out the CNG packet. |
(...skipping 26 matching lines...) Expand all Loading... | |
408 ¤t_cng_pt)); | 404 ¤t_cng_pt)); |
409 EXPECT_TRUE(list.empty()); | 405 EXPECT_TRUE(list.empty()); |
410 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); | 406 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); |
411 ASSERT_TRUE(buffer.PeekNextPacket()); | 407 ASSERT_TRUE(buffer.PeekNextPacket()); |
412 EXPECT_EQ(kCngPt, buffer.PeekNextPacket()->payload_type); | 408 EXPECT_EQ(kCngPt, buffer.PeekNextPacket()->payload_type); |
413 EXPECT_FALSE(current_pt); // Current payload type not set. | 409 EXPECT_FALSE(current_pt); // Current payload type not set. |
414 EXPECT_EQ(rtc::Optional<uint8_t>(kCngPt), | 410 EXPECT_EQ(rtc::Optional<uint8_t>(kCngPt), |
415 current_cng_pt); // CNG payload type set. | 411 current_cng_pt); // CNG payload type set. |
416 | 412 |
417 // Insert second packet, which is wide-band speech. | 413 // Insert second packet, which is wide-band speech. |
418 Packet* packet = gen.NextPacket(kPayloadLen); | 414 { |
419 packet->payload_type = kSpeechPt; | 415 Packet packet = gen.NextPacket(kPayloadLen); |
420 list.push_back(packet); | 416 packet.payload_type = kSpeechPt; |
417 list.push_back(std::move(packet)); | |
418 } | |
421 // Expect the buffer to flush out the CNG packet, since it does not match the | 419 // Expect the buffer to flush out the CNG packet, since it does not match the |
422 // new speech sample rate. | 420 // new speech sample rate. |
423 EXPECT_EQ(PacketBuffer::kFlushed, | 421 EXPECT_EQ(PacketBuffer::kFlushed, |
424 buffer.InsertPacketList(&list, decoder_database, ¤t_pt, | 422 buffer.InsertPacketList(&list, decoder_database, ¤t_pt, |
425 ¤t_cng_pt)); | 423 ¤t_cng_pt)); |
426 EXPECT_TRUE(list.empty()); | 424 EXPECT_TRUE(list.empty()); |
427 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); | 425 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); |
428 ASSERT_TRUE(buffer.PeekNextPacket()); | 426 ASSERT_TRUE(buffer.PeekNextPacket()); |
429 EXPECT_EQ(kSpeechPt, buffer.PeekNextPacket()->payload_type); | 427 EXPECT_EQ(kSpeechPt, buffer.PeekNextPacket()->payload_type); |
430 | 428 |
431 EXPECT_EQ(rtc::Optional<uint8_t>(kSpeechPt), | 429 EXPECT_EQ(rtc::Optional<uint8_t>(kSpeechPt), |
432 current_pt); // Current payload type set. | 430 current_pt); // Current payload type set. |
433 EXPECT_FALSE(current_cng_pt); // CNG payload type reset. | 431 EXPECT_FALSE(current_cng_pt); // CNG payload type reset. |
434 | 432 |
435 buffer.Flush(); // Clean up. | 433 buffer.Flush(); // Clean up. |
436 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. | 434 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. |
437 } | 435 } |
438 | 436 |
439 TEST(PacketBuffer, Failures) { | 437 TEST(PacketBuffer, Failures) { |
440 const uint16_t start_seq_no = 17; | 438 const uint16_t start_seq_no = 17; |
441 const uint32_t start_ts = 4711; | 439 const uint32_t start_ts = 4711; |
442 const uint32_t ts_increment = 10; | 440 const uint32_t ts_increment = 10; |
443 int payload_len = 100; | 441 int payload_len = 100; |
444 PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); | 442 PacketGenerator gen(start_seq_no, start_ts, 0, ts_increment); |
445 TickTimer tick_timer; | 443 TickTimer tick_timer; |
446 | 444 |
447 PacketBuffer* buffer = new PacketBuffer(100, &tick_timer); // 100 packets. | 445 PacketBuffer* buffer = new PacketBuffer(100, &tick_timer); // 100 packets. |
448 Packet* packet = NULL; | 446 { |
449 EXPECT_EQ(PacketBuffer::kInvalidPacket, buffer->InsertPacket(packet)); | 447 Packet packet = gen.NextPacket(payload_len); |
450 packet = gen.NextPacket(payload_len); | 448 packet.payload.Clear(); |
451 packet->payload.Clear(); | 449 EXPECT_EQ(PacketBuffer::kInvalidPacket, |
452 EXPECT_EQ(PacketBuffer::kInvalidPacket, buffer->InsertPacket(packet)); | 450 buffer->InsertPacket(std::move(packet))); |
453 // Packet is deleted by the PacketBuffer. | 451 } |
454 | |
455 // Buffer should still be empty. Test all empty-checks. | 452 // Buffer should still be empty. Test all empty-checks. |
456 uint32_t temp_ts; | 453 uint32_t temp_ts; |
457 EXPECT_EQ(PacketBuffer::kBufferEmpty, buffer->NextTimestamp(&temp_ts)); | 454 EXPECT_EQ(PacketBuffer::kBufferEmpty, buffer->NextTimestamp(&temp_ts)); |
458 EXPECT_EQ(PacketBuffer::kBufferEmpty, | 455 EXPECT_EQ(PacketBuffer::kBufferEmpty, |
459 buffer->NextHigherTimestamp(0, &temp_ts)); | 456 buffer->NextHigherTimestamp(0, &temp_ts)); |
460 EXPECT_EQ(NULL, buffer->PeekNextPacket()); | 457 EXPECT_EQ(NULL, buffer->PeekNextPacket()); |
461 EXPECT_EQ(NULL, buffer->GetNextPacket(NULL)); | 458 EXPECT_FALSE(buffer->GetNextPacket()); |
462 EXPECT_EQ(PacketBuffer::kBufferEmpty, buffer->DiscardNextPacket()); | 459 EXPECT_EQ(PacketBuffer::kBufferEmpty, buffer->DiscardNextPacket()); |
463 EXPECT_EQ(0, buffer->DiscardAllOldPackets(0)); // 0 packets discarded. | 460 EXPECT_EQ(0, buffer->DiscardAllOldPackets(0)); // 0 packets discarded. |
464 | 461 |
465 // Insert one packet to make the buffer non-empty. | 462 // Insert one packet to make the buffer non-empty. |
466 packet = gen.NextPacket(payload_len); | 463 EXPECT_EQ(PacketBuffer::kOK, |
467 EXPECT_EQ(PacketBuffer::kOK, buffer->InsertPacket(packet)); | 464 buffer->InsertPacket(gen.NextPacket(payload_len))); |
468 EXPECT_EQ(PacketBuffer::kInvalidPointer, buffer->NextTimestamp(NULL)); | 465 EXPECT_EQ(PacketBuffer::kInvalidPointer, buffer->NextTimestamp(NULL)); |
469 EXPECT_EQ(PacketBuffer::kInvalidPointer, | 466 EXPECT_EQ(PacketBuffer::kInvalidPointer, |
470 buffer->NextHigherTimestamp(0, NULL)); | 467 buffer->NextHigherTimestamp(0, NULL)); |
471 delete buffer; | 468 delete buffer; |
472 | 469 |
473 // Insert packet list of three packets, where the second packet has an invalid | 470 // Insert packet list of three packets, where the second packet has an invalid |
474 // payload. Expect first packet to be inserted, and the remaining two to be | 471 // payload. Expect first packet to be inserted, and the remaining two to be |
475 // discarded. | 472 // discarded. |
476 buffer = new PacketBuffer(100, &tick_timer); // 100 packets. | 473 buffer = new PacketBuffer(100, &tick_timer); // 100 packets. |
477 PacketList list; | 474 PacketList list; |
478 list.push_back(gen.NextPacket(payload_len)); // Valid packet. | 475 list.push_back(gen.NextPacket(payload_len)); // Valid packet. |
479 packet = gen.NextPacket(payload_len); | 476 { |
480 packet->payload.Clear(); // Invalid. | 477 Packet packet = gen.NextPacket(payload_len); |
481 list.push_back(packet); | 478 packet.payload.Clear(); // Invalid. |
479 list.push_back(std::move(packet)); | |
480 } | |
482 list.push_back(gen.NextPacket(payload_len)); // Valid packet. | 481 list.push_back(gen.NextPacket(payload_len)); // Valid packet. |
483 MockDecoderDatabase decoder_database; | 482 MockDecoderDatabase decoder_database; |
484 auto factory = CreateBuiltinAudioDecoderFactory(); | 483 auto factory = CreateBuiltinAudioDecoderFactory(); |
485 const DecoderDatabase::DecoderInfo info(NetEqDecoder::kDecoderPCMu, factory); | 484 const DecoderDatabase::DecoderInfo info(NetEqDecoder::kDecoderPCMu, factory); |
486 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) | 485 EXPECT_CALL(decoder_database, GetDecoderInfo(0)) |
487 .WillRepeatedly(Return(&info)); | 486 .WillRepeatedly(Return(&info)); |
488 rtc::Optional<uint8_t> current_pt; | 487 rtc::Optional<uint8_t> current_pt; |
489 rtc::Optional<uint8_t> current_cng_pt; | 488 rtc::Optional<uint8_t> current_cng_pt; |
490 EXPECT_EQ(PacketBuffer::kInvalidPacket, | 489 EXPECT_EQ(PacketBuffer::kInvalidPacket, |
491 buffer->InsertPacketList(&list, | 490 buffer->InsertPacketList(&list, |
492 decoder_database, | 491 decoder_database, |
493 ¤t_pt, | 492 ¤t_pt, |
494 ¤t_cng_pt)); | 493 ¤t_cng_pt)); |
495 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. | 494 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. |
496 EXPECT_EQ(1u, buffer->NumPacketsInBuffer()); | 495 EXPECT_EQ(1u, buffer->NumPacketsInBuffer()); |
497 delete buffer; | 496 delete buffer; |
498 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. | 497 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. |
499 } | 498 } |
500 | 499 |
501 // Test packet comparison function. | 500 // Test packet comparison function. |
502 // The function should return true if the first packet "goes before" the second. | 501 // The function should return true if the first packet "goes before" the second. |
503 TEST(PacketBuffer, ComparePackets) { | 502 TEST(PacketBuffer, ComparePackets) { |
504 PacketGenerator gen(0, 0, 0, 10); | 503 PacketGenerator gen(0, 0, 0, 10); |
505 std::unique_ptr<Packet> a(gen.NextPacket(10)); // SN = 0, TS = 0. | 504 Packet a(gen.NextPacket(10)); // SN = 0, TS = 0. |
506 std::unique_ptr<Packet> b(gen.NextPacket(10)); // SN = 1, TS = 10. | 505 Packet b(gen.NextPacket(10)); // SN = 1, TS = 10. |
507 EXPECT_FALSE(*a == *b); | 506 EXPECT_FALSE(a == b); |
508 EXPECT_TRUE(*a != *b); | 507 EXPECT_TRUE(a != b); |
509 EXPECT_TRUE(*a < *b); | 508 EXPECT_TRUE(a < b); |
510 EXPECT_FALSE(*a > *b); | 509 EXPECT_FALSE(a > b); |
511 EXPECT_TRUE(*a <= *b); | 510 EXPECT_TRUE(a <= b); |
512 EXPECT_FALSE(*a >= *b); | 511 EXPECT_FALSE(a >= b); |
513 | 512 |
514 // Testing wrap-around case; 'a' is earlier but has a larger timestamp value. | 513 // Testing wrap-around case; 'a' is earlier but has a larger timestamp value. |
515 a->timestamp = 0xFFFFFFFF - 10; | 514 a.timestamp = 0xFFFFFFFF - 10; |
516 EXPECT_FALSE(*a == *b); | 515 EXPECT_FALSE(a == b); |
517 EXPECT_TRUE(*a != *b); | 516 EXPECT_TRUE(a != b); |
518 EXPECT_TRUE(*a < *b); | 517 EXPECT_TRUE(a < b); |
519 EXPECT_FALSE(*a > *b); | 518 EXPECT_FALSE(a > b); |
520 EXPECT_TRUE(*a <= *b); | 519 EXPECT_TRUE(a <= b); |
521 EXPECT_FALSE(*a >= *b); | 520 EXPECT_FALSE(a >= b); |
522 | 521 |
523 // Test equal packets. | 522 // Test equal packets. |
524 EXPECT_TRUE(*a == *a); | 523 EXPECT_TRUE(a == a); |
525 EXPECT_FALSE(*a != *a); | 524 EXPECT_FALSE(a != a); |
526 EXPECT_FALSE(*a < *a); | 525 EXPECT_FALSE(a < a); |
527 EXPECT_FALSE(*a > *a); | 526 EXPECT_FALSE(a > a); |
528 EXPECT_TRUE(*a <= *a); | 527 EXPECT_TRUE(a <= a); |
529 EXPECT_TRUE(*a >= *a); | 528 EXPECT_TRUE(a >= a); |
530 | 529 |
531 // Test equal timestamps but different sequence numbers (0 and 1). | 530 // Test equal timestamps but different sequence numbers (0 and 1). |
532 a->timestamp = b->timestamp; | 531 a.timestamp = b.timestamp; |
533 EXPECT_FALSE(*a == *b); | 532 EXPECT_FALSE(a == b); |
534 EXPECT_TRUE(*a != *b); | 533 EXPECT_TRUE(a != b); |
535 EXPECT_TRUE(*a < *b); | 534 EXPECT_TRUE(a < b); |
536 EXPECT_FALSE(*a > *b); | 535 EXPECT_FALSE(a > b); |
537 EXPECT_TRUE(*a <= *b); | 536 EXPECT_TRUE(a <= b); |
538 EXPECT_FALSE(*a >= *b); | 537 EXPECT_FALSE(a >= b); |
539 | 538 |
540 // Test equal timestamps but different sequence numbers (32767 and 1). | 539 // Test equal timestamps but different sequence numbers (32767 and 1). |
541 a->sequence_number = 0xFFFF; | 540 a.sequence_number = 0xFFFF; |
542 EXPECT_FALSE(*a == *b); | 541 EXPECT_FALSE(a == b); |
543 EXPECT_TRUE(*a != *b); | 542 EXPECT_TRUE(a != b); |
544 EXPECT_TRUE(*a < *b); | 543 EXPECT_TRUE(a < b); |
545 EXPECT_FALSE(*a > *b); | 544 EXPECT_FALSE(a > b); |
546 EXPECT_TRUE(*a <= *b); | 545 EXPECT_TRUE(a <= b); |
547 EXPECT_FALSE(*a >= *b); | 546 EXPECT_FALSE(a >= b); |
548 | 547 |
549 // Test equal timestamps and sequence numbers, but differing priorities. | 548 // Test equal timestamps and sequence numbers, but differing priorities. |
550 a->sequence_number = b->sequence_number; | 549 a.sequence_number = b.sequence_number; |
551 a->priority = {1, 0}; | 550 a.priority = {1, 0}; |
552 b->priority = {0, 0}; | 551 b.priority = {0, 0}; |
553 // a after b | 552 // a after b |
554 EXPECT_FALSE(*a == *b); | 553 EXPECT_FALSE(a == b); |
555 EXPECT_TRUE(*a != *b); | 554 EXPECT_TRUE(a != b); |
556 EXPECT_FALSE(*a < *b); | 555 EXPECT_FALSE(a < b); |
557 EXPECT_TRUE(*a > *b); | 556 EXPECT_TRUE(a > b); |
558 EXPECT_FALSE(*a <= *b); | 557 EXPECT_FALSE(a <= b); |
559 EXPECT_TRUE(*a >= *b); | 558 EXPECT_TRUE(a >= b); |
560 | 559 |
561 std::unique_ptr<Packet> c(gen.NextPacket(0)); // SN = 2, TS = 20. | 560 Packet c(gen.NextPacket(0)); // SN = 2, TS = 20. |
562 std::unique_ptr<Packet> d(gen.NextPacket(0)); // SN = 3, TS = 20. | 561 Packet d(gen.NextPacket(0)); // SN = 3, TS = 20. |
563 c->timestamp = b->timestamp; | 562 c.timestamp = b.timestamp; |
564 d->timestamp = b->timestamp; | 563 d.timestamp = b.timestamp; |
565 c->sequence_number = b->sequence_number; | 564 c.sequence_number = b.sequence_number; |
566 d->sequence_number = b->sequence_number; | 565 d.sequence_number = b.sequence_number; |
567 c->priority = {1, 1}; | 566 c.priority = {1, 1}; |
568 d->priority = {0, 1}; | 567 d.priority = {0, 1}; |
569 // c after d | 568 // c after d |
570 EXPECT_FALSE(*c == *d); | 569 EXPECT_FALSE(c == d); |
571 EXPECT_TRUE(*c != *d); | 570 EXPECT_TRUE(c != d); |
572 EXPECT_FALSE(*c < *d); | 571 EXPECT_FALSE(c < d); |
573 EXPECT_TRUE(*c > *d); | 572 EXPECT_TRUE(c > d); |
574 EXPECT_FALSE(*c <= *d); | 573 EXPECT_FALSE(c <= d); |
575 EXPECT_TRUE(*c >= *d); | 574 EXPECT_TRUE(c >= d); |
576 | 575 |
577 // c after a | 576 // c after a |
578 EXPECT_FALSE(*c == *a); | 577 EXPECT_FALSE(c == a); |
579 EXPECT_TRUE(*c != *a); | 578 EXPECT_TRUE(c != a); |
580 EXPECT_FALSE(*c < *a); | 579 EXPECT_FALSE(c < a); |
581 EXPECT_TRUE(*c > *a); | 580 EXPECT_TRUE(c > a); |
582 EXPECT_FALSE(*c <= *a); | 581 EXPECT_FALSE(c <= a); |
583 EXPECT_TRUE(*c >= *a); | 582 EXPECT_TRUE(c >= a); |
584 | 583 |
585 // c after b | 584 // c after b |
586 EXPECT_FALSE(*c == *b); | 585 EXPECT_FALSE(c == b); |
587 EXPECT_TRUE(*c != *b); | 586 EXPECT_TRUE(c != b); |
588 EXPECT_FALSE(*c < *b); | 587 EXPECT_FALSE(c < b); |
589 EXPECT_TRUE(*c > *b); | 588 EXPECT_TRUE(c > b); |
590 EXPECT_FALSE(*c <= *b); | 589 EXPECT_FALSE(c <= b); |
591 EXPECT_TRUE(*c >= *b); | 590 EXPECT_TRUE(c >= b); |
592 | 591 |
593 // a after d | 592 // a after d |
594 EXPECT_FALSE(*a == *d); | 593 EXPECT_FALSE(a == d); |
595 EXPECT_TRUE(*a != *d); | 594 EXPECT_TRUE(a != d); |
596 EXPECT_FALSE(*a < *d); | 595 EXPECT_FALSE(a < d); |
597 EXPECT_TRUE(*a > *d); | 596 EXPECT_TRUE(a > d); |
598 EXPECT_FALSE(*a <= *d); | 597 EXPECT_FALSE(a <= d); |
599 EXPECT_TRUE(*a >= *d); | 598 EXPECT_TRUE(a >= d); |
600 | 599 |
601 // d after b | 600 // d after b |
602 EXPECT_FALSE(*d == *b); | 601 EXPECT_FALSE(d == b); |
603 EXPECT_TRUE(*d != *b); | 602 EXPECT_TRUE(d != b); |
604 EXPECT_FALSE(*d < *b); | 603 EXPECT_FALSE(d < b); |
605 EXPECT_TRUE(*d > *b); | 604 EXPECT_TRUE(d > b); |
606 EXPECT_FALSE(*d <= *b); | 605 EXPECT_FALSE(d <= b); |
607 EXPECT_TRUE(*d >= *b); | 606 EXPECT_TRUE(d >= b); |
608 } | |
609 | |
610 // Test the DeleteFirstPacket DeleteAllPackets methods. | |
611 TEST(PacketBuffer, DeleteAllPackets) { | |
612 PacketGenerator gen(0, 0, 0, 10); | |
613 PacketList list; | |
614 const int payload_len = 10; | |
615 | |
616 // Insert 10 small packets. | |
617 for (int i = 0; i < 10; ++i) { | |
618 Packet* packet = gen.NextPacket(payload_len); | |
619 list.push_back(packet); | |
620 } | |
621 EXPECT_TRUE(PacketBuffer::DeleteFirstPacket(&list)); | |
622 EXPECT_EQ(9u, list.size()); | |
623 PacketBuffer::DeleteAllPackets(&list); | |
624 EXPECT_TRUE(list.empty()); | |
625 EXPECT_FALSE(PacketBuffer::DeleteFirstPacket(&list)); | |
626 } | 607 } |
627 | 608 |
628 namespace { | 609 namespace { |
629 void TestIsObsoleteTimestamp(uint32_t limit_timestamp) { | 610 void TestIsObsoleteTimestamp(uint32_t limit_timestamp) { |
630 // Check with zero horizon, which implies that the horizon is at 2^31, i.e., | 611 // Check with zero horizon, which implies that the horizon is at 2^31, i.e., |
631 // half the timestamp range. | 612 // half the timestamp range. |
632 static const uint32_t kZeroHorizon = 0; | 613 static const uint32_t kZeroHorizon = 0; |
633 static const uint32_t k2Pow31Minus1 = 0x7FFFFFFF; | 614 static const uint32_t k2Pow31Minus1 = 0x7FFFFFFF; |
634 // Timestamp on the limit is not old. | 615 // Timestamp on the limit is not old. |
635 EXPECT_FALSE(PacketBuffer::IsObsoleteTimestamp( | 616 EXPECT_FALSE(PacketBuffer::IsObsoleteTimestamp( |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
681 // Test the IsObsoleteTimestamp method with different limit timestamps. | 662 // Test the IsObsoleteTimestamp method with different limit timestamps. |
682 TEST(PacketBuffer, IsObsoleteTimestamp) { | 663 TEST(PacketBuffer, IsObsoleteTimestamp) { |
683 TestIsObsoleteTimestamp(0); | 664 TestIsObsoleteTimestamp(0); |
684 TestIsObsoleteTimestamp(1); | 665 TestIsObsoleteTimestamp(1); |
685 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. | 666 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. |
686 TestIsObsoleteTimestamp(0x80000000); // 2^31. | 667 TestIsObsoleteTimestamp(0x80000000); // 2^31. |
687 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. | 668 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. |
688 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. | 669 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. |
689 } | 670 } |
690 } // namespace webrtc | 671 } // namespace webrtc |
OLD | NEW |