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

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: Fix compile errors 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].data(), 500 rtcp_packets[rtcp_index - 1].data(),
492 rtcp_packets[rtcp_index - 1].size()); 501 rtcp_packets[rtcp_index - 1].size());
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 printf(
524 size_t event_index = config_count; 538 "rtp_count = %zu, rtcp_count = %zu, playout_count = %zu, bwe_loss_count "
539 "= %zu\n",
540 rtp_count, rtcp_count, playout_count, bwe_loss_count);
541 if (event_count != parsed_stream.stream_size()) {
542 for (size_t i = 0; i < static_cast<size_t>(parsed_stream.stream_size());
543 i++) {
544 printf("%4d ", parsed_stream.stream(i).type());
545 }
546 printf("\n");
547 size_t rtcp_index = 1, playout_index = 1, bwe_loss_index = 1;
548 printf("strt cfg cfg ");
549 for (size_t i = 1; i <= rtp_count; i++) {
550 printf(" rtp ");
551 if (i * rtcp_count >= rtcp_index++ * rtp_count)
552 printf("rtcp ");
553 if (i * playout_count >= playout_index++ * rtp_count)
554 printf("play ");
555 if (i * bwe_loss_count >= bwe_loss_index++ * rtp_count)
556 printf("loss ");
557 }
558 printf("\n");
559 }
560 VerifyLogStartEvent(parsed_stream.stream(0));
561 VerifyReceiveStreamConfig(parsed_stream.stream(1), receiver_config);
562 VerifySendStreamConfig(parsed_stream.stream(2), sender_config);
563 size_t event_index = config_count + 1;
525 size_t rtcp_index = 1; 564 size_t rtcp_index = 1;
526 size_t playout_index = 1; 565 size_t playout_index = 1;
527 size_t bwe_loss_index = 1; 566 size_t bwe_loss_index = 1;
528 for (size_t i = 1; i <= rtp_count; i++) { 567 for (size_t i = 1; i <= rtp_count; i++) {
529 VerifyRtpEvent(parsed_stream.stream(event_index), 568 VerifyRtpEvent(parsed_stream.stream(event_index),
530 (i % 2 == 0), // Every second packet is incoming. 569 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket,
531 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, 570 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO,
532 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1], 571 rtp_packets[i - 1].data(), rtp_header_sizes[i - 1],
533 rtp_packets[i - 1].size()); 572 rtp_packets[i - 1].size());
534 event_index++; 573 event_index++;
535 if (i * rtcp_count >= rtcp_index * rtp_count) { 574 if (i * rtcp_count >= rtcp_index * rtp_count) {
536 VerifyRtcpEvent(parsed_stream.stream(event_index), 575 VerifyRtcpEvent(parsed_stream.stream(event_index),
537 rtcp_index % 2 == 0, // Every second packet is incoming. 576 (rtcp_index % 2 == 0) ? kIncomingPacket : kOutgoingPacket,
538 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, 577 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO,
539 rtcp_packets[rtcp_index - 1].data(), 578 rtcp_packets[rtcp_index - 1].data(),
540 rtcp_packets[rtcp_index - 1].size()); 579 rtcp_packets[rtcp_index - 1].size());
541 event_index++; 580 event_index++;
542 rtcp_index++; 581 rtcp_index++;
543 } 582 }
544 if (i * playout_count >= playout_index * rtp_count) { 583 if (i * playout_count >= playout_index * rtp_count) {
545 VerifyPlayoutEvent(parsed_stream.stream(event_index), 584 VerifyPlayoutEvent(parsed_stream.stream(event_index),
546 playout_ssrcs[playout_index - 1]); 585 playout_ssrcs[playout_index - 1]);
547 event_index++; 586 event_index++;
548 playout_index++; 587 playout_index++;
549 } 588 }
550 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { 589 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) {
551 VerifyBweLossEvent(parsed_stream.stream(event_index), 590 VerifyBweLossEvent(parsed_stream.stream(event_index),
552 bwe_loss_updates[bwe_loss_index - 1].first, 591 bwe_loss_updates[bwe_loss_index - 1].first,
553 bwe_loss_updates[bwe_loss_index - 1].second, i); 592 bwe_loss_updates[bwe_loss_index - 1].second, i);
554 event_index++; 593 event_index++;
555 bwe_loss_index++; 594 bwe_loss_index++;
556 } 595 }
557 if (i == rtp_count / 2) {
558 VerifyLogStartEvent(parsed_stream.stream(event_index));
559 event_index++;
560 }
561 } 596 }
562 597
563 // Clean up temporary file - can be pretty slow. 598 // Clean up temporary file - can be pretty slow.
564 remove(temp_filename.c_str()); 599 remove(temp_filename.c_str());
565 } 600 }
566 601
567 TEST(RtcEventLogTest, LogSessionAndReadBack) { 602 TEST(RtcEventLogTest, LogSessionAndReadBack) {
568 // Log 5 RTP, 2 RTCP, 0 playout events and 0 BWE events 603 // Log 5 RTP, 2 RTCP, 0 playout events and 0 BWE events
569 // with no header extensions or CSRCS. 604 // with no header extensions or CSRCS.
570 LogSessionAndReadBack(5, 2, 0, 0, 0, 0, 321); 605 LogSessionAndReadBack(5, 2, 0, 0, 0, 0, 321);
(...skipping 19 matching lines...) Expand all
590 2 + csrcs_count, // Number of RTCP packets. 625 2 + csrcs_count, // Number of RTCP packets.
591 3 + csrcs_count, // Number of playout events. 626 3 + csrcs_count, // Number of playout events.
592 1 + csrcs_count, // Number of BWE loss events. 627 1 + csrcs_count, // Number of BWE loss events.
593 extensions, // Bit vector choosing extensions. 628 extensions, // Bit vector choosing extensions.
594 csrcs_count, // Number of contributing sources. 629 csrcs_count, // Number of contributing sources.
595 extensions * 3 + csrcs_count + 1); // Random seed. 630 extensions * 3 + csrcs_count + 1); // Random seed.
596 } 631 }
597 } 632 }
598 } 633 }
599 634
600 // Tests that the event queue works correctly, i.e. drops old RTP, RTCP and 635 TEST(RtcEventLogTest, LogEventAndReadBack) {
601 // debug events, but keeps config events even if they are older than the limit. 636 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::Buffer old_rtcp_packet;
608 rtc::Buffer recent_rtcp_packet;
609 637
610 VideoReceiveStream::Config receiver_config(nullptr); 638 // 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); 639 size_t packet_size = prng.Rand(1000, 1100);
617 old_rtp_packet.SetSize(packet_size); 640 rtc::Buffer rtp_packet(packet_size);
618 GenerateRtpPacket(extensions_bitvector, csrcs_count, old_rtp_packet.data(), 641 size_t header_size =
619 packet_size, &prng); 642 GenerateRtpPacket(0, 0, rtp_packet.data(), packet_size, &prng);
620 packet_size = prng.Rand(1000, 1100); 643 rtc::Buffer 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 644
634 // Find the name of the current test, in order to use it as a temporary 645 // Find the name of the current test, in order to use it as a temporary
635 // filename. 646 // filename.
636 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); 647 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info();
637 const std::string temp_filename = 648 const std::string temp_filename =
638 test::OutputPath() + test_info->test_case_name() + test_info->name(); 649 test::OutputPath() + test_info->test_case_name() + test_info->name();
639 650
640 // The log file will be flushed to disk when the log_dumper goes out of scope. 651 // Add RTP, start logging, add RTCP and then stop logging
641 { 652 SimulatedClock fake_clock(prng.Rand<uint32_t>());
642 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); 653 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(&fake_clock));
643 // Reduce the time old events are stored to 50 ms. 654
644 log_dumper->SetBufferDuration(50000); 655 log_dumper->LogRtpHeader(kIncomingPacket, MediaType::VIDEO, rtp_packet.data(),
645 log_dumper->LogVideoReceiveStreamConfig(receiver_config); 656 rtp_packet.size());
646 log_dumper->LogVideoSendStreamConfig(sender_config); 657 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
647 log_dumper->LogRtpHeader(kOutgoingPacket, MediaType::AUDIO, 658
648 old_rtp_packet.data(), old_rtp_packet.size()); 659 log_dumper->StartLogging(temp_filename, 10000000);
649 log_dumper->LogRtcpPacket(kIncomingPacket, MediaType::AUDIO, 660 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
650 old_rtcp_packet.data(), 661
651 old_rtcp_packet.size()); 662 log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO,
652 // Sleep 55 ms to let old events be removed from the queue. 663 rtcp_packet.data(), rtcp_packet.size());
653 rtc::Thread::SleepMs(55); 664 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000));
654 log_dumper->StartLogging(temp_filename, 10000000); 665
655 log_dumper->LogRtpHeader(kIncomingPacket, MediaType::VIDEO, 666 log_dumper->StopLogging();
656 recent_rtp_packet.data(),
657 recent_rtp_packet.size());
658 log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO,
659 recent_rtcp_packet.data(),
660 recent_rtcp_packet.size());
661 }
662 667
663 // Read the generated file from disk. 668 // Read the generated file from disk.
664 rtclog::EventStream parsed_stream; 669 rtclog::EventStream parsed_stream;
665 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); 670 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream));
666 671
667 // Verify that what we read back from the event log is the same as 672 // 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, 673 // what we wrote down.
669 // but old configuration events should still be available. 674 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.data(), recent_rtcp_packet.size());
679 675
680 // Clean up temporary file - can be pretty slow. 676 VerifyLogStartEvent(parsed_stream.stream(0));
681 remove(temp_filename.c_str()); 677
678 VerifyRtpEvent(parsed_stream.stream(1), kIncomingPacket, MediaType::VIDEO,
679 rtp_packet.data(), header_size, rtp_packet.size());
680
681 VerifyRtcpEvent(parsed_stream.stream(2), kOutgoingPacket, MediaType::VIDEO,
682 rtcp_packet.data(), rtcp_packet.size());
683
684 VerifyLogEndEvent(parsed_stream.stream(3));
682 } 685 }
683
684 TEST(RtcEventLogTest, DropOldEvents) {
685 // Enable all header extensions
686 uint32_t extensions = (1u << kNumExtensions) - 1;
687 uint32_t csrcs_count = 2;
688 DropOldEvents(extensions, csrcs_count, 141421356);
689 DropOldEvents(extensions, csrcs_count, 173205080);
690 }
691
692 } // namespace webrtc 686 } // namespace webrtc
693 687
694 #endif // ENABLE_RTC_EVENT_LOG 688 #endif // ENABLE_RTC_EVENT_LOG
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698