Skip to content

Commit

Permalink
Make v4l2_sys a hard dependency
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
raymanfx committed May 5, 2024
1 parent ced9df0 commit 40e3780
Show file tree
Hide file tree
Showing 22 changed files with 60 additions and 39 deletions.
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@ 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"
jpeg-decoder = "0.3.0"
winit = "0.29"

[features]
default = ["v4l2"]
libv4l = ["v4l-sys"]
v4l2 = ["v4l2-sys"]

[workspace]
members = [
Expand Down
2 changes: 1 addition & 1 deletion src/capability.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/control.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
6 changes: 5 additions & 1 deletion src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/format/description.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion src/format/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/fraction.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
17 changes: 11 additions & 6 deletions src/frameinterval.rs
Original file line number Diff line number Diff line change
@@ -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`]
Expand Down Expand Up @@ -44,12 +48,13 @@ impl TryFrom<v4l2_frmivalenum> for FrameIntervalEnum {
fn try_from(desc: v4l2_frmivalenum) -> Result<Self, Self::Error> {
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),
Expand Down
14 changes: 9 additions & 5 deletions src/framesize.rs
Original file line number Diff line number Diff line change
@@ -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`]
Expand Down Expand Up @@ -66,15 +69,16 @@ impl TryFrom<v4l2_frmsizeenum> for FrameSizeEnum {
fn try_from(desc: v4l2_frmsizeenum) -> Result<Self, Self::Error> {
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,
Expand Down
3 changes: 2 additions & 1 deletion src/io/mmap/arena.rs
Original file line number Diff line number Diff line change
@@ -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
///
Expand Down
3 changes: 2 additions & 1 deletion src/io/mmap/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
3 changes: 2 additions & 1 deletion src/io/userptr/arena.rs
Original file line number Diff line number Diff line change
@@ -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
///
Expand Down
3 changes: 2 additions & 1 deletion src/io/userptr/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
///
Expand Down
6 changes: 0 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/timestamp.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/v4l2/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ mod detail {
}
}

#[cfg(feature = "v4l2-sys")]
#[cfg(not(feature = "v4l-sys"))]
mod detail {
use crate::v4l2::vidioc;

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/v4l2/videodev.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/v4l2/vidioc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::v4l_sys::*;
use v4l2_sys::*;

#[cfg(not(target_env = "musl"))]
#[allow(non_camel_case_types)]
Expand Down
6 changes: 5 additions & 1 deletion src/video/capture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ 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;
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 {
Expand Down
3 changes: 2 additions & 1 deletion src/video/capture/parameters.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
6 changes: 5 additions & 1 deletion src/video/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ 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;
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 {
Expand Down
3 changes: 2 additions & 1 deletion src/video/output/parameters.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 40e3780

Please sign in to comment.