1// Take a look at the license at the top of the repository in the LICENSE file.
23use std::mem;
45use glib::{prelude::*, translate::*};
6use gst::prelude::*;
78use crate::{ffi, BaseSink};
910mod sealed {
11pub trait Sealed {}
12impl<T: super::IsA<super::BaseSink>> Sealed for T {}
13}
1415pub trait BaseSinkExtManual: sealed::Sealed + IsA<BaseSink> + 'static {
16#[doc(alias = "get_segment")]
17fn segment(&self) -> gst::Segment {
18unsafe {
19let sink: &ffi::GstBaseSink = &*(self.as_ptr() as *const _);
20let sinkpad = self.sink_pad();
21let _guard = sinkpad.stream_lock();
22 from_glib_none(&sink.segment as *const gst::ffi::GstSegment)
23 }
24 }
2526/// 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")]
53fn query_latency(
54&self,
55 ) -> Result<(bool, bool, Option<gst::ClockTime>, Option<gst::ClockTime>), glib::BoolError> {
56unsafe {
57let mut live = mem::MaybeUninit::uninit();
58let mut upstream_live = mem::MaybeUninit::uninit();
59let mut min_latency = mem::MaybeUninit::uninit();
60let mut max_latency = mem::MaybeUninit::uninit();
61let ret = from_glib(ffi::gst_base_sink_query_latency(
62self.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 ));
68let live = live.assume_init();
69let upstream_live = upstream_live.assume_init();
70let min_latency = min_latency.assume_init();
71let max_latency = max_latency.assume_init();
72if ret {
73Ok((
74 from_glib(live),
75 from_glib(upstream_live),
76 from_glib(min_latency),
77 from_glib(max_latency),
78 ))
79 } else {
80Err(glib::bool_error!("Failed to query latency"))
81 }
82 }
83 }
8485fn sink_pad(&self) -> &gst::Pad {
86unsafe {
87let elt = &*(self.as_ptr() as *const ffi::GstBaseSink);
88&*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
89 }
90 }
91}
9293impl<O: IsA<BaseSink>> BaseSinkExtManual for O {}