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