1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Allow to change i/o audio devices without restart

Still needs to restart the calls for now

Fixes #713
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-11-16 16:41:30 +01:00
parent 8ed7f09803
commit 20ba8e6192
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
4 changed files with 59 additions and 2 deletions

View File

@ -1873,3 +1873,53 @@ void Core::setNospam(uint32_t nospam)
std::reverse(nspm, nspm + 4); std::reverse(nspm, nspm + 4);
tox_set_nospam(tox, nospam); 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 "<<inDevDescr;
}
void Core::useAudioOutput(const QString& outDevDescr)
{
auto* tmp = alOutDev;
alOutDev = nullptr;
alcCloseDevice(tmp);
if (outDevDescr.isEmpty())
alOutDev = alcOpenDevice(nullptr);
else
alOutDev = alcOpenDevice(outDevDescr.toStdString().c_str());
if (!alOutDev)
{
qWarning() << "Core: Cannot open output audio device";
}
else
{
alcDestroyContext(alContext);
alContext=alcCreateContext(alOutDev,nullptr);
if (!alcMakeContextCurrent(alContext))
{
qWarning() << "Core: Cannot create output audio context";
alcCloseDevice(alOutDev);
}
else
alGenSources(1, &alMainSource);
qDebug() << "Core: Opening audio output "<<outDevDescr;
}
}

View File

@ -76,6 +76,9 @@ public:
bool isPasswordSet(PasswordType passtype); bool isPasswordSet(PasswordType passtype);
bool isReady(); ///< Most of the API shouldn't be used until Core is ready, call start() first bool isReady(); ///< Most of the API shouldn't be used until Core is ready, call start() first
void useAudioInput(const QString &name);
void useAudioOutput(const QString &name);
public slots: public slots:
void start(); ///< Initializes the core, must be called before anything else void start(); ///< Initializes the core, must be called before anything else
void process(); ///< Processes toxcore events and ensure we stay connected, called by its own timer void process(); ///< Processes toxcore events and ensure we stay connected, called by its own timer

View File

@ -217,7 +217,7 @@ void Core::sendCallAudio(int callId, ToxAv* toxav)
if (!calls[callId].active) if (!calls[callId].active)
return; return;
if (calls[callId].muteMic) if (calls[callId].muteMic || !alInDev)
{ {
calls[callId].sendAudioTimer->start(); calls[callId].sendAudioTimer->start();
return; return;
@ -641,6 +641,7 @@ void Core::leaveGroupCall(int groupId)
disconnect(groupCalls[groupId].sendAudioTimer,0,0,0); disconnect(groupCalls[groupId].sendAudioTimer,0,0,0);
groupCalls[groupId].sendAudioTimer->stop(); groupCalls[groupId].sendAudioTimer->stop();
alcCaptureStop(alInDev); alcCaptureStop(alInDev);
groupCalls[groupId].alSources.clear();
} }
void Core::sendGroupCallAudio(int groupId, ToxAv* toxav) void Core::sendGroupCallAudio(int groupId, ToxAv* toxav)
@ -648,7 +649,7 @@ void Core::sendGroupCallAudio(int groupId, ToxAv* toxav)
if (!groupCalls[groupId].active) if (!groupCalls[groupId].active)
return; return;
if (groupCalls[groupId].muteMic) if (groupCalls[groupId].muteMic || !alInDev)
{ {
groupCalls[groupId].sendAudioTimer->start(); groupCalls[groupId].sendAudioTimer->start();
return; return;

View File

@ -17,6 +17,7 @@
#include "avform.h" #include "avform.h"
#include "ui_avsettings.h" #include "ui_avsettings.h"
#include "src/misc/settings.h" #include "src/misc/settings.h"
#include "src/core.h"
#if defined(__APPLE__) && defined(__MACH__) #if defined(__APPLE__) && defined(__MACH__)
#include <OpenAL/al.h> #include <OpenAL/al.h>
@ -179,9 +180,11 @@ void AVForm::getAudioOutDevices()
void AVForm::onInDevChanged(const QString &deviceDescriptor) void AVForm::onInDevChanged(const QString &deviceDescriptor)
{ {
Settings::getInstance().setInDev(deviceDescriptor); Settings::getInstance().setInDev(deviceDescriptor);
Core::getInstance()->useAudioInput(deviceDescriptor);
} }
void AVForm::onOutDevChanged(const QString& deviceDescriptor) void AVForm::onOutDevChanged(const QString& deviceDescriptor)
{ {
Settings::getInstance().setOutDev(deviceDescriptor); Settings::getInstance().setOutDev(deviceDescriptor);
Core::getInstance()->useAudioOutput(deviceDescriptor);
} }