1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Take a look at the license at the top of the repository in the LICENSE file.

use std::{boxed::Box as Box_, fmt, mem::transmute};

use glib::{
    prelude::*,
    signal::{connect_raw, SignalHandlerId},
    translate::*,
};

use crate::{auto::Discoverer, DiscovererInfo};

impl Discoverer {
    /// The duration (in nanoseconds) after which the discovery of an individual
    /// URI will timeout.
    ///
    /// If the discovery of a URI times out, the [`DiscovererResult::Timeout`][crate::DiscovererResult::Timeout] will be
    /// set on the result flags.
    pub fn set_timeout(&self, timeout: gst::ClockTime) {
        self.set_property("timeout", timeout);
    }

    /// The duration (in nanoseconds) after which the discovery of an individual
    /// URI will timeout.
    ///
    /// If the discovery of a URI times out, the [`DiscovererResult::Timeout`][crate::DiscovererResult::Timeout] will be
    /// set on the result flags.
    pub fn timeout(&self) -> gst::ClockTime {
        self.property("timeout")
    }

    #[doc(alias = "timeout")]
    pub fn connect_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(
        &self,
        f: F,
    ) -> SignalHandlerId {
        unsafe {
            let f: Box_<F> = Box_::new(f);
            connect_raw(
                self.as_ptr() as *mut _,
                b"notify::timeout\0".as_ptr() as *const _,
                Some(transmute::<_, unsafe extern "C" fn()>(
                    notify_timeout_trampoline::<Self, F> as *const (),
                )),
                Box_::into_raw(f),
            )
        }
    }
}

unsafe extern "C" fn notify_timeout_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
    this: *mut ffi::GstDiscoverer,
    _param_spec: glib::ffi::gpointer,
    f: glib::ffi::gpointer,
) where
    P: IsA<Discoverer>,
{
    let f: &F = &*(f as *const F);
    f(Discoverer::from_glib_borrow(this).unsafe_cast_ref())
}

pub struct DebugInfo<'a>(&'a DiscovererInfo);

impl<'a> fmt::Debug for DebugInfo<'a> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let stream_info = self.0.stream_info();
        let stream_list = self.0.stream_list();
        let container_streams = self.0.container_streams();
        let audio_streams = self.0.audio_streams();
        let video_streams = self.0.video_streams();
        let subtitle_streams = self.0.subtitle_streams();

        f.debug_struct("DiscovererInfo")
            .field("uri", &self.0.uri())
            .field("result", &self.0.result())
            .field("duration", &self.0.duration())
            .field("is-live", &self.0.is_live())
            .field("is-seekable", &self.0.is_seekable())
            .field(
                "stream-info",
                &stream_info.as_ref().map(|info| info.debug()),
            )
            .field(
                "stream-list",
                &stream_list
                    .iter()
                    .map(|info| info.debug())
                    .collect::<Vec<_>>(),
            )
            .field(
                "container-streams",
                &container_streams
                    .iter()
                    .map(|info| info.debug())
                    .collect::<Vec<_>>(),
            )
            .field(
                "audio-streams",
                &audio_streams
                    .iter()
                    .map(|info| info.debug())
                    .collect::<Vec<_>>(),
            )
            .field(
                "video-streams",
                &video_streams
                    .iter()
                    .map(|info| info.debug())
                    .collect::<Vec<_>>(),
            )
            .field(
                "subtitle-streams",
                &subtitle_streams
                    .iter()
                    .map(|info| info.debug())
                    .collect::<Vec<_>>(),
            )
            .field("toc", &self.0.toc())
            .field("misc", &self.0.misc())
            .field(
                "missing-elements-installer-details",
                &self.0.missing_elements_installer_details(),
            )
            .finish()
    }
}

impl DiscovererInfo {
    pub fn debug(&self) -> DebugInfo {
        DebugInfo(self)
    }
}