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

Side by Side Diff: webrtc/modules/audio_coding/neteq/packet_buffer_unittest.cc

Issue 2290153002: NetEq: Change member variables for current RTP types to rtc::Optionals (Closed)
Patch Set: Updates after review Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/audio_coding/neteq/packet_buffer.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 PacketList list; 167 PacketList list;
168 const int payload_len = 10; 168 const int payload_len = 10;
169 169
170 // Insert 10 small packets. 170 // Insert 10 small packets.
171 for (int i = 0; i < 10; ++i) { 171 for (int i = 0; i < 10; ++i) {
172 Packet* packet = gen.NextPacket(payload_len); 172 Packet* packet = gen.NextPacket(payload_len);
173 list.push_back(packet); 173 list.push_back(packet);
174 } 174 }
175 175
176 MockDecoderDatabase decoder_database; 176 MockDecoderDatabase decoder_database;
177 uint8_t current_pt = 0xFF; 177 rtc::Optional<uint8_t> current_pt;
178 uint8_t current_cng_pt = 0xFF; 178 rtc::Optional<uint8_t> current_cng_pt;
179 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, 179 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list,
180 decoder_database, 180 decoder_database,
181 &current_pt, 181 &current_pt,
182 &current_cng_pt)); 182 &current_cng_pt));
183 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. 183 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list.
184 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); 184 EXPECT_EQ(10u, buffer.NumPacketsInBuffer());
185 EXPECT_EQ(0, current_pt); // Current payload type changed to 0. 185 EXPECT_EQ(rtc::Optional<uint8_t>(0),
186 EXPECT_EQ(0xFF, current_cng_pt); // CNG payload type not changed. 186 current_pt); // Current payload type changed to 0.
187 EXPECT_FALSE(current_cng_pt); // CNG payload type not changed.
187 188
188 buffer.Flush(); // Clean up. 189 buffer.Flush(); // Clean up.
189 190
190 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. 191 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted.
191 } 192 }
192 193
193 // Test inserting a list of packets. Last packet is of a different payload type. 194 // Test inserting a list of packets. Last packet is of a different payload type.
194 // Expecting the buffer to flush. 195 // Expecting the buffer to flush.
195 // TODO(hlundin): Remove this test when legacy operation is no longer needed. 196 // TODO(hlundin): Remove this test when legacy operation is no longer needed.
196 TEST(PacketBuffer, InsertPacketListChangePayloadType) { 197 TEST(PacketBuffer, InsertPacketListChangePayloadType) {
197 TickTimer tick_timer; 198 TickTimer tick_timer;
198 PacketBuffer buffer(10, &tick_timer); // 10 packets. 199 PacketBuffer buffer(10, &tick_timer); // 10 packets.
199 PacketGenerator gen(0, 0, 0, 10); 200 PacketGenerator gen(0, 0, 0, 10);
200 PacketList list; 201 PacketList list;
201 const int payload_len = 10; 202 const int payload_len = 10;
202 203
203 // Insert 10 small packets. 204 // Insert 10 small packets.
204 for (int i = 0; i < 10; ++i) { 205 for (int i = 0; i < 10; ++i) {
205 Packet* packet = gen.NextPacket(payload_len); 206 Packet* packet = gen.NextPacket(payload_len);
206 list.push_back(packet); 207 list.push_back(packet);
207 } 208 }
208 // Insert 11th packet of another payload type (not CNG). 209 // Insert 11th packet of another payload type (not CNG).
209 Packet* packet = gen.NextPacket(payload_len); 210 Packet* packet = gen.NextPacket(payload_len);
210 packet->header.payloadType = 1; 211 packet->header.payloadType = 1;
211 list.push_back(packet); 212 list.push_back(packet);
212 213
213 214
214 MockDecoderDatabase decoder_database; 215 MockDecoderDatabase decoder_database;
215 uint8_t current_pt = 0xFF; 216 rtc::Optional<uint8_t> current_pt;
216 uint8_t current_cng_pt = 0xFF; 217 rtc::Optional<uint8_t> current_cng_pt;
217 EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacketList(&list, 218 EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacketList(&list,
218 decoder_database, 219 decoder_database,
219 &current_pt, 220 &current_pt,
220 &current_cng_pt)); 221 &current_cng_pt));
221 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. 222 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list.
222 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); // Only the last packet. 223 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); // Only the last packet.
223 EXPECT_EQ(1, current_pt); // Current payload type changed to 0. 224 EXPECT_EQ(rtc::Optional<uint8_t>(1),
224 EXPECT_EQ(0xFF, current_cng_pt); // CNG payload type not changed. 225 current_pt); // Current payload type changed to 1.
226 EXPECT_FALSE(current_cng_pt); // CNG payload type not changed.
225 227
226 buffer.Flush(); // Clean up. 228 buffer.Flush(); // Clean up.
227 229
228 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. 230 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted.
229 } 231 }
230 232
231 TEST(PacketBuffer, ExtractOrderRedundancy) { 233 TEST(PacketBuffer, ExtractOrderRedundancy) {
232 TickTimer tick_timer; 234 TickTimer tick_timer;
233 PacketBuffer buffer(100, &tick_timer); // 100 packets. 235 PacketBuffer buffer(100, &tick_timer); // 100 packets.
234 const int kPackets = 18; 236 const int kPackets = 18;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 for (int i = 0; i < 10; ++i) { 336 for (int i = 0; i < 10; ++i) {
335 Packet* packet = gen.NextPacket(payload_len); 337 Packet* packet = gen.NextPacket(payload_len);
336 if (i % 2) { 338 if (i % 2) {
337 list.push_front(packet); 339 list.push_front(packet);
338 } else { 340 } else {
339 list.push_back(packet); 341 list.push_back(packet);
340 } 342 }
341 } 343 }
342 344
343 MockDecoderDatabase decoder_database; 345 MockDecoderDatabase decoder_database;
344 uint8_t current_pt = 0xFF; 346 rtc::Optional<uint8_t> current_pt;
345 uint8_t current_cng_pt = 0xFF; 347 rtc::Optional<uint8_t> current_cng_pt;
346 348
347 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, 349 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list,
348 decoder_database, 350 decoder_database,
349 &current_pt, 351 &current_pt,
350 &current_cng_pt)); 352 &current_cng_pt));
351 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); 353 EXPECT_EQ(10u, buffer.NumPacketsInBuffer());
352 354
353 // Extract them and make sure that come out in the right order. 355 // Extract them and make sure that come out in the right order.
354 uint32_t current_ts = start_ts; 356 uint32_t current_ts = start_ts;
355 for (int i = 0; i < 10; ++i) { 357 for (int i = 0; i < 10; ++i) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 // discarded. 407 // discarded.
406 buffer = new PacketBuffer(100, &tick_timer); // 100 packets. 408 buffer = new PacketBuffer(100, &tick_timer); // 100 packets.
407 PacketList list; 409 PacketList list;
408 list.push_back(gen.NextPacket(payload_len)); // Valid packet. 410 list.push_back(gen.NextPacket(payload_len)); // Valid packet.
409 packet = gen.NextPacket(payload_len); 411 packet = gen.NextPacket(payload_len);
410 delete [] packet->payload; 412 delete [] packet->payload;
411 packet->payload = NULL; // Invalid. 413 packet->payload = NULL; // Invalid.
412 list.push_back(packet); 414 list.push_back(packet);
413 list.push_back(gen.NextPacket(payload_len)); // Valid packet. 415 list.push_back(gen.NextPacket(payload_len)); // Valid packet.
414 MockDecoderDatabase decoder_database; 416 MockDecoderDatabase decoder_database;
415 uint8_t current_pt = 0xFF; 417 rtc::Optional<uint8_t> current_pt;
416 uint8_t current_cng_pt = 0xFF; 418 rtc::Optional<uint8_t> current_cng_pt;
417 EXPECT_EQ(PacketBuffer::kInvalidPacket, 419 EXPECT_EQ(PacketBuffer::kInvalidPacket,
418 buffer->InsertPacketList(&list, 420 buffer->InsertPacketList(&list,
419 decoder_database, 421 decoder_database,
420 &current_pt, 422 &current_pt,
421 &current_cng_pt)); 423 &current_cng_pt));
422 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. 424 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list.
423 EXPECT_EQ(1u, buffer->NumPacketsInBuffer()); 425 EXPECT_EQ(1u, buffer->NumPacketsInBuffer());
424 delete buffer; 426 delete buffer;
425 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. 427 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted.
426 } 428 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 // Test the IsObsoleteTimestamp method with different limit timestamps. 566 // Test the IsObsoleteTimestamp method with different limit timestamps.
565 TEST(PacketBuffer, IsObsoleteTimestamp) { 567 TEST(PacketBuffer, IsObsoleteTimestamp) {
566 TestIsObsoleteTimestamp(0); 568 TestIsObsoleteTimestamp(0);
567 TestIsObsoleteTimestamp(1); 569 TestIsObsoleteTimestamp(1);
568 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. 570 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t.
569 TestIsObsoleteTimestamp(0x80000000); // 2^31. 571 TestIsObsoleteTimestamp(0x80000000); // 2^31.
570 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. 572 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1.
571 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. 573 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1.
572 } 574 }
573 } // namespace webrtc 575 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/neteq/packet_buffer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698