| 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 "device/capture/video/video_capture_device.h" |
| 33 #include "device/capture/video/video_capture_device_factory.h" |
| 32 #include "media/base/video_capture_types.h" | 34 #include "media/base/video_capture_types.h" |
| 33 #include "media/capture/video/video_capture_device.h" | |
| 34 #include "media/capture/video/video_capture_device_factory.h" | |
| 35 | 35 |
| 36 #if defined(OS_ANDROID) | 36 #if defined(OS_ANDROID) |
| 37 #include "base/android/application_status_listener.h" | 37 #include "base/android/application_status_listener.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 namespace content { | 40 namespace content { |
| 41 class VideoCaptureController; | 41 class VideoCaptureController; |
| 42 class VideoCaptureControllerEventHandler; | 42 class VideoCaptureControllerEventHandler; |
| 43 | 43 |
| 44 // VideoCaptureManager opens/closes and start/stops video capture devices. | 44 // VideoCaptureManager opens/closes and start/stops video capture devices. |
| 45 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { | 45 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { |
| 46 public: | 46 public: |
| 47 using VideoCaptureDevice = media::VideoCaptureDevice; | 47 using VideoCaptureDevice = device::VideoCaptureDevice; |
| 48 | 48 |
| 49 // Callback used to signal the completion of a controller lookup. | 49 // Callback used to signal the completion of a controller lookup. |
| 50 using DoneCB = | 50 using DoneCB = |
| 51 base::Callback<void(const base::WeakPtr<VideoCaptureController>&)>; | 51 base::Callback<void(const base::WeakPtr<VideoCaptureController>&)>; |
| 52 | 52 |
| 53 explicit VideoCaptureManager( | 53 explicit VideoCaptureManager( |
| 54 std::unique_ptr<media::VideoCaptureDeviceFactory> factory); | 54 std::unique_ptr<device::VideoCaptureDeviceFactory> factory); |
| 55 | 55 |
| 56 void Unregister(); | 56 void Unregister(); |
| 57 | 57 |
| 58 // Implements MediaStreamProvider. | 58 // Implements MediaStreamProvider. |
| 59 void Register(MediaStreamProviderListener* listener, | 59 void Register(MediaStreamProviderListener* listener, |
| 60 const scoped_refptr<base::SingleThreadTaskRunner>& | 60 const scoped_refptr<base::SingleThreadTaskRunner>& |
| 61 device_task_runner) override; | 61 device_task_runner) override; |
| 62 | 62 |
| 63 void EnumerateDevices(MediaStreamType stream_type) override; | 63 void EnumerateDevices(MediaStreamType stream_type) override; |
| 64 | 64 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 // otherwise. |formats_in_use| is empty if the device is not in use. | 133 // otherwise. |formats_in_use| is empty if the device is not in use. |
| 134 bool GetDeviceFormatsInUse(media::VideoCaptureSessionId capture_session_id, | 134 bool GetDeviceFormatsInUse(media::VideoCaptureSessionId capture_session_id, |
| 135 media::VideoCaptureFormats* formats_in_use); | 135 media::VideoCaptureFormats* formats_in_use); |
| 136 | 136 |
| 137 // Sets the platform-dependent window ID for the desktop capture notification | 137 // Sets the platform-dependent window ID for the desktop capture notification |
| 138 // UI for the given session. | 138 // UI for the given session. |
| 139 void SetDesktopCaptureWindowId(media::VideoCaptureSessionId session_id, | 139 void SetDesktopCaptureWindowId(media::VideoCaptureSessionId session_id, |
| 140 gfx::NativeViewId window_id); | 140 gfx::NativeViewId window_id); |
| 141 | 141 |
| 142 // Gets a weak reference to the device factory, used for tests. | 142 // Gets a weak reference to the device factory, used for tests. |
| 143 media::VideoCaptureDeviceFactory* video_capture_device_factory() const { | 143 device::VideoCaptureDeviceFactory* video_capture_device_factory() const { |
| 144 return video_capture_device_factory_.get(); | 144 return video_capture_device_factory_.get(); |
| 145 } | 145 } |
| 146 | 146 |
| 147 #if defined(OS_WIN) | 147 #if defined(OS_WIN) |
| 148 void set_device_task_runner( | 148 void set_device_task_runner( |
| 149 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { | 149 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { |
| 150 device_task_runner_ = device_task_runner; | 150 device_task_runner_ = device_task_runner; |
| 151 } | 151 } |
| 152 #endif | 152 #endif |
| 153 | 153 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 174 | 174 |
| 175 private: | 175 private: |
| 176 class CaptureDeviceStartRequest; | 176 class CaptureDeviceStartRequest; |
| 177 class DeviceEntry; | 177 class DeviceEntry; |
| 178 struct DeviceInfo; | 178 struct DeviceInfo; |
| 179 | 179 |
| 180 using SessionMap = std::map<media::VideoCaptureSessionId, MediaStreamDevice>; | 180 using SessionMap = std::map<media::VideoCaptureSessionId, MediaStreamDevice>; |
| 181 using DeviceEntries = std::vector<std::unique_ptr<DeviceEntry>>; | 181 using DeviceEntries = std::vector<std::unique_ptr<DeviceEntry>>; |
| 182 using DeviceInfos = std::vector<DeviceInfo>; | 182 using DeviceInfos = std::vector<DeviceInfo>; |
| 183 using DeviceStartQueue = std::list<CaptureDeviceStartRequest>; | 183 using DeviceStartQueue = std::list<CaptureDeviceStartRequest>; |
| 184 using VideoCaptureDeviceDescriptor = media::VideoCaptureDeviceDescriptor; | 184 using VideoCaptureDeviceDescriptor = device::VideoCaptureDeviceDescriptor; |
| 185 using VideoCaptureDeviceDescriptors = media::VideoCaptureDeviceDescriptors; | 185 using VideoCaptureDeviceDescriptors = device::VideoCaptureDeviceDescriptors; |
| 186 | 186 |
| 187 ~VideoCaptureManager() override; | 187 ~VideoCaptureManager() override; |
| 188 | 188 |
| 189 // Helpers to report an event to our Listener. | 189 // Helpers to report an event to our Listener. |
| 190 void OnOpened(MediaStreamType type, | 190 void OnOpened(MediaStreamType type, |
| 191 media::VideoCaptureSessionId capture_session_id); | 191 media::VideoCaptureSessionId capture_session_id); |
| 192 void OnClosed(MediaStreamType type, | 192 void OnClosed(MediaStreamType type, |
| 193 media::VideoCaptureSessionId capture_session_id); | 193 media::VideoCaptureSessionId capture_session_id); |
| 194 void OnDevicesInfoEnumerated(MediaStreamType stream_type, | 194 void OnDevicesInfoEnumerated(MediaStreamType stream_type, |
| 195 base::ElapsedTimer* timer, | 195 base::ElapsedTimer* timer, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 264 |
| 265 std::unique_ptr<VideoCaptureDevice> DoStartDesktopCaptureOnDeviceThread( | 265 std::unique_ptr<VideoCaptureDevice> DoStartDesktopCaptureOnDeviceThread( |
| 266 const std::string& device_id, | 266 const std::string& device_id, |
| 267 const media::VideoCaptureParams& params, | 267 const media::VideoCaptureParams& params, |
| 268 std::unique_ptr<VideoCaptureDevice::Client> client); | 268 std::unique_ptr<VideoCaptureDevice::Client> client); |
| 269 | 269 |
| 270 // Stops and destroys the VideoCaptureDevice held in |device|. | 270 // Stops and destroys the VideoCaptureDevice held in |device|. |
| 271 void DoStopDeviceOnDeviceThread(std::unique_ptr<VideoCaptureDevice> device); | 271 void DoStopDeviceOnDeviceThread(std::unique_ptr<VideoCaptureDevice> device); |
| 272 | 272 |
| 273 void MaybePostDesktopCaptureWindowId(media::VideoCaptureSessionId session_id); | 273 void MaybePostDesktopCaptureWindowId(media::VideoCaptureSessionId session_id); |
| 274 void SetDesktopCaptureWindowIdOnDeviceThread( | 274 void SetDesktopCaptureWindowIdOnDeviceThread(VideoCaptureDevice* device, |
| 275 media::VideoCaptureDevice* device, | 275 gfx::NativeViewId window_id); |
| 276 gfx::NativeViewId window_id); | |
| 277 | 276 |
| 278 #if defined(OS_MACOSX) | 277 #if defined(OS_MACOSX) |
| 279 // Called on the IO thread after the device layer has been initialized on Mac. | 278 // Called on the IO thread after the device layer has been initialized on Mac. |
| 280 // Sets |capture_device_api_initialized_| to true and then executes and_then. | 279 // Sets |capture_device_api_initialized_| to true and then executes and_then. |
| 281 void OnDeviceLayerInitialized(const base::Closure& and_then); | 280 void OnDeviceLayerInitialized(const base::Closure& and_then); |
| 282 | 281 |
| 283 // Returns true if the current operation needs to be preempted by a call to | 282 // Returns true if the current operation needs to be preempted by a call to |
| 284 // InitializeCaptureDeviceApiOnUIThread. | 283 // InitializeCaptureDeviceApiOnUIThread. |
| 285 // Called on the IO thread. | 284 // Called on the IO thread. |
| 286 bool NeedToInitializeCaptureDeviceApi(MediaStreamType stream_type); | 285 bool NeedToInitializeCaptureDeviceApi(MediaStreamType stream_type); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 | 318 |
| 320 // Currently opened DeviceEntry instances (each owning a VideoCaptureDevice - | 319 // Currently opened DeviceEntry instances (each owning a VideoCaptureDevice - |
| 321 // VideoCaptureController pair). The device may or may not be started. This | 320 // VideoCaptureController pair). The device may or may not be started. This |
| 322 // member is only accessed on IO thread. | 321 // member is only accessed on IO thread. |
| 323 DeviceEntries devices_; | 322 DeviceEntries devices_; |
| 324 | 323 |
| 325 DeviceStartQueue device_start_queue_; | 324 DeviceStartQueue device_start_queue_; |
| 326 | 325 |
| 327 // Device creation factory injected on construction from MediaStreamManager or | 326 // Device creation factory injected on construction from MediaStreamManager or |
| 328 // from the test harness. | 327 // from the test harness. |
| 329 std::unique_ptr<media::VideoCaptureDeviceFactory> | 328 std::unique_ptr<device::VideoCaptureDeviceFactory> |
| 330 video_capture_device_factory_; | 329 video_capture_device_factory_; |
| 331 | 330 |
| 332 // Local cache of the enumerated video capture devices' names and capture | 331 // Local cache of the enumerated video capture devices' names and capture |
| 333 // supported formats. A snapshot of the current devices and their capabilities | 332 // supported formats. A snapshot of the current devices and their capabilities |
| 334 // is composed in VideoCaptureDeviceFactory::EnumerateDeviceNames() and | 333 // is composed in VideoCaptureDeviceFactory::EnumerateDeviceNames() and |
| 335 // ConsolidateDevicesInfoOnDeviceThread(), and this snapshot is used to update | 334 // ConsolidateDevicesInfoOnDeviceThread(), and this snapshot is used to update |
| 336 // this list in OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will | 335 // this list in OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will |
| 337 // use this list if the device is not started, otherwise it will retrieve the | 336 // use this list if the device is not started, otherwise it will retrieve the |
| 338 // active device capture format from the VideoCaptureController associated. | 337 // active device capture format from the VideoCaptureController associated. |
| 339 DeviceInfos devices_info_cache_; | 338 DeviceInfos devices_info_cache_; |
| 340 | 339 |
| 341 // Map used by DesktopCapture. | 340 // Map used by DesktopCapture. |
| 342 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> | 341 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> |
| 343 notification_window_ids_; | 342 notification_window_ids_; |
| 344 | 343 |
| 345 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 344 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
| 346 }; | 345 }; |
| 347 | 346 |
| 348 } // namespace content | 347 } // namespace content |
| 349 | 348 |
| 350 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 349 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| OLD | NEW |