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:
parent
8ed7f09803
commit
20ba8e6192
50
src/core.cpp
50
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 "<<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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,6 +76,9 @@ public:
|
|||
bool isPasswordSet(PasswordType passtype);
|
||||
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:
|
||||
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
|
||||
|
|
|
@ -217,7 +217,7 @@ void Core::sendCallAudio(int callId, ToxAv* toxav)
|
|||
if (!calls[callId].active)
|
||||
return;
|
||||
|
||||
if (calls[callId].muteMic)
|
||||
if (calls[callId].muteMic || !alInDev)
|
||||
{
|
||||
calls[callId].sendAudioTimer->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;
|
||||
|
|
|
@ -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 <OpenAL/al.h>
|
||||
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user