Skip to main content

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::{SignalHandlerId, connect_raw},
8    translate::*,
9};
10
11use crate::{Discoverer, DiscovererInfo, ffi};
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    unsafe {
49        let f: &F = &*(f as *const F);
50        f(Discoverer::from_glib_borrow(this).unsafe_cast_ref())
51    }
52}
53
54pub struct DebugInfo<'a>(&'a DiscovererInfo);
55
56impl fmt::Debug for DebugInfo<'_> {
57    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
58        let stream_info = self.0.stream_info();
59        let stream_list = self.0.stream_list();
60        let container_streams = self.0.container_streams();
61        let audio_streams = self.0.audio_streams();
62        let video_streams = self.0.video_streams();
63        let subtitle_streams = self.0.subtitle_streams();
64
65        f.debug_struct("DiscovererInfo")
66            .field("uri", &self.0.uri())
67            .field("result", &self.0.result())
68            .field("duration", &self.0.duration())
69            .field("is-live", &self.0.is_live())
70            .field("is-seekable", &self.0.is_seekable())
71            .field(
72                "stream-info",
73                &stream_info.as_ref().map(|info| info.debug()),
74            )
75            .field(
76                "stream-list",
77                &stream_list
78                    .iter()
79                    .map(|info| info.debug())
80                    .collect::<Vec<_>>(),
81            )
82            .field(
83                "container-streams",
84                &container_streams
85                    .iter()
86                    .map(|info| info.debug())
87                    .collect::<Vec<_>>(),
88            )
89            .field(
90                "audio-streams",
91                &audio_streams
92                    .iter()
93                    .map(|info| info.debug())
94                    .collect::<Vec<_>>(),
95            )
96            .field(
97                "video-streams",
98                &video_streams
99                    .iter()
100                    .map(|info| info.debug())
101                    .collect::<Vec<_>>(),
102            )
103            .field(
104                "subtitle-streams",
105                &subtitle_streams
106                    .iter()
107                    .map(|info| info.debug())
108                    .collect::<Vec<_>>(),
109            )
110            .field("toc", &self.0.toc())
111            .field("misc", &self.0.misc())
112            .field(
113                "missing-elements-installer-details",
114                &self.0.missing_elements_installer_details(),
115            )
116            .finish()
117    }
118}
119
120impl DiscovererInfo {
121    pub fn debug(&self) -> DebugInfo<'_> {
122        DebugInfo(self)
123    }
124}