feat: add properties to offset frame

This commit is contained in:
Luca 2025-03-02 00:31:45 +01:00
parent 52dbf859ee
commit 504ad3ae03
1 changed files with 24 additions and 5 deletions

View File

@ -1,4 +1,4 @@
use gstreamer::glib::{self, ParamSpec, ParamSpecBoolean, ParamSpecString, Value};
use gstreamer::glib::{self, ParamSpec, ParamSpecBoolean, ParamSpecString, ParamSpecUInt, Value};
use gstreamer::prelude::*;
use gstreamer::subclass::prelude::*;
use gstreamer::subclass::ElementMetadata;
@ -35,6 +35,8 @@ struct Settings {
bind_address: Option<SocketAddr>,
diff_only: bool,
prefix: Option<Ipv6Addr>,
x: u32,
y: u32,
}
#[derive(Default)]
@ -79,6 +81,14 @@ impl ObjectImpl for PingxelflutSink {
.nick("Destination prefix")
.blurb("Prefix of pingxelflut server")
.build(),
ParamSpecUInt::builder("x")
.nick("X offset")
.blurb("Offset along X axis")
.build(),
ParamSpecUInt::builder("y")
.nick("Y offset")
.blurb("Offset along Y axis")
.build(),
]
});
@ -106,6 +116,12 @@ impl ObjectImpl for PingxelflutSink {
.map(|s| s.parse().ok())
.unwrap_or(None);
}
"x" => {
settings.x = value.get::<u32>().unwrap();
}
"y" => {
settings.y = value.get::<u32>().unwrap();
}
_ => unimplemented!(),
}
}
@ -125,6 +141,8 @@ impl ObjectImpl for PingxelflutSink {
.as_ref()
.map(|addr| addr.to_string())
.to_value(),
"x" => settings.x.to_value(),
"y" => settings.y.to_value(),
_ => unimplemented!(),
}
}
@ -246,10 +264,11 @@ impl VideoSinkImpl for PingxelflutSink {
let prefix = settings.prefix.as_ref().unwrap();
if let State::Started { ref socket } = *self.state.lock().unwrap() {
for y in 0..cmp::min(frame.height(), HEIGHT) {
for x in 0..cmp::min(frame.width(), WIDTH) {
let i =
(y * frame.plane_stride()[0] as u32 + x * frame.n_components()) as usize;
for y in settings.y..cmp::min(settings.y + frame.height(), HEIGHT) {
for x in settings.x..cmp::min(settings.x + frame.width(), WIDTH) {
let i = ((y - settings.y) * frame.plane_stride()[0] as u32
+ (x - settings.x) * frame.n_components())
as usize;
let (r, g, b) = (data[i] as u16, data[i + 1] as u16, data[i + 2] as u16);
if settings.diff_only