From 21cbaff6103ff952b9af306e7b923981e2987d7d Mon Sep 17 00:00:00 2001 From: uttarayan21 Date: Wed, 17 Dec 2025 14:08:17 +0530 Subject: [PATCH] feat(gst): implement Playbin3 wrapper with basic playback functionality --- gst/src/playbin3.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 gst/src/playbin3.rs diff --git a/gst/src/playbin3.rs b/gst/src/playbin3.rs new file mode 100644 index 0000000..71beb73 --- /dev/null +++ b/gst/src/playbin3.rs @@ -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) -> Result { + 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) -> Self { + use gstreamer::prelude::*; + self.inner.set_property("uri", uri.as_ref()); + self + } + + pub fn sample(&self) -> Option { + use gstreamer::prelude::*; + self.inner + .property::>("sample") + // // .and_then(|v| v.get::().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 { + 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)); +}