gstreamer_pbutils/
discoverer.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{boxed::Box as Box_, fmt, mem::transmute};
4
5use glib::{
6    prelude::*,
7    signal::{connect_raw, SignalHandlerId},
8    translate::*,
9};
10
11use crate::{ffi, Discoverer, DiscovererInfo};
12
13impl Discoverer {
14    pub fn set_timeout(&self, timeout: gst::ClockTime) {
15        self.set_property("timeout", timeout);
16    }
17
18    pub fn timeout(&self) -> gst::ClockTime {
19        self.property("timeout")
20    }
21
22    #[doc(alias = "timeout")]
23    pub fn connect_timeout_notify<F: Fn(&Self) + Send + Sync + 'static>(
24        &self,
25        f: F,
26    ) -> SignalHandlerId {
27        unsafe {
28            let f: Box_<F> = Box_::new(f);
29            connect_raw(
30                self.as_ptr() as *mut _,
31                b"notify::timeout\0".as_ptr() as *const _,
32                Some(transmute::<*const (), unsafe extern "C" fn()>(
33                    notify_timeout_trampoline::<Self, F> as *const (),
34                )),
35                Box_::into_raw(f),
36            )
37        }
38    }
39}
40
41unsafe extern "C" fn notify_timeout_trampoline<P, F: Fn(&P) + Send + Sync + 'static>(
42    this: *mut ffi::GstDiscoverer,
43    _param_spec: glib::ffi::gpointer,
44    f: glib::ffi::gpointer,
45) where
46    P: IsA<Discoverer>,
47{
48    let f: &F = &*(f as *const F);
49    f(Discoverer::from_glib_borrow(this).unsafe_cast_ref())
50}
51
52pub struct DebugInfo<'a>(&'a DiscovererInfo);
53
54impl fmt::Debug for DebugInfo<'_> {
55    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
56        let stream_info = self.0.stream_info();
57        let stream_list = self.0.stream_list();
58        let container_streams = self.0.container_streams();
59        let audio_streams = self.0.audio_streams();
60        let video_streams = self.0.video_streams();
61        let subtitle_streams = self.0.subtitle_streams();
62
63        f.debug_struct("DiscovererInfo")
64            .field("uri", &self.0.uri())
65            .field("result", &self.0.result())
66            .field("duration", &self.0.duration())
67            .field("is-live", &self.0.is_live())
68            .field("is-seekable", &self.0.is_seekable())
69            .field(
70                "stream-info",
71                &stream_info.as_ref().map(|info| info.debug()),
72            )
73            .field(
74                "stream-list",
75                &stream_list
76                    .iter()
77                    .map(|info| info.debug())
78                    .collect::<Vec<_>>(),
79            )
80            .field(
81                "container-streams",
82                &container_streams
83                    .iter()
84                    .map(|info| info.debug())
85                    .collect::<Vec<_>>(),
86            )
87            .field(
88                "audio-streams",
89                &audio_streams
90                    .iter()
91                    .map(|info| info.debug())
92                    .collect::<Vec<_>>(),
93            )
94            .field(
95                "video-streams",
96                &video_streams
97                    .iter()
98                    .map(|info| info.debug())
99                    .collect::<Vec<_>>(),
100            )
101            .field(
102                "subtitle-streams",
103                &subtitle_streams
104                    .iter()
105                    .map(|info| info.debug())
106                    .collect::<Vec<_>>(),
107            )
108            .field("toc", &self.0.toc())
109            .field("misc", &self.0.misc())
110            .field(
111                "missing-elements-installer-details",
112                &self.0.missing_elements_installer_details(),
113            )
114            .finish()
115    }
116}
117
118impl DiscovererInfo {
119    pub fn debug(&self) -> DebugInfo {
120        DebugInfo(self)
121    }
122}