playa_ffmpeg/device/
input.rs

1use std::ptr;
2
3use crate::{Format, ffi::*, format};
4
5pub struct AudioIter(*mut AVInputFormat);
6
7impl Iterator for AudioIter {
8    type Item = Format;
9
10    fn next(&mut self) -> Option<<Self as Iterator>::Item> {
11        unsafe {
12            // We get a clippy warning in 4.4 but not in 5.0 and newer, so we allow that cast to not complicate the code
13            #[allow(clippy::unnecessary_cast)]
14            let ptr = av_input_audio_device_next(self.0) as *mut AVInputFormat;
15
16            if ptr.is_null() && !self.0.is_null() {
17                None
18            } else {
19                self.0 = ptr;
20
21                Some(Format::Input(format::Input::wrap(ptr)))
22            }
23        }
24    }
25}
26
27pub fn audio() -> AudioIter {
28    AudioIter(ptr::null_mut())
29}
30
31pub struct VideoIter(*mut AVInputFormat);
32
33impl Iterator for VideoIter {
34    type Item = Format;
35
36    fn next(&mut self) -> Option<<Self as Iterator>::Item> {
37        unsafe {
38            // We get a clippy warning in 4.4 but not in 5.0 and newer, so we allow that cast to not complicate the code
39            #[allow(clippy::unnecessary_cast)]
40            let ptr = av_input_video_device_next(self.0) as *mut AVInputFormat;
41
42            if ptr.is_null() && !self.0.is_null() {
43                None
44            } else {
45                self.0 = ptr;
46
47                Some(Format::Input(format::Input::wrap(ptr)))
48            }
49        }
50    }
51}
52
53pub fn video() -> VideoIter {
54    VideoIter(ptr::null_mut())
55}