Publish Muninn OBS catalog as CultCache
This commit is contained in:
parent
ff4be20d89
commit
854e171fc5
6 changed files with 90 additions and 59 deletions
|
|
@ -1,6 +1,9 @@
|
|||
use anyhow::{Context, Result, anyhow};
|
||||
use cultmesh_rs::{CultMesh, CultMeshNodeOptions};
|
||||
use odin_core::{MuninnCaptureStreamRecord, MuninnTelemetrySurfaceRecord, OdinDocuments};
|
||||
use odin_core::{
|
||||
MuninnCaptureStreamRecord, MuninnObsStreamCatalogRecord, MuninnTelemetrySurfaceRecord,
|
||||
OdinDocuments,
|
||||
};
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
|
|
@ -37,7 +40,6 @@ struct Options {
|
|||
ffmpeg_path: String,
|
||||
loopback_script: PathBuf,
|
||||
log_root: PathBuf,
|
||||
obs_catalog_path: PathBuf,
|
||||
interval_seconds: Option<u64>,
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +165,7 @@ fn publish_surface(
|
|||
state: &str,
|
||||
active_streams: &[String],
|
||||
) -> Result<()> {
|
||||
write_obs_catalog_idle(options)?;
|
||||
publish_obs_catalog_idle(node, options)?;
|
||||
let record = MuninnTelemetrySurfaceRecord {
|
||||
surface_id: options.surface_id.clone(),
|
||||
host_id: options.host_id.clone(),
|
||||
|
|
@ -211,7 +213,7 @@ fn publish_stream(
|
|||
restart_count: u32,
|
||||
detail: &str,
|
||||
) -> Result<()> {
|
||||
write_obs_catalog_active(options, plan, state)?;
|
||||
publish_obs_catalog_active(node, options, plan, state)?;
|
||||
let record = MuninnCaptureStreamRecord {
|
||||
stream_id: options.stream_id.clone(),
|
||||
host_id: options.host_id.clone(),
|
||||
|
|
@ -238,45 +240,58 @@ fn publish_stream(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn write_obs_catalog_idle(options: &Options) -> Result<()> {
|
||||
if let Some(parent) = options.obs_catalog_path.parent() {
|
||||
fs::create_dir_all(parent).with_context(|| format!("creating {}", parent.display()))?;
|
||||
}
|
||||
let mut lines = vec![
|
||||
"# stream_id\tlabel\turl\tstate".to_string(),
|
||||
format!(
|
||||
"{}\t{} screen and loopback A/V\t\tactivation-required",
|
||||
options.stream_id, options.host_id
|
||||
),
|
||||
];
|
||||
fn publish_obs_catalog_idle(node: &mut cultmesh_rs::CultMeshNode, options: &Options) -> Result<()> {
|
||||
let mut stream_ids = vec![options.stream_id.clone()];
|
||||
let mut labels = vec![format!("{} screen and loopback A/V", options.host_id)];
|
||||
let mut urls = vec![String::new()];
|
||||
let mut states = vec!["activation-required".to_string()];
|
||||
for source in available_sources(options) {
|
||||
lines.push(format!(
|
||||
"{}:{}\t{}\t\taffordance",
|
||||
options.surface_id, source, source
|
||||
));
|
||||
stream_ids.push(format!("{}:{}", options.surface_id, source));
|
||||
labels.push(source);
|
||||
urls.push(String::new());
|
||||
states.push("affordance".to_string());
|
||||
}
|
||||
fs::write(&options.obs_catalog_path, lines.join("\r\n") + "\r\n")
|
||||
.with_context(|| format!("writing {}", options.obs_catalog_path.display()))
|
||||
publish_obs_catalog(node, options, stream_ids, labels, urls, states)
|
||||
}
|
||||
|
||||
fn write_obs_catalog_active(options: &Options, plan: &MuxPlan, state: &str) -> Result<()> {
|
||||
if let Some(parent) = options.obs_catalog_path.parent() {
|
||||
fs::create_dir_all(parent).with_context(|| format!("creating {}", parent.display()))?;
|
||||
}
|
||||
let mut lines = vec!["# stream_id\tlabel\turl\tstate".to_string()];
|
||||
fn publish_obs_catalog_active(
|
||||
node: &mut cultmesh_rs::CultMeshNode,
|
||||
options: &Options,
|
||||
plan: &MuxPlan,
|
||||
state: &str,
|
||||
) -> Result<()> {
|
||||
let mut stream_ids = Vec::new();
|
||||
let mut labels = Vec::new();
|
||||
let mut urls = Vec::new();
|
||||
let mut states = Vec::new();
|
||||
for (index, target) in plan.targets.iter().enumerate() {
|
||||
lines.push(format!(
|
||||
"{}:{}\t{} A/V target {}\t{}\t{}",
|
||||
options.stream_id,
|
||||
index,
|
||||
options.host_id,
|
||||
index + 1,
|
||||
target,
|
||||
state
|
||||
));
|
||||
stream_ids.push(format!("{}:{}", options.stream_id, index));
|
||||
labels.push(format!("{} A/V target {}", options.host_id, index + 1));
|
||||
urls.push(target.clone());
|
||||
states.push(state.to_string());
|
||||
}
|
||||
fs::write(&options.obs_catalog_path, lines.join("\r\n") + "\r\n")
|
||||
.with_context(|| format!("writing {}", options.obs_catalog_path.display()))
|
||||
publish_obs_catalog(node, options, stream_ids, labels, urls, states)
|
||||
}
|
||||
|
||||
fn publish_obs_catalog(
|
||||
node: &mut cultmesh_rs::CultMeshNode,
|
||||
options: &Options,
|
||||
stream_ids: Vec<String>,
|
||||
labels: Vec<String>,
|
||||
urls: Vec<String>,
|
||||
states: Vec<String>,
|
||||
) -> Result<()> {
|
||||
let record = MuninnObsStreamCatalogRecord {
|
||||
catalog_id: "muninn.obs.streams".to_string(),
|
||||
host_id: options.host_id.clone(),
|
||||
stream_ids,
|
||||
labels,
|
||||
urls,
|
||||
states,
|
||||
updated_at: timestamp()?,
|
||||
};
|
||||
node.put("obs", &record)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn health_check(options: &Options) -> Result<()> {
|
||||
|
|
@ -465,7 +480,6 @@ impl Options {
|
|||
ffmpeg_path: "ffmpeg".to_string(),
|
||||
loopback_script: PathBuf::from("scripts/wasapi-loopback-capture.ps1"),
|
||||
log_root: PathBuf::from("C:/Meta/Odin/logs/muninn"),
|
||||
obs_catalog_path: PathBuf::from("C:/Meta/Odin/state/muninn-obs-streams.tsv"),
|
||||
interval_seconds: None,
|
||||
};
|
||||
|
||||
|
|
@ -512,10 +526,6 @@ impl Options {
|
|||
"--log-root" => {
|
||||
options.log_root = PathBuf::from(take_value(&mut args, "--log-root")?)
|
||||
}
|
||||
"--obs-catalog" => {
|
||||
options.obs_catalog_path =
|
||||
PathBuf::from(take_value(&mut args, "--obs-catalog")?)
|
||||
}
|
||||
"--interval-seconds" => {
|
||||
options.interval_seconds = Some(
|
||||
take_value(&mut args, "--interval-seconds")?
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ pub const IDUNN_RESTART_RESULT_SCHEMA: &str = "idunn.restart_result.v1";
|
|||
pub const IDUNN_OPERATOR_ALARM_SCHEMA: &str = "idunn.operator_alarm.v1";
|
||||
pub const MUNINN_TELEMETRY_SURFACE_SCHEMA: &str = "muninn.telemetry_surface.v1";
|
||||
pub const MUNINN_CAPTURE_STREAM_SCHEMA: &str = "muninn.capture_stream.v1";
|
||||
pub const MUNINN_OBS_STREAM_CATALOG_SCHEMA: &str = "muninn.obs_stream_catalog.v1";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
|
||||
#[cultcache(type = "odin.snapshot", schema = "odin.snapshot.v1")]
|
||||
|
|
@ -347,6 +348,28 @@ pub struct MuninnTelemetrySurfaceRecord {
|
|||
pub updated_at: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "muninn.obs_stream_catalog",
|
||||
schema = "muninn.obs_stream_catalog.v1"
|
||||
)]
|
||||
pub struct MuninnObsStreamCatalogRecord {
|
||||
#[cultcache(key = 0)]
|
||||
pub catalog_id: String,
|
||||
#[cultcache(key = 1)]
|
||||
pub host_id: String,
|
||||
#[cultcache(key = 2)]
|
||||
pub stream_ids: Vec<String>,
|
||||
#[cultcache(key = 3)]
|
||||
pub labels: Vec<String>,
|
||||
#[cultcache(key = 4)]
|
||||
pub urls: Vec<String>,
|
||||
#[cultcache(key = 5)]
|
||||
pub states: Vec<String>,
|
||||
#[cultcache(key = 6)]
|
||||
pub updated_at: String,
|
||||
}
|
||||
|
||||
cultmesh_rs::cultmesh_documents!(OdinDocuments {
|
||||
OdinSnapshotRecord => ODIN_SNAPSHOT_SCHEMA,
|
||||
OdinVerseRecord => ODIN_VERSE_SCHEMA,
|
||||
|
|
@ -366,6 +389,7 @@ cultmesh_rs::cultmesh_documents!(OdinDocuments {
|
|||
IdunnOperatorAlarmRecord => IDUNN_OPERATOR_ALARM_SCHEMA,
|
||||
MuninnTelemetrySurfaceRecord => MUNINN_TELEMETRY_SURFACE_SCHEMA,
|
||||
MuninnCaptureStreamRecord => MUNINN_CAPTURE_STREAM_SCHEMA,
|
||||
MuninnObsStreamCatalogRecord => MUNINN_OBS_STREAM_CATALOG_SCHEMA,
|
||||
});
|
||||
|
||||
#[derive(Clone, Debug, Default, PartialEq, Eq)]
|
||||
|
|
|
|||
|
|
@ -29,16 +29,16 @@ muninn --health --store C:\Meta\Odin\state\muninn.telemetry.cc
|
|||
surface fresh without starting FFmpeg, screen capture, microphone capture, or
|
||||
loopback capture.
|
||||
|
||||
Muninn also writes an OBS compatibility catalog by default:
|
||||
Muninn also writes an OBS stream catalog as typed CultCache state inside:
|
||||
|
||||
```text
|
||||
C:\Meta\Odin\state\muninn-obs-streams.tsv
|
||||
C:\Meta\Odin\state\muninn.telemetry.cc
|
||||
```
|
||||
|
||||
That TSV is a lowering of Muninn's typed state for OBS source property lists. It
|
||||
is not the authority; the `.cc` CultMesh store is. On Starfire,
|
||||
`health-muninn.ps1` syncs Raven's catalog to the same local path so the OBS
|
||||
plugin can read it without learning Raven SSH or CultCache internals.
|
||||
The record is type `muninn.obs_stream_catalog` with schema
|
||||
`muninn.obs_stream_catalog.v1` at key `obs`. On Starfire, `health-muninn.ps1`
|
||||
syncs Raven's `.cc` store to the same local path so the OBS plugin can read
|
||||
CultCache directly without learning Raven SSH.
|
||||
|
||||
Activation is explicit:
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ param(
|
|||
[string] $RavenHost = "raven",
|
||||
[string] $MuninnExe = "C:\Meta\Odin\Muninn\muninn.exe",
|
||||
[string] $StorePath = "C:\Meta\Odin\state\muninn.telemetry.cc",
|
||||
[string] $ObsCatalogPath = "C:\Meta\Odin\state\muninn-obs-streams.tsv",
|
||||
[string] $LoopbackScript = "C:\Meta\Odin\Muninn\scripts\wasapi-loopback-capture.ps1",
|
||||
[string] $LogRoot = "C:\Meta\Odin\logs\muninn",
|
||||
[string] $Ffmpeg = "C:\Users\Madman's Lullaby\AppData\Local\Microsoft\WinGet\Links\ffmpeg.exe",
|
||||
|
|
@ -33,7 +32,7 @@ Get-CimInstance Win32_Process |
|
|||
`$lines = @(
|
||||
"@echo off",
|
||||
"cd /d ""`$muninnDir""",
|
||||
"""$MuninnExe"" activate --store ""$StorePath"" --obs-catalog ""$ObsCatalogPath"" --host raven --stream muninn.raven.av.srt --target-host ""$TargetHost"" --port $Port --obs-target-host ""$ObsTargetHost"" --obs-port $ObsPort --audio-device ""$AudioDevice"" --ffmpeg ""$Ffmpeg"" --loopback-script ""$LoopbackScript"" --log-root ""$LogRoot"" 1>>""$LogRoot\muninn-activate.out.log"" 2>>""$LogRoot\muninn-activate.err.log"""
|
||||
"""$MuninnExe"" activate --store ""$StorePath"" --host raven --stream muninn.raven.av.srt --target-host ""$TargetHost"" --port $Port --obs-target-host ""$ObsTargetHost"" --obs-port $ObsPort --audio-device ""$AudioDevice"" --ffmpeg ""$Ffmpeg"" --loopback-script ""$LoopbackScript"" --log-root ""$LogRoot"" 1>>""$LogRoot\muninn-activate.out.log"" 2>>""$LogRoot\muninn-activate.err.log"""
|
||||
)
|
||||
Set-Content -LiteralPath `$launcher -Value `$lines -Encoding ASCII
|
||||
cmd /c "schtasks /Delete /TN GameCult-Muninn-Activate /F 2>NUL"
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@ param(
|
|||
[string] $RavenHost = "raven",
|
||||
[string] $MuninnExe = "C:\Meta\Odin\Muninn\muninn.exe",
|
||||
[string] $StorePath = "C:\Meta\Odin\state\muninn.telemetry.cc",
|
||||
[string] $RemoteObsCatalogPath = "C:\Meta\Odin\state\muninn-obs-streams.tsv",
|
||||
[string] $LocalObsCatalogPath = "C:\Meta\Odin\state\muninn-obs-streams.tsv"
|
||||
[string] $LocalStorePath = "C:\Meta\Odin\state\muninn.telemetry.cc"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
|
@ -26,11 +25,11 @@ $encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($remoteSc
|
|||
& ssh.exe -o BatchMode=yes -o ConnectTimeout=5 $RavenHost "powershell.exe -NoProfile -EncodedCommand $encoded"
|
||||
$healthExit = $LASTEXITCODE
|
||||
if ($healthExit -eq 0) {
|
||||
$localParent = Split-Path -Parent $LocalObsCatalogPath
|
||||
$localParent = Split-Path -Parent $LocalStorePath
|
||||
if (-not [string]::IsNullOrWhiteSpace($localParent)) {
|
||||
New-Item -ItemType Directory -Force -Path $localParent | Out-Null
|
||||
}
|
||||
& ssh.exe -o BatchMode=yes -o ConnectTimeout=5 $RavenHost "cmd /c type $RemoteObsCatalogPath" |
|
||||
Set-Content -Encoding UTF8 -LiteralPath $LocalObsCatalogPath
|
||||
$remoteStore = "$RavenHost`:$StorePath"
|
||||
& scp.exe $remoteStore "$LocalStorePath" | Out-Null
|
||||
}
|
||||
exit $healthExit
|
||||
|
|
|
|||
|
|
@ -2,9 +2,8 @@ param(
|
|||
[string] $RavenHost = "raven",
|
||||
[string] $MuninnExe = "C:\Meta\Odin\Muninn\muninn.exe",
|
||||
[string] $StorePath = "C:\Meta\Odin\state\muninn.telemetry.cc",
|
||||
[string] $ObsCatalogPath = "C:\Meta\Odin\state\muninn-obs-streams.tsv",
|
||||
[string] $LogRoot = "C:\Meta\Odin\logs\muninn",
|
||||
[string] $LocalObsCatalogPath = "C:\Meta\Odin\state\muninn-obs-streams.tsv"
|
||||
[string] $LocalStorePath = "C:\Meta\Odin\state\muninn.telemetry.cc"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
|
@ -26,7 +25,7 @@ New-Item -ItemType Directory -Force -Path (Split-Path -Parent "$StorePath") | Ou
|
|||
`$lines = @(
|
||||
"@echo off",
|
||||
"cd /d ""`$muninnDir""",
|
||||
"""$MuninnExe"" serve --store ""$StorePath"" --obs-catalog ""$ObsCatalogPath"" --log-root ""$LogRoot"" --host raven --interval-seconds 15 1>>""$LogRoot\muninn-serve.out.log"" 2>>""$LogRoot\muninn-serve.err.log"""
|
||||
"""$MuninnExe"" serve --store ""$StorePath"" --log-root ""$LogRoot"" --host raven --interval-seconds 15 1>>""$LogRoot\muninn-serve.out.log"" 2>>""$LogRoot\muninn-serve.err.log"""
|
||||
)
|
||||
Set-Content -LiteralPath `$launcher -Value `$lines -Encoding ASCII
|
||||
cmd /c "schtasks /Delete /TN GameCult-Muninn /F 2>NUL"
|
||||
|
|
@ -40,6 +39,6 @@ $restartExit = $LASTEXITCODE
|
|||
if ($restartExit -eq 0) {
|
||||
Start-Sleep -Seconds 2
|
||||
$healthScript = Join-Path $PSScriptRoot "health-muninn.ps1"
|
||||
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $healthScript -RavenHost $RavenHost -MuninnExe $MuninnExe -StorePath $StorePath -RemoteObsCatalogPath $ObsCatalogPath -LocalObsCatalogPath $LocalObsCatalogPath
|
||||
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File $healthScript -RavenHost $RavenHost -MuninnExe $MuninnExe -StorePath $StorePath -LocalStorePath $LocalStorePath
|
||||
}
|
||||
exit $restartExit
|
||||
|
|
|
|||
Loading…
Reference in a new issue