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
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// 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 glib::StaticType;

glib::wrapper! {
    /// A base class for value mapping objects that attaches control sources to [`glib::Object`][crate::glib::Object]
    /// properties. Such an object is taking one or more [`ControlSource`][crate::ControlSource] instances,
    /// combines them and maps the resulting value to the type and value range of the
    /// bound property.
    ///
    /// This is an Abstract Base Class, you cannot instantiate it.
    ///
    /// # Implements
    ///
    /// [`ControlBindingExt`][trait@crate::prelude::ControlBindingExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`], [`ControlBindingExtManual`][trait@crate::prelude::ControlBindingExtManual]
    #[doc(alias = "GstControlBinding")]
    pub struct ControlBinding(Object<ffi::GstControlBinding, ffi::GstControlBindingClass>) @extends Object;

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

unsafe impl Send for ControlBinding {}
unsafe impl Sync for ControlBinding {}

pub const NONE_CONTROL_BINDING: Option<&ControlBinding> = None;

/// Trait containing all [`struct@ControlBinding`] methods.
///
/// # Implementors
///
/// [`ControlBinding`][struct@crate::ControlBinding]
pub trait ControlBindingExt: 'static {
    /// Gets the value for the given controlled property at the requested time.
    /// ## `timestamp`
    /// the time the control-change should be read from
    ///
    /// # Returns
    ///
    /// the GValue of the property at the given time,
    /// or [`None`] if the property isn't controlled.
    #[doc(alias = "gst_control_binding_get_value")]
    #[doc(alias = "get_value")]
    fn value(&self, timestamp: ClockTime) -> Option<glib::Value>;

    //#[doc(alias = "gst_control_binding_get_value_array")]
    //#[doc(alias = "get_value_array")]
    //fn is_value_array(&self, timestamp: impl Into<Option<ClockTime>>, interval: impl Into<Option<ClockTime>>, values: /*Unimplemented*/&[&Fundamental: Pointer]) -> bool;

    /// Checks if the control binding is disabled.
    ///
    /// # Returns
    ///
    /// [`true`] if the binding is inactive
    #[doc(alias = "gst_control_binding_is_disabled")]
    fn is_disabled(&self) -> bool;

    /// This function is used to disable a control binding for some time, i.e.
    /// [`GstObjectExt::sync_values()`][crate::prelude::GstObjectExt::sync_values()] will do nothing.
    /// ## `disabled`
    /// boolean that specifies whether to disable the controller
    /// or not.
    #[doc(alias = "gst_control_binding_set_disabled")]
    fn set_disabled(&self, disabled: bool);

    /// Sets the property of the `object`, according to the `GstControlSources` that
    /// handles it and for the given timestamp.
    ///
    /// If this function fails, it is most likely the application developers fault.
    /// Most probably the control sources are not setup correctly.
    /// ## `object`
    /// the object that has controlled properties
    /// ## `timestamp`
    /// the time that should be processed
    /// ## `last_sync`
    /// the last time this was called
    ///
    /// # Returns
    ///
    /// [`true`] if the controller value could be applied to the object
    /// property, [`false`] otherwise
    #[doc(alias = "gst_control_binding_sync_values")]
    fn sync_values<P: IsA<Object>>(
        &self,
        object: &P,
        timestamp: ClockTime,
        last_sync: impl Into<Option<ClockTime>>,
    ) -> bool;

    fn object(&self) -> Option<Object>;
}

impl<O: IsA<ControlBinding>> ControlBindingExt for O {
    fn value(&self, timestamp: ClockTime) -> Option<glib::Value> {
        unsafe {
            from_glib_full(ffi::gst_control_binding_get_value(
                self.as_ref().to_glib_none().0,
                timestamp.into_glib(),
            ))
        }
    }

    //fn is_value_array(&self, timestamp: impl Into<Option<ClockTime>>, interval: impl Into<Option<ClockTime>>, values: /*Unimplemented*/&[&Fundamental: Pointer]) -> bool {
    //    unsafe { TODO: call ffi:gst_control_binding_get_value_array() }
    //}

    fn is_disabled(&self) -> bool {
        unsafe {
            from_glib(ffi::gst_control_binding_is_disabled(
                self.as_ref().to_glib_none().0,
            ))
        }
    }

    fn set_disabled(&self, disabled: bool) {
        unsafe {
            ffi::gst_control_binding_set_disabled(
                self.as_ref().to_glib_none().0,
                disabled.into_glib(),
            );
        }
    }

    fn sync_values<P: IsA<Object>>(
        &self,
        object: &P,
        timestamp: ClockTime,
        last_sync: impl Into<Option<ClockTime>>,
    ) -> bool {
        unsafe {
            from_glib(ffi::gst_control_binding_sync_values(
                self.as_ref().to_glib_none().0,
                object.as_ref().to_glib_none().0,
                timestamp.into_glib(),
                last_sync.into().into_glib(),
            ))
        }
    }

    fn object(&self) -> Option<Object> {
        unsafe {
            let mut value = glib::Value::from_type(<Object as StaticType>::static_type());
            glib::gobject_ffi::g_object_get_property(
                self.to_glib_none().0 as *mut glib::gobject_ffi::GObject,
                b"object\0".as_ptr() as *const _,
                value.to_glib_none_mut().0,
            );
            value
                .get()
                .expect("Return Value for property `object` getter")
        }
    }
}