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 // 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 23 matching lines...) Expand all Loading... | |
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" | 35 #include "content/browser/renderer_host/media/media_stream_settings_requester.h" |
36 #include "content/common/media/media_stream_options.h" | 36 #include "content/common/media/media_stream_options.h" |
37 #include "content/common/content_export.h" | 37 #include "content/common/content_export.h" |
38 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
39 | 39 |
40 namespace base { | 40 namespace base { |
41 class Thread; | 41 class Thread; |
42 } | 42 } |
43 | 43 |
44 namespace content { | |
45 class MediaStreamUIController; | |
46 } | |
47 | |
48 namespace media { | 44 namespace media { |
49 class AudioManager; | 45 class AudioManager; |
50 } | 46 } |
51 | 47 |
52 namespace media_stream { | 48 namespace content { |
53 | |
54 class AudioInputDeviceManager; | 49 class AudioInputDeviceManager; |
55 class MediaStreamDeviceSettings; | 50 class MediaStreamDeviceSettings; |
51 class MediaStreamUIController; | |
tfarina
2012/10/29 17:41:34
nit: sort
jam
2012/10/29 18:14:45
Done.
| |
56 class MediaStreamRequester; | 52 class MediaStreamRequester; |
57 class VideoCaptureManager; | 53 class VideoCaptureManager; |
58 | 54 |
59 // MediaStreamManager is used to generate and close new media devices, not to | 55 // MediaStreamManager is used to generate and close new media devices, not to |
60 // start the media flow. | 56 // start the media flow. |
61 // The classes requesting new media streams are answered using | 57 // The classes requesting new media streams are answered using |
62 // MediaStreamManager::Listener. | 58 // MediaStreamManager::Listener. |
63 class CONTENT_EXPORT MediaStreamManager | 59 class CONTENT_EXPORT MediaStreamManager |
64 : public MediaStreamProviderListener, | 60 : public MediaStreamProviderListener, |
65 public MessageLoop::DestructionObserver, | 61 public MessageLoop::DestructionObserver, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 const std::string& device_id, | 130 const std::string& device_id, |
135 MediaStreamType type, | 131 MediaStreamType type, |
136 const GURL& security_origin, | 132 const GURL& security_origin, |
137 std::string* label); | 133 std::string* label); |
138 | 134 |
139 // Signals the UI that the devices are opened. | 135 // Signals the UI that the devices are opened. |
140 // Users are responsible for calling NotifyUIDevicesClosed when the devices | 136 // Users are responsible for calling NotifyUIDevicesClosed when the devices |
141 // are not used anymore, otherwise UI will leak. | 137 // are not used anymore, otherwise UI will leak. |
142 void NotifyUIDevicesOpened(int render_process_id, | 138 void NotifyUIDevicesOpened(int render_process_id, |
143 int render_view_id, | 139 int render_view_id, |
144 const content::MediaStreamDevices& devices); | 140 const MediaStreamDevices& devices); |
145 | 141 |
146 // Signals the UI that the devices are being closed. | 142 // Signals the UI that the devices are being closed. |
147 void NotifyUIDevicesClosed(int render_process_id, | 143 void NotifyUIDevicesClosed(int render_process_id, |
148 int render_view_id, | 144 int render_view_id, |
149 const content::MediaStreamDevices& devices); | 145 const MediaStreamDevices& devices); |
150 | 146 |
151 // Implements MediaStreamProviderListener. | 147 // Implements MediaStreamProviderListener. |
152 virtual void Opened(MediaStreamType stream_type, | 148 virtual void Opened(MediaStreamType stream_type, |
153 int capture_session_id) OVERRIDE; | 149 int capture_session_id) OVERRIDE; |
154 virtual void Closed(MediaStreamType stream_type, | 150 virtual void Closed(MediaStreamType stream_type, |
155 int capture_session_id) OVERRIDE; | 151 int capture_session_id) OVERRIDE; |
156 virtual void DevicesEnumerated(MediaStreamType stream_type, | 152 virtual void DevicesEnumerated(MediaStreamType stream_type, |
157 const StreamDeviceInfoArray& devices) OVERRIDE; | 153 const StreamDeviceInfoArray& devices) OVERRIDE; |
158 virtual void Error(MediaStreamType stream_type, | 154 virtual void Error(MediaStreamType stream_type, |
159 int capture_session_id, | 155 int capture_session_id, |
(...skipping 28 matching lines...) Expand all Loading... | |
188 | 184 |
189 bool valid; | 185 bool valid; |
190 StreamDeviceInfoArray devices; | 186 StreamDeviceInfoArray devices; |
191 }; | 187 }; |
192 | 188 |
193 // Helpers for signaling the media observer that new capture devices are | 189 // Helpers for signaling the media observer that new capture devices are |
194 // opened/closed. | 190 // opened/closed. |
195 void NotifyDevicesOpened(const DeviceRequest& request); | 191 void NotifyDevicesOpened(const DeviceRequest& request); |
196 void NotifyDevicesClosed(const DeviceRequest& request); | 192 void NotifyDevicesClosed(const DeviceRequest& request); |
197 void DevicesFromRequest(const DeviceRequest& request, | 193 void DevicesFromRequest(const DeviceRequest& request, |
198 content::MediaStreamDevices* devices); | 194 MediaStreamDevices* devices); |
199 | 195 |
200 // Helpers. | 196 // Helpers. |
201 bool RequestDone(const MediaStreamManager::DeviceRequest& request) const; | 197 bool RequestDone(const MediaStreamManager::DeviceRequest& request) const; |
202 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); | 198 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); |
203 void StartEnumeration(DeviceRequest* new_request, | 199 void StartEnumeration(DeviceRequest* new_request, |
204 std::string* label); | 200 std::string* label); |
205 void AddRequest(const DeviceRequest& new_request, std::string* label); | 201 void AddRequest(const DeviceRequest& new_request, std::string* label); |
206 bool HasEnumerationRequest(MediaStreamType type); | 202 bool HasEnumerationRequest(MediaStreamType type); |
207 bool HasEnumerationRequest(); | 203 bool HasEnumerationRequest(); |
208 void ClearEnumerationCache(EnumerationCache* cache); | 204 void ClearEnumerationCache(EnumerationCache* cache); |
(...skipping 10 matching lines...) Expand all Loading... | |
219 // Stop the request of enumerating devices indentified by |label|. | 215 // Stop the request of enumerating devices indentified by |label|. |
220 void StopEnumerateDevices(const std::string& label); | 216 void StopEnumerateDevices(const std::string& label); |
221 | 217 |
222 // Helpers to start and stop monitoring devices. | 218 // Helpers to start and stop monitoring devices. |
223 void StartMonitoring(); | 219 void StartMonitoring(); |
224 void StopMonitoring(); | 220 void StopMonitoring(); |
225 | 221 |
226 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. | 222 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. |
227 scoped_ptr<base::Thread> device_thread_; | 223 scoped_ptr<base::Thread> device_thread_; |
228 | 224 |
229 scoped_ptr<content::MediaStreamUIController> ui_controller_; | 225 scoped_ptr<MediaStreamUIController> ui_controller_; |
230 | 226 |
231 media::AudioManager* const audio_manager_; // not owned | 227 media::AudioManager* const audio_manager_; // not owned |
232 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; | 228 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; |
233 scoped_refptr<VideoCaptureManager> video_capture_manager_; | 229 scoped_refptr<VideoCaptureManager> video_capture_manager_; |
234 | 230 |
235 // Indicator of device monitoring state. | 231 // Indicator of device monitoring state. |
236 bool monitoring_started_; | 232 bool monitoring_started_; |
237 | 233 |
238 // Stores most recently enumerated device lists. The cache is cleared when | 234 // Stores most recently enumerated device lists. The cache is cleared when |
239 // monitoring is stopped or there is no request for that type of device. | 235 // monitoring is stopped or there is no request for that type of device. |
240 EnumerationCache audio_enumeration_cache_; | 236 EnumerationCache audio_enumeration_cache_; |
241 EnumerationCache video_enumeration_cache_; | 237 EnumerationCache video_enumeration_cache_; |
242 | 238 |
243 // Keeps track of live enumeration commands sent to VideoCaptureManager or | 239 // Keeps track of live enumeration commands sent to VideoCaptureManager or |
244 // AudioInputDeviceManager, in order to only enumerate when necessary. | 240 // AudioInputDeviceManager, in order to only enumerate when necessary. |
245 int active_enumeration_ref_count_[content::NUM_MEDIA_TYPES]; | 241 int active_enumeration_ref_count_[NUM_MEDIA_TYPES]; |
246 | 242 |
247 // All non-closed request. | 243 // All non-closed request. |
248 typedef std::map<std::string, DeviceRequest> DeviceRequests; | 244 typedef std::map<std::string, DeviceRequest> DeviceRequests; |
249 DeviceRequests requests_; | 245 DeviceRequests requests_; |
250 | 246 |
251 // Hold a pointer to the IO loop to check we delete the device thread and | 247 // Hold a pointer to the IO loop to check we delete the device thread and |
252 // managers on the right thread. | 248 // managers on the right thread. |
253 MessageLoop* io_loop_; | 249 MessageLoop* io_loop_; |
254 | 250 |
255 // Static members. | 251 // Static members. |
256 static bool always_use_fake_devices_; | 252 static bool always_use_fake_devices_; |
257 | 253 |
258 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); | 254 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); |
259 }; | 255 }; |
260 | 256 |
261 } // namespace media_stream | 257 } // namespace content |
262 | 258 |
263 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 259 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
OLD | NEW |