2019-01-05 11:08:02 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "settings/settings_calls.h"
|
|
|
|
|
|
|
|
#include "settings/settings_common.h"
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
|
|
|
#include "ui/wrap/slide_wrap.h"
|
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "ui/widgets/checkbox.h"
|
|
|
|
#include "ui/widgets/level_meter.h"
|
2019-11-02 17:06:47 +00:00
|
|
|
#include "ui/widgets/buttons.h"
|
2021-03-23 16:06:59 +00:00
|
|
|
#include "ui/boxes/single_choice_box.h"
|
2019-01-05 11:08:02 +00:00
|
|
|
#include "boxes/confirm_box.h"
|
|
|
|
#include "platform/platform_specific.h"
|
2020-06-09 16:57:05 +00:00
|
|
|
#include "main/main_session.h"
|
2019-01-05 11:08:02 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "layout.h"
|
|
|
|
#include "styles/style_settings.h"
|
|
|
|
#include "ui/widgets/continuous_sliders.h"
|
2019-08-06 16:40:08 +00:00
|
|
|
#include "window/window_session_controller.h"
|
2020-06-18 18:04:16 +00:00
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/core_settings.h"
|
2021-04-22 16:05:17 +00:00
|
|
|
#include "calls/calls_call.h"
|
2019-01-05 11:08:02 +00:00
|
|
|
#include "calls/calls_instance.h"
|
2020-08-21 10:50:13 +00:00
|
|
|
#include "calls/calls_video_bubble.h"
|
2020-08-18 07:23:45 +00:00
|
|
|
#include "webrtc/webrtc_media_devices.h"
|
2020-08-21 10:50:13 +00:00
|
|
|
#include "webrtc/webrtc_video_track.h"
|
|
|
|
#include "webrtc/webrtc_audio_input_tester.h"
|
2021-01-07 15:27:11 +00:00
|
|
|
#include "webrtc/webrtc_create_adm.h" // Webrtc::Backend.
|
2020-08-21 10:50:13 +00:00
|
|
|
#include "tgcalls/VideoCaptureInterface.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "facades.h"
|
2021-01-07 15:27:11 +00:00
|
|
|
#include "app.h" // App::restart().
|
2020-08-21 10:50:13 +00:00
|
|
|
#include "styles/style_layers.h"
|
2019-01-05 11:08:02 +00:00
|
|
|
|
2020-08-21 10:50:13 +00:00
|
|
|
namespace Settings {
|
2021-01-07 15:27:11 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
using namespace Webrtc;
|
|
|
|
|
|
|
|
} // namespace
|
2019-01-05 11:08:02 +00:00
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
Calls::Calls(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Window::SessionController*> controller)
|
2020-06-09 16:57:05 +00:00
|
|
|
: Section(parent)
|
|
|
|
, _controller(controller) {
|
|
|
|
setupContent();
|
2020-08-21 10:50:13 +00:00
|
|
|
requestPermissionAndStartTestingMicrophone();
|
2019-01-05 11:08:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-28 16:18:51 +00:00
|
|
|
Calls::~Calls() = default;
|
2019-01-05 11:08:02 +00:00
|
|
|
|
2019-01-11 10:07:56 +00:00
|
|
|
void Calls::sectionSaveChanges(FnMut<void()> done) {
|
2019-01-05 11:08:02 +00:00
|
|
|
if (_micTester) {
|
|
|
|
_micTester.reset();
|
|
|
|
}
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
|
2020-06-09 16:57:05 +00:00
|
|
|
void Calls::setupContent() {
|
2019-01-05 11:08:02 +00:00
|
|
|
const auto content = Ui::CreateChild<Ui::VerticalLayout>(this);
|
|
|
|
|
2020-06-18 18:04:16 +00:00
|
|
|
const auto &settings = Core::App().settings();
|
2021-01-07 15:27:11 +00:00
|
|
|
const auto cameras = GetVideoInputList();
|
2020-08-18 14:00:33 +00:00
|
|
|
if (!cameras.empty()) {
|
2020-08-21 11:49:51 +00:00
|
|
|
const auto hasCall = (Core::App().calls().currentCall() != nullptr);
|
|
|
|
|
|
|
|
auto capturerOwner = Core::App().calls().getVideoCapture();
|
2020-08-21 10:50:13 +00:00
|
|
|
const auto capturer = capturerOwner.get();
|
|
|
|
content->lifetime().add([owner = std::move(capturerOwner)]{});
|
|
|
|
|
2021-01-07 15:27:11 +00:00
|
|
|
const auto track = content->lifetime().make_state<VideoTrack>(
|
2020-08-21 11:49:51 +00:00
|
|
|
(hasCall
|
2021-01-07 15:27:11 +00:00
|
|
|
? VideoState::Inactive
|
|
|
|
: VideoState::Active));
|
2020-08-21 10:50:13 +00:00
|
|
|
|
2020-08-18 14:00:33 +00:00
|
|
|
const auto currentCameraName = [&] {
|
|
|
|
const auto i = ranges::find(
|
|
|
|
cameras,
|
|
|
|
settings.callVideoInputDeviceId(),
|
2021-01-07 15:27:11 +00:00
|
|
|
&VideoInput::id);
|
2020-08-18 14:00:33 +00:00
|
|
|
return (i != end(cameras))
|
2020-11-28 16:18:51 +00:00
|
|
|
? i->name
|
2020-08-18 14:00:33 +00:00
|
|
|
: tr::lng_settings_call_device_default(tr::now);
|
|
|
|
}();
|
|
|
|
|
|
|
|
AddSkip(content);
|
|
|
|
AddSubsectionTitle(content, tr::lng_settings_call_camera());
|
|
|
|
AddButtonWithLabel(
|
|
|
|
content,
|
|
|
|
tr::lng_settings_call_input_device(),
|
|
|
|
rpl::single(
|
|
|
|
currentCameraName
|
|
|
|
) | rpl::then(
|
|
|
|
_cameraNameStream.events()
|
|
|
|
),
|
|
|
|
st::settingsButton
|
|
|
|
)->addClickHandler([=] {
|
2021-01-07 15:27:11 +00:00
|
|
|
const auto &devices = GetVideoInputList();
|
2021-03-13 12:12:08 +00:00
|
|
|
const auto options = ranges::views::concat(
|
|
|
|
ranges::views::single(tr::lng_settings_call_device_default(tr::now)),
|
|
|
|
devices | ranges::views::transform(&VideoInput::name)
|
2020-08-18 14:00:33 +00:00
|
|
|
) | ranges::to_vector;
|
|
|
|
const auto i = ranges::find(
|
|
|
|
devices,
|
|
|
|
Core::App().settings().callVideoInputDeviceId(),
|
2021-01-07 15:27:11 +00:00
|
|
|
&VideoInput::id);
|
2020-08-18 14:00:33 +00:00
|
|
|
const auto currentOption = (i != end(devices))
|
|
|
|
? int(i - begin(devices) + 1)
|
|
|
|
: 0;
|
|
|
|
const auto save = crl::guard(this, [=](int option) {
|
|
|
|
_cameraNameStream.fire_copy(options[option]);
|
|
|
|
const auto deviceId = option
|
|
|
|
? devices[option - 1].id
|
|
|
|
: "default";
|
2020-08-21 10:50:13 +00:00
|
|
|
capturer->switchToDevice(deviceId.toStdString());
|
2020-08-18 14:00:33 +00:00
|
|
|
Core::App().settings().setCallVideoInputDeviceId(deviceId);
|
|
|
|
Core::App().saveSettingsDelayed();
|
|
|
|
if (const auto call = Core::App().calls().currentCall()) {
|
2020-08-21 10:50:13 +00:00
|
|
|
call->setCurrentVideoDevice(deviceId);
|
2020-08-18 14:00:33 +00:00
|
|
|
}
|
|
|
|
});
|
2021-02-01 13:51:01 +00:00
|
|
|
Ui::show(Box([=](not_null<Ui::GenericBox*> box) {
|
|
|
|
SingleChoiceBox(box, {
|
|
|
|
.title = tr::lng_settings_call_camera(),
|
|
|
|
.options = options,
|
|
|
|
.initialSelection = currentOption,
|
|
|
|
.callback = save,
|
|
|
|
});
|
|
|
|
}));
|
2020-08-18 14:00:33 +00:00
|
|
|
});
|
2020-08-21 10:50:13 +00:00
|
|
|
const auto bubbleWrap = content->add(object_ptr<Ui::RpWidget>(content));
|
|
|
|
const auto bubble = content->lifetime().make_state<::Calls::VideoBubble>(
|
|
|
|
bubbleWrap,
|
|
|
|
track);
|
|
|
|
const auto padding = st::settingsButton.padding.left();
|
|
|
|
const auto top = st::boxRoundShadow.extend.top();
|
|
|
|
const auto bottom = st::boxRoundShadow.extend.bottom();
|
|
|
|
|
|
|
|
bubbleWrap->widthValue(
|
|
|
|
) | rpl::filter([=](int width) {
|
|
|
|
return (width > 2 * padding + 1);
|
|
|
|
}) | rpl::start_with_next([=](int width) {
|
|
|
|
const auto use = (width - 2 * padding);
|
|
|
|
bubble->updateGeometry(
|
|
|
|
::Calls::VideoBubble::DragMode::None,
|
|
|
|
QRect(padding, top, use, (use * 480) / 640));
|
|
|
|
}, bubbleWrap->lifetime());
|
|
|
|
|
|
|
|
track->renderNextFrame(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
const auto size = track->frameSize();
|
2021-04-16 16:03:58 +00:00
|
|
|
if (size.isEmpty()
|
|
|
|
|| Core::App().calls().currentCall()
|
|
|
|
|| Core::App().calls().currentGroupCall()) {
|
2020-08-21 10:50:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto width = bubbleWrap->width();
|
|
|
|
const auto use = (width - 2 * padding);
|
2020-08-21 11:49:51 +00:00
|
|
|
const auto height = std::min(
|
|
|
|
((use * size.height()) / size.width()),
|
|
|
|
(use * 480) / 640);
|
|
|
|
bubbleWrap->resize(width, top + height + bottom);
|
2020-08-21 10:50:13 +00:00
|
|
|
bubbleWrap->update();
|
|
|
|
}, bubbleWrap->lifetime());
|
2020-08-18 14:00:33 +00:00
|
|
|
|
2021-04-16 16:03:58 +00:00
|
|
|
using namespace rpl::mappers;
|
|
|
|
rpl::combine(
|
|
|
|
Core::App().calls().currentCallValue(),
|
|
|
|
Core::App().calls().currentGroupCallValue(),
|
|
|
|
_1 || _2
|
|
|
|
) | rpl::start_with_next([=](bool has) {
|
|
|
|
if (has) {
|
2021-01-07 15:27:11 +00:00
|
|
|
track->setState(VideoState::Inactive);
|
2020-08-21 11:49:51 +00:00
|
|
|
bubbleWrap->resize(bubbleWrap->width(), 0);
|
|
|
|
} else {
|
|
|
|
capturer->setPreferredAspectRatio(0.);
|
2021-01-07 15:27:11 +00:00
|
|
|
track->setState(VideoState::Active);
|
2020-08-21 11:49:51 +00:00
|
|
|
capturer->setOutput(track->sink());
|
|
|
|
}
|
|
|
|
}, content->lifetime());
|
|
|
|
|
2020-08-18 14:00:33 +00:00
|
|
|
AddSkip(content);
|
|
|
|
AddDivider(content);
|
|
|
|
}
|
2019-01-05 11:08:02 +00:00
|
|
|
AddSkip(content);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(content, tr::lng_settings_call_section_output());
|
2019-01-11 10:07:56 +00:00
|
|
|
AddButtonWithLabel(
|
2019-01-05 11:08:02 +00:00
|
|
|
content,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_call_output_device(),
|
2019-01-11 10:07:56 +00:00
|
|
|
rpl::single(
|
2020-11-28 16:18:51 +00:00
|
|
|
CurrentAudioOutputName()
|
2019-01-11 10:07:56 +00:00
|
|
|
) | rpl::then(
|
|
|
|
_outputNameStream.events()
|
|
|
|
),
|
|
|
|
st::settingsButton
|
|
|
|
)->addClickHandler([=] {
|
2020-11-28 16:18:51 +00:00
|
|
|
Ui::show(ChooseAudioOutputBox(crl::guard(this, [=](
|
|
|
|
const QString &id,
|
|
|
|
const QString &name) {
|
|
|
|
_outputNameStream.fire_copy(name);
|
|
|
|
})));
|
2019-01-05 11:08:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddSkip(content);
|
|
|
|
AddDivider(content);
|
|
|
|
AddSkip(content);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(content, tr::lng_settings_call_section_input());
|
2019-01-11 10:07:56 +00:00
|
|
|
AddButtonWithLabel(
|
2019-01-05 11:08:02 +00:00
|
|
|
content,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_call_input_device(),
|
2019-01-11 10:07:56 +00:00
|
|
|
rpl::single(
|
2020-11-28 16:18:51 +00:00
|
|
|
CurrentAudioInputName()
|
2019-01-11 10:07:56 +00:00
|
|
|
) | rpl::then(
|
|
|
|
_inputNameStream.events()
|
|
|
|
),
|
|
|
|
st::settingsButton
|
|
|
|
)->addClickHandler([=] {
|
2020-12-15 10:23:40 +00:00
|
|
|
Ui::show(ChooseAudioInputBox(crl::guard(this, [=](
|
2020-11-28 16:18:51 +00:00
|
|
|
const QString &id,
|
|
|
|
const QString &name) {
|
|
|
|
_inputNameStream.fire_copy(name);
|
2019-01-05 11:08:02 +00:00
|
|
|
if (_micTester) {
|
2020-11-28 16:18:51 +00:00
|
|
|
_micTester->setDeviceId(id);
|
2019-01-05 11:08:02 +00:00
|
|
|
}
|
2020-11-28 16:18:51 +00:00
|
|
|
})));
|
2019-01-05 11:08:02 +00:00
|
|
|
});
|
|
|
|
|
2019-01-11 10:07:56 +00:00
|
|
|
_micTestLevel = content->add(
|
|
|
|
object_ptr<Ui::LevelMeter>(
|
|
|
|
content,
|
|
|
|
st::defaultLevelMeter),
|
|
|
|
st::settingsLevelMeterPadding);
|
|
|
|
_micTestLevel->resize(QSize(0, st::defaultLevelMeter.height));
|
|
|
|
|
|
|
|
_levelUpdateTimer.setCallback([=] {
|
2020-08-21 10:50:13 +00:00
|
|
|
const auto was = _micLevel;
|
|
|
|
_micLevel = _micTester->getAndResetLevel();
|
|
|
|
_micLevelAnimation.start([=] {
|
|
|
|
_micTestLevel->setValue(_micLevelAnimation.value(_micLevel));
|
|
|
|
}, was, _micLevel, kMicTestAnimationDuration);
|
2019-01-05 11:08:02 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
AddSkip(content);
|
|
|
|
AddDivider(content);
|
|
|
|
AddSkip(content);
|
2019-06-18 12:16:43 +00:00
|
|
|
AddSubsectionTitle(content, tr::lng_settings_call_section_other());
|
2019-01-05 11:08:02 +00:00
|
|
|
|
2021-01-26 11:58:30 +00:00
|
|
|
AddButton(
|
|
|
|
content,
|
|
|
|
tr::lng_settings_call_accept_calls(),
|
|
|
|
st::settingsButton
|
|
|
|
)->toggleOn(rpl::single(
|
|
|
|
!settings.disableCalls()
|
|
|
|
))->toggledChanges(
|
|
|
|
) | rpl::filter([&settings](bool value) {
|
|
|
|
return (settings.disableCalls() == value);
|
|
|
|
}) | rpl::start_with_next([=](bool value) {
|
|
|
|
Core::App().settings().setDisableCalls(!value);
|
|
|
|
Core::App().saveSettingsDelayed();
|
|
|
|
}, content->lifetime());
|
2019-01-11 10:07:56 +00:00
|
|
|
AddButton(
|
|
|
|
content,
|
2019-06-18 12:16:43 +00:00
|
|
|
tr::lng_settings_call_open_system_prefs(),
|
2019-01-11 10:07:56 +00:00
|
|
|
st::settingsButton
|
|
|
|
)->addClickHandler([] {
|
|
|
|
const auto opened = Platform::OpenSystemSettings(
|
|
|
|
Platform::SystemSettingsType::Audio);
|
|
|
|
if (!opened) {
|
2019-06-19 15:09:03 +00:00
|
|
|
Ui::show(Box<InformBox>(tr::lng_linux_no_audio_prefs(tr::now)));
|
2019-01-05 11:08:02 +00:00
|
|
|
}
|
|
|
|
});
|
2021-01-26 11:58:30 +00:00
|
|
|
|
2019-01-05 11:08:02 +00:00
|
|
|
AddSkip(content);
|
|
|
|
|
|
|
|
Ui::ResizeFitChild(this, content);
|
|
|
|
}
|
|
|
|
|
2019-01-11 10:07:56 +00:00
|
|
|
void Calls::requestPermissionAndStartTestingMicrophone() {
|
|
|
|
const auto status = Platform::GetPermissionStatus(
|
|
|
|
Platform::PermissionType::Microphone);
|
2019-01-05 11:08:02 +00:00
|
|
|
if (status == Platform::PermissionStatus::Granted) {
|
|
|
|
startTestingMicrophone();
|
|
|
|
} else if (status == Platform::PermissionStatus::CanRequest) {
|
2019-01-11 10:07:56 +00:00
|
|
|
const auto startTestingChecked = crl::guard(this, [=](
|
|
|
|
Platform::PermissionStatus status) {
|
2019-01-05 11:08:02 +00:00
|
|
|
if (status == Platform::PermissionStatus::Granted) {
|
2019-01-11 10:07:56 +00:00
|
|
|
crl::on_main(crl::guard(this, [=] {
|
2019-01-05 11:08:02 +00:00
|
|
|
startTestingMicrophone();
|
|
|
|
}));
|
|
|
|
}
|
2019-01-11 10:07:56 +00:00
|
|
|
});
|
|
|
|
Platform::RequestPermission(
|
|
|
|
Platform::PermissionType::Microphone,
|
|
|
|
startTestingChecked);
|
2019-01-05 11:08:02 +00:00
|
|
|
} else {
|
2019-01-11 10:07:56 +00:00
|
|
|
const auto showSystemSettings = [] {
|
|
|
|
Platform::OpenSystemSettingsForPermission(
|
|
|
|
Platform::PermissionType::Microphone);
|
2019-01-05 11:08:02 +00:00
|
|
|
Ui::hideLayer();
|
2019-01-11 10:07:56 +00:00
|
|
|
};
|
|
|
|
Ui::show(Box<ConfirmBox>(
|
2019-06-19 15:09:03 +00:00
|
|
|
tr::lng_no_mic_permission(tr::now),
|
|
|
|
tr::lng_menu_settings(tr::now),
|
2019-01-11 10:07:56 +00:00
|
|
|
showSystemSettings));
|
2019-01-05 11:08:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-11 10:07:56 +00:00
|
|
|
void Calls::startTestingMicrophone() {
|
2020-08-21 10:50:13 +00:00
|
|
|
_levelUpdateTimer.callEach(kMicTestUpdateInterval);
|
2021-01-07 15:27:11 +00:00
|
|
|
_micTester = std::make_unique<AudioInputTester>(
|
|
|
|
Core::App().settings().callAudioBackend(),
|
2020-08-21 10:50:13 +00:00
|
|
|
Core::App().settings().callInputDeviceId());
|
2019-01-05 11:08:02 +00:00
|
|
|
}
|
|
|
|
|
2020-11-28 16:18:51 +00:00
|
|
|
QString CurrentAudioOutputName() {
|
2021-01-07 15:27:11 +00:00
|
|
|
const auto &settings = Core::App().settings();
|
|
|
|
const auto list = GetAudioOutputList(settings.callAudioBackend());
|
2020-11-28 16:18:51 +00:00
|
|
|
const auto i = ranges::find(
|
|
|
|
list,
|
2021-01-07 15:27:11 +00:00
|
|
|
settings.callOutputDeviceId(),
|
|
|
|
&AudioOutput::id);
|
2020-11-28 16:18:51 +00:00
|
|
|
return (i != end(list))
|
|
|
|
? i->name
|
|
|
|
: tr::lng_settings_call_device_default(tr::now);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString CurrentAudioInputName() {
|
2021-01-07 15:27:11 +00:00
|
|
|
const auto &settings = Core::App().settings();
|
|
|
|
const auto list = GetAudioInputList(settings.callAudioBackend());
|
2020-11-28 16:18:51 +00:00
|
|
|
const auto i = ranges::find(
|
|
|
|
list,
|
2021-01-07 15:27:11 +00:00
|
|
|
settings.callInputDeviceId(),
|
|
|
|
&AudioInput::id);
|
2020-11-28 16:18:51 +00:00
|
|
|
return (i != end(list))
|
|
|
|
? i->name
|
|
|
|
: tr::lng_settings_call_device_default(tr::now);
|
|
|
|
}
|
|
|
|
|
2021-02-01 13:51:01 +00:00
|
|
|
object_ptr<Ui::GenericBox> ChooseAudioOutputBox(
|
2020-11-29 18:26:49 +00:00
|
|
|
Fn<void(QString id, QString name)> chosen,
|
|
|
|
const style::Checkbox *st,
|
|
|
|
const style::Radio *radioSt) {
|
2021-01-07 15:27:11 +00:00
|
|
|
const auto &settings = Core::App().settings();
|
|
|
|
const auto list = GetAudioOutputList(settings.callAudioBackend());
|
2021-03-13 12:12:08 +00:00
|
|
|
const auto options = ranges::views::concat(
|
|
|
|
ranges::views::single(tr::lng_settings_call_device_default(tr::now)),
|
|
|
|
list | ranges::views::transform(&AudioOutput::name)
|
2020-11-28 16:18:51 +00:00
|
|
|
) | ranges::to_vector;
|
|
|
|
const auto i = ranges::find(
|
2021-01-07 15:27:11 +00:00
|
|
|
list,
|
|
|
|
settings.callOutputDeviceId(),
|
|
|
|
&AudioOutput::id);
|
|
|
|
const auto currentOption = (i != end(list))
|
|
|
|
? int(i - begin(list) + 1)
|
2020-11-28 16:18:51 +00:00
|
|
|
: 0;
|
|
|
|
const auto save = [=](int option) {
|
|
|
|
const auto deviceId = option
|
2021-01-07 15:27:11 +00:00
|
|
|
? list[option - 1].id
|
2020-11-28 16:18:51 +00:00
|
|
|
: "default";
|
|
|
|
Core::App().calls().setCurrentAudioDevice(false, deviceId);
|
|
|
|
chosen(deviceId, options[option]);
|
|
|
|
};
|
2021-02-01 13:51:01 +00:00
|
|
|
return Box([=](not_null<Ui::GenericBox*> box) {
|
|
|
|
SingleChoiceBox(box, {
|
|
|
|
.title = tr::lng_settings_call_output_device(),
|
|
|
|
.options = options,
|
|
|
|
.initialSelection = currentOption,
|
|
|
|
.callback = save,
|
|
|
|
.st = st,
|
|
|
|
.radioSt = radioSt,
|
|
|
|
});
|
|
|
|
});
|
2020-11-28 16:18:51 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 13:51:01 +00:00
|
|
|
object_ptr<Ui::GenericBox> ChooseAudioInputBox(
|
2020-11-29 18:26:49 +00:00
|
|
|
Fn<void(QString id, QString name)> chosen,
|
|
|
|
const style::Checkbox *st,
|
|
|
|
const style::Radio *radioSt) {
|
2021-01-07 15:27:11 +00:00
|
|
|
const auto &settings = Core::App().settings();
|
|
|
|
const auto list = GetAudioInputList(settings.callAudioBackend());
|
2021-03-13 12:12:08 +00:00
|
|
|
const auto options = ranges::views::concat(
|
|
|
|
ranges::views::single(tr::lng_settings_call_device_default(tr::now)),
|
|
|
|
list | ranges::views::transform(&AudioInput::name)
|
2020-11-28 16:18:51 +00:00
|
|
|
) | ranges::to_vector;
|
|
|
|
const auto i = ranges::find(
|
2021-01-07 15:27:11 +00:00
|
|
|
list,
|
2020-11-28 16:18:51 +00:00
|
|
|
Core::App().settings().callInputDeviceId(),
|
2021-01-07 15:27:11 +00:00
|
|
|
&AudioInput::id);
|
|
|
|
const auto currentOption = (i != end(list))
|
|
|
|
? int(i - begin(list) + 1)
|
2020-11-28 16:18:51 +00:00
|
|
|
: 0;
|
|
|
|
const auto save = [=](int option) {
|
|
|
|
const auto deviceId = option
|
2021-01-07 15:27:11 +00:00
|
|
|
? list[option - 1].id
|
2020-11-28 16:18:51 +00:00
|
|
|
: "default";
|
|
|
|
Core::App().calls().setCurrentAudioDevice(true, deviceId);
|
|
|
|
chosen(deviceId, options[option]);
|
|
|
|
};
|
2021-02-01 13:51:01 +00:00
|
|
|
return Box([=](not_null<Ui::GenericBox*> box) {
|
|
|
|
SingleChoiceBox(box, {
|
|
|
|
.title = tr::lng_settings_call_input_device(),
|
|
|
|
.options = options,
|
|
|
|
.initialSelection = currentOption,
|
|
|
|
.callback = save,
|
|
|
|
.st = st,
|
|
|
|
.radioSt = radioSt,
|
|
|
|
});
|
|
|
|
});
|
2020-11-28 16:18:51 +00:00
|
|
|
}
|
2021-02-01 13:51:01 +00:00
|
|
|
//
|
|
|
|
//object_ptr<Ui::GenericBox> ChooseAudioBackendBox(
|
2021-01-21 15:57:12 +00:00
|
|
|
// const style::Checkbox *st,
|
|
|
|
// const style::Radio *radioSt) {
|
|
|
|
// const auto &settings = Core::App().settings();
|
|
|
|
// const auto list = GetAudioInputList(settings.callAudioBackend());
|
|
|
|
// const auto options = std::vector<QString>{
|
|
|
|
// "OpenAL",
|
|
|
|
// "Webrtc ADM",
|
|
|
|
//#ifdef Q_OS_WIN
|
|
|
|
// "Webrtc ADM2",
|
|
|
|
//#endif // Q_OS_WIN
|
|
|
|
// };
|
|
|
|
// const auto currentOption = static_cast<int>(settings.callAudioBackend());
|
|
|
|
// const auto save = [=](int option) {
|
|
|
|
// Core::App().settings().setCallAudioBackend(
|
|
|
|
// static_cast<Webrtc::Backend>(option));
|
|
|
|
// Core::App().saveSettings();
|
|
|
|
// App::restart();
|
|
|
|
// };
|
2021-02-01 13:51:01 +00:00
|
|
|
// return Box([=](not_null<Ui::GenericBox*> box) {
|
|
|
|
// SingleChoiceBox(box, {
|
|
|
|
// .title = rpl::single<QString>("Calls audio backend"),
|
|
|
|
// .options = options,
|
|
|
|
// .initialSelection = currentOption,
|
|
|
|
// .callback = save,
|
|
|
|
// .st = st,
|
|
|
|
// .radioSt = radioSt,
|
|
|
|
// });
|
|
|
|
// });
|
2021-01-21 15:57:12 +00:00
|
|
|
//}
|
2021-01-07 15:27:11 +00:00
|
|
|
|
2019-01-05 11:08:02 +00:00
|
|
|
} // namespace Settings
|
|
|
|
|