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

basic multi-plane support #71

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

illegalprime
Copy link

I care about creating a capture stream with a multi-plane camera. I have a basic version of it working, with inspiration from your mplane branch. What works:

  1. get/set/list formats
  2. create an mmap capture stream
  3. stream frames from it

@tepperson2
Copy link

I would like to see this merged into a release as I am also interested in using this on an imx8 system.

Comment on lines +35 to +38
match self {
Type::VideoCaptureMplane | Type::VideoOutputMplane => true,
_ => false,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: there's a matches!(self, Type::VideoCaptureMplane | Type::VideoOutputMplane) macro for this:

Suggested change
match self {
Type::VideoCaptureMplane | Type::VideoOutputMplane => true,
_ => false,
}
matches!(self, Type::VideoCaptureMplane | Type::VideoOutputMplane)

Comment on lines +109 to +120
let ptr = v4l2::mmap(
ptr::null_mut(),
plane.length as usize,
libc::PROT_READ | libc::PROT_WRITE,
libc::MAP_SHARED,
self.handle.fd(),
plane.m.mem_offset as libc::off_t,
)?;

planes.push(slice::from_raw_parts_mut::<u8>(
ptr as *mut u8, plane.length as usize
));

Choose a reason for hiding this comment

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

When I tried to use this branch for my application, which use both multi plane and single plane, I received error with single plane device. This fix works with my environment.

Suggested change
let ptr = v4l2::mmap(
ptr::null_mut(),
plane.length as usize,
libc::PROT_READ | libc::PROT_WRITE,
libc::MAP_SHARED,
self.handle.fd(),
plane.m.mem_offset as libc::off_t,
)?;
planes.push(slice::from_raw_parts_mut::<u8>(
ptr as *mut u8, plane.length as usize
));
let length = if !self.buf_type.planar() { v4l2_buf.length as usize } else { plane.length as usize };
let ptr = v4l2::mmap(
ptr::null_mut(),
length,
libc::PROT_READ | libc::PROT_WRITE,
libc::MAP_SHARED,
self.handle.fd(),
plane.m.mem_offset as libc::off_t,
)?;
planes.push(slice::from_raw_parts_mut::<u8>(
ptr as *mut u8, length,
));

@Type1J
Copy link

Type1J commented Dec 21, 2023

@raymanfx, @illegalprime, and @anatawa12 I have a project that uses a single plane, and a plan to add support for a multiple plane device. This PR only introduced only 1 breaking change (this project is still in 0 major, so that shouldn't be an issue) to my project, which is that Stream::next() gives a slice of slices instead of a slice. The type system will give the user information about what needs changing, and the Cargo.lock file will prevent the change from occurring for people who just want to make a working build of something, and don't want to fix anything to work with newer libs at the moment, so this PR can be merged as soon as illegalprime#1 lands. Thanks!

@illegalprime
Copy link
Author

Thank you for cleaning up the conflicts! Even though nobody's experience would necessarily break with this addition it should still not be merged until the author decides this is the abstraction they prefer.

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.

5 participants