From 20ba8e6192ca88f4f25bdd79656e0b321444bd8f Mon Sep 17 00:00:00 2001 From: "Tux3 / Mlkj / !Lev.uXFMLA" Date: Sun, 16 Nov 2014 16:41:30 +0100 Subject: [PATCH] Allow to change i/o audio devices without restart Still needs to restart the calls for now Fixes #713 --- src/core.cpp | 50 +++++++++++++++++++++++++++++ src/core.h | 3 ++ src/coreav.cpp | 5 +-- src/widget/form/settings/avform.cpp | 3 ++ 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/core.cpp b/src/core.cpp index e08bd464d..5b33361ed 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -1873,3 +1873,53 @@ void Core::setNospam(uint32_t nospam) std::reverse(nspm, nspm + 4); tox_set_nospam(tox, nospam); } + +void Core::useAudioInput(const QString& inDevDescr) +{ + auto* tmp = alInDev; + alInDev = nullptr; + alcCaptureCloseDevice(tmp); + int stereoFlag = av_DefaultSettings.audio_channels==1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16; + if (inDevDescr.isEmpty()) + alInDev = alcCaptureOpenDevice(nullptr,av_DefaultSettings.audio_sample_rate, stereoFlag, + (av_DefaultSettings.audio_frame_duration * av_DefaultSettings.audio_sample_rate * 4) + / 1000 * av_DefaultSettings.audio_channels); + else + alInDev = alcCaptureOpenDevice(inDevDescr.toStdString().c_str(),av_DefaultSettings.audio_sample_rate, stereoFlag, + (av_DefaultSettings.audio_frame_duration * av_DefaultSettings.audio_sample_rate * 4) + / 1000 * av_DefaultSettings.audio_channels); + if (!alInDev) + qWarning() << "Core: Cannot open input audio device"; + else + qDebug() << "Core: Opening audio input "<start(); return; @@ -641,6 +641,7 @@ void Core::leaveGroupCall(int groupId) disconnect(groupCalls[groupId].sendAudioTimer,0,0,0); groupCalls[groupId].sendAudioTimer->stop(); alcCaptureStop(alInDev); + groupCalls[groupId].alSources.clear(); } void Core::sendGroupCallAudio(int groupId, ToxAv* toxav) @@ -648,7 +649,7 @@ void Core::sendGroupCallAudio(int groupId, ToxAv* toxav) if (!groupCalls[groupId].active) return; - if (groupCalls[groupId].muteMic) + if (groupCalls[groupId].muteMic || !alInDev) { groupCalls[groupId].sendAudioTimer->start(); return; diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index 2a658f218..c4920291b 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -17,6 +17,7 @@ #include "avform.h" #include "ui_avsettings.h" #include "src/misc/settings.h" +#include "src/core.h" #if defined(__APPLE__) && defined(__MACH__) #include @@ -179,9 +180,11 @@ void AVForm::getAudioOutDevices() void AVForm::onInDevChanged(const QString &deviceDescriptor) { Settings::getInstance().setInDev(deviceDescriptor); + Core::getInstance()->useAudioInput(deviceDescriptor); } void AVForm::onOutDevChanged(const QString& deviceDescriptor) { Settings::getInstance().setOutDev(deviceDescriptor); + Core::getInstance()->useAudioOutput(deviceDescriptor); }