Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Side by Side Diff: content/browser/renderer_host/media/video_capture_manager.h

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

Powered by Google App Engine
This is Rietveld 408576698