From ff533cc8c64b7cbbeb855e91272eeae3e994f0a1 Mon Sep 17 00:00:00 2001 From: Sludge <96552222+SludgePhD@users.noreply.github.com> Date: Wed, 10 Jul 2024 20:57:26 +0200 Subject: [PATCH] fix menu iteration when the last item returns EINVAL --- examples/drain-read.rs | 11 +++++------ examples/drain-stream.rs | 10 +++++----- src/controls.rs | 8 ++++---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/examples/drain-read.rs b/examples/drain-read.rs index 14cec5b..79622da 100644 --- a/examples/drain-read.rs +++ b/examples/drain-read.rs @@ -12,10 +12,7 @@ use std::{ }; use anyhow::anyhow; -use linuxvideo::{ - format::{PixFormat, PixelFormat}, - Device, -}; +use linuxvideo::{format::Format, BufType, Device}; fn main() -> anyhow::Result<()> { env_logger::init(); @@ -33,8 +30,10 @@ fn main() -> anyhow::Result<()> { device.capabilities()?.device_capabilities() ); - let mut capture = - device.video_capture(PixFormat::new(u32::MAX, u32::MAX, PixelFormat::YUYV))?; + let Format::VideoCapture(fmt) = device.format(BufType::VIDEO_CAPTURE)? else { + unreachable!() + }; + let mut capture = device.video_capture(fmt)?; println!("negotiated format: {:?}", capture.format()); let size = capture.format().size_image() as usize; let mut buf = vec![0; size]; diff --git a/examples/drain-stream.rs b/examples/drain-stream.rs index 0b8bf79..88d0961 100644 --- a/examples/drain-stream.rs +++ b/examples/drain-stream.rs @@ -12,10 +12,7 @@ use std::{ }; use anyhow::anyhow; -use linuxvideo::{ - format::{PixFormat, PixelFormat}, - Device, -}; +use linuxvideo::{format::Format, BufType, Device}; fn main() -> anyhow::Result<()> { env_logger::init(); @@ -33,7 +30,10 @@ fn main() -> anyhow::Result<()> { device.capabilities()?.device_capabilities() ); - let capture = device.video_capture(PixFormat::new(u32::MAX, u32::MAX, PixelFormat::YUYV))?; + let Format::VideoCapture(fmt) = device.format(BufType::VIDEO_CAPTURE)? else { + unreachable!() + }; + let capture = device.video_capture(fmt)?; println!("negotiated format: {:?}", capture.format()); let mut stream = capture.into_stream()?; diff --git a/src/controls.rs b/src/controls.rs index 190a6cb..379bb75 100644 --- a/src/controls.rs +++ b/src/controls.rs @@ -175,10 +175,10 @@ impl Iterator for TextMenuIter<'_> { type Item = io::Result; fn next(&mut self) -> Option { - if self.next_index > self.max_index { - None - } else { - loop { + loop { + if self.next_index > self.max_index { + return None; + } else { unsafe { let mut raw = raw::QueryMenu { id: self.cid.0,