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 <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/process/process_handle.h" | 25 #include "base/process/process_handle.h" |
25 #include "base/threading/thread_checker.h" | 26 #include "base/threading/thread_checker.h" |
26 #include "base/timer/elapsed_timer.h" | 27 #include "base/timer/elapsed_timer.h" |
27 #include "build/build_config.h" | 28 #include "build/build_config.h" |
28 #include "content/browser/renderer_host/media/media_stream_provider.h" | 29 #include "content/browser/renderer_host/media/media_stream_provider.h" |
29 #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" |
30 #include "content/common/content_export.h" | 31 #include "content/common/content_export.h" |
31 #include "content/common/media/media_stream_options.h" | 32 #include "content/common/media/media_stream_options.h" |
33 #include "media/base/video_facing.h" | |
32 #include "media/capture/video/video_capture_device.h" | 34 #include "media/capture/video/video_capture_device.h" |
33 #include "media/capture/video/video_capture_device_factory.h" | 35 #include "media/capture/video/video_capture_device_factory.h" |
34 #include "media/capture/video_capture_types.h" | 36 #include "media/capture/video_capture_types.h" |
35 | 37 |
36 #if defined(OS_ANDROID) | 38 #if defined(OS_ANDROID) |
37 #include "base/android/application_status_listener.h" | 39 #include "base/android/application_status_listener.h" |
38 #endif | 40 #endif |
39 | 41 |
40 namespace content { | 42 namespace content { |
41 class VideoCaptureController; | 43 class VideoCaptureController; |
42 class VideoCaptureControllerEventHandler; | 44 class VideoCaptureControllerEventHandler; |
43 | 45 |
44 // VideoCaptureManager opens/closes and start/stops video capture devices. | 46 // VideoCaptureManager opens/closes and start/stops video capture devices. |
45 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { | 47 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { |
46 public: | 48 public: |
47 using VideoCaptureDevice = media::VideoCaptureDevice; | 49 using VideoCaptureDevice = media::VideoCaptureDevice; |
48 | 50 |
49 // Callback used to signal the completion of a controller lookup. | 51 // Callback used to signal the completion of a controller lookup. |
50 using DoneCB = | 52 using DoneCB = |
51 base::Callback<void(const base::WeakPtr<VideoCaptureController>&)>; | 53 base::Callback<void(const base::WeakPtr<VideoCaptureController>&)>; |
52 | 54 |
53 explicit VideoCaptureManager( | 55 explicit VideoCaptureManager( |
54 std::unique_ptr<media::VideoCaptureDeviceFactory> factory); | 56 std::unique_ptr<media::VideoCaptureDeviceFactory> factory); |
55 | 57 |
58 // AddVideoCaptureObserver() can be called only before any devices are opened. | |
59 // RemoveAllVideoCaptureObservers() can be called only after all devices | |
60 // are closed. | |
61 // They can be called more than once and it's ok to not call at all if the | |
62 // client is not interested in receiving media::VideoCaptureObserver callacks. | |
63 // This methods can be called on whatever thread. The callbacks of | |
64 // media::VideoCaptureObserver arrive on browser IO thread. | |
65 void AddVideoCaptureObserver(media::VideoCaptureObserver* observer); | |
66 void RemoveAllVideoCaptureObservers(); | |
67 | |
56 void Unregister(); | 68 void Unregister(); |
57 | 69 |
58 // Implements MediaStreamProvider. | 70 // Implements MediaStreamProvider. |
59 void Register(MediaStreamProviderListener* listener, | 71 void Register(MediaStreamProviderListener* listener, |
60 const scoped_refptr<base::SingleThreadTaskRunner>& | 72 const scoped_refptr<base::SingleThreadTaskRunner>& |
61 device_task_runner) override; | 73 device_task_runner) override; |
62 int Open(const StreamDeviceInfo& device) override; | 74 int Open(const StreamDeviceInfo& device) override; |
63 void Close(int capture_session_id) override; | 75 void Close(int capture_session_id) override; |
64 | 76 |
65 // Called by VideoCaptureHost to locate a capture device for |capture_params|, | 77 // Called by VideoCaptureHost to locate a capture device for |capture_params|, |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
329 // Queue to keep photo-associated requests waiting for a device to initialize, | 341 // Queue to keep photo-associated requests waiting for a device to initialize, |
330 // bundles a session id integer and an associated photo-related request. | 342 // bundles a session id integer and an associated photo-related request. |
331 std::list<std::pair<int, base::Callback<void(media::VideoCaptureDevice*)>>> | 343 std::list<std::pair<int, base::Callback<void(media::VideoCaptureDevice*)>>> |
332 photo_request_queue_; | 344 photo_request_queue_; |
333 | 345 |
334 // Device creation factory injected on construction from MediaStreamManager or | 346 // Device creation factory injected on construction from MediaStreamManager or |
335 // from the test harness. | 347 // from the test harness. |
336 std::unique_ptr<media::VideoCaptureDeviceFactory> | 348 std::unique_ptr<media::VideoCaptureDeviceFactory> |
337 video_capture_device_factory_; | 349 video_capture_device_factory_; |
338 | 350 |
351 base::ObserverList<media::VideoCaptureObserver> capture_observers_; | |
chfremer
2017/02/13 19:00:15
Nice! I didn't even know we had something like tha
| |
352 | |
339 // Local cache of the enumerated video capture devices' names and capture | 353 // Local cache of the enumerated video capture devices' names and capture |
340 // supported formats. A snapshot of the current devices and their capabilities | 354 // supported formats. A snapshot of the current devices and their capabilities |
341 // is composed in VideoCaptureDeviceFactory::EnumerateDeviceNames() and | 355 // is composed in VideoCaptureDeviceFactory::EnumerateDeviceNames() and |
342 // ConsolidateDevicesInfoOnDeviceThread(), and this snapshot is used to update | 356 // ConsolidateDevicesInfoOnDeviceThread(), and this snapshot is used to update |
343 // this list in OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will | 357 // this list in OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will |
344 // use this list if the device is not started, otherwise it will retrieve the | 358 // use this list if the device is not started, otherwise it will retrieve the |
345 // active device capture format from the VideoCaptureController associated. | 359 // active device capture format from the VideoCaptureController associated. |
346 DeviceInfos devices_info_cache_; | 360 DeviceInfos devices_info_cache_; |
347 | 361 |
348 // Map used by DesktopCapture. | 362 // Map used by DesktopCapture. |
349 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> | 363 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> |
350 notification_window_ids_; | 364 notification_window_ids_; |
351 | 365 |
352 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 366 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
353 }; | 367 }; |
354 | 368 |
355 } // namespace content | 369 } // namespace content |
356 | 370 |
357 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 371 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
OLD | NEW |