1 | // Take a look at the license at the top of the repository in the LICENSE file. |
2 | |
3 | use std::mem; |
4 | |
5 | use glib::{prelude::*, translate::*}; |
6 | use gst::prelude::*; |
7 | |
8 | use crate::BaseSink; |
9 | |
10 | mod sealed { |
11 | pub trait Sealed {} |
12 | impl<T: super::IsA<super::BaseSink>> Sealed for T {} |
13 | } |
14 | |
15 | pub 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 _guard = self.as_ref().object_lock(); |
21 | from_glib_none(&sink.segment as *const _) |
22 | } |
23 | } |
24 | |
25 | #[doc (alias = "gst_base_sink_query_latency" )] |
26 | fn query_latency( |
27 | &self, |
28 | ) -> Result<(bool, bool, Option<gst::ClockTime>, Option<gst::ClockTime>), glib::BoolError> { |
29 | unsafe { |
30 | let mut live = mem::MaybeUninit::uninit(); |
31 | let mut upstream_live = mem::MaybeUninit::uninit(); |
32 | let mut min_latency = mem::MaybeUninit::uninit(); |
33 | let mut max_latency = mem::MaybeUninit::uninit(); |
34 | let ret = from_glib(ffi::gst_base_sink_query_latency( |
35 | self.as_ref().to_glib_none().0, |
36 | live.as_mut_ptr(), |
37 | upstream_live.as_mut_ptr(), |
38 | min_latency.as_mut_ptr(), |
39 | max_latency.as_mut_ptr(), |
40 | )); |
41 | let live = live.assume_init(); |
42 | let upstream_live = upstream_live.assume_init(); |
43 | let min_latency = min_latency.assume_init(); |
44 | let max_latency = max_latency.assume_init(); |
45 | if ret { |
46 | Ok(( |
47 | from_glib(live), |
48 | from_glib(upstream_live), |
49 | from_glib(min_latency), |
50 | from_glib(max_latency), |
51 | )) |
52 | } else { |
53 | Err(glib::bool_error!("Failed to query latency" )) |
54 | } |
55 | } |
56 | } |
57 | |
58 | fn sink_pad(&self) -> &gst::Pad { |
59 | unsafe { |
60 | let elt = &*(self.as_ptr() as *const ffi::GstBaseSink); |
61 | &*(&elt.sinkpad as *const *mut gst::ffi::GstPad as *const gst::Pad) |
62 | } |
63 | } |
64 | } |
65 | |
66 | impl<O: IsA<BaseSink>> BaseSinkExtManual for O {} |
67 | |