mirror of
https://github.com/VallierDev/uu-remote-linux.git
synced 2026-11-16 16:50:41 +01:00
WebRTC: restart a promoted desktop's video after its stream ended (#114)
A tool peer promoted by capture_desktop stayed marked as the desktop after its encoder exited on its own (Wayland capture failing while locked/DPMS off), so a later capture_desktop on the same peer only logged and never restarted the video. Treat a finished stream task as ended: capture_desktop asks for the desktop again and promote() restarts the video on the existing input lease. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
ab5d0a656b
commit
cfe9601874
2 files changed
+30
-11
No files matched your search
@@ -244,6 +244,15 @@ async fn capture_desktop_on_a_port_mapping_peer_promotes_it_once() {
|
||||
let lease = host.role.input().unwrap();
|
||||
host.promote(None);
|
||||
assert!(lease.is_current());
|
||||
// Its video ended on its own (capture failed while locked, #114): capture_desktop restarts it
|
||||
// on the same input lease.
|
||||
let ended = tokio::spawn(async {});
|
||||
*host.role.stream_task.lock().unwrap() = Some(ended.abort_handle());
|
||||
ended.await.unwrap();
|
||||
send(&viewer, "CONTROL_DATA_CHANNEL", crate::initialization::envelope(9, 0, 3, &[8, 4])).await;
|
||||
tokio::time::timeout(Duration::from_secs(5), requested.recv()).await.unwrap().unwrap();
|
||||
host.promote(None);
|
||||
assert!(host.role.is_desktop() && !host.role.stream_ended() && lease.is_current());
|
||||
// A newer desktop demotes it; the port mapping stays, and capture_desktop promotes it again.
|
||||
host.demote();
|
||||
assert!(!host.role.is_desktop() && host.role.input().is_none());
|
||||
|
||||
+21
-11
@@ -64,6 +64,9 @@ impl DesktopRole {
|
||||
stream: Default::default(), stream_task: Default::default(), screen: Default::default(), tracking: Default::default(), request: Default::default() }
|
||||
}
|
||||
pub fn is_desktop(&self) -> bool { *self.active.borrow() }
|
||||
/// A promoted peer whose video ended on its own (capture failed while locked or off, #114);
|
||||
/// capture_desktop on it starts the video again.
|
||||
fn stream_ended(&self) -> bool { self.stream_task.lock().unwrap().as_ref().is_some_and(|task| task.is_finished()) }
|
||||
fn input(&self) -> Option<Arc<crate::input::DesktopInputSession>> { self.input.lock().unwrap().clone() }
|
||||
fn screen_or(&self, screen: &Arc<ScreenCapture>) -> Arc<ScreenCapture> {
|
||||
self.screen.lock().unwrap().clone().unwrap_or_else(|| screen.clone())
|
||||
@@ -1316,10 +1319,14 @@ impl WebRtcSession {
|
||||
}
|
||||
});
|
||||
} else if action == sa::CAPTURE_DESKTOP && channel_name == "CONTROL_DATA_CHANNEL" {
|
||||
if message_role.is_desktop() {
|
||||
if message_role.is_desktop() && !message_role.stream_ended() {
|
||||
log::info!("SimpleAction 4 (capture_desktop) received on a desktop connection");
|
||||
} else if let Some(request) = message_role.request.get() {
|
||||
log::info!("SimpleAction 4 (capture_desktop) received on a tool connection; starting the desktop");
|
||||
if message_role.is_desktop() {
|
||||
log::info!("SimpleAction 4 (capture_desktop) received on a tool connection whose desktop video ended; restarting it");
|
||||
} else {
|
||||
log::info!("SimpleAction 4 (capture_desktop) received on a tool connection; starting the desktop");
|
||||
}
|
||||
request();
|
||||
} else {
|
||||
log::info!("SimpleAction 4 (capture_desktop) not handled: tool connection without a desktop route");
|
||||
@@ -1461,18 +1468,21 @@ impl WebRtcSession {
|
||||
/// Makes this tool peer the desktop: it takes the input lease, starts the video it negotiated
|
||||
/// (H.264; audio was never negotiated) and repeats the desktop CONTROL initialization.
|
||||
/// `screen` replaces a capture that was unavailable when the peer was offered.
|
||||
/// A promoted peer whose video ended keeps its input lease and only restarts the video.
|
||||
pub fn promote(&self, screen: Option<Arc<ScreenCapture>>) {
|
||||
if self.role.is_desktop() { return; }
|
||||
let restart = self.role.is_desktop();
|
||||
if restart && !self.role.stream_ended() { return; }
|
||||
if let Some(screen) = screen { *self.role.screen.lock().unwrap() = Some(screen); }
|
||||
let session = self.input.desktop_session();
|
||||
if self.pc.connection_state() == RTCPeerConnectionState::Connected { session.connected(); }
|
||||
*self.role.input.lock().unwrap() = Some(session);
|
||||
self.role.active.send_replace(true);
|
||||
let stream = self.role.stream.lock().unwrap().clone();
|
||||
if let Some(stream) = stream {
|
||||
let task = stream.spawn(self.role.screen.lock().unwrap().clone(), self.role.active.subscribe());
|
||||
if let Some(old) = std::mem::replace(&mut *self.role.stream_task.lock().unwrap(), task) { old.abort(); }
|
||||
if !restart {
|
||||
let session = self.input.desktop_session();
|
||||
if self.pc.connection_state() == RTCPeerConnectionState::Connected { session.connected(); }
|
||||
*self.role.input.lock().unwrap() = Some(session);
|
||||
self.role.active.send_replace(true);
|
||||
}
|
||||
let stream = self.role.stream.lock().unwrap().clone();
|
||||
let task = stream.and_then(|stream| stream.spawn(self.role.screen.lock().unwrap().clone(), self.role.active.subscribe()));
|
||||
if let Some(old) = std::mem::replace(&mut *self.role.stream_task.lock().unwrap(), task) { old.abort(); }
|
||||
if restart { log::info!("Desktop video restarted on a tool connection after its stream ended"); return; }
|
||||
if !cfg!(test) { track_session(self.pc.clone(), self.actions.clone(), &self.role); }
|
||||
log::info!("Desktop started on an existing tool connection");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user