diff options
Diffstat (limited to 'pica-client/dialogs/settingsdialog.cpp')
| -rw-r--r-- | pica-client/dialogs/settingsdialog.cpp | 308 |
1 files changed, 265 insertions, 43 deletions
diff --git a/pica-client/dialogs/settingsdialog.cpp b/pica-client/dialogs/settingsdialog.cpp index b0eb6a5..84ca651 100644 --- a/pica-client/dialogs/settingsdialog.cpp +++ b/pica-client/dialogs/settingsdialog.cpp @@ -40,6 +40,7 @@ #include <QEvent> #include <QTabWidget> #include <QTimer> +#include <QShowEvent> #include <QHeaderView> #include <QMessageBox> #include <QHostAddress> @@ -112,7 +113,12 @@ SettingsDialog::SettingsDialog(QWidget *parent) : // Refreshed along with the camera's formats, which are filled before the // Presets tab is built. lbQualitySummary = nullptr; - hwProbeRequested = false; + btHwProbe = nullptr; + hwProbeState = HwProbeIdle; + hwProbeSecondsLeft = 0; + hwProbeOffered = false; + hwProbeAccelerations = 0; + hwProbeCloseRequested = false; // Same problem, one step further along: videoPreview is watched for its own // resizes and answers them by telling testDecoder what size to decode to, @@ -129,6 +135,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QVBoxLayout *settingsLayout = new QVBoxLayout(); QTabWidget *tabW = new QTabWidget(this); + tabWidget = tabW; QWidget* directc2ctab = new QWidget(0); QWidget* soundstab = new QWidget(0); QWidget* multilogintab = new QWidget(0); @@ -136,6 +143,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QWidget* videodevtab = new QWidget(0); QWidget* calltab = new QWidget(0); QWidget* presetstab = new QWidget(0); + presetsTab = presetstab; QVBoxLayout *directc2cLayout = new QVBoxLayout(); QVBoxLayout *multiloginlayout = new QVBoxLayout(); @@ -560,9 +568,10 @@ SettingsDialog::SettingsDialog(QWidget *parent) : connect(videoPreviewGpu->widget(), SIGNAL(renderingFailed(QString)), this, SLOT(videoTestRenderFailed(QString))); #endif - lbVideoPresetHint = new QLabel(tr("The resolution, frame rate, compressed formats and hardware " - "encoding a call uses are chosen by the call quality preset. " - "Select \"Custom\" on the Presets tab to set them here."), this); + lbVideoPresetHint = new QLabel(tr("The resolution, frame rate and compressed formats a call uses " + "are chosen by the call quality preset. Select \"Custom\" on " + "the Presets tab to set them here. The preset encodes on the " + "GPU only where hardware encoding is enabled below."), this); lbVideoPresetHint->setWordWrap(true); videodevLayout->addWidget(videoDev); @@ -790,17 +799,36 @@ SettingsDialog::SettingsDialog(QWidget *parent) : tr("The codecs, bitrates, picture size, frame rate and hardware encoding set on the Call " "Settings and Video Devices tabs.")); - gbQuality->setLayout(qualityLayout); + btHwProbe = new QPushButton(gbQuality); + hwProbeTimer = new QTimer(this); + hwProbeTimer->setInterval(1000); + connect(btHwProbe, SIGNAL(clicked()), this, SLOT(hardwareProbeClicked())); + connect(hwProbeTimer, SIGNAL(timeout()), this, SLOT(hardwareProbeTick())); + connect(testCam, SIGNAL(hardwareEncoderProbed(QString,bool)), this, SLOT(hardwareEncoderProbed(QString,bool))); + connect(testCam, SIGNAL(hardwareEncodersProbed()), this, SLOT(hardwareEncodersProbed())); - lbQualitySummary = new QLabel(this); + // Nothing to probe in a build without hardware encoders. + btHwProbe->setVisible(!VideoDevice::HardwareEncodersBuiltIn().isEmpty()); + updateHardwareProbeButton(); + qualityLayout->addWidget(btHwProbe, 0, Qt::AlignLeft); + + lbQualitySummary = new QLabel(gbQuality); lbQualitySummary->setWordWrap(true); lbQualitySummary->setTextInteractionFlags(Qt::TextSelectableByMouse); + qualityLayout->addWidget(lbQualitySummary); - connect(testCam, SIGNAL(hardwareEncodersProbed()), this, SLOT(hardwareEncodersProbed())); + gbQuality->setLayout(qualityLayout); + + // Which GPU encoders a preset may use is up to these. + for (VideoAcceleration a : { VideoAccelerationVaapi, VideoAccelerationD3d12va, + VideoAccelerationMediaFoundation }) + { + if (QCheckBox *cb = encodingCheckBox(a)) + connect(cb, &QCheckBox::toggled, this, [this]() { updateCallQualitySummary(); }); + } QVBoxLayout *presetsLayout = new QVBoxLayout(); presetsLayout->addWidget(gbQuality); - presetsLayout->addWidget(lbQualitySummary); presetsLayout->addStretch(1); presetstab->setLayout(presetsLayout); @@ -811,6 +839,11 @@ SettingsDialog::SettingsDialog(QWidget *parent) : tabW->addTab(videodevtab, tr("Video Devices")); tabW->addTab(calltab, tr("Call Settings")); tabW->addTab(soundstab, tr("Sounds")); + // After the tabs are added: adding the first one makes it the current one. + connect(tabW, &QTabWidget::currentChanged, this, [this]() { + if (tabWidget->currentWidget() == presetsTab) + offerHardwareProbe(); + }); settingsLayout->addWidget(tabW); QHBoxLayout *buttonsLayout = new QHBoxLayout; @@ -1191,7 +1224,9 @@ void SettingsDialog::toggleVideoTest() // As a call with no limit from the other side would; Adaptive stays where // it starts, there being no peer to report back. QMetaObject::invokeMethod(testCam, "setQualityPreset", Qt::QueuedConnection, - Q_ARG(int, (int)selectedQualityPreset())); + Q_ARG(int, (int)selectedQualityPreset()), + Q_ARG(QStringList, VideoDevice::HardwareEncoderNames( + VideoDevice::PresetHardwareEncoders(selectedVideoEncodingAcceleration())))); QMetaObject::invokeMethod(testCam, "Capture", Qt::QueuedConnection); // The decoder is only started once the camera has settled on a format, @@ -1786,19 +1821,9 @@ void SettingsDialog::updateCallQualityWidgets() videoFps->setEnabled(custom); cbPreferCompressed->setEnabled(custom); - // The decoding side is left alone: what the peer sends is decoded the same - // whatever the preset. The encoding side is enabled only where - // offerAcceleration() did not grey it out to begin with. -#ifdef HAVE_VAAPI - cbVaapiEncoding->setEnabled(custom && VideoDevice::AccelerationBuiltIn(VideoAccelerationVaapi, true)); -#endif -#ifdef HAVE_D3D12VA - cbD3d12vaEncoding->setEnabled(custom && VideoDevice::AccelerationBuiltIn(VideoAccelerationD3d12va, true)); -#endif -#ifdef Q_OS_WIN - cbMediaFoundationEncoding->setEnabled(custom && - VideoDevice::AccelerationBuiltIn(VideoAccelerationMediaFoundation, true)); -#endif + // The acceleration checkboxes are left alone: the decoding side applies + // whatever the preset, and the encoding side says which GPU encoders a + // preset may use. lbCallPresetHint->setVisible(!custom); lbVideoPresetHint->setVisible(!custom); @@ -1819,36 +1844,38 @@ void SettingsDialog::updateCallQualitySummary() return; const CallQualityPreset preset = selectedQualityPreset(); - QList<CallHardwareEncoder> hardware; + const QList<CallHardwareEncoder> builtIn = VideoDevice::HardwareEncodersBuiltIn(); + QStringList encoders; - if (!VideoDevice::HardwareEncodersProbed(&hardware)) + for (int i = 0; i < builtIn.size(); i++) { - lbQualitySummary->setText(tr("Finding out which hardware video encoders work on this computer...")); + const CallHardwareEncoder &e = builtIn.at(i); + const QString name = QString(QLatin1String("%1 (%2)")) + .arg(videoCodecDisplayName(e.codec), e.encoder); - // On testCam's thread rather than here: it takes a while, and on - // Windows Media Foundation does not work on this thread. A video test - // that is running holds it up until it stops. - if (!hwProbeRequested) + switch (CallSettings::loadHardwareEncoderProbe(e.encoder)) { - hwProbeRequested = true; - QMetaObject::invokeMethod(testCam, "probeHardwareEncoders", Qt::QueuedConnection); + case HardwareEncoderWorks: + encoders << tr("%1 works").arg(name); + break; + case HardwareEncoderFailed: + encoders << tr("%1 does not work").arg(name); + break; + case HardwareEncoderNotProbed: + default: + encoders << tr("%1 not probed yet").arg(name); + break; } - - return; } - QStringList encoders; - - for (int i = 0; i < hardware.size(); i++) - encoders << QString(QLatin1String("%1 (%2)")) - .arg(videoCodecDisplayName(hardware.at(i).codec), hardware.at(i).encoder); - - QString text = tr("Hardware video encoders that work on this computer: %1.") - .arg(encoders.isEmpty() ? tr("none, video is encoded on the CPU") - : encoders.join(QLatin1String(", "))); + QString text = builtIn.isEmpty() + ? tr("This build has no hardware video encoders: video is encoded on the CPU.") + : tr("Hardware video encoders: %1.").arg(encoders.join(QLatin1String(", "))); if (preset != CallQualityCustom) { + const QList<CallHardwareEncoder> hardware = + VideoDevice::PresetHardwareEncoders(selectedVideoEncodingAcceleration()); const CallVideoPlan video = callPlanVideo(preset, VideoDevice::CallCameraSizes(videoFormats), QSize(0, 0), hardware); CallSettings cs; @@ -1878,9 +1905,183 @@ void SettingsDialog::updateCallQualitySummary() lbQualitySummary->setText(text); } +QCheckBox *SettingsDialog::encodingCheckBox(VideoAcceleration acceleration) const +{ + switch (acceleration) + { +#ifdef HAVE_VAAPI + case VideoAccelerationVaapi: + return cbVaapiEncoding; +#endif +#ifdef HAVE_D3D12VA + case VideoAccelerationD3d12va: + return cbD3d12vaEncoding; +#endif +#ifdef Q_OS_WIN + case VideoAccelerationMediaFoundation: + return cbMediaFoundationEncoding; +#endif + default: + return nullptr; + } +} + +void SettingsDialog::updateHardwareProbeButton() +{ + switch (hwProbeState) + { + case HwProbeCountdown: + btHwProbe->setText(hwProbeSecondsLeft == 1 + ? tr("Probing hardware acceleration capabilities in 1 second, press to cancel") + : tr("Probing hardware acceleration capabilities in %1 seconds, press to cancel") + .arg(hwProbeSecondsLeft)); + btHwProbe->setEnabled(true); + break; + + case HwProbeRunning: + btHwProbe->setText(tr("Probing hardware acceleration capabilities...")); + btHwProbe->setEnabled(false); + break; + + case HwProbeIdle: + default: + btHwProbe->setText(tr("Probe hardware acceleration capabilities")); + btHwProbe->setEnabled(true); + break; + } +} + +void SettingsDialog::offerHardwareProbe() +{ + if (hwProbeOffered || hwProbeState != HwProbeIdle) + return; + + hwProbeOffered = true; + + // Only encoders that were never probed: one recorded as not working may + // be the one that crashed the program last time. + const QList<CallHardwareEncoder> builtIn = VideoDevice::HardwareEncodersBuiltIn(); + bool unprobed = false; + + for (int i = 0; i < builtIn.size() && !unprobed; i++) + unprobed = CallSettings::loadHardwareEncoderProbe(builtIn.at(i).encoder) == HardwareEncoderNotProbed; + + if (!unprobed) + return; + + hwProbeState = HwProbeCountdown; + hwProbeSecondsLeft = 3; + hwProbeTimer->start(); + updateHardwareProbeButton(); +} + +void SettingsDialog::hardwareProbeTick() +{ + if (--hwProbeSecondsLeft > 0) + { + updateHardwareProbeButton(); + return; + } + + hwProbeTimer->stop(); + startHardwareProbe(true); +} + +void SettingsDialog::hardwareProbeClicked() +{ + if (hwProbeState == HwProbeCountdown) + { + hwProbeTimer->stop(); + hwProbeState = HwProbeIdle; + updateHardwareProbeButton(); + return; + } + + if (hwProbeState == HwProbeIdle) + startHardwareProbe(false); +} + +void SettingsDialog::startHardwareProbe(bool unprobedOnly) +{ + const QList<CallHardwareEncoder> builtIn = VideoDevice::HardwareEncodersBuiltIn(); + QStringList encoders; + + hwProbeAccelerations = 0; + + for (int i = 0; i < builtIn.size(); i++) + { + if (unprobedOnly && + CallSettings::loadHardwareEncoderProbe(builtIn.at(i).encoder) != HardwareEncoderNotProbed) + continue; + + encoders << builtIn.at(i).encoder; + hwProbeAccelerations |= builtIn.at(i).acceleration; + } + + if (encoders.isEmpty()) + { + hwProbeState = HwProbeIdle; + updateHardwareProbeButton(); + return; + } + + // All of them recorded as failed before any is opened: if a driver + // takes the program down, none of them is probed again by itself. + for (int i = 0; i < encoders.size(); i++) + CallSettings::storeHardwareEncoderProbe(encoders.at(i), false); + + // The probe runs on testCam's thread, which a running test keeps busy. + if (videoTestRunning) + stopVideoTest(); + + hwProbeState = HwProbeRunning; + updateHardwareProbeButton(); + // Storing the checkboxes now would store them as they were before the + // probe; see also reject(). + btOk->setEnabled(false); + + // On testCam's thread rather than here: it takes a while, and on Windows + // Media Foundation does not work on this thread. + QMetaObject::invokeMethod(testCam, "probeHardwareEncoders", Qt::QueuedConnection, + Q_ARG(QStringList, encoders)); +} + +void SettingsDialog::hardwareEncoderProbed(QString encoder, bool works) +{ + if (works) + CallSettings::storeHardwareEncoderProbe(encoder, true); +} + void SettingsDialog::hardwareEncodersProbed() { + const QList<CallHardwareEncoder> builtIn = VideoDevice::HardwareEncodersBuiltIn(); + + // Each acceleration that was probed is enabled if any of its encoders + // works, and disabled otherwise - the user can still tick it. + for (VideoAcceleration a : { VideoAccelerationVaapi, VideoAccelerationD3d12va, + VideoAccelerationMediaFoundation }) + { + QCheckBox *cb = encodingCheckBox(a); + bool works = false; + + if (!cb || !(hwProbeAccelerations & a) || !cb->isEnabled()) + continue; + + for (int i = 0; i < builtIn.size() && !works; i++) + works = builtIn.at(i).acceleration == a && + CallSettings::loadHardwareEncoderProbe(builtIn.at(i).encoder) == HardwareEncoderWorks; + + cb->setChecked(works); + } + + hwProbeState = HwProbeIdle; + hwProbeAccelerations = 0; + updateHardwareProbeButton(); + btOk->setEnabled(true); updateCallQualitySummary(); + + if (hwProbeCloseRequested) + reject(); } void SettingsDialog::callAudioCodecChanged() @@ -2280,13 +2481,34 @@ void SettingsDialog::OK() if (!validateAddrTable()) return; + hwProbeTimer->stop(); storeSettings(); done(1); } void SettingsDialog::Cancel() { - done(0); + reject(); +} + +void SettingsDialog::reject() +{ + if (hwProbeState == HwProbeRunning) + { + hwProbeCloseRequested = true; + return; + } + + hwProbeTimer->stop(); + QDialog::reject(); +} + +void SettingsDialog::showEvent(QShowEvent *event) +{ + QDialog::showEvent(event); + + if (tabWidget->currentWidget() == presetsTab) + offerHardwareProbe(); } void SettingsDialog::loadSettings() |
