Skip to content

Commit

Permalink
Try alternate way of checking for device failures.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Dec 31, 2023
1 parent 2110bac commit 3d970ae
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/audio/IAudioDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions src/audio/PortAudioDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ PortAudioDevice::~PortAudioDevice()
}
}

bool PortAudioDevice::isRunning()
{
return deviceStream_ != nullptr;
}

void PortAudioDevice::start()
{
PaStreamParameters streamParameters;
Expand Down
10 changes: 6 additions & 4 deletions src/audio/PortAudioDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions src/audio/PulseAudioDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ PulseAudioDevice::~PulseAudioDevice()
}
}

bool PulseAudioDevice::isRunning()
{
return stream_ != nullptr;
}

void PulseAudioDevice::start()
{
pa_sample_spec sample_specification;
Expand Down
10 changes: 6 additions & 4 deletions src/audio/PulseAudioDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
};

Expand Down Expand Up @@ -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;
}
}

Expand Down

0 comments on commit 3d970ae

Please sign in to comment.