OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/renderer_host/media/media_capture_devices_impl.h" |
| 6 |
| 7 #include "content/browser/browser_main_loop.h" |
| 8 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 9 #include "content/public/browser/browser_thread.h" |
| 10 |
| 11 namespace content { |
| 12 |
| 13 namespace { |
| 14 |
| 15 void EnsureMonitorCaptureDevices() { |
| 16 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 17 BrowserThread::PostTask( |
| 18 BrowserThread::IO, FROM_HERE, |
| 19 base::Bind(&MediaStreamManager::EnsureDeviceMonitorStarted, |
| 20 base::Unretained( |
| 21 BrowserMainLoop::GetInstance()->media_stream_manager()))); |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
| 26 MediaCaptureDevices* MediaCaptureDevices::GetInstance() { |
| 27 return MediaCaptureDevicesImpl::GetInstance(); |
| 28 } |
| 29 |
| 30 MediaCaptureDevicesImpl* MediaCaptureDevicesImpl::GetInstance() { |
| 31 return Singleton<MediaCaptureDevicesImpl>::get(); |
| 32 } |
| 33 |
| 34 const MediaStreamDevices& |
| 35 MediaCaptureDevicesImpl::GetAudioCaptureDevices() { |
| 36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 37 if (!devices_enumerated_) { |
| 38 EnsureMonitorCaptureDevices(); |
| 39 devices_enumerated_ = true; |
| 40 } |
| 41 return audio_devices_; |
| 42 } |
| 43 |
| 44 const MediaStreamDevices& |
| 45 MediaCaptureDevicesImpl::GetVideoCaptureDevices() { |
| 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 47 if (!devices_enumerated_) { |
| 48 EnsureMonitorCaptureDevices(); |
| 49 devices_enumerated_ = true; |
| 50 } |
| 51 return video_devices_; |
| 52 } |
| 53 |
| 54 void MediaCaptureDevicesImpl::OnAudioCaptureDevicesChanged( |
| 55 const MediaStreamDevices& devices) { |
| 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 57 BrowserThread::PostTask( |
| 58 BrowserThread::UI, FROM_HERE, |
| 59 base::Bind(&MediaCaptureDevicesImpl::UpdateAudioDevicesOnUIThread, |
| 60 base::Unretained(this), devices)); |
| 61 } |
| 62 |
| 63 void MediaCaptureDevicesImpl::OnVideoCaptureDevicesChanged( |
| 64 const MediaStreamDevices& devices) { |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 66 BrowserThread::PostTask( |
| 67 BrowserThread::UI, FROM_HERE, |
| 68 base::Bind(&MediaCaptureDevicesImpl::UpdateVideoDevicesOnUIThread, |
| 69 base::Unretained(this), devices)); |
| 70 } |
| 71 |
| 72 MediaCaptureDevicesImpl::MediaCaptureDevicesImpl() |
| 73 : devices_enumerated_(false) { |
| 74 } |
| 75 |
| 76 MediaCaptureDevicesImpl::~MediaCaptureDevicesImpl() { |
| 77 } |
| 78 |
| 79 void MediaCaptureDevicesImpl::UpdateAudioDevicesOnUIThread( |
| 80 const MediaStreamDevices& devices) { |
| 81 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 82 devices_enumerated_ = true; |
| 83 audio_devices_ = devices; |
| 84 } |
| 85 |
| 86 void MediaCaptureDevicesImpl::UpdateVideoDevicesOnUIThread( |
| 87 const MediaStreamDevices& devices) { |
| 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 89 devices_enumerated_ = true; |
| 90 video_devices_ = devices; |
| 91 } |
| 92 |
| 93 } // namespace content |
OLD | NEW |