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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/media/media_capture_devices_impl.cc
diff --git a/content/browser/renderer_host/media/media_capture_devices_impl.cc b/content/browser/renderer_host/media/media_capture_devices_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f4e13ab46709d50db10e3dedb486b54f4044b419
--- /dev/null
+++ b/content/browser/renderer_host/media/media_capture_devices_impl.cc
@@ -0,0 +1,99 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/renderer_host/media/media_capture_devices_impl.h"
+
+#include "content/browser/browser_main_loop.h"
+#include "content/browser/renderer_host/media/media_stream_manager.h"
+#include "content/public/browser/browser_thread.h"
+
+namespace content {
+
+namespace {
+
+void EnsureMonitorCaptureDevices() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ BrowserThread::PostTask(
+ BrowserThread::IO, FROM_HERE,
+ base::Bind(&MediaStreamManager::EnsureDeviceMonitorStarted,
+ base::Unretained(
+ BrowserMainLoop::GetInstance()->media_stream_manager())));
+}
+
+} // namespace
+
+MediaCaptureDevices* MediaCaptureDevices::GetInstance() {
+ return MediaCaptureDevicesImpl::GetInstance();
+}
+
+MediaCaptureDevicesImpl* MediaCaptureDevicesImpl::GetInstance() {
+ return Singleton<MediaCaptureDevicesImpl>::get();
+}
+
+const MediaStreamDevices&
+MediaCaptureDevicesImpl::GetAudioCaptureDevices() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!devices_enumerated_) {
+ EnsureMonitorCaptureDevices();
+ devices_enumerated_ = true;
+ }
+ return audio_devices_;
+}
+
+const MediaStreamDevices&
+MediaCaptureDevicesImpl::GetVideoCaptureDevices() {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (!devices_enumerated_) {
+ EnsureMonitorCaptureDevices();
+ devices_enumerated_ = true;
+ }
+ return video_devices_;
+}
+
+void MediaCaptureDevicesImpl::OnAudioCaptureDevicesChanged(
+ const MediaStreamDevices& devices) {
+ if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ UpdateAudioDevicesOnUIThread(devices);
+ } else {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&MediaCaptureDevicesImpl::UpdateAudioDevicesOnUIThread,
+ base::Unretained(this), devices));
+ }
+}
+
+void MediaCaptureDevicesImpl::OnVideoCaptureDevicesChanged(
+ const MediaStreamDevices& devices) {
+ if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
+ UpdateVideoDevicesOnUIThread(devices);
+ } else {
+ BrowserThread::PostTask(
+ BrowserThread::UI, FROM_HERE,
+ base::Bind(&MediaCaptureDevicesImpl::UpdateVideoDevicesOnUIThread,
+ base::Unretained(this), devices));
+ }
+}
+
+MediaCaptureDevicesImpl::MediaCaptureDevicesImpl()
+ : devices_enumerated_(false) {
+}
+
+MediaCaptureDevicesImpl::~MediaCaptureDevicesImpl() {
+}
+
+void MediaCaptureDevicesImpl::UpdateAudioDevicesOnUIThread(
+ const MediaStreamDevices& devices) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ devices_enumerated_ = true;
+ audio_devices_ = devices;
+}
+
+void MediaCaptureDevicesImpl::UpdateVideoDevicesOnUIThread(
+ const MediaStreamDevices& devices) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ devices_enumerated_ = true;
+ video_devices_ = devices;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698