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 #include "content/browser/renderer_host/media/video_capture_manager.h" | 5 #include "content/browser/renderer_host/media/video_capture_manager.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
| 14 #include "base/task_runner_util.h" |
14 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
15 #include "content/browser/renderer_host/media/video_capture_controller.h" | 16 #include "content/browser/renderer_host/media/video_capture_controller.h" |
16 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 17 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
17 #include "content/browser/renderer_host/media/web_contents_video_capture_device.
h" | 18 #include "content/browser/renderer_host/media/web_contents_video_capture_device.
h" |
18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
20 #include "content/public/common/desktop_media_id.h" | 21 #include "content/public/common/desktop_media_id.h" |
21 #include "content/public/common/media_stream_request.h" | 22 #include "content/public/common/media_stream_request.h" |
22 #include "media/base/scoped_histogram_timer.h" | 23 #include "media/base/scoped_histogram_timer.h" |
23 #include "media/video/capture/fake_video_capture_device.h" | 24 #include "media/video/capture/fake_video_capture_device.h" |
24 #include "media/video/capture/video_capture_device.h" | 25 #include "media/video/capture/video_capture_device.h" |
25 | 26 |
26 #if defined(ENABLE_SCREEN_CAPTURE) | 27 #if defined(ENABLE_SCREEN_CAPTURE) |
27 #include "content/browser/renderer_host/media/desktop_capture_device.h" | 28 #include "content/browser/renderer_host/media/desktop_capture_device.h" |
28 #endif | 29 #endif |
29 | 30 |
30 namespace content { | 31 namespace content { |
31 | 32 |
32 VideoCaptureManager::DeviceEntry::DeviceEntry( | 33 VideoCaptureManager::DeviceEntry::DeviceEntry( |
33 MediaStreamType stream_type, | 34 MediaStreamType stream_type, |
34 const std::string& id, | 35 const std::string& id, |
35 scoped_ptr<VideoCaptureController> controller) | 36 scoped_ptr<VideoCaptureController> controller) |
36 : stream_type(stream_type), | 37 : stream_type(stream_type), |
37 id(id), | 38 id(id), |
38 video_capture_controller(controller.Pass()) {} | 39 video_capture_controller(controller.Pass()) {} |
39 | 40 |
40 VideoCaptureManager::DeviceEntry::~DeviceEntry() {} | 41 VideoCaptureManager::DeviceEntry::~DeviceEntry() {} |
41 | 42 |
| 43 VideoCaptureManager::DeviceInfo::DeviceInfo() {} |
| 44 |
| 45 VideoCaptureManager::DeviceInfo::DeviceInfo( |
| 46 const media::VideoCaptureDevice::Name& name, |
| 47 const media::VideoCaptureFormats& supported_formats) |
| 48 : name(name), |
| 49 supported_formats(supported_formats) {} |
| 50 |
| 51 VideoCaptureManager::DeviceInfo::~DeviceInfo() {} |
| 52 |
42 VideoCaptureManager::VideoCaptureManager() | 53 VideoCaptureManager::VideoCaptureManager() |
43 : listener_(NULL), | 54 : listener_(NULL), |
44 new_capture_session_id_(1), | 55 new_capture_session_id_(1), |
45 use_fake_device_(false) { | 56 use_fake_device_(false) { |
46 } | 57 } |
47 | 58 |
48 VideoCaptureManager::~VideoCaptureManager() { | 59 VideoCaptureManager::~VideoCaptureManager() { |
49 DCHECK(devices_.empty()); | 60 DCHECK(devices_.empty()); |
50 } | 61 } |
51 | 62 |
52 void VideoCaptureManager::Register(MediaStreamProviderListener* listener, | 63 void VideoCaptureManager::Register(MediaStreamProviderListener* listener, |
53 base::MessageLoopProxy* device_thread_loop) { | 64 base::MessageLoopProxy* device_thread_loop) { |
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
55 DCHECK(!listener_); | 66 DCHECK(!listener_); |
56 DCHECK(!device_loop_.get()); | 67 DCHECK(!device_loop_.get()); |
57 listener_ = listener; | 68 listener_ = listener; |
58 device_loop_ = device_thread_loop; | 69 device_loop_ = device_thread_loop; |
59 } | 70 } |
60 | 71 |
61 void VideoCaptureManager::Unregister() { | 72 void VideoCaptureManager::Unregister() { |
62 DCHECK(listener_); | 73 DCHECK(listener_); |
63 listener_ = NULL; | 74 listener_ = NULL; |
64 } | 75 } |
65 | 76 |
66 void VideoCaptureManager::EnumerateDevices(MediaStreamType stream_type) { | 77 void VideoCaptureManager::EnumerateDevices(MediaStreamType stream_type) { |
67 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
68 DVLOG(1) << "VideoCaptureManager::EnumerateDevices, type " << stream_type; | 79 DVLOG(1) << "VideoCaptureManager::EnumerateDevices, type " << stream_type; |
69 DCHECK(listener_); | 80 DCHECK(listener_); |
| 81 |
70 base::PostTaskAndReplyWithResult( | 82 base::PostTaskAndReplyWithResult( |
71 device_loop_, FROM_HERE, | 83 device_loop_, |
72 base::Bind(&VideoCaptureManager::GetAvailableDevicesOnDeviceThread, this, | 84 FROM_HERE, |
73 stream_type), | 85 base::Bind(&VideoCaptureManager::GetAvailableDevicesInfoOnDeviceThread, |
74 base::Bind(&VideoCaptureManager::OnDevicesEnumerated, this, stream_type)); | 86 this, |
| 87 stream_type, |
| 88 devices_info_cache_), |
| 89 base::Bind(&VideoCaptureManager::OnDevicesInfoEnumerated, |
| 90 this, |
| 91 stream_type)); |
75 } | 92 } |
76 | 93 |
77 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { | 94 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { |
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
79 DCHECK(listener_); | 96 DCHECK(listener_); |
80 | 97 |
81 // Generate a new id for the session being opened. | 98 // Generate a new id for the session being opened. |
82 const int capture_session_id = new_capture_session_id_++; | 99 const int capture_session_id = new_capture_session_id_++; |
83 | 100 |
84 DCHECK(sessions_.find(capture_session_id) == sessions_.end()); | 101 DCHECK(sessions_.find(capture_session_id) == sessions_.end()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { | 154 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { |
138 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 155 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
139 DCHECK(IsOnDeviceThread()); | 156 DCHECK(IsOnDeviceThread()); |
140 | 157 |
141 scoped_ptr<media::VideoCaptureDevice> video_capture_device; | 158 scoped_ptr<media::VideoCaptureDevice> video_capture_device; |
142 switch (entry->stream_type) { | 159 switch (entry->stream_type) { |
143 case MEDIA_DEVICE_VIDEO_CAPTURE: { | 160 case MEDIA_DEVICE_VIDEO_CAPTURE: { |
144 // We look up the device id from the renderer in our local enumeration | 161 // We look up the device id from the renderer in our local enumeration |
145 // since the renderer does not have all the information that might be | 162 // since the renderer does not have all the information that might be |
146 // held in the browser-side VideoCaptureDevice::Name structure. | 163 // held in the browser-side VideoCaptureDevice::Name structure. |
147 media::VideoCaptureDevice::Name* found = | 164 DeviceInfo* found = FindDeviceInfoById(entry->id, devices_info_cache_); |
148 video_capture_devices_.FindById(entry->id); | |
149 if (found) { | 165 if (found) { |
150 video_capture_device.reset(use_fake_device_ ? | 166 video_capture_device.reset(use_fake_device_ ? |
151 media::FakeVideoCaptureDevice::Create(*found) : | 167 media::FakeVideoCaptureDevice::Create(found->name) : |
152 media::VideoCaptureDevice::Create(*found)); | 168 media::VideoCaptureDevice::Create(found->name)); |
153 } | 169 } |
154 break; | 170 break; |
155 } | 171 } |
156 case MEDIA_TAB_VIDEO_CAPTURE: { | 172 case MEDIA_TAB_VIDEO_CAPTURE: { |
157 video_capture_device.reset( | 173 video_capture_device.reset( |
158 WebContentsVideoCaptureDevice::Create(entry->id)); | 174 WebContentsVideoCaptureDevice::Create(entry->id)); |
159 break; | 175 break; |
160 } | 176 } |
161 case MEDIA_DESKTOP_VIDEO_CAPTURE: { | 177 case MEDIA_DESKTOP_VIDEO_CAPTURE: { |
162 #if defined(ENABLE_SCREEN_CAPTURE) | 178 #if defined(ENABLE_SCREEN_CAPTURE) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 done_cb.Run(base::WeakPtr<VideoCaptureController>()); | 215 done_cb.Run(base::WeakPtr<VideoCaptureController>()); |
200 return; | 216 return; |
201 } | 217 } |
202 | 218 |
203 DCHECK(entry->video_capture_controller); | 219 DCHECK(entry->video_capture_controller); |
204 | 220 |
205 // First client starts the device. | 221 // First client starts the device. |
206 if (entry->video_capture_controller->GetClientCount() == 0) { | 222 if (entry->video_capture_controller->GetClientCount() == 0) { |
207 DVLOG(1) << "VideoCaptureManager starting device (type = " | 223 DVLOG(1) << "VideoCaptureManager starting device (type = " |
208 << entry->stream_type << ", id = " << entry->id << ")"; | 224 << entry->stream_type << ", id = " << entry->id << ")"; |
209 | |
210 device_loop_->PostTask( | 225 device_loop_->PostTask( |
211 FROM_HERE, | 226 FROM_HERE, |
212 base::Bind( | 227 base::Bind( |
213 &VideoCaptureManager::DoStartDeviceOnDeviceThread, | 228 &VideoCaptureManager::DoStartDeviceOnDeviceThread, |
214 this, | 229 this, |
215 entry, | 230 entry, |
216 params, | 231 params, |
217 base::Passed(entry->video_capture_controller->NewDeviceClient()))); | 232 base::Passed(entry->video_capture_controller->NewDeviceClient()))); |
218 } | 233 } |
219 // Run the callback first, as AddClient() may trigger OnFrameInfo(). | 234 // Run the callback first, as AddClient() may trigger OnFrameInfo(). |
(...skipping 18 matching lines...) Expand all Loading... |
238 | 253 |
239 // Detach client from controller. | 254 // Detach client from controller. |
240 int session_id = controller->RemoveClient(client_id, client_handler); | 255 int session_id = controller->RemoveClient(client_id, client_handler); |
241 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " | 256 DVLOG(1) << "VideoCaptureManager::StopCaptureForClient, session_id = " |
242 << session_id; | 257 << session_id; |
243 | 258 |
244 // If controller has no more clients, delete controller and device. | 259 // If controller has no more clients, delete controller and device. |
245 DestroyDeviceEntryIfNoClients(entry); | 260 DestroyDeviceEntryIfNoClients(entry); |
246 } | 261 } |
247 | 262 |
| 263 void VideoCaptureManager::GetDeviceSupportedFormats( |
| 264 int capture_session_id, |
| 265 media::VideoCaptureFormats* supported_formats) { |
| 266 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 267 supported_formats->clear(); |
| 268 |
| 269 std::map<int, MediaStreamDevice>::iterator it = |
| 270 sessions_.find(capture_session_id); |
| 271 DCHECK(it != sessions_.end()); |
| 272 DVLOG(1) << "GetDeviceSupportedFormats for device: " << it->second.name; |
| 273 |
| 274 DeviceInfo* device_in_use = |
| 275 FindDeviceInfoById(it->second.id, devices_info_cache_); |
| 276 DCHECK(device_in_use); |
| 277 if (device_in_use) { |
| 278 DeviceEntry* const existing_device = |
| 279 GetDeviceEntryForMediaStreamDevice(it->second); |
| 280 if (!existing_device) { |
| 281 // If the device is not in use, return all its cached supported formats. |
| 282 *supported_formats = device_in_use->supported_formats; |
| 283 return; |
| 284 } |
| 285 // Otherwise, get the video capture parameters in use from the controller |
| 286 // associated to the device. |
| 287 supported_formats->push_back( |
| 288 existing_device->video_capture_controller->GetVideoCaptureFormat()); |
| 289 } |
| 290 } |
| 291 |
248 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { | 292 void VideoCaptureManager::DoStopDeviceOnDeviceThread(DeviceEntry* entry) { |
249 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); | 293 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StopDeviceTime"); |
250 DCHECK(IsOnDeviceThread()); | 294 DCHECK(IsOnDeviceThread()); |
251 if (entry->video_capture_device) { | 295 if (entry->video_capture_device) { |
252 entry->video_capture_device->StopAndDeAllocate(); | 296 entry->video_capture_device->StopAndDeAllocate(); |
253 } | 297 } |
254 entry->video_capture_device.reset(); | 298 entry->video_capture_device.reset(); |
255 } | 299 } |
256 | 300 |
257 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, | 301 void VideoCaptureManager::OnOpened(MediaStreamType stream_type, |
258 int capture_session_id) { | 302 int capture_session_id) { |
259 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 303 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
260 if (!listener_) { | 304 if (!listener_) { |
261 // Listener has been removed. | 305 // Listener has been removed. |
262 return; | 306 return; |
263 } | 307 } |
264 listener_->Opened(stream_type, capture_session_id); | 308 listener_->Opened(stream_type, capture_session_id); |
265 } | 309 } |
266 | 310 |
267 void VideoCaptureManager::OnClosed(MediaStreamType stream_type, | 311 void VideoCaptureManager::OnClosed(MediaStreamType stream_type, |
268 int capture_session_id) { | 312 int capture_session_id) { |
269 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
270 if (!listener_) { | 314 if (!listener_) { |
271 // Listener has been removed. | 315 // Listener has been removed. |
272 return; | 316 return; |
273 } | 317 } |
274 listener_->Closed(stream_type, capture_session_id); | 318 listener_->Closed(stream_type, capture_session_id); |
275 } | 319 } |
276 | 320 |
277 void VideoCaptureManager::OnDevicesEnumerated( | 321 void VideoCaptureManager::OnDevicesInfoEnumerated( |
278 MediaStreamType stream_type, | 322 MediaStreamType stream_type, |
279 const media::VideoCaptureDevice::Names& device_names) { | 323 const DeviceInfos& new_devices_info_cache) { |
280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 324 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
281 | 325 DVLOG(1) << "OnDevicesInfoEnumerated, #new devices: " |
282 if (!listener_) { | 326 << new_devices_info_cache.size(); |
283 // Listener has been removed. | 327 if (!listener_) { // Listener has been removed. |
284 return; | 328 return; |
285 } | 329 } |
| 330 devices_info_cache_ = new_devices_info_cache; |
286 | 331 |
287 // Transform from VCD::Name to StreamDeviceInfo. | 332 // Walk the |devices_info_cache_| and transform from VCD::Name to |
| 333 // StreamDeviceInfo for return purposes. |
288 StreamDeviceInfoArray devices; | 334 StreamDeviceInfoArray devices; |
289 for (media::VideoCaptureDevice::Names::const_iterator it = | 335 for (DeviceInfos::const_iterator it = devices_info_cache_.begin(); |
290 device_names.begin(); it != device_names.end(); ++it) { | 336 it != devices_info_cache_.end(); |
| 337 ++it) { |
291 devices.push_back(StreamDeviceInfo( | 338 devices.push_back(StreamDeviceInfo( |
292 stream_type, it->GetNameAndModel(), it->id())); | 339 stream_type, it->name.GetNameAndModel(), it->name.id())); |
293 } | 340 } |
294 | |
295 listener_->DevicesEnumerated(stream_type, devices); | 341 listener_->DevicesEnumerated(stream_type, devices); |
296 } | 342 } |
297 | 343 |
298 bool VideoCaptureManager::IsOnDeviceThread() const { | 344 bool VideoCaptureManager::IsOnDeviceThread() const { |
299 return device_loop_->BelongsToCurrentThread(); | 345 return device_loop_->BelongsToCurrentThread(); |
300 } | 346 } |
301 | 347 |
302 media::VideoCaptureDevice::Names | 348 VideoCaptureManager::DeviceInfos |
303 VideoCaptureManager::GetAvailableDevicesOnDeviceThread( | 349 VideoCaptureManager::GetAvailableDevicesInfoOnDeviceThread( |
304 MediaStreamType stream_type) { | 350 MediaStreamType stream_type, |
305 SCOPED_UMA_HISTOGRAM_TIMER( | 351 const DeviceInfos& old_device_info_cache) { |
306 "Media.VideoCaptureManager.GetAvailableDevicesTime"); | 352 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager." |
| 353 "GetAvailableDevicesInfoOnDeviceThreadTime"); |
307 DCHECK(IsOnDeviceThread()); | 354 DCHECK(IsOnDeviceThread()); |
308 media::VideoCaptureDevice::Names result; | 355 media::VideoCaptureDevice::Names names_snapshot; |
309 | |
310 switch (stream_type) { | 356 switch (stream_type) { |
311 case MEDIA_DEVICE_VIDEO_CAPTURE: | 357 case MEDIA_DEVICE_VIDEO_CAPTURE: |
312 // Cache the latest enumeration of video capture devices. | 358 if (!use_fake_device_) |
313 // We'll refer to this list again in OnOpen to avoid having to | 359 media::VideoCaptureDevice::GetDeviceNames(&names_snapshot); |
314 // enumerate the devices again. | 360 else |
315 if (!use_fake_device_) { | 361 media::FakeVideoCaptureDevice::GetDeviceNames(&names_snapshot); |
316 media::VideoCaptureDevice::GetDeviceNames(&result); | |
317 } else { | |
318 media::FakeVideoCaptureDevice::GetDeviceNames(&result); | |
319 } | |
320 | |
321 // TODO(nick): The correctness of device start depends on this cache being | |
322 // maintained, but it seems a little odd to keep a cache here. Can we | |
323 // eliminate it? | |
324 video_capture_devices_ = result; | |
325 break; | 362 break; |
326 | |
327 case MEDIA_DESKTOP_VIDEO_CAPTURE: | 363 case MEDIA_DESKTOP_VIDEO_CAPTURE: |
328 // Do nothing. | 364 // Do nothing. |
329 break; | 365 break; |
330 | |
331 default: | 366 default: |
332 NOTREACHED(); | 367 NOTREACHED(); |
333 break; | 368 break; |
334 } | 369 } |
335 return result; | 370 |
| 371 // Construct |new_devices_info_cache| with the cached devices that are still |
| 372 // present in the system, and remove their names from |names_snapshot|, so we |
| 373 // keep there the truly new devices. |
| 374 DeviceInfos new_devices_info_cache; |
| 375 for (DeviceInfos::const_iterator it_device_info = |
| 376 old_device_info_cache.begin(); |
| 377 it_device_info != old_device_info_cache.end(); |
| 378 ++it_device_info) { |
| 379 media::VideoCaptureDevice::Names::iterator it; |
| 380 for (it = names_snapshot.begin(); it != names_snapshot.end(); ++it) { |
| 381 if (it_device_info->name.id() == it->id()) { |
| 382 new_devices_info_cache.push_back(*it_device_info); |
| 383 names_snapshot.erase(it); |
| 384 break; |
| 385 } |
| 386 } |
| 387 } |
| 388 |
| 389 // Get the supported capture formats for the new devices in |names_snapshot|. |
| 390 for (media::VideoCaptureDevice::Names::const_iterator it = |
| 391 names_snapshot.begin(); |
| 392 it != names_snapshot.end(); |
| 393 ++it) { |
| 394 media::VideoCaptureFormats supported_formats; |
| 395 DeviceInfo device_info(*it, media::VideoCaptureFormats()); |
| 396 if (!use_fake_device_) { |
| 397 media::VideoCaptureDevice::GetDeviceSupportedFormats( |
| 398 *it, &(device_info.supported_formats)); |
| 399 } else { |
| 400 media::FakeVideoCaptureDevice::GetDeviceSupportedFormats( |
| 401 *it, &(device_info.supported_formats)); |
| 402 } |
| 403 new_devices_info_cache.push_back(device_info); |
| 404 } |
| 405 return new_devices_info_cache; |
336 } | 406 } |
337 | 407 |
338 VideoCaptureManager::DeviceEntry* | 408 VideoCaptureManager::DeviceEntry* |
339 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( | 409 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( |
340 const MediaStreamDevice& device_info) { | 410 const MediaStreamDevice& device_info) { |
341 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
342 | 412 |
343 for (DeviceEntries::iterator it = devices_.begin(); | 413 for (DeviceEntries::iterator it = devices_.begin(); |
344 it != devices_.end(); ++it) { | 414 it != devices_.end(); ++it) { |
345 DeviceEntry* device = *it; | 415 DeviceEntry* device = *it; |
(...skipping 26 matching lines...) Expand all Loading... |
372 << entry->stream_type << ", id = " << entry->id << ")"; | 442 << entry->stream_type << ", id = " << entry->id << ")"; |
373 | 443 |
374 // The DeviceEntry is removed from |devices_| immediately. The controller is | 444 // The DeviceEntry is removed from |devices_| immediately. The controller is |
375 // deleted immediately, and the device is freed asynchronously. After this | 445 // deleted immediately, and the device is freed asynchronously. After this |
376 // point, subsequent requests to open this same device ID will create a new | 446 // point, subsequent requests to open this same device ID will create a new |
377 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. | 447 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. |
378 devices_.erase(entry); | 448 devices_.erase(entry); |
379 entry->video_capture_controller.reset(); | 449 entry->video_capture_controller.reset(); |
380 device_loop_->PostTask( | 450 device_loop_->PostTask( |
381 FROM_HERE, | 451 FROM_HERE, |
382 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, | 452 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, |
| 453 this, |
383 base::Owned(entry))); | 454 base::Owned(entry))); |
384 } | 455 } |
385 } | 456 } |
386 | 457 |
387 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( | 458 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( |
388 int capture_session_id) { | 459 int capture_session_id) { |
389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 460 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
390 | 461 |
391 std::map<int, MediaStreamDevice>::iterator session_it = | 462 std::map<int, MediaStreamDevice>::iterator session_it = |
392 sessions_.find(capture_session_id); | 463 sessions_.find(capture_session_id); |
(...skipping 13 matching lines...) Expand all Loading... |
406 | 477 |
407 scoped_ptr<VideoCaptureController> video_capture_controller( | 478 scoped_ptr<VideoCaptureController> video_capture_controller( |
408 new VideoCaptureController()); | 479 new VideoCaptureController()); |
409 DeviceEntry* new_device = new DeviceEntry(device_info.type, | 480 DeviceEntry* new_device = new DeviceEntry(device_info.type, |
410 device_info.id, | 481 device_info.id, |
411 video_capture_controller.Pass()); | 482 video_capture_controller.Pass()); |
412 devices_.insert(new_device); | 483 devices_.insert(new_device); |
413 return new_device; | 484 return new_device; |
414 } | 485 } |
415 | 486 |
| 487 VideoCaptureManager::DeviceInfo* VideoCaptureManager::FindDeviceInfoById( |
| 488 const std::string& id, |
| 489 DeviceInfos& device_vector) { |
| 490 for (DeviceInfos::iterator it = device_vector.begin(); |
| 491 it != device_vector.end(); ++it) { |
| 492 if (it->name.id() == id) |
| 493 return &(*it); |
| 494 } |
| 495 return NULL; |
| 496 } |
| 497 |
416 } // namespace content | 498 } // namespace content |
OLD | NEW |