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

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

Open
isc-IAS opened this issue Dec 14, 2023 · 2 comments
Open

Comments

@isc-IAS
Copy link

isc-IAS commented Dec 14, 2023

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);
}
@apbr
Copy link
Contributor

apbr commented May 6, 2024

Thanks a lot for creating this issue. I also walked into this trap.
Your proposed fix worked for me as well.

To me the main issue seems to be that the public interface of the crate is not well structured/documented.

@SoZ0
Copy link

SoZ0 commented Nov 8, 2024

I second this
Was very confused on the performance difference was halving the expect fps of what my device is capable of.

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

was the exact fix i needed before starting the stream.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants