From 3e9d442a0cb6d5dfd0178762e276cc357436ed60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 30 Nov 2026 05:43:00 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20shares=20hold=20up=20on?= =?UTF-8?q?=20bad=20networks.=20A=20slow=20or=20bloated=20link=20used=20to?= =?UTF-8?q?=20queue=20seconds=20of=20stale=20video=20(0.9=20s=20median,=20?= =?UTF-8?q?1.5=20s=20p90,=20~20=20s=20of=20freezes=20per=2040=20s=20on=20a?= =?UTF-8?q?=203=20Mbit=20bufferbloated=20link).=20Now:=20-=20relay=20and?= =?UTF-8?q?=20sender=20lane=20share=20one=20Link=20gate=20(common::datagra?= =?UTF-8?q?m):=20when=20a=20path's=20RTT=20rises=20150=20ms=20over=20its?= =?UTF-8?q?=20floor=20or=20quinn's=20datagram=20queue=20holds=20over=20250?= =?UTF-8?q?=20ms,=20stop=20sending=20video=20until=20it=20drains=20(2=20s?= =?UTF-8?q?=20cap),=20then=20resume=20on=20a=20fresh=20keyframe=20-=20watc?= =?UTF-8?q?her=20measures=20queuing=20from=20raw=20transit=20against=20a?= =?UTF-8?q?=2030=20s=20floor=20(was=20offset-relative=20over=20240=20frame?= =?UTF-8?q?s,=20which=20absorbed=20standing=20queues=20and=20misfired=20wh?= =?UTF-8?q?en=20the=20clock=20offset=20moved)=20-=20on=20congestion=20the?= =?UTF-8?q?=20watcher=20jumps=20straight=20to=20the=20rung=20that=20fits?= =?UTF-8?q?=2080%=20of=20peak=20goodput;=20random=20loss=20is=20ignored=20?= =?UTF-8?q?unless=20the=203=20s=20mean=20stays=20over=205%=20(shallow-buff?= =?UTF-8?q?er=20congestion)=20-=20failed=20up-probes=20double=20the=20wait?= =?UTF-8?q?=20before=20the=20next=20probe=20(10=20s=20up=20to=2060=20s);?= =?UTF-8?q?=20the=20watcher=20waits=20for=20a=20switch=20to=20land=20inste?= =?UTF-8?q?ad=20of=20a=20fixed=20hold=20-=20playout=20delay=20falls=20prop?= =?UTF-8?q?ortionally=20after=20a=20spike=20instead=20of=201=20ms=20per=20?= =?UTF-8?q?4=20frames=20(was=20~40=20s=20to=20recover)=20netem=20matrix=20?= =?UTF-8?q?(40=20s=20impairment,=202=20runs=20each,=20base=20vs=20fix,=20p?= =?UTF-8?q?50=20latency=20/=20frozen=20s):=20bloat=20868/19=20->=2094/3,?= =?UTF-8?q?=20shallow=20284/20=20->=2067/9,=20800=20kbit=20collapse=20921/?= =?UTF-8?q?36=20->=20354/22,=20jitter+loss=20411/28=20->=20178/9,=204=20Mb?= =?UTF-8?q?it=20uplink=20p90=20949=20->=20149,=20flapping=20722/29=20->=20?= =?UTF-8?q?180/20;=20clean=20calls=20unchanged.=20Also:=20rustfmt,=20two?= =?UTF-8?q?=20new=20clippy=20lints?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/client/src/gui/community_settings.rs | 25 ++-- crates/client/src/gui/jump.rs | 20 ++- crates/client/src/gui/settings_page.rs | 30 ++-- crates/client/src/lib.rs | 2 +- crates/client/src/share/session.rs | 145 +++++++++++++++++--- crates/client/src/tray.rs | 6 +- crates/common/src/datagram.rs | 66 ++++++++- crates/common/src/transport.rs | 2 +- crates/server/src/rooms.rs | 35 ++++- 9 files changed, 264 insertions(+), 67 deletions(-) diff --git a/crates/client/src/gui/community_settings.rs b/crates/client/src/gui/community_settings.rs index d29bbce..22595a9 100644 --- a/crates/client/src/gui/community_settings.rs +++ b/crates/client/src/gui/community_settings.rs @@ -187,17 +187,20 @@ impl Yumush { )); } if permission::can_delete_community(actor) { - sections.push(danger("danger_zone", vec![ - delete_control( - "delete_community_button", - w().community_settings.delete_community, - self.armed(Armed::DeleteCommunity), - entity, - palette, - Yumush::delete_community, - ) - .into_any_element(), - ])); + sections.push(danger( + "danger_zone", + vec![ + delete_control( + "delete_community_button", + w().community_settings.delete_community, + self.armed(Armed::DeleteCommunity), + entity, + palette, + Yumush::delete_community, + ) + .into_any_element(), + ], + )); } if sections.is_empty() { sections.push(section( diff --git a/crates/client/src/gui/jump.rs b/crates/client/src/gui/jump.rs index 4099a19..8b52724 100644 --- a/crates/client/src/gui/jump.rs +++ b/crates/client/src/gui/jump.rs @@ -180,18 +180,14 @@ impl Yumush { ), ] .into_iter() - .chain( - SettingsSection::ALL - .into_iter() - .map(|section| { - Row::new( - Place::Settings(section), - section.label().to_string(), - Glyph::Icon(IconName::Settings2), - ) - .hinted(w().jump.hint_settings) - }), - ) + .chain(SettingsSection::ALL.into_iter().map(|section| { + Row::new( + Place::Settings(section), + section.label().to_string(), + Glyph::Icon(IconName::Settings2), + ) + .hinted(w().jump.hint_settings) + })) .chain( setting_rows() .into_iter() diff --git a/crates/client/src/gui/settings_page.rs b/crates/client/src/gui/settings_page.rs index 43737ed..f4046b0 100644 --- a/crates/client/src/gui/settings_page.rs +++ b/crates/client/src/gui/settings_page.rs @@ -277,17 +277,20 @@ impl Yumush { appearance, )); if self.user.is_some() { - sections.push(danger(SettingsSection::DangerZone.id(), vec![ - delete_control( - "delete_account_button", - w().settings_page.delete_account, - self.armed(Armed::DeleteAccount), - entity, - palette, - Yumush::delete_account, - ) - .into_any_element(), - ])); + sections.push(danger( + SettingsSection::DangerZone.id(), + vec![ + delete_control( + "delete_account_button", + w().settings_page.delete_account, + self.armed(Armed::DeleteAccount), + entity, + palette, + Yumush::delete_account, + ) + .into_any_element(), + ], + )); } page( @@ -678,7 +681,10 @@ pub(super) fn page( .into_any_element() }) .collect(); - let Some(Section { title: name, body, .. }) = sections.into_iter().nth(selected) else { + let Some(Section { + title: name, body, .. + }) = sections.into_iter().nth(selected) + else { return frame(id, entity, palette, title, index, Vec::new(), Vec::new()); }; diff --git a/crates/client/src/lib.rs b/crates/client/src/lib.rs index e4437e8..db3c68d 100644 --- a/crates/client/src/lib.rs +++ b/crates/client/src/lib.rs @@ -109,7 +109,7 @@ impl Server { pub fn save(&self) { let flag = if self.any_cert { "any_cert" } else { "verify" }; - write_config("server", &format!("{}\n{flag}\n", self.address)); + write_config("server", format!("{}\n{flag}\n", self.address)); } pub fn host(&self) -> &str { diff --git a/crates/client/src/share/session.rs b/crates/client/src/share/session.rs index e08e027..02d80bc 100644 --- a/crates/client/src/share/session.rs +++ b/crates/client/src/share/session.rs @@ -15,7 +15,9 @@ use common::{ SHARE_AUDIO_BITRATE, SHARE_AUDIO_CHANNELS, VOICE_FRAME_SAMPLES, VOICE_MAX_PAYLOAD, VOICE_SAMPLE_RATE, }, - datagram::{self, FrameInfo, Packet, RELAY_PREFIX, fragments, split, warn_if_small}, + datagram::{ + self, FrameInfo, Gate, Link, Packet, RELAY_PREFIX, fragments, split, warn_if_small, + }, model::Id, share::{Codec, Fps, Kind, Layer, Mode, Quality, Resolution, Source, clamp}, }; @@ -72,11 +74,18 @@ const LOSS_LIMIT: f32 = 0.05; const CLEAN_LOSS: f32 = 0.01; const KEYFRAME_INTERVAL: Duration = Duration::from_secs(1); const CLEAN_SECONDS: u32 = 10; +const MAX_PATIENCE: u32 = 60; +const PROBE_SECONDS: u32 = 10; +const LOSS_TICKS: usize = 3; +const FIT: f32 = 0.8; +const GOODPUT_TICKS: usize = 3; +const DELAY_CATCH_UP: i64 = 32; const HOLD_SECONDS: u32 = 3; const MIN_SHOWN_WIDTH: u32 = 320; const QUEUING_LIMIT_MS: i64 = 60; const QUEUING_CLEAN_MS: i64 = 20; const QUEUING_WINDOW_MS: i64 = 1000; +const QUEUING_FLOOR_SECONDS: i64 = 30; const CHUNK_SAMPLES: usize = VOICE_FRAME_SAMPLES * SHARE_AUDIO_CHANNELS; const DECODE_SAMPLES: usize = VOICE_SAMPLE_RATE as usize * 120 / 1000 * SHARE_AUDIO_CHANNELS; const AUDIO_RING: usize = VOICE_SAMPLE_RATE as usize * SHARE_AUDIO_CHANNELS / 2; @@ -463,10 +472,10 @@ fn send( let lane = lanes.entry(item.layer).or_insert_with(|| { let (tx, rx) = mpsc::channel(); let bitrate = lock(&encoders).layer_bitrate(item.layer); - let (connection, loss) = (connection.clone(), loss.clone()); + let (connection, loss, encoders) = (connection.clone(), loss.clone(), encoders.clone()); let _ = std::thread::Builder::new() .name("share-send".to_string()) - .spawn(move || send_layer(kind, rx, &connection, &loss, bitrate, seed)); + .spawn(move || send_layer(kind, rx, &connection, &encoders, &loss, bitrate, seed)); tx }); let _ = lane.send(item); @@ -477,13 +486,30 @@ fn send_layer( kind: Kind, rx: Receiver, connection: &Connection, + encoders: &Mutex, loss: &Loss, bitrate: u32, seed: u32, ) { let mut pacer = Pacer::default(); let mut number = seed; + let mut link = Link::default(); + let mut stalled = false; for item in rx { + let gate = link.gate(connection, item.keyframe); + match gate { + Gate::Send => stalled &= !item.keyframe, + Gate::Pause => { + tracing::info!(?kind, "uplink congested, pausing until it drains"); + stalled = true; + } + Gate::Drop => {} + Gate::Resume => lock(encoders).keyframe(item.layer, false), + } + if stalled || gate != Gate::Send { + number = number.wrapping_add(1); + continue; + } let info = FrameInfo { kind, layer: item.layer, @@ -578,6 +604,8 @@ impl Clock { #[derive(Default)] struct Playout { lateness: VecDeque<(i64, i64)>, + transit: VecDeque<(i64, i64)>, + floors: VecDeque<(i64, i64)>, frames: u32, epoch: u32, } @@ -588,9 +616,12 @@ impl Playout { if epoch != self.epoch { self.epoch = epoch; self.lateness.clear(); + self.transit.clear(); + self.floors.clear(); } let now = clock.now(); let current = clock.delay.load(Ordering::Relaxed); + self.track(now, now - i64::from(sharer_ms)); let next = self.settle(now, now - clock.origin(sharer_ms), current); clock.delay.store(next, Ordering::Relaxed); clock @@ -618,6 +649,8 @@ impl Playout { target } else if target > current { current + 1 + } else if target < current - DELAY_CATCH_UP { + current - (current - target) / DELAY_CATCH_UP } else if target < current && self.frames.is_multiple_of(DELAY_FALL_EVERY) { current - 1 } else { @@ -626,21 +659,38 @@ impl Playout { next.clamp(MIN_DELAY_MS, MAX_DELAY_MS) } + fn track(&mut self, now: i64, transit: i64) { + self.transit.push_back((now, transit)); + while self + .transit + .front() + .is_some_and(|(at, _)| now - at >= QUEUING_WINDOW_MS) + { + self.transit.pop_front(); + } + match self.floors.back_mut() { + Some((second, floor)) if *second == now / 1000 => *floor = (*floor).min(transit), + _ => self.floors.push_back((now / 1000, transit)), + } + while self + .floors + .front() + .is_some_and(|(second, _)| now / 1000 - second >= QUEUING_FLOOR_SECONDS) + { + self.floors.pop_front(); + } + } + fn queuing(&self) -> i64 { - let Some(&(newest, _)) = self.lateness.back() else { - return 0; - }; let floor = self - .lateness + .floors .iter() - .map(|(_, late)| *late) + .map(|(_, floor)| *floor) .min() .unwrap_or(0); - self.lateness + self.transit .iter() - .rev() - .take_while(|(at, _)| newest - at < QUEUING_WINDOW_MS) - .map(|(_, late)| *late) + .map(|(_, transit)| *transit) .min() .map_or(0, |best| best - floor) } @@ -694,7 +744,11 @@ pub struct Watching { audio_tx: Option>, meter: Meter, received: AtomicU64, + goodput: AtomicU64, + goodputs: VecDeque, + kind: Kind, since: Instant, + ticked: Instant, _video: Worker, _audio: Option, _output: Option