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> | |
9 #include <map> | 8 #include <map> |
10 #include <string> | 9 #include <string> |
11 #include <utility> | |
12 | 10 |
13 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
14 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
15 #include "base/gtest_prod_util.h" | |
16 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
17 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
18 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
19 #include "base/message_loop_proxy.h" | |
20 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/non_thread_safe.h" |
21 #include "base/threading/thread.h" | |
22 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
23 #include "content/public/renderer/render_view_observer.h" | 18 #include "content/public/renderer/render_view_observer.h" |
24 #include "content/renderer/media/media_stream_extra_data.h" | |
25 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 19 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
26 #include "content/renderer/media/rtc_video_decoder.h" | |
27 #include "content/renderer/p2p/socket_dispatcher.h" | |
28 #include "third_party/libjingle/source/talk/app/webrtc/mediastream.h" | 20 #include "third_party/libjingle/source/talk/app/webrtc/mediastream.h" |
29 #include "third_party/libjingle/source/talk/base/scoped_ref_ptr.h" | 21 #include "third_party/libjingle/source/talk/base/scoped_ref_ptr.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h" |
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaRequest.h
" | 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaRequest.h
" |
32 #include "webkit/media/media_stream_client.h" | 24 #include "webkit/media/media_stream_client.h" |
33 | 25 |
34 namespace base { | |
35 class WaitableEvent; | |
36 } | |
37 | |
38 namespace content { | |
39 class IpcNetworkManager; | |
40 class IpcPacketSocketFactory; | |
41 } | |
42 | |
43 namespace talk_base { | |
44 class Thread; | |
45 } | |
46 | |
47 namespace WebKit { | 26 namespace WebKit { |
48 class WebFrame; | |
49 class WebMediaStreamComponent; | |
50 class WebMediaStreamDescriptor; | 27 class WebMediaStreamDescriptor; |
51 class WebPeerConnection00Handler; | |
52 class WebPeerConnection00HandlerClient; | |
53 class WebPeerConnectionHandler; | |
54 class WebPeerConnectionHandlerClient; | |
55 } | 28 } |
56 | 29 |
57 class MediaStreamDispatcher; | 30 class MediaStreamDispatcher; |
58 class MediaStreamDependencyFactory; | 31 class MediaStreamDependencyFactory; |
59 class PeerConnectionHandlerBase; | |
60 class VideoCaptureImplManager; | 32 class VideoCaptureImplManager; |
61 class RTCVideoDecoder; | |
62 | 33 |
63 // MediaStreamImpl is a delegate for the Media Stream API messages used by | 34 // MediaStreamImpl is a delegate for the Media Stream API messages used by |
64 // WebKit. It ties together WebKit, native PeerConnection in libjingle and | 35 // WebKit. It ties together WebKit, native PeerConnection in libjingle and |
65 // MediaStreamManager (via MediaStreamDispatcher and MediaStreamDispatcherHost) | 36 // MediaStreamManager (via MediaStreamDispatcher and MediaStreamDispatcherHost) |
66 // in the browser process. It must be created, called and destroyed on the | 37 // in the browser process. It must be created, called and destroyed on the |
67 // render thread. | 38 // render thread. |
68 // MediaStreamImpl have weak pointers to a P2PSocketDispatcher and a | 39 // MediaStreamImpl have weak pointers to a MediaStreamDispatcher. |
69 // MediaStreamDispatcher. These objects are also RenderViewObservers. | |
70 // MediaStreamImpl must be deleted before the P2PSocketDispatcher. | |
71 class CONTENT_EXPORT MediaStreamImpl | 40 class CONTENT_EXPORT MediaStreamImpl |
72 : public content::RenderViewObserver, | 41 : public content::RenderViewObserver, |
73 NON_EXPORTED_BASE(public WebKit::WebUserMediaClient), | 42 NON_EXPORTED_BASE(public WebKit::WebUserMediaClient), |
74 NON_EXPORTED_BASE(public webkit_media::MediaStreamClient), | 43 NON_EXPORTED_BASE(public webkit_media::MediaStreamClient), |
75 public MediaStreamDispatcherEventHandler, | 44 public MediaStreamDispatcherEventHandler, |
76 public base::SupportsWeakPtr<MediaStreamImpl>, | 45 public base::SupportsWeakPtr<MediaStreamImpl>, |
77 NON_EXPORTED_BASE(public base::NonThreadSafe) { | 46 NON_EXPORTED_BASE(public base::NonThreadSafe) { |
78 public: | 47 public: |
79 MediaStreamImpl( | 48 MediaStreamImpl( |
80 content::RenderView* render_view, | 49 content::RenderView* render_view, |
81 MediaStreamDispatcher* media_stream_dispatcher, | 50 MediaStreamDispatcher* media_stream_dispatcher, |
82 content::P2PSocketDispatcher* p2p_socket_dispatcher, | |
83 VideoCaptureImplManager* vc_manager, | 51 VideoCaptureImplManager* vc_manager, |
84 MediaStreamDependencyFactory* dependency_factory); | 52 MediaStreamDependencyFactory* dependency_factory); |
85 virtual ~MediaStreamImpl(); | 53 virtual ~MediaStreamImpl(); |
86 | 54 |
87 virtual WebKit::WebPeerConnection00Handler* CreatePeerConnectionHandlerJsep( | |
88 WebKit::WebPeerConnection00HandlerClient* client); | |
89 // Stops a local MediaStream by notifying the MediaStreamDispatcher that the | 55 // Stops a local MediaStream by notifying the MediaStreamDispatcher that the |
90 // stream no longer may be used. | 56 // stream no longer may be used. |
91 virtual void StopLocalMediaStream( | 57 virtual void StopLocalMediaStream( |
92 const WebKit::WebMediaStreamDescriptor& stream); | 58 const WebKit::WebMediaStreamDescriptor& stream); |
93 // A new MediaStream have been created based on existing tracks. | |
94 virtual void CreateMediaStream( | |
95 WebKit::WebFrame* frame, | |
96 WebKit::WebMediaStreamDescriptor* stream); | |
97 | 59 |
98 // WebKit::WebUserMediaClient implementation | 60 // WebKit::WebUserMediaClient implementation |
99 virtual void requestUserMedia( | 61 virtual void requestUserMedia( |
100 const WebKit::WebUserMediaRequest& user_media_request, | 62 const WebKit::WebUserMediaRequest& user_media_request, |
101 const WebKit::WebVector<WebKit::WebMediaStreamSource>& audio_sources, | 63 const WebKit::WebVector<WebKit::WebMediaStreamSource>& audio_sources, |
102 const WebKit::WebVector<WebKit::WebMediaStreamSource>& video_sources) | 64 const WebKit::WebVector<WebKit::WebMediaStreamSource>& video_sources) |
103 OVERRIDE; | 65 OVERRIDE; |
104 virtual void cancelUserMediaRequest( | 66 virtual void cancelUserMediaRequest( |
105 const WebKit::WebUserMediaRequest& user_media_request) OVERRIDE; | 67 const WebKit::WebUserMediaRequest& user_media_request) OVERRIDE; |
106 | 68 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 WebKit::WebUserMediaRequest request_; | 120 WebKit::WebUserMediaRequest request_; |
159 }; | 121 }; |
160 typedef std::map<int, UserMediaRequestInfo> MediaRequestMap; | 122 typedef std::map<int, UserMediaRequestInfo> MediaRequestMap; |
161 | 123 |
162 // We keep a list of the label and WebFrame of generated local media streams, | 124 // We keep a list of the label and WebFrame of generated local media streams, |
163 // so that we can stop them when needed. | 125 // so that we can stop them when needed. |
164 typedef std::map<std::string, WebKit::WebFrame*> LocalNativeStreamMap; | 126 typedef std::map<std::string, WebKit::WebFrame*> LocalNativeStreamMap; |
165 typedef talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> | 127 typedef talk_base::scoped_refptr<webrtc::LocalMediaStreamInterface> |
166 LocalNativeStreamPtr; | 128 LocalNativeStreamPtr; |
167 | 129 |
168 void InitializeWorkerThread(talk_base::Thread** thread, | |
169 base::WaitableEvent* event); | |
170 | |
171 void CreateIpcNetworkManagerOnWorkerThread(base::WaitableEvent* event); | |
172 void DeleteIpcNetworkManager(); | |
173 | |
174 bool EnsurePeerConnectionFactory(); | |
175 void CleanupPeerConnectionFactory(); | |
176 | |
177 scoped_refptr<media::VideoDecoder> CreateLocalVideoDecoder( | 130 scoped_refptr<media::VideoDecoder> CreateLocalVideoDecoder( |
178 webrtc::MediaStreamInterface* stream, | 131 webrtc::MediaStreamInterface* stream, |
179 media::MessageLoopFactory* message_loop_factory); | 132 media::MessageLoopFactory* message_loop_factory); |
180 scoped_refptr<media::VideoDecoder> CreateRemoteVideoDecoder( | 133 scoped_refptr<media::VideoDecoder> CreateRemoteVideoDecoder( |
181 webrtc::MediaStreamInterface* stream, | 134 webrtc::MediaStreamInterface* stream, |
182 media::MessageLoopFactory* message_loop_factory); | 135 media::MessageLoopFactory* message_loop_factory); |
183 bool CreateNativeLocalMediaStream( | |
184 WebKit::WebMediaStreamDescriptor* description); | |
185 | 136 |
186 scoped_ptr<MediaStreamDependencyFactory> dependency_factory_; | 137 // Weak ref to a MediaStreamDependencyFactory, owned by the RenderThread. |
| 138 // It's valid for the lifetime of RenderThread. |
| 139 MediaStreamDependencyFactory* dependency_factory_; |
187 | 140 |
188 // media_stream_dispatcher_ is a weak reference, owned by RenderView. It's | 141 // media_stream_dispatcher_ is a weak reference, owned by RenderView. It's |
189 // valid for the lifetime of RenderView. | 142 // valid for the lifetime of RenderView. |
190 MediaStreamDispatcher* media_stream_dispatcher_; | 143 MediaStreamDispatcher* media_stream_dispatcher_; |
191 | 144 |
192 scoped_refptr<content::P2PSocketDispatcher> p2p_socket_dispatcher_; | |
193 | |
194 // We own network_manager_, must be deleted on the worker thread. | |
195 // The network manager uses |p2p_socket_dispatcher_|. | |
196 content::IpcNetworkManager* network_manager_; | |
197 scoped_ptr<content::IpcPacketSocketFactory> socket_factory_; | |
198 scoped_refptr<VideoCaptureImplManager> vc_manager_; | 145 scoped_refptr<VideoCaptureImplManager> vc_manager_; |
199 | 146 |
200 MediaRequestMap user_media_requests_; | 147 MediaRequestMap user_media_requests_; |
201 LocalNativeStreamMap local_media_streams_; | 148 LocalNativeStreamMap local_media_streams_; |
202 | 149 |
203 // PeerConnection threads. signaling_thread_ is created from the | |
204 // "current" chrome thread. | |
205 talk_base::Thread* signaling_thread_; | |
206 talk_base::Thread* worker_thread_; | |
207 base::Thread chrome_worker_thread_; | |
208 | |
209 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); | 150 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); |
210 }; | 151 }; |
211 | 152 |
212 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ | 153 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
OLD | NEW |