| 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 |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 packet, payload_type, marker_bit, capture_timestamp, capture_time_ms, | 343 packet, payload_type, marker_bit, capture_timestamp, capture_time_ms, |
| 344 timestamp_provided, inc_sequence_number); | 344 timestamp_provided, inc_sequence_number); |
| 345 | 345 |
| 346 for (size_t i = header_size; i < packet_size; i++) { | 346 for (size_t i = header_size; i < packet_size; i++) { |
| 347 packet[i] = prng->Rand<uint8_t>(); | 347 packet[i] = prng->Rand<uint8_t>(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 return header_size; | 350 return header_size; |
| 351 } | 351 } |
| 352 | 352 |
| 353 rtc::scoped_ptr<rtcp::RawPacket> GenerateRtcpPacket(Random* prng) { | 353 rtc::Buffer GenerateRtcpPacket(Random* prng) { |
| 354 rtcp::ReportBlock report_block; | 354 rtcp::ReportBlock report_block; |
| 355 report_block.To(prng->Rand<uint32_t>()); // Remote SSRC. | 355 report_block.To(prng->Rand<uint32_t>()); // Remote SSRC. |
| 356 report_block.WithFractionLost(prng->Rand(50)); | 356 report_block.WithFractionLost(prng->Rand(50)); |
| 357 | 357 |
| 358 rtcp::SenderReport sender_report; | 358 rtcp::SenderReport sender_report; |
| 359 sender_report.From(prng->Rand<uint32_t>()); // Sender SSRC. | 359 sender_report.From(prng->Rand<uint32_t>()); // Sender SSRC. |
| 360 sender_report.WithNtp( | 360 sender_report.WithNtp( |
| 361 NtpTime(prng->Rand<uint32_t>(), prng->Rand<uint32_t>())); | 361 NtpTime(prng->Rand<uint32_t>(), prng->Rand<uint32_t>())); |
| 362 sender_report.WithPacketCount(prng->Rand<uint32_t>()); | 362 sender_report.WithPacketCount(prng->Rand<uint32_t>()); |
| 363 sender_report.WithReportBlock(report_block); | 363 sender_report.WithReportBlock(report_block); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 size_t rtcp_count, | 420 size_t rtcp_count, |
| 421 size_t playout_count, | 421 size_t playout_count, |
| 422 size_t bwe_loss_count, | 422 size_t bwe_loss_count, |
| 423 uint32_t extensions_bitvector, | 423 uint32_t extensions_bitvector, |
| 424 uint32_t csrcs_count, | 424 uint32_t csrcs_count, |
| 425 unsigned int random_seed) { | 425 unsigned int random_seed) { |
| 426 ASSERT_LE(rtcp_count, rtp_count); | 426 ASSERT_LE(rtcp_count, rtp_count); |
| 427 ASSERT_LE(playout_count, rtp_count); | 427 ASSERT_LE(playout_count, rtp_count); |
| 428 ASSERT_LE(bwe_loss_count, rtp_count); | 428 ASSERT_LE(bwe_loss_count, rtp_count); |
| 429 std::vector<rtc::Buffer> rtp_packets; | 429 std::vector<rtc::Buffer> rtp_packets; |
| 430 std::vector<rtc::scoped_ptr<rtcp::RawPacket> > rtcp_packets; | 430 std::vector<rtc::Buffer> rtcp_packets; |
| 431 std::vector<size_t> rtp_header_sizes; | 431 std::vector<size_t> rtp_header_sizes; |
| 432 std::vector<uint32_t> playout_ssrcs; | 432 std::vector<uint32_t> playout_ssrcs; |
| 433 std::vector<std::pair<int32_t, uint8_t> > bwe_loss_updates; | 433 std::vector<std::pair<int32_t, uint8_t> > bwe_loss_updates; |
| 434 | 434 |
| 435 VideoReceiveStream::Config receiver_config(nullptr); | 435 VideoReceiveStream::Config receiver_config(nullptr); |
| 436 VideoSendStream::Config sender_config(nullptr); | 436 VideoSendStream::Config sender_config(nullptr); |
| 437 | 437 |
| 438 Random prng(random_seed); | 438 Random prng(random_seed); |
| 439 | 439 |
| 440 // Create rtp_count RTP packets containing random data. | 440 // Create rtp_count RTP packets containing random data. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 size_t bwe_loss_index = 1; | 481 size_t bwe_loss_index = 1; |
| 482 for (size_t i = 1; i <= rtp_count; i++) { | 482 for (size_t i = 1; i <= rtp_count; i++) { |
| 483 log_dumper->LogRtpHeader( | 483 log_dumper->LogRtpHeader( |
| 484 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, | 484 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, |
| 485 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 485 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
| 486 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); | 486 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); |
| 487 if (i * rtcp_count >= rtcp_index * rtp_count) { | 487 if (i * rtcp_count >= rtcp_index * rtp_count) { |
| 488 log_dumper->LogRtcpPacket( | 488 log_dumper->LogRtcpPacket( |
| 489 (rtcp_index % 2 == 0) ? kIncomingPacket : kOutgoingPacket, | 489 (rtcp_index % 2 == 0) ? kIncomingPacket : kOutgoingPacket, |
| 490 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, | 490 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, |
| 491 rtcp_packets[rtcp_index - 1]->Buffer(), | 491 rtcp_packets[rtcp_index - 1].data(), |
| 492 rtcp_packets[rtcp_index - 1]->Length()); | 492 rtcp_packets[rtcp_index - 1].size()); |
| 493 rtcp_index++; | 493 rtcp_index++; |
| 494 } | 494 } |
| 495 if (i * playout_count >= playout_index * rtp_count) { | 495 if (i * playout_count >= playout_index * rtp_count) { |
| 496 log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]); | 496 log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]); |
| 497 playout_index++; | 497 playout_index++; |
| 498 } | 498 } |
| 499 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { | 499 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { |
| 500 log_dumper->LogBwePacketLossEvent( | 500 log_dumper->LogBwePacketLossEvent( |
| 501 bwe_loss_updates[bwe_loss_index - 1].first, | 501 bwe_loss_updates[bwe_loss_index - 1].first, |
| 502 bwe_loss_updates[bwe_loss_index - 1].second, i); | 502 bwe_loss_updates[bwe_loss_index - 1].second, i); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 529 VerifyRtpEvent(parsed_stream.stream(event_index), | 529 VerifyRtpEvent(parsed_stream.stream(event_index), |
| 530 (i % 2 == 0), // Every second packet is incoming. | 530 (i % 2 == 0), // Every second packet is incoming. |
| 531 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 531 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
| 532 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1], | 532 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1], |
| 533 rtp_packets[i - 1].size()); | 533 rtp_packets[i - 1].size()); |
| 534 event_index++; | 534 event_index++; |
| 535 if (i * rtcp_count >= rtcp_index * rtp_count) { | 535 if (i * rtcp_count >= rtcp_index * rtp_count) { |
| 536 VerifyRtcpEvent(parsed_stream.stream(event_index), | 536 VerifyRtcpEvent(parsed_stream.stream(event_index), |
| 537 rtcp_index % 2 == 0, // Every second packet is incoming. | 537 rtcp_index % 2 == 0, // Every second packet is incoming. |
| 538 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, | 538 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, |
| 539 rtcp_packets[rtcp_index - 1]->Buffer(), | 539 rtcp_packets[rtcp_index - 1].data(), |
| 540 rtcp_packets[rtcp_index - 1]->Length()); | 540 rtcp_packets[rtcp_index - 1].size()); |
| 541 event_index++; | 541 event_index++; |
| 542 rtcp_index++; | 542 rtcp_index++; |
| 543 } | 543 } |
| 544 if (i * playout_count >= playout_index * rtp_count) { | 544 if (i * playout_count >= playout_index * rtp_count) { |
| 545 VerifyPlayoutEvent(parsed_stream.stream(event_index), | 545 VerifyPlayoutEvent(parsed_stream.stream(event_index), |
| 546 playout_ssrcs[playout_index - 1]); | 546 playout_ssrcs[playout_index - 1]); |
| 547 event_index++; | 547 event_index++; |
| 548 playout_index++; | 548 playout_index++; |
| 549 } | 549 } |
| 550 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { | 550 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 } | 597 } |
| 598 } | 598 } |
| 599 | 599 |
| 600 // Tests that the event queue works correctly, i.e. drops old RTP, RTCP and | 600 // Tests that the event queue works correctly, i.e. drops old RTP, RTCP and |
| 601 // debug events, but keeps config events even if they are older than the limit. | 601 // debug events, but keeps config events even if they are older than the limit. |
| 602 void DropOldEvents(uint32_t extensions_bitvector, | 602 void DropOldEvents(uint32_t extensions_bitvector, |
| 603 uint32_t csrcs_count, | 603 uint32_t csrcs_count, |
| 604 unsigned int random_seed) { | 604 unsigned int random_seed) { |
| 605 rtc::Buffer old_rtp_packet; | 605 rtc::Buffer old_rtp_packet; |
| 606 rtc::Buffer recent_rtp_packet; | 606 rtc::Buffer recent_rtp_packet; |
| 607 rtc::scoped_ptr<rtcp::RawPacket> old_rtcp_packet; | 607 rtc::Buffer old_rtcp_packet; |
| 608 rtc::scoped_ptr<rtcp::RawPacket> recent_rtcp_packet; | 608 rtc::Buffer recent_rtcp_packet; |
| 609 | 609 |
| 610 VideoReceiveStream::Config receiver_config(nullptr); | 610 VideoReceiveStream::Config receiver_config(nullptr); |
| 611 VideoSendStream::Config sender_config(nullptr); | 611 VideoSendStream::Config sender_config(nullptr); |
| 612 | 612 |
| 613 Random prng(random_seed); | 613 Random prng(random_seed); |
| 614 | 614 |
| 615 // Create two RTP packets containing random data. | 615 // Create two RTP packets containing random data. |
| 616 size_t packet_size = prng.Rand(1000, 1100); | 616 size_t packet_size = prng.Rand(1000, 1100); |
| 617 old_rtp_packet.SetSize(packet_size); | 617 old_rtp_packet.SetSize(packet_size); |
| 618 GenerateRtpPacket(extensions_bitvector, csrcs_count, old_rtp_packet.data(), | 618 GenerateRtpPacket(extensions_bitvector, csrcs_count, old_rtp_packet.data(), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 640 // The log file will be flushed to disk when the log_dumper goes out of scope. | 640 // The log file will be flushed to disk when the log_dumper goes out of scope. |
| 641 { | 641 { |
| 642 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); | 642 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); |
| 643 // Reduce the time old events are stored to 50 ms. | 643 // Reduce the time old events are stored to 50 ms. |
| 644 log_dumper->SetBufferDuration(50000); | 644 log_dumper->SetBufferDuration(50000); |
| 645 log_dumper->LogVideoReceiveStreamConfig(receiver_config); | 645 log_dumper->LogVideoReceiveStreamConfig(receiver_config); |
| 646 log_dumper->LogVideoSendStreamConfig(sender_config); | 646 log_dumper->LogVideoSendStreamConfig(sender_config); |
| 647 log_dumper->LogRtpHeader(kOutgoingPacket, MediaType::AUDIO, | 647 log_dumper->LogRtpHeader(kOutgoingPacket, MediaType::AUDIO, |
| 648 old_rtp_packet.data(), old_rtp_packet.size()); | 648 old_rtp_packet.data(), old_rtp_packet.size()); |
| 649 log_dumper->LogRtcpPacket(kIncomingPacket, MediaType::AUDIO, | 649 log_dumper->LogRtcpPacket(kIncomingPacket, MediaType::AUDIO, |
| 650 old_rtcp_packet->Buffer(), | 650 old_rtcp_packet.data(), |
| 651 old_rtcp_packet->Length()); | 651 old_rtcp_packet.size()); |
| 652 // Sleep 55 ms to let old events be removed from the queue. | 652 // Sleep 55 ms to let old events be removed from the queue. |
| 653 rtc::Thread::SleepMs(55); | 653 rtc::Thread::SleepMs(55); |
| 654 log_dumper->StartLogging(temp_filename, 10000000); | 654 log_dumper->StartLogging(temp_filename, 10000000); |
| 655 log_dumper->LogRtpHeader(kIncomingPacket, MediaType::VIDEO, | 655 log_dumper->LogRtpHeader(kIncomingPacket, MediaType::VIDEO, |
| 656 recent_rtp_packet.data(), | 656 recent_rtp_packet.data(), |
| 657 recent_rtp_packet.size()); | 657 recent_rtp_packet.size()); |
| 658 log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO, | 658 log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO, |
| 659 recent_rtcp_packet->Buffer(), | 659 recent_rtcp_packet.data(), |
| 660 recent_rtcp_packet->Length()); | 660 recent_rtcp_packet.size()); |
| 661 } | 661 } |
| 662 | 662 |
| 663 // Read the generated file from disk. | 663 // Read the generated file from disk. |
| 664 rtclog::EventStream parsed_stream; | 664 rtclog::EventStream parsed_stream; |
| 665 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | 665 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); |
| 666 | 666 |
| 667 // Verify that what we read back from the event log is the same as | 667 // Verify that what we read back from the event log is the same as |
| 668 // what we wrote. Old RTP and RTCP events should have been discarded, | 668 // what we wrote. Old RTP and RTCP events should have been discarded, |
| 669 // but old configuration events should still be available. | 669 // but old configuration events should still be available. |
| 670 EXPECT_EQ(5, parsed_stream.stream_size()); | 670 EXPECT_EQ(5, parsed_stream.stream_size()); |
| 671 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); | 671 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); |
| 672 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); | 672 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); |
| 673 VerifyLogStartEvent(parsed_stream.stream(2)); | 673 VerifyLogStartEvent(parsed_stream.stream(2)); |
| 674 VerifyRtpEvent(parsed_stream.stream(3), true, MediaType::VIDEO, | 674 VerifyRtpEvent(parsed_stream.stream(3), true, MediaType::VIDEO, |
| 675 recent_rtp_packet.data(), recent_header_size, | 675 recent_rtp_packet.data(), recent_header_size, |
| 676 recent_rtp_packet.size()); | 676 recent_rtp_packet.size()); |
| 677 VerifyRtcpEvent(parsed_stream.stream(4), false, MediaType::VIDEO, | 677 VerifyRtcpEvent(parsed_stream.stream(4), false, MediaType::VIDEO, |
| 678 recent_rtcp_packet->Buffer(), recent_rtcp_packet->Length()); | 678 recent_rtcp_packet.data(), recent_rtcp_packet.size()); |
| 679 | 679 |
| 680 // Clean up temporary file - can be pretty slow. | 680 // Clean up temporary file - can be pretty slow. |
| 681 remove(temp_filename.c_str()); | 681 remove(temp_filename.c_str()); |
| 682 } | 682 } |
| 683 | 683 |
| 684 TEST(RtcEventLogTest, DropOldEvents) { | 684 TEST(RtcEventLogTest, DropOldEvents) { |
| 685 // Enable all header extensions | 685 // Enable all header extensions |
| 686 uint32_t extensions = (1u << kNumExtensions) - 1; | 686 uint32_t extensions = (1u << kNumExtensions) - 1; |
| 687 uint32_t csrcs_count = 2; | 687 uint32_t csrcs_count = 2; |
| 688 DropOldEvents(extensions, csrcs_count, 141421356); | 688 DropOldEvents(extensions, csrcs_count, 141421356); |
| 689 DropOldEvents(extensions, csrcs_count, 173205080); | 689 DropOldEvents(extensions, csrcs_count, 173205080); |
| 690 } | 690 } |
| 691 | 691 |
| 692 } // namespace webrtc | 692 } // namespace webrtc |
| 693 | 693 |
| 694 #endif // ENABLE_RTC_EVENT_LOG | 694 #endif // ENABLE_RTC_EVENT_LOG |
| OLD | NEW |