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