Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| 11 #ifdef ENABLE_RTC_EVENT_LOG | 11 #ifdef ENABLE_RTC_EVENT_LOG |
| 12 | 12 |
| 13 #include <stdio.h> | 13 #include <stdio.h> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "webrtc/base/buffer.h" | 18 #include "webrtc/base/buffer.h" |
| 19 #include "webrtc/base/checks.h" | 19 #include "webrtc/base/checks.h" |
| 20 #include "webrtc/base/scoped_ptr.h" | 20 #include "webrtc/base/scoped_ptr.h" |
| 21 #include "webrtc/base/thread.h" | |
| 21 #include "webrtc/call.h" | 22 #include "webrtc/call.h" |
| 22 #include "webrtc/call/rtc_event_log.h" | 23 #include "webrtc/call/rtc_event_log.h" |
| 23 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" | 24 #include "webrtc/modules/rtp_rtcp/source/rtp_sender.h" |
| 24 #include "webrtc/system_wrappers/interface/clock.h" | 25 #include "webrtc/system_wrappers/interface/clock.h" |
| 25 #include "webrtc/test/test_suite.h" | 26 #include "webrtc/test/test_suite.h" |
| 26 #include "webrtc/test/testsupport/fileutils.h" | 27 #include "webrtc/test/testsupport/fileutils.h" |
| 27 #include "webrtc/test/testsupport/gtest_disable.h" | 28 #include "webrtc/test/testsupport/gtest_disable.h" |
| 28 | 29 |
| 29 // Files generated at build-time by the protobuf compiler. | 30 // Files generated at build-time by the protobuf compiler. |
| 30 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 31 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 config->rtp.c_name = "some.user@some.host"; | 386 config->rtp.c_name = "some.user@some.host"; |
| 386 // Add header extensions. | 387 // Add header extensions. |
| 387 for (unsigned i = 0; i < kNumExtensions; i++) { | 388 for (unsigned i = 0; i < kNumExtensions; i++) { |
| 388 if (extensions_bitvector & (1u << i)) { | 389 if (extensions_bitvector & (1u << i)) { |
| 389 config->rtp.extensions.push_back( | 390 config->rtp.extensions.push_back( |
| 390 RtpExtension(kExtensionNames[i], rand())); | 391 RtpExtension(kExtensionNames[i], rand())); |
| 391 } | 392 } |
| 392 } | 393 } |
| 393 } | 394 } |
| 394 | 395 |
| 395 // Test for the RtcEventLog class. Dumps some RTP packets to disk, then reads | 396 // Test for the RtcEventLog class. Dumps some RTP packets and other events |
| 396 // them back to see if they match. | 397 // to disk, then reads them back to see if they match. |
| 397 void LogSessionAndReadBack(size_t rtp_count, | 398 void LogSessionAndReadBack(size_t rtp_count, |
| 398 size_t rtcp_count, | 399 size_t rtcp_count, |
| 399 size_t playout_count, | 400 size_t playout_count, |
| 400 uint32_t extensions_bitvector, | 401 uint32_t extensions_bitvector, |
| 401 uint32_t csrcs_count, | 402 uint32_t csrcs_count, |
| 402 unsigned random_seed) { | 403 unsigned int random_seed) { |
| 403 ASSERT_LE(rtcp_count, rtp_count); | 404 ASSERT_LE(rtcp_count, rtp_count); |
| 404 ASSERT_LE(playout_count, rtp_count); | 405 ASSERT_LE(playout_count, rtp_count); |
| 405 std::vector<rtc::Buffer> rtp_packets; | 406 std::vector<rtc::Buffer> rtp_packets; |
| 406 std::vector<rtc::Buffer> rtcp_packets; | 407 std::vector<rtc::Buffer> rtcp_packets; |
| 407 std::vector<size_t> rtp_header_sizes; | 408 std::vector<size_t> rtp_header_sizes; |
| 408 std::vector<uint32_t> playout_ssrcs; | 409 std::vector<uint32_t> playout_ssrcs; |
| 409 | 410 |
| 410 VideoReceiveStream::Config receiver_config(nullptr); | 411 VideoReceiveStream::Config receiver_config(nullptr); |
| 411 VideoSendStream::Config sender_config(nullptr); | 412 VideoSendStream::Config sender_config(nullptr); |
| 412 | 413 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 log_dumper->StartLogging(temp_filename, 10000000); | 470 log_dumper->StartLogging(temp_filename, 10000000); |
| 470 } | 471 } |
| 471 } | 472 } |
| 472 } | 473 } |
| 473 | 474 |
| 474 // Read the generated file from disk. | 475 // Read the generated file from disk. |
| 475 rtclog::EventStream parsed_stream; | 476 rtclog::EventStream parsed_stream; |
| 476 | 477 |
| 477 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | 478 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); |
| 478 | 479 |
| 479 // Verify the result. | 480 // 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 | |
| 482 // RTP we should only log the header. | |
| 480 const int event_count = | 483 const int event_count = |
| 481 config_count + playout_count + rtcp_count + rtp_count + 1; | 484 config_count + playout_count + rtcp_count + rtp_count + 1; |
| 482 EXPECT_EQ(event_count, parsed_stream.stream_size()); | 485 EXPECT_EQ(event_count, parsed_stream.stream_size()); |
| 483 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); | 486 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); |
| 484 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); | 487 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); |
| 485 size_t event_index = config_count, rtcp_index = 1, playout_index = 1; | 488 size_t event_index = config_count, rtcp_index = 1, playout_index = 1; |
| 486 for (size_t i = 1; i <= rtp_count; i++) { | 489 for (size_t i = 1; i <= rtp_count; i++) { |
| 487 VerifyRtpEvent(parsed_stream.stream(event_index), | 490 VerifyRtpEvent(parsed_stream.stream(event_index), |
| 488 (i % 2 == 0), // Every second packet is incoming. | 491 (i % 2 == 0), // Every second packet is incoming. |
| 489 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 492 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 LogSessionAndReadBack(5 + extensions, // Number of RTP packets. | 542 LogSessionAndReadBack(5 + extensions, // Number of RTP packets. |
| 540 2 + csrcs_count, // Number of RTCP packets. | 543 2 + csrcs_count, // Number of RTCP packets. |
| 541 3 + csrcs_count, // Number of playout events | 544 3 + csrcs_count, // Number of playout events |
| 542 extensions, // Bit vector choosing extensions | 545 extensions, // Bit vector choosing extensions |
| 543 csrcs_count, // Number of contributing sources | 546 csrcs_count, // Number of contributing sources |
| 544 rand()); | 547 rand()); |
| 545 } | 548 } |
| 546 } | 549 } |
| 547 } | 550 } |
| 548 | 551 |
| 552 // 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. | |
| 554 void DropOldEvents(uint32_t extensions_bitvector, | |
| 555 uint32_t csrcs_count, | |
| 556 unsigned int random_seed) { | |
| 557 rtc::Buffer old_rtp_packet; | |
| 558 rtc::Buffer recent_rtp_packet; | |
| 559 rtc::Buffer old_rtcp_packet; | |
| 560 rtc::Buffer recent_rtcp_packet; | |
| 561 | |
| 562 VideoReceiveStream::Config receiver_config(nullptr); | |
| 563 VideoSendStream::Config sender_config(nullptr); | |
| 564 | |
| 565 srand(random_seed); | |
| 566 | |
| 567 // Create two RTP packets containing random data. | |
| 568 size_t packet_size = 1000 + rand() % 64; | |
|
the sun
2015/10/16 21:47:01
Avoid rand() in unit tests; it accesses global sta
| |
| 569 old_rtp_packet.SetSize(packet_size); | |
| 570 GenerateRtpPacket(extensions_bitvector, csrcs_count, old_rtp_packet.data(), | |
| 571 packet_size); | |
| 572 packet_size = 1000 + rand() % 64; | |
| 573 recent_rtp_packet.SetSize(packet_size); | |
| 574 size_t recent_header_size = GenerateRtpPacket( | |
| 575 extensions_bitvector, csrcs_count, recent_rtp_packet.data(), packet_size); | |
| 576 | |
| 577 // Create two RTCP packets containing random data. | |
| 578 packet_size = 1000 + rand() % 64; | |
| 579 old_rtcp_packet.SetSize(packet_size); | |
| 580 GenerateRtcpPacket(old_rtcp_packet.data(), packet_size); | |
| 581 packet_size = 1000 + rand() % 64; | |
| 582 recent_rtcp_packet.SetSize(packet_size); | |
| 583 GenerateRtcpPacket(recent_rtcp_packet.data(), packet_size); | |
| 584 | |
| 585 // Create configurations for the video streams. | |
| 586 GenerateVideoReceiveConfig(extensions_bitvector, &receiver_config); | |
| 587 GenerateVideoSendConfig(extensions_bitvector, &sender_config); | |
| 588 | |
| 589 // Find the name of the current test, in order to use it as a temporary | |
| 590 // filename. | |
| 591 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | |
| 592 const std::string temp_filename = | |
| 593 test::OutputPath() + test_info->test_case_name() + test_info->name(); | |
| 594 | |
| 595 // The log file will be flushed to disk when the log_dumper goes out of scope. | |
| 596 { | |
| 597 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); | |
| 598 // Reduce the time old events are stored to 50 ms. | |
| 599 log_dumper->SetBufferDuration(50000); | |
| 600 log_dumper->LogVideoReceiveStreamConfig(receiver_config); | |
| 601 log_dumper->LogVideoSendStreamConfig(sender_config); | |
| 602 log_dumper->LogRtpHeader(false, MediaType::AUDIO, old_rtp_packet.data(), | |
| 603 old_rtp_packet.size()); | |
| 604 log_dumper->LogRtcpPacket(true, MediaType::AUDIO, old_rtcp_packet.data(), | |
| 605 old_rtcp_packet.size()); | |
| 606 // Sleep 55 ms to let old events be removed from the queue. | |
| 607 rtc::Thread::SleepMs(55); | |
| 608 log_dumper->StartLogging(temp_filename, 10000000); | |
| 609 log_dumper->LogRtpHeader(true, MediaType::VIDEO, recent_rtp_packet.data(), | |
| 610 recent_rtp_packet.size()); | |
| 611 log_dumper->LogRtcpPacket(false, MediaType::VIDEO, | |
| 612 recent_rtcp_packet.data(), | |
| 613 recent_rtcp_packet.size()); | |
| 614 } | |
| 615 | |
| 616 // Read the generated file from disk. | |
| 617 rtclog::EventStream parsed_stream; | |
| 618 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | |
| 619 | |
| 620 // Verify that what we read back from the event log is the same as | |
| 621 // what we wrote. Old RTP and RTCP events should have been discarded, | |
| 622 // but old configuration events should still be available. | |
| 623 EXPECT_EQ(5, parsed_stream.stream_size()); | |
| 624 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); | |
| 625 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); | |
| 626 VerifyLogStartEvent(parsed_stream.stream(2)); | |
| 627 VerifyRtpEvent(parsed_stream.stream(3), true, MediaType::VIDEO, | |
| 628 recent_rtp_packet.data(), recent_header_size, | |
| 629 recent_rtp_packet.size()); | |
| 630 VerifyRtcpEvent(parsed_stream.stream(4), false, MediaType::VIDEO, | |
| 631 recent_rtcp_packet.data(), recent_rtcp_packet.size()); | |
| 632 | |
| 633 // Clean up temporary file - can be pretty slow. | |
| 634 remove(temp_filename.c_str()); | |
| 635 } | |
| 636 | |
| 637 TEST(RtcEventLogTest, DropOldEvents) { | |
| 638 // Enable all header extensions | |
| 639 uint32_t extensions = (1u << kNumExtensions) - 1; | |
| 640 uint32_t csrcs_count = 2; | |
| 641 DropOldEvents(extensions, csrcs_count, 141421356); | |
| 642 DropOldEvents(extensions, csrcs_count, 173205080); | |
| 643 } | |
| 644 | |
| 549 } // namespace webrtc | 645 } // namespace webrtc |
| 550 | 646 |
| 551 #endif // ENABLE_RTC_EVENT_LOG | 647 #endif // ENABLE_RTC_EVENT_LOG |
| OLD | NEW |