Chromium Code Reviews| 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/bind_helpers.h" | 10 #include "base/bind_helpers.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/task_runner_util.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "content/browser/media/capture/web_contents_video_capture_device.h" | 16 #include "content/browser/media/capture/web_contents_video_capture_device.h" |
| 17 #include "content/browser/media/media_internals.h" | |
| 17 #include "content/browser/renderer_host/media/video_capture_controller.h" | 18 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 18 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" | 19 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/desktop_media_id.h" | 21 #include "content/public/browser/desktop_media_id.h" |
| 21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 22 #include "content/public/common/media_stream_request.h" | 23 #include "content/public/common/media_stream_request.h" |
| 23 #include "media/base/bind_to_current_loop.h" | 24 #include "media/base/bind_to_current_loop.h" |
| 24 #include "media/base/scoped_histogram_timer.h" | 25 #include "media/base/scoped_histogram_timer.h" |
| 25 #include "media/video/capture/video_capture_device.h" | 26 #include "media/video/capture/video_capture_device.h" |
| 26 #include "media/video/capture/video_capture_device_factory.h" | 27 #include "media/video/capture/video_capture_device_factory.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 98 VideoCaptureManager::DeviceEntry::DeviceEntry( | 99 VideoCaptureManager::DeviceEntry::DeviceEntry( |
| 99 MediaStreamType stream_type, | 100 MediaStreamType stream_type, |
| 100 const std::string& id, | 101 const std::string& id, |
| 101 scoped_ptr<VideoCaptureController> controller) | 102 scoped_ptr<VideoCaptureController> controller) |
| 102 : stream_type(stream_type), | 103 : stream_type(stream_type), |
| 103 id(id), | 104 id(id), |
| 104 video_capture_controller(controller.Pass()) {} | 105 video_capture_controller(controller.Pass()) {} |
| 105 | 106 |
| 106 VideoCaptureManager::DeviceEntry::~DeviceEntry() {} | 107 VideoCaptureManager::DeviceEntry::~DeviceEntry() {} |
| 107 | 108 |
| 108 VideoCaptureManager::DeviceInfo::DeviceInfo() {} | |
| 109 | |
| 110 VideoCaptureManager::DeviceInfo::DeviceInfo( | |
| 111 const media::VideoCaptureDevice::Name& name, | |
| 112 const media::VideoCaptureFormats& supported_formats) | |
| 113 : name(name), | |
| 114 supported_formats(supported_formats) {} | |
| 115 | |
| 116 VideoCaptureManager::DeviceInfo::~DeviceInfo() {} | |
| 117 | 109 |
| 118 VideoCaptureManager::VideoCaptureManager( | 110 VideoCaptureManager::VideoCaptureManager( |
| 119 scoped_ptr<media::VideoCaptureDeviceFactory> factory) | 111 scoped_ptr<media::VideoCaptureDeviceFactory> factory) |
| 120 : listener_(NULL), | 112 : listener_(NULL), |
| 121 new_capture_session_id_(1), | 113 new_capture_session_id_(1), |
| 122 video_capture_device_factory_(factory.Pass()) { | 114 video_capture_device_factory_(factory.Pass()) { |
| 123 } | 115 } |
| 124 | 116 |
| 125 VideoCaptureManager::~VideoCaptureManager() { | 117 VideoCaptureManager::~VideoCaptureManager() { |
| 126 DCHECK(devices_.empty()); | 118 DCHECK(devices_.empty()); |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 553 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 545 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 554 UMA_HISTOGRAM_TIMES( | 546 UMA_HISTOGRAM_TIMES( |
| 555 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime", | 547 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime", |
| 556 timer->Elapsed()); | 548 timer->Elapsed()); |
| 557 if (!listener_) { | 549 if (!listener_) { |
| 558 // Listener has been removed. | 550 // Listener has been removed. |
| 559 return; | 551 return; |
| 560 } | 552 } |
| 561 devices_info_cache_ = new_devices_info_cache; | 553 devices_info_cache_ = new_devices_info_cache; |
| 562 | 554 |
| 555 // Send a delayed update to MediaInternals about enumerated capabilities. | |
| 556 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, base::Bind( | |
|
perkj_chrome
2014/10/08 14:26:36
Call directly instead as discussed.
mcasas
2014/10/08 14:49:39
Done.
| |
| 557 &MediaInternals::UpdateVideoCaptureDeviceCapabilities, | |
| 558 base::Unretained(MediaInternals::GetInstance()), | |
| 559 devices_info_cache_)); | |
| 560 | |
| 563 // Walk the |devices_info_cache_| and transform from VCD::Name to | 561 // Walk the |devices_info_cache_| and transform from VCD::Name to |
| 564 // StreamDeviceInfo for return purposes. | 562 // StreamDeviceInfo for return purposes. |
| 565 StreamDeviceInfoArray devices; | 563 StreamDeviceInfoArray devices; |
| 566 for (DeviceInfos::const_iterator it = devices_info_cache_.begin(); | 564 for (const auto &it : devices_info_cache_) { |
| 567 it != devices_info_cache_.end(); ++it) { | |
| 568 devices.push_back(StreamDeviceInfo( | 565 devices.push_back(StreamDeviceInfo( |
| 569 stream_type, it->name.GetNameAndModel(), it->name.id())); | 566 stream_type, it.name.GetNameAndModel(), it.name.id())); |
| 570 } | 567 } |
| 571 listener_->DevicesEnumerated(stream_type, devices); | 568 listener_->DevicesEnumerated(stream_type, devices); |
| 572 } | 569 } |
| 573 | 570 |
| 574 bool VideoCaptureManager::IsOnDeviceThread() const { | 571 bool VideoCaptureManager::IsOnDeviceThread() const { |
| 575 return device_task_runner_->BelongsToCurrentThread(); | 572 return device_task_runner_->BelongsToCurrentThread(); |
| 576 } | 573 } |
| 577 | 574 |
| 578 void VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread( | 575 void VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread( |
| 579 base::Callback<void(const DeviceInfos&)> on_devices_enumerated_callback, | 576 base::Callback<void(const DeviceInfos&)> on_devices_enumerated_callback, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 596 names_snapshot->erase(it); | 593 names_snapshot->erase(it); |
| 597 break; | 594 break; |
| 598 } | 595 } |
| 599 } | 596 } |
| 600 } | 597 } |
| 601 | 598 |
| 602 // Get the supported capture formats for the new devices in |names_snapshot|. | 599 // Get the supported capture formats for the new devices in |names_snapshot|. |
| 603 for (media::VideoCaptureDevice::Names::const_iterator it = | 600 for (media::VideoCaptureDevice::Names::const_iterator it = |
| 604 names_snapshot->begin(); | 601 names_snapshot->begin(); |
| 605 it != names_snapshot->end(); ++it) { | 602 it != names_snapshot->end(); ++it) { |
| 606 media::VideoCaptureFormats supported_formats; | |
| 607 DeviceInfo device_info(*it, media::VideoCaptureFormats()); | 603 DeviceInfo device_info(*it, media::VideoCaptureFormats()); |
| 608 video_capture_device_factory_->GetDeviceSupportedFormats( | 604 video_capture_device_factory_->GetDeviceSupportedFormats( |
| 609 *it, &(device_info.supported_formats)); | 605 *it, &(device_info.supported_formats)); |
| 610 ConsolidateCaptureFormats(&device_info.supported_formats); | 606 ConsolidateCaptureFormats(&device_info.supported_formats); |
| 611 new_devices_info_cache.push_back(device_info); | 607 new_devices_info_cache.push_back(device_info); |
| 612 } | 608 } |
| 613 | 609 |
| 614 on_devices_enumerated_callback.Run(new_devices_info_cache); | 610 on_devices_enumerated_callback.Run(new_devices_info_cache); |
| 615 } | 611 } |
| 616 | 612 |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 722 gfx::NativeViewId window_id) { | 718 gfx::NativeViewId window_id) { |
| 723 DCHECK(IsOnDeviceThread()); | 719 DCHECK(IsOnDeviceThread()); |
| 724 DCHECK(notification_window_ids_.find(session_id) == | 720 DCHECK(notification_window_ids_.find(session_id) == |
| 725 notification_window_ids_.end()); | 721 notification_window_ids_.end()); |
| 726 notification_window_ids_[session_id] = window_id; | 722 notification_window_ids_[session_id] = window_id; |
| 727 VLOG(2) << "Screen capture notification window saved for session " | 723 VLOG(2) << "Screen capture notification window saved for session " |
| 728 << session_id << " on device thread."; | 724 << session_id << " on device thread."; |
| 729 } | 725 } |
| 730 | 726 |
| 731 } // namespace content | 727 } // namespace content |
| OLD | NEW |