OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DEPENDENCY_FACTORY_H_ | |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DEPENDENCY_FACTORY_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/files/file.h" | |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/threading/thread.h" | |
14 #include "content/common/content_export.h" | |
15 #include "content/public/renderer/render_process_observer.h" | |
16 #include "content/renderer/p2p/socket_dispatcher.h" | |
17 #include "ipc/ipc_platform_file.h" | |
18 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h
" | |
19 #include "third_party/libjingle/source/talk/app/webrtc/videosourceinterface.h" | |
20 | |
21 namespace base { | |
22 class WaitableEvent; | |
23 } | |
24 | |
25 namespace talk_base { | |
26 class NetworkManager; | |
27 class PacketSocketFactory; | |
28 class Thread; | |
29 } | |
30 | |
31 namespace blink { | |
32 class WebFrame; | |
33 class WebMediaConstraints; | |
34 class WebMediaStream; | |
35 class WebMediaStreamSource; | |
36 class WebMediaStreamTrack; | |
37 class WebRTCPeerConnectionHandler; | |
38 class WebRTCPeerConnectionHandlerClient; | |
39 } | |
40 | |
41 namespace content { | |
42 | |
43 class IpcNetworkManager; | |
44 class IpcPacketSocketFactory; | |
45 class MediaStreamAudioSource; | |
46 class RTCMediaConstraints; | |
47 class WebAudioCapturerSource; | |
48 class WebRtcAudioCapturer; | |
49 class WebRtcAudioDeviceImpl; | |
50 class WebRtcLocalAudioTrack; | |
51 class WebRtcLoggingHandlerImpl; | |
52 class WebRtcLoggingMessageFilter; | |
53 class WebRtcVideoCapturerAdapter; | |
54 struct StreamDeviceInfo; | |
55 | |
56 // Object factory for RTC MediaStreams and RTC PeerConnections. | |
57 class CONTENT_EXPORT MediaStreamDependencyFactory | |
58 : NON_EXPORTED_BASE(public base::NonThreadSafe), | |
59 public RenderProcessObserver { | |
60 public: | |
61 // MediaSourcesCreatedCallback is used in CreateNativeMediaSources. | |
62 typedef base::Callback<void(blink::WebMediaStream* web_stream, | |
63 bool live)> MediaSourcesCreatedCallback; | |
64 MediaStreamDependencyFactory( | |
65 P2PSocketDispatcher* p2p_socket_dispatcher); | |
66 virtual ~MediaStreamDependencyFactory(); | |
67 | |
68 // Create a RTCPeerConnectionHandler object that implements the | |
69 // WebKit WebRTCPeerConnectionHandler interface. | |
70 blink::WebRTCPeerConnectionHandler* CreateRTCPeerConnectionHandler( | |
71 blink::WebRTCPeerConnectionHandlerClient* client); | |
72 | |
73 // Asks the PeerConnection factory to create a Local MediaStream object. | |
74 virtual scoped_refptr<webrtc::MediaStreamInterface> | |
75 CreateLocalMediaStream(const std::string& label); | |
76 | |
77 // InitializeMediaStreamAudioSource initialize a MediaStream source object | |
78 // for audio input. | |
79 bool InitializeMediaStreamAudioSource( | |
80 int render_view_id, | |
81 const blink::WebMediaConstraints& audio_constraints, | |
82 MediaStreamAudioSource* source_data); | |
83 | |
84 // Creates an implementation of a cricket::VideoCapturer object that can be | |
85 // used when creating a libjingle webrtc::VideoSourceInterface object. | |
86 virtual WebRtcVideoCapturerAdapter* CreateVideoCapturer( | |
87 bool is_screen_capture); | |
88 | |
89 // Create an instance of WebRtcLocalAudioTrack and store it | |
90 // in the extraData field of |track|. | |
91 void CreateLocalAudioTrack(const blink::WebMediaStreamTrack& track); | |
92 | |
93 // Asks the PeerConnection factory to create a Local VideoTrack object. | |
94 virtual scoped_refptr<webrtc::VideoTrackInterface> | |
95 CreateLocalVideoTrack(const std::string& id, | |
96 webrtc::VideoSourceInterface* source); | |
97 | |
98 // Asks the PeerConnection factory to create a Video Source. | |
99 // The video source takes ownership of |capturer|. | |
100 virtual scoped_refptr<webrtc::VideoSourceInterface> | |
101 CreateVideoSource(cricket::VideoCapturer* capturer, | |
102 const blink::WebMediaConstraints& constraints); | |
103 | |
104 // Asks the libjingle PeerConnection factory to create a libjingle | |
105 // PeerConnection object. | |
106 // The PeerConnection object is owned by PeerConnectionHandler. | |
107 virtual scoped_refptr<webrtc::PeerConnectionInterface> | |
108 CreatePeerConnection( | |
109 const webrtc::PeerConnectionInterface::IceServers& ice_servers, | |
110 const webrtc::MediaConstraintsInterface* constraints, | |
111 blink::WebFrame* web_frame, | |
112 webrtc::PeerConnectionObserver* observer); | |
113 | |
114 // Creates a libjingle representation of a Session description. Used by a | |
115 // RTCPeerConnectionHandler instance. | |
116 virtual webrtc::SessionDescriptionInterface* CreateSessionDescription( | |
117 const std::string& type, | |
118 const std::string& sdp, | |
119 webrtc::SdpParseError* error); | |
120 | |
121 // Creates a libjingle representation of an ice candidate. | |
122 virtual webrtc::IceCandidateInterface* CreateIceCandidate( | |
123 const std::string& sdp_mid, | |
124 int sdp_mline_index, | |
125 const std::string& sdp); | |
126 | |
127 WebRtcAudioDeviceImpl* GetWebRtcAudioDevice(); | |
128 | |
129 static void AddNativeAudioTrackToBlinkTrack( | |
130 webrtc::MediaStreamTrackInterface* native_track, | |
131 const blink::WebMediaStreamTrack& webkit_track, | |
132 bool is_local_track); | |
133 | |
134 scoped_refptr<base::MessageLoopProxy> GetWebRtcWorkerThread() const; | |
135 | |
136 protected: | |
137 // Asks the PeerConnection factory to create a Local Audio Source. | |
138 virtual scoped_refptr<webrtc::AudioSourceInterface> | |
139 CreateLocalAudioSource( | |
140 const webrtc::MediaConstraintsInterface* constraints); | |
141 | |
142 // Creates a media::AudioCapturerSource with an implementation that is | |
143 // specific for a WebAudio source. The created WebAudioCapturerSource | |
144 // instance will function as audio source instead of the default | |
145 // WebRtcAudioCapturer. | |
146 virtual scoped_refptr<WebAudioCapturerSource> CreateWebAudioSource( | |
147 blink::WebMediaStreamSource* source); | |
148 | |
149 // Asks the PeerConnection factory to create a Local VideoTrack object with | |
150 // the video source using |capturer|. | |
151 virtual scoped_refptr<webrtc::VideoTrackInterface> | |
152 CreateLocalVideoTrack(const std::string& id, | |
153 cricket::VideoCapturer* capturer); | |
154 | |
155 virtual const scoped_refptr<webrtc::PeerConnectionFactoryInterface>& | |
156 GetPcFactory(); | |
157 virtual bool PeerConnectionFactoryCreated(); | |
158 | |
159 // Returns a new capturer or existing capturer based on the |render_view_id| | |
160 // and |device_info|. When the |render_view_id| and |device_info| are valid, | |
161 // it reuses existing capture if any; otherwise it creates a new capturer. | |
162 virtual scoped_refptr<WebRtcAudioCapturer> CreateAudioCapturer( | |
163 int render_view_id, const StreamDeviceInfo& device_info, | |
164 const blink::WebMediaConstraints& constraints, | |
165 MediaStreamAudioSource* audio_source); | |
166 | |
167 // Adds the audio device as a sink to the audio track and starts the local | |
168 // audio track. This is virtual for test purposes since no real audio device | |
169 // exist in unit tests. | |
170 virtual void StartLocalAudioTrack(WebRtcLocalAudioTrack* audio_track); | |
171 | |
172 private: | |
173 // Creates |pc_factory_|, which in turn is used for | |
174 // creating PeerConnection objects. | |
175 void CreatePeerConnectionFactory(); | |
176 | |
177 void InitializeWorkerThread(talk_base::Thread** thread, | |
178 base::WaitableEvent* event); | |
179 | |
180 void CreateIpcNetworkManagerOnWorkerThread(base::WaitableEvent* event); | |
181 void DeleteIpcNetworkManager(); | |
182 void CleanupPeerConnectionFactory(); | |
183 | |
184 // RenderProcessObserver implementation. | |
185 virtual bool OnControlMessageReceived(const IPC::Message& message) OVERRIDE; | |
186 | |
187 void OnAecDumpFile(IPC::PlatformFileForTransit file_handle); | |
188 void OnDisableAecDump(); | |
189 | |
190 void StartAecDump(base::File aec_dump_file); | |
191 | |
192 // Helper method to create a WebRtcAudioDeviceImpl. | |
193 void EnsureWebRtcAudioDeviceImpl(); | |
194 | |
195 // We own network_manager_, must be deleted on the worker thread. | |
196 // The network manager uses |p2p_socket_dispatcher_|. | |
197 IpcNetworkManager* network_manager_; | |
198 scoped_ptr<IpcPacketSocketFactory> socket_factory_; | |
199 | |
200 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; | |
201 | |
202 scoped_refptr<P2PSocketDispatcher> p2p_socket_dispatcher_; | |
203 scoped_refptr<WebRtcAudioDeviceImpl> audio_device_; | |
204 | |
205 // PeerConnection threads. signaling_thread_ is created from the | |
206 // "current" chrome thread. | |
207 talk_base::Thread* signaling_thread_; | |
208 talk_base::Thread* worker_thread_; | |
209 base::Thread chrome_worker_thread_; | |
210 | |
211 base::File aec_dump_file_; | |
212 | |
213 DISALLOW_COPY_AND_ASSIGN(MediaStreamDependencyFactory); | |
214 }; | |
215 | |
216 } // namespace content | |
217 | |
218 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DEPENDENCY_FACTORY_H_ | |
OLD | NEW |