fix #14740: report capture sources that die mid-recording
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -80,6 +80,10 @@ impl CaptureSource for PulseSource {
|
||||
thread.stop();
|
||||
}
|
||||
}
|
||||
|
||||
fn failure(&self) -> Option<String> {
|
||||
self.thread.as_ref().and_then(CaptureThread::failure)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for PulseSource {
|
||||
@@ -127,12 +131,13 @@ fn run(
|
||||
stop: &AtomicBool,
|
||||
ready: Ready,
|
||||
mut on_data: DataCallback,
|
||||
) {
|
||||
) -> Result<(), String> {
|
||||
let simple = match open(device, stream_name) {
|
||||
Ok(simple) => simple,
|
||||
Err(err) => {
|
||||
let reason = err.to_string();
|
||||
let _ = ready.send(Err(err));
|
||||
return;
|
||||
return Err(reason);
|
||||
}
|
||||
};
|
||||
let _ = ready.send(Ok(FORMAT));
|
||||
@@ -141,14 +146,15 @@ fn run(
|
||||
let mut samples = vec![0f32; CHUNK_SAMPLES];
|
||||
while !stop.load(Ordering::SeqCst) {
|
||||
if let Err(err) = simple.read(&mut bytes) {
|
||||
// Source gone (unplugged, server restart): stop delivering; the
|
||||
// recorder keeps the track aligned with silence.
|
||||
// Source gone (unplugged, server restart): stop delivering and
|
||||
// report it; the recorder keeps the track aligned with silence.
|
||||
log::warn!("PulseAudio capture '{stream_name}' ended: {err}");
|
||||
return;
|
||||
return Err(format!("PulseAudio: {err}"));
|
||||
}
|
||||
for (sample, raw) in samples.iter_mut().zip(bytes.as_chunks::<4>().0) {
|
||||
*sample = f32::from_ne_bytes(*raw);
|
||||
}
|
||||
on_data(&samples);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user