From 1d0e9f145b10ef23496802efb6e526462af88394 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Tue, 15 Oct 2024 13:30:59 +0200 Subject: [PATCH] Fix audio device selection by using the correct AudioDevice. Fix stats display (percent showing, units, and rounded value). --- Linphone/core/call/CallCore.cpp | 26 ++++++++---------- Linphone/model/setting/SettingsModel.cpp | 35 ++++++++---------------- Linphone/model/tool/ToolModel.cpp | 8 ++++-- Linphone/model/tool/ToolModel.hpp | 3 +- 4 files changed, 30 insertions(+), 42 deletions(-) diff --git a/Linphone/core/call/CallCore.cpp b/Linphone/core/call/CallCore.cpp index e135d321..790cc04e 100644 --- a/Linphone/core/call/CallCore.cpp +++ b/Linphone/core/call/CallCore.cpp @@ -345,9 +345,8 @@ void CallCore::setSelf(QSharedPointer me) { }); mCallModelConnection->makeConnectToCore(&CallCore::lSetInputAudioDevice, [this](QString id) { mCallModelConnection->invokeToModel([this, id]() { - if (auto device = ToolModel::findAudioDevice(id)) { - mCallModel->setInputAudioDevice(device); - } + auto device = ToolModel::findAudioDevice(id, linphone::AudioDevice::Capabilities::CapabilityRecord); + if (device) mCallModel->setInputAudioDevice(device); }); }); mCallModelConnection->makeConnectToModel(&CallModel::inputAudioDeviceChanged, [this](const std::string &id) { @@ -355,9 +354,8 @@ void CallCore::setSelf(QSharedPointer me) { }); mCallModelConnection->makeConnectToCore(&CallCore::lSetOutputAudioDevice, [this](QString id) { mCallModelConnection->invokeToModel([this, id]() { - if (auto device = ToolModel::findAudioDevice(id)) { - mCallModel->setOutputAudioDevice(device); - } + auto device = ToolModel::findAudioDevice(id, linphone::AudioDevice::Capabilities::CapabilityPlay); + if (device) mCallModel->setOutputAudioDevice(device); }); }); mCallModelConnection->makeConnectToModel(&CallModel::conferenceChanged, [this]() { @@ -410,12 +408,12 @@ void CallCore::setSelf(QSharedPointer me) { tr("Codec: %1 / %2 kHz").arg(Utils::coreStringToAppString(codecType)).arg(codecRate); auto linAudioStats = call->getAudioStats(); if (linAudioStats) { - audioStats.mBandwidth = tr("Bande passante : %1 %2 %3 %4") + audioStats.mBandwidth = tr("Bande passante : %1 %2 kbits/s %3 %4 kbits/s") .arg("↑") - .arg(linAudioStats->getUploadBandwidth()) + .arg(round(linAudioStats->getUploadBandwidth())) .arg("↓") - .arg(linAudioStats->getDownloadBandwidth()); - audioStats.mLossRate = tr("Taux de perte: %1 \% %2 \%") + .arg(round(linAudioStats->getDownloadBandwidth())); + audioStats.mLossRate = tr("Taux de perte: %1% %2%") .arg(linAudioStats->getSenderLossRate()) .arg(linAudioStats->getReceiverLossRate()); audioStats.mJitterBufferSize = @@ -432,12 +430,12 @@ void CallCore::setSelf(QSharedPointer me) { tr("Codec: %1 / %2 kHz").arg(Utils::coreStringToAppString(codecType)).arg(codecRate); auto linVideoStats = call->getVideoStats(); if (stats) { - videoStats.mBandwidth = tr("Bande passante : %1 %2 %3 %4") + videoStats.mBandwidth = tr("Bande passante : %1 %2 kbits/s %3 %4 kbits/s") .arg("↑") - .arg(linVideoStats->getUploadBandwidth()) + .arg(round(linVideoStats->getUploadBandwidth())) .arg("↓") - .arg(linVideoStats->getDownloadBandwidth()); - videoStats.mLossRate = tr("Taux de perte: %1 \% %2 \%") + .arg(round(linVideoStats->getDownloadBandwidth())); + videoStats.mLossRate = tr("Taux de perte: %1% %2%") .arg(linVideoStats->getSenderLossRate()) .arg(linVideoStats->getReceiverLossRate()); } diff --git a/Linphone/model/setting/SettingsModel.cpp b/Linphone/model/setting/SettingsModel.cpp index 697c2d86..1bdf05d4 100644 --- a/Linphone/model/setting/SettingsModel.cpp +++ b/Linphone/model/setting/SettingsModel.cpp @@ -293,14 +293,10 @@ QString SettingsModel::getCaptureDevice() const { void SettingsModel::setCaptureDevice(const QString &device) { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); - std::string devId = Utils::appStringToCoreString(device); - auto list = CoreModel::getInstance()->getCore()->getExtendedAudioDevices(); - auto audioDevice = - find_if(list.cbegin(), list.cend(), - [&](const std::shared_ptr &audioItem) { return audioItem->getId() == devId; }); - if (audioDevice != list.cend()) { - CoreModel::getInstance()->getCore()->setDefaultInputAudioDevice(*audioDevice); - CoreModel::getInstance()->getCore()->setInputAudioDevice(*audioDevice); + auto audioDevice = ToolModel::findAudioDevice(device, linphone::AudioDevice::Capabilities::CapabilityRecord); + if (audioDevice) { + CoreModel::getInstance()->getCore()->setDefaultInputAudioDevice(audioDevice); + CoreModel::getInstance()->getCore()->setInputAudioDevice(audioDevice); emit captureDeviceChanged(device); resetCaptureGraph(); } else qWarning() << "Cannot set Capture device. The ID cannot be matched with an existant device : " << device; @@ -317,15 +313,10 @@ QString SettingsModel::getPlaybackDevice() const { void SettingsModel::setPlaybackDevice(const QString &device) { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); - std::string devId = Utils::appStringToCoreString(device); - - auto list = CoreModel::getInstance()->getCore()->getExtendedAudioDevices(); - auto audioDevice = - find_if(list.cbegin(), list.cend(), - [&](const std::shared_ptr &audioItem) { return audioItem->getId() == devId; }); - if (audioDevice != list.cend()) { - CoreModel::getInstance()->getCore()->setDefaultOutputAudioDevice(*audioDevice); - CoreModel::getInstance()->getCore()->setOutputAudioDevice(*audioDevice); + auto audioDevice = ToolModel::findAudioDevice(device, linphone::AudioDevice::Capabilities::CapabilityPlay); + if (audioDevice) { + CoreModel::getInstance()->getCore()->setDefaultOutputAudioDevice(audioDevice); + CoreModel::getInstance()->getCore()->setOutputAudioDevice(audioDevice); emit playbackDeviceChanged(device); resetCaptureGraph(); } else qWarning() << "Cannot set Playback device. The ID cannot be matched with an existant device : " << device; @@ -340,14 +331,10 @@ QString SettingsModel::getRingerDevice() const { void SettingsModel::setRingerDevice(const QString &device) { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); - std::string devId = Utils::appStringToCoreString(device); + auto audioDevice = ToolModel::findAudioDevice(device, linphone::AudioDevice::Capabilities::CapabilityPlay); - auto list = CoreModel::getInstance()->getCore()->getExtendedAudioDevices(); - auto audioDevice = - find_if(list.cbegin(), list.cend(), - [&](const std::shared_ptr &audioItem) { return audioItem->getId() == devId; }); - if (audioDevice != list.cend()) { - CoreModel::getInstance()->getCore()->setRingerDevice(devId); + if (audioDevice) { + CoreModel::getInstance()->getCore()->setRingerDevice(audioDevice->getId()); emit ringerDeviceChanged(device); } else qWarning() << "Cannot set Ringer device. The ID cannot be matched with an existant device : " << device; } diff --git a/Linphone/model/tool/ToolModel.cpp b/Linphone/model/tool/ToolModel.cpp index 21f12236..19537d02 100644 --- a/Linphone/model/tool/ToolModel.cpp +++ b/Linphone/model/tool/ToolModel.cpp @@ -56,12 +56,14 @@ std::shared_ptr ToolModel::makeLinphoneNumber(const return linphoneNumber; } -std::shared_ptr ToolModel::findAudioDevice(const QString &id) { +std::shared_ptr ToolModel::findAudioDevice(const QString &id, + linphone::AudioDevice::Capabilities capability) { std::string devId = Utils::appStringToCoreString(id); auto devices = CoreModel::getInstance()->getCore()->getExtendedAudioDevices(); auto audioDevice = - find_if(devices.cbegin(), devices.cend(), - [&](const std::shared_ptr &audioItem) { return audioItem->getId() == devId; }); + find_if(devices.cbegin(), devices.cend(), [&](const std::shared_ptr &audioItem) { + return audioItem->hasCapability(capability) && audioItem->getId() == devId; + }); if (audioDevice != devices.cend()) { return *audioDevice; } diff --git a/Linphone/model/tool/ToolModel.hpp b/Linphone/model/tool/ToolModel.hpp index 363bd7c2..ba5057e5 100644 --- a/Linphone/model/tool/ToolModel.hpp +++ b/Linphone/model/tool/ToolModel.hpp @@ -36,7 +36,8 @@ public: static std::shared_ptr interpretUrl(const QString &address); static std::shared_ptr makeLinphoneNumber(const QString &label, const QString &number); - static std::shared_ptr findAudioDevice(const QString &id); + static std::shared_ptr findAudioDevice(const QString &id, + linphone::AudioDevice::Capabilities capability); static std::shared_ptr findAccount(const std::shared_ptr &address); static bool isMe(const QString &address); static bool isLocal(const QString &address);