Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(recording): add fallback audio config when no output device available on Windows

Richie McIlroycb4111f1f018
diff --git a/crates/recording/src/sources/screen_capture/windows.rs b/crates/recording/src/sources/screen_capture/windows.rs
index 5bbd7138a..56d4930db 100644
--- a/crates/recording/src/sources/screen_capture/windows.rs
+++ b/crates/recording/src/sources/screen_capture/windows.rs
@@ -42,8 +42,24 @@ impl ScreenCaptureFormat for Direct3DCapture {
fn audio_info() -> AudioInfo {
let host = cpal::default_host();
- let output_device = host.default_output_device().unwrap();
- let supported_config = output_device.default_output_config().unwrap();
+ let Some(output_device) = host.default_output_device() else {
+ warn!("No default audio output device available, using fallback audio config");
+ return AudioInfo::new(
+ ffmpeg::format::Sample::F32(ffmpeg::format::sample::Type::Packed),
+ 48_000,
+ 2,
+ )
+ .expect("fallback audio config");
+ };
+ let Ok(supported_config) = output_device.default_output_config() else {
+ warn!("Failed to get default output config, using fallback audio config");
+ return AudioInfo::new(
+ ffmpeg::format::Sample::F32(ffmpeg::format::sample::Type::Packed),
+ 48_000,
+ 2,
+ )
+ .expect("fallback audio config");
+ };
let mut info = AudioInfo::from_stream_config(&supported_config);
let sample_format = info.sample_format;