63 lines
1.2 KiB
Rust
63 lines
1.2 KiB
Rust
use crate::*;
|
|
#[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 {
|
|
use gstreamer::prelude::*;
|
|
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<&str> {
|
|
use gstreamer::prelude::*;
|
|
self.inner
|
|
.structure(0)
|
|
.and_then(|s| s.get::<&str>("format").ok())
|
|
}
|
|
}
|