Chromium Code Reviews| 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 // VideoCaptureManager is used to open/close, start/stop, enumerate available | 5 // VideoCaptureManager is used to open/close, start/stop, enumerate available |
| 6 // video capture devices, and manage VideoCaptureController's. | 6 // video capture devices, and manage VideoCaptureController's. |
| 7 // All functions are expected to be called from Browser::IO thread. Some helper | 7 // All functions are expected to be called from Browser::IO thread. Some helper |
| 8 // functions (*OnDeviceThread) will dispatch operations to the device thread. | 8 // functions (*OnDeviceThread) will dispatch operations to the device thread. |
| 9 // VideoCaptureManager will open OS dependent instances of VideoCaptureDevice. | 9 // VideoCaptureManager will open OS dependent instances of VideoCaptureDevice. |
| 10 // A device can only be opened once. | 10 // A device can only be opened once. |
| 11 | 11 |
| 12 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 12 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| 13 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 13 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| 14 | 14 |
| 15 #include <map> | 15 #include <map> |
| 16 #include <set> | 16 #include <set> |
| 17 #include <string> | 17 #include <string> |
| 18 | 18 |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "base/message_loop/message_loop.h" | |
| 21 #include "base/process/process_handle.h" | 22 #include "base/process/process_handle.h" |
| 22 #include "content/browser/renderer_host/media/media_stream_provider.h" | 23 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 23 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" | 24 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" |
| 24 #include "content/common/content_export.h" | 25 #include "content/common/content_export.h" |
| 25 #include "content/common/media/media_stream_options.h" | 26 #include "content/common/media/media_stream_options.h" |
| 26 #include "media/video/capture/video_capture_device.h" | 27 #include "media/video/capture/video_capture_device.h" |
| 27 #include "media/video/capture/video_capture_device_factory.h" | 28 #include "media/video/capture/video_capture_device_factory.h" |
| 28 #include "media/video/capture/video_capture_types.h" | 29 #include "media/video/capture/video_capture_types.h" |
| 29 | 30 |
| 30 namespace content { | 31 namespace content { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 DeviceInfo(); | 117 DeviceInfo(); |
| 117 DeviceInfo(const media::VideoCaptureDevice::Name& name, | 118 DeviceInfo(const media::VideoCaptureDevice::Name& name, |
| 118 const media::VideoCaptureFormats& supported_formats); | 119 const media::VideoCaptureFormats& supported_formats); |
| 119 ~DeviceInfo(); | 120 ~DeviceInfo(); |
| 120 | 121 |
| 121 media::VideoCaptureDevice::Name name; | 122 media::VideoCaptureDevice::Name name; |
| 122 media::VideoCaptureFormats supported_formats; | 123 media::VideoCaptureFormats supported_formats; |
| 123 }; | 124 }; |
| 124 typedef std::vector<DeviceInfo> DeviceInfos; | 125 typedef std::vector<DeviceInfo> DeviceInfos; |
| 125 | 126 |
| 126 // Check to see if |entry| has no clients left on its controller. If so, | 127 // Checks to see if |entry| has no clients left on its controller. If so, |
| 127 // remove it from the list of devices, and delete it asynchronously. |entry| | 128 // remove it from the list of devices, and delete it asynchronously. |entry| |
| 128 // may be freed by this function. | 129 // may be freed by this function. |
| 129 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry); | 130 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry); |
| 130 | 131 |
| 131 // Helpers to report an event to our Listener. | 132 // Helpers to report an event to our Listener. |
| 132 void OnOpened(MediaStreamType type, | 133 void OnOpened(MediaStreamType type, |
| 133 media::VideoCaptureSessionId capture_session_id); | 134 media::VideoCaptureSessionId capture_session_id); |
| 134 void OnClosed(MediaStreamType type, | 135 void OnClosed(MediaStreamType type, |
| 135 media::VideoCaptureSessionId capture_session_id); | 136 media::VideoCaptureSessionId capture_session_id); |
| 136 void OnDevicesInfoEnumerated( | 137 void OnDevicesInfoEnumerated(MediaStreamType stream_type, |
| 137 MediaStreamType stream_type, | 138 const DeviceInfos& new_devices_info_cache); |
| 138 const DeviceInfos& new_devices_info_cache); | |
| 139 | 139 |
| 140 // Find a DeviceEntry by its device ID and type, if it is already opened. | 140 // Finds a DeviceEntry by its device ID and type, if it is already opened. |
| 141 DeviceEntry* GetDeviceEntryForMediaStreamDevice( | 141 DeviceEntry* GetDeviceEntryForMediaStreamDevice( |
| 142 const MediaStreamDevice& device_info); | 142 const MediaStreamDevice& device_info); |
| 143 | 143 |
| 144 // Find a DeviceEntry entry for the indicated session, creating a fresh one | 144 // Finds a DeviceEntry entry for the indicated session, creating a fresh one |
| 145 // if necessary. Returns NULL if the session id is invalid. | 145 // if necessary. Returns NULL if the session id is invalid. |
| 146 DeviceEntry* GetOrCreateDeviceEntry( | 146 DeviceEntry* GetOrCreateDeviceEntry( |
| 147 media::VideoCaptureSessionId capture_session_id); | 147 media::VideoCaptureSessionId capture_session_id); |
| 148 | 148 |
| 149 // Find the DeviceEntry that owns a particular controller pointer. | 149 // Finds the DeviceEntry that owns a particular controller pointer. |
| 150 DeviceEntry* GetDeviceEntryForController( | 150 DeviceEntry* GetDeviceEntryForController( |
| 151 const VideoCaptureController* controller) const; | 151 const VideoCaptureController* controller) const; |
| 152 | 152 |
| 153 bool IsOnDeviceThread() const; | 153 bool IsOnDeviceThread() const; |
| 154 | 154 |
| 155 // Queries the Names of the devices in the system; the formats supported by | 155 // Consolidates the cached devices list with the list of currently connected |
| 156 // the new devices are also queried, and consolidated with the copy of the | 156 // devices in the system |names_snapshot|. Retrieves the supported formats of |
| 157 // local device info cache passed. The consolidated list of devices and | 157 // the new devices and sends the new cache to OnDevicesInfoEnumerated(). |
| 158 // supported formats is returned. | 158 void ConsolidateDevicesInfoOnDeviceThread( |
| 159 DeviceInfos GetAvailableDevicesInfoOnDeviceThread( | 159 base::MessageLoop* io_loop, |
|
perkj_chrome
2014/05/26 11:49:42
use MessageLoopProxy
mcasas
2014/05/26 13:00:18
Done.
| |
| 160 MediaStreamType stream_type, | 160 MediaStreamType stream_type, |
| 161 const DeviceInfos& old_device_info_cache); | 161 const DeviceInfos& old_device_info_cache, |
| 162 media::VideoCaptureDevice::Names& names_snapshot); | |
| 162 | 163 |
| 163 // Create and Start a new VideoCaptureDevice, storing the result in | 164 // Creates and Starts a new VideoCaptureDevice, storing the result in |
| 164 // |entry->video_capture_device|. Ownership of |client| passes to | 165 // |entry->video_capture_device|. Ownership of |client| passes to |
| 165 // the device. | 166 // the device. |
| 166 void DoStartDeviceOnDeviceThread( | 167 void DoStartDeviceOnDeviceThread( |
| 167 media::VideoCaptureSessionId session_id, | 168 media::VideoCaptureSessionId session_id, |
| 168 DeviceEntry* entry, | 169 DeviceEntry* entry, |
| 169 const media::VideoCaptureParams& params, | 170 const media::VideoCaptureParams& params, |
| 170 scoped_ptr<media::VideoCaptureDevice::Client> client); | 171 scoped_ptr<media::VideoCaptureDevice::Client> client); |
| 171 | 172 |
| 172 // Stop and destroy the VideoCaptureDevice held in | 173 // Stops and destroys the VideoCaptureDevice held in |
| 173 // |entry->video_capture_device|. | 174 // |entry->video_capture_device|. |
| 174 void DoStopDeviceOnDeviceThread(DeviceEntry* entry); | 175 void DoStopDeviceOnDeviceThread(DeviceEntry* entry); |
| 175 | 176 |
| 176 DeviceInfo* FindDeviceInfoById(const std::string& id, | 177 DeviceInfo* FindDeviceInfoById(const std::string& id, |
| 177 DeviceInfos& device_vector); | 178 DeviceInfos& device_vector); |
| 178 | 179 |
| 179 void SetDesktopCaptureWindowIdOnDeviceThread(DeviceEntry* entry, | 180 void SetDesktopCaptureWindowIdOnDeviceThread(DeviceEntry* entry, |
| 180 gfx::NativeViewId window_id); | 181 gfx::NativeViewId window_id); |
| 181 | 182 |
| 182 void SaveDesktopCaptureWindowIdOnDeviceThread( | 183 void SaveDesktopCaptureWindowIdOnDeviceThread( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 }; | 224 }; |
| 224 typedef std::set<DeviceEntry*> DeviceEntries; | 225 typedef std::set<DeviceEntry*> DeviceEntries; |
| 225 DeviceEntries devices_; | 226 DeviceEntries devices_; |
| 226 | 227 |
| 227 // Device creation factory injected on construction from MediaStreamManager or | 228 // Device creation factory injected on construction from MediaStreamManager or |
| 228 // from the test harness. | 229 // from the test harness. |
| 229 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_; | 230 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_; |
| 230 | 231 |
| 231 // Local cache of the enumerated video capture devices' names and capture | 232 // Local cache of the enumerated video capture devices' names and capture |
| 232 // supported formats. A snapshot of the current devices and their capabilities | 233 // supported formats. A snapshot of the current devices and their capabilities |
| 233 // is composed in GetAvailableDevicesInfoOnDeviceThread() --coming | 234 // is composed in VideoCaptureDeviceFactory::EnumerateDeviceNames() and |
| 234 // from EnumerateDevices()--, and this snapshot is used to update this list in | 235 // ConsolidateDevicesInfoOnDeviceThread(), and this snapshot is used to update |
| 235 // OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will | 236 // this list in OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will |
| 236 // use this list if the device is not started, otherwise it will retrieve the | 237 // use this list if the device is not started, otherwise it will retrieve the |
| 237 // active device capture format from the VideoCaptureController associated. | 238 // active device capture format from the VideoCaptureController associated. |
| 238 DeviceInfos devices_info_cache_; | 239 DeviceInfos devices_info_cache_; |
| 239 | 240 |
| 240 // Accessed on the device thread only. | 241 // Accessed on the device thread only. |
| 241 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> | 242 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> |
| 242 notification_window_ids_; | 243 notification_window_ids_; |
| 243 | 244 |
| 244 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 245 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
| 245 }; | 246 }; |
| 246 | 247 |
| 247 } // namespace content | 248 } // namespace content |
| 248 | 249 |
| 249 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 250 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| OLD | NEW |