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

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

Issue 183743021: Implement MediaCaptureDevices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: try again Created 6 years, 9 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
OLDNEW
(Empty)
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.
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 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
57 UpdateAudioDevicesOnUIThread(devices);
58 } else {
59 BrowserThread::PostTask(
60 BrowserThread::UI, FROM_HERE,
61 base::Bind(&MediaCaptureDevicesImpl::UpdateAudioDevicesOnUIThread,
62 base::Unretained(this), devices));
63 }
64 }
65
66 void MediaCaptureDevicesImpl::OnVideoCaptureDevicesChanged(
67 const MediaStreamDevices& devices) {
68 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
69 UpdateVideoDevicesOnUIThread(devices);
70 } else {
71 BrowserThread::PostTask(
72 BrowserThread::UI, FROM_HERE,
73 base::Bind(&MediaCaptureDevicesImpl::UpdateVideoDevicesOnUIThread,
74 base::Unretained(this), devices));
75 }
76 }
77
78 MediaCaptureDevicesImpl::MediaCaptureDevicesImpl()
79 : devices_enumerated_(false) {
80 }
81
82 MediaCaptureDevicesImpl::~MediaCaptureDevicesImpl() {
83 }
84
85 void MediaCaptureDevicesImpl::UpdateAudioDevicesOnUIThread(
86 const MediaStreamDevices& devices) {
87 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
88 devices_enumerated_ = true;
89 audio_devices_ = devices;
90 }
91
92 void MediaCaptureDevicesImpl::UpdateVideoDevicesOnUIThread(
93 const MediaStreamDevices& devices) {
94 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
95 devices_enumerated_ = true;
96 video_devices_ = devices;
97 }
98
99 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698