Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1628 LibUsb Error -99 During Device Discovery #1629

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
import io.github.dsheirer.source.tuner.sdrplay.rspDuo.DiscoveredRspDuoTuner1;
import io.github.dsheirer.source.tuner.ui.DiscoveredTunerModel;
import io.github.dsheirer.util.ThreadPool;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.usb4java.Context;
Expand All @@ -55,14 +62,6 @@
import org.usb4java.HotplugCallbackHandle;
import org.usb4java.LibUsb;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/**
* Tuner manager provides access to tuners using USB, recording, sound-card and system-daemon accessible devices. This
* manager also supports hot-plug detection and black-listing of discovered tuners so that they can be used with other
Expand Down Expand Up @@ -187,10 +186,10 @@ private void discoverUSBTuners()
DeviceList deviceList = new DeviceList();
int deviceCount = LibUsb.getDeviceList(mLibUsbApplicationContext, deviceList);

mLog.info("LibUsb - discovered [" + deviceCount + "] potential usb devices");

if(deviceCount >= 0)
{
mLog.info("LibUsb - discovered [" + deviceCount + "] potential usb devices");

for(Device device: deviceList)
{
int bus = LibUsb.getBusNumber(device);
Expand Down Expand Up @@ -228,9 +227,40 @@ private void discoverUSBTuners()
//Unref the device - it will be rediscovered under the device context when it is started
LibUsb.unrefDevice(device);
}
}

LibUsb.freeDeviceList(deviceList, false);
LibUsb.freeDeviceList(deviceList, false);
}
//If the get device list operation generated error -99, turn on warning logging and try device list
// again to see what's causing it.
else if(deviceCount == LibUsb.ERROR_OTHER)
{
try
{
mLog.info("LibUsb reported error -99 during get device list - increasing logging level and retrying");
LibUsb.setOption(mLibUsbApplicationContext, LibUsb.OPTION_LOG_LEVEL, LibUsb.LOG_LEVEL_WARNING);
deviceCount = LibUsb.getDeviceList(mLibUsbApplicationContext, deviceList);
if(deviceCount >=0)
{
mLog.info("LibUsb - get device list count [" + deviceCount + "] during retry");
LibUsb.freeDeviceList(deviceList, false);
}
else
{
mLog.info("LibUsb - get device list reported error [" + deviceCount + "/" +
LibUsb.errorName(deviceCount) + "] during retry");
}
LibUsb.setOption(mLibUsbApplicationContext, LibUsb.OPTION_LOG_LEVEL, LibUsb.LOG_LEVEL_NONE);
mLog.info("LibUse - get device list reattempt complete - if additional logging was generated please notify developer");
}
catch(Exception e)
{
mLog.info("LibUsb error during get device list reattempt", e);
}
}
else
{
mLog.error("LibUsb - error [" + deviceCount + "/" + LibUsb.errorName(deviceCount) + "] during get device list");
}
}
catch(Exception e)
{
Expand Down