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#[must_use = "iterators are lazy and do nothing unless consumed"]
7#[derive(Debug)]
8pub struct Iter {
9    stream_info: Option<DiscovererStreamInfo>,
10    direction_forward: bool,
11}
12
13impl Iterator for Iter {
14    type Item = DiscovererStreamInfo;
15
16    fn next(&mut self) -> Option<DiscovererStreamInfo> {
17        let current = self.stream_info.take();
18        self.stream_info = match current {
19            Some(ref c) => {
20                // Decide on the direction
21                if self.direction_forward {
22                    c.next()
23                } else {
24                    c.previous()
25                }
26            }
27            None => None,
28        };
29        current
30    }
31}
32
33impl std::iter::FusedIterator for Iter {}
34
35pub trait DiscovererStreamInfoExtManual: IsA<DiscovererStreamInfo> + 'static {
36    fn next_iter(&self) -> Iter {
37        Iter {
38            stream_info: self.next(),
39            direction_forward: true,
40        }
41    }
42
43    fn previous_iter(&self) -> Iter {
44        Iter {
45            stream_info: self.previous(),
46            direction_forward: false,
47        }
48    }
49}
50
51impl<O: IsA<DiscovererStreamInfo>> DiscovererStreamInfoExtManual for O {}
52
53pub struct Debug<'a>(&'a DiscovererStreamInfo);
54
55impl fmt::Debug for Debug<'_> {
56    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
57        let mut d = f.debug_struct("DiscovererStreamInfo");
58        d.field("caps", &self.0.caps())
59            .field("stream-id", &self.0.stream_id())
60            .field("misc", &self.0.misc())
61            .field("stream-type-nick", &self.0.stream_type_nick())
62            .field("tags", &self.0.tags())
63            .field("toc", &self.0.toc());
64
65        #[cfg(feature = "v1_20")]
66        d.field("stream-number", &self.0.stream_number());
67
68        d.finish()
69    }
70}
71
72impl DiscovererStreamInfo {
73    pub fn debug(&self) -> Debug {
74        Debug(self)
75    }
76}