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

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@s comments 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() { 187 void VideoCaptureManager::UseFakeDevice(
190 if (CommandLine::ForCurrentProcess()->HasSwitch( 188 scoped_ptr<media::VideoCaptureDeviceFactory> factory) {
191 switches::kUseFileForFakeVideoCapture)) { 189 video_capture_device_factory_.swap(factory);
192 artificial_device_source_for_testing_ = Y4M_FILE;
193 } else {
194 artificial_device_source_for_testing_ = TEST_PATTERN;
195 }
196 } 190 }
197 191
198 void VideoCaptureManager::DoStartDeviceOnDeviceThread( 192 void VideoCaptureManager::DoStartDeviceOnDeviceThread(
199 media::VideoCaptureSessionId session_id, 193 media::VideoCaptureSessionId session_id,
200 DeviceEntry* entry, 194 DeviceEntry* entry,
201 const media::VideoCaptureParams& params, 195 const media::VideoCaptureParams& params,
202 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { 196 scoped_ptr<media::VideoCaptureDevice::Client> device_client) {
203 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); 197 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime");
204 DCHECK(IsOnDeviceThread()); 198 DCHECK(IsOnDeviceThread());
205 199
206 scoped_ptr<media::VideoCaptureDevice> video_capture_device; 200 scoped_ptr<media::VideoCaptureDevice> video_capture_device;
207 switch (entry->stream_type) { 201 switch (entry->stream_type) {
208 case MEDIA_DEVICE_VIDEO_CAPTURE: { 202 case MEDIA_DEVICE_VIDEO_CAPTURE: {
209 // We look up the device id from the renderer in our local enumeration 203 // 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 204 // since the renderer does not have all the information that might be
211 // held in the browser-side VideoCaptureDevice::Name structure. 205 // held in the browser-side VideoCaptureDevice::Name structure.
212 DeviceInfo* found = FindDeviceInfoById(entry->id, devices_info_cache_); 206 DeviceInfo* found = FindDeviceInfoById(entry->id, devices_info_cache_);
213 if (found) { 207 if (found) {
214 switch (artificial_device_source_for_testing_) { 208 video_capture_device.reset(
215 case DISABLED: 209 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 } 210 }
229 break; 211 break;
230 } 212 }
231 case MEDIA_TAB_VIDEO_CAPTURE: { 213 case MEDIA_TAB_VIDEO_CAPTURE: {
232 video_capture_device.reset( 214 video_capture_device.reset(
233 WebContentsVideoCaptureDevice::Create(entry->id)); 215 WebContentsVideoCaptureDevice::Create(entry->id));
234 break; 216 break;
235 } 217 }
236 case MEDIA_DESKTOP_VIDEO_CAPTURE: { 218 case MEDIA_DESKTOP_VIDEO_CAPTURE: {
237 #if defined(ENABLE_SCREEN_CAPTURE) 219 #if defined(ENABLE_SCREEN_CAPTURE)
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 const DeviceInfos& old_device_info_cache) { 458 const DeviceInfos& old_device_info_cache) {
477 SCOPED_UMA_HISTOGRAM_TIMER( 459 SCOPED_UMA_HISTOGRAM_TIMER(
478 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime"); 460 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime");
479 DCHECK(IsOnDeviceThread()); 461 DCHECK(IsOnDeviceThread());
480 media::VideoCaptureDevice::Names names_snapshot; 462 media::VideoCaptureDevice::Names names_snapshot;
481 switch (stream_type) { 463 switch (stream_type) {
482 case MEDIA_DEVICE_VIDEO_CAPTURE: 464 case MEDIA_DEVICE_VIDEO_CAPTURE:
483 // Cache the latest enumeration of video capture devices. 465 // Cache the latest enumeration of video capture devices.
484 // We'll refer to this list again in OnOpen to avoid having to 466 // We'll refer to this list again in OnOpen to avoid having to
485 // enumerate the devices again. 467 // enumerate the devices again.
486 switch (artificial_device_source_for_testing_) { 468 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; 469 break;
498
499 case MEDIA_DESKTOP_VIDEO_CAPTURE: 470 case MEDIA_DESKTOP_VIDEO_CAPTURE:
500 // Do nothing. 471 // Do nothing.
501 break; 472 break;
502
503 default: 473 default:
504 NOTREACHED(); 474 NOTREACHED();
505 break; 475 break;
506 } 476 }
507 477
508 // Construct |new_devices_info_cache| with the cached devices that are still 478 // 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 479 // present in the system, and remove their names from |names_snapshot|, so we
510 // keep there the truly new devices. 480 // keep there the truly new devices.
511 DeviceInfos new_devices_info_cache; 481 DeviceInfos new_devices_info_cache;
512 for (DeviceInfos::const_iterator it_device_info = 482 for (DeviceInfos::const_iterator it_device_info =
513 old_device_info_cache.begin(); 483 old_device_info_cache.begin();
514 it_device_info != old_device_info_cache.end(); ++it_device_info) { 484 it_device_info != old_device_info_cache.end(); ++it_device_info) {
515 for (media::VideoCaptureDevice::Names::iterator it = 485 for (media::VideoCaptureDevice::Names::iterator it =
516 names_snapshot.begin(); 486 names_snapshot.begin();
517 it != names_snapshot.end(); ++it) { 487 it != names_snapshot.end(); ++it) {
518 if (it_device_info->name.id() == it->id()) { 488 if (it_device_info->name.id() == it->id()) {
519 new_devices_info_cache.push_back(*it_device_info); 489 new_devices_info_cache.push_back(*it_device_info);
520 names_snapshot.erase(it); 490 names_snapshot.erase(it);
521 break; 491 break;
522 } 492 }
523 } 493 }
524 } 494 }
525 495
526 // Get the supported capture formats for the new devices in |names_snapshot|. 496 // Get the supported capture formats for the new devices in |names_snapshot|.
527 for (media::VideoCaptureDevice::Names::const_iterator it = 497 for (media::VideoCaptureDevice::Names::const_iterator it =
528 names_snapshot.begin(); 498 names_snapshot.begin();
529 it != names_snapshot.end(); ++it) { 499 it != names_snapshot.end(); ++it) {
530 media::VideoCaptureFormats supported_formats; 500 media::VideoCaptureFormats supported_formats;
531 DeviceInfo device_info(*it, media::VideoCaptureFormats()); 501 DeviceInfo device_info(*it, media::VideoCaptureFormats());
532 switch (artificial_device_source_for_testing_) { 502 video_capture_device_factory_->GetDeviceSupportedFormats(
533 case DISABLED: 503 *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); 504 ConsolidateCaptureFormats(&device_info.supported_formats);
547 new_devices_info_cache.push_back(device_info); 505 new_devices_info_cache.push_back(device_info);
548 } 506 }
549 return new_devices_info_cache; 507 return new_devices_info_cache;
550 } 508 }
551 509
552 VideoCaptureManager::DeviceEntry* 510 VideoCaptureManager::DeviceEntry*
553 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( 511 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice(
554 const MediaStreamDevice& device_info) { 512 const MediaStreamDevice& device_info) {
555 DCHECK_CURRENTLY_ON(BrowserThread::IO); 513 DCHECK_CURRENTLY_ON(BrowserThread::IO);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 void VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread( 611 void VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread(
654 media::VideoCaptureSessionId session_id, 612 media::VideoCaptureSessionId session_id,
655 gfx::NativeViewId window_id) { 613 gfx::NativeViewId window_id) {
656 DCHECK(IsOnDeviceThread()); 614 DCHECK(IsOnDeviceThread());
657 DCHECK(notification_window_ids_.find(session_id) == 615 DCHECK(notification_window_ids_.find(session_id) ==
658 notification_window_ids_.end()); 616 notification_window_ids_.end());
659 notification_window_ids_[session_id] = window_id; 617 notification_window_ids_[session_id] = window_id;
660 } 618 }
661 619
662 } // namespace content 620 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698