Skip to content
Open
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 src/io/mmap/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use crate::v4l_sys::*;
///
/// All buffers are unmapped in the Drop impl.
/// In case of errors during unmapping, we panic because there is memory corruption going on.
pub struct Arena<'a> {
pub struct Arena {
handle: Arc<Handle>,
pub bufs: Vec<&'a mut [u8]>,
pub bufs: Vec<*mut [u8]>,
pub buf_type: buffer::Type,
}

impl<'a> Arena<'a> {
impl Arena {
/// Returns a new buffer manager instance
///
/// You usually do not need to use this directly.
Expand Down Expand Up @@ -94,9 +94,9 @@ impl<'a> Arena<'a> {
}

pub fn release(&mut self) -> io::Result<()> {
for buf in &self.bufs {
for &buf in &self.bufs {
unsafe {
v4l2::munmap(buf.as_ptr() as *mut core::ffi::c_void, buf.len())?;
v4l2::munmap(buf as *mut core::ffi::c_void, buf.len())?;
}
}

Expand All @@ -118,7 +118,7 @@ impl<'a> Arena<'a> {
}
}

impl<'a> Drop for Arena<'a> {
impl Drop for Arena {
fn drop(&mut self) {
if self.bufs.is_empty() {
// nothing to do
Expand Down
24 changes: 13 additions & 11 deletions src/io/mmap/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use crate::v4l_sys::*;
/// Stream of mapped buffers
///
/// An arena instance is used internally for buffer handling.
pub struct Stream<'a> {
pub struct Stream {
handle: Arc<Handle>,
arena: Arena<'a>,
arena: Arena,
arena_index: usize,
buf_type: Type,
buf_meta: Vec<Metadata>,
Expand All @@ -24,7 +24,7 @@ pub struct Stream<'a> {
active: bool,
}

impl<'a> Stream<'a> {
impl Stream {
/// Returns a stream for frame capturing
///
/// # Arguments
Expand Down Expand Up @@ -89,7 +89,7 @@ impl<'a> Stream<'a> {
}
}

impl<'a> Drop for Stream<'a> {
impl Drop for Stream {
fn drop(&mut self) {
if let Err(e) = self.stop() {
if let Some(code) = e.raw_os_error() {
Expand All @@ -107,7 +107,7 @@ impl<'a> Drop for Stream<'a> {
}
}

impl<'a> StreamTrait for Stream<'a> {
impl StreamTrait for Stream {
type Item = [u8];

fn start(&mut self) -> io::Result<()> {
Expand Down Expand Up @@ -139,7 +139,7 @@ impl<'a> StreamTrait for Stream<'a> {
}
}

impl<'a, 'b> CaptureStream<'b> for Stream<'a> {
impl CaptureStream for Stream {
fn queue(&mut self, index: usize) -> io::Result<()> {
let mut v4l2_buf = v4l2_buffer {
index: index as u32,
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<'a, 'b> CaptureStream<'b> for Stream<'a> {
Ok(self.arena_index)
}

fn next(&'b mut self) -> io::Result<(&Self::Item, &Metadata)> {
fn next(&mut self) -> io::Result<(&Self::Item, &Metadata)> {
if !self.active {
// Enqueue all buffers once on stream start
for index in 0..self.arena.bufs.len() {
Expand All @@ -203,13 +203,14 @@ impl<'a, 'b> CaptureStream<'b> for Stream<'a> {

// The index used to access the buffer elements is given to us by v4l2, so we assume it
// will always be valid.
let bytes = &self.arena.bufs[self.arena_index];
let bytes = self.arena.bufs[self.arena_index];
let bytes = unsafe { &*bytes };
let meta = &self.buf_meta[self.arena_index];
Ok((bytes, meta))
}
}

impl<'a, 'b> OutputStream<'b> for Stream<'a> {
impl OutputStream for Stream {
fn queue(&mut self, index: usize) -> io::Result<()> {
let mut v4l2_buf = v4l2_buffer {
index: index as u32,
Expand Down Expand Up @@ -266,7 +267,7 @@ impl<'a, 'b> OutputStream<'b> for Stream<'a> {
Ok(self.arena_index)
}

fn next(&'b mut self) -> io::Result<(&mut Self::Item, &mut Metadata)> {
fn next(&mut self) -> io::Result<(&mut Self::Item, &mut Metadata)> {
let init = !self.active;
if !self.active {
self.start()?;
Expand All @@ -282,7 +283,8 @@ impl<'a, 'b> OutputStream<'b> for Stream<'a> {

// The index used to access the buffer elements is given to us by v4l2, so we assume it
// will always be valid.
let bytes = &mut self.arena.bufs[self.arena_index];
let bytes = self.arena.bufs[self.arena_index];
let bytes = unsafe { &mut *bytes };
let meta = &mut self.buf_meta[self.arena_index];
Ok((bytes, meta))
}
Expand Down
8 changes: 4 additions & 4 deletions src/io/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait Stream {
fn stop(&mut self) -> io::Result<()>;
}

pub trait CaptureStream<'a>: Stream {
pub trait CaptureStream: Stream {
/// Insert a buffer into the drivers' incoming queue
fn queue(&mut self, index: usize) -> io::Result<()>;

Expand All @@ -22,10 +22,10 @@ pub trait CaptureStream<'a>: Stream {

/// Fetch a new frame by first queueing and then dequeueing.
/// First time initialization is performed if necessary.
fn next(&'a mut self) -> io::Result<(&Self::Item, &Metadata)>;
fn next(&mut self) -> io::Result<(&Self::Item, &Metadata)>;
}

pub trait OutputStream<'a>: Stream {
pub trait OutputStream: Stream {
/// Insert a buffer into the drivers' incoming queue
fn queue(&mut self, index: usize) -> io::Result<()>;

Expand All @@ -34,5 +34,5 @@ pub trait OutputStream<'a>: Stream {

/// Dump a new frame by first queueing and then dequeueing.
/// First time initialization is performed if necessary.
fn next(&'a mut self) -> io::Result<(&mut Self::Item, &mut Metadata)>;
fn next(&mut self) -> io::Result<(&mut Self::Item, &mut Metadata)>;
}
4 changes: 2 additions & 2 deletions src/io/userptr/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ impl StreamTrait for Stream {
}
}

impl<'a> CaptureStream<'a> for Stream {
impl CaptureStream for Stream {
fn queue(&mut self, index: usize) -> io::Result<()> {
let buf = &mut self.arena.bufs[index];
let mut v4l2_buf = v4l2_buffer {
Expand Down Expand Up @@ -191,7 +191,7 @@ impl<'a> CaptureStream<'a> for Stream {
Ok(self.arena_index)
}

fn next(&'a mut self) -> io::Result<(&Self::Item, &Metadata)> {
fn next(&mut self) -> io::Result<(&Self::Item, &Metadata)> {
if !self.active {
// Enqueue all buffers once on stream start
for index in 0..self.arena.bufs.len() {
Expand Down