-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main/snapshot: add missing runtime dep, fix a crash
- Loading branch information
1 parent
94e01bc
commit f9cbbd7
Showing
2 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
Patch-Source: https://gitlab.gnome.org/GNOME/snapshot/-/merge_requests/316 | ||
-- | ||
From 2cf4643b0abc1a238f8f38c3eb8250a347ccb10d Mon Sep 17 00:00:00 2001 | ||
From: "Jan Alexander Steffens (heftig)" <[email protected]> | ||
Date: Sat, 21 Sep 2024 09:38:23 +0200 | ||
Subject: [PATCH] aperture: Only get devices from the pipewiredeviceprovider | ||
|
||
`create_element`'s parameter is for giving the produced element a name. | ||
It does not select the element type. | ||
|
||
Remove the `DeviceMonitor` as it can load and start other providers that | ||
might give us incompatible cameras while the pipewire provider is still | ||
busy figuring out whether it should hide these other providers. | ||
|
||
Using a device monitor inside a device provider (which itself implicitly | ||
feeds into the monitor) also introduces recursion, which is probably | ||
unwise. | ||
|
||
Do the filtering the monitor did for us ourselves. | ||
|
||
Fixes: e60bdb67e7d9bad8016741ba40d6a560e2478653 | ||
Fixes: https://gitlab.gnome.org/GNOME/snapshot/-/issues/232 | ||
--- | ||
aperture/src/camera.rs | 2 +- | ||
aperture/src/device_provider.rs | 22 +++++++++++++--------- | ||
2 files changed, 14 insertions(+), 10 deletions(-) | ||
|
||
diff --git a/aperture/src/camera.rs b/aperture/src/camera.rs | ||
index 3ce7fb67..a5119c71 100644 | ||
--- a/aperture/src/camera.rs | ||
+++ b/aperture/src/camera.rs | ||
@@ -145,7 +145,7 @@ impl Camera { | ||
} | ||
|
||
pub(crate) fn create_element(&self) -> Result<gst::Element, glib::BoolError> { | ||
- let element = self.device().create_element(Some("pipewiresrc"))?; | ||
+ let element = self.device().create_element(None)?; | ||
element.set_property("client-name", crate::APP_ID.get().unwrap()); | ||
Ok(element) | ||
} | ||
diff --git a/aperture/src/device_provider.rs b/aperture/src/device_provider.rs | ||
index 82d5c762..f97e608e 100644 | ||
--- a/aperture/src/device_provider.rs | ||
+++ b/aperture/src/device_provider.rs | ||
@@ -28,7 +28,6 @@ mod imp { | ||
#[properties(wrapper_type = super::DeviceProvider)] | ||
pub struct DeviceProvider { | ||
pub inner: OnceCell<gst::DeviceProvider>, | ||
- pub monitor: OnceCell<gst::DeviceMonitor>, | ||
pub cameras: RefCell<Vec<crate::Camera>>, | ||
pub bus_watch: OnceCell<gst::bus::BusWatchGuard>, | ||
|
||
@@ -108,10 +107,6 @@ mod imp { | ||
|
||
crate::ensure_init(); | ||
|
||
- let monitor = gst::DeviceMonitor::new(); | ||
- monitor.add_filter(Some("Video/Source"), Some(&crate::SUPPORTED_CAPS)); | ||
- self.monitor.set(monitor).unwrap(); | ||
- | ||
if let Some(provider) = gst::DeviceProviderFactory::by_name("pipewiredeviceprovider") { | ||
self.inner.set(provider).unwrap(); | ||
} | ||
@@ -215,12 +210,11 @@ impl DeviceProvider { | ||
}; | ||
provider.start()?; | ||
|
||
- let monitor = imp.monitor.get().unwrap(); | ||
- | ||
let mut seen = HashSet::new(); | ||
- let mut cameras = monitor | ||
+ let mut cameras = provider | ||
.devices() | ||
.iter() | ||
+ .filter(|d| is_camera(d)) | ||
.map(crate::Camera::new) | ||
.filter(|d| !is_ir_camera(d)) | ||
.collect::<Vec<_>>(); | ||
@@ -238,7 +232,7 @@ impl DeviceProvider { | ||
self.imp().cameras.replace(cameras); | ||
self.items_changed(0, 0, n_items); | ||
|
||
- let bus = monitor.bus(); | ||
+ let bus = provider.bus(); | ||
let watch = bus | ||
.add_watch_local(glib::clone!( | ||
#[weak(rename_to = obj)] | ||
@@ -359,6 +353,9 @@ impl DeviceProvider { | ||
.structure() | ||
.and_then(|s| s.get::<gst::Device>("device").ok()) | ||
{ | ||
+ if !is_camera(&device) { | ||
+ return; | ||
+ } | ||
let device = crate::Camera::new(&device); | ||
if !imp.has_camera(&device) { | ||
// We ignore/filter IR cameras. | ||
@@ -405,6 +402,13 @@ impl DeviceProvider { | ||
} | ||
} | ||
|
||
+fn is_camera(device: &gst::Device) -> bool { | ||
+ device.has_classes("Video/Source") | ||
+ && device | ||
+ .caps() | ||
+ .is_some_and(|c| c.can_intersect(&crate::SUPPORTED_CAPS)) | ||
+} | ||
+ | ||
fn is_ir_camera(device: &crate::Camera) -> bool { | ||
device | ||
.device() | ||
-- | ||
GitLab | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters