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
93mod sealed {
94 pub trait Sealed {}
95 impl<T: super::IsA<super::Device>> Sealed for T {}
96}
97
98/// Trait containing all [`struct@Device`] methods.
99///
100/// # Implementors
101///
102/// [`Device`][struct@crate::Device]
103pub trait DeviceExt: IsA<Device> + sealed::Sealed + 'static {
104 /// Creates the element with all of the required parameters set to use
105 /// this device.
106 /// ## `name`
107 /// name of new element, or [`None`] to automatically
108 /// create a unique name.
109 ///
110 /// # Returns
111 ///
112 /// a new [`Element`][crate::Element] configured to use
113 /// this device
114 #[doc(alias = "gst_device_create_element")]
115 fn create_element(&self, name: Option<&str>) -> Result<Element, glib::BoolError> {
116 unsafe {
117 Option::<_>::from_glib_none(ffi::gst_device_create_element(
118 self.as_ref().to_glib_none().0,
119 name.to_glib_none().0,
120 ))
121 .ok_or_else(|| glib::bool_error!("Failed to create element for device"))
122 }
123 }
124
125 /// Getter for the [`Caps`][crate::Caps] that this device supports.
126 ///
127 /// # Returns
128 ///
129 /// The [`Caps`][crate::Caps] supported by this device. Unref with
130 /// `gst_caps_unref()` when done.
131 #[doc(alias = "gst_device_get_caps")]
132 #[doc(alias = "get_caps")]
133 fn caps(&self) -> Option<Caps> {
134 unsafe { from_glib_full(ffi::gst_device_get_caps(self.as_ref().to_glib_none().0)) }
135 }
136
137 /// Gets the "class" of a device. This is a "/" separated list of
138 /// classes that represent this device. They are a subset of the
139 /// classes of the [`DeviceProvider`][crate::DeviceProvider] that produced this device.
140 ///
141 /// # Returns
142 ///
143 /// The device class. Free with `g_free()` after use.
144 #[doc(alias = "gst_device_get_device_class")]
145 #[doc(alias = "get_device_class")]
146 #[doc(alias = "device-class")]
147 fn device_class(&self) -> glib::GString {
148 unsafe {
149 from_glib_full(ffi::gst_device_get_device_class(
150 self.as_ref().to_glib_none().0,
151 ))
152 }
153 }
154
155 /// Gets the user-friendly name of the device.
156 ///
157 /// # Returns
158 ///
159 /// The device name. Free with `g_free()` after use.
160 #[doc(alias = "gst_device_get_display_name")]
161 #[doc(alias = "get_display_name")]
162 #[doc(alias = "display-name")]
163 fn display_name(&self) -> glib::GString {
164 unsafe {
165 from_glib_full(ffi::gst_device_get_display_name(
166 self.as_ref().to_glib_none().0,
167 ))
168 }
169 }
170
171 /// Gets the extra properties of a device.
172 ///
173 /// # Returns
174 ///
175 /// The extra properties or [`None`] when there are none.
176 /// Free with `gst_structure_free()` after use.
177 #[doc(alias = "gst_device_get_properties")]
178 #[doc(alias = "get_properties")]
179 fn properties(&self) -> Option<Structure> {
180 unsafe {
181 from_glib_full(ffi::gst_device_get_properties(
182 self.as_ref().to_glib_none().0,
183 ))
184 }
185 }
186
187 /// Check if `self` matches all of the given classes
188 /// ## `classes`
189 /// a "/"-separated list of device classes to match, only match if
190 /// all classes are matched
191 ///
192 /// # Returns
193 ///
194 /// [`true`] if `self` matches.
195 #[doc(alias = "gst_device_has_classes")]
196 fn has_classes(&self, classes: &str) -> bool {
197 unsafe {
198 from_glib(ffi::gst_device_has_classes(
199 self.as_ref().to_glib_none().0,
200 classes.to_glib_none().0,
201 ))
202 }
203 }
204
205 /// Check if `factory` matches all of the given classes
206 /// ## `classes`
207 /// a [`None`] terminated array of classes
208 /// to match, only match if all classes are matched
209 ///
210 /// # Returns
211 ///
212 /// [`true`] if `self` matches.
213 #[doc(alias = "gst_device_has_classesv")]
214 fn has_classesv(&self, classes: &[&str]) -> bool {
215 unsafe {
216 from_glib(ffi::gst_device_has_classesv(
217 self.as_ref().to_glib_none().0,
218 classes.to_glib_none().0,
219 ))
220 }
221 }
222
223 /// Tries to reconfigure an existing element to use the device. If this
224 /// function fails, then one must destroy the element and create a new one
225 /// using [`create_element()`][Self::create_element()].
226 ///
227 /// Note: This should only be implemented for elements can change their
228 /// device in the PLAYING state.
229 /// ## `element`
230 /// a [`Element`][crate::Element]
231 ///
232 /// # Returns
233 ///
234 /// [`true`] if the element could be reconfigured to use this device,
235 /// [`false`] otherwise.
236 #[doc(alias = "gst_device_reconfigure_element")]
237 fn reconfigure_element(
238 &self,
239 element: &impl IsA<Element>,
240 ) -> Result<(), glib::error::BoolError> {
241 unsafe {
242 glib::result_from_gboolean!(
243 ffi::gst_device_reconfigure_element(
244 self.as_ref().to_glib_none().0,
245 element.as_ref().to_glib_none().0
246 ),
247 "Failed to reconfigure the element to use this device"
248 )
249 }
250 }
251
252 #[doc(alias = "removed")]
253 fn connect_removed<F: Fn(&Self) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
254 unsafe extern "C" fn removed_trampoline<
255 P: IsA<Device>,
256 F: Fn(&P) + Send + Sync + 'static,
257 >(
258 this: *mut ffi::GstDevice,
259 f: glib::ffi::gpointer,
260 ) {
261 let f: &F = &*(f as *const F);
262 f(Device::from_glib_borrow(this).unsafe_cast_ref())
263 }
264 unsafe {
265 let f: Box_<F> = Box_::new(f);
266 connect_raw(
267 self.as_ptr() as *mut _,
268 b"removed\0".as_ptr() as *const _,
269 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
270 removed_trampoline::<Self, F> as *const (),
271 )),
272 Box_::into_raw(f),
273 )
274 }
275 }
276}
277
278impl<O: IsA<Device>> DeviceExt for O {}