ffmpeg_the_third/util/channel_layout/
iter.rs

1use ffmpeg_sys_the_third::av_channel_layout_standard;
2use libc::c_void;
3
4use super::ChannelLayout;
5
6pub struct ChannelLayoutIter {
7    opaque: *mut c_void,
8}
9
10impl ChannelLayoutIter {
11    pub const fn new() -> Self {
12        Self {
13            opaque: std::ptr::null_mut(),
14        }
15    }
16}
17
18impl Default for ChannelLayoutIter {
19    fn default() -> Self {
20        Self::new()
21    }
22}
23
24impl Iterator for ChannelLayoutIter {
25    type Item = ChannelLayout<'static>;
26
27    fn next(&mut self) -> Option<Self::Item> {
28        unsafe {
29            av_channel_layout_standard(&mut self.opaque as _)
30                .as_ref()
31                .map(ChannelLayout::from)
32        }
33    }
34}
35
36#[cfg(test)]
37mod test {
38    use super::*;
39
40    #[test]
41    fn iter() {
42        let iter = ChannelLayoutIter::new();
43        let count = iter.count();
44        println!("{count}");
45        assert!(count > 0);
46
47        let mut iter = ChannelLayoutIter::new();
48        assert!(iter.all(|ch| ch.is_valid()));
49    }
50}