Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(622)

Side by Side Diff: content/browser/renderer_host/media/video_capture_manager.cc

Issue 616833004: chrome://media-internals: update MediaInternals when devices capabilities are enumerated. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: FakeVCDFactory needs to specify capture API for Win. Linux/CrOs MediaInternalsVideoCaptureDeviceTes… Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { 221 scoped_ptr<media::VideoCaptureDevice::Client> device_client) {
230 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); 222 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime");
231 DCHECK(IsOnDeviceThread()); 223 DCHECK(IsOnDeviceThread());
232 224
233 scoped_ptr<media::VideoCaptureDevice> video_capture_device; 225 scoped_ptr<media::VideoCaptureDevice> video_capture_device;
234 switch (entry->stream_type) { 226 switch (entry->stream_type) {
235 case MEDIA_DEVICE_VIDEO_CAPTURE: { 227 case MEDIA_DEVICE_VIDEO_CAPTURE: {
236 // We look up the device id from the renderer in our local enumeration 228 // We look up the device id from the renderer in our local enumeration
237 // since the renderer does not have all the information that might be 229 // since the renderer does not have all the information that might be
238 // held in the browser-side VideoCaptureDevice::Name structure. 230 // held in the browser-side VideoCaptureDevice::Name structure.
239 DeviceInfo* found = FindDeviceInfoById(entry->id, devices_info_cache_); 231 media::VideoCaptureDeviceInfo* found =
232 FindDeviceInfoById(entry->id, devices_info_cache_);
240 if (found) { 233 if (found) {
241 video_capture_device = 234 video_capture_device =
242 video_capture_device_factory_->Create(found->name); 235 video_capture_device_factory_->Create(found->name);
243 } 236 }
244 break; 237 break;
245 } 238 }
246 case MEDIA_TAB_VIDEO_CAPTURE: { 239 case MEDIA_TAB_VIDEO_CAPTURE: {
247 video_capture_device.reset( 240 video_capture_device.reset(
248 WebContentsVideoCaptureDevice::Create(entry->id)); 241 WebContentsVideoCaptureDevice::Create(entry->id));
249 break; 242 break;
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 media::VideoCaptureFormats* supported_formats) { 430 media::VideoCaptureFormats* supported_formats) {
438 DCHECK_CURRENTLY_ON(BrowserThread::IO); 431 DCHECK_CURRENTLY_ON(BrowserThread::IO);
439 DCHECK(supported_formats->empty()); 432 DCHECK(supported_formats->empty());
440 433
441 SessionMap::iterator it = sessions_.find(capture_session_id); 434 SessionMap::iterator it = sessions_.find(capture_session_id);
442 if (it == sessions_.end()) 435 if (it == sessions_.end())
443 return false; 436 return false;
444 DVLOG(1) << "GetDeviceSupportedFormats for device: " << it->second.name; 437 DVLOG(1) << "GetDeviceSupportedFormats for device: " << it->second.name;
445 438
446 // Return all available formats of the device, regardless its started state. 439 // Return all available formats of the device, regardless its started state.
447 DeviceInfo* existing_device = 440 media::VideoCaptureDeviceInfo* existing_device =
448 FindDeviceInfoById(it->second.id, devices_info_cache_); 441 FindDeviceInfoById(it->second.id, devices_info_cache_);
449 if (existing_device) 442 if (existing_device)
450 *supported_formats = existing_device->supported_formats; 443 *supported_formats = existing_device->supported_formats;
451 return true; 444 return true;
452 } 445 }
453 446
454 bool VideoCaptureManager::GetDeviceFormatsInUse( 447 bool VideoCaptureManager::GetDeviceFormatsInUse(
455 media::VideoCaptureSessionId capture_session_id, 448 media::VideoCaptureSessionId capture_session_id,
456 media::VideoCaptureFormats* formats_in_use) { 449 media::VideoCaptureFormats* formats_in_use) {
457 DCHECK_CURRENTLY_ON(BrowserThread::IO); 450 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 if (!listener_) { 535 if (!listener_) {
543 // Listener has been removed. 536 // Listener has been removed.
544 return; 537 return;
545 } 538 }
546 listener_->Closed(stream_type, capture_session_id); 539 listener_->Closed(stream_type, capture_session_id);
547 } 540 }
548 541
549 void VideoCaptureManager::OnDevicesInfoEnumerated( 542 void VideoCaptureManager::OnDevicesInfoEnumerated(
550 MediaStreamType stream_type, 543 MediaStreamType stream_type,
551 base::ElapsedTimer* timer, 544 base::ElapsedTimer* timer,
552 const DeviceInfos& new_devices_info_cache) { 545 const media::VideoCaptureDeviceInfos& new_devices_info_cache) {
553 DCHECK_CURRENTLY_ON(BrowserThread::IO); 546 DCHECK_CURRENTLY_ON(BrowserThread::IO);
554 UMA_HISTOGRAM_TIMES( 547 UMA_HISTOGRAM_TIMES(
555 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime", 548 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime",
556 timer->Elapsed()); 549 timer->Elapsed());
557 if (!listener_) { 550 if (!listener_) {
558 // Listener has been removed. 551 // Listener has been removed.
559 return; 552 return;
560 } 553 }
561 devices_info_cache_ = new_devices_info_cache; 554 devices_info_cache_ = new_devices_info_cache;
562 555
556 MediaInternals::GetInstance()->UpdateVideoCaptureDeviceCapabilities(
557 devices_info_cache_);
558
563 // Walk the |devices_info_cache_| and transform from VCD::Name to 559 // Walk the |devices_info_cache_| and transform from VCD::Name to
564 // StreamDeviceInfo for return purposes. 560 // StreamDeviceInfo for return purposes.
565 StreamDeviceInfoArray devices; 561 StreamDeviceInfoArray devices;
566 for (DeviceInfos::const_iterator it = devices_info_cache_.begin(); 562 for (const auto& it : devices_info_cache_) {
567 it != devices_info_cache_.end(); ++it) {
568 devices.push_back(StreamDeviceInfo( 563 devices.push_back(StreamDeviceInfo(
569 stream_type, it->name.GetNameAndModel(), it->name.id())); 564 stream_type, it.name.GetNameAndModel(), it.name.id()));
570 } 565 }
571 listener_->DevicesEnumerated(stream_type, devices); 566 listener_->DevicesEnumerated(stream_type, devices);
572 } 567 }
573 568
574 bool VideoCaptureManager::IsOnDeviceThread() const { 569 bool VideoCaptureManager::IsOnDeviceThread() const {
575 return device_task_runner_->BelongsToCurrentThread(); 570 return device_task_runner_->BelongsToCurrentThread();
576 } 571 }
577 572
578 void VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread( 573 void VideoCaptureManager::ConsolidateDevicesInfoOnDeviceThread(
579 base::Callback<void(const DeviceInfos&)> on_devices_enumerated_callback, 574 base::Callback<void(const media::VideoCaptureDeviceInfos&)>
575 on_devices_enumerated_callback,
580 MediaStreamType stream_type, 576 MediaStreamType stream_type,
581 const DeviceInfos& old_device_info_cache, 577 const media::VideoCaptureDeviceInfos& old_device_info_cache,
582 scoped_ptr<media::VideoCaptureDevice::Names> names_snapshot) { 578 scoped_ptr<media::VideoCaptureDevice::Names> names_snapshot) {
583 DCHECK(IsOnDeviceThread()); 579 DCHECK(IsOnDeviceThread());
584 // Construct |new_devices_info_cache| with the cached devices that are still 580 // Construct |new_devices_info_cache| with the cached devices that are still
585 // present in the system, and remove their names from |names_snapshot|, so we 581 // present in the system, and remove their names from |names_snapshot|, so we
586 // keep there the truly new devices. 582 // keep there the truly new devices.
587 DeviceInfos new_devices_info_cache; 583 media::VideoCaptureDeviceInfos new_devices_info_cache;
588 for (DeviceInfos::const_iterator it_device_info = 584 for (const auto& device_info : old_device_info_cache) {
589 old_device_info_cache.begin();
590 it_device_info != old_device_info_cache.end(); ++it_device_info) {
591 for (media::VideoCaptureDevice::Names::iterator it = 585 for (media::VideoCaptureDevice::Names::iterator it =
592 names_snapshot->begin(); 586 names_snapshot->begin(); it != names_snapshot->end(); ++it) {
593 it != names_snapshot->end(); ++it) { 587 if (device_info.name.id() == it->id()) {
594 if (it_device_info->name.id() == it->id()) { 588 new_devices_info_cache.push_back(device_info);
595 new_devices_info_cache.push_back(*it_device_info);
596 names_snapshot->erase(it); 589 names_snapshot->erase(it);
597 break; 590 break;
598 } 591 }
599 } 592 }
600 } 593 }
601 594
602 // Get the supported capture formats for the new devices in |names_snapshot|. 595 // Get the supported capture formats for the new devices in |names_snapshot|.
603 for (media::VideoCaptureDevice::Names::const_iterator it = 596 for (const auto& it : *names_snapshot) {
604 names_snapshot->begin(); 597 media::VideoCaptureDeviceInfo device_info(it, media::VideoCaptureFormats());
605 it != names_snapshot->end(); ++it) {
606 media::VideoCaptureFormats supported_formats;
607 DeviceInfo device_info(*it, media::VideoCaptureFormats());
608 video_capture_device_factory_->GetDeviceSupportedFormats( 598 video_capture_device_factory_->GetDeviceSupportedFormats(
609 *it, &(device_info.supported_formats)); 599 it, &(device_info.supported_formats));
610 ConsolidateCaptureFormats(&device_info.supported_formats); 600 ConsolidateCaptureFormats(&device_info.supported_formats);
611 new_devices_info_cache.push_back(device_info); 601 new_devices_info_cache.push_back(device_info);
612 } 602 }
613 603
614 on_devices_enumerated_callback.Run(new_devices_info_cache); 604 on_devices_enumerated_callback.Run(new_devices_info_cache);
615 } 605 }
616 606
617 VideoCaptureManager::DeviceEntry* 607 VideoCaptureManager::DeviceEntry*
618 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( 608 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice(
619 const MediaStreamDevice& device_info) { 609 const MediaStreamDevice& device_info) {
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 kMaxNumberOfBuffersForTabCapture : kMaxNumberOfBuffers; 676 kMaxNumberOfBuffersForTabCapture : kMaxNumberOfBuffers;
687 scoped_ptr<VideoCaptureController> video_capture_controller( 677 scoped_ptr<VideoCaptureController> video_capture_controller(
688 new VideoCaptureController(max_buffers)); 678 new VideoCaptureController(max_buffers));
689 DeviceEntry* new_device = new DeviceEntry(device_info.type, 679 DeviceEntry* new_device = new DeviceEntry(device_info.type,
690 device_info.id, 680 device_info.id,
691 video_capture_controller.Pass()); 681 video_capture_controller.Pass());
692 devices_.insert(new_device); 682 devices_.insert(new_device);
693 return new_device; 683 return new_device;
694 } 684 }
695 685
696 VideoCaptureManager::DeviceInfo* VideoCaptureManager::FindDeviceInfoById( 686 media::VideoCaptureDeviceInfo* VideoCaptureManager::FindDeviceInfoById(
697 const std::string& id, 687 const std::string& id,
698 DeviceInfos& device_vector) { 688 media::VideoCaptureDeviceInfos& device_vector) {
699 for (DeviceInfos::iterator it = device_vector.begin(); 689 for (auto& it : device_vector) {
700 it != device_vector.end(); ++it) { 690 if (it.name.id() == id)
701 if (it->name.id() == id) 691 return &(it);
702 return &(*it);
703 } 692 }
704 return NULL; 693 return NULL;
705 } 694 }
706 695
707 void VideoCaptureManager::SetDesktopCaptureWindowIdOnDeviceThread( 696 void VideoCaptureManager::SetDesktopCaptureWindowIdOnDeviceThread(
708 DeviceEntry* entry, 697 DeviceEntry* entry,
709 gfx::NativeViewId window_id) { 698 gfx::NativeViewId window_id) {
710 DCHECK(IsOnDeviceThread()); 699 DCHECK(IsOnDeviceThread());
711 DCHECK(entry->stream_type == MEDIA_DESKTOP_VIDEO_CAPTURE); 700 DCHECK(entry->stream_type == MEDIA_DESKTOP_VIDEO_CAPTURE);
712 #if defined(ENABLE_SCREEN_CAPTURE) 701 #if defined(ENABLE_SCREEN_CAPTURE)
713 DesktopCaptureDevice* device = 702 DesktopCaptureDevice* device =
714 static_cast<DesktopCaptureDevice*>(entry->video_capture_device.get()); 703 static_cast<DesktopCaptureDevice*>(entry->video_capture_device.get());
715 device->SetNotificationWindowId(window_id); 704 device->SetNotificationWindowId(window_id);
716 VLOG(2) << "Screen capture notification window passed on device thread."; 705 VLOG(2) << "Screen capture notification window passed on device thread.";
717 #endif 706 #endif
718 } 707 }
719 708
720 void VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread( 709 void VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread(
721 media::VideoCaptureSessionId session_id, 710 media::VideoCaptureSessionId session_id,
722 gfx::NativeViewId window_id) { 711 gfx::NativeViewId window_id) {
723 DCHECK(IsOnDeviceThread()); 712 DCHECK(IsOnDeviceThread());
724 DCHECK(notification_window_ids_.find(session_id) == 713 DCHECK(notification_window_ids_.find(session_id) ==
725 notification_window_ids_.end()); 714 notification_window_ids_.end());
726 notification_window_ids_[session_id] = window_id; 715 notification_window_ids_[session_id] = window_id;
727 VLOG(2) << "Screen capture notification window saved for session " 716 VLOG(2) << "Screen capture notification window saved for session "
728 << session_id << " on device thread."; 717 << session_id << " on device thread.";
729 } 718 }
730 719
731 } // namespace content 720 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/video_capture_manager.h ('k') | content/browser/resources/media/main.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698