1 // Copyright 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.
5 #include "content/browser/renderer_host/media/media_capture_devices_impl.h"
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"
15 void EnsureMonitorCaptureDevices() {
16 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
17 BrowserThread::PostTask(
18 BrowserThread::IO
, FROM_HERE
,
19 base::Bind(&MediaStreamManager::EnsureDeviceMonitorStarted
,
21 BrowserMainLoop::GetInstance()->media_stream_manager())));
26 MediaCaptureDevices
* MediaCaptureDevices::GetInstance() {
27 return MediaCaptureDevicesImpl::GetInstance();
30 MediaCaptureDevicesImpl
* MediaCaptureDevicesImpl::GetInstance() {
31 return Singleton
<MediaCaptureDevicesImpl
>::get();
34 const MediaStreamDevices
&
35 MediaCaptureDevicesImpl::GetAudioCaptureDevices() {
36 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
37 if (!devices_enumerated_
) {
38 EnsureMonitorCaptureDevices();
39 devices_enumerated_
= true;
41 return audio_devices_
;
44 const MediaStreamDevices
&
45 MediaCaptureDevicesImpl::GetVideoCaptureDevices() {
46 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
47 if (!devices_enumerated_
) {
48 EnsureMonitorCaptureDevices();
49 devices_enumerated_
= true;
51 return video_devices_
;
54 void MediaCaptureDevicesImpl::OnAudioCaptureDevicesChanged(
55 const MediaStreamDevices
& devices
) {
56 if (BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
57 UpdateAudioDevicesOnUIThread(devices
);
59 BrowserThread::PostTask(
60 BrowserThread::UI
, FROM_HERE
,
61 base::Bind(&MediaCaptureDevicesImpl::UpdateAudioDevicesOnUIThread
,
62 base::Unretained(this), devices
));
66 void MediaCaptureDevicesImpl::OnVideoCaptureDevicesChanged(
67 const MediaStreamDevices
& devices
) {
68 if (BrowserThread::CurrentlyOn(BrowserThread::UI
)) {
69 UpdateVideoDevicesOnUIThread(devices
);
71 BrowserThread::PostTask(
72 BrowserThread::UI
, FROM_HERE
,
73 base::Bind(&MediaCaptureDevicesImpl::UpdateVideoDevicesOnUIThread
,
74 base::Unretained(this), devices
));
78 MediaCaptureDevicesImpl::MediaCaptureDevicesImpl()
79 : devices_enumerated_(false) {
82 MediaCaptureDevicesImpl::~MediaCaptureDevicesImpl() {
85 void MediaCaptureDevicesImpl::UpdateAudioDevicesOnUIThread(
86 const MediaStreamDevices
& devices
) {
87 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
88 devices_enumerated_
= true;
89 audio_devices_
= devices
;
92 void MediaCaptureDevicesImpl::UpdateVideoDevicesOnUIThread(
93 const MediaStreamDevices
& devices
) {
94 DCHECK_CURRENTLY_ON(BrowserThread::UI
);
95 devices_enumerated_
= true;
96 video_devices_
= devices
;
99 } // namespace content