Inject LocalCast visual frame source
This commit is contained in:
parent
4d5aec7e2e
commit
8798908237
3 changed files with 114 additions and 7 deletions
|
|
@ -19,7 +19,7 @@ public sealed class LocalCastRuntime : IAquariumRuntime
|
|||
private readonly LocalCastGpuFusionAccumulator gpuFusionAccumulator = new(
|
||||
ResolveGpuHistorySeconds(),
|
||||
smoothing: 0.45f);
|
||||
private readonly LocalCastVisualStateReader reader;
|
||||
private readonly ILocalCastVisualFrameSource frameSource;
|
||||
private float timeSeconds;
|
||||
private float sceneTimelineSeconds;
|
||||
private long lastFrameId = -1;
|
||||
|
|
@ -30,14 +30,19 @@ public sealed class LocalCastRuntime : IAquariumRuntime
|
|||
private AquariumCalibrationEventFrame latestCalibrationEvents = AquariumCalibrationEventFrame.Empty;
|
||||
|
||||
public LocalCastRuntime(AquariumRuntimeOptions options)
|
||||
: this(options, new LocalCastVisualStateFileSource(ResolveVisualCachePath()))
|
||||
{
|
||||
}
|
||||
|
||||
public LocalCastRuntime(AquariumRuntimeOptions options, ILocalCastVisualFrameSource frameSource)
|
||||
{
|
||||
Options = options;
|
||||
reader = new LocalCastVisualStateReader(ResolveVisualCachePath());
|
||||
this.frameSource = frameSource;
|
||||
Ui = new AquariumUiDocument()
|
||||
.Panel("LocalCast", 18.0f, 82.0f, 372.0f, panel =>
|
||||
{
|
||||
panel.Section("Camera Field");
|
||||
panel.Readout("Cache", () => reader.Path);
|
||||
panel.Readout("Source", () => this.frameSource.Description);
|
||||
panel.Readout("Frame", () => lastFrameId >= 0 ? $"{lastFrameId} / {latestPointCount} splats" : latestStatus);
|
||||
panel.Readout("Claps", () => lastClapFrameId >= 0 ? $"{lastClapFrameId} / {latestClapCount} events" : "none");
|
||||
panel.Readout("History", () => $"{gpuFusionAccumulator.TrackCount} tracked seeds");
|
||||
|
|
@ -91,14 +96,14 @@ public sealed class LocalCastRuntime : IAquariumRuntime
|
|||
|
||||
public void Start()
|
||||
{
|
||||
Console.WriteLine($"LocalCast Aquarium runtime reading {reader.Path}");
|
||||
Console.WriteLine($"LocalCast Aquarium runtime reading {frameSource.Description}");
|
||||
}
|
||||
|
||||
public void Update(float deltaSeconds, InputState input)
|
||||
{
|
||||
timeSeconds += Math.Max(deltaSeconds, 0.0f);
|
||||
|
||||
if (!reader.TryReadLatest(out var frame))
|
||||
if (!frameSource.TryReadLatest(out var frame))
|
||||
{
|
||||
latestStatus = "waiting for visual-state.msgpack";
|
||||
sceneTimelineSeconds = MathF.Max(sceneTimelineSeconds, timeSeconds);
|
||||
|
|
@ -114,7 +119,7 @@ public sealed class LocalCastRuntime : IAquariumRuntime
|
|||
latestStatus = "live";
|
||||
}
|
||||
|
||||
if (reader.TryReadLatestClapEvents(out var clapFrame) && clapFrame.FrameId != lastClapFrameId)
|
||||
if (frameSource.TryReadLatestClapEvents(out var clapFrame) && clapFrame.FrameId != lastClapFrameId)
|
||||
{
|
||||
latestCalibrationEvents = MapClapEvents(clapFrame);
|
||||
lastClapFrameId = clapFrame.FrameId;
|
||||
|
|
@ -134,7 +139,7 @@ public sealed class LocalCastRuntime : IAquariumRuntime
|
|||
{
|
||||
}
|
||||
|
||||
private string ResolveVisualCachePath()
|
||||
private static string ResolveVisualCachePath()
|
||||
{
|
||||
var environmentPath = Environment.GetEnvironmentVariable("LOCALCAST_VISUAL_CACHE");
|
||||
if (!string.IsNullOrWhiteSpace(environmentPath))
|
||||
|
|
|
|||
32
src/Aquarium.LocalCast/LocalCastVisualFrameSource.cs
Normal file
32
src/Aquarium.LocalCast/LocalCastVisualFrameSource.cs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
namespace Aquarium.LocalCast;
|
||||
|
||||
public interface ILocalCastVisualFrameSource
|
||||
{
|
||||
string Description { get; }
|
||||
|
||||
bool TryReadLatest(out LocalCastVisualFrame frame);
|
||||
|
||||
bool TryReadLatestClapEvents(out LocalCastClapCalibrationFrame frame);
|
||||
}
|
||||
|
||||
public sealed class LocalCastVisualStateFileSource : ILocalCastVisualFrameSource
|
||||
{
|
||||
private readonly LocalCastVisualStateReader reader;
|
||||
|
||||
public LocalCastVisualStateFileSource(string path)
|
||||
{
|
||||
reader = new LocalCastVisualStateReader(path);
|
||||
}
|
||||
|
||||
public string Description => reader.Path;
|
||||
|
||||
public bool TryReadLatest(out LocalCastVisualFrame frame)
|
||||
{
|
||||
return reader.TryReadLatest(out frame);
|
||||
}
|
||||
|
||||
public bool TryReadLatestClapEvents(out LocalCastClapCalibrationFrame frame)
|
||||
{
|
||||
return reader.TryReadLatestClapEvents(out frame);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
using System.Numerics;
|
||||
using Aquarium.Engine;
|
||||
using Aquarium.Engine.Input;
|
||||
using Aquarium.LocalCast;
|
||||
|
||||
namespace Aquarium.LocalCast.Tests;
|
||||
|
||||
public sealed class LocalCastRuntimeSourceTests
|
||||
{
|
||||
[Fact]
|
||||
public void RuntimeConsumesInjectedFrameSource()
|
||||
{
|
||||
var source = new FakeFrameSource();
|
||||
var runtime = new LocalCastRuntime(new AquariumRuntimeOptions(true, null), source);
|
||||
|
||||
runtime.Update(0.016f, new InputState());
|
||||
var frame = runtime.Frame;
|
||||
|
||||
Assert.Equal(1, source.ReadCount);
|
||||
Assert.True(frame.Scene.GpuFusionField.Seeds.Count > 0);
|
||||
}
|
||||
|
||||
private sealed class FakeFrameSource : ILocalCastVisualFrameSource
|
||||
{
|
||||
public int ReadCount { get; private set; }
|
||||
|
||||
public string Description => "fake-native-source";
|
||||
|
||||
public bool TryReadLatest(out LocalCastVisualFrame frame)
|
||||
{
|
||||
ReadCount++;
|
||||
frame = new LocalCastVisualFrame
|
||||
{
|
||||
SchemaVersion = LocalCastVisualStateReader.RenderFrameSchemaId,
|
||||
FrameId = 10,
|
||||
CreatedMonotonicNs = 100,
|
||||
SourceTimeMinNs = 100,
|
||||
SourceTimeMaxNs = 120,
|
||||
PresentTimeNs = 160,
|
||||
AudioAlignmentTimeNs = 160,
|
||||
SpoutSenderName = "LocalCastBridge Point Cloud",
|
||||
TargetWidth = 1920,
|
||||
TargetHeight = 1080,
|
||||
Points =
|
||||
[
|
||||
new LocalCastVisualPoint(
|
||||
"fake:point",
|
||||
new Vector3(0.1f, 0.2f, 1.2f),
|
||||
0.03f,
|
||||
new Vector4(0.7f, 0.6f, 0.5f, 0.9f),
|
||||
0.8f,
|
||||
120),
|
||||
],
|
||||
};
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryReadLatestClapEvents(out LocalCastClapCalibrationFrame frame)
|
||||
{
|
||||
frame = new LocalCastClapCalibrationFrame
|
||||
{
|
||||
SchemaVersion = LocalCastVisualStateReader.ClapEventsSchemaId,
|
||||
FrameId = -1,
|
||||
CreatedMonotonicNs = 0,
|
||||
Events = [],
|
||||
};
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue