gstreamer/auto/device.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// from gst-gir-files (https://gitlab.freedesktop.org/gstreamer/gir-files-rs.git)
4// DO NOT EDIT
5
6use crate::{ffi, Caps, Element, Object, Structure};
7use glib::{
8 object::ObjectType as _,
9 prelude::*,
10 signal::{connect_raw, SignalHandlerId},
11 translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16 /// [`Device`][crate::Device] are objects representing a device, they contain
17 /// relevant metadata about the device, such as its class and the [`Caps`][crate::Caps]
18 /// representing the media types it can produce or handle.
19 ///
20 /// [`Device`][crate::Device] are created by [`DeviceProvider`][crate::DeviceProvider] objects which can be
21 /// aggregated by [`DeviceMonitor`][crate::DeviceMonitor] objects.
22 ///
23 /// This is an Abstract Base Class, you cannot instantiate it.
24 ///
25 /// ## Properties
26 ///
27 ///
28 /// #### `caps`
29 /// Readable | Writeable | Construct Only
30 ///
31 ///
32 /// #### `device-class`
33 /// Readable | Writeable | Construct Only
34 ///
35 ///
36 /// #### `display-name`
37 /// Readable | Writeable | Construct Only
38 ///
39 ///
40 /// #### `properties`
41 /// Readable | Writeable | Construct Only
42 /// <details><summary><h4>Object</h4></summary>
43 ///
44 ///
45 /// #### `name`
46 /// Readable | Writeable | Construct
47 ///
48 ///
49 /// #### `parent`
50 /// The parent of the object. Please note, that when changing the 'parent'
51 /// property, we don't emit [`notify`][struct@crate::glib::Object#notify] and [`deep-notify`][struct@crate::Object#deep-notify]
52 /// signals due to locking issues. In some cases one can use
53 /// [`element-added`][struct@crate::Bin#element-added] or [`element-removed`][struct@crate::Bin#element-removed] signals on the parent to
54 /// achieve a similar effect.
55 ///
56 /// Readable | Writeable
57 /// </details>
58 ///
59 /// ## Signals
60 ///
61 ///
62 /// #### `removed`
63 ///
64 /// <details><summary><h4>Object</h4></summary>
65 ///
66 ///
67 /// #### `deep-notify`
68 /// The deep notify signal is used to be notified of property changes. It is
69 /// typically attached to the toplevel bin to receive notifications from all
70 /// the elements contained in that bin.
71 ///
72 /// Detailed
73 /// </details>
74 ///
75 /// # Implements
76 ///
77 /// [`DeviceExt`][trait@crate::prelude::DeviceExt], [`GstObjectExt`][trait@crate::prelude::GstObjectExt], [`trait@glib::ObjectExt`]
78 #[doc(alias = "GstDevice")]
79 pub struct Device(Object<ffi::GstDevice, ffi::GstDeviceClass>) @extends Object;
80
81 match fn {
82 type_ => || ffi::gst_device_get_type(),
83 }
84}
85
86impl Device {
87 pub const NONE: Option<&'static Device> = None;
88}
89
90unsafe impl Send for Device {}
91unsafe impl Sync for Device {}
92
93/// Trait containing all [`struct@Device`] methods.
94///
95/// # Implementors
96///
97/// [`Device`][struct@crate::Device]
98pub trait DeviceExt: IsA<Device> + 'static {
99 /// Creates the element with all of the required parameters set to use
100 /// this device.
101 /// ## `name`
102 /// name of new element, or [`None`] to automatically
103 /// create a unique name.
104 ///
105 /// # Returns
106 ///
107 /// a new [`Element`][crate::Element] configured to use
108 /// this device
109 #[doc(alias = "gst_device_create_element")]
110 fn create_element(&self, name: Option<&str>) -> Result<Element, glib::BoolError> {
111 unsafe {
112 Option::<_>::from_glib_none(ffi::gst_device_create_element(
113 self.as_ref().to_glib_none().0,
114 name.to_glib_none().0,
115 ))
116 .ok_or_else(|| glib::bool_error!("Failed to create element for device"))
117 }
118 }
119
120 /// Getter for the [`Caps`][crate::Caps] that this device supports.
121 ///
122 /// # Returns
123 ///
124 /// The [`Caps`][crate::Caps] supported by this device. Unref with
125 /// `gst_caps_unref()` when done.
126 #[doc(alias = "gst_device_get_caps")]
127 #[doc(alias = "get_caps")]
128 fn caps(&self) -> Option<Caps> {
129 unsafe { from_glib_full(ffi::gst_device_get_caps(self.as_ref().to_glib_none().0)) }
130 }
131
132 /// Gets the "class" of a device. This is a "/" separated list of
133 /// classes that represent this device. They are a subset of the
134 /// classes of the [`DeviceProvider`][crate::DeviceProvider] that produced this device.
135 ///
136 /// # Returns
137 ///
138 /// The device class. Free with `g_free()` after use.
139 #[doc(alias = "gst_device_get_device_class")]
140 #[doc(alias = "get_device_class")]
141 #[doc(alias = "device-class")]
142 fn device_class(&self) -> glib::GString {
143 unsafe {
144 from_glib_full(ffi::gst_device_get_device_class(
145 self.as_ref().to_glib_none().0,
146 ))
147 }
148 }
149
150 /// Gets the user-friendly name of the device.
151 ///
152 /// # Returns
153 ///
154 /// The device name. Free with `g_free()` after use.
155 #[doc(alias = "gst_device_get_display_name")]
156 #[doc(alias = "get_display_name")]
157 #[doc(alias = "display-name")]
158 fn display_name(&self) -> glib::GString {
159 unsafe {
160 from_glib_full(ffi::gst_device_get_display_name(
161 self.as_ref().to_glib_none().0,
162 ))
163 }
164 }
165
166 /// Gets the extra properties of a device.
167 ///
168 /// # Returns
169 ///
170 /// The extra properties or [`None`] when there are none.
171 /// Free with `gst_structure_free()` after use.
172 #[doc(alias = "gst_device_get_properties")]
173 #[doc(alias = "get_properties")]
174 fn properties(&self) -> Option<Structure> {
175 unsafe {
176 from_glib_full(ffi::gst_device_get_properties(
177 self.as_ref().to_glib_none().0,
178 ))
179 }
180 }
181
182 /// Check if `self` matches all of the given classes
183 /// ## `classes`
184 /// a "/"-separated list of device classes to match, only match if
185 /// all classes are matched
186 ///
187 /// # Returns
188 ///
189 /// [`true`] if `self` matches.
190 #[doc(alias = "gst_device_has_classes")]
191 fn has_classes(&self, classes: &str) -> bool {
192 unsafe {
193 from_glib(ffi::gst_device_has_classes(
194 self.as_ref().to_glib_none().0,
195 classes.to_glib_none().0,
196 ))
197 }
198 }
199
200 /// Check if `factory` matches all of the given classes
201 /// ## `classes`
202 /// a [`None`] terminated array of classes
203 /// to match, only match if all classes are matched
204 ///
205 /// # Returns
206 ///
207 /// [`true`] if `self` matches.
208 #[doc(alias = "gst_device_has_classesv")]
209 fn has_classesv(&self, classes: &[&str]) -> bool {
210 unsafe {
211 from_glib(ffi::gst_device_has_classesv(
212 self.as_ref().to_glib_none().0,
213 classes.to_glib_none().0,
214 ))
215 }
216 }
217
218 /// Tries to reconfigure an existing element to use the device. If this
219 /// function fails, then one must destroy the element and create a new one
220 /// using [`create_element()`][Self::create_element()].
221 ///
222 /// Note: This should only be implemented for elements can change their
223 /// device in the PLAYING state.
224 /// ## `element`
225 /// a [`Element`][crate::Element]
226 ///
227 /// # Returns
228 ///
229 /// [`true`] if the element could be reconfigured to use this device,
230 /// [`false`] otherwise.
231 #[doc(alias = "gst_device_reconfigure_element")]
232 fn reconfigure_element(
233 &self,
234 element: &impl IsA<Element>,
235 ) -> Result<(), glib::error::BoolError> {
236 unsafe {
237 glib::result_from_gboolean!(
238 ffi::gst_device_reconfigure_element(
239 self.as_ref().to_glib_none().0,
240 element.as_ref().to_glib_none().0
241 ),
242 "Failed to reconfigure the element to use this device"
243 )
244 }
245 }
246
247 #[doc(alias = "removed")]
248 fn connect_removed<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
249 unsafe extern "C" fn removed_trampoline<
250 P: IsA<Device>,
251 F: Fn(&P) + Send + Sync + 'static,
252 >(
253 this: *mut ffi::GstDevice,
254 f: glib::ffi::gpointer,
255 ) {
256 let f: &F = &*(f as *const F);
257 f(Device::from_glib_borrow(this).unsafe_cast_ref())
258 }
259 unsafe {
260 let f: Box_<F> = Box_::new(f);
261 connect_raw(
262 self.as_ptr() as *mut _,
263 c"removed".as_ptr() as *const _,
264 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
265 removed_trampoline::<Self, F> as *const (),
266 )),
267 Box_::into_raw(f),
268 )
269 }
270 }
271}
272
273impl<O: IsA<Device>> DeviceExt for O {}