OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_WEBRTC_PEER_CONNECTION_DEPENDENCY_FACTORY_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_DEPENDENCY_FACTORY_H_ |
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_DEPENDENCY_FACTORY_H_ | 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_DEPENDENCY_FACTORY_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/files/file.h" | 10 #include "base/files/file.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 class WebMediaStreamSource; | 40 class WebMediaStreamSource; |
41 class WebMediaStreamTrack; | 41 class WebMediaStreamTrack; |
42 class WebRTCPeerConnectionHandler; | 42 class WebRTCPeerConnectionHandler; |
43 class WebRTCPeerConnectionHandlerClient; | 43 class WebRTCPeerConnectionHandlerClient; |
44 } | 44 } |
45 | 45 |
46 namespace content { | 46 namespace content { |
47 | 47 |
48 class IpcNetworkManager; | 48 class IpcNetworkManager; |
49 class IpcPacketSocketFactory; | 49 class IpcPacketSocketFactory; |
50 class MediaStreamAudioSource; | |
51 class WebAudioCapturerSource; | |
52 class WebRtcAudioCapturer; | |
53 class WebRtcAudioDeviceImpl; | 50 class WebRtcAudioDeviceImpl; |
54 class WebRtcLocalAudioTrack; | |
55 class WebRtcLoggingHandlerImpl; | 51 class WebRtcLoggingHandlerImpl; |
56 class WebRtcLoggingMessageFilter; | 52 class WebRtcLoggingMessageFilter; |
57 class WebRtcVideoCapturerAdapter; | 53 class WebRtcVideoCapturerAdapter; |
58 struct StreamDeviceInfo; | 54 struct StreamDeviceInfo; |
59 | 55 |
60 // Object factory for RTC PeerConnections. | 56 // Object factory for RTC PeerConnections. |
61 class CONTENT_EXPORT PeerConnectionDependencyFactory | 57 class CONTENT_EXPORT PeerConnectionDependencyFactory |
62 : NON_EXPORTED_BASE(base::MessageLoop::DestructionObserver), | 58 : NON_EXPORTED_BASE(base::MessageLoop::DestructionObserver), |
63 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 59 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
64 public: | 60 public: |
65 PeerConnectionDependencyFactory( | 61 PeerConnectionDependencyFactory( |
66 P2PSocketDispatcher* p2p_socket_dispatcher); | 62 P2PSocketDispatcher* p2p_socket_dispatcher); |
67 ~PeerConnectionDependencyFactory() override; | 63 ~PeerConnectionDependencyFactory() override; |
68 | 64 |
69 // Create a RTCPeerConnectionHandler object that implements the | 65 // Create a RTCPeerConnectionHandler object that implements the |
70 // WebKit WebRTCPeerConnectionHandler interface. | 66 // WebKit WebRTCPeerConnectionHandler interface. |
71 blink::WebRTCPeerConnectionHandler* CreateRTCPeerConnectionHandler( | 67 blink::WebRTCPeerConnectionHandler* CreateRTCPeerConnectionHandler( |
72 blink::WebRTCPeerConnectionHandlerClient* client); | 68 blink::WebRTCPeerConnectionHandlerClient* client); |
73 | 69 |
74 // Generate an ECDSA certificate. | 70 // Generate an ECDSA certificate. |
75 static rtc::scoped_refptr<rtc::RTCCertificate> GenerateDefaultCertificate(); | 71 static rtc::scoped_refptr<rtc::RTCCertificate> GenerateDefaultCertificate(); |
76 | 72 |
77 // Asks the PeerConnection factory to create a Local MediaStream object. | 73 // Asks the PeerConnection factory to create a Local MediaStream object. |
78 virtual scoped_refptr<webrtc::MediaStreamInterface> | 74 virtual scoped_refptr<webrtc::MediaStreamInterface> |
79 CreateLocalMediaStream(const std::string& label); | 75 CreateLocalMediaStream(const std::string& label); |
80 | 76 |
81 // InitializeMediaStreamAudioSource initialize a MediaStream source object | |
82 // for audio input. | |
83 bool InitializeMediaStreamAudioSource( | |
84 int render_frame_id, | |
85 const blink::WebMediaConstraints& audio_constraints, | |
86 MediaStreamAudioSource* source_data); | |
87 | |
88 // Creates an implementation of a cricket::VideoCapturer object that can be | 77 // Creates an implementation of a cricket::VideoCapturer object that can be |
89 // used when creating a libjingle webrtc::VideoTrackSourceInterface object. | 78 // used when creating a libjingle webrtc::VideoTrackSourceInterface object. |
90 virtual WebRtcVideoCapturerAdapter* CreateVideoCapturer( | 79 virtual WebRtcVideoCapturerAdapter* CreateVideoCapturer( |
91 bool is_screen_capture); | 80 bool is_screen_capture); |
92 | 81 |
93 // Creates an instance of WebRtcLocalAudioTrack and stores it | |
94 // in the extraData field of |track|. | |
95 void CreateLocalAudioTrack(const blink::WebMediaStreamTrack& track); | |
96 | |
97 // Creates an instance of MediaStreamRemoteAudioTrack and associates with the | |
98 // |track| object. | |
99 void CreateRemoteAudioTrack(const blink::WebMediaStreamTrack& track); | |
100 | |
101 // Asks the PeerConnection factory to create a Local VideoTrack object. | 82 // Asks the PeerConnection factory to create a Local VideoTrack object. |
102 virtual scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack( | 83 virtual scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack( |
103 const std::string& id, | 84 const std::string& id, |
104 webrtc::VideoTrackSourceInterface* source); | 85 webrtc::VideoTrackSourceInterface* source); |
105 | 86 |
106 // Asks the PeerConnection factory to create a Video Source. | 87 // Asks the PeerConnection factory to create a Video Source. |
107 // The video source takes ownership of |capturer|. | 88 // The video source takes ownership of |capturer|. |
108 virtual scoped_refptr<webrtc::VideoTrackSourceInterface> CreateVideoSource( | 89 virtual scoped_refptr<webrtc::VideoTrackSourceInterface> CreateVideoSource( |
109 cricket::VideoCapturer* capturer); | 90 cricket::VideoCapturer* capturer); |
110 | 91 |
(...skipping 22 matching lines...) Expand all Loading... |
133 // Starts recording an RTC event log. | 114 // Starts recording an RTC event log. |
134 virtual bool StartRtcEventLog(base::PlatformFile file); | 115 virtual bool StartRtcEventLog(base::PlatformFile file); |
135 | 116 |
136 // Starts recording an RTC event log. | 117 // Starts recording an RTC event log. |
137 virtual void StopRtcEventLog(); | 118 virtual void StopRtcEventLog(); |
138 | 119 |
139 WebRtcAudioDeviceImpl* GetWebRtcAudioDevice(); | 120 WebRtcAudioDeviceImpl* GetWebRtcAudioDevice(); |
140 | 121 |
141 void EnsureInitialized(); | 122 void EnsureInitialized(); |
142 scoped_refptr<base::SingleThreadTaskRunner> GetWebRtcWorkerThread() const; | 123 scoped_refptr<base::SingleThreadTaskRunner> GetWebRtcWorkerThread() const; |
143 scoped_refptr<base::SingleThreadTaskRunner> GetWebRtcSignalingThread() const; | 124 virtual scoped_refptr<base::SingleThreadTaskRunner> GetWebRtcSignalingThread() |
| 125 const; |
144 | 126 |
145 protected: | 127 // Called by ProcessedLocalAudioSource to have the PeerConnection factory |
146 // Asks the PeerConnection factory to create a Local Audio Source. | 128 // create the corresponding WebRtc-internal instance. |
147 virtual scoped_refptr<webrtc::AudioSourceInterface> CreateLocalAudioSource( | 129 virtual scoped_refptr<webrtc::AudioSourceInterface> CreateLocalAudioSource( |
148 const cricket::AudioOptions& options); | 130 const cricket::AudioOptions& options); |
149 | 131 |
150 // Creates a media::AudioCapturerSource with an implementation that is | 132 protected: |
151 // specific for a WebAudio source. The created WebAudioCapturerSource | |
152 // instance will function as audio source instead of the default | |
153 // WebRtcAudioCapturer. Ownership of the new WebAudioCapturerSource is | |
154 // transferred to |source|. | |
155 virtual void CreateWebAudioSource(blink::WebMediaStreamSource* source); | |
156 | |
157 // Asks the PeerConnection factory to create a Local VideoTrack object with | 133 // Asks the PeerConnection factory to create a Local VideoTrack object with |
158 // the video source using |capturer|. | 134 // the video source using |capturer|. |
159 virtual scoped_refptr<webrtc::VideoTrackInterface> | 135 virtual scoped_refptr<webrtc::VideoTrackInterface> |
160 CreateLocalVideoTrack(const std::string& id, | 136 CreateLocalVideoTrack(const std::string& id, |
161 cricket::VideoCapturer* capturer); | 137 cricket::VideoCapturer* capturer); |
162 | 138 |
163 virtual const scoped_refptr<webrtc::PeerConnectionFactoryInterface>& | 139 virtual const scoped_refptr<webrtc::PeerConnectionFactoryInterface>& |
164 GetPcFactory(); | 140 GetPcFactory(); |
165 virtual bool PeerConnectionFactoryCreated(); | 141 virtual bool PeerConnectionFactoryCreated(); |
166 | 142 |
167 // Returns a new capturer or existing capturer based on the |render_frame_id| | 143 // Helper method to create a WebRtcAudioDeviceImpl. |
168 // and |device_info|; if both are valid, it reuses existing capture if any -- | 144 void EnsureWebRtcAudioDeviceImpl(); |
169 // otherwise it creates a new capturer. | |
170 virtual std::unique_ptr<WebRtcAudioCapturer> CreateAudioCapturer( | |
171 int render_frame_id, | |
172 const StreamDeviceInfo& device_info, | |
173 const blink::WebMediaConstraints& constraints, | |
174 MediaStreamAudioSource* audio_source); | |
175 | 145 |
176 private: | 146 private: |
177 // Implement base::MessageLoop::DestructionObserver. | 147 // Implement base::MessageLoop::DestructionObserver. |
178 // This makes sure the libjingle PeerConnectionFactory is released before | 148 // This makes sure the libjingle PeerConnectionFactory is released before |
179 // the renderer message loop is destroyed. | 149 // the renderer message loop is destroyed. |
180 void WillDestroyCurrentMessageLoop() override; | 150 void WillDestroyCurrentMessageLoop() override; |
181 | 151 |
182 // Functions related to Stun probing trial to determine how fast we could send | 152 // Functions related to Stun probing trial to determine how fast we could send |
183 // Stun request without being dropped by NAT. | 153 // Stun request without being dropped by NAT. |
184 void TryScheduleStunProbeTrial(); | 154 void TryScheduleStunProbeTrial(); |
185 void StartStunProbeTrialOnWorkerThread(const std::string& params); | 155 void StartStunProbeTrialOnWorkerThread(const std::string& params); |
186 | 156 |
187 // Creates |pc_factory_|, which in turn is used for | 157 // Creates |pc_factory_|, which in turn is used for |
188 // creating PeerConnection objects. | 158 // creating PeerConnection objects. |
189 void CreatePeerConnectionFactory(); | 159 void CreatePeerConnectionFactory(); |
190 | 160 |
191 void InitializeSignalingThread( | 161 void InitializeSignalingThread( |
192 media::GpuVideoAcceleratorFactories* gpu_factories, | 162 media::GpuVideoAcceleratorFactories* gpu_factories, |
193 base::WaitableEvent* event); | 163 base::WaitableEvent* event); |
194 | 164 |
195 void InitializeWorkerThread(rtc::Thread** thread, | 165 void InitializeWorkerThread(rtc::Thread** thread, |
196 base::WaitableEvent* event); | 166 base::WaitableEvent* event); |
197 | 167 |
198 void CreateIpcNetworkManagerOnWorkerThread(base::WaitableEvent* event); | 168 void CreateIpcNetworkManagerOnWorkerThread(base::WaitableEvent* event); |
199 void DeleteIpcNetworkManager(); | 169 void DeleteIpcNetworkManager(); |
200 void CleanupPeerConnectionFactory(); | 170 void CleanupPeerConnectionFactory(); |
201 | 171 |
202 // Helper method to create a WebRtcAudioDeviceImpl. | |
203 void EnsureWebRtcAudioDeviceImpl(); | |
204 | |
205 // We own network_manager_, must be deleted on the worker thread. | 172 // We own network_manager_, must be deleted on the worker thread. |
206 // The network manager uses |p2p_socket_dispatcher_|. | 173 // The network manager uses |p2p_socket_dispatcher_|. |
207 IpcNetworkManager* network_manager_; | 174 IpcNetworkManager* network_manager_; |
208 std::unique_ptr<IpcPacketSocketFactory> socket_factory_; | 175 std::unique_ptr<IpcPacketSocketFactory> socket_factory_; |
209 | 176 |
210 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; | 177 scoped_refptr<webrtc::PeerConnectionFactoryInterface> pc_factory_; |
211 | 178 |
212 scoped_refptr<P2PSocketDispatcher> p2p_socket_dispatcher_; | 179 scoped_refptr<P2PSocketDispatcher> p2p_socket_dispatcher_; |
213 scoped_refptr<WebRtcAudioDeviceImpl> audio_device_; | 180 scoped_refptr<WebRtcAudioDeviceImpl> audio_device_; |
214 | 181 |
215 std::unique_ptr<StunProberTrial> stun_trial_; | 182 std::unique_ptr<StunProberTrial> stun_trial_; |
216 | 183 |
217 // PeerConnection threads. signaling_thread_ is created from the | 184 // PeerConnection threads. signaling_thread_ is created from the |
218 // "current" chrome thread. | 185 // "current" chrome thread. |
219 rtc::Thread* signaling_thread_; | 186 rtc::Thread* signaling_thread_; |
220 rtc::Thread* worker_thread_; | 187 rtc::Thread* worker_thread_; |
221 base::Thread chrome_signaling_thread_; | 188 base::Thread chrome_signaling_thread_; |
222 base::Thread chrome_worker_thread_; | 189 base::Thread chrome_worker_thread_; |
223 | 190 |
224 DISALLOW_COPY_AND_ASSIGN(PeerConnectionDependencyFactory); | 191 DISALLOW_COPY_AND_ASSIGN(PeerConnectionDependencyFactory); |
225 }; | 192 }; |
226 | 193 |
227 } // namespace content | 194 } // namespace content |
228 | 195 |
229 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_DEPENDENCY_FACTORY_H_ | 196 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_PEER_CONNECTION_DEPENDENCY_FACTORY_H_ |
OLD | NEW |