feat: Many more improvements to video player now with a subscription

This commit is contained in:
uttarayan21
2025-12-26 19:06:40 +05:30
parent 99853167df
commit 584495453f
13 changed files with 800 additions and 801 deletions

View File

@@ -18,6 +18,7 @@ pub struct VideoSource {
pub(crate) bus: Bus,
pub(crate) ready: Arc<AtomicBool>,
pub(crate) frame: Arc<Mutex<gst::Sample>>,
pub(crate) size: std::sync::OnceLock<(i32, i32)>,
}
impl VideoSource {
@@ -79,15 +80,17 @@ impl VideoSource {
bus,
ready,
frame,
size: std::sync::OnceLock::new(),
})
}
pub async fn wait(self) -> Result<()> {
pub async fn wait(&self) -> Result<()> {
self.playbin
.wait_for_states(&[gst::State::Paused, gst::State::Playing])
.await
.change_context(Error)
.attach("Failed to wait for video initialisation")
.attach("Failed to wait for video initialisation")?;
Ok(())
}
pub fn is_playing(&self) -> Result<bool> {
@@ -126,14 +129,20 @@ impl VideoSource {
}
pub fn size(&self) -> Result<(i32, i32)> {
if let Some(size) = self.size.get() {
return Ok(*size);
}
let caps = self
.appsink
.sink("sink")
.current_caps()
.change_context(Error)?;
caps.width()
let out = caps
.width()
.and_then(|width| caps.height().map(|height| (width, height)))
.ok_or(Error)
.attach("Failed to get width, height")
.attach("Failed to get width, height")?;
self.size.set(out);
Ok(out)
}
}