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. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // this value should be a session id previously returned by Open(). | 80 // this value should be a session id previously returned by Open(). |
81 // | 81 // |
82 // If the device is not already started (i.e., no other client is currently | 82 // If the device is not already started (i.e., no other client is currently |
83 // capturing from this device), this call will cause a VideoCaptureController | 83 // capturing from this device), this call will cause a VideoCaptureController |
84 // and VideoCaptureDevice to be created, possibly asynchronously. | 84 // and VideoCaptureDevice to be created, possibly asynchronously. |
85 // | 85 // |
86 // On success, the controller is returned via calling |done_cb|, indicating | 86 // On success, the controller is returned via calling |done_cb|, indicating |
87 // that the client was successfully added. A NULL controller is passed to | 87 // that the client was successfully added. A NULL controller is passed to |
88 // the callback on failure. |done_cb| is not allowed to synchronously call | 88 // the callback on failure. |done_cb| is not allowed to synchronously call |
89 // StopCaptureForClient(). | 89 // StopCaptureForClient(). |
90 void StartCaptureForClient(media::VideoCaptureSessionId session_id, | 90 void ConnectClient(media::VideoCaptureSessionId session_id, |
91 const media::VideoCaptureParams& capture_params, | 91 const media::VideoCaptureParams& capture_params, |
92 VideoCaptureControllerID client_id, | 92 VideoCaptureControllerID client_id, |
93 VideoCaptureControllerEventHandler* client_handler, | 93 VideoCaptureControllerEventHandler* client_handler, |
94 const DoneCB& done_cb); | 94 const DoneCB& done_cb); |
95 | 95 |
96 // Called by VideoCaptureHost to remove |client_handler|. If this is the last | 96 // Called by VideoCaptureHost to remove |client_handler|. If this is the last |
97 // client of the device, the |controller| and its VideoCaptureDevice may be | 97 // client of the device, the |controller| and its VideoCaptureDevice may be |
98 // destroyed. The client must not access |controller| after calling this | 98 // destroyed. The client must not access |controller| after calling this |
99 // function. | 99 // function. |
100 void StopCaptureForClient(VideoCaptureController* controller, | 100 void DisconnectClient(VideoCaptureController* controller, |
101 VideoCaptureControllerID client_id, | 101 VideoCaptureControllerID client_id, |
102 VideoCaptureControllerEventHandler* client_handler, | 102 VideoCaptureControllerEventHandler* client_handler, |
103 bool aborted_due_to_error); | 103 bool aborted_due_to_error); |
104 | 104 |
105 // Called by VideoCaptureHost to pause to update video buffer specified by | 105 // Called by VideoCaptureHost to pause to update video buffer specified by |
106 // |client_id| and |client_handler|. If all clients of |controller| are | 106 // |client_id| and |client_handler|. If all clients of |controller| are |
107 // paused, the corresponding device will be closed. | 107 // paused, the corresponding device will be closed. |
108 void PauseCaptureForClient( | 108 void PauseCaptureForClient( |
109 VideoCaptureController* controller, | 109 VideoCaptureController* controller, |
110 VideoCaptureControllerID client_id, | 110 VideoCaptureControllerID client_id, |
111 VideoCaptureControllerEventHandler* client_handler); | 111 VideoCaptureControllerEventHandler* client_handler); |
112 | 112 |
113 // Called by VideoCaptureHost to resume to update video buffer specified by | 113 // Called by VideoCaptureHost to resume to update video buffer specified by |
114 // |client_id| and |client_handler|. The |session_id| and |params| should be | 114 // |client_id| and |client_handler|. The |session_id| and |params| should be |
115 // same as those used in StartCaptureForClient(). | 115 // same as those used in ConnectClient(). |
116 // If this is first active client of |controller|, device will be allocated | 116 // If this is first active client of |controller|, device will be allocated |
117 // and it will take a little time to resume. | 117 // and it will take a little time to resume. |
118 // Allocating device could failed if other app holds the camera, the error | 118 // Allocating device could failed if other app holds the camera, the error |
119 // will be notified through VideoCaptureControllerEventHandler::OnError(). | 119 // will be notified through VideoCaptureControllerEventHandler::OnError(). |
120 void ResumeCaptureForClient( | 120 void ResumeCaptureForClient( |
121 media::VideoCaptureSessionId session_id, | 121 media::VideoCaptureSessionId session_id, |
122 const media::VideoCaptureParams& params, | 122 const media::VideoCaptureParams& params, |
123 VideoCaptureController* controller, | 123 VideoCaptureController* controller, |
124 VideoCaptureControllerID client_id, | 124 VideoCaptureControllerID client_id, |
125 VideoCaptureControllerEventHandler* client_handler); | 125 VideoCaptureControllerEventHandler* client_handler); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 using EnumerationCallback = | 197 using EnumerationCallback = |
198 base::Callback<void(const media::VideoCaptureDeviceDescriptors&)>; | 198 base::Callback<void(const media::VideoCaptureDeviceDescriptors&)>; |
199 void EnumerateDevices(const EnumerationCallback& client_callback); | 199 void EnumerateDevices(const EnumerationCallback& client_callback); |
200 | 200 |
201 // BuildableDeviceCallbacks implementation: | 201 // BuildableDeviceCallbacks implementation: |
202 const media::VideoCaptureDeviceDescriptor* LookupDeviceDescriptor( | 202 const media::VideoCaptureDeviceDescriptor* LookupDeviceDescriptor( |
203 const std::string& id) override; | 203 const std::string& id) override; |
204 void WillStartDevice(media::VideoFacingMode facing_mode) override; | 204 void WillStartDevice(media::VideoFacingMode facing_mode) override; |
205 void DidStartDevice(VideoCaptureController* controller) override; | 205 void DidStartDevice(VideoCaptureController* controller) override; |
206 void OnDeviceStartFailed(VideoCaptureController* controller) override; | 206 void OnDeviceStartFailed(VideoCaptureController* controller) override; |
| 207 void OnDeviceStartAborted() override; |
207 | 208 |
208 // Retrieves camera calibration information for a particular device. Returns | 209 // Retrieves camera calibration information for a particular device. Returns |
209 // nullopt_t if the |device_id| is not found or camera calibration information | 210 // nullopt_t if the |device_id| is not found or camera calibration information |
210 // is not available for the device. Camera calibration is cached during | 211 // is not available for the device. Camera calibration is cached during |
211 // device(s) enumeration. | 212 // device(s) enumeration. |
212 base::Optional<CameraCalibration> GetCameraCalibration( | 213 base::Optional<CameraCalibration> GetCameraCalibration( |
213 const std::string& device_id); | 214 const std::string& device_id); |
214 | 215 |
215 private: | 216 private: |
216 class CaptureDeviceStartRequest; | 217 class CaptureDeviceStartRequest; |
(...skipping 26 matching lines...) Expand all Loading... |
243 | 244 |
244 // Checks to see if |controller| has no clients left. If so, remove it from | 245 // Checks to see if |controller| has no clients left. If so, remove it from |
245 // the list of controllers, and delete it asynchronously. |controller| may be | 246 // the list of controllers, and delete it asynchronously. |controller| may be |
246 // freed by this function. | 247 // freed by this function. |
247 void DestroyControllerIfNoClients(VideoCaptureController* controller); | 248 void DestroyControllerIfNoClients(VideoCaptureController* controller); |
248 | 249 |
249 // Finds a VideoCaptureController in different ways: by |session_id|, by its | 250 // Finds a VideoCaptureController in different ways: by |session_id|, by its |
250 // |device_id| and |type| (if it is already opened), by its |controller| or by | 251 // |device_id| and |type| (if it is already opened), by its |controller| or by |
251 // its |serial_id|. In all cases, if not found, nullptr is returned. | 252 // its |serial_id|. In all cases, if not found, nullptr is returned. |
252 VideoCaptureController* LookupControllerBySessionId(int session_id); | 253 VideoCaptureController* LookupControllerBySessionId(int session_id); |
253 VideoCaptureController* LookupControllerByTypeAndId( | 254 VideoCaptureController* LookupControllerByMediaTypeAndDeviceId( |
254 MediaStreamType type, | 255 MediaStreamType type, |
255 const std::string& device_id) const; | 256 const std::string& device_id) const; |
256 bool IsControllerPointerValid(const VideoCaptureController* controller) const; | 257 bool IsControllerPointerValid(const VideoCaptureController* controller) const; |
257 VideoCaptureController* LookupControllerBySerialId(int serial_id) const; | 258 VideoCaptureController* LookupControllerBySerialId(int serial_id) const; |
258 scoped_refptr<VideoCaptureController> GetControllerSharedRefFromSerialId( | 259 scoped_refptr<VideoCaptureController> GetControllerSharedRefFromSerialId( |
259 int serial_id) const; | 260 int serial_id) const; |
260 | 261 |
261 // Finds the device info by |id| in |devices_info_cache_|, or nullptr. | 262 // Finds the device info by |id| in |devices_info_cache_|, or nullptr. |
262 DeviceInfo* GetDeviceInfoById(const std::string& id); | 263 DeviceInfo* GetDeviceInfoById(const std::string& id); |
263 | 264 |
264 // Finds a VideoCaptureController for the indicated |capture_session_id|, | 265 // Finds a VideoCaptureController for the indicated |capture_session_id|, |
265 // creating a fresh one if necessary. Returns nullptr if said | 266 // creating a fresh one if necessary. Returns nullptr if said |
266 // |capture_session_id| is invalid. | 267 // |capture_session_id| is invalid. |
267 VideoCaptureController* GetOrCreateController( | 268 VideoCaptureController* GetOrCreateController( |
268 media::VideoCaptureSessionId capture_session_id, | 269 media::VideoCaptureSessionId capture_session_id, |
269 const media::VideoCaptureParams& params); | 270 const media::VideoCaptureParams& params); |
270 | 271 |
271 // Starting a capture device can take 1-2 seconds. | 272 // Starting a capture device can take 1-2 seconds. |
272 // To avoid multiple unnecessary start/stop commands to the OS, each start | 273 // To avoid multiple unnecessary start/stop commands to the OS, each start |
273 // request is queued in |device_start_queue_|. | 274 // request is queued in |device_start_request_queue_|. |
274 // QueueStartDevice creates a new entry in |device_start_queue_| and posts a | 275 // QueueStartDevice creates a new entry in |device_start_request_queue_| and |
| 276 // posts a |
275 // request to start the device on the device thread unless there is | 277 // request to start the device on the device thread unless there is |
276 // another request pending start. | 278 // another request pending start. |
277 void QueueStartDevice(media::VideoCaptureSessionId session_id, | 279 void QueueStartDevice(media::VideoCaptureSessionId session_id, |
278 VideoCaptureController* controller, | 280 VideoCaptureController* controller, |
279 const media::VideoCaptureParams& params); | 281 const media::VideoCaptureParams& params); |
280 void DoStopDevice(VideoCaptureController* controller); | 282 void DoStopDevice(VideoCaptureController* controller); |
281 void HandleQueuedStartRequest(); | 283 void ProcessDeviceStartRequestQueue(); |
282 | 284 |
283 void MaybePostDesktopCaptureWindowId(media::VideoCaptureSessionId session_id); | 285 void MaybePostDesktopCaptureWindowId(media::VideoCaptureSessionId session_id); |
284 | 286 |
285 #if defined(OS_ANDROID) | 287 #if defined(OS_ANDROID) |
286 void ReleaseDevices(); | 288 void ReleaseDevices(); |
287 void ResumeDevices(); | 289 void ResumeDevices(); |
288 | 290 |
289 std::unique_ptr<base::android::ApplicationStatusListener> | 291 std::unique_ptr<base::android::ApplicationStatusListener> |
290 app_status_listener_; | 292 app_status_listener_; |
291 bool application_state_has_running_activities_; | 293 bool application_state_has_running_activities_; |
292 #endif | 294 #endif |
293 | 295 |
294 // The message loop of media stream device thread, where VCD's live. | 296 // The message loop of media stream device thread, where VCD's live. |
295 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; | 297 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; |
296 | 298 |
297 // Only accessed on Browser::IO thread. | 299 // Only accessed on Browser::IO thread. |
298 base::ObserverList<MediaStreamProviderListener> listeners_; | 300 base::ObserverList<MediaStreamProviderListener> listeners_; |
299 media::VideoCaptureSessionId new_capture_session_id_; | 301 media::VideoCaptureSessionId new_capture_session_id_; |
300 | 302 |
301 // An entry is kept in this map for every session that has been created via | 303 // An entry is kept in this map for every session that has been created via |
302 // the Open() entry point. The keys are session_id's. This map is used to | 304 // the Open() entry point. The keys are session_id's. This map is used to |
303 // determine which device to use when StartCaptureForClient() occurs. Used | 305 // determine which device to use when ConnectClient() occurs. Used |
304 // only on the IO thread. | 306 // only on the IO thread. |
305 SessionMap sessions_; | 307 SessionMap sessions_; |
306 | 308 |
307 // Currently opened VideoCaptureController instances. The device may or may | 309 // Currently opened VideoCaptureController instances. The device may or may |
308 // not be started. This member is only accessed on IO thread. | 310 // not be started. This member is only accessed on IO thread. |
309 std::vector<scoped_refptr<VideoCaptureController>> controllers_; | 311 std::vector<scoped_refptr<VideoCaptureController>> controllers_; |
310 | 312 |
311 DeviceStartQueue device_start_queue_; | 313 DeviceStartQueue device_start_request_queue_; |
312 | 314 |
313 // Queue to keep photo-associated requests waiting for a device to initialize, | 315 // Queue to keep photo-associated requests waiting for a device to initialize, |
314 // bundles a session id integer and an associated photo-related request. | 316 // bundles a session id integer and an associated photo-related request. |
315 std::list<std::pair<int, base::Closure>> photo_request_queue_; | 317 std::list<std::pair<int, base::Closure>> photo_request_queue_; |
316 | 318 |
317 // Device creation factory injected on construction from MediaStreamManager or | 319 // Device creation factory injected on construction from MediaStreamManager or |
318 // from the test harness. | 320 // from the test harness. |
319 std::unique_ptr<media::VideoCaptureDeviceFactory> | 321 std::unique_ptr<media::VideoCaptureDeviceFactory> |
320 video_capture_device_factory_; | 322 video_capture_device_factory_; |
321 | 323 |
(...skipping 11 matching lines...) Expand all Loading... |
333 // Map used by DesktopCapture. | 335 // Map used by DesktopCapture. |
334 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> | 336 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> |
335 notification_window_ids_; | 337 notification_window_ids_; |
336 | 338 |
337 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 339 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
338 }; | 340 }; |
339 | 341 |
340 } // namespace content | 342 } // namespace content |
341 | 343 |
342 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 344 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
OLD | NEW |