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:
@@ -143,6 +143,10 @@ impl CaptureSource for WasapiSource {
|
||||
thread.stop();
|
||||
}
|
||||
}
|
||||
|
||||
fn failure(&self) -> Option<String> {
|
||||
self.thread.as_ref().and_then(CaptureThread::failure)
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for WasapiSource {
|
||||
@@ -243,24 +247,35 @@ fn open(endpoint: &Endpoint, format: Option<StreamFormat>) -> Result<Stream, Cap
|
||||
})
|
||||
}
|
||||
|
||||
fn run(endpoint: Endpoint, stop: &AtomicBool, ready: Ready, on_data: DataCallback) {
|
||||
fn run(
|
||||
endpoint: Endpoint,
|
||||
stop: &AtomicBool,
|
||||
ready: Ready,
|
||||
on_data: DataCallback,
|
||||
) -> Result<(), String> {
|
||||
if let Err(err) = initialize_mta().ok() {
|
||||
let _ = ready.send(Err(CaptureError::Backend(format!(
|
||||
"COM initialisation failed: {err}"
|
||||
))));
|
||||
return;
|
||||
let reason = format!("COM initialisation failed: {err}");
|
||||
let _ = ready.send(Err(CaptureError::Backend(reason.clone())));
|
||||
return Err(reason);
|
||||
}
|
||||
capture(&endpoint, stop, ready, on_data);
|
||||
let result = capture(&endpoint, stop, ready, on_data);
|
||||
// Every COM object is dropped by now.
|
||||
deinitialize();
|
||||
result
|
||||
}
|
||||
|
||||
fn capture(endpoint: &Endpoint, stop: &AtomicBool, ready: Ready, mut on_data: DataCallback) {
|
||||
fn capture(
|
||||
endpoint: &Endpoint,
|
||||
stop: &AtomicBool,
|
||||
ready: Ready,
|
||||
mut on_data: DataCallback,
|
||||
) -> Result<(), String> {
|
||||
let mut stream = match open(endpoint, None) {
|
||||
Ok(stream) => stream,
|
||||
Err(err) => {
|
||||
let reason = err.to_string();
|
||||
let _ = ready.send(Err(err));
|
||||
return;
|
||||
return Err(reason);
|
||||
}
|
||||
};
|
||||
let format = stream.format;
|
||||
@@ -279,7 +294,7 @@ fn capture(endpoint: &Endpoint, stop: &AtomicBool, ready: Ready, mut on_data: Da
|
||||
};
|
||||
if !is_device_invalidated(&err) || reopened {
|
||||
log::warn!("WASAPI capture '{label}' ended: {err}");
|
||||
return;
|
||||
return Err(format!("WASAPI: {err}"));
|
||||
}
|
||||
reopened = true;
|
||||
log::warn!("WASAPI capture '{label}': device invalidated, reopening the default device");
|
||||
@@ -288,10 +303,11 @@ fn capture(endpoint: &Endpoint, stop: &AtomicBool, ready: Ready, mut on_data: Da
|
||||
Ok(stream) => stream,
|
||||
Err(err) => {
|
||||
log::warn!("WASAPI capture '{label}': reopening failed: {err}");
|
||||
return;
|
||||
return Err(format!("device lost, reopening failed: {err}"));
|
||||
}
|
||||
};
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Delivers every packet currently queued in the capture buffer.
|
||||
|
||||
Reference in New Issue
Block a user