From 79ddbf7d029f0b6f7caf38bd338939418caa2053 Mon Sep 17 00:00:00 2001 From: Nils Fenner Date: Mon, 28 Dec 2015 12:06:22 +0100 Subject: [PATCH] open the first available audio in/out device as default, if specifier is empty --- src/audio/audio.cpp | 56 +++++++++++---------------------------------- 1 file changed, 13 insertions(+), 43 deletions(-) diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index 704c4c17c..639fac1ef 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -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) {