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

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: Incorporate suggestions from Patch Set 1 Created 3 years, 9 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
mcasas 2017/03/24 21:54:36 nit: Should we rename also {Pause,Resume}CaptureFo
chfremer 2017/03/31 17:25:37 I actually prefer the naming as it is. To me, {Pau
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);
126 126
127 // Called by VideoCaptureHost to request a refresh frame from the video 127 // Called by VideoCaptureHost to request a refresh frame from the video
128 // capture device. 128 // capture device.
129 void RequestRefreshFrameForClient(VideoCaptureController* controller); 129 void RequestRefreshFrameForClient(VideoCaptureController* controller);
130 130
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 scoped_refptr<VideoCaptureController> GetControllerSharedRef(
258 scoped_refptr<VideoCaptureController> GetControllerSharedRefFromSerialId( 259 VideoCaptureController* controller) const;
259 int serial_id) const;
260 260
261 // Finds the device info by |id| in |devices_info_cache_|, or nullptr. 261 // Finds the device info by |id| in |devices_info_cache_|, or nullptr.
262 DeviceInfo* GetDeviceInfoById(const std::string& id); 262 DeviceInfo* GetDeviceInfoById(const std::string& id);
263 263
264 // Finds a VideoCaptureController for the indicated |capture_session_id|, 264 // Finds a VideoCaptureController for the indicated |capture_session_id|,
265 // creating a fresh one if necessary. Returns nullptr if said 265 // creating a fresh one if necessary. Returns nullptr if said
266 // |capture_session_id| is invalid. 266 // |capture_session_id| is invalid.
267 VideoCaptureController* GetOrCreateController( 267 VideoCaptureController* GetOrCreateController(
268 media::VideoCaptureSessionId capture_session_id, 268 media::VideoCaptureSessionId capture_session_id,
269 const media::VideoCaptureParams& params); 269 const media::VideoCaptureParams& params);
270 270
271 // Starting a capture device can take 1-2 seconds. 271 // Starting a capture device can take 1-2 seconds.
272 // To avoid multiple unnecessary start/stop commands to the OS, each start 272 // To avoid multiple unnecessary start/stop commands to the OS, each start
273 // request is queued in |device_start_queue_|. 273 // request is queued in |device_start_request_queue_|.
274 // QueueStartDevice creates a new entry in |device_start_queue_| and posts a 274 // QueueStartDevice creates a new entry in |device_start_request_queue_| and
275 // posts a
275 // request to start the device on the device thread unless there is 276 // request to start the device on the device thread unless there is
276 // another request pending start. 277 // another request pending start.
277 void QueueStartDevice(media::VideoCaptureSessionId session_id, 278 void QueueStartDevice(media::VideoCaptureSessionId session_id,
278 VideoCaptureController* controller, 279 VideoCaptureController* controller,
279 const media::VideoCaptureParams& params); 280 const media::VideoCaptureParams& params);
280 void DoStopDevice(VideoCaptureController* controller); 281 void DoStopDevice(VideoCaptureController* controller);
281 void HandleQueuedStartRequest(); 282 void ProcessDeviceStartRequestQueue();
282 283
283 void MaybePostDesktopCaptureWindowId(media::VideoCaptureSessionId session_id); 284 void MaybePostDesktopCaptureWindowId(media::VideoCaptureSessionId session_id);
284 285
285 #if defined(OS_ANDROID) 286 #if defined(OS_ANDROID)
286 void ReleaseDevices(); 287 void ReleaseDevices();
287 void ResumeDevices(); 288 void ResumeDevices();
288 289
289 std::unique_ptr<base::android::ApplicationStatusListener> 290 std::unique_ptr<base::android::ApplicationStatusListener>
290 app_status_listener_; 291 app_status_listener_;
291 bool application_state_has_running_activities_; 292 bool application_state_has_running_activities_;
292 #endif 293 #endif
293 294
294 // The message loop of media stream device thread, where VCD's live. 295 // The message loop of media stream device thread, where VCD's live.
295 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; 296 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_;
296 297
297 // Only accessed on Browser::IO thread. 298 // Only accessed on Browser::IO thread.
298 base::ObserverList<MediaStreamProviderListener> listeners_; 299 base::ObserverList<MediaStreamProviderListener> listeners_;
299 media::VideoCaptureSessionId new_capture_session_id_; 300 media::VideoCaptureSessionId new_capture_session_id_;
300 301
301 // An entry is kept in this map for every session that has been created via 302 // 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 303 // 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 304 // determine which device to use when ConnectClient() occurs. Used
304 // only on the IO thread. 305 // only on the IO thread.
305 SessionMap sessions_; 306 SessionMap sessions_;
306 307
307 // Currently opened VideoCaptureController instances. The device may or may 308 // Currently opened VideoCaptureController instances. The device may or may
308 // not be started. This member is only accessed on IO thread. 309 // not be started. This member is only accessed on IO thread.
309 std::vector<scoped_refptr<VideoCaptureController>> controllers_; 310 std::vector<scoped_refptr<VideoCaptureController>> controllers_;
310 311
311 DeviceStartQueue device_start_queue_; 312 DeviceStartQueue device_start_request_queue_;
mcasas 2017/03/24 21:54:36 DeviceStartQueue is just a list of CaptureDeviceSt
chfremer 2017/03/31 17:25:37 Done.
312 313
313 // Queue to keep photo-associated requests waiting for a device to initialize, 314 // Queue to keep photo-associated requests waiting for a device to initialize,
314 // bundles a session id integer and an associated photo-related request. 315 // bundles a session id integer and an associated photo-related request.
315 std::list<std::pair<int, base::Closure>> photo_request_queue_; 316 std::list<std::pair<int, base::Closure>> photo_request_queue_;
316 317
317 // Device creation factory injected on construction from MediaStreamManager or 318 // Device creation factory injected on construction from MediaStreamManager or
318 // from the test harness. 319 // from the test harness.
319 std::unique_ptr<media::VideoCaptureDeviceFactory> 320 std::unique_ptr<media::VideoCaptureDeviceFactory>
320 video_capture_device_factory_; 321 video_capture_device_factory_;
321 322
(...skipping 11 matching lines...) Expand all
333 // Map used by DesktopCapture. 334 // Map used by DesktopCapture.
334 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> 335 std::map<media::VideoCaptureSessionId, gfx::NativeViewId>
335 notification_window_ids_; 336 notification_window_ids_;
336 337
337 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); 338 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager);
338 }; 339 };
339 340
340 } // namespace content 341 } // namespace content
341 342
342 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ 343 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698