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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 base::Bind(&VideoCaptureManager::OnApplicationStateChange, | 284 base::Bind(&VideoCaptureManager::OnApplicationStateChange, |
285 base::Unretained(this)))); | 285 base::Unretained(this)))); |
286 #endif | 286 #endif |
287 } | 287 } |
288 | 288 |
289 void VideoCaptureManager::Unregister() { | 289 void VideoCaptureManager::Unregister() { |
290 DCHECK(listener_); | 290 DCHECK(listener_); |
291 listener_ = nullptr; | 291 listener_ = nullptr; |
292 } | 292 } |
293 | 293 |
294 void VideoCaptureManager::EnumerateDevices(MediaStreamType stream_type) { | 294 void VideoCaptureManager::EnumerateDevices( |
| 295 const EnumerationCallback& client_callback) { |
295 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 296 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
296 DVLOG(1) << "VideoCaptureManager::EnumerateDevices, type " << stream_type; | 297 DVLOG(1) << "VideoCaptureManager::EnumerateDevices"; |
297 DCHECK(listener_); | |
298 DCHECK_EQ(stream_type, MEDIA_DEVICE_VIDEO_CAPTURE); | |
299 | 298 |
300 #if defined(OS_MACOSX) | 299 #if defined(OS_MACOSX) |
301 if (NeedToInitializeCaptureDeviceApi(stream_type)) { | 300 if (NeedToInitializeCaptureDeviceApi(MEDIA_DEVICE_VIDEO_CAPTURE)) { |
302 InitializeCaptureDeviceApiOnUIThread( | 301 InitializeCaptureDeviceApiOnUIThread(base::Bind( |
303 base::Bind(&VideoCaptureManager::EnumerateDevices, this, stream_type)); | 302 &VideoCaptureManager::EnumerateDevices, this, client_callback)); |
304 return; | 303 return; |
305 } | 304 } |
306 #endif | 305 #endif |
307 | 306 |
308 // Bind a callback to ConsolidateDevicesInfoOnDeviceThread() with an argument | 307 // Bind a callback to ConsolidateDevicesInfoOnDeviceThread() with an argument |
309 // for another callback to OnDevicesInfoEnumerated() to be run in the current | 308 // for another callback to OnDevicesInfoEnumerated() to be run in the current |
310 // loop, i.e. IO loop. Pass a timer for UMA histogram collection. | 309 // loop, i.e. IO loop. Pass a timer for UMA histogram collection. |
311 base::Callback<void(std::unique_ptr<VideoCaptureDeviceDescriptors>)> | 310 base::Callback<void(std::unique_ptr<VideoCaptureDeviceDescriptors>)> |
312 devices_enumerated_callback = base::Bind( | 311 devices_enumerated_callback = base::Bind( |
313 &VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread, this, | 312 &VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread, this, |
314 media::BindToCurrentLoop( | 313 media::BindToCurrentLoop(base::Bind( |
315 base::Bind(&VideoCaptureManager::OnDevicesInfoEnumerated, this, | 314 &VideoCaptureManager::OnDevicesInfoEnumerated, this, |
316 stream_type, base::Owned(new base::ElapsedTimer()))), | 315 base::Owned(new base::ElapsedTimer()), client_callback)), |
317 stream_type, devices_info_cache_); | 316 devices_info_cache_); |
318 // OK to use base::Unretained() since we own the VCDFactory and |this| is | 317 // OK to use base::Unretained() since we own the VCDFactory and |this| is |
319 // bound in |devices_enumerated_callback|. | 318 // bound in |devices_enumerated_callback|. |
320 device_task_runner_->PostTask( | 319 device_task_runner_->PostTask( |
321 FROM_HERE, | 320 FROM_HERE, |
322 base::Bind(&media::VideoCaptureDeviceFactory::EnumerateDeviceDescriptors, | 321 base::Bind(&media::VideoCaptureDeviceFactory::EnumerateDeviceDescriptors, |
323 base::Unretained(video_capture_device_factory_.get()), | 322 base::Unretained(video_capture_device_factory_.get()), |
324 devices_enumerated_callback)); | 323 devices_enumerated_callback)); |
325 } | 324 } |
326 | 325 |
327 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { | 326 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
951 media::VideoCaptureSessionId capture_session_id) { | 950 media::VideoCaptureSessionId capture_session_id) { |
952 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 951 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
953 if (!listener_) { | 952 if (!listener_) { |
954 // Listener has been removed. | 953 // Listener has been removed. |
955 return; | 954 return; |
956 } | 955 } |
957 listener_->Closed(stream_type, capture_session_id); | 956 listener_->Closed(stream_type, capture_session_id); |
958 } | 957 } |
959 | 958 |
960 void VideoCaptureManager::OnDevicesInfoEnumerated( | 959 void VideoCaptureManager::OnDevicesInfoEnumerated( |
961 MediaStreamType stream_type, | |
962 base::ElapsedTimer* timer, | 960 base::ElapsedTimer* timer, |
| 961 const EnumerationCallback& client_callback, |
963 const VideoCaptureManager::DeviceInfos& new_devices_info_cache) { | 962 const VideoCaptureManager::DeviceInfos& new_devices_info_cache) { |
964 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 963 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
965 UMA_HISTOGRAM_TIMES( | 964 UMA_HISTOGRAM_TIMES( |
966 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime", | 965 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime", |
967 timer->Elapsed()); | 966 timer->Elapsed()); |
968 if (!listener_) { | |
969 // Listener has been removed. | |
970 return; | |
971 } | |
972 devices_info_cache_ = new_devices_info_cache; | 967 devices_info_cache_ = new_devices_info_cache; |
973 | 968 |
974 // Walk the |devices_info_cache_| and transform from | 969 // Walk the |devices_info_cache_| and produce a |
975 // VideoCaptureDeviceDescriptor to StreamDeviceInfo for return purposes. | 970 // media::VideoCaptureDeviceDescriptors for return purposes. |
976 StreamDeviceInfoArray devices; | 971 media::VideoCaptureDeviceDescriptors devices; |
977 std::vector<std::tuple<media::VideoCaptureDeviceDescriptor, | 972 std::vector<std::tuple<media::VideoCaptureDeviceDescriptor, |
978 media::VideoCaptureFormats>> | 973 media::VideoCaptureFormats>> |
979 descriptors_and_formats; | 974 descriptors_and_formats; |
980 for (const auto& it : devices_info_cache_) { | 975 for (const auto& it : devices_info_cache_) { |
981 // TODO(guidou): Implement group IDs for video capture devices. | 976 devices.emplace_back(it.descriptor); |
982 // http://crbug.com/627793 | |
983 devices.emplace_back(stream_type, it.descriptor.GetNameAndModel(), | |
984 it.descriptor.device_id); | |
985 descriptors_and_formats.emplace_back(it.descriptor, it.supported_formats); | 977 descriptors_and_formats.emplace_back(it.descriptor, it.supported_formats); |
986 MediaInternals::GetInstance()->UpdateVideoCaptureDeviceCapabilities( | 978 MediaInternals::GetInstance()->UpdateVideoCaptureDeviceCapabilities( |
987 descriptors_and_formats); | 979 descriptors_and_formats); |
988 } | 980 } |
989 listener_->DevicesEnumerated(stream_type, devices); | 981 |
| 982 client_callback.Run(devices); |
990 } | 983 } |
991 | 984 |
992 bool VideoCaptureManager::IsOnDeviceThread() const { | 985 bool VideoCaptureManager::IsOnDeviceThread() const { |
993 return device_task_runner_->BelongsToCurrentThread(); | 986 return device_task_runner_->BelongsToCurrentThread(); |
994 } | 987 } |
995 | 988 |
996 void VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread( | 989 void VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread( |
997 base::Callback<void(const VideoCaptureManager::DeviceInfos&)> | 990 base::Callback<void(const VideoCaptureManager::DeviceInfos&)> |
998 on_devices_enumerated_callback, | 991 on_devices_enumerated_callback, |
999 MediaStreamType stream_type, | |
1000 const VideoCaptureManager::DeviceInfos& old_device_info_cache, | 992 const VideoCaptureManager::DeviceInfos& old_device_info_cache, |
1001 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors_snapshot) { | 993 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors_snapshot) { |
1002 DCHECK(IsOnDeviceThread()); | 994 DCHECK(IsOnDeviceThread()); |
1003 // Construct |new_devices_info_cache| with the cached devices that are still | 995 // Construct |new_devices_info_cache| with the cached devices that are still |
1004 // present in the system, and remove their names from |names_snapshot|, so we | 996 // present in the system, and remove their names from |names_snapshot|, so we |
1005 // keep there the truly new devices. | 997 // keep there the truly new devices. |
1006 VideoCaptureManager::DeviceInfos new_devices_info_cache; | 998 VideoCaptureManager::DeviceInfos new_devices_info_cache; |
1007 for (const auto& device_info : old_device_info_cache) { | 999 for (const auto& device_info : old_device_info_cache) { |
1008 for (VideoCaptureDeviceDescriptors::iterator it = | 1000 for (VideoCaptureDeviceDescriptors::iterator it = |
1009 descriptors_snapshot->begin(); | 1001 descriptors_snapshot->begin(); |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 if (!device_in_queue) { | 1254 if (!device_in_queue) { |
1263 // Session ID is only valid for Screen capture. So we can fake it to | 1255 // Session ID is only valid for Screen capture. So we can fake it to |
1264 // resume video capture devices here. | 1256 // resume video capture devices here. |
1265 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); | 1257 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); |
1266 } | 1258 } |
1267 } | 1259 } |
1268 } | 1260 } |
1269 #endif // defined(OS_ANDROID) | 1261 #endif // defined(OS_ANDROID) |
1270 | 1262 |
1271 } // namespace content | 1263 } // namespace content |
OLD | NEW |