diff --git a/src/blackcore/audio/audiosettings.h b/src/blackcore/audio/audiosettings.h index 36d05b4ac..1f630c5ea 100644 --- a/src/blackcore/audio/audiosettings.h +++ b/src/blackcore/audio/audiosettings.h @@ -14,6 +14,7 @@ #include "blackmisc/settingscache.h" #include "blackmisc/audio/audiosettings.h" +#include namespace BlackCore { @@ -28,6 +29,21 @@ namespace BlackCore //! \copydoc BlackMisc::TSettingTrait::isValid static bool isValid(const BlackMisc::Audio::CSettings &value) { Q_UNUSED(value); return true; } }; + + //! Audio input device settings + struct TInputDevice : public BlackMisc::TSettingTrait + { + //! \copydoc BlackMisc::TSettingTrait::key + static const char *key() { return "audio/inputdevice"; } + }; + + //! Audio input device settings + struct TOutputDevice : public BlackMisc::TSettingTrait + { + //! \copydoc BlackMisc::TSettingTrait::key + static const char *key() { return "audio/outputdevice"; } + }; + } // ns } // ns diff --git a/src/blackcore/context/contextaudioimpl.cpp b/src/blackcore/context/contextaudioimpl.cpp index 6d016b3a4..8ef77973c 100644 --- a/src/blackcore/context/contextaudioimpl.cpp +++ b/src/blackcore/context/contextaudioimpl.cpp @@ -88,6 +88,8 @@ namespace BlackCore m_unusedVoiceChannels.push_back(m_channel2); m_selcalPlayer = new CSelcalPlayer(QAudioDeviceInfo::defaultOutputDevice(), this); + + changeDeviceSettings(); } CContextAudio *CContextAudio::registerWithDBus(CDBusServer *server) @@ -207,6 +209,10 @@ namespace BlackCore this->m_voiceInputDevice->setInputDevice(audioDevice); changed = true; } + if (m_inputDeviceSetting.get() != audioDevice.getName()) + { + m_inputDeviceSetting.set(audioDevice.getName()); + } } else { @@ -215,6 +221,10 @@ namespace BlackCore this->m_voiceOutputDevice->setOutputDevice(audioDevice); changed = true; } + if (m_outputDeviceSetting.get() != audioDevice.getName()) + { + m_outputDeviceSetting.set(audioDevice.getName()); + } } if (changed) @@ -549,6 +559,35 @@ namespace BlackCore emit this->changedVoiceRoomMembers(); } + void CContextAudio::changeDeviceSettings() + { + QString inputDeviceName = m_inputDeviceSetting.get(); + if (!inputDeviceName.isEmpty()) + { + for (auto device : m_voiceInputDevice->getInputDevices()) + { + if (device.getName() == inputDeviceName) + { + setCurrentAudioDevice(device); + break; + } + } + } + + QString outputDeviceName = m_outputDeviceSetting.get(); + if (!outputDeviceName.isEmpty()) + { + for (auto device : m_voiceOutputDevice->getOutputDevices()) + { + if (device.getName() == outputDeviceName) + { + setCurrentAudioDevice(device); + break; + } + } + } + } + QSharedPointer CContextAudio::getVoiceChannelBy(const CVoiceRoom &voiceRoom) { QSharedPointer voiceChannel; diff --git a/src/blackcore/context/contextaudioimpl.h b/src/blackcore/context/contextaudioimpl.h index f06ee8129..12bc61897 100644 --- a/src/blackcore/context/contextaudioimpl.h +++ b/src/blackcore/context/contextaudioimpl.h @@ -134,6 +134,8 @@ namespace BlackCore //! Connection in transition bool inTransitionState() const; + void changeDeviceSettings(); + //! Voice channel by room QSharedPointer getVoiceChannelBy(const BlackMisc::Audio::CVoiceRoom &voiceRoom); @@ -156,6 +158,8 @@ namespace BlackCore // settings BlackMisc::CSetting m_audioSettings { this }; + BlackMisc::CSetting m_inputDeviceSetting { this, &CContextAudio::changeDeviceSettings }; + BlackMisc::CSetting m_outputDeviceSetting { this, &CContextAudio::changeDeviceSettings }; }; } // namespace } // namespace