Route live Leap depth into surface claims
This commit is contained in:
parent
7a7533231c
commit
7b0fdde601
14 changed files with 159 additions and 39 deletions
|
|
@ -892,6 +892,7 @@ static int RunKsCameraDriverSmoke(string[] args)
|
|||
var fourCc = ParseStringOption(args, "--fourcc", "YUY2");
|
||||
var minFps = ParseDoubleOption(args, "--min-fps", 100.0);
|
||||
var timeoutMs = ParseIntOption(args, "--timeout-ms", 3000);
|
||||
var dumpFrame = ParseStringOption(args, "--dump-frame", "");
|
||||
|
||||
var broker = new FakeFieldResourceBroker();
|
||||
using var driver = new MimirKsVideoCaptureDriver(new MimirKsVideoCaptureDriverOptions(
|
||||
|
|
@ -906,7 +907,10 @@ static int RunKsCameraDriverSmoke(string[] args)
|
|||
new MimirStreamDescriptor(sourceId, MimirStreamKind.Video, MimirStreamOrigin.LocalDevice),
|
||||
driver,
|
||||
static () => StopwatchTicksToNs(Stopwatch.GetTimestamp()));
|
||||
source.AttachTextureLeaseClient(new MimirFensalirTextureLeaseClient(broker));
|
||||
if (string.IsNullOrWhiteSpace(dumpFrame))
|
||||
{
|
||||
source.AttachTextureLeaseClient(new MimirFensalirTextureLeaseClient(broker));
|
||||
}
|
||||
|
||||
var deadline = Stopwatch.GetTimestamp() + (long)(timeoutMs / 1000.0 * Stopwatch.Frequency);
|
||||
while (Stopwatch.GetTimestamp() < deadline)
|
||||
|
|
@ -920,6 +924,20 @@ static int RunKsCameraDriverSmoke(string[] args)
|
|||
var frame = sample.VideoFrame;
|
||||
Console.WriteLine(
|
||||
$"ks-camera-driver-smoke source={sample.SourceId} {frame?.Width}x{frame?.Height} format={frame?.PixelFormat} liveBytes={sample.ByteLength} uploadedBytes={source.LastUploadedByteLength} uploaded={broker.UploadedResourceKey} copies={source.LastUploadedCopyCount}");
|
||||
if (!string.IsNullOrWhiteSpace(dumpFrame) && !sample.Data.IsEmpty)
|
||||
{
|
||||
var dumpPath = Path.GetFullPath(dumpFrame);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(dumpPath) ?? ".");
|
||||
File.WriteAllBytes(dumpPath, sample.Data.ToArray());
|
||||
Console.WriteLine($"ks-camera-driver-dump path={dumpPath} bytes={sample.Data.Length}");
|
||||
return frame != null &&
|
||||
frame.Width == width &&
|
||||
frame.Height == height &&
|
||||
sample.ByteLength > 0
|
||||
? 0
|
||||
: 1;
|
||||
}
|
||||
|
||||
return frame != null &&
|
||||
frame.Width == width &&
|
||||
frame.Height == height &&
|
||||
|
|
@ -2620,7 +2638,7 @@ static int RunLeapPointCloudRootSmoke()
|
|||
pointResource.Kind == AquariumFieldResourceKind.Mesh &&
|
||||
pointResource.Mesh.Topology == AquariumFieldMeshTopology.PointList &&
|
||||
pointResource.Mesh.Layout == AquariumFieldMeshLayout.PositionNormalUvColor &&
|
||||
pointResource.Mesh.Vertices.Count == 320 * 120 &&
|
||||
pointResource.Mesh.Vertices.Count == 160 * 120 &&
|
||||
pointResource.Mesh.Indices.Count == pointResource.Mesh.Vertices.Count &&
|
||||
pointResource.SourceUri == "derived-from:mimir:resource:stereo-depth:leap-stereo-ir:disparity-r16f" &&
|
||||
stereoPacket.Backend == AquariumFieldBackendKind.SurfacePage &&
|
||||
|
|
|
|||
|
|
@ -1433,14 +1433,19 @@ public sealed class MimirRuntime : IAquariumRuntime, IAquariumRuntimeServicesRec
|
|||
|
||||
private void StartConfiguredSources()
|
||||
{
|
||||
var started = 0;
|
||||
foreach (var factory in sourceFactories)
|
||||
{
|
||||
var source = factory.Create();
|
||||
if (source != null)
|
||||
{
|
||||
synchronization.AddSource(source);
|
||||
started++;
|
||||
Console.WriteLine($"mimir-source-started source={factory.Descriptor.SourceId} kind={factory.Descriptor.Kind}");
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine($"mimir-source-started total={started} configured={sourceFactories.Count}");
|
||||
}
|
||||
|
||||
private void EmitTelemetry()
|
||||
|
|
@ -1454,7 +1459,7 @@ public sealed class MimirRuntime : IAquariumRuntime, IAquariumRuntimeServicesRec
|
|||
string.Equals(buffer.Descriptor.SourceId, audioSyncSettings.ReferenceSourceId, StringComparison.Ordinal));
|
||||
var states = synchronization.AudioSynchronizationStates;
|
||||
Console.WriteLine(
|
||||
$"mimir-sync-telemetry t={runtimeSeconds:0.00}s audioSync={audioSyncSettings.Mode} loopbackCount={loopback?.Count ?? 0} loopbackEdgeNs={loopback?.EdgeNs ?? 0} reports={lastAudioSynchronizationReports.Count} states={states.Count} analyzeMs={lastAudioSyncAnalysisMilliseconds:0.0} aligned={DescribeAlignedAudio()}");
|
||||
$"mimir-sync-telemetry t={runtimeSeconds:0.00}s sources={synchronization.SourceCount} lastPoll={lastPollCount} ingested={synchronization.IngestedSamples} audioSync={audioSyncSettings.Mode} loopbackCount={loopback?.Count ?? 0} loopbackEdgeNs={loopback?.EdgeNs ?? 0} reports={lastAudioSynchronizationReports.Count} states={states.Count} analyzeMs={lastAudioSyncAnalysisMilliseconds:0.0} aligned={DescribeAlignedAudio()}");
|
||||
if (lastObsStemPublication.ReadyStems.Count > 0 || lastObsStemPublication.MissingStemIds.Count > 0)
|
||||
{
|
||||
Console.WriteLine(
|
||||
|
|
@ -1462,6 +1467,12 @@ public sealed class MimirRuntime : IAquariumRuntime, IAquariumRuntimeServicesRec
|
|||
}
|
||||
|
||||
Console.WriteLine($"mimir-sync-buffers {DescribeAudioBuffers()}");
|
||||
foreach (var buffer in synchronization.Buffers.Buffers.Where(static buffer => buffer.Descriptor.Kind == MimirStreamKind.Video))
|
||||
{
|
||||
var frame = buffer.Latest?.VideoFrame;
|
||||
Console.WriteLine(
|
||||
$"mimir-video-buffer {buffer.Descriptor.SourceId} count={buffer.Count} latest={(frame == null ? "none" : $"{frame.Width}x{frame.Height} {frame.PixelFormat} bytes={buffer.Latest?.ByteLength ?? 0} resource={frame.ResourceKey} handle={frame.NativeHandle} kind={frame.NativeHandleKind} fence={frame.ProducerFenceHandle}/{frame.ProducerFenceValue}")}");
|
||||
}
|
||||
Console.WriteLine($"mimir-spectrum-frustum {DescribeSpectrumFrustum()}");
|
||||
foreach (var spectrum in lastAudioSpectra.OrderBy(snapshot => snapshot.SourceId, StringComparer.Ordinal))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -373,13 +373,13 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt
|
|||
CameraPairId: leapWindow.StreamId,
|
||||
ProducerKey: profile.Id,
|
||||
ProfileId: profile.Id,
|
||||
LeftObservationKey: $"{leapWindow.WindowId}:left-packed-r",
|
||||
RightObservationKey: $"{leapWindow.WindowId}:right-packed-g",
|
||||
LeftObservationKey: $"{leapWindow.WindowId}:left-ir-luma",
|
||||
RightObservationKey: $"{leapWindow.WindowId}:right-ir-luma",
|
||||
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),
|
||||
Width: Math.Max(1, leapWindow.SampleDescriptor.Width / 2),
|
||||
Height: Math.Max(1, leapWindow.SampleDescriptor.Height),
|
||||
MinDisparity: profile.MinDisparity,
|
||||
DisparityLevels: profile.DisparityLevels,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ public readonly record struct MimirFensalirTextureLease(
|
|||
IntPtr ProducerFenceHandle,
|
||||
AquariumFieldResourceDeclaration Declaration)
|
||||
{
|
||||
public bool IsValid => NativeHandle != IntPtr.Zero && Frame.NativeHandle != 0 && !string.IsNullOrWhiteSpace(Frame.ResourceKey);
|
||||
public bool IsValid => !string.IsNullOrWhiteSpace(Frame.ResourceKey) && Declaration.HasIdentity;
|
||||
}
|
||||
|
||||
public sealed class MimirFensalirTextureLeaseClient(IAquariumFieldResourceBroker broker)
|
||||
|
|
@ -42,8 +42,14 @@ public sealed class MimirFensalirTextureLeaseClient(IAquariumFieldResourceBroker
|
|||
FormatForPixelFormat(request.PixelFormat),
|
||||
request.ProducerAccess,
|
||||
request.Version));
|
||||
if (!engineLease.IsValid || engineLease.NativeHandle == IntPtr.Zero)
|
||||
if (!engineLease.IsValid)
|
||||
{
|
||||
if (Environment.GetEnvironmentVariable("MIMIR_TEXTURE_LEASE_DIAG") == "1")
|
||||
{
|
||||
Console.WriteLine(
|
||||
$"mimir-texture-lease-failed source={request.SourceId} resource={resourceKey} {request.Width}x{request.Height} format={FormatForPixelFormat(request.PixelFormat)} access={request.ProducerAccess} valid={engineLease.IsValid} handle={engineLease.NativeHandle}");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ public sealed record MimirKsVideoCaptureDriverOptions(
|
|||
int Height,
|
||||
string FourCc,
|
||||
double MinimumFramesPerSecond,
|
||||
int QueueDepth = 8);
|
||||
int QueueDepth = 8,
|
||||
MimirVideoPixelFormat DeclaredPixelFormat = MimirVideoPixelFormat.Unknown);
|
||||
|
||||
public sealed unsafe class MimirKsVideoCaptureDriver : IMimirVideoCaptureDriver, IMimirFensalirTextureLeaseReceiver
|
||||
{
|
||||
|
|
@ -19,8 +20,12 @@ public sealed unsafe class MimirKsVideoCaptureDriver : IMimirVideoCaptureDriver,
|
|||
private readonly byte[] scratch;
|
||||
private readonly string sourceId;
|
||||
private readonly string fourCc;
|
||||
private readonly MimirVideoPixelFormat declaredPixelFormat;
|
||||
private MimirFensalirTextureLeaseClient? textureLeaseClient;
|
||||
private string resourceKey = "";
|
||||
private ulong nativeHandle;
|
||||
private string nativeHandleKind = "";
|
||||
private ulong producerFenceHandle;
|
||||
private bool disposed;
|
||||
|
||||
public MimirKsVideoCaptureDriver(MimirKsVideoCaptureDriverOptions options)
|
||||
|
|
@ -43,6 +48,7 @@ public sealed unsafe class MimirKsVideoCaptureDriver : IMimirVideoCaptureDriver,
|
|||
native = Native.Load(options.NativeLibraryPath);
|
||||
sourceId = options.SourceId;
|
||||
fourCc = options.FourCc.Trim();
|
||||
declaredPixelFormat = options.DeclaredPixelFormat;
|
||||
capture = native.Create(
|
||||
options.PathNeedle,
|
||||
options.Width,
|
||||
|
|
@ -68,6 +74,9 @@ public sealed unsafe class MimirKsVideoCaptureDriver : IMimirVideoCaptureDriver,
|
|||
{
|
||||
textureLeaseClient = client;
|
||||
resourceKey = "";
|
||||
nativeHandle = 0;
|
||||
nativeHandleKind = "";
|
||||
producerFenceHandle = 0;
|
||||
}
|
||||
|
||||
public bool TryCapture(out MimirVideoFrameDescriptor frame, out ReadOnlyMemory<byte> data)
|
||||
|
|
@ -92,7 +101,10 @@ public sealed unsafe class MimirKsVideoCaptureDriver : IMimirVideoCaptureDriver,
|
|||
return false;
|
||||
}
|
||||
|
||||
var pixelFormat = PixelFormatFromFourCc(FourCcFromBytes(fourCcBytes));
|
||||
var capturedPixelFormat = PixelFormatFromFourCc(FourCcFromBytes(fourCcBytes));
|
||||
var pixelFormat = declaredPixelFormat == MimirVideoPixelFormat.Unknown
|
||||
? capturedPixelFormat
|
||||
: declaredPixelFormat;
|
||||
EnsureLease(width, height, pixelFormat, stride, timestampNs, sequence);
|
||||
frame = new MimirVideoFrameDescriptor(
|
||||
width,
|
||||
|
|
@ -100,7 +112,10 @@ public sealed unsafe class MimirKsVideoCaptureDriver : IMimirVideoCaptureDriver,
|
|||
pixelFormat,
|
||||
stride,
|
||||
timestampNs,
|
||||
NativeHandle: nativeHandle,
|
||||
NativeHandleKind: nativeHandleKind,
|
||||
ResourceKey: resourceKey,
|
||||
ProducerFenceHandle: producerFenceHandle,
|
||||
ProducerFenceValue: sequence);
|
||||
data = string.IsNullOrWhiteSpace(resourceKey)
|
||||
? scratch.AsMemory(0, byteLength).ToArray()
|
||||
|
|
@ -138,6 +153,9 @@ public sealed unsafe class MimirKsVideoCaptureDriver : IMimirVideoCaptureDriver,
|
|||
version), out var lease))
|
||||
{
|
||||
resourceKey = lease.Frame.ResourceKey;
|
||||
nativeHandle = lease.Frame.NativeHandle;
|
||||
nativeHandleKind = lease.Frame.NativeHandleKind;
|
||||
producerFenceHandle = unchecked((ulong)lease.ProducerFenceHandle.ToInt64());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ public sealed unsafe class MimirPs3EyeVideoCaptureDriver : IMimirVideoCaptureDri
|
|||
private readonly string sourceId;
|
||||
private MimirFensalirTextureLeaseClient? textureLeaseClient;
|
||||
private string resourceKey = "";
|
||||
private ulong nativeHandle;
|
||||
private string nativeHandleKind = "";
|
||||
private ulong producerFenceHandle;
|
||||
private bool disposed;
|
||||
|
||||
public MimirPs3EyeVideoCaptureDriver(MimirPs3EyeVideoCaptureDriverOptions options)
|
||||
|
|
@ -53,6 +56,9 @@ public sealed unsafe class MimirPs3EyeVideoCaptureDriver : IMimirVideoCaptureDri
|
|||
{
|
||||
textureLeaseClient = client;
|
||||
resourceKey = "";
|
||||
nativeHandle = 0;
|
||||
nativeHandleKind = "";
|
||||
producerFenceHandle = 0;
|
||||
}
|
||||
|
||||
public bool TryCapture(out MimirVideoFrameDescriptor frame, out ReadOnlyMemory<byte> data)
|
||||
|
|
@ -82,7 +88,10 @@ public sealed unsafe class MimirPs3EyeVideoCaptureDriver : IMimirVideoCaptureDri
|
|||
MimirVideoPixelFormat.Bayer8,
|
||||
stride,
|
||||
timestampNs,
|
||||
NativeHandle: nativeHandle,
|
||||
NativeHandleKind: nativeHandleKind,
|
||||
ResourceKey: resourceKey,
|
||||
ProducerFenceHandle: producerFenceHandle,
|
||||
ProducerFenceValue: sequence);
|
||||
data = string.IsNullOrWhiteSpace(resourceKey)
|
||||
? scratch.AsMemory(0, byteLength).ToArray()
|
||||
|
|
@ -120,6 +129,9 @@ public sealed unsafe class MimirPs3EyeVideoCaptureDriver : IMimirVideoCaptureDri
|
|||
version), out var lease))
|
||||
{
|
||||
resourceKey = lease.Frame.ResourceKey;
|
||||
nativeHandle = lease.Frame.NativeHandle;
|
||||
nativeHandleKind = lease.Frame.NativeHandleKind;
|
||||
producerFenceHandle = unchecked((ulong)lease.ProducerFenceHandle.ToInt64());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -168,9 +168,10 @@ public sealed class MimirRuntimeConfiguration
|
|||
stream.PathNeedle,
|
||||
stream.Width,
|
||||
stream.Height,
|
||||
stream.PixelFormat,
|
||||
string.IsNullOrWhiteSpace(stream.InputFormat) ? stream.PixelFormat : stream.InputFormat,
|
||||
stream.MinimumFramesPerSecond,
|
||||
stream.QueueDepth)),
|
||||
stream.QueueDepth,
|
||||
ParsePixelFormat(stream.PixelFormat))),
|
||||
static () => StopwatchTicksToNs(System.Diagnostics.Stopwatch.GetTimestamp())));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue