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:
parent
6ac8827d29
commit
bec635ad11
|
@ -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
|
qreal inputGain() const
|
||||||
{
|
{
|
||||||
return gain;
|
return gain;
|
||||||
|
@ -323,7 +335,7 @@ bool Audio::initInput(QString inDevDescr)
|
||||||
const ALCsizei bufSize = (frameDuration * sampleRate * 4) / 1000 * chnls;
|
const ALCsizei bufSize = (frameDuration * sampleRate * 4) / 1000 * chnls;
|
||||||
if (inDevDescr.isEmpty())
|
if (inDevDescr.isEmpty())
|
||||||
{
|
{
|
||||||
const ALchar *pDeviceList = Audio::inDeviceNames();
|
const ALchar *pDeviceList = Private::inDeviceNames();
|
||||||
if (pDeviceList)
|
if (pDeviceList)
|
||||||
inDevDescr = QString::fromUtf8(pDeviceList, strlen(pDeviceList));
|
inDevDescr = QString::fromUtf8(pDeviceList, strlen(pDeviceList));
|
||||||
}
|
}
|
||||||
|
@ -366,7 +378,7 @@ bool Audio::initOutput(QString outDevDescr)
|
||||||
if (outDevDescr.isEmpty())
|
if (outDevDescr.isEmpty())
|
||||||
{
|
{
|
||||||
// default to the first available audio device.
|
// default to the first available audio device.
|
||||||
const ALchar *pDeviceList = Audio::outDeviceNames();
|
const ALchar *pDeviceList = Private::outDeviceNames();
|
||||||
if (pDeviceList)
|
if (pDeviceList)
|
||||||
outDevDescr = QString::fromUtf8(pDeviceList, strlen(pDeviceList));
|
outDevDescr = QString::fromUtf8(pDeviceList, strlen(pDeviceList));
|
||||||
}
|
}
|
||||||
|
@ -600,20 +612,40 @@ bool Audio::isOutputReady() const
|
||||||
return alOutDev && outputInitialized;
|
return alOutDev && outputInitialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Audio::outDeviceNames()
|
QStringList Audio::outDeviceNames()
|
||||||
{
|
{
|
||||||
const char* pDeviceList;
|
QStringList list;
|
||||||
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATE_ALL_EXT") != AL_FALSE)
|
const ALchar* pDeviceList = Private::outDeviceNames();
|
||||||
pDeviceList = alcGetString(NULL, ALC_ALL_DEVICES_SPECIFIER);
|
|
||||||
else
|
|
||||||
pDeviceList = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
|
|
||||||
|
|
||||||
return pDeviceList;
|
if (pDeviceList)
|
||||||
|
{
|
||||||
|
while (*pDeviceList)
|
||||||
|
{
|
||||||
|
int len = static_cast<int>(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<int>(strlen(pDeviceList));
|
||||||
|
list << QString::fromUtf8(pDeviceList, len);
|
||||||
|
pDeviceList += len+1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::subscribeOutput(ALuint& sid)
|
void Audio::subscribeOutput(ALuint& sid)
|
||||||
|
|
|
@ -74,8 +74,8 @@ public:
|
||||||
bool isInputReady() const;
|
bool isInputReady() const;
|
||||||
bool isOutputReady() const;
|
bool isOutputReady() const;
|
||||||
|
|
||||||
static const char* outDeviceNames();
|
static QStringList outDeviceNames();
|
||||||
static const char* inDeviceNames();
|
static QStringList inDeviceNames();
|
||||||
void subscribeOutput(ALuint& sid);
|
void subscribeOutput(ALuint& sid);
|
||||||
void unsubscribeOutput(ALuint& sid);
|
void unsubscribeOutput(ALuint& sid);
|
||||||
void subscribeInput();
|
void subscribeInput();
|
||||||
|
|
|
@ -344,52 +344,30 @@ void AVForm::getVideoDevices()
|
||||||
|
|
||||||
void AVForm::getAudioInDevices()
|
void AVForm::getAudioInDevices()
|
||||||
{
|
{
|
||||||
QString settingsInDev = Settings::getInstance().getInDev();
|
QStringList deviceNames;
|
||||||
int inDevIndex = 0;
|
deviceNames << tr("None") << Audio::inDeviceNames();
|
||||||
|
|
||||||
bodyUI->inDevCombobox->blockSignals(true);
|
bodyUI->inDevCombobox->blockSignals(true);
|
||||||
bodyUI->inDevCombobox->clear();
|
bodyUI->inDevCombobox->clear();
|
||||||
bodyUI->inDevCombobox->addItem(tr("None"));
|
bodyUI->inDevCombobox->addItems(deviceNames);
|
||||||
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->blockSignals(false);
|
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()
|
void AVForm::getAudioOutDevices()
|
||||||
{
|
{
|
||||||
QString settingsOutDev = Settings::getInstance().getOutDev();
|
QStringList deviceNames;
|
||||||
int outDevIndex = 0;
|
deviceNames << tr("None") << Audio::outDeviceNames();
|
||||||
|
|
||||||
bodyUI->outDevCombobox->blockSignals(true);
|
bodyUI->outDevCombobox->blockSignals(true);
|
||||||
bodyUI->outDevCombobox->clear();
|
bodyUI->outDevCombobox->clear();
|
||||||
bodyUI->outDevCombobox->addItem(tr("None"));
|
bodyUI->outDevCombobox->addItems(deviceNames);
|
||||||
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->blockSignals(false);
|
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)
|
void AVForm::onInDevChanged(QString deviceDescriptor)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user