mirror of
https://github.com/f4exb/sdrangel.git
synced 2024-11-10 10:33:29 -05:00
Audio Input: Make settings assignments atomic. Part of #1329
This commit is contained in:
parent
2eeadfe758
commit
a1161657ad
@ -113,7 +113,7 @@ bool AudioInput::openAudioDevice(QString deviceName, qint32 sampleRate)
|
||||
|
||||
void AudioInput::init()
|
||||
{
|
||||
applySettings(m_settings, true);
|
||||
applySettings(m_settings, QList<QString>(), true);
|
||||
}
|
||||
|
||||
bool AudioInput::start()
|
||||
@ -131,7 +131,7 @@ bool AudioInput::start()
|
||||
}
|
||||
|
||||
qDebug() << "AudioInput::start";
|
||||
applySettings(m_settings, true, true);
|
||||
applySettings(m_settings, QList<QString>(), true, true);
|
||||
|
||||
m_workerThread = new QThread();
|
||||
m_worker = new AudioInputWorker(&m_sampleFifo, &m_fifo);
|
||||
@ -194,12 +194,12 @@ bool AudioInput::deserialize(const QByteArray& data)
|
||||
success = false;
|
||||
}
|
||||
|
||||
MsgConfigureAudioInput* message = MsgConfigureAudioInput::create(m_settings, true);
|
||||
MsgConfigureAudioInput* message = MsgConfigureAudioInput::create(m_settings, QList<QString>(), true);
|
||||
m_inputMessageQueue.push(message);
|
||||
|
||||
if (m_guiMessageQueue)
|
||||
{
|
||||
MsgConfigureAudioInput* messageToGUI = MsgConfigureAudioInput::create(m_settings, true);
|
||||
MsgConfigureAudioInput* messageToGUI = MsgConfigureAudioInput::create(m_settings, QList<QString>(), true);
|
||||
m_guiMessageQueue->push(messageToGUI);
|
||||
}
|
||||
|
||||
@ -223,11 +223,11 @@ quint64 AudioInput::getCenterFrequency() const
|
||||
|
||||
bool AudioInput::handleMessage(const Message& message)
|
||||
{
|
||||
if(MsgConfigureAudioInput::match(message))
|
||||
if (MsgConfigureAudioInput::match(message))
|
||||
{
|
||||
qDebug() << "AudioInput::handleMessage: MsgConfigureAudioInput";
|
||||
MsgConfigureAudioInput& conf = (MsgConfigureAudioInput&) message;
|
||||
applySettings(conf.getSettings(), conf.getForce());
|
||||
applySettings(conf.getSettings(), conf.getSettingsKeys(), conf.getForce());
|
||||
return true;
|
||||
}
|
||||
else if (MsgStartStop::match(message))
|
||||
@ -259,13 +259,16 @@ bool AudioInput::handleMessage(const Message& message)
|
||||
}
|
||||
}
|
||||
|
||||
void AudioInput::applySettings(const AudioInputSettings& settings, bool force, bool starting)
|
||||
void AudioInput::applySettings(const AudioInputSettings& settings, QList<QString> settingsKeys, bool force, bool starting)
|
||||
{
|
||||
bool forwardChange = false;
|
||||
QList<QString> reverseAPIKeys;
|
||||
|
||||
if ((m_settings.m_deviceName != settings.m_deviceName)
|
||||
|| (m_settings.m_sampleRate != settings.m_sampleRate) || force)
|
||||
qDebug() << "AudioInput::applySettings: "
|
||||
<< " force:" << force
|
||||
<< settings.getDebugString(settingsKeys, force);
|
||||
|
||||
if (settingsKeys.contains("deviceName")
|
||||
|| settingsKeys.contains("sampleRate") || force)
|
||||
{
|
||||
// Don't call openAudioDevice if called from start(), otherwise ::AudioInput
|
||||
// will be created on wrong thread and we'll crash after ::AudioInput::stop calls delete
|
||||
@ -279,27 +282,18 @@ void AudioInput::applySettings(const AudioInputSettings& settings, bool force, b
|
||||
}
|
||||
}
|
||||
|
||||
if ((m_settings.m_deviceName != settings.m_deviceName) || force)
|
||||
{
|
||||
reverseAPIKeys.append("device");
|
||||
}
|
||||
|
||||
if ((m_settings.m_sampleRate != settings.m_sampleRate) || force)
|
||||
{
|
||||
reverseAPIKeys.append("sampleRate");
|
||||
if (settingsKeys.contains("sampleRate") || force) {
|
||||
forwardChange = true;
|
||||
}
|
||||
|
||||
if ((m_settings.m_volume != settings.m_volume) || force)
|
||||
if (settingsKeys.contains("volume") || force)
|
||||
{
|
||||
reverseAPIKeys.append("volume");
|
||||
m_audioInput.setVolume(settings.m_volume);
|
||||
qDebug() << "AudioInput::applySettings: set volume to " << settings.m_volume;
|
||||
}
|
||||
|
||||
if ((m_settings.m_log2Decim != settings.m_log2Decim) || force)
|
||||
if (settingsKeys.contains("log2Decim") || force)
|
||||
{
|
||||
reverseAPIKeys.append("log2Decim");
|
||||
forwardChange = true;
|
||||
|
||||
if (m_running)
|
||||
@ -309,9 +303,8 @@ void AudioInput::applySettings(const AudioInputSettings& settings, bool force, b
|
||||
}
|
||||
}
|
||||
|
||||
if ((m_settings.m_iqMapping != settings.m_iqMapping) || force)
|
||||
if (settingsKeys.contains("iqMapping") || force)
|
||||
{
|
||||
reverseAPIKeys.append("iqMapping");
|
||||
forwardChange = true;
|
||||
|
||||
if (m_running) {
|
||||
@ -319,16 +312,20 @@ void AudioInput::applySettings(const AudioInputSettings& settings, bool force, b
|
||||
}
|
||||
}
|
||||
|
||||
if (settings.m_useReverseAPI)
|
||||
if (settingsKeys.contains("useReverseAPI"))
|
||||
{
|
||||
bool fullUpdate = ((m_settings.m_useReverseAPI != settings.m_useReverseAPI) && settings.m_useReverseAPI) ||
|
||||
(m_settings.m_reverseAPIAddress != settings.m_reverseAPIAddress) ||
|
||||
(m_settings.m_reverseAPIPort != settings.m_reverseAPIPort) ||
|
||||
(m_settings.m_reverseAPIDeviceIndex != settings.m_reverseAPIDeviceIndex);
|
||||
webapiReverseSendSettings(reverseAPIKeys, settings, fullUpdate || force);
|
||||
bool fullUpdate = (settingsKeys.contains("useReverseAPI") && settings.m_useReverseAPI) ||
|
||||
settingsKeys.contains("reverseAPIAddress") ||
|
||||
settingsKeys.contains("reverseAPIPort") ||
|
||||
settingsKeys.contains("reverseAPIDeviceIndex");
|
||||
webapiReverseSendSettings(settingsKeys, settings, fullUpdate || force);
|
||||
}
|
||||
|
||||
m_settings = settings;
|
||||
if (force) {
|
||||
m_settings = settings;
|
||||
} else {
|
||||
m_settings.applySettings(settingsKeys, settings);
|
||||
}
|
||||
|
||||
if (forwardChange)
|
||||
{
|
||||
@ -393,12 +390,12 @@ int AudioInput::webapiSettingsPutPatch(
|
||||
AudioInputSettings settings = m_settings;
|
||||
webapiUpdateDeviceSettings(settings, deviceSettingsKeys, response);
|
||||
|
||||
MsgConfigureAudioInput *msg = MsgConfigureAudioInput::create(settings, force);
|
||||
MsgConfigureAudioInput *msg = MsgConfigureAudioInput::create(settings, deviceSettingsKeys, force);
|
||||
m_inputMessageQueue.push(msg);
|
||||
|
||||
if (m_guiMessageQueue) // forward to GUI if any
|
||||
{
|
||||
MsgConfigureAudioInput *msgToGUI = MsgConfigureAudioInput::create(settings, force);
|
||||
MsgConfigureAudioInput *msgToGUI = MsgConfigureAudioInput::create(settings, deviceSettingsKeys, force);
|
||||
m_guiMessageQueue->push(msgToGUI);
|
||||
}
|
||||
|
||||
@ -460,7 +457,7 @@ void AudioInput::webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings& resp
|
||||
response.getAudioInputSettings()->setReverseApiDeviceIndex(settings.m_reverseAPIDeviceIndex);
|
||||
}
|
||||
|
||||
void AudioInput::webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const AudioInputSettings& settings, bool force)
|
||||
void AudioInput::webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const AudioInputSettings& settings, bool force)
|
||||
{
|
||||
SWGSDRangel::SWGDeviceSettings *swgDeviceSettings = new SWGSDRangel::SWGDeviceSettings();
|
||||
swgDeviceSettings->setDirection(0); // single Rx
|
||||
|
@ -46,20 +46,23 @@ public:
|
||||
|
||||
public:
|
||||
const AudioInputSettings& getSettings() const { return m_settings; }
|
||||
const QList<QString>& getSettingsKeys() const { return m_settingsKeys; }
|
||||
bool getForce() const { return m_force; }
|
||||
|
||||
static MsgConfigureAudioInput* create(const AudioInputSettings& settings, bool force)
|
||||
static MsgConfigureAudioInput* create(const AudioInputSettings& settings, const QList<QString>& settingsKeys, bool force)
|
||||
{
|
||||
return new MsgConfigureAudioInput(settings, force);
|
||||
return new MsgConfigureAudioInput(settings, settingsKeys, force);
|
||||
}
|
||||
|
||||
private:
|
||||
AudioInputSettings m_settings;
|
||||
QList<QString> m_settingsKeys;
|
||||
bool m_force;
|
||||
|
||||
MsgConfigureAudioInput(const AudioInputSettings& settings, bool force) :
|
||||
MsgConfigureAudioInput(const AudioInputSettings& settings, const QList<QString>& settingsKeys, bool force) :
|
||||
Message(),
|
||||
m_settings(settings),
|
||||
m_settingsKeys(settingsKeys),
|
||||
m_force(force)
|
||||
{ }
|
||||
};
|
||||
@ -149,9 +152,9 @@ private:
|
||||
bool openDevice();
|
||||
void closeDevice();
|
||||
bool openAudioDevice(QString deviceName, int sampleRate);
|
||||
void applySettings(const AudioInputSettings& settings, bool force, bool starting=false);
|
||||
void applySettings(const AudioInputSettings& settings, QList<QString> settingsKeys, bool force, bool starting=false);
|
||||
|
||||
void webapiReverseSendSettings(QList<QString>& deviceSettingsKeys, const AudioInputSettings& settings, bool force);
|
||||
void webapiReverseSendSettings(const QList<QString>& deviceSettingsKeys, const AudioInputSettings& settings, bool force);
|
||||
void webapiReverseSendStartStop(bool start);
|
||||
|
||||
private slots:
|
||||
|
@ -73,6 +73,7 @@ void AudioInputGui::resetToDefaults()
|
||||
{
|
||||
m_settings.resetToDefaults();
|
||||
displaySettings();
|
||||
m_forceSettings = true;
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
@ -108,7 +109,13 @@ bool AudioInputGui::handleMessage(const Message& message)
|
||||
if (AudioInput::MsgConfigureAudioInput::match(message))
|
||||
{
|
||||
const AudioInput::MsgConfigureAudioInput& cfg = (AudioInput::MsgConfigureAudioInput&) message;
|
||||
m_settings = cfg.getSettings();
|
||||
|
||||
if (cfg.getForce()) {
|
||||
m_settings = cfg.getSettings();
|
||||
} else {
|
||||
m_settings.applySettings(cfg.getSettingsKeys(), cfg.getSettings());
|
||||
}
|
||||
|
||||
blockApplySettings(true);
|
||||
displaySettings();
|
||||
blockApplySettings(false);
|
||||
@ -203,8 +210,8 @@ void AudioInputGui::refreshSampleRates(QString deviceName)
|
||||
if (deviceName == AudioInputSettings::getFullDeviceName(deviceInfo))
|
||||
{
|
||||
QList<int> sampleRates = deviceInfo.supportedSampleRates();
|
||||
for(int i = 0; i < sampleRates.size(); ++i)
|
||||
{
|
||||
|
||||
for (int i = 0; i < sampleRates.size(); ++i) {
|
||||
ui->sampleRate->addItem(QString("%1").arg(sampleRates[i]));
|
||||
}
|
||||
}
|
||||
@ -212,20 +219,25 @@ void AudioInputGui::refreshSampleRates(QString deviceName)
|
||||
ui->sampleRate->blockSignals(false);
|
||||
|
||||
int index = ui->sampleRate->findText(QString("%1").arg(m_settings.m_sampleRate));
|
||||
if (index >= 0)
|
||||
|
||||
if (index >= 0) {
|
||||
ui->sampleRate->setCurrentIndex(index);
|
||||
else
|
||||
} else {
|
||||
ui->sampleRate->setCurrentIndex(0);
|
||||
}
|
||||
}
|
||||
|
||||
void AudioInputGui::displaySettings()
|
||||
{
|
||||
refreshDeviceList();
|
||||
int index = ui->device->findText(m_settings.m_deviceName);
|
||||
if (index >= 0)
|
||||
|
||||
if (index >= 0) {
|
||||
ui->device->setCurrentIndex(index);
|
||||
else
|
||||
} else {
|
||||
ui->device->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
ui->decim->setCurrentIndex(m_settings.m_log2Decim);
|
||||
ui->volume->setValue((int)(m_settings.m_volume*10.0f));
|
||||
ui->volumeText->setText(QString("%1").arg(m_settings.m_volume, 3, 'f', 1));
|
||||
@ -238,6 +250,7 @@ void AudioInputGui::on_device_currentIndexChanged(int index)
|
||||
(void) index;
|
||||
m_settings.m_deviceName = ui->device->currentText();
|
||||
refreshSampleRates(m_settings.m_deviceName);
|
||||
m_settingsKeys.append("deviceName");
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
@ -245,6 +258,7 @@ void AudioInputGui::on_sampleRate_currentIndexChanged(int index)
|
||||
{
|
||||
(void) index;
|
||||
m_settings.m_sampleRate = ui->sampleRate->currentText().toInt();
|
||||
m_settingsKeys.append("sampleRate");
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
@ -255,6 +269,7 @@ void AudioInputGui::on_decim_currentIndexChanged(int index)
|
||||
}
|
||||
|
||||
m_settings.m_log2Decim = index;
|
||||
m_settingsKeys.append("log2Decim");
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
@ -262,6 +277,7 @@ void AudioInputGui::on_volume_valueChanged(int value)
|
||||
{
|
||||
m_settings.m_volume = value/10.0f;
|
||||
ui->volumeText->setText(QString("%1").arg(m_settings.m_volume, 3, 'f', 1));
|
||||
m_settingsKeys.append("volume");
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
@ -269,6 +285,7 @@ void AudioInputGui::on_channels_currentIndexChanged(int index)
|
||||
{
|
||||
m_settings.m_iqMapping = (AudioInputSettings::IQMapping)index;
|
||||
updateSampleRateAndFrequency();
|
||||
m_settingsKeys.append("iqMapping");
|
||||
sendSettings();
|
||||
}
|
||||
|
||||
@ -291,8 +308,9 @@ void AudioInputGui::updateHardware()
|
||||
{
|
||||
if (m_doApplySettings)
|
||||
{
|
||||
AudioInput::MsgConfigureAudioInput* message = AudioInput::MsgConfigureAudioInput::create(m_settings, m_forceSettings);
|
||||
AudioInput::MsgConfigureAudioInput* message = AudioInput::MsgConfigureAudioInput::create(m_settings, m_settingsKeys, m_forceSettings);
|
||||
m_sampleSource->getInputMessageQueue()->push(message);
|
||||
m_settingsKeys.clear();
|
||||
m_forceSettings = false;
|
||||
m_updateTimer.stop();
|
||||
}
|
||||
@ -315,6 +333,10 @@ void AudioInputGui::openDeviceSettingsDialog(const QPoint& p)
|
||||
m_settings.m_reverseAPIAddress = dialog.getReverseAPIAddress();
|
||||
m_settings.m_reverseAPIPort = dialog.getReverseAPIPort();
|
||||
m_settings.m_reverseAPIDeviceIndex = dialog.getReverseAPIDeviceIndex();
|
||||
m_settingsKeys.append("useReverseAPI");
|
||||
m_settingsKeys.append("reverseAPIAddress");
|
||||
m_settingsKeys.append("reverseAPIPort");
|
||||
m_settingsKeys.append("reverseAPIDeviceIndex");
|
||||
|
||||
sendSettings();
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ private:
|
||||
bool m_doApplySettings;
|
||||
bool m_forceSettings;
|
||||
AudioInputSettings m_settings;
|
||||
QList<QString> m_settingsKeys;
|
||||
QTimer m_updateTimer;
|
||||
DeviceSampleSource* m_sampleSource;
|
||||
int m_sampleRate;
|
||||
|
@ -97,3 +97,69 @@ bool AudioInputSettings::deserialize(const QByteArray& data)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void AudioInputSettings::applySettings(const QStringList& settingsKeys, const AudioInputSettings& settings)
|
||||
{
|
||||
if (settingsKeys.contains("deviceName")) {
|
||||
m_deviceName = settings.m_deviceName;
|
||||
}
|
||||
if (settingsKeys.contains("sampleRate")) {
|
||||
m_sampleRate = settings.m_sampleRate;
|
||||
}
|
||||
if (settingsKeys.contains("volume")) {
|
||||
m_volume = settings.m_volume;
|
||||
}
|
||||
if (settingsKeys.contains("log2Decim")) {
|
||||
m_log2Decim = settings.m_log2Decim;
|
||||
}
|
||||
if (settingsKeys.contains("iqMapping")) {
|
||||
m_iqMapping = settings.m_iqMapping;
|
||||
}
|
||||
if (settingsKeys.contains("useReverseAPI")) {
|
||||
m_useReverseAPI = settings.m_useReverseAPI;
|
||||
}
|
||||
if (settingsKeys.contains("reverseAPIAddress")) {
|
||||
m_reverseAPIAddress = settings.m_reverseAPIAddress;
|
||||
}
|
||||
if (settingsKeys.contains("reverseAPIPort")) {
|
||||
m_reverseAPIPort = settings.m_reverseAPIPort;
|
||||
}
|
||||
if (settingsKeys.contains("reverseAPIDeviceIndex")) {
|
||||
m_reverseAPIDeviceIndex = settings.m_reverseAPIDeviceIndex;
|
||||
}
|
||||
}
|
||||
|
||||
QString AudioInputSettings::getDebugString(const QStringList& settingsKeys, bool force) const
|
||||
{
|
||||
std::ostringstream ostr;
|
||||
|
||||
if (settingsKeys.contains("deviceName") || force) {
|
||||
ostr << " m_deviceName: " << m_deviceName.toStdString();
|
||||
}
|
||||
if (settingsKeys.contains("sampleRate") || force) {
|
||||
ostr << " m_sampleRate: " << m_sampleRate;
|
||||
}
|
||||
if (settingsKeys.contains("volume") || force) {
|
||||
ostr << " m_volume: " << m_volume;
|
||||
}
|
||||
if (settingsKeys.contains("log2Decim") || force) {
|
||||
ostr << " m_log2Decim: " << m_log2Decim;
|
||||
}
|
||||
if (settingsKeys.contains("iqMapping") || force) {
|
||||
ostr << " m_iqMapping: " << m_iqMapping;
|
||||
}
|
||||
if (settingsKeys.contains("useReverseAPI") || force) {
|
||||
ostr << " m_useReverseAPI: " << m_useReverseAPI;
|
||||
}
|
||||
if (settingsKeys.contains("reverseAPIAddress") || force) {
|
||||
ostr << " m_reverseAPIAddress: " << m_reverseAPIAddress.toStdString();
|
||||
}
|
||||
if (settingsKeys.contains("reverseAPIPort") || force) {
|
||||
ostr << " m_reverseAPIPort: " << m_reverseAPIPort;
|
||||
}
|
||||
if (settingsKeys.contains("reverseAPIDeviceIndex") || force) {
|
||||
ostr << " m_reverseAPIDeviceIndex: " << m_reverseAPIDeviceIndex;
|
||||
}
|
||||
|
||||
return QString(ostr.str().c_str());
|
||||
}
|
||||
|
@ -58,7 +58,8 @@ struct AudioInputSettings {
|
||||
return deviceInfo.deviceName();
|
||||
#endif
|
||||
}
|
||||
|
||||
void applySettings(const QStringList& settingsKeys, const AudioInputSettings& settings);
|
||||
QString getDebugString(const QStringList& settingsKeys, bool force=false) const;
|
||||
};
|
||||
|
||||
#endif /* _AUDIOINPUT_AUDIOINPUTSETTINGS_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user