summaryrefslogtreecommitdiffstats
path: root/pica-client/audiovideocallcontroller.cpp
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/audiovideocallcontroller.cpp
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/audiovideocallcontroller.cpp')
-rw-r--r--pica-client/audiovideocallcontroller.cpp57
1 files changed, 51 insertions, 6 deletions
diff --git a/pica-client/audiovideocallcontroller.cpp b/pica-client/audiovideocallcontroller.cpp
index 55bcf3a..5a79c06 100644
--- a/pica-client/audiovideocallcontroller.cpp
+++ b/pica-client/audiovideocallcontroller.cpp
@@ -19,6 +19,7 @@
#include "skynet.h"
#include "settings.h"
#include "callsettings.h"
+#include "callquality.h"
#include "accounts.h"
#include <QByteArray>
#include <QDebug>
@@ -49,6 +50,7 @@ AudioVideoCallController::AudioVideoCallController(QObject *parent)
connect(skynet, SIGNAL(IncomingVideoPacket(QByteArray,quint16,quint32,QByteArray)), this, SLOT(incoming_video_packet(QByteArray,quint16,quint32,QByteArray)));
connect(skynet, SIGNAL(CallMediaTransportChanged(QByteArray,bool,QString,quint32)), this, SLOT(media_transport_changed(QByteArray,bool,QString,quint32)));
+ connect(skynet, SIGNAL(CallReceptionReported(QByteArray,CallReceptionReport)), this, SLOT(reception_reported(QByteArray,CallReceptionReport)));
// Earpiece tones (ringback/busy/unreachable) and the incoming call bell
// are played by two TonePlayer instances, each living on its own
@@ -87,8 +89,15 @@ AudioVideoCallController::AudioVideoCallController(QObject *parent)
cam->moveToThread(&cam_thread);
connect(cam, SIGNAL(captureStarted(QString,int,int,double)), this, SLOT(video_capture_started(QString,int,int,double)));
connect(cam, SIGNAL(packetReady(QByteArray,bool)), this, SLOT(send_video_packet(QByteArray,bool)));
+ connect(cam, SIGNAL(streamChanged(QString,int,int)), this, SLOT(video_stream_changed(QString,int,int)));
cam_thread.start();
+ // The presets choose among the hardware encoders that work, which takes
+ // opening each of them to find out. Done now, on the camera's thread,
+ // rather than holding up the first call's video.
+ if (CallSettings::load().qualityPreset != CallQualityCustom)
+ QMetaObject::invokeMethod(cam, "probeHardwareEncoders", Qt::QueuedConnection);
+
remotevideo = new VideoDevice();
remotevideo->moveToThread(&remotevideo_thread);
remotevideo_thread.start();
@@ -167,7 +176,8 @@ void AudioVideoCallController::startAudioPipeline()
{
Settings st(config_dbname);
QString capDev = st.loadValue("audio.capture_device", "default").toString();
- const CallSettings cs = CallSettings::load();
+ // The stored codec and bitrate, or the preset's.
+ const CallAudioPlan audio = callPlanAudio(CallSettings::load());
// What we capture and encode at, announced to the peer in the 0x74
// message. It follows from the codec - see callAudioSampleRate().
@@ -175,12 +185,12 @@ void AudioVideoCallController::startAudioPipeline()
// The playback direction is NOT this: it follows whatever the peer
// announces in its own 0x74 (see incoming_audio_params()), so a call with
// a peer that picked a different codec or rate keeps working.
- const int sampleRate = callAudioSampleRate(cs.audioCodec);
+ const int sampleRate = callAudioSampleRate(audio.codec);
// G.722 and A-law spend a fixed number of bits per sample and have no rate
// to ask for; the setting only means anything to Opus.
- const int bitrate = callAudioBitrateAdjustable(cs.audioCodec)
- ? cs.audioBitrateKbps * 1000
+ const int bitrate = callAudioBitrateAdjustable(audio.codec)
+ ? audio.bitrateKbps * 1000
: 0;
m_audioSeq = 0;
@@ -227,10 +237,10 @@ void AudioVideoCallController::startAudioPipeline()
// encoding right away - the peer's decoder is only ready once it has
// processed this 0x74 message, but since the call is carried over TCP,
// packets sent immediately after are guaranteed to arrive after it.
- skynet->SendAudioParams(m_peer_id, cs.audioCodec, (quint16)sampleRate);
+ skynet->SendAudioParams(m_peer_id, audio.codec, (quint16)sampleRate);
QMetaObject::invokeMethod(microphone, "configureCapture", Qt::QueuedConnection,
- Q_ARG(QString, capDev), Q_ARG(QString, cs.audioCodec),
+ Q_ARG(QString, capDev), Q_ARG(QString, audio.codec),
Q_ARG(int, sampleRate), Q_ARG(int, bitrate),
Q_ARG(QByteArray, m_caller_id), Q_ARG(QByteArray, m_callee_id));
QMetaObject::invokeMethod(microphone, "Capture", Qt::QueuedConnection);
@@ -268,6 +278,7 @@ void AudioVideoCallController::startVideoPipeline()
// Before anything is queued for them - see MediaCallSession. And before
// the check for a camera below: remotevideo does not depend on having one.
m_videoPlaybackStarted = false;
+ m_remoteVideoCodec.clear();
cam->openSession(m_caller_id, m_callee_id);
remotevideo->openSession(m_caller_id, m_callee_id);
@@ -323,6 +334,10 @@ void AudioVideoCallController::startVideoPipeline()
QMetaObject::invokeMethod(cam, "limitCaptureSize", Qt::QueuedConnection,
Q_ARG(int, m_peerRecommendedResolution.width()),
Q_ARG(int, m_peerRecommendedResolution.height()));
+ // Anything but Custom replaces most of what configureCapture() was just
+ // given, within that limit - see VideoDevice::setQualityPreset().
+ QMetaObject::invokeMethod(cam, "setQualityPreset", Qt::QueuedConnection,
+ Q_ARG(int, (int)cs.qualityPreset));
QMetaObject::invokeMethod(cam, "Capture", Qt::QueuedConnection);
// remotevideo is configured lazily, once the peer's own 0x75 (see
@@ -669,6 +684,24 @@ void AudioVideoCallController::video_capture_started(QString codec, int width, i
skynet->SendVideoParams(m_peer_id, codec, (quint16)width, (quint16)height);
}
+void AudioVideoCallController::video_stream_changed(QString codec, int width, int height)
+{
+ if (m_state != CallActive)
+ return;
+
+ skynet->SendVideoParams(m_peer_id, codec, (quint16)width, (quint16)height);
+}
+
+void AudioVideoCallController::reception_reported(QByteArray peer_id, CallReceptionReport report)
+{
+ if (m_state != CallActive || peer_id != m_peer_id)
+ return;
+
+ // Direct call, not invokeMethod()/QueuedConnection - cam's thread is
+ // blocked inside Capture(), see stopAudioPipeline().
+ cam->reportReception(report);
+}
+
void AudioVideoCallController::send_video_packet(QByteArray data, bool is_last_fragment)
{
if (m_state != CallActive)
@@ -742,16 +775,28 @@ void AudioVideoCallController::incoming_video_params(QByteArray peer_id, QString
if (!m_videoPlaybackStarted)
{
m_videoPlaybackStarted = true;
+ m_remoteVideoCodec = codec;
QMetaObject::invokeMethod(remotevideo, "configurePlayback", Qt::QueuedConnection,
Q_ARG(QString, codec), Q_ARG(int, (int)width), Q_ARG(int, (int)height),
Q_ARG(int, cs.videoDecodingAcceleration), Q_ARG(bool, vaapiRendering),
Q_ARG(QByteArray, m_caller_id), Q_ARG(QByteArray, m_callee_id));
}
+ else if (codec == m_remoteVideoCodec)
+ {
+ // Only the picture size changed - the peer's adaptive quality stepping
+ // up or down. The decoder takes the size from the stream itself and
+ // follows it at the keyframe the new size starts with; restarting it
+ // would drop that keyframe along with whatever is queued, and leave
+ // the picture frozen until the next one. Nothing to restart Play()
+ // for either.
+ return;
+ }
else
{
// The peer changed what it is sending in the middle of the call - as
// in incoming_audio_params(). A fragment of a frame in the old format
// that is still being put together is of no use to the new decoder.
+ m_remoteVideoCodec = codec;
m_videoAssembler.reset();
remotevideo->changePlayback(codec, (int)width, (int)height,
cs.videoDecodingAcceleration, vaapiRendering);