Apply share settings live and fix share stats and settings
Browse files at this commit6cc4c4cb5523666883e1e9cadea52c7140d940aeParent: f550e1a- fix
- apply share settings live and fix share stats and settings
21 changed files +395 -129
- Cargo.toml +0 -3
- crates/client/Cargo.toml +16 -16
- crates/client/src/gui/share_view.rs +36 -16
- crates/client/src/gui/sidebar.rs +3 -1
- crates/client/src/gui/voice_stats.rs +28 -20
- crates/client/src/network.rs +71 -4
- crates/client/src/settings.rs +7 -0
- crates/client/src/share/audio.rs +1 -0
- crates/client/src/share/encode.rs +2 -7
- crates/client/src/share/session.rs +81 -34
- crates/server/src/request.rs +5 -4
- crates/server/src/share.rs +53 -2
- harness/audio.sh +33 -0
- harness/client.sh +1 -1
- harness/down.sh +1 -1
- harness/niri.kdl +3 -0
- harness/pipewire/pipewire.conf.d/harness.conf +8 -0
- harness/pipewire/wireplumber.conf.d/harness.conf +10 -0
- harness/session.sh +34 -18
- harness/shot.sh +1 -1
- harness/ui.sh +1 -1
Cargo.tomlmodified+0 -3
| @@ -32,6 +32,3 @@ quinn = { version = "0.11.12", default-features = false, features = [ | ||
| 32 | 32 | "runtime-tokio", |
| 33 | 33 | ] } |
| 34 | 34 | rustls = "0.23.45" |
| 35 | - | |
| 36 | -[patch."https://github.com/chromeos/cros-libva"] | |
| 37 | -cros-libva = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } |
crates/client/Cargo.tomlmodified+16 -16
| @@ -9,20 +9,20 @@ tokio.workspace = true | ||
| 9 | 9 | quinn = { workspace = true, features = ["rustls-ring", "platform-verifier"] } |
| 10 | 10 | |
| 11 | 11 | gpui-kit = { version = "0.11.0", features = ["syntect"] } |
| 12 | -ec-opus = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 13 | -ec-core = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 14 | -ec-probe = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 15 | -ec-mp4 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 16 | -ec-matroska = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 17 | -ec-ogg = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 18 | -ec-h264 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 19 | -ec-vp8 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 20 | -ec-aac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 21 | -ec-mp3 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 22 | -ec-vorbis = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 23 | -ec-flac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 24 | -ec-h265 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 25 | -ec-vp9 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 12 | +ec-opus = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 13 | +ec-core = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 14 | +ec-probe = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 15 | +ec-mp4 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 16 | +ec-matroska = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 17 | +ec-ogg = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 18 | +ec-h264 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 19 | +ec-vp8 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 20 | +ec-aac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 21 | +ec-mp3 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 22 | +ec-vorbis = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 23 | +ec-flac = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 24 | +ec-h265 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 25 | +ec-vp9 = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 26 | 26 | ureq = "3.5.2" |
| 27 | 27 | bytes = "1.12.2" |
| 28 | 28 | tracing = "0.1.44" |
| @@ -37,8 +37,8 @@ rtrb = "0.4.1" | ||
| 37 | 37 | pipewire = { version = "0.10.1", features = ["v0_3_49"] } |
| 38 | 38 | ksni = "0.3.7" |
| 39 | 39 | ashpd = { version = "0.14.3", default-features = false, features = ["tokio", "screencast"] } |
| 40 | -ec-hw = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 41 | -ec-va = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "19320a9deb61d27aaaedf2f18948184ca7838730" } | |
| 40 | +ec-hw = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 41 | +ec-va = { git = "https://git.tahinli.com/Tahinli/edith_codecs.git", rev = "24666c0482f23b366ea752d2eb988c41ea07657f" } | |
| 42 | 42 | |
| 43 | 43 | [target.'cfg(target_os = "windows")'.dependencies] |
| 44 | 44 | wasapi = "0.27.0" |
crates/client/src/gui/share_view.rsmodified+36 -16
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | use std::{sync::Arc, time::Duration}; |
| 2 | 2 | |
| 3 | -use common::share::{Codec, Fps, Quality, Resolution}; | |
| 3 | +use common::share::{Codec, Fps, Quality, Resolution, Source, options}; | |
| 4 | 4 | use gpui_kit::{ |
| 5 | 5 | Anchor, AnyElement, AppContext, Context, Div, Entity, FontWeight, InteractiveElement, |
| 6 | 6 | IntoElement, MouseButton, ObjectFit, ParentElement, RenderImage, Styled, StyledImage, |
| @@ -122,7 +122,15 @@ impl Yumush { | ||
| 122 | 122 | fn update_share(&mut self, cx: &mut Context<Self>, change: impl FnOnce(&mut ShareSettings)) { |
| 123 | 123 | change(&mut self.settings.share); |
| 124 | 124 | settings::save(&self.settings); |
| 125 | - self.network.set_share_settings(self.settings.share.clone()); | |
| 125 | + if self.network.set_share_settings(self.settings.share.clone()) { | |
| 126 | + let network = self.network.clone(); | |
| 127 | + cx.spawn(async move |_, _| { | |
| 128 | + if let Err(error) = network.update_share().await { | |
| 129 | + tracing::warn!("share update failed: {error}"); | |
| 130 | + } | |
| 131 | + }) | |
| 132 | + .detach(); | |
| 133 | + } | |
| 126 | 134 | cx.notify(); |
| 127 | 135 | } |
| 128 | 136 | |
| @@ -543,6 +551,7 @@ pub(super) fn share_badge( | ||
| 543 | 551 | |
| 544 | 552 | fn settings_card(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> Div { |
| 545 | 553 | let settings = &yumush.settings.share; |
| 554 | + let (resolutions, fps) = share_limits(yumush.network.share_source()); | |
| 546 | 555 | |
| 547 | 556 | div() |
| 548 | 557 | .w(px(320.)) |
| @@ -558,7 +567,9 @@ fn settings_card(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> | ||
| 558 | 567 | .child(field( |
| 559 | 568 | "Resolution", |
| 560 | 569 | segmented( |
| 561 | - RESOLUTIONS, | |
| 570 | + RESOLUTIONS | |
| 571 | + .into_iter() | |
| 572 | + .filter(|(resolution, _)| resolutions.contains(resolution)), | |
| 562 | 573 | settings.top.resolution, |
| 563 | 574 | entity, |
| 564 | 575 | palette, |
| @@ -569,7 +580,7 @@ fn settings_card(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> | ||
| 569 | 580 | .child(field( |
| 570 | 581 | "FPS", |
| 571 | 582 | segmented( |
| 572 | - FPS, | |
| 583 | + FPS.into_iter().filter(|(value, _)| fps.contains(value)), | |
| 573 | 584 | settings.top.fps, |
| 574 | 585 | entity, |
| 575 | 586 | palette, |
| @@ -605,24 +616,33 @@ fn settings_card(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> | ||
| 605 | 616 | .children(audio_list(entity, yumush, palette)) |
| 606 | 617 | } |
| 607 | 618 | |
| 619 | +fn share_limits(source: Option<Source>) -> (Vec<Resolution>, Vec<Fps>) { | |
| 620 | + options( | |
| 621 | + source.map_or(u32::MAX, |source| source.height), | |
| 622 | + u32::MAX, | |
| 623 | + capabilities().max_height, | |
| 624 | + ) | |
| 625 | +} | |
| 626 | + | |
| 608 | 627 | fn audio_list(entity: &Entity<Yumush>, yumush: &Yumush, palette: Palette) -> Option<AnyElement> { |
| 609 | 628 | let settings = &yumush.settings.share; |
| 610 | 629 | |
| 611 | 630 | match &settings.audio { |
| 612 | 631 | ShareAudio::Off => None, |
| 613 | 632 | ShareAudio::Everything => { |
| 614 | - let rows = div() | |
| 615 | - .flex() | |
| 616 | - .flex_col() | |
| 617 | - .gap(px(2.)) | |
| 618 | - .children( | |
| 619 | - yumush | |
| 620 | - .share_apps | |
| 621 | - .iter() | |
| 622 | - .filter(|app| app.kind == AudioKind::App) | |
| 623 | - .map(|app| exclude_row(entity, settings, app)), | |
| 624 | - ); | |
| 625 | - Some(field("Exclude", app_list(rows), palette).into_any_element()) | |
| 633 | + let apps: Vec<&AudioApp> = yumush | |
| 634 | + .share_apps | |
| 635 | + .iter() | |
| 636 | + .filter(|app| app.kind == AudioKind::App) | |
| 637 | + .collect(); | |
| 638 | + (!apps.is_empty()).then(|| { | |
| 639 | + let rows = div() | |
| 640 | + .flex() | |
| 641 | + .flex_col() | |
| 642 | + .gap(px(2.)) | |
| 643 | + .children(apps.into_iter().map(|app| exclude_row(entity, settings, app))); | |
| 644 | + field("Exclude", app_list(rows), palette).into_any_element() | |
| 645 | + }) | |
| 626 | 646 | } |
| 627 | 647 | ShareAudio::Source(selected) => Some( |
| 628 | 648 | app_list(pick_list( |
crates/client/src/gui/sidebar.rsmodified+3 -1
| @@ -173,10 +173,12 @@ impl Yumush { | ||
| 173 | 173 | .flex_col() |
| 174 | 174 | .child( |
| 175 | 175 | div() |
| 176 | + .min_w_0() | |
| 177 | + .truncate() | |
| 176 | 178 | .text_size(text(12.)) |
| 177 | 179 | .font_weight(FontWeight::SEMIBOLD) |
| 178 | 180 | .text_color(palette.ok) |
| 179 | - .child("Voice connected"), | |
| 181 | + .child("Connected"), | |
| 180 | 182 | ) |
| 181 | 183 | .child( |
| 182 | 184 | div() |
crates/client/src/gui/voice_stats.rsmodified+28 -20
| @@ -176,13 +176,7 @@ fn voice_body(samples: &VecDeque<VoiceSample>, palette: Palette) -> Div { | ||
| 176 | 176 | ]; |
| 177 | 177 | |
| 178 | 178 | column() |
| 179 | - .child( | |
| 180 | - div() | |
| 181 | - .flex() | |
| 182 | - .flex_wrap() | |
| 183 | - .gap(px(6.)) | |
| 184 | - .children(tiles.map(|(label, value)| tile(label, value, palette))), | |
| 185 | - ) | |
| 179 | + .child(tile_grid(tiles, palette)) | |
| 186 | 180 | .child(graph( |
| 187 | 181 | "Ping", |
| 188 | 182 | samples |
| @@ -220,11 +214,10 @@ fn voice_body(samples: &VecDeque<VoiceSample>, palette: Palette) -> Div { | ||
| 220 | 214 | fn sharing_body(layers: &[LayerStats], palette: Palette) -> Div { |
| 221 | 215 | let upload: u32 = layers.iter().map(|layer| layer.kbps).sum(); |
| 222 | 216 | column() |
| 223 | - .child(div().flex().flex_wrap().gap(px(6.)).child(tile( | |
| 224 | - "Upload", | |
| 225 | - format!("{upload} kbps"), | |
| 217 | + .child(tile_grid( | |
| 218 | + [("Upload", format!("{upload} kbps"))], | |
| 226 | 219 | palette, |
| 227 | - ))) | |
| 220 | + )) | |
| 228 | 221 | .children(layers.iter().map(|stat| { |
| 229 | 222 | row_line( |
| 230 | 223 | describe(Some(stat.layer), Some(stat.engine)), |
| @@ -236,7 +229,7 @@ fn sharing_body(layers: &[LayerStats], palette: Palette) -> Div { | ||
| 236 | 229 | |
| 237 | 230 | fn watching_body(watching: &[(String, WatchStats)], chat: &Chat, palette: Palette) -> Div { |
| 238 | 231 | column().children(watching.iter().map(|(user_id, stats)| { |
| 239 | - let name = chat.users.get(user_id).map_or_else( | |
| 232 | + let name = chat.author(user_id).map_or_else( | |
| 240 | 233 | || user_id.chars().take(8).collect(), |
| 241 | 234 | |user| user.username.clone(), |
| 242 | 235 | ); |
| @@ -249,13 +242,7 @@ fn watching_body(watching: &[(String, WatchStats)], chat: &Chat, palette: Palett | ||
| 249 | 242 | ]; |
| 250 | 243 | column() |
| 251 | 244 | .child(row_line(name, describe(stats.layer, stats.engine), palette)) |
| 252 | - .child( | |
| 253 | - div() | |
| 254 | - .flex() | |
| 255 | - .flex_wrap() | |
| 256 | - .gap(px(6.)) | |
| 257 | - .children(tiles.map(|(label, value)| tile(label, value, palette))), | |
| 258 | - ) | |
| 245 | + .child(tile_grid(tiles, palette)) | |
| 259 | 246 | .child(graph( |
| 260 | 247 | "Loss", |
| 261 | 248 | chat.share_loss |
| @@ -323,9 +310,30 @@ fn row_line(left: String, right: String, palette: Palette) -> Div { | ||
| 323 | 310 | ) |
| 324 | 311 | } |
| 325 | 312 | |
| 313 | +fn tile_grid<const N: usize>(tiles: [(&'static str, String); N], palette: Palette) -> Div { | |
| 314 | + let mut tiles: Vec<Div> = tiles | |
| 315 | + .into_iter() | |
| 316 | + .map(|(label, value)| tile(label, value, palette).flex_1()) | |
| 317 | + .collect(); | |
| 318 | + let mut grid = div().flex().flex_col().gap(px(6.)); | |
| 319 | + while !tiles.is_empty() { | |
| 320 | + let rest = tiles.split_off(tiles.len().min(3)); | |
| 321 | + let filler = 3 - tiles.len(); | |
| 322 | + grid = grid.child( | |
| 323 | + div() | |
| 324 | + .flex() | |
| 325 | + .gap(px(6.)) | |
| 326 | + .children(tiles) | |
| 327 | + .children((0..filler).map(|_| div().flex_1())), | |
| 328 | + ); | |
| 329 | + tiles = rest; | |
| 330 | + } | |
| 331 | + grid | |
| 332 | +} | |
| 333 | + | |
| 326 | 334 | fn tile(label: &'static str, value: String, palette: Palette) -> Div { |
| 327 | 335 | div() |
| 328 | - .w(px(80.)) | |
| 336 | + .min_w_0() | |
| 329 | 337 | .px(px(8.)) |
| 330 | 338 | .py(px(6.)) |
| 331 | 339 | .flex() |
crates/client/src/network.rsmodified+71 -4
| @@ -25,6 +25,7 @@ use common::{ | ||
| 25 | 25 | }, |
| 26 | 26 | request::{DownloadRequest, Request, UploadHeader}, |
| 27 | 27 | response::Response, |
| 28 | + share::Source, | |
| 28 | 29 | validate::{ |
| 29 | 30 | validate_attachment_name, validate_attachment_size, validate_avatar_size, |
| 30 | 31 | validate_community_name, validate_forward, validate_message_body, validate_new_message, |
| @@ -85,6 +86,7 @@ type SharedShareSettings = Arc<Mutex<ShareSettings>>; | ||
| 85 | 86 | #[derive(Default)] |
| 86 | 87 | struct Share { |
| 87 | 88 | sharing: Option<Sharing>, |
| 89 | + source: Option<Source>, | |
| 88 | 90 | watching: HashMap<String, Watching>, |
| 89 | 91 | } |
| 90 | 92 | |
| @@ -169,6 +171,10 @@ enum Command { | ||
| 169 | 171 | settings: ShareSettings, |
| 170 | 172 | reply: oneshot::Sender<Result<(), Error>>, |
| 171 | 173 | }, |
| 174 | + UpdateShare { | |
| 175 | + settings: ShareSettings, | |
| 176 | + reply: oneshot::Sender<Result<(), Error>>, | |
| 177 | + }, | |
| 172 | 178 | } |
| 173 | 179 | |
| 174 | 180 | #[derive(Clone)] |
| @@ -1372,9 +1378,17 @@ impl NetworkHandle { | ||
| 1372 | 1378 | .await |
| 1373 | 1379 | } |
| 1374 | 1380 | |
| 1381 | + pub async fn update_share(&self) -> Result<(), Error> { | |
| 1382 | + let settings = self.share_settings.lock().unwrap().clone(); | |
| 1383 | + self.ask(|reply| Command::UpdateShare { settings, reply }) | |
| 1384 | + .await | |
| 1385 | + } | |
| 1386 | + | |
| 1375 | 1387 | pub async fn stop_share(&self) -> Result<(), Error> { |
| 1376 | 1388 | let result = self.done(Request::StopShare).await; |
| 1377 | - self.share.lock().unwrap().sharing.take(); | |
| 1389 | + let mut share = self.share.lock().unwrap(); | |
| 1390 | + share.sharing.take(); | |
| 1391 | + share.source.take(); | |
| 1378 | 1392 | result |
| 1379 | 1393 | } |
| 1380 | 1394 | |
| @@ -1382,6 +1396,10 @@ impl NetworkHandle { | ||
| 1382 | 1396 | self.share.lock().unwrap().sharing.is_some() |
| 1383 | 1397 | } |
| 1384 | 1398 | |
| 1399 | + pub fn share_source(&self) -> Option<Source> { | |
| 1400 | + self.share.lock().unwrap().source.clone() | |
| 1401 | + } | |
| 1402 | + | |
| 1385 | 1403 | pub async fn shares(&self, community_id: &str) -> Result<Vec<common::share::Share>, Error> { |
| 1386 | 1404 | match self |
| 1387 | 1405 | .request(Request::Shares { |
| @@ -1449,12 +1467,19 @@ impl NetworkHandle { | ||
| 1449 | 1467 | self.share.lock().unwrap().watching.get(user_id)?.frame() |
| 1450 | 1468 | } |
| 1451 | 1469 | |
| 1452 | - pub fn set_share_settings(&self, settings: ShareSettings) { | |
| 1470 | + pub fn set_share_settings(&self, settings: ShareSettings) -> bool { | |
| 1471 | + let changed = self.sharing() | |
| 1472 | + && self | |
| 1473 | + .share_settings | |
| 1474 | + .lock() | |
| 1475 | + .unwrap() | |
| 1476 | + .encoding_differs(&settings); | |
| 1453 | 1477 | *self.share_settings.lock().unwrap() = settings.clone(); |
| 1454 | 1478 | for watching in self.share.lock().unwrap().watching.values_mut() { |
| 1455 | 1479 | watching.set_volume(settings.volume); |
| 1456 | 1480 | watching.set_quality(settings.watch); |
| 1457 | 1481 | } |
| 1482 | + changed | |
| 1458 | 1483 | } |
| 1459 | 1484 | |
| 1460 | 1485 | pub fn audio_apps(&self) -> Vec<AudioApp> { |
| @@ -1858,6 +1883,14 @@ async fn actor( | ||
| 1858 | 1883 | let _ = reply.send(start_share(&connection, &share, &settings).await); |
| 1859 | 1884 | }); |
| 1860 | 1885 | } |
| 1886 | + Some(Command::UpdateShare { settings, reply }) => { | |
| 1887 | + let connection = connection.clone(); | |
| 1888 | + let share = share.clone(); | |
| 1889 | + | |
| 1890 | + tokio::spawn(async move { | |
| 1891 | + let _ = reply.send(update_share(&connection, &share, &settings).await); | |
| 1892 | + }); | |
| 1893 | + } | |
| 1861 | 1894 | Some(Command::Upload { community_id, path, maximum, reply }) => { |
| 1862 | 1895 | let connection = connection.clone(); |
| 1863 | 1896 | |
| @@ -1926,7 +1959,11 @@ async fn start_share( | ||
| 1926 | 1959 | ) |
| 1927 | 1960 | .await |
| 1928 | 1961 | .map_err(Error::Network)?; |
| 1929 | - share.lock().unwrap().sharing = Some(sharing); | |
| 1962 | + { | |
| 1963 | + let mut share = share.lock().unwrap(); | |
| 1964 | + share.sharing = Some(sharing); | |
| 1965 | + share.source = Some(source.clone()); | |
| 1966 | + } | |
| 1930 | 1967 | |
| 1931 | 1968 | let result = match send(connection, &Request::StartShare { source }).await { |
| 1932 | 1969 | Ok(Response::Done) => Ok(()), |
| @@ -1934,11 +1971,41 @@ async fn start_share( | ||
| 1934 | 1971 | Err(error) => Err(error), |
| 1935 | 1972 | }; |
| 1936 | 1973 | if result.is_err() { |
| 1937 | - share.lock().unwrap().sharing.take(); | |
| 1974 | + let mut share = share.lock().unwrap(); | |
| 1975 | + share.sharing.take(); | |
| 1976 | + share.source.take(); | |
| 1938 | 1977 | } |
| 1939 | 1978 | result |
| 1940 | 1979 | } |
| 1941 | 1980 | |
| 1981 | +async fn update_share( | |
| 1982 | + connection: &quinn::Connection, | |
| 1983 | + share: &SharedShare, | |
| 1984 | + settings: &ShareSettings, | |
| 1985 | +) -> Result<(), Error> { | |
| 1986 | + let source = { | |
| 1987 | + let mut share = share.lock().unwrap(); | |
| 1988 | + let Some(sharing) = share.sharing.as_mut() else { | |
| 1989 | + return Ok(()); | |
| 1990 | + }; | |
| 1991 | + sharing | |
| 1992 | + .update( | |
| 1993 | + connection, | |
| 1994 | + settings.top, | |
| 1995 | + settings.encode(), | |
| 1996 | + settings.audio_mode(), | |
| 1997 | + ) | |
| 1998 | + .map_err(Error::Network)? | |
| 1999 | + }; | |
| 2000 | + share.lock().unwrap().source = Some(source.clone()); | |
| 2001 | + | |
| 2002 | + match send(connection, &Request::StartShare { source }).await { | |
| 2003 | + Ok(Response::Done) => Ok(()), | |
| 2004 | + Ok(_) => Err(Error::Server), | |
| 2005 | + Err(error) => Err(error), | |
| 2006 | + } | |
| 2007 | +} | |
| 2008 | + | |
| 1942 | 2009 | async fn event_receive_loop( |
| 1943 | 2010 | connection: quinn::Connection, |
| 1944 | 2011 | event_sender: mpsc::Sender<NetworkEvent>, |
crates/client/src/settings.rsmodified+7 -0
| @@ -160,6 +160,13 @@ impl Default for ShareSettings { | ||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | impl ShareSettings { |
| 163 | + pub fn encoding_differs(&self, other: &Self) -> bool { | |
| 164 | + self.top != other.top | |
| 165 | + || self.codec != other.codec | |
| 166 | + || self.audio != other.audio | |
| 167 | + || self.excluded != other.excluded | |
| 168 | + } | |
| 169 | + | |
| 163 | 170 | pub fn encode(&self) -> Vec<Codec> { |
| 164 | 171 | let capable = &capabilities().encode; |
| 165 | 172 | match self.codec { |
crates/client/src/share/audio.rsmodified+1 -0
| @@ -1,3 +1,4 @@ | ||
| 1 | +#[derive(Debug, Clone, PartialEq, Eq)] | |
| 1 | 2 | pub enum AudioMode { |
| 2 | 3 | Everything { excluded: Vec<String> }, |
| 3 | 4 | Source(String), |
crates/client/src/share/encode.rsmodified+2 -7
| @@ -116,7 +116,8 @@ impl Backend { | ||
| 116 | 116 | &planes.u, |
| 117 | 117 | &planes.v, |
| 118 | 118 | ); |
| 119 | - report(encoder.encode(&picture)).map(|picture| (picture.au, picture.key_frame)) | |
| 119 | + report(encoder.encode_with(&picture, force)) | |
| 120 | + .map(|picture| (picture.au, picture.key_frame)) | |
| 120 | 121 | } |
| 121 | 122 | } |
| 122 | 123 | } |
| @@ -247,12 +248,6 @@ fn run( | ||
| 247 | 248 | } |
| 248 | 249 | last = Some(frame.timestamp_ms); |
| 249 | 250 | let force = request.swap(false, Ordering::Relaxed); |
| 250 | - if force | |
| 251 | - && matches!(backend, Backend::H264(_)) | |
| 252 | - && let Some(fresh) = Backend::software(&settings) | |
| 253 | - { | |
| 254 | - backend = fresh; | |
| 255 | - } | |
| 256 | 251 | let planes = convert::bgra_to_i420(&frame, settings.width, settings.height); |
| 257 | 252 | let Some((data, keyframe)) = backend.encode(planes, frame.timestamp_ms, force) else { |
| 258 | 253 | continue; |
crates/client/src/share/session.rsmodified+81 -34
| @@ -150,6 +150,10 @@ pub struct Sharing { | ||
| 150 | 150 | encoders: Arc<Mutex<Encoders>>, |
| 151 | 151 | _feed: Worker, |
| 152 | 152 | _capture: Capture, |
| 153 | + refresh: u32, | |
| 154 | + source: Source, | |
| 155 | + started: Instant, | |
| 156 | + audio: Option<AudioMode>, | |
| 153 | 157 | _audio: Option<AudioCapture>, |
| 154 | 158 | _audio_encode: Option<Worker>, |
| 155 | 159 | _sender: Worker, |
| @@ -167,6 +171,16 @@ impl Sharing { | ||
| 167 | 171 | Err("screen share needs linux".into()) |
| 168 | 172 | } |
| 169 | 173 | |
| 174 | + pub fn update( | |
| 175 | + &mut self, | |
| 176 | + _: &Connection, | |
| 177 | + _: Quality, | |
| 178 | + _: Vec<Codec>, | |
| 179 | + _: Option<AudioMode>, | |
| 180 | + ) -> Result<Source, String> { | |
| 181 | + Err("screen share needs linux".into()) | |
| 182 | + } | |
| 183 | + | |
| 170 | 184 | pub fn set_layers(&mut self, _: &[Layer]) {} |
| 171 | 185 | |
| 172 | 186 | pub fn keyframe(&self, _: Layer) {} |
| @@ -178,22 +192,10 @@ impl Sharing { | ||
| 178 | 192 | |
| 179 | 193 | #[cfg(any(target_os = "linux", target_os = "windows"))] |
| 180 | 194 | impl Sharing { |
| 181 | - pub async fn start( | |
| 182 | - connection: Connection, | |
| 183 | - top: Quality, | |
| 184 | - encode: Vec<Codec>, | |
| 185 | - audio: Option<AudioMode>, | |
| 186 | - ) -> Result<(Sharing, Source), String> { | |
| 187 | - if encode.is_empty() { | |
| 188 | - return Err("codec unavailable".into()); | |
| 189 | - } | |
| 190 | - let mut capture = capture::open().await?; | |
| 191 | - let (resolutions, frame_rates) = options( | |
| 192 | - capture.height, | |
| 193 | - capture.refresh, | |
| 194 | - encode::capabilities().max_height, | |
| 195 | - ); | |
| 196 | - let clamped = Quality { | |
| 195 | + fn clamp(top: Quality, height: u32, refresh: u32) -> Result<Quality, String> { | |
| 196 | + let (resolutions, frame_rates) = | |
| 197 | + options(height, refresh, encode::capabilities().max_height); | |
| 198 | + Ok(Quality { | |
| 197 | 199 | resolution: resolutions |
| 198 | 200 | .into_iter() |
| 199 | 201 | .filter(|resolution| *resolution <= top.resolution) |
| @@ -204,11 +206,24 @@ impl Sharing { | ||
| 204 | 206 | .filter(|fps| *fps <= top.fps) |
| 205 | 207 | .max() |
| 206 | 208 | .ok_or("no share fps")?, |
| 207 | - }; | |
| 209 | + }) | |
| 210 | + } | |
| 211 | + | |
| 212 | + pub async fn start( | |
| 213 | + connection: Connection, | |
| 214 | + top: Quality, | |
| 215 | + encode: Vec<Codec>, | |
| 216 | + audio: Option<AudioMode>, | |
| 217 | + ) -> Result<(Sharing, Source), String> { | |
| 218 | + if encode.is_empty() { | |
| 219 | + return Err("codec unavailable".into()); | |
| 220 | + } | |
| 221 | + let mut capture = capture::open().await?; | |
| 222 | + let refresh = capture.refresh; | |
| 208 | 223 | let source = Source { |
| 209 | 224 | width: capture.width, |
| 210 | 225 | height: capture.height, |
| 211 | - top: clamped, | |
| 226 | + top: Self::clamp(top, capture.height, refresh)?, | |
| 212 | 227 | encode, |
| 213 | 228 | }; |
| 214 | 229 | |
| @@ -227,17 +242,7 @@ impl Sharing { | ||
| 227 | 242 | }) |
| 228 | 243 | }; |
| 229 | 244 | |
| 230 | - let (audio_capture, audio_encode) = match audio { | |
| 231 | - Some(mode) => { | |
| 232 | - let (producer, consumer) = RingBuffer::new(AUDIO_RING); | |
| 233 | - let audio_connection = connection.clone(); | |
| 234 | - let encode = Worker::spawn("share-audio-encode", move |stop| { | |
| 235 | - encode_audio(consumer, audio_connection, started, stop) | |
| 236 | - }); | |
| 237 | - (Some(audio_capture::start(mode, producer)), Some(encode)) | |
| 238 | - } | |
| 239 | - None => (None, None), | |
| 240 | - }; | |
| 245 | + let (audio_capture, audio_encode) = start_audio(&connection, started, audio.clone()); | |
| 241 | 246 | |
| 242 | 247 | let sent = Arc::new(Mutex::new(Sent { |
| 243 | 248 | since: Instant::now(), |
| @@ -255,6 +260,10 @@ impl Sharing { | ||
| 255 | 260 | encoders, |
| 256 | 261 | _feed: feed, |
| 257 | 262 | _capture: capture, |
| 263 | + refresh, | |
| 264 | + source: source.clone(), | |
| 265 | + started, | |
| 266 | + audio, | |
| 258 | 267 | _audio: audio_capture, |
| 259 | 268 | _audio_encode: audio_encode, |
| 260 | 269 | _sender: sender, |
| @@ -264,6 +273,26 @@ impl Sharing { | ||
| 264 | 273 | )) |
| 265 | 274 | } |
| 266 | 275 | |
| 276 | + pub fn update( | |
| 277 | + &mut self, | |
| 278 | + connection: &Connection, | |
| 279 | + top: Quality, | |
| 280 | + encode: Vec<Codec>, | |
| 281 | + audio: Option<AudioMode>, | |
| 282 | + ) -> Result<Source, String> { | |
| 283 | + if encode.is_empty() { | |
| 284 | + return Err("codec unavailable".into()); | |
| 285 | + } | |
| 286 | + self.source.top = Self::clamp(top, self.source.height, self.refresh)?; | |
| 287 | + self.source.encode = encode; | |
| 288 | + if self.audio != audio { | |
| 289 | + self.audio = audio.clone(); | |
| 290 | + (self._audio, self._audio_encode) = start_audio(connection, self.started, audio); | |
| 291 | + } | |
| 292 | + | |
| 293 | + Ok(self.source.clone()) | |
| 294 | + } | |
| 295 | + | |
| 267 | 296 | pub fn set_layers(&mut self, layers: &[Layer]) { |
| 268 | 297 | lock(&self.encoders).set_layers(layers); |
| 269 | 298 | } |
| @@ -277,6 +306,22 @@ impl Sharing { | ||
| 277 | 306 | } |
| 278 | 307 | } |
| 279 | 308 | |
| 309 | +fn start_audio( | |
| 310 | + connection: &Connection, | |
| 311 | + started: Instant, | |
| 312 | + mode: Option<AudioMode>, | |
| 313 | +) -> (Option<AudioCapture>, Option<Worker>) { | |
| 314 | + let Some(mode) = mode else { | |
| 315 | + return (None, None); | |
| 316 | + }; | |
| 317 | + let (producer, consumer) = RingBuffer::new(AUDIO_RING); | |
| 318 | + let audio_connection = connection.clone(); | |
| 319 | + let encode = Worker::spawn("share-audio-encode", move |stop| { | |
| 320 | + encode_audio(consumer, audio_connection, started, stop) | |
| 321 | + }); | |
| 322 | + (Some(audio_capture::start(mode, producer)), Some(encode)) | |
| 323 | +} | |
| 324 | + | |
| 280 | 325 | fn feed( |
| 281 | 326 | frames: Receiver<Frame>, |
| 282 | 327 | encoders: Arc<Mutex<Encoders>>, |
| @@ -379,6 +424,7 @@ struct Health { | ||
| 379 | 424 | loss: f32, |
| 380 | 425 | lost: bool, |
| 381 | 426 | served: Option<Layer>, |
| 427 | + keyframes: u32, | |
| 382 | 428 | } |
| 383 | 429 | |
| 384 | 430 | pub struct Watching { |
| @@ -389,7 +435,6 @@ pub struct Watching { | ||
| 389 | 435 | video_tx: Sender<Vec<u8>>, |
| 390 | 436 | audio_tx: Sender<Vec<u8>>, |
| 391 | 437 | received: AtomicU64, |
| 392 | - keyframes: u32, | |
| 393 | 438 | since: Instant, |
| 394 | 439 | _video: Worker, |
| 395 | 440 | _audio: Worker, |
| @@ -436,7 +481,6 @@ impl Watching { | ||
| 436 | 481 | video_tx, |
| 437 | 482 | audio_tx, |
| 438 | 483 | received: AtomicU64::new(0), |
| 439 | - keyframes: 0, | |
| 440 | 484 | since: Instant::now(), |
| 441 | 485 | _video: video_worker, |
| 442 | 486 | _audio: audio_worker, |
| @@ -485,7 +529,7 @@ impl Watching { | ||
| 485 | 529 | kbps: (bytes as f32 * 8. / 1000. / seconds) as u32, |
| 486 | 530 | fps: decoded as f32 / seconds, |
| 487 | 531 | loss: health.loss, |
| 488 | - keyframes: self.keyframes, | |
| 532 | + keyframes: health.keyframes, | |
| 489 | 533 | buffer_ms, |
| 490 | 534 | } |
| 491 | 535 | } |
| @@ -522,7 +566,6 @@ impl Watching { | ||
| 522 | 566 | }; |
| 523 | 567 | let mut ticks = Vec::new(); |
| 524 | 568 | if lost { |
| 525 | - self.keyframes += 1; | |
| 526 | 569 | ticks.push(Tick::Keyframe); |
| 527 | 570 | } |
| 528 | 571 | let wanted = match self.quality { |
| @@ -588,7 +631,11 @@ fn watch_video( | ||
| 588 | 631 | if let Some(Datagram::Video(fragment)) = Datagram::decode(&bytes) |
| 589 | 632 | && let Some(assembled) = reassembler.push(fragment) |
| 590 | 633 | { |
| 591 | - lock(health).served = Some(assembled.layer); | |
| 634 | + { | |
| 635 | + let mut health = lock(health); | |
| 636 | + health.served = Some(assembled.layer); | |
| 637 | + health.keyframes += u32::from(assembled.keyframe); | |
| 638 | + } | |
| 592 | 639 | decode_video(&mut decoder, &assembled, clock, video); |
| 593 | 640 | } |
| 594 | 641 | } |
crates/server/src/request.rsmodified+5 -4
| @@ -988,16 +988,17 @@ async fn dispatch( | ||
| 988 | 988 | return Err(CommonError::Server.into()); |
| 989 | 989 | }; |
| 990 | 990 | let members = user_community::members(&community_id, &conn).await?; |
| 991 | - share.start(&community_id, &me.id, connection.clone(), source.clone()); | |
| 992 | 991 | let event = Event::ShareStarted { |
| 993 | - community_id, | |
| 992 | + community_id: community_id.clone(), | |
| 994 | 993 | share: Share { |
| 995 | 994 | user_id: me.id.clone(), |
| 996 | - source, | |
| 995 | + source: source.clone(), | |
| 997 | 996 | }, |
| 998 | 997 | }; |
| 998 | + let mut broadcasts = vec![broadcast(event, &members)]; | |
| 999 | + broadcasts.extend(share.start(&community_id, &me.id, connection.clone(), source)); | |
| 999 | 1000 | |
| 1000 | - (Response::Done, vec![broadcast(event, &members)]) | |
| 1001 | + (Response::Done, broadcasts) | |
| 1001 | 1002 | } |
| 1002 | 1003 | Request::StopShare => { |
| 1003 | 1004 | let me = authenticated(state, &conn).await?; |
crates/server/src/share.rsmodified+53 -2
| @@ -63,6 +63,8 @@ impl Forward { | ||
| 63 | 63 | struct Viewer { |
| 64 | 64 | user_id: String, |
| 65 | 65 | connection: Connection, |
| 66 | + quality: Quality, | |
| 67 | + decode: Vec<Codec>, | |
| 66 | 68 | forward: Forward, |
| 67 | 69 | } |
| 68 | 70 | |
| @@ -103,6 +105,36 @@ fn layers_changed( | ||
| 103 | 105 | (after != before).then(|| to(sharer_id, Event::ShareLayers(after.into_iter().collect()))) |
| 104 | 106 | } |
| 105 | 107 | |
| 108 | +fn reroute(sharer_id: &str, sharing: &mut Sharing) -> Vec<Broadcast> { | |
| 109 | + let before = sharing.layers(); | |
| 110 | + let Sharing { | |
| 111 | + source, viewers, .. | |
| 112 | + } = sharing; | |
| 113 | + let mut used: Vec<Layer> = Vec::new(); | |
| 114 | + let mut keyframes = Vec::new(); | |
| 115 | + viewers.retain_mut(|viewer| { | |
| 116 | + let Some(layer) = choose(source, viewer.quality, &viewer.decode, &used) else { | |
| 117 | + return false; | |
| 118 | + }; | |
| 119 | + if !used.contains(&layer) { | |
| 120 | + used.push(layer); | |
| 121 | + } | |
| 122 | + if viewer.forward.target() != layer { | |
| 123 | + keyframes.push(to(sharer_id, Event::KeyframeWanted(layer))); | |
| 124 | + } | |
| 125 | + viewer.forward = viewer.forward.retarget(layer); | |
| 126 | + | |
| 127 | + true | |
| 128 | + }); | |
| 129 | + | |
| 130 | + let mut broadcasts: Vec<Broadcast> = layers_changed(sharer_id, sharing, before) | |
| 131 | + .into_iter() | |
| 132 | + .collect(); | |
| 133 | + broadcasts.extend(keyframes); | |
| 134 | + | |
| 135 | + broadcasts | |
| 136 | +} | |
| 137 | + | |
| 106 | 138 | fn remove_viewer(sharer_id: &str, sharing: &mut Sharing, viewer_id: &str) -> Option<Broadcast> { |
| 107 | 139 | let before = sharing.layers(); |
| 108 | 140 | sharing.viewers.retain(|viewer| viewer.user_id != viewer_id); |
| @@ -114,8 +146,23 @@ fn remove_viewer(sharer_id: &str, sharing: &mut Sharing, viewer_id: &str) -> Opt | ||
| 114 | 146 | pub struct Shares(Arc<Mutex<BTreeMap<String, Sharing>>>); |
| 115 | 147 | |
| 116 | 148 | impl Shares { |
| 117 | - pub fn start(&self, community_id: &str, user_id: &str, connection: Connection, source: Source) { | |
| 118 | - self.0.lock().unwrap().insert( | |
| 149 | + pub fn start( | |
| 150 | + &self, | |
| 151 | + community_id: &str, | |
| 152 | + user_id: &str, | |
| 153 | + connection: Connection, | |
| 154 | + source: Source, | |
| 155 | + ) -> Vec<Broadcast> { | |
| 156 | + let mut sharings = self.0.lock().unwrap(); | |
| 157 | + if let Some(sharing) = sharings | |
| 158 | + .get_mut(user_id) | |
| 159 | + .filter(|sharing| sharing.community_id == community_id) | |
| 160 | + { | |
| 161 | + sharing.connection = connection; | |
| 162 | + sharing.source = source; | |
| 163 | + return reroute(user_id, sharing); | |
| 164 | + } | |
| 165 | + sharings.insert( | |
| 119 | 166 | user_id.to_string(), |
| 120 | 167 | Sharing { |
| 121 | 168 | community_id: community_id.to_string(), |
| @@ -124,6 +171,8 @@ impl Shares { | ||
| 124 | 171 | viewers: Vec::new(), |
| 125 | 172 | }, |
| 126 | 173 | ); |
| 174 | + | |
| 175 | + Vec::new() | |
| 127 | 176 | } |
| 128 | 177 | |
| 129 | 178 | pub fn stop(&self, user_id: &str) -> Option<String> { |
| @@ -169,6 +218,8 @@ impl Shares { | ||
| 169 | 218 | sharing.viewers.push(Viewer { |
| 170 | 219 | user_id: viewer_id.to_string(), |
| 171 | 220 | connection, |
| 221 | + quality, | |
| 222 | + decode: decode.to_vec(), | |
| 172 | 223 | forward, |
| 173 | 224 | }); |
| 174 | 225 | let mut broadcasts: Vec<Broadcast> = layers_changed(sharer_id, sharing, before) |
harness/audio.shadded+33 -0
| @@ -0,0 +1,33 @@ | ||
| 1 | +#!/usr/bin/env bash | |
| 2 | +set -euo pipefail | |
| 3 | +STATE="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}" | |
| 4 | +source "$STATE/env" | |
| 5 | +out="$STATE/audio" | |
| 6 | +mkdir -p "$out" | |
| 7 | +python3 - "$out/tone.wav" "${1:-8}" <<'PY' | |
| 8 | +import sys, wave, struct, math | |
| 9 | +w = wave.open(sys.argv[1], "wb"); w.setnchannels(2); w.setsampwidth(2); w.setframerate(48000) | |
| 10 | +v = [int(12000 * math.sin(2 * math.pi * 440 * i / 48000)) for i in range(48000 * int(sys.argv[2]))] | |
| 11 | +w.writeframes(b"".join(struct.pack("<hh", a, a) for a in v)) | |
| 12 | +PY | |
| 13 | +pw-play --target harness-app "$out/tone.wav" & | |
| 14 | +player=$! | |
| 15 | +sleep 2 | |
| 16 | +timeout 4 pw-record --target harness-speaker -P '{ stream.capture.sink = true }' "$out/speaker.wav" || true | |
| 17 | +wait "$player" || true | |
| 18 | +python3 - "$out/speaker.wav" <<'PY' | |
| 19 | +import sys, wave, struct, math | |
| 20 | +w = wave.open(sys.argv[1]) | |
| 21 | +n = w.getnframes(); ch = w.getnchannels(); width = w.getsampwidth() | |
| 22 | +raw = w.readframes(n) | |
| 23 | +fmt = {2: "h", 4: "i"}[width] | |
| 24 | +s = struct.unpack("<" + fmt * (len(raw) // width), raw)[::ch] | |
| 25 | +scale = float(1 << (8 * width - 1)) | |
| 26 | +x = [v / scale for v in s[: 48000 * 2]] | |
| 27 | +def power(f): | |
| 28 | + re = sum(v * math.cos(2 * math.pi * f * i / 48000) for i, v in enumerate(x)) | |
| 29 | + im = sum(v * math.sin(2 * math.pi * f * i / 48000) for i, v in enumerate(x)) | |
| 30 | + return math.hypot(re, im) / max(len(x), 1) | |
| 31 | +rms = math.sqrt(sum(v * v for v in x) / max(len(x), 1)) | |
| 32 | +print(f"rms {rms:.4f} 440Hz {power(440):.4f} 1000Hz {power(1000):.4f}") | |
| 33 | +PY |
harness/client.shmodified+1 -1
| @@ -4,7 +4,7 @@ HERE="$(cd "$(dirname "$0")" && pwd)" | ||
| 4 | 4 | ROOT="$(dirname "$HERE")" |
| 5 | 5 | STATE="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}" |
| 6 | 6 | NAME="$1" |
| 7 | -source "$STATE/env" | |
| 7 | +source "${ENV_FILE:-$STATE/env}" | |
| 8 | 8 | mkdir -p "$STATE/clients/$NAME" |
| 9 | 9 | XDG_CONFIG_HOME="$STATE/clients/$NAME" RUST_LOG="${RUST_LOG:-info}" "$ROOT/target/${PROFILE:-harness}/client" >"$STATE/$NAME.log" 2>&1 & |
| 10 | 10 | echo "$NAME $!" >> "$STATE/pids" |
harness/down.shmodified+1 -1
| @@ -2,4 +2,4 @@ | ||
| 2 | 2 | STATE="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}" |
| 3 | 3 | [ -f "$STATE/pids" ] || exit 0 |
| 4 | 4 | tac "$STATE/pids" | while read -r name pid; do kill "$pid" 2>/dev/null && echo "stopped $name $pid"; done |
| 5 | -rm -f "$STATE/pids" "$STATE/env" | |
| 5 | +rm -f "$STATE/pids" "$STATE/env" "$STATE/env2" |
harness/niri.kdlmodified+3 -0
| @@ -18,3 +18,6 @@ gestures { | ||
| 18 | 18 | off |
| 19 | 19 | } |
| 20 | 20 | } |
| 21 | +input { | |
| 22 | + focus-follows-mouse | |
| 23 | +} |
harness/pipewire/pipewire.conf.d/harness.confadded+8 -0
| @@ -0,0 +1,8 @@ | ||
| 1 | +context.objects = [ | |
| 2 | + { factory = adapter | |
| 3 | + args = { factory.name = support.null-audio-sink node.name = harness-speaker media.class = Audio/Sink audio.position = [ FL FR ] monitor.channel-volumes = true } } | |
| 4 | + { factory = adapter | |
| 5 | + args = { factory.name = support.null-audio-sink node.name = harness-app media.class = Audio/Sink audio.position = [ FL FR ] } } | |
| 6 | + { factory = adapter | |
| 7 | + args = { factory.name = support.null-audio-sink node.name = harness-mic media.class = Audio/Source/Virtual audio.position = [ FL FR ] } } | |
| 8 | +] |
harness/pipewire/wireplumber.conf.d/harness.confadded+10 -0
| @@ -0,0 +1,10 @@ | ||
| 1 | +wireplumber.profiles = { | |
| 2 | + main = { | |
| 3 | + monitor.alsa = disabled | |
| 4 | + monitor.alsa-midi = disabled | |
| 5 | + monitor.bluez = disabled | |
| 6 | + monitor.bluez-midi = disabled | |
| 7 | + monitor.v4l2 = disabled | |
| 8 | + monitor.libcamera = disabled | |
| 9 | + } | |
| 10 | +} |
harness/session.shmodified+34 -18
| @@ -2,22 +2,38 @@ | ||
| 2 | 2 | set -euo pipefail |
| 3 | 3 | HERE="$(cd "$(dirname "$0")" && pwd)" |
| 4 | 4 | STATE="$1" |
| 5 | -before="$(ls "$XDG_RUNTIME_DIR" | grep -E '^wayland-[0-9]+$' || true)" | |
| 6 | -niri --headless -c "$HERE/niri.kdl" >"$STATE/niri.log" 2>&1 & | |
| 7 | -echo "niri $!" >> "$STATE/pids" | |
| 8 | -socket="" | |
| 9 | -for _ in $(seq 100); do | |
| 10 | - socket="$(comm -13 <(echo "$before" | sort) <(ls "$XDG_RUNTIME_DIR" | grep -E '^wayland-[0-9]+$' | sort) | head -1)" | |
| 11 | - [ -n "$socket" ] && break | |
| 12 | - sleep 0.1 | |
| 13 | -done | |
| 14 | -export WAYLAND_DISPLAY="$socket" XDG_CURRENT_DESKTOP=niri XDG_SESSION_TYPE=wayland | |
| 15 | -export NIRI_SOCKET="$(ls "$XDG_RUNTIME_DIR"/niri.$socket.*.sock | head -1)" | |
| 16 | -dbus-update-activation-environment WAYLAND_DISPLAY XDG_CURRENT_DESKTOP XDG_SESSION_TYPE NIRI_SOCKET XDG_CONFIG_HOME="$STATE/xdg" | |
| 17 | -{ | |
| 18 | - echo "export WAYLAND_DISPLAY=$WAYLAND_DISPLAY" | |
| 19 | - echo "export NIRI_SOCKET=$NIRI_SOCKET" | |
| 20 | - echo "export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" | |
| 21 | - echo "export XDG_CURRENT_DESKTOP=niri" | |
| 22 | -} > "$STATE/env" | |
| 5 | +mkdir -p "$STATE/pw" "$STATE/xdg/pipewire" "$STATE/xdg/wireplumber" "$STATE/wpstate" | |
| 6 | +cp -r "$HERE/pipewire/pipewire.conf.d" "$STATE/xdg/pipewire/" | |
| 7 | +cp -r "$HERE/pipewire/wireplumber.conf.d" "$STATE/xdg/wireplumber/" | |
| 8 | +export PIPEWIRE_RUNTIME_DIR="$STATE/pw" | |
| 9 | +XDG_CONFIG_HOME="$STATE/xdg" pipewire >"$STATE/pipewire.log" 2>&1 & | |
| 10 | +echo "pipewire $!" >> "$STATE/pids" | |
| 11 | +sleep 0.5 | |
| 12 | +XDG_CONFIG_HOME="$STATE/xdg" XDG_STATE_HOME="$STATE/wpstate" wireplumber >"$STATE/wireplumber.log" 2>&1 & | |
| 13 | +echo "wireplumber $!" >> "$STATE/pids" | |
| 14 | +sleep 0.5 | |
| 15 | +dbus-update-activation-environment PIPEWIRE_RUNTIME_DIR="$PIPEWIRE_RUNTIME_DIR" XDG_CURRENT_DESKTOP=niri XDG_SESSION_TYPE=wayland XDG_CONFIG_HOME="$STATE/xdg" | |
| 16 | +compositor() { | |
| 17 | + local before socket="" | |
| 18 | + before="$(ls "$XDG_RUNTIME_DIR" | grep -E '^wayland-[0-9]+$' || true)" | |
| 19 | + niri --headless -c "$HERE/niri.kdl" >"$STATE/$1.log" 2>&1 & | |
| 20 | + echo "$1 $!" >> "$STATE/pids" | |
| 21 | + for _ in $(seq 100); do | |
| 22 | + socket="$(comm -13 <(echo "$before" | sort) <(ls "$XDG_RUNTIME_DIR" | grep -E '^wayland-[0-9]+$' | sort) | head -1)" | |
| 23 | + [ -n "$socket" ] && break | |
| 24 | + sleep 0.1 | |
| 25 | + done | |
| 26 | + { | |
| 27 | + echo "export WAYLAND_DISPLAY=$socket" | |
| 28 | + echo "export NIRI_SOCKET=$(ls "$XDG_RUNTIME_DIR"/niri.$socket.*.sock | head -1)" | |
| 29 | + echo "export DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" | |
| 30 | + echo "export XDG_CURRENT_DESKTOP=niri" | |
| 31 | + echo "export PIPEWIRE_RUNTIME_DIR=$PIPEWIRE_RUNTIME_DIR" | |
| 32 | + } > "$STATE/$2.tmp" | |
| 33 | + mv "$STATE/$2.tmp" "$STATE/$2" | |
| 34 | +} | |
| 35 | +compositor niri2 env2 | |
| 36 | +compositor niri env | |
| 37 | +source "$STATE/env" | |
| 38 | +dbus-update-activation-environment WAYLAND_DISPLAY NIRI_SOCKET | |
| 23 | 39 | wait |
harness/shot.shmodified+1 -1
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | #!/usr/bin/env bash |
| 2 | 2 | STATE="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}" |
| 3 | -source "$STATE/env" | |
| 3 | +source "${ENV_FILE:-$STATE/env}" | |
| 4 | 4 | out="$STATE/shots/${1:-shot}.png" |
| 5 | 5 | grim "$out" && echo "$out" |
harness/ui.shmodified+1 -1
| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | #!/usr/bin/env bash |
| 2 | 2 | set -euo pipefail |
| 3 | 3 | STATE="${HARNESS_STATE:-/tmp/claude-1000/yumush-harness}" |
| 4 | -source "$STATE/env" | |
| 4 | +source "${ENV_FILE:-$STATE/env}" | |
| 5 | 5 | to() { wlrctl pointer move -4000 -4000; wlrctl pointer move "$1" "$2"; sleep 0.1; } |
| 6 | 6 | case "$1" in |
| 7 | 7 | click) to "$2" "$3"; wlrctl pointer click "${4:-left}";; |