From 3d970ae2bab7db625987044d39fc5b2234ec4841 Mon Sep 17 00:00:00 2001 From: Mooneer Salem Date: Sun, 31 Dec 2023 11:06:02 -0800 Subject: [PATCH] Try alternate way of checking for device failures. --- src/audio/IAudioDevice.h | 2 ++ src/audio/PortAudioDevice.cpp | 5 +++++ src/audio/PortAudioDevice.h | 10 ++++++---- src/audio/PulseAudioDevice.cpp | 5 +++++ src/audio/PulseAudioDevice.h | 10 ++++++---- src/main.cpp | 14 ++++++++++---- 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/audio/IAudioDevice.h b/src/audio/IAudioDevice.h index 0a185340e..523b10903 100644 --- a/src/audio/IAudioDevice.h +++ b/src/audio/IAudioDevice.h @@ -43,6 +43,8 @@ class IAudioDevice virtual void start() = 0; virtual void stop() = 0; + virtual bool isRunning() = 0; + // Sets user friendly description of device. Not used by all engines. void setDescription(std::string desc); diff --git a/src/audio/PortAudioDevice.cpp b/src/audio/PortAudioDevice.cpp index 78b726ce7..1b47e0883 100644 --- a/src/audio/PortAudioDevice.cpp +++ b/src/audio/PortAudioDevice.cpp @@ -57,6 +57,11 @@ PortAudioDevice::~PortAudioDevice() } } +bool PortAudioDevice::isRunning() +{ + return deviceStream_ != nullptr; +} + void PortAudioDevice::start() { PaStreamParameters streamParameters; diff --git a/src/audio/PortAudioDevice.h b/src/audio/PortAudioDevice.h index ef7e34510..4d1c722e0 100644 --- a/src/audio/PortAudioDevice.h +++ b/src/audio/PortAudioDevice.h @@ -32,11 +32,13 @@ class PortAudioDevice : public IAudioDevice public: virtual ~PortAudioDevice(); - virtual int getNumChannels() { return numChannels_; } - virtual int getSampleRate() const { return sampleRate_; } + virtual int getNumChannels() override { return numChannels_; } + virtual int getSampleRate() const override { return sampleRate_; } - virtual void start(); - virtual void stop(); + virtual void start() override; + virtual void stop() override; + + virtual bool isRunning() override; protected: // PortAudioDevice cannot be created directly, only via PortAudioEngine. diff --git a/src/audio/PulseAudioDevice.cpp b/src/audio/PulseAudioDevice.cpp index 403afe52a..942fd7f32 100644 --- a/src/audio/PulseAudioDevice.cpp +++ b/src/audio/PulseAudioDevice.cpp @@ -55,6 +55,11 @@ PulseAudioDevice::~PulseAudioDevice() } } +bool PulseAudioDevice::isRunning() +{ + return stream_ != nullptr; +} + void PulseAudioDevice::start() { pa_sample_spec sample_specification; diff --git a/src/audio/PulseAudioDevice.h b/src/audio/PulseAudioDevice.h index 2a76b6bc9..13274ed55 100644 --- a/src/audio/PulseAudioDevice.h +++ b/src/audio/PulseAudioDevice.h @@ -36,11 +36,13 @@ class PulseAudioDevice : public IAudioDevice public: virtual ~PulseAudioDevice(); - virtual int getNumChannels() { return numChannels_; } - virtual int getSampleRate() const { return sampleRate_; } + virtual int getNumChannels() override { return numChannels_; } + virtual int getSampleRate() const override { return sampleRate_; } - virtual void start(); - virtual void stop(); + virtual void start() override; + virtual void stop() override; + + virtual bool isRunning() override; protected: // PulseAudioDevice cannot be created directly, only via PulseAudioEngine. diff --git a/src/main.cpp b/src/main.cpp index 4e7b09802..8c2e45135 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2679,10 +2679,6 @@ void MainFrame::startRxStream() { CallAfter([&, error]() { wxMessageBox(wxString::Format("Error encountered while processing audio: %s", error), wxT("Error"), wxOK); - - // Force shutdown of connection - wxCommandEvent tmpEvent; - OnTogBtnOnOff(tmpEvent); }); }; @@ -2912,6 +2908,16 @@ void MainFrame::startRxStream() } if (g_verbose) fprintf(stderr, "starting tx/rx processing thread\n"); + + // Work around an issue where the buttons stay disabled even if there + // is an error opening one or more audio device(s). + bool txDevicesRunning = + (!txInSoundDevice || txInSoundDevice->isRunning()) && + (!txOutSoundDevice || txOutSoundDevice->isRunning()); + bool rxDevicesRunning = + (rxInSoundDevice && rxInSoundDevice->isRunning()) && + (rxOutSoundDevice && rxOutSoundDevice->isRunning()); + m_RxRunning = txDevicesRunning && rxDevicesRunning; } }