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 <algorithm> | 7 #include <algorithm> |
8 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
220 } | 220 } |
221 | 221 |
222 void VideoCaptureManager::EnumerateDevices( | 222 void VideoCaptureManager::EnumerateDevices( |
223 const EnumerationCallback& client_callback) { | 223 const EnumerationCallback& client_callback) { |
224 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 224 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
225 DVLOG(1) << "VideoCaptureManager::EnumerateDevices"; | 225 DVLOG(1) << "VideoCaptureManager::EnumerateDevices"; |
226 | 226 |
227 // Bind a callback to ConsolidateDevicesInfoOnDeviceThread() with an argument | 227 // Bind a callback to ConsolidateDevicesInfoOnDeviceThread() with an argument |
228 // for another callback to OnDevicesInfoEnumerated() to be run in the current | 228 // for another callback to OnDevicesInfoEnumerated() to be run in the current |
229 // loop, i.e. IO loop. Pass a timer for UMA histogram collection. | 229 // loop, i.e. IO loop. Pass a timer for UMA histogram collection. |
230 base::Callback<void(std::unique_ptr<VideoCaptureDeviceDescriptors>)> | |
231 devices_enumerated_callback = base::Bind( | |
232 &VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread, this, | |
233 media::BindToCurrentLoop(base::Bind( | |
234 &VideoCaptureManager::OnDevicesInfoEnumerated, this, | |
235 base::Owned(new base::ElapsedTimer()), client_callback)), | |
236 devices_info_cache_); | |
237 // OK to use base::Unretained() since we own the VCDFactory and |this| is | |
238 // bound in |devices_enumerated_callback|. | |
239 device_task_runner_->PostTask( | 230 device_task_runner_->PostTask( |
240 FROM_HERE, | 231 FROM_HERE, |
241 base::Bind(&media::VideoCaptureDeviceFactory::EnumerateDeviceDescriptors, | 232 base::Bind(&VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread, |
chfremer
2017/04/07 16:34:21
As a heads up, I am sorry about the extra work thi
Chandan
2017/04/10 09:18:24
Done.
| |
242 base::Unretained(video_capture_device_factory_.get()), | 233 this, |
243 devices_enumerated_callback)); | 234 media::BindToCurrentLoop(base::Bind( |
235 &VideoCaptureManager::OnDevicesInfoEnumerated, this, | |
236 base::Owned(new base::ElapsedTimer()), client_callback)), | |
237 devices_info_cache_)); | |
244 } | 238 } |
245 | 239 |
246 const media::VideoCaptureDeviceDescriptor* | 240 const media::VideoCaptureDeviceDescriptor* |
247 VideoCaptureManager::LookupDeviceDescriptor(const std::string& id) { | 241 VideoCaptureManager::LookupDeviceDescriptor(const std::string& id) { |
248 const DeviceInfo* info = GetDeviceInfoById(id); | 242 const DeviceInfo* info = GetDeviceInfoById(id); |
249 return info ? (&info->descriptor) : nullptr; | 243 return info ? (&info->descriptor) : nullptr; |
250 } | 244 } |
251 | 245 |
252 int VideoCaptureManager::Open(const MediaStreamDevice& device) { | 246 int VideoCaptureManager::Open(const MediaStreamDevice& device) { |
253 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 247 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
763 for (const auto& it : devices_info_cache_) { | 757 for (const auto& it : devices_info_cache_) { |
764 devices.emplace_back(it.descriptor); | 758 devices.emplace_back(it.descriptor); |
765 descriptors_and_formats.emplace_back(it.descriptor, it.supported_formats); | 759 descriptors_and_formats.emplace_back(it.descriptor, it.supported_formats); |
766 MediaInternals::GetInstance()->UpdateVideoCaptureDeviceCapabilities( | 760 MediaInternals::GetInstance()->UpdateVideoCaptureDeviceCapabilities( |
767 descriptors_and_formats); | 761 descriptors_and_formats); |
768 } | 762 } |
769 | 763 |
770 client_callback.Run(devices); | 764 client_callback.Run(devices); |
771 } | 765 } |
772 | 766 |
773 void VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread( | 767 void VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread( |
chfremer
2017/04/07 16:34:21
Now that this method includes the logic for pullin
Chandan
2017/04/10 09:18:24
This method no longer exists in this class.
| |
774 base::Callback<void(const VideoCaptureManager::DeviceInfos&)> | 768 base::Callback<void(const VideoCaptureManager::DeviceInfos&)> |
775 on_devices_enumerated_callback, | 769 on_devices_enumerated_callback, |
776 const VideoCaptureManager::DeviceInfos& old_device_info_cache, | 770 const VideoCaptureManager::DeviceInfos& old_device_info_cache) { |
777 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors_snapshot) { | |
778 DCHECK(device_task_runner_->BelongsToCurrentThread()); | 771 DCHECK(device_task_runner_->BelongsToCurrentThread()); |
772 media::VideoCaptureDeviceDescriptors descriptors; | |
773 video_capture_device_factory_->GetDeviceDescriptors(&descriptors); | |
779 // Construct |new_devices_info_cache| with the cached devices that are still | 774 // Construct |new_devices_info_cache| with the cached devices that are still |
780 // present in the system, and remove their names from |names_snapshot|, so we | 775 // present in the system, and remove their names from |names_snapshot|, so we |
781 // keep there the truly new devices. | 776 // keep there the truly new devices. |
782 VideoCaptureManager::DeviceInfos new_devices_info_cache; | 777 VideoCaptureManager::DeviceInfos new_devices_info_cache; |
783 for (const auto& device_info : old_device_info_cache) { | 778 for (const auto& device_info : old_device_info_cache) { |
784 for (VideoCaptureDeviceDescriptors::iterator it = | 779 for (VideoCaptureDeviceDescriptors::iterator it = descriptors.begin(); |
785 descriptors_snapshot->begin(); | 780 it != descriptors.end(); ++it) { |
786 it != descriptors_snapshot->end(); ++it) { | |
787 if (device_info.descriptor.device_id == it->device_id) { | 781 if (device_info.descriptor.device_id == it->device_id) { |
788 new_devices_info_cache.push_back(device_info); | 782 new_devices_info_cache.push_back(device_info); |
789 descriptors_snapshot->erase(it); | 783 descriptors.erase(it); |
790 break; | 784 break; |
791 } | 785 } |
792 } | 786 } |
793 } | 787 } |
794 | 788 |
795 // Get the device info for the new devices in |names_snapshot|. | 789 // Get the device info for the new devices in |names_snapshot|. |
796 for (const auto& it : *descriptors_snapshot) { | 790 for (const auto& it : descriptors) { |
797 DeviceInfo device_info(it); | 791 DeviceInfo device_info(it); |
798 video_capture_device_factory_->GetSupportedFormats( | 792 video_capture_device_factory_->GetSupportedFormats( |
799 it, &device_info.supported_formats); | 793 it, &device_info.supported_formats); |
800 ConsolidateCaptureFormats(&device_info.supported_formats); | 794 ConsolidateCaptureFormats(&device_info.supported_formats); |
801 new_devices_info_cache.push_back(device_info); | 795 new_devices_info_cache.push_back(device_info); |
802 } | 796 } |
803 | 797 |
804 on_devices_enumerated_callback.Run(new_devices_info_cache); | 798 on_devices_enumerated_callback.Run(new_devices_info_cache); |
805 } | 799 } |
806 | 800 |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
968 // Session ID is only valid for Screen capture. So we can fake it to | 962 // Session ID is only valid for Screen capture. So we can fake it to |
969 // resume video capture devices here. | 963 // resume video capture devices here. |
970 QueueStartDevice(kFakeSessionId, controller.get(), | 964 QueueStartDevice(kFakeSessionId, controller.get(), |
971 controller->parameters()); | 965 controller->parameters()); |
972 } | 966 } |
973 } | 967 } |
974 } | 968 } |
975 #endif // defined(OS_ANDROID) | 969 #endif // defined(OS_ANDROID) |
976 | 970 |
977 } // namespace content | 971 } // namespace content |
OLD | NEW |