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 <map> |
| 9 #include <string> |
7 | 10 |
8 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/gtest_prod_util.h" |
9 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop_proxy.h" |
| 16 #include "base/threading/thread.h" |
| 17 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaClient.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebUserMediaRequest.h
" |
10 #include "webkit/glue/media/media_stream_client.h" | 20 #include "webkit/glue/media/media_stream_client.h" |
11 | 21 |
| 22 namespace base { |
| 23 class WaitableEvent; |
| 24 } |
| 25 |
| 26 namespace content { |
| 27 class IpcNetworkManager; |
| 28 class IpcPacketSocketFactory; |
| 29 class P2PSocketDispatcher; |
| 30 } |
| 31 |
| 32 namespace cricket { |
| 33 class HttpPortAllocator; |
| 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_glue::MediaStreamClient, | 57 : public WebKit::WebUserMediaClient, |
| 58 public webkit_glue::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_glue::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 userMediaControllerDestroyed(); |
| 78 virtual void requestUserMedia( |
| 79 const WebKit::WebUserMediaRequest& user_media_request); |
| 80 virtual void cancelUserMediaRequest( |
| 81 const WebKit::WebUserMediaRequest& user_media_request); |
| 82 |
| 83 // webkit_glue::MediaStreamClient implementation. |
24 virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder( | 84 virtual scoped_refptr<media::VideoDecoder> GetVideoDecoder( |
25 const GURL& url, media::MessageLoopFactory* message_loop_factory); | 85 const GURL& url, |
| 86 media::MessageLoopFactory* message_loop_factory) OVERRIDE; |
| 87 |
| 88 // MediaStreamDispatcherEventHandler implementation. |
| 89 virtual void OnStreamGenerated( |
| 90 int request_id, |
| 91 const std::string& label, |
| 92 const media_stream::StreamDeviceInfoArray& audio_array, |
| 93 const media_stream::StreamDeviceInfoArray& video_array) OVERRIDE; |
| 94 virtual void OnStreamGenerationFailed(int request_id) OVERRIDE; |
| 95 virtual void OnVideoDeviceFailed( |
| 96 const std::string& label, |
| 97 int index) OVERRIDE; |
| 98 virtual void OnAudioDeviceFailed( |
| 99 const std::string& label, |
| 100 int index) OVERRIDE; |
26 | 101 |
27 private: | 102 private: |
| 103 FRIEND_TEST(MediaStreamImplTest, Basic); |
| 104 |
| 105 void InitializeWorkerThread( |
| 106 talk_base::Thread** thread, |
| 107 base::WaitableEvent* event); |
| 108 |
| 109 // dependency_factory_ is owned by us. |
| 110 scoped_ptr<MediaStreamDependencyFactory> dependency_factory_; |
| 111 |
| 112 // media_stream_dispatcher_ is a weak reference, owned by RenderView. It's |
| 113 // valid for the lifetime of RenderView. |
| 114 MediaStreamDispatcher* media_stream_dispatcher_; |
| 115 |
| 116 // The media_engine_ is owned by pc_factory_ and is valid for the lifetime of |
| 117 // pc_factory_. |
| 118 cricket::WebRtcMediaEngine* media_engine_; |
| 119 |
| 120 // p2p_socket_dispatcher_ is a weak reference, owned by RenderView. It's valid |
| 121 // for the lifetime of RenderView. |
| 122 content::P2PSocketDispatcher* p2p_socket_dispatcher_; |
| 123 |
28 scoped_refptr<VideoCaptureImplManager> vc_manager_; | 124 scoped_refptr<VideoCaptureImplManager> vc_manager_; |
| 125 scoped_ptr<content::IpcNetworkManager> ipc_network_manager_; |
| 126 scoped_ptr<content::IpcPacketSocketFactory> ipc_socket_factory_; |
| 127 |
| 128 // peer_connection_handler_ is owned by us. |
| 129 // TODO(grunell): Support several PeerConnectionsHandlers. |
| 130 scoped_ptr<PeerConnectionHandler> peer_connection_handler_; |
| 131 |
| 132 scoped_refptr<RTCVideoDecoder> rtc_video_decoder_; |
| 133 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
| 134 |
| 135 // PeerConnection threads. signaling_thread_ is created from the |
| 136 // "current" chrome thread. |
| 137 talk_base::Thread* signaling_thread_; |
| 138 talk_base::Thread* worker_thread_; |
| 139 base::Thread chrome_worker_thread_; |
| 140 |
| 141 int request_id_counter_; |
| 142 typedef std::map<int, WebKit::WebUserMediaRequest> MediaRequestMap; |
| 143 MediaRequestMap user_media_requests_; |
| 144 |
| 145 // Make sure we only create the video capture module once. This is also |
| 146 // temporary and will be handled differently when several PeerConnections |
| 147 // and/or streams is supported. |
| 148 // TODO(grunell): This shall be removed or changed when native PeerConnection |
| 149 // has been updated to closer follow the specification. |
| 150 bool vcm_created_; |
29 | 151 |
30 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); | 152 DISALLOW_COPY_AND_ASSIGN(MediaStreamImpl); |
31 }; | 153 }; |
32 | 154 |
33 #endif // CONTENT_RENDERER_MEDIA_STREAM_MEDIA_STREAM_IMPL_H_ | 155 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_IMPL_H_ |
OLD | NEW |