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

Side by Side Diff: webrtc/api/statscollector_unittest.cc

Issue 1713043002: Late initialize MediaController, for less resource i.e. ProcessThread, usage by PeerConnection. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Missed one comment 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 2014 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2014 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // Error return values 59 // Error return values
60 const char kNotFound[] = "NOT FOUND"; 60 const char kNotFound[] = "NOT FOUND";
61 61
62 // Constant names for track identification. 62 // Constant names for track identification.
63 const char kLocalTrackId[] = "local_track_id"; 63 const char kLocalTrackId[] = "local_track_id";
64 const char kRemoteTrackId[] = "remote_track_id"; 64 const char kRemoteTrackId[] = "remote_track_id";
65 const uint32_t kSsrcOfTrack = 1234; 65 const uint32_t kSsrcOfTrack = 1234;
66 66
67 class MockWebRtcSession : public webrtc::WebRtcSession { 67 class MockWebRtcSession : public webrtc::WebRtcSession {
68 public: 68 public:
69 explicit MockWebRtcSession(webrtc::MediaControllerInterface* media_controller) 69 explicit MockWebRtcSession()
70 : WebRtcSession(media_controller, 70 : WebRtcSession(rtc::Thread::Current(),
71 rtc::Thread::Current(),
72 rtc::Thread::Current(), 71 rtc::Thread::Current(),
73 nullptr) {} 72 nullptr) {}
74 MOCK_METHOD0(voice_channel, cricket::VoiceChannel*()); 73 MOCK_METHOD0(voice_channel, cricket::VoiceChannel*());
75 MOCK_METHOD0(video_channel, cricket::VideoChannel*()); 74 MOCK_METHOD0(video_channel, cricket::VideoChannel*());
76 // Libjingle uses "local" for a outgoing track, and "remote" for a incoming 75 // Libjingle uses "local" for a outgoing track, and "remote" for a incoming
77 // track. 76 // track.
78 MOCK_METHOD2(GetLocalTrackIdBySsrc, bool(uint32_t, std::string*)); 77 MOCK_METHOD2(GetLocalTrackIdBySsrc, bool(uint32_t, std::string*));
79 MOCK_METHOD2(GetRemoteTrackIdBySsrc, bool(uint32_t, std::string*)); 78 MOCK_METHOD2(GetRemoteTrackIdBySsrc, bool(uint32_t, std::string*));
80 MOCK_METHOD1(GetTransportStats, bool(SessionStats*)); 79 MOCK_METHOD1(GetTransportStats, bool(SessionStats*));
81 MOCK_METHOD2(GetLocalCertificate, 80 MOCK_METHOD2(GetLocalCertificate,
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 } 478 }
480 479
481 private: 480 private:
482 double time_now_; 481 double time_now_;
483 }; 482 };
484 483
485 class StatsCollectorTest : public testing::Test { 484 class StatsCollectorTest : public testing::Test {
486 protected: 485 protected:
487 StatsCollectorTest() 486 StatsCollectorTest()
488 : media_engine_(new cricket::FakeMediaEngine()), 487 : media_engine_(new cricket::FakeMediaEngine()),
489 channel_manager_( 488 session_() {
490 new cricket::ChannelManager(media_engine_, rtc::Thread::Current())),
491 media_controller_(
492 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
493 rtc::Thread::Current(),
494 channel_manager_.get())),
495 session_(media_controller_.get()) {
496 // By default, we ignore session GetStats calls. 489 // By default, we ignore session GetStats calls.
497 EXPECT_CALL(session_, GetTransportStats(_)).WillRepeatedly(Return(false)); 490 EXPECT_CALL(session_, GetTransportStats(_)).WillRepeatedly(Return(false));
498 // Add default returns for mock classes. 491 // Add default returns for mock classes.
499 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull()); 492 EXPECT_CALL(session_, video_channel()).WillRepeatedly(ReturnNull());
500 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull()); 493 EXPECT_CALL(session_, voice_channel()).WillRepeatedly(ReturnNull());
501 EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_)); 494 EXPECT_CALL(pc_, session()).WillRepeatedly(Return(&session_));
502 EXPECT_CALL(pc_, sctp_data_channels()) 495 EXPECT_CALL(pc_, sctp_data_channels())
503 .WillRepeatedly(ReturnRef(data_channels_)); 496 .WillRepeatedly(ReturnRef(data_channels_));
504 } 497 }
505 498
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 EXPECT_EQ(rtc::SSLStreamAdapter::SslCipherSuiteToName( 732 EXPECT_EQ(rtc::SSLStreamAdapter::SslCipherSuiteToName(
740 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA), 733 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA),
741 dtls_cipher_suite); 734 dtls_cipher_suite);
742 std::string srtp_crypto_suite = 735 std::string srtp_crypto_suite =
743 ExtractStatsValue(StatsReport::kStatsReportTypeComponent, reports, 736 ExtractStatsValue(StatsReport::kStatsReportTypeComponent, reports,
744 StatsReport::kStatsValueNameSrtpCipher); 737 StatsReport::kStatsValueNameSrtpCipher);
745 EXPECT_EQ(rtc::SrtpCryptoSuiteToName(rtc::SRTP_AES128_CM_SHA1_80), 738 EXPECT_EQ(rtc::SrtpCryptoSuiteToName(rtc::SRTP_AES128_CM_SHA1_80),
746 srtp_crypto_suite); 739 srtp_crypto_suite);
747 } 740 }
748 741
749 cricket::FakeMediaEngine* media_engine_; 742 rtc::scoped_ptr<cricket::FakeMediaEngine> media_engine_;
750 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
751 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
752 MockWebRtcSession session_; 743 MockWebRtcSession session_;
753 MockPeerConnection pc_; 744 MockPeerConnection pc_;
754 FakeDataChannelProvider data_channel_provider_; 745 FakeDataChannelProvider data_channel_provider_;
755 SessionStats session_stats_; 746 SessionStats session_stats_;
756 rtc::scoped_refptr<webrtc::MediaStream> stream_; 747 rtc::scoped_refptr<webrtc::MediaStream> stream_;
757 rtc::scoped_refptr<webrtc::VideoTrack> track_; 748 rtc::scoped_refptr<webrtc::VideoTrack> track_;
758 rtc::scoped_refptr<FakeAudioTrack> audio_track_; 749 rtc::scoped_refptr<FakeAudioTrack> audio_track_;
759 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_; 750 std::vector<rtc::scoped_refptr<DataChannel>> data_channels_;
760 }; 751 };
761 752
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 StatsCollectorForTest stats(&pc_); 1469 StatsCollectorForTest stats(&pc_);
1479 1470
1480 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1471 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1481 .WillRepeatedly(Return(false)); 1472 .WillRepeatedly(Return(false));
1482 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1473 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1483 .WillRepeatedly(Return(false)); 1474 .WillRepeatedly(Return(false));
1484 1475
1485 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1476 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1486 // The transport_name known by the voice channel. 1477 // The transport_name known by the voice channel.
1487 const std::string kVcName("vcname"); 1478 const std::string kVcName("vcname");
1488 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), media_engine_, 1479 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
1489 media_channel, nullptr, kVcName, false); 1480 media_engine_.get(), media_channel,
1481 nullptr, kVcName, false);
1490 AddOutgoingAudioTrackStats(); 1482 AddOutgoingAudioTrackStats();
1491 stats.AddStream(stream_); 1483 stats.AddStream(stream_);
1492 stats.AddLocalAudioTrack(audio_track_, kSsrcOfTrack); 1484 stats.AddLocalAudioTrack(audio_track_, kSsrcOfTrack);
1493 1485
1494 cricket::VoiceSenderInfo voice_sender_info; 1486 cricket::VoiceSenderInfo voice_sender_info;
1495 InitVoiceSenderInfo(&voice_sender_info); 1487 InitVoiceSenderInfo(&voice_sender_info);
1496 1488
1497 cricket::VoiceMediaInfo stats_read; 1489 cricket::VoiceMediaInfo stats_read;
1498 StatsReports reports; // returned values. 1490 StatsReports reports; // returned values.
1499 SetupAndVerifyAudioTrackStats( 1491 SetupAndVerifyAudioTrackStats(
(...skipping 13 matching lines...) Expand all
1513 StatsCollectorForTest stats(&pc_); 1505 StatsCollectorForTest stats(&pc_);
1514 1506
1515 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1507 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1516 .WillRepeatedly(Return(false)); 1508 .WillRepeatedly(Return(false));
1517 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1509 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1518 .WillRepeatedly(Return(false)); 1510 .WillRepeatedly(Return(false));
1519 1511
1520 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1512 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1521 // The transport_name known by the voice channel. 1513 // The transport_name known by the voice channel.
1522 const std::string kVcName("vcname"); 1514 const std::string kVcName("vcname");
1523 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), media_engine_, 1515 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
1524 media_channel, nullptr, kVcName, false); 1516 media_engine_.get(), media_channel,
1517 nullptr, kVcName, false);
1525 AddIncomingAudioTrackStats(); 1518 AddIncomingAudioTrackStats();
1526 stats.AddStream(stream_); 1519 stats.AddStream(stream_);
1527 1520
1528 cricket::VoiceReceiverInfo voice_receiver_info; 1521 cricket::VoiceReceiverInfo voice_receiver_info;
1529 InitVoiceReceiverInfo(&voice_receiver_info); 1522 InitVoiceReceiverInfo(&voice_receiver_info);
1530 voice_receiver_info.codec_name = "fake_codec"; 1523 voice_receiver_info.codec_name = "fake_codec";
1531 1524
1532 cricket::VoiceMediaInfo stats_read; 1525 cricket::VoiceMediaInfo stats_read;
1533 StatsReports reports; // returned values. 1526 StatsReports reports; // returned values.
1534 SetupAndVerifyAudioTrackStats( 1527 SetupAndVerifyAudioTrackStats(
1535 audio_track_.get(), stream_.get(), &stats, &voice_channel, kVcName, 1528 audio_track_.get(), stream_.get(), &stats, &voice_channel, kVcName,
1536 media_channel, NULL, &voice_receiver_info, &stats_read, &reports); 1529 media_channel, NULL, &voice_receiver_info, &stats_read, &reports);
1537 } 1530 }
1538 1531
1539 // This test verifies that a local stats object won't update its statistics 1532 // This test verifies that a local stats object won't update its statistics
1540 // after a RemoveLocalAudioTrack() call. 1533 // after a RemoveLocalAudioTrack() call.
1541 TEST_F(StatsCollectorTest, GetStatsAfterRemoveAudioStream) { 1534 TEST_F(StatsCollectorTest, GetStatsAfterRemoveAudioStream) {
1542 StatsCollectorForTest stats(&pc_); 1535 StatsCollectorForTest stats(&pc_);
1543 1536
1544 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1537 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1545 .WillRepeatedly(Return(false)); 1538 .WillRepeatedly(Return(false));
1546 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1539 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1547 .WillRepeatedly(Return(false)); 1540 .WillRepeatedly(Return(false));
1548 1541
1549 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1542 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1550 // The transport_name known by the voice channel. 1543 // The transport_name known by the voice channel.
1551 const std::string kVcName("vcname"); 1544 const std::string kVcName("vcname");
1552 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), media_engine_, 1545 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
1553 media_channel, nullptr, kVcName, false); 1546 media_engine_.get(), media_channel,
1547 nullptr, kVcName, false);
1554 AddOutgoingAudioTrackStats(); 1548 AddOutgoingAudioTrackStats();
1555 stats.AddStream(stream_); 1549 stats.AddStream(stream_);
1556 stats.AddLocalAudioTrack(audio_track_.get(), kSsrcOfTrack); 1550 stats.AddLocalAudioTrack(audio_track_.get(), kSsrcOfTrack);
1557 1551
1558 // Instruct the session to return stats containing the transport channel. 1552 // Instruct the session to return stats containing the transport channel.
1559 InitSessionStats(kVcName); 1553 InitSessionStats(kVcName);
1560 EXPECT_CALL(session_, GetTransportStats(_)) 1554 EXPECT_CALL(session_, GetTransportStats(_))
1561 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_), 1555 .WillRepeatedly(DoAll(SetArgPointee<0>(session_stats_),
1562 Return(true))); 1556 Return(true)));
1563 1557
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1603 StatsCollectorForTest stats(&pc_); 1597 StatsCollectorForTest stats(&pc_);
1604 1598
1605 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1599 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1606 .WillRepeatedly(Return(false)); 1600 .WillRepeatedly(Return(false));
1607 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1601 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1608 .WillRepeatedly(Return(false)); 1602 .WillRepeatedly(Return(false));
1609 1603
1610 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1604 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1611 // The transport_name known by the voice channel. 1605 // The transport_name known by the voice channel.
1612 const std::string kVcName("vcname"); 1606 const std::string kVcName("vcname");
1613 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), media_engine_, 1607 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
1614 media_channel, nullptr, kVcName, false); 1608 media_engine_.get(), media_channel,
1609 nullptr, kVcName, false);
1615 1610
1616 // Create a local stream with a local audio track and adds it to the stats. 1611 // Create a local stream with a local audio track and adds it to the stats.
1617 AddOutgoingAudioTrackStats(); 1612 AddOutgoingAudioTrackStats();
1618 stats.AddStream(stream_); 1613 stats.AddStream(stream_);
1619 stats.AddLocalAudioTrack(audio_track_.get(), kSsrcOfTrack); 1614 stats.AddLocalAudioTrack(audio_track_.get(), kSsrcOfTrack);
1620 1615
1621 // Create a remote stream with a remote audio track and adds it to the stats. 1616 // Create a remote stream with a remote audio track and adds it to the stats.
1622 rtc::scoped_refptr<webrtc::MediaStream> remote_stream( 1617 rtc::scoped_refptr<webrtc::MediaStream> remote_stream(
1623 webrtc::MediaStream::Create("remotestreamlabel")); 1618 webrtc::MediaStream::Create("remotestreamlabel"));
1624 rtc::scoped_refptr<FakeAudioTrack> remote_track( 1619 rtc::scoped_refptr<FakeAudioTrack> remote_track(
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1690 StatsCollectorForTest stats(&pc_); 1685 StatsCollectorForTest stats(&pc_);
1691 1686
1692 EXPECT_CALL(session_, GetLocalCertificate(_, _)) 1687 EXPECT_CALL(session_, GetLocalCertificate(_, _))
1693 .WillRepeatedly(Return(false)); 1688 .WillRepeatedly(Return(false));
1694 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _)) 1689 EXPECT_CALL(session_, GetRemoteSSLCertificate(_, _))
1695 .WillRepeatedly(Return(false)); 1690 .WillRepeatedly(Return(false));
1696 1691
1697 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel(); 1692 MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
1698 // The transport_name known by the voice channel. 1693 // The transport_name known by the voice channel.
1699 const std::string kVcName("vcname"); 1694 const std::string kVcName("vcname");
1700 cricket::VoiceChannel voice_channel(rtc::Thread::Current(), media_engine_, 1695 cricket::VoiceChannel voice_channel(rtc::Thread::Current(),
1701 media_channel, nullptr, kVcName, false); 1696 media_engine_.get(), media_channel,
1697 nullptr, kVcName, false);
1702 1698
1703 // Create a local stream with a local audio track and adds it to the stats. 1699 // Create a local stream with a local audio track and adds it to the stats.
1704 AddOutgoingAudioTrackStats(); 1700 AddOutgoingAudioTrackStats();
1705 stats.AddStream(stream_); 1701 stats.AddStream(stream_);
1706 stats.AddLocalAudioTrack(audio_track_, kSsrcOfTrack); 1702 stats.AddLocalAudioTrack(audio_track_, kSsrcOfTrack);
1707 1703
1708 cricket::VoiceSenderInfo voice_sender_info; 1704 cricket::VoiceSenderInfo voice_sender_info;
1709 voice_sender_info.add_ssrc(kSsrcOfTrack); 1705 voice_sender_info.add_ssrc(kSsrcOfTrack);
1710 1706
1711 cricket::VoiceMediaInfo stats_read; 1707 cricket::VoiceMediaInfo stats_read;
(...skipping 19 matching lines...) Expand all
1731 cricket::VoiceSenderInfo new_voice_sender_info; 1727 cricket::VoiceSenderInfo new_voice_sender_info;
1732 InitVoiceSenderInfo(&new_voice_sender_info); 1728 InitVoiceSenderInfo(&new_voice_sender_info);
1733 cricket::VoiceMediaInfo new_stats_read; 1729 cricket::VoiceMediaInfo new_stats_read;
1734 reports.clear(); 1730 reports.clear();
1735 SetupAndVerifyAudioTrackStats( 1731 SetupAndVerifyAudioTrackStats(
1736 new_audio_track.get(), stream_.get(), &stats, &voice_channel, kVcName, 1732 new_audio_track.get(), stream_.get(), &stats, &voice_channel, kVcName,
1737 media_channel, &new_voice_sender_info, NULL, &new_stats_read, &reports); 1733 media_channel, &new_voice_sender_info, NULL, &new_stats_read, &reports);
1738 } 1734 }
1739 1735
1740 } // namespace webrtc 1736 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698