Compare commits

..
29 Commits
Author SHA1 Message Date
Patrick Nicolas b0c05813fe Prepare v26.11 release
Release APK Only / Android (Release) (push) Failing after 37m19s
Release APK Only / Android (Debug) (push) Failing after 37m22s
Release APK Only / Android (DebugWithValidationLayer) (push) Failing after 37m23s
Release APK Only / Create APK release (push) Skipped
Build / Linux (map[packages:extra-cmake-modules libarchive-dev libboost-all-dev libkf6coreaddons-dev libkf6qqc2desktopstyle-dev libkf6iconthemes-dev libkirigami-dev librsvg2-dev nlohmann-json3-dev qcoro-qt6-dev qml6-module-org-kde-kirigamiaddons-formcard prese… (push) Waiting to run
Build / Linux (map[packages:libboost-all-dev libsystemd-dev preset:server-tracing]) (push) Waiting to run
Build / Linux (map[packages:libboost-all-dev libsystemd-dev preset:server]) (push) Waiting to run
Build / Linux (map[packages:libboost-all-dev preset:server-no-systemd]) (push) Waiting to run
Build / Linux (map[packages:libboost-all-dev wireshark-dev preset:dissector-no-system-boost]) (push) Waiting to run
Build / Linux (map[packages:libharfbuzz-dev libfreetype-dev libavcodec-dev libavutil-dev libswscale-dev librsvg2-bin gettext libcurl4-openssl-dev libfontconfig-dev libpipewire-0.3-dev preset:client-no-system-boost]) (push) Waiting to run
Build / Linux (map[packages:libsystemd-dev preset:server-no-system-boost]) (push) Waiting to run
Build / Steam Frame (push) Waiting to run
Build / Create release (push) Blocked by required conditions
Build / Sync fork downstream (push) Blocked by required conditions
Build / Linux server (flatpak) (push) Skipped
Build / Test Nix package and devshell (push) Skipped
Build / Android (Debug) (push) Skipped
Build / Android (DebugWithValidationLayer) (push) Skipped
Build / Android (Oculus) (push) Skipped
Build / Android (Release) (push) Skipped
Build / Build Ubuntu package (plucky) (push) Skipped
Format / Formatting check (client) (push) Skipped
Format / Formatting check (common) (push) Skipped
Format / Formatting check (dashboard) (push) Skipped
Format / Formatting check (server) (push) Skipped
Format / Formatting check (tools/wireshark) (push) Skipped
Format / Python lint (ruff) (push) Skipped
Locales / Locale check (push) Skipped
2026-11-28 08:57:11 +01:00
Patrick Nicolas c8e74a3430 Fix secrets initialization 2026-11-28 08:47:30 +01:00
galister 0f020f2bb6 desktop file for linux client 2026-11-28 08:45:06 +01:00
guideahon b470b13dfc Clarify full WiVRn version strings 2026-11-27 13:51:57 +01:00
guideahon c5932f6ed9 Clarify WiVRn protocol compatibility 2026-11-27 13:51:57 +01:00
Sapphire 15b5ed07e1 Support Steam appinfo v42 (sharded) format 2026-11-27 02:58:57 -05:00
ZokuTe 2529e0bfa0 Update Simplified Chinese localization & Fix non-honorific pronouns for certain individuals. close #599 2026-11-24 09:38:54 +01:00
Patrick Nicolas dd472aee25 Workaround for source_group error
CMake Error at cmake-fetch/boost-src/libs/locale/CMakeLists.txt:236 (source_group):
  source_group
  "/home/runner/work/WiVRn/WiVRn/cmake-fetch/boost-src/libs/locale/include/boost/locale"
  is not a prefix of file
  "/home/runner/work/WiVRn/WiVRn/cmake-fetch/boost-src/libs/locale/include/boost/locale.hpp"
2026-11-23 15:25:22 +01:00
schlegp 04837ba215 Add Vulkan AV1 video encoder (#1087)
Experimental support, is never automatically selected.
2026-11-16 17:24:08 +01:00
TommiTheFirst 540d95ae7e Replaced custom bitcast with std::bit_cast 2026-11-16 15:57:57 +01:00
galister 47651c00e8 v4l2_decoder: 10-bit only if p010 capture supported 2026-11-16 21:30:12 +09:00
Patrick Nicolas 63700f05fa Fix buffer overflow when creating listen socket 2026-11-15 10:04:16 +01:00
Patrick Nicolas 4d782f7370 Set higher priorities for pipewire devices 2026-11-13 19:44:09 +01:00
Sapphire ea57db02f4 Add missing #pragma once to android USB header 2026-11-12 15:25:34 -05:00
Sapphire 7bb6f7c866 Allow changing log level on Android 2026-11-12 15:25:34 -05:00
Jonathan Steffan c26740b62d Merge pull request #1206 from damaestro/ci-ccache-fixes
ci: fix ccache effectiveness for Linux and Android builds
2026-11-11 21:40:33 -07:00
Sapphire e98e28fedc Change real panel size log to debug 2026-11-11 17:39:13 -05:00
Sapphire d3d15fab4c Make sure view is scaled for GUI render resolution display 2026-11-11 17:26:49 -05:00
Sapphire 6be331fbaa Fix Android battery change log condition 2026-11-11 16:23:54 -05:00
Sapphire 64ecbdc24b Move battery handling into dedicated monitor class 2026-11-11 16:23:54 -05:00
Sapphire 2233817b59 Forward controller battery info via XR_EXT_interaction_profile_battery_state_display 2026-11-11 16:23:54 -05:00
Sapphire aba0210923 Bind Frame bumper click to trigger as well for GUI interactions 2026-11-11 16:23:54 -05:00
Sapphire 86bbb80f90 Reorder some inputs and fix comments 2026-11-11 15:56:13 -05:00
Sapphire f4358ebe85 Reuse menu ID for view button, give left system click a distinct ID 2026-11-11 15:56:13 -05:00
Sapphire 4049f2125a Remove superfluous subpaths from Frame interaction profile patch 2026-11-11 15:56:13 -05:00
Sapphire 235eac73c2 Add missing hand interaction poses for Frame left/right bindings 2026-11-11 15:56:13 -05:00
Patrick Nicolas 1540df2e6b Add -fno-finite-math-only 2026-11-11 20:22:01 +01:00
Jonathan Steffan 70282d57fd ci: fix ccache effectiveness for Linux and Android builds
- Disable CMake module scanning, which made compilations uncacheable.
- Linux: trailing "." on cache key so one preset's key is not a prefix of
  another's.
- Android: add ccache (action, CCACHE_BASEDIR, gradle compiler launcher).
- Save cache on master only; evict files unused by the job.
2026-11-11 11:19:21 -07:00
Patrick Nicolas 7f9957ae79 Fix incorrect resolution show in stream settings 2026-11-11 12:00:26 +01:00
72 changed files with 2077 additions and 4454 deletions
+9 -9
View File
@@ -2,7 +2,7 @@ name: Release APK Only
on:
push:
branches: [ "apk-build" ]
branches: [ "master" ]
env:
BUILD_TYPE: RelWithDebInfo
@@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v6
with:
# Checkout from upstream instead of WiVRn-APK to ensure the GIT_DESC variable is set correctly
repository: 'Vindicus999/WiVRn'
repository: 'WiVRn/WiVRn'
ref: ${{ github.sha }}
fetch-depth: 0
@@ -102,13 +102,13 @@ jobs:
pattern: 'apk-*'
merge-multiple: true
# - name: Rename APK artifacts
# run: |
# cd apk
# for f in *.apk; do
# BASENAME=`echo ${f}|awk -F '-APK-' '{print $2}'`
# mv "${f}" "org.meumeu.wivrn-${BASENAME}"
# done
- name: Rename APK artifacts
run: |
cd apk
for f in *.apk; do
BASENAME=`echo ${f}|awk -F '-APK-' '{print $2}'`
mv "${f}" "org.meumeu.wivrn-${BASENAME}"
done
- name: Download APK debug artifacts
uses: actions/download-artifact@v8
+27 -6
View File
@@ -45,11 +45,14 @@ jobs:
packages: ccache libvulkan-dev glslang-tools spirv-tools libwayland-dev libxrandr-dev ${{matrix.config.packages}} ${{ startsWith(matrix.config.preset, 'server') && env.SERVER_DEPS || ''}}
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2.23
uses: hendrikmuhs/ccache-action@v1.2.24
with:
key: linux-${{matrix.config.preset}}
job-summary: ""
restore-keys: linux-
# The trailing "." keeps one preset's key from being a prefix of another's
key: linux-${{matrix.config.preset}}.
verbose: 1
job-summary: ''
evict-old-files: job
save: ${{ github.ref == 'refs/heads/master' }}
- uses: actions/cache@v5
with:
@@ -139,10 +142,14 @@ jobs:
packages: librsvg2-bin npm
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2.23
uses: hendrikmuhs/ccache-action@v1.2.24
with:
key: steam-frame
job-summary: ""
verbose: 1
job-summary: ''
evict-old-files: job
save: ${{ github.ref == 'refs/heads/master' }}
restore-keys: steam-frame
- uses: actions/cache@v5
with:
@@ -289,6 +296,16 @@ jobs:
${{github.workspace}}/cmake-fetch/*.tgz
restore-keys: cmake-android-
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2.24
with:
# The trailing "." keeps one build type's key from being a prefix of another's
key: android-${{matrix.buildtype}}.
verbose: 1
job-summary: ''
evict-old-files: job
save: ${{ github.ref == 'refs/heads/master' }}
# Gradle distribution and the Android plugin's dependencies.
- uses: actions/cache@v5
with:
@@ -330,6 +347,9 @@ jobs:
echo "$APK_KEYSTORE_BASE64" | base64 --decode --ignore-garbage > ks.keystore
- name: Build
env:
# Paths under the workspace are hashed relative to it
CCACHE_BASEDIR: ${{github.workspace}}
run: |
VERSION=$(git describe --tags --always | sed "s/^v\([0-9]\)/\1/")
if [ ${{ matrix.buildtype }} = 'Oculus' ]
@@ -367,6 +387,7 @@ jobs:
-Pwivrn_app_name="$APPNAME" \
-Pwivrn_compress_glb=ON \
-Pfetchcontent_base_dir=${{github.workspace}}/cmake-fetch \
-Pcompiler_launcher=ccache \
assemble${{ matrix.buildtype }}
- name: Upload build dir
-51
View File
@@ -1,51 +0,0 @@
name: Sync Fork with Upstream
env:
UPSTREAM_URL: "https://github.com/wivrn/wivrn.git"
WORKFLOW_TOKEN: ${{ secrets.DOWNSTREAM_GITHUB_TOKEN }}
UPSTREAM_BRANCH: "master"
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
upstream_repo: vindicus999/wivrn
fetch-depth: 0
token: ${{ env.WORKFLOW_TOKEN }}
- name: Add upstream
run: |
git remote add upstream ${{ env.UPSTREAM_URL }}
- name: Fetch all
run: |
git fetch origin
git fetch upstream
- name: Update sync branch
run: |
git config --global user.email "sneed@feedandse.edu"
git config --global user.name "Sneed Chuckinson"
git checkout -B sync upstream/master
git push origin sync --force
- name: Copy master -> apk-build
run: |
git checkout -B apk-build sync
git push origin apk-build --force
- name: Apply sneed changes
run: |
git merge origin/sneed --no-edit
- name: Push apk build
run: |
git push origin apk-build --force
+6
View File
@@ -1,6 +1,10 @@
cmake_minimum_required(VERSION 3.28)
project(WiVRn VERSION 0.0.0 LANGUAGES C CXX)
# Workaround for boost CMake error
function(source_group)
endfunction()
# Set default for FetchContent projects
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
@@ -8,6 +12,7 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(ANDROID)
@@ -342,6 +347,7 @@ foreach(TARGET_NAME wivrn wivrn-server wivrn-dashboard wivrn-common wivrn-dissec
target_compile_options(${TARGET_NAME} PRIVATE
-fdiagnostics-color -Wall -Wextra -pedantic
-ffast-math
-fno-finite-math-only
-Wundef
-Wno-missing-field-initializers
-Wno-unused-parameter
+2 -2
View File
@@ -62,7 +62,7 @@ Follow the wizard in the PC dashboard to install the client on your VR headset.
It should either lead you to the [Meta Store](https://www.meta.com/experiences/7959676140827574/) (for Meta Quest headsets) or to download the correct APK (for other headsets).
> [!WARNING]
> The VR client and PC server need to be on the same version of WiVRn
> The VR client and PC server must use the same WiVRn protocol. For development builds, compare the full version string, including the Git commit suffix (for example, `26.8-42-g1234afe`); the release prefix alone (for example, `26.8`) does not identify the build.
> [!TIP]
> If the headset fails to connect to the computer, see [troubleshooting](#troubleshooting).
@@ -150,7 +150,7 @@ If the server list is empty in the headset app:
<details><summary>My headset does not connect to my computer</summary>
- If you have a firewall, check that port 9757 (UDP and TCP) is open
- The server and client must be the same version.</details>
- If the app reports an incompatible server protocol, compare the full version shown in the headset app's About screen with the server's startup log. Package metadata may show only the release prefix. For development builds, use client and server built from the same source revision. If multiple builds are installed, make sure you start the intended server.</details>
<details><summary>How do I use a wired connection manually?</summary>
+4 -1
View File
@@ -117,6 +117,8 @@ android {
def compressGlb = project.hasProperty('wivrn_compress_glb') ? wivrn_compress_glb : 'OFF'
def fetchcontentBaseDir = project.hasProperty('fetchcontent_base_dir') ? ['-DFETCHCONTENT_BASE_DIR=' + fetchcontent_base_dir] : []
def compilerLauncher = project.hasProperty('compiler_launcher') ? ['-DCMAKE_C_COMPILER_LAUNCHER=' + compiler_launcher, '-DCMAKE_CXX_COMPILER_LAUNCHER=' + compiler_launcher] : []
def asan = use_asan ? 'ON': 'OFF'
def stl = use_asan ? 'c++_shared' : "c++_static"
@@ -146,7 +148,8 @@ android {
'-DWIVRN_COMPRESS_GLB=' + compressGlb,
'-DWIVRN_ADDRESS_SANITIZER=' + asan,
] +
fetchcontentBaseDir
fetchcontentBaseDir +
compilerLauncher
resValue "string", "app_name", project.hasProperty('wivrn_app_name') ? project.wivrn_app_name : "WiVRn Local"
abiFilters 'arm64-v8a'//, 'x86_64'
}
+9
View File
@@ -184,6 +184,8 @@ target_compile_definitions(wivrn PRIVATE IMGUI_DEFINE_MATH_OPERATORS)
target_include_directories(wivrn PRIVATE .)
if(NOT ANDROID)
configure_file(io.github.wivrn.wivrn-client.desktop.in io.github.wivrn.wivrn-client.desktop)
install(TARGETS wivrn)
endif()
@@ -351,4 +353,11 @@ if(NOT ANDROID)
set_target_properties(wivrn PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
install(DIRECTORY "${ASSETS_DIR}" DESTINATION ${CMAKE_INSTALL_DATADIR}/wivrn)
install(FILES ../images/wivrn.svg
DESTINATION share/icons/hicolor/scalable/apps
RENAME io.github.wivrn.wivrn-client.svg
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/io.github.wivrn.wivrn-client.desktop
DESTINATION share/applications
)
endif()
+21 -18
View File
@@ -2,6 +2,7 @@
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2024 Patrick Nicolas <patricknicolas@laposte.net>
* Copyright (C) 2026 Sapphire <imsapphire0@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,20 +20,19 @@
#include "battery.h"
#include "android/jnipp.h"
#include "application.h"
#include <mutex>
#include <spdlog/spdlog.h>
namespace
battery::battery(xr::instance & instance, xr::session & session, jobject activity) : battery(instance, session)
{
std::mutex last_status_lock;
battery_status last_status;
} // namespace
jni::object<""> act(activity);
auto app = act.call<jni::object<"android/app/Application">>("getApplication");
auto ctx = app.call<jni::object<"android/content/Context">>("getApplicationContext");
battery_status get_battery_status()
{
std::unique_lock _{last_status_lock};
return last_status;
auto bat_receiver = act.field<jni::object<"android/content/BroadcastReceiver">>("BatteryInfoReceiver");
ctx.call<jni::object<"android/content/Intent">>("registerReceiver", bat_receiver, jni::new_object<"android/content/IntentFilter">(jni::string{"android.intent.action.BATTERY_CHANGED"}));
}
extern "C" void Java_org_meumeu_wivrn_BroadcastReceiver_onReceive(JNIEnv * env, jobject instance, jobject ctxt_obj, jobject intent_obj)
@@ -51,16 +51,19 @@ extern "C" void Java_org_meumeu_wivrn_BroadcastReceiver_onReceive(JNIEnv * env,
auto scale_jint = intent.call<jni::Int>(get_int_extra, scale_jstr, default_jint);
auto plugged_jint = intent.call<jni::Int>(get_int_extra, plugged_jstr, default_jint);
{
std::unique_lock _{last_status_lock};
if (level_jint && level_jint.value >= 0 && scale_jint && scale_jint.value >= 0)
last_status.charge = (float)(level_jint.value) / (float)(scale_jint.value);
else
last_status.charge = std::nullopt;
std::optional<float> charge{};
if (level_jint && level_jint.value >= 0 && scale_jint && scale_jint.value >= 0)
charge = (float)(level_jint.value) / (float)(scale_jint.value);
last_status.charging = plugged_jint && plugged_jint.value > 0;
}
bool charging = plugged_jint && plugged_jint.value > 0;
if (level_jint and scale_jint and plugged_jint)
spdlog::debug("Received ACTION_BATTERY_CHANGED: level {}%, plugged {}", *last_status.charge * 100, last_status.charging);
if (charge)
spdlog::debug("Received ACTION_BATTERY_CHANGED: level {}%, plugged {}", *charge * 100, charging);
application::get_battery_monitor().on_status_update(
battery::device::head,
{
.charge = charge,
.charging = charging,
});
}
+38
View File
@@ -0,0 +1,38 @@
/*
* WiVRn VR streaming
* Copyright (C) 2023 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2023 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "property.h"
#include "utils/wrap_lambda.h"
#include <sys/system_properties.h>
std::optional<std::string> get_property(const char * property)
{
auto info = __system_property_find(property);
if (not info)
return std::nullopt;
std::string result;
wrap_lambda cb = [&result](const char * name, const char * value, uint32_t serial) {
result = value;
};
__system_property_read_callback(info, cb.userdata_first(), cb);
return result;
}
+25
View File
@@ -0,0 +1,25 @@
/*
* WiVRn VR streaming
* Copyright (C) 2023 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2023 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <optional>
#include <string>
std::optional<std::string> get_property(const char * property);
+2
View File
@@ -16,4 +16,6 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
bool usb_link_properties_changed();
+8
View File
@@ -1376,6 +1376,7 @@ void application::initialize()
XR_KHR_MAINTENANCE1_EXTENSION_NAME,
XR_KHR_VISIBILITY_MASK_EXTENSION_NAME,
XR_EXT_INTERACTION_PROFILE_BATTERY_STATE_DISPLAY_EXTENSION_NAME,
XR_EXT_EYE_GAZE_INTERACTION_EXTENSION_NAME,
XR_EXT_HAND_INTERACTION_EXTENSION_NAME,
XR_EXT_HAND_TRACKING_EXTENSION_NAME,
@@ -1500,6 +1501,12 @@ void application::initialize()
spaces[size_t(xr::spaces::view)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_VIEW);
spaces[size_t(xr::spaces::world)] = xr_session.create_reference_space(XR_REFERENCE_SPACE_TYPE_STAGE);
#ifdef __ANDROID__
battery_monitor.emplace(xr_instance, xr_session, app_info.native_app->activity->clazz);
#else
battery_monitor.emplace(xr_instance, xr_session);
#endif
config.emplace(xr_system_id, xr_session, application::get_config_path() / "client.json");
default_config.emplace(xr_system_id, xr_session);
@@ -1796,6 +1803,7 @@ application::~application()
void application::loop()
{
poll_events();
battery_monitor->poll_batteries();
auto scene = current_scene();
if (not is_session_running())
+8
View File
@@ -19,6 +19,7 @@
#pragma once
#include "battery.h"
#ifdef __ANDROID__
#include "android/hid.h"
#include <android_native_app_glue.h>
@@ -148,6 +149,7 @@ private:
std::filesystem::path cache_path;
std::shared_ptr<wifi_lock> wifi;
std::optional<battery> battery_monitor;
std::mutex server_intent_mutex;
std::optional<wivrn_discover::service> server_intent;
@@ -316,6 +318,12 @@ public:
return *instance().wifi;
}
static battery & get_battery_monitor()
{
assert(instance().battery_monitor);
return *instance().battery_monitor;
}
#ifdef __ANDROID__
void set_usb_networking(bool enabled);
#endif
+108
View File
@@ -0,0 +1,108 @@
/*
* WiVRn VR streaming
* Copyright (C) 2026 Sapphire <imsapphire0@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "battery.h"
#include "application.h"
#include "scene.h"
#include <chrono>
#include <magic_enum.hpp>
#include <spdlog/spdlog.h>
battery::battery(xr::instance & instance, xr::session & session) :
session(session)
{
if (instance.has_extension(XR_EXT_INTERACTION_PROFILE_BATTERY_STATE_DISPLAY_EXTENSION_NAME))
{
top_level_paths.emplace({
std::make_pair(instance.string_to_path("/user/hand/left"), device::left_controller),
std::make_pair(instance.string_to_path("/user/hand/right"), device::right_controller),
std::make_pair(instance.string_to_path("/user/gamepad"), device::gamepad),
});
}
}
void battery::poll_batteries()
{
using namespace std::chrono_literals;
auto now = std::chrono::steady_clock::now();
if (now - last_poll < 10s)
return;
last_poll = now;
spdlog::debug("Polling batteries");
std::lock_guard lock(m);
#ifndef __ANDROID__
{
battery_status status = get_hmd_battery();
if (status != statuses.at(device::head))
{
on_status_update(device::head, std::move(status));
}
}
#endif
if (top_level_paths)
{
for (auto [path, device]: *top_level_paths)
{
XrBatteryStateDisplayEXT battery_state{
.type = XR_TYPE_BATTERY_STATE_DISPLAY_EXT,
};
XrInteractionProfileState profile_state{
.type = XR_TYPE_INTERACTION_PROFILE_STATE,
.next = &battery_state,
};
try
{
CHECK_XR(xrGetCurrentInteractionProfile(session, path, &profile_state));
}
catch (std::exception & e)
{
spdlog::warn("Failed to get battery charge state for device {}: {}", magic_enum::enum_name(device), e.what());
continue;
}
std::optional<float> charge{};
if (battery_state.stateFlags & XR_BATTERY_STATE_DISPLAY_STATE_VALID_BIT_EXT)
charge = battery_state.batteryLevel;
battery_status status{
.charge = charge,
.charging = (battery_state.stateFlags & XR_BATTERY_STATE_DISPLAY_STATE_CHARGING_BIT_EXT) != 0,
};
if (status != statuses.at(device))
{
on_status_update(device, std::move(status));
}
}
}
}
void battery::on_status_update(battery::device device, battery::battery_status && new_status)
{
std::lock_guard lock(m);
if (std::shared_ptr<scene> s = application::instance().current_scene())
{
s->on_battery_update(device, new_status);
}
statuses.at(device) = std::move(new_status);
}
+62 -5
View File
@@ -2,6 +2,7 @@
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2024 Patrick Nicolas <patricknicolas@laposte.net>
* Copyright (C) 2026 Sapphire <imsapphire0@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,12 +20,68 @@
#pragma once
#include "xr/instance.h"
#include "xr/session.h"
#ifdef __ANDROID__
#include "jni.h"
#endif
#include <chrono>
#include <inplace_vector.hpp>
#include <magic_enum_containers.hpp>
#include <mutex>
#include <optional>
struct battery_status
class battery
{
std::optional<float> charge = std::nullopt;
bool charging = false;
};
public:
enum device : uint8_t
{
head = 0,
left_controller,
right_controller,
gamepad,
};
battery_status get_battery_status();
struct battery_status
{
std::optional<float> charge = std::nullopt;
bool charging = false;
bool operator!=(const battery_status & other) const
{
return charge != other.charge || charging != other.charging;
}
};
battery(xr::instance & instance, xr::session & session);
#ifdef __ANDROID__
battery(xr::instance & instance, xr::session & session, jobject activity);
#endif
private:
xr::session & session;
std::optional<beman::inplace_vector::inplace_vector<std::pair<XrPath, device>, 3>> top_level_paths;
std::recursive_mutex m;
magic_enum::containers::array<device, battery_status> statuses;
// we need to poll for controller batteries, there's no XR event sent when their state changes
// linux implementation also doesn't have an event-based API for battery
std::chrono::steady_clock::time_point last_poll{};
#ifndef __ANDROID__
battery_status get_hmd_battery();
#endif
public:
void poll_batteries();
// updates statuses and sends the new battery status to the focused scene
void on_status_update(device device, battery_status && new_status);
inline battery_status get_battery_status(device device)
{
std::lock_guard lock(m);
return statuses.at(device);
};
};
+44 -1
View File
@@ -102,6 +102,20 @@ bool supports_format(int fd, v4l2_buf_type type, uint32_t pixel_format)
}
}
bool supports_p010_capture(int fd)
{
if (!supports_format(fd, capture_type, V4L2_PIX_FMT_P010))
return false;
v4l2_format fmt{.type = capture_type};
if (xioctl(fd, VIDIOC_G_FMT, &fmt) < 0)
return false;
fmt.fmt.pix_mp.pixelformat = V4L2_PIX_FMT_P010;
return xioctl(fd, VIDIOC_TRY_FMT, &fmt) == 0 &&
fmt.fmt.pix_mp.pixelformat == V4L2_PIX_FMT_P010 &&
fmt.fmt.pix_mp.num_planes == 1;
}
wivrn::fd_base find_device(wivrn::video_codec codec)
{
const uint32_t pixel_format = v4l2_codec(codec);
@@ -594,6 +608,18 @@ void decoder::setup_capture_queue()
fmt.type = capture_type;
ioctl_or_throw(fd.get_fd(), VIDIOC_G_FMT, &fmt, "VIDIOC_G_FMT(CAPTURE)");
const uint32_t current = fmt.fmt.pix_mp.pixelformat;
const bool ten_bit = current == V4L2_PIX_FMT_P010 || current == V4L2_PIX_FMT_QC10C;
const uint32_t wanted = ten_bit && supports_p010_capture(fd.get_fd()) ? V4L2_PIX_FMT_P010 : V4L2_PIX_FMT_NV12;
if (current != wanted)
{
fmt.fmt.pix_mp.pixelformat = wanted;
fmt.fmt.pix_mp.plane_fmt[0] = {};
ioctl_or_throw(fd.get_fd(), VIDIOC_S_FMT, &fmt, "VIDIOC_S_FMT(CAPTURE)");
if (fmt.fmt.pix_mp.pixelformat != wanted)
throw std::runtime_error("iris rejected requested NV12/P010 CAPTURE format");
}
capture_width = fmt.fmt.pix_mp.width;
capture_height = fmt.fmt.pix_mp.height;
capture_pixelformat = fmt.fmt.pix_mp.pixelformat;
@@ -1033,7 +1059,24 @@ bool decoder::supports_10bit(wivrn::video_codec codec)
try
{
auto device = find_device(codec);
return supports_format(device.get_fd(), capture_type, V4L2_PIX_FMT_P010);
v4l2_format fmt{
.type = output_type,
.fmt = {
.pix_mp = {
.width = 640,
.height = 640,
.pixelformat = v4l2_codec(codec),
.field = V4L2_FIELD_NONE,
.plane_fmt = {{
.sizeimage = 4 * 1024 * 1024,
}},
.num_planes = 1,
}},
};
if (xioctl(device.get_fd(), VIDIOC_S_FMT, &fmt) < 0 ||
fmt.fmt.pix_mp.pixelformat != v4l2_codec(codec))
return false;
return supports_p010_capture(device.get_fd());
}
catch (...)
{
+5 -108
View File
@@ -19,8 +19,8 @@
#include "hmd_traits.h"
#include "utils/env.h"
#include "utils/overloaded.h"
#include "utils/strings.h"
#include "xr/to_string.h"
#include <boost/pfr.hpp>
@@ -41,114 +41,11 @@
#include <openxr/openxr.h>
#ifdef __ANDROID__
#include "utils/wrap_lambda.h"
#include <sys/system_properties.h>
static std::optional<std::string> get_property(const char * property)
{
auto info = __system_property_find(property);
if (not info)
return std::nullopt;
std::string result;
wrap_lambda cb = [&result](const char * name, const char * value, uint32_t serial) {
result = value;
};
__system_property_read_callback(info, cb.userdata_first(), cb);
return result;
}
#include "android/property.h"
#include "utils/env.h"
#include "utils/strings.h"
#endif
template <typename T>
std::optional<T> env(std::string_view name);
template <>
std::optional<std::string> env(std::string_view name)
{
#ifdef __ANDROID__
auto android_sysprop_name = std::format("debug.wivrn.{}", name);
return get_property(android_sysprop_name.c_str());
#else
std::string env_name = "WIVRN_";
env_name.reserve(env_name.size() + name.size());
for (const auto & c: name)
env_name += std::toupper(c);
const char * value = std::getenv(env_name.c_str());
if (value)
return value;
return std::nullopt;
#endif
}
template <>
std::optional<uint32_t> env(std::string_view name)
{
const auto value = env<std::string>(name);
if (not value)
return std::nullopt;
try
{
const unsigned long parsed = std::stoul(*value);
if (parsed > std::numeric_limits<uint32_t>::max())
return std::nullopt;
return static_cast<uint32_t>(parsed);
}
catch (std::runtime_error & e)
{
spdlog::warn("failed to parse {} (value: {}: {}", name, *value, e.what());
return std::nullopt;
}
}
template <>
std::optional<bool> env(std::string_view name)
{
const auto value = env<std::string>(name);
if (not value)
return std::nullopt;
if (strcmp(value->c_str(), "1") == 0 || strcasecmp(value->c_str(), "true") == 0 || strcasecmp(value->c_str(), "yes") == 0 || strcasecmp(value->c_str(), "on") == 0)
return true;
if (strcmp(value->c_str(), "0") == 0 || strcasecmp(value->c_str(), "false") == 0 || strcasecmp(value->c_str(), "no") == 0 || strcasecmp(value->c_str(), "off") == 0)
return false;
return std::nullopt;
}
template <>
std::optional<std::unordered_map<std::string, std::string>> env(std::string_view name)
{
const auto values = env<std::string>(name);
if (not values)
return std::nullopt;
std::unordered_map<std::string, std::string> map;
for (auto value: utils::split(*values, ","))
{
if (auto pos = value.find('='); pos != std::string::npos)
map.insert(std::make_pair(value.substr(0, pos), value.substr(pos + 1)));
}
return map;
}
template <>
std::optional<std::unordered_set<std::string>> env(std::string_view name)
{
const auto values = env<std::string>(name);
if (not values)
return std::nullopt;
#if defined(__cpp_lib_containers_ranges) && __cpp_lib_containers_ranges >= 202202L
return std::unordered_set<std::string>{std::from_range, utils::split(*values, ",")};
#else
std::optional<std::unordered_set<std::string>> res{std::in_place};
for (auto & val: utils::split(*values))
res->insert(std::move(val));
return res;
#endif
}
void hmd_traits::init()
{
#ifndef NDEBUG
@@ -444,7 +341,7 @@ static XrViewConfigurationView scale_view(XrViewConfigurationView view, uint32_t
double ratio = double(width) / view.recommendedImageRectWidth;
view.recommendedImageRectWidth = width;
view.recommendedImageRectHeight *= ratio;
spdlog::info("Using panel size: {}x{}", view.recommendedImageRectWidth, view.recommendedImageRectHeight);
spdlog::debug("Using panel size: {}x{}", view.recommendedImageRectWidth, view.recommendedImageRectHeight);
return view;
}
@@ -0,0 +1,9 @@
[Desktop Entry]
Name=WiVRn
Comment=Play your PC VR games on a standalone headset
GenericName=WiVRn client
Exec=@CMAKE_INSTALL_PREFIX@/bin/wivrn
Icon=io.github.wivrn.wivrn-client
Type=Application
Categories=Network;
Keywords=VR;Virtual reality;OpenVR;OpenXR;
+2 -4
View File
@@ -16,7 +16,7 @@ public class MainActivity extends android.app.NativeActivity
@Override
public native void onActivityResult(int requestCode, int resultCode, android.content.Intent data);
private android.content.BroadcastReceiver BatteryInfoReceiver = null;
public android.content.BroadcastReceiver BatteryInfoReceiver = null;
public android.net.ConnectivityManager.NetworkCallback netcb = null;
@Override
@@ -24,9 +24,7 @@ public class MainActivity extends android.app.NativeActivity
{
super.onCreate(savedInstanceState);
this.BatteryInfoReceiver = new BroadcastReceiver();
this.BatteryInfoReceiver = new org.meumeu.wivrn.BroadcastReceiver();
this.netcb = new org.meumeu.wivrn.NetworkInfoCallback();
this.registerReceiver(this.BatteryInfoReceiver, new android.content.IntentFilter(android.content.Intent.ACTION_BATTERY_CHANGED));
}
}
+3 -21
View File
@@ -25,10 +25,6 @@
namespace
{
std::mutex last_status_lock;
battery_status last_status;
std::chrono::steady_clock::time_point last_read;
std::optional<std::string> read_line(const std::filesystem::path & path)
{
std::ifstream file(path);
@@ -37,7 +33,6 @@ std::optional<std::string> read_line(const std::filesystem::path & path)
return line;
return std::nullopt;
}
std::optional<float> read_percent(const std::filesystem::path & path)
{
std::ifstream file(path);
@@ -47,7 +42,7 @@ std::optional<float> read_percent(const std::filesystem::path & path)
return std::nullopt;
}
battery_status read_battery_status(const std::filesystem::path & percent_path, const std::filesystem::path & status_path)
battery::battery_status read_battery_status(const std::filesystem::path & percent_path, const std::filesystem::path & status_path)
{
auto charge = read_percent(percent_path);
if (not charge)
@@ -58,8 +53,9 @@ battery_status read_battery_status(const std::filesystem::path & percent_path, c
.charging = status == "Charging" or status == "Full",
};
}
} // namespace
battery_status read_battery_status()
battery::battery_status battery::get_hmd_battery()
{
// SteamOS on the Steam Frame: the charger daemon's percentage is what the system UI shows
const std::filesystem::path deckard = "/run/deckardcharger";
@@ -78,17 +74,3 @@ battery_status read_battery_status()
return {};
}
} // namespace
battery_status get_battery_status()
{
// The lobby asks every frame, the files only change every few seconds
std::unique_lock _{last_status_lock};
auto now = std::chrono::steady_clock::now();
if (now - last_read > std::chrono::seconds(5))
{
last_status = read_battery_status();
last_read = now;
}
return last_status;
}
+25 -21
View File
@@ -20,10 +20,13 @@
#include "application.h"
#include "scenes/lobby.h"
#include "spdlog/spdlog.h"
#include "utils/env.h"
#include "version.h"
#include <algorithm>
#include <arpa/inet.h>
#include <netdb.h>
#include <string>
#include <sys/socket.h>
#include <sys/types.h>
@@ -41,6 +44,28 @@ void real_main(android_app * native_app)
void real_main(int argc, char ** argv)
#endif
{
auto log_level = env<std::string>("loglevel");
if (log_level)
{
std::transform(log_level->begin(), log_level->end(), log_level->begin(), [](char c) { return tolower(c); });
if (log_level == "trace")
spdlog::set_level(spdlog::level::trace);
else if (log_level == "debug")
spdlog::set_level(spdlog::level::debug);
else if (log_level == "info")
spdlog::set_level(spdlog::level::info);
else if (log_level == "warning")
spdlog::set_level(spdlog::level::warn);
else if (log_level == "error")
spdlog::set_level(spdlog::level::err);
else if (log_level == "critical")
spdlog::set_level(spdlog::level::critical);
else if (log_level == "off")
spdlog::set_level(spdlog::level::off);
else
spdlog::warn("Invalid value for log level: {}", *log_level);
}
if (wivrn::is_tag)
spdlog::info("Starting WiVRn version {}", wivrn::display_version());
else
@@ -107,27 +132,6 @@ int main(int argc, char * argv[])
{
spdlog::set_default_logger(spdlog::stdout_color_mt("WiVRn"));
char * loglevel = getenv("WIVRN_LOGLEVEL");
if (loglevel)
{
if (!strcasecmp(loglevel, "trace"))
spdlog::set_level(spdlog::level::trace);
else if (!strcasecmp(loglevel, "debug"))
spdlog::set_level(spdlog::level::debug);
else if (!strcasecmp(loglevel, "info"))
spdlog::set_level(spdlog::level::info);
else if (!strcasecmp(loglevel, "warning"))
spdlog::set_level(spdlog::level::warn);
else if (!strcasecmp(loglevel, "error"))
spdlog::set_level(spdlog::level::err);
else if (!strcasecmp(loglevel, "critical"))
spdlog::set_level(spdlog::level::critical);
else if (!strcasecmp(loglevel, "off"))
spdlog::set_level(spdlog::level::off);
else
spdlog::warn("Invalid value for WIVRN_LOGLEVEL environment variable");
}
real_main(argc, argv);
}
#endif
+1
View File
@@ -584,6 +584,7 @@ void scene::remove(entt::entity entity)
void scene::on_unfocused() {}
void scene::on_focused() {}
void scene::on_xr_event(const xr::event &) {}
void scene::on_battery_update(battery::device, const battery::battery_status &) {}
bool scene::on_input_key_down(uint8_t key_code)
{
+2
View File
@@ -19,6 +19,7 @@
#pragma once
#include "battery.h"
#include "render/image_loader.h"
#include "render/scene_loader.h"
#include "render/scene_renderer.h"
@@ -209,6 +210,7 @@ public:
void set_focused(bool status);
virtual void render(const XrFrameState &) = 0;
virtual void on_xr_event(const xr::event &);
virtual void on_battery_update(battery::device device, const battery::battery_status &);
virtual bool on_input_key_down(uint8_t key_code);
virtual bool on_input_key_up(uint8_t key_code);
+2 -1
View File
@@ -19,6 +19,7 @@
#include "gui_common.h"
#include "application.h"
#include "battery.h"
#include "render/ui_theme.h"
#include "render/ui_widgets.h"
@@ -37,7 +38,7 @@ float toggle_width()
std::optional<battery_indicator> battery_status_indicator(XrTime now)
{
const auto battery = get_battery_status();
const auto battery = application::get_battery_monitor().get_battery_status(battery::device::head);
if (not battery.charge)
return std::nullopt;
+5 -2
View File
@@ -267,8 +267,11 @@ void settings_video(const settings_context & ctx)
}
{
const auto width = ctx.recommended_width;
const auto height = ctx.recommended_height;
auto view = ctx.system.stereo_view();
view = application::get_hmd_traits().override_view(view);
const auto width = view.recommendedImageRectWidth;
const auto height = view.recommendedImageRectHeight;
list.push_back({
.id = "##resolution",
.label = _("Render resolution"),
-5
View File
@@ -19,7 +19,6 @@
#pragma once
#include <cstdint>
#include <functional>
#include <optional>
@@ -46,10 +45,6 @@ struct settings_context
xr::system & system;
imgui_context & imgui_ctx;
// recommended per-eye render resolution, for the resolution description
uint32_t recommended_width = 0;
uint32_t recommended_height = 0;
// streaming: connection-time settings are disabled, in-stream controls appear
bool in_game = false;
+18 -9
View File
@@ -144,6 +144,10 @@ void scenes::lobby::move_gui(glm::vec3 head_position, glm::vec3 new_gui_position
scenes::lobby::lobby() :
scene_impl<lobby>(supported_color_formats, supported_depth_formats)
{
const auto & view = system.stereo_view();
width = view.recommendedImageRectWidth;
height = view.recommendedImageRectHeight;
spdlog::info("Using formats {} and {}", vk::to_string(swapchain_format), vk::to_string(depth_format));
if (composition_layer_depth_test_supported)
@@ -1140,15 +1144,6 @@ void scenes::lobby::on_focused()
{
recenter_gui = true;
auto views = system.view_configuration_views(viewconfig);
assert(views.size() == 2); // FIXME
stream_view = application::get_hmd_traits().override_view(views[0]);
width = views[0].recommendedImageRectWidth;
height = views[0].recommendedImageRectHeight;
// assert(std::ranges::all_of(views, [width](const XrViewConfigurationView & view) { return view.recommendedImageRectWidth == width; }));
// assert(std::ranges::all_of(views, [height](const XrViewConfigurationView & view) { return view.recommendedImageRectHeight == height; }));
auto & config = application::get_config();
try
@@ -1416,6 +1411,11 @@ void scenes::lobby::on_xr_event(const xr::event & event)
if (next_scene)
next_scene->on_xr_event(event);
}
void scenes::lobby::on_battery_update(battery::device device, const battery::battery_status & battery)
{
if (next_scene)
next_scene->on_battery_update(device, battery);
}
scene::meta & scenes::lobby::get_meta_scene()
{
@@ -1467,6 +1467,15 @@ scene::meta & scenes::lobby::get_meta_scene()
{"recenter_right", "/user/hand/right/input/squeeze/value"},
},
},
suggested_binding{
{
"/interaction_profiles/valve/frame_controller_valve",
},
{
{"left_trigger", "/user/hand/left/input/bumper/click"},
{"right_trigger", "/user/hand/right/input/bumper/click"},
},
},
suggested_binding{
{
"/interaction_profiles/khr/simple_controller",
+1 -1
View File
@@ -95,7 +95,6 @@ class lobby : public scene_impl<lobby>
uint32_t width;
uint32_t height;
XrViewConfigurationView stream_view;
#if WIVRN_CLIENT_DEBUG_MENU
// GUI debug
@@ -271,6 +270,7 @@ public:
void on_unfocused() override;
void on_focused() override;
void on_xr_event(const xr::event &) override;
void on_battery_update(battery::device device, const battery::battery_status &) override;
static meta & get_meta_scene();
};
+9 -11
View File
@@ -26,7 +26,7 @@
namespace
{
wivrn::gui::settings_context lobby_settings_context(xr::instance & instance, xr::session & session, xr::system & system, imgui_context & imgui_ctx, const XrViewConfigurationView & stream_view, std::optional<bool> server_hid_forwarding)
wivrn::gui::settings_context lobby_settings_context(xr::instance & instance, xr::session & session, xr::system & system, imgui_context & imgui_ctx, std::optional<bool> server_hid_forwarding)
{
return {
.config = application::get_config(),
@@ -35,8 +35,6 @@ wivrn::gui::settings_context lobby_settings_context(xr::instance & instance, xr:
.session = session,
.system = system,
.imgui_ctx = imgui_ctx,
.recommended_width = stream_view.recommendedImageRectWidth,
.recommended_height = stream_view.recommendedImageRectHeight,
.in_game = false,
.server_hid_forwarding = server_hid_forwarding,
};
@@ -45,40 +43,40 @@ wivrn::gui::settings_context lobby_settings_context(xr::instance & instance, xr:
void scenes::lobby::gui_video()
{
wivrn::gui::settings_video(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
wivrn::gui::settings_video(lobby_settings_context(instance, session, system, *imgui_ctx, server_hid_forwarding));
}
void scenes::lobby::gui_streaming()
{
wivrn::gui::settings_streaming(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
wivrn::gui::settings_streaming(lobby_settings_context(instance, session, system, *imgui_ctx, server_hid_forwarding));
}
void scenes::lobby::gui_post_processing()
{
wivrn::gui::settings_post_processing(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
wivrn::gui::settings_post_processing(lobby_settings_context(instance, session, system, *imgui_ctx, server_hid_forwarding));
}
void scenes::lobby::gui_audio()
{
wivrn::gui::settings_audio(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
wivrn::gui::settings_audio(lobby_settings_context(instance, session, system, *imgui_ctx, server_hid_forwarding));
}
void scenes::lobby::gui_devices()
{
wivrn::gui::settings_devices(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
wivrn::gui::settings_devices(lobby_settings_context(instance, session, system, *imgui_ctx, server_hid_forwarding));
}
void scenes::lobby::gui_tracking()
{
wivrn::gui::settings_tracking(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
wivrn::gui::settings_tracking(lobby_settings_context(instance, session, system, *imgui_ctx, server_hid_forwarding));
}
void scenes::lobby::gui_system()
{
wivrn::gui::settings_system(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
wivrn::gui::settings_system(lobby_settings_context(instance, session, system, *imgui_ctx, server_hid_forwarding));
}
void scenes::lobby::gui_theme()
{
wivrn::gui::settings_theme(lobby_settings_context(instance, session, system, *imgui_ctx, stream_view, server_hid_forwarding));
wivrn::gui::settings_theme(lobby_settings_context(instance, session, system, *imgui_ctx, server_hid_forwarding));
}
+47 -11
View File
@@ -59,20 +59,21 @@ using namespace beman::inplace_vector;
static const std::unordered_map<std::string, device_id> device_ids = {
{"/user/hand/left/input/dpad_up/click", device_id::DPAD_UP_CLICK},
{"/user/hand/left/input/dpad_up/touch", device_id::DPAD_UP_TOUCH},
{"/user/hand/left/input/dpad_down/click", device_id::LEFT_X_CLICK},
{"/user/hand/left/input/dpad_down/touch", device_id::LEFT_X_TOUCH},
{"/user/hand/left/input/dpad_left/click", device_id::DPAD_LEFT_CLICK},
{"/user/hand/left/input/dpad_left/touch", device_id::DPAD_LEFT_TOUCH},
{"/user/hand/left/input/dpad_down/click", device_id::LEFT_X_CLICK},
{"/user/hand/left/input/dpad_down/touch", device_id::LEFT_X_TOUCH},
{"/user/hand/left/input/dpad_right/click", device_id::LEFT_Y_CLICK},
{"/user/hand/left/input/dpad_right/touch", device_id::LEFT_Y_TOUCH},
{"/user/hand/left/input/x/click", device_id::LEFT_X_CLICK},
{"/user/hand/left/input/x/touch", device_id::LEFT_X_TOUCH},
{"/user/hand/left/input/y/click", device_id::LEFT_Y_CLICK},
{"/user/hand/left/input/y/touch", device_id::LEFT_Y_TOUCH},
{"/user/hand/left/input/view/click", device_id::VIEW_CLICK},
{"/user/hand/left/input/view/touch", device_id::VIEW_TOUCH},
{"/user/hand/left/input/view/click", device_id::LEFT_MENU_CLICK},
{"/user/hand/left/input/view/touch", device_id::LEFT_MENU_TOUCH},
{"/user/hand/left/input/menu/click", device_id::LEFT_MENU_CLICK},
{"/user/hand/left/input/system/click", device_id::LEFT_MENU_CLICK},
{"/user/hand/left/input/menu/touch", device_id::LEFT_MENU_TOUCH},
{"/user/hand/left/input/system/click", device_id::LEFT_SYSTEM_CLICK},
{"/user/hand/left/input/system/touch", device_id::LEFT_SYSTEM_TOUCH},
{"/user/hand/left/input/bumper/click", device_id::LEFT_BUMPER_CLICK},
{"/user/hand/left/input/bumper/touch", device_id::LEFT_BUMPER_TOUCH},
@@ -115,10 +116,10 @@ static const std::unordered_map<std::string, device_id> device_ids = {
{"/user/hand/right/input/x/touch", device_id::RIGHT_X_TOUCH},
{"/user/hand/right/input/y/click", device_id::RIGHT_Y_CLICK},
{"/user/hand/right/input/y/touch", device_id::RIGHT_Y_TOUCH},
{"/user/hand/right/input/system/click", device_id::RIGHT_SYSTEM_CLICK},
{"/user/hand/right/input/system/touch", device_id::RIGHT_SYSTEM_TOUCH},
{"/user/hand/right/input/menu/click", device_id::RIGHT_MENU_CLICK},
{"/user/hand/right/input/menu/touch", device_id::RIGHT_MENU_TOUCH},
{"/user/hand/right/input/system/click", device_id::RIGHT_SYSTEM_CLICK},
{"/user/hand/right/input/system/touch", device_id::RIGHT_SYSTEM_TOUCH},
{"/user/hand/right/input/bumper/click", device_id::RIGHT_BUMPER_CLICK},
{"/user/hand/right/input/bumper/touch", device_id::RIGHT_BUMPER_TOUCH},
{"/user/hand/right/input/squeeze/click", device_id::RIGHT_SQUEEZE_CLICK},
@@ -205,9 +206,9 @@ scenes::stream::stream(std::string server_name, scene & parent_scene) :
apps{*this, std::move(server_name)},
foveation_center{instance, system, session, device, commandpool, queue, swapchain_format}
{
auto views = system.view_configuration_views(viewconfig);
width = views[0].recommendedImageRectWidth;
height = views[0].recommendedImageRectHeight;
const auto & view = system.stereo_view();
width = view.recommendedImageRectWidth;
height = view.recommendedImageRectHeight;
}
static from_headset::visibility_mask_changed::masks get_visibility_mask(xr::instance & inst, xr::session & session, int view)
@@ -253,7 +254,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
const auto & config = application::get_config();
{
auto view = self->system.view_configuration_views(self->viewconfig)[0];
auto view = self->system.stereo_view();
view = application::get_hmd_traits().override_view(view);
info.render_eye_width = view.recommendedImageRectWidth * config.resolution_scale;
@@ -285,6 +286,7 @@ std::shared_ptr<scenes::stream> scenes::stream::create(std::unique_ptr<wivrn_ses
info.settings.mirror_gamepad = config.forward_gamepad;
info.settings.enabled_body_parts = config.body_part_mask;
info.battery_status = self->instance.has_extension(XR_EXT_INTERACTION_PROFILE_BATTERY_STATE_DISPLAY_EXTENSION_NAME);
info.hand_tracking = config.check_feature(feature::hand_tracking);
info.eye_gaze = config.check_feature(feature::eye_gaze);
@@ -1303,6 +1305,12 @@ void scenes::stream::setup(const to_headset::video_stream_description & descript
spdlog::info("setup, refresh rate {}", description.refresh_rate);
session.set_refresh_rate(description.refresh_rate);
battery & battery_monitor = application::get_battery_monitor();
for (auto device: magic_enum::enum_values<battery::device>())
{
on_battery_update(device, battery_monitor.get_battery_status(device));
}
std::unique_lock lock(decoder_mutex);
if (video_stream_description == description)
return;
@@ -1458,6 +1466,9 @@ scene::meta & scenes::stream::get_meta_scene()
"/interaction_profiles/valve/frame_controller_valve",
},
{
{"left_trigger", "/user/hand/left/input/bumper/click"},
{"right_trigger", "/user/hand/right/input/bumper/click"},
{"gamepad_mode_1", "/user/hand/left/input/squeeze/click"},
{"gamepad_mode_2", "/user/hand/right/input/squeeze/click"},
},
@@ -1531,6 +1542,31 @@ void scenes::stream::on_xr_event(const xr::event & event)
}
}
void scenes::stream::on_battery_update(battery::device device, const battery::battery_status & battery)
{
device_id id = [&] {
switch (device)
{
case battery::device::head:
return device_id::HEAD;
case battery::device::left_controller:
return device_id::LEFT_CONTROLLER;
case battery::device::right_controller:
return device_id::RIGHT_CONTROLLER;
case battery::device::gamepad:
return device_id::GAMEPAD;
default:
assert(false);
__builtin_unreachable();
}
}();
network_session->send_control(from_headset::battery{
.device = id,
.charge = battery.charge,
.charging = battery.charging,
});
}
bool scenes::stream::forward_hid_input(from_headset::hid::input_t packet, bool device_enabled)
{
// hid_forwarding is whether the server permits it; device_enabled is the headset toggle.
+1
View File
@@ -248,6 +248,7 @@ public:
void on_focused() override;
void on_unfocused() override;
void on_xr_event(const xr::event &) override;
void on_battery_update(battery::device device, const battery::battery_status &) override;
bool on_input_key_down(uint8_t key_code) override;
bool on_input_key_up(uint8_t key_code) override;
+3 -3
View File
@@ -33,7 +33,7 @@ std::optional<device_id> frame_gamepad_input(device_id id)
{
switch (id)
{
case device_id::VIEW_CLICK:
case device_id::LEFT_MENU_CLICK:
return device_id::GAMEPAD_VIEW_CLICK;
case device_id::RIGHT_MENU_CLICK:
return device_id::GAMEPAD_MENU_CLICK;
@@ -47,10 +47,10 @@ std::optional<device_id> frame_gamepad_input(device_id id)
return device_id::GAMEPAD_Y_CLICK;
case device_id::DPAD_UP_CLICK:
return device_id::GAMEPAD_DPAD_UP_CLICK;
case device_id::LEFT_X_CLICK:
return device_id::GAMEPAD_DPAD_DOWN_CLICK;
case device_id::DPAD_LEFT_CLICK:
return device_id::GAMEPAD_DPAD_LEFT_CLICK;
case device_id::LEFT_X_CLICK:
return device_id::GAMEPAD_DPAD_DOWN_CLICK;
case device_id::LEFT_Y_CLICK:
return device_id::GAMEPAD_DPAD_RIGHT_CLICK;
case device_id::LEFT_BUMPER_CLICK:
-2
View File
@@ -407,8 +407,6 @@ void scenes::stream::gui_settings(float)
.session = session,
.system = system,
.imgui_ctx = *imgui_ctx,
.recommended_width = width,
.recommended_height = height,
.in_game = true,
.server_hid_forwarding = hid_forwarding_enabled(),
.on_streaming_changed = [this] { send_settings_changed_packet(session, network_session.get(), application::get_config()); },
-17
View File
@@ -18,7 +18,6 @@
*/
#include "application.h"
#include "battery.h"
#include "stream.h"
#include "utils/overloaded.h"
#include "wivrn_packets.h"
@@ -279,9 +278,6 @@ void scenes::stream::tracking()
application::instance().setup_jni();
#endif
XrTime next_battery_check = 0;
const XrDuration battery_check_interval = 30'000'000'000; // 30s
magic_enum::containers::array<device_id, XrSpace> spaces{};
const auto & config = application::get_config();
@@ -590,19 +586,6 @@ void scenes::stream::tracking()
throw;
}
// FIXME: switch to event based
if (next_battery_check < now)
{
auto status = get_battery_status();
network_session->send_stream(from_headset::battery{
.charge = status.charge.value_or(-1),
.present = status.charge.has_value(),
.charging = status.charging,
});
next_battery_check = now + battery_check_interval;
}
if (auto fb = std::get_if<xr::fb_body_tracker>(&body_tracker); fb and fb->should_send_skeleton())
{
try
+123
View File
@@ -0,0 +1,123 @@
/*
* WiVRn VR streaming
* Copyright (C) 2023 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2023 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "utils/strings.h"
#include <cstdint>
#include <cstring>
#include <optional>
#include <spdlog/spdlog.h>
#include <stdexcept>
#include <string>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#ifdef __ANDROID__
#include "android/property.h"
#endif
template <typename T>
std::optional<T> env(std::string_view name);
template <>
inline std::optional<std::string> env(std::string_view name)
{
#ifdef __ANDROID__
auto android_sysprop_name = std::format("debug.wivrn.{}", name);
return get_property(android_sysprop_name.c_str());
#else
std::string env_name = "WIVRN_";
env_name.reserve(env_name.size() + name.size());
for (const auto & c: name)
env_name += std::toupper(c);
const char * value = std::getenv(env_name.c_str());
if (value)
return value;
return std::nullopt;
#endif
}
template <>
inline std::optional<uint32_t> env(std::string_view name)
{
const auto value = env<std::string>(name);
if (not value)
return std::nullopt;
try
{
const unsigned long parsed = std::stoul(*value);
if (parsed > std::numeric_limits<uint32_t>::max())
return std::nullopt;
return static_cast<uint32_t>(parsed);
}
catch (std::runtime_error & e)
{
spdlog::warn("failed to parse {} (value: {}: {}", name, *value, e.what());
return std::nullopt;
}
}
template <>
inline std::optional<bool> env(std::string_view name)
{
const auto value = env<std::string>(name);
if (not value)
return std::nullopt;
if (strcmp(value->c_str(), "1") == 0 || strcasecmp(value->c_str(), "true") == 0 || strcasecmp(value->c_str(), "yes") == 0 || strcasecmp(value->c_str(), "on") == 0)
return true;
if (strcmp(value->c_str(), "0") == 0 || strcasecmp(value->c_str(), "false") == 0 || strcasecmp(value->c_str(), "no") == 0 || strcasecmp(value->c_str(), "off") == 0)
return false;
return std::nullopt;
}
template <>
inline std::optional<std::unordered_map<std::string, std::string>> env(std::string_view name)
{
const auto values = env<std::string>(name);
if (not values)
return std::nullopt;
std::unordered_map<std::string, std::string> map;
for (auto value: utils::split(*values, ","))
{
if (auto pos = value.find('='); pos != std::string::npos)
map.insert(std::make_pair(value.substr(0, pos), value.substr(pos + 1)));
}
return map;
}
template <>
inline std::optional<std::unordered_set<std::string>> env(std::string_view name)
{
const auto values = env<std::string>(name);
if (not values)
return std::nullopt;
#if defined(__cpp_lib_containers_ranges) && __cpp_lib_containers_ranges >= 202202L
return std::unordered_set<std::string>{std::from_range, utils::split(*values, ",")};
#else
std::optional<std::unordered_set<std::string>> res{std::in_place};
for (auto & val: utils::split(*values))
res->insert(std::move(val));
return res;
#endif
}
+4
View File
@@ -53,6 +53,10 @@ xr::system::system(xr::instance & inst, XrFormFactor formfactor)
body_tracker = xr::body_tracker_supported(inst, *this);
face_tracker = xr::face_tracker_supported(inst, *this);
auto views = view_configuration_views(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO);
assert(views.size() == 2);
stereo_view_ = views[0];
}
XrGraphicsRequirementsVulkan2KHR xr::system::graphics_requirements() const
+5
View File
@@ -66,6 +66,7 @@ class system
passthrough_type passthrough;
body_tracker_type body_tracker;
face_tracker_type face_tracker;
XrViewConfigurationView stereo_view_;
public:
system() = default;
@@ -106,6 +107,10 @@ public:
vk::raii::Device create_device(vk::raii::PhysicalDevice & pdev, vk::DeviceCreateInfo & create_info) const;
std::vector<XrViewConfigurationType> view_configurations() const;
const XrViewConfigurationView & stereo_view() const
{
return stereo_view_;
}
XrViewConfigurationProperties view_configuration_properties(XrViewConfigurationType) const;
std::vector<XrViewConfigurationView> view_configuration_views(XrViewConfigurationType) const;
std::vector<XrEnvironmentBlendMode> environment_blend_modes(XrViewConfigurationType) const;
+1 -1
View File
@@ -507,10 +507,10 @@ void decrypt_context::decrypt_in_place(std::span<std::span<uint8_t>> text)
std::vector<uint8_t> pbkdf2(std::string pass, std::string salt, std::span<uint8_t> secret, size_t size)
{
pass.append((char *)secret.data(), secret.size());
std::array params{
OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, salt.data(), salt.size()),
OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_PASSWORD, pass.data(), pass.size()),
OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SECRET, secret.data(), secret.size()),
OSSL_PARAM_construct_end(),
};
+205 -89
View File
@@ -65,6 +65,7 @@ public:
}
std::vector<std::string> string_table();
std::vector<std::string> string_table(uint32_t count);
auto tellg()
{
@@ -101,6 +102,15 @@ std::vector<std::string> binary_reader::string_table()
return res;
}
std::vector<std::string> binary_reader::string_table(uint32_t count)
{
std::vector<std::string> res;
res.reserve(count);
for (size_t i = 0; i < count; ++i)
res.emplace_back(read<std::string>());
return res;
}
template <typename T>
void read_dict(binary_reader & in, T & visitor, const std::vector<std::string> * string_table = nullptr)
{
@@ -217,15 +227,113 @@ std::unordered_set<uint64_t> owned_appids(std::filesystem::path localconfig)
return res;
}
std::vector<wivrn::steam::application> read_appinfo(std::filesystem::path root, std::unordered_set<uint64_t> const & appids)
struct app_data
{
enum section
{
common,
other,
};
std::vector<enum section> section;
wivrn::steam::application current{};
std::string clienticon;
std::string linuxclienticon;
bool VR = false;
void clear()
{
section.clear();
current.icon.clear();
current.name.clear();
current.url.clear();
clienticon.clear();
linuxclienticon.clear();
VR = false;
section.push_back(section::other);
}
void begin_dict(const std::string & key)
{
if (key == "common")
section.push_back(section::common);
else
section.push_back(section::other);
}
void end_dict()
{
section.pop_back();
}
void on_string(const std::string & key, std::string && val)
{
switch (section.back())
{
case common:
if (strcasecmp(key.c_str(), "clienticon") == 0)
clienticon = std::move(val);
else if (strcasecmp(key.c_str(), "linuxclienticon") == 0)
linuxclienticon = std::move(val);
else if (strcasecmp(key.c_str(), "name") == 0)
current.name[""] = std::move(val);
break;
case other:
break;
}
}
void on_uint32_t(const std::string & key, uint32_t val)
{
switch (section.back())
{
case common:
if (key == "openvrsupport")
VR = val;
break;
case other:
break;
}
}
};
bool is_appid_magic(uint32_t magic)
{
return (magic & 0xff'ff'ff'00) == 0x07'56'44'00;
}
void try_parse_application(std::vector<wivrn::steam::application> & out, std::filesystem::path root, uint32_t app_id, binary_reader & in, app_data & v, const std::vector<std::string> * string_table)
{
try
{
v.clear();
read_dict(in, v, string_table);
if (v.VR)
{
auto & item = out.emplace_back(std::move(v.current));
item.appid = app_id;
item.url = std::format("steam://launch/{}/VR", app_id);
if (auto icon_path = root / "steam/games" / (v.clienticon + ".ico"); std::filesystem::exists(icon_path))
item.icon = icon_path;
else if (auto icon_path = root / "steam/games" / (v.linuxclienticon + ".zip"); std::filesystem::exists(icon_path))
item.icon = icon_path;
}
}
catch (...)
{
// Ignore errors
}
}
// TODO: Remove when v42 appinfo is used in stable Steam Client
std::vector<wivrn::steam::application> read_appinfo_pre_v42(std::filesystem::path root, std::unordered_set<uint64_t> const & appids)
{
binary_reader in{std::ifstream{root / "appcache/appinfo.vdf"}};
uint32_t magic = in.read<uint32_t>();
if ((magic & 0xff'ff'ff'00) != 0x07'56'44'00)
if (!is_appid_magic(magic))
throw std::runtime_error{"Wrong magic number"};
auto universe = in.read<uint32_t>();
in.discard(4); // universe
int version = magic & 0xff;
@@ -238,71 +346,7 @@ std::vector<wivrn::steam::application> read_appinfo(std::filesystem::path root,
}
std::vector<wivrn::steam::application> res;
enum section
{
common,
other,
};
struct V
{
std::vector<enum section> section;
wivrn::steam::application current{};
std::string clienticon;
std::string linuxclienticon;
bool VR = false;
void clear()
{
section.clear();
current.icon.clear();
current.name.clear();
current.url.clear();
clienticon.clear();
linuxclienticon.clear();
VR = false;
section.push_back(section::other);
}
void begin_dict(const std::string & key)
{
if (key == "common")
section.push_back(section::common);
else
section.push_back(section::other);
}
void end_dict()
{
section.pop_back();
}
void on_string(const std::string & key, std::string && val)
{
switch (section.back())
{
case common:
if (strcasecmp(key.c_str(), "clienticon") == 0)
clienticon = std::move(val);
else if (strcasecmp(key.c_str(), "linuxclienticon") == 0)
linuxclienticon = std::move(val);
else if (strcasecmp(key.c_str(), "name") == 0)
current.name[""] = std::move(val);
break;
case other:
break;
}
}
void on_uint32_t(const std::string & key, uint32_t val)
{
switch (section.back())
{
case common:
if (key == "openvrsupport")
VR = val;
break;
case other:
break;
}
}
} v;
app_data v;
while (true)
{
@@ -325,33 +369,105 @@ std::vector<wivrn::steam::application> read_appinfo(std::filesystem::path root,
);
if (appids.contains(app_id))
{
try
{
v.clear();
read_dict(in, v, string_table_ptr);
if (v.VR)
{
auto & item = res.emplace_back(std::move(v.current));
item.appid = app_id;
item.url = std::format("steam://launch/{}/VR", app_id);
if (auto icon_path = root / "steam/games" / (v.clienticon + ".ico"); std::filesystem::exists(icon_path))
item.icon = icon_path;
else if (auto icon_path = root / "steam/games" / (v.linuxclienticon + ".zip"); std::filesystem::exists(icon_path))
item.icon = icon_path;
}
}
catch (...)
{
// Ignore errors
}
try_parse_application(res, root, app_id, in, v, string_table_ptr);
}
in.seekg(pos + size_data);
}
return res;
}
std::vector<wivrn::steam::application> read_appinfo_v42(std::filesystem::path root, std::unordered_set<uint64_t> const & appids)
{
std::vector<wivrn::steam::application> res;
for (auto const & entry: std::filesystem::directory_iterator(root / "appcache/appinfo"))
{
try
{
if (auto extension = entry.path().extension(); extension != ".vdf")
throw std::runtime_error{"Improper file extension"};
binary_reader in{std::ifstream{entry.path()}};
// https://github.com/xPaw/SteamAppInfo/blob/master/README.md#shard-header
uint32_t magic = in.read<uint32_t>();
if (!is_appid_magic(magic))
throw std::runtime_error{"Wrong magic number"};
int version = magic & 0xff;
if (version < 42)
throw std::runtime_error{std::format("Invalid version {}", version)};
in.discard(4 // universe
+ 4 // shard_index
+ 4 // shard_count
);
auto index_count = in.read<uint32_t>();
auto index_size = in.read<uint32_t>();
auto string_table_count = in.read<uint32_t>();
auto string_table_size = in.read<uint32_t>();
in.discard(4 // data_size
+ 4 // index_crc
+ 4 // header_crc
);
size_t index_data_pos = in.tellg();
size_t string_table_pos = index_data_pos + index_size;
size_t data_pos = string_table_pos + string_table_size;
in.seekg(string_table_pos);
std::vector<std::string> string_table = in.string_table(string_table_count);
// https://github.com/xPaw/SteamAppInfo/blob/master/README.md#index-entry-repeated
in.seekg(index_data_pos);
app_data v;
for (uint32_t i = 0; i < index_count; i++)
{
auto app_id = in.read<uint32_t>();
if (app_id == 0)
break;
auto data_offset = in.read<uint32_t>();
in.discard(4); // data_size
auto remaining = in.read<uint32_t>();
auto next = (size_t)in.tellg() + remaining;
if (appids.contains(app_id))
{
in.seekg(data_pos + data_offset);
in.discard(20); // SHA-1 of the bin data
try_parse_application(res, root, app_id, in, v, &string_table);
}
in.seekg(next);
}
}
catch (std::exception & e)
{
std::cerr << "Failed to read appinfo shard " << entry.path().filename() << ": " << e.what() << std::endl;
}
}
return res;
}
std::vector<wivrn::steam::application> read_appinfo(std::filesystem::path root, std::unordered_set<uint64_t> const & appids)
{
std::error_code ec;
if (std::filesystem::exists(root / "appcache/appinfo.vdf", ec))
{
return read_appinfo_pre_v42(root, appids);
}
else if (std::filesystem::is_directory(root / "appcache/appinfo", ec))
{
return read_appinfo_v42(root, appids);
}
throw std::runtime_error("No appinfos found in appcache");
}
} // namespace
void read_steam_shortcuts(
+25 -20
View File
@@ -40,7 +40,7 @@
namespace wivrn
{
static constexpr int protocol_revision = 1;
static constexpr int protocol_revision = 2;
enum class device_id : uint8_t
{
@@ -61,13 +61,17 @@ enum class device_id : uint8_t
RIGHT_GRIP, // /user/hand/right/input/grip/pose
RIGHT_AIM, // /user/hand/right/input/aim/pose
RIGHT_PALM, // /user/hand/right/palm_ext/pose
LEFT_X_CLICK, // /user/hand/left/input/x/click
LEFT_X_TOUCH, // /user/hand/left/input/x/touch
LEFT_Y_CLICK, // /user/hand/left/input/y/click
LEFT_Y_TOUCH, // /user/hand/left/input/y/touch
VIEW_CLICK, // /user/hand/left/input/view/click
VIEW_TOUCH, // /user/hand/left/input/view/touch
LEFT_MENU_CLICK, // /user/hand/left/input/{menu,system}/click
DPAD_UP_CLICK, // /user/hand/left/input/dpad_up/click
DPAD_UP_TOUCH, // /user/hand/left/input/dpad_up/touch
DPAD_LEFT_CLICK, // /user/hand/left/input/dpad_left/click
DPAD_LEFT_TOUCH, // /user/hand/left/input/dpad_left/touch
LEFT_X_CLICK, // /user/hand/left/input/x/click or /user/hand/left/input/dpad_down/click
LEFT_X_TOUCH, // /user/hand/left/input/x/touch or /user/hand/left/input/dpad_down/touch
LEFT_Y_CLICK, // /user/hand/left/input/y/click or /user/hand/left/input/dpad_right/click
LEFT_Y_TOUCH, // /user/hand/left/input/y/touch or /user/hand/left/input/dpad_right/touch
LEFT_MENU_CLICK, // /user/hand/left/input/{menu,view}/click
LEFT_MENU_TOUCH, // /user/hand/left/input/{menu,view}/touch
LEFT_SYSTEM_CLICK, // /user/hand/left/input/system/click
LEFT_SYSTEM_TOUCH, // /user/hand/left/input/system/touch
LEFT_BUMPER_CLICK, // /user/hand/left/input/bumper/click
LEFT_BUMPER_TOUCH, // /user/hand/left/input/bumper/touch
@@ -103,10 +107,6 @@ enum class device_id : uint8_t
LEFT_AIM_ACTIVATE_READY, // /user/hand/left/input/aim_activate_ext/ready_ext
LEFT_GRASP_VALUE, // /user/hand/left/input/grasp_ext/value
LEFT_GRASP_READY, // /user/hand/left/input/grasp_ext/ready_ext
DPAD_UP_CLICK, // /user/hand/left/input/dpad_up/click
DPAD_UP_TOUCH, // /user/hand/left/input/dpad_up/touch
DPAD_LEFT_CLICK, // /user/hand/left/input/dpad_left/click
DPAD_LEFT_TOUCH, // /user/hand/left/input/dpad_left/touch
A_CLICK, // /user/hand/right/input/a/click
A_TOUCH, // /user/hand/right/input/a/touch
B_CLICK, // /user/hand/right/input/b/click
@@ -115,10 +115,10 @@ enum class device_id : uint8_t
RIGHT_X_TOUCH, // /user/hand/right/input/x/touch
RIGHT_Y_CLICK, // /user/hand/right/input/y/click
RIGHT_Y_TOUCH, // /user/hand/right/input/y/touch
RIGHT_SYSTEM_CLICK, // /user/hand/right/input/system/click
RIGHT_SYSTEM_TOUCH, // /user/hand/right/input/system/touch
RIGHT_MENU_CLICK, // /user/hand/right/input/menu/click
RIGHT_MENU_TOUCH, // /user/hand/right/input/menu/touch
RIGHT_SYSTEM_CLICK, // /user/hand/right/input/system/click
RIGHT_SYSTEM_TOUCH, // /user/hand/right/input/system/touch
RIGHT_BUMPER_CLICK, // /user/hand/right/input/bumper/click
RIGHT_BUMPER_TOUCH, // /user/hand/right/input/bumper/touch
RIGHT_SQUEEZE_CLICK, // /user/hand/right/input/squeeze/click
@@ -154,10 +154,14 @@ enum class device_id : uint8_t
RIGHT_GRASP_VALUE, // /user/hand/right/input/grasp_ext/value
RIGHT_GRASP_READY, // /user/hand/right/input/grasp_ext/ready_ext
EYE_GAZE, // /user/eyes_ext/input/gaze_ext/pose
LEFT_HAND, // identify hand tracking
RIGHT_HAND, // identify hand tracking
BODY, // identify body tracking
FACE, // identify face tracking
LEFT_CONTROLLER, // identify controller
RIGHT_CONTROLLER, // identify controller
LEFT_HAND = LEFT_CONTROLLER, // identify hand tracking
RIGHT_HAND = RIGHT_CONTROLLER, // identify hand tracking
BODY, // identify body tracking
FACE, // identify face tracking
GAMEPAD, // identify gamepad
// Gamepad, microsoft/xbox_controller profile (/user/gamepad)
GAMEPAD_MENU_CLICK, // /user/gamepad/input/menu/click
@@ -346,6 +350,7 @@ struct headset_info_packet
};
std::optional<audio_description> speaker;
std::optional<audio_description> microphone;
bool battery_status; // supports XR_EXT_interaction_profile_battery_state_display, for reporting controller/gamepad battery status
bool hand_tracking;
bool eye_gaze;
bool palm_pose;
@@ -668,8 +673,8 @@ struct feedback
struct battery
{
float charge;
bool present;
device_id device;
std::optional<float> charge;
bool charging;
};
@@ -68,6 +68,17 @@
<content_rating type="oars-1.1" />
<releases>
<release version="26.11" date="2026-11-28">
<url type="details">https://github.com/WiVRn/WiVRn/releases/tag/v26.11</url>
<description>
<ul>
<li>Initial support for Steam Frame</li>
<li>Use vulkan video encode by default on all GPU</li>
<li>Experimental AV1 support for vulkan video encode, only if manually configured</li>
<li>Don't show boundary/guardian by default</li>
</ul>
</description>
</release>
<release version="26.9" date="2026-09-12">
<url type="details">https://github.com/WiVRn/WiVRn/releases/tag/v26.9</url>
<description>
+1 -1
View File
@@ -39,7 +39,7 @@ One of `h264`, `h265`, `av1`, `raw`.
Not all encoders support every codec:
- `x264` encoder only supports `h264` codec
- `vulkan` encoder supports `h264` and `h265` codecs
- `vulkan` encoder supports `h264`, `h265` and `av1` codecs, but `av1` is never selected automatically: it must be requested by setting `encoder` to `vulkan`
- `raw` encoder only supports `raw` codec
- `nvenc` and `vaapi` support all codecs, except `raw`
+2 -1
View File
@@ -35,7 +35,8 @@ finish-args:
# Set the active OpenXR / OpenVR runtime
- --filesystem=xdg-config/openxr:create
- --filesystem=xdg-config/openvr:create
# Access to SlimeVR IPC socket
# Access to SlimeVR IPC sockets
- --filesystem=xdg-run/SlimeVRInput
- --filesystem=xdg-run/SlimeVRRpc
- --filesystem=xdg-run/.flatpak/dev.slimevr.SlimeVR
- --filesystem=xdg-data/dev.slimevr.SlimeVR
+264 -192
View File
File diff suppressed because it is too large Load Diff
@@ -1,4 +1,4 @@
From cdd0a756a872e391f38b23ce73259497209c559b Mon Sep 17 00:00:00 2001
From 9873bdc4f2432a2530c4bd559d5d80610ffbacbb Mon Sep 17 00:00:00 2001
From: galister <85970-galister@users.noreply.gitlab.freedesktop.org>
Date: Fri, 18 Sep 2026 14:59:50 +0900
Subject: [PATCH 11/13] st/oxr: add XR_VALVE_frame_controller_interaction
@@ -7,13 +7,13 @@ Signed-off-by: galister <85970-galister@users.noreply.gitlab.freedesktop.org>
---
CMakeLists.txt | 2 +
cmake/MonadoSetOptions.cmake | 1 +
.../XR_VALVE_frame_controller_interaction.h | 25 ++
src/xrt/auxiliary/bindings/bindings.json | 257 ++++++++++++++++++
.../XR_VALVE_frame_controller_interaction.h | 25 +++
src/xrt/auxiliary/bindings/bindings.json | 191 ++++++++++++++++++
.../include/xrt/xrt_config_build.h.cmake_in | 1 +
src/xrt/include/xrt/xrt_defines.h | 48 ++++
src/xrt/include/xrt/xrt_defines.h | 48 +++++
src/xrt/include/xrt/xrt_openxr_includes.h | 1 +
.../oxr_extension_support.py | 1 +
8 files changed, 336 insertions(+)
8 files changed, 270 insertions(+)
create mode 100644 src/external/openxr_includes/openxr/XR_VALVE_frame_controller_interaction.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -81,10 +81,10 @@ index 000000000..d67826910
+#endif
\ No newline at end of file
diff --git a/src/xrt/auxiliary/bindings/bindings.json b/src/xrt/auxiliary/bindings/bindings.json
index 462ffbf43..dbb0129a3 100644
index 462ffbf43..003716a98 100644
--- a/src/xrt/auxiliary/bindings/bindings.json
+++ b/src/xrt/auxiliary/bindings/bindings.json
@@ -3258,6 +3258,263 @@
@@ -3258,6 +3258,197 @@
}
},
@@ -268,72 +268,6 @@ index 462ffbf43..dbb0129a3 100644
+ "touch": "XRT_INPUT_FRAME_VIEW_TOUCH"
+ }
+ },
+ "/input/bumper_left": {
+ "type": "button",
+ "localized_name": "Bumper",
+ "components": ["click", "touch"],
+ "side": "left",
+ "monado_bindings": {
+ "click": "XRT_INPUT_FRAME_BUMPER_CLICK",
+ "touch": "XRT_INPUT_FRAME_BUMPER_TOUCH"
+ }
+ },
+ "/input/squeeze_left": {
+ "type": "button",
+ "localized_name": "Squeeze",
+ "components": ["click", "touch", "value"],
+ "side": "left",
+ "monado_bindings": {
+ "click": "XRT_INPUT_FRAME_SQUEEZE_CLICK",
+ "touch": "XRT_INPUT_FRAME_SQUEEZE_TOUCH",
+ "value": "XRT_INPUT_FRAME_SQUEEZE_VALUE"
+ }
+ },
+ "/input/trigger_left": {
+ "type": "trigger",
+ "localized_name": "Trigger",
+ "components": ["click", "value", "touch"],
+ "side": "left",
+ "monado_bindings": {
+ "click": "XRT_INPUT_FRAME_TRIGGER_CLICK",
+ "value": "XRT_INPUT_FRAME_TRIGGER_VALUE",
+ "touch": "XRT_INPUT_FRAME_TRIGGER_TOUCH"
+ }
+ },
+ "/input/thumbstick_left": {
+ "type": "joystick",
+ "localized_name": "Thumbstick",
+ "components": ["click", "touch", "position"],
+ "dpad_emulation": {
+ "position": "position",
+ "activate": "click",
+ "center": true
+ },
+ "side": "left",
+ "monado_bindings": {
+ "click": "XRT_INPUT_FRAME_THUMBSTICK_CLICK",
+ "touch": "XRT_INPUT_FRAME_THUMBSTICK_TOUCH",
+ "position": "XRT_INPUT_FRAME_THUMBSTICK"
+ }
+ },
+ "/input/grip_left": {
+ "type": "pose",
+ "localized_name": "Grip",
+ "components": ["pose"],
+ "side": "left",
+ "monado_bindings": {
+ "pose": "XRT_INPUT_FRAME_GRIP_POSE"
+ }
+ },
+ "/input/aim_left": {
+ "type": "pose",
+ "localized_name": "Aim",
+ "components": ["pose"],
+ "side": "left",
+ "monado_bindings": {
+ "pose": "XRT_INPUT_FRAME_AIM_POSE"
+ }
+ },
+ "/output/haptic": {
+ "type": "vibration",
+ "localized_name": "Haptic",
File diff suppressed because it is too large Load Diff
@@ -1,112 +0,0 @@
From 1db037337db699783cb8e8f66fd6e592d51f1b1b Mon Sep 17 00:00:00 2001
From: Sapphire <imsapphire0@gmail.com>
Date: Wed, 26 Aug 2026 04:07:59 -0500
Subject: [PATCH 2/8] d/solarxr: Consume battery status for generic trackers
Signed-off-by: Sapphire <imsapphire0@gmail.com>
---
src/xrt/drivers/solarxr/solarxr_device.c | 55 ++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/src/xrt/drivers/solarxr/solarxr_device.c b/src/xrt/drivers/solarxr/solarxr_device.c
index b3cc11e47..b976774ae 100644
--- a/src/xrt/drivers/solarxr/solarxr_device.c
+++ b/src/xrt/drivers/solarxr/solarxr_device.c
@@ -34,6 +34,8 @@ struct solarxr_generic_tracker
uint32_t index;
struct m_relation_history *history; // weak reference
enum solarxr_body_part role;
+ float charge; // -1.f == no battery info
+ bool charging;
};
struct solarxr_device
@@ -682,6 +684,15 @@ solarxr_network_thread(void *const ptr)
solarxr_handshake_status_to_str(header.message.handshake_response.status));
device->shook_hands = false;
atomic_store(&device->enabled_bones, 0);
+ for (size_t i = 0; i < ARRAY_SIZE(device->tracker_refs); ++i) {
+ struct solarxr_generic_tracker *const tracker = device->tracker_refs[i];
+ if (tracker == NULL)
+ break;
+
+ os_mutex_lock(&tracker->mutex);
+ tracker->charge = -1.f;
+ os_mutex_unlock(&tracker->mutex);
+ }
feeder_mark_unsent(&device->feeder);
}
break;
@@ -705,6 +716,22 @@ solarxr_network_thread(void *const ptr)
bones.data = header.message.skeleton_update.bones.data;
}
break;
+ case SOLARXR_DRIVER_MESSAGE_TYPE_BONE_BATTERY_UPDATE:
+ for (size_t i = 0; i < ARRAY_SIZE(device->tracker_refs); ++i) {
+ struct solarxr_generic_tracker *const tracker = device->tracker_refs[i];
+ if (tracker == NULL)
+ break;
+ if (tracker->role != header.message.bone_battery_update.bone)
+ continue;
+
+ os_mutex_lock(&tracker->mutex);
+ tracker->charge =
+ (float)header.message.bone_battery_update.battery_level / 100.f;
+ tracker->charging = header.message.bone_battery_update.charging;
+ os_mutex_unlock(&tracker->mutex);
+ break;
+ }
+ break;
default:;
}
}
@@ -826,6 +853,31 @@ solarxr_generic_tracker_get_tracked_pose(struct xrt_device *const xdev,
return result;
}
+static xrt_result_t
+solarxr_generic_tracker_get_battery_status(struct xrt_device *const xdev,
+ bool *const out_present,
+ bool *const out_charging,
+ float *const out_charge)
+{
+ struct solarxr_generic_tracker *const device = solarxr_generic_tracker(xdev);
+ assert(device != NULL);
+
+ os_mutex_lock(&device->mutex);
+
+ if (device->charge == -1.f) {
+ *out_present = false;
+ goto end;
+ }
+
+ *out_present = true;
+ *out_charge = device->charge;
+ *out_charging = device->charging;
+
+end:
+ os_mutex_unlock(&device->mutex);
+ return XRT_SUCCESS;
+}
+
static void
solarxr_generic_tracker_destroy(struct xrt_device *const xdev)
{
@@ -944,11 +996,14 @@ solarxr_device_create_xdevs(struct xrt_tracking_origin *const tracking_origin,
tracker->base.tracking_origin = device->base.tracking_origin;
tracker->base.supported.orientation_tracking = true;
tracker->base.supported.position_tracking = true;
+ tracker->base.supported.battery_status = true;
tracker->base.update_inputs = solarxr_generic_tracker_update_inputs;
tracker->base.get_tracked_pose = solarxr_generic_tracker_get_tracked_pose;
+ tracker->base.get_battery_status = solarxr_generic_tracker_get_battery_status;
tracker->base.destroy = solarxr_generic_tracker_destroy;
tracker->base.inputs[0].name = XRT_INPUT_GENERIC_TRACKER_POSE;
tracker->role = body_part;
+ tracker->charge = -1.f;
assert(trackers_len < ARRAY_SIZE(trackers));
m_relation_history_create(&device->trackers[trackers_len]);
--
2.56.0
@@ -1,27 +0,0 @@
From b1f2190a7fb3367548c6a763b29e78c4331e0d32 Mon Sep 17 00:00:00 2001
From: Sapphire <imsapphire0@gmail.com>
Date: Mon, 3 Aug 2026 02:48:40 -0500
Subject: [PATCH 3/8] d/solarxr: Check for hang up event when polling IPC
sockets
Signed-off-by: Sapphire <imsapphire0@gmail.com>
---
src/xrt/drivers/solarxr/solarxr_ipc_socket.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/xrt/drivers/solarxr/solarxr_ipc_socket.c b/src/xrt/drivers/solarxr/solarxr_ipc_socket.c
index 85e9cad37..8a38a990c 100644
--- a/src/xrt/drivers/solarxr/solarxr_ipc_socket.c
+++ b/src/xrt/drivers/solarxr/solarxr_ipc_socket.c
@@ -239,7 +239,7 @@ solarxr_ipc_socket_wait_timeout(struct solarxr_ipc_socket *const state, const ti
.tv_nsec = timeout % U_TIME_1S_IN_NS,
};
const bool result = (ppoll(&fd, 1, (timeout >= 0) ? &timeout_ts : NULL, NULL) != -1)
- ? (fd.revents & POLLERR) == 0
+ ? (fd.revents & (POLLERR | POLLHUP)) == 0
: errno == EINTR;
xrt_reference_dec(&state->reference);
--
2.56.0
@@ -1,79 +0,0 @@
From b3c2ad7da88a0c509fc8237f25d06aba314a2e30 Mon Sep 17 00:00:00 2001
From: Sapphire <imsapphire0@gmail.com>
Date: Mon, 3 Aug 2026 02:52:06 -0500
Subject: [PATCH 4/8] d/solarxr: Reconnect to IPC sockets when connection
breaks
Signed-off-by: Sapphire <imsapphire0@gmail.com>
---
src/xrt/drivers/solarxr/solarxr_device.c | 37 +++++++++++++++++++-
src/xrt/drivers/solarxr/solarxr_ipc_socket.c | 2 --
2 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/src/xrt/drivers/solarxr/solarxr_device.c b/src/xrt/drivers/solarxr/solarxr_device.c
index b976774ae..0993f4f41 100644
--- a/src/xrt/drivers/solarxr/solarxr_device.c
+++ b/src/xrt/drivers/solarxr/solarxr_device.c
@@ -591,10 +591,45 @@ solarxr_network_thread(void *const ptr)
},
};
- while (solarxr_ipc_socket_wait_timeout(&device->socket, -1)) {
+ bool lost_connection = false;
+ while (solarxr_ipc_socket_is_connected(&device->socket)) {
+ if (!solarxr_ipc_socket_wait_timeout(&device->socket, -1)) {
+ if (!solarxr_ipc_socket_is_connected(&device->socket)) {
+ // We were woke up from wait_timeout when destroying the socket
+ break;
+ }
+
+ if (!lost_connection) {
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(),
+ "solarxr_ipc_socket_wait_timeout failed; attempting socket reconnect");
+ lost_connection = true;
+ device->shook_hands = false;
+ atomic_store(&device->enabled_bones, 0);
+ for (size_t i = 0; i < ARRAY_SIZE(device->tracker_refs); ++i) {
+ struct solarxr_generic_tracker *const tracker = device->tracker_refs[i];
+ if (tracker == NULL)
+ break;
+
+ os_mutex_lock(&tracker->mutex);
+ tracker->charge = -1.f;
+ os_mutex_unlock(&tracker->mutex);
+ }
+ feeder_mark_unsent(&device->feeder);
+ }
+
+ //! @todo Maybe write a better way to silence the logs than passing in RAW log level?
+ const struct sockaddr_un path = solarxr_ipc_socket_find(U_LOGGING_RAW, "SlimeVRRpc");
+ if (solarxr_ipc_socket_connect(&device->socket, path)) {
+ lost_connection = false;
+ } else {
+ os_nanosleep(U_TIME_1S_IN_NS);
+ }
+ continue;
+ }
const struct span buffer = {solarxr_ipc_socket_receive(&device->socket), device->socket.buffer};
if (buffer.length == 0) {
+ U_LOG_IFL_E(debug_get_log_option_solarxr_log(), "solarxr_ipc_socket_receive failed");
continue;
}
diff --git a/src/xrt/drivers/solarxr/solarxr_ipc_socket.c b/src/xrt/drivers/solarxr/solarxr_ipc_socket.c
index 8a38a990c..9492df71f 100644
--- a/src/xrt/drivers/solarxr/solarxr_ipc_socket.c
+++ b/src/xrt/drivers/solarxr/solarxr_ipc_socket.c
@@ -161,8 +161,6 @@ solarxr_ipc_socket_find(const enum u_logging_level log_level, const char filenam
bool
solarxr_ipc_socket_connect(struct solarxr_ipc_socket *const state, const struct sockaddr_un addr)
{
- solarxr_ipc_socket_close(state);
-
xrt_ipc_handle_t ipc_handle = XRT_IPC_HANDLE_INVALID;
if (addr.sun_family != AF_UNIX) {
goto fail;
--
2.56.0
@@ -1,27 +0,0 @@
From 6980a355a5c7b623097f52f60e6595794778208e Mon Sep 17 00:00:00 2001
From: Sapphire <imsapphire0@gmail.com>
Date: Wed, 26 Aug 2026 02:53:26 -0500
Subject: [PATCH 5/8] d/solarxr: Add missing includes in solarxr_ipc_message
header
Signed-off-by: Sapphire <imsapphire0@gmail.com>
---
src/xrt/drivers/solarxr/solarxr_ipc_message.h | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/xrt/drivers/solarxr/solarxr_ipc_message.h b/src/xrt/drivers/solarxr/solarxr_ipc_message.h
index 72eeb381e..7d827a7b8 100644
--- a/src/xrt/drivers/solarxr/solarxr_ipc_message.h
+++ b/src/xrt/drivers/solarxr/solarxr_ipc_message.h
@@ -3,6 +3,8 @@
#pragma once
#include <endian.h>
+#include <stdbool.h>
+#include <stdint.h>
#include <string.h>
#ifdef __cplusplus
--
2.56.0
@@ -1,37 +0,0 @@
From 570b839dba744f592685fbc76a3dee00d397de9b Mon Sep 17 00:00:00 2001
From: Sapphire <imsapphire0@gmail.com>
Date: Wed, 26 Aug 2026 04:30:16 -0500
Subject: [PATCH 6/8] d/solarxr: Name the network thread
Signed-off-by: Sapphire <imsapphire0@gmail.com>
---
src/xrt/drivers/solarxr/solarxr_device.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/xrt/drivers/solarxr/solarxr_device.c b/src/xrt/drivers/solarxr/solarxr_device.c
index 0993f4f41..e5c6303df 100644
--- a/src/xrt/drivers/solarxr/solarxr_device.c
+++ b/src/xrt/drivers/solarxr/solarxr_device.c
@@ -15,6 +15,7 @@
#include "util/u_debug.h"
#include "util/u_device.h"
#include "util/u_time.h"
+#include "util/u_trace_marker.h"
#include <endian.h>
#include <stdatomic.h>
@@ -348,6 +349,11 @@ solarxr_network_thread(void *const ptr)
{
struct solarxr_device *const device = (struct solarxr_device *)ptr;
+ const char *const thread_name = "SolarXR Network";
+
+ U_TRACE_SET_THREAD_NAME(thread_name);
+ os_thread_name_self(thread_name);
+
static const char driver_name[] = "Monado";
struct
{
--
2.56.0
@@ -1,88 +0,0 @@
From 6987a5982092d91d142b065f5bf00ca9ea50d861 Mon Sep 17 00:00:00 2001
From: Sapphire <imsapphire0@gmail.com>
Date: Wed, 26 Aug 2026 18:57:37 -0500
Subject: [PATCH 7/8] d/solarxr: Add tracing markers
Signed-off-by: Sapphire <imsapphire0@gmail.com>
---
src/xrt/drivers/solarxr/feeder.c | 8 ++++++++
src/xrt/drivers/solarxr/solarxr_device.c | 6 ++++++
2 files changed, 14 insertions(+)
diff --git a/src/xrt/drivers/solarxr/feeder.c b/src/xrt/drivers/solarxr/feeder.c
index f217a446c..6f38fe24b 100644
--- a/src/xrt/drivers/solarxr/feeder.c
+++ b/src/xrt/drivers/solarxr/feeder.c
@@ -12,6 +12,7 @@
#include "solarxr_ipc_message.h"
#include "util/u_hashmap.h"
+#include "util/u_trace_marker.h"
#include "xrt/xrt_device.h"
#include <math.h>
@@ -777,6 +778,8 @@ feeder_device_send_feedback_cb(const uint64_t key, const void *const value, void
struct send_feedback_userdata *const data = (struct send_feedback_userdata *)userptr;
enum solarxr_tracker_status status = SOLARXR_TRACKER_STATUS_DISCONNECTED;
+ XRT_TRACE_MARKER();
+
if (xdev == NULL) {
device->next_to_erase = data->to_erase;
data->to_erase = device;
@@ -827,6 +830,8 @@ feeder_device_send_feedback_cb(const uint64_t key, const void *const value, void
void
feeder_send_feedback(struct feeder *const feeder)
{
+ XRT_TRACE_MARKER();
+
os_mutex_lock(&feeder->mutex);
struct send_feedback_userdata data;
@@ -834,7 +839,10 @@ feeder_send_feedback(struct feeder *const feeder)
data.time = os_monotonic_get_ns();
data.log_level = feeder->socket->log_level;
data.packet_end = data.packet;
+
+ XRT_TRACE_BEGIN(feeder_device_send_feedback_foreach);
u_hashmap_int_for_each(feeder->devices, feeder_device_send_feedback_cb, &data);
+ XRT_TRACE_END(feeder_device_send_feedback_foreach);
// flush queued messages to socket
if (data.packet_end != data.packet) {
diff --git a/src/xrt/drivers/solarxr/solarxr_device.c b/src/xrt/drivers/solarxr/solarxr_device.c
index e5c6303df..c0fb60c10 100644
--- a/src/xrt/drivers/solarxr/solarxr_device.c
+++ b/src/xrt/drivers/solarxr/solarxr_device.c
@@ -294,8 +294,11 @@ static void
solarxr_device_handle_bones(struct solarxr_device *const device,
const struct solarxr_bone bones[ARRAY_SIZE(device->bones)])
{
+ XRT_TRACE_MARKER();
+
os_mutex_lock(&device->mutex);
+ XRT_TRACE_BEGIN(solarxr_device_handle_generic_trackers);
for (size_t i = 0; i < ARRAY_SIZE(device->tracker_refs); ++i) {
const struct solarxr_generic_tracker *const tracker = device->tracker_refs[i];
if (tracker == NULL || tracker->role == SOLARXR_BODY_PART_NONE) {
@@ -324,6 +327,7 @@ solarxr_device_handle_bones(struct solarxr_device *const device,
};
m_relation_history_push(history, &relation, device->socket.timestamp);
}
+ XRT_TRACE_END(solarxr_device_handle_generic_trackers);
bool generation_increased = false;
for (uint32_t i = 0; i < ARRAY_SIZE(device->bones); ++i) {
@@ -639,6 +643,8 @@ solarxr_network_thread(void *const ptr)
continue;
}
+ XRT_TRACE_IDENT(solarxr_network_frame);
+
struct solarxr_message_bundle bundle;
if (!read_solarxr_message_bundle(&bundle, buffer.data, buffer.length,
(const solarxr_message_bundle_t *)buffer.data)) {
--
2.56.0
@@ -1,36 +0,0 @@
From 96a51c1a89db5fd07e44f6026173a44e050a0c43 Mon Sep 17 00:00:00 2001
From: Sapphire <imsapphire0@gmail.com>
Date: Tue, 1 Sep 2026 02:50:08 -0500
Subject: [PATCH 8/8] d/solarxr: Try SLIMEVR_SOCKET_DIR override socket path
Signed-off-by: Sapphire <imsapphire0@gmail.com>
---
src/xrt/drivers/solarxr/solarxr_ipc_socket.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/src/xrt/drivers/solarxr/solarxr_ipc_socket.c b/src/xrt/drivers/solarxr/solarxr_ipc_socket.c
index 9492df71f..2d833223b 100644
--- a/src/xrt/drivers/solarxr/solarxr_ipc_socket.c
+++ b/src/xrt/drivers/solarxr/solarxr_ipc_socket.c
@@ -115,6 +115,18 @@ solarxr_ipc_socket_find(const enum u_logging_level log_level, const char filenam
return (struct sockaddr_un){0};
}
+ // try override path
+ const char *override_env;
+ int override_path_len = 0;
+ if ((override_env = getenv("SLIMEVR_SOCKET_DIR")) != NULL) {
+ override_path_len = snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s", override_env, filename);
+ }
+
+ if (override_path_len > 0 && (unsigned)override_path_len < sizeof(addr.sun_path) &&
+ check_socket_path(log_level, addr.sun_path)) {
+ return addr;
+ }
+
const ssize_t runtime_dir_len =
u_file_get_path_in_runtime_dir("", addr.sun_path, sizeof(addr.sun_path) - 1 - filename_len);
if (runtime_dir_len <= 0 || (size_t)runtime_dir_len >= sizeof(addr.sun_path) - 1 - filename_len) {
--
2.56.0
+1
View File
@@ -184,6 +184,7 @@ if (WIVRN_BUILD_SERVER)
if(WIVRN_USE_VULKAN_ENCODE)
target_sources(wivrn-server PRIVATE
encoder/video_encoder_vulkan.cpp
encoder/video_encoder_vulkan_av1.cpp
encoder/video_encoder_vulkan_h264.cpp
encoder/video_encoder_vulkan_h265.cpp
)
+6 -2
View File
@@ -127,9 +127,11 @@ struct pipewire_device : public audio_device
"Audio/Sink",
PW_KEY_MEDIA_ROLE,
"Game",
PW_KEY_PRIORITY_SESSION,
"1700", // wireplumber gives priorities in range 1000-1600 for alsa sinks
PW_KEY_NODE_RATE,
// Set stream rate to match client, preventing PipeWire from doing
// unnecessary resampling which degrades audio quality
PW_KEY_NODE_RATE,
rate_str.c_str(),
// Declare target latency to help PipeWire optimize buffering
PW_KEY_NODE_LATENCY,
@@ -206,9 +208,11 @@ struct pipewire_device : public audio_device
"Audio/Source",
PW_KEY_MEDIA_ROLE,
"Game",
PW_KEY_PRIORITY_SESSION,
"2700", // wireplumber gives priorities in range 2000-2600 for alsa sources
PW_KEY_NODE_RATE,
// Set stream rate to match client, preventing PipeWire from doing
// unnecessary resampling which degrades audio quality
PW_KEY_NODE_RATE,
rate_str.c_str(),
// Declare target latency to help PipeWire optimize buffering
PW_KEY_NODE_LATENCY,
+67 -35
View File
@@ -57,20 +57,18 @@ enum wivrn_controller_input_index
WIVRN_CONTROLLER_MENU_TOUCH, // /user/hand/XXXX/input/menu/touch
WIVRN_CONTROLLER_SYSTEM_CLICK, // /user/hand/XXXX/input/system/click
WIVRN_CONTROLLER_SYSTEM_TOUCH, // /user/hand/XXXX/input/system/touch
WIVRN_CONTROLLER_VIEW_CLICK, // /user/hand/left/input/view/click
WIVRN_CONTROLLER_VIEW_TOUCH, // /user/hand/left/input/view/touch
WIVRN_CONTROLLER_DPAD_UP_CLICK, // /user/hand/left/input/dpad_up/click
WIVRN_CONTROLLER_DPAD_UP_TOUCH, // /user/hand/left/input/dpad_up/touch
WIVRN_CONTROLLER_DPAD_LEFT_CLICK, // /user/hand/left/input/dpad_left/click
WIVRN_CONTROLLER_DPAD_LEFT_TOUCH, // /user/hand/left/input/dpad_left/touch
WIVRN_CONTROLLER_X_CLICK, // /user/hand/XXXX/input/x/click or /user/hand/left/input/dpad_down/click
WIVRN_CONTROLLER_X_TOUCH, // /user/hand/XXXX/input/x/touch or /user/hand/left/input/dpad_down/touch
WIVRN_CONTROLLER_Y_CLICK, // /user/hand/XXXX/input/y/click or /user/hand/left/input/dpad_right/click
WIVRN_CONTROLLER_Y_TOUCH, // /user/hand/XXXX/input/y/touch or /user/hand/left/input/dpad_right/touch
WIVRN_CONTROLLER_A_CLICK, // /user/hand/right/input/a/click
WIVRN_CONTROLLER_A_TOUCH, // /user/hand/right/input/a/touch
WIVRN_CONTROLLER_B_CLICK, // /user/hand/right/input/b/click
WIVRN_CONTROLLER_B_TOUCH, // /user/hand/right/input/b/touch
WIVRN_CONTROLLER_X_CLICK, // /user/hand/XXXX/input/x/click
WIVRN_CONTROLLER_X_TOUCH, // /user/hand/XXXX/input/x/touch
WIVRN_CONTROLLER_Y_CLICK, // /user/hand/XXXX/input/y/click
WIVRN_CONTROLLER_Y_TOUCH, // /user/hand/XXXX/input/y/touch
WIVRN_CONTROLLER_DPAD_UP_CLICK, // /user/hand/XXXX/input/dpad_up/click
WIVRN_CONTROLLER_DPAD_UP_TOUCH, // /user/hand/XXXX/input/dpad_up/touch
WIVRN_CONTROLLER_DPAD_LEFT_CLICK, // /user/hand/XXXX/input/dpad_left/click
WIVRN_CONTROLLER_DPAD_LEFT_TOUCH, // /user/hand/XXXX/input/dpad_left/touch
WIVRN_CONTROLLER_SQUEEZE_CLICK, // /user/hand/XXXX/input/squeeze/click
WIVRN_CONTROLLER_SQUEEZE_FORCE, // /user/hand/XXXX/input/squeeze/force
WIVRN_CONTROLLER_SQUEEZE_TOUCH, // /user/hand/XXXX/input/squeeze/touch
@@ -150,6 +148,14 @@ input_data map_input(device_id id)
return {WIVRN_CONTROLLER_PALM_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_PALM:
return {WIVRN_CONTROLLER_PALM_POSE, wivrn_input_type::POSE, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::DPAD_UP_CLICK:
return {WIVRN_CONTROLLER_DPAD_UP_CLICK, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::DPAD_UP_TOUCH:
return {WIVRN_CONTROLLER_DPAD_UP_TOUCH, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::DPAD_LEFT_CLICK:
return {WIVRN_CONTROLLER_DPAD_LEFT_CLICK, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::DPAD_LEFT_TOUCH:
return {WIVRN_CONTROLLER_DPAD_LEFT_TOUCH, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_X_CLICK:
return {WIVRN_CONTROLLER_X_CLICK, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_X_TOUCH:
@@ -174,26 +180,18 @@ input_data map_input(device_id id)
return {WIVRN_CONTROLLER_B_CLICK, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::B_TOUCH:
return {WIVRN_CONTROLLER_B_TOUCH, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::DPAD_UP_CLICK:
return {WIVRN_CONTROLLER_DPAD_UP_CLICK, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::DPAD_UP_TOUCH:
return {WIVRN_CONTROLLER_DPAD_UP_TOUCH, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::DPAD_LEFT_CLICK:
return {WIVRN_CONTROLLER_DPAD_LEFT_CLICK, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::DPAD_LEFT_TOUCH:
return {WIVRN_CONTROLLER_DPAD_LEFT_TOUCH, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_MENU_CLICK:
return {WIVRN_CONTROLLER_MENU_CLICK, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_MENU_TOUCH:
return {WIVRN_CONTROLLER_MENU_TOUCH, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_MENU_CLICK:
return {WIVRN_CONTROLLER_MENU_CLICK, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_MENU_TOUCH:
return {WIVRN_CONTROLLER_MENU_TOUCH, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::LEFT_SYSTEM_CLICK:
return {WIVRN_CONTROLLER_SYSTEM_CLICK, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::LEFT_SYSTEM_TOUCH:
return {WIVRN_CONTROLLER_SYSTEM_TOUCH, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::VIEW_CLICK:
return {WIVRN_CONTROLLER_VIEW_CLICK, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::VIEW_TOUCH:
return {WIVRN_CONTROLLER_VIEW_TOUCH, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER};
case device_id::RIGHT_SYSTEM_CLICK:
return {WIVRN_CONTROLLER_SYSTEM_CLICK, wivrn_input_type::BOOL, XRT_DEVICE_TYPE_RIGHT_HAND_CONTROLLER};
case device_id::RIGHT_SYSTEM_TOUCH:
@@ -406,15 +404,15 @@ xrt_binding_input_pair index_input_binding_right[] = {
xrt_binding_input_pair frame_input_binding_left[] = {
{XRT_INPUT_FRAME_DPAD_UP_CLICK, XRT_INPUT_FRAME_DPAD_UP_CLICK},
{XRT_INPUT_FRAME_DPAD_UP_TOUCH, XRT_INPUT_FRAME_DPAD_UP_TOUCH},
{XRT_INPUT_FRAME_DPAD_DOWN_CLICK, XRT_INPUT_TOUCH_X_CLICK},
{XRT_INPUT_FRAME_DPAD_DOWN_TOUCH, XRT_INPUT_TOUCH_X_TOUCH},
{XRT_INPUT_FRAME_DPAD_LEFT_CLICK, XRT_INPUT_FRAME_DPAD_LEFT_CLICK},
{XRT_INPUT_FRAME_DPAD_LEFT_TOUCH, XRT_INPUT_FRAME_DPAD_LEFT_TOUCH},
{XRT_INPUT_FRAME_DPAD_DOWN_CLICK, XRT_INPUT_TOUCH_X_CLICK},
{XRT_INPUT_FRAME_DPAD_DOWN_TOUCH, XRT_INPUT_TOUCH_X_TOUCH},
{XRT_INPUT_FRAME_DPAD_RIGHT_CLICK, XRT_INPUT_TOUCH_Y_CLICK},
{XRT_INPUT_FRAME_DPAD_RIGHT_TOUCH, XRT_INPUT_TOUCH_Y_TOUCH},
{XRT_INPUT_FRAME_VIEW_CLICK, XRT_INPUT_FRAME_VIEW_CLICK},
{XRT_INPUT_FRAME_VIEW_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
{XRT_INPUT_FRAME_VIEW_TOUCH, XRT_INPUT_FRAME_VIEW_TOUCH},
{XRT_INPUT_FRAME_SYSTEM_CLICK, XRT_INPUT_TOUCH_MENU_CLICK},
{XRT_INPUT_FRAME_SYSTEM_CLICK, XRT_INPUT_FRAME_SYSTEM_CLICK},
{XRT_INPUT_FRAME_SYSTEM_TOUCH, XRT_INPUT_INDEX_SYSTEM_TOUCH},
{XRT_INPUT_FRAME_BUMPER_CLICK, XRT_INPUT_FRAME_BUMPER_CLICK},
{XRT_INPUT_FRAME_BUMPER_TOUCH, XRT_INPUT_FRAME_BUMPER_TOUCH},
@@ -429,6 +427,8 @@ xrt_binding_input_pair frame_input_binding_left[] = {
{XRT_INPUT_FRAME_THUMBSTICK, XRT_INPUT_TOUCH_THUMBSTICK},
{XRT_INPUT_FRAME_GRIP_POSE, XRT_INPUT_TOUCH_GRIP_POSE},
{XRT_INPUT_FRAME_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
{XRT_INPUT_HAND_POKE_POSE, XRT_INPUT_HAND_POKE_POSE},
};
xrt_binding_input_pair frame_input_binding_right[] = {
@@ -457,6 +457,8 @@ xrt_binding_input_pair frame_input_binding_right[] = {
{XRT_INPUT_FRAME_THUMBSTICK, XRT_INPUT_TOUCH_THUMBSTICK},
{XRT_INPUT_FRAME_GRIP_POSE, XRT_INPUT_TOUCH_GRIP_POSE},
{XRT_INPUT_FRAME_AIM_POSE, XRT_INPUT_TOUCH_AIM_POSE},
{XRT_INPUT_HAND_PINCH_POSE, XRT_INPUT_HAND_PINCH_POSE},
{XRT_INPUT_HAND_POKE_POSE, XRT_INPUT_HAND_POKE_POSE},
};
xrt_binding_output_pair frame_output_binding[] = {
@@ -726,11 +728,13 @@ wivrn_controller::wivrn_controller(xrt_device_name name,
.orientation_tracking = true,
.position_tracking = true,
.hand_tracking = name != XRT_DEVICE_EXT_HAND_INTERACTION and cnx->get_info().hand_tracking,
.battery_status = cnx->get_info().battery_status,
},
.update_inputs = method_pointer<&wivrn_controller::update_inputs>,
.get_tracked_pose = method_pointer<&wivrn_controller::get_tracked_pose>,
.get_hand_tracking = method_pointer<&wivrn_controller::get_hand_tracking>,
.set_output = method_pointer<&wivrn_controller::set_output>,
.get_battery_status = method_pointer<&wivrn_controller::get_battery_status>,
.destroy = [](xrt_device *) {},
},
grip(hand_id == 0 ? device_id::LEFT_GRIP : device_id::RIGHT_GRIP),
@@ -779,19 +783,19 @@ wivrn_controller::wivrn_controller(xrt_device_name name,
{
inputs[WIVRN_CONTROLLER_HAND_TRACKING_LEFT].name = XRT_INPUT_HT_UNOBSTRUCTED_LEFT;
inputs[WIVRN_CONTROLLER_HAND_TRACKING_LEFT].active = true;
SET_INPUT(FRAME, VIEW_CLICK);
SET_INPUT(FRAME, VIEW_TOUCH);
SET_INPUT(TOUCH, MENU_CLICK);
SET_INPUT(TOUCH, X_CLICK);
SET_INPUT(TOUCH, Y_CLICK);
SET_INPUT(TOUCH, X_TOUCH);
SET_INPUT(TOUCH, Y_TOUCH);
inputs[WIVRN_CONTROLLER_MENU_TOUCH].name = XRT_INPUT_FRAME_VIEW_TOUCH;
inputs[WIVRN_CONTROLLER_MENU_TOUCH].active = true;
SET_INPUT(FRAME, SYSTEM_CLICK);
SET_INPUT(FRAME, DPAD_UP_CLICK);
SET_INPUT(FRAME, DPAD_UP_TOUCH);
SET_INPUT(FRAME, DPAD_LEFT_CLICK);
SET_INPUT(FRAME, DPAD_LEFT_TOUCH);
SET_INPUT(TOUCH, X_CLICK);
SET_INPUT(TOUCH, X_TOUCH);
SET_INPUT(TOUCH, Y_CLICK);
SET_INPUT(TOUCH, Y_TOUCH);
}
else
{
@@ -802,12 +806,12 @@ wivrn_controller::wivrn_controller(xrt_device_name name,
SET_INPUT(TOUCH, SYSTEM_CLICK);
SET_INPUT(TOUCH, A_CLICK);
SET_INPUT(TOUCH, B_CLICK);
SET_INPUT(TOUCH, A_TOUCH);
SET_INPUT(TOUCH, B_CLICK);
SET_INPUT(TOUCH, B_TOUCH);
SET_INPUT(FRAME, X_CLICK);
SET_INPUT(FRAME, Y_CLICK);
SET_INPUT(FRAME, X_TOUCH);
SET_INPUT(FRAME, Y_CLICK);
SET_INPUT(FRAME, Y_TOUCH);
}
SET_INPUT(VIVE_FOCUS3, SQUEEZE_CLICK);
@@ -990,6 +994,26 @@ xrt_result_t wivrn_controller::get_hand_tracking(xrt_input_name name, int64_t de
}
}
xrt_result_t wivrn_controller::get_battery_status(bool * out_present,
bool * out_charging,
float * out_charge)
{
auto bat = battery.lock();
*out_charging = bat->charging;
if (bat->charge)
{
*out_present = true;
*out_charge = *bat->charge;
}
else
{
*out_present = false;
}
return XRT_SUCCESS;
}
void wivrn_controller::set_derived_pose(const from_headset::derived_pose & derived)
{
auto list = [this](device_id id) -> pose_list * {
@@ -1006,6 +1030,14 @@ void wivrn_controller::set_derived_pose(const from_headset::derived_pose & deriv
target->set_derived(source, xrt_cast(derived.relation));
}
void wivrn_controller::update_battery(const from_headset::battery & new_battery)
{
const device_id device = device_type == XRT_DEVICE_TYPE_LEFT_HAND_CONTROLLER ? device_id::LEFT_CONTROLLER : device_id::RIGHT_CONTROLLER;
if (new_battery.device == device)
{
*battery.lock() = new_battery;
}
}
void wivrn_controller::update_tracking(const from_headset::tracking & tracking, const clock_offset & offset)
{
aim.update_tracking(tracking, offset);
+8 -1
View File
@@ -20,6 +20,7 @@
#pragma once
#include "utils/thread_safe.h"
#include "xrt/xrt_device.h"
#include "hand_joints_list.h"
@@ -48,6 +49,8 @@ class wivrn_controller : public xrt_device
std::vector<xrt_input> inputs_array;
std::vector<xrt_output> outputs_array;
thread_safe<from_headset::battery> battery{};
wivrn::wivrn_session * cnx;
public:
@@ -58,12 +61,16 @@ public:
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation);
xrt_result_t get_hand_tracking(xrt_input_name name, int64_t desired_timestamp_ns, xrt_hand_joint_set * out_value, int64_t * out_timestamp_ns);
xrt_result_t get_battery_status(bool * out_present,
bool * out_charging,
float * out_charge);
xrt_result_t set_output(xrt_output_name name, const xrt_output_value * value);
void set_inputs(const from_headset::inputs &, const clock_offset &);
void set_derived_pose(const from_headset::derived_pose &);
void update_battery(const from_headset::battery &);
void update_tracking(const from_headset::tracking &, const clock_offset &);
void update_hand_tracking(const from_headset::hand_tracking &, const clock_offset &);
+32
View File
@@ -42,9 +42,13 @@ wivrn_gamepad::wivrn_gamepad(wivrn::wivrn_session & cnx) :
.str = "WiVRn Gamepad",
.serial = "WiVRn Gamepad",
.tracking_origin = &origin,
.supported = {
.battery_status = cnx.get_info().battery_status,
},
.update_inputs = method_pointer<&wivrn_gamepad::update_inputs>,
.get_tracked_pose = method_pointer<&wivrn_gamepad::get_tracked_pose>,
.set_output = method_pointer<&wivrn_gamepad::set_output>,
.get_battery_status = method_pointer<&wivrn_gamepad::get_battery_status>,
.destroy = [](xrt_device *) {},
},
origin{
@@ -110,6 +114,34 @@ xrt_result_t wivrn_gamepad::get_tracked_pose(xrt_input_name name, int64_t, xrt_s
return XRT_ERROR_INPUT_UNSUPPORTED;
}
xrt_result_t wivrn_gamepad::get_battery_status(bool * out_present,
bool * out_charging,
float * out_charge)
{
auto bat = battery.lock();
*out_charging = bat->charging;
if (bat->charge)
{
*out_present = true;
*out_charge = *bat->charge;
}
else
{
*out_present = false;
}
return XRT_SUCCESS;
}
void wivrn_gamepad::set_battery(const from_headset::battery & new_battery)
{
if (new_battery.device == device_id::GAMEPAD)
{
*battery.lock() = new_battery;
}
}
void wivrn_gamepad::set_inputs(const from_headset::inputs & inputs)
{
std::lock_guard lock(mutex);
+7
View File
@@ -18,6 +18,7 @@
#pragma once
#include "utils/thread_safe.h"
#include "wivrn_packets.h"
#include "xrt/xrt_defines.h"
@@ -43,6 +44,8 @@ class wivrn_gamepad : public xrt_device
std::array<xrt_input, 18> inputs_staging; // written from the network thread, published by update_inputs
std::array<xrt_output, 4> outputs_array;
thread_safe<from_headset::battery> battery{};
wivrn::wivrn_session * cnx;
public:
@@ -51,8 +54,12 @@ public:
xrt_result_t update_inputs();
xrt_result_t get_tracked_pose(xrt_input_name name, int64_t at_timestamp_ns, xrt_space_relation * out_relation);
xrt_result_t get_battery_status(bool * out_present,
bool * out_charging,
float * out_charge);
xrt_result_t set_output(xrt_output_name name, const xrt_output_value * value);
void set_battery(const from_headset::battery &);
// Update from a forwarded inputs packet (gamepad device_ids).
void set_inputs(const from_headset::inputs &);
void set_connected(bool);
+14 -4
View File
@@ -164,8 +164,10 @@ void wivrn_hmd::update_tracking(const from_headset::tracking & tracking, const c
void wivrn_hmd::update_battery(const from_headset::battery & new_battery)
{
// We will only request a new sample if the current one is consumed
*battery.lock() = new_battery;
if (new_battery.device == device_id::HEAD)
{
*battery.lock() = new_battery;
}
}
xrt_result_t wivrn_hmd::get_view_poses(const xrt_vec3 * default_eye_relation,
@@ -214,9 +216,17 @@ xrt_result_t wivrn_hmd::get_battery_status(bool * out_present,
float * out_charge)
{
auto bat = battery.lock();
*out_present = bat->present;
*out_charging = bat->charging;
*out_charge = bat->charge;
if (bat->charge)
{
*out_present = true;
*out_charge = *bat->charge;
}
else
{
*out_present = false;
}
return XRT_SUCCESS;
}
+6
View File
@@ -822,6 +822,12 @@ void wivrn_session::operator()(from_headset::feedback && feedback)
void wivrn_session::operator()(from_headset::battery && battery)
{
hmd.update_battery(battery);
left_controller.update_battery(battery);
left_hand_interaction.update_battery(battery);
right_controller.update_battery(battery);
right_hand_interaction.update_battery(battery);
if (gamepad_device)
gamepad_device->set_battery(battery);
}
void wivrn_session::operator()(from_headset::visibility_mask_changed && mask)
-27
View File
@@ -19,35 +19,8 @@
#include "xrt_cast.h"
#include "wivrn_packets.h"
#include <cstring>
#include <type_traits>
namespace
{
template <typename Out, typename In>
Out do_cast(const In & in)
{
Out res;
static_assert(sizeof(res) == sizeof(in));
memcpy(&res, &in, sizeof(res));
return res;
}
} // namespace
#define XRT_CAST(in_type, out_type) \
out_type xrt_cast(const in_type & in) \
{ \
return do_cast<out_type>(in); \
}
XRT_CAST(XrPosef, xrt_pose)
XRT_CAST(XrVector3f, xrt_vec3)
XRT_CAST(XrQuaternionf, xrt_quat)
XRT_CAST(XrFovf, xrt_fov)
XRT_CAST(xrt_pose, XrPosef)
XRT_CAST(xrt_fov, XrFovf)
xrt_space_relation_flags from_pose_flags(uint8_t in_flags)
{
std::underlying_type_t<xrt_space_relation_flags> flags{};
+15 -6
View File
@@ -20,14 +20,23 @@
#pragma once
#include "xrt/xrt_defines.h"
#include <bit>
#include <openxr/openxr.h>
xrt_pose xrt_cast(const XrPosef &);
xrt_vec3 xrt_cast(const XrVector3f &);
xrt_quat xrt_cast(const XrQuaternionf &);
xrt_fov xrt_cast(const XrFovf &);
#define XRT_CAST(in_type, out_type) \
constexpr out_type xrt_cast(const in_type & in) noexcept \
{ \
return std::bit_cast<out_type>(in); \
}
XrPosef xrt_cast(const xrt_pose &);
XrFovf xrt_cast(const xrt_fov &);
XRT_CAST(XrPosef, xrt_pose)
XRT_CAST(XrVector3f, xrt_vec3)
XRT_CAST(XrQuaternionf, xrt_quat)
XRT_CAST(XrFovf, xrt_fov)
XRT_CAST(xrt_pose, XrPosef)
XRT_CAST(xrt_fov, XrFovf)
#undef XRT_CAST
xrt_space_relation_flags from_pose_flags(uint8_t in_flags);
+9 -2
View File
@@ -204,8 +204,12 @@ class prober
U_LOG_I("GPU does not support H.265 Vulkan video encode");
return res;
}
case av1:
U_LOG_D("Vulkan video encode for AV1 is not implemented in WiVRn");
case av1: {
auto res = vk.has_device_ext(VK_KHR_VIDEO_ENCODE_AV1_EXTENSION_NAME) and flags & vk::VideoCodecOperationFlagBitsKHR::eEncodeAv1;
if (not res)
U_LOG_I("GPU does not support AV1 Vulkan video encode");
return res;
}
case raw:
return false;
}
@@ -240,6 +244,9 @@ public:
{
for (auto codec: codecs)
{
if (codec == video_codec::av1 and config.name.empty())
continue;
if (has_vk(codec))
return {encoder_vulkan, codec};
}
+3 -1
View File
@@ -39,6 +39,7 @@
#include "video_encoder_x264.h"
#endif
#if WIVRN_USE_VULKAN_ENCODE
#include "video_encoder_vulkan_av1.h"
#include "video_encoder_vulkan_h264.h"
#include "video_encoder_vulkan_h265.h"
#endif
@@ -120,7 +121,8 @@ std::unique_ptr<video_encoder> video_encoder::create(
res = video_encoder_vulkan_h265::create(wivrn_vk, settings, stream_idx);
break;
case video_codec::av1:
throw std::runtime_error("av1 not supported for vulkan video encode");
res = video_encoder_vulkan_av1::create(wivrn_vk, settings, stream_idx);
break;
case video_codec::raw:
throw std::runtime_error("raw codec only supported on raw encoder");
}
+1 -1
View File
@@ -821,7 +821,7 @@ void wivrn::video_encoder_vulkan::present_image(vk::Image y_cbcr, vk::SemaphoreS
}
video_cmd_buf.beginVideoCodingKHR({
.pNext = (session_initialized and rate_control) ? &rate_control.value() : nullptr,
.pNext = begin_coding_next((session_initialized and rate_control) ? &rate_control.value() : nullptr),
.videoSession = *video_session,
.videoSessionParameters = *video_session_parameters,
.referenceSlotCount = ref_slot ? 2u : 1u,
+8
View File
@@ -111,6 +111,14 @@ protected:
virtual void * encode_info_next(uint32_t frame_num, size_t slot, std::optional<int32_t> reference_slot) = 0;
virtual vk::ExtensionProperties std_header_version() = 0;
// Codec-specific structures to prepend to the vkCmdBeginVideoCodingKHR pNext chain.
// Note that this chain accepts structures the vkCmdControlVideoCodingKHR one does not,
// so it must not be reused for rate control updates.
virtual const void * begin_coding_next(const void * next)
{
return next;
}
public:
void present_image(vk::Image y_cbcr, vk::SemaphoreSubmitInfo, uint8_t slot, uint64_t frame_index) override;
std::optional<data> encode(uint8_t slot, uint64_t frame_index) override;
+633
View File
@@ -0,0 +1,633 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Patrick Nicolas <patricknicolas@laposte.net>
* Copyright (C) 2026 Philipp Schlegel <dev@phischle.xyz>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "video_encoder_vulkan_av1.h"
#include "encoder/encoder_settings.h"
#include "util/u_logging.h"
#include "utils/wivrn_vk_bundle.h"
#include <algorithm>
#include <bit>
#include <cstring>
#include <limits>
#include <numeric>
namespace
{
uint32_t align_div(uint32_t value, uint32_t divisor)
{
return (value + divisor - 1) / divisor;
}
uint8_t bits_for(uint32_t value)
{
return std::max<uint8_t>(std::bit_width(value), 1);
}
// AV1 spec, annex A.3 "Levels", limited to the levels that are actually defined.
// MaxDisplayRate is omitted, it is always smaller than MaxDecodeRate and we never
// display more samples than we decode.
struct av1_level_limits
{
StdVideoAV1Level level;
uint32_t max_pic_size; // samples
uint32_t max_h_size; // samples
uint32_t max_v_size; // samples
uint64_t max_decode_rate;
};
constexpr av1_level_limits av1_levels[] = {
{STD_VIDEO_AV1_LEVEL_2_0, 147456, 2048, 1152, 5529600},
{STD_VIDEO_AV1_LEVEL_2_1, 278784, 2816, 1584, 10454400},
{STD_VIDEO_AV1_LEVEL_3_0, 665856, 4352, 2448, 24969600},
{STD_VIDEO_AV1_LEVEL_3_1, 1065024, 5504, 3096, 39938400},
{STD_VIDEO_AV1_LEVEL_4_0, 2359296, 6144, 3456, 77856768},
{STD_VIDEO_AV1_LEVEL_4_1, 2359296, 6144, 3456, 155713536},
{STD_VIDEO_AV1_LEVEL_5_0, 8912896, 8192, 4352, 273715200},
{STD_VIDEO_AV1_LEVEL_5_1, 8912896, 8192, 4352, 547430400},
{STD_VIDEO_AV1_LEVEL_5_2, 8912896, 8192, 4352, 1094860800},
{STD_VIDEO_AV1_LEVEL_5_3, 8912896, 8192, 4352, 1176502272},
{STD_VIDEO_AV1_LEVEL_6_0, 35651584, 16384, 8704, 1176502272},
{STD_VIDEO_AV1_LEVEL_6_1, 35651584, 16384, 8704, 2189721600},
{STD_VIDEO_AV1_LEVEL_6_2, 35651584, 16384, 8704, 4379443200},
{STD_VIDEO_AV1_LEVEL_6_3, 35651584, 16384, 8704, 4706009088},
};
// Smallest level able to carry the stream, clamped to what the encoder supports.
// Reporting the driver's maximum instead would make decoders reject or downgrade
// the stream for no reason.
StdVideoAV1Level select_level(uint32_t width, uint32_t height, float fps, StdVideoAV1Level max_level)
{
const uint64_t pic_size = uint64_t(width) * height;
const uint64_t decode_rate = uint64_t(double(pic_size) * std::max(fps, 1.f));
for (const auto & l: av1_levels)
{
if (l.level > max_level)
break;
if (pic_size <= l.max_pic_size and width <= l.max_h_size and height <= l.max_v_size and decode_rate <= l.max_decode_rate)
return l.level;
}
U_LOG_W("AV1: no level supports %ux%u@%.1f, falling back to the encoder maximum", width, height, fps);
return max_level;
}
} // namespace
wivrn::video_encoder_vulkan_av1::video_encoder_vulkan_av1(
wivrn::vk_bundle & vk,
const vk::VideoCapabilitiesKHR & video_caps,
const vk::VideoEncodeCapabilitiesKHR & encode_caps,
const vk::VideoEncodeAV1CapabilitiesKHR & encode_av1_caps,
uint8_t stream_idx,
const encoder_settings & settings) :
video_encoder_vulkan(vk, video_caps, encode_caps, stream_idx, settings)
{
if (not vk.has_device_ext(VK_KHR_VIDEO_ENCODE_AV1_EXTENSION_NAME))
throw std::runtime_error("Vulkan video encode AV1 extension not available");
if (settings.bit_depth != 8 && settings.bit_depth != 10)
throw std::runtime_error("av1 encoder supports 8-bit or 10-bit only");
configure_from_caps(encode_av1_caps);
level = select_level(aligned_extent.width, aligned_extent.height, settings.fps, encode_av1_caps.maxLevel);
color_config = {
.flags = {
.mono_chrome = 0,
.color_range = 1,
.separate_uv_delta_q = 0,
.color_description_present_flag = 1,
},
.BitDepth = static_cast<uint8_t>(settings.bit_depth),
.subsampling_x = 1,
.subsampling_y = 1,
.reserved1 = 0,
.color_primaries = STD_VIDEO_AV1_COLOR_PRIMARIES_BT_709,
.transfer_characteristics = STD_VIDEO_AV1_TRANSFER_CHARACTERISTICS_BT_709,
.matrix_coefficients = STD_VIDEO_AV1_MATRIX_COEFFICIENTS_BT_709,
.chroma_sample_position = STD_VIDEO_AV1_CHROMA_SAMPLE_POSITION_COLOCATED,
};
seq_header = {
.flags = {
.still_picture = 0,
.reduced_still_picture_header = 0,
.use_128x128_superblock = superblock_size == 128 ? 1u : 0u,
.enable_filter_intra = 0,
.enable_intra_edge_filter = 0,
.enable_interintra_compound = 0,
.enable_masked_compound = 0,
.enable_warped_motion = 0,
.enable_dual_filter = 0,
.enable_order_hint = 1,
.enable_jnt_comp = 0,
.enable_ref_frame_mvs = 0,
.frame_id_numbers_present_flag = 0,
.enable_superres = 0,
.enable_cdef = 0,
.enable_restoration = 0,
.film_grain_params_present = 0,
.timing_info_present_flag = 0,
.initial_display_delay_present_flag = 0,
},
.seq_profile = STD_VIDEO_AV1_PROFILE_MAIN,
.frame_width_bits_minus_1 = static_cast<uint8_t>(bits_for(aligned_extent.width - 1) - 1),
.frame_height_bits_minus_1 = static_cast<uint8_t>(bits_for(aligned_extent.height - 1) - 1),
.max_frame_width_minus_1 = static_cast<uint16_t>(aligned_extent.width - 1),
.max_frame_height_minus_1 = static_cast<uint16_t>(aligned_extent.height - 1),
.delta_frame_id_length_minus_2 = 0,
.additional_frame_id_length_minus_1 = 0,
.order_hint_bits_minus_1 = static_cast<uint8_t>(order_hint_bits - 1),
.seq_force_integer_mv = STD_VIDEO_AV1_SELECT_INTEGER_MV,
.seq_force_screen_content_tools = STD_VIDEO_AV1_SELECT_SCREEN_CONTENT_TOOLS,
.reserved1 = {},
.pColorConfig = &color_config,
.pTimingInfo = nullptr,
};
operating_point = {
.flags = {
.decoder_model_present_for_this_op = 0,
.low_delay_mode_flag = 1,
.initial_display_delay_present_for_this_op = 0,
},
.operating_point_idc = 0,
.seq_level_idx = static_cast<uint8_t>(level),
.seq_tier = 0,
.decoder_buffer_delay = 0,
.encoder_buffer_delay = 0,
.initial_display_delay_minus_1 = 0,
};
const uint32_t sb_cols = align_div(aligned_extent.width, superblock_size);
const uint32_t sb_rows = align_div(aligned_extent.height, superblock_size);
const uint32_t mi_cols = align_div(aligned_extent.width, 4);
const uint32_t mi_rows = align_div(aligned_extent.height, 4);
const bool uniform_tile_spacing = bool(std_flags & vk::VideoEncodeAV1StdFlagBitsKHR::eUniformTileSpacingFlagSet);
// A single tile is enough for the resolutions WiVRn streams, but AV1 caps a tile at 4096
// samples wide (annex A.3), a wider stream would not be decodable.
if (sb_cols * superblock_size > 4096)
throw std::runtime_error("av1 encoder supports at most 4096 samples per tile row");
mi_col_starts = {0u, static_cast<uint16_t>(mi_cols)};
mi_row_starts = {0u, static_cast<uint16_t>(mi_rows)};
if (!tile_widths_sb.empty())
tile_widths_sb[0] = static_cast<uint16_t>(sb_cols - 1);
if (!tile_heights_sb.empty())
tile_heights_sb[0] = static_cast<uint16_t>(sb_rows - 1);
tile_info = {
.flags = {
.uniform_tile_spacing_flag = uniform_tile_spacing ? 1u : 0u,
},
.TileCols = 1,
.TileRows = 1,
.context_update_tile_id = 0,
.tile_size_bytes_minus_1 = 0,
.reserved1 = {},
.pMiColStarts = uniform_tile_spacing ? nullptr : mi_col_starts.data(),
.pMiRowStarts = uniform_tile_spacing ? nullptr : mi_row_starts.data(),
.pWidthInSbsMinus1 = uniform_tile_spacing ? nullptr : tile_widths_sb.data(),
.pHeightInSbsMinus1 = uniform_tile_spacing ? nullptr : tile_heights_sb.data(),
};
quantization = {
.flags = {
.using_qmatrix = 0,
.diff_uv_delta = 0,
},
.base_q_idx = static_cast<uint8_t>(encode_av1_caps.maxQIndex),
.DeltaQYDc = 0,
.DeltaQUDc = 0,
.DeltaQUAc = 0,
.DeltaQVDc = 0,
.DeltaQVAc = 0,
.qm_y = 0,
.qm_u = 0,
.qm_v = 0,
};
loop_filter = {
.flags = {
.loop_filter_delta_enabled = 0,
.loop_filter_delta_update = 0,
},
.loop_filter_level = {},
.loop_filter_sharpness = 0,
.update_ref_delta = 0,
.loop_filter_ref_deltas = {},
.update_mode_delta = 0,
.loop_filter_mode_deltas = {},
};
cdef = {
.cdef_damping_minus_3 = 0,
.cdef_bits = 0,
.cdef_y_pri_strength = {},
.cdef_y_sec_strength = {},
.cdef_uv_pri_strength = {},
.cdef_uv_sec_strength = {},
};
loop_restoration = {
.FrameRestorationType = {STD_VIDEO_AV1_FRAME_RESTORATION_TYPE_NONE,
STD_VIDEO_AV1_FRAME_RESTORATION_TYPE_NONE,
STD_VIDEO_AV1_FRAME_RESTORATION_TYPE_NONE},
.LoopRestorationSize = {0, 0, 0},
};
global_motion = {
.GmType = {},
.gm_params = {},
};
segmentation = {};
rate_control_layer.pNext = &rate_control_layer_av1;
}
void wivrn::video_encoder_vulkan_av1::configure_from_caps(const vk::VideoEncodeAV1CapabilitiesKHR & encode_av1_caps)
{
U_LOG_D("AV1: capabilities: stdSyntaxFlags=0x%x, superblockSizes=0x%x, singleReferenceNameMask=0x%x, maxSingleReferenceCount=%u, maxUnidirectionalCompoundReferenceCount=%u, maxBidirectionalCompoundReferenceCount=%u, maxQIndex=%u, minQIndex=%u, requiresGopRemainingFrames=%u, maxOperatingPoints=%u",
static_cast<uint32_t>(encode_av1_caps.stdSyntaxFlags),
static_cast<uint32_t>(encode_av1_caps.superblockSizes),
encode_av1_caps.singleReferenceNameMask,
encode_av1_caps.maxSingleReferenceCount,
encode_av1_caps.maxUnidirectionalCompoundReferenceCount,
encode_av1_caps.maxBidirectionalCompoundReferenceCount,
encode_av1_caps.maxQIndex,
encode_av1_caps.minQIndex,
encode_av1_caps.requiresGopRemainingFrames,
encode_av1_caps.maxOperatingPoints);
std_flags = encode_av1_caps.stdSyntaxFlags;
if (encode_av1_caps.superblockSizes & vk::VideoEncodeAV1SuperblockSizeFlagBitsKHR::e64)
superblock_size = 64;
else
superblock_size = 128;
single_reference_name_mask = encode_av1_caps.singleReferenceNameMask;
max_single_reference_count = encode_av1_caps.maxSingleReferenceCount;
max_q_index = encode_av1_caps.maxQIndex;
min_q_index = encode_av1_caps.minQIndex;
// The single reference of an inter frame must use a reference name the encoder
// advertises, bit i standing for LAST_FRAME + i.
// VUID-vkCmdEncodeVideoKHR-predictionMode-10329
ref_name_index = -1;
for (size_t i = 0; i < reference_name_slot_indices.size(); ++i)
{
if (single_reference_name_mask & (1u << i))
{
ref_name_index = int32_t(i);
break;
}
}
// WiVRn streams key frame + inter frames referencing a single acknowledged frame, an
// encoder that cannot do single reference prediction is of no use to us.
if (ref_name_index < 0 or max_single_reference_count == 0)
throw std::runtime_error("av1 encoder does not support single reference prediction");
if (ref_name_index != 0)
U_LOG_W("AV1: LAST_FRAME not supported (mask=0x%x), using reference name index %d", single_reference_name_mask, ref_name_index);
rate_control_av1 = vk::VideoEncodeAV1RateControlInfoKHR{
.flags = vk::VideoEncodeAV1RateControlFlagBitsKHR::eRegularGop,
.gopFrameCount = std::numeric_limits<uint32_t>::max(),
.keyFramePeriod = std::numeric_limits<uint32_t>::max(),
.consecutiveBipredictiveFrameCount = 0,
// VUID-VkVideoEncodeAV1RateControlInfoKHR-temporalLayerCount-10299
.temporalLayerCount = std::min(1u, encode_av1_caps.maxTemporalLayerCount),
};
rate_control_layer_av1 = vk::VideoEncodeAV1RateControlLayerInfoKHR{
.useMinQIndex = VK_FALSE,
.minQIndex = {
.intraQIndex = encode_av1_caps.minQIndex,
.predictiveQIndex = encode_av1_caps.minQIndex,
.bipredictiveQIndex = encode_av1_caps.minQIndex,
},
.useMaxQIndex = VK_FALSE,
.maxQIndex = {
.intraQIndex = encode_av1_caps.maxQIndex,
.predictiveQIndex = encode_av1_caps.maxQIndex,
.bipredictiveQIndex = encode_av1_caps.maxQIndex,
},
.useMaxFrameSize = VK_FALSE,
.maxFrameSize = {},
};
}
std::vector<void *> wivrn::video_encoder_vulkan_av1::setup_slot_info(size_t dpb_size)
{
dpb_std_info.resize(dpb_size, {});
dpb_std_slots.reserve(dpb_size);
std::vector<void *> res;
for (size_t i = 0; i < dpb_size; ++i)
{
dpb_std_slots.push_back({
.pStdReferenceInfo = &dpb_std_info[i],
});
res.push_back(&dpb_std_slots[i]);
}
return res;
}
static auto get_video_caps(vk::raii::PhysicalDevice & phys_dev, int bit_depth)
{
if (!(bit_depth == 8 || bit_depth == 10))
throw std::runtime_error("av1 encoder supports 8-bit or 10-bit only");
vk::StructureChain video_profile_info{
vk::VideoProfileInfoKHR{
.videoCodecOperation = vk::VideoCodecOperationFlagBitsKHR::eEncodeAv1,
.chromaSubsampling = vk::VideoChromaSubsamplingFlagBitsKHR::e420,
.lumaBitDepth = bit_depth == 10 ? vk::VideoComponentBitDepthFlagBitsKHR::e10 : vk::VideoComponentBitDepthFlagBitsKHR::e8,
.chromaBitDepth = bit_depth == 10 ? vk::VideoComponentBitDepthFlagBitsKHR::e10 : vk::VideoComponentBitDepthFlagBitsKHR::e8,
},
vk::VideoEncodeAV1ProfileInfoKHR{
.stdProfile = STD_VIDEO_AV1_PROFILE_MAIN,
},
vk::VideoEncodeUsageInfoKHR{
.videoUsageHints = vk::VideoEncodeUsageFlagBitsKHR::eStreaming,
.videoContentHints = vk::VideoEncodeContentFlagBitsKHR::eRendered,
.tuningMode = vk::VideoEncodeTuningModeKHR::eUltraLowLatency,
}};
try
{
auto [video_caps, encode_caps, encode_av1_caps] =
phys_dev.getVideoCapabilitiesKHR<
vk::VideoCapabilitiesKHR,
vk::VideoEncodeCapabilitiesKHR,
vk::VideoEncodeAV1CapabilitiesKHR>(video_profile_info.get());
video_caps.maxDpbSlots = std::min(video_caps.maxDpbSlots, uint32_t(STD_VIDEO_AV1_NUM_REF_FRAMES));
return std::make_tuple(video_caps, encode_caps, encode_av1_caps, video_profile_info);
}
catch (...)
{}
video_profile_info.unlink<vk::VideoEncodeUsageInfoKHR>();
auto [video_caps, encode_caps, encode_av1_caps] =
phys_dev.getVideoCapabilitiesKHR<
vk::VideoCapabilitiesKHR,
vk::VideoEncodeCapabilitiesKHR,
vk::VideoEncodeAV1CapabilitiesKHR>(video_profile_info.get());
video_caps.maxDpbSlots = std::min(video_caps.maxDpbSlots, uint32_t(STD_VIDEO_AV1_NUM_REF_FRAMES));
return std::make_tuple(video_caps, encode_caps, encode_av1_caps, video_profile_info);
}
std::unique_ptr<wivrn::video_encoder_vulkan_av1> wivrn::video_encoder_vulkan_av1::create(
wivrn::vk_bundle & vk,
const encoder_settings & settings,
uint8_t stream_idx)
{
auto [video_caps, encode_caps, encode_av1_caps, video_profile_info] = get_video_caps(vk.physical_device, settings.bit_depth);
std::unique_ptr<video_encoder_vulkan_av1> self(
new video_encoder_vulkan_av1(vk, video_caps, encode_caps, encode_av1_caps, stream_idx, settings));
vk::VideoEncodeAV1SessionParametersCreateInfoKHR session_params_info{
.pStdSequenceHeader = &self->seq_header,
.pStdDecoderModelInfo = nullptr,
.stdOperatingPointCount = 0,
.pStdOperatingPoints = nullptr,
};
self->quality_level_info = vk::VideoEncodeQualityLevelInfoKHR{
.qualityLevel = 0, // Use default quality level
};
session_params_info.pNext = &self->quality_level_info;
// Let the session be sized for whatever the encoder supports, the level that matters to the
// decoder is the one written to the operating point.
vk::VideoEncodeAV1SessionCreateInfoKHR session_create_info{
.useMaxLevel = false,
.maxLevel = encode_av1_caps.maxLevel,
};
// VkVideoEncodeAV1RateControlInfoKHR belongs to the same pNext chain as the generic
// rate control info, in both vkCmdBeginVideoCodingKHR and vkCmdControlVideoCodingKHR.
if (self->rate_control)
{
self->rate_control_enabled = true;
self->rate_control->pNext = &self->rate_control_av1;
}
// VkVideoEncodeAV1GopRemainingFrameInfoKHR only extends VkVideoBeginCodingInfoKHR, so it
// is added by begin_coding_next() rather than chained onto the rate control info, which is
// also used for vkCmdControlVideoCodingKHR.
// VUID-vkCmdBeginVideoCodingKHR-pBeginInfo-10282
if (self->rate_control_enabled and (encode_av1_caps.requiresGopRemainingFrames or encode_av1_caps.prefersGopRemainingFrames))
{
self->gop_info = vk::VideoEncodeAV1GopRemainingFrameInfoKHR{
.useGopRemainingFrames = true,
.gopRemainingIntra = 0,
.gopRemainingPredictive = std::numeric_limits<uint32_t>::max(),
.gopRemainingBipredictive = 0,
};
}
if (encode_av1_caps.maxOperatingPoints > 0)
{
session_params_info.stdOperatingPointCount = 1;
session_params_info.pStdOperatingPoints = &self->operating_point;
}
#ifdef VK_KHR_video_encode_intra_refresh
vk::VideoEncodeIntraRefreshCapabilitiesKHR intra_caps{};
if (std::get<vk::PhysicalDeviceVideoEncodeIntraRefreshFeaturesKHR>(vk.feat).videoEncodeIntraRefresh)
intra_caps = std::get<vk::VideoEncodeIntraRefreshCapabilitiesKHR>(
vk.physical_device.getVideoCapabilitiesKHR<vk::VideoCapabilitiesKHR, vk::VideoEncodeCapabilitiesKHR, vk::VideoEncodeAV1CapabilitiesKHR, vk::VideoEncodeIntraRefreshCapabilitiesKHR>(video_profile_info.get()));
#endif
self->init(video_caps,
#ifdef VK_KHR_video_encode_intra_refresh
intra_caps,
#endif
video_profile_info.get(),
&session_create_info,
&session_params_info);
return self;
}
void wivrn::video_encoder_vulkan_av1::send_idr_data()
{
U_LOG_D("AV1: send_idr_data() called");
// Fetch encoded session parameters (sequence header OBU).
try
{
auto data = get_encoded_parameters(nullptr);
U_LOG_D("AV1: get_encoded_parameters returned %zu bytes", data.size());
if (!data.empty())
SendData(data, false, true);
else
U_LOG_W("AV1: get_encoded_parameters returned empty data");
}
catch (const std::exception & e)
{
U_LOG_E("AV1: Exception in get_encoded_parameters: %s", e.what());
}
}
void * wivrn::video_encoder_vulkan_av1::encode_info_next(uint32_t frame_num, size_t slot, std::optional<int32_t> ref_slot)
{
const bool has_ref = ref_slot.has_value();
const bool is_keyframe = not has_ref;
// Initialize reference name slot indices to -1 (no reference)
std::ranges::fill(reference_name_slot_indices, -1);
if (has_ref)
reference_name_slot_indices[ref_name_index] = *ref_slot;
std_picture_info = {};
std_picture_info.flags.error_resilient_mode = is_keyframe ? 1u : 0u;
std_picture_info.flags.disable_cdf_update = 0;
std_picture_info.flags.use_superres = 0;
// The coded frame is always aligned_extent, which is what the sequence header declares as
// max_frame_{width,height}, so the frame size is never overridden. Only the render size
// differs, when the requested extent needed padding to satisfy the encoder granularity.
// VUID-vkCmdEncodeVideoKHR-flags-10322
std_picture_info.flags.frame_size_override_flag = 0;
std_picture_info.flags.render_and_frame_size_different =
(aligned_extent.width != extent.width or aligned_extent.height != extent.height) ? 1u : 0u;
std_picture_info.flags.allow_screen_content_tools = 0;
std_picture_info.flags.is_filter_switchable = 1;
// AV1 spec 5.9.2: both are inferred for intra frames, match what the decoder will derive
std_picture_info.flags.force_integer_mv = is_keyframe ? 1u : 0u;
std_picture_info.flags.buffer_removal_time_present_flag = 0;
std_picture_info.flags.allow_intrabc = 0;
std_picture_info.flags.frame_refs_short_signaling = 0;
std_picture_info.flags.allow_high_precision_mv = is_keyframe ? 0u : 1u;
std_picture_info.flags.is_motion_mode_switchable = 0;
std_picture_info.flags.use_ref_frame_mvs = 0;
std_picture_info.flags.disable_frame_end_update_cdf = 0;
std_picture_info.flags.allow_warped_motion = 0;
std_picture_info.flags.reduced_tx_set = 0;
std_picture_info.flags.skip_mode_present = 0;
std_picture_info.flags.delta_q_present = 0;
std_picture_info.flags.delta_lf_present = 0;
std_picture_info.flags.delta_lf_multi = 0;
std_picture_info.flags.segmentation_enabled = 0;
std_picture_info.flags.segmentation_update_map = 0;
std_picture_info.flags.segmentation_temporal_update = 0;
std_picture_info.flags.segmentation_update_data = 0;
std_picture_info.flags.UsesLr = 0;
std_picture_info.flags.usesChromaLr = 0;
std_picture_info.flags.show_frame = 1;
std_picture_info.flags.showable_frame = std_picture_info.flags.show_frame ? (is_keyframe ? 0u : 1u) : 1u;
std_picture_info.frame_type = is_keyframe ? STD_VIDEO_AV1_FRAME_TYPE_KEY : STD_VIDEO_AV1_FRAME_TYPE_INTER;
// Both are only coded when the decoder model / frame ids are signalled, which the sequence
// header disables, and the decoder then infers 0 for them (AV1 spec 5.9.2).
std_picture_info.frame_presentation_time = 0;
std_picture_info.current_frame_id = 0;
std_picture_info.order_hint = static_cast<uint8_t>(frame_num & ((1u << order_hint_bits) - 1));
// primary_ref_frame indexes ref_frame_idx[], it selects the reference to load the CDFs and
// the loop filter / segmentation state from. Only usable if the encoder supports values
// other than PRIMARY_REF_NONE.
if (has_ref and (std_flags & vk::VideoEncodeAV1StdFlagBitsKHR::ePrimaryRefFrame))
std_picture_info.primary_ref_frame = uint8_t(ref_name_index);
else
std_picture_info.primary_ref_frame = STD_VIDEO_AV1_PRIMARY_REF_NONE;
std_picture_info.refresh_frame_flags = static_cast<uint8_t>(is_keyframe ? 0xFF : (1u << slot));
std_picture_info.coded_denom = 0;
std_picture_info.render_width_minus_1 = static_cast<uint16_t>(extent.width - 1);
std_picture_info.render_height_minus_1 = static_cast<uint16_t>(extent.height - 1);
std_picture_info.interpolation_filter = STD_VIDEO_AV1_INTERPOLATION_FILTER_SWITCHABLE;
std_picture_info.TxMode = STD_VIDEO_AV1_TX_MODE_SELECT;
std_picture_info.delta_q_res = 0;
std_picture_info.delta_lf_res = 0;
std::fill(std_picture_info.ref_order_hint, std_picture_info.ref_order_hint + STD_VIDEO_AV1_NUM_REF_FRAMES, 0);
std::fill(std_picture_info.ref_frame_idx, std_picture_info.ref_frame_idx + STD_VIDEO_AV1_REFS_PER_FRAME, static_cast<int8_t>(-1));
std::fill(std_picture_info.delta_frame_id_minus_1, std_picture_info.delta_frame_id_minus_1 + STD_VIDEO_AV1_REFS_PER_FRAME, 0);
std_picture_info.pTileInfo = &tile_info;
std_picture_info.pQuantization = &quantization;
std_picture_info.pSegmentation = (std_picture_info.flags.segmentation_enabled) ? &segmentation : nullptr;
std_picture_info.pLoopFilter = &loop_filter;
std_picture_info.pCDEF = &cdef;
std_picture_info.pLoopRestoration = &loop_restoration;
std_picture_info.pGlobalMotion = &global_motion;
std_picture_info.pExtensionHeader = nullptr;
std_picture_info.pBufferRemovalTimes = nullptr;
// ref_frame_idx[] maps a reference name to a DPB slot, and must be filled in for the same
// reference name that referenceNameSlotIndices uses.
if (has_ref)
std_picture_info.ref_frame_idx[ref_name_index] = static_cast<int8_t>(*ref_slot);
const size_t dpb_ref_count = std::min<size_t>(dpb_std_info.size(), STD_VIDEO_AV1_NUM_REF_FRAMES);
for (size_t i = 0; i < dpb_ref_count; ++i)
std_picture_info.ref_order_hint[i] = dpb_std_info[i].OrderHint;
picture_info = vk::VideoEncodeAV1PictureInfoKHR{};
// WiVRn always predicts from the primary reference, never uses it for CDFs only.
// VUID-VkVideoEncodeAV1PictureInfoKHR-flags-10289
picture_info.primaryReferenceCdfOnly = VK_FALSE;
// Key frames are the only intra frames we produce, everything else predicts from the single
// acknowledged reference frame. Encoders without single reference support are rejected in
// configure_from_caps().
// VUID-vkCmdEncodeVideoKHR-pStdPictureInfo-10327
picture_info.predictionMode = is_keyframe ? vk::VideoEncodeAV1PredictionModeKHR::eIntraOnly
: vk::VideoEncodeAV1PredictionModeKHR::eSingleReference;
// Set rate control group based on frame type
// Note: WiVRn currently doesn't support B-frames, so only INTRA and PREDICTIVE groups
picture_info.rateControlGroup = is_keyframe ? vk::VideoEncodeAV1RateControlGroupKHR::eIntra
: vk::VideoEncodeAV1RateControlGroupKHR::ePredictive;
// Must be zero while rate control is active, and within the reported range otherwise.
// VUID-vkCmdEncodeVideoKHR-constantQIndex-10320, VUID-vkCmdEncodeVideoKHR-constantQIndex-10321
picture_info.constantQIndex = rate_control_enabled ? 0 : std::midpoint(min_q_index, max_q_index);
picture_info.pStdPictureInfo = &std_picture_info;
picture_info.referenceNameSlotIndices = reference_name_slot_indices;
picture_info.generateObuExtensionHeader = VK_FALSE;
auto & i = dpb_std_info[slot];
i = {};
i.flags.disable_frame_end_update_cdf = 0;
i.flags.segmentation_enabled = 0;
// Frame ids are not signalled, see current_frame_id above
i.RefFrameId = 0;
i.frame_type = std_picture_info.frame_type;
i.OrderHint = std_picture_info.order_hint;
i.pExtensionHeader = nullptr;
return &picture_info;
}
const void * wivrn::video_encoder_vulkan_av1::begin_coding_next(const void * next)
{
if (not gop_info)
return next;
gop_info->pNext = next;
return &*gop_info;
}
vk::ExtensionProperties wivrn::video_encoder_vulkan_av1::std_header_version()
{
vk::ExtensionProperties std_header_version{
.specVersion = VK_STD_VULKAN_VIDEO_CODEC_AV1_ENCODE_SPEC_VERSION,
};
strcpy(std_header_version.extensionName,
VK_STD_VULKAN_VIDEO_CODEC_AV1_ENCODE_EXTENSION_NAME);
return std_header_version;
}
+101
View File
@@ -0,0 +1,101 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Patrick Nicolas <patricknicolas@laposte.net>
* Copyright (C) 2026 Philipp Schlegel <dev@phischle.xyz>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include "video_encoder_vulkan.h"
#include <array>
#include <memory>
#include <optional>
#include <vector>
#include <vulkan/vulkan.hpp>
#include <vk_video/vulkan_video_codec_av1std.h>
#include <vk_video/vulkan_video_codec_av1std_encode.h>
namespace wivrn
{
class video_encoder_vulkan_av1 : public video_encoder_vulkan
{
StdVideoAV1ColorConfig color_config{};
StdVideoAV1SequenceHeader seq_header{};
StdVideoAV1TileInfo tile_info{};
StdVideoAV1Quantization quantization{};
StdVideoAV1LoopFilter loop_filter{};
StdVideoAV1CDEF cdef{};
StdVideoAV1LoopRestoration loop_restoration{};
StdVideoAV1GlobalMotion global_motion{};
StdVideoAV1Segmentation segmentation{};
StdVideoEncodeAV1PictureInfo std_picture_info{};
StdVideoEncodeAV1OperatingPointInfo operating_point{};
std::array<int32_t, VK_MAX_VIDEO_AV1_REFERENCES_PER_FRAME_KHR> reference_name_slot_indices{};
std::array<uint16_t, 2> mi_col_starts{};
std::array<uint16_t, 2> mi_row_starts{};
std::array<uint16_t, 1> tile_widths_sb{};
std::array<uint16_t, 1> tile_heights_sb{};
std::vector<StdVideoEncodeAV1ReferenceInfo> dpb_std_info;
std::vector<vk::VideoEncodeAV1DpbSlotInfoKHR> dpb_std_slots;
vk::VideoEncodeAV1PictureInfoKHR picture_info{};
std::optional<vk::VideoEncodeAV1GopRemainingFrameInfoKHR> gop_info;
vk::VideoEncodeQualityLevelInfoKHR quality_level_info{};
vk::VideoEncodeAV1RateControlInfoKHR rate_control_av1{};
vk::VideoEncodeAV1RateControlLayerInfoKHR rate_control_layer_av1{};
vk::VideoEncodeAV1StdFlagsKHR std_flags{};
uint32_t single_reference_name_mask = 0;
uint32_t max_single_reference_count = 0;
uint32_t max_q_index = 0;
uint32_t min_q_index = 0;
uint32_t superblock_size = 64;
uint8_t order_hint_bits = 7;
// Reference name (LAST_FRAME + index) used for the single reference of inter frames
int32_t ref_name_index = 0;
bool rate_control_enabled = false;
StdVideoAV1Level level = STD_VIDEO_AV1_LEVEL_2_0;
video_encoder_vulkan_av1(wivrn::vk_bundle & vk,
const vk::VideoCapabilitiesKHR & video_caps,
const vk::VideoEncodeCapabilitiesKHR & encode_caps,
const vk::VideoEncodeAV1CapabilitiesKHR & encode_av1_caps,
uint8_t stream_idx,
const encoder_settings & settings);
void configure_from_caps(const vk::VideoEncodeAV1CapabilitiesKHR & encode_av1_caps);
protected:
std::vector<void *> setup_slot_info(size_t dpb_size) override;
void * encode_info_next(uint32_t frame_num, size_t slot, std::optional<int32_t> ref_slot) override;
vk::ExtensionProperties std_header_version() override;
const void * begin_coding_next(const void * next) override;
void send_idr_data() override;
public:
static std::unique_ptr<video_encoder_vulkan_av1> create(wivrn::vk_bundle & vk,
const encoder_settings & settings,
uint8_t stream_idx);
};
} // namespace wivrn
+2
View File
@@ -100,6 +100,8 @@ int create_listen_socket()
sockaddr_un addr{};
auto sock_file = socket_path();
if (sock_file.native().size() >= std::size(addr.sun_path))
throw std::runtime_error("Socket file name too long");
addr.sun_family = AF_UNIX;
strcpy(addr.sun_path, sock_file.c_str());
+7
View File
@@ -269,6 +269,9 @@ wivrn::vk_bundle::vk_bundle() :
#ifdef VK_KHR_video_encode_h265
VK_KHR_VIDEO_ENCODE_H265_EXTENSION_NAME,
#endif
#ifdef VK_KHR_video_encode_av1
VK_KHR_VIDEO_ENCODE_AV1_EXTENSION_NAME,
#endif
#ifdef VK_KHR_video_encode_intra_refresh
VK_KHR_VIDEO_ENCODE_INTRA_REFRESH_EXTENSION_NAME,
#endif
@@ -334,6 +337,10 @@ wivrn::vk_bundle::vk_bundle() :
if (has_device_ext(VK_KHR_VIDEO_ENCODE_INTRA_REFRESH_EXTENSION_NAME))
std::get<vk::PhysicalDeviceVideoEncodeIntraRefreshFeaturesKHR>(feat).videoEncodeIntraRefresh = std::get<vk::PhysicalDeviceVideoEncodeIntraRefreshFeaturesKHR>(physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVideoEncodeIntraRefreshFeaturesKHR>()).videoEncodeIntraRefresh;
#endif
#ifdef VK_KHR_video_encode_av1
if (has_device_ext(VK_KHR_VIDEO_ENCODE_AV1_EXTENSION_NAME))
std::get<vk::PhysicalDeviceVideoEncodeAV1FeaturesKHR>(feat).videoEncodeAV1 = std::get<vk::PhysicalDeviceVideoEncodeAV1FeaturesKHR>(physical_device.getFeatures2<vk::PhysicalDeviceFeatures2, vk::PhysicalDeviceVideoEncodeAV1FeaturesKHR>()).videoEncodeAV1;
#endif
#ifdef VK_KHR_unified_image_layouts
if (has_device_ext(VK_KHR_UNIFIED_IMAGE_LAYOUTS_EXTENSION_NAME))
{
+3
View File
@@ -131,6 +131,9 @@ struct vk_bundle
#ifdef VK_KHR_video_encode_intra_refresh
vk::PhysicalDeviceVideoEncodeIntraRefreshFeaturesKHR,
#endif
#ifdef VK_KHR_video_encode_av1
vk::PhysicalDeviceVideoEncodeAV1FeaturesKHR,
#endif
#ifdef VK_KHR_unified_image_layouts
vk::PhysicalDeviceUnifiedImageLayoutsFeaturesKHR,
#endif