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

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: perkj@s comments 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_) {
wolenetz 2014/10/09 20:51:43 nit: ditto auto&
mcasas 2014/10/10 11:30:42 Done.
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 (media::VideoCaptureDeviceInfos::const_iterator it_device_info =
wolenetz 2014/10/09 20:51:43 nit: is this outer for-loop a candidate for const
mcasas 2014/10/10 11:30:42 Done.
589 old_device_info_cache.begin(); 585 old_device_info_cache.begin();
590 it_device_info != old_device_info_cache.end(); ++it_device_info) { 586 it_device_info != old_device_info_cache.end(); ++it_device_info) {
591 for (media::VideoCaptureDevice::Names::iterator it = 587 for (media::VideoCaptureDevice::Names::iterator it =
592 names_snapshot->begin(); 588 names_snapshot->begin();
593 it != names_snapshot->end(); ++it) { 589 it != names_snapshot->end(); ++it) {
594 if (it_device_info->name.id() == it->id()) { 590 if (it_device_info->name.id() == it->id()) {
595 new_devices_info_cache.push_back(*it_device_info); 591 new_devices_info_cache.push_back(*it_device_info);
596 names_snapshot->erase(it); 592 names_snapshot->erase(it);
597 break; 593 break;
598 } 594 }
599 } 595 }
600 } 596 }
601 597
602 // Get the supported capture formats for the new devices in |names_snapshot|. 598 // Get the supported capture formats for the new devices in |names_snapshot|.
603 for (media::VideoCaptureDevice::Names::const_iterator it = 599 for (media::VideoCaptureDevice::Names::const_iterator it =
604 names_snapshot->begin(); 600 names_snapshot->begin();
605 it != names_snapshot->end(); ++it) { 601 it != names_snapshot->end(); ++it) {
606 media::VideoCaptureFormats supported_formats; 602 media::VideoCaptureDeviceInfo device_info(*it,
607 DeviceInfo device_info(*it, media::VideoCaptureFormats()); 603 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
617 VideoCaptureManager::DeviceEntry* 613 VideoCaptureManager::DeviceEntry*
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 kMaxNumberOfBuffersForTabCapture : kMaxNumberOfBuffers; 682 kMaxNumberOfBuffersForTabCapture : kMaxNumberOfBuffers;
687 scoped_ptr<VideoCaptureController> video_capture_controller( 683 scoped_ptr<VideoCaptureController> video_capture_controller(
688 new VideoCaptureController(max_buffers)); 684 new VideoCaptureController(max_buffers));
689 DeviceEntry* new_device = new DeviceEntry(device_info.type, 685 DeviceEntry* new_device = new DeviceEntry(device_info.type,
690 device_info.id, 686 device_info.id,
691 video_capture_controller.Pass()); 687 video_capture_controller.Pass());
692 devices_.insert(new_device); 688 devices_.insert(new_device);
693 return new_device; 689 return new_device;
694 } 690 }
695 691
696 VideoCaptureManager::DeviceInfo* VideoCaptureManager::FindDeviceInfoById( 692 media::VideoCaptureDeviceInfo* VideoCaptureManager::FindDeviceInfoById(
697 const std::string& id, 693 const std::string& id,
698 DeviceInfos& device_vector) { 694 media::VideoCaptureDeviceInfos& device_vector) {
699 for (DeviceInfos::iterator it = device_vector.begin(); 695 for (media::VideoCaptureDeviceInfos::iterator it = device_vector.begin();
700 it != device_vector.end(); ++it) { 696 it != device_vector.end(); ++it) {
701 if (it->name.id() == id) 697 if (it->name.id() == id)
702 return &(*it); 698 return &(*it);
703 } 699 }
704 return NULL; 700 return NULL;
705 } 701 }
706 702
707 void VideoCaptureManager::SetDesktopCaptureWindowIdOnDeviceThread( 703 void VideoCaptureManager::SetDesktopCaptureWindowIdOnDeviceThread(
708 DeviceEntry* entry, 704 DeviceEntry* entry,
709 gfx::NativeViewId window_id) { 705 gfx::NativeViewId window_id) {
(...skipping 12 matching lines...) Expand all
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698