From ac03de66635963a787cfddf39256512044bb161c Mon Sep 17 00:00:00 2001 From: Gaelle Braud Date: Thu, 13 Nov 2025 12:51:39 +0100 Subject: [PATCH] update audio device when changed automatically in sdk --- Linphone/model/call/CallModel.cpp | 1 + Linphone/model/core/CoreModel.cpp | 9 +++++++ Linphone/model/core/CoreModel.hpp | 6 +++++ Linphone/model/setting/SettingsModel.cpp | 34 +++++++++++++++++++++++- Linphone/model/setting/SettingsModel.hpp | 1 + 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/Linphone/model/call/CallModel.cpp b/Linphone/model/call/CallModel.cpp index a753b377e..900d45729 100644 --- a/Linphone/model/call/CallModel.cpp +++ b/Linphone/model/call/CallModel.cpp @@ -491,6 +491,7 @@ void CallModel::onVideoDisplayErrorOccurred(const std::shared_ptr &call, const std::shared_ptr &audioDevice) { + lInfo() << log().arg("audio device changed"); emit audioDeviceChanged(call, audioDevice); } diff --git a/Linphone/model/core/CoreModel.cpp b/Linphone/model/core/CoreModel.cpp index 226d47c97..6ac9f2207 100644 --- a/Linphone/model/core/CoreModel.cpp +++ b/Linphone/model/core/CoreModel.cpp @@ -626,3 +626,12 @@ void CoreModel::onFriendListRemoved(const std::shared_ptr &core, } */ } + +void CoreModel::onAudioDevicesListUpdated(const std::shared_ptr &core) { + emit audioDevicesListUpdated(core); +} + +void CoreModel::onAudioDeviceChanged(const std::shared_ptr &core, + const std::shared_ptr &device) { + emit audioDeviceChanged(core, device); +} \ No newline at end of file diff --git a/Linphone/model/core/CoreModel.hpp b/Linphone/model/core/CoreModel.hpp index 0bbc46c82..94caad489 100644 --- a/Linphone/model/core/CoreModel.hpp +++ b/Linphone/model/core/CoreModel.hpp @@ -206,6 +206,9 @@ private: const std::string &url) override; virtual void onFriendListRemoved(const std::shared_ptr &core, const std::shared_ptr &friendList) override; + virtual void onAudioDevicesListUpdated(const std::shared_ptr &core) override; + virtual void onAudioDeviceChanged(const std::shared_ptr &core, + const std::shared_ptr &device) override; signals: void accountAdded(const std::shared_ptr &core, const std::shared_ptr &account); @@ -289,6 +292,9 @@ signals: bool checkRequestedByUser); void friendListRemoved(const std::shared_ptr &core, const std::shared_ptr &friendList); + void audioDevicesListUpdated(const std::shared_ptr &core); + void audioDeviceChanged(const std::shared_ptr &core, + const std::shared_ptr &device); }; #endif diff --git a/Linphone/model/setting/SettingsModel.cpp b/Linphone/model/setting/SettingsModel.cpp index 79bd40b58..d88bfd0c6 100644 --- a/Linphone/model/setting/SettingsModel.cpp +++ b/Linphone/model/setting/SettingsModel.cpp @@ -81,6 +81,20 @@ SettingsModel::SettingsModel() { QObject::connect(CoreModel::getInstance().get(), &CoreModel::lastCallEnded, this, [this]() { if (mCaptureGraphListenerCount > 0) createCaptureGraph(); // Repair the capture graph }); + QObject::connect(CoreModel::getInstance().get(), &CoreModel::audioDevicesListUpdated, this, + [this](const std::shared_ptr &core) { + lInfo() << log().arg("audio device list updated"); + updateCallSettings(); + }); + QObject::connect( + CoreModel::getInstance().get(), &CoreModel::audioDeviceChanged, this, + [this](const std::shared_ptr &core, const std::shared_ptr &device) { + lInfo() << log().arg("audio device changed"); + if (device) lInfo() << "device :" << device->getDeviceName(); + emit playbackDeviceChanged(getPlaybackDevice()); + emit captureDeviceChanged(getCaptureDevice()); + emit ringerDeviceChanged(getRingerDevice()); + }); } SettingsModel::~SettingsModel() { @@ -173,9 +187,10 @@ void SettingsModel::stopCaptureGraph() { // Force a call on the 'detect' method of all audio filters, updating new or removed devices void SettingsModel::accessCallSettings() { - // Audio mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); startCaptureGraph(); + + // Audio CoreModel::getInstance()->getCore()->reloadSoundDevices(); emit captureDevicesChanged(getCaptureDevices()); emit playbackDevicesChanged(getPlaybackDevices()); @@ -191,6 +206,23 @@ void SettingsModel::accessCallSettings() { emit videoDevicesChanged(getVideoDevices()); } +void SettingsModel::updateCallSettings() { + mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); + + // Audio + emit captureDevicesChanged(getCaptureDevices()); + emit playbackDevicesChanged(getPlaybackDevices()); + emit playbackDeviceChanged(getPlaybackDevice()); + emit ringerDevicesChanged(getRingerDevices()); + emit ringerDeviceChanged(getRingerDevice()); + emit captureDeviceChanged(getCaptureDevice()); + emit playbackGainChanged(getPlaybackGain()); + emit captureGainChanged(getCaptureGain()); + + // Video + emit videoDevicesChanged(getVideoDevices()); +} + void SettingsModel::closeCallSettings() { mustBeInLinphoneThread(log().arg(Q_FUNC_INFO)); stopCaptureGraph(); diff --git a/Linphone/model/setting/SettingsModel.hpp b/Linphone/model/setting/SettingsModel.hpp index 416dbf954..25b57b2a7 100644 --- a/Linphone/model/setting/SettingsModel.hpp +++ b/Linphone/model/setting/SettingsModel.hpp @@ -70,6 +70,7 @@ public: bool getIsInCall() const; void accessCallSettings(); + void updateCallSettings(); void closeCallSettings(); void startCaptureGraph();