Add virtual Initialize methods to PortAllocator and NetworkManager.

This will allow PeerConnection to handle hopping to the right thread
and doing thread-specific initialization for the PortAllocator.
This eliminates a required thread-hop for whatever is passing the
PortAllocator into CreatePeerConnection.

BUG=617648
R=pthatcher@webrtc.org, skvlad@webrtc.org

Review URL: https://codereview.webrtc.org/2097653002 .

Cr-Commit-Position: refs/heads/master@{#13283}
This commit is contained in:
Taylor Brandstetter
2016-06-24 14:04:01 -07:00
parent 059e183419
commit a6bdb0990a
5 changed files with 63 additions and 12 deletions

View File

@ -1066,6 +1066,28 @@ TEST_F(PeerConnectionInterfaceTest, CreatePeerConnectionWithPooledCandidates) {
session->flags() & cricket::PORTALLOCATOR_DISABLE_COSTLY_NETWORKS);
}
// Test that the PeerConnection initializes the port allocator passed into it,
// and on the correct thread.
TEST_F(PeerConnectionInterfaceTest,
CreatePeerConnectionInitializesPortAllocator) {
rtc::Thread network_thread;
network_thread.Start();
rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory(
webrtc::CreatePeerConnectionFactory(
&network_thread, rtc::Thread::Current(), rtc::Thread::Current(),
nullptr, nullptr, nullptr));
std::unique_ptr<cricket::FakePortAllocator> port_allocator(
new cricket::FakePortAllocator(&network_thread, nullptr));
cricket::FakePortAllocator* raw_port_allocator = port_allocator.get();
PeerConnectionInterface::RTCConfiguration config;
rtc::scoped_refptr<PeerConnectionInterface> pc(
pc_factory_->CreatePeerConnection(
config, nullptr, std::move(port_allocator), nullptr, &observer_));
// FakePortAllocator RTC_CHECKs that it's initialized on the right thread,
// so all we have to do here is check that it's initialized.
EXPECT_TRUE(raw_port_allocator->initialized());
}
TEST_F(PeerConnectionInterfaceTest, AddStreams) {
CreatePeerConnection();
AddVideoStream(kStreamLabel1);