Upload CPU camera frames into Fensalir leases
This commit is contained in:
parent
9147fcd626
commit
7f3df7979b
9 changed files with 105 additions and 8 deletions
|
|
@ -68,6 +68,27 @@ public sealed class MimirFensalirTextureLeaseClient(IAquariumFieldResourceBroker
|
|||
public bool Commit(string resourceKey, ulong version, ulong producerFenceValue) =>
|
||||
broker.CommitLeaseVersion(resourceKey, version, producerFenceValue);
|
||||
|
||||
public bool UploadCpuFrame(MimirVideoFrameDescriptor frame, ReadOnlyMemory<byte> data)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(frame.ResourceKey) ||
|
||||
frame.Width <= 0 ||
|
||||
frame.Height <= 0 ||
|
||||
frame.StrideBytes <= 0 ||
|
||||
data.IsEmpty)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return broker.UploadTexture2D(new AquariumTexture2DUpload(
|
||||
frame.ResourceKey,
|
||||
frame.Width,
|
||||
frame.Height,
|
||||
FormatForPixelFormat(frame.PixelFormat),
|
||||
frame.StrideBytes,
|
||||
data,
|
||||
frame.ProducerFenceValue));
|
||||
}
|
||||
|
||||
public static string ResourceKeyForSource(string sourceId)
|
||||
{
|
||||
var normalized = sourceId.Trim().ToLowerInvariant().Replace('\\', '/');
|
||||
|
|
@ -78,7 +99,9 @@ public sealed class MimirFensalirTextureLeaseClient(IAquariumFieldResourceBroker
|
|||
pixelFormat switch
|
||||
{
|
||||
MimirVideoPixelFormat.Gray8 or MimirVideoPixelFormat.R8 => "R8Unorm",
|
||||
MimirVideoPixelFormat.Bayer8 => "R8Unorm",
|
||||
MimirVideoPixelFormat.Rg8 or MimirVideoPixelFormat.LeapStereoIr => "R8G8_UNorm",
|
||||
MimirVideoPixelFormat.Yuy2 => "YUY2",
|
||||
MimirVideoPixelFormat.Bgra8 => "Bgra8",
|
||||
MimirVideoPixelFormat.Nv12 => "Nv12",
|
||||
_ => "Rgba8Unorm",
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ public sealed class MimirVideoCaptureDriverSource : IMimirStreamSource, IMimirFe
|
|||
{
|
||||
private readonly IMimirVideoCaptureDriver driver;
|
||||
private readonly MimirNativeIngestStreamSource nativeSource;
|
||||
private MimirFensalirTextureLeaseClient? textureLeaseClient;
|
||||
|
||||
public MimirVideoCaptureDriverSource(
|
||||
MimirStreamDescriptor descriptor,
|
||||
|
|
@ -25,8 +26,11 @@ public sealed class MimirVideoCaptureDriverSource : IMimirStreamSource, IMimirFe
|
|||
|
||||
public Func<long> ReadArrivalNs { get; }
|
||||
|
||||
public int LastUploadedCopyCount { get; private set; }
|
||||
|
||||
public void AttachTextureLeaseClient(MimirFensalirTextureLeaseClient? client)
|
||||
{
|
||||
textureLeaseClient = client;
|
||||
if (driver is IMimirFensalirTextureLeaseReceiver receiver)
|
||||
{
|
||||
receiver.AttachTextureLeaseClient(client);
|
||||
|
|
@ -45,6 +49,16 @@ public sealed class MimirVideoCaptureDriverSource : IMimirStreamSource, IMimirFe
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!data.IsEmpty && !string.IsNullOrWhiteSpace(frame.ResourceKey))
|
||||
{
|
||||
if (textureLeaseClient?.UploadCpuFrame(frame, data) == true)
|
||||
{
|
||||
frame = frame with { UnavoidableCopyCount = frame.UnavoidableCopyCount + 1 };
|
||||
LastUploadedCopyCount = frame.UnavoidableCopyCount;
|
||||
data = default;
|
||||
}
|
||||
}
|
||||
|
||||
nativeSource.PushVideoFrame(frame, ReadArrivalNs(), data);
|
||||
return nativeSource.TryRead(out sample);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,4 +24,5 @@ public sealed record MimirVideoFrameDescriptor(
|
|||
ulong NativeHandle = 0,
|
||||
string NativeHandleKind = "",
|
||||
string ResourceKey = "",
|
||||
ulong ProducerFenceValue = 0);
|
||||
ulong ProducerFenceValue = 0,
|
||||
int UnavoidableCopyCount = 0);
|
||||
|
|
|
|||
Loading…
Reference in a new issue