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 <list> | |
15 #include <map> | 16 #include <map> |
16 #include <set> | 17 #include <set> |
17 #include <string> | 18 #include <string> |
18 | 19 |
19 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
21 #include "base/memory/scoped_vector.h" | |
20 #include "base/memory/weak_ptr.h" | 22 #include "base/memory/weak_ptr.h" |
21 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
22 #include "base/process/process_handle.h" | 24 #include "base/process/process_handle.h" |
23 #include "base/timer/elapsed_timer.h" | 25 #include "base/timer/elapsed_timer.h" |
24 #include "content/browser/renderer_host/media/media_stream_provider.h" | 26 #include "content/browser/renderer_host/media/media_stream_provider.h" |
25 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" | 27 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" |
26 #include "content/common/content_export.h" | 28 #include "content/common/content_export.h" |
27 #include "content/common/media/media_stream_options.h" | 29 #include "content/common/media/media_stream_options.h" |
28 #include "media/video/capture/video_capture_device.h" | 30 #include "media/video/capture/video_capture_device.h" |
29 #include "media/video/capture/video_capture_device_factory.h" | 31 #include "media/video/capture/video_capture_device_factory.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 // Consolidates the cached devices list with the list of currently connected | 177 // Consolidates the cached devices list with the list of currently connected |
176 // devices in the system |names_snapshot|. Retrieves the supported formats of | 178 // devices in the system |names_snapshot|. Retrieves the supported formats of |
177 // the new devices and sends the new cache to OnDevicesInfoEnumerated(). | 179 // the new devices and sends the new cache to OnDevicesInfoEnumerated(). |
178 void ConsolidateDevicesInfoOnDeviceThread( | 180 void ConsolidateDevicesInfoOnDeviceThread( |
179 base::Callback<void(const media::VideoCaptureDeviceInfos&)> | 181 base::Callback<void(const media::VideoCaptureDeviceInfos&)> |
180 on_devices_enumerated_callback, | 182 on_devices_enumerated_callback, |
181 MediaStreamType stream_type, | 183 MediaStreamType stream_type, |
182 const media::VideoCaptureDeviceInfos& old_device_info_cache, | 184 const media::VideoCaptureDeviceInfos& old_device_info_cache, |
183 scoped_ptr<media::VideoCaptureDevice::Names> names_snapshot); | 185 scoped_ptr<media::VideoCaptureDevice::Names> names_snapshot); |
184 | 186 |
185 // Creates and Starts a new VideoCaptureDevice, storing the result in | 187 // Starting a capture device can take 1-2 seconds. |
186 // |entry->video_capture_device|. Ownership of |client| passes to | 188 // To avoid multiple unnecessary start/stop commands to the OS, each start |
189 // request is queued in |device_start_queue_|. | |
190 // QueueStartDevice creates a new entry in |device_start_queue_| and posts a | |
191 // request to start the device on the device thread unless there is | |
192 // another request pending start. | |
193 void QueueStartDevice(media::VideoCaptureSessionId session_id, | |
194 DeviceEntry* entry, | |
195 const media::VideoCaptureParams& params); | |
196 void OnDeviceStarted(DeviceEntry* device_entry, | |
197 scoped_ptr<media::VideoCaptureDevice> device); | |
198 void DoStopDevice(DeviceEntry* entry); | |
199 void HandleQueuedStartRequest(); | |
200 | |
201 // Creates and Starts a new VideoCaptureDevice. The resulting | |
202 // VideoCaptureDevice is returned to the IO-thread and stored in | |
203 // a DeviceEntry in |devices_|. Ownership of |client| passes to | |
187 // the device. | 204 // the device. |
188 void DoStartDeviceOnDeviceThread( | 205 scoped_ptr<media::VideoCaptureDevice> DoStartDeviceOnDeviceThread( |
189 media::VideoCaptureSessionId session_id, | 206 media::VideoCaptureSessionId session_id, |
190 DeviceEntry* entry, | 207 const std::string& device_id, |
208 MediaStreamType stream_type, | |
191 const media::VideoCaptureParams& params, | 209 const media::VideoCaptureParams& params, |
192 scoped_ptr<media::VideoCaptureDevice::Client> client); | 210 scoped_ptr<media::VideoCaptureDevice::Client> client); |
193 | 211 |
194 // Stops and destroys the VideoCaptureDevice held in | 212 // Stops and destroys the VideoCaptureDevice held in |
195 // |entry->video_capture_device|. | 213 // |device|. |
196 void DoStopDeviceOnDeviceThread(DeviceEntry* entry); | 214 void DoStopDeviceOnDeviceThread(scoped_ptr<media::VideoCaptureDevice> device); |
197 | 215 |
198 media::VideoCaptureDeviceInfo* FindDeviceInfoById( | 216 media::VideoCaptureDeviceInfo* FindDeviceInfoById( |
199 const std::string& id, | 217 const std::string& id, |
200 media::VideoCaptureDeviceInfos& device_vector); | 218 media::VideoCaptureDeviceInfos& device_vector); |
201 | 219 |
202 void SetDesktopCaptureWindowIdOnDeviceThread(DeviceEntry* entry, | 220 void SetDesktopCaptureWindowIdOnDeviceThread(DeviceEntry* entry, |
203 gfx::NativeViewId window_id); | 221 gfx::NativeViewId window_id); |
204 | 222 |
205 void SaveDesktopCaptureWindowIdOnDeviceThread( | 223 void SaveDesktopCaptureWindowIdOnDeviceThread( |
206 media::VideoCaptureSessionId session_id, | 224 media::VideoCaptureSessionId session_id, |
(...skipping 12 matching lines...) Expand all Loading... | |
219 // determine which device to use when StartCaptureForClient() occurs. Used | 237 // determine which device to use when StartCaptureForClient() occurs. Used |
220 // only on the IO thread. | 238 // only on the IO thread. |
221 SessionMap sessions_; | 239 SessionMap sessions_; |
222 | 240 |
223 // An entry, kept in a map, that owns a VideoCaptureDevice and its associated | 241 // An entry, kept in a map, that owns a VideoCaptureDevice and its associated |
224 // VideoCaptureController. VideoCaptureManager owns all VideoCaptureDevices | 242 // VideoCaptureController. VideoCaptureManager owns all VideoCaptureDevices |
225 // and VideoCaptureControllers and is responsible for deleting the instances | 243 // and VideoCaptureControllers and is responsible for deleting the instances |
226 // when they are not used any longer. | 244 // when they are not used any longer. |
227 // | 245 // |
228 // The set of currently started VideoCaptureDevice and VideoCaptureController | 246 // The set of currently started VideoCaptureDevice and VideoCaptureController |
229 // objects is only accessed from IO thread, though the DeviceEntry instances | 247 // objects is only accessed from IO thread. |
230 // themselves may visit to the device thread for device creation and | |
231 // destruction. | |
232 struct DeviceEntry { | 248 struct DeviceEntry { |
233 DeviceEntry(MediaStreamType stream_type, | 249 DeviceEntry(MediaStreamType stream_type, |
234 const std::string& id, | 250 const std::string& id, |
235 scoped_ptr<VideoCaptureController> controller); | 251 scoped_ptr<VideoCaptureController> controller); |
236 ~DeviceEntry(); | 252 ~DeviceEntry(); |
237 | 253 |
238 const MediaStreamType stream_type; | 254 const MediaStreamType stream_type; |
239 const std::string id; | 255 const std::string id; |
240 | 256 |
241 // The controller. Only used from the IO thread. | 257 // The controller. Only used from the IO thread. |
242 scoped_ptr<VideoCaptureController> video_capture_controller; | 258 scoped_ptr<VideoCaptureController> video_capture_controller; |
243 | 259 |
244 // The capture device. Only used from the device thread. | 260 // The capture device. Only used from the device thread. |
245 scoped_ptr<media::VideoCaptureDevice> video_capture_device; | 261 scoped_ptr<media::VideoCaptureDevice> video_capture_device; |
246 }; | 262 }; |
247 typedef std::set<DeviceEntry*> DeviceEntries; | 263 |
264 typedef ScopedVector<DeviceEntry> DeviceEntries; | |
265 // Currently opened devices. The device may or may not be started. | |
248 DeviceEntries devices_; | 266 DeviceEntries devices_; |
249 | 267 |
268 // Struct used for queuing request for starting a device. | |
269 struct CaptureDeviceStartRequest { | |
270 CaptureDeviceStartRequest( | |
271 DeviceEntry* entry, | |
272 media::VideoCaptureSessionId session_id, | |
273 const media::VideoCaptureParams& params); | |
274 | |
275 DeviceEntry* entry; // Owned by |devices_| | |
276 media::VideoCaptureSessionId session_id; | |
277 media::VideoCaptureParams params; | |
278 // Set to true if the device should be stopped before it have successfully | |
tommi (sloooow) - chröme
2014/12/17 14:46:12
it have -> it has
perkj_chrome
2014/12/18 12:15:32
Done.
| |
279 // been started. | |
280 bool abort_start; | |
281 }; | |
282 | |
283 typedef std::list<CaptureDeviceStartRequest> DeviceStartQueue; | |
284 DeviceStartQueue device_start_queue_; | |
285 | |
250 // Device creation factory injected on construction from MediaStreamManager or | 286 // Device creation factory injected on construction from MediaStreamManager or |
251 // from the test harness. | 287 // from the test harness. |
252 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_; | 288 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_; |
253 | 289 |
254 // Local cache of the enumerated video capture devices' names and capture | 290 // Local cache of the enumerated video capture devices' names and capture |
255 // supported formats. A snapshot of the current devices and their capabilities | 291 // supported formats. A snapshot of the current devices and their capabilities |
256 // is composed in VideoCaptureDeviceFactory::EnumerateDeviceNames() and | 292 // is composed in VideoCaptureDeviceFactory::EnumerateDeviceNames() and |
257 // ConsolidateDevicesInfoOnDeviceThread(), and this snapshot is used to update | 293 // ConsolidateDevicesInfoOnDeviceThread(), and this snapshot is used to update |
258 // this list in OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will | 294 // this list in OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will |
259 // use this list if the device is not started, otherwise it will retrieve the | 295 // use this list if the device is not started, otherwise it will retrieve the |
260 // active device capture format from the VideoCaptureController associated. | 296 // active device capture format from the VideoCaptureController associated. |
261 media::VideoCaptureDeviceInfos devices_info_cache_; | 297 media::VideoCaptureDeviceInfos devices_info_cache_; |
262 | 298 |
263 // Accessed on the device thread only. | 299 // Accessed on the device thread only. |
264 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> | 300 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> |
265 notification_window_ids_; | 301 notification_window_ids_; |
266 | 302 |
267 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 303 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
268 }; | 304 }; |
269 | 305 |
270 } // namespace content | 306 } // namespace content |
271 | 307 |
272 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 308 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
OLD | NEW |