Skip to content

Commit

Permalink
hal: Update v4l to 0.14.0
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher N. Hesse <raymanfx@gmail.com>
  • Loading branch information
raymanfx committed Oct 28, 2023
1 parent 52959d6 commit 6d39ed9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
2 changes: 1 addition & 1 deletion eye-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository= "https://github.com/raymanfx/eye-rs"
bitflags = "1.2.1"

[target.'cfg(target_os = "linux")'.dependencies]
v4l = { git = "https://github.com/raymanfx/libv4l-rs", rev = "d7ac71" }
v4l = "0.14.0"

[target.'cfg(target_os="windows")'.dependencies]
uvc = { version = "0.2.0", features = ["vendor"] }
Expand Down
35 changes: 8 additions & 27 deletions eye-hal/src/platform/v4l2/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::traits::Stream;

pub struct Handle<'a> {
stream: MmapStream<'a>,
stream_buf_index: usize,
active: bool,
}

Expand All @@ -17,7 +16,6 @@ impl<'a> Handle<'a> {
let stream = MmapStream::new(dev.inner(), BufType::VideoCapture)?;
Ok(Handle {
stream,
stream_buf_index: 0,
active: false,
})
}
Expand All @@ -41,27 +39,6 @@ impl<'a> Handle<'a> {
self.active = false;
Ok(())
}

fn queue(&mut self) -> Result<()> {
if !self.active {
self.start()?;
}

self.stream.queue(self.stream_buf_index)?;
Ok(())
}

fn dequeue(&mut self) -> Result<&[u8]> {
self.stream_buf_index = self.stream.dequeue()?;

let buffer = self.stream.get(self.stream_buf_index).unwrap();
let meta = self.stream.get_meta(self.stream_buf_index).unwrap();

// For compressed formats, the buffer length will not actually describe the number of bytes
// in a frame. Instead, we have to explicitly query about the amount of used bytes.
let view = &buffer[0..meta.bytesused as usize];
Ok(view)
}
}

impl<'a> Drop for Handle<'a> {
Expand All @@ -77,10 +54,14 @@ impl<'a, 'b> Stream<'b> for Handle<'a> {
type Item = Result<&'b [u8]>;

fn next(&'b mut self) -> Option<Self::Item> {
if let Err(e) = self.queue() {
return Some(Err(e));
match self.stream.next() {
Ok((buf, meta)) => {
// For compressed formats, the buffer length will not actually describe the number
// of bytes in a frame. Instead, we have to explicitly query about the amount of
// used bytes.
Some(Ok(&buf[0..meta.bytesused as usize]))
}
Err(e) => Some(Err(e.into())),
}

Some(self.dequeue())
}
}

0 comments on commit 6d39ed9

Please sign in to comment.