1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-06-01 21:54:55 -04:00

Multiple audio support: Web API: new GET and PATCHes to set input and output parameters

This commit is contained in:
f4exb
2018-03-29 00:38:01 +02:00
parent 231cb45aa6
commit 249ea735c8
21 changed files with 2748 additions and 491 deletions
+135 -24
View File
@@ -234,51 +234,162 @@ int WebAPIAdapterGUI::instanceAudioGet(
response.init();
response.setNbInputDevices(nbInputDevices);
response.setInputDeviceSelectedIndex(-1); // FIXME: remove
response.setNbOutputDevices(nbOutputDevices);
response.setOutputDeviceSelectedIndex(-1); // FIXME: remove
response.setInputVolume(1.0f); // FIXME: remove
QList<SWGSDRangel::SWGAudioDevice*> *inputDevices = response.getInputDevices();
QList<SWGSDRangel::SWGAudioDevice*> *outputDevices = response.getOutputDevices();
QList<SWGSDRangel::SWGAudioInputDevice*> *inputDevices = response.getInputDevices();
QList<SWGSDRangel::SWGAudioOutputDevice*> *outputDevices = response.getOutputDevices();
AudioDeviceManager::InputDeviceInfo inputDeviceInfo;
AudioDeviceManager::OutputDeviceInfo outputDeviceInfo;
// system default input device
inputDevices->append(new SWGSDRangel::SWGAudioInputDevice);
inputDevices->back()->init();
bool found = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(AudioDeviceManager::m_defaultDeviceName, inputDeviceInfo);
*inputDevices->back()->getName() = AudioDeviceManager::m_defaultDeviceName;
inputDevices->back()->setIndex(-1);
inputDevices->back()->setSampleRate(inputDeviceInfo.sampleRate);
inputDevices->back()->setIsSystemDefault(0);
inputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
inputDevices->back()->setVolume(inputDeviceInfo.volume);
// real input devices
for (int i = 0; i < nbInputDevices; i++)
{
inputDevices->append(new SWGSDRangel::SWGAudioDevice);
inputDevices->append(new SWGSDRangel::SWGAudioInputDevice);
inputDevices->back()->init();
inputDeviceInfo.resetToDefaults();
found = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(audioInputDevices.at(i).deviceName(), inputDeviceInfo);
*inputDevices->back()->getName() = audioInputDevices.at(i).deviceName();
inputDevices->back()->setIndex(i);
inputDevices->back()->setSampleRate(inputDeviceInfo.sampleRate);
inputDevices->back()->setIsSystemDefault(audioInputDevices.at(i).deviceName() == QAudioDeviceInfo::defaultInputDevice().deviceName() ? 1 : 0);
inputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
inputDevices->back()->setVolume(inputDeviceInfo.volume);
}
// system default output device
outputDevices->append(new SWGSDRangel::SWGAudioOutputDevice);
outputDevices->back()->init();
found = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(AudioDeviceManager::m_defaultDeviceName, outputDeviceInfo);
*outputDevices->back()->getName() = AudioDeviceManager::m_defaultDeviceName;
outputDevices->back()->setIndex(-1);
outputDevices->back()->setSampleRate(outputDeviceInfo.sampleRate);
inputDevices->back()->setIsSystemDefault(0);
outputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
outputDevices->back()->setCopyToUdp(outputDeviceInfo.copyToUDP ? 1 : 0);
outputDevices->back()->setUdpUsesRtp(outputDeviceInfo.udpUseRTP ? 1 : 0);
outputDevices->back()->setUdpChannelMode((int) outputDeviceInfo.udpChannelMode);
*outputDevices->back()->getUdpAddress() = outputDeviceInfo.udpAddress;
outputDevices->back()->setUdpPort(outputDeviceInfo.udpPort);
// real output devices
for (int i = 0; i < nbOutputDevices; i++)
{
outputDevices->append(new SWGSDRangel::SWGAudioDevice);
outputDevices->append(new SWGSDRangel::SWGAudioOutputDevice);
outputDevices->back()->init();
outputDeviceInfo.resetToDefaults();
found = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(audioOutputDevices.at(i).deviceName(), outputDeviceInfo);
*outputDevices->back()->getName() = audioOutputDevices.at(i).deviceName();
outputDevices->back()->setIndex(i);
outputDevices->back()->setSampleRate(outputDeviceInfo.sampleRate);
outputDevices->back()->setIsSystemDefault(audioOutputDevices.at(i).deviceName() == QAudioDeviceInfo::defaultOutputDevice().deviceName() ? 1 : 0);
outputDevices->back()->setDefaultUnregistered(found ? 0 : 1);
outputDevices->back()->setCopyToUdp(outputDeviceInfo.copyToUDP ? 1 : 0);
outputDevices->back()->setUdpUsesRtp(outputDeviceInfo.udpUseRTP ? 1 : 0);
outputDevices->back()->setUdpChannelMode((int) outputDeviceInfo.udpChannelMode);
*outputDevices->back()->getUdpAddress() = outputDeviceInfo.udpAddress;
outputDevices->back()->setUdpPort(outputDeviceInfo.udpPort);
}
return 200;
}
int WebAPIAdapterGUI::instanceAudioPatch(
SWGSDRangel::SWGAudioDevicesSelect& response,
SWGSDRangel::SWGErrorResponse& error __attribute__((unused)))
int WebAPIAdapterGUI::instanceAudioInputPatch(
SWGSDRangel::SWGAudioInputDevice& response,
const QStringList& audioInputKeys,
SWGSDRangel::SWGErrorResponse& error)
{
// response input is the query actually
float inputVolume = response.getInputVolume();
int inputIndex = response.getInputIndex();
int outputIndex = response.getOutputIndex();
// TODO
AudioDeviceManager::InputDeviceInfo inputDeviceInfo;
QString deviceName;
int deviceIndex = response.getIndex();
const QList<QAudioDeviceInfo>& audioInputDevices = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDevices();
const QList<QAudioDeviceInfo>& audioOutputDevices = m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDevices();
int nbInputDevices = audioInputDevices.size();
int nbOutputDevices = audioOutputDevices.size();
if (!m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceName(deviceIndex, deviceName))
{
error.init();
*error.getMessage() = QString("There is no audio input device at index %1").arg(deviceIndex);
return 404;
}
inputVolume = inputVolume < 0.0 ? 0.0 : inputVolume > 1.0 ? 1.0 : inputVolume;
inputIndex = inputIndex < -1 ? -1 : inputIndex > nbInputDevices ? nbInputDevices-1 : inputIndex;
outputIndex = outputIndex < -1 ? -1 : outputIndex > nbOutputDevices ? nbOutputDevices-1 : outputIndex;
m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo);
response.setInputVolume(1.0f); // FIXME: remove
response.setInputIndex(-1); // FIXME: remove
response.setOutputIndex(-1); // FIXME: remove
if (audioInputKeys.contains("sampleRate")) {
inputDeviceInfo.sampleRate = response.getSampleRate();
}
if (audioInputKeys.contains("volume")) {
inputDeviceInfo.volume = response.getVolume();
}
m_mainWindow.m_dspEngine->getAudioDeviceManager()->setInputDeviceInfo(deviceIndex, inputDeviceInfo);
m_mainWindow.m_dspEngine->getAudioDeviceManager()->getInputDeviceInfo(deviceName, inputDeviceInfo);
response.setSampleRate(inputDeviceInfo.sampleRate);
response.setVolume(inputDeviceInfo.volume);
return 200;
}
int WebAPIAdapterGUI::instanceAudioOutputPatch(
SWGSDRangel::SWGAudioOutputDevice& response,
const QStringList& audioOutputKeys,
SWGSDRangel::SWGErrorResponse& error)
{
AudioDeviceManager::OutputDeviceInfo outputDeviceInfo;
QString deviceName;
int deviceIndex = response.getIndex();
if (!m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceName(deviceIndex, deviceName))
{
error.init();
*error.getMessage() = QString("There is no audio output device at index %1").arg(deviceIndex);
return 404;
}
m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo);
if (audioOutputKeys.contains("sampleRate")) {
outputDeviceInfo.sampleRate = response.getSampleRate();
}
if (audioOutputKeys.contains("copyToUDP")) {
outputDeviceInfo.copyToUDP = response.getCopyToUdp() == 0 ? 0 : 1;
}
if (audioOutputKeys.contains("udpUsesRTP")) {
outputDeviceInfo.udpUseRTP = response.getUdpUsesRtp() == 0 ? 0 : 1;
}
if (audioOutputKeys.contains("udpChannelMode")) {
outputDeviceInfo.udpChannelMode = static_cast<AudioOutput::UDPChannelMode>(response.getUdpChannelMode() % 4);
}
if (audioOutputKeys.contains("udpAddress")) {
outputDeviceInfo.udpAddress = *response.getUdpAddress();
}
if (audioOutputKeys.contains("udpPort")) {
outputDeviceInfo.udpPort = response.getUdpPort() % (1<<16);
}
m_mainWindow.m_dspEngine->getAudioDeviceManager()->setOutputDeviceInfo(deviceIndex, outputDeviceInfo);
m_mainWindow.m_dspEngine->getAudioDeviceManager()->getOutputDeviceInfo(deviceName, outputDeviceInfo);
response.setSampleRate(outputDeviceInfo.sampleRate);
response.setCopyToUdp(outputDeviceInfo.copyToUDP == 0 ? 0 : 1);
response.setUdpUsesRtp(outputDeviceInfo.udpUseRTP == 0 ? 0 : 1);
response.setUdpChannelMode(outputDeviceInfo.udpChannelMode % 4);
if (response.getUdpAddress()) {
*response.getUdpAddress() = outputDeviceInfo.udpAddress;
} else {
response.setUdpAddress(new QString(outputDeviceInfo.udpAddress));
}
response.setUdpPort(outputDeviceInfo.udpPort % (1<<16));
return 200;
}