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, } impl CapsBuilder { pub fn field + Send>(mut self, name: impl AsRef, 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 { 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 { self.inner .structure(0) .and_then(|s| s.get::("width").ok()) } pub fn height(&self) -> Option { self.inner .structure(0) .and_then(|s| s.get::("height").ok()) } pub fn framerate(&self) -> Option { self.inner .structure(0) .and_then(|s| s.get::("framerate").ok()) } }