Clarify Well source health and process clocks
This commit is contained in:
parent
980f185104
commit
2fa008aee4
7 changed files with 25 additions and 41 deletions
|
|
@ -108,8 +108,6 @@ public sealed class MimirAsioStreamSource : IMimirMultiplexedStreamSource
|
|||
|
||||
started.Set();
|
||||
var sampleBuffer = new float[Math.Max(1, maxFrames)];
|
||||
long firstDeviceTimestampNs = 0;
|
||||
long firstCanonicalEndNs = 0;
|
||||
while (!cancellation.IsCancellationRequested)
|
||||
{
|
||||
if (!Native.Read(
|
||||
|
|
@ -134,16 +132,7 @@ public sealed class MimirAsioStreamSource : IMimirMultiplexedStreamSource
|
|||
var bytes = new byte[frameCount * sizeof(float)];
|
||||
var arrivalNs = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() * 1_000_000L;
|
||||
var durationNs = checked((long)Math.Ceiling(frameCount * 1_000_000_000.0 / Math.Max(1, sampleRate)));
|
||||
if (timestampNs > 0 && firstDeviceTimestampNs == 0)
|
||||
{
|
||||
firstDeviceTimestampNs = timestampNs;
|
||||
firstCanonicalEndNs = arrivalNs;
|
||||
}
|
||||
|
||||
var endNs = timestampNs > 0 && firstDeviceTimestampNs > 0
|
||||
? checked(firstCanonicalEndNs + (timestampNs - firstDeviceTimestampNs))
|
||||
: arrivalNs;
|
||||
var startNs = Math.Max(0, endNs - durationNs);
|
||||
var startNs = Math.Max(0, arrivalNs - durationNs);
|
||||
MemoryMarshal.AsBytes(sampleBuffer.AsSpan(0, frameCount)).CopyTo(bytes);
|
||||
samples.Enqueue(new MimirStreamSample(
|
||||
sourceId,
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ public sealed class MimirFfmpegPcmAudioStreamSource : IMimirStreamSource
|
|||
offset += read;
|
||||
}
|
||||
|
||||
var timestampNs = StopwatchTicksToNs(Stopwatch.GetTimestamp());
|
||||
var timestampNs = UtcNowNs();
|
||||
samples.Enqueue(new MimirStreamSample(
|
||||
Descriptor.SourceId,
|
||||
Descriptor.Kind,
|
||||
|
|
@ -137,10 +137,7 @@ public sealed class MimirFfmpegPcmAudioStreamSource : IMimirStreamSource
|
|||
_ => 0,
|
||||
};
|
||||
|
||||
private static long StopwatchTicksToNs(long ticks)
|
||||
{
|
||||
return checked((long)(ticks * (1_000_000_000.0 / Stopwatch.Frequency)));
|
||||
}
|
||||
private static long UtcNowNs() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() * 1_000_000L;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ public sealed class MimirFfmpegRawVideoStreamSource : IMimirStreamSource
|
|||
offset += read;
|
||||
}
|
||||
|
||||
var timestampNs = StopwatchTicksToNs(Stopwatch.GetTimestamp());
|
||||
var timestampNs = UtcNowNs();
|
||||
var videoFrame = new MimirVideoFrameDescriptor(
|
||||
Options.Width,
|
||||
Options.Height,
|
||||
|
|
@ -152,10 +152,7 @@ public sealed class MimirFfmpegRawVideoStreamSource : IMimirStreamSource
|
|||
};
|
||||
}
|
||||
|
||||
private static long StopwatchTicksToNs(long ticks)
|
||||
{
|
||||
return checked((long)(ticks * (1_000_000_000.0 / Stopwatch.Frequency)));
|
||||
}
|
||||
private static long UtcNowNs() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() * 1_000_000L;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -118,8 +118,8 @@ public sealed class MimirFrameEventProcessStreamSource : IMimirStreamSource
|
|||
|
||||
var timestampNs = frameEvent.TimestampNs > 0
|
||||
? frameEvent.TimestampNs
|
||||
: StopwatchTicksToNs(Stopwatch.GetTimestamp());
|
||||
var arrivalNs = StopwatchTicksToNs(Stopwatch.GetTimestamp());
|
||||
: UtcNowNs();
|
||||
var arrivalNs = UtcNowNs();
|
||||
var byteLength = Math.Max(0, frameEvent.ByteLength);
|
||||
var payloadHandle = frameEvent.NativeHandle;
|
||||
var sampleKind = frameEvent.IsAudioBlock ? MimirStreamKind.Audio : Descriptor.Kind;
|
||||
|
|
@ -271,10 +271,7 @@ public sealed class MimirFrameEventProcessStreamSource : IMimirStreamSource
|
|||
};
|
||||
}
|
||||
|
||||
private static long StopwatchTicksToNs(long ticks)
|
||||
{
|
||||
return checked((long)(ticks * (1_000_000_000.0 / Stopwatch.Frequency)));
|
||||
}
|
||||
private static long UtcNowNs() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() * 1_000_000L;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -74,8 +74,7 @@ public sealed class MimirProcessStreamSource : IMimirStreamSource
|
|||
Array.Resize(ref buffer, read);
|
||||
}
|
||||
|
||||
var now = Stopwatch.GetTimestamp();
|
||||
var timestampNs = StopwatchTicksToNs(now);
|
||||
var timestampNs = UtcNowNs();
|
||||
samples.Enqueue(new MimirStreamSample(
|
||||
Descriptor.SourceId,
|
||||
Descriptor.Kind,
|
||||
|
|
@ -102,10 +101,7 @@ public sealed class MimirProcessStreamSource : IMimirStreamSource
|
|||
}
|
||||
}
|
||||
|
||||
private static long StopwatchTicksToNs(long ticks)
|
||||
{
|
||||
return checked((long)(ticks * (1_000_000_000.0 / Stopwatch.Frequency)));
|
||||
}
|
||||
private static long UtcNowNs() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() * 1_000_000L;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue