Set the current active runtime when a headset connects
This commit is contained in:
+3
-26
@@ -58,6 +58,7 @@
|
||||
#include "jnipp.h"
|
||||
#else
|
||||
#include <signal.h>
|
||||
#include "utils/xdg_base_directory.h"
|
||||
#endif
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
@@ -293,30 +294,6 @@ static XrActionType guess_action_type(const std::string & name)
|
||||
return XR_ACTION_TYPE_FLOAT_INPUT;
|
||||
}
|
||||
|
||||
#ifndef __ANDROID__
|
||||
static std::filesystem::path get_config_base_dir()
|
||||
{
|
||||
const char * xdg_config_home = std::getenv("XDG_CONFIG_HOME");
|
||||
if (xdg_config_home)
|
||||
return xdg_config_home;
|
||||
const char * home = std::getenv("HOME");
|
||||
if (home)
|
||||
return std::filesystem::path(home) / ".config";
|
||||
return ".";
|
||||
}
|
||||
|
||||
static std::filesystem::path get_cache_base_dir()
|
||||
{
|
||||
const char * xdg_cache_home = std::getenv("XDG_CACHE_HOME");
|
||||
if (xdg_cache_home)
|
||||
return xdg_cache_home;
|
||||
const char * home = std::getenv("HOME");
|
||||
if (home)
|
||||
return std::filesystem::path(home) / ".cache";
|
||||
return ".";
|
||||
}
|
||||
#endif
|
||||
|
||||
VkBool32 application::vulkan_debug_report_callback(
|
||||
VkDebugReportFlagsEXT flags,
|
||||
VkDebugReportObjectTypeEXT objectType,
|
||||
@@ -927,8 +904,8 @@ application::application(application_info info) :
|
||||
}
|
||||
|
||||
#else
|
||||
config_path = get_config_base_dir() / "wivrn";
|
||||
cache_path = get_cache_base_dir() / "wivrn";
|
||||
config_path = xdg_config_home() / "wivrn";
|
||||
cache_path = xdg_cache_home() / "wivrn";
|
||||
#endif
|
||||
|
||||
std::filesystem::create_directories(config_path);
|
||||
|
||||
@@ -24,6 +24,7 @@ configure_file(wivrn_config.h.in wivrn_config.h)
|
||||
|
||||
add_library(wivrn-common STATIC
|
||||
wivrn_sockets.cpp
|
||||
utils/xdg_base_directory.cpp
|
||||
vk/allocation.cpp
|
||||
vk/error_category.cpp
|
||||
vk/vk_allocator.cpp
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2024 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 <filesystem>
|
||||
#include <cstdlib>
|
||||
|
||||
std::filesystem::path xdg_config_home()
|
||||
{
|
||||
const char * xdg_config_home = std::getenv("XDG_CONFIG_HOME");
|
||||
if (xdg_config_home)
|
||||
return xdg_config_home;
|
||||
const char * home = std::getenv("HOME");
|
||||
if (home)
|
||||
return std::filesystem::path(home) / ".config";
|
||||
return ".";
|
||||
}
|
||||
|
||||
std::filesystem::path xdg_cache_home()
|
||||
{
|
||||
const char * xdg_cache_home = std::getenv("XDG_CACHE_HOME");
|
||||
if (xdg_cache_home)
|
||||
return xdg_cache_home;
|
||||
const char * home = std::getenv("HOME");
|
||||
if (home)
|
||||
return std::filesystem::path(home) / ".cache";
|
||||
return ".";
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
|
||||
* Copyright (C) 2024 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 <filesystem>
|
||||
|
||||
std::filesystem::path xdg_config_home();
|
||||
std::filesystem::path xdg_cache_home();
|
||||
@@ -24,3 +24,5 @@
|
||||
#cmakedefine WIVRN_USE_X264
|
||||
|
||||
#cmakedefine WIVRN_USE_SYSTEMD
|
||||
|
||||
#define WIVRN_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"
|
||||
|
||||
@@ -57,10 +57,11 @@ endif()
|
||||
|
||||
|
||||
add_executable(wivrn-server
|
||||
main.cpp
|
||||
target_instance_wivrn.cpp
|
||||
active_runtime.cpp
|
||||
avahi_publisher.cpp
|
||||
hostname.cpp
|
||||
main.cpp
|
||||
target_instance_wivrn.cpp
|
||||
wivrn_ipc.cpp
|
||||
|
||||
encoder/encoder_settings.cpp
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.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 "active_runtime.h"
|
||||
#include "utils/xdg_base_directory.h"
|
||||
#include "wivrn_config.h"
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
active_runtime::active_runtime() : pid(getpid()), active_runtime_json(xdg_config_home() / "openxr" / "1" / "active_runtime.json")
|
||||
{
|
||||
try
|
||||
{
|
||||
if (std::filesystem::exists(active_runtime_json))
|
||||
return;
|
||||
|
||||
std::filesystem::create_directories(active_runtime_json.parent_path());
|
||||
|
||||
auto exe = std::filesystem::read_symlink("/proc/self/exe");
|
||||
auto openxr_wivrn_json = exe.parent_path().parent_path() / "openxr_wivrn-dev.json";
|
||||
if (!std::filesystem::exists(openxr_wivrn_json))
|
||||
openxr_wivrn_json = std::filesystem::path(WIVRN_INSTALL_PREFIX) / "share" / "openxr" / "1" / "openxr_wivrn.json";
|
||||
|
||||
std::filesystem::create_symlink(openxr_wivrn_json, active_runtime_json);
|
||||
|
||||
to_be_deleted = true;
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cerr << "Cannot set active OpenXR runtime: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
active_runtime::~active_runtime()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (pid == getpid() && to_be_deleted)
|
||||
{
|
||||
std::filesystem::remove(active_runtime_json);
|
||||
}
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cerr << "Cannot unset active OpenXR runtime: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.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 <unistd.h>
|
||||
#include <filesystem>
|
||||
|
||||
class active_runtime
|
||||
{
|
||||
bool to_be_deleted = false;
|
||||
std::filesystem::path active_runtime_json;
|
||||
pid_t pid;
|
||||
|
||||
public:
|
||||
active_runtime();
|
||||
active_runtime(const active_runtime&) = delete;
|
||||
active_runtime& operator=(const active_runtime&) = delete;
|
||||
~active_runtime();
|
||||
};
|
||||
@@ -31,26 +31,16 @@
|
||||
#include "util/u_logging.h"
|
||||
|
||||
#include "configuration.h"
|
||||
|
||||
static std::filesystem::path get_config_base_dir()
|
||||
{
|
||||
const char * xdg_config_home = std::getenv("XDG_CONFIG_HOME");
|
||||
if (xdg_config_home)
|
||||
return xdg_config_home;
|
||||
const char * home = std::getenv("HOME");
|
||||
if (home)
|
||||
return std::filesystem::path(home) / ".config";
|
||||
return ".";
|
||||
}
|
||||
#include "utils/xdg_base_directory.h"
|
||||
|
||||
static std::filesystem::path get_config_file()
|
||||
{
|
||||
return get_config_base_dir() / "wivrn" / "config.json";
|
||||
return xdg_config_home() / "wivrn" / "config.json";
|
||||
}
|
||||
|
||||
static std::filesystem::path get_cookie_file()
|
||||
{
|
||||
return get_config_base_dir() / "wivrn" / "cookie";
|
||||
return xdg_config_home() / "wivrn" / "cookie";
|
||||
}
|
||||
|
||||
namespace xrt::drivers::wivrn
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "hostname.h"
|
||||
#include <shared/ipc_protocol.h>
|
||||
#include <util/u_file.h>
|
||||
#include "active_runtime.h"
|
||||
|
||||
// Insert the on load constructor to init trace marker.
|
||||
U_TRACE_TARGET_SETUP(U_TRACE_WHICH_SERVICE)
|
||||
@@ -237,6 +238,8 @@ int inner_main(int argc, char * argv[])
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
active_runtime runtime_setter;
|
||||
|
||||
pid_t client_pid = start_application();
|
||||
|
||||
pid_t server_pid = fork();
|
||||
|
||||
Reference in New Issue
Block a user