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" |
20 #include "base/memory/weak_ptr.h" | 21 #include "base/memory/weak_ptr.h" |
21 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
22 #include "base/process/process_handle.h" | 23 #include "base/process/process_handle.h" |
23 #include "base/timer/elapsed_timer.h" | 24 #include "base/timer/elapsed_timer.h" |
24 #include "content/browser/renderer_host/media/media_stream_provider.h" | 25 #include "content/browser/renderer_host/media/media_stream_provider.h" |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 // Consolidates the cached devices list with the list of currently connected | 176 // Consolidates the cached devices list with the list of currently connected |
176 // devices in the system |names_snapshot|. Retrieves the supported formats of | 177 // devices in the system |names_snapshot|. Retrieves the supported formats of |
177 // the new devices and sends the new cache to OnDevicesInfoEnumerated(). | 178 // the new devices and sends the new cache to OnDevicesInfoEnumerated(). |
178 void ConsolidateDevicesInfoOnDeviceThread( | 179 void ConsolidateDevicesInfoOnDeviceThread( |
179 base::Callback<void(const media::VideoCaptureDeviceInfos&)> | 180 base::Callback<void(const media::VideoCaptureDeviceInfos&)> |
180 on_devices_enumerated_callback, | 181 on_devices_enumerated_callback, |
181 MediaStreamType stream_type, | 182 MediaStreamType stream_type, |
182 const media::VideoCaptureDeviceInfos& old_device_info_cache, | 183 const media::VideoCaptureDeviceInfos& old_device_info_cache, |
183 scoped_ptr<media::VideoCaptureDevice::Names> names_snapshot); | 184 scoped_ptr<media::VideoCaptureDevice::Names> names_snapshot); |
184 | 185 |
186 // On the OS level, starting a capture device can take 1-2 seconds. | |
187 // To avoid multiple unnecessary start/stop commands to the OS, each start | |
188 // request is queued in |device_start_queue_|. | |
189 // QueueStartDevice creates a new entry in |device_start_queue_| and posts a | |
190 // request to start |entry| on the device thread unless there is another | |
191 // request pending start. | |
192 void QueueStartDevice(media::VideoCaptureSessionId session_id, | |
193 DeviceEntry* entry, | |
tommi (sloooow) - chröme
2014/12/15 16:25:05
can you document the ownership/lifetime of |entry|
| |
194 const media::VideoCaptureParams& params); | |
195 void OnDeviceStarted(); | |
196 void DoStopDevice(DeviceEntry* entry, bool delete_entry); | |
197 void HandleQueuedStartRequest(); | |
198 | |
185 // Creates and Starts a new VideoCaptureDevice, storing the result in | 199 // Creates and Starts a new VideoCaptureDevice, storing the result in |
186 // |entry->video_capture_device|. Ownership of |client| passes to | 200 // |entry->video_capture_device|. Ownership of |client| passes to |
187 // the device. | 201 // the device. |
188 void DoStartDeviceOnDeviceThread( | 202 void DoStartDeviceOnDeviceThread( |
189 media::VideoCaptureSessionId session_id, | 203 media::VideoCaptureSessionId session_id, |
190 DeviceEntry* entry, | 204 DeviceEntry* entry, |
191 const media::VideoCaptureParams& params, | 205 const media::VideoCaptureParams& params, |
192 scoped_ptr<media::VideoCaptureDevice::Client> client); | 206 scoped_ptr<media::VideoCaptureDevice::Client> client); |
193 | 207 |
194 // Stops and destroys the VideoCaptureDevice held in | 208 // Stops and destroys the VideoCaptureDevice held in |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 const MediaStreamType stream_type; | 252 const MediaStreamType stream_type; |
239 const std::string id; | 253 const std::string id; |
240 | 254 |
241 // The controller. Only used from the IO thread. | 255 // The controller. Only used from the IO thread. |
242 scoped_ptr<VideoCaptureController> video_capture_controller; | 256 scoped_ptr<VideoCaptureController> video_capture_controller; |
243 | 257 |
244 // The capture device. Only used from the device thread. | 258 // The capture device. Only used from the device thread. |
245 scoped_ptr<media::VideoCaptureDevice> video_capture_device; | 259 scoped_ptr<media::VideoCaptureDevice> video_capture_device; |
246 }; | 260 }; |
247 typedef std::set<DeviceEntry*> DeviceEntries; | 261 typedef std::set<DeviceEntry*> DeviceEntries; |
262 // Currently opened devices. The device may or may not be started. | |
248 DeviceEntries devices_; | 263 DeviceEntries devices_; |
249 | 264 |
265 // On the OS level, starting a capture device can take 1-2 seconds. | |
266 // To avoid multiple unnecessary start/stop commands to the OS, each start | |
267 // request is queued in a CaptureDeviceStartRequest. | |
268 struct CaptureDeviceStartRequest { | |
269 CaptureDeviceStartRequest(DeviceEntry* device_entry, | |
270 media::VideoCaptureSessionId session_id, | |
271 const media::VideoCaptureParams& params); | |
272 | |
273 DeviceEntry* device_entry; | |
tommi (sloooow) - chröme
2014/12/15 16:25:05
ownership/scope?
| |
274 media::VideoCaptureSessionId session_id; | |
275 media::VideoCaptureParams params; | |
276 }; | |
277 typedef std::list<CaptureDeviceStartRequest> DeviceStartQueue; | |
278 DeviceStartQueue device_start_queue_; | |
279 | |
250 // Device creation factory injected on construction from MediaStreamManager or | 280 // Device creation factory injected on construction from MediaStreamManager or |
251 // from the test harness. | 281 // from the test harness. |
252 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_; | 282 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_; |
253 | 283 |
254 // Local cache of the enumerated video capture devices' names and capture | 284 // Local cache of the enumerated video capture devices' names and capture |
255 // supported formats. A snapshot of the current devices and their capabilities | 285 // supported formats. A snapshot of the current devices and their capabilities |
256 // is composed in VideoCaptureDeviceFactory::EnumerateDeviceNames() and | 286 // is composed in VideoCaptureDeviceFactory::EnumerateDeviceNames() and |
257 // ConsolidateDevicesInfoOnDeviceThread(), and this snapshot is used to update | 287 // ConsolidateDevicesInfoOnDeviceThread(), and this snapshot is used to update |
258 // this list in OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will | 288 // this list in OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will |
259 // use this list if the device is not started, otherwise it will retrieve the | 289 // use this list if the device is not started, otherwise it will retrieve the |
260 // active device capture format from the VideoCaptureController associated. | 290 // active device capture format from the VideoCaptureController associated. |
261 media::VideoCaptureDeviceInfos devices_info_cache_; | 291 media::VideoCaptureDeviceInfos devices_info_cache_; |
262 | 292 |
263 // Accessed on the device thread only. | 293 // Accessed on the device thread only. |
264 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> | 294 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> |
265 notification_window_ids_; | 295 notification_window_ids_; |
266 | 296 |
267 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 297 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
268 }; | 298 }; |
269 | 299 |
270 } // namespace content | 300 } // namespace content |
271 | 301 |
272 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 302 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
OLD | NEW |