mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-17 09:10:41 +01:00
X11: change the desktop resolution for the viewer's choice; survive live resizes (#86)
* Restart X11 capture at the new size when the desktop is resized mid-stream
A RandR resize during a session made x11grab fail with BadMatch on the old
size. read_encoder treated that as an encoder failure and walked the whole
fallback chain (NVENC -> CPU, HEVC -> H.264) with the stale size, then the
stream stopped ("Encoder output ended") and the viewer froze. New connections
already re-probed the geometry (#18); live ones did not.
- When an X11 stream fails and the root size differs, skip the encoder
fallback and restart capture at the new size with the same settings.
- Absolute pointer mapping follows the refreshed X11 size.
- New connections compare the root size with their capture instead of the
engine's change flag, which a live stream may already have consumed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
* Change the X11 desktop resolution when the viewer picks one
The official Windows host changes its display resolution for the viewer's
分辨率 choice; this host only scaled the encoded stream, so a smaller choice
made text smaller and blurrier instead of larger.
On X11 the capture/resolution RPC now switches the primary output's mode with
xrandr (an existing mode of that size, else a CVT reduced-blanking mode at
60 Hz, or 30 Hz above an HDMI 2.0 pixel clock), re-applying it when mutter
resets the mode after the list changes. resolution_type 3 (original) and the
end of the last desktop stream restore the mode in use before the first
change. The stream restarts capture at the new native size and reports it in
the screen sources and CaptureSettingSync. UU_DESKTOP_RESIZE=0 keeps the old
encoder scaling; Wayland is unchanged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---------
Co-authored-by: VallierDev <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
9 files changed
+297
-12
No files matched your search
+20
-3
@@ -510,14 +510,14 @@ async fn read_encoder(
|
||||
// A failed native NVENC session (old driver, unsupported mode) still leaves FFmpeg's NVENC process pipeline.
|
||||
#[cfg(feature = "inproc-av")]
|
||||
if let Err(error) = &result {
|
||||
if !latest.is_closed() && native_inproc(&display, portal.is_some(), encoder) {
|
||||
if !latest.is_closed() && native_inproc(&display, portal.is_some(), encoder) && x11_resized(&display, portal.is_some(), size).is_none() {
|
||||
log::warn!("In-process {} stream unavailable; switching to the FFmpeg process pipeline: {}",encoder.name_for(settings.codec),error);
|
||||
result = read_encoder_with(size,display.clone(),portal.clone(),latest.clone(),encoder,false,sequence.clone(),settings,idr.clone(),budget.clone()).await;
|
||||
}
|
||||
}
|
||||
match result {
|
||||
Ok(())=>Ok(()),
|
||||
Err(error) if !latest.is_closed()=>{
|
||||
Err(error) if !latest.is_closed() && x11_resized(&display, portal.is_some(), size).is_none()=>{
|
||||
log::warn!("{} stream unavailable; switching scoped encoder to CPU: {}",encoder.name_for(settings.codec),error);
|
||||
read_encoder_with(size,display,portal,latest,Encoder::Cpu,true,sequence,settings,idr,budget).await
|
||||
},
|
||||
@@ -525,6 +525,13 @@ async fn read_encoder(
|
||||
}
|
||||
}
|
||||
|
||||
/// A resized X11 root fails every encoder alike (x11grab BadMatch on the old size);
|
||||
/// returns the new size so the stream restarts capture instead of walking the fallback chain.
|
||||
fn x11_resized(display: &str, portal: bool, size: (u32, u32)) -> Option<(u32, u32)> {
|
||||
if portal || display.starts_with("wayland:") || display.starts_with("kms:") { return None; }
|
||||
crate::capture::x11_size().filter(|current| *current != size)
|
||||
}
|
||||
|
||||
/// The native in-process NVENC path serves X11 only (not Wayland/KMS capture or a portal session).
|
||||
#[cfg(feature = "inproc-av")]
|
||||
fn native_inproc(display: &str, portal: bool, encoder: Encoder) -> bool {
|
||||
@@ -915,8 +922,9 @@ pub async fn probe(size:(u32,u32),display:String,portal:Option<Arc<crate::portal
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_track::VideoTrack>, size: (u32, u32), display: String, portal:Option<Arc<crate::portal::PortalSession>>,
|
||||
pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_track::VideoTrack>, mut size: (u32, u32), display: String, portal:Option<Arc<crate::portal::PortalSession>>,
|
||||
mut settings: tokio::sync::watch::Receiver<VideoSettings>, applied: Arc<tokio::sync::watch::Sender<VideoSettings>>, idr: Arc<AtomicBool>) -> Result<(), String> {
|
||||
let _desktop_mode = crate::desktop_mode::StreamGuard::new();
|
||||
loop {
|
||||
if transport_closed(&pc) { return Ok(()); }
|
||||
if pc.connection_state() == RTCPeerConnectionState::Connected
|
||||
@@ -956,6 +964,8 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_
|
||||
let discard = next.codec != current.codec || next.source_generation != current.source_generation || next.source_id != current.source_id || send_interrupted;
|
||||
current = next;
|
||||
timeline.fps = u64::from(next.fps);
|
||||
// A viewer resolution choice may have changed the X11 display mode (desktop_mode).
|
||||
if let Some(resized) = x11_resized(&display, portal_stream, size) { size = resized; }
|
||||
if discard {
|
||||
reader.0.abort();
|
||||
let _ = (&mut reader.0).await;
|
||||
@@ -969,6 +979,13 @@ pub async fn stream_desktop(pc: Arc<RTCPeerConnection>, track: Arc<crate::video_
|
||||
tokio::select! {
|
||||
result = &mut reader.0 => {
|
||||
let result = result.map_err(|e| format!("Encoder reader task: {e}"))?;
|
||||
if let Some(resized) = result.as_ref().err().and_then(|_| x11_resized(&display, portal_stream, size)) {
|
||||
log::info!("Desktop geometry changed during the stream ({}x{} -> {}x{}); restarting capture", size.0, size.1, resized.0, resized.1);
|
||||
size = resized;
|
||||
while receiver.try_recv().is_ok() {}
|
||||
reader.0 = tokio::spawn(read_encoder(size, display.clone(), portal.clone(), latest.clone(), current, sequence.clone(), idr.clone(), budget.clone()));
|
||||
continue;
|
||||
}
|
||||
if let (Err(error), VideoCodec::H265, true) = (&result, current.codec, track.supports(VideoCodec::H264)) {
|
||||
log::warn!("HEVC stream failed ({error}); falling back to negotiated H264");
|
||||
applied.send_modify(|value| value.codec = VideoCodec::H264);
|
||||
|
||||
Reference in new issue
Block a user