Giter Club home page Giter Club logo

Comments (11)

bvernoux avatar bvernoux commented on July 23, 2024

I suspect this "issue" mainly comes from libusb which does not manage correctly hotplug by default

from airspyone_host.

johanhedin avatar johanhedin commented on July 23, 2024

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:

error = libusb_handle_events_timeout_completed(device->usb_context, &timeout, NULL);

or called, like here:
if (libusb_submit_transfer(usb_transfer) != 0)

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:

pthread_cond_signal(&device->consumer_cv);

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.

bvernoux avatar bvernoux commented on July 23, 2024

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.

johanhedin avatar johanhedin commented on July 23, 2024

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.

bvernoux avatar bvernoux commented on July 23, 2024

Thanks for your contribution it is fixed with #76

from airspyone_host.

johanhedin avatar johanhedin commented on July 23, 2024

Thank you for the quick response!

from airspyone_host.

touil avatar touil commented on July 23, 2024

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.

johanhedin avatar johanhedin commented on July 23, 2024

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.

touil avatar touil commented on July 23, 2024

Correct. The line in question is commented in other implementations (like airspy_adsb.)

from airspyone_host.

bvernoux avatar bvernoux commented on July 23, 2024

This issue shall be fixed with #78

from airspyone_host.

bvernoux avatar bvernoux commented on July 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.