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 | |
56 // video capture device. Due to timing requirements, the function must be | |
57 // called before EnumerateDevices and Open. | |
58 void UseFakeDevice(); | |
59 | |
60 // Called by VideoCaptureHost to locate a capture device for |capture_params|, | 57 // 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 | 58 // adding the Host as a client of the device's controller if successful. The |
62 // value of |session_id| controls which device is selected; | 59 // value of |session_id| controls which device is selected; |
63 // this value should be a session id previously returned by Open(). | 60 // this value should be a session id previously returned by Open(). |
64 // | 61 // |
65 // If the device is not already started (i.e., no other client is currently | 62 // 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 | 63 // capturing from this device), this call will cause a VideoCaptureController |
67 // and VideoCaptureDevice to be created, possibly asynchronously. | 64 // and VideoCaptureDevice to be created, possibly asynchronously. |
68 // | 65 // |
69 // On success, the controller is returned via calling |done_cb|, indicating | 66 // On success, the controller is returned via calling |done_cb|, indicating |
(...skipping 26 matching lines...) Expand all Loading... |
96 // |capture_session_id| is not found. Returns true and |formats_in_use| | 93 // |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. | 94 // otherwise. |formats_in_use| is empty if the device is not in use. |
98 bool GetDeviceFormatsInUse(media::VideoCaptureSessionId capture_session_id, | 95 bool GetDeviceFormatsInUse(media::VideoCaptureSessionId capture_session_id, |
99 media::VideoCaptureFormats* formats_in_use); | 96 media::VideoCaptureFormats* formats_in_use); |
100 | 97 |
101 // Sets the platform-dependent window ID for the desktop capture notification | 98 // Sets the platform-dependent window ID for the desktop capture notification |
102 // UI for the given session. | 99 // UI for the given session. |
103 void SetDesktopCaptureWindowId(media::VideoCaptureSessionId session_id, | 100 void SetDesktopCaptureWindowId(media::VideoCaptureSessionId session_id, |
104 gfx::NativeViewId window_id); | 101 gfx::NativeViewId window_id); |
105 | 102 |
| 103 // Gets a weak reference to the device factory, used for tests. |
| 104 media::VideoCaptureDeviceFactory* video_capture_device_factory() const { |
| 105 return video_capture_device_factory_.get(); |
| 106 } |
| 107 |
106 private: | 108 private: |
107 virtual ~VideoCaptureManager(); | 109 virtual ~VideoCaptureManager(); |
108 struct DeviceEntry; | 110 struct DeviceEntry; |
109 | 111 |
110 // This data structure is a convenient wrap of a devices' name and associated | 112 // This data structure is a convenient wrap of a devices' name and associated |
111 // video capture supported formats. | 113 // video capture supported formats. |
112 struct DeviceInfo { | 114 struct DeviceInfo { |
113 DeviceInfo(); | 115 DeviceInfo(); |
114 DeviceInfo(const media::VideoCaptureDevice::Name& name, | 116 DeviceInfo(const media::VideoCaptureDevice::Name& name, |
115 const media::VideoCaptureFormats& supported_formats); | 117 const media::VideoCaptureFormats& supported_formats); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 215 |
214 // The controller. Only used from the IO thread. | 216 // The controller. Only used from the IO thread. |
215 scoped_ptr<VideoCaptureController> video_capture_controller; | 217 scoped_ptr<VideoCaptureController> video_capture_controller; |
216 | 218 |
217 // The capture device. Only used from the device thread. | 219 // The capture device. Only used from the device thread. |
218 scoped_ptr<media::VideoCaptureDevice> video_capture_device; | 220 scoped_ptr<media::VideoCaptureDevice> video_capture_device; |
219 }; | 221 }; |
220 typedef std::set<DeviceEntry*> DeviceEntries; | 222 typedef std::set<DeviceEntry*> DeviceEntries; |
221 DeviceEntries devices_; | 223 DeviceEntries devices_; |
222 | 224 |
| 225 // Device creation factory injected from Media Stream Manager or from the test |
| 226 // harness. Supported fake devices include a simple fake device (a rolling |
| 227 // pacman), or a file that is played in a loop continuously. Test device is |
| 228 // only and always of type MEDIA_DEVICE_VIDEO_CAPTURE. |
| 229 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_; |
| 230 |
223 // Local cache of the enumerated video capture devices' names and capture | 231 // Local cache of the enumerated video capture devices' names and capture |
224 // supported formats. A snapshot of the current devices and their capabilities | 232 // supported formats. A snapshot of the current devices and their capabilities |
225 // is composed in GetAvailableDevicesInfoOnDeviceThread() --coming | 233 // is composed in GetAvailableDevicesInfoOnDeviceThread() --coming |
226 // from EnumerateDevices()--, and this snapshot is used to update this list in | 234 // from EnumerateDevices()--, and this snapshot is used to update this list in |
227 // OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will | 235 // OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will |
228 // use this list if the device is not started, otherwise it will retrieve the | 236 // use this list if the device is not started, otherwise it will retrieve the |
229 // active device capture format from the VideoCaptureController associated. | 237 // active device capture format from the VideoCaptureController associated. |
230 DeviceInfos devices_info_cache_; | 238 DeviceInfos devices_info_cache_; |
231 | 239 |
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. | 240 // Accessed on the device thread only. |
243 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> | 241 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> |
244 notification_window_ids_; | 242 notification_window_ids_; |
245 | 243 |
246 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 244 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
247 }; | 245 }; |
248 | 246 |
249 } // namespace content | 247 } // namespace content |
250 | 248 |
251 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 249 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
OLD | NEW |