From 40e37801d673b5f6bc4200fc0e956401c60f0a44 Mon Sep 17 00:00:00 2001 From: "Christopher N. Hesse" Date: Sat, 4 May 2024 16:53:31 +0200 Subject: [PATCH] Make v4l2_sys a hard dependency libv4l is really the only feature at the moment. Directly import the v4l2 definitions as necessary and get rid of blanket imports. Signed-off-by: Christopher N. Hesse --- Cargo.toml | 4 +--- src/capability.rs | 2 +- src/control.rs | 2 +- src/device.rs | 6 +++++- src/format/description.rs | 3 ++- src/format/mod.rs | 2 +- src/fraction.rs | 3 ++- src/frameinterval.rs | 17 +++++++++++------ src/framesize.rs | 14 +++++++++----- src/io/mmap/arena.rs | 3 ++- src/io/mmap/stream.rs | 3 ++- src/io/userptr/arena.rs | 3 ++- src/io/userptr/stream.rs | 3 ++- src/lib.rs | 6 ------ src/timestamp.rs | 2 +- src/v4l2/api.rs | 4 ++-- src/v4l2/videodev.rs | 2 +- src/v4l2/vidioc.rs | 2 +- src/video/capture/mod.rs | 6 +++++- src/video/capture/parameters.rs | 3 ++- src/video/output/mod.rs | 6 +++++- src/video/output/parameters.rs | 3 ++- 22 files changed, 60 insertions(+), 39 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3ebcec3..ce9f726 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,8 +11,8 @@ repository= "https://github.com/raymanfx/libv4l-rs" [dependencies] bitflags = "2" libc = "0.2" +v4l2-sys = { path = "v4l2-sys", version = "0.3.0", package="v4l2-sys-mit" } v4l-sys = { path = "v4l-sys", version = "0.3.0", optional = true } -v4l2-sys = { path = "v4l2-sys", version = "0.3.0", package="v4l2-sys-mit", optional = true } [dev-dependencies] glium = "0.34" @@ -20,9 +20,7 @@ jpeg-decoder = "0.3.0" winit = "0.29" [features] -default = ["v4l2"] libv4l = ["v4l-sys"] -v4l2 = ["v4l2-sys"] [workspace] members = [ diff --git a/src/capability.rs b/src/capability.rs index 835e2e6..63223dd 100644 --- a/src/capability.rs +++ b/src/capability.rs @@ -1,6 +1,6 @@ use std::{fmt, str}; -use crate::v4l_sys::*; +use v4l2_sys::v4l2_capability; bitflags::bitflags! { #[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)] diff --git a/src/control.rs b/src/control.rs index db434af..8a3d51c 100644 --- a/src/control.rs +++ b/src/control.rs @@ -1,7 +1,7 @@ use std::convert::{TryFrom, TryInto}; use std::{ffi, fmt, mem, str}; -use crate::v4l_sys::*; +use v4l2_sys::{v4l2_control, v4l2_query_ext_ctrl, v4l2_querymenu}; /// Control data type #[allow(clippy::unreadable_literal)] diff --git a/src/device.rs b/src/device.rs index 4b62721..bc4d397 100644 --- a/src/device.rs +++ b/src/device.rs @@ -5,11 +5,15 @@ use std::{io, mem}; use libc; +use v4l2_sys::{ + v4l2_capability, v4l2_ext_control, v4l2_query_ext_ctrl, v4l2_querymenu, + V4L2_CTRL_FLAG_NEXT_COMPOUND, V4L2_CTRL_FLAG_NEXT_CTRL, +}; + use crate::capability::Capabilities; use crate::control::{self, Control, Description}; use crate::v4l2; use crate::v4l2::videodev::v4l2_ext_controls; -use crate::v4l_sys::*; /// Linux capture device abstraction pub struct Device { diff --git a/src/format/description.rs b/src/format/description.rs index e5f0039..66582fe 100644 --- a/src/format/description.rs +++ b/src/format/description.rs @@ -1,7 +1,8 @@ use std::{fmt, str}; +use v4l2_sys::v4l2_fmtdesc; + use crate::format::FourCC; -use crate::v4l_sys::*; bitflags::bitflags! { #[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)] diff --git a/src/format/mod.rs b/src/format/mod.rs index 27d782d..343eba8 100644 --- a/src/format/mod.rs +++ b/src/format/mod.rs @@ -1,6 +1,6 @@ use std::{convert::TryFrom, fmt, mem}; -use crate::v4l_sys::*; +use v4l2_sys::v4l2_pix_format; pub mod colorspace; pub use colorspace::Colorspace; diff --git a/src/fraction.rs b/src/fraction.rs index 28590fd..ac3be94 100644 --- a/src/fraction.rs +++ b/src/fraction.rs @@ -1,6 +1,7 @@ -use crate::v4l_sys::*; use std::fmt; +use v4l2_sys::v4l2_fract; + #[derive(Debug, Default, Clone, Copy)] /// Fraction used for timing settings pub struct Fraction { diff --git a/src/frameinterval.rs b/src/frameinterval.rs index 2b3b0e0..ae0f87e 100644 --- a/src/frameinterval.rs +++ b/src/frameinterval.rs @@ -1,8 +1,12 @@ use std::convert::TryFrom; use std::fmt; +use v4l2_sys::{ + v4l2_frmivalenum, v4l2_frmivaltypes_V4L2_FRMIVAL_TYPE_CONTINUOUS, + v4l2_frmivaltypes_V4L2_FRMIVAL_TYPE_DISCRETE, v4l2_frmivaltypes_V4L2_FRMIVAL_TYPE_STEPWISE, +}; + use crate::{format::FourCC, fraction::Fraction}; -use crate::{v4l_sys, v4l_sys::*}; #[derive(Debug)] /// Format description as returned by [`crate::v4l2::vidioc::VIDIOC_ENUM_FRAMEINTERVALS`] @@ -44,12 +48,13 @@ impl TryFrom for FrameIntervalEnum { fn try_from(desc: v4l2_frmivalenum) -> Result { unsafe { // Unsafe because of access to union __bindgen_anon_1 + #[allow(non_upper_case_globals)] match desc.type_ { - v4l_sys::v4l2_frmivaltypes_V4L2_FRMIVAL_TYPE_DISCRETE => Ok( - FrameIntervalEnum::Discrete(Fraction::from(desc.__bindgen_anon_1.discrete)), - ), - v4l_sys::v4l2_frmivaltypes_V4L2_FRMIVAL_TYPE_CONTINUOUS - | v4l_sys::v4l2_frmivaltypes_V4L2_FRMIVAL_TYPE_STEPWISE => Ok({ + v4l2_frmivaltypes_V4L2_FRMIVAL_TYPE_DISCRETE => Ok(FrameIntervalEnum::Discrete( + Fraction::from(desc.__bindgen_anon_1.discrete), + )), + v4l2_frmivaltypes_V4L2_FRMIVAL_TYPE_CONTINUOUS + | v4l2_frmivaltypes_V4L2_FRMIVAL_TYPE_STEPWISE => Ok({ FrameIntervalEnum::Stepwise(Stepwise { min: Fraction::from(desc.__bindgen_anon_1.stepwise.min), max: Fraction::from(desc.__bindgen_anon_1.stepwise.max), diff --git a/src/framesize.rs b/src/framesize.rs index 92b9cc4..19c79e3 100644 --- a/src/framesize.rs +++ b/src/framesize.rs @@ -1,9 +1,12 @@ use std::convert::TryFrom; use std::fmt; +use v4l2_sys::{ + v4l2_frmsizeenum, v4l2_frmsizetypes_V4L2_FRMSIZE_TYPE_CONTINUOUS, + v4l2_frmsizetypes_V4L2_FRMSIZE_TYPE_DISCRETE, v4l2_frmsizetypes_V4L2_FRMSIZE_TYPE_STEPWISE, +}; + use crate::format::FourCC; -use crate::v4l_sys; -use crate::v4l_sys::*; #[derive(Debug)] /// Format description as returned by [`crate::v4l2::vidioc::VIDIOC_ENUM_FRAMESIZES`] @@ -66,15 +69,16 @@ impl TryFrom for FrameSizeEnum { fn try_from(desc: v4l2_frmsizeenum) -> Result { unsafe { // Unsafe because of access to union __bindgen_anon_1 + #[allow(non_upper_case_globals)] match desc.type_ { - v4l_sys::v4l2_frmsizetypes_V4L2_FRMSIZE_TYPE_DISCRETE => Ok({ + v4l2_frmsizetypes_V4L2_FRMSIZE_TYPE_DISCRETE => Ok({ FrameSizeEnum::Discrete(Discrete { width: desc.__bindgen_anon_1.discrete.width, height: desc.__bindgen_anon_1.discrete.height, }) }), - v4l_sys::v4l2_frmsizetypes_V4L2_FRMSIZE_TYPE_STEPWISE - | v4l_sys::v4l2_frmsizetypes_V4L2_FRMSIZE_TYPE_CONTINUOUS => Ok({ + v4l2_frmsizetypes_V4L2_FRMSIZE_TYPE_STEPWISE + | v4l2_frmsizetypes_V4L2_FRMSIZE_TYPE_CONTINUOUS => Ok({ FrameSizeEnum::Stepwise(Stepwise { min_width: desc.__bindgen_anon_1.stepwise.min_width, max_width: desc.__bindgen_anon_1.stepwise.max_width, diff --git a/src/io/mmap/arena.rs b/src/io/mmap/arena.rs index 9fae806..75efd43 100644 --- a/src/io/mmap/arena.rs +++ b/src/io/mmap/arena.rs @@ -1,10 +1,11 @@ use std::{io, mem, ptr, slice, sync::Arc}; +use v4l2_sys::{v4l2_buffer, v4l2_requestbuffers}; + use crate::buffer; use crate::device::Handle; use crate::memory::Memory; use crate::v4l2; -use crate::v4l_sys::*; /// Manage mapped buffers /// diff --git a/src/io/mmap/stream.rs b/src/io/mmap/stream.rs index cd666bd..0d1b7e8 100644 --- a/src/io/mmap/stream.rs +++ b/src/io/mmap/stream.rs @@ -2,13 +2,14 @@ use std::convert::TryInto; use std::time::Duration; use std::{io, mem, sync::Arc}; +use v4l2_sys::v4l2_buffer; + use crate::buffer::{Metadata, Type}; use crate::device::{Device, Handle}; use crate::io::mmap::arena::Arena; use crate::io::traits::{CaptureStream, OutputStream, Stream as StreamTrait}; use crate::memory::Memory; use crate::v4l2; -use crate::v4l_sys::*; /// Stream of mapped buffers /// diff --git a/src/io/userptr/arena.rs b/src/io/userptr/arena.rs index 8f9c89c..2cf345a 100644 --- a/src/io/userptr/arena.rs +++ b/src/io/userptr/arena.rs @@ -1,10 +1,11 @@ use std::{io, mem, sync::Arc}; +use v4l2_sys::{v4l2_format, v4l2_requestbuffers}; + use crate::buffer; use crate::device::Handle; use crate::memory::Memory; use crate::v4l2; -use crate::v4l_sys::*; /// Manage user allocated buffers /// diff --git a/src/io/userptr/stream.rs b/src/io/userptr/stream.rs index 5261806..e829053 100644 --- a/src/io/userptr/stream.rs +++ b/src/io/userptr/stream.rs @@ -2,13 +2,14 @@ use std::convert::TryInto; use std::time::Duration; use std::{io, mem, sync::Arc}; +use v4l2_sys::{v4l2_buffer, v4l2_buffer__bindgen_ty_1}; + use crate::buffer::{Metadata, Type}; use crate::device::{Device, Handle}; use crate::io::traits::{CaptureStream, Stream as StreamTrait}; use crate::io::userptr::arena::Arena; use crate::memory::Memory; use crate::v4l2; -use crate::v4l_sys::*; /// Stream of user buffers /// diff --git a/src/lib.rs b/src/lib.rs index fcbe19b..71ddc9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,12 +67,6 @@ //! //! Have a look at the examples to learn more about device and buffer management. -#[cfg(feature = "v4l-sys")] -pub use v4l_sys; - -#[cfg(feature = "v4l2-sys")] -pub use v4l2_sys as v4l_sys; - pub mod v4l2; pub mod buffer; diff --git a/src/timestamp.rs b/src/timestamp.rs index a32b9ff..ed20da1 100644 --- a/src/timestamp.rs +++ b/src/timestamp.rs @@ -1,6 +1,6 @@ use std::{fmt, time}; -use crate::v4l_sys::*; +use v4l2_sys::{time_t, timeval}; #[derive(Debug, Default, Clone, Copy)] /// Timestamp consisting of a seconds and a microseconds component diff --git a/src/v4l2/api.rs b/src/v4l2/api.rs index 0f6fb1d..409d919 100644 --- a/src/v4l2/api.rs +++ b/src/v4l2/api.rs @@ -56,7 +56,7 @@ mod detail { } } -#[cfg(feature = "v4l2-sys")] +#[cfg(not(feature = "v4l-sys"))] mod detail { use crate::v4l2::vidioc; @@ -183,8 +183,8 @@ pub fn close(fd: std::os::raw::c_int) -> io::Result<()> { /// /// use std::mem; /// -/// use v4l::v4l_sys::*; /// use v4l::v4l2; +/// use v4l2_sys::v4l2_capability; /// /// let fd = v4l2::open("/dev/video0", libc::O_RDWR); /// let mut v4l2_caps: v4l2_capability; diff --git a/src/v4l2/videodev.rs b/src/v4l2/videodev.rs index 54d5240..da2ae21 100644 --- a/src/v4l2/videodev.rs +++ b/src/v4l2/videodev.rs @@ -1,4 +1,4 @@ -use crate::v4l_sys::v4l2_ext_control; +use v4l2_sys::v4l2_ext_control; // We need to carry our own copy of this struct, because the `which` field used to be called // `ctrl_class` and Linux now has both fields in a union. While the change is transparent as far as diff --git a/src/v4l2/vidioc.rs b/src/v4l2/vidioc.rs index baab400..31d5de7 100644 --- a/src/v4l2/vidioc.rs +++ b/src/v4l2/vidioc.rs @@ -1,4 +1,4 @@ -use crate::v4l_sys::*; +use v4l2_sys::*; #[cfg(not(target_env = "musl"))] #[allow(non_camel_case_types)] diff --git a/src/video/capture/mod.rs b/src/video/capture/mod.rs index 949502c..df7c0aa 100644 --- a/src/video/capture/mod.rs +++ b/src/video/capture/mod.rs @@ -4,6 +4,11 @@ pub use parameters::Parameters; use std::convert::TryFrom; use std::{io, mem}; +use v4l2_sys::{ + v4l2_fmtdesc, v4l2_format, v4l2_format__bindgen_ty_1, v4l2_frmivalenum, v4l2_frmsizeenum, + v4l2_streamparm, v4l2_streamparm__bindgen_ty_1, +}; + use crate::buffer::Type; use crate::device::Device; use crate::format::FourCC; @@ -11,7 +16,6 @@ use crate::format::{Description as FormatDescription, Format}; use crate::frameinterval::FrameInterval; use crate::framesize::FrameSize; use crate::v4l2; -use crate::v4l_sys::*; use crate::video::traits::Capture; impl Capture for Device { diff --git a/src/video/capture/parameters.rs b/src/video/capture/parameters.rs index 1a3a89f..ac5243a 100644 --- a/src/video/capture/parameters.rs +++ b/src/video/capture/parameters.rs @@ -1,8 +1,9 @@ use std::{fmt, mem}; +use v4l2_sys::v4l2_captureparm; + use crate::fraction::Fraction; use crate::parameters::Capabilities; -use crate::v4l_sys::*; bitflags::bitflags! { #[derive(PartialEq, Eq, Hash, Debug, Clone, Copy)] diff --git a/src/video/output/mod.rs b/src/video/output/mod.rs index f7f82c3..3f90495 100644 --- a/src/video/output/mod.rs +++ b/src/video/output/mod.rs @@ -4,6 +4,11 @@ pub use parameters::Parameters; use std::convert::TryFrom; use std::{io, mem}; +use v4l2_sys::{ + v4l2_fmtdesc, v4l2_format, v4l2_format__bindgen_ty_1, v4l2_frmivalenum, v4l2_frmsizeenum, + v4l2_streamparm, v4l2_streamparm__bindgen_ty_1, +}; + use crate::buffer::Type; use crate::device::Device; use crate::format::FourCC; @@ -11,7 +16,6 @@ use crate::format::{Description as FormatDescription, Format}; use crate::frameinterval::FrameInterval; use crate::framesize::FrameSize; use crate::v4l2; -use crate::v4l_sys::*; use crate::video::traits::Output; impl Output for Device { diff --git a/src/video/output/parameters.rs b/src/video/output/parameters.rs index b0b5aec..ef62d10 100644 --- a/src/video/output/parameters.rs +++ b/src/video/output/parameters.rs @@ -1,8 +1,9 @@ use std::{fmt, mem}; +use v4l2_sys::v4l2_outputparm; + use crate::fraction::Fraction; use crate::parameters::Capabilities; -use crate::v4l_sys::*; #[derive(Debug, Copy, Clone)] /// Output parameters (single-planar)