Skip to content

Manually starting a CaptureStream results in a single queued buffer #89

Description

@isc-IAS

I noticed a low FPS on my camera while using the crate, I think this may be the cause:
If .start() has not been called, calling the .next() method on an MMapStream queues all the buffers.
If .start() has been called it attempts to queue a single buffer.
Manually queuing the buffers at start can then cause an InvalidInput on the first call to .next() as it tries to re-queue the buffer.

Queues only a single buffer

let buffer_count = 4;
let v4l2_device = v4l::Device::with_path("/dev/video0").expect("failed to open video");
let mut stream = mmap::Stream::with_buffers(&v4l2_device, Type::VideoCapture, buffer_count)
    .expect("failed to create stream");
stream.start().expect("failed to start stream");

loop {
    let (_, meta) = stream.next().expect("failed to get image");
    println!("seq: {}, timestamp: {}", meta.sequence, meta.timestamp);
}

Fails with InvalidInput

let buffer_count = 4;
let v4l2_device = v4l::Device::with_path("/dev/video0").expect("failed to open video");
let mut stream = mmap::Stream::with_buffers(&v4l2_device, Type::VideoCapture, buffer_count)
    .expect("failed to create stream");

for index in 0..buffer_count as usize {
    stream.queue(index).expect("failed to queue buffer");
}
stream.start().expect("failed to start stream");

loop {
    let (_, meta) = stream.next().expect("failed to get image"); // <-- fails here
    println!("seq: {}, timestamp: {}", meta.sequence, meta.timestamp);
}

I believe creates expected behavior

let buffer_count = 4;
let v4l2_device = v4l::Device::with_path("/dev/video0").expect("failed to open video");
let mut stream = mmap::Stream::with_buffers(&v4l2_device, Type::VideoCapture, buffer_count)
    .expect("failed to create stream");

for index in 1..buffer_count as usize {
    stream.queue(index).expect("failed to queue buffer");
}
stream.start().expect("failed to start stream");

loop {
    let (_, meta) = stream.next().expect("failed to get image");
    println!("seq: {}, timestamp: {}", meta.sequence, meta.timestamp);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions