1// Take a look at the license at the top of the repository in the LICENSE file.
23use std::{mem, ptr};
45use glib::{prelude::*, translate::*};
6use gst::prelude::*;
78use crate::{ffi, BaseSrc};
910pub trait BaseSrcExtManual: IsA<BaseSrc> + 'static {
11/// Lets [`BaseSrc`][crate::BaseSrc] sub-classes to know the memory `allocator`
12 /// used by the base class and its `params`.
13 ///
14 /// Unref the `allocator` after usage.
15 ///
16 /// # Returns
17 ///
18 ///
19 /// ## `allocator`
20 /// the [`gst::Allocator`][crate::gst::Allocator]
21 /// used
22 ///
23 /// ## `params`
24 /// the [`gst::AllocationParams`][crate::gst::AllocationParams] of `allocator`
25#[doc(alias = "get_allocator")]
26 #[doc(alias = "gst_base_src_get_allocator")]
27fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
28unsafe {
29let mut allocator = ptr::null_mut();
30let mut params = mem::MaybeUninit::uninit();
31 ffi::gst_base_src_get_allocator(
32self.as_ref().to_glib_none().0,
33&mut allocator,
34 params.as_mut_ptr(),
35 );
36 (from_glib_full(allocator), params.assume_init().into())
37 }
38 }
3940#[doc(alias = "get_segment")]
41fn segment(&self) -> gst::Segment {
42unsafe {
43let src: &ffi::GstBaseSrc = &*(self.as_ptr() as *const _);
44let srcpad = self.src_pad();
45let _guard = srcpad.stream_lock();
46let _guard = self.as_ref().object_lock();
47 from_glib_none(&src.segment as *const _)
48 }
49 }
5051/// Query the source for the latency parameters. `live` will be [`true`] when `self` is
52 /// configured as a live source. `min_latency` and `max_latency` will be set
53 /// to the difference between the running time and the timestamp of the first
54 /// buffer.
55 ///
56 /// This function is mostly used by subclasses.
57 ///
58 /// # Returns
59 ///
60 /// [`true`] if the query succeeded.
61 ///
62 /// ## `live`
63 /// if the source is live
64 ///
65 /// ## `min_latency`
66 /// the min latency of the source
67 ///
68 /// ## `max_latency`
69 /// the max latency of the source
70#[doc(alias = "gst_base_src_query_latency")]
71fn query_latency(
72&self,
73 ) -> Result<(bool, Option<gst::ClockTime>, Option<gst::ClockTime>), glib::BoolError> {
74unsafe {
75let mut live = mem::MaybeUninit::uninit();
76let mut min_latency = mem::MaybeUninit::uninit();
77let mut max_latency = mem::MaybeUninit::uninit();
78let ret = from_glib(ffi::gst_base_src_query_latency(
79self.as_ref().to_glib_none().0,
80 live.as_mut_ptr(),
81 min_latency.as_mut_ptr(),
82 max_latency.as_mut_ptr(),
83 ));
84let live = live.assume_init();
85let min_latency = min_latency.assume_init();
86let max_latency = max_latency.assume_init();
87if ret {
88Ok((
89 from_glib(live),
90 from_glib(min_latency),
91 from_glib(max_latency),
92 ))
93 } else {
94Err(glib::bool_error!("Failed to query latency"))
95 }
96 }
97 }
9899fn src_pad(&self) -> &gst::Pad {
100unsafe {
101let elt = &*(self.as_ptr() as *const ffi::GstBaseSrc);
102&*(&elt.srcpad as *const *mut gst::ffi::GstPad as *const gst::Pad)
103 }
104 }
105}
106107impl<O: IsA<BaseSrc>> BaseSrcExtManual for O {}