| 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 <map> |
| 13 #include <memory> | 14 #include <memory> |
| 14 #include <string> | 15 #include <string> |
| 15 #include <utility> | 16 #include <utility> |
| 16 #include <vector> | 17 #include <vector> |
| 17 | 18 |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "webrtc/base/buffer.h" | 20 #include "webrtc/base/buffer.h" |
| 20 #include "webrtc/base/checks.h" | 21 #include "webrtc/base/checks.h" |
| 21 #include "webrtc/base/random.h" | 22 #include "webrtc/base/random.h" |
| 22 #include "webrtc/base/thread.h" | 23 #include "webrtc/base/thread.h" |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 ASSERT_TRUE(sender_config.has_encoder()); | 218 ASSERT_TRUE(sender_config.has_encoder()); |
| 218 ASSERT_TRUE(sender_config.encoder().has_name()); | 219 ASSERT_TRUE(sender_config.encoder().has_name()); |
| 219 ASSERT_TRUE(sender_config.encoder().has_payload_type()); | 220 ASSERT_TRUE(sender_config.encoder().has_payload_type()); |
| 220 EXPECT_EQ(config.encoder_settings.payload_name, | 221 EXPECT_EQ(config.encoder_settings.payload_name, |
| 221 sender_config.encoder().name()); | 222 sender_config.encoder().name()); |
| 222 EXPECT_EQ(config.encoder_settings.payload_type, | 223 EXPECT_EQ(config.encoder_settings.payload_type, |
| 223 sender_config.encoder().payload_type()); | 224 sender_config.encoder().payload_type()); |
| 224 } | 225 } |
| 225 | 226 |
| 226 void VerifyRtpEvent(const rtclog::Event& event, | 227 void VerifyRtpEvent(const rtclog::Event& event, |
| 227 bool incoming, | 228 PacketDirection direction, |
| 228 MediaType media_type, | 229 MediaType media_type, |
| 229 const uint8_t* header, | 230 const uint8_t* header, |
| 230 size_t header_size, | 231 size_t header_size, |
| 231 size_t total_size) { | 232 size_t total_size) { |
| 232 ASSERT_TRUE(IsValidBasicEvent(event)); | 233 ASSERT_TRUE(IsValidBasicEvent(event)); |
| 233 ASSERT_EQ(rtclog::Event::RTP_EVENT, event.type()); | 234 ASSERT_EQ(rtclog::Event::RTP_EVENT, event.type()); |
| 234 const rtclog::RtpPacket& rtp_packet = event.rtp_packet(); | 235 const rtclog::RtpPacket& rtp_packet = event.rtp_packet(); |
| 235 ASSERT_TRUE(rtp_packet.has_incoming()); | 236 ASSERT_TRUE(rtp_packet.has_incoming()); |
| 236 EXPECT_EQ(incoming, rtp_packet.incoming()); | 237 EXPECT_EQ(direction == kIncomingPacket, rtp_packet.incoming()); |
| 237 ASSERT_TRUE(rtp_packet.has_type()); | 238 ASSERT_TRUE(rtp_packet.has_type()); |
| 238 EXPECT_EQ(media_type, GetRuntimeMediaType(rtp_packet.type())); | 239 EXPECT_EQ(media_type, GetRuntimeMediaType(rtp_packet.type())); |
| 239 ASSERT_TRUE(rtp_packet.has_packet_length()); | 240 ASSERT_TRUE(rtp_packet.has_packet_length()); |
| 240 EXPECT_EQ(total_size, rtp_packet.packet_length()); | 241 EXPECT_EQ(total_size, rtp_packet.packet_length()); |
| 241 ASSERT_TRUE(rtp_packet.has_header()); | 242 ASSERT_TRUE(rtp_packet.has_header()); |
| 242 ASSERT_EQ(header_size, rtp_packet.header().size()); | 243 ASSERT_EQ(header_size, rtp_packet.header().size()); |
| 243 for (size_t i = 0; i < header_size; i++) { | 244 for (size_t i = 0; i < header_size; i++) { |
| 244 EXPECT_EQ(header[i], static_cast<uint8_t>(rtp_packet.header()[i])); | 245 EXPECT_EQ(header[i], static_cast<uint8_t>(rtp_packet.header()[i])); |
| 245 } | 246 } |
| 246 } | 247 } |
| 247 | 248 |
| 248 void VerifyRtcpEvent(const rtclog::Event& event, | 249 void VerifyRtcpEvent(const rtclog::Event& event, |
| 249 bool incoming, | 250 PacketDirection direction, |
| 250 MediaType media_type, | 251 MediaType media_type, |
| 251 const uint8_t* packet, | 252 const uint8_t* packet, |
| 252 size_t total_size) { | 253 size_t total_size) { |
| 253 ASSERT_TRUE(IsValidBasicEvent(event)); | 254 ASSERT_TRUE(IsValidBasicEvent(event)); |
| 254 ASSERT_EQ(rtclog::Event::RTCP_EVENT, event.type()); | 255 ASSERT_EQ(rtclog::Event::RTCP_EVENT, event.type()); |
| 255 const rtclog::RtcpPacket& rtcp_packet = event.rtcp_packet(); | 256 const rtclog::RtcpPacket& rtcp_packet = event.rtcp_packet(); |
| 256 ASSERT_TRUE(rtcp_packet.has_incoming()); | 257 ASSERT_TRUE(rtcp_packet.has_incoming()); |
| 257 EXPECT_EQ(incoming, rtcp_packet.incoming()); | 258 EXPECT_EQ(direction == kIncomingPacket, rtcp_packet.incoming()); |
| 258 ASSERT_TRUE(rtcp_packet.has_type()); | 259 ASSERT_TRUE(rtcp_packet.has_type()); |
| 259 EXPECT_EQ(media_type, GetRuntimeMediaType(rtcp_packet.type())); | 260 EXPECT_EQ(media_type, GetRuntimeMediaType(rtcp_packet.type())); |
| 260 ASSERT_TRUE(rtcp_packet.has_packet_data()); | 261 ASSERT_TRUE(rtcp_packet.has_packet_data()); |
| 261 ASSERT_EQ(total_size, rtcp_packet.packet_data().size()); | 262 ASSERT_EQ(total_size, rtcp_packet.packet_data().size()); |
| 262 for (size_t i = 0; i < total_size; i++) { | 263 for (size_t i = 0; i < total_size; i++) { |
| 263 EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.packet_data()[i])); | 264 EXPECT_EQ(packet[i], static_cast<uint8_t>(rtcp_packet.packet_data()[i])); |
| 264 } | 265 } |
| 265 } | 266 } |
| 266 | 267 |
| 267 void VerifyPlayoutEvent(const rtclog::Event& event, uint32_t ssrc) { | 268 void VerifyPlayoutEvent(const rtclog::Event& event, uint32_t ssrc) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 285 EXPECT_EQ(fraction_loss, bwe_event.fraction_loss()); | 286 EXPECT_EQ(fraction_loss, bwe_event.fraction_loss()); |
| 286 ASSERT_TRUE(bwe_event.has_total_packets()); | 287 ASSERT_TRUE(bwe_event.has_total_packets()); |
| 287 EXPECT_EQ(total_packets, bwe_event.total_packets()); | 288 EXPECT_EQ(total_packets, bwe_event.total_packets()); |
| 288 } | 289 } |
| 289 | 290 |
| 290 void VerifyLogStartEvent(const rtclog::Event& event) { | 291 void VerifyLogStartEvent(const rtclog::Event& event) { |
| 291 ASSERT_TRUE(IsValidBasicEvent(event)); | 292 ASSERT_TRUE(IsValidBasicEvent(event)); |
| 292 EXPECT_EQ(rtclog::Event::LOG_START, event.type()); | 293 EXPECT_EQ(rtclog::Event::LOG_START, event.type()); |
| 293 } | 294 } |
| 294 | 295 |
| 296 void VerifyLogEndEvent(const rtclog::Event& event) { |
| 297 ASSERT_TRUE(IsValidBasicEvent(event)); |
| 298 EXPECT_EQ(rtclog::Event::LOG_END, event.type()); |
| 299 } |
| 300 |
| 295 /* | 301 /* |
| 296 * Bit number i of extension_bitvector is set to indicate the | 302 * Bit number i of extension_bitvector is set to indicate the |
| 297 * presence of extension number i from kExtensionTypes / kExtensionNames. | 303 * presence of extension number i from kExtensionTypes / kExtensionNames. |
| 298 * The least significant bit extension_bitvector has number 0. | 304 * The least significant bit extension_bitvector has number 0. |
| 299 */ | 305 */ |
| 300 size_t GenerateRtpPacket(uint32_t extensions_bitvector, | 306 size_t GenerateRtpPacket(uint32_t extensions_bitvector, |
| 301 uint32_t csrcs_count, | 307 uint32_t csrcs_count, |
| 302 uint8_t* packet, | 308 uint8_t* packet, |
| 303 size_t packet_size, | 309 size_t packet_size, |
| 304 Random* prng) { | 310 Random* prng) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 471 |
| 466 // Find the name of the current test, in order to use it as a temporary | 472 // Find the name of the current test, in order to use it as a temporary |
| 467 // filename. | 473 // filename. |
| 468 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 474 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
| 469 const std::string temp_filename = | 475 const std::string temp_filename = |
| 470 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 476 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
| 471 | 477 |
| 472 // When log_dumper goes out of scope, it causes the log file to be flushed | 478 // When log_dumper goes out of scope, it causes the log file to be flushed |
| 473 // to disk. | 479 // to disk. |
| 474 { | 480 { |
| 475 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); | 481 SimulatedClock fake_clock(prng.Rand<uint32_t>()); |
| 482 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(&fake_clock)); |
| 476 log_dumper->LogVideoReceiveStreamConfig(receiver_config); | 483 log_dumper->LogVideoReceiveStreamConfig(receiver_config); |
| 484 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 477 log_dumper->LogVideoSendStreamConfig(sender_config); | 485 log_dumper->LogVideoSendStreamConfig(sender_config); |
| 486 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 478 size_t rtcp_index = 1; | 487 size_t rtcp_index = 1; |
| 479 size_t playout_index = 1; | 488 size_t playout_index = 1; |
| 480 size_t bwe_loss_index = 1; | 489 size_t bwe_loss_index = 1; |
| 481 for (size_t i = 1; i <= rtp_count; i++) { | 490 for (size_t i = 1; i <= rtp_count; i++) { |
| 482 log_dumper->LogRtpHeader( | 491 log_dumper->LogRtpHeader( |
| 483 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, | 492 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, |
| 484 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 493 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
| 485 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); | 494 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); |
| 495 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 486 if (i * rtcp_count >= rtcp_index * rtp_count) { | 496 if (i * rtcp_count >= rtcp_index * rtp_count) { |
| 487 log_dumper->LogRtcpPacket( | 497 log_dumper->LogRtcpPacket( |
| 488 (rtcp_index % 2 == 0) ? kIncomingPacket : kOutgoingPacket, | 498 (rtcp_index % 2 == 0) ? kIncomingPacket : kOutgoingPacket, |
| 489 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, | 499 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, |
| 490 rtcp_packets[rtcp_index - 1].data(), | 500 rtcp_packets[rtcp_index - 1].data(), |
| 491 rtcp_packets[rtcp_index - 1].size()); | 501 rtcp_packets[rtcp_index - 1].size()); |
| 492 rtcp_index++; | 502 rtcp_index++; |
| 503 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 493 } | 504 } |
| 494 if (i * playout_count >= playout_index * rtp_count) { | 505 if (i * playout_count >= playout_index * rtp_count) { |
| 495 log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]); | 506 log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]); |
| 496 playout_index++; | 507 playout_index++; |
| 508 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 497 } | 509 } |
| 498 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { | 510 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { |
| 499 log_dumper->LogBwePacketLossEvent( | 511 log_dumper->LogBwePacketLossEvent( |
| 500 bwe_loss_updates[bwe_loss_index - 1].first, | 512 bwe_loss_updates[bwe_loss_index - 1].first, |
| 501 bwe_loss_updates[bwe_loss_index - 1].second, i); | 513 bwe_loss_updates[bwe_loss_index - 1].second, i); |
| 502 bwe_loss_index++; | 514 bwe_loss_index++; |
| 515 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 503 } | 516 } |
| 504 if (i == rtp_count / 2) { | 517 if (i == rtp_count / 2) { |
| 505 log_dumper->StartLogging(temp_filename, 10000000); | 518 log_dumper->StartLogging(temp_filename, 10000000); |
| 519 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 506 } | 520 } |
| 507 } | 521 } |
| 522 log_dumper->StopLogging(); |
| 508 } | 523 } |
| 509 | 524 |
| 510 // Read the generated file from disk. | 525 // Read the generated file from disk. |
| 511 rtclog::EventStream parsed_stream; | 526 rtclog::EventStream parsed_stream; |
| 512 | 527 |
| 513 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | 528 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); |
| 514 | 529 |
| 515 // Verify that what we read back from the event log is the same as | 530 // Verify that what we read back from the event log is the same as |
| 516 // what we wrote down. For RTCP we log the full packets, but for | 531 // what we wrote down. For RTCP we log the full packets, but for |
| 517 // RTP we should only log the header. | 532 // RTP we should only log the header. |
| 518 const int event_count = config_count + playout_count + bwe_loss_count + | 533 const int event_count = config_count + playout_count + bwe_loss_count + |
| 519 rtcp_count + rtp_count + 1; | 534 rtcp_count + rtp_count + 2; |
| 535 EXPECT_GE(1000, event_count); // The events must fit in the message queue. |
| 520 EXPECT_EQ(event_count, parsed_stream.stream_size()); | 536 EXPECT_EQ(event_count, parsed_stream.stream_size()); |
| 521 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); | 537 if (event_count != parsed_stream.stream_size()) { |
| 522 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); | 538 // Print the expected and actual event types for easier debugging. |
| 523 size_t event_index = config_count; | 539 std::map<int, size_t> actual_event_counts; |
| 540 for (size_t i = 0; i < static_cast<size_t>(parsed_stream.stream_size()); |
| 541 i++) { |
| 542 actual_event_counts[parsed_stream.stream(i).type()]++; |
| 543 } |
| 544 printf("Actual events: "); |
| 545 for (auto kv : actual_event_counts) { |
| 546 printf("%d_count = %zu, ", kv.first, kv.second); |
| 547 } |
| 548 printf("\n"); |
| 549 for (size_t i = 0; i < static_cast<size_t>(parsed_stream.stream_size()); |
| 550 i++) { |
| 551 printf("%4d ", parsed_stream.stream(i).type()); |
| 552 } |
| 553 printf("\n"); |
| 554 printf( |
| 555 "Expected events: rtp_count = %zu, rtcp_count = %zu," |
| 556 "playout_count = %zu, bwe_loss_count = %zu\n", |
| 557 rtp_count, rtcp_count, playout_count, bwe_loss_count); |
| 558 size_t rtcp_index = 1, playout_index = 1, bwe_loss_index = 1; |
| 559 printf("strt cfg cfg "); |
| 560 for (size_t i = 1; i <= rtp_count; i++) { |
| 561 printf(" rtp "); |
| 562 if (i * rtcp_count >= rtcp_index * rtp_count) { |
| 563 printf("rtcp "); |
| 564 rtcp_index++; |
| 565 } |
| 566 if (i * playout_count >= playout_index * rtp_count) { |
| 567 printf("play "); |
| 568 playout_index++; |
| 569 } |
| 570 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { |
| 571 printf("loss "); |
| 572 bwe_loss_index++; |
| 573 } |
| 574 } |
| 575 printf("\n"); |
| 576 } |
| 577 VerifyLogStartEvent(parsed_stream.stream(0)); |
| 578 VerifyReceiveStreamConfig(parsed_stream.stream(1), receiver_config); |
| 579 VerifySendStreamConfig(parsed_stream.stream(2), sender_config); |
| 580 size_t event_index = config_count + 1; |
| 524 size_t rtcp_index = 1; | 581 size_t rtcp_index = 1; |
| 525 size_t playout_index = 1; | 582 size_t playout_index = 1; |
| 526 size_t bwe_loss_index = 1; | 583 size_t bwe_loss_index = 1; |
| 527 for (size_t i = 1; i <= rtp_count; i++) { | 584 for (size_t i = 1; i <= rtp_count; i++) { |
| 528 VerifyRtpEvent(parsed_stream.stream(event_index), | 585 VerifyRtpEvent(parsed_stream.stream(event_index), |
| 529 (i % 2 == 0), // Every second packet is incoming. | 586 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, |
| 530 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 587 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
| 531 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1], | 588 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1], |
| 532 rtp_packets[i - 1].size()); | 589 rtp_packets[i - 1].size()); |
| 533 event_index++; | 590 event_index++; |
| 534 if (i * rtcp_count >= rtcp_index * rtp_count) { | 591 if (i * rtcp_count >= rtcp_index * rtp_count) { |
| 535 VerifyRtcpEvent(parsed_stream.stream(event_index), | 592 VerifyRtcpEvent(parsed_stream.stream(event_index), |
| 536 rtcp_index % 2 == 0, // Every second packet is incoming. | 593 (rtcp_index % 2 == 0) ? kIncomingPacket : kOutgoingPacket, |
| 537 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, | 594 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, |
| 538 rtcp_packets[rtcp_index - 1].data(), | 595 rtcp_packets[rtcp_index - 1].data(), |
| 539 rtcp_packets[rtcp_index - 1].size()); | 596 rtcp_packets[rtcp_index - 1].size()); |
| 540 event_index++; | 597 event_index++; |
| 541 rtcp_index++; | 598 rtcp_index++; |
| 542 } | 599 } |
| 543 if (i * playout_count >= playout_index * rtp_count) { | 600 if (i * playout_count >= playout_index * rtp_count) { |
| 544 VerifyPlayoutEvent(parsed_stream.stream(event_index), | 601 VerifyPlayoutEvent(parsed_stream.stream(event_index), |
| 545 playout_ssrcs[playout_index - 1]); | 602 playout_ssrcs[playout_index - 1]); |
| 546 event_index++; | 603 event_index++; |
| 547 playout_index++; | 604 playout_index++; |
| 548 } | 605 } |
| 549 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { | 606 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { |
| 550 VerifyBweLossEvent(parsed_stream.stream(event_index), | 607 VerifyBweLossEvent(parsed_stream.stream(event_index), |
| 551 bwe_loss_updates[bwe_loss_index - 1].first, | 608 bwe_loss_updates[bwe_loss_index - 1].first, |
| 552 bwe_loss_updates[bwe_loss_index - 1].second, i); | 609 bwe_loss_updates[bwe_loss_index - 1].second, i); |
| 553 event_index++; | 610 event_index++; |
| 554 bwe_loss_index++; | 611 bwe_loss_index++; |
| 555 } | 612 } |
| 556 if (i == rtp_count / 2) { | |
| 557 VerifyLogStartEvent(parsed_stream.stream(event_index)); | |
| 558 event_index++; | |
| 559 } | |
| 560 } | 613 } |
| 561 | 614 |
| 562 // Clean up temporary file - can be pretty slow. | 615 // Clean up temporary file - can be pretty slow. |
| 563 remove(temp_filename.c_str()); | 616 remove(temp_filename.c_str()); |
| 564 } | 617 } |
| 565 | 618 |
| 566 TEST(RtcEventLogTest, LogSessionAndReadBack) { | 619 TEST(RtcEventLogTest, LogSessionAndReadBack) { |
| 567 // Log 5 RTP, 2 RTCP, 0 playout events and 0 BWE events | 620 // Log 5 RTP, 2 RTCP, 0 playout events and 0 BWE events |
| 568 // with no header extensions or CSRCS. | 621 // with no header extensions or CSRCS. |
| 569 LogSessionAndReadBack(5, 2, 0, 0, 0, 0, 321); | 622 LogSessionAndReadBack(5, 2, 0, 0, 0, 0, 321); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 589 2 + csrcs_count, // Number of RTCP packets. | 642 2 + csrcs_count, // Number of RTCP packets. |
| 590 3 + csrcs_count, // Number of playout events. | 643 3 + csrcs_count, // Number of playout events. |
| 591 1 + csrcs_count, // Number of BWE loss events. | 644 1 + csrcs_count, // Number of BWE loss events. |
| 592 extensions, // Bit vector choosing extensions. | 645 extensions, // Bit vector choosing extensions. |
| 593 csrcs_count, // Number of contributing sources. | 646 csrcs_count, // Number of contributing sources. |
| 594 extensions * 3 + csrcs_count + 1); // Random seed. | 647 extensions * 3 + csrcs_count + 1); // Random seed. |
| 595 } | 648 } |
| 596 } | 649 } |
| 597 } | 650 } |
| 598 | 651 |
| 599 // Tests that the event queue works correctly, i.e. drops old RTP, RTCP and | 652 TEST(RtcEventLogTest, LogEventAndReadBack) { |
| 600 // debug events, but keeps config events even if they are older than the limit. | 653 Random prng(987654321); |
| 601 void DropOldEvents(uint32_t extensions_bitvector, | |
| 602 uint32_t csrcs_count, | |
| 603 unsigned int random_seed) { | |
| 604 rtc::Buffer old_rtp_packet; | |
| 605 rtc::Buffer recent_rtp_packet; | |
| 606 rtc::Buffer old_rtcp_packet; | |
| 607 rtc::Buffer recent_rtcp_packet; | |
| 608 | 654 |
| 609 VideoReceiveStream::Config receiver_config(nullptr); | 655 // Create one RTP and one RTCP packet containing random data. |
| 610 VideoSendStream::Config sender_config(nullptr); | |
| 611 | |
| 612 Random prng(random_seed); | |
| 613 | |
| 614 // Create two RTP packets containing random data. | |
| 615 size_t packet_size = prng.Rand(1000, 1100); | 656 size_t packet_size = prng.Rand(1000, 1100); |
| 616 old_rtp_packet.SetSize(packet_size); | 657 rtc::Buffer rtp_packet(packet_size); |
| 617 GenerateRtpPacket(extensions_bitvector, csrcs_count, old_rtp_packet.data(), | 658 size_t header_size = |
| 618 packet_size, &prng); | 659 GenerateRtpPacket(0, 0, rtp_packet.data(), packet_size, &prng); |
| 619 packet_size = prng.Rand(1000, 1100); | 660 rtc::Buffer rtcp_packet = GenerateRtcpPacket(&prng); |
| 620 recent_rtp_packet.SetSize(packet_size); | |
| 621 size_t recent_header_size = | |
| 622 GenerateRtpPacket(extensions_bitvector, csrcs_count, | |
| 623 recent_rtp_packet.data(), packet_size, &prng); | |
| 624 | |
| 625 // Create two RTCP packets containing random data. | |
| 626 old_rtcp_packet = GenerateRtcpPacket(&prng); | |
| 627 recent_rtcp_packet = GenerateRtcpPacket(&prng); | |
| 628 | |
| 629 // Create configurations for the video streams. | |
| 630 GenerateVideoReceiveConfig(extensions_bitvector, &receiver_config, &prng); | |
| 631 GenerateVideoSendConfig(extensions_bitvector, &sender_config, &prng); | |
| 632 | 661 |
| 633 // Find the name of the current test, in order to use it as a temporary | 662 // Find the name of the current test, in order to use it as a temporary |
| 634 // filename. | 663 // filename. |
| 635 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 664 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
| 636 const std::string temp_filename = | 665 const std::string temp_filename = |
| 637 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 666 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
| 638 | 667 |
| 639 // The log file will be flushed to disk when the log_dumper goes out of scope. | 668 // Add RTP, start logging, add RTCP and then stop logging |
| 640 { | 669 SimulatedClock fake_clock(prng.Rand<uint32_t>()); |
| 641 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); | 670 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(&fake_clock)); |
| 642 // Reduce the time old events are stored to 50 ms. | 671 |
| 643 log_dumper->SetBufferDuration(50000); | 672 log_dumper->LogRtpHeader(kIncomingPacket, MediaType::VIDEO, rtp_packet.data(), |
| 644 log_dumper->LogVideoReceiveStreamConfig(receiver_config); | 673 rtp_packet.size()); |
| 645 log_dumper->LogVideoSendStreamConfig(sender_config); | 674 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 646 log_dumper->LogRtpHeader(kOutgoingPacket, MediaType::AUDIO, | 675 |
| 647 old_rtp_packet.data(), old_rtp_packet.size()); | 676 log_dumper->StartLogging(temp_filename, 10000000); |
| 648 log_dumper->LogRtcpPacket(kIncomingPacket, MediaType::AUDIO, | 677 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 649 old_rtcp_packet.data(), | 678 |
| 650 old_rtcp_packet.size()); | 679 log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO, |
| 651 // Sleep 55 ms to let old events be removed from the queue. | 680 rtcp_packet.data(), rtcp_packet.size()); |
| 652 rtc::Thread::SleepMs(55); | 681 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); |
| 653 log_dumper->StartLogging(temp_filename, 10000000); | 682 |
| 654 log_dumper->LogRtpHeader(kIncomingPacket, MediaType::VIDEO, | 683 log_dumper->StopLogging(); |
| 655 recent_rtp_packet.data(), | |
| 656 recent_rtp_packet.size()); | |
| 657 log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO, | |
| 658 recent_rtcp_packet.data(), | |
| 659 recent_rtcp_packet.size()); | |
| 660 } | |
| 661 | 684 |
| 662 // Read the generated file from disk. | 685 // Read the generated file from disk. |
| 663 rtclog::EventStream parsed_stream; | 686 rtclog::EventStream parsed_stream; |
| 664 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | 687 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); |
| 665 | 688 |
| 666 // Verify that what we read back from the event log is the same as | 689 // Verify that what we read back from the event log is the same as |
| 667 // what we wrote. Old RTP and RTCP events should have been discarded, | 690 // what we wrote down. |
| 668 // but old configuration events should still be available. | 691 EXPECT_EQ(4, parsed_stream.stream_size()); |
| 669 EXPECT_EQ(5, parsed_stream.stream_size()); | 692 |
| 670 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); | 693 VerifyLogStartEvent(parsed_stream.stream(0)); |
| 671 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); | 694 |
| 672 VerifyLogStartEvent(parsed_stream.stream(2)); | 695 VerifyRtpEvent(parsed_stream.stream(1), kIncomingPacket, MediaType::VIDEO, |
| 673 VerifyRtpEvent(parsed_stream.stream(3), true, MediaType::VIDEO, | 696 rtp_packet.data(), header_size, rtp_packet.size()); |
| 674 recent_rtp_packet.data(), recent_header_size, | 697 |
| 675 recent_rtp_packet.size()); | 698 VerifyRtcpEvent(parsed_stream.stream(2), kOutgoingPacket, MediaType::VIDEO, |
| 676 VerifyRtcpEvent(parsed_stream.stream(4), false, MediaType::VIDEO, | 699 rtcp_packet.data(), rtcp_packet.size()); |
| 677 recent_rtcp_packet.data(), recent_rtcp_packet.size()); | 700 |
| 701 VerifyLogEndEvent(parsed_stream.stream(3)); |
| 678 | 702 |
| 679 // Clean up temporary file - can be pretty slow. | 703 // Clean up temporary file - can be pretty slow. |
| 680 remove(temp_filename.c_str()); | 704 remove(temp_filename.c_str()); |
| 681 } | 705 } |
| 682 | |
| 683 TEST(RtcEventLogTest, DropOldEvents) { | |
| 684 // Enable all header extensions | |
| 685 uint32_t extensions = (1u << kNumExtensions) - 1; | |
| 686 uint32_t csrcs_count = 2; | |
| 687 DropOldEvents(extensions, csrcs_count, 141421356); | |
| 688 DropOldEvents(extensions, csrcs_count, 173205080); | |
| 689 } | |
| 690 | |
| 691 } // namespace webrtc | 706 } // namespace webrtc |
| 692 | 707 |
| 693 #endif // ENABLE_RTC_EVENT_LOG | 708 #endif // ENABLE_RTC_EVENT_LOG |
| OLD | NEW |