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

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

Issue 2800493002: [Mojo Video Capture] Create abstraction VideoCaptureProvider (Closed)
Patch Set: Rebase 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.
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 <list>
16 #include <map> 16 #include <map>
17 #include <set> 17 #include <set>
18 #include <string> 18 #include <string>
19 19
20 #include "base/macros.h" 20 #include "base/macros.h"
21 #include "base/memory/ref_counted.h" 21 #include "base/memory/ref_counted.h"
22 #include "base/memory/weak_ptr.h" 22 #include "base/memory/weak_ptr.h"
23 #include "base/message_loop/message_loop.h" 23 #include "base/message_loop/message_loop.h"
24 #include "base/observer_list.h" 24 #include "base/observer_list.h"
25 #include "base/process/process_handle.h" 25 #include "base/process/process_handle.h"
26 #include "base/threading/thread_checker.h" 26 #include "base/threading/thread_checker.h"
27 #include "base/timer/elapsed_timer.h" 27 #include "base/timer/elapsed_timer.h"
28 #include "build/build_config.h" 28 #include "build/build_config.h"
29 #include "content/browser/renderer_host/media/buildable_video_capture_device.h"
30 #include "content/browser/renderer_host/media/media_stream_provider.h" 29 #include "content/browser/renderer_host/media/media_stream_provider.h"
31 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" 30 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
31 #include "content/browser/renderer_host/media/video_capture_provider.h"
32 #include "content/common/content_export.h" 32 #include "content/common/content_export.h"
33 #include "content/common/media/media_stream_options.h" 33 #include "content/common/media/media_stream_options.h"
34 #include "media/base/video_facing.h" 34 #include "media/base/video_facing.h"
35 #include "media/capture/video/video_capture_device.h" 35 #include "media/capture/video/video_capture_device.h"
36 #include "media/capture/video/video_capture_device_info.h" 36 #include "media/capture/video/video_capture_device_info.h"
37 #include "media/capture/video/video_capture_system.h"
38 #include "media/capture/video_capture_types.h" 37 #include "media/capture/video_capture_types.h"
39 38
40 #if defined(OS_ANDROID) 39 #if defined(OS_ANDROID)
41 #include "base/android/application_status_listener.h" 40 #include "base/android/application_status_listener.h"
42 #endif 41 #endif
43 42
44 namespace content { 43 namespace content {
45 class VideoCaptureController; 44 class VideoCaptureController;
46 class VideoCaptureControllerEventHandler; 45 class VideoCaptureControllerEventHandler;
47 46
48 // VideoCaptureManager opens/closes and start/stops video capture devices. 47 // VideoCaptureManager opens/closes and start/stops video capture devices.
emircan 2017/04/10 20:48:12 Can you add information about threading?
chfremer 2017/04/10 22:24:44 Done. Moved the file-level comment down to the cla
49 class CONTENT_EXPORT VideoCaptureManager 48 class CONTENT_EXPORT VideoCaptureManager
50 : public MediaStreamProvider, 49 : public MediaStreamProvider,
51 public BuildableVideoCaptureDevice::Callbacks { 50 public BuildableVideoCaptureDevice::Callbacks {
52 public: 51 public:
53 using VideoCaptureDevice = media::VideoCaptureDevice; 52 using VideoCaptureDevice = media::VideoCaptureDevice;
54 53
55 // Callback used to signal the completion of a controller lookup. 54 // Callback used to signal the completion of a controller lookup.
56 using DoneCB = 55 using DoneCB =
57 base::Callback<void(const base::WeakPtr<VideoCaptureController>&)>; 56 base::Callback<void(const base::WeakPtr<VideoCaptureController>&)>;
58 57
59 VideoCaptureManager( 58 explicit VideoCaptureManager(
60 std::unique_ptr<media::VideoCaptureSystem> capture_system, 59 std::unique_ptr<VideoCaptureProvider> video_capture_provider);
61 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner);
62 60
63 // AddVideoCaptureObserver() can be called only before any devices are opened. 61 // AddVideoCaptureObserver() can be called only before any devices are opened.
64 // RemoveAllVideoCaptureObservers() can be called only after all devices 62 // RemoveAllVideoCaptureObservers() can be called only after all devices
65 // are closed. 63 // are closed.
66 // They can be called more than once and it's ok to not call at all if the 64 // They can be called more than once and it's ok to not call at all if the
67 // client is not interested in receiving media::VideoCaptureObserver callacks. 65 // client is not interested in receiving media::VideoCaptureObserver callacks.
68 // This methods can be called on whatever thread. The callbacks of 66 // This methods can be called on whatever thread. The callbacks of
69 // media::VideoCaptureObserver arrive on browser IO thread. 67 // media::VideoCaptureObserver arrive on browser IO thread.
70 void AddVideoCaptureObserver(media::VideoCaptureObserver* observer); 68 void AddVideoCaptureObserver(media::VideoCaptureObserver* observer);
71 void RemoveAllVideoCaptureObservers(); 69 void RemoveAllVideoCaptureObservers();
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 258
261 #if defined(OS_ANDROID) 259 #if defined(OS_ANDROID)
262 void ReleaseDevices(); 260 void ReleaseDevices();
263 void ResumeDevices(); 261 void ResumeDevices();
264 262
265 std::unique_ptr<base::android::ApplicationStatusListener> 263 std::unique_ptr<base::android::ApplicationStatusListener>
266 app_status_listener_; 264 app_status_listener_;
267 bool application_state_has_running_activities_; 265 bool application_state_has_running_activities_;
268 #endif 266 #endif
269 267
270 // The message loop of media stream device thread, where VCD's live.
271 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_;
272
273 // Only accessed on Browser::IO thread. 268 // Only accessed on Browser::IO thread.
274 base::ObserverList<MediaStreamProviderListener> listeners_; 269 base::ObserverList<MediaStreamProviderListener> listeners_;
275 media::VideoCaptureSessionId new_capture_session_id_; 270 media::VideoCaptureSessionId new_capture_session_id_;
276 271
277 // An entry is kept in this map for every session that has been created via 272 // An entry is kept in this map for every session that has been created via
278 // the Open() entry point. The keys are session_id's. This map is used to 273 // the Open() entry point. The keys are session_id's. This map is used to
279 // determine which device to use when ConnectClient() occurs. Used 274 // determine which device to use when ConnectClient() occurs. Used
280 // only on the IO thread. 275 // only on the IO thread.
281 SessionMap sessions_; 276 SessionMap sessions_;
282 277
283 // Currently opened VideoCaptureController instances. The device may or may 278 // Currently opened VideoCaptureController instances. The device may or may
284 // not be started. This member is only accessed on IO thread. 279 // not be started. This member is only accessed on IO thread.
285 std::vector<scoped_refptr<VideoCaptureController>> controllers_; 280 std::vector<scoped_refptr<VideoCaptureController>> controllers_;
286 281
287 // TODO(chfremer): Consider using CancellableTaskTracker, see 282 // TODO(chfremer): Consider using CancellableTaskTracker, see
288 // crbug.com/598465. 283 // crbug.com/598465.
289 DeviceStartQueue device_start_request_queue_; 284 DeviceStartQueue device_start_request_queue_;
290 285
291 // Queue to keep photo-associated requests waiting for a device to initialize, 286 // Queue to keep photo-associated requests waiting for a device to initialize,
292 // bundles a session id integer and an associated photo-related request. 287 // bundles a session id integer and an associated photo-related request.
293 std::list<std::pair<int, base::Closure>> photo_request_queue_; 288 std::list<std::pair<int, base::Closure>> photo_request_queue_;
294 289
295 // Device creation factory injected on construction from MediaStreamManager or 290 const std::unique_ptr<VideoCaptureProvider> video_capture_provider_;
296 // from the test harness.
297 std::unique_ptr<media::VideoCaptureSystem> video_capture_system_;
298 291
299 base::ObserverList<media::VideoCaptureObserver> capture_observers_; 292 base::ObserverList<media::VideoCaptureObserver> capture_observers_;
300 293
301 // Local cache of the enumerated DeviceInfos. GetDeviceSupportedFormats() will 294 // Local cache of the enumerated DeviceInfos. GetDeviceSupportedFormats() will
302 // 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
303 // active device capture format from the VideoCaptureController associated. 296 // active device capture format from the VideoCaptureController associated.
304 std::vector<media::VideoCaptureDeviceInfo> devices_info_cache_; 297 std::vector<media::VideoCaptureDeviceInfo> devices_info_cache_;
305 298
306 // Map used by DesktopCapture. 299 // Map used by DesktopCapture.
307 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> 300 std::map<media::VideoCaptureSessionId, gfx::NativeViewId>
308 notification_window_ids_; 301 notification_window_ids_;
309 302
310 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); 303 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager);
311 }; 304 };
312 305
313 } // namespace content 306 } // namespace content
314 307
315 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ 308 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698