Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/install-desktop-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ runs:
libasound2-dev \
libasound2-plugins \
pulseaudio-utils \
dbus-daemon \
libdbus-1-dev \
libudev-dev \
libx11-dev \
Expand Down
60 changes: 51 additions & 9 deletions crates/recording/src/sources/screen_capture/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ mod x11_tests;
#[cfg(test)]
mod system_audio_channel_tests;

#[cfg(test)]
mod wayland_portal_tests;

use frame_scaler::FrameScaler;

#[derive(Debug)]
Expand Down Expand Up @@ -103,8 +106,49 @@ struct WaylandInputConfig {
}

struct WaylandPortalSession {
_proxy: Screencast<'static>,
_session: Session<'static, Screencast<'static>>,
session: Arc<Session<'static, Screencast<'static>>>,
_close_on_drop: tokio::sync::oneshot::Sender<()>,
}

impl WaylandPortalSession {
fn new(session: Session<'static, Screencast<'static>>) -> Self {
let session = Arc::new(session);
let (close_on_drop, dropped) = tokio::sync::oneshot::channel::<()>();
let close = {
let session = session.clone();
async move {
let _ = dropped.await;
let result = tokio::time::timeout(Duration::from_secs(3), session.close())
.await
.context("Wayland screen capture portal session close timed out")?;
if let Err(ashpd::Error::Portal(ashpd::PortalError::ZBus(
ashpd::zbus::Error::MethodError(name, _, _),
))) = &result
&& matches!(
name.as_str(),
"org.freedesktop.DBus.Error.UnknownObject"
| "org.freedesktop.DBus.Error.UnknownMethod"
)
{
return Ok(());
}
result.context("close Wayland screen capture portal session")
}
};
if let Some(scope) = crate::output_pipeline::PipelineBuildScope::current() {
scope.spawn_cleanup(close);
} else {
drop(tokio::spawn(async move {
if let Err(error) = close.await {
tracing::warn!(%error, "Could not close the Wayland screen capture portal session");
}
}));
}
Self {
session,
_close_on_drop: close_on_drop,
}
}
}

pub struct VideoSource {
Expand Down Expand Up @@ -412,6 +456,7 @@ async fn open_wayland_portal(
.create_session()
.await
.context("create XDG Desktop Portal ScreenCast session")?;
let portal_session = WaylandPortalSession::new(session);
let cursor_mode = if show_cursor {
CursorMode::Embedded
} else {
Expand All @@ -420,7 +465,7 @@ async fn open_wayland_portal(

proxy
.select_sources(
&session,
&portal_session.session,
cursor_mode,
wayland_source_type(source),
false,
Expand All @@ -431,7 +476,7 @@ async fn open_wayland_portal(
.context("select Wayland screen capture source")?;

let response = proxy
.start(&session, None)
.start(&portal_session.session, None)
.await
.context("start Wayland screen capture portal request")?
.response()
Expand All @@ -442,17 +487,14 @@ async fn open_wayland_portal(
.cloned()
.ok_or_else(|| anyhow!("Wayland screen capture portal did not return a stream"))?;
let fd = proxy
.open_pipe_wire_remote(&session)
.open_pipe_wire_remote(&portal_session.session)
.await
.context("open PipeWire remote for Wayland screen capture")?;

Ok(WaylandPortalCapture {
stream,
fd,
portal_session: WaylandPortalSession {
_proxy: proxy,
_session: session,
},
portal_session,
})
}

Expand Down
Loading
Loading