mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-12-31 12:28:45 +00:00
gstreamer: Add DeviceProviderClassExt
extension trait for class methods
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1322>
This commit is contained in:
parent
27a0bc5af0
commit
3f16233a01
3 changed files with 31 additions and 11 deletions
|
@ -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",
|
||||
|
|
|
@ -39,16 +39,9 @@ pub trait DeviceProviderExtManual: sealed::Sealed + IsA<DeviceProvider> + '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::<DeviceProvider>()
|
||||
.class()
|
||||
.metadata(key)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,3 +57,29 @@ pub trait DeviceProviderExtManual: sealed::Sealed + IsA<DeviceProvider> + 'stati
|
|||
}
|
||||
|
||||
impl<O: IsA<DeviceProvider>> 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<T: IsA<DeviceProvider> + glib::object::IsClass> DeviceProviderClassExt
|
||||
for glib::object::Class<T>
|
||||
{
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue