Skip to content

Commit ff533cc

Browse files
committed
fix menu iteration when the last item returns EINVAL
1 parent b3ed024 commit ff533cc

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

examples/drain-read.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ use std::{
1212
};
1313

1414
use anyhow::anyhow;
15-
use linuxvideo::{
16-
format::{PixFormat, PixelFormat},
17-
Device,
18-
};
15+
use linuxvideo::{format::Format, BufType, Device};
1916

2017
fn main() -> anyhow::Result<()> {
2118
env_logger::init();
@@ -33,8 +30,10 @@ fn main() -> anyhow::Result<()> {
3330
device.capabilities()?.device_capabilities()
3431
);
3532

36-
let mut capture =
37-
device.video_capture(PixFormat::new(u32::MAX, u32::MAX, PixelFormat::YUYV))?;
33+
let Format::VideoCapture(fmt) = device.format(BufType::VIDEO_CAPTURE)? else {
34+
unreachable!()
35+
};
36+
let mut capture = device.video_capture(fmt)?;
3837
println!("negotiated format: {:?}", capture.format());
3938
let size = capture.format().size_image() as usize;
4039
let mut buf = vec![0; size];

examples/drain-stream.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ use std::{
1212
};
1313

1414
use anyhow::anyhow;
15-
use linuxvideo::{
16-
format::{PixFormat, PixelFormat},
17-
Device,
18-
};
15+
use linuxvideo::{format::Format, BufType, Device};
1916

2017
fn main() -> anyhow::Result<()> {
2118
env_logger::init();
@@ -33,7 +30,10 @@ fn main() -> anyhow::Result<()> {
3330
device.capabilities()?.device_capabilities()
3431
);
3532

36-
let capture = device.video_capture(PixFormat::new(u32::MAX, u32::MAX, PixelFormat::YUYV))?;
33+
let Format::VideoCapture(fmt) = device.format(BufType::VIDEO_CAPTURE)? else {
34+
unreachable!()
35+
};
36+
let capture = device.video_capture(fmt)?;
3737
println!("negotiated format: {:?}", capture.format());
3838

3939
let mut stream = capture.into_stream()?;

src/controls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ impl Iterator for TextMenuIter<'_> {
175175
type Item = io::Result<TextMenuItem>;
176176

177177
fn next(&mut self) -> Option<Self::Item> {
178-
if self.next_index > self.max_index {
179-
None
180-
} else {
181-
loop {
178+
loop {
179+
if self.next_index > self.max_index {
180+
return None;
181+
} else {
182182
unsafe {
183183
let mut raw = raw::QueryMenu {
184184
id: self.cid.0,

0 commit comments

Comments
 (0)