mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 19:11:06 +00:00
gstreamer: Add a PadTemplateBuilder
And only allow setting documentation caps via that. It's not actually allowed to update the documentation caps at random times as it is not thread-safe.
This commit is contained in:
parent
0aa59be45c
commit
cd49659fae
4 changed files with 83 additions and 12 deletions
|
@ -1801,6 +1801,11 @@ final_type = true
|
|||
# directly access the field
|
||||
manual = true
|
||||
|
||||
[[object.function]]
|
||||
name = "set_documentation_caps"
|
||||
# builder
|
||||
manual = true
|
||||
|
||||
[[object.function]]
|
||||
name = "get_documentation_caps"
|
||||
# directly access the field
|
||||
|
|
|
@ -74,18 +74,6 @@ impl PadTemplate {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
||||
#[doc(alias = "gst_pad_template_set_documentation_caps")]
|
||||
pub fn set_documentation_caps(&self, caps: &Caps) {
|
||||
unsafe {
|
||||
ffi::gst_pad_template_set_documentation_caps(
|
||||
self.to_glib_none().0,
|
||||
caps.to_glib_full(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(alias = "pad-created")]
|
||||
pub fn connect_pad_created<F: Fn(&Self, &Pad) + Send + Sync + 'static>(
|
||||
&self,
|
||||
|
|
|
@ -240,6 +240,7 @@ mod buffer_pool;
|
|||
pub use crate::buffer_pool::{BufferPoolAcquireParams, BufferPoolConfig, BufferPoolConfigRef};
|
||||
|
||||
mod pad_template;
|
||||
pub use pad_template::PadTemplateBuilder;
|
||||
|
||||
pub mod param_spec;
|
||||
pub use crate::param_spec::ParamSpecArray;
|
||||
|
|
|
@ -79,4 +79,81 @@ impl PadTemplate {
|
|||
from_glib(templ.presence)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn builder<'a>(
|
||||
name_template: &'a str,
|
||||
direction: PadDirection,
|
||||
presence: PadPresence,
|
||||
caps: &'a Caps,
|
||||
) -> PadTemplateBuilder<'a> {
|
||||
assert_initialized_main_thread!();
|
||||
|
||||
PadTemplateBuilder {
|
||||
name_template,
|
||||
direction,
|
||||
presence,
|
||||
caps,
|
||||
gtype: None,
|
||||
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
||||
documentation_caps: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PadTemplateBuilder<'a> {
|
||||
name_template: &'a str,
|
||||
direction: PadDirection,
|
||||
presence: PadPresence,
|
||||
caps: &'a Caps,
|
||||
gtype: Option<glib::Type>,
|
||||
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
||||
documentation_caps: Option<&'a Caps>,
|
||||
}
|
||||
|
||||
impl<'a> PadTemplateBuilder<'a> {
|
||||
pub fn gtype(self, gtype: glib::Type) -> Self {
|
||||
PadTemplateBuilder {
|
||||
gtype: Some(gtype),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
||||
pub fn documentation_caps(self, documentation_caps: &'a Caps) -> Self {
|
||||
PadTemplateBuilder {
|
||||
documentation_caps: Some(documentation_caps),
|
||||
..self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build(self) -> Result<PadTemplate, glib::BoolError> {
|
||||
let templ = if let Some(gtype) = self.gtype {
|
||||
PadTemplate::with_gtype(
|
||||
self.name_template,
|
||||
self.direction,
|
||||
self.presence,
|
||||
self.caps,
|
||||
gtype,
|
||||
)?
|
||||
} else {
|
||||
PadTemplate::new(self.name_template, self.direction, self.presence, self.caps)?
|
||||
};
|
||||
|
||||
#[cfg(any(feature = "v1_18", feature = "dox"))]
|
||||
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
|
||||
if let Some(documentation_caps) = self.documentation_caps {
|
||||
unsafe {
|
||||
ffi::gst_pad_template_set_documentation_caps(
|
||||
templ.to_glib_none().0,
|
||||
documentation_caps.to_glib_none().0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Ok(templ)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue