Strip deprecated A/V streaming stack, dead Sleipnir/Idunn/compat residue, and stale docs (#3)
This commit is contained in:
parent
573ffea956
commit
1993fbe53c
24 changed files with 4200 additions and 17693 deletions
75
README.md
75
README.md
|
|
@ -1,61 +1,48 @@
|
|||
# Muninn
|
||||
|
||||
> **Deprecation notice (Meta, 2026-11-06).** Muninn's *streaming* role (screen and audio
|
||||
> capture, the media sender, and the OBS media receiver at
|
||||
> [github.com/GameCult/Ratatoskr](https://github.com/GameCult/Ratatoskr), not the forge chat
|
||||
> client of the same name) is superseded in the streaming space. Do not build new work on it.
|
||||
> Nothing is deleted yet; what depends on it and what looks removable is in
|
||||
> [docs/streaming-deprecation.md](docs/streaming-deprecation.md). The non-streaming roles
|
||||
> (sensors, PS Move, input for Sleipnir) are not covered by this notice.
|
||||
> **Streaming stack removed (2026-12-03).** Muninn's deprecated A/V streaming
|
||||
> role (screen and loopback-audio capture, the media sender, and Ratatoskr OBS
|
||||
> receiver wiring) has been removed from `main` and archived at tag
|
||||
> `parked/muninn-media-streaming-2026-12-03` (see
|
||||
> [docs/streaming-deprecation.md](docs/streaming-deprecation.md)). The
|
||||
> non-streaming roles (PS Move, Quest, HID/XInput forwarding to Sleipnir, and
|
||||
> Idunn presence) are live.
|
||||
|
||||
|
||||
**Local capture broker for the GameCult swarm.**
|
||||
**Local sensor and HID broker for the GameCult swarm.**
|
||||
|
||||
Muninn resolves what data streams a host can offer, advertises them, and serves
|
||||
them to CultMesh peers on request. Screen and loopback audio, cameras, PS Move
|
||||
controllers and their optical markers, HID and XInput gamepads, Quest access.
|
||||
Muninn reads PS Move controllers and optical markers, HID and XInput gamepads,
|
||||
and Quest state, and serves typed records and low-latency RUDP HID streams to
|
||||
CultMesh peers such as Sleipnir and Mimir.
|
||||
|
||||
Muninn running does not mean Muninn is broadcasting. Each feed it can reach is
|
||||
*available* for another service to request. Mimir asks for sensors. Sleipnir asks
|
||||
for input. A stream asks for screen and audio. Muninn does not decide what any of
|
||||
them are for.
|
||||
|
||||
**Naming note.** Muninn's docs say "Ratatoskr" for the OBS media receiver, which lives at
|
||||
[github.com/GameCult/Ratatoskr](https://github.com/GameCult/Ratatoskr) (forge mirror:
|
||||
**Naming note.** Older docs say "Ratatoskr" for the archived OBS media receiver,
|
||||
which lives at [github.com/GameCult/Ratatoskr](https://github.com/GameCult/Ratatoskr)
|
||||
(forge mirror:
|
||||
[GameCult/Ratatoskr-receiver](https://eureka.gamecult.org/forge/GameCult/Ratatoskr-receiver)).
|
||||
The forge repo `GameCult/Ratatoskr` is an unrelated project, Void's Cinny-based chat client.
|
||||
|
||||
Extracted from [Odin](https://github.com/GameCult/Odin) with its full history.
|
||||
Muninn had lived as three crates inside the repository of the service that
|
||||
discovers it, with its document schemas owned by `odin-core` — an inversion of
|
||||
the ownership it needs to hold. Same shape as the
|
||||
[Idunn](https://github.com/GameCult/Idunn) extraction of 2026-09-05, and done
|
||||
deliberately after it.
|
||||
Extracted from [Odin](https://github.com/GameCult/Odin) with its full history;
|
||||
Muninn's own record contracts live in `muninn-contracts`.
|
||||
|
||||
---
|
||||
|
||||
## Status
|
||||
|
||||
**This repository does not build yet.** It is a faithful history extraction, not
|
||||
a finished cut. `muninn-daemon` still depends on `odin-core` by path for the
|
||||
twenty record types and schema constants it uses, and that dependency is one of
|
||||
the things being removed.
|
||||
|
||||
See [docs/teardown-map.md](docs/teardown-map.md) for the working map: current
|
||||
body, the authorities currently fused into one 14,567-line `main.rs`, schema
|
||||
decomposition, extraction blast radius, and the measured diagnosis of the audio
|
||||
decay that prompted the rebuild.
|
||||
`muninn-contracts`, `muninn-daemon` (`Move`, `Quest`, HID, and
|
||||
`idunn_presence.rs`), `muninn-move-tracker`, `muninn-psmoveapi-tracker`, and
|
||||
`sleipnir-daemon` build and test on the workspace. Both `muninn-daemon` and
|
||||
`sleipnir-daemon` read `odin-core` strictly for Odin's external
|
||||
`EveProviderAdvertisementRecord` discovery surface (`muninn-daemon` publishes
|
||||
its advertised HID RUDP endpoint lease via `EveProviderAdvertisementRecord`, and
|
||||
`sleipnir-daemon` resolves it via `odin_core::discover_provider_endpoints`).
|
||||
|
||||
## Authority
|
||||
|
||||
- **Owner:** Muninn owns local source enumeration, capability advertisement,
|
||||
per-consumer stream grants, and transport of granted streams.
|
||||
- **Input:** locally reachable devices; typed capture stream commands from
|
||||
requesting peers.
|
||||
- **Output:** CultMesh Media Streams and typed sensor records.
|
||||
- **Not Muninn's:** the media protocol itself (a general CultMesh contract, owned
|
||||
by CultLib), discovery and rendezvous (Odin), deployment and continuity
|
||||
(Idunn), the hue programs that decide what colour a Move should be (Mimir),
|
||||
and any consumer's lowering — OBS, browser, or otherwise.
|
||||
|
||||
Muninn is one producer of a general contract. It is not the contract.
|
||||
- **Owner:** Muninn owns local source enumeration, HID RUDP serving, Quest
|
||||
state publishing, and Move tracking/hue-program state.
|
||||
- **Input:** locally reachable controllers, optical trackers, and Quest state.
|
||||
- **Output:** low-latency RUDP HID frames and typed CultMesh/CultCache sensor
|
||||
and Move records.
|
||||
- **Not Muninn's:** discovery and rendezvous (Odin), deployment and runtime
|
||||
presence policy (Idunn), the hue programs that decide what colour a Move
|
||||
should be (Mimir), and Sleipnir's virtual HID output.
|
||||
|
|
|
|||
|
|
@ -7,9 +7,6 @@ pub use records::*;
|
|||
|
||||
cultmesh_rs::cultmesh_documents!(MuninnRecords {
|
||||
MuninnTelemetrySurfaceRecord => MUNINN_TELEMETRY_SURFACE_SCHEMA,
|
||||
MuninnCaptureStreamRecord => MUNINN_CAPTURE_STREAM_SCHEMA,
|
||||
MuninnCaptureStreamCommandRecord => MUNINN_CAPTURE_STREAM_COMMAND_SCHEMA,
|
||||
MuninnObsStreamCatalogRecord => MUNINN_OBS_STREAM_CATALOG_SCHEMA,
|
||||
MuninnMoveMarkerCandidateRecord => MUNINN_MOVE_MARKER_CANDIDATE_SCHEMA,
|
||||
MuninnMoveControllerStateRecord => MUNINN_MOVE_CONTROLLER_STATE_SCHEMA,
|
||||
MuninnHidControllerStateRecord => MUNINN_HID_CONTROLLER_STATE_SCHEMA,
|
||||
|
|
@ -19,8 +16,7 @@ cultmesh_rs::cultmesh_documents!(MuninnRecords {
|
|||
MuninnMoveTrackerHealthRecord => MUNINN_MOVE_TRACKER_HEALTH_SCHEMA,
|
||||
MuninnMoveEvidenceTransportHealthRecord => MUNINN_MOVE_EVIDENCE_TRANSPORT_HEALTH_SCHEMA,
|
||||
MuninnQuestAccessRecord => MUNINN_QUEST_ACCESS_SCHEMA,
|
||||
MuninnCommandBoundaryCompatRecord => MUNINN_COMMAND_BOUNDARY_SCHEMA,
|
||||
MuninnTransportProfileCompatRecord => MUNINN_TRANSPORT_PROFILE_SCHEMA,
|
||||
SleipnirInputMappingRecord => SLEIPNIR_INPUT_MAPPING_SCHEMA,
|
||||
});
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -45,9 +41,6 @@ mod tests {
|
|||
}
|
||||
vec![
|
||||
row!(MuninnTelemetrySurfaceRecord, MUNINN_TELEMETRY_SURFACE_SCHEMA),
|
||||
row!(MuninnCaptureStreamRecord, MUNINN_CAPTURE_STREAM_SCHEMA),
|
||||
row!(MuninnCaptureStreamCommandRecord, MUNINN_CAPTURE_STREAM_COMMAND_SCHEMA),
|
||||
row!(MuninnObsStreamCatalogRecord, MUNINN_OBS_STREAM_CATALOG_SCHEMA),
|
||||
row!(MuninnMoveMarkerCandidateRecord, MUNINN_MOVE_MARKER_CANDIDATE_SCHEMA),
|
||||
row!(MuninnMoveControllerStateRecord, MUNINN_MOVE_CONTROLLER_STATE_SCHEMA),
|
||||
row!(MuninnHidControllerStateRecord, MUNINN_HID_CONTROLLER_STATE_SCHEMA),
|
||||
|
|
@ -60,8 +53,7 @@ mod tests {
|
|||
MUNINN_MOVE_EVIDENCE_TRANSPORT_HEALTH_SCHEMA
|
||||
),
|
||||
row!(MuninnQuestAccessRecord, MUNINN_QUEST_ACCESS_SCHEMA),
|
||||
row!(MuninnCommandBoundaryCompatRecord, MUNINN_COMMAND_BOUNDARY_SCHEMA),
|
||||
row!(MuninnTransportProfileCompatRecord, MUNINN_TRANSPORT_PROFILE_SCHEMA),
|
||||
row!(SleipnirInputMappingRecord, SLEIPNIR_INPUT_MAPPING_SCHEMA),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -69,9 +61,6 @@ mod tests {
|
|||
fn record_names_are_the_published_schema_ids() {
|
||||
let expected = [
|
||||
("muninn.telemetry_surface", "muninn.telemetry_surface.v1"),
|
||||
("muninn.capture_stream", "muninn.capture_stream.v1"),
|
||||
("muninn.capture_stream_command", "muninn.capture_stream_command.v1"),
|
||||
("muninn.obs_stream_catalog", "muninn.obs_stream_catalog.v1"),
|
||||
("muninn.move_marker_candidate", "muninn.move_marker_candidate.v1"),
|
||||
("muninn.move_controller_state", "muninn.move_controller_state.v1"),
|
||||
("muninn.hid_controller_state", "muninn.hid_controller_state.v1"),
|
||||
|
|
@ -84,8 +73,7 @@ mod tests {
|
|||
"muninn.move_evidence_transport_health.v1",
|
||||
),
|
||||
("muninn.quest_access", "muninn.quest_access.v1"),
|
||||
("muninn.command_boundary", "muninn.command_boundary.v1"),
|
||||
("muninn.transport_profile", "muninn.transport_profile.v1"),
|
||||
("sleipnir.input_mapping", "sleipnir.input_mapping.v1"),
|
||||
];
|
||||
let actual: Vec<_> = contract()
|
||||
.into_iter()
|
||||
|
|
@ -191,75 +179,6 @@ mod tests {
|
|||
Some(9),
|
||||
"dc0015a773757266616365a4686f7374a46c69766591a373726391a361666691a3616374a461757468a664657461696ca174a470736964a6706c6162656ca3636d64a36d7468cd0fa1cd04b0cd1f402891a376696491a4766c616291a361696491a4616c6162",
|
||||
),
|
||||
pin(
|
||||
"MuninnCaptureStreamRecord",
|
||||
MuninnCaptureStreamRecord {
|
||||
stream_id: text("stream"),
|
||||
host_id: text("host"),
|
||||
state: text("live"),
|
||||
video_source: text("vsrc"),
|
||||
audio_source: text("asrc"),
|
||||
transport: text("rudp"),
|
||||
targets: texts(&["tgt"]),
|
||||
command_witness: text("wit"),
|
||||
supervisor_pid: None,
|
||||
mux_pid: Some(77),
|
||||
restart_count: 3,
|
||||
detail: text("detail"),
|
||||
updated_at: text("t"),
|
||||
},
|
||||
None,
|
||||
"9da673747265616da4686f7374a46c697665a476737263a461737263a47275647091a3746774a3776974c04d03a664657461696ca174",
|
||||
),
|
||||
pin(
|
||||
"MuninnCaptureStreamCommandRecord",
|
||||
MuninnCaptureStreamCommandRecord {
|
||||
command_id: text("cmd"),
|
||||
host_id: text("host"),
|
||||
stream_id: text("stream"),
|
||||
state: text("live"),
|
||||
action: text("start"),
|
||||
target_host: text("tgt"),
|
||||
port: 4001,
|
||||
obs_target_host: Some(text("obs")),
|
||||
obs_port: 4002,
|
||||
media_transport: text("rudp"),
|
||||
media_packet_bytes: 1200,
|
||||
requested_by: text("who"),
|
||||
detail: text("detail"),
|
||||
updated_at: text("t"),
|
||||
rudp_video_bitrate_kbps: 8000,
|
||||
rudp_latency_budget_ms: 40,
|
||||
video_source_id: text("vid"),
|
||||
audio_source_id: text("aid"),
|
||||
},
|
||||
Some(14),
|
||||
"dc0012a3636d64a4686f7374a673747265616da46c697665a57374617274a3746774cd0fa1a36f6273cd0fa2a472756470cd04b0a377686fa664657461696ca174cd1f4028a3766964a3616964",
|
||||
),
|
||||
pin(
|
||||
"MuninnObsStreamCatalogRecord",
|
||||
MuninnObsStreamCatalogRecord {
|
||||
catalog_id: text("catalog"),
|
||||
host_id: text("host"),
|
||||
stream_ids: texts(&["sid"]),
|
||||
labels: texts(&["lab"]),
|
||||
urls: texts(&["url"]),
|
||||
states: texts(&["st"]),
|
||||
updated_at: text("t"),
|
||||
command_rudp_target: text("cmd"),
|
||||
media_target_host: text("mth"),
|
||||
media_port: 4001,
|
||||
media_packet_bytes: 1200,
|
||||
rudp_video_bitrate_kbps: 8000,
|
||||
rudp_latency_budget_ms: 40,
|
||||
video_source_ids: texts(&["vid"]),
|
||||
video_source_labels: texts(&["vlab"]),
|
||||
audio_source_ids: texts(&["aid"]),
|
||||
audio_source_labels: texts(&["alab"]),
|
||||
},
|
||||
Some(7),
|
||||
"dc0011a7636174616c6f67a4686f737491a373696491a36c616291a375726c91a27374a174a3636d64a36d7468cd0fa1cd04b0cd1f402891a376696491a4766c616291a361696491a4616c6162",
|
||||
),
|
||||
pin(
|
||||
"MuninnMoveMarkerCandidateRecord",
|
||||
MuninnMoveMarkerCandidateRecord {
|
||||
|
|
@ -442,20 +361,21 @@ mod tests {
|
|||
"9fa6616363657373a4686f7374a673657269616ca4636f6e6ea770726f64756374a56d6f64656ca6646576696365a3746964a5696e707574a4706f7365a5766964656faa767472616e73706f7274a46c697665a664657461696ca174",
|
||||
),
|
||||
pin(
|
||||
"MuninnCommandBoundaryCompatRecord",
|
||||
MuninnCommandBoundaryCompatRecord {
|
||||
value: serde_json::json!({ "daemon_id": "muninn" }),
|
||||
"SleipnirInputMappingRecord",
|
||||
SleipnirInputMappingRecord {
|
||||
provider_id: text("prov"),
|
||||
enabled: true,
|
||||
device_filter: text("dev"),
|
||||
stream_id: text("stream"),
|
||||
presentation: text("xbox360"),
|
||||
axis_map: serde_json::json!({ "leftX": 0 }),
|
||||
button_map: serde_json::json!({ "cross": "a" }),
|
||||
pending_learn: serde_json::json!({ "target": "b" }),
|
||||
updated_at: text("t"),
|
||||
source: text("src"),
|
||||
},
|
||||
None,
|
||||
"9181a96461656d6f6e5f6964a66d756e696e6e",
|
||||
),
|
||||
pin(
|
||||
"MuninnTransportProfileCompatRecord",
|
||||
MuninnTransportProfileCompatRecord {
|
||||
value: serde_json::json!({ "state": "live" }),
|
||||
},
|
||||
None,
|
||||
"9181a57374617465a46c697665",
|
||||
"9aa470726f76c3a3646576a673747265616da778626f7833363081a56c656674580081a563726f7373a16181a6746172676574a162a174a3737263",
|
||||
),
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,6 @@ use cultcache_rs::DatabaseEntry;
|
|||
use serde_json::Value;
|
||||
|
||||
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_CAPTURE_STREAM_COMMAND_SCHEMA: &str = "muninn.capture_stream_command.v1";
|
||||
pub const MUNINN_OBS_STREAM_CATALOG_SCHEMA: &str = "muninn.obs_stream_catalog.v1";
|
||||
pub const MUNINN_MOVE_MARKER_CANDIDATE_SCHEMA: &str = "muninn.move_marker_candidate.v1";
|
||||
pub const MUNINN_MOVE_CONTROLLER_STATE_SCHEMA: &str = "muninn.move_controller_state.v1";
|
||||
pub const MUNINN_HID_CONTROLLER_STATE_SCHEMA: &str = "muninn.hid_controller_state.v1";
|
||||
|
|
@ -15,83 +12,7 @@ pub const MUNINN_MOVE_TRACKER_HEALTH_SCHEMA: &str = "muninn.move_tracker_health.
|
|||
pub const MUNINN_MOVE_EVIDENCE_TRANSPORT_HEALTH_SCHEMA: &str =
|
||||
"muninn.move_evidence_transport_health.v1";
|
||||
pub const MUNINN_QUEST_ACCESS_SCHEMA: &str = "muninn.quest_access.v1";
|
||||
pub const MUNINN_COMMAND_BOUNDARY_SCHEMA: &str = "muninn.command_boundary.v1";
|
||||
pub const MUNINN_TRANSPORT_PROFILE_SCHEMA: &str = "muninn.transport_profile.v1";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
|
||||
#[cultcache(type = "muninn.capture_stream", schema = "muninn.capture_stream.v1")]
|
||||
pub struct MuninnCaptureStreamRecord {
|
||||
#[cultcache(key = 0)]
|
||||
pub stream_id: String,
|
||||
#[cultcache(key = 1)]
|
||||
pub host_id: String,
|
||||
#[cultcache(key = 2)]
|
||||
pub state: String,
|
||||
#[cultcache(key = 3)]
|
||||
pub video_source: String,
|
||||
#[cultcache(key = 4)]
|
||||
pub audio_source: String,
|
||||
#[cultcache(key = 5)]
|
||||
pub transport: String,
|
||||
#[cultcache(key = 6)]
|
||||
pub targets: Vec<String>,
|
||||
#[cultcache(key = 7)]
|
||||
pub command_witness: String,
|
||||
#[cultcache(key = 8)]
|
||||
pub supervisor_pid: Option<u32>,
|
||||
#[cultcache(key = 9)]
|
||||
pub mux_pid: Option<u32>,
|
||||
#[cultcache(key = 10)]
|
||||
pub restart_count: u32,
|
||||
#[cultcache(key = 11)]
|
||||
pub detail: String,
|
||||
#[cultcache(key = 12)]
|
||||
pub updated_at: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "muninn.capture_stream_command",
|
||||
schema = "muninn.capture_stream_command.v1"
|
||||
)]
|
||||
pub struct MuninnCaptureStreamCommandRecord {
|
||||
#[cultcache(key = 0)]
|
||||
pub command_id: String,
|
||||
#[cultcache(key = 1)]
|
||||
pub host_id: String,
|
||||
#[cultcache(key = 2)]
|
||||
pub stream_id: String,
|
||||
#[cultcache(key = 3)]
|
||||
pub state: String,
|
||||
#[cultcache(key = 4)]
|
||||
pub action: String,
|
||||
#[cultcache(key = 5)]
|
||||
pub target_host: String,
|
||||
#[cultcache(key = 6)]
|
||||
pub port: u16,
|
||||
#[cultcache(key = 7)]
|
||||
pub obs_target_host: Option<String>,
|
||||
#[cultcache(key = 8)]
|
||||
pub obs_port: u16,
|
||||
#[cultcache(key = 9)]
|
||||
pub media_transport: String,
|
||||
#[cultcache(key = 10)]
|
||||
pub media_packet_bytes: u32,
|
||||
#[cultcache(key = 11)]
|
||||
pub requested_by: String,
|
||||
#[cultcache(key = 12)]
|
||||
pub detail: String,
|
||||
#[cultcache(key = 13)]
|
||||
pub updated_at: String,
|
||||
#[cultcache(key = 14, default)]
|
||||
pub rudp_video_bitrate_kbps: u32,
|
||||
#[cultcache(key = 15, default)]
|
||||
pub rudp_latency_budget_ms: u32,
|
||||
#[cultcache(key = 16, default)]
|
||||
pub video_source_id: String,
|
||||
#[cultcache(key = 17, default)]
|
||||
pub audio_source_id: String,
|
||||
}
|
||||
pub const SLEIPNIR_INPUT_MAPPING_SCHEMA: &str = "sleipnir.input_mapping.v1";
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
|
|
@ -143,48 +64,6 @@ pub struct MuninnTelemetrySurfaceRecord {
|
|||
pub audio_source_labels: Vec<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,
|
||||
#[cultcache(key = 7, default)]
|
||||
pub command_rudp_target: String,
|
||||
#[cultcache(key = 8, default)]
|
||||
pub media_target_host: String,
|
||||
#[cultcache(key = 9, default)]
|
||||
pub media_port: u16,
|
||||
#[cultcache(key = 10, default)]
|
||||
pub media_packet_bytes: u32,
|
||||
#[cultcache(key = 11, default)]
|
||||
pub rudp_video_bitrate_kbps: u32,
|
||||
#[cultcache(key = 12, default)]
|
||||
pub rudp_latency_budget_ms: u32,
|
||||
#[cultcache(key = 13, default)]
|
||||
pub video_source_ids: Vec<String>,
|
||||
#[cultcache(key = 14, default)]
|
||||
pub video_source_labels: Vec<String>,
|
||||
#[cultcache(key = 15, default)]
|
||||
pub audio_source_ids: Vec<String>,
|
||||
#[cultcache(key = 16, default)]
|
||||
pub audio_source_labels: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "muninn.move_marker_candidate",
|
||||
|
|
@ -488,21 +367,26 @@ pub struct MuninnQuestAccessRecord {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "muninn.command_boundary",
|
||||
schema = "muninn.command_boundary.v1"
|
||||
)]
|
||||
pub struct MuninnCommandBoundaryCompatRecord {
|
||||
#[cultcache(type = "sleipnir.input_mapping", schema = "sleipnir.input_mapping.v1")]
|
||||
pub struct SleipnirInputMappingRecord {
|
||||
#[cultcache(key = 0)]
|
||||
pub value: Value,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DatabaseEntry)]
|
||||
#[cultcache(
|
||||
type = "muninn.transport_profile",
|
||||
schema = "muninn.transport_profile.v1"
|
||||
)]
|
||||
pub struct MuninnTransportProfileCompatRecord {
|
||||
#[cultcache(key = 0)]
|
||||
pub value: Value,
|
||||
pub provider_id: String,
|
||||
#[cultcache(key = 1)]
|
||||
pub enabled: bool,
|
||||
#[cultcache(key = 2)]
|
||||
pub device_filter: String,
|
||||
#[cultcache(key = 3)]
|
||||
pub stream_id: String,
|
||||
#[cultcache(key = 4)]
|
||||
pub presentation: String,
|
||||
#[cultcache(key = 5)]
|
||||
pub axis_map: Value,
|
||||
#[cultcache(key = 6)]
|
||||
pub button_map: Value,
|
||||
#[cultcache(key = 7)]
|
||||
pub pending_learn: Value,
|
||||
#[cultcache(key = 8)]
|
||||
pub updated_at: String,
|
||||
#[cultcache(key = 9)]
|
||||
pub source: String,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ rmp-serde = "1.3"
|
|||
serde = { version = "1", features = ["derive"] }
|
||||
serde_bytes = "0.11"
|
||||
serde_json = "1"
|
||||
socket2 = "0.5"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows-sys = { version = "0.59", features = [
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
BIN
crates/muninn-daemon/testdata/clip.h264
vendored
BIN
crates/muninn-daemon/testdata/clip.h264
vendored
Binary file not shown.
|
|
@ -1,7 +0,0 @@
|
|||
clip.h264: 15 frames of the ffmpeg testsrc2 pattern, 160x120 at 30 fps, H.264 Constrained
|
||||
Baseline in Annex B with access unit delimiters, one IDR every 8 frames, no B-frames.
|
||||
Generated once and committed so the media send harness needs no ffmpeg.
|
||||
|
||||
Command (ffmpeg 8.1.1 full build, libx264, 2026-09-29):
|
||||
|
||||
ffmpeg -f lavfi -i "testsrc2=size=160x120:rate=30:duration=0.5" -c:v libx264 -profile:v baseline -preset veryslow -crf 28 -bf 0 -g 8 -x264-params "threads=1:aud=1:repeat-headers=1:keyint=8:min-keyint=8:scenecut=0" -f h264 clip.h264
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -29,52 +29,26 @@ source = "target/release/muninn.exe"
|
|||
destination = "muninn.exe"
|
||||
executable = true
|
||||
|
||||
[[artifacts]]
|
||||
id = "wasapi-loopback-capture"
|
||||
source_kind = "worktree-tree"
|
||||
source = "scripts/wasapi-loopback-capture.ps1"
|
||||
destination = "wasapi-loopback-capture.ps1"
|
||||
|
||||
# The launch contract. Host-specific values come from the operator binding's
|
||||
# argument bindings; everything Raven-independent is literal. The loopback
|
||||
# script is named relative to the installed release, which is the working
|
||||
# directory the actuator starts serve in.
|
||||
# argument bindings; everything Raven-independent is literal.
|
||||
[service]
|
||||
executable_artifact = "muninn"
|
||||
arguments = [
|
||||
{ kind = "literal", value = "serve" },
|
||||
{ kind = "literal", value = "--store" },
|
||||
{ kind = "binding", name = "store_path" },
|
||||
{ kind = "literal", value = "--activate-store" },
|
||||
{ kind = "binding", name = "activate_store_path" },
|
||||
{ kind = "literal", value = "--log-root" },
|
||||
{ kind = "binding", name = "log_root" },
|
||||
{ kind = "literal", value = "--host" },
|
||||
{ kind = "literal", value = "raven" },
|
||||
{ kind = "literal", value = "--stream" },
|
||||
{ kind = "literal", value = "muninn.raven.av.rudp" },
|
||||
{ kind = "literal", value = "--target-host" },
|
||||
{ kind = "binding", name = "media_target_uri" },
|
||||
{ kind = "literal", value = "--media-transport" },
|
||||
{ kind = "literal", value = "rudp" },
|
||||
{ kind = "literal", value = "--odin-cultmesh-uri" },
|
||||
{ kind = "literal", value = "cultmesh://odin/rendezvous/provider-catalog" },
|
||||
{ kind = "literal", value = "--hid-controller-rudp-bind" },
|
||||
{ kind = "literal", value = "0.0.0.0:17887" },
|
||||
{ kind = "literal", value = "--hid-controller-rudp-advertise" },
|
||||
{ kind = "binding", name = "hid_controller_rudp_advertise" },
|
||||
{ kind = "literal", value = "--media-rudp-bind" },
|
||||
{ kind = "literal", value = "0.0.0.0:5220" },
|
||||
{ kind = "literal", value = "--media-rudp-advertise" },
|
||||
{ kind = "binding", name = "media_rudp_advertise" },
|
||||
{ kind = "literal", value = "--move-state" },
|
||||
{ kind = "literal", value = "xbox-raven=xinput://0" },
|
||||
{ kind = "literal", value = "--audio-device" },
|
||||
{ kind = "literal", value = "Realtek" },
|
||||
{ kind = "literal", value = "--ffmpeg" },
|
||||
{ kind = "binding", name = "ffmpeg_path" },
|
||||
{ kind = "literal", value = "--loopback-script" },
|
||||
{ kind = "literal", value = "wasapi-loopback-capture.ps1" },
|
||||
{ kind = "literal", value = "--interval-seconds" },
|
||||
{ kind = "literal", value = "15" },
|
||||
]
|
||||
|
|
@ -90,10 +64,7 @@ required_environment = [
|
|||
[service.health]
|
||||
contract = "muninn.runtime-health.v1"
|
||||
|
||||
[[provides]]
|
||||
capability = "muninn.media-producer"
|
||||
schema = "gamecult.media_stream_advertisement.v1"
|
||||
compatibility = "v1"
|
||||
|
||||
|
||||
# raven-muninn publishes to Odin over CultMesh RUDP (--odin-cultmesh-uri), and
|
||||
# it has no route, so it declares the Odin dependency: Idunn admits it as Ready
|
||||
|
|
|
|||
|
|
@ -1,376 +0,0 @@
|
|||
# Muninn Media Streaming
|
||||
|
||||
Muninn live A/V is the stress organ for CultMesh transport. The goal is not
|
||||
"make OBS show something once." The goal is encoded game video and audio moving
|
||||
between nearby PCs at LAN speed with bounded latency, observable ownership, and
|
||||
transport behavior that teaches CultMesh how to carry hot media.
|
||||
|
||||
## Objective
|
||||
|
||||
Raven Muninn captures screen video and Realtek loopback audio, encodes them with
|
||||
hardware-first low-latency settings, publishes them through CultNet/CultMesh
|
||||
media streams, and lets the Muninn OBS plugin render the stream without owning
|
||||
capture, daemon lifecycle, or transport truth.
|
||||
|
||||
## Current Mechanism
|
||||
|
||||
The current Raven A/V path is a compatibility path:
|
||||
|
||||
1. OBS reads Raven's `muninn.obs_stream_catalog` from the synced CultCache
|
||||
store.
|
||||
2. The OBS plugin sends a typed `muninn.capture_stream_command` to Raven's
|
||||
Muninn daemon over CultNet RUDP.
|
||||
3. Raven Muninn `serve` owns command acceptance and spawns a daemon-owned
|
||||
activation child for the requested stream.
|
||||
4. The activation child starts WASAPI loopback capture and FFmpeg.
|
||||
5. FFmpeg muxes encoded video and audio into MPEG-TS on stdout.
|
||||
6. Muninn slices that byte stream into fixed-size chunks and sends those chunks
|
||||
over the RUDP `media` channel.
|
||||
7. The OBS plugin forwards received bytes into a local FFmpeg source.
|
||||
|
||||
That path proved activation, capture, hardware encode, and cross-machine
|
||||
delivery. It is not the final media architecture. MPEG-TS byte chunks over an
|
||||
unordered lossy hot path give CultMesh no frame identity, no deadline, no media
|
||||
dependency graph, and no clean way to choose between retransmit, conceal,
|
||||
discard, keyframe request, or audio/video resync.
|
||||
|
||||
## Invariants
|
||||
|
||||
- Muninn owns local capture and stream activation for the machine body where
|
||||
the sensors live.
|
||||
- OBS and Mimir are consumers. They may request a stream and report receiver
|
||||
health, but they do not start capture by implication and do not own Raven
|
||||
daemon state.
|
||||
- Idunn owns daemon supervision and health pressure. It does not infer that
|
||||
liveness means screen/audio capture should be burning.
|
||||
- CultMesh owns live media stream semantics: stream identity, frame identity,
|
||||
timestamps, deadlines, dependencies, channel policy, and receiver feedback.
|
||||
- CultCache records are receipts, catalog entries, and operator/debug state.
|
||||
They are not the hot media lane.
|
||||
- Audio and video have separate clocks and recovery policy. They may share a
|
||||
session, but they must not be hidden inside an opaque transport byte soup.
|
||||
- Transport reliability is deadline-bound. Late media is damage, not treasure.
|
||||
|
||||
## Intended Change
|
||||
|
||||
Replace "MPEG-TS stdout sliced into RUDP packets" with "codec access units and
|
||||
audio packets published as typed CultMesh media frames."
|
||||
|
||||
The stream owner should emit media documents shaped around decisions the
|
||||
transport and decoder actually need:
|
||||
|
||||
```text
|
||||
muninn.media_video_access_unit.v1
|
||||
stream_id
|
||||
session_id
|
||||
frame_id
|
||||
codec
|
||||
pts_ticks
|
||||
duration_ticks
|
||||
timebase_num
|
||||
timebase_den
|
||||
keyframe
|
||||
dependency_frame_id
|
||||
deadline_ticks
|
||||
chunk_index
|
||||
chunk_count
|
||||
payload
|
||||
|
||||
muninn.media_audio_packet.v1
|
||||
stream_id
|
||||
session_id
|
||||
packet_id
|
||||
codec
|
||||
pts_ticks
|
||||
duration_ticks
|
||||
timebase_num
|
||||
timebase_den
|
||||
deadline_ticks
|
||||
payload
|
||||
|
||||
muninn.media_receiver_feedback.v1
|
||||
stream_id
|
||||
session_id
|
||||
receiver_id
|
||||
highest_decodable_frame_id
|
||||
missing_frame_ids
|
||||
missing_video_chunk_keys
|
||||
late_frame_ids
|
||||
requested_keyframe
|
||||
jitter_us
|
||||
decode_queue_us
|
||||
```
|
||||
|
||||
The exact schema names can move when promoted into the shared document catalog,
|
||||
but the ownership shape should not: frame/access-unit identity is load-bearing.
|
||||
|
||||
## Authority Map
|
||||
|
||||
- Owner: Muninn capture runtime owns source capture, encode configuration, and
|
||||
emission of video access units plus audio packets for a requested stream.
|
||||
- Inputs: explicit `muninn.capture_stream_command`, local capture devices,
|
||||
encoder capabilities, receiver feedback, stream policy, and Idunn-supervised
|
||||
daemon runtime state.
|
||||
- Outputs: typed active stream receipts in CultCache, CultMesh media frames over
|
||||
CultNet RUDP, and typed receiver/transport health receipts.
|
||||
- Derived state: OBS catalog entries are discovery hints; local FFmpeg bridge
|
||||
URLs are compatibility lowering details; packet counters and logs are
|
||||
observability only.
|
||||
- Forbidden writers: OBS source settings, local UDP bridge behavior, scheduled
|
||||
task wrappers, health scripts, and replayed command receipts must not decide
|
||||
capture state, stream identity, frame order, or media repair policy.
|
||||
- Shared paths: direct operator requests, OBS plugin requests, future Mimir
|
||||
requests, restart recovery, and reconnect recovery must all publish the same
|
||||
typed capture command and consume the same active stream receipts.
|
||||
- Deletion line: delete the hot-path assumption that a media stream is an
|
||||
MPEG-TS byte stream. Keep it only as a named compatibility lowering until the
|
||||
OBS receiver can consume typed media frames directly.
|
||||
|
||||
## Boring Stream Discovery Contract
|
||||
|
||||
The desired operator experience is boring: OBS asks the Verse for Muninns, the
|
||||
plugin shows live sources, and a selected source either activates or reports the
|
||||
specific owner that refused it. No local plugin fallback may invent Raven
|
||||
devices. A fake `display:0` or Realtek loopback row is worse than an empty list
|
||||
because it makes stale state look selectable.
|
||||
|
||||
Live ownership:
|
||||
|
||||
- Owner: Muninn `serve` owns source inventory for the body where the devices
|
||||
exist. It publishes video and audio source ids, labels, command boundary,
|
||||
media profile, and current active sessions.
|
||||
- Inputs: local display/audio enumeration, explicit configured source hints,
|
||||
daemon health, and accepted stream commands.
|
||||
- Outputs: `muninn.telemetry_surface.v1`, `gamecult.eve.provider_advertisement.v1`,
|
||||
`muninn.command_boundary.v1`, `muninn.transport_profile.v1`, active
|
||||
`muninn.capture_stream.v1` receipts, and the temporary
|
||||
`muninn.obs_stream_catalog.v1` compatibility record.
|
||||
- Derived state: the OBS dropdown is a lowering of discovered Muninn state. It
|
||||
is not an inventory owner, activation owner, or health owner.
|
||||
- Forbidden writers: OBS defaults, local hard-coded device names, synced stale
|
||||
CultCache mirrors, scheduled-task launchers, and previous activation receipts
|
||||
must not create selectable devices or active streams.
|
||||
- Shared paths: initial OBS load, refresh button, periodic refresh, source
|
||||
selection, reconnect, and OBS restart must all read the same live-discovered
|
||||
source list and issue the same typed capture command when activation is
|
||||
needed.
|
||||
- Deletion line: the plugin may display `discovery missing`, but it must not
|
||||
synthesize `Display 1` or `Realtek loopback` as if Raven advertised them.
|
||||
Until Odin/Verse discovery is the direct plugin input, the OBS catalog remains
|
||||
a compatibility projection of Muninn-owned live state, not its own truth.
|
||||
Compatibility store fallback is allowed only as availability fallback: the
|
||||
plugin must use the first current store that yields Muninn telemetry and must
|
||||
not merge stale stores into a more attractive fake inventory.
|
||||
A store older than the Muninn health freshness budget is not a discovery
|
||||
source; it is an outage receipt.
|
||||
|
||||
This contract also splits the media session truth:
|
||||
|
||||
- Video session: selected video source id, encoder profile, bitrate, frame
|
||||
timestamps, access-unit ids, keyframe policy, feedback pressure, and video
|
||||
receiver queue.
|
||||
- Audio session: selected audio source id, sample format, packet timestamps,
|
||||
reorder budget, continuity/drop policy, and OBS audio output cadence.
|
||||
- Combined OBS source: a convenience lowering that may request one video session
|
||||
and one audio session together. It does not merge their clocks or transport
|
||||
state into one opaque "A/V target".
|
||||
|
||||
## Known-Good Checkpoint (2026-06-23)
|
||||
|
||||
The current system is in a usable compatibility state worth preserving before
|
||||
the next transport experiment.
|
||||
|
||||
What is working:
|
||||
|
||||
- Raven Muninn runs continuously as the capture owner and accepts stream
|
||||
activation over CultNet RUDP.
|
||||
- OBS on Starfire shows the live-discovered Muninn source inventory instead of
|
||||
synthesizing fake devices from stale local defaults.
|
||||
- Video and audio sessions activate separately through the combined OBS source
|
||||
lowering and the stream comes up cleanly again after reconnect.
|
||||
- The OBS plugin currently receives the temporary live
|
||||
`muninn.obs_stream_catalog.v1` projection over UDP `17874` and uses it as the
|
||||
live discovery source before any CultCache fallback.
|
||||
|
||||
Current compatibility details:
|
||||
|
||||
- Raven command ingress is currently bound to `0.0.0.0:17883`.
|
||||
- Starfire OBS listens for the temporary live OBS catalog on UDP `17874`.
|
||||
- The daemon `serve` loop must continue publishing the OBS catalog while idle;
|
||||
otherwise OBS falls back to stale store state and reports `discovery-missing`
|
||||
or shows dead inventory.
|
||||
- The current OBS plugin is still a compatibility client. It does not yet host
|
||||
the Rust CultMesh runtime directly and it is not yet consuming Odin/Verse
|
||||
discovery as a first-class Verse client.
|
||||
|
||||
Known debt that remains intentionally visible:
|
||||
|
||||
- Idunn health publication can still time out independently of the media path.
|
||||
That is operational debt, not proof that Muninn discovery or streaming is
|
||||
down.
|
||||
- The OBS catalog is still a temporary projection. The boring end state is live
|
||||
Verse discovery with no plugin-owned catalog receiver and no stale store
|
||||
merge behavior.
|
||||
|
||||
## Codec Direction
|
||||
|
||||
Use vendor hardware encode before inventing a codec. NVIDIA's practical answer
|
||||
in this space is NVENC/NVDEC, low-latency encode presets, high LAN bitrate,
|
||||
short GOP or intra-refresh, no B-frames, no lookahead, and application-level
|
||||
transport that understands frame deadlines.
|
||||
|
||||
Shipping order:
|
||||
|
||||
1. H.264 NVENC low-latency as the compatibility baseline for broad decoder
|
||||
support, simple failure analysis, and OBS bridge stability.
|
||||
2. HEVC NVENC low-latency when Raven encode and OBS decode both prove the
|
||||
target latency budget.
|
||||
3. AV1 NVENC only after the exact Raven-to-OBS path proves encode, decode, and
|
||||
queue latency inside budget. AV1 can be the quality/bandwidth winner, but it
|
||||
must earn the low-latency lane on our hardware instead of getting promoted by
|
||||
codec fashion.
|
||||
|
||||
The codec should produce elementary video access units, not a muxed MPEG-TS
|
||||
program. Audio should use Opus low-delay packets unless the OBS lowering needs
|
||||
a temporary PCM/AAC compatibility bridge.
|
||||
|
||||
Recommended first LAN profile:
|
||||
|
||||
- Profile id: `muninn.rudp.low_latency_h264_lan.v1`.
|
||||
- Video: H.264 NVENC, `p5` (`main.rs:9504`), ultra-low-latency tune, CBR high enough that LAN
|
||||
bandwidth is not the constraint, no B-frames, no lookahead, short GOP or
|
||||
intra-refresh, keyframe actuation on feedback pressure (not built: keyframe requests are only
|
||||
counted and logged today; Cut 6 builds it).
|
||||
- VBV: derive `bufsize` from roughly one frame of bitrate
|
||||
(`bitrate_kbps / framerate`) instead of a large fixed encoder reservoir.
|
||||
The point is bounded latency, not hoarding compressed video in a nicer hat.
|
||||
- Audio: Opus low-delay when OBS lowering can consume it directly; otherwise a
|
||||
temporary PCM/AAC bridge with separate packet identity and clock.
|
||||
- Transport: payload elementary access units as typed media records, never a
|
||||
muxed container as the unit of truth.
|
||||
- Packet size: default typed media chunks are `848` bytes (`main.rs:81`). That leaves headroom
|
||||
for CultNet/MessagePack/RUDP headers inside a normal Ethernet MTU so the OBS
|
||||
bridge does not depend on IP fragmentation or private RUDP fragment
|
||||
reassembly. The sender also sets CultNet RUDP `max_fragment_bytes` to `1431`
|
||||
bytes (`1472` byte IPv4 UDP payload budget minus `36` RUDP fixed header bytes
|
||||
minus the five-byte `media` channel id), so oversized typed records fragment
|
||||
in CultNet deliberately instead of falling through to accidental IP
|
||||
fragmentation.
|
||||
- Resend cadence: sender RUDP media resends are scheduled every `30` ms (`main.rs:94`) while
|
||||
the packet is still inside its expiry, which is the request's latency budget (a request that names none gets `250` ms, `main.rs:98`, and the advertisement offers the same as `default_latency_budget_ms`).
|
||||
- Send queue: `media_send.rs` owns it. The unit is a group, one access unit with its parity or one audio packet, stamped `produced_at + latency budget` when the packetizer emits it. A request's latency budget is clamped to 1..=2000 ms. The send loop moves one payload per step and picks it afresh each time: audio, then repairs, then video, so audio never waits behind more than the payload in progress, full socket or not. The group deadline is checked before every payload; a group that outlives it mid-send is abandoned and counted `groups_cut_short`. Queues are capped per kind (audio 256, video 512 groups) and drop the oldest group, counted as `groups_dropped_audio` and `groups_dropped_video`. Every access unit the sender drops (queue cap, expiry, packetizer overflow) has already consumed its frame id, so the receiver sees a gap; an overflow also discards the dropped frame's remaining slices instead of emitting them as a frame. A repair keeps the deadline of the frame it repairs, goes only to the receiver that asked, and is not sent after that deadline.
|
||||
- Control: sender may adapt bitrate, keyframe cadence, chunk size, and playout
|
||||
budget from receiver feedback; the receiver must not silently stretch latency
|
||||
to preserve visual perfection.
|
||||
- Receiver URL policy: RUDP stream URLs carry `profile`,
|
||||
`sender_resend_delay_ms`, `reliable_expire_after_ms`,
|
||||
`assembly_deadline_ms`, and `gap_wait_ms` so the OBS bridge receives timing
|
||||
budget from Muninn's stream profile instead of hard-coding receiver policy
|
||||
privately.
|
||||
|
||||
### Motion Vectors And Reconstruction
|
||||
|
||||
Do not make CultMesh a bespoke game-streaming codec in the first shipping path.
|
||||
The motion-vector/delta idea is real, but it belongs as an augmentation around
|
||||
the hardware codec, not as the primary authority.
|
||||
|
||||
NVIDIA's relevant public pattern is:
|
||||
|
||||
- NVENC/NVDEC for hardware video encode and decode.
|
||||
- Low-latency encode tuning, high refresh rate, adaptive bitrate, and explicit
|
||||
network/frame timing for cloud gaming.
|
||||
- Foveated streaming for bandwidth reduction when a trusted focus region exists.
|
||||
- Optical Flow / motion estimation hardware for interpolation, extrapolation,
|
||||
analysis, or concealment experiments.
|
||||
|
||||
For Muninn, that means:
|
||||
|
||||
- If we only have desktop capture pixels, trust NVENC for motion estimation and
|
||||
compression. Do not compute our own patch stream before the codec has failed a
|
||||
measured requirement.
|
||||
- If a game or renderer we control can expose motion vectors, depth, regions of
|
||||
interest, or dirty rectangles, publish them as optional sideband media hints.
|
||||
They may guide encoder ROI, decoder concealment, frame extrapolation, or
|
||||
foveated quality allocation. They do not replace the encoded video access
|
||||
unit unless a separate research path proves that decoder under the same OBS
|
||||
latency budget.
|
||||
- Stochastic reconstruction is allowed only inside a bounded playout budget.
|
||||
When the deadline expires, the receiver displays the best available frame,
|
||||
conceals damage, or requests a keyframe. It must not preserve dead packets by
|
||||
growing latency.
|
||||
|
||||
Useful references for this direction:
|
||||
|
||||
- NVIDIA Video Codec SDK presets describe low-latency and ultra-low-latency
|
||||
tuning plus preset tradeoffs for encoder tools such as GOP structure,
|
||||
B-frames, and lookahead:
|
||||
<https://developer.nvidia.com/blog/introducing-video-codec-sdk-10-presets/>
|
||||
- NVIDIA CloudXR publicly frames low-latency spatial streaming around NVENC,
|
||||
adaptive bitrate, foveated streaming, diagnostics, and bidirectional data
|
||||
channels:
|
||||
<https://docs.nvidia.com/cloudxr-sdk/latest/overview/overview.html>
|
||||
- NVIDIA's Optical Flow SDK exposes hardware motion vectors for real-time
|
||||
interpolation/extrapolation and related video processing:
|
||||
<https://developer.nvidia.com/optical-flow-sdk>
|
||||
|
||||
## CultNet RUDP Media Policy
|
||||
|
||||
The RUDP `media` channel should become a media-aware lane, not merely a reliable
|
||||
unordered byte lane.
|
||||
|
||||
Required behavior:
|
||||
|
||||
- Frame-level fragmentation and reassembly keyed by `(stream_id, session_id,
|
||||
frame_id)`.
|
||||
- Deadline-aware retransmission: resend while useful, drop when the playout
|
||||
budget is gone.
|
||||
- Receiver feedback that can NACK missing chunks, request a keyframe, and
|
||||
report jitter/decode queue pressure.
|
||||
- Small playout buffer chosen by policy, for example 8-20 ms on a wired LAN.
|
||||
- Optional FEC/parity for video chunks where one repair packet beats a resend.
|
||||
- Separate audio policy that favors continuity and bounded drift over perfect
|
||||
packet recovery.
|
||||
|
||||
## OBS Lowering
|
||||
|
||||
The OBS plugin should lower typed media frames into OBS-friendly video/audio.
|
||||
The clean target is direct decode from elementary streams using libavcodec or
|
||||
NVDEC where available, then hand decoded video frames and audio packets to OBS.
|
||||
|
||||
Temporary bridge allowed:
|
||||
|
||||
- Reconstruct an elementary stream from typed video access units.
|
||||
- Feed the local FFmpeg source only as a compatibility decoder.
|
||||
- Keep audio as a separate OBS audio path so audio sync is explicit instead of
|
||||
being hidden inside a damaged MPEG-TS stream.
|
||||
|
||||
The compatibility bridge must not own stream truth. It is a lowering target,
|
||||
not the protocol.
|
||||
|
||||
## Cut Plan
|
||||
|
||||
1. Promote media-frame schemas in Odin/CultLib and add unit tests for
|
||||
encode/decode round trips.
|
||||
2. Teach Muninn activation to emit video access units and audio packets instead
|
||||
of arbitrary MPEG-TS byte chunks.
|
||||
3. Teach CultNet RUDP media receive to reassemble by frame and deadline, with
|
||||
explicit NACK/keyframe feedback.
|
||||
4. Teach the OBS plugin to consume typed media frames and feed OBS through a
|
||||
direct decoder or a narrowly named compatibility elementary-stream bridge.
|
||||
5. Remove the MPEG-TS byte-chunk hot path once the typed receiver is stable.
|
||||
|
||||
## Verification
|
||||
|
||||
The rebuild is not proven by "OBS shows video once." Minimum proof:
|
||||
|
||||
- Raven `serve` remains idle until an explicit capture command arrives.
|
||||
- OBS request activates Raven without manual Raven terminals.
|
||||
- Sender logs and receiver telemetry agree on stream id, session id, frame id,
|
||||
codec, PTS, deadlines, drops, NACKs, and keyframe requests.
|
||||
- A forced packet drop causes bounded damage and recovery, not OBS freeze.
|
||||
- Audio remains present as an OBS audio source and stays within the chosen
|
||||
sync budget.
|
||||
- Restarting OBS does not strand Raven capture or poison the next request with
|
||||
stale command receipts.
|
||||
- Restarting Raven Muninn restores catalog/health without starting capture
|
||||
until requested.
|
||||
|
|
@ -3,20 +3,25 @@
|
|||
Muninn is Odin's portable local telemetry Verse assembler.
|
||||
|
||||
It runs on a device body and publishes a typed CultMesh/CultCache surface for
|
||||
what that body can sense or expose locally: screen capture, loopback audio,
|
||||
microphones, cameras, and future sensors.
|
||||
what that body exposes locally: PS Move controllers and optical marker evidence,
|
||||
HID/XInput gamepads, and Quest USB access.
|
||||
|
||||
> The deprecated A/V streaming stack (screen capture, WASAPI loopback audio,
|
||||
> FFmpeg muxing, `muninn.capture_stream.v1`, `muninn.obs_stream_catalog.v1`,
|
||||
> `request-stream`, and `wasapi-loopback-capture.ps1`) was removed on
|
||||
> 2026-12-03 and archived at git tag `parked/muninn-media-streaming-2026-12-03`.
|
||||
|
||||
## Authority
|
||||
|
||||
- Owner: Muninn owns local telemetry discovery, stream affordance publication,
|
||||
and explicit activation of requested local streams.
|
||||
- Inputs: cheap local probes, operator or Verse activation requests, and local
|
||||
capture tools such as FFmpeg or WASAPI helpers.
|
||||
- Outputs: `muninn.telemetry_surface.v1`, active `muninn.capture_stream.v1`,
|
||||
- Owner: Muninn owns local telemetry discovery, HID RUDP endpoint
|
||||
serving/advertisement, Quest USB probing, and local Move evidence/light state.
|
||||
- Inputs: cheap local HID/USB/camera probes and typed Move commands (`muninn.move_light_command.v1`, `muninn.move_hue_program.v1`).
|
||||
- Outputs: `muninn.telemetry_surface.v1`, `gamecult.eve.provider_advertisement.v1`
|
||||
(carrying HID RUDP endpoints for Sleipnir), `muninn.hid_controller_state.v1`,
|
||||
Quest access records, Move receipt records, and a CultMesh bytes stream
|
||||
carrying live Move evidence frames for Mimir.
|
||||
- Forbidden writers: daemon startup, Idunn keepalive, Mimir ingest, OBS, Odin,
|
||||
Gjallar, and renderer bodies must not start capture by implication.
|
||||
- Forbidden writers: daemon startup, Idunn keepalive, Mimir ingest, Odin, and
|
||||
renderer bodies must not hijack Muninn's local device state.
|
||||
|
||||
## Runtime
|
||||
|
||||
|
|
@ -26,33 +31,21 @@ muninn serve --store C:\Meta\Odin\state\muninn.telemetry.cc --interval-seconds 1
|
|||
muninn --health --store C:\Meta\Odin\state\muninn.telemetry.cc
|
||||
```
|
||||
|
||||
`serve` is cheap and idle. It publishes affordances, consumes addressed pending
|
||||
`muninn.move_light_command.v1` records, and keeps the local Verse surface fresh
|
||||
without starting FFmpeg, screen capture, microphone capture, or loopback
|
||||
capture.
|
||||
`serve` publishes `muninn.telemetry_surface.v1` and Odin's
|
||||
`gamecult.eve.provider_advertisement.v1` lease (including
|
||||
`--hid-controller-rudp-advertise` when HID RUDP serving is enabled), consumes
|
||||
addressed pending `muninn.move_light_command.v1` records, syncs
|
||||
`muninn.move_hue_program.v1`, and keeps the local telemetry surface fresh.
|
||||
|
||||
Muninn writes its stream affordance catalog as typed CultCache state inside:
|
||||
Muninn writes its telemetry surface and local state as typed CultCache state inside:
|
||||
|
||||
```text
|
||||
C:\Meta\Odin\state\muninn.telemetry.cc
|
||||
```
|
||||
|
||||
The record is type `muninn.obs_stream_catalog` with schema
|
||||
`muninn.obs_stream_catalog.v1` at key `obs`. Consumers discover the catalog
|
||||
through Odin/CultMesh; Muninn does not publish a parallel OBS RUDP catalog.
|
||||
|
||||
Activation is explicit typed state:
|
||||
|
||||
```powershell
|
||||
muninn request-stream --target-host cultmesh://odin/media/muninn-raven-av --media-transport rudp
|
||||
```
|
||||
|
||||
`target_host` in the legacy command record field is a CultMesh URI, not a host
|
||||
or IP. The activation child resolves `muninn.media.rudp.v1` endpoints from
|
||||
Odin's provider catalog before opening the CultNet RUDP media lane. SRT, OBS
|
||||
target flags, and standalone Raven activation scripts are archived; Mimir,
|
||||
OBS, and other renderers are consumers of Odin/CultMesh discovery, not transport
|
||||
owners.
|
||||
Peers such as Sleipnir discover Muninn's HID RUDP endpoint from Odin's
|
||||
`gamecult.eve.provider_advertisement.v1` catalog rather than passing static
|
||||
port bindings out of band.
|
||||
|
||||
## Quest Access And Unity Return Video
|
||||
|
||||
|
|
@ -93,8 +86,8 @@ For Starfire's local Quest-attached daemon, Idunn supervises the
|
|||
`starfire-muninn` target through:
|
||||
|
||||
```powershell
|
||||
E:\Projects\Odin\scripts\restart-starfire-muninn.cmd
|
||||
E:\Projects\Odin\scripts\health-starfire-muninn.cmd
|
||||
scripts/restart-starfire-muninn.ps1
|
||||
scripts/health-starfire-muninn.ps1
|
||||
```
|
||||
|
||||
The restart script launches Muninn hidden with `--host starfire --quest-adb`.
|
||||
|
|
@ -103,17 +96,6 @@ fails MessagePack decode on boot, the restart path archives the corrupt file,
|
|||
clears the stale `.lock`, and relaunches the daemon instead of leaving the lane
|
||||
dead.
|
||||
|
||||
The deployed loopback helper must accept Muninn's command contract:
|
||||
|
||||
```powershell
|
||||
wasapi-loopback-capture.ps1 -Output stdout -Device Realtek -SampleRate 48000 -Channels 2
|
||||
```
|
||||
|
||||
`stdout` is an alias for binary standard output, and `Device` is the requested
|
||||
render-device hint. Current helper builds may ignore the hint and use the
|
||||
default render endpoint, but they must accept the argument so Muninn's generated
|
||||
mux command remains executable.
|
||||
|
||||
## Move Marker Candidates
|
||||
|
||||
`crates/muninn-move-tracker` is Muninn's native/Rust PS Move optical candidate
|
||||
|
|
@ -197,9 +179,9 @@ missing or the Quest is unavailable, Muninn publishes `muninn.quest_access` as
|
|||
## Host Deployments
|
||||
|
||||
Raven is deployed by Idunn since 2026-09-11. `deployment/idunn/raven-muninn.toml`
|
||||
is the target declaration: the build step, the two artifacts (`muninn.exe`
|
||||
and the loopback capture script) and the launch contract. Raven's paths and
|
||||
advertised endpoints are argument bindings in the yggdrasil operator binding
|
||||
is the target declaration: the build step, the `muninn.exe` artifact, and the
|
||||
launch contract. Raven's paths and advertised endpoints are argument bindings in
|
||||
the yggdrasil operator binding
|
||||
(`gamecult-ops/idunn/yggdrasil/bindings/raven-muninn.toml.in`). The host
|
||||
actuator (`idunn-host`, from the Idunn repo) runs in Raven's user session,
|
||||
builds the exact frozen revision with Raven's own cargo, installs the sealed
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,37 +1,29 @@
|
|||
# Streaming deprecation (Meta, 2026-11-06)
|
||||
# Streaming deprecation & removal (Meta, 2026-11-06; removed 2026-12-03)
|
||||
|
||||
Muninn's streaming role and the OBS media receiver are superseded in the streaming
|
||||
space. Scope: screen and loopback-audio capture, the media sender, and the receiver at
|
||||
github.com/GameCult/Ratatoskr (forge mirror `GameCult/Ratatoskr-receiver`; the forge repo
|
||||
`GameCult/Ratatoskr` is an unrelated chat client and is not covered). Nothing has been
|
||||
deleted. The lists below come from file names and docs, not from a consumer audit;
|
||||
confirm each consumer before cutting.
|
||||
Muninn's streaming role and the OBS media receiver were superseded in the streaming
|
||||
space (screen and loopback-audio capture, the media sender, and the receiver at
|
||||
github.com/GameCult/Ratatoskr; forge mirror `GameCult/Ratatoskr-receiver`, distinct
|
||||
from the unrelated `GameCult/Ratatoskr` chat client).
|
||||
|
||||
## What depends on the streaming role
|
||||
On 2026-12-03 (`kiko-body:ruling:strip-deprecated-streaming-pipe`), the streaming
|
||||
stack was removed from the active tree and archived at git tag
|
||||
`parked/muninn-media-streaming-2026-12-03`.
|
||||
|
||||
- Nothing in StreamPixels on main. StreamPixels `tools/showcheck` (PR #2) read Muninn's
|
||||
activation log and the receiver's OBS log until it was rescoped on 2026-11-06 (a762f69)
|
||||
to server, overlay and OBS only; the Muninn and Ratatoskr hops are gone from it and
|
||||
survive only on its parked branch `kiko/showcheck-muninn-chain`.
|
||||
- Docs here that describe it: `docs/muninn-media-streaming.md`,
|
||||
`docs/realtime-robustness-cut.md`, and the receiver sections of `docs/teardown-map.md`.
|
||||
- Operations: `scripts/activate-muninn-raven-*`, `scripts/health-*`,
|
||||
`scripts/restart-*`, and `deployment/idunn` (the health and restart scripts also serve
|
||||
the non-streaming daemon, so they stay).
|
||||
- The receiver repo's README names Muninn in prose.
|
||||
|
||||
## Removal candidates (streaming only; verify consumers first)
|
||||
## Removed surfaces (archived at `parked/muninn-media-streaming-2026-12-03`)
|
||||
|
||||
- `crates/muninn-daemon/src/media_send.rs`, `media_send/tests.rs`,
|
||||
`media_packetizer.rs`, and the media wiring in `main.rs`.
|
||||
- Media-related records in `crates/muninn-contracts` (`records.rs`, `lib.rs`), if no
|
||||
non-streaming consumer reads them.
|
||||
- `scripts/activate-muninn-raven-av-srt.cmd`, `scripts/activate-muninn-raven-media.ps1`,
|
||||
`scripts/wasapi-loopback-capture.ps1`.
|
||||
- `docs/muninn-media-streaming.md` (move to history rather than delete if it is cited).
|
||||
`media_packetizer.rs`, test fixtures (`clip.h264`), and media capture/mux/catalog
|
||||
wiring in `crates/muninn-daemon/src/main.rs`.
|
||||
- Streaming-only records (`MuninnCaptureStreamRecord`,
|
||||
`MuninnCaptureStreamCommandRecord`, `MuninnObsStreamCatalogRecord`,
|
||||
`MuninnCommandBoundaryCompatRecord`, `MuninnTransportProfileCompatRecord`) in
|
||||
`crates/muninn-contracts`.
|
||||
- `scripts/wasapi-loopback-capture.ps1`, `scripts/activate-muninn-raven-av-srt.cmd`,
|
||||
`scripts/activate-muninn-raven-media.ps1`, dead `.cmd` health stubs, and
|
||||
`docs/muninn-media-streaming.md` / `docs/realtime-robustness-cut.md`.
|
||||
- `muninn.media-producer` and streaming arguments in `deployment/idunn/raven-muninn.toml`.
|
||||
|
||||
## Keep
|
||||
## Kept
|
||||
|
||||
Sensor serving, PS Move tracking (`muninn-move-tracker`, `muninn-psmoveapi-tracker`,
|
||||
`native/`), and `sleipnir-daemon` input are outside this notice. Do not remove them under
|
||||
it. `idunn_presence.rs` matched a media search term only; it is presence, not streaming.
|
||||
`native/`), `Quest`, `idunn_presence.rs`, and `sleipnir-daemon` remain active.
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
@echo off
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File %~dp0activate-muninn-raven-av-srt.ps1
|
||||
|
|
@ -1 +0,0 @@
|
|||
throw "activate-muninn-raven-media.ps1 archived: Muninn media activation is daemon-owned and target resolution is through Odin/CultMesh. Redeploy Muninn through Idunn and publish a typed muninn.capture_stream_command with a cultmesh:// media target URI."
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
@echo off
|
||||
echo health-muninn.cmd archived: Raven Muninn has no daemon-published health. Run health-muninn.ps1 as an explicit witness inspection (scheduled-task actions, serve process, store freshness); it is not Idunn health truth.
|
||||
exit /b 2
|
||||
|
|
@ -2,7 +2,6 @@ param(
|
|||
[string] $RavenHost = "raven-local",
|
||||
[string] $MuninnExe = "C:\Meta\Odin\Muninn\muninn.exe",
|
||||
[string] $StorePath = "C:\Meta\Odin\state\muninn.telemetry.cc",
|
||||
[string] $ActivateStorePath = "C:\Meta\Odin\state\muninn.activate.cc",
|
||||
[string] $LogRoot = "C:\Meta\Odin\logs\muninn",
|
||||
[int] $MaxStoreAgeSeconds = 180,
|
||||
[int] $ConnectTimeoutSeconds = 10,
|
||||
|
|
@ -171,8 +170,7 @@ if (`$null -eq `$process) {
|
|||
throw "Muninn serve process is not running"
|
||||
}
|
||||
foreach (`$pattern in @(
|
||||
"--host raven",
|
||||
"--activate-store $ActivateStorePath"
|
||||
"--host raven"
|
||||
)) {
|
||||
if (`$process.CommandLine -notlike "*`$pattern*") {
|
||||
throw "Muninn serve process is missing expected command-line segment `${pattern}: `$(`$process.CommandLine)"
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
@echo off
|
||||
echo health-nightwing-muninn.cmd archived: Nightwing Muninn has no daemon-published health. Run health-nightwing-muninn.ps1 as an explicit witness inspection (serve process, store freshness, PID file); it is not Idunn health truth.
|
||||
exit /b 2
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
@echo off
|
||||
echo health-starfire-muninn.cmd archived: Starfire Muninn has no daemon-published health. Run health-starfire-muninn.ps1 as an explicit witness inspection (serve process, store freshness, PID file); it is not Idunn health truth.
|
||||
exit /b 2
|
||||
|
|
@ -20,8 +20,7 @@ param(
|
|||
[string] $OdinCultMeshUri = $(if ($env:ODIN_CULTMESH_URI) { $env:ODIN_CULTMESH_URI } else { "cultmesh://odin/rendezvous/provider-catalog" }),
|
||||
[string] $OdinCultMeshRudpEndpoint = $(if ($env:CULTMESH_URI_ODIN_RUDP) { $env:CULTMESH_URI_ODIN_RUDP } else { "10.77.0.2:17871" }),
|
||||
[string] $HidControllerRudpBind = "0.0.0.0:17888",
|
||||
[string] $HidControllerRudpAdvertise = $(if ($env:MUNINN_HID_CONTROLLER_RUDP_ADVERTISE) { $env:MUNINN_HID_CONTROLLER_RUDP_ADVERTISE } else { "10.77.0.3:17888" }),
|
||||
[string] $CommandRudpAdvertise = "10.77.0.3:17889"
|
||||
[string] $HidControllerRudpAdvertise = $(if ($env:MUNINN_HID_CONTROLLER_RUDP_ADVERTISE) { $env:MUNINN_HID_CONTROLLER_RUDP_ADVERTISE } else { "10.77.0.3:17888" })
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
|
@ -125,7 +124,6 @@ if (-not [string]::IsNullOrWhiteSpace($HidControllerRudpAdvertise)) {
|
|||
$hidControllerRudpSetLines += "set -- ""`$@"" --hid-controller-rudp-advertise $(Quote-ShSingle $HidControllerRudpAdvertise)"
|
||||
}
|
||||
$hidControllerRudpSetBlock = ($hidControllerRudpSetLines -join "`n")
|
||||
$commandRudpSetBlock = "set -- ""`$@"" --command-rudp-advertise $(Quote-ShSingle $CommandRudpAdvertise)"
|
||||
$remoteScript = @"
|
||||
set -eu
|
||||
mkdir -p '$LogRoot'
|
||||
|
|
@ -155,7 +153,6 @@ set -- "`$@" \
|
|||
--interval-seconds '$IntervalSeconds'
|
||||
$odinCultMeshUriSetBlock
|
||||
$hidControllerRudpSetBlock
|
||||
$commandRudpSetBlock
|
||||
CULTNET_RUDP_TRACE=1 CULTMESH_URI_ODIN_RUDP='$OdinCultMeshRudpEndpoint' nohup '$MuninnExe' "`$@" \
|
||||
> '$LogRoot/muninn-serve.out.log' \
|
||||
2> '$LogRoot/muninn-serve.err.log' \
|
||||
|
|
|
|||
|
|
@ -1,469 +0,0 @@
|
|||
param(
|
||||
[string]$Output = "-",
|
||||
[string]$Device = "",
|
||||
[double]$Seconds = 0,
|
||||
[int]$SampleRate = 48000,
|
||||
[int]$Channels = 2,
|
||||
[ValidateSet("Render", "Capture")]
|
||||
[string]$DataFlow = "Render",
|
||||
[switch]$Loopback,
|
||||
[ValidateSet("Console", "Multimedia", "Communications")]
|
||||
[string]$Role = "Console"
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$source = @"
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
|
||||
namespace Mimir {
|
||||
public static class WasapiLoopbackCapture {
|
||||
const int eRender = 0;
|
||||
const int eCapture = 1;
|
||||
const int eConsole = 0;
|
||||
const int eMultimedia = 1;
|
||||
const int eCommunications = 2;
|
||||
const int CLSCTX_ALL = 23;
|
||||
const uint DEVICE_STATE_ACTIVE = 0x00000001;
|
||||
const uint AUDCLNT_SHAREMODE_SHARED = 0;
|
||||
const uint AUDCLNT_STREAMFLAGS_LOOPBACK = 0x00020000;
|
||||
const int AUDCLNT_BUFFERFLAGS_SILENT = 0x2;
|
||||
static readonly Guid IID_IAudioClient = new Guid("1CB9AD4C-DBFA-4c32-B178-C2F568A703B2");
|
||||
static readonly Guid IID_IAudioCaptureClient = new Guid("C8ADBD64-E71E-48a0-A4DE-185C395CD317");
|
||||
static readonly Guid PcmSubformat = new Guid("00000001-0000-0010-8000-00aa00389b71");
|
||||
static readonly Guid FloatSubformat = new Guid("00000003-0000-0010-8000-00aa00389b71");
|
||||
static readonly PROPERTYKEY DeviceFriendlyNameKey = new PROPERTYKEY(
|
||||
new Guid("A45C254E-DF1C-4EFD-8020-67D146A850E0"),
|
||||
14);
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
struct WAVEFORMATEX {
|
||||
public ushort wFormatTag;
|
||||
public ushort nChannels;
|
||||
public uint nSamplesPerSec;
|
||||
public uint nAvgBytesPerSec;
|
||||
public ushort nBlockAlign;
|
||||
public ushort wBitsPerSample;
|
||||
public ushort cbSize;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential, Pack = 2)]
|
||||
struct WAVEFORMATEXTENSIBLE {
|
||||
public WAVEFORMATEX Format;
|
||||
public ushort wValidBitsPerSample;
|
||||
public uint dwChannelMask;
|
||||
public Guid SubFormat;
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct PROPERTYKEY {
|
||||
public Guid fmtid;
|
||||
public uint pid;
|
||||
|
||||
public PROPERTYKEY(Guid formatId, uint propertyId) {
|
||||
fmtid = formatId;
|
||||
pid = propertyId;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
struct PROPVARIANT {
|
||||
public ushort vt;
|
||||
public ushort wReserved1;
|
||||
public ushort wReserved2;
|
||||
public ushort wReserved3;
|
||||
public IntPtr pointerValue;
|
||||
public int intValue;
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")]
|
||||
class MMDeviceEnumerator { }
|
||||
|
||||
[ComImport]
|
||||
[Guid("A95664D2-9614-4F35-A746-DE8DB63617E6")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
interface IMMDeviceEnumerator {
|
||||
[PreserveSig]
|
||||
int EnumAudioEndpoints(int dataFlow, uint stateMask, out IMMDeviceCollection devices);
|
||||
[PreserveSig]
|
||||
int GetDefaultAudioEndpoint(int dataFlow, int role, out IMMDevice endpoint);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("0BD7A1BE-7A1A-44DB-8397-CC5392387B5E")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
interface IMMDeviceCollection {
|
||||
[PreserveSig]
|
||||
int GetCount(out uint count);
|
||||
[PreserveSig]
|
||||
int Item(uint index, out IMMDevice device);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("D666063F-1587-4E43-81F1-B948E807363F")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
interface IMMDevice {
|
||||
[PreserveSig]
|
||||
int Activate(ref Guid iid, int dwClsCtx, IntPtr pActivationParams, out IAudioClient audioClient);
|
||||
[PreserveSig]
|
||||
int OpenPropertyStore(uint access, out IPropertyStore properties);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
interface IPropertyStore {
|
||||
[PreserveSig]
|
||||
int GetCount(out uint propertyCount);
|
||||
[PreserveSig]
|
||||
int GetAt(uint propertyIndex, out PROPERTYKEY key);
|
||||
[PreserveSig]
|
||||
int GetValue(ref PROPERTYKEY key, out PROPVARIANT value);
|
||||
[PreserveSig]
|
||||
int SetValue(ref PROPERTYKEY key, ref PROPVARIANT value);
|
||||
[PreserveSig]
|
||||
int Commit();
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("1CB9AD4C-DBFA-4c32-B178-C2F568A703B2")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
interface IAudioClient {
|
||||
[PreserveSig]
|
||||
int Initialize(uint shareMode, uint streamFlags, long hnsBufferDuration, long hnsPeriodicity, IntPtr pFormat, IntPtr audioSessionGuid);
|
||||
[PreserveSig]
|
||||
int GetBufferSize(out uint bufferSize);
|
||||
[PreserveSig]
|
||||
int GetStreamLatency(out long latency);
|
||||
[PreserveSig]
|
||||
int GetCurrentPadding(out uint currentPadding);
|
||||
[PreserveSig]
|
||||
int IsFormatSupported(uint shareMode, IntPtr pFormat, out IntPtr closestMatch);
|
||||
[PreserveSig]
|
||||
int GetMixFormat(out IntPtr deviceFormat);
|
||||
[PreserveSig]
|
||||
int GetDevicePeriod(out long defaultDevicePeriod, out long minimumDevicePeriod);
|
||||
[PreserveSig]
|
||||
int Start();
|
||||
[PreserveSig]
|
||||
int Stop();
|
||||
[PreserveSig]
|
||||
int Reset();
|
||||
[PreserveSig]
|
||||
int SetEventHandle(IntPtr eventHandle);
|
||||
[PreserveSig]
|
||||
int GetService(ref Guid iid, out IAudioCaptureClient captureClient);
|
||||
}
|
||||
|
||||
[ComImport]
|
||||
[Guid("C8ADBD64-E71E-48a0-A4DE-185C395CD317")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
interface IAudioCaptureClient {
|
||||
[PreserveSig]
|
||||
int GetBuffer(out IntPtr data, out uint frames, out uint flags, out ulong devicePosition, out ulong qpcPosition);
|
||||
[PreserveSig]
|
||||
int ReleaseBuffer(uint frames);
|
||||
[PreserveSig]
|
||||
int GetNextPacketSize(out uint frames);
|
||||
}
|
||||
|
||||
[DllImport("ole32.dll")]
|
||||
static extern int PropVariantClear(ref PROPVARIANT variant);
|
||||
|
||||
public static void Capture(string outputPath, string deviceSubstring, double seconds, int targetRate, int targetChannels, string dataFlowName, bool loopback, string roleName) {
|
||||
Stream output = IsStdoutPath(outputPath) ? Console.OpenStandardOutput() : new FileStream(outputPath, FileMode.Create, FileAccess.Write, FileShare.Read);
|
||||
try {
|
||||
IMMDeviceEnumerator enumerator = (IMMDeviceEnumerator)(new MMDeviceEnumerator());
|
||||
int dataFlow = DataFlowFromName(dataFlowName);
|
||||
uint streamFlags = loopback ? AUDCLNT_STREAMFLAGS_LOOPBACK : 0u;
|
||||
IMMDevice device = ResolveDevice(enumerator, dataFlow, roleName, deviceSubstring);
|
||||
try {
|
||||
IAudioClient audioClient;
|
||||
Guid audioClientId = IID_IAudioClient;
|
||||
Check(device.Activate(ref audioClientId, CLSCTX_ALL, IntPtr.Zero, out audioClient), "Activate IAudioClient");
|
||||
IntPtr mixFormatPtr;
|
||||
Check(audioClient.GetMixFormat(out mixFormatPtr), "GetMixFormat");
|
||||
WAVEFORMATEX fmt = Marshal.PtrToStructure<WAVEFORMATEX>(mixFormatPtr);
|
||||
Console.Error.WriteLine("MixFormat tag={0} channels={1} rate={2} bits={3} blockAlign={4} cbSize={5}", fmt.wFormatTag, fmt.nChannels, fmt.nSamplesPerSec, fmt.wBitsPerSample, fmt.nBlockAlign, fmt.cbSize);
|
||||
IntPtr activeFormatPtr = mixFormatPtr;
|
||||
IntPtr fallbackFormatPtr = IntPtr.Zero;
|
||||
IntPtr closest = IntPtr.Zero;
|
||||
int support = audioClient.IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, activeFormatPtr, out closest);
|
||||
Console.Error.WriteLine("MixFormatSupport hr=0x{0:X8} closest={1}", support, closest != IntPtr.Zero);
|
||||
if (support != 0 && closest != IntPtr.Zero) {
|
||||
activeFormatPtr = closest;
|
||||
fmt = Marshal.PtrToStructure<WAVEFORMATEX>(activeFormatPtr);
|
||||
Console.Error.WriteLine("ClosestFormat tag={0} channels={1} rate={2} bits={3} blockAlign={4} cbSize={5}", fmt.wFormatTag, fmt.nChannels, fmt.nSamplesPerSec, fmt.wBitsPerSample, fmt.nBlockAlign, fmt.cbSize);
|
||||
}
|
||||
int init = audioClient.Initialize(AUDCLNT_SHAREMODE_SHARED, streamFlags, 0, 0, activeFormatPtr, IntPtr.Zero);
|
||||
if (init < 0) {
|
||||
fallbackFormatPtr = MakeWaveFormatPcm((ushort)targetChannels, (uint)targetRate, 16);
|
||||
activeFormatPtr = fallbackFormatPtr;
|
||||
fmt = Marshal.PtrToStructure<WAVEFORMATEX>(activeFormatPtr);
|
||||
Console.Error.WriteLine("RetryFormat tag={0} channels={1} rate={2} bits={3} blockAlign={4} cbSize={5}", fmt.wFormatTag, fmt.nChannels, fmt.nSamplesPerSec, fmt.wBitsPerSample, fmt.nBlockAlign, fmt.cbSize);
|
||||
IntPtr retryClosest = IntPtr.Zero;
|
||||
int retrySupport = audioClient.IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, activeFormatPtr, out retryClosest);
|
||||
Console.Error.WriteLine("RetryFormatSupport hr=0x{0:X8} closest={1}", retrySupport, retryClosest != IntPtr.Zero);
|
||||
if (retrySupport != 0 && retryClosest != IntPtr.Zero) {
|
||||
Marshal.FreeHGlobal(fallbackFormatPtr);
|
||||
fallbackFormatPtr = IntPtr.Zero;
|
||||
activeFormatPtr = retryClosest;
|
||||
fmt = Marshal.PtrToStructure<WAVEFORMATEX>(activeFormatPtr);
|
||||
Console.Error.WriteLine("RetryClosestFormat tag={0} channels={1} rate={2} bits={3} blockAlign={4} cbSize={5}", fmt.wFormatTag, fmt.nChannels, fmt.nSamplesPerSec, fmt.wBitsPerSample, fmt.nBlockAlign, fmt.cbSize);
|
||||
}
|
||||
init = audioClient.Initialize(AUDCLNT_SHAREMODE_SHARED, streamFlags, 0, 0, activeFormatPtr, IntPtr.Zero);
|
||||
}
|
||||
Check(init, loopback ? "Initialize loopback" : "Initialize capture");
|
||||
IAudioCaptureClient captureClient;
|
||||
Guid captureClientId = IID_IAudioCaptureClient;
|
||||
Check(audioClient.GetService(ref captureClientId, out captureClient), "GetService IAudioCaptureClient");
|
||||
Check(audioClient.Start(), "Start");
|
||||
DateTime end = seconds > 0 ? DateTime.UtcNow.AddSeconds(seconds) : DateTime.MaxValue;
|
||||
byte[] pcm = new byte[8192];
|
||||
byte[] silence = new byte[0];
|
||||
int sourceRate = Math.Max(1, (int)fmt.nSamplesPerSec);
|
||||
double sourceFramesPerTargetFrame = sourceRate / (double)Math.Max(1, targetRate);
|
||||
long sourceFramesSeen = 0;
|
||||
double nextOutputSourceFrame = 0.0;
|
||||
float[] previousFrame = new float[Math.Max(1, targetChannels)];
|
||||
bool hasPreviousFrame = false;
|
||||
int idleFramesPerChunk = Math.Max(1, (int)Math.Round(Math.Max(1, targetRate) * 0.005));
|
||||
int idleBytes = checked(idleFramesPerChunk * Math.Max(1, targetChannels) * 4);
|
||||
try {
|
||||
while (DateTime.UtcNow < end) {
|
||||
uint packetFrames;
|
||||
Check(captureClient.GetNextPacketSize(out packetFrames), "GetNextPacketSize");
|
||||
if (packetFrames == 0) {
|
||||
Thread.Sleep(5);
|
||||
continue;
|
||||
}
|
||||
IntPtr data;
|
||||
uint frames;
|
||||
uint flags;
|
||||
ulong devicePosition;
|
||||
ulong qpcPosition;
|
||||
Check(captureClient.GetBuffer(out data, out frames, out flags, out devicePosition, out qpcPosition), "GetBuffer");
|
||||
try {
|
||||
int sourceChannels = Math.Max(1, (int)fmt.nChannels);
|
||||
int sourceBytesPerFrame = (int)fmt.nBlockAlign;
|
||||
int sourceBits = (int)fmt.wBitsPerSample;
|
||||
int sourceBytesPerSample = Math.Max(1, sourceBits / 8);
|
||||
int frameBytes = targetChannels * 4;
|
||||
long packetStart = sourceFramesSeen;
|
||||
long packetEnd = packetStart + frames;
|
||||
int outputFrames = 0;
|
||||
double countCursor = nextOutputSourceFrame;
|
||||
while (countCursor < packetEnd) {
|
||||
outputFrames++;
|
||||
countCursor += sourceFramesPerTargetFrame;
|
||||
}
|
||||
int needed = checked(outputFrames * frameBytes);
|
||||
if (pcm.Length < needed) pcm = new byte[needed];
|
||||
int dst = 0;
|
||||
float[] left = new float[targetChannels];
|
||||
float[] right = new float[targetChannels];
|
||||
while (nextOutputSourceFrame < packetEnd) {
|
||||
long leftAbsolute = (long)Math.Floor(nextOutputSourceFrame);
|
||||
long rightAbsolute = Math.Min(packetEnd - 1, leftAbsolute + 1);
|
||||
double fraction = nextOutputSourceFrame - leftAbsolute;
|
||||
ReadFrame(leftAbsolute, packetStart, data, flags, sourceChannels, sourceBytesPerFrame, sourceBytesPerSample, sourceBits, fmt.wFormatTag, activeFormatPtr, previousFrame, hasPreviousFrame, left);
|
||||
ReadFrame(rightAbsolute, packetStart, data, flags, sourceChannels, sourceBytesPerFrame, sourceBytesPerSample, sourceBits, fmt.wFormatTag, activeFormatPtr, previousFrame, hasPreviousFrame, right);
|
||||
for (int ch = 0; ch < targetChannels; ch++) {
|
||||
float sample = (float)(left[ch] + (right[ch] - left[ch]) * fraction);
|
||||
byte[] bytes = BitConverter.GetBytes(sample);
|
||||
Buffer.BlockCopy(bytes, 0, pcm, dst, 4);
|
||||
dst += 4;
|
||||
}
|
||||
nextOutputSourceFrame += sourceFramesPerTargetFrame;
|
||||
}
|
||||
if (frames > 0) {
|
||||
ReadFrame(packetEnd - 1, packetStart, data, flags, sourceChannels, sourceBytesPerFrame, sourceBytesPerSample, sourceBits, fmt.wFormatTag, activeFormatPtr, previousFrame, false, previousFrame);
|
||||
hasPreviousFrame = true;
|
||||
}
|
||||
output.Write(pcm, 0, needed);
|
||||
output.Flush();
|
||||
sourceFramesSeen = packetEnd;
|
||||
}
|
||||
finally {
|
||||
Check(captureClient.ReleaseBuffer(frames), "ReleaseBuffer");
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
audioClient.Stop();
|
||||
Marshal.FreeCoTaskMem(mixFormatPtr);
|
||||
if (fallbackFormatPtr != IntPtr.Zero) Marshal.FreeHGlobal(fallbackFormatPtr);
|
||||
if (closest != IntPtr.Zero) Marshal.FreeCoTaskMem(closest);
|
||||
Marshal.ReleaseComObject(captureClient);
|
||||
Marshal.ReleaseComObject(audioClient);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Marshal.ReleaseComObject(device);
|
||||
Marshal.ReleaseComObject(enumerator);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
if (!IsStdoutPath(outputPath)) output.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
static IMMDevice ResolveDevice(IMMDeviceEnumerator enumerator, int dataFlow, string roleName, string deviceSubstring) {
|
||||
if (String.IsNullOrWhiteSpace(deviceSubstring)) {
|
||||
IMMDevice defaultDevice;
|
||||
Check(enumerator.GetDefaultAudioEndpoint(dataFlow, RoleFromName(roleName), out defaultDevice), "GetDefaultAudioEndpoint");
|
||||
Console.Error.WriteLine("SelectedAudioDevice dataFlow={0} default role={1} name=\"{2}\"", dataFlow == eCapture ? "capture" : "render", roleName, DeviceFriendlyName(defaultDevice));
|
||||
return defaultDevice;
|
||||
}
|
||||
|
||||
IMMDeviceCollection devices;
|
||||
Check(enumerator.EnumAudioEndpoints(dataFlow, DEVICE_STATE_ACTIVE, out devices), "EnumAudioEndpoints");
|
||||
try {
|
||||
uint count;
|
||||
Check(devices.GetCount(out count), "GetCount");
|
||||
for (uint index = 0; index < count; index++) {
|
||||
IMMDevice device;
|
||||
Check(devices.Item(index, out device), "Item");
|
||||
string friendlyName = "";
|
||||
try {
|
||||
friendlyName = DeviceFriendlyName(device);
|
||||
if (friendlyName.IndexOf(deviceSubstring, StringComparison.OrdinalIgnoreCase) >= 0) {
|
||||
Console.Error.WriteLine("SelectedAudioDevice dataFlow={0} match=\"{1}\" name=\"{2}\"", dataFlow == eCapture ? "capture" : "render", deviceSubstring, friendlyName);
|
||||
return device;
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Marshal.ReleaseComObject(device);
|
||||
throw;
|
||||
}
|
||||
Marshal.ReleaseComObject(device);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Marshal.ReleaseComObject(devices);
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("No active " + (dataFlow == eCapture ? "capture" : "render") + " endpoint matched --device \"" + deviceSubstring + "\"");
|
||||
}
|
||||
|
||||
static string DeviceFriendlyName(IMMDevice device) {
|
||||
IPropertyStore store;
|
||||
Check(device.OpenPropertyStore(0, out store), "OpenPropertyStore");
|
||||
try {
|
||||
PROPERTYKEY key = DeviceFriendlyNameKey;
|
||||
PROPVARIANT value;
|
||||
Check(store.GetValue(ref key, out value), "GetValue FriendlyName");
|
||||
try {
|
||||
if (value.vt == 31 && value.pointerValue != IntPtr.Zero) {
|
||||
return Marshal.PtrToStringUni(value.pointerValue) ?? "";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
finally {
|
||||
PropVariantClear(ref value);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
Marshal.ReleaseComObject(store);
|
||||
}
|
||||
}
|
||||
|
||||
static bool IsStdoutPath(string outputPath) {
|
||||
return String.Equals(outputPath, "-", StringComparison.Ordinal) ||
|
||||
String.Equals(outputPath, "stdout", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
static void ReadFrame(long absoluteFrame, long packetStart, IntPtr data, uint flags, int sourceChannels, int sourceBytesPerFrame, int sourceBytesPerSample, int sourceBits, ushort tag, IntPtr formatPtr, float[] previousFrame, bool hasPreviousFrame, float[] target) {
|
||||
if (absoluteFrame < packetStart) {
|
||||
for (int ch = 0; ch < target.Length; ch++) target[ch] = hasPreviousFrame ? previousFrame[ch] : 0f;
|
||||
return;
|
||||
}
|
||||
|
||||
int packetFrame = checked((int)(absoluteFrame - packetStart));
|
||||
for (int ch = 0; ch < target.Length; ch++) {
|
||||
float sample = 0f;
|
||||
if ((flags & AUDCLNT_BUFFERFLAGS_SILENT) == 0) {
|
||||
int srcCh = Math.Min(ch, sourceChannels - 1);
|
||||
IntPtr src = IntPtr.Add(data, packetFrame * sourceBytesPerFrame + srcCh * sourceBytesPerSample);
|
||||
sample = ReadSample(src, sourceBits, tag, formatPtr);
|
||||
}
|
||||
target[ch] = sample;
|
||||
}
|
||||
}
|
||||
|
||||
static void Check(int hr, string stage) {
|
||||
if (hr < 0) {
|
||||
Exception inner = Marshal.GetExceptionForHR(hr);
|
||||
throw new InvalidOperationException(stage + " failed: 0x" + hr.ToString("X8") + " " + (inner == null ? "" : inner.Message), inner);
|
||||
}
|
||||
}
|
||||
|
||||
static int RoleFromName(string roleName) {
|
||||
if (String.Equals(roleName, "Multimedia", StringComparison.OrdinalIgnoreCase)) return eMultimedia;
|
||||
if (String.Equals(roleName, "Communications", StringComparison.OrdinalIgnoreCase)) return eCommunications;
|
||||
return eConsole;
|
||||
}
|
||||
|
||||
static int DataFlowFromName(string dataFlowName) {
|
||||
if (String.Equals(dataFlowName, "Capture", StringComparison.OrdinalIgnoreCase)) return eCapture;
|
||||
return eRender;
|
||||
}
|
||||
|
||||
static IntPtr MakeWaveFormatPcm(ushort channels, uint sampleRate, ushort bits) {
|
||||
WAVEFORMATEX fmt = new WAVEFORMATEX();
|
||||
fmt.wFormatTag = 1;
|
||||
fmt.nChannels = channels;
|
||||
fmt.nSamplesPerSec = sampleRate;
|
||||
fmt.wBitsPerSample = bits;
|
||||
fmt.nBlockAlign = (ushort)(channels * bits / 8);
|
||||
fmt.nAvgBytesPerSec = sampleRate * fmt.nBlockAlign;
|
||||
fmt.cbSize = 0;
|
||||
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WAVEFORMATEX)));
|
||||
Marshal.StructureToPtr(fmt, ptr, false);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
static float ReadSample(IntPtr source, int bits, ushort tag, IntPtr formatPtr) {
|
||||
bool isFloat = tag == 3;
|
||||
if (tag == 65534) {
|
||||
WAVEFORMATEXTENSIBLE ext = Marshal.PtrToStructure<WAVEFORMATEXTENSIBLE>(formatPtr);
|
||||
isFloat = ext.SubFormat == FloatSubformat;
|
||||
}
|
||||
if (isFloat && bits == 32) {
|
||||
return Math.Max(-1f, Math.Min(1f, (float)Marshal.PtrToStructure(source, typeof(float))));
|
||||
}
|
||||
if (bits == 16) {
|
||||
return Marshal.ReadInt16(source) / 32768f;
|
||||
}
|
||||
if (bits == 24) {
|
||||
int b0 = Marshal.ReadByte(source, 0);
|
||||
int b1 = Marshal.ReadByte(source, 1);
|
||||
int b2 = Marshal.ReadByte(source, 2);
|
||||
int value = b0 | (b1 << 8) | (b2 << 16);
|
||||
if ((value & 0x800000) != 0) value |= unchecked((int)0xff000000);
|
||||
return Math.Max(-1f, Math.Min(1f, value / 8388608f));
|
||||
}
|
||||
if (bits == 32) {
|
||||
if (tag == 65534) {
|
||||
WAVEFORMATEXTENSIBLE ext = Marshal.PtrToStructure<WAVEFORMATEXTENSIBLE>(formatPtr);
|
||||
if (ext.SubFormat == PcmSubformat && ext.wValidBitsPerSample > 0 && ext.wValidBitsPerSample < 32) {
|
||||
int value = Marshal.ReadInt32(source);
|
||||
int shifted = value >> (32 - ext.wValidBitsPerSample);
|
||||
return Math.Max(-1f, Math.Min(1f, shifted / (float)(1 << (ext.wValidBitsPerSample - 1))));
|
||||
}
|
||||
}
|
||||
return Math.Max(-1f, Math.Min(1f, Marshal.ReadInt32(source) / 2147483648f));
|
||||
}
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
"@
|
||||
|
||||
Add-Type -TypeDefinition $source
|
||||
$effectiveOutput = if ($Output -eq "stdout") { "-" } else { $Output }
|
||||
[Mimir.WasapiLoopbackCapture]::Capture($effectiveOutput, $Device, $Seconds, $SampleRate, $Channels, $DataFlow, $Loopback, $Role)
|
||||
Loading…
Reference in a new issue