2013-07-31 18:08:45 +00: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-CHROMIUM file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/browser/media/media_capture_devices_dispatcher.h"
|
2024-02-29 09:31:13 +00:00
|
|
|
|
|
|
|
#include "components/webrtc/media_stream_devices_util.h"
|
2013-07-31 18:08:45 +00:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
2014-06-26 20:31:32 +00:00
|
|
|
#include "content/public/browser/media_capture_devices.h"
|
2013-07-31 18:08:45 +00:00
|
|
|
|
|
|
|
using content::BrowserThread;
|
2019-01-21 16:28:04 +00:00
|
|
|
|
|
|
|
namespace electron {
|
2013-07-31 18:08:45 +00:00
|
|
|
|
|
|
|
MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() {
|
2024-02-23 09:35:20 +00:00
|
|
|
static base::NoDestructor<MediaCaptureDevicesDispatcher> instance;
|
|
|
|
return instance.get();
|
2013-07-31 18:08:45 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 18:16:21 +00:00
|
|
|
MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher() {
|
2013-10-07 20:13:01 +00:00
|
|
|
// MediaCaptureDevicesDispatcher is a singleton. It should be created on
|
|
|
|
// UI thread.
|
2017-12-07 04:15:17 +00:00
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
2013-10-07 20:13:01 +00:00
|
|
|
}
|
2013-07-31 18:08:45 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() = default;
|
2013-07-31 18:08:45 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
void MediaCaptureDevicesDispatcher::OnAudioCaptureDevicesChanged() {}
|
2013-07-31 18:08:45 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
void MediaCaptureDevicesDispatcher::OnVideoCaptureDevicesChanged() {}
|
2013-07-31 18:08:45 +00:00
|
|
|
|
|
|
|
void MediaCaptureDevicesDispatcher::OnMediaRequestStateChanged(
|
|
|
|
int render_process_id,
|
|
|
|
int render_view_id,
|
2013-10-07 20:13:01 +00:00
|
|
|
int page_request_id,
|
2014-06-26 20:31:32 +00:00
|
|
|
const GURL& security_origin,
|
2019-07-03 01:22:09 +00:00
|
|
|
blink::mojom::MediaStreamType stream_type,
|
2018-04-18 01:56:12 +00:00
|
|
|
content::MediaRequestState state) {}
|
2013-10-07 20:13:01 +00:00
|
|
|
|
2018-04-18 01:56:12 +00:00
|
|
|
void MediaCaptureDevicesDispatcher::OnCreatingAudioStream(int render_process_id,
|
|
|
|
int render_view_id) {}
|
2013-07-31 18:08:45 +00:00
|
|
|
|
2016-07-04 06:06:05 +00:00
|
|
|
void MediaCaptureDevicesDispatcher::OnSetCapturingLinkSecured(
|
|
|
|
int render_process_id,
|
|
|
|
int render_frame_id,
|
|
|
|
int page_request_id,
|
2019-07-03 01:22:09 +00:00
|
|
|
blink::mojom::MediaStreamType stream_type,
|
2018-04-18 01:56:12 +00:00
|
|
|
bool is_secure) {}
|
2016-07-04 06:06:05 +00:00
|
|
|
|
2024-02-29 09:31:13 +00:00
|
|
|
const std::optional<blink::MediaStreamDevice>
|
|
|
|
MediaCaptureDevicesDispatcher::GetPreferredAudioDeviceForBrowserContext(
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const std::vector<std::string>& eligible_audio_device_ids) const {
|
|
|
|
auto audio_devices = GetAudioCaptureDevices();
|
|
|
|
if (!eligible_audio_device_ids.empty()) {
|
|
|
|
audio_devices =
|
|
|
|
webrtc::FilterMediaDevices(audio_devices, eligible_audio_device_ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (audio_devices.empty())
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
return audio_devices.front();
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::optional<blink::MediaStreamDevice>
|
|
|
|
MediaCaptureDevicesDispatcher::GetPreferredVideoDeviceForBrowserContext(
|
|
|
|
content::BrowserContext* browser_context,
|
|
|
|
const std::vector<std::string>& eligible_video_device_ids) const {
|
|
|
|
auto video_devices = GetVideoCaptureDevices();
|
|
|
|
if (!eligible_video_device_ids.empty()) {
|
|
|
|
video_devices =
|
|
|
|
webrtc::FilterMediaDevices(video_devices, eligible_video_device_ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (video_devices.empty())
|
|
|
|
return std::nullopt;
|
|
|
|
|
|
|
|
return video_devices.front();
|
|
|
|
}
|
|
|
|
|
2018-10-19 18:51:43 +00:00
|
|
|
} // namespace electron
|