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/message_loop/message_loop.h" | |
21 #include "base/process/process_handle.h" | 22 #include "base/process/process_handle.h" |
23 #include "base/timer/elapsed_timer.h" | |
22 #include "content/browser/renderer_host/media/media_stream_provider.h" | 24 #include "content/browser/renderer_host/media/media_stream_provider.h" |
23 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" | 25 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" |
24 #include "content/common/content_export.h" | 26 #include "content/common/content_export.h" |
25 #include "content/common/media/media_stream_options.h" | 27 #include "content/common/media/media_stream_options.h" |
26 #include "media/video/capture/video_capture_device.h" | 28 #include "media/video/capture/video_capture_device.h" |
27 #include "media/video/capture/video_capture_device_factory.h" | 29 #include "media/video/capture/video_capture_device_factory.h" |
28 #include "media/video/capture/video_capture_types.h" | 30 #include "media/video/capture/video_capture_types.h" |
29 | 31 |
30 namespace content { | 32 namespace content { |
31 class VideoCaptureController; | 33 class VideoCaptureController; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 DeviceInfo(); | 118 DeviceInfo(); |
117 DeviceInfo(const media::VideoCaptureDevice::Name& name, | 119 DeviceInfo(const media::VideoCaptureDevice::Name& name, |
118 const media::VideoCaptureFormats& supported_formats); | 120 const media::VideoCaptureFormats& supported_formats); |
119 ~DeviceInfo(); | 121 ~DeviceInfo(); |
120 | 122 |
121 media::VideoCaptureDevice::Name name; | 123 media::VideoCaptureDevice::Name name; |
122 media::VideoCaptureFormats supported_formats; | 124 media::VideoCaptureFormats supported_formats; |
123 }; | 125 }; |
124 typedef std::vector<DeviceInfo> DeviceInfos; | 126 typedef std::vector<DeviceInfo> DeviceInfos; |
125 | 127 |
126 // Check to see if |entry| has no clients left on its controller. If so, | 128 // Checks to see if |entry| has no clients left on its controller. If so, |
127 // remove it from the list of devices, and delete it asynchronously. |entry| | 129 // remove it from the list of devices, and delete it asynchronously. |entry| |
128 // may be freed by this function. | 130 // may be freed by this function. |
129 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry); | 131 void DestroyDeviceEntryIfNoClients(DeviceEntry* entry); |
130 | 132 |
131 // Helpers to report an event to our Listener. | 133 // Helpers to report an event to our Listener. |
132 void OnOpened(MediaStreamType type, | 134 void OnOpened(MediaStreamType type, |
133 media::VideoCaptureSessionId capture_session_id); | 135 media::VideoCaptureSessionId capture_session_id); |
134 void OnClosed(MediaStreamType type, | 136 void OnClosed(MediaStreamType type, |
135 media::VideoCaptureSessionId capture_session_id); | 137 media::VideoCaptureSessionId capture_session_id); |
136 void OnDevicesInfoEnumerated( | 138 void OnDevicesInfoEnumerated(MediaStreamType stream_type, |
137 MediaStreamType stream_type, | 139 base::ElapsedTimer* timer, |
138 const DeviceInfos& new_devices_info_cache); | 140 const DeviceInfos& new_devices_info_cache); |
139 | 141 |
140 // Find a DeviceEntry by its device ID and type, if it is already opened. | 142 // Finds a DeviceEntry by its device ID and type, if it is already opened. |
141 DeviceEntry* GetDeviceEntryForMediaStreamDevice( | 143 DeviceEntry* GetDeviceEntryForMediaStreamDevice( |
142 const MediaStreamDevice& device_info); | 144 const MediaStreamDevice& device_info); |
143 | 145 |
144 // Find a DeviceEntry entry for the indicated session, creating a fresh one | 146 // Finds a DeviceEntry entry for the indicated session, creating a fresh one |
145 // if necessary. Returns NULL if the session id is invalid. | 147 // if necessary. Returns NULL if the session id is invalid. |
146 DeviceEntry* GetOrCreateDeviceEntry( | 148 DeviceEntry* GetOrCreateDeviceEntry( |
147 media::VideoCaptureSessionId capture_session_id); | 149 media::VideoCaptureSessionId capture_session_id); |
148 | 150 |
149 // Find the DeviceEntry that owns a particular controller pointer. | 151 // Finds the DeviceEntry that owns a particular controller pointer. |
150 DeviceEntry* GetDeviceEntryForController( | 152 DeviceEntry* GetDeviceEntryForController( |
151 const VideoCaptureController* controller) const; | 153 const VideoCaptureController* controller) const; |
152 | 154 |
153 bool IsOnDeviceThread() const; | 155 bool IsOnDeviceThread() const; |
154 | 156 |
155 // Queries the Names of the devices in the system; the formats supported by | 157 // Consolidates the cached devices list with the list of currently connected |
156 // the new devices are also queried, and consolidated with the copy of the | 158 // devices in the system |names_snapshot|. Retrieves the supported formats of |
157 // local device info cache passed. The consolidated list of devices and | 159 // the new devices and sends the new cache to OnDevicesInfoEnumerated(). |
158 // supported formats is returned. | 160 void ConsolidateDevicesInfoOnDeviceThread( |
159 DeviceInfos GetAvailableDevicesInfoOnDeviceThread( | 161 base::Callback<void(const DeviceInfos&)> on_devices_enumerated_callback, |
160 MediaStreamType stream_type, | 162 MediaStreamType stream_type, |
161 const DeviceInfos& old_device_info_cache); | 163 const DeviceInfos& old_device_info_cache, |
164 media::VideoCaptureDevice::Names& names_snapshot); | |
tommi (sloooow) - chröme
2014/05/30 12:37:51
const
(or if it is meant to be writable, pass by p
mcasas
2014/05/30 14:08:50
Made it const& and used inside a local copy for
mo
| |
162 | 165 |
163 // Create and Start a new VideoCaptureDevice, storing the result in | 166 // Creates and Starts a new VideoCaptureDevice, storing the result in |
164 // |entry->video_capture_device|. Ownership of |client| passes to | 167 // |entry->video_capture_device|. Ownership of |client| passes to |
165 // the device. | 168 // the device. |
166 void DoStartDeviceOnDeviceThread( | 169 void DoStartDeviceOnDeviceThread( |
167 media::VideoCaptureSessionId session_id, | 170 media::VideoCaptureSessionId session_id, |
168 DeviceEntry* entry, | 171 DeviceEntry* entry, |
169 const media::VideoCaptureParams& params, | 172 const media::VideoCaptureParams& params, |
170 scoped_ptr<media::VideoCaptureDevice::Client> client); | 173 scoped_ptr<media::VideoCaptureDevice::Client> client); |
171 | 174 |
172 // Stop and destroy the VideoCaptureDevice held in | 175 // Stops and destroys the VideoCaptureDevice held in |
173 // |entry->video_capture_device|. | 176 // |entry->video_capture_device|. |
174 void DoStopDeviceOnDeviceThread(DeviceEntry* entry); | 177 void DoStopDeviceOnDeviceThread(DeviceEntry* entry); |
175 | 178 |
176 DeviceInfo* FindDeviceInfoById(const std::string& id, | 179 DeviceInfo* FindDeviceInfoById(const std::string& id, |
177 DeviceInfos& device_vector); | 180 DeviceInfos& device_vector); |
178 | 181 |
179 void SetDesktopCaptureWindowIdOnDeviceThread(DeviceEntry* entry, | 182 void SetDesktopCaptureWindowIdOnDeviceThread(DeviceEntry* entry, |
180 gfx::NativeViewId window_id); | 183 gfx::NativeViewId window_id); |
181 | 184 |
182 void SaveDesktopCaptureWindowIdOnDeviceThread( | 185 void SaveDesktopCaptureWindowIdOnDeviceThread( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 }; | 226 }; |
224 typedef std::set<DeviceEntry*> DeviceEntries; | 227 typedef std::set<DeviceEntry*> DeviceEntries; |
225 DeviceEntries devices_; | 228 DeviceEntries devices_; |
226 | 229 |
227 // Device creation factory injected on construction from MediaStreamManager or | 230 // Device creation factory injected on construction from MediaStreamManager or |
228 // from the test harness. | 231 // from the test harness. |
229 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_; | 232 scoped_ptr<media::VideoCaptureDeviceFactory> video_capture_device_factory_; |
230 | 233 |
231 // Local cache of the enumerated video capture devices' names and capture | 234 // Local cache of the enumerated video capture devices' names and capture |
232 // supported formats. A snapshot of the current devices and their capabilities | 235 // supported formats. A snapshot of the current devices and their capabilities |
233 // is composed in GetAvailableDevicesInfoOnDeviceThread() --coming | 236 // is composed in VideoCaptureDeviceFactory::EnumerateDeviceNames() and |
234 // from EnumerateDevices()--, and this snapshot is used to update this list in | 237 // ConsolidateDevicesInfoOnDeviceThread(), and this snapshot is used to update |
235 // OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will | 238 // this list in OnDevicesInfoEnumerated(). GetDeviceSupportedFormats() will |
236 // use this list if the device is not started, otherwise it will retrieve the | 239 // use this list if the device is not started, otherwise it will retrieve the |
237 // active device capture format from the VideoCaptureController associated. | 240 // active device capture format from the VideoCaptureController associated. |
238 DeviceInfos devices_info_cache_; | 241 DeviceInfos devices_info_cache_; |
239 | 242 |
240 // Accessed on the device thread only. | 243 // Accessed on the device thread only. |
241 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> | 244 std::map<media::VideoCaptureSessionId, gfx::NativeViewId> |
242 notification_window_ids_; | 245 notification_window_ids_; |
243 | 246 |
244 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); | 247 DISALLOW_COPY_AND_ASSIGN(VideoCaptureManager); |
245 }; | 248 }; |
246 | 249 |
247 } // namespace content | 250 } // namespace content |
248 | 251 |
249 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ | 252 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_VIDEO_CAPTURE_MANAGER_H_ |
OLD | NEW |