1
0
Fork 0
mirror of https://git.jami.net/savoirfairelinux/jami-client-qt.git synced 2025-09-10 12:03:18 +02:00

audio-preview: synchronize start/stop calls off the UI thread

Use QThreadpool to queue the start and stop of the audio device preview.

Gitlab: #522
Change-Id: I476e754628e0d1e00475c0ead7f1421579683ada
This commit is contained in:
Andreas Traczyk 2021-09-13 11:00:18 -04:00 committed by Ming Rui Zhang
parent dc393c7ad0
commit f7ce4b69f6
6 changed files with 31 additions and 36 deletions

View file

@ -225,15 +225,15 @@ AvAdapter::stopSharing()
}
void
AvAdapter::startAudioMeter(bool async)
AvAdapter::startAudioMeter()
{
lrcInstance_->startAudioMeter(async);
lrcInstance_->startAudioMeter();
}
void
AvAdapter::stopAudioMeter(bool async)
AvAdapter::stopAudioMeter()
{
lrcInstance_->stopAudioMeter(async);
lrcInstance_->stopAudioMeter();
}
void

View file

@ -72,8 +72,8 @@ protected:
// Stop sharing the screen or file
Q_INVOKABLE void stopSharing();
Q_INVOKABLE void startAudioMeter(bool async);
Q_INVOKABLE void stopAudioMeter(bool async);
Q_INVOKABLE void startAudioMeter();
Q_INVOKABLE void stopAudioMeter();
private Q_SLOTS:
void onAudioDeviceEvent();

View file

@ -36,7 +36,9 @@ LRCInstance::LRCInstance(migrateCallback willMigrateCb,
: lrc_(std::make_unique<Lrc>(willMigrateCb, didMigrateCb, muteDring))
, renderer_(std::make_unique<RenderManager>(lrc_->getAVModel()))
, updateManager_(std::make_unique<UpdateManager>(updateUrl, connectivityMonitor, this))
, threadPool_(new QThreadPool(this))
{
threadPool_->setMaxThreadCount(1);
lrc_->holdConferences = false;
connect(this, &LRCInstance::currentAccountIdChanged, [this] {
@ -319,35 +321,25 @@ LRCInstance::subscribeToDebugReceived()
}
void
LRCInstance::startAudioMeter(bool async)
LRCInstance::startAudioMeter()
{
auto f = [this] {
threadPool_->start([this] {
if (!getActiveCalls().size()) {
avModel().startAudioDevice();
}
avModel().setAudioMeterState(true);
};
if (async) {
QtConcurrent::run(f);
} else {
f();
}
});
}
void
LRCInstance::stopAudioMeter(bool async)
LRCInstance::stopAudioMeter()
{
auto f = [this] {
threadPool_->start([this] {
if (!getActiveCalls().size()) {
avModel().stopAudioDevice();
}
avModel().setAudioMeterState(false);
};
if (async) {
QtConcurrent::run(f);
} else {
f();
}
});
}
QString

View file

@ -41,6 +41,7 @@
#include "api/newcallmodel.h"
#include <QObject>
#include <QThreadPool>
#include <memory>
@ -113,8 +114,8 @@ public:
const account::ConfProperties_t& getCurrAccConfig();
int indexOf(const QString& convId);
void startAudioMeter(bool async);
void stopAudioMeter(bool async);
void startAudioMeter();
void stopAudioMeter();
void monitor(bool continous);
@ -138,5 +139,7 @@ private:
MapStringString lastConferences_;
conversation::Info invalid {};
QThreadPool* threadPool_;
};
Q_DECLARE_METATYPE(LRCInstance*)

View file

@ -88,11 +88,11 @@ Control {
type: AudioDeviceModel.Type.Record
}
function accept(index) {
AvAdapter.stopAudioMeter(false)
AvAdapter.stopAudioMeter()
AVModel.setInputDevice(listModel.data(
listModel.index(index, 0),
AudioDeviceModel.RawDeviceName))
AvAdapter.startAudioMeter(false)
AvAdapter.startAudioMeter()
}
},
Action {
@ -105,11 +105,11 @@ Control {
type: AudioDeviceModel.Type.Playback
}
function accept(index) {
AvAdapter.stopAudioMeter(false)
AvAdapter.stopAudioMeter()
AVModel.setOutputDevice(listModel.data(
listModel.index(index, 0),
AudioDeviceModel.RawDeviceName))
AvAdapter.startAudioMeter(false)
AvAdapter.startAudioMeter()
}
},
Action {

View file

@ -75,11 +75,11 @@ ColumnLayout {
role: "DeviceName"
onIndexChanged: {
AvAdapter.stopAudioMeter(false)
AvAdapter.stopAudioMeter()
AVModel.setInputDevice(comboModel.data(
comboModel.index(modelIndex, 0),
AudioDeviceModel.RawDeviceName))
AvAdapter.startAudioMeter(false)
AvAdapter.startAudioMeter()
}
}
@ -114,11 +114,11 @@ ColumnLayout {
role: "DeviceName"
onIndexChanged: {
AvAdapter.stopAudioMeter(false)
AvAdapter.stopAudioMeter()
AVModel.setOutputDevice(comboModel.data(
comboModel.index(modelIndex, 0),
AudioDeviceModel.RawDeviceName))
AvAdapter.startAudioMeter(false)
AvAdapter.startAudioMeter()
}
}
@ -140,11 +140,11 @@ ColumnLayout {
role: "DeviceName"
onIndexChanged: {
AvAdapter.stopAudioMeter(false)
AvAdapter.stopAudioMeter()
AVModel.setRingtoneDevice(comboModel.data(
comboModel.index(modelIndex, 0),
AudioDeviceModel.RawDeviceName))
AvAdapter.startAudioMeter(false)
AvAdapter.startAudioMeter()
}
}
@ -164,11 +164,11 @@ ColumnLayout {
role: "ID_UTF8"
onIndexChanged: {
AvAdapter.stopAudioMeter(false)
AvAdapter.stopAudioMeter()
var selectedAudioManager = comboModel.data(
comboModel.index(modelIndex, 0), AudioManagerListModel.AudioManagerID)
AVModel.setAudioManager(selectedAudioManager)
AvAdapter.startAudioMeter(false)
AvAdapter.startAudioMeter()
populateAudioSettings()
}
}