feat(gst): enhance GStreamer integration with new modules and improved API
This commit introduces significant enhancements to the GStreamer integration by: - Adding new modules for bins, caps, elements, pads, and plugins - Implementing a more ergonomic API with helper methods like play(), pause(), ready() - Adding support for various GStreamer plugins including app, autodetect, playback, and videoconvertscale - Improving error handling with better context attachment - Updating dependencies to latest versions including gstreamer-video 0.24.4 - Refactoring existing code to use modern Rust patterns and features
This commit is contained in:
52
gst/src/element.rs
Normal file
52
gst/src/element.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use crate::{Error, Pad, Result, ResultExt};
|
||||
#[repr(transparent)]
|
||||
pub struct Element {
|
||||
pub(crate) inner: gstreamer::Element,
|
||||
}
|
||||
|
||||
pub trait IsElement {
|
||||
fn as_element(&self) -> ∈
|
||||
fn into_element(self) -> Element;
|
||||
fn pad(&self, name: &str) -> Option<Pad> {
|
||||
use gstreamer::prelude::*;
|
||||
self.as_element().inner.static_pad(name).map(Pad::from)
|
||||
}
|
||||
}
|
||||
|
||||
impl IsElement for Element {
|
||||
fn as_element(&self) -> &Element {
|
||||
self
|
||||
}
|
||||
|
||||
fn into_element(self) -> Element {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Sink: IsElement {
|
||||
fn sink_pad(&self) -> Pad {
|
||||
use gstreamer::prelude::*;
|
||||
self.as_element()
|
||||
.pad("sink")
|
||||
.map(From::from)
|
||||
.expect("Sink element has no sink pad")
|
||||
}
|
||||
}
|
||||
pub trait Source: IsElement {
|
||||
fn source_pad(&self) -> Pad {
|
||||
use gstreamer::prelude::*;
|
||||
self.as_element()
|
||||
.pad("src")
|
||||
.map(From::from)
|
||||
.expect("Source element has no src pad")
|
||||
}
|
||||
|
||||
fn link<S: Sink>(&self, sink: &S) -> Result<()> {
|
||||
use gstreamer::prelude::*;
|
||||
self.as_element()
|
||||
.inner
|
||||
.link(&sink.as_element().inner)
|
||||
.change_context(Error)
|
||||
.attach("Failed to link source to sink")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user