| 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 11 matching lines...) Expand all Loading... |
| 22 #include "base/threading/thread_task_runner_handle.h" | 22 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 24 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" | 24 #include "content/browser/media/capture/desktop_capture_device_uma_types.h" |
| 25 #include "content/browser/media/capture/web_contents_video_capture_device.h" | 25 #include "content/browser/media/capture/web_contents_video_capture_device.h" |
| 26 #include "content/browser/media/media_internals.h" | 26 #include "content/browser/media/media_internals.h" |
| 27 #include "content/browser/renderer_host/media/video_capture_controller.h" | 27 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 28 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 28 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
| 29 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
| 30 #include "content/public/browser/desktop_media_id.h" | 30 #include "content/public/browser/desktop_media_id.h" |
| 31 #include "content/public/common/media_stream_request.h" | 31 #include "content/public/common/media_stream_request.h" |
| 32 #include "device/capture/video/video_capture_device.h" |
| 33 #include "device/capture/video/video_capture_device_factory.h" |
| 32 #include "media/base/bind_to_current_loop.h" | 34 #include "media/base/bind_to_current_loop.h" |
| 33 #include "media/base/media_switches.h" | 35 #include "media/base/media_switches.h" |
| 34 #include "media/capture/video/video_capture_device.h" | |
| 35 #include "media/capture/video/video_capture_device_factory.h" | |
| 36 | 36 |
| 37 #if defined(ENABLE_SCREEN_CAPTURE) | 37 #if defined(ENABLE_SCREEN_CAPTURE) |
| 38 #include "content/browser/media/capture/desktop_capture_device.h" | 38 #include "content/browser/media/capture/desktop_capture_device.h" |
| 39 #if defined(USE_AURA) | 39 #if defined(USE_AURA) |
| 40 #include "content/browser/media/capture/desktop_capture_device_aura.h" | 40 #include "content/browser/media/capture/desktop_capture_device_aura.h" |
| 41 #endif | 41 #endif |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 #if defined(OS_MACOSX) | 44 #if defined(OS_MACOSX) |
| 45 #include "media/base/mac/avfoundation_glue.h" | 45 #include "media/base/mac/avfoundation_glue.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 std::unique_ptr<VideoCaptureController> controller, | 135 std::unique_ptr<VideoCaptureController> controller, |
| 136 const media::VideoCaptureParams& params); | 136 const media::VideoCaptureParams& params); |
| 137 ~DeviceEntry(); | 137 ~DeviceEntry(); |
| 138 | 138 |
| 139 const int serial_id; | 139 const int serial_id; |
| 140 const MediaStreamType stream_type; | 140 const MediaStreamType stream_type; |
| 141 const std::string id; | 141 const std::string id; |
| 142 const media::VideoCaptureParams parameters; | 142 const media::VideoCaptureParams parameters; |
| 143 | 143 |
| 144 VideoCaptureController* video_capture_controller() const; | 144 VideoCaptureController* video_capture_controller() const; |
| 145 media::VideoCaptureDevice* video_capture_device() const; | 145 device::VideoCaptureDevice* video_capture_device() const; |
| 146 | 146 |
| 147 void SetVideoCaptureDevice(std::unique_ptr<VideoCaptureDevice> device); | 147 void SetVideoCaptureDevice(std::unique_ptr<VideoCaptureDevice> device); |
| 148 std::unique_ptr<VideoCaptureDevice> ReleaseVideoCaptureDevice(); | 148 std::unique_ptr<VideoCaptureDevice> ReleaseVideoCaptureDevice(); |
| 149 | 149 |
| 150 private: | 150 private: |
| 151 const std::unique_ptr<VideoCaptureController> video_capture_controller_; | 151 const std::unique_ptr<VideoCaptureController> video_capture_controller_; |
| 152 | 152 |
| 153 std::unique_ptr<VideoCaptureDevice> video_capture_device_; | 153 std::unique_ptr<VideoCaptureDevice> video_capture_device_; |
| 154 | 154 |
| 155 base::ThreadChecker thread_checker_; | 155 base::ThreadChecker thread_checker_; |
| 156 }; | 156 }; |
| 157 | 157 |
| 158 // Bundles a media::VideoCaptureDeviceDescriptor with corresponding supported | 158 // Bundles a device::VideoCaptureDeviceDescriptor with corresponding supported |
| 159 // video formats. | 159 // video formats. |
| 160 struct VideoCaptureManager::DeviceInfo { | 160 struct VideoCaptureManager::DeviceInfo { |
| 161 DeviceInfo(); | 161 DeviceInfo(); |
| 162 DeviceInfo(media::VideoCaptureDeviceDescriptor descriptor); | 162 DeviceInfo(device::VideoCaptureDeviceDescriptor descriptor); |
| 163 DeviceInfo(const DeviceInfo& other); | 163 DeviceInfo(const DeviceInfo& other); |
| 164 ~DeviceInfo(); | 164 ~DeviceInfo(); |
| 165 DeviceInfo& operator=(const DeviceInfo& other); | 165 DeviceInfo& operator=(const DeviceInfo& other); |
| 166 | 166 |
| 167 media::VideoCaptureDeviceDescriptor descriptor; | 167 device::VideoCaptureDeviceDescriptor descriptor; |
| 168 media::VideoCaptureFormats supported_formats; | 168 media::VideoCaptureFormats supported_formats; |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 // Class used for queuing request for starting a device. | 171 // Class used for queuing request for starting a device. |
| 172 class VideoCaptureManager::CaptureDeviceStartRequest { | 172 class VideoCaptureManager::CaptureDeviceStartRequest { |
| 173 public: | 173 public: |
| 174 CaptureDeviceStartRequest(int serial_id, | 174 CaptureDeviceStartRequest(int serial_id, |
| 175 media::VideoCaptureSessionId session_id, | 175 media::VideoCaptureSessionId session_id, |
| 176 const media::VideoCaptureParams& params); | 176 const media::VideoCaptureParams& params); |
| 177 int serial_id() const { return serial_id_; } | 177 int serial_id() const { return serial_id_; } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 199 const media::VideoCaptureParams& params) | 199 const media::VideoCaptureParams& params) |
| 200 : serial_id(g_device_start_id++), | 200 : serial_id(g_device_start_id++), |
| 201 stream_type(stream_type), | 201 stream_type(stream_type), |
| 202 id(id), | 202 id(id), |
| 203 parameters(params), | 203 parameters(params), |
| 204 video_capture_controller_(std::move(controller)) {} | 204 video_capture_controller_(std::move(controller)) {} |
| 205 | 205 |
| 206 VideoCaptureManager::DeviceEntry::~DeviceEntry() { | 206 VideoCaptureManager::DeviceEntry::~DeviceEntry() { |
| 207 DCHECK(thread_checker_.CalledOnValidThread()); | 207 DCHECK(thread_checker_.CalledOnValidThread()); |
| 208 // DCHECK that this DeviceEntry does not still own a | 208 // DCHECK that this DeviceEntry does not still own a |
| 209 // media::VideoCaptureDevice. media::VideoCaptureDevice must be deleted on | 209 // device::VideoCaptureDevice. media::VideoCaptureDevice must be deleted on |
| 210 // the device thread. | 210 // the device thread. |
| 211 DCHECK(video_capture_device_ == nullptr); | 211 DCHECK(video_capture_device_ == nullptr); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void VideoCaptureManager::DeviceEntry::SetVideoCaptureDevice( | 214 void VideoCaptureManager::DeviceEntry::SetVideoCaptureDevice( |
| 215 std::unique_ptr<VideoCaptureDevice> device) { | 215 std::unique_ptr<VideoCaptureDevice> device) { |
| 216 DCHECK(thread_checker_.CalledOnValidThread()); | 216 DCHECK(thread_checker_.CalledOnValidThread()); |
| 217 video_capture_device_.swap(device); | 217 video_capture_device_.swap(device); |
| 218 } | 218 } |
| 219 | 219 |
| 220 std::unique_ptr<media::VideoCaptureDevice> | 220 std::unique_ptr<device::VideoCaptureDevice> |
| 221 VideoCaptureManager::DeviceEntry::ReleaseVideoCaptureDevice() { | 221 VideoCaptureManager::DeviceEntry::ReleaseVideoCaptureDevice() { |
| 222 DCHECK(thread_checker_.CalledOnValidThread()); | 222 DCHECK(thread_checker_.CalledOnValidThread()); |
| 223 return std::move(video_capture_device_); | 223 return std::move(video_capture_device_); |
| 224 } | 224 } |
| 225 | 225 |
| 226 VideoCaptureController* | 226 VideoCaptureController* |
| 227 VideoCaptureManager::DeviceEntry::video_capture_controller() const { | 227 VideoCaptureManager::DeviceEntry::video_capture_controller() const { |
| 228 DCHECK(thread_checker_.CalledOnValidThread()); | 228 DCHECK(thread_checker_.CalledOnValidThread()); |
| 229 return video_capture_controller_.get(); | 229 return video_capture_controller_.get(); |
| 230 } | 230 } |
| 231 | 231 |
| 232 media::VideoCaptureDevice* | 232 device::VideoCaptureDevice* |
| 233 VideoCaptureManager::DeviceEntry::video_capture_device() const { | 233 VideoCaptureManager::DeviceEntry::video_capture_device() const { |
| 234 DCHECK(thread_checker_.CalledOnValidThread()); | 234 DCHECK(thread_checker_.CalledOnValidThread()); |
| 235 return video_capture_device_.get(); | 235 return video_capture_device_.get(); |
| 236 } | 236 } |
| 237 | 237 |
| 238 VideoCaptureManager::DeviceInfo::DeviceInfo() = default; | 238 VideoCaptureManager::DeviceInfo::DeviceInfo() = default; |
| 239 | 239 |
| 240 VideoCaptureManager::DeviceInfo::DeviceInfo( | 240 VideoCaptureManager::DeviceInfo::DeviceInfo( |
| 241 media::VideoCaptureDeviceDescriptor descriptor) | 241 device::VideoCaptureDeviceDescriptor descriptor) |
| 242 : descriptor(descriptor) {} | 242 : descriptor(descriptor) {} |
| 243 | 243 |
| 244 VideoCaptureManager::DeviceInfo::DeviceInfo( | 244 VideoCaptureManager::DeviceInfo::DeviceInfo( |
| 245 const VideoCaptureManager::DeviceInfo& other) = default; | 245 const VideoCaptureManager::DeviceInfo& other) = default; |
| 246 | 246 |
| 247 VideoCaptureManager::DeviceInfo::~DeviceInfo() = default; | 247 VideoCaptureManager::DeviceInfo::~DeviceInfo() = default; |
| 248 | 248 |
| 249 VideoCaptureManager::DeviceInfo& VideoCaptureManager::DeviceInfo::operator=( | 249 VideoCaptureManager::DeviceInfo& VideoCaptureManager::DeviceInfo::operator=( |
| 250 const VideoCaptureManager::DeviceInfo& other) = default; | 250 const VideoCaptureManager::DeviceInfo& other) = default; |
| 251 | 251 |
| 252 VideoCaptureManager::CaptureDeviceStartRequest::CaptureDeviceStartRequest( | 252 VideoCaptureManager::CaptureDeviceStartRequest::CaptureDeviceStartRequest( |
| 253 int serial_id, | 253 int serial_id, |
| 254 media::VideoCaptureSessionId session_id, | 254 media::VideoCaptureSessionId session_id, |
| 255 const media::VideoCaptureParams& params) | 255 const media::VideoCaptureParams& params) |
| 256 : serial_id_(serial_id), | 256 : serial_id_(serial_id), |
| 257 session_id_(session_id), | 257 session_id_(session_id), |
| 258 params_(params), | 258 params_(params), |
| 259 abort_start_(false) { | 259 abort_start_(false) { |
| 260 } | 260 } |
| 261 | 261 |
| 262 VideoCaptureManager::VideoCaptureManager( | 262 VideoCaptureManager::VideoCaptureManager( |
| 263 std::unique_ptr<media::VideoCaptureDeviceFactory> factory) | 263 std::unique_ptr<device::VideoCaptureDeviceFactory> factory) |
| 264 : listener_(nullptr), | 264 : listener_(nullptr), |
| 265 new_capture_session_id_(1), | 265 new_capture_session_id_(1), |
| 266 video_capture_device_factory_(std::move(factory)) {} | 266 video_capture_device_factory_(std::move(factory)) {} |
| 267 | 267 |
| 268 VideoCaptureManager::~VideoCaptureManager() { | 268 VideoCaptureManager::~VideoCaptureManager() { |
| 269 DCHECK(devices_.empty()); | 269 DCHECK(devices_.empty()); |
| 270 DCHECK(device_start_queue_.empty()); | 270 DCHECK(device_start_queue_.empty()); |
| 271 } | 271 } |
| 272 | 272 |
| 273 void VideoCaptureManager::Register( | 273 void VideoCaptureManager::Register( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 devices_enumerated_callback = base::Bind( | 312 devices_enumerated_callback = base::Bind( |
| 313 &VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread, this, | 313 &VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread, this, |
| 314 media::BindToCurrentLoop( | 314 media::BindToCurrentLoop( |
| 315 base::Bind(&VideoCaptureManager::OnDevicesInfoEnumerated, this, | 315 base::Bind(&VideoCaptureManager::OnDevicesInfoEnumerated, this, |
| 316 stream_type, base::Owned(new base::ElapsedTimer()))), | 316 stream_type, base::Owned(new base::ElapsedTimer()))), |
| 317 stream_type, devices_info_cache_); | 317 stream_type, devices_info_cache_); |
| 318 // OK to use base::Unretained() since we own the VCDFactory and |this| is | 318 // OK to use base::Unretained() since we own the VCDFactory and |this| is |
| 319 // bound in |devices_enumerated_callback|. | 319 // bound in |devices_enumerated_callback|. |
| 320 device_task_runner_->PostTask( | 320 device_task_runner_->PostTask( |
| 321 FROM_HERE, | 321 FROM_HERE, |
| 322 base::Bind(&media::VideoCaptureDeviceFactory::EnumerateDeviceDescriptors, | 322 base::Bind(&device::VideoCaptureDeviceFactory::EnumerateDeviceDescriptors, |
| 323 base::Unretained(video_capture_device_factory_.get()), | 323 base::Unretained(video_capture_device_factory_.get()), |
| 324 devices_enumerated_callback)); | 324 devices_enumerated_callback)); |
| 325 } | 325 } |
| 326 | 326 |
| 327 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { | 327 int VideoCaptureManager::Open(const StreamDeviceInfo& device_info) { |
| 328 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 328 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 329 DCHECK(listener_); | 329 DCHECK(listener_); |
| 330 | 330 |
| 331 // Generate a new id for the session being opened. | 331 // Generate a new id for the session being opened. |
| 332 const media::VideoCaptureSessionId capture_session_id = | 332 const media::VideoCaptureSessionId capture_session_id = |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 int serial_id, | 518 int serial_id, |
| 519 std::unique_ptr<VideoCaptureDevice> device) { | 519 std::unique_ptr<VideoCaptureDevice> device) { |
| 520 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 520 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 521 DCHECK(serial_id == device_start_queue_.begin()->serial_id()); | 521 DCHECK(serial_id == device_start_queue_.begin()->serial_id()); |
| 522 DVLOG(3) << "OnDeviceStarted"; | 522 DVLOG(3) << "OnDeviceStarted"; |
| 523 if (device_start_queue_.front().abort_start()) { | 523 if (device_start_queue_.front().abort_start()) { |
| 524 // |device| can be null if creation failed in | 524 // |device| can be null if creation failed in |
| 525 // DoStartDeviceCaptureOnDeviceThread. | 525 // DoStartDeviceCaptureOnDeviceThread. |
| 526 // The device is no longer wanted. Stop the device again. | 526 // The device is no longer wanted. Stop the device again. |
| 527 DVLOG(3) << "OnDeviceStarted but start request have been aborted."; | 527 DVLOG(3) << "OnDeviceStarted but start request have been aborted."; |
| 528 media::VideoCaptureDevice* device_ptr = device.get(); | 528 device::VideoCaptureDevice* device_ptr = device.get(); |
| 529 base::Closure closure = | 529 base::Closure closure = |
| 530 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, | 530 base::Bind(&VideoCaptureManager::DoStopDeviceOnDeviceThread, this, |
| 531 base::Passed(&device)); | 531 base::Passed(&device)); |
| 532 if (device_ptr && !device_task_runner_->PostTask(FROM_HERE, closure)) { | 532 if (device_ptr && !device_task_runner_->PostTask(FROM_HERE, closure)) { |
| 533 // PostTask failed. The device must be stopped anyway. | 533 // PostTask failed. The device must be stopped anyway. |
| 534 device_ptr->StopAndDeAllocate(); | 534 device_ptr->StopAndDeAllocate(); |
| 535 } | 535 } |
| 536 } else { | 536 } else { |
| 537 DeviceEntry* const entry = GetDeviceEntryBySerialId(serial_id); | 537 DeviceEntry* const entry = GetDeviceEntryBySerialId(serial_id); |
| 538 DCHECK(entry); | 538 DCHECK(entry); |
| 539 DCHECK(!entry->video_capture_device()); | 539 DCHECK(!entry->video_capture_device()); |
| 540 entry->SetVideoCaptureDevice(std::move(device)); | 540 entry->SetVideoCaptureDevice(std::move(device)); |
| 541 | 541 |
| 542 if (entry->stream_type == MEDIA_DESKTOP_VIDEO_CAPTURE) { | 542 if (entry->stream_type == MEDIA_DESKTOP_VIDEO_CAPTURE) { |
| 543 const media::VideoCaptureSessionId session_id = | 543 const media::VideoCaptureSessionId session_id = |
| 544 device_start_queue_.front().session_id(); | 544 device_start_queue_.front().session_id(); |
| 545 DCHECK(session_id != kFakeSessionId); | 545 DCHECK(session_id != kFakeSessionId); |
| 546 MaybePostDesktopCaptureWindowId(session_id); | 546 MaybePostDesktopCaptureWindowId(session_id); |
| 547 } | 547 } |
| 548 } | 548 } |
| 549 | 549 |
| 550 device_start_queue_.pop_front(); | 550 device_start_queue_.pop_front(); |
| 551 HandleQueuedStartRequest(); | 551 HandleQueuedStartRequest(); |
| 552 } | 552 } |
| 553 | 553 |
| 554 std::unique_ptr<media::VideoCaptureDevice> | 554 std::unique_ptr<device::VideoCaptureDevice> |
| 555 VideoCaptureManager::DoStartDeviceCaptureOnDeviceThread( | 555 VideoCaptureManager::DoStartDeviceCaptureOnDeviceThread( |
| 556 const VideoCaptureDeviceDescriptor& descriptor, | 556 const VideoCaptureDeviceDescriptor& descriptor, |
| 557 const media::VideoCaptureParams& params, | 557 const media::VideoCaptureParams& params, |
| 558 std::unique_ptr<VideoCaptureDevice::Client> device_client) { | 558 std::unique_ptr<VideoCaptureDevice::Client> device_client) { |
| 559 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 559 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
| 560 DCHECK(IsOnDeviceThread()); | 560 DCHECK(IsOnDeviceThread()); |
| 561 | 561 |
| 562 std::unique_ptr<VideoCaptureDevice> video_capture_device; | 562 std::unique_ptr<VideoCaptureDevice> video_capture_device; |
| 563 video_capture_device = | 563 video_capture_device = |
| 564 video_capture_device_factory_->CreateDevice(descriptor); | 564 video_capture_device_factory_->CreateDevice(descriptor); |
| 565 | 565 |
| 566 if (!video_capture_device) { | 566 if (!video_capture_device) { |
| 567 device_client->OnError(FROM_HERE, "Could not create capture device"); | 567 device_client->OnError(FROM_HERE, "Could not create capture device"); |
| 568 return nullptr; | 568 return nullptr; |
| 569 } | 569 } |
| 570 | 570 |
| 571 video_capture_device->AllocateAndStart(params, std::move(device_client)); | 571 video_capture_device->AllocateAndStart(params, std::move(device_client)); |
| 572 return video_capture_device; | 572 return video_capture_device; |
| 573 } | 573 } |
| 574 | 574 |
| 575 std::unique_ptr<media::VideoCaptureDevice> | 575 std::unique_ptr<device::VideoCaptureDevice> |
| 576 VideoCaptureManager::DoStartTabCaptureOnDeviceThread( | 576 VideoCaptureManager::DoStartTabCaptureOnDeviceThread( |
| 577 const std::string& id, | 577 const std::string& id, |
| 578 const media::VideoCaptureParams& params, | 578 const media::VideoCaptureParams& params, |
| 579 std::unique_ptr<VideoCaptureDevice::Client> device_client) { | 579 std::unique_ptr<VideoCaptureDevice::Client> device_client) { |
| 580 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 580 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
| 581 DCHECK(IsOnDeviceThread()); | 581 DCHECK(IsOnDeviceThread()); |
| 582 | 582 |
| 583 std::unique_ptr<VideoCaptureDevice> video_capture_device; | 583 std::unique_ptr<VideoCaptureDevice> video_capture_device; |
| 584 video_capture_device.reset(WebContentsVideoCaptureDevice::Create(id)); | 584 video_capture_device.reset(WebContentsVideoCaptureDevice::Create(id)); |
| 585 | 585 |
| 586 if (!video_capture_device) { | 586 if (!video_capture_device) { |
| 587 device_client->OnError(FROM_HERE, "Could not create capture device"); | 587 device_client->OnError(FROM_HERE, "Could not create capture device"); |
| 588 return nullptr; | 588 return nullptr; |
| 589 } | 589 } |
| 590 | 590 |
| 591 video_capture_device->AllocateAndStart(params, std::move(device_client)); | 591 video_capture_device->AllocateAndStart(params, std::move(device_client)); |
| 592 return video_capture_device; | 592 return video_capture_device; |
| 593 } | 593 } |
| 594 | 594 |
| 595 std::unique_ptr<media::VideoCaptureDevice> | 595 std::unique_ptr<device::VideoCaptureDevice> |
| 596 VideoCaptureManager::DoStartDesktopCaptureOnDeviceThread( | 596 VideoCaptureManager::DoStartDesktopCaptureOnDeviceThread( |
| 597 const std::string& id, | 597 const std::string& id, |
| 598 const media::VideoCaptureParams& params, | 598 const media::VideoCaptureParams& params, |
| 599 std::unique_ptr<VideoCaptureDevice::Client> device_client) { | 599 std::unique_ptr<VideoCaptureDevice::Client> device_client) { |
| 600 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 600 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
| 601 DCHECK(IsOnDeviceThread()); | 601 DCHECK(IsOnDeviceThread()); |
| 602 | 602 |
| 603 std::unique_ptr<VideoCaptureDevice> video_capture_device; | 603 std::unique_ptr<VideoCaptureDevice> video_capture_device; |
| 604 #if defined(ENABLE_SCREEN_CAPTURE) | 604 #if defined(ENABLE_SCREEN_CAPTURE) |
| 605 DesktopMediaID desktop_id = DesktopMediaID::Parse(id); | 605 DesktopMediaID desktop_id = DesktopMediaID::Parse(id); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 return; | 747 return; |
| 748 | 748 |
| 749 controller->ResumeClient(client_id, client_handler); | 749 controller->ResumeClient(client_id, client_handler); |
| 750 } | 750 } |
| 751 | 751 |
| 752 void VideoCaptureManager::RequestRefreshFrameForClient( | 752 void VideoCaptureManager::RequestRefreshFrameForClient( |
| 753 VideoCaptureController* controller) { | 753 VideoCaptureController* controller) { |
| 754 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 754 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 755 | 755 |
| 756 if (DeviceEntry* entry = GetDeviceEntryByController(controller)) { | 756 if (DeviceEntry* entry = GetDeviceEntryByController(controller)) { |
| 757 if (media::VideoCaptureDevice* device = entry->video_capture_device()) { | 757 if (device::VideoCaptureDevice* device = entry->video_capture_device()) { |
| 758 device_task_runner_->PostTask( | 758 device_task_runner_->PostTask( |
| 759 FROM_HERE, | 759 FROM_HERE, |
| 760 base::Bind(&VideoCaptureDevice::RequestRefreshFrame, | 760 base::Bind(&VideoCaptureDevice::RequestRefreshFrame, |
| 761 // Unretained is safe to use here because |device| would be | 761 // Unretained is safe to use here because |device| would be |
| 762 // null if it was scheduled for shutdown and destruction, | 762 // null if it was scheduled for shutdown and destruction, |
| 763 // and because this task is guaranteed to run before the | 763 // and because this task is guaranteed to run before the |
| 764 // task that destroys the |device|. | 764 // task that destroys the |device|. |
| 765 base::Unretained(device))); | 765 base::Unretained(device))); |
| 766 } | 766 } |
| 767 } | 767 } |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 timer->Elapsed()); | 943 timer->Elapsed()); |
| 944 if (!listener_) { | 944 if (!listener_) { |
| 945 // Listener has been removed. | 945 // Listener has been removed. |
| 946 return; | 946 return; |
| 947 } | 947 } |
| 948 devices_info_cache_ = new_devices_info_cache; | 948 devices_info_cache_ = new_devices_info_cache; |
| 949 | 949 |
| 950 // Walk the |devices_info_cache_| and transform from | 950 // Walk the |devices_info_cache_| and transform from |
| 951 // VideoCaptureDeviceDescriptor to StreamDeviceInfo for return purposes. | 951 // VideoCaptureDeviceDescriptor to StreamDeviceInfo for return purposes. |
| 952 StreamDeviceInfoArray devices; | 952 StreamDeviceInfoArray devices; |
| 953 std::vector<std::tuple<media::VideoCaptureDeviceDescriptor, | 953 std::vector<std::tuple<device::VideoCaptureDeviceDescriptor, |
| 954 media::VideoCaptureFormats>> | 954 media::VideoCaptureFormats>> |
| 955 descriptors_and_formats; | 955 descriptors_and_formats; |
| 956 for (const auto& it : devices_info_cache_) { | 956 for (const auto& it : devices_info_cache_) { |
| 957 devices.emplace_back(stream_type, it.descriptor.GetNameAndModel(), | 957 devices.emplace_back(stream_type, it.descriptor.GetNameAndModel(), |
| 958 it.descriptor.device_id); | 958 it.descriptor.device_id); |
| 959 descriptors_and_formats.emplace_back(it.descriptor, it.supported_formats); | 959 descriptors_and_formats.emplace_back(it.descriptor, it.supported_formats); |
| 960 MediaInternals::GetInstance()->UpdateVideoCaptureDeviceCapabilities( | 960 MediaInternals::GetInstance()->UpdateVideoCaptureDeviceCapabilities( |
| 961 descriptors_and_formats); | 961 descriptors_and_formats); |
| 962 } | 962 } |
| 963 listener_->DevicesEnumerated(stream_type, devices); | 963 listener_->DevicesEnumerated(stream_type, devices); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1018 // TODO(mcasas): use a helper function https://crbug.com/624854. | 1018 // TODO(mcasas): use a helper function https://crbug.com/624854. |
| 1019 DeviceEntries::iterator device_it = | 1019 DeviceEntries::iterator device_it = |
| 1020 std::find_if(devices_.begin(), devices_.end(), | 1020 std::find_if(devices_.begin(), devices_.end(), |
| 1021 [entry](const std::unique_ptr<DeviceEntry>& device_entry) { | 1021 [entry](const std::unique_ptr<DeviceEntry>& device_entry) { |
| 1022 return device_entry.get() == entry; | 1022 return device_entry.get() == entry; |
| 1023 }); | 1023 }); |
| 1024 devices_.erase(device_it); | 1024 devices_.erase(device_it); |
| 1025 } | 1025 } |
| 1026 } | 1026 } |
| 1027 | 1027 |
| 1028 media::VideoCaptureDevice* | 1028 device::VideoCaptureDevice* |
| 1029 VideoCaptureManager::GetVideoCaptureDeviceBySessionId(int session_id) { | 1029 VideoCaptureManager::GetVideoCaptureDeviceBySessionId(int session_id) { |
| 1030 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 1030 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 1031 SessionMap::const_iterator session_it = sessions_.find(session_id); | 1031 SessionMap::const_iterator session_it = sessions_.find(session_id); |
| 1032 if (session_it == sessions_.end()) | 1032 if (session_it == sessions_.end()) |
| 1033 return nullptr; | 1033 return nullptr; |
| 1034 | 1034 |
| 1035 DeviceEntry* const device_info = | 1035 DeviceEntry* const device_info = |
| 1036 GetDeviceEntryByTypeAndId(session_it->second.type, session_it->second.id); | 1036 GetDeviceEntryByTypeAndId(session_it->second.type, session_it->second.id); |
| 1037 return device_info ? device_info->video_capture_device() : nullptr; | 1037 return device_info ? device_info->video_capture_device() : nullptr; |
| 1038 } | 1038 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1107 std::unique_ptr<VideoCaptureController> video_capture_controller( | 1107 std::unique_ptr<VideoCaptureController> video_capture_controller( |
| 1108 new VideoCaptureController(max_buffers)); | 1108 new VideoCaptureController(max_buffers)); |
| 1109 DeviceEntry* new_device = | 1109 DeviceEntry* new_device = |
| 1110 new DeviceEntry(device_info.type, device_info.id, | 1110 new DeviceEntry(device_info.type, device_info.id, |
| 1111 std::move(video_capture_controller), params); | 1111 std::move(video_capture_controller), params); |
| 1112 devices_.emplace_back(new_device); | 1112 devices_.emplace_back(new_device); |
| 1113 return new_device; | 1113 return new_device; |
| 1114 } | 1114 } |
| 1115 | 1115 |
| 1116 void VideoCaptureManager::SetDesktopCaptureWindowIdOnDeviceThread( | 1116 void VideoCaptureManager::SetDesktopCaptureWindowIdOnDeviceThread( |
| 1117 media::VideoCaptureDevice* device, | 1117 device::VideoCaptureDevice* device, |
| 1118 gfx::NativeViewId window_id) { | 1118 gfx::NativeViewId window_id) { |
| 1119 DCHECK(IsOnDeviceThread()); | 1119 DCHECK(IsOnDeviceThread()); |
| 1120 #if defined(ENABLE_SCREEN_CAPTURE) | 1120 #if defined(ENABLE_SCREEN_CAPTURE) |
| 1121 DesktopCaptureDevice* desktop_device = | 1121 DesktopCaptureDevice* desktop_device = |
| 1122 static_cast<DesktopCaptureDevice*>(device); | 1122 static_cast<DesktopCaptureDevice*>(device); |
| 1123 desktop_device->SetNotificationWindowId(window_id); | 1123 desktop_device->SetNotificationWindowId(window_id); |
| 1124 VLOG(2) << "Screen capture notification window passed on device thread."; | 1124 VLOG(2) << "Screen capture notification window passed on device thread."; |
| 1125 #endif | 1125 #endif |
| 1126 } | 1126 } |
| 1127 | 1127 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 if (!device_in_queue) { | 1202 if (!device_in_queue) { |
| 1203 // Session ID is only valid for Screen capture. So we can fake it to | 1203 // Session ID is only valid for Screen capture. So we can fake it to |
| 1204 // resume video capture devices here. | 1204 // resume video capture devices here. |
| 1205 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); | 1205 QueueStartDevice(kFakeSessionId, entry.get(), entry->parameters); |
| 1206 } | 1206 } |
| 1207 } | 1207 } |
| 1208 } | 1208 } |
| 1209 #endif // defined(OS_ANDROID) | 1209 #endif // defined(OS_ANDROID) |
| 1210 | 1210 |
| 1211 } // namespace content | 1211 } // namespace content |
| OLD | NEW |