generated from dfgHiatus/Neos-Eye-Face-API
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Earthmark/main
Migrated to using ALVR v20
- Loading branch information
Showing
14 changed files
with
919 additions
and
1,023 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
using BaseX; | ||
using System; | ||
using System.Net.Sockets; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using OscCore; | ||
|
||
namespace QuestProModule; | ||
|
||
public class AlvrConnection : IDisposable | ||
{ | ||
private readonly SyncCell<FbMessage> _messageTarget; | ||
|
||
/// <summary> | ||
/// A message owned by this reader that is currently being mutated. | ||
/// </summary> | ||
private FbMessage _workingMessage = new(); | ||
|
||
private readonly UdpClient _client; | ||
private readonly CancellationTokenSource _stopToken = new(); | ||
private readonly Task _listenTask; | ||
|
||
public AlvrConnection(int port, SyncCell<FbMessage> target) | ||
{ | ||
_messageTarget = target; | ||
_client = new UdpClient(port); | ||
_listenTask = Task.Run(ListenAsync); | ||
UniLog.Log($"Opening Alvr connection on {port}"); | ||
} | ||
|
||
private async Task ListenAsync() | ||
{ | ||
while (!_stopToken.IsCancellationRequested) | ||
{ | ||
try | ||
{ | ||
var got = await _client.ReceiveAsync(); | ||
var message = new OscMessageRaw(new ArraySegment<byte>(got.Buffer)); | ||
switch (message.Address) | ||
{ | ||
case "/tracking/eye/left/Quat": | ||
case "/tracking/eye/left/Active": | ||
case "/tracking/eye/right/Quat": | ||
case "/tracking/eye/right/Active": | ||
// Ignore these, we do this ourselves. | ||
break; | ||
case "/tracking/eye_htc": | ||
case "/tracking/lip_htc": | ||
UniLog.Error("Unexpected ALVR message in loading area, please use facebook eye tracking."); | ||
break; | ||
case "/tracking/face_fb": | ||
_workingMessage.ParseOsc(message); | ||
if (!_stopToken.IsCancellationRequested) | ||
{ | ||
_messageTarget.Swap(ref _workingMessage); | ||
} | ||
break; | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
UniLog.Error(ex.Message); | ||
} | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
UniLog.Log("Alvr connection closing."); | ||
_stopToken.Cancel(); | ||
_client.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using BaseX; | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Timers; | ||
|
||
namespace QuestProModule; | ||
|
||
internal class AlvrMonitor : IDisposable | ||
{ | ||
public string ClientName { get; set; } | ||
public string ClientPath { get; set; } | ||
public string Arguments { get; set; } | ||
|
||
private readonly Timer _timer; | ||
|
||
private Process _foundProcess; | ||
|
||
public AlvrMonitor() | ||
{ | ||
_timer = new(1000); | ||
_timer.Elapsed += (o, e) => CheckProcess(); | ||
} | ||
|
||
void CheckProcess() | ||
{ | ||
if (!CheckIfRunning()) | ||
{ | ||
StartClient(); | ||
} | ||
} | ||
|
||
private bool CheckIfRunning() | ||
{ | ||
Process[] alvrClients = Process.GetProcessesByName("alxr-client"); | ||
foreach (Process client in alvrClients) | ||
{ | ||
if (_foundProcess is { HasExited: false }) | ||
{ | ||
client.Dispose(); | ||
continue; | ||
} | ||
|
||
WatchProcess(client); | ||
} | ||
|
||
return !(_foundProcess?.HasExited ?? true); | ||
} | ||
|
||
private void WatchProcess(Process process) | ||
{ | ||
_foundProcess?.Dispose(); | ||
_foundProcess = null; | ||
|
||
if (process.HasExited) | ||
{ | ||
return; | ||
} | ||
|
||
_foundProcess = process; | ||
|
||
_foundProcess.Exited += (o, e) => _timer.Start(); | ||
} | ||
|
||
private void StartClient() | ||
{ | ||
try | ||
{ | ||
string directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); | ||
string clientPath = Path.Combine(directory, ClientPath); | ||
var process = Process.Start(clientPath, Arguments); | ||
|
||
UniLog.Log($"Starting ALXR at: {process.StartInfo.FileName}"); | ||
WatchProcess(process); | ||
} | ||
catch | ||
{ | ||
UniLog.Log($"Failed to start process at {ClientPath}"); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_timer.Dispose(); | ||
_foundProcess?.Dispose(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.