Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
ci(linux): cover X11 targets, screenshots, export and Instant uploads; keep Cap's windows out of the X11 picker (#3288)
Richie McIlroy66893b47297b
diff --git a/.github/workflows/instant-reliability.yml b/.github/workflows/instant-reliability.ymlindex 137864ea6..f3213417d 100644--- a/.github/workflows/instant-reliability.yml+++ b/.github/workflows/instant-reliability.yml@@ -5,7 +5,9 @@ name: Instant reliability (real app)# server video's creation through the first seconds of capture, and a crash# followed by Recover. Each case checks what reached the mock server and what# was left on disk, so a regression that loses a recording, deletes one with-# media, or leaves an empty video behind fails here.+# media, or leaves an empty video behind fails here. The Linux job runs the+# cases whose expectations hold there on Xvfb: Linux keeps a cancelled or+# crashed start's files and video rather than deleting them.on:pull_request:@@ -185,3 +187,87 @@ jobs:name: instant-reliability-sandboxespath: ${{ runner.temp }}/real-appretention-days: 7++ real-app-linux:+ name: Instant upload and recovery on Linux (real app)+ needs: scope+ if: needs.scope.outputs.run == 'true'+ runs-on: blacksmith-8vcpu-ubuntu-2404+ timeout-minutes: 60+ env:+ CARGO_PROFILE_DEV_DEBUG: "0"+ steps:+ - name: Checkout repository+ uses: actions/checkout@v4++ - name: Install Linux desktop dependencies+ uses: ./.github/actions/install-desktop-deps++ - name: Rust setup+ uses: dtolnay/[email protected]+ with:+ targets: x86_64-unknown-linux-gnu++ - uses: ./.github/actions/setup-rust-cache+ with:+ target: x86_64-unknown-linux-gnu+ prefix-key: v1-rust-gpui+ save-cache: "false"+ workspaces: apps/desktop-gpui -> target++ - name: Run setup+ run: node scripts/setup.js+ env:+ RUST_TARGET_TRIPLE: x86_64-unknown-linux-gnu++ - name: Prepare GPUI dependency+ run: |+ node scripts/sync-desktop-versions.mjs+ ./scripts/prepare-gpui-dependency.sh++ - name: Build the app and its tests+ run: |+ set -euo pipefail+ cargo +1.95.0 build --manifest-path apps/desktop-gpui/Cargo.toml --locked --bin cap-gpui+ cargo +1.95.0 test --manifest-path apps/desktop-gpui/Cargo.toml --locked --bin cap-gpui --no-run --message-format=json \+ | python3 -c 'import json, sys+ for line in sys.stdin:+ m = json.loads(line)+ if m.get("reason") == "compiler-artifact" and m.get("executable") and m["target"]["name"] == "cap-gpui" and m["profile"]["test"]:+ print(m["executable"])' > "$RUNNER_TEMP/test-binary"+ test -s "$RUNNER_TEMP/test-binary"++ # X11 captures without a portal. Display and area recordings wait for+ # the Stop shortcut to start, so the cases record another app's window.+ # The runner has no audio device: a PulseAudio null sink plays the cue.+ - name: Real-app Instant upload and recovery on Xvfb+ run: |+ set -euo pipefail+ sudo apt-get install -y -qq xvfb x11-utils dbus pulseaudio pulseaudio-utils libasound2-plugins >/dev/null+ # An output device for the start cue, which the start-cue case waits on.+ pulse_dir=$(mktemp -d)+ pulseaudio -n --daemonize=yes --exit-idle-time=-1 \+ -L "module-native-protocol-unix socket=$pulse_dir/native auth-anonymous=1" \+ -L "module-null-sink sink_name=cap_output" -L "module-always-sink"+ export PULSE_SERVER="unix:$pulse_dir/native"+ for _ in $(seq 40); do pactl info >/dev/null 2>&1 && break; sleep 0.25; done+ pactl set-default-sink cap_output+ Xvfb :78 -screen 0 1920x1080x24 >/dev/null 2>&1 &+ sleep 1+ DISPLAY=:78 xmessage -geometry 640x360+200+200 "A window to record" >/dev/null 2>&1 &+ env -u WAYLAND_DISPLAY DISPLAY=:78 XDG_SESSION_TYPE=x11 \+ LD_LIBRARY_PATH="$GITHUB_WORKSPACE/target/native-deps/lib" \+ CAP_GPUI_REAL_APP_BIN="$GITHUB_WORKSPACE/apps/desktop-gpui/target/debug/cap-gpui" \+ CAP_GPUI_REAL_APP_ARTIFACTS="$RUNNER_TEMP/real-app" \+ CAP_GPUI_AUTO_OVERLAY=window CAP_GPUI_AUTO_WINDOW=xmessage \+ dbus-run-session -- "$(cat "$RUNNER_TEMP/test-binary")" --ignored --test-threads=1 --nocapture \+ real_app_instant_recording_uploads_and_verifies real_app_recovered_recording_uploads \+ real_app_start_cue_waits_for_a_slow_server_video++ - name: Upload sandboxes+ if: failure()+ uses: actions/upload-artifact@v4+ with:+ name: instant-reliability-sandboxes-linux+ path: ${{ runner.temp }}/real-app+ retention-days: 7diff --git a/.github/workflows/linux-desktop-reliability.yml b/.github/workflows/linux-desktop-reliability.ymlindex 589aa7b1f..13803c2f2 100644--- a/.github/workflows/linux-desktop-reliability.yml+++ b/.github/workflows/linux-desktop-reliability.yml@@ -123,6 +123,12 @@ jobs:bash scripts/linux-desktop-harness/dialog-x11.sh \apps/desktop-gpui/target/debug/cap-gpui target/native-deps/lib+ - name: X11 display, area and window recordings, audio and a screenshot+ run: |+ sudo apt-get install -y -qq x11-utils pulseaudio pulseaudio-utils libasound2-plugins ffmpeg >/dev/null+ bash scripts/linux-desktop-harness/x11-capture.sh \+ apps/desktop-gpui/target/debug/cap-gpui target/native-deps/lib "$RUNNER_TEMP/out/x11-capture"+- name: Fetch the Cap package for desktop integrationrun: |curl --fail --location --retry 3 -o "$RUNNER_TEMP/cap.deb" "$CAP_DEB_URL"@@ -268,6 +274,32 @@ jobs:grep -qx "$line" "$RUNNER_TEMP/out/gnome-screenshot/result.txt"done+ - name: GNOME 50 area recording (portal stream cropped to the area)+ env:+ DEV_BIN: ${{ github.workspace }}/apps/desktop-gpui/target/debug/cap-gpui+ DEV_LIBS: ${{ github.workspace }}/target/native-deps/lib+ run: |+ sudo -E bash scripts/linux-desktop-harness/run-desktop.sh gnome "$RUNNER_TEMP/cap.deb" \+ "$RUNNER_TEMP/out/gnome-area" LAUNCH=dock APPROVE_SHORTCUT_AFTER=6 AREA=200,150,800,450+ cat "$RUNNER_TEMP/out/gnome-area/result.txt"+ for line in attempt1_finished=yes area_video=yes panics=0; do+ grep -qx "$line" "$RUNNER_TEMP/out/gnome-area/result.txt"+ done++ - name: GNOME 50 editor export to MP4 and GIF+ env:+ DEV_BIN: ${{ github.workspace }}/apps/desktop-gpui/target/debug/cap-gpui+ DEV_LIBS: ${{ github.workspace }}/target/native-deps/lib+ SCENARIO: export+ run: |+ sudo -E bash scripts/linux-desktop-harness/run-desktop.sh gnome "$RUNNER_TEMP/cap.deb" \+ "$RUNNER_TEMP/out/gnome-export" LAUNCH=dock APPROVE_SHORTCUT_AFTER=6+ cat "$RUNNER_TEMP/out/gnome-export/result.txt"+ for line in recorded=yes mp4_exported=yes mp4_has_video=yes mp4_cap_alive=yes gif_exported=yes \+ gif_has_video=yes gif_cap_alive=yes; do+ grep -qx "$line" "$RUNNER_TEMP/out/gnome-export/result.txt"+ done+- name: Check resultsrun: |bash scripts/linux-desktop-harness/check-results.sh \@@ -358,6 +390,16 @@ jobs:bash scripts/linux-desktop-harness/x11-camera.sh "$RUNNER_TEMP/build/cap-gpui" "$RUNNER_TEMP/build/libs" \"$RUNNER_TEMP/out/x11-camera"+ - name: Hyprland area recording+ run: |+ sudo -E env DEV_BIN="$RUNNER_TEMP/build/cap-gpui" DEV_LIBS="$RUNNER_TEMP/build/libs" \+ bash scripts/linux-desktop-harness/run-desktop.sh hyprland "$RUNNER_TEMP/build/cap-gpui" \+ "$RUNNER_TEMP/out/hyprland-area" LAUNCH=dock AREA=200,150,800,450+ cat "$RUNNER_TEMP/out/hyprland-area/result.txt"+ for line in attempt1_finished=yes area_video=yes panics=0; do+ grep -qx "$line" "$RUNNER_TEMP/out/hyprland-area/result.txt"+ done+- name: Hyprland clipboard (Ctrl+V into and Ctrl+C out of a text field)env:SCENARIO: clipboarddiff --git a/apps/desktop-gpui/src/devices.rs b/apps/desktop-gpui/src/devices.rsindex c2fa1cf56..745d9d46b 100644--- a/apps/desktop-gpui/src/devices.rs+++ b/apps/desktop-gpui/src/devices.rs@@ -990,6 +990,11 @@ fn linux_window_targets_from_snapshot() -> Option<Vec<(WindowOption, Window)>> {if app == "Window Server" {return None;}+ // As on macOS: recording one of our own windows records a+ // window the recording hides.+ if snapshot.owner_pid == Some(std::process::id()) {+ return None;+ }Some((WindowOption {id,diff --git a/apps/desktop-gpui/src/editor_export.rs b/apps/desktop-gpui/src/editor_export.rsindex dc66a8375..e3c53ce48 100644--- a/apps/desktop-gpui/src/editor_export.rs+++ b/apps/desktop-gpui/src/editor_export.rs@@ -2736,6 +2736,7 @@ async fn confirm_export_resources(let result = async {let warning = check.map_err(|error| error.to_string())??;if let Some(message) = warning {+ tracing::info!(%message, "export waits for the user to confirm its resources");#[cfg(target_os = "linux")]let confirmed = {let response = loop {diff --git a/apps/desktop-gpui/src/main_window.rs b/apps/desktop-gpui/src/main_window.rsindex 7c01b3167..48989b3b0 100644--- a/apps/desktop-gpui/src/main_window.rs+++ b/apps/desktop-gpui/src/main_window.rs@@ -2001,6 +2001,9 @@ impl MainWindow {self.set_microphone_selection(None, cx);}let required_window = auto_window_title();+ // Pause and stop go to the session: on Linux the main window is not+ // there while a window or Instant recording runs.+ let session = self.session.clone();cx.spawn_in(window, async move |this, cx| {// Give enumeration and the first paint a moment; the recorder@@ -2126,18 +2129,14 @@ impl MainWindow {}let third = std::time::Duration::from_secs(record_secs.div_ceil(3));- let toggle = |this: &gpui::WeakEntity<Self>, cx: &mut gpui::AsyncWindowContext| {- this.update_in(cx, |this, _, cx| {- this.session- .update(cx, |session, cx| session.toggle_pause(cx));- })- .ok();+ let toggle = |cx: &gpui::AsyncApp| {+ cx.update(|cx| session.update(cx, |session, cx| session.toggle_pause(cx)));};if pause_wiggle {cx.background_executor().timer(third).await;- toggle(&this, cx);+ toggle(cx);cx.background_executor().timer(third).await;- toggle(&this, cx);+ toggle(cx);cx.background_executor().timer(third).await;} else {cx.background_executor()@@ -2145,10 +2144,8 @@ impl MainWindow {.await;}tracing::info!("auto-record stop requested");- this.update_in(cx, |this, _, cx| {- this.session.update(cx, |session, cx| session.stop(cx));- })- .ok();+ let app: &gpui::AsyncApp = cx;+ app.update(|cx| session.update(cx, |session, cx| session.stop(cx)));}).detach();}diff --git a/scripts/linux-desktop-harness/README.md b/scripts/linux-desktop-harness/README.mdindex be35930e3..168ff44c2 100644--- a/scripts/linux-desktop-harness/README.md+++ b/scripts/linux-desktop-harness/README.md@@ -64,6 +64,11 @@ with a PNG first, as Omarchy does on Hyprland.`SCENARIO=register` launches Cap from a shell `ROUNDS` times, each time oncewith its `so.cap.Cap.desktop` entry removed and once with it in place, andcounts the launches that registered the app id with the portals.+`AREA=x,y,width,height` makes the start-stop scenario record that area of the+display and check the video is its size.+`SCENARIO=export` records a clip, opens it in the editor and exports it to an+MP4 and to a GIF (`CAP_GPUI_AUTO_EXPORT`), checking the length each file+declares.`report.sh <out-dir>` prints the results with Cap's own log lines. TheHyprland image needs `modprobe vkms` on the host. With `GNOME_UNSAFE=1`,@@ -84,6 +89,13 @@ real login activates.display track, about five seconds, and fails if any result is missing. Itneeds root for modprobe, and runs in the Hyprland job, whose hosted runnercan build the module.+- `x11-capture.sh <cap-gpui> <ffmpeg lib dir> <out-dir>` records the display,+ an area and another app's window on Xvfb (MIT-SHM capture, no portal),+ pressing the Stop shortcut with real X input where Cap waits for it, records+ the microphone and system audio from a tone a private PulseAudio plays, takes+ a screenshot, and checks the size, length and loudness of each result. It also+ checks the window picker offers the other app's window rather than one of+ Cap's own.- `niri-screencast/run.sh` records through Cap's PipeWire capture loop from aproducer that negotiates and shares frames the way niri 26.04 does: adiff --git a/scripts/linux-desktop-harness/scenario-export.sh b/scripts/linux-desktop-harness/scenario-export.shnew file mode 100755index 000000000..d73efcf77--- /dev/null+++ b/scripts/linux-desktop-harness/scenario-export.sh@@ -0,0 +1,111 @@+#!/usr/bin/env bash+set -uo pipefail+here=$(cd "$(dirname "$0")" && pwd)+export XDG_RUNTIME_DIR=/run/user/$(id -u)+export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus+out=${HARNESS_OUT:-/out}++bash "$here/scenario-start-stop.sh" >/dev/null+recorded=$(sed -n 's/^attempt1_finished=//p' "$out/result.txt")+mv "$out/result.txt" "$out/recording-result.txt"+: >"$out/result.txt"+result() { printf '%s=%s\n' "$1" "$2" >>"$out/result.txt"; }+result recorded "${recorded:-no}"+[[ $recorded == yes ]] || exit 0++eval "$(systemctl --user show-environment | grep -E "^(WAYLAND_DISPLAY|XDG_SESSION_TYPE|XDG_CURRENT_DESKTOP|XDG_SESSION_DESKTOP|LIBGL_ALWAYS_SOFTWARE|HYPRLAND_INSTANCE_SIGNATURE|NIRI_SOCKET)=" | sed 's/^/export /')"++mp4_seconds() {+ python3 - "$1" <<'PY'+import struct+import sys++data = open(sys.argv[1], "rb").read()+++def boxes(start, end):+ while start + 8 <= end:+ size, kind = struct.unpack(">I4s", data[start : start + 8])+ header = 8+ if size == 1:+ size = struct.unpack(">Q", data[start + 8 : start + 16])[0]+ header = 16+ elif size == 0:+ size = end - start+ if size < header:+ return+ yield kind, start + header, start + size+ start += size+++for kind, body, end in boxes(0, len(data)):+ if kind != b"moov":+ continue+ for inner, inner_body, _ in boxes(body, end):+ if inner == b"mvhd":+ version = data[inner_body]+ if version == 1:+ scale, duration = struct.unpack(">IQ", data[inner_body + 20 : inner_body + 32])+ else:+ scale, duration = struct.unpack(">II", data[inner_body + 12 : inner_body + 20])+ if scale:+ print(f"{duration / scale:.2f}")+PY+}++# The encoder merges identical frames into longer ones, so a GIF's length is+# the sum of its frame delays.+gif_frames_and_seconds() {+ python3 - "$1" <<'PY'+import sys++data = open(sys.argv[1], "rb").read()+if data[:6] in (b"GIF87a", b"GIF89a"):+ frames, centiseconds, at = 0, 0, data.find(b"\x21\xf9\x04")+ while at != -1 and at + 6 <= len(data):+ frames += 1+ centiseconds += data[at + 4] | data[at + 5] << 8+ at = data.find(b"\x21\xf9\x04", at + 8)+ print(frames, f"{centiseconds / 100:.2f}")+PY+}++# An export holds the whole clip: its length is the recording's, give or take+# half a second.+matches_source() {+ awk -v s="$1" -v want="${source_seconds:-0}" 'BEGIN { d = s - want; if (d < 0) d = -d; print (want >= 1 && d <= 0.5 ? "yes" : "no") }'+}++export_once() {+ local kind=$1 file=$out/export.$1 name=cap-$1+ bash "$here/launch-cap.sh" "$name" CAP_GPUI_AUTO_EDITOR=1 CAP_GPUI_AUTO_EXPORT="$file" >/dev/null+ local done=""+ for _ in $(seq 720); do+ done=$(sed 's/\x1b\[[0-9;]*m//g' "$out/$name.log" 2>/dev/null |+ grep -aoE "editor export completed|editor export failed.*|export waits for the user to confirm.*|panicked at.*" | head -1)+ [[ -n $done ]] && break+ sleep 0.25+ done+ echo "$kind: ${done:-no export line}" >>"$out/actions.log"+ result "${kind}_exported" "$([[ $done == "editor export completed" ]] && echo yes || echo no)"+ if [[ $kind == mp4 ]]; then+ local seconds+ seconds=$(mp4_seconds "$file" 2>/dev/null)+ echo "mp4 seconds: ${seconds:-none}, bytes: $(stat -c %s "$file" 2>/dev/null)" >>"$out/actions.log"+ result mp4_has_video "$(matches_source "${seconds:-0}")"+ else+ local frames seconds+ read -r frames seconds < <(gif_frames_and_seconds "$file" 2>/dev/null)+ echo "gif frames: ${frames:-none}, seconds: ${seconds:-none}, bytes: $(stat -c %s "$file" 2>/dev/null)" >>"$out/actions.log"+ result gif_has_video "$(matches_source "${seconds:-0}")"+ fi+ result "${kind}_cap_alive" "$(kill -0 "$(cat "$XDG_RUNTIME_DIR/$name.pid" 2>/dev/null)" 2>/dev/null && echo yes || echo no)"+ kill "$(cat "$XDG_RUNTIME_DIR/$name.pid" 2>/dev/null)" 2>/dev/null+ sleep 2+}++source_seconds=$(mp4_seconds "$(find "$out/profile/recordings" -path "*segment-0/display.mp4" | head -1)" 2>/dev/null)+echo "recording seconds: ${source_seconds:-none}" >>"$out/actions.log"+export_once mp4+export_once gif+cat "$out/result.txt"diff --git a/scripts/linux-desktop-harness/scenario-start-stop.sh b/scripts/linux-desktop-harness/scenario-start-stop.shindex 1335d3d37..7264bc8a7 100644--- a/scripts/linux-desktop-harness/scenario-start-stop.sh+++ b/scripts/linux-desktop-harness/scenario-start-stop.sh@@ -6,7 +6,7 @@## Env: HARNESS_OUT, LAUNCH (dock|terminal), RECORD_MODE (studio|instant),# PRESS_AFTER (seconds; with no tray item by then, press the shortcut),-# TRAY_CLICK (host|pointer).+# TRAY_CLICK (host|pointer), AREA (x,y,width,height).set -uo pipefailhere=$(cd "$(dirname "$0")" && pwd)export XDG_RUNTIME_DIR=/run/user/$(id -u)@@ -174,7 +174,9 @@ if [[ ${TRAY_CLICK:-host} == pointer || ${GNOME_TRAY:-1} == 0 ]]; thenread -r -t 10 ready <&"${POINTER[0]}"echo "$ready" >>"$out/actions.log"fi-pid=$("$here/launch-cap.sh" cap CAP_GPUI_AUTO_RECORD="$mode:${AUTO_STOP_SECS:-900}" CAP_GPUI_AUTO_OVERLAY=display)+target=(CAP_GPUI_AUTO_OVERLAY=display)+[[ -n ${AREA:-} ]] && target=(CAP_GPUI_AUTO_OVERLAY=area CAP_GPUI_AUTO_AREA="$AREA")+pid=$("$here/launch-cap.sh" cap CAP_GPUI_AUTO_RECORD="$mode:${AUTO_STOP_SECS:-900}" "${target[@]}")attempt 1result cap_alive "$(kill -0 "$pid" 2>/dev/null && echo yes || echo no)"@@ -190,6 +192,23 @@ result pipeline_failed "$(count 'recording pipeline failed')"crashes="$out/profile/logs/cap-gpui.log.crashes"result panics "$(( $(count 'panicked at\|cap_desktop_panic\|panic location') + $(grep -E 'panic thread=|native crash' "$crashes" 2>/dev/null | wc -l) ))"result projects "$(find "$out/profile/recordings" -maxdepth 1 -name '*.cap' | wc -l)"+if [[ -n ${AREA:-} ]]; then+ video=$(find "$out/profile/recordings" -path "*segment-0/display.mp4" | head -1)+ size=""+ [[ -n $video ]] && size=$(python3 -c 'import struct, sys+data = open(sys.argv[1], "rb").read()+at = data.find(b"tkhd")+while at != -1:+ body = at + 4+ width, height = struct.unpack(">II", data[body + (88 if data[body] == 1 else 76) :][:8])+ if width and height:+ print(width >> 16, height >> 16)+ break+ at = data.find(b"tkhd", at + 4)' "$video")+ echo "area video: ${video:-none} ${size:-}" >>"$out/actions.log"+ IFS=, read -r _ _ area_width area_height <<<"$AREA"+ result area_video "$([[ $size == "$area_width $area_height" ]] && echo yes || echo no)"+fikill "$pid" 2>/dev/nullsleep 1cat "$out/result.txt"diff --git a/scripts/linux-desktop-harness/x11-capture.sh b/scripts/linux-desktop-harness/x11-capture.shnew file mode 100755index 000000000..b64ec0850--- /dev/null+++ b/scripts/linux-desktop-harness/x11-capture.sh@@ -0,0 +1,227 @@+#!/usr/bin/env bash+# Usage: x11-capture.sh <cap-gpui> <ffmpeg lib dir> <out-dir>+set -uo pipefail+for tool in Xvfb xdotool xmessage pulseaudio pactl paplay ffmpeg; do+ command -v "$tool" >/dev/null ||+ { echo "install xvfb, xdotool, x11-utils, pulseaudio, pulseaudio-utils and ffmpeg" >&2; exit 2; }+done+if [[ -z ${X11_CAPTURE_BUS:-} ]]; then+ exec env X11_CAPTURE_BUS=1 dbus-run-session -- bash "$0" "$@"+fi+bin=$1 libs=$2 out=$3+mkdir -p "$out" && : >"$out/result.txt" || { echo "x11-capture: cannot write to $out" >&2; exit 2; }+result() { printf '%s=%s\n' "$1" "$2" >>"$out/result.txt"; }+unset WAYLAND_DISPLAY+export DISPLAY=:79 XDG_SESSION_TYPE=x11+Xvfb "$DISPLAY" -screen 0 1920x1080x24 >/dev/null 2>&1 &+xvfb=$!+sleep 1+xmessage -geometry 480x270+700+300 -title "Window to record" "A window to record" >/dev/null 2>&1 &+other=$!++pulse_dir=$(mktemp -d)+export PULSE_SERVER=unix:$pulse_dir/native+pulseaudio -n --daemonize=no --exit-idle-time=-1 --log-target=stderr \+ -L "module-native-protocol-unix socket=$pulse_dir/native auth-anonymous=1" \+ -L "module-null-sink sink_name=cap_tone" \+ -L "module-remap-source master=cap_tone.monitor source_name=cap_mic" >"$out/pulse.log" 2>&1 &+pulse=$!+for _ in $(seq 40); do pactl info >/dev/null 2>&1 && break; sleep 0.25; done+pactl set-default-sink cap_tone+pactl set-default-source cap_mic+python3 - "$out/tone.wav" <<'PY'+import math+import struct+import sys+import wave++rate = 48000+with wave.open(sys.argv[1], "wb") as tone:+ tone.setnchannels(2)+ tone.setsampwidth(2)+ tone.setframerate(rate)+ tone.writeframes(b"".join(+ struct.pack("<hh", sample, sample)+ for sample in (int(12000 * math.sin(2 * math.pi * 440 * n / rate)) for n in range(rate * 30))+ ))+PY+(while paplay --device=cap_tone "$out/tone.wav"; do :; done) &+player=$!+trap 'pkill -P $player 2>/dev/null; kill $player $pulse $other $xvfb 2>/dev/null' EXIT++mp4_info() {+ python3 - "$1" <<'PY'+import struct+import sys++data = open(sys.argv[1], "rb").read()+++def boxes(start, end):+ while start + 8 <= end:+ size, kind = struct.unpack(">I4s", data[start : start + 8])+ header = 8+ if size == 1:+ size = struct.unpack(">Q", data[start + 8 : start + 16])[0]+ header = 16+ elif size == 0:+ size = end - start+ if size < header:+ return+ yield kind, start + header, start + size+ start += size+++seconds = width = height = None+for kind, body, end in boxes(0, len(data)):+ if kind != b"moov":+ continue+ for inner, inner_body, inner_end in boxes(body, end):+ if inner == b"mvhd":+ if data[inner_body] == 1:+ scale, duration = struct.unpack(">IQ", data[inner_body + 20 : inner_body + 32])+ else:+ scale, duration = struct.unpack(">II", data[inner_body + 12 : inner_body + 20])+ seconds = duration / scale if scale else None+ if inner == b"trak" and width is None:+ for track, track_body, _ in boxes(inner_body, inner_end):+ if track == b"tkhd":+ offset = track_body + (88 if data[track_body] == 1 else 76)+ w, h = struct.unpack(">II", data[offset : offset + 8])+ if w and h:+ width, height = w >> 16, h >> 16+if seconds is not None:+ print(f"{seconds:.2f} {width} {height}")+PY+}++png_size() {+ python3 -c 'import struct, sys+data = open(sys.argv[1], "rb").read(24)+if data[:8] == b"\x89PNG\r\n\x1a\n":+ print(*struct.unpack(">II", data[16:24]))' "$1"+}++launch() {+ local name=$1; shift+ local profile=$out/$name+ mkdir -p "$profile/recordings" "$profile/logs"+ printf '%s' '{"general_settings":{"hasCompletedStartup":true,"hasCompletedOnboarding":true,"enableNotifications":false,"enableTelemetry":false,"recordingCountdown":0},"recording_start_safety":{"confirmBeforeRecordingWithoutMicrophone":false}}' >"$profile/store"+ env LD_LIBRARY_PATH="$libs" CAP_GPUI_APP_DATA_DIR="$profile" CAP_GPUI_RECORDINGS_DIR="$profile/recordings" \+ CAP_GPUI_LOG_DIR="$profile/logs" CAP_GPUI_NO_TRAY=1 CAP_GPUI_AUTO_NO_MIC=1 RUST_LOG=info "$@" \+ "$bin" >"$profile/cap.log" 2>&1 &+ echo $! >"$profile/pid"+}++wait_log() {+ local log=$1 pattern=$2 seconds=$3+ for _ in $(seq $((seconds * 4))); do+ grep -aq -- "$pattern" "$log" 2>/dev/null && return 0+ sleep 0.25+ done+ return 1+}++finish() {+ local name=$1 pid+ pid=$(cat "$out/$name/pid")+ result "${name}_cap_alive" "$(kill -0 "$pid" 2>/dev/null && echo yes || echo no)"+ result "${name}_panics" "$(grep -ac 'panicked at' "$out/$name/cap.log")"+ kill "$pid" 2>/dev/null+ for _ in $(seq 20); do kill -0 "$pid" 2>/dev/null || break; sleep 0.25; done+ kill -9 "$pid" 2>/dev/null+}++record() {+ local name=$1 want_width=$2 want_height=$3 shortcut=$4; shift 4+ local log=$out/$name/cap.log+ launch "$name" "$@"+ if [[ $shortcut == yes ]]; then+ wait_log "$log" "auto-record start requested" 30+ sleep 2+ xdotool key ctrl+shift+F9+ fi+ local started=no finished=no+ wait_log "$log" "recording started" 20 && started=yes+ if [[ $started == yes && $shortcut == yes ]]; then+ sleep 4+ xdotool key ctrl+shift+F9+ fi+ # Well before the 60 s automatic stop of the shortcut cases, so a Stop+ # shortcut that does not work fails here.+ wait_log "$log" "recording finished" 15 && finished=yes+ sleep 2+ result "${name}_started" "$started"+ result "${name}_finished" "$finished"+ local project video info+ project=$(find "$out/$name/recordings" -maxdepth 1 -name "*.cap" | head -1)+ # A finish keeps its recovery workspace by design; the backup of the media+ # it replaced must be gone.+ result "${name}_backup_left" "$(find "$out/$name/recordings" -path '*/.recovery-*/original-segments' 2>/dev/null | wc -l)"+ video=$(find "${project:-/nonexistent}" -path "*segment-0/display.mp4" 2>/dev/null | head -1)+ info=$( [[ -n $video ]] && mp4_info "$video")+ echo "$name: ${video:-no display.mp4} ${info:-}" >>"$out/actions.log"+ read -r seconds width height <<<"${info:-0 0 0}"+ result "${name}_video" "$(awk -v s="$seconds" -v w="$width" -v h="$height" -v W="$want_width" -v H="$want_height" \+ 'BEGIN { print (s >= 3 && s <= 10 && w == W && h == H ? "yes" : "no") }')"+ finish "$name"+}++record display 1920 1080 yes CAP_GPUI_AUTO_RECORD=studio:60+record area 640 360 yes CAP_GPUI_AUTO_RECORD=studio:60 CAP_GPUI_AUTO_OVERLAY=area CAP_GPUI_AUTO_AREA=100,100,640,360+record window 480 270 no CAP_GPUI_AUTO_RECORD=studio:6 CAP_GPUI_AUTO_OVERLAY=window \+ CAP_GPUI_AUTO_WINDOW="Window to record"+record audio 480 270 no CAP_GPUI_AUTO_RECORD=studio:6 CAP_GPUI_AUTO_OVERLAY=window \+ CAP_GPUI_AUTO_WINDOW="Window to record" CAP_GPUI_AUTO_NO_MIC=0 CAP_GPUI_AUTO_SYSTEM_AUDIO=1+# Both tracks span the recording: as long as its video, give or take half a+# second.+audio_video=$(find "$out/audio/recordings" -path "*segment-0/display.mp4" 2>/dev/null | head -1)+read -r audio_video_seconds _ <<<"$( [[ -n $audio_video ]] && mp4_info "$audio_video")"+for track in audio-input system_audio; do+ file=$(find "$out/audio/recordings" -path "*segment-0/$track.m4a" 2>/dev/null | head -1)+ seconds=0 level=-91+ if [[ -n $file ]]; then+ read -r seconds _ <<<"$(mp4_info "$file")"+ level=$(ffmpeg -hide_banner -nostats -i "$file" -af volumedetect -f null - 2>&1 |+ sed -n 's/.*mean_volume: \(-\{0,1\}[0-9.]*\) dB.*/\1/p')+ fi+ echo "audio $track: ${file:-missing} seconds=${seconds:-0} mean_volume=${level:--91}" >>"$out/actions.log"+ result "audio_${track//-/_}" "$(awk -v s="${seconds:-0}" -v want="${audio_video_seconds:-0}" -v v="${level:--91}" \+ 'BEGIN { d = s - want; if (d < 0) d = -d; print (want >= 3 && d <= 0.5 && v > -40 ? "yes" : "no") }')"+done++# With no title to match, the picker's first window must be the other app's:+# Cap's own windows are not offered.+launch picker CAP_GPUI_AUTO_OVERLAY=window+wait_log "$out/picker/cap.log" "auto window target" 30+picked=$(sed 's/\x1b\[[0-9;]*m//g' "$out/picker/cap.log" | grep -a "auto window target" | head -1)+echo "picker: ${picked:-no window picked}" >>"$out/actions.log"+result picker_offers_other_app "$([[ $picked == *'title=Window to record'* ]] && echo yes || echo no)"+finish picker++launch screenshot CAP_GPUI_AUTO_RECORD=screenshot+shot=""+for _ in $(seq 80); do+ shot=$(find "$out/screenshot" -path "*.cap/original.png" 2>/dev/null | head -1)+ [[ -n $shot ]] && break+ sleep 0.25+done+sleep 1+size=$( [[ -n $shot ]] && png_size "$shot")+echo "screenshot: ${shot:-none} ${size:-}" >>"$out/actions.log"+result screenshot_png "$([[ $size == "1920 1080" ]] && echo yes || echo no)"+finish screenshot++cat "$out/result.txt"+failed=0+for key in display_finished area_finished window_finished audio_finished display_video area_video window_video \+ audio_video audio_audio_input audio_system_audio picker_offers_other_app screenshot_png; do+ grep -q "^$key=" "$out/result.txt" || { echo "x11-capture: no $key result" >&2; failed=1; }+done+while IFS== read -r key value; do+ case $key in+ *_panics | *_backup_left) [[ $value == 0 ]] || failed=1 ;;+ *) [[ $value == yes ]] || failed=1 ;;+ esac+done <"$out/result.txt"+exit $failed