diff --git a/README.md b/README.md index 4bbe6b3..450c2e9 100644 --- a/README.md +++ b/README.md @@ -38,22 +38,22 @@ There are various HAL specific properties. For example, the v4l2 HAL on Linux su Below you can find a quick example usage of this crate. It introduces the basics necessary for image capturing. ```rust -use eye_hal::PlatformContext; use eye_hal::traits::{Context, Device, Stream}; +use eye_hal::PlatformContext; -fn main() -> Result<()> { +fn main() -> Result<(), Box> { // Create a context let ctx = PlatformContext::default(); // Query for available devices. - let devices = ctx.query_devices()?; + let devices = ctx.devices()?; // First, we need a capture device to read images from. For this example, let's just choose // whatever device is first in the list. - let dev = ctx.open_device(&devices[0])?; + let dev = ctx.open_device(&devices[0].uri)?; // Query for available streams and just choose the first one. - let streams = dev.query_streams()?; + let streams = dev.streams()?; let stream_desc = streams[0].clone(); println!("Stream: {:?}", stream_desc); @@ -65,7 +65,7 @@ fn main() -> Result<()> { // Here we create a loop and just capture images as long as the device produces them. Normally, // this loop will run forever unless we unplug the camera or exit the program. loop { - let frame = stream + let _frame = stream .next() .expect("Stream is dead") .expect("Failed to capture frame"); diff --git a/eye-hal/Cargo.toml b/eye-hal/Cargo.toml index 78e3487..37b08c9 100644 --- a/eye-hal/Cargo.toml +++ b/eye-hal/Cargo.toml @@ -9,7 +9,7 @@ readme = "README.md" repository= "https://github.com/raymanfx/eye-rs" [dependencies] -bitflags = "1.3.2" +bitflags = "2.5.0" [target.'cfg(target_os = "linux")'.dependencies] v4l = "0.14.0" diff --git a/eye-hal/examples/list-streams.rs b/eye-hal/examples/list-streams.rs index 22831df..a3bc6af 100644 --- a/eye-hal/examples/list-streams.rs +++ b/eye-hal/examples/list-streams.rs @@ -18,7 +18,7 @@ fn main() -> Result<()> { println!(" Streams:"); for (pixfmt, streams) in &streams.into_iter().group_by(|desc| desc.pixfmt.clone()) { - println!(""); + println!(); println!(" Pixelformat : {}", pixfmt); // sort by resolution, smallest first diff --git a/eye-hal/src/control.rs b/eye-hal/src/control.rs index 4e1ca0c..5ed5460 100644 --- a/eye-hal/src/control.rs +++ b/eye-hal/src/control.rs @@ -58,6 +58,7 @@ pub enum MenuItem { bitflags! { /// Control state flags + #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct Flags: u32 { /// No flags are set const NONE = 0x000; diff --git a/eye-hal/src/error.rs b/eye-hal/src/error.rs index badec7b..a8ee85e 100644 --- a/eye-hal/src/error.rs +++ b/eye-hal/src/error.rs @@ -29,7 +29,7 @@ impl fmt::Debug for Repr { #[derive(Debug)] struct Custom { - kind: ErrorKind, + _kind: ErrorKind, error: Box, } @@ -57,7 +57,7 @@ impl Error { { Error { repr: Repr::Custom(Box::new(Custom { - kind, + _kind: kind, error: error.into(), })), } @@ -76,7 +76,7 @@ impl From for Error { fn from(error: io::Error) -> Self { Error { repr: Repr::Custom(Box::new(Custom { - kind: ErrorKind::Other, + _kind: ErrorKind::Other, error: error.into(), })), } diff --git a/eye-hal/src/platform/mod.rs b/eye-hal/src/platform/mod.rs index fa6abf7..5c69538 100644 --- a/eye-hal/src/platform/mod.rs +++ b/eye-hal/src/platform/mod.rs @@ -2,8 +2,6 @@ //! //! Multiple backends can be implemented for a given platform. -use std::array; - use crate::control; use crate::device; use crate::error::Result; @@ -41,7 +39,7 @@ pub enum Context<'a> { impl<'a> Context<'a> { pub fn all() -> impl Iterator> { - array::IntoIter::new([ + std::iter::IntoIterator::into_iter([ #[cfg(target_os = "linux")] Context::V4l2(v4l2::context::Context {}), #[cfg(any(target_os = "windows", feature = "plat-uvc"))] diff --git a/eye-hal/src/platform/v4l2/mod.rs b/eye-hal/src/platform/v4l2/mod.rs index 07a7d0e..f6c3345 100644 --- a/eye-hal/src/platform/v4l2/mod.rs +++ b/eye-hal/src/platform/v4l2/mod.rs @@ -9,7 +9,6 @@ pub mod context; pub mod device; pub mod stream; -pub use context::Context; use std::{convert::TryInto, str}; diff --git a/eye-hal/src/platform/v4l2/stream.rs b/eye-hal/src/platform/v4l2/stream.rs index 8748e81..5139787 100644 --- a/eye-hal/src/platform/v4l2/stream.rs +++ b/eye-hal/src/platform/v4l2/stream.rs @@ -20,7 +20,7 @@ impl<'a> Handle<'a> { }) } - fn start(&mut self) -> Result<()> { + fn _start(&mut self) -> Result<()> { if self.active { return Ok(()); } diff --git a/eye/src/colorconvert/codec/error.rs b/eye/src/colorconvert/codec/error.rs index 1b61e34..0c576dd 100644 --- a/eye/src/colorconvert/codec/error.rs +++ b/eye/src/colorconvert/codec/error.rs @@ -29,7 +29,7 @@ impl fmt::Debug for Repr { #[derive(Debug)] struct Custom { - kind: ErrorKind, + _kind: ErrorKind, error: Box, } @@ -47,7 +47,12 @@ pub enum ErrorKind { impl fmt::Display for ErrorKind { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self) + match self { + ErrorKind::InvalidBuffer => write!(f, "InvalidBuffer"), + ErrorKind::InvalidParam => write!(f, "InvalidParam"), + ErrorKind::UnsupportedFormat => write!(f, "UnsupportedFormat"), + ErrorKind::Other => write!(f, "Other"), + } } } @@ -58,7 +63,7 @@ impl Error { { Error { repr: Repr::Custom(Box::new(Custom { - kind, + _kind: kind, error: error.into(), })), } @@ -77,7 +82,7 @@ impl From for Error { fn from(error: io::Error) -> Self { Error { repr: Repr::Custom(Box::new(Custom { - kind: ErrorKind::Other, + _kind: ErrorKind::Other, error: error.into(), })), } diff --git a/eye/src/colorconvert/codec/jpeg.rs b/eye/src/colorconvert/codec/jpeg.rs index 3185b26..7398517 100644 --- a/eye/src/colorconvert/codec/jpeg.rs +++ b/eye/src/colorconvert/codec/jpeg.rs @@ -9,13 +9,9 @@ pub fn blueprint() -> impl Blueprint { } #[derive(Debug, Clone)] +#[derive(Default)] pub struct Builder {} -impl Default for Builder { - fn default() -> Self { - Builder {} - } -} impl Blueprint for Builder { fn instantiate( @@ -23,16 +19,12 @@ impl Blueprint for Builder { inparams: Parameters, outparams: Parameters, ) -> Result> { - if self + if !self .src_fmts() - .iter() - .find(|pixfmt| **pixfmt == inparams.pixfmt) - .is_none() - || self + .iter().any(|pixfmt| *pixfmt == inparams.pixfmt) + || !self .dst_fmts() - .iter() - .find(|pixfmt| **pixfmt == outparams.pixfmt) - .is_none() + .iter().any(|pixfmt| *pixfmt == outparams.pixfmt) { return Err(Error::from(ErrorKind::UnsupportedFormat)); } diff --git a/eye/src/colorconvert/codec/rgb.rs b/eye/src/colorconvert/codec/rgb.rs index eaa596c..16d713f 100644 --- a/eye/src/colorconvert/codec/rgb.rs +++ b/eye/src/colorconvert/codec/rgb.rs @@ -12,13 +12,9 @@ pub fn blueprint() -> impl Blueprint { } #[derive(Debug, Clone)] +#[derive(Default)] pub struct Builder {} -impl Default for Builder { - fn default() -> Self { - Builder {} - } -} impl Blueprint for Builder { fn instantiate( @@ -26,16 +22,12 @@ impl Blueprint for Builder { inparams: Parameters, outparams: Parameters, ) -> Result> { - if self + if !self .src_fmts() - .iter() - .find(|pixfmt| **pixfmt == inparams.pixfmt) - .is_none() - || self + .iter().any(|pixfmt| *pixfmt == inparams.pixfmt) + || !self .dst_fmts() - .iter() - .find(|pixfmt| **pixfmt == outparams.pixfmt) - .is_none() + .iter().any(|pixfmt| *pixfmt == outparams.pixfmt) { return Err(Error::from(ErrorKind::UnsupportedFormat)); } diff --git a/eye/src/colorconvert/codec/yuv.rs b/eye/src/colorconvert/codec/yuv.rs index 621971f..13734da 100644 --- a/eye/src/colorconvert/codec/yuv.rs +++ b/eye/src/colorconvert/codec/yuv.rs @@ -12,31 +12,23 @@ pub fn blueprint() -> impl Blueprint { Builder::default() } -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct Builder {} -impl Default for Builder { - fn default() -> Self { - Builder {} - } -} - impl Blueprint for Builder { fn instantiate( &self, inparams: Parameters, outparams: Parameters, ) -> Result> { - if self + if !self .src_fmts() .iter() - .find(|pixfmt| **pixfmt == inparams.pixfmt) - .is_none() - || self + .any(|pixfmt| *pixfmt == inparams.pixfmt) + || !self .dst_fmts() .iter() - .find(|pixfmt| **pixfmt == outparams.pixfmt) - .is_none() + .any(|pixfmt| *pixfmt == outparams.pixfmt) { return Err(Error::from(ErrorKind::UnsupportedFormat)); } @@ -69,7 +61,7 @@ impl Codec for Instance { fn decode(&self, inbuf: &[u8], outbuf: &mut Vec) -> Result<()> { match (&self.inparams.pixfmt, &self.outparams.pixfmt) { (PixelFormat::Custom(ident), PixelFormat::Rgb(24)) => { - if *ident != String::from("YUYV") { + if ident.as_str() != "YUYV" { return Err(Error::from(ErrorKind::UnsupportedFormat)); } @@ -86,7 +78,7 @@ impl Codec for Instance { } } -pub fn yuv444_to_rgb(src: &[u8], src_fmt: &ImageFormat, dst: &mut Vec) -> Result<()> { +pub fn _yuv444_to_rgb(src: &[u8], src_fmt: &ImageFormat, dst: &mut Vec) -> Result<()> { let src_len = (src_fmt.width * src_fmt.height * 3) as usize; let dst_len = (src_fmt.width * src_fmt.height * 3) as usize; if src_len != src.len() { diff --git a/eye/src/colorconvert/device.rs b/eye/src/colorconvert/device.rs index 68af53d..0c58a43 100644 --- a/eye/src/colorconvert/device.rs +++ b/eye/src/colorconvert/device.rs @@ -42,12 +42,9 @@ impl<'a> DeviceTrait<'a> for Device<'a> { for chain in blueprint.src_fmts().iter().zip(blueprint.dst_fmts().iter()) { if streams .iter() - .find(|stream| stream.pixfmt == *chain.0) - .is_some() - && streams - .iter() - .find(|stream| stream.pixfmt == *chain.1) - .is_none() + .any(|stream| stream.pixfmt == *chain.0) + && !streams + .iter().any(|stream| stream.pixfmt == *chain.1) { // collect all streams with this pixfmt let _streams: Vec = streams @@ -78,9 +75,9 @@ impl<'a> DeviceTrait<'a> for Device<'a> { fn start_stream(&self, desc: &stream::Descriptor) -> Result { let native_streams = self.inner.streams()?; - if let Some(_) = native_streams + if native_streams .iter() - .find(|stream| stream.pixfmt == desc.pixfmt) + .any(|stream| stream.pixfmt == desc.pixfmt) { // no emulation required return self.inner.start_stream(desc); @@ -92,8 +89,7 @@ impl<'a> DeviceTrait<'a> for Device<'a> { .filter(|bp| { bp.dst_fmts() .iter() - .find(|pixfmt| **pixfmt == desc.pixfmt) - .is_some() + .any(|pixfmt| *pixfmt == desc.pixfmt) }) .collect(); let src_fmt = if let Some(pixfmt) = blueprints.iter().find_map(|bp| { @@ -118,8 +114,7 @@ impl<'a> DeviceTrait<'a> for Device<'a> { let blueprint = if let Some(bp) = blueprints.into_iter().find(|bp| { bp.src_fmts() .into_iter() - .find(|pixfmt| *pixfmt == src_fmt) - .is_some() + .any(|pixfmt| pixfmt == src_fmt) }) { bp } else { diff --git a/eye/src/colorconvert/stream.rs b/eye/src/colorconvert/stream.rs index ad6a082..412d078 100644 --- a/eye/src/colorconvert/stream.rs +++ b/eye/src/colorconvert/stream.rs @@ -24,7 +24,7 @@ where return Some(item); }; - self.codec.decode(&inbuf, &mut self.buf).unwrap(); + self.codec.decode(inbuf, &mut self.buf).unwrap(); Some(Ok(&self.buf)) } }