Skip to content

Commit

Permalink
#1511 Resolves issue with SDRPlay library crashes application when li…
Browse files Browse the repository at this point in the history
…nux service is in stopped state.
  • Loading branch information
Dennis Sheirer committed Apr 11, 2023
1 parent 372d2ff commit e4c6733
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
14 changes: 12 additions & 2 deletions src/main/java/io/github/dsheirer/source/tuner/TunerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,19 @@ public static RspTuner getRspTuner(DeviceInfo deviceInfo, ChannelizerType channe
{
//API instance is retained across the lifecycle of the constructed device, so we only close it if we don't get
//a device from it.
SDRplay api = new SDRplay();
SDRplay api = null;

if(api.isAvailable())
try
{
api = new SDRplay();
}
catch(SDRPlayException se)
{
mLog.info("Caught the exception here ...", se);
api = null;
}

if(api != null && api.isAvailable())
{
Device device = api.getDevice(deviceInfo);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,18 @@ private void discoverSdrPlayTuners()

//Note: we have to keep this first API instance open while we use any RSP tuners, otherwise the additional API
//instance(s) used by the individual tuners become unresponsive. Note sure why.
mSDRplay = new SDRplay();

if(mSDRplay.isAvailable())
try
{
mSDRplay = new SDRplay();
}
catch(SDRPlayException se)
{
mLog.error("Couldn't load SDRPlay API");
mSDRplay = null;
}

if(mSDRplay != null && mSDRplay.isAvailable())
{
try
{
Expand Down Expand Up @@ -333,7 +342,11 @@ private void discoverSdrPlayTuners()
}
else
{
mSDRplay.close();
if(mSDRplay != null)
{
mSDRplay.close();
}

mSDRplay = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public class SDRplay
/**
* Constructs an instance of the SDRPLay API
*/
public SDRplay()
public SDRplay() throws SDRPlayException
{
mSdrplayLibraryLoaded = loadLibrary();

Expand All @@ -116,6 +116,11 @@ public SDRplay()
mLog.info("API library - open status: " + openStatus);
}
mAvailable = openStatus.success() && getVersion().isSupported();

if(openStatus == Status.FAIL)
{
throw new SDRPlayException("Service not available");
}
}
else
{
Expand Down Expand Up @@ -693,23 +698,23 @@ public static void main(String[] args)
* Java will look there for the library, without having to specify it as a launcher
* option. This would allow for users that have installed the API to an alternate location.
*/
SDRplay sdrplay = new SDRplay();
Status status = sdrplay.open();
mLog.info("Open Status: " + status);

try
{
SDRplay sdrplay = new SDRplay();
Status status = sdrplay.open();
mLog.info("Open Status: " + status);

for(DeviceInfo deviceInfo: sdrplay.getDeviceInfos())
{
mLog.info("Found: " + deviceInfo);
}
Status closeStatus = sdrplay.close();
mLog.info("Close Status: " + closeStatus);
}
catch(SDRPlayException se)
{
mLog.info("Error", se);
}

Status closeStatus = sdrplay.close();
mLog.info("Close Status: " + closeStatus);
}
}

0 comments on commit e4c6733

Please sign in to comment.