feat: add boolean property for diff-only mode
This commit is contained in:
parent
4a332db17e
commit
52dbf859ee
|
@ -1,4 +1,4 @@
|
|||
use gstreamer::glib::{self, ParamSpec, ParamSpecString, Value};
|
||||
use gstreamer::glib::{self, ParamSpec, ParamSpecBoolean, ParamSpecString, Value};
|
||||
use gstreamer::prelude::*;
|
||||
use gstreamer::subclass::prelude::*;
|
||||
use gstreamer::subclass::ElementMetadata;
|
||||
|
@ -7,7 +7,6 @@ use gstreamer::{
|
|||
FlowSuccess, LoggableError, PadDirection, PadPresence, PadTemplate, ResourceError,
|
||||
};
|
||||
|
||||
use gstreamer_base::prelude::*;
|
||||
use gstreamer_base::subclass::prelude::*;
|
||||
|
||||
use gstreamer_video::prelude::*;
|
||||
|
@ -34,6 +33,7 @@ static CAT: LazyLock<DebugCategory> = LazyLock::new(|| {
|
|||
#[derive(Default)]
|
||||
struct Settings {
|
||||
bind_address: Option<SocketAddr>,
|
||||
diff_only: bool,
|
||||
prefix: Option<Ipv6Addr>,
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,10 @@ impl ObjectImpl for PingxelflutSink {
|
|||
.nick("Bind address")
|
||||
.blurb("Local address to bind to")
|
||||
.build(),
|
||||
ParamSpecBoolean::builder("diff-only")
|
||||
.nick("Diff only")
|
||||
.blurb("Only send pixels different from previous frame")
|
||||
.build(),
|
||||
ParamSpecString::builder("prefix")
|
||||
.nick("Destination prefix")
|
||||
.blurb("Prefix of pingxelflut server")
|
||||
|
@ -92,6 +96,9 @@ impl ObjectImpl for PingxelflutSink {
|
|||
.map(|s| s.parse().ok())
|
||||
.unwrap_or(None);
|
||||
}
|
||||
"diff-only" => {
|
||||
settings.diff_only = value.get::<bool>().unwrap();
|
||||
}
|
||||
"prefix" => {
|
||||
settings.prefix = value
|
||||
.get::<Option<String>>()
|
||||
|
@ -112,6 +119,7 @@ impl ObjectImpl for PingxelflutSink {
|
|||
.as_ref()
|
||||
.map(|addr| addr.to_string())
|
||||
.to_value(),
|
||||
"diff-only" => settings.diff_only.to_value(),
|
||||
"prefix" => settings
|
||||
.prefix
|
||||
.as_ref()
|
||||
|
@ -244,11 +252,13 @@ impl VideoSinkImpl for PingxelflutSink {
|
|||
(y * frame.plane_stride()[0] as u32 + 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 prev_frame.as_ref().map_or(false, |f| {
|
||||
if settings.diff_only
|
||||
&& prev_frame.as_ref().map_or(false, |f| {
|
||||
f.plane_data(0).is_ok_and(|d| {
|
||||
d[i] as u16 == r && d[i + 1] as u16 == g && d[i + 2] as u16 == b
|
||||
})
|
||||
}) {
|
||||
})
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue