1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
// DO NOT EDIT

use crate::ClockTime;
use crate::Object;
use glib::object::IsA;
use glib::translate::*;
use std::mem;

glib::wrapper! {
    /// The [`ControlSource`][crate::ControlSource] is a base class for control value sources that could
    /// be used to get timestamp-value pairs. A control source essentially is a
    /// function over time.
    ///
    /// A [`ControlSource`][crate::ControlSource] is used by first getting an instance of a specific
    /// control-source, creating a binding for the control-source to the target property
    /// of the element and then adding the binding to the element. The binding will
    /// convert the data types and value range to fit to the bound property.
    ///
    /// For implementing a new [`ControlSource`][crate::ControlSource] one has to implement
    /// `GstControlSourceGetValue` and `GstControlSourceGetValueArray` functions.
    /// These are then used by [`ControlSourceExt::value()`][crate::prelude::ControlSourceExt::value()] and
    /// [`ControlSourceExtManual::control_source_get_value_array()`][crate::prelude::ControlSourceExtManual::control_source_get_value_array()] to get values for specific timestamps.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// # Implements
    ///
    /// [`ControlSourceExt`][trait@crate::prelude::ControlSourceExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`ControlSourceExtManual`][trait@crate::prelude::ControlSourceExtManual]
    #[doc(alias = "GstControlSource")]
    pub struct ControlSource(Object<ffi::GstControlSource, ffi::GstControlSourceClass>) @extends Object;

    match fn {
        type_ => || ffi::gst_control_source_get_type(),
    }
}

impl ControlSource {
    pub const NONE: Option<&'static ControlSource> = None;
}

unsafe impl Send for ControlSource {}
unsafe impl Sync for ControlSource {}

/// Trait containing all [`struct@ControlSource`] methods.
///
/// # Implementors
///
/// [`ControlSource`][struct@crate::ControlSource]
pub trait ControlSourceExt: 'static {
    /// Gets the value for this [`ControlSource`][crate::ControlSource] at a given timestamp.
    /// ## `timestamp`
    /// the time for which the value should be returned
    ///
    /// # Returns
    ///
    /// [`false`] if the value couldn't be returned, [`true`] otherwise.
    ///
    /// ## `value`
    /// the value
    #[doc(alias = "gst_control_source_get_value")]
    #[doc(alias = "control_source_get_value")]
    fn value(&self, timestamp: ClockTime) -> Option<f64>;
}

impl<O: IsA<ControlSource>> ControlSourceExt for O {
    fn value(&self, timestamp: ClockTime) -> Option<f64> {
        unsafe {
            let mut value = mem::MaybeUninit::uninit();
            let ret = from_glib(ffi::gst_control_source_get_value(
                self.as_ref().to_glib_none().0,
                timestamp.into_glib(),
                value.as_mut_ptr(),
            ));
            let value = value.assume_init();
            if ret {
                Some(value)
            } else {
                None
            }
        }
    }
}