Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions src/Baballonia.VFTCapture/VFTCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public override async Task<bool> StartCapture()
{
try
{
Logger.LogDebug("Trying to enable device.");
// Open the VFT device and initialize it.
SetTrackerState(setActive: true);

Expand Down Expand Up @@ -97,25 +98,18 @@ private Task VideoCapture_UpdateLoop()

private void SetTrackerState(bool setActive)
{
// Prev: var fd = ViveFacialTracker.open(Url, ViveFacialTracker.FileOpenFlags.O_RDWR);
var vftFileStream = File.Open(Source, FileMode.Open, FileAccess.ReadWrite);
var fd = vftFileStream.SafeFileHandle.DangerousGetHandle();
if (fd != IntPtr.Zero)
try
{
try
{
// Activate the tracker and give it some time to warm up/cool down
if (setActive)
ViveFacialTracker.activate_tracker((int)fd);
else
ViveFacialTracker.deactivate_tracker((int)fd);
// await Task.Delay(1000);
}
finally
{
// Prev: ViveFacialTracker.close((int)fd);
vftFileStream.Close();
}
// Leverage IDisposable for GC-less release of handle.
using var device = new ViveFacialTracker(Logger, Source);
if (!device.IsValid)
throw new NullReferenceException();

device.SetState(setActive);
}
catch(Exception e)
{
Logger.LogError(e.Message);
}
}

Expand Down
Loading