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 warnings + clippy #10

Merged
merged 2 commits into from
Apr 14, 2024
Merged
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
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::error::Error>> {
// 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);

Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion eye-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion eye-hal/examples/list-streams.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions eye-hal/src/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions eye-hal/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl fmt::Debug for Repr {

#[derive(Debug)]
struct Custom {
kind: ErrorKind,
_kind: ErrorKind,
error: Box<dyn error::Error + Send + Sync>,
}

Expand Down Expand Up @@ -57,7 +57,7 @@ impl Error {
{
Error {
repr: Repr::Custom(Box::new(Custom {
kind,
_kind: kind,
error: error.into(),
})),
}
Expand All @@ -76,7 +76,7 @@ impl From<io::Error> for Error {
fn from(error: io::Error) -> Self {
Error {
repr: Repr::Custom(Box::new(Custom {
kind: ErrorKind::Other,
_kind: ErrorKind::Other,
error: error.into(),
})),
}
Expand Down
4 changes: 1 addition & 3 deletions eye-hal/src/platform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,7 +39,7 @@ pub enum Context<'a> {

impl<'a> Context<'a> {
pub fn all() -> impl Iterator<Item = Context<'a>> {
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"))]
Expand Down
1 change: 0 additions & 1 deletion eye-hal/src/platform/v4l2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ pub mod context;
pub mod device;
pub mod stream;

pub use context::Context;

use std::{convert::TryInto, str};

Expand Down
2 changes: 1 addition & 1 deletion eye-hal/src/platform/v4l2/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl<'a> Handle<'a> {
})
}

fn start(&mut self) -> Result<()> {
fn _start(&mut self) -> Result<()> {
if self.active {
return Ok(());
}
Expand Down
13 changes: 9 additions & 4 deletions eye/src/colorconvert/codec/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl fmt::Debug for Repr {

#[derive(Debug)]
struct Custom {
kind: ErrorKind,
_kind: ErrorKind,
error: Box<dyn error::Error + Send + Sync>,
}

Expand All @@ -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"),
}
}
}

Expand All @@ -58,7 +63,7 @@ impl Error {
{
Error {
repr: Repr::Custom(Box::new(Custom {
kind,
_kind: kind,
error: error.into(),
})),
}
Expand All @@ -77,7 +82,7 @@ impl From<io::Error> for Error {
fn from(error: io::Error) -> Self {
Error {
repr: Repr::Custom(Box::new(Custom {
kind: ErrorKind::Other,
_kind: ErrorKind::Other,
error: error.into(),
})),
}
Expand Down
18 changes: 5 additions & 13 deletions eye/src/colorconvert/codec/jpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,22 @@ 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(
&self,
inparams: Parameters,
outparams: Parameters,
) -> Result<Box<dyn Codec + Send>> {
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));
}
Expand Down
18 changes: 5 additions & 13 deletions eye/src/colorconvert/codec/rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,22 @@ 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(
&self,
inparams: Parameters,
outparams: Parameters,
) -> Result<Box<dyn Codec + Send>> {
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));
}
Expand Down
22 changes: 7 additions & 15 deletions eye/src/colorconvert/codec/yuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Box<dyn Codec + Send>> {
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));
}
Expand Down Expand Up @@ -69,7 +61,7 @@ impl Codec for Instance {
fn decode(&self, inbuf: &[u8], outbuf: &mut Vec<u8>) -> 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));
}

Expand All @@ -86,7 +78,7 @@ impl Codec for Instance {
}
}

pub fn yuv444_to_rgb(src: &[u8], src_fmt: &ImageFormat, dst: &mut Vec<u8>) -> Result<()> {
pub fn _yuv444_to_rgb(src: &[u8], src_fmt: &ImageFormat, dst: &mut Vec<u8>) -> 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() {
Expand Down
19 changes: 7 additions & 12 deletions eye/src/colorconvert/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<stream::Descriptor> = streams
Expand Down Expand Up @@ -78,9 +75,9 @@ impl<'a> DeviceTrait<'a> for Device<'a> {

fn start_stream(&self, desc: &stream::Descriptor) -> Result<Self::Stream> {
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);
Expand All @@ -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| {
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion eye/src/colorconvert/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Loading