From 0aa59be45ce4d8578d786e837dccc863466d5625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 6 May 2022 16:06:02 +0300 Subject: [PATCH] gstreamer: Improve accessors to various pad template fields --- gstreamer/Gir.toml | 30 ++++++++++++++++ gstreamer/src/auto/pad_template.rs | 36 ------------------- gstreamer/src/pad_template.rs | 58 ++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 36 deletions(-) diff --git a/gstreamer/Gir.toml b/gstreamer/Gir.toml index 7de0639fd..bd10916e3 100644 --- a/gstreamer/Gir.toml +++ b/gstreamer/Gir.toml @@ -1796,6 +1796,36 @@ final_type = true # static pad template manual manual = true + [[object.function]] + name = "get_caps" + # directly access the field + manual = true + + [[object.function]] + name = "get_documentation_caps" + # directly access the field + manual = true + + [[object.property]] + name = "name-template" + # directly access the field and borrow the string + manual = true + + [[object.property]] + name = "direction" + # directly access the field + manual = true + + [[object.property]] + name = "presence" + # directly access the field + manual = true + + [[object.property]] + name = "gtype" + # directly access the field + manual = true + [[object]] name = "Gst.ParseContext" status = "manual" diff --git a/gstreamer/src/auto/pad_template.rs b/gstreamer/src/auto/pad_template.rs index d019f0263..9b6b781df 100644 --- a/gstreamer/src/auto/pad_template.rs +++ b/gstreamer/src/auto/pad_template.rs @@ -13,7 +13,6 @@ use glib::object::ObjectType as ObjectType_; use glib::signal::connect_raw; use glib::signal::SignalHandlerId; use glib::translate::*; -use glib::StaticType; use std::boxed::Box as Box_; use std::mem::transmute; @@ -68,24 +67,6 @@ impl PadTemplate { } } - #[doc(alias = "gst_pad_template_get_caps")] - #[doc(alias = "get_caps")] - pub fn caps(&self) -> Caps { - unsafe { from_glib_full(ffi::gst_pad_template_get_caps(self.to_glib_none().0)) } - } - - #[cfg(any(feature = "v1_18", feature = "dox"))] - #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] - #[doc(alias = "gst_pad_template_get_documentation_caps")] - #[doc(alias = "get_documentation_caps")] - pub fn documentation_caps(&self) -> Caps { - unsafe { - from_glib_full(ffi::gst_pad_template_get_documentation_caps( - self.to_glib_none().0, - )) - } - } - #[doc(alias = "gst_pad_template_pad_created")] pub fn pad_created(&self, pad: &impl IsA) { unsafe { @@ -105,23 +86,6 @@ impl PadTemplate { } } - pub fn direction(&self) -> PadDirection { - glib::ObjectExt::property(self, "direction") - } - - pub fn gtype(&self) -> glib::types::Type { - glib::ObjectExt::property(self, "gtype") - } - - #[doc(alias = "name-template")] - pub fn name_template(&self) -> Option { - glib::ObjectExt::property(self, "name-template") - } - - pub fn presence(&self) -> PadPresence { - glib::ObjectExt::property(self, "presence") - } - #[doc(alias = "pad-created")] pub fn connect_pad_created( &self, diff --git a/gstreamer/src/pad_template.rs b/gstreamer/src/pad_template.rs index 0da10caf1..74b1e93e5 100644 --- a/gstreamer/src/pad_template.rs +++ b/gstreamer/src/pad_template.rs @@ -1,8 +1,13 @@ // Take a look at the license at the top of the repository in the LICENSE file. +use crate::Caps; +use crate::PadDirection; +use crate::PadPresence; use crate::PadTemplate; use crate::StaticPadTemplate; +use glib::prelude::*; use glib::translate::*; +use std::ffi::CStr; impl PadTemplate { #[doc(alias = "gst_pad_template_new_from_static_pad_template_with_gtype")] @@ -21,4 +26,57 @@ impl PadTemplate { .ok_or_else(|| glib::bool_error!("Failed to create PadTemplate")) } } + + #[doc(alias = "gst_pad_template_get_caps")] + #[doc(alias = "get_caps")] + pub fn caps(&self) -> &Caps { + unsafe { + let templ = &*(self.as_ptr() as *const ffi::GstPadTemplate); + &*(&templ.caps as *const *mut ffi::GstCaps as *const Caps) + } + } + + #[cfg(any(feature = "v1_18", feature = "dox"))] + #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] + #[doc(alias = "gst_pad_template_get_documentation_caps")] + #[doc(alias = "get_documentation_caps")] + pub fn documentation_caps(&self) -> &Caps { + unsafe { + let templ = &*(self.as_ptr() as *const ffi::GstPadTemplate); + if !templ.ABI.abi.documentation_caps.is_null() { + &*(&templ.ABI.abi.documentation_caps as *const *mut ffi::GstCaps as *const Caps) + } else { + &*(&templ.caps as *const *mut ffi::GstCaps as *const Caps) + } + } + } + + pub fn direction(&self) -> PadDirection { + unsafe { + let templ = &*(self.as_ptr() as *const ffi::GstPadTemplate); + from_glib(templ.direction) + } + } + + pub fn gtype(&self) -> glib::types::Type { + unsafe { + let templ = &*(self.as_ptr() as *const ffi::GstPadTemplate); + from_glib(templ.ABI.abi.gtype) + } + } + + #[doc(alias = "name-template")] + pub fn name_template(&self) -> &str { + unsafe { + let templ = &*(self.as_ptr() as *const ffi::GstPadTemplate); + CStr::from_ptr(templ.name_template).to_str().unwrap() + } + } + + pub fn presence(&self) -> PadPresence { + unsafe { + let templ = &*(self.as_ptr() as *const ffi::GstPadTemplate); + from_glib(templ.presence) + } + } }