diff --git a/hl2ss_unreal/Plugins/hl2ss/Source/hl2ss/Private/hl2ss_api.cpp b/hl2ss_unreal/Plugins/hl2ss/Source/hl2ss/Private/hl2ss_api.cpp index 1db399e9c..4fe37ae68 100644 --- a/hl2ss_unreal/Plugins/hl2ss/Source/hl2ss/Private/hl2ss_api.cpp +++ b/hl2ss_unreal/Plugins/hl2ss/Source/hl2ss/Private/hl2ss_api.cpp @@ -16,6 +16,11 @@ typedef void(*pfn_MQ_SI_Pop)(uint32_t& command, uint8_t* data); typedef void(*pfn_MQ_SO_Push)(uint32_t id); typedef void(*pfn_MQ_Restart)(); +typedef uint32_t(*pfn_MQX_CO_Peek)(); +typedef void(*pfn_MQX_CO_Pop)(uint32_t& id); +typedef void(*pfn_MQX_CI_Push)(uint32_t command, uint32_t size, uint8_t const* data); +typedef void(*pfn_MQX_Restart)(); + #if PLATFORM_HOLOLENS extern "C" { HMODULE LoadLibraryW(LPCWSTR lpLibFileName); } #endif @@ -34,6 +39,11 @@ void* hl2ss_api::p_MQ_SI_Pop = NULL; void* hl2ss_api::p_MQ_SO_Push = NULL; void* hl2ss_api::p_MQ_Restart = NULL; +void* hl2ss_api::p_MQX_CO_Peek = NULL; +void* hl2ss_api::p_MQX_CO_Pop = NULL; +void* hl2ss_api::p_MQX_CI_Push = NULL; +void* hl2ss_api::p_MQX_Restart = NULL; + int hl2ss_api::Load() { FString path_base = FPaths::ProjectPluginsDir() + L"hl2ss/Binaries/hl2ss/"; @@ -66,6 +76,11 @@ int hl2ss_api::Load() p_MQ_SO_Push = GetProcAddress((HMODULE)hmod_hl2ss, "MQ_SO_Push"); p_MQ_Restart = GetProcAddress((HMODULE)hmod_hl2ss, "MQ_Restart"); + p_MQX_CO_Peek = GetProcAddress((HMODULE)hmod_hl2ss, "MQX_CO_Peek"); + p_MQX_CO_Pop = GetProcAddress((HMODULE)hmod_hl2ss, "MQX_CO_Pop"); + p_MQX_CI_Push = GetProcAddress((HMODULE)hmod_hl2ss, "MQX_CI_Push"); + p_MQX_Restart = GetProcAddress((HMODULE)hmod_hl2ss, "MQX_Restart"); + if (p_InitializeStreams == NULL) { return -7; } if (p_DebugMessage == NULL) { return -8; } if (p_OverrideWorldCoordinateSystem == NULL) { return -9; } @@ -76,6 +91,11 @@ int hl2ss_api::Load() if (p_MQ_SO_Push == NULL) { return -13; } if (p_MQ_Restart == NULL) { return -14; } + if (p_MQX_CO_Peek == NULL) { return -15; } + if (p_MQX_CO_Pop == NULL) { return -16; } + if (p_MQX_CI_Push == NULL) { return -17; } + if (p_MQX_Restart == NULL) { return -18; } + return 1; } @@ -133,3 +153,27 @@ void hl2ss_api::MQ_Restart() if (p_MQ_Restart == NULL) { return; } reinterpret_cast(p_MQ_Restart)(); } + +uint32_t hl2ss_api::MQX_CO_Peek() +{ + if (p_MQX_CO_Peek == NULL) { return 0xFFFFFFFF; } + return reinterpret_cast(p_MQX_CO_Peek)(); +} + +void hl2ss_api::MQX_CO_Pop(uint32_t& id) +{ + if (p_MQX_CO_Pop == NULL) { return; } + reinterpret_cast(p_MQX_CO_Pop)(id); +} + +void hl2ss_api::MQX_CI_Push(uint32_t command, uint32_t size, uint8_t const* data) +{ + if (p_MQX_CI_Push == NULL) { return; } + reinterpret_cast(p_MQX_CI_Push)(command, size, data); +} + +void hl2ss_api::MQX_Restart() +{ + if (p_MQX_Restart == NULL) { return; } + reinterpret_cast(p_MQX_Restart)(); +} diff --git a/hl2ss_unreal/Plugins/hl2ss/Source/hl2ss/Public/hl2ss_api.h b/hl2ss_unreal/Plugins/hl2ss/Source/hl2ss/Public/hl2ss_api.h index 75133898e..708dfacaf 100644 --- a/hl2ss_unreal/Plugins/hl2ss/Source/hl2ss/Public/hl2ss_api.h +++ b/hl2ss_unreal/Plugins/hl2ss/Source/hl2ss/Public/hl2ss_api.h @@ -24,6 +24,11 @@ class HL2SS_API hl2ss_api static void* p_MQ_SO_Push; static void* p_MQ_Restart; + static void* p_MQX_CO_Peek; + static void* p_MQX_CO_Pop; + static void* p_MQX_CI_Push; + static void* p_MQX_Restart; + static int Load(); public: @@ -41,6 +46,7 @@ class HL2SS_API hl2ss_api ENABLE_EET = 512, ENABLE_EA = 1024, ENABLE_EV = 2048, + ENABLE_MQX = 4096, ENABLE_ALL = 0xFFFFFFFF, }; @@ -57,4 +63,8 @@ class HL2SS_API hl2ss_api static void MQ_SI_Pop(uint32_t& command, uint8_t* data); static void MQ_SO_Push(uint32_t id); static void MQ_Restart(); + static uint32_t MQX_CO_Peek(); + static void MQX_CO_Pop(uint32_t& id); + static void MQX_CI_Push(uint32_t command, uint32_t size, uint8_t const* data); + static void MQX_Restart(); }; diff --git a/hl2ss_unreal/Source/hl2ss_unreal/hl2ss_loader.cpp b/hl2ss_unreal/Source/hl2ss_unreal/hl2ss_loader.cpp index 7d0d468e1..f942fe1c5 100644 --- a/hl2ss_unreal/Source/hl2ss_unreal/hl2ss_loader.cpp +++ b/hl2ss_unreal/Source/hl2ss_unreal/hl2ss_loader.cpp @@ -31,6 +31,7 @@ void Ahl2ss_loader::BeginPlay() auto ip_address = FString(buffer); hl2ss_api::DebugMessage(StringCast(*ip_address).Get()); + mqx_state = 0; } // Called every frame @@ -38,6 +39,12 @@ void Ahl2ss_loader::Tick(float DeltaTime) { Super::Tick(DeltaTime); + ProcessClientMessage(); + ProcessServerMessage(); +} + +void Ahl2ss_loader::ProcessClientMessage() +{ // Translate and process client messages uint32_t size = hl2ss_api::MQ_SI_Peek(); @@ -67,3 +74,25 @@ void Ahl2ss_loader::Tick(float DeltaTime) if (command == hl2ss_api::CLIENT_DISCONNECTED) { hl2ss_api::MQ_Restart(); } } +void Ahl2ss_loader::ProcessServerMessage() +{ + char const* text = "Hello from HoloLens 2!"; + uint32_t status; + uint32_t response; + + switch (mqx_state) + { + case 0: + hl2ss_api::MQX_CI_Push(0xFFFFFFFE, (uint32_t)strlen(text), (uint8_t*)text); + mqx_state = 1; + break; + case 1: + status = hl2ss_api::MQX_CO_Peek(); + if (status == hl2ss_api::QUEUE_EMPTY) { break; } + hl2ss_api::MQX_CO_Pop(response); + if (response != hl2ss_api::CLIENT_DISCONNECTED) { break; } + hl2ss_api::MQX_Restart(); + mqx_state = 0; + break; + } +} diff --git a/hl2ss_unreal/Source/hl2ss_unreal/hl2ss_loader.h b/hl2ss_unreal/Source/hl2ss_unreal/hl2ss_loader.h index a8b914d05..aea6a453d 100644 --- a/hl2ss_unreal/Source/hl2ss_unreal/hl2ss_loader.h +++ b/hl2ss_unreal/Source/hl2ss_unreal/hl2ss_loader.h @@ -11,10 +11,15 @@ class HL2SS_UNREAL_API Ahl2ss_loader : public AActor { GENERATED_BODY() + int mqx_state; + public: // Sets default values for this actor's properties Ahl2ss_loader(); + void ProcessClientMessage(); + void ProcessServerMessage(); + protected: // Called when the game starts or when spawned virtual void BeginPlay() override;