summaryrefslogtreecommitdiffstats
path: root/pica-client/dialogs
diff options
context:
space:
mode:
authorAnton <anton@picapica.im>2026-11-29 23:38:25 +0400
committerAnton <anton@picapica.im>2026-11-29 23:38:25 +0400
commit56863d74399c8d7354a00bc8ddc87b924ef870ab (patch)
treebd9e44c438f974f80aa6cfef59fe842d3e128ee7 /pica-client/dialogs
parentd6ce3a2226bda81cce96c61f0a73fb1516adbd0b (diff)
downloadpica-pica-call_quality_presets.tar.gz
pica-pica-call_quality_presets.zip
pica-client: new presets tab, call quality presetscall_quality_presets
Diffstat (limited to 'pica-client/dialogs')
-rw-r--r--pica-client/dialogs/settingsdialog.cpp255
-rw-r--r--pica-client/dialogs/settingsdialog.h27
2 files changed, 276 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));
diff --git a/pica-client/dialogs/settingsdialog.h b/pica-client/dialogs/settingsdialog.h
index d5b624c..3525cbf 100644
--- a/pica-client/dialogs/settingsdialog.h
+++ b/pica-client/dialogs/settingsdialog.h
@@ -96,6 +96,27 @@ private:
// told the user why, if it cannot be.
bool validateAddrTable();
+ // "Call quality" on the "Presets" tab, see CallQualityPreset.
+ QRadioButton *rbQualityMax;
+ QRadioButton *rbQualityAdaptive;
+ QRadioButton *rbQualityEconomy;
+ QRadioButton *rbQualityCustom;
+ // What the selected preset comes to on this machine with the selected
+ // camera, and which hardware encoders work. Null until built, which is
+ // after the camera lists that refresh it.
+ QLabel *lbQualitySummary;
+ // The hardware encoder probe has been asked of testCam's thread.
+ bool hwProbeRequested;
+ // Say on the tabs the custom settings live on that a preset is deciding
+ // them instead.
+ QLabel *lbCallPresetHint;
+ QLabel *lbVideoPresetHint;
+
+ CallQualityPreset selectedQualityPreset() const;
+ // Enables what only the Custom preset uses, and disables it otherwise.
+ void updateCallQualityWidgets();
+ void updateCallQualitySummary();
+
QRadioButton *rbMLPProhibit;
QRadioButton *rbMLPReplace;
QRadioButton *rbMLPAllowMultiple;
@@ -147,6 +168,10 @@ private:
QComboBox *callAudioCodec;
QSpinBox *callVideoBitrate;
QSpinBox *callAudioBitrate;
+ // Holds the four above, and is disabled with a preset other than Custom.
+ // Whether callAudioBitrate is disabled on its own account - a fixed rate
+ // codec - is told by isEnabledTo(callCustomBox), see audioBitrateKbps.
+ QWidget *callCustomBox;
// "Maximum incoming video resolution": the recommended resolution a call
// sends to the peer in 0x70/0x71, see IncomingVideoLimit. The combo box
@@ -355,6 +380,8 @@ private slots:
// Greys out the audio bitrate box for a codec whose bitrate is not ours to
// choose - see audioBitrateKbps.
void callAudioCodecChanged();
+ void callQualityChanged();
+ void hardwareEncodersProbed();
// Device names are driver specific, so all three lists have to be filled
// again when the driver changes. Only ever connected on Linux.
void audioDriverChanged(int index);