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" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 VideoCaptureManager::VideoCaptureManager() | 58 VideoCaptureManager::VideoCaptureManager() |
59 : listener_(NULL), | 59 : listener_(NULL), |
60 new_capture_session_id_(1), | 60 new_capture_session_id_(1), |
61 artificial_device_source_for_testing_(DISABLED) { | 61 artificial_device_source_for_testing_(DISABLED) { |
62 } | 62 } |
63 | 63 |
64 VideoCaptureManager::~VideoCaptureManager() { | 64 VideoCaptureManager::~VideoCaptureManager() { |
65 DCHECK(devices_.empty()); | 65 DCHECK(devices_.empty()); |
66 } | 66 } |
67 | 67 |
68 void VideoCaptureManager::Register(MediaStreamProviderListener* listener, | 68 void VideoCaptureManager::Register( |
69 base::MessageLoopProxy* device_thread_loop) { | 69 MediaStreamProviderListener* listener, |
| 70 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { |
70 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
71 DCHECK(!listener_); | 72 DCHECK(!listener_); |
72 DCHECK(!device_loop_.get()); | 73 DCHECK(!device_task_runner_.get()); |
73 listener_ = listener; | 74 listener_ = listener; |
74 device_loop_ = device_thread_loop; | 75 device_task_runner_ = device_task_runner; |
75 } | 76 } |
76 | 77 |
77 void VideoCaptureManager::Unregister() { | 78 void VideoCaptureManager::Unregister() { |
78 DCHECK(listener_); | 79 DCHECK(listener_); |
79 listener_ = NULL; | 80 listener_ = NULL; |
80 } | 81 } |
81 | 82 |
82 void VideoCaptureManager::EnumerateDevices(MediaStreamType stream_type) { | 83 void VideoCaptureManager::EnumerateDevices(MediaStreamType stream_type) { |
83 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
84 DVLOG(1) << "VideoCaptureManager::EnumerateDevices, type " << stream_type; | 85 DVLOG(1) << "VideoCaptureManager::EnumerateDevices, type " << stream_type; |
85 DCHECK(listener_); | 86 DCHECK(listener_); |
86 base::PostTaskAndReplyWithResult( | 87 base::PostTaskAndReplyWithResult( |
87 device_loop_, FROM_HERE, | 88 device_task_runner_, FROM_HERE, |
88 base::Bind(&VideoCaptureManager::GetAvailableDevicesInfoOnDeviceThread, | 89 base::Bind(&VideoCaptureManager::GetAvailableDevicesInfoOnDeviceThread, |
89 this, stream_type, devices_info_cache_), | 90 this, stream_type, devices_info_cache_), |
90 base::Bind(&VideoCaptureManager::OnDevicesInfoEnumerated, this, | 91 base::Bind(&VideoCaptureManager::OnDevicesInfoEnumerated, this, |
91 stream_type)); | 92 stream_type)); |
92 } | 93 } |
93 | 94 |
94 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { | 95 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { |
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
96 DCHECK(listener_); | 97 DCHECK(listener_); |
97 | 98 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 return; | 240 return; |
240 } | 241 } |
241 | 242 |
242 DCHECK(entry->video_capture_controller); | 243 DCHECK(entry->video_capture_controller); |
243 | 244 |
244 // First client starts the device. | 245 // First client starts the device. |
245 if (entry->video_capture_controller->GetClientCount() == 0) { | 246 if (entry->video_capture_controller->GetClientCount() == 0) { |
246 DVLOG(1) << "VideoCaptureManager starting device (type = " | 247 DVLOG(1) << "VideoCaptureManager starting device (type = " |
247 << entry->stream_type << ", id = " << entry->id << ")"; | 248 << entry->stream_type << ", id = " << entry->id << ")"; |
248 | 249 |
249 device_loop_->PostTask( | 250 device_task_runner_->PostTask( |
250 FROM_HERE, | 251 FROM_HERE, |
251 base::Bind( | 252 base::Bind( |
252 &VideoCaptureManager::DoStartDeviceOnDeviceThread, | 253 &VideoCaptureManager::DoStartDeviceOnDeviceThread, |
253 this, | 254 this, |
254 entry, | 255 entry, |
255 params, | 256 params, |
256 base::Passed(entry->video_capture_controller->NewDeviceClient()))); | 257 base::Passed(entry->video_capture_controller->NewDeviceClient()))); |
257 } | 258 } |
258 // Run the callback first, as AddClient() may trigger OnFrameInfo(). | 259 // Run the callback first, as AddClient() may trigger OnFrameInfo(). |
259 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); | 260 done_cb.Run(entry->video_capture_controller->GetWeakPtr()); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 StreamDeviceInfoArray devices; | 374 StreamDeviceInfoArray devices; |
374 for (DeviceInfos::const_iterator it = devices_info_cache_.begin(); | 375 for (DeviceInfos::const_iterator it = devices_info_cache_.begin(); |
375 it != devices_info_cache_.end(); ++it) { | 376 it != devices_info_cache_.end(); ++it) { |
376 devices.push_back(StreamDeviceInfo( | 377 devices.push_back(StreamDeviceInfo( |
377 stream_type, it->name.GetNameAndModel(), it->name.id())); | 378 stream_type, it->name.GetNameAndModel(), it->name.id())); |
378 } | 379 } |
379 listener_->DevicesEnumerated(stream_type, devices); | 380 listener_->DevicesEnumerated(stream_type, devices); |
380 } | 381 } |
381 | 382 |
382 bool VideoCaptureManager::IsOnDeviceThread() const { | 383 bool VideoCaptureManager::IsOnDeviceThread() const { |
383 return device_loop_->BelongsToCurrentThread(); | 384 return device_task_runner_->BelongsToCurrentThread(); |
384 } | 385 } |
385 | 386 |
386 VideoCaptureManager::DeviceInfos | 387 VideoCaptureManager::DeviceInfos |
387 VideoCaptureManager::GetAvailableDevicesInfoOnDeviceThread( | 388 VideoCaptureManager::GetAvailableDevicesInfoOnDeviceThread( |
388 MediaStreamType stream_type, | 389 MediaStreamType stream_type, |
389 const DeviceInfos& old_device_info_cache) { | 390 const DeviceInfos& old_device_info_cache) { |
390 SCOPED_UMA_HISTOGRAM_TIMER( | 391 SCOPED_UMA_HISTOGRAM_TIMER( |
391 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime"); | 392 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime"); |
392 DCHECK(IsOnDeviceThread()); | 393 DCHECK(IsOnDeviceThread()); |
393 media::VideoCaptureDevice::Names names_snapshot; | 394 media::VideoCaptureDevice::Names names_snapshot; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 if (entry->video_capture_controller->GetClientCount() == 0) { | 497 if (entry->video_capture_controller->GetClientCount() == 0) { |
497 DVLOG(1) << "VideoCaptureManager stopping device (type = " | 498 DVLOG(1) << "VideoCaptureManager stopping device (type = " |
498 << entry->stream_type << ", id = " << entry->id << ")"; | 499 << entry->stream_type << ", id = " << entry->id << ")"; |
499 | 500 |
500 // The DeviceEntry is removed from |devices_| immediately. The controller is | 501 // The DeviceEntry is removed from |devices_| immediately. The controller is |
501 // deleted immediately, and the device is freed asynchronously. After this | 502 // deleted immediately, and the device is freed asynchronously. After this |
502 // point, subsequent requests to open this same device ID will create a new | 503 // point, subsequent requests to open this same device ID will create a new |
503 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. | 504 // DeviceEntry, VideoCaptureController, and VideoCaptureDevice. |
504 devices_.erase(entry); | 505 devices_.erase(entry); |
505 entry->video_capture_controller.reset(); | 506 entry->video_capture_controller.reset(); |
506 device_loop_->PostTask( | 507 device_task_runner_->PostTask( |
507 FROM_HERE, | 508 FROM_HERE, |
508 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, | 509 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, |
509 base::Owned(entry))); | 510 base::Owned(entry))); |
510 } | 511 } |
511 } | 512 } |
512 | 513 |
513 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( | 514 VideoCaptureManager::DeviceEntry* VideoCaptureManager::GetOrCreateDeviceEntry( |
514 media::VideoCaptureSessionId capture_session_id) { | 515 media::VideoCaptureSessionId capture_session_id) { |
515 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 516 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
516 | 517 |
(...skipping 27 matching lines...) Expand all Loading... |
544 DeviceInfos& device_vector) { | 545 DeviceInfos& device_vector) { |
545 for (DeviceInfos::iterator it = device_vector.begin(); | 546 for (DeviceInfos::iterator it = device_vector.begin(); |
546 it != device_vector.end(); ++it) { | 547 it != device_vector.end(); ++it) { |
547 if (it->name.id() == id) | 548 if (it->name.id() == id) |
548 return &(*it); | 549 return &(*it); |
549 } | 550 } |
550 return NULL; | 551 return NULL; |
551 } | 552 } |
552 | 553 |
553 } // namespace content | 554 } // namespace content |
OLD | NEW |