Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: content/browser/renderer_host/media/media_stream_manager.h

Issue 13989003: Replace MediaStreamUIController with MediaStreamUIProxy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // MediaStreamManager is used to open/enumerate media capture devices (video 5 // MediaStreamManager is used to open/enumerate media capture devices (video
6 // supported now). Call flow: 6 // supported now). Call flow:
7 // 1. GenerateStream is called when a render process wants to use a capture 7 // 1. GenerateStream is called when a render process wants to use a capture
8 // device. 8 // device.
9 // 2. MediaStreamManager will ask MediaStreamUIController for permission to 9 // 2. MediaStreamManager will ask MediaStreamUIController for permission to
10 // use devices and for which device to use. 10 // use devices and for which device to use.
(...skipping 14 matching lines...) Expand all
25 25
26 #include <map> 26 #include <map>
27 #include <string> 27 #include <string>
28 28
29 #include "base/basictypes.h" 29 #include "base/basictypes.h"
30 #include "base/memory/scoped_ptr.h" 30 #include "base/memory/scoped_ptr.h"
31 #include "base/memory/ref_counted.h" 31 #include "base/memory/ref_counted.h"
32 #include "base/message_loop.h" 32 #include "base/message_loop.h"
33 #include "base/system_monitor/system_monitor.h" 33 #include "base/system_monitor/system_monitor.h"
34 #include "content/browser/renderer_host/media/media_stream_provider.h" 34 #include "content/browser/renderer_host/media/media_stream_provider.h"
35 #include "content/browser/renderer_host/media/media_stream_settings_requester.h"
36 #include "content/common/media/media_stream_options.h" 35 #include "content/common/media/media_stream_options.h"
37 #include "content/common/content_export.h" 36 #include "content/common/content_export.h"
38 37
39 namespace base { 38 namespace base {
40 class Thread; 39 class Thread;
41 } 40 }
42 41
43 namespace media { 42 namespace media {
44 class AudioManager; 43 class AudioManager;
45 } 44 }
46 45
47 namespace content { 46 namespace content {
48 47
49 class AudioInputDeviceManager; 48 class AudioInputDeviceManager;
50 class MediaStreamDeviceSettings; 49 class MediaStreamDeviceSettings;
51 class MediaStreamRequester; 50 class MediaStreamRequester;
52 class MediaStreamUIController; 51 class MediaStreamUIProxy;
53 class VideoCaptureManager; 52 class VideoCaptureManager;
54 53
55 // MediaStreamManager is used to generate and close new media devices, not to 54 // MediaStreamManager is used to generate and close new media devices, not to
56 // start the media flow. 55 // start the media flow.
57 // The classes requesting new media streams are answered using 56 // The classes requesting new media streams are answered using
58 // MediaStreamManager::Listener. 57 // MediaStreamManager::Listener.
59 class CONTENT_EXPORT MediaStreamManager 58 class CONTENT_EXPORT MediaStreamManager
60 : public MediaStreamProviderListener, 59 : public MediaStreamProviderListener,
61 public MessageLoop::DestructionObserver, 60 public MessageLoop::DestructionObserver,
62 public SettingsRequester,
63 public base::SystemMonitor::DevicesChangedObserver { 61 public base::SystemMonitor::DevicesChangedObserver {
64 public: 62 public:
63 // Callback to deliver the result of a media request. |label| is the string
64 // to identify the request,
65 typedef base::Callback<void(const MediaStreamDevices& devices,
66 scoped_ptr<MediaStreamUIProxy> ui)>
67 MediaRequestResponseCallback;
68
65 explicit MediaStreamManager(media::AudioManager* audio_manager); 69 explicit MediaStreamManager(media::AudioManager* audio_manager);
66 virtual ~MediaStreamManager(); 70 virtual ~MediaStreamManager();
67 71
68 // Used to access VideoCaptureManager. 72 // Used to access VideoCaptureManager.
69 VideoCaptureManager* video_capture_manager(); 73 VideoCaptureManager* video_capture_manager();
70 74
71 // Used to access AudioInputDeviceManager. 75 // Used to access AudioInputDeviceManager.
72 AudioInputDeviceManager* audio_input_device_manager(); 76 AudioInputDeviceManager* audio_input_device_manager();
73 77
74 // Creates a new media access request which is identified by a unique string 78 // Creates a new media access request which is identified by a unique string
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // Open a device identified by |device_id|. |type| must be either 119 // Open a device identified by |device_id|. |type| must be either
116 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. 120 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE.
117 // The request is identified using string returned to the caller. 121 // The request is identified using string returned to the caller.
118 std::string OpenDevice(MediaStreamRequester* requester, 122 std::string OpenDevice(MediaStreamRequester* requester,
119 int render_process_id, 123 int render_process_id,
120 int render_view_id, 124 int render_view_id,
121 const std::string& device_id, 125 const std::string& device_id,
122 MediaStreamType type, 126 MediaStreamType type,
123 const GURL& security_origin); 127 const GURL& security_origin);
124 128
125 // Signals the UI that the devices are opened.
126 // Users are responsible for calling NotifyUIDevicesClosed when the devices
127 // are not used anymore, otherwise UI will leak.
128 void NotifyUIDevicesOpened(const std::string& label);
129
130 // Signals the UI that the devices are being closed.
131 void NotifyUIDevicesClosed(const std::string& label);
132
133 // Implements MediaStreamProviderListener. 129 // Implements MediaStreamProviderListener.
134 virtual void Opened(MediaStreamType stream_type, 130 virtual void Opened(MediaStreamType stream_type,
135 int capture_session_id) OVERRIDE; 131 int capture_session_id) OVERRIDE;
136 virtual void Closed(MediaStreamType stream_type, 132 virtual void Closed(MediaStreamType stream_type,
137 int capture_session_id) OVERRIDE; 133 int capture_session_id) OVERRIDE;
138 virtual void DevicesEnumerated(MediaStreamType stream_type, 134 virtual void DevicesEnumerated(MediaStreamType stream_type,
139 const StreamDeviceInfoArray& devices) OVERRIDE; 135 const StreamDeviceInfoArray& devices) OVERRIDE;
140 virtual void Error(MediaStreamType stream_type, 136 virtual void Error(MediaStreamType stream_type,
141 int capture_session_id, 137 int capture_session_id,
142 MediaStreamProviderError error) OVERRIDE; 138 MediaStreamProviderError error) OVERRIDE;
143 139
144 // Implements SettingsRequester.
145 virtual void DevicesAccepted(const std::string& label,
146 const StreamDeviceInfoArray& devices) OVERRIDE;
147 virtual void SettingsError(const std::string& label) OVERRIDE;
148 virtual void StopStreamFromUI(const std::string& label) OVERRIDE;
149 virtual void GetAvailableDevices(MediaStreamDevices* devices) OVERRIDE;
150
151 // Implements base::SystemMonitor::DevicesChangedObserver. 140 // Implements base::SystemMonitor::DevicesChangedObserver.
152 virtual void OnDevicesChanged( 141 virtual void OnDevicesChanged(
153 base::SystemMonitor::DeviceType device_type) OVERRIDE; 142 base::SystemMonitor::DeviceType device_type) OVERRIDE;
154 143
155 // Used by unit test to make sure fake devices are used instead of a real 144 // Used by unit test to make sure fake devices are used instead of a real
156 // devices, which is needed for server based testing. 145 // devices, which is needed for server based testing.
157 void UseFakeDevice(); 146 void UseFakeDevice();
158 147
159 // Called by the unittests to specify fake UI that should be used for next 148 // Called by the unittests to specify fake UI that should be used for next
160 // generated stream. 149 // generated stream.
161 void UseFakeUI(scoped_ptr<MediaStreamUI> fake_ui); 150 void UseFakeUI(scoped_ptr<MediaStreamUIProxy> fake_ui);
162 151
163 // This object gets deleted on the UI thread after the IO thread has been 152 // This object gets deleted on the UI thread after the IO thread has been
164 // destroyed. So we need to know when IO thread is being destroyed so that 153 // destroyed. So we need to know when IO thread is being destroyed so that
165 // we can delete VideoCaptureManager and AudioInputDeviceManager. 154 // we can delete VideoCaptureManager and AudioInputDeviceManager.
166 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; 155 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
167 156
168 private: 157 private:
169 // Contains all data needed to keep track of requests. 158 // Contains all data needed to keep track of requests.
170 class DeviceRequest; 159 class DeviceRequest;
171 160
(...skipping 10 matching lines...) Expand all
182 171
183 // Initializes the device managers on IO thread. Auto-starts the device 172 // Initializes the device managers on IO thread. Auto-starts the device
184 // thread and registers this as a listener with the device managers. 173 // thread and registers this as a listener with the device managers.
185 void InitializeDeviceManagersOnIOThread(); 174 void InitializeDeviceManagersOnIOThread();
186 175
187 // Helper for sending up-to-date device lists to media observer when a 176 // Helper for sending up-to-date device lists to media observer when a
188 // capture device is plugged in or unplugged. 177 // capture device is plugged in or unplugged.
189 void NotifyDevicesChanged(MediaStreamType stream_type, 178 void NotifyDevicesChanged(MediaStreamType stream_type,
190 const StreamDeviceInfoArray& devices); 179 const StreamDeviceInfoArray& devices);
191 180
181
182 void HandleAccessRequestResponse(const std::string& label,
183 const MediaStreamDevices& devices);
184 void StopStreamFromUI(const std::string& label);
185
192 // Helpers. 186 // Helpers.
193 bool RequestDone(const DeviceRequest& request) const; 187 bool RequestDone(const DeviceRequest& request) const;
194 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); 188 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type);
195 void StartEnumeration(DeviceRequest* request); 189 void StartEnumeration(DeviceRequest* request);
196 std::string AddRequest(DeviceRequest* request); 190 std::string AddRequest(DeviceRequest* request);
197 void RemoveRequest(DeviceRequests::iterator it); 191 void RemoveRequest(DeviceRequests::iterator it);
198 void ClearEnumerationCache(EnumerationCache* cache); 192 void ClearEnumerationCache(EnumerationCache* cache);
199 void PostRequestToUI(const std::string& label); 193 void PostRequestToUI(const std::string& label);
200 void HandleRequest(const std::string& label); 194 void HandleRequest(const std::string& label);
201 195
202 // Sends cached device list to a client corresponding to the request 196 // Sends cached device list to a client corresponding to the request
203 // identified by |label|. 197 // identified by |label|.
204 void SendCachedDeviceList(EnumerationCache* cache, const std::string& label); 198 void SendCachedDeviceList(EnumerationCache* cache, const std::string& label);
205 199
206 // Stop the request of enumerating devices indentified by |label|. 200 // Stop the request of enumerating devices indentified by |label|.
207 void StopEnumerateDevices(const std::string& label); 201 void StopEnumerateDevices(const std::string& label);
208 202
209 // Helpers to start and stop monitoring devices. 203 // Helpers to start and stop monitoring devices.
210 void StartMonitoring(); 204 void StartMonitoring();
211 void StopMonitoring(); 205 void StopMonitoring();
212 206
213 // Callback for UI called when the user requests stream with the specified
214 // |label| to be stopped.
215 void OnStopStreamRequested(const std::string& label);
216
217 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. 207 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager.
218 scoped_ptr<base::Thread> device_thread_; 208 scoped_ptr<base::Thread> device_thread_;
219 209
220 scoped_ptr<MediaStreamUIController> ui_controller_;
221
222 media::AudioManager* const audio_manager_; // not owned 210 media::AudioManager* const audio_manager_; // not owned
223 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; 211 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_;
224 scoped_refptr<VideoCaptureManager> video_capture_manager_; 212 scoped_refptr<VideoCaptureManager> video_capture_manager_;
225 213
226 // Indicator of device monitoring state. 214 // Indicator of device monitoring state.
227 bool monitoring_started_; 215 bool monitoring_started_;
228 216
229 // Stores most recently enumerated device lists. The cache is cleared when 217 // Stores most recently enumerated device lists. The cache is cleared when
230 // monitoring is stopped or there is no request for that type of device. 218 // monitoring is stopped or there is no request for that type of device.
231 EnumerationCache audio_enumeration_cache_; 219 EnumerationCache audio_enumeration_cache_;
232 EnumerationCache video_enumeration_cache_; 220 EnumerationCache video_enumeration_cache_;
233 221
234 // Keeps track of live enumeration commands sent to VideoCaptureManager or 222 // Keeps track of live enumeration commands sent to VideoCaptureManager or
235 // AudioInputDeviceManager, in order to only enumerate when necessary. 223 // AudioInputDeviceManager, in order to only enumerate when necessary.
236 int active_enumeration_ref_count_[NUM_MEDIA_TYPES]; 224 int active_enumeration_ref_count_[NUM_MEDIA_TYPES];
237 225
238 // All non-closed request. 226 // All non-closed request.
239 DeviceRequests requests_; 227 DeviceRequests requests_;
240 228
241 // Hold a pointer to the IO loop to check we delete the device thread and 229 // Hold a pointer to the IO loop to check we delete the device thread and
242 // managers on the right thread. 230 // managers on the right thread.
243 MessageLoop* io_loop_; 231 MessageLoop* io_loop_;
244 232
245 bool screen_capture_active_; 233 bool screen_capture_active_;
246 234
235 bool use_fake_ui_;
236 scoped_ptr<MediaStreamUIProxy> fake_ui_;
237
247 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); 238 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager);
248 }; 239 };
249 240
250 } // namespace content 241 } // namespace content
251 242
252 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ 243 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698