OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifdef ENABLE_RTC_EVENT_LOG | 11 #ifdef ENABLE_RTC_EVENT_LOG |
12 | 12 |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include <string> | 14 #include <string> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/base/scoped_ptr.h" | 19 #include "webrtc/base/scoped_ptr.h" |
20 #include "webrtc/base/thread.h" | |
20 #include "webrtc/call.h" | 21 #include "webrtc/call.h" |
21 #include "webrtc/system_wrappers/interface/clock.h" | 22 #include "webrtc/system_wrappers/interface/clock.h" |
22 #include "webrtc/test/test_suite.h" | 23 #include "webrtc/test/test_suite.h" |
23 #include "webrtc/test/testsupport/fileutils.h" | 24 #include "webrtc/test/testsupport/fileutils.h" |
24 #include "webrtc/test/testsupport/gtest_disable.h" | 25 #include "webrtc/test/testsupport/gtest_disable.h" |
25 #include "webrtc/video/rtc_event_log.h" | 26 #include "webrtc/video/rtc_event_log.h" |
26 | 27 |
27 // Files generated at build-time by the protobuf compiler. | 28 // Files generated at build-time by the protobuf compiler. |
28 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 29 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
29 #include "external/webrtc/webrtc/video/rtc_event_log.pb.h" | 30 #include "external/webrtc/webrtc/video/rtc_event_log.pb.h" |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 // Clean up temporary file - can be pretty slow. | 418 // Clean up temporary file - can be pretty slow. |
418 remove(temp_filename.c_str()); | 419 remove(temp_filename.c_str()); |
419 } | 420 } |
420 | 421 |
421 TEST(RtcEventLogTest, LogSessionAndReadBack) { | 422 TEST(RtcEventLogTest, LogSessionAndReadBack) { |
422 LogSessionAndReadBack(5, 321); | 423 LogSessionAndReadBack(5, 321); |
423 LogSessionAndReadBack(8, 3141592653u); | 424 LogSessionAndReadBack(8, 3141592653u); |
424 LogSessionAndReadBack(9, 2718281828u); | 425 LogSessionAndReadBack(9, 2718281828u); |
425 } | 426 } |
426 | 427 |
428 void DropOldEvents(unsigned random_seed) { | |
429 std::vector<uint8_t> old_rtp_packet; | |
430 std::vector<uint8_t> recent_rtp_packet; | |
431 std::vector<uint8_t> old_rtcp_packet; | |
432 std::vector<uint8_t> recent_rtcp_packet; | |
433 | |
434 VideoReceiveStream::Config receiver_config; | |
435 VideoSendStream::Config sender_config; | |
436 | |
437 srand(random_seed); | |
438 | |
439 // Create two RTP packets containing random data. | |
440 const size_t rtp_header_size = 20; | |
441 size_t packet_size = 1000 + rand() % 64; | |
442 old_rtp_packet.reserve(packet_size); | |
443 for (size_t j = 0; j < packet_size; j++) { | |
444 old_rtp_packet.push_back(rand()); | |
445 } | |
446 packet_size = 1000 + rand() % 64; | |
447 recent_rtp_packet.reserve(packet_size); | |
448 for (size_t j = 0; j < packet_size; j++) { | |
449 recent_rtp_packet.push_back(rand()); | |
450 } | |
451 // Create two RTCP packets containing random data. | |
452 packet_size = 1000 + rand() % 64; | |
453 old_rtcp_packet.reserve(packet_size); | |
454 for (size_t j = 0; j < packet_size; j++) { | |
455 old_rtcp_packet.push_back(rand()); | |
456 } | |
457 packet_size = 1000 + rand() % 64; | |
458 recent_rtcp_packet.reserve(packet_size); | |
459 for (size_t j = 0; j < packet_size; j++) { | |
460 recent_rtcp_packet.push_back(rand()); | |
461 } | |
462 // Create configurations for the video streams. | |
463 GenerateVideoReceiveConfig(&receiver_config); | |
464 GenerateVideoSendConfig(&sender_config); | |
465 | |
466 // Find the name of the current test, in order to use it as a temporary | |
467 // filename. | |
468 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | |
469 const std::string temp_filename = | |
470 test::OutputPath() + test_info->test_case_name() + test_info->name(); | |
471 | |
472 // The log file will be flushed to disk when the log_dumper goes out of scope. | |
473 { | |
474 rtc::scoped_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); | |
475 log_dumper->SetBufferDuration(50000); | |
476 log_dumper->LogVideoReceiveStreamConfig(receiver_config); | |
477 log_dumper->LogVideoSendStreamConfig(sender_config); | |
478 log_dumper->LogRtpHeader(false, MediaType::AUDIO, old_rtp_packet.data(), | |
479 rtp_header_size, old_rtp_packet.size()); | |
480 log_dumper->LogRtcpPacket(true, MediaType::AUDIO, old_rtcp_packet.data(), | |
481 old_rtcp_packet.size()); | |
482 rtc::Thread::SleepMs(50); | |
ivoc
2015/08/25 08:03:21
I wonder if the sleep should be a little bit longe
terelius
2015/08/25 16:41:44
On POSIX systems it uses nanosleep() which should
| |
483 log_dumper->StartLogging(temp_filename, 10000000); | |
484 log_dumper->LogRtpHeader(true, MediaType::VIDEO, recent_rtp_packet.data(), | |
485 rtp_header_size, recent_rtp_packet.size()); | |
486 log_dumper->LogRtcpPacket(false, MediaType::VIDEO, | |
487 recent_rtcp_packet.data(), | |
488 recent_rtcp_packet.size()); | |
489 } | |
490 | |
491 // Read the generated file from disk. | |
492 rtclog::EventStream parsed_stream; | |
493 ASSERT_TRUE(RtcEventLog::ParseRtcEventLog(temp_filename, &parsed_stream)); | |
494 | |
495 // Verify the result. | |
496 EXPECT_EQ(5, parsed_stream.stream_size()); | |
497 VerifyReceiveStreamConfig(parsed_stream.stream(0), receiver_config); | |
498 VerifySendStreamConfig(parsed_stream.stream(1), sender_config); | |
499 VerifyLogStartEvent(parsed_stream.stream(2)); | |
500 VerifyRtpEvent(parsed_stream.stream(3), true, MediaType::VIDEO, | |
501 recent_rtp_packet.data(), rtp_header_size, | |
502 recent_rtp_packet.size()); | |
503 VerifyRtcpEvent(parsed_stream.stream(4), false, MediaType::VIDEO, | |
504 recent_rtcp_packet.data(), recent_rtcp_packet.size()); | |
505 | |
506 // Clean up temporary file - can be pretty slow. | |
507 remove(temp_filename.c_str()); | |
508 } | |
509 | |
510 TEST(RtcEventLogTest, DropOldEvents) { | |
511 DropOldEvents(141421356); | |
512 DropOldEvents(173205080); | |
513 } | |
514 | |
427 } // namespace webrtc | 515 } // namespace webrtc |
428 | 516 |
429 #endif // ENABLE_RTC_EVENT_LOG | 517 #endif // ENABLE_RTC_EVENT_LOG |
OLD | NEW |