OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_STREAM_MEDIA_STREAM_IMPL_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
6 #define CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
| 7 |
| 8 #include <list> |
| 9 #include <map> |
| 10 #include <string> |
7 | 11 |
8 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/gtest_prod_util.h" |
9 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/message_loop_proxy.h" |
| 17 #include "base/threading/thread.h" |
| 18 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaRequest.h
" |
10 #include "webkit/media/media_stream_client.h" | 21 #include "webkit/media/media_stream_client.h" |
11 | 22 |
| 23 namespace base { |
| 24 class WaitableEvent; |
| 25 } |
| 26 |
| 27 namespace content { |
| 28 class IpcNetworkManager; |
| 29 class IpcPacketSocketFactory; |
| 30 class P2PSocketDispatcher; |
| 31 } |
| 32 |
| 33 namespace cricket { |
| 34 class WebRtcMediaEngine; |
| 35 } |
| 36 |
| 37 namespace talk_base { |
| 38 class Thread; |
| 39 } |
| 40 |
| 41 namespace WebKit { |
| 42 class WebPeerConnectionHandler; |
| 43 class WebPeerConnectionHandlerClient; |
| 44 } |
| 45 |
| 46 class MediaStreamDispatcher; |
| 47 class MediaStreamDependencyFactory; |
| 48 class PeerConnectionHandler; |
12 class VideoCaptureImplManager; | 49 class VideoCaptureImplManager; |
| 50 class RTCVideoDecoder; |
13 | 51 |
14 // A implementation of StreamClient to provide supporting functions, such as | 52 // MediaStreamImpl is a delegate for the Media Stream API messages used by |
15 // GetVideoDecoder. | 53 // WebKit. It ties together WebKit, native PeerConnection in libjingle and |
| 54 // MediaStreamManager (via MediaStreamDispatcher and MediaStreamDispatcherHost) |
| 55 // in the browser process. |
16 class MediaStreamImpl | 56 class MediaStreamImpl |
17 : public webkit_media::MediaStreamClient, | 57 : public WebKit::WebUserMediaClient, |
| 58 public webkit_media::MediaStreamClient, |
| 59 public MediaStreamDispatcherEventHandler, |
18 public base::RefCountedThreadSafe<MediaStreamImpl> { | 60 public base::RefCountedThreadSafe<MediaStreamImpl> { |
19 public: | 61 public: |
20 explicit MediaStreamImpl(VideoCaptureImplManager* vc_manager); | 62 MediaStreamImpl( |
| 63 MediaStreamDispatcher* media_stream_dispatcher, |
| 64 content::P2PSocketDispatcher* p2p_socket_dispatcher, |
| 65 VideoCaptureImplManager* vc_manager, |
| 66 MediaStreamDependencyFactory* dependency_factory); |
21 virtual ~MediaStreamImpl(); | 67 virtual ~MediaStreamImpl(); |
22 | 68 |
23 // Implement webkit_media::StreamClient. | 69 virtual WebKit::WebPeerConnectionHandler* CreatePeerConnectionHandler( |
| 70 WebKit::WebPeerConnectionHandlerClient* client); |
| 71 virtual void ClosePeerConnection(); |
| 72 |
| 73 // Returns true if created successfully or already exists, false otherwise. |
| 74 virtual bool SetVideoCaptureModule(const std::string& label); |
| 75 |
| 76 // WebKit::WebUserMediaClient implementation |
| 77 virtual void requestUserMedia( |
| 78 const WebKit::WebUserMediaRequest& user_media_request, |
| 79 const WebKit::WebVector<WebKit::WebMediaStreamSource>& |
| 80 media_stream_source_vector) OVERRIDE; |
| 81 virtual void cancelUserMediaRequest( |
| 82 const WebKit::WebUserMediaRequest& user_media_request) OVERRIDE; |
| 83 |
| 84 // webkit_media::MediaStreamClient implementation. |
24 virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder( | 85 virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder( |
25 const GURL& url, | 86 const GURL& url, |
26 media::MessageLoopFactory* message_loop_factory) OVERRIDE; | 87 media::MessageLoopFactory* message_loop_factory) OVERRIDE; |
27 | 88 |
| 89 // MediaStreamDispatcherEventHandler implementation. |
| 90 virtual void OnStreamGenerated( |
| 91 int request_id, |
| 92 const std::string& label, |
| 93 const media_stream::StreamDeviceInfoArray& audio_array, |
| 94 const media_stream::StreamDeviceInfoArray& video_array) OVERRIDE; |
| 95 virtual void OnStreamGenerationFailed(int request_id) OVERRIDE; |
| 96 virtual void OnVideoDeviceFailed( |
| 97 const std::string& label, |
| 98 int index) OVERRIDE; |
| 99 virtual void OnAudioDeviceFailed( |
| 100 const std::string& label, |
| 101 int index) OVERRIDE; |
| 102 |
28 private: | 103 private: |
| 104 FRIEND_TEST_ALL_PREFIXES(MediaStreamImplTest, Basic); |
| 105 |
| 106 void InitializeWorkerThread( |
| 107 talk_base::Thread** thread, |
| 108 base::WaitableEvent* event); |
| 109 void DeleteIpcNetworkManager(base::WaitableEvent* event); |
| 110 |
| 111 scoped_ptr<MediaStreamDependencyFactory> dependency_factory_; |
| 112 |
| 113 // media_stream_dispatcher_ is a weak reference, owned by RenderView. It's |
| 114 // valid for the lifetime of RenderView. |
| 115 MediaStreamDispatcher* media_stream_dispatcher_; |
| 116 |
| 117 // media_engine_ is owned by PeerConnectionFactory (which is owned by |
| 118 // dependency_factory_) and is valid for the lifetime of |
| 119 // PeerConnectionFactory. |
| 120 cricket::WebRtcMediaEngine* media_engine_; |
| 121 |
| 122 // p2p_socket_dispatcher_ is a weak reference, owned by RenderView. It's valid |
| 123 // for the lifetime of RenderView. |
| 124 content::P2PSocketDispatcher* p2p_socket_dispatcher_; |
| 125 |
| 126 // We own network_manager_, must be deleted on the worker thread. |
| 127 content::IpcNetworkManager* network_manager_; |
| 128 |
| 129 scoped_ptr<content::IpcPacketSocketFactory> socket_factory_; |
| 130 |
29 scoped_refptr<VideoCaptureImplManager> vc_manager_; | 131 scoped_refptr<VideoCaptureImplManager> vc_manager_; |
30 | 132 |
| 133 // peer_connection_handler_ is a weak reference, owned by WebKit. It's valid |
| 134 // until stop is called on it (which will call ClosePeerConnection on us). |
| 135 // TODO(grunell): Support several PeerConnectionsHandlers. |
| 136 PeerConnectionHandler* peer_connection_handler_; |
| 137 |
| 138 scoped_refptr<RTCVideoDecoder> rtc_video_decoder_; |
| 139 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 140 |
| 141 // PeerConnection threads. signaling_thread_ is created from the |
| 142 // "current" chrome thread. |
| 143 talk_base::Thread* signaling_thread_; |
| 144 talk_base::Thread* worker_thread_; |
| 145 base::Thread chrome_worker_thread_; |
| 146 |
| 147 static int next_request_id_; |
| 148 typedef std::map<int, WebKit::WebUserMediaRequest> MediaRequestMap; |
| 149 MediaRequestMap user_media_requests_; |
| 150 |
| 151 std::list<std::string> stream_labels_; |
| 152 |
| 153 // Make sure we only create the video capture module once. This is also |
| 154 // temporary and will be handled differently when several PeerConnections |
| 155 // and/or streams is supported. |
| 156 // TODO(grunell): This shall be removed or changed when native PeerConnection |
| 157 // has been updated to closer follow the specification. |
| 158 bool vcm_created_; |
| 159 |
31 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); | 160 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); |
32 }; | 161 }; |
33 | 162 |
34 #endif // CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ | 163 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
OLD | NEW |