Comments (11)
I suspect this "issue" mainly comes from libusb which does not manage correctly hotplug by default
- It will be interesting to use a newer/latest stable libusb which probably cancel transfer properly and return error codes (which are all checked in libairspy)...
See https://sourceforge.net/p/libusb/mailman/libusb-devel/thread/4A9BB29B.1030602%40edigma.com/#msg23442207- If issue is not fixed maybe, it will be interesting to implement https://libusb.sourceforge.io/api-1.0/libusb_hotplug.html to see if that fix the issue, anyway an investigation shall be done to understand what happen exactly ...
from airspyone_host.
Full hotpluging looks nice, but I think than this issue is actually in the current libairspy implementation (I might be wrong ofcourse).
When the device is removed, all libusb_* functions that are blocking, like here:
airspyone_host/libairspy/src/airspy.c
Line 503 in 229d5a5
or called, like here:
airspyone_host/libairspy/src/airspy.c
Line 478 in 229d5a5
will return with some libusb error and libairspy will, as you mention, act on the error and set
device->streaming = false
which will stop streaming. But setting device->streaming = false
without releasing the conditional will cause the consumer_threadproc
to never exit.
The "cleanup release" of the conditional that is called during a "normal" stop here:
airspyone_host/libairspy/src/airspy.c
Line 524 in 229d5a5
is not called when
streaming == false
as in this error case.
I think the fix is as simple as making sure that the conditional is signaled from the transfer_threadproc
when libusb_handle_events_timeout_completed
returns an error and sets device->streaming = false
.
I will create a pull request for you to look at.
from airspyone_host.
Yes very interesting thanks for the analyze
Such use case was not tested as it is not "normal process" to remove the USB cable when streaming anyway it is a good improvement if that can be correctly managed in libairspy.
To be checked with your code which reproduce the issue more "easily" with a PR to test the fix.
Note: About libusb hotplug support it seems still not supported for Windows see libusb/libusb#86
from airspyone_host.
You can easily run your own "hotplug" with the current libairspy (if we disregard the current deadlock) by simply checking airspy_is_streaming
. If that function returns error, it means that the device disappeared somehow and you can close the device and try opening it again. And just repeat until the device is inserted.
My use case is using an Airspy from a program in deamon mode so I like to have a robust implementation that can handle if the device is pulled for some reason.
BTW, there are memory leaks in libairspy as well when pulling a device that are streaming (if not valgrind is messing up something here...). I think I have some leads, but some way of dealing with the deadlock seem like priority one.
from airspyone_host.
Thanks for your contribution it is fixed with #76
from airspyone_host.
Thank you for the quick response!
from airspyone_host.
There is still one problem. If one transfer fails, the entire streaming will be stopped. This could happen more often than you think depending on the USB host hardware and the quality of the transmission line. That's why the buffer sizes are aligned to specific values so the streaming can resume without corrupting the upcoming data. Losing one transfer is less dramatic than stopping the entire streaming session. In some scenarios, stopping the stream cannot be tolerated.
A better solution would be to detect if the device is still alive using a time stamp which is updated on successful receive, and only stop the streaming if no data is reaching the host after some timeout.
from airspyone_host.
There is still one problem. If one transfer fails, the entire streaming will be stopped.
Point taken. But as far as I can se, this was already the case before #76. Right?
from airspyone_host.
Correct. The line in question is commented in other implementations (like airspy_adsb.)
from airspyone_host.
This issue shall be fixed with #78
from airspyone_host.
This issue is now fixed with merge of #78
- It will be nice to have feedback from users to confirm all work fine in normal cases (on different OS/Computer) and also when USB is disconnected during streaming which shall be work fine now
from airspyone_host.
Related Issues (20)
- compilation HOT 1
- 10MHz Bandwidth AirSpy Mini HOT 1
- airspy_close() blocks for ever if disconnect from USB unconditionally HOT 1
- Is this program support Airspy HF+?
- Compilation issue in Windows 10 with MSVC/CMake HOT 2
- missing license for the repo HOT 1
- Airspy GR-Windows support HOT 1
- Inconsistent line endings in airspy.c HOT 1
- libusb transfers not properly cleaned up if device is unplugged while streaming HOT 1
- Ship the udev rules upstream HOT 5
- position of dropped_samples in stream HOT 12
- use clang14.0.5 build opencv,but “always_inline function '_mm_shuffle_epi8' requires target feature 'ssse3', but would be inlined into function 'ExtractAlpha_SSE41' that is compiled without support for 'ssse3'” HOT 1
- BUG: Adding users to group `plugdev` HOT 1
- build fails on Raspberry Pi (debian buster) because of libusb_wrap_sys_device() API not supported HOT 5
- libairspy is slow when receiving float32 iq on Apple M1 HOT 6
- TR setup on Raspberry Pi not creating or saving audio files to shortName Dir HOT 1
- Use of uninitialized variables after commit 099256f HOT 8
- airspy_rx could use ppm correction option (fixed with new tool airspy_calibrate) HOT 7
- Receive callback stops being called HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from airspyone_host.