Lower live Leap packed stereo to depth socket

This commit is contained in:
Meta Vens 2026-05-30 21:54:58 +01:00
commit 2c197cb3ae
9 changed files with 247 additions and 36 deletions

View file

@ -321,7 +321,8 @@ public sealed class MimirRuntime : IAquariumRuntime, IAquariumRuntimeServicesRec
}
var frame = fieldLowering.BuildFieldEvidenceFrame(windows, observations, constraints, intents);
return AddSpectrumFieldEvidence(frame);
frame = AddSpectrumFieldEvidence(frame);
return AddLeapStereoDepthFieldEvidence(frame, windows);
}
private void CommitProducerLeases(IReadOnlyList<MimirRollingStreamWindow> windows)
@ -368,6 +369,58 @@ public sealed class MimirRuntime : IAquariumRuntime, IAquariumRuntimeServicesRec
Purpose: MimirSurfaceIntentPurpose.Production);
}
private AquariumFieldEvidenceFrame AddLeapStereoDepthFieldEvidence(
AquariumFieldEvidenceFrame frame,
IReadOnlyList<MimirRollingStreamWindow> windows)
{
var stereoFrame = fieldLowering.BuildLeapPackedStereoDepthCandidateFrame(windows, frame.Resources);
if (!stereoFrame.HasInput)
{
return frame;
}
return new AquariumFieldEvidenceFrame
{
Domains = [.. frame.Domains, .. stereoFrame.Domains],
Claims = [.. frame.Claims, .. stereoFrame.Claims],
Candidates = [.. frame.Candidates, .. stereoFrame.Candidates],
BackendPackets = [.. frame.BackendPackets, .. stereoFrame.BackendPackets],
Resources = MergeResources(frame.Resources, stereoFrame.Resources),
ResourceUploads = [.. frame.ResourceUploads, .. stereoFrame.ResourceUploads],
TubeSplineLowerings = [.. frame.TubeSplineLowerings, .. stereoFrame.TubeSplineLowerings],
StereoDepthLowerings = [.. frame.StereoDepthLowerings, .. stereoFrame.StereoDepthLowerings],
AccumulationWindowSeconds = frame.AccumulationWindowSeconds,
PresentationDelaySeconds = frame.PresentationDelaySeconds,
};
}
private static IReadOnlyList<AquariumFieldResourceDeclaration> MergeResources(
IReadOnlyList<AquariumFieldResourceDeclaration> first,
IReadOnlyList<AquariumFieldResourceDeclaration> second)
{
if (first.Count == 0)
{
return second;
}
if (second.Count == 0)
{
return first;
}
var resources = new List<AquariumFieldResourceDeclaration>(first.Count + second.Count);
var seen = new HashSet<string>(StringComparer.Ordinal);
foreach (var resource in first.Concat(second))
{
if (resource.HasIdentity && seen.Add(resource.ResourceKey))
{
resources.Add(resource);
}
}
return resources;
}
private AquariumFieldEvidenceFrame AddSpectrumFieldEvidence(AquariumFieldEvidenceFrame frame)
{
if (lastAudioSpectra.Count == 0)

View file

@ -180,6 +180,63 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt
};
}
public AquariumFieldEvidenceFrame BuildLeapPackedStereoDepthCandidateFrame(
IEnumerable<MimirRollingStreamWindow> windows,
IEnumerable<AquariumFieldResourceDeclaration> inputResources)
{
var resourcesByKey = inputResources
.Where(static resource => resource.HasIdentity)
.GroupBy(static resource => resource.ResourceKey, StringComparer.Ordinal)
.ToDictionary(static group => group.Key, static group => group.First(), StringComparer.Ordinal);
var leapWindow = windows
.Where(static window =>
window.Status == MimirBridgeWindowStatus.Live &&
window.SourceKind == MimirStreamKind.Video &&
window.SampleDescriptor.PixelFormat == MimirVideoPixelFormat.LeapStereoIr &&
window.Payload.HasResource &&
!string.IsNullOrWhiteSpace(window.Payload.ResourceKey))
.OrderByDescending(static window => window.EdgeNs)
.FirstOrDefault();
if (string.IsNullOrWhiteSpace(leapWindow.WindowId))
{
return AquariumFieldEvidenceFrame.Empty;
}
var packedResourceKey = MimirFensalirBridgeMapper.ResourceKeyForPayload(leapWindow.Payload);
if (!resourcesByKey.TryGetValue(packedResourceKey, out var packedInput))
{
return AquariumFieldEvidenceFrame.Empty;
}
var profile = MimirStereoDepthConfigurations.D3D12SgmLibSgmProvenance;
var sourceSegment = SanitizeResourceSegment(leapWindow.StreamId);
var candidate = new MimirStereoDepthFieldCandidate(
CandidateKey: $"live-{sourceSegment}-{leapWindow.SequenceId}",
CalibrationId: "leapuvc-packed-stereo-ir-calibration-pending",
CameraPairId: leapWindow.StreamId,
ProducerKey: profile.Id,
ProfileId: profile.Id,
LeftObservationKey: $"{leapWindow.WindowId}:left-packed-r",
RightObservationKey: $"{leapWindow.WindowId}:right-packed-g",
LeftResourceKey: packedResourceKey,
RightResourceKey: packedResourceKey,
DisparityResourceKey: $"mimir:resource:stereo-depth:{sourceSegment}:disparity-r16f",
ConfidenceResourceKey: $"mimir:resource:stereo-depth:{sourceSegment}:confidence-r8",
Width: Math.Max(1, leapWindow.SampleDescriptor.Width),
Height: Math.Max(1, leapWindow.SampleDescriptor.Height),
MinDisparity: profile.MinDisparity,
DisparityLevels: profile.DisparityLevels,
AggregationPathCount: profile.AggregationPathCount,
CensusRadius: profile.CensusRadius,
SmoothnessPenaltySmall: profile.SmoothnessPenaltySmall,
SmoothnessPenaltyLarge: profile.SmoothnessPenaltyLarge,
MinDepthMeters: 0.20,
MaxDepthMeters: 4.0,
Confidence: 0.50,
ObservedTimeNs: leapWindow.EdgeNs);
return BuildStereoDepthCandidateFrame([candidate], [packedInput]);
}
public AquariumFieldEvidenceFrame BuildStereoDepthCandidateFrame(
IEnumerable<MimirStereoDepthFieldCandidate> depthCandidates,
IEnumerable<AquariumFieldResourceDeclaration>? inputResources = null)
@ -951,6 +1008,19 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt
private static string DomainKeyForSurfaceIntent(string intentKey) => $"mimir:intent:{intentKey}";
private static string SanitizeResourceSegment(string value)
{
if (string.IsNullOrWhiteSpace(value))
{
return "unknown";
}
var chars = value.Trim().ToLowerInvariant()
.Select(static character => char.IsLetterOrDigit(character) ? character : '-')
.ToArray();
return chars.Length == 0 ? "unknown" : new string(chars);
}
private static float Clamp01(float value) => Math.Clamp(value, 0.0f, 1.0f);
private static uint StableSeed(string key)