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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 explicit VideoCaptureManager( | 53 explicit VideoCaptureManager( |
54 std::unique_ptr<media::VideoCaptureDeviceFactory> factory); | 54 std::unique_ptr<media::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 | |
63 void EnumerateDevices(MediaStreamType stream_type) override; | |
64 | |
65 int Open(const StreamDeviceInfo& device) override; | 62 int Open(const StreamDeviceInfo& device) override; |
66 | |
67 void Close(int capture_session_id) override; | 63 void Close(int capture_session_id) override; |
68 | 64 |
69 // Called by VideoCaptureHost to locate a capture device for |capture_params|, | 65 // Called by VideoCaptureHost to locate a capture device for |capture_params|, |
70 // adding the Host as a client of the device's controller if successful. The | 66 // adding the Host as a client of the device's controller if successful. The |
71 // value of |session_id| controls which device is selected; | 67 // value of |session_id| controls which device is selected; |
72 // this value should be a session id previously returned by Open(). | 68 // this value should be a session id previously returned by Open(). |
73 // | 69 // |
74 // If the device is not already started (i.e., no other client is currently | 70 // If the device is not already started (i.e., no other client is currently |
75 // capturing from this device), this call will cause a VideoCaptureController | 71 // capturing from this device), this call will cause a VideoCaptureController |
76 // and VideoCaptureDevice to be created, possibly asynchronously. | 72 // and VideoCaptureDevice to be created, possibly asynchronously. |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 void TakePhoto(int session_id, | 162 void TakePhoto(int session_id, |
167 VideoCaptureDevice::TakePhotoCallback callback); | 163 VideoCaptureDevice::TakePhotoCallback callback); |
168 | 164 |
169 #if defined(OS_ANDROID) | 165 #if defined(OS_ANDROID) |
170 // Some devices had troubles when stopped and restarted quickly, so the device | 166 // Some devices had troubles when stopped and restarted quickly, so the device |
171 // is only stopped when Chrome is sent to background and not when, e.g., a tab | 167 // is only stopped when Chrome is sent to background and not when, e.g., a tab |
172 // is hidden, see http://crbug.com/582295. | 168 // is hidden, see http://crbug.com/582295. |
173 void OnApplicationStateChange(base::android::ApplicationState state); | 169 void OnApplicationStateChange(base::android::ApplicationState state); |
174 #endif | 170 #endif |
175 | 171 |
| 172 using EnumerationCallback = |
| 173 base::Callback<void(const media::VideoCaptureDeviceDescriptors&)>; |
| 174 void EnumerateDevices(const EnumerationCallback& client_callback); |
| 175 |
176 private: | 176 private: |
177 class CaptureDeviceStartRequest; | 177 class CaptureDeviceStartRequest; |
178 class DeviceEntry; | 178 class DeviceEntry; |
179 struct DeviceInfo; | 179 struct DeviceInfo; |
180 | 180 |
181 using SessionMap = std::map<media::VideoCaptureSessionId, MediaStreamDevice>; | 181 using SessionMap = std::map<media::VideoCaptureSessionId, MediaStreamDevice>; |
182 using DeviceEntries = std::vector<std::unique_ptr<DeviceEntry>>; | 182 using DeviceEntries = std::vector<std::unique_ptr<DeviceEntry>>; |
183 using DeviceInfos = std::vector<DeviceInfo>; | 183 using DeviceInfos = std::vector<DeviceInfo>; |
184 using DeviceStartQueue = std::list<CaptureDeviceStartRequest>; | 184 using DeviceStartQueue = std::list<CaptureDeviceStartRequest>; |
185 using VideoCaptureDeviceDescriptor = media::VideoCaptureDeviceDescriptor; | 185 using VideoCaptureDeviceDescriptor = media::VideoCaptureDeviceDescriptor; |
186 using VideoCaptureDeviceDescriptors = media::VideoCaptureDeviceDescriptors; | 186 using VideoCaptureDeviceDescriptors = media::VideoCaptureDeviceDescriptors; |
187 | 187 |
188 ~VideoCaptureManager() override; | 188 ~VideoCaptureManager() override; |
189 | 189 |
190 // Helpers to report an event to our Listener. | 190 // Helpers to report an event to our Listener. |
191 void OnOpened(MediaStreamType type, | 191 void OnOpened(MediaStreamType type, |
192 media::VideoCaptureSessionId capture_session_id); | 192 media::VideoCaptureSessionId capture_session_id); |
193 void OnClosed(MediaStreamType type, | 193 void OnClosed(MediaStreamType type, |
194 media::VideoCaptureSessionId capture_session_id); | 194 media::VideoCaptureSessionId capture_session_id); |
195 void OnDevicesInfoEnumerated(MediaStreamType stream_type, | 195 void OnDevicesInfoEnumerated(base::ElapsedTimer* timer, |
196 base::ElapsedTimer* timer, | 196 const EnumerationCallback& client_callback, |
197 const DeviceInfos& new_devices_info_cache); | 197 const DeviceInfos& new_devices_info_cache); |
198 | 198 |
199 bool IsOnDeviceThread() const; | 199 bool IsOnDeviceThread() const; |
200 | 200 |
201 // Consolidates the cached devices list with the list of currently connected | 201 // Consolidates the cached devices list with the list of currently connected |
202 // devices in the system |names_snapshot|. Retrieves the supported formats of | 202 // devices in the system |names_snapshot|. Retrieves the supported formats of |
203 // the new devices and sends the new cache to OnDevicesInfoEnumerated(). | 203 // the new devices and sends the new cache to OnDevicesInfoEnumerated(). |
204 void ConsolidateDevicesInfoOnDeviceThread( | 204 void ConsolidateDevicesInfoOnDeviceThread( |
205 base::Callback<void(const DeviceInfos&)> on_devices_enumerated_callback, | 205 base::Callback<void(const DeviceInfos&)> on_devices_enumerated_callback, |
206 MediaStreamType stream_type, | |
207 const DeviceInfos& old_device_info_cache, | 206 const DeviceInfos& old_device_info_cache, |
208 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors_snapshot); | 207 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors_snapshot); |
209 | 208 |
210 // Checks to see if |entry| has no clients left on its controller. If so, | 209 // Checks to see if |entry| has no clients left on its controller. If so, |
211 // remove it from the list of devices, and delete it asynchronously. |entry| | 210 // remove it from the list of devices, and delete it asynchronously. |entry| |
212 // may be freed by this function. | 211 // may be freed by this function. |
213 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry); | 212 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry); |
214 | 213 |
215 // Finds a DeviceEntry in different ways: by |session_id|, by its |device_id| | 214 // Finds a DeviceEntry in different ways: by |session_id|, by its |device_id| |
216 // and |type| (if it is already opened), by its |controller| or by its | 215 // and |type| (if it is already opened), by its |controller| or by its |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 // Map used by DesktopCapture. | 354 // Map used by DesktopCapture. |
356 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> | 355 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> |
357 notification_window_ids_; | 356 notification_window_ids_; |
358 | 357 |
359 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 358 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
360 }; | 359 }; |
361 | 360 |
362 } // namespace content | 361 } // namespace content |
363 | 362 |
364 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 363 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
OLD | NEW |