diff options
Diffstat (limited to 'pica-client/dialogs/settingsdialog.cpp')
| -rw-r--r-- | pica-client/dialogs/settingsdialog.cpp | 255 |
1 files changed, 249 insertions, 6 deletions
diff --git a/pica-client/dialogs/settingsdialog.cpp b/pica-client/dialogs/settingsdialog.cpp index 1698a97..b0eb6a5 100644 --- a/pica-client/dialogs/settingsdialog.cpp +++ b/pica-client/dialogs/settingsdialog.cpp @@ -20,6 +20,7 @@ #include "../audiodevice.h" #include "../videodevice.h" #include "../callsettings.h" +#include "../callquality.h" #include "../directc2csettings.h" #include "../../PICA_netconf.h" #include "../../PICA_proto.h" @@ -108,6 +109,11 @@ SettingsDialog::SettingsDialog(QWidget *parent) : videoRes = nullptr; videoFps = nullptr; + // Refreshed along with the camera's formats, which are filled before the + // Presets tab is built. + lbQualitySummary = nullptr; + hwProbeRequested = 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, // but the preview is built - and the layout that can resize it applied - @@ -129,6 +135,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) : QWidget* audiodevtab = new QWidget(0); QWidget* videodevtab = new QWidget(0); QWidget* calltab = new QWidget(0); + QWidget* presetstab = new QWidget(0); QVBoxLayout *directc2cLayout = new QVBoxLayout(); QVBoxLayout *multiloginlayout = new QVBoxLayout(); @@ -553,8 +560,14 @@ 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->setWordWrap(true); + videodevLayout->addWidget(videoDev); videodevLayout->addWidget(videoDevRefresh); + videodevLayout->addWidget(lbVideoPresetHint); videodevLayout->addLayout(videoFormatLayout); videodevLayout->addWidget(cbPreferCompressed); #ifdef HAVE_VAAPI @@ -723,13 +736,75 @@ SettingsDialog::SettingsDialog(QWidget *parent) : incomingVideoLayout->addLayout(incomingVideoCustomLayout); gbIncomingVideo->setLayout(incomingVideoLayout); - callLayout->addLayout(callFormLayout); + // A widget of its own so that a preset can disable the lot at once. + callCustomBox = new QWidget(this); + callFormLayout->setContentsMargins(0, 0, 0, 0); + callCustomBox->setLayout(callFormLayout); + + lbCallPresetHint = new QLabel(tr("The codecs and bitrates below are only used with the \"Custom\" " + "call quality preset - see the Presets tab."), this); + lbCallPresetHint->setWordWrap(true); + + callLayout->addWidget(lbCallPresetHint); + callLayout->addWidget(callCustomBox); callLayout->addWidget(lbCallHint); callLayout->addWidget(gbIncomingVideo); callLayout->addStretch(1); calltab->setLayout(callLayout); +//Presets + // Several settings at once, all over the other tabs. Parented to the group + // box for the same reason as the echo cancellation buttons. + QGroupBox *gbQuality = new QGroupBox(tr("Call quality"), this); + QVBoxLayout *qualityLayout = new QVBoxLayout(); + const int radioIndent = style()->pixelMetric(QStyle::PM_ExclusiveIndicatorWidth) + + style()->pixelMetric(QStyle::PM_RadioButtonLabelSpacing); + + // Each choice with what it does underneath, indented under its label. + auto addQualityChoice = [&](const QString &label, const QString &description) { + QRadioButton *rb = new QRadioButton(label, gbQuality); + QLabel *lb = new QLabel(description, gbQuality); + + lb->setWordWrap(true); + lb->setContentsMargins(radioIndent, 0, 0, 0); + lb->setEnabled(false); + qualityLayout->addWidget(rb); + qualityLayout->addWidget(lb); + connect(rb, SIGNAL(toggled(bool)), this, SLOT(callQualityChanged())); + + return rb; + }; + + rbQualityMax = addQualityChoice(tr("Max quality"), + tr("The largest picture and the highest frame rate the camera offers, within what the " + "other side asks for, at the bitrate that picture needs.")); + rbQualityAdaptive = addQualityChoice(tr("Adaptive"), + tr("Starts at up to 720p and follows the connection: the other side reports what it " + "receives, and the picture size and bitrate go down when packets get lost or delayed, " + "and back up as far as Max quality would go while the connection keeps up.")); + rbQualityEconomy = addQualityChoice(tr("Economy"), + tr("A small picture at a low frame rate and bitrate, encoded in H.264 on the GPU where " + "possible: the least CPU, battery and bandwidth.")); + rbQualityCustom = addQualityChoice(tr("Custom"), + tr("The codecs, bitrates, picture size, frame rate and hardware encoding set on the Call " + "Settings and Video Devices tabs.")); + + gbQuality->setLayout(qualityLayout); + + lbQualitySummary = new QLabel(this); + lbQualitySummary->setWordWrap(true); + lbQualitySummary->setTextInteractionFlags(Qt::TextSelectableByMouse); + + connect(testCam, SIGNAL(hardwareEncodersProbed()), this, SLOT(hardwareEncodersProbed())); + + QVBoxLayout *presetsLayout = new QVBoxLayout(); + presetsLayout->addWidget(gbQuality); + presetsLayout->addWidget(lbQualitySummary); + presetsLayout->addStretch(1); + presetstab->setLayout(presetsLayout); + + tabW->addTab(presetstab, tr("Presets")); tabW->addTab(directc2ctab, tr("Direct Connections")); tabW->addTab(multilogintab, tr("Multiple Logins")); tabW->addTab(audiodevtab, tr("Audio Devices")); @@ -869,9 +944,17 @@ void SettingsDialog::toggleAudioTest() // The codec selected on the "Call Settings" tab, at the rate a call with // it would run at - same as the video test, this exercises what the // current selections do rather than a fixed pipeline of its own. - const QString codec = callAudioCodec->itemData(callAudioCodec->currentIndex()).toString(); + // Or the preset's, with one selected. + CallSettings cs; + + cs.qualityPreset = selectedQualityPreset(); + cs.audioCodec = callAudioCodec->itemData(callAudioCodec->currentIndex()).toString(); + cs.audioBitrateKbps = callAudioBitrate->value(); + + const CallAudioPlan audio = callPlanAudio(cs); + const QString codec = audio.codec; const int rate = callAudioSampleRate(codec); - const int bitrate = callAudioBitrateAdjustable(codec) ? callAudioBitrate->value() * 1000 : 0; + const int bitrate = callAudioBitrateAdjustable(codec) ? audio.bitrateKbps * 1000 : 0; testMic->openSession(testSessionId(), testSessionId()); QMetaObject::invokeMethod(testMic, "configureCapture", Qt::QueuedConnection, @@ -1105,6 +1188,10 @@ void SettingsDialog::toggleVideoTest() Q_ARG(int, callVideoBitrate->value() * 1000), Q_ARG(int, selectedVideoEncodingAcceleration()), Q_ARG(QByteArray, testSessionId()), Q_ARG(QByteArray, testSessionId())); + // 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())); QMetaObject::invokeMethod(testCam, "Capture", Qt::QueuedConnection); // The decoder is only started once the camera has settled on a format, @@ -1531,6 +1618,9 @@ void SettingsDialog::fillVideoResolutions() videoRes->blockSignals(false); fillVideoFrameRates(); + + // What a preset makes of a camera depends on what the camera offers. + updateCallQualitySummary(); } void SettingsDialog::fillVideoFrameRates() @@ -1663,6 +1753,136 @@ int SettingsDialog::selectedVideoDecodingAcceleration() const return flags; } +CallQualityPreset SettingsDialog::selectedQualityPreset() const +{ + if (rbQualityMax->isChecked()) + return CallQualityMax; + if (rbQualityEconomy->isChecked()) + return CallQualityEconomy; + if (rbQualityCustom->isChecked()) + return CallQualityCustom; + + return CallQualityAdaptive; +} + +void SettingsDialog::callQualityChanged() +{ + // Each button's toggled() lands here, the one going off as well as the + // one going on; in between, none is checked. + if (!rbQualityMax->isChecked() && !rbQualityAdaptive->isChecked() && + !rbQualityEconomy->isChecked() && !rbQualityCustom->isChecked()) + return; + + updateCallQualityWidgets(); + updateCallQualitySummary(); +} + +void SettingsDialog::updateCallQualityWidgets() +{ + const bool custom = selectedQualityPreset() == CallQualityCustom; + + callCustomBox->setEnabled(custom); + videoRes->setEnabled(custom); + 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 + + lbCallPresetHint->setVisible(!custom); + lbVideoPresetHint->setVisible(!custom); +} + +static QString videoCodecDisplayName(const QString &codec) +{ + for (int i = 0; i < kCallVideoCodecCount; i++) + if (codec == QLatin1String(kCallVideoCodecs[i].name)) + return QLatin1String(kCallVideoCodecs[i].displayName); + + return codec; +} + +void SettingsDialog::updateCallQualitySummary() +{ + if (!lbQualitySummary) + return; + + const CallQualityPreset preset = selectedQualityPreset(); + QList<CallHardwareEncoder> hardware; + + if (!VideoDevice::HardwareEncodersProbed(&hardware)) + { + lbQualitySummary->setText(tr("Finding out which hardware video encoders work on this computer...")); + + // 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) + { + hwProbeRequested = true; + QMetaObject::invokeMethod(testCam, "probeHardwareEncoders", Qt::QueuedConnection); + } + + 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(", "))); + + if (preset != CallQualityCustom) + { + const CallVideoPlan video = callPlanVideo(preset, VideoDevice::CallCameraSizes(videoFormats), + QSize(0, 0), hardware); + CallSettings cs; + + cs.qualityPreset = preset; + + const CallAudioPlan audio = callPlanAudio(cs); + + text += QLatin1String("\n\n"); + text += tr("With the selected camera a call starts with %1 video encoded on the %2, %3x%4 " + "at %5 fps and %6 kbit/s, and Opus audio at %7 kbit/s.") + .arg(videoCodecDisplayName(video.codec), + video.acceleration ? tr("GPU") : tr("CPU")) + .arg(video.encodeSize.width()).arg(video.encodeSize.height()) + .arg(video.frameRate).arg(video.bitrateKbps).arg(audio.bitrateKbps); + + if (video.adaptive()) + text += QLatin1Char(' ') + tr("It goes as high as %1x%2 at %3 kbit/s and as low as %4x%5, " + "as the connection allows.") + .arg(video.captureSize.width()).arg(video.captureSize.height()) + .arg(video.maxBitrateKbps) + .arg(video.ladder.last().width()).arg(video.ladder.last().height()); + + text += QLatin1Char(' ') + tr("The other side can ask for a smaller picture."); + } + + lbQualitySummary->setText(text); +} + +void SettingsDialog::hardwareEncodersProbed() +{ + updateCallQualitySummary(); +} + void SettingsDialog::callAudioCodecChanged() { const QString codec = callAudioCodec->itemData(callAudioCodec->currentIndex()).toString(); @@ -1671,7 +1891,7 @@ void SettingsDialog::callAudioCodecChanged() { // Coming back from a fixed rate codec, whose rate is showing in the // box; the user's own choice is in audioBitrateKbps. - if (!callAudioBitrate->isEnabled()) + if (!callAudioBitrate->isEnabledTo(callCustomBox)) { callAudioBitrate->setEnabled(true); callAudioBitrate->setValue(audioBitrateKbps); @@ -1681,7 +1901,7 @@ void SettingsDialog::callAudioCodecChanged() return; } - if (callAudioBitrate->isEnabled()) + if (callAudioBitrate->isEnabledTo(callCustomBox)) audioBitrateKbps = callAudioBitrate->value(); // Show what the codec will actually run at rather than leaving a number @@ -2174,6 +2394,23 @@ void SettingsDialog::loadSettings() // actually changes - and the stored codec is often the one already showing. callAudioCodecChanged(); + switch (cs.qualityPreset) + { + case CallQualityMax: + rbQualityMax->setChecked(true); + break; + case CallQualityEconomy: + rbQualityEconomy->setChecked(true); + break; + case CallQualityCustom: + rbQualityCustom->setChecked(true); + break; + case CallQualityAdaptive: + default: + rbQualityAdaptive->setChecked(true); + break; + } + if (cs.incomingVideoLimit == IncomingVideoLimitCustom) rbIncomingVideoCustom->setChecked(true); else @@ -2237,6 +2474,9 @@ void SettingsDialog::loadSettings() int audioRingDevItem = audioRingDev->findData(audioRingDevVal); if (audioRingDevItem >= 0) audioRingDev->setCurrentIndex(audioRingDevItem); + + // Explicitly, for the same reason as callAudioCodecChanged() above. + callQualityChanged(); } void SettingsDialog::storeSettings() @@ -2294,6 +2534,9 @@ void SettingsDialog::storeSettings() st.storeValue("video.capture_framerate", QString::number(selectedVideoFrameRate())); st.storeValue("video.prefer_compressed", cbPreferCompressed->isChecked() ? "1" : "0"); + static const char * const kPresetKeys[] = { "max", "adaptive", "economy", "custom" }; + st.storeValue("call.quality_preset", kPresetKeys[selectedQualityPreset()]); + st.storeValue("call.video_codec", callVideoCodec->itemData(callVideoCodec->currentIndex()).toString()); st.storeValue("call.audio_codec", callAudioCodec->itemData(callAudioCodec->currentIndex()).toString()); st.storeValue("call.video_bitrate_kbps", QString::number(callVideoBitrate->value())); @@ -2301,7 +2544,7 @@ void SettingsDialog::storeSettings() // The box shows a fixed rate codec's own bitrate while such a codec is // selected; what gets stored is the user's choice either way, so that // switching back to Opus finds it again on the next visit. - if (callAudioBitrate->isEnabled()) + if (callAudioBitrate->isEnabledTo(callCustomBox)) audioBitrateKbps = callAudioBitrate->value(); st.storeValue("call.audio_bitrate_kbps", QString::number(audioBitrateKbps)); |
