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