diff --git a/Gir_Gst.toml b/Gir_Gst.toml index a818a07f0..a4f7dcdcd 100644 --- a/Gir_Gst.toml +++ b/Gir_Gst.toml @@ -547,6 +547,11 @@ status = "generate" # Work-around for 1.14 switch from transfer-floating to transfer-full ignore = true + [[object.function]] + name = "add_filter" + # Return Option + ignore = true + [[object.function]] name = "get_bus" [object.function.return] @@ -559,8 +564,8 @@ status = "generate" [[object.function]] name = "remove_filter" - [object.function.return] - bool_return_is_error = "Failed to remove the filter" + # Use DeviceMonitorFilterId and return Result<(), glib::BoolError> + ignore = true [[object]] name = "Gst.Device" diff --git a/gstreamer/src/auto/device_monitor.rs b/gstreamer/src/auto/device_monitor.rs index f89a7506e..3fbd365fd 100644 --- a/gstreamer/src/auto/device_monitor.rs +++ b/gstreamer/src/auto/device_monitor.rs @@ -3,7 +3,6 @@ // DO NOT EDIT use Bus; -use Caps; use Device; use Object; use ffi; @@ -35,8 +34,6 @@ unsafe impl Sync for DeviceMonitor {} pub const NONE_DEVICE_MONITOR: Option<&DeviceMonitor> = None; pub trait DeviceMonitorExt: 'static { - fn add_filter<'a, 'b, P: Into>, Q: Into>>(&self, classes: P, caps: Q) -> u32; - fn get_bus(&self) -> Bus; fn get_devices(&self) -> Vec; @@ -45,8 +42,6 @@ pub trait DeviceMonitorExt: 'static { fn get_show_all_devices(&self) -> bool; - fn remove_filter(&self, filter_id: u32) -> Result<(), glib::error::BoolError>; - fn set_show_all_devices(&self, show_all: bool); fn start(&self) -> Result<(), glib::error::BoolError>; @@ -61,14 +56,6 @@ pub trait DeviceMonitorExt: 'static { } impl> DeviceMonitorExt for O { - fn add_filter<'a, 'b, P: Into>, Q: Into>>(&self, classes: P, caps: Q) -> u32 { - let classes = classes.into(); - let caps = caps.into(); - unsafe { - ffi::gst_device_monitor_add_filter(self.as_ref().to_glib_none().0, classes.to_glib_none().0, caps.to_glib_none().0) - } - } - fn get_bus(&self) -> Bus { unsafe { from_glib_full(ffi::gst_device_monitor_get_bus(self.as_ref().to_glib_none().0)) @@ -93,12 +80,6 @@ impl> DeviceMonitorExt for O { } } - fn remove_filter(&self, filter_id: u32) -> Result<(), glib::error::BoolError> { - unsafe { - glib_result_from_gboolean!(ffi::gst_device_monitor_remove_filter(self.as_ref().to_glib_none().0, filter_id), "Failed to remove the filter") - } - } - fn set_show_all_devices(&self, show_all: bool) { unsafe { ffi::gst_device_monitor_set_show_all_devices(self.as_ref().to_glib_none().0, show_all.to_glib()); diff --git a/gstreamer/src/device_monitor.rs b/gstreamer/src/device_monitor.rs index 44f1cc742..ffcd761bb 100644 --- a/gstreamer/src/device_monitor.rs +++ b/gstreamer/src/device_monitor.rs @@ -1,4 +1,4 @@ -// Copyright (C) 2018 Sebastian Dröge +// Copyright (C) 2018-2019 Sebastian Dröge // // Licensed under the Apache License, Version 2.0 or the MIT license @@ -6,10 +6,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use ffi; -use glib::translate::*; +use Caps; use DeviceMonitor; +use glib; +use glib::object::IsA; +use glib::translate::*; + +use ffi; + impl DeviceMonitor { pub fn new() -> DeviceMonitor { assert_initialized_main_thread!(); @@ -28,3 +33,72 @@ impl Default for DeviceMonitor { Self::new() } } + +#[derive(Debug, PartialEq, Eq)] +pub struct DeviceMonitorFilterId(libc::c_uint); + +impl ToGlib for DeviceMonitorFilterId { + type GlibType = libc::c_uint; + + fn to_glib(&self) -> libc::c_uint { + self.0 + } +} + +impl FromGlib for DeviceMonitorFilterId { + fn from_glib(val: libc::c_uint) -> DeviceMonitorFilterId { + skip_assert_initialized!(); + assert_ne!(val, 0); + DeviceMonitorFilterId(val) + } +} + +pub trait DeviceMonitorExtManual: 'static { + fn add_filter<'a, 'b, P: Into>, Q: Into>>( + &self, + classes: P, + caps: Q, + ) -> Option; + + fn remove_filter(&self, filter_id: DeviceMonitorFilterId) + -> Result<(), glib::error::BoolError>; +} + +impl> DeviceMonitorExtManual for O { + fn add_filter<'a, 'b, P: Into>, Q: Into>>( + &self, + classes: P, + caps: Q, + ) -> Option { + let classes = classes.into(); + let caps = caps.into(); + let id = unsafe { + ffi::gst_device_monitor_add_filter( + self.as_ref().to_glib_none().0, + classes.to_glib_none().0, + caps.to_glib_none().0, + ) + }; + + if id == 0 { + None + } else { + Some(from_glib(id)) + } + } + + fn remove_filter( + &self, + filter_id: DeviceMonitorFilterId, + ) -> Result<(), glib::error::BoolError> { + unsafe { + glib_result_from_gboolean!( + ffi::gst_device_monitor_remove_filter( + self.as_ref().to_glib_none().0, + filter_id.to_glib() + ), + "Failed to remove the filter" + ) + } + } +} diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index ee7cdaa3a..80dc6b6be 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -210,6 +210,7 @@ pub use self::iterator::{Iterator, IteratorError, IteratorImpl}; pub use bus::BusStream; pub use child_proxy::ChildProxyExtManual; pub use clock_time::ClockTime; +pub use device_monitor::{DeviceMonitorExtManual, DeviceMonitorFilterId}; pub use device_provider::DeviceProviderExtManual; pub use enums::{ ClockError, ClockSuccess, FlowError, FlowSuccess, PadLinkError, PadLinkSuccess, @@ -324,6 +325,7 @@ pub mod prelude { pub use buffer_pool::BufferPoolExtManual; pub use child_proxy::ChildProxyExtManual; pub use clock::ClockExtManual; + pub use device_monitor::DeviceMonitorExtManual; pub use device_provider::DeviceProviderExtManual; pub use gobject::GObjectExtManualGst; pub use object::GstObjectExtManual;