forge
Explore
Log in

Don't you dare go Hollow

Share the fake capture with windows and quiet repeated audio retries

Browse files at this commit

c6ed9767c9a7d2004fece0243267d5594a13d922Ahmet Kaan GümüşParent: fd75e8c
  • feat
    • share the fake capture with windows and quiet repeated audio retries
Show full message
✨ feat: share the fake capture with windows and quiet repeated audio retries

YUMUSH_TEST_CAPTURE now works on Windows too, so the harness can measure
frame rates there. Audio device retries warn once per distinct error
instead of every second. The harness syncs and builds the Windows VM
and reads frame counters from its screen.
crates/client/src/share/capture.rsmodified+17 -64
@@ -30,13 +30,13 @@ use spa::{
30 utils::{Direction, Fraction, Rectangle, SpaTypes},30 utils::{Direction, Fraction, Rectangle, SpaTypes},
31 };31 };
32 32
33-use super::frame::Frame;33+use super::{
34+ fake,
35+ frame::{BYTES_PER_PIXEL, DEFAULT_REFRESH, FRAME_QUEUE, Frame},
36+};
34 37
35 const NEGOTIATE_TIMEOUT: Duration = Duration::from_secs(10);38 const NEGOTIATE_TIMEOUT: Duration = Duration::from_secs(10);
36 const STOP_CHECK: Duration = Duration::from_millis(100);39 const STOP_CHECK: Duration = Duration::from_millis(100);
37-const DEFAULT_REFRESH: u32 = 60;
38-const FRAME_QUEUE: usize = 2;
39-const BYTES_PER_PIXEL: usize = 4;
40 40
41 type Negotiated = (u32, u32, u32);41 type Negotiated = (u32, u32, u32);
42 42
@@ -48,6 +48,7 @@ pub struct Capture {
48 stop: Arc<AtomicBool>,48 stop: Arc<AtomicBool>,
49 thread: Option<JoinHandle<()>>,49 thread: Option<JoinHandle<()>>,
50 _session: Option<Session<Screencast>>,50 _session: Option<Session<Screencast>>,
51+ _fake: Option<fake::Generator>,
51 }52 }
52 53
53 impl Drop for Capture {54 impl Drop for Capture {
@@ -61,7 +62,17 @@ impl Drop for Capture {
61 62
62 pub async fn open() -> Result<Capture, String> {63 pub async fn open() -> Result<Capture, String> {
63 if let Ok(spec) = std::env::var("YUMUSH_TEST_CAPTURE") {64 if let Ok(spec) = std::env::var("YUMUSH_TEST_CAPTURE") {
64- return Ok(fake(&spec));65+ let (width, height, refresh, frames, generator) = fake::start(&spec);
66+ return Ok(Capture {
67+ width,
68+ height,
69+ refresh,
70+ frames,
71+ stop: Arc::new(AtomicBool::new(false)),
72+ thread: None,
73+ _session: None,
74+ _fake: Some(generator),
75+ });
65 }76 }
66 let screencast = Screencast::new().await.map_err(text)?;77 let screencast = Screencast::new().await.map_err(text)?;
67 let session = screencast78 let session = screencast
@@ -126,68 +137,10 @@ pub async fn open() -> Result<Capture, String> {
126 stop,137 stop,
127 thread: Some(thread),138 thread: Some(thread),
128 _session: Some(session),139 _session: Some(session),
140+ _fake: None,
129 })141 })
130 }142 }
131 143
132-fn fake(spec: &str) -> Capture {
133- let parsed: Option<(u32, u32, u32)> = spec.split_once('@').and_then(|(size, fps)| {
134- let (width, height) = size.split_once('x')?;
135- Some((width.parse().ok()?, height.parse().ok()?, fps.parse().ok()?))
136- });
137- let (width, height, refresh) = parsed
138- .filter(|(width, height, fps)| *width > 0 && *height > 0 && *fps > 0)
139- .unwrap_or((1280, 720, DEFAULT_REFRESH));
140- let (frames_tx, frames_rx) = sync_channel(FRAME_QUEUE);
141- let stop = Arc::new(AtomicBool::new(false));
142- let thread = {
143- let stop = stop.clone();
144- std::thread::Builder::new()
145- .name("share-capture-fake".to_string())
146- .spawn(move || {
147- let started = Instant::now();
148- let interval = Duration::from_secs_f64(1.0 / f64::from(refresh));
149- let mut number: u64 = 0;
150- while !stop.load(Ordering::Relaxed) {
151- let bar = (number as usize * 8) % width as usize;
152- let mut bgra = vec![40u8; (width * height) as usize * BYTES_PER_PIXEL];
153- for y in 0..height as usize {
154- let row = y * width as usize;
155- for x in bar..(bar + 32).min(width as usize) {
156- bgra[(row + x) * BYTES_PER_PIXEL..][..3].fill(255);
157- }
158- if y < 16 {
159- for x in 0..(32 * 16).min(width as usize) {
160- let value = if (number >> (x / 16)) & 1 == 1 { 255 } else { 0 };
161- bgra[(row + x) * BYTES_PER_PIXEL..][..3].fill(value);
162- }
163- }
164- }
165- let frame = Frame {
166- width,
167- height,
168- stride: width * BYTES_PER_PIXEL as u32,
169- timestamp_ms: u32::try_from(started.elapsed().as_millis())
170- .unwrap_or(u32::MAX),
171- bgra,
172- };
173- let _ = frames_tx.try_send(frame);
174- number += 1;
175- std::thread::sleep(interval);
176- }
177- })
178- .ok()
179- };
180- Capture {
181- width,
182- height,
183- refresh,
184- frames: frames_rx,
185- stop,
186- thread,
187- _session: None,
188- }
189-}
190-
191 fn text(error: impl std::fmt::Display) -> String {144 fn text(error: impl std::fmt::Display) -> String {
192 error.to_string()145 error.to_string()
193 }146 }
crates/client/src/share/capture_windows.rsmodified+17 -5
@@ -14,11 +14,10 @@ use windows_capture::{
14 },14 },
15 };15 };
16 16
17-use super::frame::Frame;17+use super::{
18-18+ fake,
19-const DEFAULT_REFRESH: u32 = 60;19+ frame::{BYTES_PER_PIXEL, DEFAULT_REFRESH, FRAME_QUEUE, Frame},
20-const FRAME_QUEUE: usize = 2;20+};
21-const BYTES_PER_PIXEL: usize = 4;
22 21
23 pub struct Capture {22 pub struct Capture {
24 pub width: u32,23 pub width: u32,
@@ -26,6 +25,7 @@ pub struct Capture {
26 pub refresh: u32,25 pub refresh: u32,
27 pub frames: Receiver<Frame>,26 pub frames: Receiver<Frame>,
28 control: Option<CaptureControl<Handler, String>>,27 control: Option<CaptureControl<Handler, String>>,
28+ _fake: Option<fake::Generator>,
29 }29 }
30 30
31 impl Drop for Capture {31 impl Drop for Capture {
@@ -37,6 +37,17 @@ impl Drop for Capture {
37 }37 }
38 38
39 pub async fn open() -> Result<Capture, String> {39 pub async fn open() -> Result<Capture, String> {
40+ if let Ok(spec) = std::env::var("YUMUSH_TEST_CAPTURE") {
41+ let (width, height, refresh, frames, generator) = fake::start(&spec);
42+ return Ok(Capture {
43+ width,
44+ height,
45+ refresh,
46+ frames,
47+ control: None,
48+ _fake: Some(generator),
49+ });
50+ }
40 let monitor = Monitor::primary().map_err(text)?;51 let monitor = Monitor::primary().map_err(text)?;
41 let width = monitor.width().map_err(text)?;52 let width = monitor.width().map_err(text)?;
42 let height = monitor.height().map_err(text)?;53 let height = monitor.height().map_err(text)?;
@@ -65,6 +76,7 @@ pub async fn open() -> Result<Capture, String> {
65 refresh,76 refresh,
66 frames: frames_rx,77 frames: frames_rx,
67 control: Some(control),78 control: Some(control),
79+ _fake: None,
68 })80 })
69 }81 }
70 82
crates/client/src/share/fake.rsadded+76 -0
@@ -0,0 +1,76 @@
1+use std::{
2+ sync::{
3+ Arc,
4+ atomic::{AtomicBool, Ordering},
5+ mpsc::{Receiver, sync_channel},
6+ },
7+ thread::JoinHandle,
8+ time::{Duration, Instant},
9+};
10+
11+use super::frame::{BYTES_PER_PIXEL, DEFAULT_REFRESH, FRAME_QUEUE, Frame};
12+
13+pub struct Generator {
14+ stop: Arc<AtomicBool>,
15+ thread: Option<JoinHandle<()>>,
16+}
17+
18+impl Drop for Generator {
19+ fn drop(&mut self) {
20+ self.stop.store(true, Ordering::Relaxed);
21+ if let Some(thread) = self.thread.take() {
22+ let _ = thread.join();
23+ }
24+ }
25+}
26+
27+pub fn start(spec: &str) -> (u32, u32, u32, Receiver<Frame>, Generator) {
28+ let parsed: Option<(u32, u32, u32)> = spec.split_once('@').and_then(|(size, fps)| {
29+ let (width, height) = size.split_once('x')?;
30+ Some((width.parse().ok()?, height.parse().ok()?, fps.parse().ok()?))
31+ });
32+ let (width, height, refresh) = parsed
33+ .filter(|(width, height, fps)| *width > 0 && *height > 0 && *fps > 0)
34+ .unwrap_or((1280, 720, DEFAULT_REFRESH));
35+ let (frames_tx, frames_rx) = sync_channel(FRAME_QUEUE);
36+ let stop = Arc::new(AtomicBool::new(false));
37+ let thread = {
38+ let stop = stop.clone();
39+ std::thread::Builder::new()
40+ .name("share-capture-fake".to_string())
41+ .spawn(move || {
42+ let started = Instant::now();
43+ let interval = Duration::from_secs_f64(1.0 / f64::from(refresh));
44+ let mut number: u64 = 0;
45+ while !stop.load(Ordering::Relaxed) {
46+ let bar = (number as usize * 8) % width as usize;
47+ let mut bgra = vec![40u8; (width * height) as usize * BYTES_PER_PIXEL];
48+ for y in 0..height as usize {
49+ let row = y * width as usize;
50+ for x in bar..(bar + 32).min(width as usize) {
51+ bgra[(row + x) * BYTES_PER_PIXEL..][..3].fill(255);
52+ }
53+ if y < 16 {
54+ for x in 0..(32 * 16).min(width as usize) {
55+ let value = if (number >> (x / 16)) & 1 == 1 { 255 } else { 0 };
56+ bgra[(row + x) * BYTES_PER_PIXEL..][..3].fill(value);
57+ }
58+ }
59+ }
60+ let frame = Frame {
61+ width,
62+ height,
63+ stride: width * BYTES_PER_PIXEL as u32,
64+ timestamp_ms: u32::try_from(started.elapsed().as_millis())
65+ .unwrap_or(u32::MAX),
66+ bgra,
67+ };
68+ let _ = frames_tx.try_send(frame);
69+ number += 1;
70+ std::thread::sleep(interval);
71+ }
72+ })
73+ .ok()
74+ };
75+ (width, height, refresh, frames_rx, Generator { stop, thread })
76+}
crates/client/src/share/frame.rsmodified+4 -0
@@ -2,6 +2,10 @@ use common::share::Layer;
2 2
3 use crate::media::decode::Engine;3 use crate::media::decode::Engine;
4 4
5+pub const DEFAULT_REFRESH: u32 = 60;
6+pub const FRAME_QUEUE: usize = 2;
7+pub const BYTES_PER_PIXEL: usize = 4;
8+
5 pub struct Frame {9 pub struct Frame {
6 pub width: u32,10 pub width: u32,
7 pub height: u32,11 pub height: u32,
crates/client/src/share/mod.rsmodified+2 -0
@@ -9,6 +9,8 @@ pub mod capture;
9 #[cfg(target_os = "windows")]9 #[cfg(target_os = "windows")]
10 #[path = "capture_windows.rs"]10 #[path = "capture_windows.rs"]
11 pub mod capture;11 pub mod capture;
12+#[cfg(any(target_os = "linux", target_os = "windows"))]
13+pub mod fake;
12 pub mod convert;14 pub mod convert;
13 pub mod encode;15 pub mod encode;
14 pub mod frame;16 pub mod frame;
crates/client/src/voice/audio.rsmodified+12 -2
@@ -207,11 +207,21 @@ pub fn supervise(
207 stop: &AtomicBool,207 stop: &AtomicBool,
208 mut attempt: impl FnMut() -> Result<(), Box<dyn Error>>,208 mut attempt: impl FnMut() -> Result<(), Box<dyn Error>>,
209 ) {209 ) {
210+ let mut last: Option<String> = None;
210 while !stop.load(Ordering::Relaxed) {211 while !stop.load(Ordering::Relaxed) {
211 let pause = match attempt() {212 let pause = match attempt() {
212- Ok(()) => RETRY_AFTER_CHANGE,213+ Ok(()) => {
214+ last = None;
215+ RETRY_AFTER_CHANGE
216+ }
213 Err(error) => {217 Err(error) => {
214- warn!("{name}: {error}, retrying");218+ let message = error.to_string();
219+ if last.as_deref() == Some(message.as_str()) {
220+ tracing::debug!("{name}: {message}, retrying");
221+ } else {
222+ warn!("{name}: {message}, retrying");
223+ last = Some(message);
224+ }
215 RETRY_AFTER_ERROR225 RETRY_AFTER_ERROR
216 }226 }
217 };227 };
harness/fps.pymodified+4 -1
@@ -26,7 +26,10 @@ end = time.time() + seconds
26 while time.time() < end:26 while time.time() < end:
27 p = f"{state}/shots/fps.png"27 p = f"{state}/shots/fps.png"
28 t = time.time()28 t = time.time()
29- subprocess.run(["grim", p], env=env, check=True)29+ if os.environ.get("WIN"):
30+ subprocess.run(["./win.sh", "shot", "fps"], check=True, stdout=subprocess.DEVNULL)
31+ else:
32+ subprocess.run(["grim", p], env=env, check=True)
30 samples.append((t, read(p)))33 samples.append((t, read(p)))
31 (t0, n0), (t1, n1) = samples[0], samples[-1]34 (t0, n0), (t1, n1) = samples[0], samples[-1]
32 print(f"frames {n0}->{n1} in {t1-t0:.2f}s = {(n1-n0)/(t1-t0):.1f} fps, {len(samples)} shots")35 print(f"frames {n0}->{n1} in {t1-t0:.2f}s = {(n1-n0)/(t1-t0):.1f} fps, {len(samples)} shots")
harness/win.shmodified+5 -0
@@ -16,5 +16,10 @@ case "$1" in
16 run)16 run)
17 ssh_win "schtasks /create /f /tn yumush_$2 /sc once /st 00:00 /it /ru yumush /tr \"$3\" | Out-Null; schtasks /run /tn yumush_$2";;17 ssh_win "schtasks /create /f /tn yumush_$2 /sc once /st 00:00 /it /ru yumush /tr \"$3\" | Out-Null; schtasks /run /tn yumush_$2";;
18 ssh) shift; ssh_win "$@";;18 ssh) shift; ssh_win "$@";;
19+ sync)
20+ ssh_win 'Stop-Process -Name client,server -ErrorAction SilentlyContinue' || true
21+ (cd .. && (git ls-files -co --exclude-standard; echo fullchain.pem; echo privkey.pem; echo configs/server_config.toml) | grep -v "^harness/" | tar czf /tmp/claude-1000/src.tgz -T -)
22+ scp -q -i ~/vm/yumush-win/id_ed25519 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -P 2222 /tmp/claude-1000/src.tgz yumush@127.0.0.1:src.tgz
23+ ssh_win 'tar xmzf src.tgz -C yumush; cd yumush; $env:Path += ";C:\Users\yumush\.cargo\bin"; cargo build --profile harness -p client -p server 2>&1 | Select-String -Pattern "^error|^warning|Finished|error\[" -Context 0,8 | Select -First 40';;
19 esac24 esac
20 sleep "${UI_DELAY:-0.3}"25 sleep "${UI_DELAY:-0.3}"