forked from mirrors/gstreamer-rs
gstreamer: Add extension trait to mark API as plugins API
This adds an extension trait implemented for GType so we can add and check plugins API status. Required so we can document plugins written in rust.
This commit is contained in:
parent
70d95dca4c
commit
e9d95eda59
4 changed files with 99 additions and 23 deletions
|
@ -372,7 +372,7 @@ status = "generate"
|
||||||
|
|
||||||
[[object.function]]
|
[[object.function]]
|
||||||
name = "type_is_plugin_api"
|
name = "type_is_plugin_api"
|
||||||
# confusing return type
|
# We implement it in an extension Trait
|
||||||
ignore = true
|
ignore = true
|
||||||
|
|
||||||
[[object.function]]
|
[[object.function]]
|
||||||
|
|
|
@ -169,28 +169,6 @@ pub fn calculate_linear_regression(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
|
||||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
|
||||||
#[doc(alias = "gst_type_is_plugin_api")]
|
|
||||||
pub fn type_is_plugin_api(type_: glib::types::Type) -> Option<crate::PluginAPIFlags> {
|
|
||||||
assert_initialized_main_thread!();
|
|
||||||
unsafe {
|
|
||||||
use std::mem;
|
|
||||||
|
|
||||||
let mut flags = mem::MaybeUninit::uninit();
|
|
||||||
let ret = from_glib(ffi::gst_type_is_plugin_api(
|
|
||||||
type_.into_glib(),
|
|
||||||
flags.as_mut_ptr(),
|
|
||||||
));
|
|
||||||
let flags = flags.assume_init();
|
|
||||||
if ret {
|
|
||||||
Some(from_glib(flags))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
||||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
||||||
#[doc(alias = "gst_tracing_get_active_tracers")]
|
#[doc(alias = "gst_tracing_get_active_tracers")]
|
||||||
|
|
93
gstreamer/src/gtype.rs
Normal file
93
gstreamer/src/gtype.rs
Normal file
|
@ -0,0 +1,93 @@
|
||||||
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
||||||
|
|
||||||
|
use glib::translate::*;
|
||||||
|
use std::ffi::c_void;
|
||||||
|
|
||||||
|
pub trait PluginApiExt {
|
||||||
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
||||||
|
#[doc(alias = "gst_type_mark_as_plugin_api")]
|
||||||
|
fn mark_as_plugin_api(self, flags: crate::PluginAPIFlags);
|
||||||
|
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
||||||
|
#[doc(alias = "gst_type_is_plugin_api")]
|
||||||
|
fn plugin_api_flags(self) -> Option<crate::PluginAPIFlags>;
|
||||||
|
#[doc(alias = "gst_element_type_set_skip_documentation")]
|
||||||
|
fn set_skip_documentation(self);
|
||||||
|
#[doc(alias = "gst_element_factory_get_skip_documentation")]
|
||||||
|
fn skip_documentation(self) -> bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl PluginApiExt for glib::Type {
|
||||||
|
fn set_skip_documentation(self) {
|
||||||
|
let quark = glib::Quark::from_str("GST_ELEMENTCLASS_SKIP_DOCUMENTATION");
|
||||||
|
unsafe {
|
||||||
|
crate::glib::gobject_ffi::g_type_set_qdata(
|
||||||
|
self.into_glib(),
|
||||||
|
quark.into_glib(),
|
||||||
|
1 as *mut c_void,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn skip_documentation(self) -> bool {
|
||||||
|
let quark = glib::Quark::from_str("GST_ELEMENTCLASS_SKIP_DOCUMENTATION");
|
||||||
|
unsafe {
|
||||||
|
!crate::glib::gobject_ffi::g_type_get_qdata(self.into_glib(), quark.into_glib())
|
||||||
|
.is_null()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn plugin_api_flags(self) -> Option<crate::PluginAPIFlags> {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
unsafe {
|
||||||
|
use std::mem;
|
||||||
|
|
||||||
|
let mut flags = mem::MaybeUninit::uninit();
|
||||||
|
let ret = from_glib(ffi::gst_type_is_plugin_api(
|
||||||
|
self.into_glib(),
|
||||||
|
flags.as_mut_ptr(),
|
||||||
|
));
|
||||||
|
let flags = flags.assume_init();
|
||||||
|
if ret {
|
||||||
|
Some(from_glib(flags))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn mark_as_plugin_api(self, flags: crate::PluginAPIFlags) {
|
||||||
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
|
unsafe { ffi::gst_type_mark_as_plugin_api(self.into_glib(), flags.into_glib()) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use glib::StaticType;
|
||||||
|
|
||||||
|
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy, glib::Enum)]
|
||||||
|
#[repr(u32)]
|
||||||
|
#[enum_type(name = "GstTestEnum")]
|
||||||
|
pub enum TestEnum {
|
||||||
|
#[enum_value(name = "test", nick = "test")]
|
||||||
|
Test,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_gtype_mark_as_api() {
|
||||||
|
crate::init().unwrap();
|
||||||
|
|
||||||
|
assert!(TestEnum::static_type().plugin_api_flags().is_none());
|
||||||
|
assert!(!TestEnum::static_type().skip_documentation());
|
||||||
|
|
||||||
|
TestEnum::static_type().mark_as_plugin_api(crate::PluginAPIFlags::empty());
|
||||||
|
TestEnum::static_type().set_skip_documentation();
|
||||||
|
|
||||||
|
assert!(
|
||||||
|
TestEnum::static_type().plugin_api_flags().unwrap() == crate::PluginAPIFlags::empty()
|
||||||
|
);
|
||||||
|
assert!(TestEnum::static_type().skip_documentation());
|
||||||
|
}
|
||||||
|
}
|
|
@ -261,6 +261,9 @@ pub use crate::functions::*;
|
||||||
|
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
||||||
|
mod gtype;
|
||||||
|
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
#[doc(alias = "gst_init_check")]
|
#[doc(alias = "gst_init_check")]
|
||||||
|
@ -326,6 +329,8 @@ pub mod prelude {
|
||||||
pub use crate::device_provider::DeviceProviderExtManual;
|
pub use crate::device_provider::DeviceProviderExtManual;
|
||||||
pub use crate::element::{ElementClassExt, ElementExtManual};
|
pub use crate::element::{ElementClassExt, ElementExtManual};
|
||||||
pub use crate::gobject::GObjectExtManualGst;
|
pub use crate::gobject::GObjectExtManualGst;
|
||||||
|
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
||||||
|
pub use crate::gtype::PluginApiExt;
|
||||||
pub use crate::message::MessageErrorDomain;
|
pub use crate::message::MessageErrorDomain;
|
||||||
pub use crate::object::GstObjectExtManual;
|
pub use crate::object::GstObjectExtManual;
|
||||||
pub use crate::pad::PadExtManual;
|
pub use crate::pad::PadExtManual;
|
||||||
|
|
Loading…
Reference in a new issue