Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
|
miu
2017/04/03 21:31:24
ditto: video_capture_system_impl.cc?
chfremer
2017/04/04 21:59:32
Done.
| |
| 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 "media/capture/video/video_capture_system.h" | 5 #include "media/capture/video/video_capture_system.h" |
| 6 | 6 |
| 7 #include "media/base/bind_to_current_loop.h" | 7 #include "media/base/bind_to_current_loop.h" |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| 11 // Compares two VideoCaptureFormat by checking smallest frame_size area, then | 11 // Compares two VideoCaptureFormat by checking smallest frame_size area, then |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 for (auto& format : *formats) { | 50 for (auto& format : *formats) { |
| 51 if (format.pixel_format != media::PIXEL_FORMAT_Y16) | 51 if (format.pixel_format != media::PIXEL_FORMAT_Y16) |
| 52 format.pixel_format = media::PIXEL_FORMAT_I420; | 52 format.pixel_format = media::PIXEL_FORMAT_I420; |
| 53 } | 53 } |
| 54 } | 54 } |
| 55 | 55 |
| 56 } // anonymous namespace | 56 } // anonymous namespace |
| 57 | 57 |
| 58 namespace media { | 58 namespace media { |
| 59 | 59 |
| 60 VideoCaptureSystem::VideoCaptureSystem( | 60 VideoCaptureSystemImpl::VideoCaptureSystemImpl( |
| 61 std::unique_ptr<VideoCaptureDeviceFactory> factory) | 61 std::unique_ptr<VideoCaptureDeviceFactory> factory) |
| 62 : factory_(std::move(factory)) {} | 62 : factory_(std::move(factory)) {} |
| 63 | 63 |
| 64 VideoCaptureSystem::~VideoCaptureSystem() = default; | 64 VideoCaptureSystemImpl::~VideoCaptureSystemImpl() = default; |
| 65 | 65 |
| 66 void VideoCaptureSystem::GetDeviceInfosAsync( | 66 void VideoCaptureSystemImpl::GetDeviceInfosAsync( |
| 67 const DeviceInfoCallback& result_callback) { | 67 const DeviceInfoCallback& result_callback) { |
| 68 factory_->EnumerateDeviceDescriptors(media::BindToCurrentLoop( | 68 factory_->EnumerateDeviceDescriptors(media::BindToCurrentLoop( |
| 69 base::Bind(&VideoCaptureSystem::OnDescriptorsReceived, | 69 base::Bind(&VideoCaptureSystemImpl::OnDescriptorsReceived, |
| 70 base::Unretained(this), result_callback))); | 70 base::Unretained(this), result_callback))); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Creates a VideoCaptureDevice object. Returns NULL if something goes wrong. | 73 // Creates a VideoCaptureDevice object. Returns NULL if something goes wrong. |
| 74 std::unique_ptr<VideoCaptureDevice> VideoCaptureSystem::CreateDevice( | 74 std::unique_ptr<VideoCaptureDevice> VideoCaptureSystemImpl::CreateDevice( |
| 75 const std::string& device_id) { | 75 const std::string& device_id) { |
| 76 const VideoCaptureDeviceInfo* device_info = LookupDeviceInfoFromId(device_id); | 76 const VideoCaptureDeviceInfo* device_info = LookupDeviceInfoFromId(device_id); |
| 77 if (!device_info) | 77 if (!device_info) |
| 78 return nullptr; | 78 return nullptr; |
| 79 return factory_->CreateDevice(device_info->descriptor); | 79 return factory_->CreateDevice(device_info->descriptor); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void VideoCaptureSystem::OnDescriptorsReceived( | 82 void VideoCaptureSystemImpl::OnDescriptorsReceived( |
| 83 const DeviceInfoCallback& result_callback, | 83 const DeviceInfoCallback& result_callback, |
| 84 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors) { | 84 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors) { |
| 85 // For devices for which we already have an entry in |devices_info_cache_|, | 85 // For devices for which we already have an entry in |devices_info_cache_|, |
| 86 // we do not want to query the |factory_| for supported formats again. We | 86 // we do not want to query the |factory_| for supported formats again. We |
| 87 // simply copy them from |devices_info_cache_|. | 87 // simply copy them from |devices_info_cache_|. |
| 88 std::vector<VideoCaptureDeviceInfo> new_devices_info_cache; | 88 std::vector<VideoCaptureDeviceInfo> new_devices_info_cache; |
| 89 new_devices_info_cache.reserve(descriptors->size()); | 89 new_devices_info_cache.reserve(descriptors->size()); |
| 90 for (const auto& descriptor : *descriptors) { | 90 for (const auto& descriptor : *descriptors) { |
| 91 if (auto* cached_info = LookupDeviceInfoFromId(descriptor.device_id)) { | 91 if (auto* cached_info = LookupDeviceInfoFromId(descriptor.device_id)) { |
| 92 new_devices_info_cache.push_back(*cached_info); | 92 new_devices_info_cache.push_back(*cached_info); |
| 93 } else { | 93 } else { |
| 94 // Query for supported formats in order to create the entry. | 94 // Query for supported formats in order to create the entry. |
| 95 VideoCaptureDeviceInfo device_info(descriptor); | 95 VideoCaptureDeviceInfo device_info(descriptor); |
| 96 factory_->GetSupportedFormats(descriptor, &device_info.supported_formats); | 96 factory_->GetSupportedFormats(descriptor, &device_info.supported_formats); |
| 97 ConsolidateCaptureFormats(&device_info.supported_formats); | 97 ConsolidateCaptureFormats(&device_info.supported_formats); |
| 98 new_devices_info_cache.push_back(device_info); | 98 new_devices_info_cache.push_back(device_info); |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 | 101 |
| 102 devices_info_cache_.swap(new_devices_info_cache); | 102 devices_info_cache_.swap(new_devices_info_cache); |
| 103 result_callback.Run(devices_info_cache_); | 103 result_callback.Run(devices_info_cache_); |
| 104 } | 104 } |
| 105 | 105 |
| 106 const VideoCaptureDeviceInfo* VideoCaptureSystem::LookupDeviceInfoFromId( | 106 const VideoCaptureDeviceInfo* VideoCaptureSystemImpl::LookupDeviceInfoFromId( |
| 107 const std::string& device_id) { | 107 const std::string& device_id) { |
| 108 auto iter = std::find_if( | 108 auto iter = std::find_if( |
| 109 devices_info_cache_.begin(), devices_info_cache_.end(), | 109 devices_info_cache_.begin(), devices_info_cache_.end(), |
| 110 [&device_id](const media::VideoCaptureDeviceInfo& device_info) { | 110 [&device_id](const media::VideoCaptureDeviceInfo& device_info) { |
| 111 return device_info.descriptor.device_id == device_id; | 111 return device_info.descriptor.device_id == device_id; |
| 112 }); | 112 }); |
| 113 if (iter == devices_info_cache_.end()) | 113 if (iter == devices_info_cache_.end()) |
| 114 return nullptr; | 114 return nullptr; |
| 115 return &(*iter); | 115 return &(*iter); |
| 116 } | 116 } |
| 117 | 117 |
| 118 } // namespace media | 118 } // namespace media |
| OLD | NEW |