Prove probe feeds reach runtime buffers
This commit is contained in:
parent
17aa027c79
commit
2347495824
10 changed files with 155 additions and 11 deletions
92
src/Mimir.BufferSmoke/Program.cs
Normal file
92
src/Mimir.BufferSmoke/Program.cs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
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<string>();
|
||||
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<string> 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<IMimirStreamSource> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue