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};
910pub trait BaseSinkExtManual: IsA<BaseSink> + 'static {
11#[doc(alias = "get_segment")]
12fn segment(&self) -> gst::Segment {
13unsafe {
14let sink: &ffi::GstBaseSink = &*(self.as_ptr() as *const _);
15let sinkpad = self.sink_pad();
16let _guard = sinkpad.stream_lock();
17 from_glib_none(&sink.segment as *const gst::ffi::GstSegment)
18 }
19 }
2021/// 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")]
48fn query_latency(
49&self,
50 ) -> Result<(bool, bool, Option<gst::ClockTime>, Option<gst::ClockTime>), glib::BoolError> {
51unsafe {
52let mut live = mem::MaybeUninit::uninit();
53let mut upstream_live = mem::MaybeUninit::uninit();
54let mut min_latency = mem::MaybeUninit::uninit();
55let mut max_latency = mem::MaybeUninit::uninit();
56let ret = from_glib(ffi::gst_base_sink_query_latency(
57self.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 ));
63let live = live.assume_init();
64let upstream_live = upstream_live.assume_init();
65let min_latency = min_latency.assume_init();
66let max_latency = max_latency.assume_init();
67if ret {
68Ok((
69 from_glib(live),
70 from_glib(upstream_live),
71 from_glib(min_latency),
72 from_glib(max_latency),
73 ))
74 } else {
75Err(glib::bool_error!("Failed to query latency"))
76 }
77 }
78 }
7980fn sink_pad(&self) -> &gst::Pad {
81unsafe {
82let elt = &*(self.as_ptr() as *const ffi::GstBaseSink);
83&*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
84 }
85 }
86}
8788impl<O: IsA<BaseSink>> BaseSinkExtManual for O {}