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 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 config->rtp.rtx.payload_type = prng->Rand(0, 127); | 194 config->rtp.rtx.payload_type = prng->Rand(0, 127); |
195 // Add header extensions. | 195 // Add header extensions. |
196 for (unsigned i = 0; i < kNumExtensions; i++) { | 196 for (unsigned i = 0; i < kNumExtensions; i++) { |
197 if (extensions_bitvector & (1u << i)) { | 197 if (extensions_bitvector & (1u << i)) { |
198 config->rtp.extensions.push_back( | 198 config->rtp.extensions.push_back( |
199 RtpExtension(kExtensionNames[i], prng->Rand<int>())); | 199 RtpExtension(kExtensionNames[i], prng->Rand<int>())); |
200 } | 200 } |
201 } | 201 } |
202 } | 202 } |
203 | 203 |
| 204 void GenerateAudioReceiveConfig(uint32_t extensions_bitvector, |
| 205 AudioReceiveStream::Config* config, |
| 206 Random* prng) { |
| 207 // Add SSRCs for the stream. |
| 208 config->rtp.remote_ssrc = prng->Rand<uint32_t>(); |
| 209 config->rtp.local_ssrc = prng->Rand<uint32_t>(); |
| 210 // Add header extensions. |
| 211 for (unsigned i = 0; i < kNumExtensions; i++) { |
| 212 if (extensions_bitvector & (1u << i)) { |
| 213 config->rtp.extensions.push_back( |
| 214 RtpExtension(kExtensionNames[i], prng->Rand<int>())); |
| 215 } |
| 216 } |
| 217 } |
| 218 |
| 219 void GenerateAudioSendConfig(uint32_t extensions_bitvector, |
| 220 AudioSendStream::Config* config, |
| 221 Random* prng) { |
| 222 // Add SSRC to the stream. |
| 223 config->rtp.ssrc = prng->Rand<uint32_t>(); |
| 224 // Add header extensions. |
| 225 for (unsigned i = 0; i < kNumExtensions; i++) { |
| 226 if (extensions_bitvector & (1u << i)) { |
| 227 config->rtp.extensions.push_back( |
| 228 RtpExtension(kExtensionNames[i], prng->Rand<int>())); |
| 229 } |
| 230 } |
| 231 } |
| 232 |
204 // Test for the RtcEventLog class. Dumps some RTP packets and other events | 233 // Test for the RtcEventLog class. Dumps some RTP packets and other events |
205 // to disk, then reads them back to see if they match. | 234 // to disk, then reads them back to see if they match. |
206 void LogSessionAndReadBack(size_t rtp_count, | 235 void LogSessionAndReadBack(size_t rtp_count, |
207 size_t rtcp_count, | 236 size_t rtcp_count, |
208 size_t playout_count, | 237 size_t playout_count, |
209 size_t bwe_loss_count, | 238 size_t bwe_loss_count, |
210 uint32_t extensions_bitvector, | 239 uint32_t extensions_bitvector, |
211 uint32_t csrcs_count, | 240 uint32_t csrcs_count, |
212 unsigned int random_seed) { | 241 unsigned int random_seed) { |
213 ASSERT_LE(rtcp_count, rtp_count); | 242 ASSERT_LE(rtcp_count, rtp_count); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 const size_t event_count = config_count + playout_count + bwe_loss_count + | 347 const size_t event_count = config_count + playout_count + bwe_loss_count + |
319 rtcp_count + rtp_count + 2; | 348 rtcp_count + rtp_count + 2; |
320 EXPECT_GE(1000u, event_count); // The events must fit in the message queue. | 349 EXPECT_GE(1000u, event_count); // The events must fit in the message queue. |
321 EXPECT_EQ(event_count, parsed_log.GetNumberOfEvents()); | 350 EXPECT_EQ(event_count, parsed_log.GetNumberOfEvents()); |
322 if (event_count != parsed_log.GetNumberOfEvents()) { | 351 if (event_count != parsed_log.GetNumberOfEvents()) { |
323 // Print the expected and actual event types for easier debugging. | 352 // Print the expected and actual event types for easier debugging. |
324 PrintActualEvents(parsed_log); | 353 PrintActualEvents(parsed_log); |
325 PrintExpectedEvents(rtp_count, rtcp_count, playout_count, bwe_loss_count); | 354 PrintExpectedEvents(rtp_count, rtcp_count, playout_count, bwe_loss_count); |
326 } | 355 } |
327 RtcEventLogTestHelper::VerifyLogStartEvent(parsed_log, 0); | 356 RtcEventLogTestHelper::VerifyLogStartEvent(parsed_log, 0); |
328 RtcEventLogTestHelper::VerifyReceiveStreamConfig(parsed_log, 1, | 357 RtcEventLogTestHelper::VerifyVideoReceiveStreamConfig(parsed_log, 1, |
329 receiver_config); | 358 receiver_config); |
330 RtcEventLogTestHelper::VerifySendStreamConfig(parsed_log, 2, sender_config); | 359 RtcEventLogTestHelper::VerifyVideoSendStreamConfig(parsed_log, 2, |
| 360 sender_config); |
331 size_t event_index = config_count + 1; | 361 size_t event_index = config_count + 1; |
332 size_t rtcp_index = 1; | 362 size_t rtcp_index = 1; |
333 size_t playout_index = 1; | 363 size_t playout_index = 1; |
334 size_t bwe_loss_index = 1; | 364 size_t bwe_loss_index = 1; |
335 for (size_t i = 1; i <= rtp_count; i++) { | 365 for (size_t i = 1; i <= rtp_count; i++) { |
336 RtcEventLogTestHelper::VerifyRtpEvent( | 366 RtcEventLogTestHelper::VerifyRtpEvent( |
337 parsed_log, event_index, | 367 parsed_log, event_index, |
338 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, | 368 (i % 2 == 0) ? kIncomingPacket : kOutgoingPacket, |
339 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, | 369 (i % 3 == 0) ? MediaType::AUDIO : MediaType::VIDEO, |
340 rtp_packets[i - 1].data(), rtp_packets[i - 1].headers_size(), | 370 rtp_packets[i - 1].data(), rtp_packets[i - 1].headers_size(), |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 RtcEventLogTestHelper::VerifyRtcpEvent(parsed_log, 2, kOutgoingPacket, | 481 RtcEventLogTestHelper::VerifyRtcpEvent(parsed_log, 2, kOutgoingPacket, |
452 MediaType::VIDEO, rtcp_packet.data(), | 482 MediaType::VIDEO, rtcp_packet.data(), |
453 rtcp_packet.size()); | 483 rtcp_packet.size()); |
454 | 484 |
455 RtcEventLogTestHelper::VerifyLogEndEvent(parsed_log, 3); | 485 RtcEventLogTestHelper::VerifyLogEndEvent(parsed_log, 3); |
456 | 486 |
457 // Clean up temporary file - can be pretty slow. | 487 // Clean up temporary file - can be pretty slow. |
458 remove(temp_filename.c_str()); | 488 remove(temp_filename.c_str()); |
459 } | 489 } |
460 | 490 |
| 491 class ConfigReadWriteTest { |
| 492 public: |
| 493 ConfigReadWriteTest() : prng(987654321) {} |
| 494 virtual ~ConfigReadWriteTest() {} |
| 495 virtual void GenerateConfig(uint32_t extensions_bitvector) = 0; |
| 496 virtual void VerifyConfig(const ParsedRtcEventLog& parsed_log, |
| 497 size_t index) = 0; |
| 498 virtual void LogConfig(RtcEventLog* event_log) = 0; |
| 499 |
| 500 void DoTest() { |
| 501 // Find the name of the current test, in order to use it as a temporary |
| 502 // filename. |
| 503 auto test_info = ::testing::UnitTest::GetInstance()->current_test_info(); |
| 504 const std::string temp_filename = |
| 505 test::OutputPath() + test_info->test_case_name() + test_info->name(); |
| 506 |
| 507 // Use all extensions. |
| 508 uint32_t extensions_bitvector = (1u << kNumExtensions) - 1; |
| 509 GenerateConfig(extensions_bitvector); |
| 510 |
| 511 // Log a single config event and stop logging. |
| 512 SimulatedClock fake_clock(prng.Rand<uint32_t>()); |
| 513 std::unique_ptr<RtcEventLog> log_dumper(RtcEventLog::Create(&fake_clock)); |
| 514 |
| 515 log_dumper->StartLogging(temp_filename, 10000000); |
| 516 LogConfig(log_dumper.get()); |
| 517 log_dumper->StopLogging(); |
| 518 |
| 519 // Read the generated file from disk. |
| 520 ParsedRtcEventLog parsed_log; |
| 521 ASSERT_TRUE(parsed_log.ParseFile(temp_filename)); |
| 522 |
| 523 // Check the generated number of events. |
| 524 EXPECT_EQ(3u, parsed_log.GetNumberOfEvents()); |
| 525 |
| 526 RtcEventLogTestHelper::VerifyLogStartEvent(parsed_log, 0); |
| 527 |
| 528 // Verify that the parsed config struct matches the one that was logged. |
| 529 VerifyConfig(parsed_log, 1); |
| 530 |
| 531 RtcEventLogTestHelper::VerifyLogEndEvent(parsed_log, 2); |
| 532 |
| 533 // Clean up temporary file - can be pretty slow. |
| 534 remove(temp_filename.c_str()); |
| 535 } |
| 536 Random prng; |
| 537 }; |
| 538 |
| 539 class AudioReceiveConfigReadWriteTest : public ConfigReadWriteTest { |
| 540 public: |
| 541 void GenerateConfig(uint32_t extensions_bitvector) override { |
| 542 GenerateAudioReceiveConfig(extensions_bitvector, &config, &prng); |
| 543 } |
| 544 void LogConfig(RtcEventLog* event_log) override { |
| 545 event_log->LogAudioReceiveStreamConfig(config); |
| 546 } |
| 547 void VerifyConfig(const ParsedRtcEventLog& parsed_log, |
| 548 size_t index) override { |
| 549 RtcEventLogTestHelper::VerifyAudioReceiveStreamConfig(parsed_log, index, |
| 550 config); |
| 551 } |
| 552 AudioReceiveStream::Config config; |
| 553 }; |
| 554 |
| 555 class AudioSendConfigReadWriteTest : public ConfigReadWriteTest { |
| 556 public: |
| 557 AudioSendConfigReadWriteTest() : config(nullptr) {} |
| 558 void GenerateConfig(uint32_t extensions_bitvector) override { |
| 559 GenerateAudioSendConfig(extensions_bitvector, &config, &prng); |
| 560 } |
| 561 void LogConfig(RtcEventLog* event_log) override { |
| 562 event_log->LogAudioSendStreamConfig(config); |
| 563 } |
| 564 void VerifyConfig(const ParsedRtcEventLog& parsed_log, |
| 565 size_t index) override { |
| 566 RtcEventLogTestHelper::VerifyAudioSendStreamConfig(parsed_log, index, |
| 567 config); |
| 568 } |
| 569 AudioSendStream::Config config; |
| 570 }; |
| 571 |
| 572 class VideoReceiveConfigReadWriteTest : public ConfigReadWriteTest { |
| 573 public: |
| 574 VideoReceiveConfigReadWriteTest() : config(nullptr) {} |
| 575 void GenerateConfig(uint32_t extensions_bitvector) override { |
| 576 GenerateVideoReceiveConfig(extensions_bitvector, &config, &prng); |
| 577 } |
| 578 void LogConfig(RtcEventLog* event_log) override { |
| 579 event_log->LogVideoReceiveStreamConfig(config); |
| 580 } |
| 581 void VerifyConfig(const ParsedRtcEventLog& parsed_log, |
| 582 size_t index) override { |
| 583 RtcEventLogTestHelper::VerifyVideoReceiveStreamConfig(parsed_log, index, |
| 584 config); |
| 585 } |
| 586 VideoReceiveStream::Config config; |
| 587 }; |
| 588 |
| 589 class VideoSendConfigReadWriteTest : public ConfigReadWriteTest { |
| 590 public: |
| 591 VideoSendConfigReadWriteTest() : config(nullptr) {} |
| 592 void GenerateConfig(uint32_t extensions_bitvector) override { |
| 593 GenerateVideoSendConfig(extensions_bitvector, &config, &prng); |
| 594 } |
| 595 void LogConfig(RtcEventLog* event_log) override { |
| 596 event_log->LogVideoSendStreamConfig(config); |
| 597 } |
| 598 void VerifyConfig(const ParsedRtcEventLog& parsed_log, |
| 599 size_t index) override { |
| 600 RtcEventLogTestHelper::VerifyVideoSendStreamConfig(parsed_log, index, |
| 601 config); |
| 602 } |
| 603 VideoSendStream::Config config; |
| 604 }; |
| 605 |
| 606 TEST(RtcEventLogTest, LogAudioReceiveConfig) { |
| 607 AudioReceiveConfigReadWriteTest test; |
| 608 test.DoTest(); |
| 609 } |
| 610 |
| 611 TEST(RtcEventLogTest, LogAudioSendConfig) { |
| 612 AudioSendConfigReadWriteTest test; |
| 613 test.DoTest(); |
| 614 } |
| 615 |
| 616 TEST(RtcEventLogTest, LogVideoReceiveConfig) { |
| 617 VideoReceiveConfigReadWriteTest test; |
| 618 test.DoTest(); |
| 619 } |
| 620 |
| 621 TEST(RtcEventLogTest, LogVideoSendConfig) { |
| 622 VideoSendConfigReadWriteTest test; |
| 623 test.DoTest(); |
| 624 } |
461 } // namespace webrtc | 625 } // namespace webrtc |
OLD | NEW |