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 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 #include <string> | 13 #include <string> |
14 #include <utility> | 14 #include <utility> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "webrtc/base/buffer.h" | 17 #include "webrtc/base/buffer.h" |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/fakeclock.h" |
19 #include "webrtc/base/random.h" | 20 #include "webrtc/base/random.h" |
20 #include "webrtc/call/call.h" | 21 #include "webrtc/call/call.h" |
21 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 22 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
22 #include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h" | 23 #include "webrtc/logging/rtc_event_log/rtc_event_log_parser.h" |
23 #include "webrtc/logging/rtc_event_log/rtc_event_log_unittest_helper.h" | 24 #include "webrtc/logging/rtc_event_log/rtc_event_log_unittest_helper.h" |
24 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" | 25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet.h" |
25 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" | 26 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
26 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" | 27 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extension.h" |
27 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" | 28 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
28 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" | 29 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h" |
29 #include "webrtc/system_wrappers/include/clock.h" | |
30 #include "webrtc/test/gtest.h" | 30 #include "webrtc/test/gtest.h" |
31 #include "webrtc/test/testsupport/fileutils.h" | 31 #include "webrtc/test/testsupport/fileutils.h" |
32 | 32 |
33 // Files generated at build-time by the protobuf compiler. | 33 // Files generated at build-time by the protobuf compiler. |
34 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD | 34 #ifdef WEBRTC_ANDROID_PLATFORM_BUILD |
35 #include "external/webrtc/webrtc/logging/rtc_event_log/rtc_event_log.pb.h" | 35 #include "external/webrtc/webrtc/logging/rtc_event_log/rtc_event_log.pb.h" |
36 #else | 36 #else |
37 #include "webrtc/logging/rtc_event_log/rtc_event_log.pb.h" | 37 #include "webrtc/logging/rtc_event_log/rtc_event_log.pb.h" |
38 #endif | 38 #endif |
39 | 39 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 | 283 |
284 // Find the name of the current test, in order to use it as a temporary | 284 // Find the name of the current test, in order to use it as a temporary |
285 // filename. | 285 // filename. |
286 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 286 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
287 const std::string temp_filename = | 287 const std::string temp_filename = |
288 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 288 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
289 | 289 |
290 // When log_dumper goes out of scope, it causes the log file to be flushed | 290 // When log_dumper goes out of scope, it causes the log file to be flushed |
291 // to disk. | 291 // to disk. |
292 { | 292 { |
293 SimulatedClock fake_clock(prng.Rand<uint32_t>()); | 293 rtc::ScopedFakeClock fake_clock; |
294 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(&fake_clock)); | 294 fake_clock.SetTimeMicros(prng.Rand<uint32_t>()); |
| 295 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); |
295 log_dumper->LogVideoReceiveStreamConfig(receiver_config); | 296 log_dumper->LogVideoReceiveStreamConfig(receiver_config); |
296 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 297 fake_clock.AdvanceTimeMicros(prng.Rand(1, 1000)); |
297 log_dumper->LogVideoSendStreamConfig(sender_config); | 298 log_dumper->LogVideoSendStreamConfig(sender_config); |
298 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 299 fake_clock.AdvanceTimeMicros(prng.Rand(1, 1000)); |
299 size_t rtcp_index = 1; | 300 size_t rtcp_index = 1; |
300 size_t playout_index = 1; | 301 size_t playout_index = 1; |
301 size_t bwe_loss_index = 1; | 302 size_t bwe_loss_index = 1; |
302 for (size_t i = 1; i <= rtp_count; i++) { | 303 for (size_t i = 1; i <= rtp_count; i++) { |
303 log_dumper->LogRtpHeader( | 304 log_dumper->LogRtpHeader( |
304 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, | 305 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, |
305 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 306 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
306 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); | 307 rtp_packets[i - 1].data(), rtp_packets[i - 1].size()); |
307 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 308 fake_clock.AdvanceTimeMicros(prng.Rand(1, 1000)); |
308 if (i * rtcp_count >= rtcp_index * rtp_count) { | 309 if (i * rtcp_count >= rtcp_index * rtp_count) { |
309 log_dumper->LogRtcpPacket( | 310 log_dumper->LogRtcpPacket( |
310 (rtcp_index % 2 == 0) ? kIncomingPacket : kOutgoingPacket, | 311 (rtcp_index % 2 == 0) ? kIncomingPacket : kOutgoingPacket, |
311 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, | 312 rtcp_index % 3 == 0 ? MediaType::AUDIO : MediaType::VIDEO, |
312 rtcp_packets[rtcp_index - 1].data(), | 313 rtcp_packets[rtcp_index - 1].data(), |
313 rtcp_packets[rtcp_index - 1].size()); | 314 rtcp_packets[rtcp_index - 1].size()); |
314 rtcp_index++; | 315 rtcp_index++; |
315 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 316 fake_clock.AdvanceTimeMicros(prng.Rand(1, 1000)); |
316 } | 317 } |
317 if (i * playout_count >= playout_index * rtp_count) { | 318 if (i * playout_count >= playout_index * rtp_count) { |
318 log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]); | 319 log_dumper->LogAudioPlayout(playout_ssrcs[playout_index - 1]); |
319 playout_index++; | 320 playout_index++; |
320 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 321 fake_clock.AdvanceTimeMicros(prng.Rand(1, 1000)); |
321 } | 322 } |
322 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { | 323 if (i * bwe_loss_count >= bwe_loss_index * rtp_count) { |
323 log_dumper->LogBwePacketLossEvent( | 324 log_dumper->LogBwePacketLossEvent( |
324 bwe_loss_updates[bwe_loss_index - 1].first, | 325 bwe_loss_updates[bwe_loss_index - 1].first, |
325 bwe_loss_updates[bwe_loss_index - 1].second, i); | 326 bwe_loss_updates[bwe_loss_index - 1].second, i); |
326 bwe_loss_index++; | 327 bwe_loss_index++; |
327 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 328 fake_clock.AdvanceTimeMicros(prng.Rand(1, 1000)); |
328 } | 329 } |
329 if (i == rtp_count / 2) { | 330 if (i == rtp_count / 2) { |
330 log_dumper->StartLogging(temp_filename, 10000000); | 331 log_dumper->StartLogging(temp_filename, 10000000); |
331 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 332 fake_clock.AdvanceTimeMicros(prng.Rand(1, 1000)); |
332 } | 333 } |
333 } | 334 } |
334 log_dumper->StopLogging(); | 335 log_dumper->StopLogging(); |
335 } | 336 } |
336 | 337 |
337 // Read the generated file from disk. | 338 // Read the generated file from disk. |
338 ParsedRtcEventLog parsed_log; | 339 ParsedRtcEventLog parsed_log; |
339 | 340 |
340 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); | 341 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); |
341 | 342 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 GenerateRtpPacket(nullptr, 0, packet_size, &prng); | 440 GenerateRtpPacket(nullptr, 0, packet_size, &prng); |
440 rtc::Buffer rtcp_packet = GenerateRtcpPacket(&prng); | 441 rtc::Buffer rtcp_packet = GenerateRtcpPacket(&prng); |
441 | 442 |
442 // Find the name of the current test, in order to use it as a temporary | 443 // Find the name of the current test, in order to use it as a temporary |
443 // filename. | 444 // filename. |
444 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 445 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
445 const std::string temp_filename = | 446 const std::string temp_filename = |
446 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 447 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
447 | 448 |
448 // Add RTP, start logging, add RTCP and then stop logging | 449 // Add RTP, start logging, add RTCP and then stop logging |
449 SimulatedClock fake_clock(prng.Rand<uint32_t>()); | 450 rtc::ScopedFakeClock fake_clock; |
450 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(&fake_clock)); | 451 fake_clock.SetTimeMicros(prng.Rand<uint32_t>()); |
| 452 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); |
451 | 453 |
452 log_dumper->LogRtpHeader(kIncomingPacket, MediaType::VIDEO, rtp_packet.data(), | 454 log_dumper->LogRtpHeader(kIncomingPacket, MediaType::VIDEO, rtp_packet.data(), |
453 rtp_packet.size()); | 455 rtp_packet.size()); |
454 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 456 fake_clock.AdvanceTimeMicros(prng.Rand(1, 1000)); |
455 | 457 |
456 log_dumper->StartLogging(temp_filename, 10000000); | 458 log_dumper->StartLogging(temp_filename, 10000000); |
457 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 459 fake_clock.AdvanceTimeMicros(prng.Rand(1, 1000)); |
458 | 460 |
459 log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO, | 461 log_dumper->LogRtcpPacket(kOutgoingPacket, MediaType::VIDEO, |
460 rtcp_packet.data(), rtcp_packet.size()); | 462 rtcp_packet.data(), rtcp_packet.size()); |
461 fake_clock.AdvanceTimeMicroseconds(prng.Rand(1, 1000)); | 463 fake_clock.AdvanceTimeMicros(prng.Rand(1, 1000)); |
462 | 464 |
463 log_dumper->StopLogging(); | 465 log_dumper->StopLogging(); |
464 | 466 |
465 // Read the generated file from disk. | 467 // Read the generated file from disk. |
466 ParsedRtcEventLog parsed_log; | 468 ParsedRtcEventLog parsed_log; |
467 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); | 469 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); |
468 | 470 |
469 // Verify that what we read back from the event log is the same as | 471 // Verify that what we read back from the event log is the same as |
470 // what we wrote down. | 472 // what we wrote down. |
471 EXPECT_EQ(4u, parsed_log.GetNumberOfEvents()); | 473 EXPECT_EQ(4u, parsed_log.GetNumberOfEvents()); |
(...skipping 28 matching lines...) Expand all Loading... |
500 // filename. | 502 // filename. |
501 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); | 503 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
502 const std::string temp_filename = | 504 const std::string temp_filename = |
503 test::OutputPath() + test_info->test_case_name() + test_info->name(); | 505 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
504 | 506 |
505 // Use all extensions. | 507 // Use all extensions. |
506 uint32_t extensions_bitvector = (1u << kNumExtensions) - 1; | 508 uint32_t extensions_bitvector = (1u << kNumExtensions) - 1; |
507 GenerateConfig(extensions_bitvector); | 509 GenerateConfig(extensions_bitvector); |
508 | 510 |
509 // Log a single config event and stop logging. | 511 // Log a single config event and stop logging. |
510 SimulatedClock fake_clock(prng.Rand<uint32_t>()); | 512 rtc::ScopedFakeClock fake_clock; |
511 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(&fake_clock)); | 513 fake_clock.SetTimeMicros(prng.Rand<uint32_t>()); |
| 514 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create()); |
512 | 515 |
513 log_dumper->StartLogging(temp_filename, 10000000); | 516 log_dumper->StartLogging(temp_filename, 10000000); |
514 LogConfig(log_dumper.get()); | 517 LogConfig(log_dumper.get()); |
515 log_dumper->StopLogging(); | 518 log_dumper->StopLogging(); |
516 | 519 |
517 // Read the generated file from disk. | 520 // Read the generated file from disk. |
518 ParsedRtcEventLog parsed_log; | 521 ParsedRtcEventLog parsed_log; |
519 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); | 522 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); |
520 | 523 |
521 // Check the generated number of events. | 524 // Check the generated number of events. |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 TEST(RtcEventLogTest, LogVideoReceiveConfig) { | 617 TEST(RtcEventLogTest, LogVideoReceiveConfig) { |
615 VideoReceiveConfigReadWriteTest test; | 618 VideoReceiveConfigReadWriteTest test; |
616 test.DoTest(); | 619 test.DoTest(); |
617 } | 620 } |
618 | 621 |
619 TEST(RtcEventLogTest, LogVideoSendConfig) { | 622 TEST(RtcEventLogTest, LogVideoSendConfig) { |
620 VideoSendConfigReadWriteTest test; | 623 VideoSendConfigReadWriteTest test; |
621 test.DoTest(); | 624 test.DoTest(); |
622 } | 625 } |
623 } // namespace webrtc | 626 } // namespace webrtc |
OLD | NEW |