1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::{mem, ptr};
4
5use glib::{prelude::*, translate::*};
6use gst::prelude::*;
7
8use crate::BaseSrc;
9
10mod sealed {
11 pub trait Sealed {}
12 impl<T: super::IsA<super::BaseSrc>> Sealed for T {}
13}
14
15pub trait BaseSrcExtManual: sealed::Sealed + IsA<BaseSrc> + 'static {
16 #[doc(alias = "get_allocator")]
17 #[doc(alias = "gst_base_src_get_allocator")]
18 fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
19 unsafe {
20 let mut allocator = ptr::null_mut();
21 let mut params = mem::MaybeUninit::uninit();
22 ffi::gst_base_src_get_allocator(
23 self.as_ref().to_glib_none().0,
24 &mut allocator,
25 params.as_mut_ptr(),
26 );
27 (from_glib_full(allocator), params.assume_init().into())
28 }
29 }
30
31 #[doc(alias = "get_segment")]
32 fn segment(&self) -> gst::Segment {
33 unsafe {
34 let src: &ffi::GstBaseSrc = &*(self.as_ptr() as *const _);
35 let _guard = self.as_ref().object_lock();
36 from_glib_none(&src.segment as *const _)
37 }
38 }
39
40 #[doc(alias = "gst_base_src_query_latency")]
41 fn query_latency(
42 &self,
43 ) -> Result<(bool, Option<gst::ClockTime>, Option<gst::ClockTime>), glib::BoolError> {
44 unsafe {
45 let mut live = mem::MaybeUninit::uninit();
46 let mut min_latency = mem::MaybeUninit::uninit();
47 let mut max_latency = mem::MaybeUninit::uninit();
48 let ret = from_glib(ffi::gst_base_src_query_latency(
49 self.as_ref().to_glib_none().0,
50 live.as_mut_ptr(),
51 min_latency.as_mut_ptr(),
52 max_latency.as_mut_ptr(),
53 ));
54 let live = live.assume_init();
55 let min_latency = min_latency.assume_init();
56 let max_latency = max_latency.assume_init();
57 if ret {
58 Ok((
59 from_glib(live),
60 from_glib(min_latency),
61 from_glib(max_latency),
62 ))
63 } else {
64 Err(glib::bool_error!("Failed to query latency"))
65 }
66 }
67 }
68
69 fn src_pad(&self) -> &gst::Pad {
70 unsafe {
71 let elt = &*(self.as_ptr() as *const ffi::GstBaseSrc);
72 &*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
73 }
74 }
75}
76
77impl<O: IsA<BaseSrc>> BaseSrcExtManual for O {}
78