# jdibenes/hl2ss architecture

> Architecture diagram of the GitHub repository jdibenes/hl2ss, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/jdibenes/hl2ss
- Repository: https://github.com/jdibenes/hl2ss

## Overview

##### Project Type and Purpose
- This is a cross-platform, client–server sensor-streaming framework for HoloLens 2.
- The “server” runs on the HoloLens device (C++ UWP app or plugin for Unity/Unreal). It captures sensor data (cameras, depth, IMU, audio, spatial input, mapping, voice) via the Research Mode API and Cannon library, encodes it (H264/HEVC/AAC/Zdepth/PNG), and streams it over TCP.
- The “clients” run on Windows/Linux/macOS, or inside MATLAB, LabVIEW, Android, Unity, Unreal, TouchDesigner, or Python, decode/unpack the streams, and optionally send control commands back (configuration, calibration, message queuing, remote scene commands).

##### File-Structure Analysis
- Top-level directories:
– hl2ss/ → C++ UWP server and plugin projects
– extensions/ → Language-specific client libraries (C++, Python MT, MATLAB, LabVIEW, Android, Unity, Unreal, TouchDesigner)
– viewer/ → Python sample clients for each interface
– hl2ss_unity/, hl2ss_unreal/ → Sample Unity and Unreal projects integrating the plugin
– hl2ss_td/ → TouchDesigner components and samples
– tools/ → Utility scripts (calibration download, device enumeration, format conversion)
– etc/ → Configuration files, calibration data, Redis adapters, Docker compose
- Core server code sits in hl2ss/ (captures, encodes, IPC messaging, networking).
- Zdepth compression library and Cannon helper code live under 3rdparty/.

##### Key README Insights
- The server exports multiple independent TCP streams, one per sensor/interface.
- Clients must decode (via PyAV/OpenCV/NumPy/Zdepth), unpack, and optionally recombine streams.
- Clients can also send IPC commands back to configure streams, query calibration, or control Unity/Unreal via message queues.
- Integration points (extensibility) are clearly marked: extensions/, viewer/, sample projects.

a. Main Components
- HoloLens 2 Device (Windows UWP)
– Research Mode Sensors
– Cannon helper library
– Zdepth compressor
– hl2ss core server app (captures, encodes per‐sensor pipelines)
– Plugin DLLs for Unity/UWP/Unreal (same capture/encode, exposed as WinRT)
- Network Layer
– TCP sockets on configurable ports (one port per stream type via server_ports.h)
– Bi-directional message queues (GMQ/UMQ) for control messages
- Host‐side Clients
– Python “viewer” scripts (client_stream_*.py, client_ipc_*.py)
– C++ client library (extensions/client_cpp)
– MATLAB/Simulink library (extensions/client_matlab)
– LabVIEW VIs (extensions/client_labview)
– Android client (extensions/client_android)
– Unity plugin client (extensions/client_unity + sample hl2ss_unity)
– Unreal plugin client (extensions/client_unreal + sample project)
– TouchDesigner components (hl2ss_td)
– Tools (calibration downloader, device enumerator)
b. Relationships & Interactions
– On HoloLens: Sensor hardware → Research Mode API → capture threads → encode modules (H264/HEVC/AAC/PNG/Zdepth) → network server socket.
– Network: TCP connection(s) carry media payloads and timestamp/control channels.
– Host Client: TCP client socket → receive encoded packets → demux & decode (PyAV, Zdepth lib, OpenCV) → unpack payload → deliver frames/events to application.
– IPC: Clients use Redis adapters or ZeroMQ (ipc_gmq, ipc_umq) to exchange control messages with Unity/Unreal or with the hl2ss server for on-the-fly reconfiguration.
c. Architectural Patterns
– Modular pipeline per sensor (producer‐consumer).
– Plugin/extension pattern for each language/runtime.
– Client–server over TCP (multi-stream, single‐client per stream).
– Message-queue IPC for control.
d. Technologies & Libraries
– C++ (WinRT, UWP, Visual Studio solution)
– HoloLens2ForCV Cannon library
– Zdepth (lossless depth compression)
– FFmpeg/PyAV, OpenCV, NumPy for Python
– MATLAB API wrappers, LabVIEW VIs, Android NDK+Gradle, Unity C# plugin, Unreal C++ plugin
– Redis or ZeroMQ for IPC

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Swimlanes
    subgraph "HoloLens 2 Device" 
        direction TB
        Sensors["Research Mode Sensors"]:::hardware
        RM_API["Research Mode API"]:::server
        Cannon["Cannon Helper Library"]:::server
        Zdepth["Zdepth Compressor"]:::server
        CoreServer["hl2ss Core Server\n(C++ UWP)"]:::server
        Plugins["Plugin DLLs\n(Unity/UWP/Unreal)"]:::server
        IPC_Server["IPC Modules\n(GMQ/UMQ/etc.)"]:::ipc
        Sensors -->|"API Calls"| RM_API
        RM_API -->|"Captures"| CoreServer
        CoreServer -->|"Uses"| Cannon
        CoreServer -->|"Uses"| Zdepth
        CoreServer -->|"Hosts"| IPC_Server
        CoreServer -->|"Exports Streams"| Plugins
    end

    subgraph "Network Layer"
        direction TB
        TCP["TCP Sockets\n(per-stream ports)"]:::network
        MQ["Message Queues\n(Redis/ZeroMQ)"]:::ipc
        CoreServer -->|TCP| TCP
        IPC_Server -->|ZMQ/Redis| MQ
    end

    subgraph "Host Applications"
        direction TB
        subgraph "Python Viewer" 
            PyClient["Python Client\n(PyAV/OpenCV)"]:::client
        end
        subgraph "C++ Client Library"
            CPPClient["C++ Client\nLibrary"]:::client
        end
        subgraph "MATLAB Client"
            MATLAB["MATLAB Client\n(+hl2ss wrappers)"]:::client
        end
        subgraph "LabVIEW Client"
            LabVIEW["LabVIEW VIs"]:::client
        end
        subgraph "Android Client"
            Android["Android Client\n(NDK)"]:::client
        end
        subgraph "Unity Client"
            UnityClient["Unity Extension\n& Sample"]:::client
        end
        subgraph "Unreal Client"
            UnrealClient["Unreal Extension\n& Sample"]:::client
        end
        subgraph "TouchDesigner"
            TD["TouchDesigner Modules"]:::client
        end
        subgraph "Tools & Utilities"
            Tools["Calibration, Enumeration,\nConversion Tools"]:::client
        end

        TCP -->|H264/AAC/Zdepth| PyClient
        TCP -->|H264/AAC/Zdepth| CPPClient
        TCP -->|H264/AAC/Zdepth| MATLAB
        TCP -->|H264/AAC/Zdepth| LabVIEW
        TCP -->|H264/AAC/Zdepth| Android
        TCP -->|H264/AAC/Zdepth| UnityClient
        TCP -->|H264/AAC/Zdepth| UnrealClient
        TCP -->|H264/AAC/Zdepth| TD

        MQ -->|Control| PyClient
        MQ -->|Control| CPPClient
        MQ -->|Control| MATLAB
        MQ -->|Control| LabVIEW
        MQ -->|Control| Android
        MQ -->|Control| UnityClient
        MQ -->|Control| UnrealClient
        MQ -->|Control| TD
        MQ -->|Control| Tools
    end

    %% Click Events
    click CoreServer "https://github.com/jdibenes/hl2ss/tree/main/hl2ss/hl2ss"
    click Cannon "https://github.com/jdibenes/hl2ss/tree/main/3rdparty/HoloLens2ForCV/Cannon"
    click Zdepth "https://github.com/jdibenes/hl2ss/tree/main/3rdparty/Zdepth"
    click PyClient "https://github.com/jdibenes/hl2ss/tree/main/viewer/"
    click CPPClient "https://github.com/jdibenes/hl2ss/tree/main/extensions/client_cpp/"
    click MATLAB "https://github.com/jdibenes/hl2ss/tree/main/extensions/client_matlab/"
    click LabVIEW "https://github.com/jdibenes/hl2ss/tree/main/extensions/client_labview/hl2ss_labview/"
    click Android "https://github.com/jdibenes/hl2ss/tree/main/extensions/client_android/hl2ss_ulm/"
    click UnityClient "https://github.com/jdibenes/hl2ss/tree/main/extensions/client_unity/"
    click UnrealClient "https://github.com/jdibenes/hl2ss/tree/main/extensions/client_unreal/"
    click TD "https://github.com/jdibenes/hl2ss/tree/main/hl2ss_td/"
    click Tools "https://github.com/jdibenes/hl2ss/tree/main/tools/"

    %% Styles
    classDef hardware fill:#ffe4e1,stroke:#d62728,color:#000
    classDef server fill:#e1eaff,stroke:#1f77b4,color:#000
    classDef network fill:#fff2cc,stroke:#ff7f0e,color:#000
    classDef client fill:#e2ffe2,stroke:#2ca02c,color:#000
    classDef ipc fill:#fce6c9,stroke:#9467bd,color:#000
```
