gstreamer_base/
base_sink.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::mem;
4
5use glib::{prelude::*, translate::*};
6use gst::prelude::*;
7
8use crate::{ffi, BaseSink};
9
10mod sealed {
11    pub trait Sealed {}
12    impl<T: super::IsA<super::BaseSink>> Sealed for T {}
13}
14
15pub trait BaseSinkExtManual: sealed::Sealed + IsA<BaseSink> + 'static {
16    #[doc(alias = "get_segment")]
17    fn segment(&self) -> gst::Segment {
18        unsafe {
19            let sink: &ffi::GstBaseSink = &*(self.as_ptr() as *const _);
20            let sinkpad = self.sink_pad();
21            let _guard = sinkpad.stream_lock();
22            from_glib_none(&sink.segment as *const gst::ffi::GstSegment)
23        }
24    }
25
26    /// Query the sink for the latency parameters. The latency will be queried from
27    /// the upstream elements. `live` will be [`true`] if `self` is configured to
28    /// synchronize against the clock. `upstream_live` will be [`true`] if an upstream
29    /// element is live.
30    ///
31    /// If both `live` and `upstream_live` are [`true`], the sink will want to compensate
32    /// for the latency introduced by the upstream elements by setting the
33    /// `min_latency` to a strictly positive value.
34    ///
35    /// This function is mostly used by subclasses.
36    ///
37    /// # Returns
38    ///
39    /// [`true`] if the query succeeded.
40    ///
41    /// ## `live`
42    /// if the sink is live
43    ///
44    /// ## `upstream_live`
45    /// if an upstream element is live
46    ///
47    /// ## `min_latency`
48    /// the min latency of the upstream elements
49    ///
50    /// ## `max_latency`
51    /// the max latency of the upstream elements
52    #[doc(alias = "gst_base_sink_query_latency")]
53    fn query_latency(
54        &self,
55    ) -> Result<(bool, bool, Option<gst::ClockTime>, Option<gst::ClockTime>), glib::BoolError> {
56        unsafe {
57            let mut live = mem::MaybeUninit::uninit();
58            let mut upstream_live = mem::MaybeUninit::uninit();
59            let mut min_latency = mem::MaybeUninit::uninit();
60            let mut max_latency = mem::MaybeUninit::uninit();
61            let ret = from_glib(ffi::gst_base_sink_query_latency(
62                self.as_ref().to_glib_none().0,
63                live.as_mut_ptr(),
64                upstream_live.as_mut_ptr(),
65                min_latency.as_mut_ptr(),
66                max_latency.as_mut_ptr(),
67            ));
68            let live = live.assume_init();
69            let upstream_live = upstream_live.assume_init();
70            let min_latency = min_latency.assume_init();
71            let max_latency = max_latency.assume_init();
72            if ret {
73                Ok((
74                    from_glib(live),
75                    from_glib(upstream_live),
76                    from_glib(min_latency),
77                    from_glib(max_latency),
78                ))
79            } else {
80                Err(glib::bool_error!("Failed to query latency"))
81            }
82        }
83    }
84
85    fn sink_pad(&self) -> &gst::Pad {
86        unsafe {
87            let elt = &*(self.as_ptr() as *const ffi::GstBaseSink);
88            &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
89        }
90    }
91}
92
93impl<O: IsA<BaseSink>> BaseSinkExtManual for O {}