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

Fix v4l2 wrapper usage for 32 bit systems #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
23 changes: 16 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,22 @@ impl fmt::Debug for IntervalInfo {

Ok(())
}
IntervalInfo::Stepwise { min, max, step } => write!(
f,
"Stepwise from {}fps to {}fps by {}fps",
max.1 / max.0,
min.1 / min.0,
step.1 / step.0
),
IntervalInfo::Stepwise { min, max, step }
if min.0 != 0 && max.0 != 0 && step.0 != 0 =>
{
write!(
f,
"Stepwise from {}fps to {}fps by {}fps",
max.1 / max.0,
min.1 / min.0,
step.1 / step.0
)
}
IntervalInfo::Stepwise {
min: _,
max: _,
step: _,
} => write!(f, "Invalid stepwise interval info with 0 denominators"),
}
}
}
Expand Down
30 changes: 26 additions & 4 deletions src/v4l2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,21 @@ mod ll {

pub use self::v4l2_close as close;
pub use self::v4l2_ioctl as ioctl;
pub use self::v4l2_mmap as mmap;
pub use self::v4l2_munmap as munmap;
pub use self::v4l2_open as open;

pub unsafe fn mmap(
start: *mut c_void,
length: size_t,
prot: c_int,
flags: c_int,
fd: RawFd,
offset: off_t,
) -> *mut c_void {
// Note the subtle function signature mismatch between mmap and v4l2_mmap.
v4l2_mmap(start, length, prot, flags, fd, offset as i64)
}

#[link(name = "v4l2")]
extern "C" {
pub fn v4l2_open(file: *const c_char, flags: c_int, arg: c_int) -> RawFd;
Expand All @@ -32,18 +43,29 @@ mod ll {
prot: c_int,
flags: c_int,
fd: RawFd,
offset: off_t,
offset: i64,
) -> *mut c_void;
pub fn v4l2_munmap(start: *mut c_void, length: size_t) -> c_int;
}
}

#[cfg(feature = "no_wrapper")]
mod ll {
use libc::{c_int, c_ulong, c_void};
use libc::{c_int, c_ulong, c_void, off_t, size_t};
use std::os::unix::io::RawFd;

pub use libc::{close, mmap, munmap, open};
pub use libc::{close, munmap, open};

pub unsafe fn mmap(
start: *mut c_void,
length: size_t,
prot: c_int,
flags: c_int,
fd: RawFd,
offset: off_t,
) -> *mut c_void {
libc::mmap(start, length, prot, flags, fd, offset)
}

extern "C" {
pub fn ioctl(fd: RawFd, request: c_ulong, argp: *mut c_void) -> c_int;
Expand Down