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

open the first available audio in/out device as default, if specifier is empty

This commit is contained in:
Nils Fenner 2015-12-28 12:06:22 +01:00
parent 552155bd1f
commit 79ddbf7d02
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C

View File

@ -422,27 +422,14 @@ bool AudioPrivate::initInput(QString inDevDescr)
const uint16_t frameDuration = AUDIO_FRAME_DURATION;
const uint32_t chnls = AUDIO_CHANNELS;
const ALCsizei bufSize = (frameDuration * sampleRate * 4) / 1000 * chnls;
if (inDevDescr.isEmpty())
{
const ALchar *pDeviceList = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
if (inDevDescr.isEmpty()) {
const ALchar *pDeviceList = Audio::inDeviceNames();
if (pDeviceList)
{
alInDev = alcCaptureOpenDevice(pDeviceList, sampleRate, stereoFlag, bufSize);
int len = strlen(pDeviceList);
#ifdef Q_OS_WIN
inDevDescr = QString::fromUtf8(pDeviceList, len);
#else
inDevDescr = QString::fromLocal8Bit(pDeviceList, len);
#endif
Settings::getInstance().setInDev(inDevDescr);
}
else
{
alInDev = alcCaptureOpenDevice(nullptr, sampleRate, stereoFlag, bufSize);
}
inDevDescr = QString::fromUtf8(pDeviceList, strlen(pDeviceList));
}
else
alInDev = alcCaptureOpenDevice(inDevDescr.toStdString().c_str(),
if (!inDevDescr.isEmpty())
alInDev = alcCaptureOpenDevice(inDevDescr.toUtf8().constData(),
sampleRate, stereoFlag, bufSize);
// Restart the capture if necessary
@ -474,32 +461,15 @@ bool AudioPrivate::initOutput(QString outDevDescr)
assert(!alOutDev);
if (outDevDescr.isEmpty())
{
// Attempt to default to the first available audio device.
const ALchar *pDeviceList;
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
pDeviceList = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
else
pDeviceList = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
if (outDevDescr.isEmpty()) {
// default to the first available audio device.
const ALchar *pDeviceList = Audio::outDeviceNames();
if (pDeviceList)
{
alOutDev = alcOpenDevice(pDeviceList);
int len = strlen(pDeviceList);
#ifdef Q_OS_WIN
outDevDescr = QString::fromUtf8(pDeviceList, len);
#else
outDevDescr = QString::fromLocal8Bit(pDeviceList, len);
#endif
Settings::getInstance().setOutDev(outDevDescr);
}
else
{
alOutDev = alcOpenDevice(nullptr);
}
outDevDescr = QString::fromUtf8(pDeviceList, strlen(pDeviceList));
}
else
alOutDev = alcOpenDevice(outDevDescr.toStdString().c_str());
if (!outDevDescr.isEmpty())
alOutDev = alcOpenDevice(outDevDescr.toUtf8().constData());
if (alOutDev)
{