using Mimir.Runtime.Synchronization; var duration = TimeSpan.FromSeconds(ParseDoubleOption(args, "--seconds", 10.0)); var pollDelay = TimeSpan.FromMilliseconds(ParseDoubleOption(args, "--poll-ms", 10.0)); var requireSamples = args.Any(arg => string.Equals(arg, "--require-samples", StringComparison.OrdinalIgnoreCase)); using var configuration = new DisposableConfiguration(MimirRuntimeConfiguration.Load()); using var hub = new MimirSynchronizationHub(configuration.Value.Settings); foreach (var source in configuration.Value.Sources) { configuration.Detach(source); hub.AddSource(source); } var deadline = DateTimeOffset.UtcNow + duration; while (DateTimeOffset.UtcNow < deadline) { hub.PollSources(maxSamplesPerSource: 4096); await Task.Delay(pollDelay).ConfigureAwait(false); } hub.PollSources(maxSamplesPerSource: 16384); Console.WriteLine($"sources={hub.SourceCount} ingested={hub.IngestedSamples} buffers={hub.Buffers.Buffers.Count}"); var emptyBuffers = new List(); foreach (var buffer in hub.Buffers.Buffers.OrderBy(buffer => buffer.Descriptor.SourceId, StringComparer.Ordinal)) { var latest = buffer.Latest; if (latest?.VideoFrame is { } frame) { Console.WriteLine( $"{buffer.Descriptor.SourceId}: count={buffer.Count} edgeNs={buffer.EdgeNs} latest={frame.Width}x{frame.Height} {frame.PixelFormat} bytes={latest.Value.ByteLength}"); } else { Console.WriteLine($"{buffer.Descriptor.SourceId}: count={buffer.Count} edgeNs={buffer.EdgeNs}"); } if (buffer.Count == 0) { emptyBuffers.Add(buffer.Descriptor.SourceId); } } if (requireSamples && emptyBuffers.Count > 0) { Console.Error.WriteLine($"empty buffers: {string.Join(", ", emptyBuffers)}"); return 1; } return 0; static double ParseDoubleOption(IReadOnlyList args, string name, double fallback) { for (var index = 0; index < args.Count - 1; index++) { if (string.Equals(args[index], name, StringComparison.OrdinalIgnoreCase) && double.TryParse(args[index + 1], out var parsed) && parsed > 0) { return parsed; } } return fallback; } internal sealed class DisposableConfiguration : IDisposable { private readonly List ownedSources; public DisposableConfiguration(MimirRuntimeConfiguration value) { Value = value; ownedSources = value.Sources.ToList(); } public MimirRuntimeConfiguration Value { get; } public void Detach(IMimirStreamSource source) { ownedSources.Remove(source); } public void Dispose() { foreach (var source in ownedSources) { source.Dispose(); } } }