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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
// This file was generated by gir (https://github.com/gtk-rs/gir)
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

use Caps;
use Element;
use Object;
use Structure;
use ffi;
use glib;
use glib::object::Downcast;
use glib::object::IsA;
use glib::signal::SignalHandlerId;
use glib::signal::connect;
use glib::translate::*;
use glib_ffi;
use gobject_ffi;
use std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute;
use std::ptr;

glib_wrapper! {
    /// `Device` are objects representing a device, they contain
    /// relevant metadata about the device, such as its class and the `Caps`
    /// representing the media types it can produce or handle.
    ///
    /// `Device` are created by `DeviceProvider` objects which can be
    /// aggregated by `DeviceMonitor` objects.
    ///
    /// # Implements
    ///
    /// [`DeviceExt`](trait.DeviceExt.html), [`GstObjectExt`](trait.GstObjectExt.html), [`glib::object::ObjectExt`](../glib/object/trait.ObjectExt.html)
    pub struct Device(Object<ffi::GstDevice, ffi::GstDeviceClass>): Object;

    match fn {
        get_type => || ffi::gst_device_get_type(),
    }
}

unsafe impl Send for Device {}
unsafe impl Sync for Device {}

/// Trait containing all `Device` methods.
///
/// # Implementors
///
/// [`Device`](struct.Device.html)
pub trait DeviceExt {
    /// Creates the element with all of the required parameters set to use
    /// this device.
    /// ## `name`
    /// name of new element, or `None` to automatically
    /// create a unique name.
    ///
    /// # Returns
    ///
    /// a new `Element` configured to use
    /// this device
    fn create_element<'a, P: Into<Option<&'a str>>>(&self, name: P) -> Option<Element>;

    /// Getter for the `Caps` that this device supports.
    ///
    /// # Returns
    ///
    /// The `Caps` supported by this device. Unref with
    /// `gst_caps_unref` when done.
    fn get_caps(&self) -> Option<Caps>;

    /// Gets the "class" of a device. This is a "/" separated list of
    /// classes that represent this device. They are a subset of the
    /// classes of the `DeviceProvider` that produced this device.
    ///
    /// # Returns
    ///
    /// The device class. Free with `g_free` after use.
    fn get_device_class(&self) -> String;

    /// Gets the user-friendly name of the device.
    ///
    /// # Returns
    ///
    /// The device name. Free with `g_free` after use.
    fn get_display_name(&self) -> String;

    /// Gets the extra properties of a device.
    ///
    /// # Returns
    ///
    /// The extra properties or `None` when there are none.
    ///  Free with `Structure::free` after use.
    fn get_properties(&self) -> Option<Structure>;

    /// Check if `self` matches all of the given classes
    /// ## `classes`
    /// a "/"-separated list of device classes to match, only match if
    ///  all classes are matched
    ///
    /// # Returns
    ///
    /// `true` if `self` matches.
    fn has_classes(&self, classes: &str) -> bool;

    /// Check if `factory` matches all of the given classes
    /// ## `classes`
    /// a `None` terminated array of classes
    ///  to match, only match if all classes are matched
    ///
    /// # Returns
    ///
    /// `true` if `self` matches.
    fn has_classesv(&self, classes: &[&str]) -> bool;

    /// Tries to reconfigure an existing element to use the device. If this
    /// function fails, then one must destroy the element and create a new one
    /// using `DeviceExt::create_element`.
    ///
    /// Note: This should only be implemented for elements can change their
    /// device in the PLAYING state.
    /// ## `element`
    /// a `Element`
    ///
    /// # Returns
    ///
    /// `true` if the element could be reconfigured to use this device,
    /// `false` otherwise.
    fn reconfigure_element<P: IsA<Element>>(&self, element: &P) -> bool;

    fn connect_removed<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_caps_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_device_class_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_display_name_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;

    fn connect_property_properties_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId;
}

impl<O: IsA<Device> + IsA<glib::object::Object>> DeviceExt for O {
    fn create_element<'a, P: Into<Option<&'a str>>>(&self, name: P) -> Option<Element> {
        let name = name.into();
        let name = name.to_glib_none();
        unsafe {
            from_glib_full(ffi::gst_device_create_element(self.to_glib_none().0, name.0))
        }
    }

    fn get_caps(&self) -> Option<Caps> {
        unsafe {
            from_glib_full(ffi::gst_device_get_caps(self.to_glib_none().0))
        }
    }

    fn get_device_class(&self) -> String {
        unsafe {
            from_glib_full(ffi::gst_device_get_device_class(self.to_glib_none().0))
        }
    }

    fn get_display_name(&self) -> String {
        unsafe {
            from_glib_full(ffi::gst_device_get_display_name(self.to_glib_none().0))
        }
    }

    fn get_properties(&self) -> Option<Structure> {
        unsafe {
            from_glib_full(ffi::gst_device_get_properties(self.to_glib_none().0))
        }
    }

    fn has_classes(&self, classes: &str) -> bool {
        unsafe {
            from_glib(ffi::gst_device_has_classes(self.to_glib_none().0, classes.to_glib_none().0))
        }
    }

    fn has_classesv(&self, classes: &[&str]) -> bool {
        unsafe {
            from_glib(ffi::gst_device_has_classesv(self.to_glib_none().0, classes.to_glib_none().0))
        }
    }

    fn reconfigure_element<P: IsA<Element>>(&self, element: &P) -> bool {
        unsafe {
            from_glib(ffi::gst_device_reconfigure_element(self.to_glib_none().0, element.to_glib_none().0))
        }
    }

    fn connect_removed<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "removed",
                transmute(removed_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_caps_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "notify::caps",
                transmute(notify_caps_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_device_class_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "notify::device-class",
                transmute(notify_device_class_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_display_name_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "notify::display-name",
                transmute(notify_display_name_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }

    fn connect_property_properties_notify<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
        unsafe {
            let f: Box_<Box_<Fn(&Self) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
            connect(self.to_glib_none().0, "notify::properties",
                transmute(notify_properties_trampoline::<Self> as usize), Box_::into_raw(f) as *mut _)
        }
    }
}

unsafe extern "C" fn removed_trampoline<P>(this: *mut ffi::GstDevice, f: glib_ffi::gpointer)
where P: IsA<Device> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&Device::from_glib_borrow(this).downcast_unchecked())
}

unsafe extern "C" fn notify_caps_trampoline<P>(this: *mut ffi::GstDevice, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Device> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&Device::from_glib_borrow(this).downcast_unchecked())
}

unsafe extern "C" fn notify_device_class_trampoline<P>(this: *mut ffi::GstDevice, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Device> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&Device::from_glib_borrow(this).downcast_unchecked())
}

unsafe extern "C" fn notify_display_name_trampoline<P>(this: *mut ffi::GstDevice, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Device> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&Device::from_glib_borrow(this).downcast_unchecked())
}

unsafe extern "C" fn notify_properties_trampoline<P>(this: *mut ffi::GstDevice, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer)
where P: IsA<Device> {
    let f: &&(Fn(&P) + Send + Sync + 'static) = transmute(f);
    f(&Device::from_glib_borrow(this).downcast_unchecked())
}