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 <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" | 23 #include "media/video/capture/fake_video_capture_device_factory.h" |
perkj_chrome
2014/04/15 09:34:01
You should not need these includes here.
mcasas
2014/04/15 13:47:09
Done.
| |
26 #include "media/video/capture/file_video_capture_device.h" | 24 #include "media/video/capture/file_video_capture_device_factory.h" |
27 #include "media/video/capture/video_capture_device.h" | 25 #include "media/video/capture/video_capture_device.h" |
28 | 26 |
29 #if defined(ENABLE_SCREEN_CAPTURE) | 27 #if defined(ENABLE_SCREEN_CAPTURE) |
30 #include "content/browser/media/capture/desktop_capture_device.h" | 28 #include "content/browser/media/capture/desktop_capture_device.h" |
31 #if defined(USE_AURA) | 29 #if defined(USE_AURA) |
32 #include "content/browser/media/capture/desktop_capture_device_aura.h" | 30 #include "content/browser/media/capture/desktop_capture_device_aura.h" |
33 #endif | 31 #endif |
34 #endif | 32 #endif |
35 | 33 |
36 namespace { | 34 namespace { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 const media::VideoCaptureDevice::Name& name, | 89 const media::VideoCaptureDevice::Name& name, |
92 const media::VideoCaptureFormats& supported_formats) | 90 const media::VideoCaptureFormats& supported_formats) |
93 : name(name), | 91 : name(name), |
94 supported_formats(supported_formats) {} | 92 supported_formats(supported_formats) {} |
95 | 93 |
96 VideoCaptureManager::DeviceInfo::~DeviceInfo() {} | 94 VideoCaptureManager::DeviceInfo::~DeviceInfo() {} |
97 | 95 |
98 VideoCaptureManager::VideoCaptureManager() | 96 VideoCaptureManager::VideoCaptureManager() |
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 use_testing_device_source_(false) { |
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 Loading... | |
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 use_testing_device_source_ = true; |
192 artificial_device_source_for_testing_ = Y4M_FILE; | 190 video_capture_device_factory_ = factory.Pass(); |
193 } else { | |
194 artificial_device_source_for_testing_ = TEST_PATTERN; | |
195 } | |
196 } | 191 } |
197 | 192 |
198 void VideoCaptureManager::DoStartDeviceOnDeviceThread( | 193 void VideoCaptureManager::DoStartDeviceOnDeviceThread( |
199 media::VideoCaptureSessionId session_id, | 194 media::VideoCaptureSessionId session_id, |
200 DeviceEntry* entry, | 195 DeviceEntry* entry, |
201 const media::VideoCaptureParams& params, | 196 const media::VideoCaptureParams& params, |
202 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { | 197 scoped_ptr<media::VideoCaptureDevice::Client> device_client) { |
203 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); | 198 SCOPED_UMA_HISTOGRAM_TIMER("Media.VideoCaptureManager.StartDeviceTime"); |
204 DCHECK(IsOnDeviceThread()); | 199 DCHECK(IsOnDeviceThread()); |
perkj_chrome
2014/04/15 09:34:01
This is not the IO thread right?
mcasas
2014/04/15 13:47:09
No, is a different one, Device thread, also known
| |
205 | 200 |
206 scoped_ptr<media::VideoCaptureDevice> video_capture_device; | 201 scoped_ptr<media::VideoCaptureDevice> video_capture_device; |
207 switch (entry->stream_type) { | 202 switch (entry->stream_type) { |
208 case MEDIA_DEVICE_VIDEO_CAPTURE: { | 203 case MEDIA_DEVICE_VIDEO_CAPTURE: { |
209 // We look up the device id from the renderer in our local enumeration | 204 // 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 | 205 // since the renderer does not have all the information that might be |
211 // held in the browser-side VideoCaptureDevice::Name structure. | 206 // held in the browser-side VideoCaptureDevice::Name structure. |
212 DeviceInfo* found = FindDeviceInfoById(entry->id, devices_info_cache_); | 207 DeviceInfo* found = FindDeviceInfoById(entry->id, devices_info_cache_); |
213 if (found) { | 208 if (found) { |
214 switch (artificial_device_source_for_testing_) { | 209 if (!use_testing_device_source_) { |
perkj_chrome
2014/04/15 09:34:01
This is ugly. Always use a device factory but have
mcasas
2014/04/15 13:47:09
Done.
| |
215 case DISABLED: | 210 video_capture_device.reset( |
216 video_capture_device.reset( | 211 media::VideoCaptureDevice::Create(found->name)); |
217 media::VideoCaptureDevice::Create(found->name)); | 212 } else { |
218 break; | 213 video_capture_device.reset( |
219 case TEST_PATTERN: | 214 video_capture_device_factory_->Create(found->name)); |
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 } | 215 } |
228 } | 216 } |
229 break; | 217 break; |
230 } | 218 } |
231 case MEDIA_TAB_VIDEO_CAPTURE: { | 219 case MEDIA_TAB_VIDEO_CAPTURE: { |
232 video_capture_device.reset( | 220 video_capture_device.reset( |
233 WebContentsVideoCaptureDevice::Create(entry->id)); | 221 WebContentsVideoCaptureDevice::Create(entry->id)); |
234 break; | 222 break; |
235 } | 223 } |
236 case MEDIA_DESKTOP_VIDEO_CAPTURE: { | 224 case MEDIA_DESKTOP_VIDEO_CAPTURE: { |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 const DeviceInfos& old_device_info_cache) { | 464 const DeviceInfos& old_device_info_cache) { |
477 SCOPED_UMA_HISTOGRAM_TIMER( | 465 SCOPED_UMA_HISTOGRAM_TIMER( |
478 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime"); | 466 "Media.VideoCaptureManager.GetAvailableDevicesInfoOnDeviceThreadTime"); |
479 DCHECK(IsOnDeviceThread()); | 467 DCHECK(IsOnDeviceThread()); |
480 media::VideoCaptureDevice::Names names_snapshot; | 468 media::VideoCaptureDevice::Names names_snapshot; |
481 switch (stream_type) { | 469 switch (stream_type) { |
482 case MEDIA_DEVICE_VIDEO_CAPTURE: | 470 case MEDIA_DEVICE_VIDEO_CAPTURE: |
483 // Cache the latest enumeration of video capture devices. | 471 // Cache the latest enumeration of video capture devices. |
484 // We'll refer to this list again in OnOpen to avoid having to | 472 // We'll refer to this list again in OnOpen to avoid having to |
485 // enumerate the devices again. | 473 // enumerate the devices again. |
486 switch (artificial_device_source_for_testing_) { | 474 if (!use_testing_device_source_) |
perkj_chrome
2014/04/15 09:34:01
dito
mcasas
2014/04/15 13:47:09
Done.
| |
487 case DISABLED: | 475 media::VideoCaptureDevice::GetDeviceNames(&names_snapshot); |
488 media::VideoCaptureDevice::GetDeviceNames(&names_snapshot); | 476 else |
489 break; | 477 video_capture_device_factory_->GetDeviceNames(&names_snapshot); |
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; | 478 break; |
498 | 479 |
499 case MEDIA_DESKTOP_VIDEO_CAPTURE: | 480 case MEDIA_DESKTOP_VIDEO_CAPTURE: |
500 // Do nothing. | 481 // Do nothing. |
501 break; | 482 break; |
502 | 483 |
503 default: | 484 default: |
504 NOTREACHED(); | 485 NOTREACHED(); |
505 break; | 486 break; |
506 } | 487 } |
(...skipping 15 matching lines...) Expand all Loading... | |
522 } | 503 } |
523 } | 504 } |
524 } | 505 } |
525 | 506 |
526 // Get the supported capture formats for the new devices in |names_snapshot|. | 507 // Get the supported capture formats for the new devices in |names_snapshot|. |
527 for (media::VideoCaptureDevice::Names::const_iterator it = | 508 for (media::VideoCaptureDevice::Names::const_iterator it = |
528 names_snapshot.begin(); | 509 names_snapshot.begin(); |
529 it != names_snapshot.end(); ++it) { | 510 it != names_snapshot.end(); ++it) { |
530 media::VideoCaptureFormats supported_formats; | 511 media::VideoCaptureFormats supported_formats; |
531 DeviceInfo device_info(*it, media::VideoCaptureFormats()); | 512 DeviceInfo device_info(*it, media::VideoCaptureFormats()); |
532 switch (artificial_device_source_for_testing_) { | 513 |
533 case DISABLED: | 514 if (!use_testing_device_source_) { |
534 media::VideoCaptureDevice::GetDeviceSupportedFormats( | 515 media::VideoCaptureDevice::GetDeviceSupportedFormats( |
535 *it, &(device_info.supported_formats)); | 516 *it, &(device_info.supported_formats)); |
536 break; | 517 } else { |
537 case TEST_PATTERN: | 518 video_capture_device_factory_->GetDeviceSupportedFormats( |
538 media::FakeVideoCaptureDevice::GetDeviceSupportedFormats( | 519 *it, &(device_info.supported_formats)); |
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 } | 520 } |
546 ConsolidateCaptureFormats(&device_info.supported_formats); | 521 ConsolidateCaptureFormats(&device_info.supported_formats); |
547 new_devices_info_cache.push_back(device_info); | 522 new_devices_info_cache.push_back(device_info); |
548 } | 523 } |
549 return new_devices_info_cache; | 524 return new_devices_info_cache; |
550 } | 525 } |
551 | 526 |
552 VideoCaptureManager::DeviceEntry* | 527 VideoCaptureManager::DeviceEntry* |
553 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( | 528 VideoCaptureManager::GetDeviceEntryForMediaStreamDevice( |
554 const MediaStreamDevice& device_info) { | 529 const MediaStreamDevice& device_info) { |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
653 void VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread( | 628 void VideoCaptureManager::SaveDesktopCaptureWindowIdOnDeviceThread( |
654 media::VideoCaptureSessionId session_id, | 629 media::VideoCaptureSessionId session_id, |
655 gfx::NativeViewId window_id) { | 630 gfx::NativeViewId window_id) { |
656 DCHECK(IsOnDeviceThread()); | 631 DCHECK(IsOnDeviceThread()); |
657 DCHECK(notification_window_ids_.find(session_id) == | 632 DCHECK(notification_window_ids_.find(session_id) == |
658 notification_window_ids_.end()); | 633 notification_window_ids_.end()); |
659 notification_window_ids_[session_id] = window_id; | 634 notification_window_ids_[session_id] = window_id; |
660 } | 635 } |
661 | 636 |
662 } // namespace content | 637 } // namespace content |
OLD | NEW |