record-daemon: refactor and cleanup

This commit is contained in:
2026-03-21 00:05:46 +01:00
parent 1166424c29
commit 03e36d0f1b
12 changed files with 140 additions and 139 deletions

View File

@@ -6,7 +6,10 @@ use async_trait::async_trait;
use parking_lot::RwLock;
use tracing::{debug, info};
use super::protocol::{IpcCommand, IpcMessage, IpcResponse};
use super::protocol::{
EncoderInfo, GetEncodersResponse, GetRecordingsResponse, GetSettingsResponse,
GetStatusResponse, IpcCommand, IpcMessage, IpcResponse,
};
use crate::config::Settings;
use crate::error::Result;
use crate::recording::encoder::{detect_hardware_encoders, EncoderCapability};
@@ -94,7 +97,8 @@ impl IpcHandlers {
async fn handle_get_settings(&self) -> Result<serde_json::Value> {
let settings = self.settings.read().clone();
Ok(serde_json::to_value(settings)?)
let response = GetSettingsResponse { settings };
Ok(serde_json::to_value(response)?)
}
async fn handle_update_settings(
@@ -142,12 +146,15 @@ impl IpcHandlers {
.map(|r| r.is_recording())
.unwrap_or(false);
let client_connected = *self.client_connected.read();
let current_game_id = recording.as_ref().and_then(|r| r.current_game_id());
Ok(serde_json::json!({
"status": status,
"isRecording": is_recording,
"clientConnected": client_connected,
}))
let response = GetStatusResponse {
status,
is_recording,
current_game_id,
client_connected,
};
Ok(serde_json::to_value(response)?)
}
async fn handle_get_encoders(&self) -> Result<serde_json::Value> {
@@ -160,40 +167,38 @@ impl IpcHandlers {
.encoder_name()
.to_string();
let encoders: Vec<_> = capabilities
let available: Vec<EncoderInfo> = capabilities
.iter()
.map(|cap| match cap {
EncoderCapability::Nvenc => serde_json::json!({
"id": "jim_nvenc",
"name": "NVIDIA NVENC",
"isHardware": true,
"available": true,
}),
EncoderCapability::Amf => serde_json::json!({
"id": "amd_amf_h264",
"name": "AMD AMF",
"isHardware": true,
"available": true,
}),
EncoderCapability::QuickSync => serde_json::json!({
"id": "qsv",
"name": "Intel QuickSync",
"isHardware": true,
"available": true,
}),
EncoderCapability::Software => serde_json::json!({
"id": "x264",
"name": "x264 (Software)",
"isHardware": false,
"available": true,
}),
EncoderCapability::Nvenc => EncoderInfo {
id: "jim_nvenc".to_string(),
name: "NVIDIA NVENC".to_string(),
is_hardware: true,
available: true,
},
EncoderCapability::Amf => EncoderInfo {
id: "amd_amf_h264".to_string(),
name: "AMD AMF".to_string(),
is_hardware: true,
available: true,
},
EncoderCapability::QuickSync => EncoderInfo {
id: "qsv".to_string(),
name: "Intel QuickSync".to_string(),
is_hardware: true,
available: true,
},
EncoderCapability::Software => EncoderInfo {
id: "x264".to_string(),
name: "x264 (Software)".to_string(),
is_hardware: false,
available: true,
},
})
.collect();
Ok(serde_json::json!({
"available": encoders,
"current": current,
}))
let response = GetEncodersResponse { available, current };
Ok(serde_json::to_value(response)?)
}
async fn handle_start_recording(&self) -> Result<serde_json::Value> {
@@ -232,7 +237,8 @@ impl IpcHandlers {
async fn handle_get_recordings(&self) -> Result<serde_json::Value> {
let recordings = self.timeline.read().get_all_recordings()?;
Ok(serde_json::to_value(recordings)?)
let response = GetRecordingsResponse { recordings };
Ok(serde_json::to_value(response)?)
}
async fn handle_get_recording(&self, id: uuid::Uuid) -> Result<serde_json::Value> {