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_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
19 #include "base/message_loop_proxy.h" | 19 #include "base/message_loop_proxy.h" |
20 #include "base/threading/non_thread_safe.h" | 20 #include "base/threading/non_thread_safe.h" |
21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
22 #include "content/common/content_export.h" | 22 #include "content/common/content_export.h" |
23 #include "content/public/renderer/render_view_observer.h" | 23 #include "content/public/renderer/render_view_observer.h" |
24 #include "content/renderer/media/media_stream_extra_data.h" | 24 #include "content/renderer/media/media_stream_extra_data.h" |
25 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 25 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
26 #include "content/renderer/media/rtc_video_decoder.h" | 26 #include "content/renderer/media/rtc_video_decoder.h" |
| 27 #include "content/renderer/p2p/socket_dispatcher.h" |
27 #include "third_party/libjingle/source/talk/app/webrtc/mediastream.h" | 28 #include "third_party/libjingle/source/talk/app/webrtc/mediastream.h" |
28 #include "third_party/libjingle/source/talk/base/scoped_ref_ptr.h" | 29 #include "third_party/libjingle/source/talk/base/scoped_ref_ptr.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaRequest.h
" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaRequest.h
" |
31 #include "webkit/media/media_stream_client.h" | 32 #include "webkit/media/media_stream_client.h" |
32 | 33 |
33 namespace base { | 34 namespace base { |
34 class WaitableEvent; | 35 class WaitableEvent; |
35 } | 36 } |
36 | 37 |
37 namespace content { | 38 namespace content { |
38 class IpcNetworkManager; | 39 class IpcNetworkManager; |
39 class IpcPacketSocketFactory; | 40 class IpcPacketSocketFactory; |
40 class P2PSocketDispatcher; | |
41 } | 41 } |
42 | 42 |
43 namespace talk_base { | 43 namespace talk_base { |
44 class Thread; | 44 class Thread; |
45 } | 45 } |
46 | 46 |
47 namespace WebKit { | 47 namespace WebKit { |
48 class WebFrame; | 48 class WebFrame; |
49 class WebMediaStreamComponent; | 49 class WebMediaStreamComponent; |
50 class WebMediaStreamDescriptor; | 50 class WebMediaStreamDescriptor; |
(...skipping 16 matching lines...) Expand all Loading... |
67 // render thread. | 67 // render thread. |
68 // MediaStreamImpl have weak pointers to a P2PSocketDispatcher and a | 68 // MediaStreamImpl have weak pointers to a P2PSocketDispatcher and a |
69 // MediaStreamDispatcher. These objects are also RenderViewObservers. | 69 // MediaStreamDispatcher. These objects are also RenderViewObservers. |
70 // MediaStreamImpl must be deleted before the P2PSocketDispatcher. | 70 // MediaStreamImpl must be deleted before the P2PSocketDispatcher. |
71 class CONTENT_EXPORT MediaStreamImpl | 71 class CONTENT_EXPORT MediaStreamImpl |
72 : public content::RenderViewObserver, | 72 : public content::RenderViewObserver, |
73 NON_EXPORTED_BASE(public WebKit::WebUserMediaClient), | 73 NON_EXPORTED_BASE(public WebKit::WebUserMediaClient), |
74 NON_EXPORTED_BASE(public webkit_media::MediaStreamClient), | 74 NON_EXPORTED_BASE(public webkit_media::MediaStreamClient), |
75 public MediaStreamDispatcherEventHandler, | 75 public MediaStreamDispatcherEventHandler, |
76 public base::SupportsWeakPtr<MediaStreamImpl>, | 76 public base::SupportsWeakPtr<MediaStreamImpl>, |
| 77 NON_EXPORTED_BASE(public content::P2PSocketDispatcherDestructionObserver), |
77 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 78 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
78 public: | 79 public: |
79 MediaStreamImpl( | 80 MediaStreamImpl( |
80 content::RenderView* render_view, | 81 content::RenderView* render_view, |
81 MediaStreamDispatcher* media_stream_dispatcher, | 82 MediaStreamDispatcher* media_stream_dispatcher, |
82 content::P2PSocketDispatcher* p2p_socket_dispatcher, | 83 content::P2PSocketDispatcher* p2p_socket_dispatcher, |
83 VideoCaptureImplManager* vc_manager, | 84 VideoCaptureImplManager* vc_manager, |
84 MediaStreamDependencyFactory* dependency_factory); | 85 MediaStreamDependencyFactory* dependency_factory); |
85 virtual ~MediaStreamImpl(); | 86 virtual ~MediaStreamImpl(); |
86 | 87 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 virtual void OnDevicesEnumerationFailed(int request_id) OVERRIDE; | 131 virtual void OnDevicesEnumerationFailed(int request_id) OVERRIDE; |
131 virtual void OnDeviceOpened( | 132 virtual void OnDeviceOpened( |
132 int request_id, | 133 int request_id, |
133 const std::string& label, | 134 const std::string& label, |
134 const media_stream::StreamDeviceInfo& device_info) OVERRIDE; | 135 const media_stream::StreamDeviceInfo& device_info) OVERRIDE; |
135 virtual void OnDeviceOpenFailed(int request_id) OVERRIDE; | 136 virtual void OnDeviceOpenFailed(int request_id) OVERRIDE; |
136 | 137 |
137 // content::RenderViewObserver OVERRIDE | 138 // content::RenderViewObserver OVERRIDE |
138 virtual void FrameWillClose(WebKit::WebFrame* frame) OVERRIDE; | 139 virtual void FrameWillClose(WebKit::WebFrame* frame) OVERRIDE; |
139 | 140 |
| 141 // content P2PSocketDispatcherDestructionObserver implementation. |
| 142 // This is needed since all IpcNetworkManager must be deleted before the |
| 143 // P2PSocketDispatcher is destroyed. MediaStreamImpl owns a IpcNetworkManager. |
| 144 virtual void OnSocketDispatcherDestroyed() OVERRIDE; |
| 145 |
140 protected: | 146 protected: |
141 // This function is virtual for test purposes. A test can override this to | 147 // This function is virtual for test purposes. A test can override this to |
142 // test requesting local media streams. The function notifies WebKit that the | 148 // test requesting local media streams. The function notifies WebKit that the |
143 // |request| have completed and generated the MediaStream |stream|. | 149 // |request| have completed and generated the MediaStream |stream|. |
144 virtual void CompleteGetUserMediaRequest( | 150 virtual void CompleteGetUserMediaRequest( |
145 const WebKit::WebMediaStreamDescriptor& stream, | 151 const WebKit::WebMediaStreamDescriptor& stream, |
146 WebKit::WebUserMediaRequest* request); | 152 WebKit::WebUserMediaRequest* request); |
147 // This function is virtual for test purposes. | 153 // This function is virtual for test purposes. |
148 // Returns the WebKit representation of a MediaStream given an URL. | 154 // Returns the WebKit representation of a MediaStream given an URL. |
149 virtual WebKit::WebMediaStreamDescriptor GetMediaStream(const GURL& url); | 155 virtual WebKit::WebMediaStreamDescriptor GetMediaStream(const GURL& url); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 typedef talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> | 187 typedef talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> |
182 LocalNativeStreamPtr; | 188 LocalNativeStreamPtr; |
183 | 189 |
184 void InitializeWorkerThread(talk_base::Thread** thread, | 190 void InitializeWorkerThread(talk_base::Thread** thread, |
185 base::WaitableEvent* event); | 191 base::WaitableEvent* event); |
186 | 192 |
187 void CreateIpcNetworkManagerOnWorkerThread(base::WaitableEvent* event); | 193 void CreateIpcNetworkManagerOnWorkerThread(base::WaitableEvent* event); |
188 void DeleteIpcNetworkManager(); | 194 void DeleteIpcNetworkManager(); |
189 | 195 |
190 bool EnsurePeerConnectionFactory(); | 196 bool EnsurePeerConnectionFactory(); |
| 197 void CleanupPeerConnectionFactory(); |
191 | 198 |
192 PeerConnectionHandlerBase* FindPeerConnectionByStream( | 199 PeerConnectionHandlerBase* FindPeerConnectionByStream( |
193 const WebKit::WebMediaStreamDescriptor& stream); | 200 const WebKit::WebMediaStreamDescriptor& stream); |
194 scoped_refptr<media::VideoDecoder> CreateLocalVideoDecoder( | 201 scoped_refptr<media::VideoDecoder> CreateLocalVideoDecoder( |
195 webrtc::MediaStreamInterface* stream, | 202 webrtc::MediaStreamInterface* stream, |
196 media::MessageLoopFactory* message_loop_factory); | 203 media::MessageLoopFactory* message_loop_factory); |
197 scoped_refptr<media::VideoDecoder> CreateRemoteVideoDecoder( | 204 scoped_refptr<media::VideoDecoder> CreateRemoteVideoDecoder( |
198 webrtc::MediaStreamInterface* stream, | 205 webrtc::MediaStreamInterface* stream, |
199 const GURL& url, | 206 const GURL& url, |
200 media::MessageLoopFactory* message_loop_factory); | 207 media::MessageLoopFactory* message_loop_factory); |
(...skipping 25 matching lines...) Expand all Loading... |
226 // PeerConnection threads. signaling_thread_ is created from the | 233 // PeerConnection threads. signaling_thread_ is created from the |
227 // "current" chrome thread. | 234 // "current" chrome thread. |
228 talk_base::Thread* signaling_thread_; | 235 talk_base::Thread* signaling_thread_; |
229 talk_base::Thread* worker_thread_; | 236 talk_base::Thread* worker_thread_; |
230 base::Thread chrome_worker_thread_; | 237 base::Thread chrome_worker_thread_; |
231 | 238 |
232 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); | 239 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); |
233 }; | 240 }; |
234 | 241 |
235 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ | 242 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
OLD | NEW |