fix(call_capture): compile platform-gated Windows/Linux audio capture
Some checks are pending
CI / cargo check (linux) (push) Waiting to run
CI / cargo check (macos) (push) Waiting to run
CI / cargo check (windows) (push) Waiting to run
CI / tsc + hotkey smoke (push) Waiting to run

Windows: cpal::Stream is !Send; wrap it in a SendStream newtype with a
documented unsafe impl Send so the global SESSIONS static is Sync (the WASAPI
stream is a control handle, access serialized via the mutex).

Linux: spa::pod::Pod::from_bytes returns Option, not Result — use ok_or_else
instead of map_err.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
David Perov 2026-06-22 12:16:02 +03:00
parent b005052763
commit d2750a031a

View file

@ -153,9 +153,19 @@ struct MacosAudioWriterState {
stream_description: AudioStreamBasicDescription,
}
#[cfg(target_os = "windows")]
/// Wraps a cpal `Stream`, which cpal marks `!Send` for cross-platform uniformity.
/// The WASAPI backend runs its audio work on a dedicated thread; the `Stream` itself
/// is a control handle that is sound to move and drop across threads. Access is
/// additionally serialized through the global `SESSIONS` mutex.
struct SendStream(cpal::Stream);
#[cfg(target_os = "windows")]
// SAFETY: see the SendStream doc comment above.
unsafe impl Send for SendStream {}
#[cfg(target_os = "windows")]
struct WindowsCallCaptureState {
stream: Option<cpal::Stream>,
stream: Option<SendStream>,
writer: Arc<Mutex<Option<SystemAudioWriter<BufWriter<File>>>>>,
device_name: String,
source_sample_rate: u32,
@ -1447,9 +1457,8 @@ fn run_linux_pipewire_capture(
.map_err(|err| linux_pipewire_error("Не удалось подготовить PipeWire audio format", err))?
.0
.into_inner();
let mut params = [spa::pod::Pod::from_bytes(&values).map_err(|err| {
linux_pipewire_error("Не удалось прочитать PipeWire audio format", err)
})?];
let mut params = [spa::pod::Pod::from_bytes(&values)
.ok_or_else(|| "Не удалось прочитать PipeWire audio format".to_string())?];
stream
.connect(
@ -1767,7 +1776,7 @@ fn start_windows_system_audio_capture(
);
Ok(Some(WindowsCallCaptureState {
stream: Some(stream),
stream: Some(SendStream(stream)),
writer,
device_name,
source_sample_rate,