2025-06-24 23:48:06 -05:00

53 lines
1.6 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// client/src/output/video.rs
use gstreamer as gst;
use gstreamer_app as gst_app;
use gst::prelude::*;
use gst_app::prelude::*;
use lesavka_common::lesavka::VideoPacket;
use winit::window::{Window, WindowAttributes};
use winit::event_loop::EventLoop;
pub struct MonitorWindow {
id: u32,
_window: Window,
src: gst_app::AppSrc,
}
impl MonitorWindow {
pub fn new(id: u32, el: &EventLoop<()>) -> anyhow::Result<Self> {
gst::init()?;
let window = el.create_window(
WindowAttributes::default()
.with_title(format!("Lesavkamonitor{id}"))
.with_decorations(false)
)?;
// appsrc -> decode -> convert -> waylandsink
let desc = "appsrc name=src is-live=true format=time do-timestamp=true ! \
queue ! h264parse ! avdec_h264 ! videoconvert ! \
waylandsink name=sink sync=false";
let pipeline = gst::parse::launch(desc)?
.downcast::<gst::Pipeline>()
.unwrap();
let src = pipeline
.by_name("src").unwrap()
.downcast::<gst_app::AppSrc>().unwrap();
src.set_latency(gst::ClockTime::NONE, gst::ClockTime::NONE);
pipeline.set_state(gst::State::Playing)?;
Ok(Self { id, _window: window, src })
}
pub fn push_packet(&self, pkt: VideoPacket) {
let mut buf = gst::Buffer::from_slice(pkt.data);
buf.get_mut().unwrap()
.set_pts(Some(gst::ClockTime::from_useconds(pkt.pts)));
let _ = self.src.push_buffer(buf);
}
}