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 MediaStreamDeviceSettings for permission to | 9 // 2. MediaStreamManager will ask MediaStreamDeviceSettings for permission to |
10 // use devices and for which device to use. | 10 // use devices and for which device to use. |
11 // 3. MediaStreamManager will request the corresponding media device manager(s) | 11 // 3. MediaStreamManager will request the corresponding media device manager(s) |
12 // to enumerate available devices. The result will be given to | 12 // to enumerate available devices. The result will be given to |
13 // MediaStreamDeviceSettings. | 13 // MediaStreamDeviceSettings. |
14 // 4. MediaStreamDeviceSettings will, by using user settings, pick devices which | 14 // 4. MediaStreamDeviceSettings will, by using user settings, pick devices which |
15 // devices to use and let MediaStreamManager know the result. | 15 // devices to use and let MediaStreamManager know the result. |
16 // 5. MediaStreamManager will call the proper media device manager to open the | 16 // 5. MediaStreamManager will call the proper media device manager to open the |
17 // device and let the MediaStreamRequester know it has been done. | 17 // device and let the MediaStreamRequester know it has been done. |
18 | 18 |
19 // When enumeration and open are done in separate operations, | 19 // When enumeration and open are done in separate operations, |
20 // MediaStreamDeviceSettings is not involved as in steps. | 20 // MediaStreamDeviceSettings is not involved as in steps. |
21 | 21 |
22 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 22 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
23 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 23 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
24 | 24 |
25 #include <map> | 25 #include <map> |
26 #include <string> | 26 #include <string> |
27 #include <vector> | |
28 | 27 |
29 #include "base/basictypes.h" | 28 #include "base/basictypes.h" |
30 #include "base/memory/scoped_ptr.h" | 29 #include "base/memory/scoped_ptr.h" |
31 #include "base/memory/ref_counted.h" | 30 #include "base/memory/ref_counted.h" |
32 #include "base/message_loop.h" | 31 #include "base/message_loop.h" |
33 #include "base/system_monitor/system_monitor.h" | 32 #include "base/system_monitor/system_monitor.h" |
34 #include "base/threading/thread.h" | 33 #include "base/threading/thread.h" |
35 #include "content/browser/renderer_host/media/media_stream_provider.h" | 34 #include "content/browser/renderer_host/media/media_stream_provider.h" |
36 #include "content/browser/renderer_host/media/media_stream_settings_requester.h" | 35 #include "content/browser/renderer_host/media/media_stream_settings_requester.h" |
37 #include "content/common/media/media_stream_options.h" | 36 #include "content/common/media/media_stream_options.h" |
38 #include "content/common/content_export.h" | 37 #include "content/common/content_export.h" |
39 #include "content/public/browser/browser_thread.h" | 38 #include "content/public/browser/browser_thread.h" |
40 | 39 |
41 namespace base { | 40 namespace base { |
42 namespace win { | 41 namespace win { |
43 class ScopedCOMInitializer; | 42 class ScopedCOMInitializer; |
44 } | 43 } |
45 } | 44 } |
46 | 45 |
46 namespace media { | |
47 class AudioManager; | |
48 } | |
49 | |
47 namespace media_stream { | 50 namespace media_stream { |
48 | 51 |
49 class AudioInputDeviceManager; | 52 class AudioInputDeviceManager; |
50 class MediaStreamDeviceSettings; | 53 class MediaStreamDeviceSettings; |
51 class MediaStreamRequester; | 54 class MediaStreamRequester; |
52 class VideoCaptureManager; | 55 class VideoCaptureManager; |
53 | 56 |
54 // Thread that enters MTA on windows, and is base::Thread on linux and mac. | 57 // Thread that enters MTA on windows, and is base::Thread on linux and mac. |
55 class DeviceThread : public base::Thread { | 58 class DeviceThread : public base::Thread { |
56 public: | 59 public: |
(...skipping 12 matching lines...) Expand all Loading... | |
69 // MediaStreamManager is used to generate and close new media devices, not to | 72 // MediaStreamManager is used to generate and close new media devices, not to |
70 // start the media flow. | 73 // start the media flow. |
71 // The classes requesting new media streams are answered using | 74 // The classes requesting new media streams are answered using |
72 // MediaStreamManager::Listener. | 75 // MediaStreamManager::Listener. |
73 class CONTENT_EXPORT MediaStreamManager | 76 class CONTENT_EXPORT MediaStreamManager |
74 : public MediaStreamProviderListener, | 77 : public MediaStreamProviderListener, |
75 public MessageLoop::DestructionObserver, | 78 public MessageLoop::DestructionObserver, |
76 public SettingsRequester, | 79 public SettingsRequester, |
77 public base::SystemMonitor::DevicesChangedObserver { | 80 public base::SystemMonitor::DevicesChangedObserver { |
78 public: | 81 public: |
79 // This class takes the ownerships of the |audio_input_device_manager| | 82 explicit MediaStreamManager(media::AudioManager* audio_manager); |
80 // and |video_capture_manager|. | |
81 MediaStreamManager(AudioInputDeviceManager* audio_input_device_manager, | |
82 VideoCaptureManager* video_capture_manager); | |
83 | |
84 virtual ~MediaStreamManager(); | 83 virtual ~MediaStreamManager(); |
85 | 84 |
86 // Used to access VideoCaptureManager. | 85 // Used to access VideoCaptureManager. |
87 VideoCaptureManager* video_capture_manager(); | 86 VideoCaptureManager* video_capture_manager(); |
88 | 87 |
89 // Used to access AudioInputDeviceManager. | 88 // Used to access AudioInputDeviceManager. |
90 AudioInputDeviceManager* audio_input_device_manager(); | 89 AudioInputDeviceManager* audio_input_device_manager(); |
91 | 90 |
92 // GenerateStream opens new media devices according to |components|. It | 91 // GenerateStream opens new media devices according to |components|. It |
93 // creates a new request which is identified by a unique |label| that's | 92 // creates a new request which is identified by a unique |label| that's |
94 // returned to the caller. | 93 // returned to the caller. |render_process_id| and |render_view_id| refer to |
94 // the view where the infobar will appear to the user. | |
95 void GenerateStream(MediaStreamRequester* requester, int render_process_id, | 95 void GenerateStream(MediaStreamRequester* requester, int render_process_id, |
96 int render_view_id, const StreamOptions& options, | 96 int render_view_id, const StreamOptions& components, |
97 const GURL& security_origin, std::string* label); | 97 const GURL& security_origin, std::string* label); |
98 | 98 |
99 // Like GenerateStream above, except the user is only able to allow/deny the | |
100 // request for the device specified by |device_id|. | |
101 void GenerateStreamForDevice(MediaStreamRequester* requester, | |
102 int render_process_id, int render_view_id, | |
103 const StreamOptions& components, | |
104 const std::string& device_id, | |
105 const GURL& security_origin, std::string* label); | |
106 | |
99 // Cancel generate stream. | 107 // Cancel generate stream. |
100 void CancelGenerateStream(const std::string& label); | 108 void CancelGenerateStream(const std::string& label); |
101 | 109 |
102 // Closes generated stream. | 110 // Closes generated stream. |
103 void StopGeneratedStream(const std::string& label); | 111 void StopGeneratedStream(const std::string& label); |
104 | 112 |
105 // Gets a list of devices of |type|. | 113 // Gets a list of devices of |type|, which must be MEDIA_DEVICE_AUDIO_CAPTURE |
114 // or MEDIA_DEVICE_VIDEO_CAPTURE. | |
106 // The request is identified using |label|, which is pointing to a | 115 // The request is identified using |label|, which is pointing to a |
107 // std::string. | 116 // std::string. |
108 // The request is persistent, which means the client keeps listening to | 117 // The request is persistent, which means the client keeps listening to |
109 // device changes, such as plug/unplug, and expects new device list for | 118 // device changes, such as plug/unplug, and expects new device list for |
110 // such a change, till the client stops the request. | 119 // such a change, till the client stops the request. |
111 void EnumerateDevices(MediaStreamRequester* requester, | 120 void EnumerateDevices(MediaStreamRequester* requester, |
112 int render_process_id, | 121 int render_process_id, |
113 int render_view_id, | 122 int render_view_id, |
114 MediaStreamType type, | 123 MediaStreamType type, |
115 const GURL& security_origin, | 124 const GURL& security_origin, |
116 std::string* label); | 125 std::string* label); |
117 | 126 |
118 // Open a device identified by |device_id|. | 127 // Open a device identified by |device_id|. |type| must be either |
128 // MEDIA_DEVICE_AUDIO_CAPTURE or MEDIA_DEVICE_VIDEO_CAPTURE. | |
119 // The request is identified using |label|, which is pointing to a | 129 // The request is identified using |label|, which is pointing to a |
120 // std::string. | 130 // std::string. |
121 void OpenDevice(MediaStreamRequester* requester, | 131 void OpenDevice(MediaStreamRequester* requester, |
122 int render_process_id, | 132 int render_process_id, |
123 int render_view_id, | 133 int render_view_id, |
124 const std::string& device_id, | 134 const std::string& device_id, |
125 MediaStreamType type, | 135 MediaStreamType type, |
126 const GURL& security_origin, | 136 const GURL& security_origin, |
127 std::string* label); | 137 std::string* label); |
128 | 138 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 void NotifyObserverDevicesOpened(DeviceRequest* request); | 185 void NotifyObserverDevicesOpened(DeviceRequest* request); |
176 void NotifyObserverDevicesClosed(DeviceRequest* request); | 186 void NotifyObserverDevicesClosed(DeviceRequest* request); |
177 void DevicesFromRequest(DeviceRequest* request, | 187 void DevicesFromRequest(DeviceRequest* request, |
178 content::MediaStreamDevices* devices); | 188 content::MediaStreamDevices* devices); |
179 | 189 |
180 // Helpers. | 190 // Helpers. |
181 bool RequestDone(const MediaStreamManager::DeviceRequest& request) const; | 191 bool RequestDone(const MediaStreamManager::DeviceRequest& request) const; |
182 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); | 192 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); |
183 void StartEnumeration(DeviceRequest* new_request, | 193 void StartEnumeration(DeviceRequest* new_request, |
184 std::string* label); | 194 std::string* label); |
185 void AddRequest(DeviceRequest* new_request, std::string* label); | 195 void AddRequest(const DeviceRequest& new_request, std::string* label); |
186 bool HasEnumerationRequest(MediaStreamType type); | 196 bool HasEnumerationRequest(MediaStreamType type); |
187 bool HasEnumerationRequest(); | 197 bool HasEnumerationRequest(); |
188 void ClearEnumerationCache(EnumerationCache* cache); | 198 void ClearEnumerationCache(EnumerationCache* cache); |
189 | 199 |
190 // Helper to ensure the device thread and pass the message loop to device | 200 // Helper to create the device managers, if needed. Auto-starts the device |
191 // managers, it also register itself as the listener to the device managers. | 201 // thread and registers this as a listener with the device managers. |
192 void EnsureDeviceThreadAndListener(); | 202 void EnsureDeviceManagersStarted(); |
193 | 203 |
194 // Sends cached device list to a client corresponding to the request | 204 // Sends cached device list to a client corresponding to the request |
195 // identified by |label|. | 205 // identified by |label|. |
196 void SendCachedDeviceList(EnumerationCache* cache, const std::string& label); | 206 void SendCachedDeviceList(EnumerationCache* cache, const std::string& label); |
197 | 207 |
198 // Stop the request of enumerating devices indentified by |label|. | 208 // Stop the request of enumerating devices indentified by |label|. |
199 void StopEnumerateDevices(const std::string& label); | 209 void StopEnumerateDevices(const std::string& label); |
200 | 210 |
201 // Helpers to start and stop monitoring devices. | 211 // Helpers to start and stop monitoring devices. |
202 void StartMonitoring(); | 212 void StartMonitoring(); |
203 void StopMonitoring(); | 213 void StopMonitoring(); |
204 | 214 |
205 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. | 215 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. |
206 scoped_ptr<base::Thread> device_thread_; | 216 scoped_ptr<base::Thread> device_thread_; |
207 | 217 |
208 scoped_ptr<MediaStreamDeviceSettings> device_settings_; | 218 scoped_ptr<MediaStreamDeviceSettings> device_settings_; |
219 | |
220 media::AudioManager* const audio_manager_; // not owned | |
tommi (sloooow) - chröme
2012/09/10 09:17:25
chrome convention is: const media::AudioManager*
.
miu
2012/09/10 21:24:38
The object isn't const. The pointer is. It is se
| |
209 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; | 221 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; |
210 scoped_refptr<VideoCaptureManager> video_capture_manager_; | 222 scoped_refptr<VideoCaptureManager> video_capture_manager_; |
211 | 223 |
212 // Indicator of device monitoring state. | 224 // Indicator of device monitoring state. |
213 bool monitoring_started_; | 225 bool monitoring_started_; |
214 | 226 |
215 // Stores most recently enumerated device lists. The cache is cleared when | 227 // Stores most recently enumerated device lists. The cache is cleared when |
216 // monitoring is stopped or there is no request for that type of device. | 228 // monitoring is stopped or there is no request for that type of device. |
217 EnumerationCache audio_enumeration_cache_; | 229 EnumerationCache audio_enumeration_cache_; |
218 EnumerationCache video_enumeration_cache_; | 230 EnumerationCache video_enumeration_cache_; |
219 | 231 |
220 // Keeps track of live enumeration commands sent to VideoCaptureManager or | 232 // Keeps track of live enumeration commands sent to VideoCaptureManager or |
221 // AudioInputDeviceManager, in order to only enumerate when necessary. | 233 // AudioInputDeviceManager, in order to only enumerate when necessary. |
222 int active_enumeration_ref_count_[content::NUM_MEDIA_STREAM_DEVICE_TYPES]; | 234 int active_enumeration_ref_count_[content::NUM_MEDIA_TYPES]; |
223 | 235 |
224 // All non-closed request. | 236 // All non-closed request. |
225 typedef std::map<std::string, DeviceRequest> DeviceRequests; | 237 typedef std::map<std::string, DeviceRequest> DeviceRequests; |
226 DeviceRequests requests_; | 238 DeviceRequests requests_; |
227 | 239 |
228 // Hold a pointer to the IO loop to check we delete the device thread and | 240 // Hold a pointer to the IO loop to check we delete the device thread and |
229 // managers on the right thread. | 241 // managers on the right thread. |
230 MessageLoop* io_loop_; | 242 MessageLoop* io_loop_; |
231 | 243 |
232 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); | 244 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); |
233 }; | 245 }; |
234 | 246 |
235 } // namespace media_stream | 247 } // namespace media_stream |
236 | 248 |
237 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 249 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
OLD | NEW |