| 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 <map> | 15 #include <map> |
| 16 #include <set> | 16 #include <set> |
| 17 #include <string> | 17 #include <string> |
| 18 | 18 |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
| 20 #include "base/memory/weak_ptr.h" | 20 #include "base/memory/weak_ptr.h" |
| 21 #include "base/process/process_handle.h" | 21 #include "base/process/process_handle.h" |
| 22 #include "content/browser/renderer_host/media/media_stream_provider.h" | 22 #include "content/browser/renderer_host/media/media_stream_provider.h" |
| 23 #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/common/content_export.h" | 24 #include "content/common/content_export.h" |
| 25 #include "content/common/media/media_stream_options.h" | 25 #include "content/common/media/media_stream_options.h" |
| 26 #include "media/video/capture/video_capture_device.h" | 26 #include "media/video/capture/video_capture_device.h" |
| 27 #include "media/video/capture/video_capture_device_factory.h" |
| 27 #include "media/video/capture/video_capture_types.h" | 28 #include "media/video/capture/video_capture_types.h" |
| 28 | 29 |
| 29 namespace content { | 30 namespace content { |
| 30 class VideoCaptureController; | 31 class VideoCaptureController; |
| 31 class VideoCaptureControllerEventHandler; | 32 class VideoCaptureControllerEventHandler; |
| 32 | 33 |
| 33 // VideoCaptureManager opens/closes and start/stops video capture devices. | 34 // VideoCaptureManager opens/closes and start/stops video capture devices. |
| 34 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { | 35 class CONTENT_EXPORT VideoCaptureManager : public MediaStreamProvider { |
| 35 public: | 36 public: |
| 36 // Callback used to signal the completion of a controller lookup. | 37 // Callback used to signal the completion of a controller lookup. |
| 37 typedef base::Callback< | 38 typedef base::Callback< |
| 38 void(const base::WeakPtr<VideoCaptureController>&)> DoneCB; | 39 void(const base::WeakPtr<VideoCaptureController>&)> DoneCB; |
| 39 | 40 |
| 40 VideoCaptureManager(); | 41 explicit VideoCaptureManager( |
| 42 scoped_ptr<media::VideoCaptureDeviceFactory> factory); |
| 41 | 43 |
| 42 // Implements MediaStreamProvider. | 44 // Implements MediaStreamProvider. |
| 43 virtual void Register(MediaStreamProviderListener* listener, | 45 virtual void Register(MediaStreamProviderListener* listener, |
| 44 const scoped_refptr<base::SingleThreadTaskRunner>& | 46 const scoped_refptr<base::SingleThreadTaskRunner>& |
| 45 device_task_runner) OVERRIDE; | 47 device_task_runner) OVERRIDE; |
| 46 | 48 |
| 47 virtual void Unregister() OVERRIDE; | 49 virtual void Unregister() OVERRIDE; |
| 48 | 50 |
| 49 virtual void EnumerateDevices(MediaStreamType stream_type) OVERRIDE; | 51 virtual void EnumerateDevices(MediaStreamType stream_type) OVERRIDE; |
| 50 | 52 |
| 51 virtual int Open(const StreamDeviceInfo& device) OVERRIDE; | 53 virtual int Open(const StreamDeviceInfo& device) OVERRIDE; |
| 52 | 54 |
| 53 virtual void Close(int capture_session_id) OVERRIDE; | 55 virtual void Close(int capture_session_id) OVERRIDE; |
| 54 | 56 |
| 55 // Used by unit test to make sure a fake device is used instead of a real | 57 // Used by unit tests to pass a fake device factory. Due to timing |
| 56 // video capture device. Due to timing requirements, the function must be | 58 // requirements, the function must be called before EnumerateDevices and Open. |
| 57 // called before EnumerateDevices and Open. | 59 void UseFakeDevice(scoped_ptr<media::VideoCaptureDeviceFactory> factory); |
| 58 void UseFakeDevice(); | |
| 59 | 60 |
| 60 // Called by VideoCaptureHost to locate a capture device for |capture_params|, | 61 // Called by VideoCaptureHost to locate a capture device for |capture_params|, |
| 61 // adding the Host as a client of the device's controller if successful. The | 62 // adding the Host as a client of the device's controller if successful. The |
| 62 // value of |session_id| controls which device is selected; | 63 // value of |session_id| controls which device is selected; |
| 63 // this value should be a session id previously returned by Open(). | 64 // this value should be a session id previously returned by Open(). |
| 64 // | 65 // |
| 65 // If the device is not already started (i.e., no other client is currently | 66 // If the device is not already started (i.e., no other client is currently |
| 66 // capturing from this device), this call will cause a VideoCaptureController | 67 // capturing from this device), this call will cause a VideoCaptureController |
| 67 // and VideoCaptureDevice to be created, possibly asynchronously. | 68 // and VideoCaptureDevice to be created, possibly asynchronously. |
| 68 // | 69 // |
| (...skipping 27 matching lines...) Expand all Loading... |
| 96 // |capture_session_id| is not found. Returns true and |formats_in_use| | 97 // |capture_session_id| is not found. Returns true and |formats_in_use| |
| 97 // otherwise. |formats_in_use| is empty if the device is not in use. | 98 // otherwise. |formats_in_use| is empty if the device is not in use. |
| 98 bool GetDeviceFormatsInUse(media::VideoCaptureSessionId capture_session_id, | 99 bool GetDeviceFormatsInUse(media::VideoCaptureSessionId capture_session_id, |
| 99 media::VideoCaptureFormats* formats_in_use); | 100 media::VideoCaptureFormats* formats_in_use); |
| 100 | 101 |
| 101 // Sets the platform-dependent window ID for the desktop capture notification | 102 // Sets the platform-dependent window ID for the desktop capture notification |
| 102 // UI for the given session. | 103 // UI for the given session. |
| 103 void SetDesktopCaptureWindowId(media::VideoCaptureSessionId session_id, | 104 void SetDesktopCaptureWindowId(media::VideoCaptureSessionId session_id, |
| 104 gfx::NativeViewId window_id); | 105 gfx::NativeViewId window_id); |
| 105 | 106 |
| 107 // Gets a weak reference to the device factory, used for tests. |
| 108 media::VideoCaptureDeviceFactory* video_capture_device_factory() const { |
| 109 return video_capture_device_factory_.get(); |
| 110 } |
| 111 |
| 106 private: | 112 private: |
| 107 virtual ~VideoCaptureManager(); | 113 virtual ~VideoCaptureManager(); |
| 108 struct DeviceEntry; | 114 struct DeviceEntry; |
| 109 | 115 |
| 110 // This data structure is a convenient wrap of a devices' name and associated | 116 // This data structure is a convenient wrap of a devices' name and associated |
| 111 // video capture supported formats. | 117 // video capture supported formats. |
| 112 struct DeviceInfo { | 118 struct DeviceInfo { |
| 113 DeviceInfo(); | 119 DeviceInfo(); |
| 114 DeviceInfo(const media::VideoCaptureDevice::Name& name, | 120 DeviceInfo(const media::VideoCaptureDevice::Name& name, |
| 115 const media::VideoCaptureFormats& supported_formats); | 121 const media::VideoCaptureFormats& supported_formats); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 | 219 |
| 214 // The controller. Only used from the IO thread. | 220 // The controller. Only used from the IO thread. |
| 215 scoped_ptr<VideoCaptureController> video_capture_controller; | 221 scoped_ptr<VideoCaptureController> video_capture_controller; |
| 216 | 222 |
| 217 // The capture device. Only used from the device thread. | 223 // The capture device. Only used from the device thread. |
| 218 scoped_ptr<media::VideoCaptureDevice> video_capture_device; | 224 scoped_ptr<media::VideoCaptureDevice> video_capture_device; |
| 219 }; | 225 }; |
| 220 typedef std::set<DeviceEntry*> DeviceEntries; | 226 typedef std::set<DeviceEntry*> DeviceEntries; |
| 221 DeviceEntries devices_; | 227 DeviceEntries devices_; |
| 222 | 228 |
| 229 // Device creation factory injected from Media Stream Manager or from the test |
| 230 // harness. Supported fake devices include a simple fake device (a rolling |
| 231 // pacman), or a file that is played in a loop continuously. Test device is |
| 232 // only and always of type MEDIA_DEVICE_VIDEO_CAPTURE. |
| 233 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_; |
| 234 |
| 223 // Local cache of the enumerated video capture devices' names and capture | 235 // Local cache of the enumerated video capture devices' names and capture |
| 224 // supported formats. A snapshot of the current devices and their capabilities | 236 // supported formats. A snapshot of the current devices and their capabilities |
| 225 // is composed in GetAvailableDevicesInfoOnDeviceThread() --coming | 237 // is composed in GetAvailableDevicesInfoOnDeviceThread() --coming |
| 226 // from EnumerateDevices()--, and this snapshot is used to update this list in | 238 // from EnumerateDevices()--, and this snapshot is used to update this list in |
| 227 // OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will | 239 // OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will |
| 228 // use this list if the device is not started, otherwise it will retrieve the | 240 // use this list if the device is not started, otherwise it will retrieve the |
| 229 // active device capture format from the VideoCaptureController associated. | 241 // active device capture format from the VideoCaptureController associated. |
| 230 DeviceInfos devices_info_cache_; | 242 DeviceInfos devices_info_cache_; |
| 231 | 243 |
| 232 // For unit testing and for performance/quality tests, a test device can be | |
| 233 // used instead of a real one. The device can be a simple fake device (a | |
| 234 // rolling pacman), or a file that is played in a loop continuously. This only | |
| 235 // applies to the MEDIA_DEVICE_VIDEO_CAPTURE device type. | |
| 236 enum { | |
| 237 DISABLED, | |
| 238 TEST_PATTERN, | |
| 239 Y4M_FILE | |
| 240 } artificial_device_source_for_testing_; | |
| 241 | |
| 242 // Accessed on the device thread only. | 244 // Accessed on the device thread only. |
| 243 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> | 245 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> |
| 244 notification_window_ids_; | 246 notification_window_ids_; |
| 245 | 247 |
| 246 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 248 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
| 247 }; | 249 }; |
| 248 | 250 |
| 249 } // namespace content | 251 } // namespace content |
| 250 | 252 |
| 251 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 253 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
| OLD | NEW |