raymanfx / libv4l-rs

Video4Linux2 bindings for Rust
MIT License
145 stars 62 forks source link

Dequeue does not read buffer index in OutputStream #29

Closed rytec-nl closed 3 years ago

rytec-nl commented 3 years ago

Hi,

I'm using your library to configure a Raspberry Pi as Output device and have run into an issue when trying to stream. It seems that there is a line missing in src/io/mmap/stream.rs:218 that reads the returned index from the DQBUF ioctl.

In the CaptureStream you do this:

fn dequeue(&mut self) -> io::Result<usize> {
        let mut v4l2_buf: v4l2_buffer;
        unsafe {
            v4l2_buf = mem::zeroed();
            v4l2_buf.type_ = self.buf_type as u32;
            v4l2_buf.memory = Memory::Mmap as u32;
            v4l2::ioctl(
                self.handle.fd(),
                v4l2::vidioc::VIDIOC_DQBUF,
                &mut v4l2_buf as *mut _ as *mut std::os::raw::c_void,
            )?;
        }
        self.arena_index = v4l2_buf.index as usize;

        self.buf_meta[self.arena_index] = Metadata {
            bytesused: v4l2_buf.bytesused,
            flags: v4l2_buf.flags.into(),
            field: v4l2_buf.field,
            timestamp: v4l2_buf.timestamp.into(),
            sequence: v4l2_buf.sequence,
        };

        Ok(self.arena_index)
    }

However in the OutputStream implementation the line self.arena_index = v4l2_buf.index as usize; is missing. When I added that line all started working.

Please let me know if you need any more info or if I'm doing something wrong.

Thanks!

raymanfx commented 3 years ago

Makes sense to me. Would you mind sending a PR with your proposed patch so I can give it a proper review and get it in?

rytec-nl commented 3 years ago

Absolutely: https://github.com/raymanfx/libv4l-rs/pull/32

This is my first pull request ever, so please do tell if I should do stuff differently in the future :)

edit: Sorry about the messy commit and revert :( like I said first pull ever.

raymanfx commented 3 years ago

Don't worry, you're doing great! :) Let's discuss this in the PR.