Expose Well source configuration health
This commit is contained in:
parent
79de23a4c1
commit
f87803f26f
3 changed files with 87 additions and 12 deletions
|
|
@ -129,9 +129,10 @@ public sealed class MimirRuntimeConfiguration
|
|||
private static MimirStreamSourceFactory? TryCreateSourceFactory(MimirStreamConfig stream, string? configDirectory)
|
||||
{
|
||||
var descriptor = ToDescriptor(stream);
|
||||
var diagnostics = ToDiagnostics(stream, configDirectory);
|
||||
if (string.Equals(stream.Adapter, "native", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new MimirStreamSourceFactory(descriptor, () => new MimirNativeIngestStreamSource(descriptor));
|
||||
return new MimirStreamSourceFactory(descriptor, () => new MimirNativeIngestStreamSource(descriptor), diagnostics);
|
||||
}
|
||||
|
||||
if (string.Equals(stream.Adapter, "asio", StringComparison.OrdinalIgnoreCase))
|
||||
|
|
@ -148,7 +149,8 @@ public sealed class MimirRuntimeConfiguration
|
|||
ResolveCommand(stream.Command, configDirectory),
|
||||
stream.DriverClsid,
|
||||
stream.SampleRate,
|
||||
stream.AcceptSourceIds)));
|
||||
stream.AcceptSourceIds)),
|
||||
diagnostics);
|
||||
#pragma warning restore CA1416
|
||||
}
|
||||
|
||||
|
|
@ -172,7 +174,8 @@ public sealed class MimirRuntimeConfiguration
|
|||
stream.MinimumFramesPerSecond,
|
||||
stream.QueueDepth,
|
||||
ParsePixelFormat(stream.PixelFormat))),
|
||||
UtcNowNs));
|
||||
UtcNowNs),
|
||||
diagnostics);
|
||||
}
|
||||
|
||||
if (string.Equals(stream.Adapter, "ps3eye", StringComparison.OrdinalIgnoreCase)
|
||||
|
|
@ -192,7 +195,8 @@ public sealed class MimirRuntimeConfiguration
|
|||
stream.Width,
|
||||
stream.Height,
|
||||
stream.FramesPerSecond)),
|
||||
UtcNowNs));
|
||||
UtcNowNs),
|
||||
diagnostics);
|
||||
}
|
||||
|
||||
if (string.Equals(stream.Adapter, "mf-gpu", StringComparison.OrdinalIgnoreCase)
|
||||
|
|
@ -214,7 +218,8 @@ public sealed class MimirRuntimeConfiguration
|
|||
stream.InputFormat,
|
||||
stream.OutputFormat,
|
||||
stream.MinimumFramesPerSecond)),
|
||||
UtcNowNs));
|
||||
UtcNowNs),
|
||||
diagnostics);
|
||||
}
|
||||
|
||||
if (string.Equals(stream.Adapter, "frame-events", StringComparison.OrdinalIgnoreCase)
|
||||
|
|
@ -232,7 +237,8 @@ public sealed class MimirRuntimeConfiguration
|
|||
stream.Arguments,
|
||||
stream.AcceptSourceIds.Length > 0
|
||||
? new HashSet<string>(stream.AcceptSourceIds, StringComparer.Ordinal)
|
||||
: null)));
|
||||
: null)),
|
||||
diagnostics);
|
||||
}
|
||||
|
||||
if (string.Equals(stream.Adapter, "ffmpeg-rawvideo", StringComparison.OrdinalIgnoreCase)
|
||||
|
|
@ -252,7 +258,8 @@ public sealed class MimirRuntimeConfiguration
|
|||
stream.Height,
|
||||
ParsePixelFormat(stream.PixelFormat),
|
||||
stream.FrameBytes,
|
||||
stream.StrideBytes)));
|
||||
stream.StrideBytes)),
|
||||
diagnostics);
|
||||
}
|
||||
|
||||
if (string.Equals(stream.Adapter, "ffmpeg-pcmaudio", StringComparison.OrdinalIgnoreCase)
|
||||
|
|
@ -271,7 +278,8 @@ public sealed class MimirRuntimeConfiguration
|
|||
stream.SampleRate,
|
||||
stream.Channels,
|
||||
ParseAudioSampleFormat(stream.SampleFormat),
|
||||
stream.BlockFrames)));
|
||||
stream.BlockFrames)),
|
||||
diagnostics);
|
||||
}
|
||||
|
||||
if (!string.Equals(stream.Adapter, "process", StringComparison.OrdinalIgnoreCase))
|
||||
|
|
@ -289,9 +297,27 @@ public sealed class MimirRuntimeConfiguration
|
|||
new MimirProcessStreamSourceOptions(
|
||||
ResolveCommand(stream.Command, configDirectory),
|
||||
stream.Arguments,
|
||||
Math.Max(1024, stream.ChunkBytes))));
|
||||
Math.Max(1024, stream.ChunkBytes))),
|
||||
diagnostics);
|
||||
}
|
||||
|
||||
private static MimirStreamSourceDiagnostics ToDiagnostics(MimirStreamConfig stream, string? configDirectory) =>
|
||||
new(
|
||||
stream.Adapter,
|
||||
ResolveCommand(stream.Command, configDirectory),
|
||||
stream.PathNeedle,
|
||||
stream.Width,
|
||||
stream.Height,
|
||||
stream.InputFormat,
|
||||
stream.OutputFormat,
|
||||
stream.PixelFormat,
|
||||
stream.MinimumFramesPerSecond,
|
||||
stream.FramesPerSecond,
|
||||
stream.SampleRate,
|
||||
stream.Channels,
|
||||
stream.QueueDepth,
|
||||
stream.AcceptSourceIds);
|
||||
|
||||
private static string ResolveCommand(string command, string? configDirectory)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(command)
|
||||
|
|
@ -358,7 +384,24 @@ public sealed class MimirRuntimeConfiguration
|
|||
|
||||
public sealed record MimirStreamSourceFactory(
|
||||
MimirStreamDescriptor Descriptor,
|
||||
Func<IMimirStreamSource?> Create);
|
||||
Func<IMimirStreamSource?> Create,
|
||||
MimirStreamSourceDiagnostics? Diagnostics = null);
|
||||
|
||||
public sealed record MimirStreamSourceDiagnostics(
|
||||
string Adapter,
|
||||
string Command,
|
||||
string PathNeedle,
|
||||
int Width,
|
||||
int Height,
|
||||
string InputFormat,
|
||||
string OutputFormat,
|
||||
string PixelFormat,
|
||||
double MinimumFramesPerSecond,
|
||||
int FramesPerSecond,
|
||||
int SampleRate,
|
||||
int Channels,
|
||||
int QueueDepth,
|
||||
IReadOnlyList<string> AcceptSourceIds);
|
||||
|
||||
public sealed class MimirRuntimeConfigFile
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1471,7 +1471,7 @@ internal static class MimirWellSnapshot
|
|||
liveSources = hub.SourceCount,
|
||||
sourceErrors,
|
||||
sourceHealth = runtimeConfig.SourceFactories
|
||||
.Select(factory => SourceHealthSnapshot(factory.Descriptor, hub.Buffers.Buffers, sourceErrors, startedAt))
|
||||
.Select(factory => SourceHealthSnapshot(factory, hub.Buffers.Buffers, sourceErrors, startedAt))
|
||||
.ToArray(),
|
||||
buffers = hub.Buffers.Buffers.Select(BufferSnapshot).ToArray(),
|
||||
synchronizedFrame = new
|
||||
|
|
@ -1653,11 +1653,13 @@ internal static class MimirWellSnapshot
|
|||
}
|
||||
|
||||
private static object SourceHealthSnapshot(
|
||||
MimirStreamDescriptor descriptor,
|
||||
MimirStreamSourceFactory factory,
|
||||
IEnumerable<MimirRollingStreamBuffer> buffers,
|
||||
IReadOnlyList<object> sourceErrors,
|
||||
DateTimeOffset startedAt)
|
||||
{
|
||||
var descriptor = factory.Descriptor;
|
||||
var diagnostics = factory.Diagnostics;
|
||||
var matchingBuffers = buffers
|
||||
.Where(buffer => string.Equals(buffer.Descriptor.SourceId, descriptor.SourceId, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
|
|
@ -1700,12 +1702,33 @@ internal static class MimirWellSnapshot
|
|||
Kind = descriptor.Kind.ToString(),
|
||||
Origin = descriptor.Origin.ToString(),
|
||||
descriptor.Label,
|
||||
configured = diagnostics is null
|
||||
? null
|
||||
: new
|
||||
{
|
||||
diagnostics.Adapter,
|
||||
diagnostics.Command,
|
||||
diagnostics.PathNeedle,
|
||||
diagnostics.Width,
|
||||
diagnostics.Height,
|
||||
diagnostics.InputFormat,
|
||||
diagnostics.OutputFormat,
|
||||
diagnostics.PixelFormat,
|
||||
diagnostics.MinimumFramesPerSecond,
|
||||
diagnostics.FramesPerSecond,
|
||||
diagnostics.SampleRate,
|
||||
diagnostics.Channels,
|
||||
diagnostics.QueueDepth,
|
||||
acceptSourceIds = diagnostics.AcceptSourceIds,
|
||||
},
|
||||
status,
|
||||
reason = status switch
|
||||
{
|
||||
"create-error" => "source creation failed; see sourceErrors",
|
||||
"stalled" => "source emitted samples earlier but latest sample is stale",
|
||||
"waiting-network" => "network source listener is configured but no producer samples have arrived",
|
||||
"waiting-device-samples" when descriptor.Kind == MimirStreamKind.Video && IsKsCamera(diagnostics) =>
|
||||
KsCameraWaitingReason(diagnostics),
|
||||
"waiting-device-samples" => "local device source is configured but has not emitted a sample",
|
||||
_ => "samples arriving",
|
||||
},
|
||||
|
|
@ -1717,6 +1740,14 @@ internal static class MimirWellSnapshot
|
|||
};
|
||||
}
|
||||
|
||||
private static bool IsKsCamera(MimirStreamSourceDiagnostics? diagnostics) =>
|
||||
string.Equals(diagnostics?.Adapter, "ks-camera", StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private static string KsCameraWaitingReason(MimirStreamSourceDiagnostics? diagnostics) =>
|
||||
diagnostics is null
|
||||
? "KS camera opened but no frames have arrived; verify device ownership/driver"
|
||||
: $"KS camera opened but no frames have arrived; verify device ownership/driver for {diagnostics.Width}x{diagnostics.Height} {diagnostics.InputFormat}";
|
||||
|
||||
private static string? TryReadAnonymousString(object value, params string[] names)
|
||||
{
|
||||
var type = value.GetType();
|
||||
|
|
|
|||
Loading…
Reference in a new issue