mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-26 01:39:05 -05:00
Merge pull request #2038 from mxi-box/audio
Audio optimize & default input/output bugfix
This commit is contained in:
commit
aa95a5bd53
@ -186,8 +186,7 @@ void AudioInputGui::updateSampleRateAndFrequency()
|
||||
void AudioInputGui::refreshDeviceList()
|
||||
{
|
||||
ui->device->blockSignals(true);
|
||||
AudioDeviceManager *audioDeviceManager = DSPEngine::instance()->getAudioDeviceManager();
|
||||
const QList<AudioDeviceInfo>& audioList = audioDeviceManager->getInputDevices();
|
||||
const QList<AudioDeviceInfo>& audioList = AudioDeviceInfo::availableInputDevices();
|
||||
|
||||
ui->device->clear();
|
||||
for (const auto &itAudio : audioList)
|
||||
|
@ -174,7 +174,7 @@ void FCDProInput::closeDevice()
|
||||
bool FCDProInput::openFCDAudio(const char* cardname)
|
||||
{
|
||||
AudioDeviceManager *audioDeviceManager = DSPEngine::instance()->getAudioDeviceManager();
|
||||
const QList<AudioDeviceInfo>& audioList = audioDeviceManager->getInputDevices();
|
||||
const QList<AudioDeviceInfo>& audioList = AudioDeviceInfo::availableInputDevices();
|
||||
|
||||
for (const auto &itAudio : audioList)
|
||||
{
|
||||
|
@ -176,7 +176,7 @@ void FCDProPlusInput::closeDevice()
|
||||
bool FCDProPlusInput::openFCDAudio(const char* cardname)
|
||||
{
|
||||
AudioDeviceManager *audioDeviceManager = DSPEngine::instance()->getAudioDeviceManager();
|
||||
const QList<AudioDeviceInfo>& audioList = audioDeviceManager->getInputDevices();
|
||||
const QList<AudioDeviceInfo>& audioList = AudioDeviceInfo::availableInputDevices();
|
||||
|
||||
for (const auto &itAudio : audioList)
|
||||
{
|
||||
|
@ -20,6 +20,10 @@
|
||||
|
||||
#include "audiodeviceinfo.h"
|
||||
|
||||
bool inputDevicesEnumerated = false, outputDevicesEnumerated = false;
|
||||
QList<AudioDeviceInfo> inputDevices, outputDevices;
|
||||
AudioDeviceInfo defaultInputDevice_, defaultOutputDevice_;
|
||||
|
||||
QString AudioDeviceInfo::deviceName() const
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
@ -67,69 +71,81 @@ QString AudioDeviceInfo::realm() const
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
QList<AudioDeviceInfo> AudioDeviceInfo::availableInputDevices()
|
||||
const QList<AudioDeviceInfo> &AudioDeviceInfo::availableInputDevices()
|
||||
{
|
||||
if (!inputDevicesEnumerated) {
|
||||
QList<QAudioDevice> devInfos = QMediaDevices::audioInputs();
|
||||
QList<AudioDeviceInfo> list;
|
||||
|
||||
for (auto devInfo : devInfos) {
|
||||
list.append(AudioDeviceInfo(devInfo));
|
||||
inputDevices.append(AudioDeviceInfo(devInfo));
|
||||
}
|
||||
inputDevicesEnumerated = true;
|
||||
}
|
||||
|
||||
return list;
|
||||
return inputDevices;
|
||||
}
|
||||
|
||||
QList<AudioDeviceInfo> AudioDeviceInfo::availableOutputDevices()
|
||||
const QList<AudioDeviceInfo> &AudioDeviceInfo::availableOutputDevices()
|
||||
{
|
||||
if (!outputDevicesEnumerated) {
|
||||
QList<QAudioDevice> devInfos = QMediaDevices::audioOutputs();
|
||||
QList<AudioDeviceInfo> list;
|
||||
|
||||
for (auto devInfo : devInfos) {
|
||||
list.append(AudioDeviceInfo(devInfo));
|
||||
outputDevices.append(AudioDeviceInfo(devInfo));
|
||||
}
|
||||
outputDevicesEnumerated = true;
|
||||
}
|
||||
|
||||
return list;
|
||||
return outputDevices;
|
||||
}
|
||||
#else
|
||||
QList<AudioDeviceInfo> AudioDeviceInfo::availableInputDevices()
|
||||
const QList<AudioDeviceInfo> &AudioDeviceInfo::availableInputDevices()
|
||||
{
|
||||
if (!inputDevicesEnumerated) {
|
||||
QList<QAudioDeviceInfo> devInfos = QAudioDeviceInfo::availableDevices(QAudio::AudioInput);
|
||||
QList<AudioDeviceInfo> list;
|
||||
|
||||
for (auto devInfo : devInfos) {
|
||||
list.append(AudioDeviceInfo(devInfo));
|
||||
inputDevices.append(AudioDeviceInfo(devInfo));
|
||||
}
|
||||
inputDevicesEnumerated = true;
|
||||
}
|
||||
|
||||
return list;
|
||||
return inputDevices;
|
||||
}
|
||||
|
||||
QList<AudioDeviceInfo> AudioDeviceInfo::availableOutputDevices()
|
||||
const QList<AudioDeviceInfo> &AudioDeviceInfo::availableOutputDevices()
|
||||
{
|
||||
if (!outputDevicesEnumerated) {
|
||||
QList<QAudioDeviceInfo> devInfos = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
|
||||
QList<AudioDeviceInfo> list;
|
||||
|
||||
for (auto devInfo : devInfos) {
|
||||
list.append(AudioDeviceInfo(devInfo));
|
||||
outputDevices.append(AudioDeviceInfo(devInfo));
|
||||
}
|
||||
outputDevicesEnumerated = true;
|
||||
}
|
||||
|
||||
return list;
|
||||
return outputDevices;
|
||||
}
|
||||
#endif
|
||||
|
||||
AudioDeviceInfo AudioDeviceInfo::defaultOutputDevice()
|
||||
const AudioDeviceInfo &AudioDeviceInfo::defaultOutputDevice()
|
||||
{
|
||||
if (defaultOutputDevice_.m_deviceInfo.isNull())
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
return AudioDeviceInfo(QMediaDevices::defaultAudioOutput());
|
||||
defaultOutputDevice_ = AudioDeviceInfo(QMediaDevices::defaultAudioOutput());
|
||||
#else
|
||||
return AudioDeviceInfo(QAudioDeviceInfo::defaultOutputDevice());
|
||||
defaultOutputDevice_ = AudioDeviceInfo(QAudioDeviceInfo::defaultOutputDevice());
|
||||
#endif
|
||||
}
|
||||
return defaultOutputDevice_;
|
||||
}
|
||||
|
||||
AudioDeviceInfo AudioDeviceInfo::defaultInputDevice()
|
||||
const AudioDeviceInfo &AudioDeviceInfo::defaultInputDevice()
|
||||
{
|
||||
if (defaultInputDevice_.m_deviceInfo.isNull())
|
||||
{
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
return AudioDeviceInfo(QMediaDevices::defaultAudioInput());
|
||||
defaultInputDevice_ = AudioDeviceInfo(QMediaDevices::defaultAudioInput());
|
||||
#else
|
||||
return AudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice());
|
||||
defaultInputDevice_ = AudioDeviceInfo(QAudioDeviceInfo::defaultInputDevice());
|
||||
#endif
|
||||
}
|
||||
return defaultInputDevice_;
|
||||
}
|
||||
|
@ -67,10 +67,10 @@ public:
|
||||
bool isFormatSupported(const QAudioFormat &settings) const;
|
||||
QList<int> supportedSampleRates() const;
|
||||
|
||||
static QList<AudioDeviceInfo> availableInputDevices();
|
||||
static QList<AudioDeviceInfo> availableOutputDevices();
|
||||
static AudioDeviceInfo defaultInputDevice();
|
||||
static AudioDeviceInfo defaultOutputDevice();
|
||||
static const QList<AudioDeviceInfo> &availableInputDevices();
|
||||
static const QList<AudioDeviceInfo> &availableOutputDevices();
|
||||
static const AudioDeviceInfo &defaultInputDevice();
|
||||
static const AudioDeviceInfo &defaultOutputDevice();
|
||||
|
||||
private:
|
||||
|
||||
|
@ -82,20 +82,22 @@ QDataStream& operator>>(QDataStream& ds, AudioDeviceManager::OutputDeviceInfo& i
|
||||
AudioDeviceManager::AudioDeviceManager()
|
||||
{
|
||||
qDebug("AudioDeviceManager::AudioDeviceManager: scan input devices");
|
||||
m_inputDevicesInfo = AudioDeviceInfo::availableInputDevices();
|
||||
{
|
||||
auto &devicesInfo = AudioDeviceInfo::availableInputDevices();
|
||||
|
||||
for (int i = 0; i < m_inputDevicesInfo.size(); i++) {
|
||||
qDebug("AudioDeviceManager::AudioDeviceManager: input device #%d: %s", i, qPrintable(m_inputDevicesInfo[i].deviceName()));
|
||||
for (int i = 0; i < devicesInfo.size(); i++) {
|
||||
qDebug("AudioDeviceManager::AudioDeviceManager: input device #%d: %s", i, qPrintable(devicesInfo[i].deviceName()));
|
||||
}
|
||||
}
|
||||
|
||||
qDebug("AudioDeviceManager::AudioDeviceManager: scan output devices");
|
||||
|
||||
m_outputDevicesInfo = AudioDeviceInfo::availableOutputDevices();
|
||||
{
|
||||
auto &devicesInfo = AudioDeviceInfo::availableOutputDevices();
|
||||
|
||||
for (int i = 0; i < m_outputDevicesInfo.size(); i++) {
|
||||
qDebug("AudioDeviceManager::AudioDeviceManager: output device #%d: %s", i, qPrintable(m_outputDevicesInfo[i].deviceName()));
|
||||
for (int i = 0; i < devicesInfo.size(); i++) {
|
||||
qDebug("AudioDeviceManager::AudioDeviceManager: output device #%d: %s", i, qPrintable(devicesInfo[i].deviceName()));
|
||||
}
|
||||
}
|
||||
|
||||
m_defaultInputStarted = false;
|
||||
m_defaultOutputStarted = false;
|
||||
|
||||
@ -142,9 +144,9 @@ bool AudioDeviceManager::getOutputDeviceName(int outputDeviceIndex, QString &dev
|
||||
}
|
||||
else
|
||||
{
|
||||
if (outputDeviceIndex < m_outputDevicesInfo.size())
|
||||
if (outputDeviceIndex < AudioDeviceInfo::availableOutputDevices().size())
|
||||
{
|
||||
deviceName = m_outputDevicesInfo[outputDeviceIndex].deviceName();
|
||||
deviceName = AudioDeviceInfo::availableOutputDevices()[outputDeviceIndex].deviceName();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -163,9 +165,9 @@ bool AudioDeviceManager::getInputDeviceName(int inputDeviceIndex, QString &devic
|
||||
}
|
||||
else
|
||||
{
|
||||
if (inputDeviceIndex < m_inputDevicesInfo.size())
|
||||
if (inputDeviceIndex < AudioDeviceInfo::availableInputDevices().size())
|
||||
{
|
||||
deviceName = m_inputDevicesInfo[inputDeviceIndex].deviceName();
|
||||
deviceName = AudioDeviceInfo::availableInputDevices()[inputDeviceIndex].deviceName();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -177,10 +179,10 @@ bool AudioDeviceManager::getInputDeviceName(int inputDeviceIndex, QString &devic
|
||||
|
||||
int AudioDeviceManager::getOutputDeviceIndex(const QString &deviceName) const
|
||||
{
|
||||
for (int i = 0; i < m_outputDevicesInfo.size(); i++)
|
||||
for (int i = 0; i < AudioDeviceInfo::availableOutputDevices().size(); i++)
|
||||
{
|
||||
//qDebug("AudioDeviceManager::getOutputDeviceIndex: %d: %s|%s", i, qPrintable(deviceName), qPrintable(m_outputDevicesInfo[i].deviceName()));
|
||||
if (deviceName == m_outputDevicesInfo[i].deviceName()) {
|
||||
//qDebug("AudioDeviceManager::getOutputDeviceIndex: %d: %s|%s", i, qPrintable(deviceName), qPrintable(AudioDeviceInfo::availableOutputDevices()[i].deviceName()));
|
||||
if (deviceName == AudioDeviceInfo::availableOutputDevices()[i].deviceName()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@ -190,10 +192,10 @@ int AudioDeviceManager::getOutputDeviceIndex(const QString &deviceName) const
|
||||
|
||||
int AudioDeviceManager::getInputDeviceIndex(const QString &deviceName) const
|
||||
{
|
||||
for (int i = 0; i < m_inputDevicesInfo.size(); i++)
|
||||
for (int i = 0; i < AudioDeviceInfo::availableInputDevices().size(); i++)
|
||||
{
|
||||
//qDebug("AudioDeviceManager::getInputDeviceIndex: %d: %s|%s", i, qPrintable(deviceName), qPrintable(m_inputDevicesInfo[i].deviceName()));
|
||||
if (deviceName == m_inputDevicesInfo[i].deviceName()) {
|
||||
//qDebug("AudioDeviceManager::getInputDeviceIndex: %d: %s|%s", i, qPrintable(deviceName), qPrintable(AudioDeviceInfo::availableInputDevices()[i].deviceName()));
|
||||
if (deviceName == AudioDeviceInfo::availableInputDevices()[i].deviceName()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@ -295,7 +297,7 @@ void AudioDeviceManager::addAudioSink(AudioFifo* audioFifo, MessageQueue *sample
|
||||
if (outputDeviceIndex < 0) {
|
||||
audioOutputDevice->setDeviceName("System default");
|
||||
} else {
|
||||
audioOutputDevice->setDeviceName(m_outputDevicesInfo[outputDeviceIndex].deviceName());
|
||||
audioOutputDevice->setDeviceName(AudioDeviceInfo::availableOutputDevices()[outputDeviceIndex].deviceName());
|
||||
}
|
||||
|
||||
qDebug("AudioDeviceManager::addAudioSink: new AudioOutputDevice on thread: %p", thread);
|
||||
@ -382,7 +384,7 @@ void AudioDeviceManager::addAudioSource(AudioFifo* audioFifo, MessageQueue *samp
|
||||
if (inputDeviceIndex < 0) {
|
||||
audioInputDevice->setDeviceName("System default");
|
||||
} else {
|
||||
audioInputDevice->setDeviceName(m_outputDevicesInfo[inputDeviceIndex].deviceName());
|
||||
audioInputDevice->setDeviceName(AudioDeviceInfo::availableOutputDevices()[inputDeviceIndex].deviceName());
|
||||
}
|
||||
|
||||
qDebug("AudioDeviceManager::addAudioSource: new AudioInputDevice on thread: %p", thread);
|
||||
@ -500,7 +502,7 @@ void AudioDeviceManager::startAudioOutput(int outputDeviceIndex)
|
||||
m_audioOutputInfos[deviceName].udpChannelMode = udpChannelMode;
|
||||
m_audioOutputInfos[deviceName].udpChannelCodec = udpChannelCodec;
|
||||
m_audioOutputInfos[deviceName].udpDecimationFactor = decimationFactor;
|
||||
m_defaultOutputStarted = (outputDeviceIndex == -1);
|
||||
m_defaultOutputStarted |= (outputDeviceIndex == -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -538,7 +540,7 @@ void AudioDeviceManager::startAudioInput(int inputDeviceIndex)
|
||||
|
||||
m_audioInputs[inputDeviceIndex]->setVolume(volume);
|
||||
m_audioInputInfos[deviceName].volume = volume;
|
||||
m_defaultInputStarted = (inputDeviceIndex == -1);
|
||||
m_defaultInputStarted |= (inputDeviceIndex == -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -789,9 +791,9 @@ void AudioDeviceManager::inputInfosCleanup()
|
||||
{
|
||||
QSet<QString> deviceNames;
|
||||
deviceNames.insert(m_defaultDeviceName);
|
||||
QList<AudioDeviceInfo>::const_iterator itd = m_inputDevicesInfo.begin();
|
||||
QList<AudioDeviceInfo>::const_iterator itd = AudioDeviceInfo::availableInputDevices().begin();
|
||||
|
||||
for (; itd != m_inputDevicesInfo.end(); ++itd)
|
||||
for (; itd != AudioDeviceInfo::availableInputDevices().end(); ++itd)
|
||||
{
|
||||
qDebug("AudioDeviceManager::inputInfosCleanup: device: %s", qPrintable(itd->deviceName()));
|
||||
deviceNames.insert(itd->deviceName());
|
||||
@ -817,9 +819,9 @@ void AudioDeviceManager::outputInfosCleanup()
|
||||
{
|
||||
QSet<QString> deviceNames;
|
||||
deviceNames.insert(m_defaultDeviceName);
|
||||
QList<AudioDeviceInfo>::const_iterator itd = m_outputDevicesInfo.begin();
|
||||
QList<AudioDeviceInfo>::const_iterator itd = AudioDeviceInfo::availableOutputDevices().begin();
|
||||
|
||||
for (; itd != m_outputDevicesInfo.end(); ++itd)
|
||||
for (; itd != AudioDeviceInfo::availableOutputDevices().end(); ++itd)
|
||||
{
|
||||
qDebug("AudioDeviceManager::outputInfosCleanup: device: %s", qPrintable(itd->deviceName()));
|
||||
deviceNames.insert(itd->deviceName());
|
||||
|
@ -102,9 +102,6 @@ public:
|
||||
AudioDeviceManager();
|
||||
~AudioDeviceManager();
|
||||
|
||||
const QList<AudioDeviceInfo>& getInputDevices() const { return m_inputDevicesInfo; }
|
||||
const QList<AudioDeviceInfo>& getOutputDevices() const { return m_outputDevicesInfo; }
|
||||
|
||||
bool getOutputDeviceName(int outputDeviceIndex, QString &deviceName) const;
|
||||
bool getInputDeviceName(int inputDeviceIndex, QString &deviceName) const;
|
||||
int getOutputDeviceIndex(const QString &deviceName) const;
|
||||
@ -136,9 +133,6 @@ public:
|
||||
static const QString m_defaultDeviceName;
|
||||
|
||||
private:
|
||||
QList<AudioDeviceInfo> m_inputDevicesInfo;
|
||||
QList<AudioDeviceInfo> m_outputDevicesInfo;
|
||||
|
||||
QMap<AudioFifo*, int> m_audioSinkFifos; //< audio sink FIFO to audio output device index-1 map
|
||||
QMap<AudioFifo*, MessageQueue*> m_audioFifoToSinkMessageQueues; //!< audio sink FIFO to attached sink message queue
|
||||
QMap<int, QList<MessageQueue*> > m_outputDeviceSinkMessageQueues; //!< sink message queues attached to device
|
||||
|
@ -91,7 +91,7 @@ bool AudioOutputDevice::start(int deviceIndex, int sampleRate)
|
||||
}
|
||||
else
|
||||
{
|
||||
QList<AudioDeviceInfo> devicesInfo = AudioDeviceInfo::availableOutputDevices();
|
||||
auto &devicesInfo = AudioDeviceInfo::availableOutputDevices();
|
||||
|
||||
if (deviceIndex < devicesInfo.size())
|
||||
{
|
||||
|
@ -454,8 +454,8 @@ int WebAPIAdapter::instanceAudioGet(
|
||||
{
|
||||
(void) error;
|
||||
DSPEngine *dspEngine = DSPEngine::instance();
|
||||
const QList<AudioDeviceInfo>& audioInputDevices = dspEngine->getAudioDeviceManager()->getInputDevices();
|
||||
const QList<AudioDeviceInfo>& audioOutputDevices = dspEngine->getAudioDeviceManager()->getOutputDevices();
|
||||
const QList<AudioDeviceInfo>& audioInputDevices = AudioDeviceInfo::availableInputDevices();
|
||||
const QList<AudioDeviceInfo>& audioOutputDevices = AudioDeviceInfo::availableOutputDevices();
|
||||
int nbInputDevices = audioInputDevices.size();
|
||||
int nbOutputDevices = audioOutputDevices.size();
|
||||
|
||||
|
@ -40,14 +40,14 @@ AudioDialogX::AudioDialogX(AudioDeviceManager* audioDeviceManager, QWidget* pare
|
||||
// out panel
|
||||
|
||||
AudioDeviceManager::OutputDeviceInfo outDeviceInfo;
|
||||
AudioDeviceInfo defaultOutputDeviceInfo = AudioDeviceInfo::defaultOutputDevice();
|
||||
const AudioDeviceInfo &defaultOutputDeviceInfo = AudioDeviceInfo::defaultOutputDevice();
|
||||
treeItem = new QTreeWidgetItem(ui->audioOutTree);
|
||||
treeItem->setText(1, AudioDeviceManager::m_defaultDeviceName);
|
||||
bool found = m_audioDeviceManager->getOutputDeviceInfo(AudioDeviceManager::m_defaultDeviceName, outDeviceInfo);
|
||||
treeItem->setText(0, found ? "__" : "_D");
|
||||
ui->audioOutTree->setCurrentItem(treeItem);
|
||||
|
||||
const QList<AudioDeviceInfo>& outputDevices = m_audioDeviceManager->getOutputDevices();
|
||||
const QList<AudioDeviceInfo>& outputDevices = AudioDeviceInfo::availableOutputDevices();
|
||||
|
||||
for(QList<AudioDeviceInfo>::const_iterator it = outputDevices.begin(); it != outputDevices.end(); ++it)
|
||||
{
|
||||
@ -75,7 +75,7 @@ AudioDialogX::AudioDialogX(AudioDeviceManager* audioDeviceManager, QWidget* pare
|
||||
treeItem->setText(0, found ? "__" : "_D");
|
||||
ui->audioInTree->setCurrentItem(treeItem);
|
||||
|
||||
const QList<AudioDeviceInfo>& inputDevices = m_audioDeviceManager->getInputDevices();
|
||||
const QList<AudioDeviceInfo>& inputDevices = AudioDeviceInfo::availableInputDevices();
|
||||
|
||||
for(QList<AudioDeviceInfo>::const_iterator it = inputDevices.begin(); it != inputDevices.end(); ++it)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ AudioSelectDialog::AudioSelectDialog(const AudioDeviceManager* audioDeviceManage
|
||||
defaultItem->setText(2, tr("%1").arg(sampleRate));
|
||||
defaultItem->setTextAlignment(2, Qt::AlignRight);
|
||||
|
||||
QList<AudioDeviceInfo> devices = input ? m_audioDeviceManager->getInputDevices() : m_audioDeviceManager->getOutputDevices();
|
||||
const QList<AudioDeviceInfo> &devices = input ? AudioDeviceInfo::availableInputDevices() : AudioDeviceInfo::availableOutputDevices();
|
||||
|
||||
for(QList<AudioDeviceInfo>::const_iterator it = devices.begin(); it != devices.end(); ++it)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user