Signal MF GPU camera producer fences
This commit is contained in:
parent
e59cf4450a
commit
dab0f520ca
8 changed files with 83 additions and 13 deletions
|
|
@ -49,6 +49,7 @@ public readonly record struct MimirBridgePayloadView(
|
|||
string NativeHandleKind,
|
||||
int ByteLength,
|
||||
string ResourceKey = "",
|
||||
ulong ProducerFenceHandle = 0,
|
||||
ulong ProducerFenceValue = 0)
|
||||
{
|
||||
public bool HasResource => NativeHandle != 0 || !string.IsNullOrWhiteSpace(ResourceKey);
|
||||
|
|
@ -363,12 +364,14 @@ public static class MimirFensalirBridgeMapper
|
|||
var nativeHandle = sample.VideoFrame?.NativeHandle ?? sample.AudioBlock?.NativeHandle ?? sample.PayloadHandle;
|
||||
var nativeHandleKind = sample.VideoFrame?.NativeHandleKind ?? sample.AudioBlock?.NativeHandleKind ?? "";
|
||||
var resourceKey = sample.VideoFrame?.ResourceKey ?? "";
|
||||
var producerFenceHandle = sample.VideoFrame?.ProducerFenceHandle ?? 0;
|
||||
var producerFenceValue = sample.VideoFrame?.ProducerFenceValue ?? 0;
|
||||
return new MimirBridgePayloadView(
|
||||
nativeHandle,
|
||||
nativeHandleKind,
|
||||
sample.ByteLength,
|
||||
string.IsNullOrWhiteSpace(resourceKey) ? ResourceKeyForPayload(nativeHandle, nativeHandleKind) : resourceKey,
|
||||
producerFenceHandle,
|
||||
producerFenceValue);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -193,7 +193,9 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt
|
|||
ValidUntilNs: window.EdgeNs,
|
||||
Version: window.SequenceId,
|
||||
NativeHandle: new IntPtr(unchecked((long)window.Payload.NativeHandle)),
|
||||
NativeHandleKind: window.Payload.NativeHandleKind);
|
||||
NativeHandleKind: window.Payload.NativeHandleKind,
|
||||
ProducerFenceHandle: new IntPtr(unchecked((long)window.Payload.ProducerFenceHandle)),
|
||||
ProducerFenceValue: window.Payload.ProducerFenceValue);
|
||||
}
|
||||
|
||||
private static AquariumFieldResourceDeclaration ResourceForObservation(MimirObservation observation)
|
||||
|
|
@ -223,7 +225,9 @@ public sealed class MimirFensalirFieldLowering(MimirFensalirLoweringOptions? opt
|
|||
ValidUntilNs: observation.CanonicalTimeEstimateNs + Math.Max(0, observation.UncertaintyNs),
|
||||
Version: observation.Provenance.SequenceId,
|
||||
NativeHandle: new IntPtr(unchecked((long)observation.Payload.NativeHandle)),
|
||||
NativeHandleKind: observation.Payload.NativeHandleKind);
|
||||
NativeHandleKind: observation.Payload.NativeHandleKind,
|
||||
ProducerFenceHandle: new IntPtr(unchecked((long)observation.Payload.ProducerFenceHandle)),
|
||||
ProducerFenceValue: observation.Payload.ProducerFenceValue);
|
||||
}
|
||||
|
||||
private static AquariumFieldDomain DomainForObservation(MimirObservation observation) =>
|
||||
|
|
|
|||
|
|
@ -58,7 +58,8 @@ public sealed unsafe class MimirMediaFoundationGpuVideoCaptureDriver : IMimirVid
|
|||
out var height,
|
||||
formatBytes,
|
||||
out var timestampNs,
|
||||
out var sequence) ||
|
||||
out var sequence,
|
||||
out var producerFenceHandle) ||
|
||||
sharedHandle == 0)
|
||||
{
|
||||
frame = default!;
|
||||
|
|
@ -76,6 +77,7 @@ public sealed unsafe class MimirMediaFoundationGpuVideoCaptureDriver : IMimirVid
|
|||
NativeHandle: unchecked((ulong)sharedHandle),
|
||||
NativeHandleKind: "shared-d3d11-texture",
|
||||
ResourceKey: MimirFensalirTextureLeaseClient.ResourceKeyForSource(sourceId),
|
||||
ProducerFenceHandle: unchecked((ulong)producerFenceHandle),
|
||||
ProducerFenceValue: sequence);
|
||||
data = default;
|
||||
return true;
|
||||
|
|
@ -126,14 +128,14 @@ public sealed unsafe class MimirMediaFoundationGpuVideoCaptureDriver : IMimirVid
|
|||
{
|
||||
private readonly nint library;
|
||||
private readonly delegate* unmanaged[Stdcall]<byte*, int, int, byte*, byte*, double, nint> create;
|
||||
private readonly delegate* unmanaged[Stdcall]<nint, out nint, out int, out int, byte*, int, out long, out ulong, int> read;
|
||||
private readonly delegate* unmanaged[Stdcall]<nint, out nint, out int, out int, byte*, int, out long, out ulong, out nint, int> read;
|
||||
private readonly delegate* unmanaged[Stdcall]<nint, void> destroy;
|
||||
|
||||
private Native(nint library)
|
||||
{
|
||||
this.library = library;
|
||||
create = (delegate* unmanaged[Stdcall]<byte*, int, int, byte*, byte*, double, nint>)NativeLibrary.GetExport(library, "mimir_mf_gpu_create");
|
||||
read = (delegate* unmanaged[Stdcall]<nint, out nint, out int, out int, byte*, int, out long, out ulong, int>)NativeLibrary.GetExport(library, "mimir_mf_gpu_read");
|
||||
read = (delegate* unmanaged[Stdcall]<nint, out nint, out int, out int, byte*, int, out long, out ulong, out nint, int>)NativeLibrary.GetExport(library, "mimir_mf_gpu_read");
|
||||
destroy = (delegate* unmanaged[Stdcall]<nint, void>)NativeLibrary.GetExport(library, "mimir_mf_gpu_destroy");
|
||||
}
|
||||
|
||||
|
|
@ -159,11 +161,12 @@ public sealed unsafe class MimirMediaFoundationGpuVideoCaptureDriver : IMimirVid
|
|||
out int height,
|
||||
Span<byte> format,
|
||||
out long timestampNs,
|
||||
out ulong sequence)
|
||||
out ulong sequence,
|
||||
out nint producerFenceHandle)
|
||||
{
|
||||
fixed (byte* formatPointer = format)
|
||||
{
|
||||
return read(capture, out sharedHandle, out width, out height, formatPointer, format.Length, out timestampNs, out sequence) != 0;
|
||||
return read(capture, out sharedHandle, out width, out height, formatPointer, format.Length, out timestampNs, out sequence, out producerFenceHandle) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,5 +24,6 @@ public sealed record MimirVideoFrameDescriptor(
|
|||
ulong NativeHandle = 0,
|
||||
string NativeHandleKind = "",
|
||||
string ResourceKey = "",
|
||||
ulong ProducerFenceHandle = 0,
|
||||
ulong ProducerFenceValue = 0,
|
||||
int UnavoidableCopyCount = 0);
|
||||
|
|
|
|||
Loading…
Reference in a new issue