Skip to content

Commit

Permalink
fix menu iteration when the last item returns EINVAL
Browse files Browse the repository at this point in the history
  • Loading branch information
SludgePhD committed Jul 10, 2024
1 parent b3ed024 commit ff533cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
11 changes: 5 additions & 6 deletions examples/drain-read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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];
Expand Down
10 changes: 5 additions & 5 deletions examples/drain-stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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()?;
Expand Down
8 changes: 4 additions & 4 deletions src/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ impl Iterator for TextMenuIter<'_> {
type Item = io::Result<TextMenuItem>;

fn next(&mut self) -> Option<Self::Item> {
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,
Expand Down

0 comments on commit ff533cc

Please sign in to comment.