diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index 1030b6cfa..072c7d563 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -50,6 +50,18 @@ public: { } + static const ALchar* inDeviceNames() + { + return alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER); + } + + static const ALchar* outDeviceNames() + { + return (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE) + ? alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER) + : alcGetString(NULL, ALC_DEVICE_SPECIFIER); + } + qreal inputGain() const { return gain; @@ -323,7 +335,7 @@ bool Audio::initInput(QString inDevDescr) const ALCsizei bufSize = (frameDuration * sampleRate * 4) / 1000 * chnls; if (inDevDescr.isEmpty()) { - const ALchar *pDeviceList = Audio::inDeviceNames(); + const ALchar *pDeviceList = Private::inDeviceNames(); if (pDeviceList) inDevDescr = QString::fromUtf8(pDeviceList, strlen(pDeviceList)); } @@ -366,7 +378,7 @@ bool Audio::initOutput(QString outDevDescr) if (outDevDescr.isEmpty()) { // default to the first available audio device. - const ALchar *pDeviceList = Audio::outDeviceNames(); + const ALchar *pDeviceList = Private::outDeviceNames(); if (pDeviceList) outDevDescr = QString::fromUtf8(pDeviceList, strlen(pDeviceList)); } @@ -600,20 +612,40 @@ bool Audio::isOutputReady() const return alOutDev && outputInitialized; } -const char* Audio::outDeviceNames() +QStringList Audio::outDeviceNames() { - const char* pDeviceList; - if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE) - pDeviceList = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER); - else - pDeviceList = alcGetString(NULL, ALC_DEVICE_SPECIFIER); + QStringList list; + const ALchar* pDeviceList = Private::outDeviceNames(); - return pDeviceList; + if (pDeviceList) + { + while (*pDeviceList) + { + int len = static_cast(strlen(pDeviceList)); + list << QString::fromUtf8(pDeviceList, len); + pDeviceList += len+1; + } + } + + return list; } -const char* Audio::inDeviceNames() +QStringList Audio::inDeviceNames() { - return alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER); + QStringList list; + const ALchar* pDeviceList = Private::inDeviceNames(); + + if (pDeviceList) + { + while (*pDeviceList) + { + int len = static_cast(strlen(pDeviceList)); + list << QString::fromUtf8(pDeviceList, len); + pDeviceList += len+1; + } + } + + return list; } void Audio::subscribeOutput(ALuint& sid) diff --git a/src/audio/audio.h b/src/audio/audio.h index d30fe8152..6b0490450 100644 --- a/src/audio/audio.h +++ b/src/audio/audio.h @@ -74,8 +74,8 @@ public: bool isInputReady() const; bool isOutputReady() const; - static const char* outDeviceNames(); - static const char* inDeviceNames(); + static QStringList outDeviceNames(); + static QStringList inDeviceNames(); void subscribeOutput(ALuint& sid); void unsubscribeOutput(ALuint& sid); void subscribeInput(); diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index 88f10277c..402ac4229 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -344,52 +344,30 @@ void AVForm::getVideoDevices() void AVForm::getAudioInDevices() { - QString settingsInDev = Settings::getInstance().getInDev(); - int inDevIndex = 0; + QStringList deviceNames; + deviceNames << tr("None") << Audio::inDeviceNames(); + bodyUI->inDevCombobox->blockSignals(true); bodyUI->inDevCombobox->clear(); - bodyUI->inDevCombobox->addItem(tr("None")); - const char* pDeviceList = Audio::inDeviceNames(); - if (pDeviceList) - { - while (*pDeviceList) - { - int len = strlen(pDeviceList); - QString inDev = QString::fromUtf8(pDeviceList, len); - bodyUI->inDevCombobox->addItem(inDev); - if (settingsInDev == inDev) - inDevIndex = bodyUI->inDevCombobox->count()-1; - pDeviceList += len+1; - } - } + bodyUI->inDevCombobox->addItems(deviceNames); bodyUI->inDevCombobox->blockSignals(false); - bodyUI->inDevCombobox->setCurrentIndex(inDevIndex); + + int idx = deviceNames.indexOf(Settings::getInstance().getInDev()); + bodyUI->inDevCombobox->setCurrentIndex(idx > 0 ? idx : 0); } void AVForm::getAudioOutDevices() { - QString settingsOutDev = Settings::getInstance().getOutDev(); - int outDevIndex = 0; + QStringList deviceNames; + deviceNames << tr("None") << Audio::outDeviceNames(); + bodyUI->outDevCombobox->blockSignals(true); bodyUI->outDevCombobox->clear(); - bodyUI->outDevCombobox->addItem(tr("None")); - const char* pDeviceList = Audio::outDeviceNames(); - if (pDeviceList) - { - while (*pDeviceList) - { - int len = strlen(pDeviceList); - QString outDev = QString::fromUtf8(pDeviceList, len); - bodyUI->outDevCombobox->addItem(outDev); - if (settingsOutDev == outDev) - { - outDevIndex = bodyUI->outDevCombobox->count()-1; - } - pDeviceList += len+1; - } - } + bodyUI->outDevCombobox->addItems(deviceNames); bodyUI->outDevCombobox->blockSignals(false); - bodyUI->outDevCombobox->setCurrentIndex(outDevIndex); + + int idx = deviceNames.indexOf(Settings::getInstance().getOutDev()); + bodyUI->outDevCombobox->setCurrentIndex(idx > 0 ? idx : 0); } void AVForm::onInDevChanged(QString deviceDescriptor)