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

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

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

Powered by Google App Engine
This is Rietveld 408576698