Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/media_stream_dependency_factory.h" | 5 #include "content/renderer/media/media_stream_dependency_factory.h" |
| 6 | 6 |
| 7 #include <vector> | |
| 8 | |
| 7 #include "content/renderer/media/video_capture_module_impl.h" | 9 #include "content/renderer/media/video_capture_module_impl.h" |
| 8 #include "content/renderer/media/webrtc_audio_device_impl.h" | 10 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 9 #include "content/renderer/p2p/ipc_network_manager.h" | 11 #include "content/renderer/p2p/ipc_network_manager.h" |
| 10 #include "content/renderer/p2p/ipc_socket_factory.h" | 12 #include "content/renderer/p2p/ipc_socket_factory.h" |
| 11 #include "content/renderer/p2p/port_allocator.h" | 13 #include "content/renderer/p2p/port_allocator.h" |
| 12 #include "jingle/glue/thread_wrapper.h" | 14 #include "jingle/glue/thread_wrapper.h" |
| 13 #include "third_party/libjingle/source/talk/app/webrtcv1/peerconnection.h" | 15 #include "third_party/libjingle/source/talk/app/webrtc/peerconnection.h" |
| 14 #include "third_party/libjingle/source/talk/session/phone/dummydevicemanager.h" | |
| 15 #include "third_party/libjingle/source/talk/session/phone/webrtcmediaengine.h" | |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 17 | 17 |
| 18 static std::string GetAddress(const std::string& hostname) { | |
| 19 std::string address; | |
| 20 size_t pos = hostname.find(':'); | |
| 21 if (pos == std::string::npos) { | |
| 22 DVLOG(1) << "Invalid hostname."; | |
|
tommi (sloooow) - chröme
2012/01/24 15:18:56
is this correct? Feels like the hostname might be
Henrik Grunell
2012/01/26 13:03:16
Right. Fixed.
| |
| 23 } else { | |
| 24 address = hostname.substr(0, pos); | |
| 25 } | |
| 26 return address; | |
|
tommi (sloooow) - chröme
2012/01/24 15:18:56
nit: Change the name of the method to be GetHostNa
Henrik Grunell
2012/01/26 13:03:16
Done.
| |
| 27 } | |
| 28 | |
| 29 class P2PPortAllocatorFactory : public webrtc::PortAllocatorFactoryInterface { | |
| 30 public: | |
| 31 P2PPortAllocatorFactory(content::P2PSocketDispatcher* socket_dispatcher, | |
| 32 talk_base::NetworkManager* network_manager, | |
| 33 talk_base::PacketSocketFactory* socket_factory) | |
| 34 : socket_dispatcher_(socket_dispatcher), | |
| 35 network_manager_(network_manager), | |
| 36 socket_factory_(socket_factory) { | |
| 37 } | |
| 38 virtual cricket::PortAllocator* CreatePortAllocator( | |
| 39 const std::vector<StunConfiguration>& stun_servers, | |
| 40 const std::vector<TurnConfiguration>& turn_configurations) { | |
|
tommi (sloooow) - chröme
2012/01/24 15:18:56
don't forget to use OVERRIDE for all overridden vi
Henrik Grunell
2012/01/26 13:03:16
Done.
| |
| 41 WebKit::WebFrame* web_frame = WebKit::WebFrame::frameForCurrentContext(); | |
| 42 if (!web_frame) { | |
| 43 DVLOG(1) << "WebFrame is NULL."; | |
|
tommi (sloooow) - chröme
2012/01/24 15:18:56
warning/error?
Henrik Grunell
2012/01/26 13:03:16
Yes, I think it should be an error. Fixed.
| |
| 44 return NULL; | |
| 45 } | |
| 46 webkit_glue::P2PTransport::Config config; | |
| 47 // P2PPortAllocator only supports one set of config. | |
| 48 if (stun_servers.size() > 0) { | |
| 49 config.stun_server = GetAddress( | |
| 50 stun_servers[0].server.hostname()); | |
|
tommi (sloooow) - chröme
2012/01/24 15:18:56
instead of having to strip the port away from the
Henrik Grunell
2012/01/26 13:03:16
Yes I agree, but it's libjingle code that sets thi
| |
| 51 config.stun_server_port = stun_servers[0].server.port(); | |
| 52 } | |
| 53 if (turn_configurations.size() > 0) { | |
| 54 config.relay_server = GetAddress( | |
| 55 turn_configurations[0].server.hostname()); | |
| 56 config.relay_server_port = turn_configurations[0].server.port(); | |
| 57 config.relay_username = turn_configurations[0].username; | |
| 58 config.relay_password = turn_configurations[0].password; | |
| 59 } | |
| 60 | |
| 61 return new content::P2PPortAllocator(web_frame, | |
| 62 socket_dispatcher_, | |
| 63 network_manager_, | |
| 64 socket_factory_, | |
| 65 config); | |
| 66 } | |
| 67 | |
| 68 protected: | |
| 69 virtual ~P2PPortAllocatorFactory() {} | |
| 70 | |
| 71 private: | |
| 72 // socket_dispatcher_ is a weak reference, owned by RenderView. It's valid | |
| 73 // for the lifetime of RenderView. | |
| 74 content::P2PSocketDispatcher* socket_dispatcher_; | |
| 75 // network_manager_ and socket_factory_ are a weak references, owned by | |
| 76 // MediaStreamImpl. | |
| 77 talk_base::NetworkManager* network_manager_; | |
| 78 talk_base::PacketSocketFactory* socket_factory_; | |
| 79 }; | |
| 80 | |
| 81 | |
| 18 MediaStreamDependencyFactory::MediaStreamDependencyFactory() {} | 82 MediaStreamDependencyFactory::MediaStreamDependencyFactory() {} |
| 19 | 83 |
| 20 MediaStreamDependencyFactory::~MediaStreamDependencyFactory() {} | 84 MediaStreamDependencyFactory::~MediaStreamDependencyFactory() {} |
| 21 | 85 |
| 22 cricket::WebRtcMediaEngine* | 86 bool MediaStreamDependencyFactory::CreatePeerConnectionFactory( |
| 23 MediaStreamDependencyFactory::CreateWebRtcMediaEngine() { | 87 talk_base::Thread* worker_thread, |
| 24 webrtc::AudioDeviceModule* adm = new WebRtcAudioDeviceImpl(); | 88 talk_base::Thread* signaling_thread, |
| 25 webrtc::AudioDeviceModule* adm_sc = new WebRtcAudioDeviceImpl(); | 89 content::P2PSocketDispatcher* socket_dispatcher, |
| 26 return new cricket::WebRtcMediaEngine(adm, adm_sc, NULL); | 90 talk_base::NetworkManager* network_manager, |
| 27 } | 91 talk_base::PacketSocketFactory* socket_factory) { |
| 92 if (!pc_factory_.get()) { | |
| 93 talk_base::scoped_refptr<P2PPortAllocatorFactory> pa_factory = | |
| 94 new talk_base::RefCountedObject<P2PPortAllocatorFactory>( | |
|
tommi (sloooow) - chröme
2012/01/24 15:18:56
indent
Henrik Grunell
2012/01/26 13:03:16
Done.
| |
| 95 socket_dispatcher, network_manager, socket_factory); | |
| 28 | 96 |
| 29 bool MediaStreamDependencyFactory::CreatePeerConnectionFactory( | 97 talk_base::scoped_refptr<webrtc::PeerConnectionFactoryInterface> factory( |
| 30 cricket::MediaEngineInterface* media_engine, | 98 webrtc::CreatePeerConnectionFactory(worker_thread, |
| 31 talk_base::Thread* worker_thread) { | 99 signaling_thread, |
| 32 if (!pc_factory_.get()) { | 100 pa_factory.release(), |
| 33 scoped_ptr<webrtc::PeerConnectionFactory> factory( | 101 new WebRtcAudioDeviceImpl())); |
| 34 new webrtc::PeerConnectionFactory(media_engine, | 102 if (factory.get()) |
| 35 new cricket::DummyDeviceManager(), | 103 pc_factory_ = factory.release(); |
| 36 worker_thread)); | |
| 37 if (factory->Initialize()) | |
| 38 pc_factory_.reset(factory.release()); | |
| 39 } | 104 } |
| 40 return pc_factory_.get() != NULL; | 105 return pc_factory_.get() != NULL; |
| 41 } | 106 } |
| 42 | 107 |
| 43 void MediaStreamDependencyFactory::DeletePeerConnectionFactory() { | 108 void MediaStreamDependencyFactory::ReleasePeerConnectionFactory() { |
| 44 pc_factory_.reset(); | 109 if (pc_factory_.get()) |
| 110 pc_factory_.release(); | |
|
tommi (sloooow) - chröme
2012/01/24 15:18:56
hmm... are you sure that scoped_refptr.release() d
Henrik Grunell
2012/01/26 13:03:16
Indeed, complete brain loss. Fixed.
| |
| 45 } | 111 } |
| 46 | 112 |
| 47 bool MediaStreamDependencyFactory::PeerConnectionFactoryCreated() { | 113 bool MediaStreamDependencyFactory::PeerConnectionFactoryCreated() { |
| 48 return pc_factory_.get() != NULL; | 114 return pc_factory_.get() != NULL; |
| 49 } | 115 } |
| 50 | 116 |
| 51 cricket::PortAllocator* MediaStreamDependencyFactory::CreatePortAllocator( | 117 talk_base::scoped_refptr<webrtc::PeerConnectionInterface> |
|
tommi (sloooow) - chröme
2012/01/24 15:18:56
nit: add this at the top of the file to save a bit
Henrik Grunell
2012/01/26 13:03:16
Chrome's scoped_refptr is in the global namespace,
| |
| 52 content::P2PSocketDispatcher* socket_dispatcher, | 118 MediaStreamDependencyFactory::CreatePeerConnection( |
| 53 talk_base::NetworkManager* network_manager, | 119 const std::string& config, webrtc::PeerConnectionObserver* observer) { |
|
tommi (sloooow) - chröme
2012/01/24 15:18:56
does |config| fit in the line above?
Henrik Grunell
2012/01/26 13:03:16
Yes, but observer doesn't if aligned under. Not al
| |
| 54 talk_base::PacketSocketFactory* socket_factory, | 120 // TODO(grunell): Can we move this out to pc handler? |
| 55 const webkit_glue::P2PTransport::Config& config) { | 121 return pc_factory_->CreatePeerConnection(config, observer); |
| 56 WebKit::WebFrame* web_frame = WebKit::WebFrame::frameForCurrentContext(); | |
| 57 if (!web_frame) { | |
| 58 DVLOG(1) << "WebFrame is NULL."; | |
| 59 return NULL; | |
| 60 } | |
| 61 return new content::P2PPortAllocator(web_frame, | |
| 62 socket_dispatcher, | |
| 63 network_manager, | |
| 64 socket_factory, | |
| 65 config); | |
| 66 } | 122 } |
| 67 | 123 |
| 68 webrtc::PeerConnection* MediaStreamDependencyFactory::CreatePeerConnection( | 124 talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> |
| 69 cricket::PortAllocator* port_allocator, | 125 MediaStreamDependencyFactory::CreateLocalMediaStream( |
| 70 talk_base::Thread* signaling_thread) { | 126 const std::string& label) { |
| 71 return pc_factory_->CreatePeerConnection(port_allocator, signaling_thread); | 127 return pc_factory_->CreateLocalMediaStream(label); |
| 72 } | 128 } |
| 129 | |
| 130 talk_base::scoped_refptr<webrtc::LocalVideoTrackInterface> | |
| 131 MediaStreamDependencyFactory::CreateLocalVideoTrack( | |
| 132 const std::string& label, cricket::VideoCapturer* video_device) { | |
| 133 return pc_factory_->CreateLocalVideoTrack(label, video_device); | |
| 134 } | |
| 135 | |
| 136 talk_base::scoped_refptr<webrtc::LocalAudioTrackInterface> | |
| 137 MediaStreamDependencyFactory::CreateLocalAudioTrack( | |
| 138 const std::string& label, webrtc::AudioDeviceModule* audio_device) { | |
| 139 return pc_factory_->CreateLocalAudioTrack(label, audio_device); | |
| 140 } | |
| OLD | NEW |