gstreamer-rs/gstreamer/src/pad_template.rs

83 lines
2.7 KiB
Rust
Raw Normal View History

2020-12-15 10:53:31 +00:00
// Take a look at the license at the top of the repository in the LICENSE file.
2018-03-15 08:46:49 +00:00
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;
2018-03-15 08:46:49 +00:00
impl PadTemplate {
#[doc(alias = "gst_pad_template_new_from_static_pad_template_with_gtype")]
pub fn from_static_pad_template_with_gtype(
2018-04-01 08:30:03 +00:00
pad_template: &StaticPadTemplate,
pad_type: glib::types::Type,
) -> Result<PadTemplate, glib::BoolError> {
2018-03-15 08:46:49 +00:00
assert_initialized_main_thread!();
unsafe {
Option::<_>::from_glib_none(
ffi::gst_pad_template_new_from_static_pad_template_with_gtype(
2018-04-01 08:30:03 +00:00
mut_override(pad_template.to_glib_none().0),
pad_type.into_glib(),
2018-04-01 08:30:03 +00:00
),
)
.ok_or_else(|| glib::bool_error!("Failed to create PadTemplate"))
2018-03-15 08:46:49 +00:00
}
}
#[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)
}
}
2018-03-15 08:46:49 +00:00
}