gstreamer_controller/timed_value_control_source.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::{prelude::*, translate::*};
4
5use crate::{ffi, TimedValueControlSource};
6
7pub trait TimedValueControlSourceExtManual: IsA<TimedValueControlSource> + 'static {
8 #[doc(alias = "gst_timed_value_control_source_list_control_points")]
9 fn list_control_points(&self) -> glib::collections::Slice<gst::TimedValue> {
10 #[cfg(feature = "v1_28")]
11 unsafe {
12 let mut n_control_points = std::mem::MaybeUninit::uninit();
13 let ptr = ffi::gst_timed_value_control_source_list_control_points(
14 self.as_ref().to_glib_none().0,
15 n_control_points.as_mut_ptr(),
16 );
17 let len = n_control_points.assume_init() as usize;
18 FromGlibContainer::from_glib_full_num(ptr, len)
19 }
20 #[cfg(not(feature = "v1_28"))]
21 unsafe {
22 // Get the GList of GstControlPoint pointers
23 use std::mem;
24 use std::ptr;
25
26 let glist_head =
27 ffi::gst_timed_value_control_source_get_all(self.as_ref().to_glib_none().0);
28 let len = glib::ffi::g_list_length(glist_head) as usize;
29 let result = glib::ffi::g_malloc(
30 mem::size_of::<gst::ffi::GstTimedValue>()
31 .checked_mul(len)
32 .unwrap(),
33 ) as *mut gst::ffi::GstTimedValue;
34
35 let mut glist_ptr = glist_head;
36 for i in 0..len {
37 let cp_ptr = (*glist_ptr).data as *const gst::ffi::GstTimedValue;
38 *result.add(i) = ptr::read(cp_ptr);
39 glist_ptr = (*glist_ptr).next;
40 }
41 glib::ffi::g_list_free(glist_head);
42
43 FromGlibContainer::from_glib_full_num(result, len)
44 }
45 }
46}
47
48impl<O: IsA<TimedValueControlSource>> TimedValueControlSourceExtManual for O {}