1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-25 01:18:38 -05:00

SDRPlayV3: prevent segfault when SDRPlay library fails to initialize

This commit is contained in:
f4exb 2022-02-06 12:08:04 +01:00
parent 50d61c7247
commit 7880a523a7
3 changed files with 24 additions and 13 deletions

View File

@ -146,7 +146,7 @@ bool SDRPlayV3Input::start()
m_sdrPlayThread->setFcPos((int) m_settings.m_fcPos);
m_sdrPlayThread->startWork();
m_running = true;
m_running = m_sdrPlayThread->isRunning();
applySettings(m_settings, true, true);
return true;

View File

@ -44,10 +44,27 @@ SDRPlayV3Thread::~SDRPlayV3Thread()
void SDRPlayV3Thread::startWork()
{
sdrplay_api_ErrT err;
sdrplay_api_CallbackFnsT cbFns;
cbFns.StreamACbFn = &SDRPlayV3Thread::callbackHelper;
cbFns.StreamBCbFn = &SDRPlayV3Thread::callbackHelper;
cbFns.EventCbFn = &SDRPlayV3Thread::eventCallback;
if ((err = sdrplay_api_Init(m_dev->dev, &cbFns, this)) != sdrplay_api_Success)
{
qCritical() << "SDRPlayV3Thread::run: sdrplay_api_Init error: " << sdrplay_api_GetErrorString(err);
m_running = false;
return;
}
m_startWaitMutex.lock();
start();
while(!m_running)
while(!m_running) {
m_startWaiter.wait(&m_startWaitMutex, 100);
}
m_startWaitMutex.unlock();
}
@ -58,9 +75,12 @@ void SDRPlayV3Thread::stopWork()
if (m_running)
{
m_running = false;
if ((err = sdrplay_api_Uninit(m_dev->dev)) != sdrplay_api_Success)
if ((err = sdrplay_api_Uninit(m_dev->dev)) != sdrplay_api_Success) {
qWarning() << "SDRPlayV3Thread::callbackHelper: sdrplay_api_Uninit error: " << sdrplay_api_GetErrorString(err);
}
}
wait();
}
@ -94,16 +114,6 @@ bool SDRPlayV3Thread::waitForRfChanged()
// Don't really need a thread here - just using same structure as other plugins
void SDRPlayV3Thread::run()
{
sdrplay_api_ErrT err;
sdrplay_api_CallbackFnsT cbFns;
cbFns.StreamACbFn = &SDRPlayV3Thread::callbackHelper;
cbFns.StreamBCbFn = &SDRPlayV3Thread::callbackHelper;
cbFns.EventCbFn = &SDRPlayV3Thread::eventCallback;
if ((err = sdrplay_api_Init(m_dev->dev, &cbFns, this)) != sdrplay_api_Success)
qCritical() << "SDRPlayV3Thread::run: sdrplay_api_Init error: " << sdrplay_api_GetErrorString(err);
m_running = true;
m_startWaiter.wakeAll();
}

View File

@ -37,6 +37,7 @@ public:
void startWork();
void stopWork();
bool isRunning() const { return m_running; }
void setSamplerate(int samplerate);
void setLog2Decimation(unsigned int log2_decim);
void setFcPos(int fcPos);