2014-02-05 21:35:45 +01:00
|
|
|
// Copyright (c) 2012 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 "libcef/browser/media_capture_devices_dispatcher.h"
|
|
|
|
|
|
|
|
#include "chrome/common/pref_names.h"
|
2016-02-05 01:49:19 +01:00
|
|
|
#include "components/prefs/pref_registry_simple.h"
|
|
|
|
#include "components/prefs/pref_service.h"
|
2014-02-05 21:35:45 +01:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2014-04-04 18:50:38 +02:00
|
|
|
#include "content/public/browser/media_capture_devices.h"
|
2014-02-05 21:35:45 +01:00
|
|
|
|
2019-02-01 17:42:40 +01:00
|
|
|
using blink::MediaStreamDevices;
|
2014-02-05 21:35:45 +01:00
|
|
|
using content::BrowserThread;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2019-02-01 17:42:40 +01:00
|
|
|
const blink::MediaStreamDevice* FindDefaultDeviceWithId(
|
|
|
|
const blink::MediaStreamDevices& devices,
|
2014-02-05 21:35:45 +01:00
|
|
|
const std::string& device_id) {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (devices.empty()) {
|
2020-01-15 14:36:24 +01:00
|
|
|
return nullptr;
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-02-05 21:35:45 +01:00
|
|
|
|
2019-02-01 17:42:40 +01:00
|
|
|
blink::MediaStreamDevices::const_iterator iter = devices.begin();
|
2014-02-05 21:35:45 +01:00
|
|
|
for (; iter != devices.end(); ++iter) {
|
|
|
|
if (iter->id == device_id) {
|
|
|
|
return &(*iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return &(*devices.begin());
|
2019-03-13 22:27:37 +01:00
|
|
|
}
|
2014-02-05 21:35:45 +01:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
CefMediaCaptureDevicesDispatcher*
|
2017-05-17 11:29:28 +02:00
|
|
|
CefMediaCaptureDevicesDispatcher::GetInstance() {
|
2015-10-09 17:23:12 +02:00
|
|
|
return base::Singleton<CefMediaCaptureDevicesDispatcher>::get();
|
2014-02-05 21:35:45 +01:00
|
|
|
}
|
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
CefMediaCaptureDevicesDispatcher::CefMediaCaptureDevicesDispatcher() {}
|
2014-02-05 21:35:45 +01:00
|
|
|
|
|
|
|
CefMediaCaptureDevicesDispatcher::~CefMediaCaptureDevicesDispatcher() {}
|
|
|
|
|
|
|
|
void CefMediaCaptureDevicesDispatcher::RegisterPrefs(
|
|
|
|
PrefRegistrySimple* registry) {
|
|
|
|
registry->RegisterStringPref(prefs::kDefaultAudioCaptureDevice,
|
|
|
|
std::string());
|
|
|
|
registry->RegisterStringPref(prefs::kDefaultVideoCaptureDevice,
|
|
|
|
std::string());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefMediaCaptureDevicesDispatcher::GetDefaultDevices(
|
|
|
|
PrefService* prefs,
|
|
|
|
bool audio,
|
|
|
|
bool video,
|
2019-02-01 17:42:40 +01:00
|
|
|
blink::MediaStreamDevices* devices) {
|
2014-02-05 21:35:45 +01:00
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
|
DCHECK(audio || video);
|
|
|
|
|
|
|
|
std::string default_device;
|
|
|
|
if (audio) {
|
|
|
|
default_device = prefs->GetString(prefs::kDefaultAudioCaptureDevice);
|
|
|
|
GetRequestedDevice(default_device, true, false, devices);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (video) {
|
|
|
|
default_device = prefs->GetString(prefs::kDefaultVideoCaptureDevice);
|
|
|
|
GetRequestedDevice(default_device, false, true, devices);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefMediaCaptureDevicesDispatcher::GetRequestedDevice(
|
|
|
|
const std::string& requested_device_id,
|
|
|
|
bool audio,
|
|
|
|
bool video,
|
2019-02-01 17:42:40 +01:00
|
|
|
blink::MediaStreamDevices* devices) {
|
2014-02-05 21:35:45 +01:00
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
|
DCHECK(audio || video);
|
|
|
|
|
|
|
|
if (audio) {
|
2019-02-01 17:42:40 +01:00
|
|
|
const blink::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
|
|
|
|
const blink::MediaStreamDevice* const device =
|
2014-02-05 21:35:45 +01:00
|
|
|
FindDefaultDeviceWithId(audio_devices, requested_device_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (device) {
|
2014-02-05 21:35:45 +01:00
|
|
|
devices->push_back(*device);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-02-05 21:35:45 +01:00
|
|
|
}
|
|
|
|
if (video) {
|
2019-02-01 17:42:40 +01:00
|
|
|
const blink::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
|
|
|
|
const blink::MediaStreamDevice* const device =
|
2014-02-05 21:35:45 +01:00
|
|
|
FindDefaultDeviceWithId(video_devices, requested_device_id);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (device) {
|
2014-02-05 21:35:45 +01:00
|
|
|
devices->push_back(*device);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-02-05 21:35:45 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefMediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged() {}
|
2014-02-05 21:35:45 +01:00
|
|
|
|
2017-05-17 11:29:28 +02:00
|
|
|
void CefMediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged() {}
|
2014-02-05 21:35:45 +01:00
|
|
|
|
|
|
|
void CefMediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
|
2013-07-24 22:15:18 +02:00
|
|
|
int render_process_id,
|
2014-09-04 19:53:40 +02:00
|
|
|
int render_frame_id,
|
2013-07-24 22:15:18 +02:00
|
|
|
int page_request_id,
|
2014-02-05 21:35:45 +01:00
|
|
|
const GURL& security_origin,
|
2019-09-04 17:13:32 +02:00
|
|
|
blink::mojom::MediaStreamType stream_type,
|
2017-05-17 11:29:28 +02:00
|
|
|
content::MediaRequestState state) {}
|
2014-02-05 21:35:45 +01:00
|
|
|
|
2013-07-24 22:15:18 +02:00
|
|
|
void CefMediaCaptureDevicesDispatcher::OnCreatingAudioStream(
|
|
|
|
int render_process_id,
|
2017-05-17 11:29:28 +02:00
|
|
|
int render_view_id) {}
|
2014-02-05 21:35:45 +01:00
|
|
|
|
2016-05-25 01:35:43 +02:00
|
|
|
void CefMediaCaptureDevicesDispatcher::OnSetCapturingLinkSecured(
|
|
|
|
int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
int page_request_id,
|
2019-09-04 17:13:32 +02:00
|
|
|
blink::mojom::MediaStreamType stream_type,
|
2017-05-17 11:29:28 +02:00
|
|
|
bool is_secure) {}
|
2016-05-25 01:35:43 +02:00
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
const MediaStreamDevices&
|
|
|
|
CefMediaCaptureDevicesDispatcher::GetAudioCaptureDevices() {
|
2014-02-05 21:35:45 +01:00
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
2014-04-04 18:50:38 +02:00
|
|
|
return content::MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices();
|
2014-02-05 21:35:45 +01:00
|
|
|
}
|
|
|
|
|
2014-04-04 18:50:38 +02:00
|
|
|
const MediaStreamDevices&
|
|
|
|
CefMediaCaptureDevicesDispatcher::GetVideoCaptureDevices() {
|
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
|
return content::MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
|
2014-02-05 21:35:45 +01:00
|
|
|
}
|