feat(gst): implement Playbin3 wrapper with basic playback functionality
Some checks failed
build / checks-matrix (push) Has been cancelled
build / checks-build (push) Has been cancelled
build / codecov (push) Has been cancelled
docs / docs (push) Has been cancelled

This commit is contained in:
uttarayan21
2025-12-17 14:08:17 +05:30
parent a0bda88246
commit 21cbaff610

65
gst/src/playbin3.rs Normal file
View File

@@ -0,0 +1,65 @@
use crate::*;
pub struct Playbin3 {
inner: gstreamer::Element,
}
impl Drop for Playbin3 {
fn drop(&mut self) {
let _ = self.inner.set_state(gstreamer::State::Null);
}
}
impl Playbin3 {
pub fn new(name: impl AsRef<str>) -> Result<Self> {
use gstreamer::prelude::*;
gstreamer::ElementFactory::make("playbin3")
.name(name.as_ref())
.build()
.map(|element| Playbin3 { inner: element })
.change_context(Error)
}
pub fn with_uri(self, uri: impl AsRef<str>) -> Self {
use gstreamer::prelude::*;
self.inner.set_property("uri", uri.as_ref());
self
}
pub fn sample(&self) -> Option<Sample> {
use gstreamer::prelude::*;
self.inner
.property::<Option<gstreamer::Sample>>("sample")
// // .and_then(|v| v.get::<gstreamer::Sample>().ok())
.map(|sample| Sample { sample })
}
pub fn play(&self) -> Result<()> {
use gstreamer::prelude::*;
self.inner
.set_state(gstreamer::State::Playing)
.change_context(Error)
.attach("Failed to set playbin3 to Playing state")?;
Ok(())
}
pub fn bus(&self) -> Result<Bus> {
let bus = self
.inner
.bus()
.ok_or(Error)
.attach("Failed to get bus from playbin3")?;
Ok(Bus { bus })
}
}
#[test]
fn test_playbin3() {
use gstreamer::prelude::*;
gstreamer::init().unwrap();
let playbin3 = Playbin3::new("test_playbin3").unwrap().with_uri(
"https://www.freedesktop.org/software/gstreamer-sdk/data/media/sintel_trailer-480p.webm",
);
playbin3.play().unwrap();
let bus = playbin3.bus().unwrap();
for msg in bus.iter_timed(None) {}
// std::thread::sleep(std::time::Duration::from_secs(5));
}