mirror of
https://github.com/anomalyco/hex.git
synced 2026-11-22 01:54:19 +08:00
Automated fix from the Hex issue pipeline (run 681-2026-10-31t21-36-18-652z). Fixes #681 Co-authored-by: Hex issue pipeline <noreply@anoma.ly>
This commit is contained in:
co-authored by
Hex issue pipeline
parent
0fd8309805
commit
eef51da7e0
@@ -870,6 +870,10 @@ pub(crate) struct Sampler {
|
||||
pub stopping: Arc<AtomicBool>,
|
||||
pub urgent: Arc<AtomicBool>,
|
||||
pub frames: Arc<Mutex<CandidateBuffer>>,
|
||||
/// Why the screen source gave up before the stop (Linux: the portal's picker was cancelled
|
||||
/// or the stream never started), so the host can end the capture.
|
||||
#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
|
||||
pub failure: Arc<Mutex<Option<String>>>,
|
||||
/// Where the Windows recorder stores when its movie started (ms since `started_at`).
|
||||
#[cfg(target_os = "windows")]
|
||||
pub video_offset_ms: Arc<AtomicU64>,
|
||||
@@ -882,6 +886,7 @@ pub struct ScreenCaptureSession {
|
||||
stopping: Arc<AtomicBool>,
|
||||
urgent_snapshot: Arc<AtomicBool>,
|
||||
frames: Arc<Mutex<CandidateBuffer>>,
|
||||
failure: Arc<Mutex<Option<String>>>,
|
||||
sampler_thread: Option<JoinHandle<Option<Movie>>>,
|
||||
_recording: crate::retention::Recording,
|
||||
}
|
||||
@@ -918,6 +923,8 @@ impl ScreenCaptureSession {
|
||||
let thread_stopping = Arc::clone(&stopping);
|
||||
let thread_urgent = Arc::clone(&urgent_snapshot);
|
||||
let thread_frames = Arc::clone(&frames);
|
||||
let failure = Arc::new(Mutex::new(None));
|
||||
let thread_failure = Arc::clone(&failure);
|
||||
let sampler_target = target;
|
||||
let sampler_thread = thread::Builder::new()
|
||||
.name("scrawl-frame-sampler".into())
|
||||
@@ -933,6 +940,7 @@ impl ScreenCaptureSession {
|
||||
stopping: thread_stopping,
|
||||
urgent: thread_urgent,
|
||||
frames: thread_frames,
|
||||
failure: thread_failure,
|
||||
#[cfg(target_os = "windows")]
|
||||
video_offset_ms: Arc::new(AtomicU64::new(0)),
|
||||
})
|
||||
@@ -944,11 +952,21 @@ impl ScreenCaptureSession {
|
||||
stopping,
|
||||
urgent_snapshot,
|
||||
frames,
|
||||
failure,
|
||||
sampler_thread,
|
||||
_recording: crate::retention::Recording::start(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Why the screen source gave up before the stop, if it did: nothing more of the screen
|
||||
/// will be recorded.
|
||||
pub fn failure(&self) -> Option<String> {
|
||||
self.failure
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner)
|
||||
.clone()
|
||||
}
|
||||
|
||||
pub fn request_immediate_frame(&self) {
|
||||
self.urgent_snapshot.store(true, Ordering::Release);
|
||||
if let Some(ref handle) = self.sampler_thread {
|
||||
@@ -2790,6 +2808,15 @@ impl Capture {
|
||||
}
|
||||
}
|
||||
|
||||
/// Why the screen source gave up before the stop, if it did (Linux: the portal's picker
|
||||
/// was cancelled): the capture has nothing more to record.
|
||||
pub fn screen_failure(&self) -> Option<String> {
|
||||
match &self.source {
|
||||
InnerSource::Screen { session, .. } => session.failure(),
|
||||
InnerSource::Phone(_) => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn started_at_boot_ns(&self) -> u64 {
|
||||
self.t0_boot_ns
|
||||
}
|
||||
|
||||
@@ -246,6 +246,14 @@ pub(super) fn run_sampler(sampler: Sampler) -> Option<super::Movie> {
|
||||
Ok(movie) => movie,
|
||||
Err(error) => {
|
||||
scrawl_log(format!("Screen capture failed: {error:#}"));
|
||||
// The host ends the capture: nothing more of the screen will come.
|
||||
if !sampler.stopping.load(Ordering::Acquire) {
|
||||
*sampler
|
||||
.failure
|
||||
.lock()
|
||||
.unwrap_or_else(std::sync::PoisonError::into_inner) =
|
||||
Some(format!("{error:#}"));
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +85,11 @@ On Linux // capture.linux
|
||||
│ pass: radeonsi crashes past it)
|
||||
├── Reading movies back (keyframes, probe, audio) -> `ffmpeg`/`ffprobe`
|
||||
├── Missing PipeWire, ffmpeg, or a picker answer -> that capture fails with why
|
||||
│ └── The screen-share picker cancelled (or the stream never starting) after
|
||||
│ the capture started -> its collector notices within 100 ms, cancels
|
||||
│ it, and settles `failed`; the listener's next reap ends it, so the
|
||||
│ shortcut and dictation work again (#681). Check: capture_host
|
||||
│ a_screen_source_that_gives_up_ends_the_capture; not observed on GNOME
|
||||
├── Narration -> the listener's microphone through ListenerTimeline (each
|
||||
│ stream anchored to the monotonic clock); released-while-idle microphones
|
||||
│ open for the capture
|
||||
@@ -729,6 +734,7 @@ Checks:
|
||||
`finalize_capture_bundle_with_flags`, without a screen):
|
||||
`controls_are_idempotent_and_stop_writes_a_scrawl_bundle`,
|
||||
`an_engine_that_cannot_start_leaves_nothing_behind`,
|
||||
`a_screen_source_that_gives_up_ends_the_capture`,
|
||||
`scrawls_engine_claims_nothing_machine_wide`,
|
||||
`the_timeline_resamples_pads_gaps_and_ends_at_the_stop`,
|
||||
`a_pending_gap_and_a_stalled_tail_come_back_from_the_closed_sink`,
|
||||
|
||||
+98
-6
@@ -154,6 +154,9 @@ pub const SHORTCUT_DEBOUNCE: Duration = Duration::from_millis(400);
|
||||
/// Retention passes over the captures folder.
|
||||
const RETENTION_FIRST: Duration = Duration::from_secs(90);
|
||||
const RETENTION_EVERY: Duration = Duration::from_secs(60 * 60);
|
||||
/// How often a recording capture's collector looks whether its screen source
|
||||
/// gave up.
|
||||
const SCREEN_CHECK: Duration = Duration::from_millis(100);
|
||||
/// How long captures wait to try again after the host failed to start.
|
||||
const START_RETRY: Duration = Duration::from_secs(60);
|
||||
|
||||
@@ -301,6 +304,11 @@ trait Recording: Send {
|
||||
fn input(&self) -> Option<InputSink> {
|
||||
None
|
||||
}
|
||||
/// Why its screen source gave up before the stop (Linux: the portal's
|
||||
/// picker was cancelled), if it did: the capture then fails.
|
||||
fn failure(&self) -> Option<String> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// A stopped capture, waiting to be written.
|
||||
@@ -346,6 +354,10 @@ impl Recording for scrawl_capture::capture::Capture {
|
||||
fn input(&self) -> Option<InputSink> {
|
||||
Some(scrawl_capture::capture::Capture::input(self).clone())
|
||||
}
|
||||
|
||||
fn failure(&self) -> Option<String> {
|
||||
scrawl_capture::capture::Capture::screen_failure(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Sealed for scrawl_capture::capture::SealedCapture {
|
||||
@@ -1741,8 +1753,9 @@ impl CaptureHost {
|
||||
}
|
||||
}
|
||||
|
||||
/// Ends a capture whose engine failed to start: its collector exited on
|
||||
/// its own and settled the failure. Finishes an iPhone capture whose
|
||||
/// Ends a capture whose engine failed to start, or whose screen source
|
||||
/// gave up while it recorded: its collector exited on its own and
|
||||
/// settled the failure. Finishes an iPhone capture whose
|
||||
/// mirror ended on its own (unplugged, never found, or no camera
|
||||
/// access): what it recorded is written, or why it recorded nothing
|
||||
/// fails it.
|
||||
@@ -3272,14 +3285,36 @@ fn collect(
|
||||
}
|
||||
};
|
||||
let mut timeline = Timeline::new(t0);
|
||||
for chunk in chunks {
|
||||
let mut checked = Instant::now();
|
||||
loop {
|
||||
let chunk = match chunks.recv_timeout(SCREEN_CHECK) {
|
||||
Ok(chunk) => Some(chunk),
|
||||
Err(mpsc::RecvTimeoutError::Timeout) => None,
|
||||
Err(mpsc::RecvTimeoutError::Disconnected) => break,
|
||||
};
|
||||
match chunk {
|
||||
CaptureAudio::Samples {
|
||||
Some(CaptureAudio::Samples {
|
||||
samples,
|
||||
sample_rate,
|
||||
captured_through,
|
||||
} => timeline.push(&samples, sample_rate, captured_through),
|
||||
CaptureAudio::Gap { from, through } => timeline.gap(from, through),
|
||||
}) => timeline.push(&samples, sample_rate, captured_through),
|
||||
Some(CaptureAudio::Gap { from, through }) => timeline.gap(from, through),
|
||||
None => {}
|
||||
}
|
||||
// A screen source that gave up (the portal's picker cancelled) ends
|
||||
// the capture, as an engine that never started does: the listener's
|
||||
// next reap clears it, so dictation and the shortcut work again.
|
||||
if checked.elapsed() >= SCREEN_CHECK {
|
||||
checked = Instant::now();
|
||||
if let Some(error) = capture.failure() {
|
||||
tracing::error!(error, "the capture's screen source failed");
|
||||
input.detach(&bundle);
|
||||
drop(chunks);
|
||||
capture.cancel();
|
||||
remove_bundle(&bundle);
|
||||
lock(outcomes).fail(bundle, error);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
input.detach(&bundle);
|
||||
@@ -4114,6 +4149,63 @@ mod tests {
|
||||
fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
/// A screen source that gives up after the engine started (GNOME's
|
||||
/// screen-share picker cancelled) fails the capture on its own, so it
|
||||
/// no longer counts as recording and dictation works again (#681).
|
||||
#[test]
|
||||
fn a_screen_source_that_gives_up_ends_the_capture() {
|
||||
struct GivesUp;
|
||||
impl CaptureEngine for GivesUp {
|
||||
fn start(&self, start: Start) -> anyhow::Result<Box<dyn Recording>> {
|
||||
Ok(Box::new(GaveUp {
|
||||
dir: start.bundle_dir.unwrap(),
|
||||
}))
|
||||
}
|
||||
|
||||
fn phones(&self) -> anyhow::Result<Vec<String>> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
}
|
||||
struct GaveUp {
|
||||
dir: PathBuf,
|
||||
}
|
||||
impl Recording for GaveUp {
|
||||
fn cancel(self: Box<Self>) {
|
||||
let _ = fs::remove_dir_all(&self.dir);
|
||||
}
|
||||
|
||||
fn stop(self: Box<Self>) -> Box<dyn Sealed> {
|
||||
panic!("a capture whose screen gave up is never stopped")
|
||||
}
|
||||
|
||||
fn failure(&self) -> Option<String> {
|
||||
Some("the screen share was cancelled".into())
|
||||
}
|
||||
}
|
||||
|
||||
let dir = temp_dir("gave-up");
|
||||
let audio = FakeTimeline::default();
|
||||
let mut host = CaptureHost::with(Arc::new(GivesUp), Some(dir.clone())).unwrap();
|
||||
let bundle = report(host.control(ScrawlCaptureAction::Start, &audio))
|
||||
.bundle
|
||||
.unwrap();
|
||||
let last = wait_for_last(&mut host, &audio, &bundle, true);
|
||||
assert_eq!(last.stage, "failed");
|
||||
assert!(!bundle.exists());
|
||||
let mut recording = true;
|
||||
for _ in 0..500 {
|
||||
recording = host.recording_since(&audio).is_some();
|
||||
if !recording {
|
||||
break;
|
||||
}
|
||||
thread::sleep(Duration::from_millis(10));
|
||||
}
|
||||
assert!(!recording, "the failed capture still counts as recording");
|
||||
assert!(audio.open.lock().unwrap().is_none(), "the sink is closed");
|
||||
host.shutdown(&audio);
|
||||
fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scrawls_engine_claims_nothing_machine_wide() {
|
||||
let (events, _received) = mpsc::sync_channel(1);
|
||||
|
||||
Reference in New Issue
Block a user