Add audio device selection
This commit is contained in:
1 parent
32a8aa4753
commit
2b465a3555
8 files changed
+192
-16
No files matched your search
@@ -0,0 +1,76 @@
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum AudioDeviceKind {
|
||||
Input,
|
||||
SystemLoopback,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct AudioDevice {
|
||||
pub name: String,
|
||||
pub kind: AudioDeviceKind,
|
||||
}
|
||||
|
||||
pub fn list_ffmpeg_dshow_audio_inputs(ffmpeg: &Path) -> Vec<AudioDevice> {
|
||||
let Ok(output) = Command::new(ffmpeg)
|
||||
.args([
|
||||
"-hide_banner",
|
||||
"-list_devices",
|
||||
"true",
|
||||
"-f",
|
||||
"dshow",
|
||||
"-i",
|
||||
"dummy",
|
||||
])
|
||||
.output()
|
||||
else {
|
||||
return Vec::new();
|
||||
};
|
||||
let combined = format!(
|
||||
"{}\n{}",
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
parse_dshow_audio_devices(&combined)
|
||||
}
|
||||
|
||||
pub fn parse_dshow_audio_devices(output: &str) -> Vec<AudioDevice> {
|
||||
output
|
||||
.lines()
|
||||
.filter_map(|line| {
|
||||
if !line.contains("\" (audio)") {
|
||||
return None;
|
||||
}
|
||||
let start = line.find('"')?;
|
||||
let rest = &line[start + 1..];
|
||||
let end = rest.find('"')?;
|
||||
Some(AudioDevice {
|
||||
name: rest[..end].to_string(),
|
||||
kind: AudioDeviceKind::Input,
|
||||
})
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn parses_dshow_audio_devices() {
|
||||
let output = r#"
|
||||
[in#0 @ 000001] "HP 5MP Camera" (video)
|
||||
[in#0 @ 000001] "Microfoon (Realtek(R) Audio)" (audio)
|
||||
[in#0 @ 000001] Alternative name "@device_cm_{...}"
|
||||
[in#0 @ 000001] "Headset (Crusher ANC 2)" (audio)
|
||||
"#;
|
||||
|
||||
let devices = parse_dshow_audio_devices(output);
|
||||
|
||||
assert_eq!(devices.len(), 2);
|
||||
assert_eq!(devices[0].name, "Microfoon (Realtek(R) Audio)");
|
||||
assert_eq!(devices[1].name, "Headset (Crusher ANC 2)");
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod audio;
|
||||
pub mod capture;
|
||||
pub mod database;
|
||||
pub mod game_detection;
|
||||
|
||||
+1
-6
@@ -1,7 +1,7 @@
|
||||
use clipforge::game_detection::{default_profiles, detect_game, RunningProcess};
|
||||
use clipforge::recorder::{BufferSegment, RecorderAction, RecorderService};
|
||||
use clipforge::settings::AppSettings;
|
||||
use clipforge::storage::{write_placeholder_mp4, LibraryPaths};
|
||||
use clipforge::storage::LibraryPaths;
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::time::{Duration, SystemTime};
|
||||
@@ -48,11 +48,6 @@ fn main() {
|
||||
let clip_action =
|
||||
service.save_manual_clip(Duration::from_secs(60), now + Duration::from_secs(60));
|
||||
if let Some(RecorderAction::CreatedClip { clip_id, .. }) = clip_action {
|
||||
if let Some(clip) = service.library.all().iter().find(|clip| clip.id == clip_id) {
|
||||
if let Err(error) = write_placeholder_mp4(&clip.path, &clip.id) {
|
||||
eprintln!("Could not write placeholder clip: {error}");
|
||||
}
|
||||
}
|
||||
println!("Created manual clip: {clip_id}");
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -26,6 +26,10 @@ pub struct HotkeySettings {
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub struct PrivacySettings {
|
||||
pub mic_enabled: bool,
|
||||
#[serde(default)]
|
||||
pub mic_device: Option<String>,
|
||||
#[serde(default)]
|
||||
pub system_audio_device: Option<String>,
|
||||
pub desktop_capture_requires_confirmation: bool,
|
||||
pub excluded_window_titles: Vec<String>,
|
||||
pub upload_requires_confirmation: bool,
|
||||
@@ -80,6 +84,8 @@ impl AppSettings {
|
||||
},
|
||||
privacy: PrivacySettings {
|
||||
mic_enabled: false,
|
||||
mic_device: None,
|
||||
system_audio_device: None,
|
||||
desktop_capture_requires_confirmation: true,
|
||||
excluded_window_titles: Vec::new(),
|
||||
upload_requires_confirmation: true,
|
||||
|
||||
@@ -172,13 +172,6 @@ fn collect_files(root: &Path) -> io::Result<Vec<FileFact>> {
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
pub fn write_placeholder_mp4(path: &Path, label: &str) -> io::Result<()> {
|
||||
if let Some(parent) = path.parent() {
|
||||
fs::create_dir_all(parent)?;
|
||||
}
|
||||
fs::write(path, format!("ClipForge placeholder video: {label}\n"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in new issue
Block a user