| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 void NotifyObserverDevicesOpened(DeviceRequest* request); | 187 void NotifyObserverDevicesOpened(DeviceRequest* request); |
| 178 void NotifyObserverDevicesClosed(DeviceRequest* request); | 188 void NotifyObserverDevicesClosed(DeviceRequest* request); |
| 179 void DevicesFromRequest(DeviceRequest* request, | 189 void DevicesFromRequest(DeviceRequest* request, |
| 180 content::MediaStreamDevices* devices); | 190 content::MediaStreamDevices* devices); |
| 181 | 191 |
| 182 // Helpers. | 192 // Helpers. |
| 183 bool RequestDone(const MediaStreamManager::DeviceRequest& request) const; | 193 bool RequestDone(const MediaStreamManager::DeviceRequest& request) const; |
| 184 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); | 194 MediaStreamProvider* GetDeviceManager(MediaStreamType stream_type); |
| 185 void StartEnumeration(DeviceRequest* new_request, | 195 void StartEnumeration(DeviceRequest* new_request, |
| 186 std::string* label); | 196 std::string* label); |
| 187 void AddRequest(DeviceRequest* new_request, std::string* label); | 197 void AddRequest(const DeviceRequest& new_request, std::string* label); |
| 188 bool HasEnumerationRequest(MediaStreamType type); | 198 bool HasEnumerationRequest(MediaStreamType type); |
| 189 bool HasEnumerationRequest(); | 199 bool HasEnumerationRequest(); |
| 190 void ClearEnumerationCache(EnumerationCache* cache); | 200 void ClearEnumerationCache(EnumerationCache* cache); |
| 191 | 201 |
| 192 // Helper to ensure the device thread and pass the message loop to device | 202 // Helper to create the device managers, if needed. Auto-starts the device |
| 193 // managers, it also register itself as the listener to the device managers. | 203 // thread and registers this as a listener with the device managers. |
| 194 void EnsureDeviceThreadAndListener(); | 204 void EnsureDeviceManagersStarted(); |
| 195 | 205 |
| 196 // Sends cached device list to a client corresponding to the request | 206 // Sends cached device list to a client corresponding to the request |
| 197 // identified by |label|. | 207 // identified by |label|. |
| 198 void SendCachedDeviceList(EnumerationCache* cache, const std::string& label); | 208 void SendCachedDeviceList(EnumerationCache* cache, const std::string& label); |
| 199 | 209 |
| 200 // Stop the request of enumerating devices indentified by |label|. | 210 // Stop the request of enumerating devices indentified by |label|. |
| 201 void StopEnumerateDevices(const std::string& label); | 211 void StopEnumerateDevices(const std::string& label); |
| 202 | 212 |
| 203 // Helpers to start and stop monitoring devices. | 213 // Helpers to start and stop monitoring devices. |
| 204 void StartMonitoring(); | 214 void StartMonitoring(); |
| 205 void StopMonitoring(); | 215 void StopMonitoring(); |
| 206 | 216 |
| 207 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. | 217 // Device thread shared by VideoCaptureManager and AudioInputDeviceManager. |
| 208 scoped_ptr<base::Thread> device_thread_; | 218 scoped_ptr<base::Thread> device_thread_; |
| 209 | 219 |
| 210 scoped_ptr<MediaStreamDeviceSettings> device_settings_; | 220 scoped_ptr<MediaStreamDeviceSettings> device_settings_; |
| 221 |
| 222 media::AudioManager* const audio_manager_; // not owned |
| 211 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; | 223 scoped_refptr<AudioInputDeviceManager> audio_input_device_manager_; |
| 212 scoped_refptr<VideoCaptureManager> video_capture_manager_; | 224 scoped_refptr<VideoCaptureManager> video_capture_manager_; |
| 213 | 225 |
| 214 // Indicator of device monitoring state. | 226 // Indicator of device monitoring state. |
| 215 bool monitoring_started_; | 227 bool monitoring_started_; |
| 216 | 228 |
| 217 // Stores most recently enumerated device lists. The cache is cleared when | 229 // Stores most recently enumerated device lists. The cache is cleared when |
| 218 // monitoring is stopped or there is no request for that type of device. | 230 // monitoring is stopped or there is no request for that type of device. |
| 219 EnumerationCache audio_enumeration_cache_; | 231 EnumerationCache audio_enumeration_cache_; |
| 220 EnumerationCache video_enumeration_cache_; | 232 EnumerationCache video_enumeration_cache_; |
| 221 | 233 |
| 222 // Keeps track of live enumeration commands sent to VideoCaptureManager or | 234 // Keeps track of live enumeration commands sent to VideoCaptureManager or |
| 223 // AudioInputDeviceManager, in order to only enumerate when necessary. | 235 // AudioInputDeviceManager, in order to only enumerate when necessary. |
| 224 int active_enumeration_ref_count_[content::NUM_MEDIA_STREAM_DEVICE_TYPES]; | 236 int active_enumeration_ref_count_[content::NUM_MEDIA_TYPES]; |
| 225 | 237 |
| 226 // All non-closed request. | 238 // All non-closed request. |
| 227 typedef std::map<std::string, DeviceRequest> DeviceRequests; | 239 typedef std::map<std::string, DeviceRequest> DeviceRequests; |
| 228 DeviceRequests requests_; | 240 DeviceRequests requests_; |
| 229 | 241 |
| 230 // Hold a pointer to the IO loop to check we delete the device thread and | 242 // Hold a pointer to the IO loop to check we delete the device thread and |
| 231 // managers on the right thread. | 243 // managers on the right thread. |
| 232 MessageLoop* io_loop_; | 244 MessageLoop* io_loop_; |
| 233 | 245 |
| 234 // Static members. | 246 // Static members. |
| 235 static bool always_use_fake_devices_; | 247 static bool always_use_fake_devices_; |
| 236 | 248 |
| 237 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); | 249 DISALLOW_COPY_AND_ASSIGN(MediaStreamManager); |
| 238 }; | 250 }; |
| 239 | 251 |
| 240 } // namespace media_stream | 252 } // namespace media_stream |
| 241 | 253 |
| 242 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ | 254 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_MEDIA_STREAM_MANAGER_H_ |
| OLD | NEW |