mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Add None audio I/O devices
Can be changed in the middle of a call without problem
This commit is contained in:
parent
021049cfa7
commit
5c8dc1d7c9
|
@ -191,6 +191,9 @@ void Audio::openInput(const QString& inDevDescr)
|
|||
}
|
||||
alInDev = nullptr;
|
||||
|
||||
if (inDevDescr == "none")
|
||||
return;
|
||||
|
||||
/// TODO: Try to actually detect if our audio source is stereo
|
||||
int stereoFlag = AUDIO_CHANNELS == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16;
|
||||
const uint32_t sampleRate = AUDIO_SAMPLE_RATE;
|
||||
|
@ -235,35 +238,43 @@ bool Audio::openOutput(const QString &outDevDescr)
|
|||
|
||||
auto* tmp = alOutDev;
|
||||
alOutDev = nullptr;
|
||||
if (outDevDescr.isEmpty())
|
||||
alOutDev = alcOpenDevice(nullptr);
|
||||
else
|
||||
alOutDev = alcOpenDevice(outDevDescr.toStdString().c_str());
|
||||
|
||||
if (alOutDev)
|
||||
if (outDevDescr != "none")
|
||||
{
|
||||
if (alContext && alcMakeContextCurrent(nullptr) == ALC_TRUE)
|
||||
alcDestroyContext(alContext);
|
||||
if (outDevDescr.isEmpty())
|
||||
alOutDev = alcOpenDevice(nullptr);
|
||||
else
|
||||
alOutDev = alcOpenDevice(outDevDescr.toStdString().c_str());
|
||||
|
||||
if (tmp)
|
||||
alcCloseDevice(tmp);
|
||||
|
||||
alContext = alcCreateContext(alOutDev, nullptr);
|
||||
if (alcMakeContextCurrent(alContext))
|
||||
if (alOutDev)
|
||||
{
|
||||
alGenSources(1, &alMainSource);
|
||||
if (alContext && alcMakeContextCurrent(nullptr) == ALC_TRUE)
|
||||
alcDestroyContext(alContext);
|
||||
|
||||
if (tmp)
|
||||
alcCloseDevice(tmp);
|
||||
|
||||
alContext = alcCreateContext(alOutDev, nullptr);
|
||||
if (alcMakeContextCurrent(alContext))
|
||||
{
|
||||
alGenSources(1, &alMainSource);
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Cannot create output audio context";
|
||||
alcCloseDevice(alOutDev);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Cannot create output audio context";
|
||||
alcCloseDevice(alOutDev);
|
||||
qWarning() << "Cannot open output audio device " + outDevDescr;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
qWarning() << "Cannot open output audio device " + outDevDescr;
|
||||
return false;
|
||||
closeOutput();
|
||||
}
|
||||
|
||||
Core* core = Core::getInstance();
|
||||
|
@ -307,9 +318,6 @@ void Audio::closeOutput()
|
|||
qDebug() << "Closing output";
|
||||
QMutexLocker locker(&audioOutLock);
|
||||
|
||||
if (inputSubscriptions > 0)
|
||||
return;
|
||||
|
||||
if (alContext && alcMakeContextCurrent(nullptr) == ALC_TRUE)
|
||||
{
|
||||
alcDestroyContext(alContext);
|
||||
|
@ -472,6 +480,12 @@ bool Audio::isInputReady()
|
|||
return alInDev && inputSubscriptions;
|
||||
}
|
||||
|
||||
bool Audio::isInputSubscribed()
|
||||
{
|
||||
// No lock, inputSubscriptions is atomic!
|
||||
return inputSubscriptions;
|
||||
}
|
||||
|
||||
/**
|
||||
Returns true if the output device is open
|
||||
*/
|
||||
|
|
|
@ -70,6 +70,7 @@ public:
|
|||
bool openOutput(const QString& outDevDescr);
|
||||
|
||||
bool isInputReady();
|
||||
bool isInputSubscribed();
|
||||
bool isOutputReady();
|
||||
|
||||
static void createSource(ALuint* source);
|
||||
|
|
|
@ -253,6 +253,7 @@ void AVForm::getAudioInDevices()
|
|||
QString settingsInDev = Settings::getInstance().getInDev();
|
||||
int inDevIndex = 0;
|
||||
bodyUI->inDevCombobox->clear();
|
||||
bodyUI->inDevCombobox->addItem(tr("None"));
|
||||
const ALchar *pDeviceList = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
|
||||
if (pDeviceList)
|
||||
{
|
||||
|
@ -283,6 +284,7 @@ void AVForm::getAudioOutDevices()
|
|||
QString settingsOutDev = Settings::getInstance().getOutDev();
|
||||
int outDevIndex = 0;
|
||||
bodyUI->outDevCombobox->clear();
|
||||
bodyUI->outDevCombobox->addItem(tr("None"));
|
||||
const ALchar *pDeviceList;
|
||||
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
|
||||
pDeviceList = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
|
||||
|
@ -314,22 +316,25 @@ void AVForm::getAudioOutDevices()
|
|||
bodyUI->outDevCombobox->setCurrentIndex(outDevIndex);
|
||||
}
|
||||
|
||||
void AVForm::onInDevChanged(const QString &deviceDescriptor)
|
||||
void AVForm::onInDevChanged(QString deviceDescriptor)
|
||||
{
|
||||
if (!bodyUI->inDevCombobox->currentIndex())
|
||||
deviceDescriptor = "none";
|
||||
Settings::getInstance().setInDev(deviceDescriptor);
|
||||
|
||||
Audio& audio = Audio::getInstance();
|
||||
if (audio.isInputReady())
|
||||
if (audio.isInputSubscribed())
|
||||
audio.openInput(deviceDescriptor);
|
||||
}
|
||||
|
||||
void AVForm::onOutDevChanged(const QString& deviceDescriptor)
|
||||
void AVForm::onOutDevChanged(QString deviceDescriptor)
|
||||
{
|
||||
if (!bodyUI->outDevCombobox->currentIndex())
|
||||
deviceDescriptor = "none";
|
||||
Settings::getInstance().setOutDev(deviceDescriptor);
|
||||
|
||||
Audio& audio = Audio::getInstance();
|
||||
if (audio.isOutputReady())
|
||||
audio.openOutput(deviceDescriptor);
|
||||
audio.openOutput(deviceDescriptor);
|
||||
}
|
||||
|
||||
void AVForm::onFilterAudioToggled(bool filterAudio)
|
||||
|
|
|
@ -54,8 +54,8 @@ private:
|
|||
private slots:
|
||||
|
||||
// audio
|
||||
void onInDevChanged(const QString& deviceDescriptor);
|
||||
void onOutDevChanged(const QString& deviceDescriptor);
|
||||
void onInDevChanged(QString deviceDescriptor);
|
||||
void onOutDevChanged(QString deviceDescriptor);
|
||||
void onFilterAudioToggled(bool filterAudio);
|
||||
void on_playbackSlider_valueChanged(int value);
|
||||
void on_microphoneSlider_valueChanged(int value);
|
||||
|
|
Loading…
Reference in New Issue
Block a user