diff --git a/gstreamer/Gir.toml b/gstreamer/Gir.toml index 6174f7b58..364506761 100644 --- a/gstreamer/Gir.toml +++ b/gstreamer/Gir.toml @@ -56,6 +56,7 @@ manual = [ "Gst.CapsFeatures", "Gst.DebugCategory", "Gst.DebugMessage", + "Gst.DeviceProviderClass", # for docs only "Gst.ElementClass", # for docs only "Gst.Segment", "Gst.StaticCaps", diff --git a/gstreamer/src/device_provider.rs b/gstreamer/src/device_provider.rs index 6b361bde1..9c6fc7dbc 100644 --- a/gstreamer/src/device_provider.rs +++ b/gstreamer/src/device_provider.rs @@ -39,16 +39,9 @@ pub trait DeviceProviderExtManual: sealed::Sealed + IsA + 'stati #[doc(alias = "gst_device_provider_class_get_metadata")] fn metadata<'a>(&self, key: &str) -> Option<&'a str> { unsafe { - let klass = (*(self.as_ptr() as *mut glib::gobject_ffi::GTypeInstance)).g_class - as *mut ffi::GstDeviceProviderClass; - - let ptr = ffi::gst_device_provider_class_get_metadata(klass, key.to_glib_none().0); - - if ptr.is_null() { - None - } else { - Some(CStr::from_ptr(ptr).to_str().unwrap()) - } + self.unsafe_cast_ref::() + .class() + .metadata(key) } } @@ -64,3 +57,29 @@ pub trait DeviceProviderExtManual: sealed::Sealed + IsA + 'stati } impl> DeviceProviderExtManual for O {} + +pub unsafe trait DeviceProviderClassExt { + #[doc(alias = "get_metadata")] + #[doc(alias = "gst_device_provider_class_get_metadata")] + fn metadata<'a>(&self, key: &str) -> Option<&'a str> { + unsafe { + let klass = self as *const _ as *const ffi::GstDeviceProviderClass; + + let ptr = ffi::gst_device_provider_class_get_metadata( + mut_override(klass), + key.to_glib_none().0, + ); + + if ptr.is_null() { + None + } else { + Some(CStr::from_ptr(ptr).to_str().unwrap()) + } + } + } +} + +unsafe impl + glib::object::IsClass> DeviceProviderClassExt + for glib::object::Class +{ +} diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index d64f7ed49..9708d3081 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -317,7 +317,7 @@ pub mod prelude { child_proxy::ChildProxyExtManual, clock::ClockExtManual, device_monitor::DeviceMonitorExtManual, - device_provider::DeviceProviderExtManual, + device_provider::{DeviceProviderClassExt, DeviceProviderExtManual}, element::{ElementClassExt, ElementExtManual}, format::prelude::*, gobject::GObjectExtManualGst,