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

Don't block when unplugging camera #48

Merged
merged 7 commits into from
Jun 12, 2022
Merged

Conversation

spebern
Copy link
Contributor

@spebern spebern commented Jan 5, 2022

This resolves #16.

Additionally, are you interested in supporting a timeout for polling the frames? Using pselect this is doable now.

@raymanfx
Copy link
Owner

Thanks! This is a rather invasive change so I'll probably need some more days to review everything.

Side note: I wonder if it would be better to rely on the pselect implementation of the libc crate [1]?

@spebern
Copy link
Contributor Author

spebern commented Feb 17, 2022

Take your time :).

This is using the pselect of the libc crate: 324458d#diff-3580938c9bca860af321337225afa27f299ca34ebfb674d4d4a0a7c3f516331dR45

@spebern
Copy link
Contributor Author

spebern commented Mar 22, 2022

Have you had time to look at it yet? Is there any way that I can support you here?

Copy link
Owner

@raymanfx raymanfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. Would you mind rebasing this against the current master branch?
I left some comments in the code.

@@ -354,13 +361,19 @@ impl io::Write for Device {
/// Acquiring a handle facilitates (possibly mutating) interactions with the device.
pub struct Handle {
fd: std::os::raw::c_int,
fd_set: FdSet,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I would prefer a lazy initialization approach: create the FdSet inside fd_set as needed and store it in an Option<FdSet> in Handle. An fd set is a pure function of the fd in our case and I feel like our code should reflect that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem if I understand your suggestion correctly is, that initializing the FdSet later requires mutable access to the Handl, but it is stored in an Arc.

}
}

pub fn make_timespec(duration: time::Duration) -> libc::timespec {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Contributor Author

@spebern spebern Apr 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a commit for timeouts inside streams.

@@ -214,6 +243,15 @@ impl<'a, 'b> OutputStream<'b> for Stream<'a> {

fn dequeue(&mut self) -> io::Result<usize> {
let mut v4l2_buf: v4l2_buffer;

pselect(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for doing pselect here?
IIRC, a device unplug event can affect the dequeue event of capture streams and the queue event of output streams, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I put the select before each dequeue and queue because I thought waiting for readiness is always correct.

@raymanfx raymanfx merged commit ec11c12 into raymanfx:master Jun 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stream.next() blocks when camera unplugged
2 participants