Add native Windows capture backend

This commit is contained in:
Alvin-Zilverstand committed 2026-09-10 08:52:03 +02:00
1 parent 2b465a3555
commit a89e61ed95
9 files changed
+800 -21

No files matched your search

+69 -4
View File
@@ -365,6 +365,7 @@ dependencies = [
"serde",
"serde_json",
"sysinfo",
"windows-capture",
]
[[package]]
@@ -4570,11 +4571,36 @@ version = "0.61.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9babd3a767a4c1aef6900409f85f5d53ce2544ccdfaa86dad48c91782c6d6893"
dependencies = [
"windows-collections",
"windows-collections 0.2.0",
"windows-core 0.61.2",
"windows-future",
"windows-future 0.2.1",
"windows-link 0.1.3",
"windows-numerics",
"windows-numerics 0.2.0",
]
[[package]]
name = "windows"
version = "0.62.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580"
dependencies = [
"windows-collections 0.3.2",
"windows-core 0.62.2",
"windows-future 0.3.2",
"windows-numerics 0.3.1",
]
[[package]]
name = "windows-capture"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09046acbe9b6d039cde50e8c8178d95bb0f9b33ed7feccc4465dadc5404b31b4"
dependencies = [
"parking_lot",
"rayon",
"thiserror 2.0.20",
"windows 0.62.2",
"windows-future 0.3.2",
]
[[package]]
@@ -4586,6 +4612,15 @@ dependencies = [
"windows-core 0.61.2",
]
[[package]]
name = "windows-collections"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610"
dependencies = [
"windows-core 0.62.2",
]
[[package]]
name = "windows-core"
version = "0.57.0"
@@ -4632,7 +4667,18 @@ checksum = "fc6a41e98427b19fe4b73c550f060b59fa592d7d686537eebf9385621bfbad8e"
dependencies = [
"windows-core 0.61.2",
"windows-link 0.1.3",
"windows-threading",
"windows-threading 0.1.0",
]
[[package]]
name = "windows-future"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb"
dependencies = [
"windows-core 0.62.2",
"windows-link 0.2.1",
"windows-threading 0.2.1",
]
[[package]]
@@ -4701,6 +4747,16 @@ dependencies = [
"windows-link 0.1.3",
]
[[package]]
name = "windows-numerics"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26"
dependencies = [
"windows-core 0.62.2",
"windows-link 0.2.1",
]
[[package]]
name = "windows-result"
version = "0.1.2"
@@ -4822,6 +4878,15 @@ dependencies = [
"windows-link 0.1.3",
]
[[package]]
name = "windows-threading"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37"
dependencies = [
"windows-link 0.2.1",
]
[[package]]
name = "windows-version"
version = "0.1.7"
+53 -4
View File
@@ -17,6 +17,7 @@ use clipforge::media::{
trim_clip as ffmpeg_trim_clip,
};
use clipforge::models::{Clip, ClipSource, GameEvent, RecordingStatus};
use clipforge::native_wgc::NativeWgcReplayCaptureBackend;
use clipforge::recorder::{RecorderAction, RecorderService};
use clipforge::settings::{load_or_create_settings, save_settings};
use clipforge::storage::{clip_path, is_inside_root, LibraryPaths};
@@ -44,13 +45,33 @@ struct AppRuntime {
valve_events: Mutex<Vec<RawGameEvent>>,
}
#[derive(Debug)]
struct ActiveCapture {
buffer_dir: PathBuf,
session_output_path: PathBuf,
segment_duration: Duration,
started_at: SystemTime,
backend: FfmpegReplayCaptureBackend,
backend: ActiveCaptureBackend,
}
enum ActiveCaptureBackend {
Ffmpeg(FfmpegReplayCaptureBackend),
NativeWgc(NativeWgcReplayCaptureBackend),
}
impl ActiveCaptureBackend {
fn name(&self) -> &'static str {
match self {
Self::Ffmpeg(backend) => backend.name(),
Self::NativeWgc(backend) => backend.name(),
}
}
fn stop(&mut self) -> Result<(), clipforge::capture::CaptureError> {
match self {
Self::Ffmpeg(backend) => backend.stop(),
Self::NativeWgc(backend) => backend.stop(),
}
}
}
#[derive(Debug, Serialize)]
@@ -64,6 +85,7 @@ struct DesktopStatus {
upload_enabled: bool,
session_recording: bool,
capture_active: bool,
capture_backend: Option<String>,
capture_path: Option<String>,
clip_count: usize,
library_root: String,
@@ -457,8 +479,13 @@ fn start_capture_inner(runtime: &AppRuntime) -> Result<DesktopStatus, String> {
system_audio_device: recorder.settings.privacy.system_audio_device.clone(),
mic_device: recorder.settings.privacy.mic_device.clone(),
};
let mut backend = FfmpegReplayCaptureBackend::new(ffmpeg, &segment_pattern, segment_duration);
backend.start(config).map_err(|error| error.to_string())?;
let backend = start_best_capture_backend(
&ffmpeg,
&segment_pattern,
segment_duration,
config,
system_audio_enabled || recorder.settings.privacy.mic_enabled,
)?;
*capture = Some(ActiveCapture {
buffer_dir,
session_output_path,
@@ -845,6 +872,27 @@ fn add_session_clip(
Ok(clip)
}
fn start_best_capture_backend(
ffmpeg: &std::path::Path,
segment_pattern: &std::path::Path,
segment_duration: Duration,
config: CaptureConfig,
needs_ffmpeg_audio: bool,
) -> Result<ActiveCaptureBackend, String> {
if !needs_ffmpeg_audio {
let mut native = NativeWgcReplayCaptureBackend::new(segment_pattern, segment_duration);
if native.start(config.clone()).is_ok() {
return Ok(ActiveCaptureBackend::NativeWgc(native));
}
}
let mut ffmpeg_backend = FfmpegReplayCaptureBackend::new(ffmpeg, segment_pattern, segment_duration);
ffmpeg_backend
.start(config)
.map_err(|error| error.to_string())?;
Ok(ActiveCaptureBackend::Ffmpeg(ffmpeg_backend))
}
fn start_valve_gsi_receiver(app: tauri::AppHandle) {
thread::spawn(move || {
let Ok(listener) = TcpListener::bind("127.0.0.1:49321") else {
@@ -886,6 +934,7 @@ fn status_from_recorder(recorder: &RecorderService, capture: Option<&ActiveCaptu
upload_enabled: false,
session_recording: matches!(recorder.state.status, RecordingStatus::RecordingSession),
capture_active: capture.is_some(),
capture_backend: capture.map(|active| active.backend.name().to_string()),
capture_path: capture.map(|active| active.session_output_path.display().to_string()),
clip_count: recorder.library.all().len(),
library_root: recorder.paths.clip_root.display().to_string(),