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    /// Returns an array of `GstTimedValue` representing the control points
9    /// that have been set on this control source. To modify the value of a
10    /// control point, use `gst_timed_value_control_source_set`.
11    ///
12    /// # Returns
13    ///
14    /// an array of
15    /// control points, or [`None`] if no control points are set.
16    #[doc(alias = "gst_timed_value_control_source_list_control_points")]
17    fn list_control_points(&self) -> glib::collections::Slice<gst::TimedValue> {
18        #[cfg(feature = "v1_28")]
19        unsafe {
20            let mut n_control_points = std::mem::MaybeUninit::uninit();
21            let ptr = ffi::gst_timed_value_control_source_list_control_points(
22                self.as_ref().to_glib_none().0,
23                n_control_points.as_mut_ptr(),
24            );
25            let len = n_control_points.assume_init() as usize;
26            FromGlibContainer::from_glib_full_num(ptr, len)
27        }
28        #[cfg(not(feature = "v1_28"))]
29        unsafe {
30            // Get the GList of GstControlPoint pointers
31            use std::mem;
32            use std::ptr;
33
34            let glist_head =
35                ffi::gst_timed_value_control_source_get_all(self.as_ref().to_glib_none().0);
36            let len = glib::ffi::g_list_length(glist_head) as usize;
37            let result = glib::ffi::g_malloc(
38                mem::size_of::<gst::ffi::GstTimedValue>()
39                    .checked_mul(len)
40                    .unwrap(),
41            ) as *mut gst::ffi::GstTimedValue;
42
43            let mut glist_ptr = glist_head;
44            for i in 0..len {
45                let cp_ptr = (*glist_ptr).data as *const gst::ffi::GstTimedValue;
46                *result.add(i) = ptr::read(cp_ptr);
47                glist_ptr = (*glist_ptr).next;
48            }
49            glib::ffi::g_list_free(glist_head);
50
51            FromGlibContainer::from_glib_full_num(result, len)
52        }
53    }
54}
55
56impl<O: IsA<TimedValueControlSource>> TimedValueControlSourceExtManual for O {}