From 6e172f2f0431ea9c062a56b1cfbc170b1840a2d2 Mon Sep 17 00:00:00 2001 From: Julien Wadel Date: Wed, 7 May 2025 15:30:03 +0200 Subject: [PATCH] Volumes sliders in settings now use hardware volumes and doesn't use internal software gains anymore. --- CHANGELOG.md | 2 +- .../src/components/core/CoreManager.cpp | 4 ++ .../src/components/settings/SettingsModel.cpp | 37 +++++++++++++------ .../src/components/settings/SettingsModel.hpp | 2 +- .../ui/views/App/Settings/SettingsAudio.qml | 10 +++-- 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88aef28f0..de423715c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Timezones and Windows fix. - Download the correct version of openH264 (2.2.0) - Avoid to register the account while activating it. -- Update SDK to 5.3.80 +- Volumes settings based on hardware volumes. Remove software gains. ### Added - Screen Sharing diff --git a/linphone-app/src/components/core/CoreManager.cpp b/linphone-app/src/components/core/CoreManager.cpp index 1c75faadf..f3b061c55 100644 --- a/linphone-app/src/components/core/CoreManager.cpp +++ b/linphone-app/src/components/core/CoreManager.cpp @@ -297,6 +297,10 @@ void CoreManager::createLinphoneCore (const QString &configPath) { } if( mCore->getAccountList().size() == 0) mCore->setLogCollectionUploadServerUrl(Constants::DefaultUploadLogsServer); + // These 2 API should not be used because they are only software and manage internal gains. + // Functions from 'Call' object or from the CaptureGraph must be used in order to impact the system volume. + mCore->setMicGainDb(0.0); + mCore->setPlaybackGainDb(0.0); } void CoreManager::updateUserAgent(){ diff --git a/linphone-app/src/components/settings/SettingsModel.cpp b/linphone-app/src/components/settings/SettingsModel.cpp index 44fa3c08e..69997b8a6 100644 --- a/linphone-app/src/components/settings/SettingsModel.cpp +++ b/linphone-app/src/components/settings/SettingsModel.cpp @@ -410,37 +410,50 @@ bool SettingsModel::getCaptureGraphRunning() { return mSimpleCaptureGraph && mSimpleCaptureGraph->isRunning() && !getIsInCall(); } -float SettingsModel::getMicVolume() { +float SettingsModel::getPlaybackGain() const { float v = 0.0; - if (mSimpleCaptureGraph && mSimpleCaptureGraph->isRunning()) { - v = mSimpleCaptureGraph->getCaptureVolume(); + v = mSimpleCaptureGraph->getPlaybackGain(); + }else{ + auto call = CoreManager::getInstance()->getCore()->getCurrentCall(); + if (call) v = call->getSpeakerVolumeGain(); } return v; } -float SettingsModel::getPlaybackGain() const { - float dbGain = CoreManager::getInstance()->getCore()->getPlaybackGainDb(); - return MediastreamerUtils::dbToLinear(dbGain); -} - void SettingsModel::setPlaybackGain(float gain) { float oldGain = getPlaybackGain(); - CoreManager::getInstance()->getCore()->setPlaybackGainDb(MediastreamerUtils::linearToDb(gain)); + auto call = CoreManager::getInstance()->getCore()->getCurrentCall(); + if (call) call->setSpeakerVolumeGain(gain); if (mSimpleCaptureGraph && mSimpleCaptureGraph->isRunning()) { mSimpleCaptureGraph->setPlaybackGain(gain); } if ((int)(oldGain * 1000) != (int)(gain * 1000)) emit playbackGainChanged(gain); } +float SettingsModel::getMicVolume() const { + float v = 0.0; + if (mSimpleCaptureGraph && mSimpleCaptureGraph->isRunning()) + v = mSimpleCaptureGraph->getCaptureVolume(); + return v; +} + float SettingsModel::getCaptureGain() const { - float dbGain = CoreManager::getInstance()->getCore()->getMicGainDb(); - return MediastreamerUtils::dbToLinear(dbGain); + float v = 0.0; + if (mSimpleCaptureGraph && mSimpleCaptureGraph->isRunning()) { + v = mSimpleCaptureGraph->getCaptureGain(); + }else{ + auto call = CoreManager::getInstance()->getCore()->getCurrentCall(); + if (call) v = call->getMicrophoneVolumeGain(); + } + return v; + } void SettingsModel::setCaptureGain(float gain) { float oldGain = getCaptureGain(); - CoreManager::getInstance()->getCore()->setMicGainDb(MediastreamerUtils::linearToDb(gain)); + auto call = CoreManager::getInstance()->getCore()->getCurrentCall(); + if (call) call->setMicrophoneVolumeGain(gain); if (mSimpleCaptureGraph && mSimpleCaptureGraph->isRunning()) { mSimpleCaptureGraph->setCaptureGain(gain); } diff --git a/linphone-app/src/components/settings/SettingsModel.hpp b/linphone-app/src/components/settings/SettingsModel.hpp index 447852a47..bc49b452e 100644 --- a/linphone-app/src/components/settings/SettingsModel.hpp +++ b/linphone-app/src/components/settings/SettingsModel.hpp @@ -382,7 +382,7 @@ public: void accessAudioSettings(); void closeAudioSettings(); - Q_INVOKABLE float getMicVolume(); + Q_INVOKABLE float getMicVolume() const; // Get realtime microphone volume float getPlaybackGain() const; void setPlaybackGain(float gain); diff --git a/linphone-app/ui/views/App/Settings/SettingsAudio.qml b/linphone-app/ui/views/App/Settings/SettingsAudio.qml index b091aa8ce..cf3864032 100644 --- a/linphone-app/ui/views/App/Settings/SettingsAudio.qml +++ b/linphone-app/ui/views/App/Settings/SettingsAudio.qml @@ -70,15 +70,16 @@ TabContainer { id: playbackSlider width: parent.width enabled: !SettingsModel.isInCall - - value: SettingsModel.playbackGain + onPositionChanged: SettingsModel.playbackGain = position + onVisibleChanged: value = SettingsModel.playbackGain ToolTip { parent: playbackSlider.handle visible: playbackSlider.pressed text: (playbackSlider.value * 100).toFixed(0) + " %" } + Component.onCompleted: value = SettingsModel.playbackGain } } } @@ -106,15 +107,16 @@ TabContainer { id: captureSlider width: parent.width enabled: !SettingsModel.isInCall - - value: SettingsModel.captureGain + onPositionChanged: SettingsModel.captureGain = position + onVisibleChanged: value = SettingsModel.captureGain ToolTip { parent: captureSlider.handle visible: captureSlider.pressed text: (captureSlider.value * 100).toFixed(0) + " %" } + Component.onCompleted: value = SettingsModel.captureGain } } }