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 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DEPENDENCY_FACTORY_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DEPENDENCY_FACTORY_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DEPENDENCY_FACTORY_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DEPENDENCY_FACTORY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/threading/thread.h" | |
12 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
14 #include "content/renderer/p2p/socket_dispatcher.h" | |
13 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h " | 15 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h " |
14 | 16 |
17 namespace base { | |
18 class WaitableEvent; | |
19 } | |
20 | |
15 namespace content { | 21 namespace content { |
16 class IpcNetworkManager; | 22 class IpcNetworkManager; |
17 class IpcPacketSocketFactory; | 23 class IpcPacketSocketFactory; |
18 class P2PSocketDispatcher; | |
19 } | |
20 | |
21 namespace cricket { | |
22 class PortAllocator; | |
23 } | 24 } |
24 | 25 |
25 namespace talk_base { | 26 namespace talk_base { |
26 class NetworkManager; | 27 class NetworkManager; |
27 class PacketSocketFactory; | 28 class PacketSocketFactory; |
28 class Thread; | 29 class Thread; |
29 } | 30 } |
30 | 31 |
31 namespace webrtc { | 32 namespace webrtc { |
32 class PeerConnection; | 33 class PeerConnection; |
33 class VideoCaptureModule; | |
34 } | 34 } |
35 | 35 |
36 namespace WebKit { | |
37 class WebMediaStreamDescriptor; | |
38 class WebPeerConnection00Handler; | |
39 class WebPeerConnection00HandlerClient; | |
40 } | |
41 | |
42 class WebRtcAudioDeviceImpl; | |
36 class VideoCaptureImplManager; | 43 class VideoCaptureImplManager; |
37 class WebRtcAudioDeviceImpl; | |
38 | 44 |
39 // Object factory for MediaStreamImpl and PeerConnectionHandler. | 45 // Object factory for RTC MediaStreams and RTC PeerConnections. |
40 class CONTENT_EXPORT MediaStreamDependencyFactory { | 46 class CONTENT_EXPORT MediaStreamDependencyFactory |
47 : NON_EXPORTED_BASE(public base::NonThreadSafe) { | |
41 public: | 48 public: |
42 explicit MediaStreamDependencyFactory(VideoCaptureImplManager* vc_manager); | 49 MediaStreamDependencyFactory( |
50 VideoCaptureImplManager* vc_manager, | |
51 content::P2PSocketDispatcher* p2p_socket_dispatcher); | |
43 virtual ~MediaStreamDependencyFactory(); | 52 virtual ~MediaStreamDependencyFactory(); |
44 | 53 |
45 // Creates and deletes |pc_factory_|, which in turn is used for | 54 // Create a a PeerConnectionHandlerJsep object that implements the |
46 // creating PeerConnection objects. | 55 // WebKit WebPeerConnection00Handler interface. |
47 virtual bool CreatePeerConnectionFactory( | 56 WebKit::WebPeerConnection00Handler* CreatePeerConnectionHandlerJsep( |
48 talk_base::Thread* worker_thread, | 57 WebKit::WebPeerConnection00HandlerClient* client); |
49 talk_base::Thread* signaling_thread, | |
50 content::P2PSocketDispatcher* socket_dispatcher, | |
51 talk_base::NetworkManager* network_manager, | |
52 talk_base::PacketSocketFactory* socket_factory); | |
53 virtual void ReleasePeerConnectionFactory(); | |
54 virtual bool PeerConnectionFactoryCreated(); | |
55 | 58 |
56 // Asks the PeerConnection factory to create a PeerConnection object. | 59 // Creates a libjingle representation of a MediaStream and stores |
60 // it in the extra data field of |description| | |
61 bool CreateNativeLocalMediaStream( | |
62 WebKit::WebMediaStreamDescriptor* description); | |
63 | |
64 // Asks the libjingle PeerConnection factory to create a libjingle | |
65 // PeerConnection object. | |
57 // The PeerConnection object is owned by PeerConnectionHandler. | 66 // The PeerConnection object is owned by PeerConnectionHandler. |
58 virtual talk_base::scoped_refptr<webrtc::PeerConnectionInterface> | 67 virtual talk_base::scoped_refptr<webrtc::PeerConnectionInterface> |
59 CreatePeerConnection(const std::string& config, | 68 CreatePeerConnection(const std::string& config, |
60 webrtc::PeerConnectionObserver* observer); | 69 webrtc::PeerConnectionObserver* observer); |
61 | 70 |
71 // Creates a libjingle representation of a Session description. | |
72 virtual webrtc::SessionDescriptionInterface* CreateSessionDescription( | |
73 const std::string& sdp); | |
74 | |
75 // Creates a libjingle representation of an ice candidate. | |
76 virtual webrtc::IceCandidateInterface* CreateIceCandidate( | |
77 const std::string& sdp_mid, | |
78 int sdp_mline_index, | |
79 const std::string& sdp); | |
80 | |
tommi (sloooow) - chröme
2012/09/12 13:10:24
only one space
perkj_chrome
2012/09/12 13:54:39
Done.
| |
81 | |
82 protected: | |
62 // Asks the PeerConnection factory to create a Local MediaStream object. | 83 // Asks the PeerConnection factory to create a Local MediaStream object. |
63 virtual talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> | 84 virtual talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> |
64 CreateLocalMediaStream(const std::string& label); | 85 CreateLocalMediaStream(const std::string& label); |
65 | 86 |
66 // Asks the PeerConnection factory to create a Local VideoTrack object. | 87 // Asks the PeerConnection factory to create a Local VideoTrack object. |
67 virtual talk_base::scoped_refptr<webrtc::LocalVideoTrackInterface> | 88 virtual talk_base::scoped_refptr<webrtc::LocalVideoTrackInterface> |
68 CreateLocalVideoTrack(const std::string& label, | 89 CreateLocalVideoTrack(const std::string& label, |
69 int video_session_id); | 90 int video_session_id); |
70 | 91 |
71 // Asks the PeerConnection factory to create a Local AudioTrack object. | 92 // Asks the PeerConnection factory to create a Local AudioTrack object. |
72 virtual talk_base::scoped_refptr<webrtc::LocalAudioTrackInterface> | 93 virtual talk_base::scoped_refptr<webrtc::LocalAudioTrackInterface> |
73 CreateLocalAudioTrack(const std::string& label, | 94 CreateLocalAudioTrack(const std::string& label, |
74 webrtc::AudioDeviceModule* audio_device); | 95 webrtc::AudioDeviceModule* audio_device); |
75 | 96 |
76 virtual webrtc::SessionDescriptionInterface* CreateSessionDescription( | 97 virtual bool EnsurePeerConnectionFactory(); |
77 const std::string& sdp); | |
78 virtual webrtc::IceCandidateInterface* CreateIceCandidate( | |
79 const std::string& sdp_mid, | |
80 int sdp_mline_index, | |
81 const std::string& sdp); | |
82 | |
83 virtual void SetAudioDeviceSessionId(int session_id); | 98 virtual void SetAudioDeviceSessionId(int session_id); |
84 | 99 |
85 private: | 100 private: |
101 // Creates and deletes |pc_factory_|, which in turn is used for | |
102 // creating PeerConnection objects. | |
103 bool CreatePeerConnectionFactory( | |
104 talk_base::Thread* worker_thread, | |
105 talk_base::Thread* signaling_thread, | |
106 content::P2PSocketDispatcher* socket_dispatcher, | |
107 talk_base::NetworkManager* network_manager, | |
108 talk_base::PacketSocketFactory* socket_factory); | |
109 bool PeerConnectionFactoryCreated(); | |
110 | |
111 void InitializeWorkerThread(talk_base::Thread** thread, | |
112 base::WaitableEvent* event); | |
113 | |
114 void CreateIpcNetworkManagerOnWorkerThread(base::WaitableEvent* event); | |
115 void DeleteIpcNetworkManager(); | |
116 void CleanupPeerConnectionFactory(); | |
117 | |
118 // We own network_manager_, must be deleted on the worker thread. | |
119 // The network manager uses |p2p_socket_dispatcher_|. | |
120 content::IpcNetworkManager* network_manager_; | |
121 scoped_ptr<content::IpcPacketSocketFactory> socket_factory_; | |
122 | |
86 talk_base::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; | 123 talk_base::scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; |
124 | |
87 scoped_refptr<VideoCaptureImplManager> vc_manager_; | 125 scoped_refptr<VideoCaptureImplManager> vc_manager_; |
126 scoped_refptr<content::P2PSocketDispatcher> p2p_socket_dispatcher_; | |
tommi (sloooow) - chröme
2012/09/12 13:10:24
can we always fetch this from the render thread pe
perkj_chrome
2012/09/12 13:54:39
It would be hard to test using the mock_dependency
| |
88 scoped_refptr<WebRtcAudioDeviceImpl> audio_device_; | 127 scoped_refptr<WebRtcAudioDeviceImpl> audio_device_; |
89 | 128 |
129 // PeerConnection threads. signaling_thread_ is created from the | |
130 // "current" chrome thread. | |
131 talk_base::Thread* signaling_thread_; | |
132 talk_base::Thread* worker_thread_; | |
133 base::Thread chrome_worker_thread_; | |
134 | |
90 DISALLOW_COPY_AND_ASSIGN(MediaStreamDependencyFactory); | 135 DISALLOW_COPY_AND_ASSIGN(MediaStreamDependencyFactory); |
91 }; | 136 }; |
92 | 137 |
93 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DEPENDENCY_FACTORY_H_ | 138 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DEPENDENCY_FACTORY_H_ |
OLD | NEW |