Files
jello/gst/src/caps.rs
2025-12-25 02:14:56 +05:30

79 lines
1.8 KiB
Rust

use gstreamer::Fraction;
#[derive(Debug, Clone)]
#[repr(transparent)]
pub struct Caps {
pub(crate) inner: gstreamer::caps::Caps,
}
impl Caps {
pub fn builder(cs: CapsType) -> CapsBuilder {
CapsBuilder::new(cs)
}
}
pub struct CapsBuilder {
inner: gstreamer::caps::Builder<gstreamer::caps::NoFeature>,
}
impl CapsBuilder {
pub fn field<V: Into<glib::Value> + Send>(mut self, name: impl AsRef<str>, value: V) -> Self {
self.inner = self.inner.field(name.as_ref(), value);
self
}
pub fn build(self) -> Caps {
Caps {
inner: self.inner.build(),
}
}
}
pub enum CapsType {
Video,
Audio,
Text,
}
impl CapsType {
pub fn as_str(&self) -> &str {
match self {
CapsType::Video => "video/x-raw",
CapsType::Audio => "audio/x-raw",
CapsType::Text => "text/x-raw",
}
}
}
impl CapsBuilder {
pub fn new(cs: CapsType) -> Self {
CapsBuilder {
inner: gstreamer::Caps::builder(cs.as_str()),
}
}
}
impl Caps {
pub fn format(&self) -> Option<gstreamer_video::VideoFormat> {
self.inner
.structure(0)
.and_then(|s| s.get::<&str>("format").ok())
.map(|s| gstreamer_video::VideoFormat::from_string(s))
}
pub fn width(&self) -> Option<i32> {
self.inner
.structure(0)
.and_then(|s| s.get::<i32>("width").ok())
}
pub fn height(&self) -> Option<i32> {
self.inner
.structure(0)
.and_then(|s| s.get::<i32>("height").ok())
}
pub fn framerate(&self) -> Option<gstreamer::Fraction> {
self.inner
.structure(0)
.and_then(|s| s.get::<Fraction>("framerate").ok())
}
}