1 | use std::ptr; |
2 | |
3 | use ffi::*; |
4 | use format; |
5 | use Format; |
6 | |
7 | pub struct AudioIter(*mut AVInputFormat); |
8 | |
9 | impl Iterator for AudioIter { |
10 | type Item = Format; |
11 | |
12 | fn next(&mut self) -> Option<<Self as Iterator>::Item> { |
13 | unsafe { |
14 | // 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 |
15 | #[allow (clippy::unnecessary_cast)] |
16 | let ptr: *mut {unknown} = av_input_audio_device_next(self.0) as *mut AVInputFormat; |
17 | |
18 | if ptr.is_null() && !self.0.is_null() { |
19 | None |
20 | } else { |
21 | self.0 = ptr; |
22 | |
23 | Some(Format::Input(format::Input::wrap(ptr))) |
24 | } |
25 | } |
26 | } |
27 | } |
28 | |
29 | pub fn audio() -> AudioIter { |
30 | AudioIter(ptr::null_mut()) |
31 | } |
32 | |
33 | pub struct VideoIter(*mut AVInputFormat); |
34 | |
35 | impl Iterator for VideoIter { |
36 | type Item = Format; |
37 | |
38 | fn next(&mut self) -> Option<<Self as Iterator>::Item> { |
39 | unsafe { |
40 | // 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 |
41 | #[allow (clippy::unnecessary_cast)] |
42 | let ptr: *mut {unknown} = av_input_video_device_next(self.0) as *mut AVInputFormat; |
43 | |
44 | if ptr.is_null() && !self.0.is_null() { |
45 | None |
46 | } else { |
47 | self.0 = ptr; |
48 | |
49 | Some(Format::Input(format::Input::wrap(ptr))) |
50 | } |
51 | } |
52 | } |
53 | } |
54 | |
55 | pub fn video() -> VideoIter { |
56 | VideoIter(ptr::null_mut()) |
57 | } |
58 | |