Skip to content

Commit 827504c

Browse files
committed
[*] add recording desktop speaker for windows(not testing)
1 parent eca3a55 commit 827504c

File tree

7 files changed

+345
-8
lines changed

7 files changed

+345
-8
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ winapi = "0.3"
9999
rubato = "0.16"
100100
fdk-aac = "0.8"
101101
memmap2 = "0.9"
102+
windows = "0.62"
102103
pipewire = "0.9"
103104
openh264 = "0.9"
104105
thiserror = "2.0"

lib/recorder/Cargo.toml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ description.workspace = true
1212

1313
[dependencies]
1414
log.workspace = true
15-
x264.workspace = true
1615
cpal.workspace = true
1716
mp4m.workspace = true
1817
hound.workspace = true
@@ -29,19 +28,28 @@ yuv = { workspace = true, features = ["rayon"] }
2928
fast_image_resize = { workspace = true, features = ["rayon"] }
3029

3130
[target.'cfg(target_os = "linux")'.dependencies]
31+
x264.workspace = true
3232
pipewire.workspace = true
3333
screen-capture-wayland-wlr = { workspace = true, optional = true }
3434
screen-capture-wayland-portal = { workspace = true, optional = true }
3535

3636
[target.'cfg(target_os = "windows")'.dependencies]
37-
screen-capture-windows = { workspace = true, optional = true }
37+
screen-capture-windows.workspace = true
38+
windows = { workspace = true, features = [
39+
"Win32_Media_Audio",
40+
"Win32_Media_Audio_Endpoints",
41+
"Win32_Media_Audio_Apo",
42+
"Win32_Media_KernelStreaming",
43+
"Win32_System_Com",
44+
"Win32_System_Ole",
45+
] }
3846

3947
[dev-dependencies]
4048
ctrlc.workspace = true
4149
env_logger.workspace = true
4250

4351
[features]
4452
default = ["wayland-wlr"]
45-
windows = ["dep:screen-capture-windows"]
53+
windows = []
4654
wayland-wlr = ["dep:screen-capture-wayland-wlr"]
4755
wayland-portal = ["dep:screen-capture-wayland-portal"]

lib/recorder/src/speaker_recorder.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,24 @@ use std::sync::{
99
#[cfg(target_os = "linux")]
1010
mod speaker_recorder_linux;
1111

12+
#[cfg(target_os = "windows")]
13+
mod speaker_recorder_windows;
14+
1215
#[derive(Debug, thiserror::Error)]
1316
pub enum SpeakerRecorderError {
17+
#[cfg(target_os = "linux")]
1418
#[error("Pipewire error: {0}")]
1519
PipewireError(String),
20+
21+
#[cfg(target_os = "windows")]
22+
#[error("WASAPI error: {0}")]
23+
WasapiError(String),
24+
25+
#[error("Audio device error: {0}")]
26+
DeviceError(String),
27+
28+
#[error("IO error: {0}")]
29+
IoError(#[from] std::io::Error),
1630
}
1731

1832
#[derive(Setters)]
@@ -56,5 +70,8 @@ pub fn platform_speaker_recoder(
5670
#[cfg(target_os = "linux")]
5771
let recoder = speaker_recorder_linux::SpeakerRecorderLinux::new(config);
5872

73+
#[cfg(target_os = "windows")]
74+
let recoder = speaker_recorder_windows::SpeakerRecorderWindows::new(config);
75+
5976
recoder
6077
}

lib/recorder/src/speaker_recorder/speaker_recorder_linux.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@ impl SpeakerRecorderLinux {
5454
Ok(recoder)
5555
}
5656

57-
// pub fn stop(&self) {
58-
// self.config.stop_sig.store(true, Ordering::Relaxed);
59-
// }
60-
6157
fn create_stream<'a>(&'a self) -> Result<StreamBox<'a>, SpeakerRecorderError> {
6258
let stream_props = pipewire::properties::properties! {
6359
"node.name" => "wayshot-speaker-recorder",

0 commit comments

Comments
 (0)