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

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: 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
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(0, current_pt.value_or(-1)); // Current payload type changed to 0.
kwiberg-webrtc 2016/08/30 10:29:32 Or EXPECT_EQ(rtc::Optional<uint8_t>(0), current
hlundin-webrtc 2016/08/30 10:53:16 Done.
186 EXPECT_EQ(0xFF, current_cng_pt); // CNG payload type not changed. 186 EXPECT_FALSE(current_cng_pt); // CNG payload type not changed.
187 187
188 buffer.Flush(); // Clean up. 188 buffer.Flush(); // Clean up.
189 189
190 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. 190 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted.
191 } 191 }
192 192
193 // Test inserting a list of packets. Last packet is of a different payload type. 193 // Test inserting a list of packets. Last packet is of a different payload type.
194 // Expecting the buffer to flush. 194 // Expecting the buffer to flush.
195 // TODO(hlundin): Remove this test when legacy operation is no longer needed. 195 // TODO(hlundin): Remove this test when legacy operation is no longer needed.
196 TEST(PacketBuffer, InsertPacketListChangePayloadType) { 196 TEST(PacketBuffer, InsertPacketListChangePayloadType) {
197 TickTimer tick_timer; 197 TickTimer tick_timer;
198 PacketBuffer buffer(10, &tick_timer); // 10 packets. 198 PacketBuffer buffer(10, &tick_timer); // 10 packets.
199 PacketGenerator gen(0, 0, 0, 10); 199 PacketGenerator gen(0, 0, 0, 10);
200 PacketList list; 200 PacketList list;
201 const int payload_len = 10; 201 const int payload_len = 10;
202 202
203 // Insert 10 small packets. 203 // Insert 10 small packets.
204 for (int i = 0; i < 10; ++i) { 204 for (int i = 0; i < 10; ++i) {
205 Packet* packet = gen.NextPacket(payload_len); 205 Packet* packet = gen.NextPacket(payload_len);
206 list.push_back(packet); 206 list.push_back(packet);
207 } 207 }
208 // Insert 11th packet of another payload type (not CNG). 208 // Insert 11th packet of another payload type (not CNG).
209 Packet* packet = gen.NextPacket(payload_len); 209 Packet* packet = gen.NextPacket(payload_len);
210 packet->header.payloadType = 1; 210 packet->header.payloadType = 1;
211 list.push_back(packet); 211 list.push_back(packet);
212 212
213 213
214 MockDecoderDatabase decoder_database; 214 MockDecoderDatabase decoder_database;
215 uint8_t current_pt = 0xFF; 215 rtc::Optional<uint8_t> current_pt;
216 uint8_t current_cng_pt = 0xFF; 216 rtc::Optional<uint8_t> current_cng_pt;
217 EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacketList(&list, 217 EXPECT_EQ(PacketBuffer::kFlushed, buffer.InsertPacketList(&list,
218 decoder_database, 218 decoder_database,
219 &current_pt, 219 &current_pt,
220 &current_cng_pt)); 220 &current_cng_pt));
221 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. 221 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list.
222 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); // Only the last packet. 222 EXPECT_EQ(1u, buffer.NumPacketsInBuffer()); // Only the last packet.
223 EXPECT_EQ(1, current_pt); // Current payload type changed to 0. 223 EXPECT_EQ(1, current_pt.value_or(-1)); // Current payload type changed to 0.
224 EXPECT_EQ(0xFF, current_cng_pt); // CNG payload type not changed. 224 EXPECT_FALSE(current_cng_pt); // CNG payload type not changed.
225 225
226 buffer.Flush(); // Clean up. 226 buffer.Flush(); // Clean up.
227 227
228 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. 228 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted.
229 } 229 }
230 230
231 TEST(PacketBuffer, ExtractOrderRedundancy) { 231 TEST(PacketBuffer, ExtractOrderRedundancy) {
232 TickTimer tick_timer; 232 TickTimer tick_timer;
233 PacketBuffer buffer(100, &tick_timer); // 100 packets. 233 PacketBuffer buffer(100, &tick_timer); // 100 packets.
234 const int kPackets = 18; 234 const int kPackets = 18;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 for (int i = 0; i < 10; ++i) { 334 for (int i = 0; i < 10; ++i) {
335 Packet* packet = gen.NextPacket(payload_len); 335 Packet* packet = gen.NextPacket(payload_len);
336 if (i % 2) { 336 if (i % 2) {
337 list.push_front(packet); 337 list.push_front(packet);
338 } else { 338 } else {
339 list.push_back(packet); 339 list.push_back(packet);
340 } 340 }
341 } 341 }
342 342
343 MockDecoderDatabase decoder_database; 343 MockDecoderDatabase decoder_database;
344 uint8_t current_pt = 0xFF; 344 rtc::Optional<uint8_t> current_pt;
345 uint8_t current_cng_pt = 0xFF; 345 rtc::Optional<uint8_t> current_cng_pt;
346 346
347 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list, 347 EXPECT_EQ(PacketBuffer::kOK, buffer.InsertPacketList(&list,
348 decoder_database, 348 decoder_database,
349 &current_pt, 349 &current_pt,
350 &current_cng_pt)); 350 &current_cng_pt));
351 EXPECT_EQ(10u, buffer.NumPacketsInBuffer()); 351 EXPECT_EQ(10u, buffer.NumPacketsInBuffer());
352 352
353 // Extract them and make sure that come out in the right order. 353 // Extract them and make sure that come out in the right order.
354 uint32_t current_ts = start_ts; 354 uint32_t current_ts = start_ts;
355 for (int i = 0; i < 10; ++i) { 355 for (int i = 0; i < 10; ++i) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 // discarded. 405 // discarded.
406 buffer = new PacketBuffer(100, &tick_timer); // 100 packets. 406 buffer = new PacketBuffer(100, &tick_timer); // 100 packets.
407 PacketList list; 407 PacketList list;
408 list.push_back(gen.NextPacket(payload_len)); // Valid packet. 408 list.push_back(gen.NextPacket(payload_len)); // Valid packet.
409 packet = gen.NextPacket(payload_len); 409 packet = gen.NextPacket(payload_len);
410 delete [] packet->payload; 410 delete [] packet->payload;
411 packet->payload = NULL; // Invalid. 411 packet->payload = NULL; // Invalid.
412 list.push_back(packet); 412 list.push_back(packet);
413 list.push_back(gen.NextPacket(payload_len)); // Valid packet. 413 list.push_back(gen.NextPacket(payload_len)); // Valid packet.
414 MockDecoderDatabase decoder_database; 414 MockDecoderDatabase decoder_database;
415 uint8_t current_pt = 0xFF; 415 rtc::Optional<uint8_t> current_pt;
416 uint8_t current_cng_pt = 0xFF; 416 rtc::Optional<uint8_t> current_cng_pt;
417 EXPECT_EQ(PacketBuffer::kInvalidPacket, 417 EXPECT_EQ(PacketBuffer::kInvalidPacket,
418 buffer->InsertPacketList(&list, 418 buffer->InsertPacketList(&list,
419 decoder_database, 419 decoder_database,
420 &current_pt, 420 &current_pt,
421 &current_cng_pt)); 421 &current_cng_pt));
422 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list. 422 EXPECT_TRUE(list.empty()); // The PacketBuffer should have depleted the list.
423 EXPECT_EQ(1u, buffer->NumPacketsInBuffer()); 423 EXPECT_EQ(1u, buffer->NumPacketsInBuffer());
424 delete buffer; 424 delete buffer;
425 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted. 425 EXPECT_CALL(decoder_database, Die()); // Called when object is deleted.
426 } 426 }
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 // Test the IsObsoleteTimestamp method with different limit timestamps. 564 // Test the IsObsoleteTimestamp method with different limit timestamps.
565 TEST(PacketBuffer, IsObsoleteTimestamp) { 565 TEST(PacketBuffer, IsObsoleteTimestamp) {
566 TestIsObsoleteTimestamp(0); 566 TestIsObsoleteTimestamp(0);
567 TestIsObsoleteTimestamp(1); 567 TestIsObsoleteTimestamp(1);
568 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t. 568 TestIsObsoleteTimestamp(0xFFFFFFFF); // -1 in uint32_t.
569 TestIsObsoleteTimestamp(0x80000000); // 2^31. 569 TestIsObsoleteTimestamp(0x80000000); // 2^31.
570 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1. 570 TestIsObsoleteTimestamp(0x80000001); // 2^31 + 1.
571 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1. 571 TestIsObsoleteTimestamp(0x7FFFFFFF); // 2^31 - 1.
572 } 572 }
573 } // namespace webrtc 573 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698