gstreamer_pbutils/
discoverer_stream_info.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2use std::fmt;
3
4use crate::{prelude::*, DiscovererStreamInfo};
5
6#[derive(Debug)]
7pub struct Iter {
8    stream_info: Option<DiscovererStreamInfo>,
9    direction_forward: bool,
10}
11
12impl Iterator for Iter {
13    type Item = DiscovererStreamInfo;
14
15    fn next(&mut self) -> Option<DiscovererStreamInfo> {
16        let current = self.stream_info.take();
17        self.stream_info = match current {
18            Some(ref c) => {
19                // Decide on the direction
20                if self.direction_forward {
21                    c.next()
22                } else {
23                    c.previous()
24                }
25            }
26            None => None,
27        };
28        current
29    }
30}
31
32impl std::iter::FusedIterator for Iter {}
33
34mod sealed {
35    pub trait Sealed {}
36    impl<T: super::IsA<super::DiscovererStreamInfo>> Sealed for T {}
37}
38
39pub trait DiscovererStreamInfoExtManual:
40    sealed::Sealed + IsA<DiscovererStreamInfo> + 'static
41{
42    fn next_iter(&self) -> Iter {
43        Iter {
44            stream_info: self.next(),
45            direction_forward: true,
46        }
47    }
48
49    fn previous_iter(&self) -> Iter {
50        Iter {
51            stream_info: self.previous(),
52            direction_forward: false,
53        }
54    }
55}
56
57impl<O: IsA<DiscovererStreamInfo>> DiscovererStreamInfoExtManual for O {}
58
59pub struct Debug<'a>(&'a DiscovererStreamInfo);
60
61impl fmt::Debug for Debug<'_> {
62    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63        let mut d = f.debug_struct("DiscovererStreamInfo");
64        d.field("caps", &self.0.caps())
65            .field("stream-id", &self.0.stream_id())
66            .field("misc", &self.0.misc())
67            .field("stream-type-nick", &self.0.stream_type_nick())
68            .field("tags", &self.0.tags())
69            .field("toc", &self.0.toc());
70
71        #[cfg(feature = "v1_20")]
72        d.field("stream-number", &self.0.stream_number());
73
74        d.finish()
75    }
76}
77
78impl DiscovererStreamInfo {
79    pub fn debug(&self) -> Debug {
80        Debug(self)
81    }
82}