Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.
Sessions: send the control stream ahead of video
Bee15ac86dab4ad
diff --git a/core/nectarlink-core/src/mirror.rs b/core/nectarlink-core/src/mirror.rsindex 4aedd04..f4d2ad7 100644--- a/core/nectarlink-core/src/mirror.rs+++ b/core/nectarlink-core/src/mirror.rs@@ -590,6 +590,11 @@ pub(crate) async fn open(shared: &Arc<Shared>, session: &Session, audio: bool) -Ok(MirrorStream::spawn_stream(send, recv, audio, on_end))}+/// Send priorities: sound before video, as a gap in it is the more+/// noticeable; both after the control stream (`session::CONTROL_PRIORITY`).+pub(crate) const VIDEO_PRIORITY: i32 = 1;+pub(crate) const AUDIO_PRIORITY: i32 = 2;+impl MirrorStream {pub(crate) fn spawn_stream(mut send: SendStream,@@ -597,9 +602,8 @@ impl MirrorStream {audio: bool,on_end: Option<(Arc<Shared>, i64, std::time::Instant)>,) -> MirrorStream {- // Sound and video go out as soon as they're written; sound first, as a- // gap in it is the more noticeable.- let _ = send.set_priority(if audio { 2 } else { 1 });+ // Sound and video go out as soon as they're written; sound first.+ let _ = send.set_priority(if audio { AUDIO_PRIORITY } else { VIDEO_PRIORITY });let (queue, mut packets) =mpsc::channel::<(PacketKind, u64, Vec<u8>)>(if audio { AUDIO_QUEUE } else { QUEUE });let closed = Arc::new(AtomicBool::new(false));diff --git a/core/nectarlink-core/src/session.rs b/core/nectarlink-core/src/session.rsindex a9e8a7a..33b368c 100644--- a/core/nectarlink-core/src/session.rs+++ b/core/nectarlink-core/src/session.rs@@ -336,7 +336,16 @@ impl Session {}}+/// The control stream goes out before media streams ([`crate::mirror`]):+/// with a few app windows filling the link, heartbeats queued behind video+/// timed out and closed a live session.+const CONTROL_PRIORITY: i32 = 8;+const _: () = assert!(+ CONTROL_PRIORITY > crate::mirror::AUDIO_PRIORITY && CONTROL_PRIORITY > crate::mirror::VIDEO_PRIORITY+);+async fn writer(mut send: SendStream, mut outbox: mpsc::Receiver<Envelope>) {+ let _ = send.set_priority(CONTROL_PRIORITY);while let Some(env) = outbox.recv().await {if let Err(e) = write_frame(&mut send, &env.to_cbor()).await {tracing::debug!(error = %e, "control stream write failed");