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

refactor(audio): cleanup initialization of audio device lists

* move private code
* fix unsigned/signed conversion warnings
This commit is contained in:
Nils Fenner 2016-06-02 22:54:10 +02:00
parent 6ac8827d29
commit bec635ad11
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C
3 changed files with 59 additions and 49 deletions

View File

@ -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<int>(strlen(pDeviceList));
list << QString::fromUtf8(pDeviceList, len);
pDeviceList += len+1;
}
}
const char* Audio::inDeviceNames()
return list;
}
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<int>(strlen(pDeviceList));
list << QString::fromUtf8(pDeviceList, len);
pDeviceList += len+1;
}
}
return list;
}
void Audio::subscribeOutput(ALuint& sid)

View File

@ -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();

View File

@ -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)