diff options
author | perkj@chromium.org <perkj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-27 17:20:40 +0000 |
---|---|---|
committer | perkj@chromium.org <perkj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-27 17:20:40 +0000 |
commit | 275cc06144eeb80f766bb62aac14fc4d3a85a01e (patch) | |
tree | 08e660f64cac642563e836834eaba6e02ef2961f | |
parent | 7e18fe1ea62bff56e9c8e6cac9c57a17170d4020 (diff) | |
download | chromium_src-275cc06144eeb80f766bb62aac14fc4d3a85a01e.zip chromium_src-275cc06144eeb80f766bb62aac14fc4d3a85a01e.tar.gz chromium_src-275cc06144eeb80f766bb62aac14fc4d3a85a01e.tar.bz2 |
Refactored to provide a new PortAllocatorFactory per PeerConnection.
This refactor MediaStreamDependencyFactory to create one PortAllocatorFactory per created PeerConnection. The reason is that the PortAllocator need a valid WebFrame that belongs to the
webpage that creates the PeerConnection. The valid WebFrame will be provided in a later cl from WebKit.
Roles libjingle to revision 195.
BUG=148366,150755
TEST= existing unit tests and https://apprtc.appspot.com/?r= between two tabs.
Review URL: https://chromiumcodereview.appspot.com/10977035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@159056 0039d316-1c4b-4281-b951-d872f2087c98
8 files changed, 91 insertions, 65 deletions
@@ -18,7 +18,7 @@ vars = { "nacl_tools_revision": "9330", # native_client/DEPS: tools_rev "gtm_revision": "578", - "libjingle_revision": "193", + "libjingle_revision": "195", "libphonenumber_revision": "456", "libvpx_revision": "152423", "lss_revision": "13", diff --git a/content/renderer/media/media_stream_dependency_factory.cc b/content/renderer/media/media_stream_dependency_factory.cc index 06319d0..19c7691 100644 --- a/content/renderer/media/media_stream_dependency_factory.cc +++ b/content/renderer/media/media_stream_dependency_factory.cc @@ -29,20 +29,18 @@ class P2PPortAllocatorFactory : public webrtc::PortAllocatorFactoryInterface { P2PPortAllocatorFactory( content::P2PSocketDispatcher* socket_dispatcher, talk_base::NetworkManager* network_manager, - talk_base::PacketSocketFactory* socket_factory) + talk_base::PacketSocketFactory* socket_factory, + WebKit::WebFrame* web_frame) : socket_dispatcher_(socket_dispatcher), network_manager_(network_manager), - socket_factory_(socket_factory) { + socket_factory_(socket_factory), + web_frame_(web_frame) { } virtual cricket::PortAllocator* CreatePortAllocator( const std::vector<StunConfiguration>& stun_servers, const std::vector<TurnConfiguration>& turn_configurations) OVERRIDE { - WebKit::WebFrame* web_frame = WebKit::WebFrame::frameForCurrentContext(); - if (!web_frame) { - LOG(ERROR) << "WebFrame is NULL."; - return NULL; - } + CHECK(web_frame_); content::P2PPortAllocator::Config config; if (stun_servers.size() > 0) { config.stun_server = stun_servers[0].server.hostname(); @@ -55,7 +53,7 @@ class P2PPortAllocatorFactory : public webrtc::PortAllocatorFactoryInterface { config.relay_password = turn_configurations[0].password; } - return new content::P2PPortAllocator(web_frame, + return new content::P2PPortAllocator(web_frame_, socket_dispatcher_, network_manager_, socket_factory_, @@ -71,6 +69,8 @@ class P2PPortAllocatorFactory : public webrtc::PortAllocatorFactoryInterface { // MediaStreamDependencyFactory. talk_base::NetworkManager* network_manager_; talk_base::PacketSocketFactory* socket_factory_; + // Raw ptr to the WebFrame that created the P2PPortAllocatorFactory. + WebKit::WebFrame* web_frame_; }; MediaStreamDependencyFactory::MediaStreamDependencyFactory( @@ -182,34 +182,22 @@ bool MediaStreamDependencyFactory::CreateNativeLocalMediaStream( bool MediaStreamDependencyFactory::CreateNativeLocalMediaStream( WebKit::WebMediaStreamDescriptor* description, const MediaStreamExtraData::StreamStopCallback& stream_stop) { - if(!CreateNativeLocalMediaStream(description)) - return false; + if (!CreateNativeLocalMediaStream(description)) + return false; - MediaStreamExtraData* extra_data = - static_cast<MediaStreamExtraData*>(description->extraData()); - extra_data->SetLocalStreamStopCallback(stream_stop); - return true; + MediaStreamExtraData* extra_data = + static_cast<MediaStreamExtraData*>(description->extraData()); + extra_data->SetLocalStreamStopCallback(stream_stop); + return true; } -bool MediaStreamDependencyFactory::CreatePeerConnectionFactory( - talk_base::Thread* worker_thread, - talk_base::Thread* signaling_thread, - content::P2PSocketDispatcher* socket_dispatcher, - talk_base::NetworkManager* network_manager, - talk_base::PacketSocketFactory* socket_factory) { +bool MediaStreamDependencyFactory::CreatePeerConnectionFactory() { if (!pc_factory_.get()) { - scoped_refptr<P2PPortAllocatorFactory> pa_factory = - new talk_base::RefCountedObject<P2PPortAllocatorFactory>( - socket_dispatcher, - network_manager, - socket_factory); - DCHECK(!audio_device_); audio_device_ = new WebRtcAudioDeviceImpl(); scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( - webrtc::CreatePeerConnectionFactory(worker_thread, - signaling_thread, - pa_factory.release(), + webrtc::CreatePeerConnectionFactory(worker_thread_, + signaling_thread_, audio_device_)); if (factory.get()) pc_factory_ = factory.release(); @@ -225,16 +213,31 @@ scoped_refptr<webrtc::PeerConnectionInterface> MediaStreamDependencyFactory::CreatePeerConnection( const std::string& config, webrtc::PeerConnectionObserver* observer) { - return pc_factory_->CreatePeerConnection(config, observer).get(); + scoped_refptr<P2PPortAllocatorFactory> pa_factory = + new talk_base::RefCountedObject<P2PPortAllocatorFactory>( + p2p_socket_dispatcher_.get(), + network_manager_, + socket_factory_.get(), + WebKit::WebFrame::frameForCurrentContext()); + return pc_factory_->CreatePeerConnection(config, pa_factory, observer).get(); } scoped_refptr<webrtc::PeerConnectionInterface> MediaStreamDependencyFactory::CreatePeerConnection( const webrtc::JsepInterface::IceServers& ice_servers, const webrtc::MediaConstraintsInterface* constraints, + WebKit::WebFrame* web_frame, webrtc::PeerConnectionObserver* observer) { + CHECK(web_frame); + CHECK(observer); + scoped_refptr<P2PPortAllocatorFactory> pa_factory = + new talk_base::RefCountedObject<P2PPortAllocatorFactory>( + p2p_socket_dispatcher_.get(), + network_manager_, + socket_factory_.get(), + web_frame); return pc_factory_->CreatePeerConnection( - ice_servers, constraints, observer).get(); + ice_servers, constraints, pa_factory, observer).get(); } scoped_refptr<webrtc::LocalMediaStreamInterface> @@ -307,7 +310,7 @@ void MediaStreamDependencyFactory::DeleteIpcNetworkManager() { bool MediaStreamDependencyFactory::EnsurePeerConnectionFactory() { DCHECK(CalledOnValidThread()); - if(PeerConnectionFactoryCreated()) + if (PeerConnectionFactoryCreated()) return true; if (!signaling_thread_) { @@ -349,12 +352,7 @@ bool MediaStreamDependencyFactory::EnsurePeerConnectionFactory() { new content::IpcPacketSocketFactory(p2p_socket_dispatcher_)); } - if (!CreatePeerConnectionFactory( - worker_thread_, - signaling_thread_, - p2p_socket_dispatcher_, - network_manager_, - socket_factory_.get())) { + if (!CreatePeerConnectionFactory()) { LOG(ERROR) << "Could not create PeerConnection factory"; return false; } diff --git a/content/renderer/media/media_stream_dependency_factory.h b/content/renderer/media/media_stream_dependency_factory.h index 95d2ac9..c9deb11 100644 --- a/content/renderer/media/media_stream_dependency_factory.h +++ b/content/renderer/media/media_stream_dependency_factory.h @@ -35,6 +35,7 @@ class PeerConnection; } namespace WebKit { +class WebFrame; class WebMediaStreamDescriptor; class WebPeerConnection00Handler; class WebPeerConnection00HandlerClient; @@ -87,6 +88,7 @@ class CONTENT_EXPORT MediaStreamDependencyFactory virtual scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(const webrtc::JsepInterface::IceServers& ice_servers, const webrtc::MediaConstraintsInterface* constraints, + WebKit::WebFrame* web_frame, webrtc::PeerConnectionObserver* observer); // Creates a libjingle representation of a Session description. Used by a @@ -127,12 +129,7 @@ class CONTENT_EXPORT MediaStreamDependencyFactory private: // Creates and deletes |pc_factory_|, which in turn is used for // creating PeerConnection objects. - bool CreatePeerConnectionFactory( - talk_base::Thread* worker_thread, - talk_base::Thread* signaling_thread, - content::P2PSocketDispatcher* socket_dispatcher, - talk_base::NetworkManager* network_manager, - talk_base::PacketSocketFactory* socket_factory); + bool CreatePeerConnectionFactory(); bool PeerConnectionFactoryCreated(); void InitializeWorkerThread(talk_base::Thread** thread, diff --git a/content/renderer/media/mock_media_stream_dependency_factory.cc b/content/renderer/media/mock_media_stream_dependency_factory.cc index 104f74f..d45cf7f 100644 --- a/content/renderer/media/mock_media_stream_dependency_factory.cc +++ b/content/renderer/media/mock_media_stream_dependency_factory.cc @@ -275,6 +275,7 @@ scoped_refptr<webrtc::PeerConnectionInterface> MockMediaStreamDependencyFactory::CreatePeerConnection( const webrtc::JsepInterface::IceServers& ice_servers, const webrtc::MediaConstraintsInterface* constraints, + WebKit::WebFrame* frame, webrtc::PeerConnectionObserver* observer) { DCHECK(mock_pc_factory_created_); return new talk_base::RefCountedObject<webrtc::MockPeerConnectionImpl>(this); diff --git a/content/renderer/media/mock_media_stream_dependency_factory.h b/content/renderer/media/mock_media_stream_dependency_factory.h index 59b8917..e4de0dd 100644 --- a/content/renderer/media/mock_media_stream_dependency_factory.h +++ b/content/renderer/media/mock_media_stream_dependency_factory.h @@ -79,6 +79,7 @@ class MockMediaStreamDependencyFactory : public MediaStreamDependencyFactory { virtual scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(const webrtc::JsepInterface::IceServers& ice_servers, const webrtc::MediaConstraintsInterface* constraints, + WebKit::WebFrame* frame, webrtc::PeerConnectionObserver* observer) OVERRIDE; virtual scoped_refptr<webrtc::LocalMediaStreamInterface> CreateLocalMediaStream(const std::string& label) OVERRIDE; diff --git a/content/renderer/media/rtc_peer_connection_handler.cc b/content/renderer/media/rtc_peer_connection_handler.cc index ba33ed7..a02dc51 100644 --- a/content/renderer/media/rtc_peer_connection_handler.cc +++ b/content/renderer/media/rtc_peer_connection_handler.cc @@ -19,6 +19,7 @@ #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCSessionDescriptionRequest.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCVoidRequest.h" #include "third_party/WebKit/Source/Platform/chromium/public/WebURL.h" +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" // Converter functions from libjingle types to WebKit types. @@ -154,7 +155,21 @@ class RTCMediaConstraints : public webrtc::MediaConstraintsInterface { explicit RTCMediaConstraints( const WebKit::WebMediaConstraints& constraints) { } + virtual const Constraints& GetMandatory() const OVERRIDE { + // TODO(perkj): Implement. + NOTIMPLEMENTED(); + return mandatory_; + } + virtual const Constraints& GetOptional() const OVERRIDE { + // TODO(perkj): Implement. + NOTIMPLEMENTED(); + return optional_; + } ~RTCMediaConstraints() {} + + private: + Constraints mandatory_; + Constraints optional_; }; RTCPeerConnectionHandler::RTCPeerConnectionHandler( @@ -169,14 +184,40 @@ RTCPeerConnectionHandler::~RTCPeerConnectionHandler() { bool RTCPeerConnectionHandler::initialize( const WebKit::WebRTCConfiguration& server_configuration, - const WebKit::WebMediaConstraints& options ) { + const WebKit::WebMediaConstraints& options) { + webrtc::JsepInterface::IceServers servers; + GetNativeIceServers(server_configuration, &servers); + + // TODO(perkj) use a frame provided by WebKit to + // RTCPeerConnectionHandler::initialize when the new WebKit version has been + // rolled. + WebKit::WebFrame* frame = WebKit::WebFrame::frameForCurrentContext(); + if (!frame) { + LOG(ERROR) << "frame is NULL"; + return false; + } + + RTCMediaConstraints constraints(options); + native_peer_connection_ = + dependency_factory_->CreatePeerConnection( + servers, &constraints, frame, this); + if (!native_peer_connection_) { + LOG(ERROR) << "Failed to initialize native PeerConnection."; + return false; + } + return true; +} + +bool RTCPeerConnectionHandler::InitializeForTest( + const WebKit::WebRTCConfiguration& server_configuration, + const WebKit::WebMediaConstraints& options) { webrtc::JsepInterface::IceServers servers; GetNativeIceServers(server_configuration, &servers); RTCMediaConstraints constraints(options); native_peer_connection_ = dependency_factory_->CreatePeerConnection( - servers, &constraints, this); + servers, &constraints, NULL, this); if (!native_peer_connection_) { LOG(ERROR) << "Failed to initialize native PeerConnection."; return false; diff --git a/content/renderer/media/rtc_peer_connection_handler.h b/content/renderer/media/rtc_peer_connection_handler.h index 433e24f..5dab126 100644 --- a/content/renderer/media/rtc_peer_connection_handler.h +++ b/content/renderer/media/rtc_peer_connection_handler.h @@ -26,6 +26,11 @@ class CONTENT_EXPORT RTCPeerConnectionHandler MediaStreamDependencyFactory* dependency_factory); virtual ~RTCPeerConnectionHandler(); + // Initialize method only used for unit test. + bool InitializeForTest( + const WebKit::WebRTCConfiguration& server_configuration, + const WebKit::WebMediaConstraints& options); + // WebKit::WebRTCPeerConnectionHandler implementation virtual bool initialize( const WebKit::WebRTCConfiguration& server_configuration, diff --git a/content/renderer/media/rtc_peer_connection_handler_unittest.cc b/content/renderer/media/rtc_peer_connection_handler_unittest.cc index 3e249af..b2eb8fb 100644 --- a/content/renderer/media/rtc_peer_connection_handler_unittest.cc +++ b/content/renderer/media/rtc_peer_connection_handler_unittest.cc @@ -56,20 +56,7 @@ class RTCPeerConnectionHandlerTest : public ::testing::Test { WebKit::WebRTCConfiguration config; WebKit::WebMediaConstraints constraints; - EXPECT_TRUE(pc_handler_->initialize(config, constraints)); - - mock_peer_connection_ = pc_handler_->native_peer_connection(); - ASSERT_TRUE(mock_peer_connection_); - } - - void Initialize(const std::string& server, const std::string& password) { - WebKit::WebRTCConfiguration config; - WebKit::WebMediaConstraints constraints; - - // TODO(perkj): Test that the parameters in |config| can be translated when - // a WebRTCConfiguration can be constructed. It's WebKit class and can't be - // initialized from a test. - EXPECT_TRUE(pc_handler_->initialize(config, constraints)); + EXPECT_TRUE(pc_handler_->InitializeForTest(config, constraints)); mock_peer_connection_ = pc_handler_->native_peer_connection(); ASSERT_TRUE(mock_peer_connection_); @@ -142,10 +129,6 @@ class RTCPeerConnectionHandlerTest : public ::testing::Test { webrtc::MockPeerConnectionImpl* mock_peer_connection_; }; -TEST_F(RTCPeerConnectionHandlerTest, Initialize) { - Initialize("dummy", "dummy_pwd"); -} - TEST_F(RTCPeerConnectionHandlerTest, CreateOffer) { WebKit::WebRTCSessionDescriptionRequest request; WebKit::WebMediaConstraints options; |