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

Side by Side Diff: webrtc/call/rtc_event_log_unittest.cc

Issue 1411673003: Added protobuf message for loss-based BWE events, and wired it up to the send side bandwidth estima… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 5 years, 1 month 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) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 } 269 }
270 270
271 void VerifyPlayoutEvent(const rtclog::Event& event, uint32_t ssrc) { 271 void VerifyPlayoutEvent(const rtclog::Event& event, uint32_t ssrc) {
272 ASSERT_TRUE(IsValidBasicEvent(event)); 272 ASSERT_TRUE(IsValidBasicEvent(event));
273 ASSERT_EQ(rtclog::Event::AUDIO_PLAYOUT_EVENT, event.type()); 273 ASSERT_EQ(rtclog::Event::AUDIO_PLAYOUT_EVENT, event.type());
274 const rtclog::AudioPlayoutEvent& playout_event = event.audio_playout_event(); 274 const rtclog::AudioPlayoutEvent& playout_event = event.audio_playout_event();
275 ASSERT_TRUE(playout_event.has_local_ssrc()); 275 ASSERT_TRUE(playout_event.has_local_ssrc());
276 EXPECT_EQ(ssrc, playout_event.local_ssrc()); 276 EXPECT_EQ(ssrc, playout_event.local_ssrc());
277 } 277 }
278 278
279 void VerifyBweLossEvent(const rtclog::Event& event,
280 int32_t bitrate,
281 uint8_t fraction_loss,
282 int32_t total_packets) {
283 ASSERT_TRUE(IsValidBasicEvent(event));
284 ASSERT_EQ(rtclog::Event::BWE_PACKET_LOSS_EVENT, event.type());
285 const rtclog::BwePacketLossEvent& bwe_event = event.bwe_packet_loss_event();
286 ASSERT_TRUE(bwe_event.has_bitrate());
287 EXPECT_EQ(bitrate, bwe_event.bitrate());
288 ASSERT_TRUE(bwe_event.has_fraction_loss());
289 EXPECT_EQ(fraction_loss, bwe_event.fraction_loss());
290 ASSERT_TRUE(bwe_event.has_total_packets());
291 EXPECT_EQ(total_packets, bwe_event.total_packets());
292 }
293
279 void VerifyLogStartEvent(const rtclog::Event& event) { 294 void VerifyLogStartEvent(const rtclog::Event& event) {
280 ASSERT_TRUE(IsValidBasicEvent(event)); 295 ASSERT_TRUE(IsValidBasicEvent(event));
281 EXPECT_EQ(rtclog::Event::LOG_START, event.type()); 296 EXPECT_EQ(rtclog::Event::LOG_START, event.type());
282 } 297 }
283 298
284 /* 299 /*
285 * Bit number i of extension_bitvector is set to indicate the 300 * Bit number i of extension_bitvector is set to indicate the
286 * presence of extension number i from kExtensionTypes / kExtensionNames. 301 * presence of extension number i from kExtensionTypes / kExtensionNames.
287 * The least significant bit extension_bitvector has number 0. 302 * The least significant bit extension_bitvector has number 0.
288 */ 303 */
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 RtpExtension(kExtensionNames[i], rand())); 406 RtpExtension(kExtensionNames[i], rand()));
392 } 407 }
393 } 408 }
394 } 409 }
395 410
396 // Test for the RtcEventLog class. Dumps some RTP packets and other events 411 // Test for the RtcEventLog class. Dumps some RTP packets and other events
397 // to disk, then reads them back to see if they match. 412 // to disk, then reads them back to see if they match.
398 void LogSessionAndReadBack(size_t rtp_count, 413 void LogSessionAndReadBack(size_t rtp_count,
399 size_t rtcp_count, 414 size_t rtcp_count,
400 size_t playout_count, 415 size_t playout_count,
416 size_t bwe_loss_count,
401 uint32_t extensions_bitvector, 417 uint32_t extensions_bitvector,
402 uint32_t csrcs_count, 418 uint32_t csrcs_count,
403 unsigned int random_seed) { 419 unsigned int random_seed) {
404 ASSERT_LE(rtcp_count, rtp_count); 420 ASSERT_LE(rtcp_count, rtp_count);
405 ASSERT_LE(playout_count, rtp_count); 421 ASSERT_LE(playout_count, rtp_count);
422 ASSERT_LE(bwe_loss_count, rtp_count);
406 std::vector<rtc::Buffer> rtp_packets; 423 std::vector<rtc::Buffer> rtp_packets;
407 std::vector<rtc::Buffer> rtcp_packets; 424 std::vector<rtc::Buffer> rtcp_packets;
408 std::vector<size_t> rtp_header_sizes; 425 std::vector<size_t> rtp_header_sizes;
409 std::vector<uint32_t> playout_ssrcs; 426 std::vector<uint32_t> playout_ssrcs;
427 std::vector<std::pair<int32_t, uint8_t> > bwe_loss_updates;
410 428
411 VideoReceiveStream::Config receiver_config(nullptr); 429 VideoReceiveStream::Config receiver_config(nullptr);
412 VideoSendStream::Config sender_config(nullptr); 430 VideoSendStream::Config sender_config(nullptr);
413 431
414 srand(random_seed); 432 srand(random_seed);
415 433
416 // Create rtp_count RTP packets containing random data. 434 // Create rtp_count RTP packets containing random data.
417 for (size_t i = 0; i < rtp_count; i++) { 435 for (size_t i = 0; i < rtp_count; i++) {
418 size_t packet_size = 1000 + rand() % 64; 436 size_t packet_size = 1000 + rand() % 64;
419 rtp_packets.push_back(rtc::Buffer(packet_size)); 437 rtp_packets.push_back(rtc::Buffer(packet_size));
420 size_t header_size = GenerateRtpPacket(extensions_bitvector, csrcs_count, 438 size_t header_size = GenerateRtpPacket(extensions_bitvector, csrcs_count,
421 rtp_packets[i].data(), packet_size); 439 rtp_packets[i].data(), packet_size);
422 rtp_header_sizes.push_back(header_size); 440 rtp_header_sizes.push_back(header_size);
423 } 441 }
424 // Create rtcp_count RTCP packets containing random data. 442 // Create rtcp_count RTCP packets containing random data.
425 for (size_t i = 0; i < rtcp_count; i++) { 443 for (size_t i = 0; i < rtcp_count; i++) {
426 size_t packet_size = 1000 + rand() % 64; 444 size_t packet_size = 1000 + rand() % 64;
427 rtcp_packets.push_back(rtc::Buffer(packet_size)); 445 rtcp_packets.push_back(rtc::Buffer(packet_size));
428 GenerateRtcpPacket(rtcp_packets[i].data(), packet_size); 446 GenerateRtcpPacket(rtcp_packets[i].data(), packet_size);
429 } 447 }
430 // Create playout_count random SSRCs to use when logging AudioPlayout events. 448 // Create playout_count random SSRCs to use when logging AudioPlayout events.
431 for (size_t i = 0; i < playout_count; i++) { 449 for (size_t i = 0; i < playout_count; i++) {
432 playout_ssrcs.push_back(static_cast<uint32_t>(rand())); 450 playout_ssrcs.push_back(static_cast<uint32_t>(rand()));
433 } 451 }
452 // Create bwe_loss_count random bitrate updates for BwePacketLoss.
453 for (size_t i = 0; i < bwe_loss_count; i++) {
454 bwe_loss_updates.push_back(std::pair<int32_t, uint8_t>(rand(), rand()));
455 }
434 // Create configurations for the video streams. 456 // Create configurations for the video streams.
435 GenerateVideoReceiveConfig(extensions_bitvector, &receiver_config); 457 GenerateVideoReceiveConfig(extensions_bitvector, &receiver_config);
436 GenerateVideoSendConfig(extensions_bitvector, &sender_config); 458 GenerateVideoSendConfig(extensions_bitvector, &sender_config);
437 const int config_count = 2; 459 const int config_count = 2;
438 460
439 // Find the name of the current test, in order to use it as a temporary 461 // Find the name of the current test, in order to use it as a temporary
440 // filename. 462 // filename.
441 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); 463 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
442 const std::string temp_filename = 464 const std::string temp_filename =
443 test::OutputPath() + test_info->test_case_name() + test_info->name(); 465 test::OutputPath() + test_info->test_case_name() + test_info->name();
444 466
445 // When log_dumper goes out of scope, it causes the log file to be flushed 467 // When log_dumper goes out of scope, it causes the log file to be flushed
446 // to disk. 468 // to disk.
447 { 469 {
448 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); 470 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create());
449 log_dumper->LogVideoReceiveStreamConfig(receiver_config); 471 log_dumper->LogVideoReceiveStreamConfig(receiver_config);
450 log_dumper->LogVideoSendStreamConfig(sender_config); 472 log_dumper->LogVideoSendStreamConfig(sender_config);
451 size_t rtcp_index = 1, playout_index = 1; 473 size_t rtcp_index = 1;
474 size_t playout_index = 1;
475 size_t bwe_loss_index = 1;
452 for (size_t i = 1; i <= rtp_count; i++) { 476 for (size_t i = 1; i <= rtp_count; i++) {
453 log_dumper->LogRtpHeader( 477 log_dumper->LogRtpHeader(
454 (i % 2 == 0), // Every second packet is incoming. 478 (i % 2 == 0), // Every second packet is incoming.
455 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, 479 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO,
456 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); 480 rtp_packets[i - 1].data(), rtp_packets[i - 1].size());
457 if (i * rtcp_count >= rtcp_index * rtp_count) { 481 if (i * rtcp_count >= rtcp_index * rtp_count) {
458 log_dumper->LogRtcpPacket( 482 log_dumper->LogRtcpPacket(
459 rtcp_index % 2 == 0, // Every second packet is incoming 483 rtcp_index % 2 == 0, // Every second packet is incoming
460 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, 484 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO,
461 rtcp_packets[rtcp_index - 1].data(), 485 rtcp_packets[rtcp_index - 1].data(),
462 rtcp_packets[rtcp_index - 1].size()); 486 rtcp_packets[rtcp_index - 1].size());
463 rtcp_index++; 487 rtcp_index++;
464 } 488 }
465 if (i * playout_count >= playout_index * rtp_count) { 489 if (i * playout_count >= playout_index * rtp_count) {
466 log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]); 490 log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]);
467 playout_index++; 491 playout_index++;
468 } 492 }
493 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) {
494 log_dumper->LogBwePacketLossEvent(
495 bwe_loss_updates[bwe_loss_index - 1].first,
496 bwe_loss_updates[bwe_loss_index - 1].second, i);
497 bwe_loss_index++;
498 }
469 if (i == rtp_count / 2) { 499 if (i == rtp_count / 2) {
470 log_dumper->StartLogging(temp_filename, 10000000); 500 log_dumper->StartLogging(temp_filename, 10000000);
471 } 501 }
472 } 502 }
473 } 503 }
474 504
475 // Read the generated file from disk. 505 // Read the generated file from disk.
476 rtclog::EventStream parsed_stream; 506 rtclog::EventStream parsed_stream;
477 507
478 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); 508 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream));
479 509
480 // Verify that what we read back from the event log is the same as 510 // Verify that what we read back from the event log is the same as
481 // what we wrote down. For RTCP we log the full packets, but for 511 // what we wrote down. For RTCP we log the full packets, but for
482 // RTP we should only log the header. 512 // RTP we should only log the header.
483 const int event_count = 513 const int event_count = config_count + playout_count + bwe_loss_count +
484 config_count + playout_count + rtcp_count + rtp_count + 1; 514 rtcp_count + rtp_count + 1;
485 EXPECT_EQ(event_count, parsed_stream.stream_size()); 515 EXPECT_EQ(event_count, parsed_stream.stream_size());
486 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); 516 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config);
487 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); 517 VerifySendStreamConfig(parsed_stream.stream(1), sender_config);
488 size_t event_index = config_count, rtcp_index = 1, playout_index = 1; 518 size_t event_index = config_count;
519 size_t rtcp_index = 1;
520 size_t playout_index = 1;
521 size_t bwe_loss_index = 1;
489 for (size_t i = 1; i <= rtp_count; i++) { 522 for (size_t i = 1; i <= rtp_count; i++) {
490 VerifyRtpEvent(parsed_stream.stream(event_index), 523 VerifyRtpEvent(parsed_stream.stream(event_index),
491 (i % 2 == 0), // Every second packet is incoming. 524 (i % 2 == 0), // Every second packet is incoming.
492 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, 525 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO,
493 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1], 526 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1],
494 rtp_packets[i - 1].size()); 527 rtp_packets[i - 1].size());
495 event_index++; 528 event_index++;
496 if (i * rtcp_count >= rtcp_index * rtp_count) { 529 if (i * rtcp_count >= rtcp_index * rtp_count) {
497 VerifyRtcpEvent(parsed_stream.stream(event_index), 530 VerifyRtcpEvent(parsed_stream.stream(event_index),
498 rtcp_index % 2 == 0, // Every second packet is incoming. 531 rtcp_index % 2 == 0, // Every second packet is incoming.
499 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, 532 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO,
500 rtcp_packets[rtcp_index - 1].data(), 533 rtcp_packets[rtcp_index - 1].data(),
501 rtcp_packets[rtcp_index - 1].size()); 534 rtcp_packets[rtcp_index - 1].size());
502 event_index++; 535 event_index++;
503 rtcp_index++; 536 rtcp_index++;
504 } 537 }
505 if (i * playout_count >= playout_index * rtp_count) { 538 if (i * playout_count >= playout_index * rtp_count) {
506 VerifyPlayoutEvent(parsed_stream.stream(event_index), 539 VerifyPlayoutEvent(parsed_stream.stream(event_index),
507 playout_ssrcs[playout_index - 1]); 540 playout_ssrcs[playout_index - 1]);
508 event_index++; 541 event_index++;
509 playout_index++; 542 playout_index++;
510 } 543 }
544 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) {
545 VerifyBweLossEvent(parsed_stream.stream(event_index),
546 bwe_loss_updates[bwe_loss_index - 1].first,
547 bwe_loss_updates[bwe_loss_index - 1].second, i);
548 event_index++;
549 bwe_loss_index++;
550 }
511 if (i == rtp_count / 2) { 551 if (i == rtp_count / 2) {
512 VerifyLogStartEvent(parsed_stream.stream(event_index)); 552 VerifyLogStartEvent(parsed_stream.stream(event_index));
513 event_index++; 553 event_index++;
514 } 554 }
515 } 555 }
516 556
517 // Clean up temporary file - can be pretty slow. 557 // Clean up temporary file - can be pretty slow.
518 remove(temp_filename.c_str()); 558 remove(temp_filename.c_str());
519 } 559 }
520 560
521 TEST(RtcEventLogTest, LogSessionAndReadBack) { 561 TEST(RtcEventLogTest, LogSessionAndReadBack) {
522 // Log 5 RTP, 2 RTCP, and 0 playout events with no header extensions or CSRCS. 562 // Log 5 RTP, 2 RTCP, 0 playout events and 0 BWE events
523 LogSessionAndReadBack(5, 2, 0, 0, 0, 321); 563 // with no header extensions or CSRCS.
564 LogSessionAndReadBack(5, 2, 0, 0, 0, 0, 321);
524 565
525 // Enable AbsSendTime and TransportSequenceNumbers 566 // Enable AbsSendTime and TransportSequenceNumbers.
526 uint32_t extensions = 0; 567 uint32_t extensions = 0;
527 for (uint32_t i = 0; i < kNumExtensions; i++) { 568 for (uint32_t i = 0; i < kNumExtensions; i++) {
528 if (kExtensionTypes[i] == RTPExtensionType::kRtpExtensionAbsoluteSendTime || 569 if (kExtensionTypes[i] == RTPExtensionType::kRtpExtensionAbsoluteSendTime ||
529 kExtensionTypes[i] == 570 kExtensionTypes[i] ==
530 RTPExtensionType::kRtpExtensionTransportSequenceNumber) { 571 RTPExtensionType::kRtpExtensionTransportSequenceNumber) {
531 extensions |= 1u << i; 572 extensions |= 1u << i;
532 } 573 }
533 } 574 }
534 LogSessionAndReadBack(8, 2, 0, extensions, 0, 3141592653u); 575 LogSessionAndReadBack(8, 2, 0, 0, extensions, 0, 3141592653u);
535 576
536 extensions = (1u << kNumExtensions) - 1; // Enable all header extensions 577 extensions = (1u << kNumExtensions) - 1; // Enable all header extensions.
537 LogSessionAndReadBack(9, 2, 3, extensions, 2, 2718281828u); 578 LogSessionAndReadBack(9, 2, 3, 2, extensions, 2, 2718281828u);
538 579
539 // Try all combinations of header extensions and up to 2 CSRCS. 580 // Try all combinations of header extensions and up to 2 CSRCS.
540 for (extensions = 0; extensions < (1u << kNumExtensions); extensions++) { 581 for (extensions = 0; extensions < (1u << kNumExtensions); extensions++) {
541 for (uint32_t csrcs_count = 0; csrcs_count < 3; csrcs_count++) { 582 for (uint32_t csrcs_count = 0; csrcs_count < 3; csrcs_count++) {
542 LogSessionAndReadBack(5 + extensions, // Number of RTP packets. 583 LogSessionAndReadBack(5 + extensions, // Number of RTP packets.
543 2 + csrcs_count, // Number of RTCP packets. 584 2 + csrcs_count, // Number of RTCP packets.
544 3 + csrcs_count, // Number of playout events 585 3 + csrcs_count, // Number of playout events.
545 extensions, // Bit vector choosing extensions 586 1 + csrcs_count, // Number of BWE loss events.
546 csrcs_count, // Number of contributing sources 587 extensions, // Bit vector choosing extensions.
588 csrcs_count, // Number of contributing sources.
547 rand()); 589 rand());
548 } 590 }
549 } 591 }
550 } 592 }
551 593
552 // Tests that the event queue works correctly, i.e. drops old RTP, RTCP and 594 // Tests that the event queue works correctly, i.e. drops old RTP, RTCP and
553 // debug events, but keeps config events even if they are older than the limit. 595 // debug events, but keeps config events even if they are older than the limit.
554 void DropOldEvents(uint32_t extensions_bitvector, 596 void DropOldEvents(uint32_t extensions_bitvector,
555 uint32_t csrcs_count, 597 uint32_t csrcs_count,
556 unsigned int random_seed) { 598 unsigned int random_seed) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 // Enable all header extensions 680 // Enable all header extensions
639 uint32_t extensions = (1u << kNumExtensions) - 1; 681 uint32_t extensions = (1u << kNumExtensions) - 1;
640 uint32_t csrcs_count = 2; 682 uint32_t csrcs_count = 2;
641 DropOldEvents(extensions, csrcs_count, 141421356); 683 DropOldEvents(extensions, csrcs_count, 141421356);
642 DropOldEvents(extensions, csrcs_count, 173205080); 684 DropOldEvents(extensions, csrcs_count, 173205080);
643 } 685 }
644 686
645 } // namespace webrtc 687 } // namespace webrtc
646 688
647 #endif // ENABLE_RTC_EVENT_LOG 689 #endif // ENABLE_RTC_EVENT_LOG
OLDNEW
« no previous file with comments | « webrtc/call/rtc_event_log.proto ('k') | webrtc/modules/bitrate_controller/bitrate_controller_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698