gstreamer/
device_monitor.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::num::NonZeroU32;
4
5use glib::{prelude::*, translate::*};
6
7use crate::{ffi, Caps, DeviceMonitor};
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        skip_assert_initialized!();
25        debug_assert_ne!(val, 0);
26        DeviceMonitorFilterId(NonZeroU32::new_unchecked(val))
27    }
28}
29
30pub trait DeviceMonitorExtManual: IsA<DeviceMonitor> + 'static {
31    #[doc(alias = "gst_device_monitor_add_filter")]
32    fn add_filter(
33        &self,
34        classes: Option<&str>,
35        caps: Option<&Caps>,
36    ) -> Option<DeviceMonitorFilterId> {
37        let id = unsafe {
38            ffi::gst_device_monitor_add_filter(
39                self.as_ref().to_glib_none().0,
40                classes.to_glib_none().0,
41                caps.to_glib_none().0,
42            )
43        };
44
45        if id == 0 {
46            None
47        } else {
48            Some(unsafe { from_glib(id) })
49        }
50    }
51
52    #[doc(alias = "gst_device_monitor_remove_filter")]
53    fn remove_filter(
54        &self,
55        filter_id: DeviceMonitorFilterId,
56    ) -> Result<(), glib::error::BoolError> {
57        unsafe {
58            glib::result_from_gboolean!(
59                ffi::gst_device_monitor_remove_filter(
60                    self.as_ref().to_glib_none().0,
61                    filter_id.into_glib()
62                ),
63                "Failed to remove the filter"
64            )
65        }
66    }
67
68    #[doc(alias = "gst_device_monitor_get_devices")]
69    #[doc(alias = "get_devices")]
70    fn devices(&self) -> glib::List<crate::Device> {
71        unsafe {
72            FromGlibPtrContainer::from_glib_full(ffi::gst_device_monitor_get_devices(
73                self.as_ref().to_glib_none().0,
74            ))
75        }
76    }
77}
78
79impl<O: IsA<DeviceMonitor>> DeviceMonitorExtManual for O {}