Skip to content

Commit

Permalink
perf(area_selector): use gl when available
Browse files Browse the repository at this point in the history
Also set use-scaling-filter=true, allowing crisper downscaling with ScalingFilter::Linear by default
  • Loading branch information
SeaDve committed Feb 25, 2024
1 parent 79c6ab2 commit 784db3b
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 9 deletions.
80 changes: 80 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ gettext-rs = { version = "0.7.0", features = ["gettext-system"] }
gsettings-macro = "0.2"
gst = { package = "gstreamer", version = "0.22", features = ["v1_20"] }
gst-plugin-gif = "0.12"
gst-plugin-gtk4 = { version = "0.12", features = ["gtk_v4_14"] }
gst-plugin-gtk4 = { version = "0.12", features = [
"gtk_v4_14",
"wayland",
"x11egl",
"x11glx",
] }
gtk = { package = "gtk4", version = "0.8", features = ["v4_14"] }
num-rational = { version = "0.4", default-features = false }
num-traits = "0.2"
Expand Down
33 changes: 25 additions & 8 deletions src/area_selector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,33 @@ impl AreaSelector {

// Setup pipeline
let pipeline = gst::Pipeline::new();
let videosrc_bin = pipeline::make_pipewiresrc_bin(fd, streams, PREVIEW_FRAMERATE, None)?;
let videoconvert = gst::ElementFactory::make("videoconvert").build()?;
let sink = gst::ElementFactory::make("gtk4paintablesink").build()?;
pipeline.add_many([videosrc_bin.upcast_ref(), &videoconvert, &sink])?;
gst::Element::link_many([videosrc_bin.upcast_ref(), &videoconvert, &sink])?;
imp.pipeline.set(pipeline.clone()).unwrap();

// Setup paintable
let paintable = sink.property::<gdk::Paintable>("paintable");
imp.view_port.set_paintable(Some(paintable));
let videosrc_bin = pipeline::make_pipewiresrc_bin(fd, streams, PREVIEW_FRAMERATE, None)?;
let gtksink = gst::ElementFactory::make("gtk4paintablesink").build()?;

let paintable = gtksink.property::<gdk::Paintable>("paintable");
paintable.set_property("use-scaling-filter", true);
imp.view_port.set_paintable(Some(paintable.clone()));

if paintable
.property::<Option<gdk::GLContext>>("gl-context")
.is_some()
{
tracing::debug!("Using gl pipeline");

let glsinkbin = gst::ElementFactory::make("glsinkbin")
.property("sink", &gtksink)
.build()?;
pipeline.add_many([videosrc_bin.upcast_ref(), &glsinkbin])?;
videosrc_bin.link(&glsinkbin)?;
} else {
tracing::debug!("Falling back to non-gl pipeline");

let videoconvert = gst::ElementFactory::make("videoconvert").build()?;
pipeline.add_many([videosrc_bin.upcast_ref(), &videoconvert, &gtksink])?;
gst::Element::link_many([videosrc_bin.upcast_ref(), &videoconvert, &gtksink])?;
}

let (async_done_tx, async_done_rx) = oneshot::channel();
imp.async_done_tx.replace(Some(async_done_tx));
Expand Down

0 comments on commit 784db3b

Please sign in to comment.