Use audio device enumeration from lib_webrtc.

This commit is contained in:
John Preston 2020-08-18 11:23:45 +04:00
parent f36240eb38
commit e782e065a0
8 changed files with 34 additions and 28 deletions

View File

@ -24,7 +24,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h"
#include "calls/calls_panel.h"
#include "webrtc/webrtc_video_track.h"
#include "webrtc/webrtc_camera_utilities.h"
#include "webrtc/webrtc_media_devices.h"
#include "data/data_user.h"
#include "data/data_session.h"
#include "facades.h"
@ -350,7 +350,7 @@ void Call::setupOutgoingVideo() {
_videoOutgoing->stateValue(
) | rpl::start_with_next([=](Webrtc::VideoState state) {
if (state != Webrtc::VideoState::Inactive
&& Webrtc::GetCamerasList().empty()) {
&& Webrtc::GetVideoInputList().empty()) {
_videoOutgoing->setState(Webrtc::VideoState::Inactive);
} else if (_state.current() != State::Established
&& state != started
@ -710,6 +710,8 @@ void Call::createAndStartController(const MTPDphoneCall &call) {
auto encryptionKeyValue = std::make_shared<std::array<uint8_t, 256>>();
memcpy(encryptionKeyValue->data(), _authKey.data(), 256);
const auto &settings = Core::App().settings();
const auto weak = base::make_weak(this);
tgcalls::Descriptor descriptor = {
.config = tgcalls::Config{
@ -726,6 +728,12 @@ void Call::createAndStartController(const MTPDphoneCall &call) {
.encryptionKey = tgcalls::EncryptionKey(
std::move(encryptionKeyValue),
(_type == Type::Outgoing)),
.mediaDevicesConfig = tgcalls::MediaDevicesConfig{
.audioInputId = settings.callInputDeviceID().toStdString(),
.audioOutputId = settings.callOutputDeviceID().toStdString(),
.inputVolume = settings.callInputVolume() / 100.f,
.outputVolume = settings.callOutputVolume() / 100.f,
},
.videoCapture = _videoCapture,
.stateUpdated = [=](tgcalls::State state) {
crl::on_main(weak, [=] {
@ -810,14 +818,6 @@ void Call::createAndStartController(const MTPDphoneCall &call) {
}
raw->setIncomingVideoOutput(_videoIncoming->sink());
const auto &settings = Core::App().settings();
raw->setAudioOutputDevice(
settings.callOutputDeviceID().toStdString());
raw->setAudioInputDevice(
settings.callInputDeviceID().toStdString());
raw->setOutputVolume(settings.callOutputVolume() / 100.0f);
raw->setInputVolume(settings.callInputVolume() / 100.0f);
raw->setAudioOutputDuckingEnabled(settings.callAudioDuckingEnabled());
}

View File

@ -176,13 +176,17 @@ public:
_autoLock = value;
}
[[nodiscard]] QString callOutputDeviceID() const {
return _callOutputDeviceID;
return _callOutputDeviceID.isEmpty()
? u"default"_q
: _callOutputDeviceID;
}
void setCallOutputDeviceID(const QString &value) {
_callOutputDeviceID = value;
}
[[nodiscard]] QString callInputDeviceID() const {
return _callInputDeviceID;
return _callInputDeviceID.isEmpty()
? u"default"_q
: _callInputDeviceID;
}
void setCallInputDeviceID(const QString &value) {
_callInputDeviceID = value;

View File

@ -593,6 +593,7 @@ bool OpenSystemSettings(SystemSettingsType type) {
if (type == SystemSettingsType::Audio) {
crl::on_main([] {
WinExec("control.exe mmsys.cpl", SW_SHOW);
//QDesktopServices::openUrl(QUrl("ms-settings:sound"));
});
}
return true;

View File

@ -26,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h"
#include "core/core_settings.h"
#include "calls/calls_instance.h"
#include "webrtc/webrtc_media_devices.h"
#include "facades.h"
#ifdef slots
@ -68,10 +69,10 @@ void Calls::setupContent() {
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
const auto getId = [](const auto &device) {
return QString::fromStdString(device.id);
return device.id;
};
const auto getName = [](const auto &device) {
return QString::fromStdString(device.displayName);
return device.name;
};
const auto &settings = Core::App().settings();
@ -79,7 +80,7 @@ void Calls::setupContent() {
if (settings.callOutputDeviceID() == qsl("default")) {
return tr::lng_settings_call_device_default(tr::now);
}
const auto &list = VoIP::EnumerateAudioOutputs();
const auto list = Webrtc::GetAudioOutputList();
const auto i = ranges::find(
list,
settings.callOutputDeviceID(),
@ -93,7 +94,7 @@ void Calls::setupContent() {
if (settings.callInputDeviceID() == qsl("default")) {
return tr::lng_settings_call_device_default(tr::now);
}
const auto &list = VoIP::EnumerateAudioInputs();
const auto list = Webrtc::GetAudioInputList();
const auto i = ranges::find(
list,
settings.callInputDeviceID(),
@ -115,7 +116,7 @@ void Calls::setupContent() {
),
st::settingsButton
)->addClickHandler([=] {
const auto &devices = VoIP::EnumerateAudioOutputs();
const auto &devices = Webrtc::GetAudioOutputList();
const auto options = ranges::view::concat(
ranges::view::single(tr::lng_settings_call_device_default(tr::now)),
devices | ranges::view::transform(getName)
@ -132,11 +133,10 @@ void Calls::setupContent() {
const auto deviceId = option
? devices[option - 1].id
: "default";
Core::App().settings().setCallOutputDeviceID(
QString::fromStdString(deviceId));
Core::App().settings().setCallOutputDeviceID(deviceId);
Core::App().saveSettingsDelayed();
if (const auto call = Core::App().calls().currentCall()) {
call->setCurrentAudioDevice(false, deviceId);
call->setCurrentAudioDevice(false, deviceId.toStdString());
}
});
Ui::show(Box<SingleChoiceBox>(
@ -171,7 +171,7 @@ void Calls::setupContent() {
};
outputSlider->resize(st::settingsAudioVolumeSlider.seekSize);
outputSlider->setPseudoDiscrete(
201,
101,
[](int val) { return val; },
settings.callOutputVolume(),
updateOutputVolume);
@ -191,7 +191,7 @@ void Calls::setupContent() {
),
st::settingsButton
)->addClickHandler([=] {
const auto &devices = VoIP::EnumerateAudioInputs();
const auto devices = Webrtc::GetAudioInputList();
const auto options = ranges::view::concat(
ranges::view::single(tr::lng_settings_call_device_default(tr::now)),
devices | ranges::view::transform(getName)
@ -208,14 +208,13 @@ void Calls::setupContent() {
const auto deviceId = option
? devices[option - 1].id
: "default";
Core::App().settings().setCallInputDeviceID(
QString::fromStdString(deviceId));
Core::App().settings().setCallInputDeviceID(deviceId);
Core::App().saveSettingsDelayed();
if (_micTester) {
stopTestingMicrophone();
}
if (const auto call = Core::App().calls().currentCall()) {
call->setCurrentAudioDevice(true, deviceId);
call->setCurrentAudioDevice(true, deviceId.toStdString());
}
});
Ui::show(Box<SingleChoiceBox>(

@ -1 +1 @@
Subproject commit 6e82b6e45664c1f80b9039256c99bebc76d34672
Subproject commit 7563a96b8f8e86b7a5fd1ce783388adf29bf4cf9

@ -1 +1 @@
Subproject commit 3e4c5e2c23b644fe9b2444e291c32d7efa31db41
Subproject commit c6c78d68729ce16cff2bee868939780788443963

View File

@ -170,6 +170,8 @@ remove_target_sources(lib_tgcalls ${tgcalls_loc}
platform/android/VideoCameraCapturer.h
platform/android/VideoCapturerInterfaceImpl.cpp
platform/android/VideoCapturerInterfaceImpl.h
reference/InstanceImplReference.cpp
reference/InstanceImplReference.h
)
target_include_directories(lib_tgcalls

@ -1 +1 @@
Subproject commit 4d0f0b8ef41b7a7f8014cebb1dbc5549b06fde6f
Subproject commit 32957e855993b20c95fa714518ba4bc55ebcdd32