gstreamer/
device_monitor.rs1use std::num::NonZeroU32;
4
5use glib::{prelude::*, translate::*};
6
7use crate::{Caps, DeviceMonitor, ffi};
8
9#[derive(Debug, PartialEq, Eq)]
10pub struct DeviceMonitorFilterId(NonZeroU32);
11
12impl IntoGlib for DeviceMonitorFilterId {
13 type GlibType = libc::c_uint;
14
15 #[inline]
16 fn into_glib(self) -> libc::c_uint {
17 self.0.get()
18 }
19}
20
21impl FromGlib<libc::c_uint> for DeviceMonitorFilterId {
22 #[inline]
23 unsafe fn from_glib(val: libc::c_uint) -> DeviceMonitorFilterId {
24 unsafe {
25 skip_assert_initialized!();
26 debug_assert_ne!(val, 0);
27 DeviceMonitorFilterId(NonZeroU32::new_unchecked(val))
28 }
29 }
30}
31
32pub trait DeviceMonitorExtManual: IsA<DeviceMonitor> + 'static {
33 #[doc(alias = "gst_device_monitor_add_filter")]
34 fn add_filter(
35 &self,
36 classes: Option<&str>,
37 caps: Option<&Caps>,
38 ) -> Option<DeviceMonitorFilterId> {
39 let id = unsafe {
40 ffi::gst_device_monitor_add_filter(
41 self.as_ref().to_glib_none().0,
42 classes.to_glib_none().0,
43 caps.to_glib_none().0,
44 )
45 };
46
47 if id == 0 {
48 None
49 } else {
50 Some(unsafe { from_glib(id) })
51 }
52 }
53
54 #[doc(alias = "gst_device_monitor_remove_filter")]
55 fn remove_filter(
56 &self,
57 filter_id: DeviceMonitorFilterId,
58 ) -> Result<(), glib::error::BoolError> {
59 unsafe {
60 glib::result_from_gboolean!(
61 ffi::gst_device_monitor_remove_filter(
62 self.as_ref().to_glib_none().0,
63 filter_id.into_glib()
64 ),
65 "Failed to remove the filter"
66 )
67 }
68 }
69
70 #[doc(alias = "gst_device_monitor_get_devices")]
71 #[doc(alias = "get_devices")]
72 fn devices(&self) -> glib::List<crate::Device> {
73 unsafe {
74 FromGlibPtrContainer::from_glib_full(ffi::gst_device_monitor_get_devices(
75 self.as_ref().to_glib_none().0,
76 ))
77 }
78 }
79}
80
81impl<O: IsA<DeviceMonitor>> DeviceMonitorExtManual for O {}