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