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

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

Issue 235353002: Extract VideoCaptureDeviceFactory out of VideoCaptureDevice and use for File and FakeVCD. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: perkj@ nit Created 6 years, 8 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 | Annotate | Revision Log
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/command_line.h"
11 #include "base/logging.h" 10 #include "base/logging.h"
12 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
13 #include "base/stl_util.h" 12 #include "base/stl_util.h"
14 #include "base/task_runner_util.h" 13 #include "base/task_runner_util.h"
15 #include "base/threading/sequenced_worker_pool.h" 14 #include "base/threading/sequenced_worker_pool.h"
16 #include "content/browser/media/capture/web_contents_video_capture_device.h" 15 #include "content/browser/media/capture/web_contents_video_capture_device.h"
17 #include "content/browser/renderer_host/media/video_capture_controller.h" 16 #include "content/browser/renderer_host/media/video_capture_controller.h"
18 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h" 17 #include "content/browser/renderer_host/media/video_capture_controller_event_han dler.h"
19 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
20 #include "content/public/browser/desktop_media_id.h" 19 #include "content/public/browser/desktop_media_id.h"
21 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
22 #include "content/public/common/media_stream_request.h" 21 #include "content/public/common/media_stream_request.h"
23 #include "media/base/media_switches.h"
24 #include "media/base/scoped_histogram_timer.h" 22 #include "media/base/scoped_histogram_timer.h"
25 #include "media/video/capture/fake_video_capture_device.h"
26 #include "media/video/capture/file_video_capture_device.h"
27 #include "media/video/capture/video_capture_device.h" 23 #include "media/video/capture/video_capture_device.h"
24 #include "media/video/capture/video_capture_device_factory.h"
28 25
29 #if defined(ENABLE_SCREEN_CAPTURE) 26 #if defined(ENABLE_SCREEN_CAPTURE)
30 #include "content/browser/media/capture/desktop_capture_device.h" 27 #include "content/browser/media/capture/desktop_capture_device.h"
31 #if defined(USE_AURA) 28 #if defined(USE_AURA)
32 #include "content/browser/media/capture/desktop_capture_device_aura.h" 29 #include "content/browser/media/capture/desktop_capture_device_aura.h"
33 #endif 30 #endif
34 #endif 31 #endif
35 32
36 namespace { 33 namespace {
37 34
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 VideoCaptureManager::DeviceInfo::DeviceInfo() {} 85 VideoCaptureManager::DeviceInfo::DeviceInfo() {}
89 86
90 VideoCaptureManager::DeviceInfo::DeviceInfo( 87 VideoCaptureManager::DeviceInfo::DeviceInfo(
91 const media::VideoCaptureDevice::Name& name, 88 const media::VideoCaptureDevice::Name& name,
92 const media::VideoCaptureFormats& supported_formats) 89 const media::VideoCaptureFormats& supported_formats)
93 : name(name), 90 : name(name),
94 supported_formats(supported_formats) {} 91 supported_formats(supported_formats) {}
95 92
96 VideoCaptureManager::DeviceInfo::~DeviceInfo() {} 93 VideoCaptureManager::DeviceInfo::~DeviceInfo() {}
97 94
98 VideoCaptureManager::VideoCaptureManager() 95 VideoCaptureManager::VideoCaptureManager(
96 scoped_ptr<media::VideoCaptureDeviceFactory> factory)
99 : listener_(NULL), 97 : listener_(NULL),
100 new_capture_session_id_(1), 98 new_capture_session_id_(1),
101 artificial_device_source_for_testing_(DISABLED) { 99 video_capture_device_factory_(factory.Pass()) {
102 } 100 }
103 101
104 VideoCaptureManager::~VideoCaptureManager() { 102 VideoCaptureManager::~VideoCaptureManager() {
105 DCHECK(devices_.empty()); 103 DCHECK(devices_.empty());
106 } 104 }
107 105
108 void VideoCaptureManager::Register( 106 void VideoCaptureManager::Register(
109 MediaStreamProviderListener* listener, 107 MediaStreamProviderListener* listener,
110 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) { 108 const scoped_refptr<base::SingleThreadTaskRunner>& device_task_runner) {
111 DCHECK_CURRENTLY_ON(BrowserThread::IO); 109 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 DestroyDeviceEntryIfNoClients(existing_device); 177 DestroyDeviceEntryIfNoClients(existing_device);
180 } 178 }
181 179
182 // Notify listeners asynchronously, and forget the session. 180 // Notify listeners asynchronously, and forget the session.
183 base::MessageLoop::current()->PostTask(FROM_HERE, 181 base::MessageLoop::current()->PostTask(FROM_HERE,
184 base::Bind(&VideoCaptureManager::OnClosed, this, session_it->second.type, 182 base::Bind(&VideoCaptureManager::OnClosed, this, session_it->second.type,
185 capture_session_id)); 183 capture_session_id));
186 sessions_.erase(session_it); 184 sessions_.erase(session_it);
187 } 185 }
188 186
189 void VideoCaptureManager::UseFakeDevice() {
190 if (CommandLine::ForCurrentProcess()->HasSwitch(
191 switches::kUseFileForFakeVideoCapture)) {
192 artificial_device_source_for_testing_ = Y4M_FILE;
193 } else {
194 artificial_device_source_for_testing_ = TEST_PATTERN;
195 }
196 }
197
198 void VideoCaptureManager::DoStartDeviceOnDeviceThread( 187 void VideoCaptureManager::DoStartDeviceOnDeviceThread(
199 media::VideoCaptureSessionId session_id, 188 media::VideoCaptureSessionId session_id,
200 DeviceEntry* entry, 189 DeviceEntry* entry,
201 const media::VideoCaptureParams& params, 190 const media::VideoCaptureParams& params,
202 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { 191 scoped_ptr<media::VideoCaptureDevice::Client> device_client) {
203 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); 192 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime");
204 DCHECK(IsOnDeviceThread()); 193 DCHECK(IsOnDeviceThread());
205 194
206 scoped_ptr<media::VideoCaptureDevice> video_capture_device; 195 scoped_ptr<media::VideoCaptureDevice> video_capture_device;
207 switch (entry->stream_type) { 196 switch (entry->stream_type) {
208 case MEDIA_DEVICE_VIDEO_CAPTURE: { 197 case MEDIA_DEVICE_VIDEO_CAPTURE: {
209 // We look up the device id from the renderer in our local enumeration 198 // We look up the device id from the renderer in our local enumeration
210 // since the renderer does not have all the information that might be 199 // since the renderer does not have all the information that might be
211 // held in the browser-side VideoCaptureDevice::Name structure. 200 // held in the browser-side VideoCaptureDevice::Name structure.
212 DeviceInfo* found = FindDeviceInfoById(entry->id, devices_info_cache_); 201 DeviceInfo* found = FindDeviceInfoById(entry->id, devices_info_cache_);
213 if (found) { 202 if (found) {
214 switch (artificial_device_source_for_testing_) { 203 video_capture_device =
215 case DISABLED: 204 video_capture_device_factory_->Create(found->name);
216 video_capture_device.reset(
217 media::VideoCaptureDevice::Create(found->name));
218 break;
219 case TEST_PATTERN:
220 video_capture_device.reset(
221 media::FakeVideoCaptureDevice::Create(found->name));
222 break;
223 case Y4M_FILE:
224 video_capture_device.reset(
225 media::FileVideoCaptureDevice::Create(found->name));
226 break;
227 }
228 } 205 }
229 break; 206 break;
230 } 207 }
231 case MEDIA_TAB_VIDEO_CAPTURE: { 208 case MEDIA_TAB_VIDEO_CAPTURE: {
232 video_capture_device.reset( 209 video_capture_device.reset(
233 WebContentsVideoCaptureDevice::Create(entry->id)); 210 WebContentsVideoCaptureDevice::Create(entry->id));
234 break; 211 break;
235 } 212 }
236 case MEDIA_DESKTOP_VIDEO_CAPTURE: { 213 case MEDIA_DESKTOP_VIDEO_CAPTURE: {
237 #if defined(ENABLE_SCREEN_CAPTURE) 214 #if defined(ENABLE_SCREEN_CAPTURE)
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 const DeviceInfos& old_device_info_cache) { 453 const DeviceInfos& old_device_info_cache) {
477 SCOPED_UMA_HISTOGRAM_TIMER( 454 SCOPED_UMA_HISTOGRAM_TIMER(
478 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime"); 455 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime");
479 DCHECK(IsOnDeviceThread()); 456 DCHECK(IsOnDeviceThread());
480 media::VideoCaptureDevice::Names names_snapshot; 457 media::VideoCaptureDevice::Names names_snapshot;
481 switch (stream_type) { 458 switch (stream_type) {
482 case MEDIA_DEVICE_VIDEO_CAPTURE: 459 case MEDIA_DEVICE_VIDEO_CAPTURE:
483 // Cache the latest enumeration of video capture devices. 460 // Cache the latest enumeration of video capture devices.
484 // We'll refer to this list again in OnOpen to avoid having to 461 // We'll refer to this list again in OnOpen to avoid having to
485 // enumerate the devices again. 462 // enumerate the devices again.
486 switch (artificial_device_source_for_testing_) { 463 video_capture_device_factory_->GetDeviceNames(&names_snapshot);
487 case DISABLED:
488 media::VideoCaptureDevice::GetDeviceNames(&names_snapshot);
489 break;
490 case TEST_PATTERN:
491 media::FakeVideoCaptureDevice::GetDeviceNames(&names_snapshot);
492 break;
493 case Y4M_FILE:
494 media::FileVideoCaptureDevice::GetDeviceNames(&names_snapshot);
495 break;
496 }
497 break; 464 break;
498
499 case MEDIA_DESKTOP_VIDEO_CAPTURE: 465 case MEDIA_DESKTOP_VIDEO_CAPTURE:
500 // Do nothing. 466 // Do nothing.
501 break; 467 break;
502
503 default: 468 default:
504 NOTREACHED(); 469 NOTREACHED();
505 break; 470 break;
506 } 471 }
507 472
508 // Construct |new_devices_info_cache| with the cached devices that are still 473 // Construct |new_devices_info_cache| with the cached devices that are still
509 // present in the system, and remove their names from |names_snapshot|, so we 474 // present in the system, and remove their names from |names_snapshot|, so we
510 // keep there the truly new devices. 475 // keep there the truly new devices.
511 DeviceInfos new_devices_info_cache; 476 DeviceInfos new_devices_info_cache;
512 for (DeviceInfos::const_iterator it_device_info = 477 for (DeviceInfos::const_iterator it_device_info =
513 old_device_info_cache.begin(); 478 old_device_info_cache.begin();
514 it_device_info != old_device_info_cache.end(); ++it_device_info) { 479 it_device_info != old_device_info_cache.end(); ++it_device_info) {
515 for (media::VideoCaptureDevice::Names::iterator it = 480 for (media::VideoCaptureDevice::Names::iterator it =
516 names_snapshot.begin(); 481 names_snapshot.begin();
517 it != names_snapshot.end(); ++it) { 482 it != names_snapshot.end(); ++it) {
518 if (it_device_info->name.id() == it->id()) { 483 if (it_device_info->name.id() == it->id()) {
519 new_devices_info_cache.push_back(*it_device_info); 484 new_devices_info_cache.push_back(*it_device_info);
520 names_snapshot.erase(it); 485 names_snapshot.erase(it);
521 break; 486 break;
522 } 487 }
523 } 488 }
524 } 489 }
525 490
526 // Get the supported capture formats for the new devices in |names_snapshot|. 491 // Get the supported capture formats for the new devices in |names_snapshot|.
527 for (media::VideoCaptureDevice::Names::const_iterator it = 492 for (media::VideoCaptureDevice::Names::const_iterator it =
528 names_snapshot.begin(); 493 names_snapshot.begin();
529 it != names_snapshot.end(); ++it) { 494 it != names_snapshot.end(); ++it) {
530 media::VideoCaptureFormats supported_formats; 495 media::VideoCaptureFormats supported_formats;
531 DeviceInfo device_info(*it, media::VideoCaptureFormats()); 496 DeviceInfo device_info(*it, media::VideoCaptureFormats());
532 switch (artificial_device_source_for_testing_) { 497 video_capture_device_factory_->GetDeviceSupportedFormats(
533 case DISABLED: 498 *it, &(device_info.supported_formats));
534 media::VideoCaptureDevice::GetDeviceSupportedFormats(
535 *it, &(device_info.supported_formats));
536 break;
537 case TEST_PATTERN:
538 media::FakeVideoCaptureDevice::GetDeviceSupportedFormats(
539 *it, &(device_info.supported_formats));
540 break;
541 case Y4M_FILE:
542 media::FileVideoCaptureDevice::GetDeviceSupportedFormats(
543 *it, &(device_info.supported_formats));
544 break;
545 }
546 ConsolidateCaptureFormats(&device_info.supported_formats); 499 ConsolidateCaptureFormats(&device_info.supported_formats);
547 new_devices_info_cache.push_back(device_info); 500 new_devices_info_cache.push_back(device_info);
548 } 501 }
549 return new_devices_info_cache; 502 return new_devices_info_cache;
550 } 503 }
551 504
552 VideoCaptureManager::DeviceEntry* 505 VideoCaptureManager::DeviceEntry*
553 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( 506 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice(
554 const MediaStreamDevice& device_info) { 507 const MediaStreamDevice& device_info) {
555 DCHECK_CURRENTLY_ON(BrowserThread::IO); 508 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 void VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread( 606 void VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread(
654 media::VideoCaptureSessionId session_id, 607 media::VideoCaptureSessionId session_id,
655 gfx::NativeViewId window_id) { 608 gfx::NativeViewId window_id) {
656 DCHECK(IsOnDeviceThread()); 609 DCHECK(IsOnDeviceThread());
657 DCHECK(notification_window_ids_.find(session_id) == 610 DCHECK(notification_window_ids_.find(session_id) ==
658 notification_window_ids_.end()); 611 notification_window_ids_.end());
659 notification_window_ids_[session_id] = window_id; 612 notification_window_ids_[session_id] = window_id;
660 } 613 }
661 614
662 } // namespace content 615 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698