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.
|
|
|
|
|
2018-10-19 18:51:43 +00:00
|
|
|
#include "atom/browser/media/media_capture_devices_dispatcher.h"
|
2013-07-31 18:08:45 +00:00
|
|
|
|
2013-10-07 20:13:01 +00:00
|
|
|
#include "base/logging.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 atom {
|
2013-07-31 18:08:45 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2013-10-07 20:13:01 +00:00
|
|
|
// Finds a device in |devices| that has |device_id|, or NULL if not found.
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevice* FindDeviceWithId(
|
|
|
|
const blink::MediaStreamDevices& devices,
|
2013-07-31 18:08:45 +00:00
|
|
|
const std::string& device_id) {
|
2016-07-10 11:12:33 +00:00
|
|
|
auto iter = devices.begin();
|
2013-07-31 18:08:45 +00:00
|
|
|
for (; iter != devices.end(); ++iter) {
|
|
|
|
if (iter->id == device_id) {
|
|
|
|
return &(*iter);
|
|
|
|
}
|
|
|
|
}
|
2016-07-10 09:56:02 +00:00
|
|
|
return nullptr;
|
2013-11-18 00:14:08 +00:00
|
|
|
}
|
2013-07-31 18:08:45 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
MediaCaptureDevicesDispatcher* MediaCaptureDevicesDispatcher::GetInstance() {
|
2015-12-07 11:55:01 +00:00
|
|
|
return base::Singleton<MediaCaptureDevicesDispatcher>::get();
|
2013-07-31 18:08:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher()
|
2014-06-26 20:31:32 +00:00
|
|
|
: is_device_enumeration_disabled_(false) {
|
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
|
|
|
|
|
|
|
MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {}
|
|
|
|
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevices&
|
2013-07-31 18:08:45 +00:00
|
|
|
MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() {
|
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
2014-06-26 20:31:32 +00:00
|
|
|
if (is_device_enumeration_disabled_)
|
2019-01-21 16:28:04 +00:00
|
|
|
return test_audio_devices_;
|
2014-06-26 20:31:32 +00:00
|
|
|
return content::MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices();
|
2013-07-31 18:08:45 +00:00
|
|
|
}
|
|
|
|
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevices&
|
2013-07-31 18:08:45 +00:00
|
|
|
MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() {
|
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
2014-06-26 20:31:32 +00:00
|
|
|
if (is_device_enumeration_disabled_)
|
2019-01-21 16:28:04 +00:00
|
|
|
return test_video_devices_;
|
2014-06-26 20:31:32 +00:00
|
|
|
return content::MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
|
2013-07-31 18:08:45 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 20:13:01 +00:00
|
|
|
void MediaCaptureDevicesDispatcher::GetDefaultDevices(
|
2013-07-31 18:08:45 +00:00
|
|
|
bool audio,
|
|
|
|
bool video,
|
2019-01-21 16:28:04 +00:00
|
|
|
blink::MediaStreamDevices* devices) {
|
2013-07-31 18:08:45 +00:00
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
|
|
|
DCHECK(audio || video);
|
|
|
|
|
|
|
|
if (audio) {
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevice* device = GetFirstAvailableAudioDevice();
|
2013-07-31 18:08:45 +00:00
|
|
|
if (device)
|
|
|
|
devices->push_back(*device);
|
|
|
|
}
|
2013-10-07 20:13:01 +00:00
|
|
|
|
2013-07-31 18:08:45 +00:00
|
|
|
if (video) {
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevice* device = GetFirstAvailableVideoDevice();
|
2013-07-31 18:08:45 +00:00
|
|
|
if (device)
|
|
|
|
devices->push_back(*device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevice*
|
2013-10-07 20:13:01 +00:00
|
|
|
MediaCaptureDevicesDispatcher::GetRequestedAudioDevice(
|
|
|
|
const std::string& requested_audio_device_id) {
|
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
|
|
|
|
const blink::MediaStreamDevice* const device =
|
2013-10-07 20:13:01 +00:00
|
|
|
FindDeviceWithId(audio_devices, requested_audio_device_id);
|
|
|
|
return device;
|
|
|
|
}
|
2013-07-31 18:08:45 +00:00
|
|
|
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevice*
|
2013-10-07 20:13:01 +00:00
|
|
|
MediaCaptureDevicesDispatcher::GetFirstAvailableAudioDevice() {
|
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevices& audio_devices = GetAudioCaptureDevices();
|
2013-10-07 20:13:01 +00:00
|
|
|
if (audio_devices.empty())
|
2016-07-10 09:56:02 +00:00
|
|
|
return nullptr;
|
2013-10-07 20:13:01 +00:00
|
|
|
return &(*audio_devices.begin());
|
|
|
|
}
|
|
|
|
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevice*
|
2013-10-07 20:13:01 +00:00
|
|
|
MediaCaptureDevicesDispatcher::GetRequestedVideoDevice(
|
|
|
|
const std::string& requested_video_device_id) {
|
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
|
|
|
|
const blink::MediaStreamDevice* const device =
|
2013-10-07 20:13:01 +00:00
|
|
|
FindDeviceWithId(video_devices, requested_video_device_id);
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevice*
|
2013-10-07 20:13:01 +00:00
|
|
|
MediaCaptureDevicesDispatcher::GetFirstAvailableVideoDevice() {
|
|
|
|
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
2019-01-21 16:28:04 +00:00
|
|
|
const blink::MediaStreamDevices& video_devices = GetVideoCaptureDevices();
|
2013-10-07 20:13:01 +00:00
|
|
|
if (video_devices.empty())
|
2016-07-10 09:56:02 +00:00
|
|
|
return nullptr;
|
2013-10-07 20:13:01 +00:00
|
|
|
return &(*video_devices.begin());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MediaCaptureDevicesDispatcher::DisableDeviceEnumerationForTesting() {
|
|
|
|
is_device_enumeration_disabled_ = true;
|
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-01-21 16:28:04 +00:00
|
|
|
blink::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-01-21 16:28:04 +00:00
|
|
|
blink::MediaStreamType stream_type,
|
2018-04-18 01:56:12 +00:00
|
|
|
bool is_secure) {}
|
2016-07-04 06:06:05 +00:00
|
|
|
|
2018-10-19 18:51:43 +00:00
|
|
|
} // namespace atom
|