Rebase almost everything to Master
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
if (BOOST_FOUND)
|
||||
if (WIVRN_USE_SYSTEM_BOOST)
|
||||
add_library(Boost::pfr ALIAS Boost::headers)
|
||||
elseif (WIVRN_BUILD_CLIENT)
|
||||
FetchContent_MakeAvailable(boost)
|
||||
@@ -50,7 +50,7 @@ if (WIVRN_BUILD_DASHBOARD OR WIVRN_BUILD_SERVER)
|
||||
utils/ini.cpp
|
||||
application.cpp
|
||||
)
|
||||
target_link_libraries(wivrn-common-server PRIVATE nlohmann_json::nlohmann_json PNG::PNG PkgConfig::librsvg-2.0 PUBLIC wivrn-common-base)
|
||||
target_link_libraries(wivrn-common-server PRIVATE nlohmann_json::nlohmann_json PNG::PNG PkgConfig::librsvg-2.0 LibArchive::LibArchive PUBLIC wivrn-common-base)
|
||||
|
||||
if (WIVRN_BUILD_TEST)
|
||||
add_executable(list-apps
|
||||
|
||||
+34
-40
@@ -20,7 +20,6 @@
|
||||
#include "application.h"
|
||||
|
||||
#include "utils/flatpak.h"
|
||||
#include "utils/load_icon.h"
|
||||
#include "utils/steam_app_info.h"
|
||||
#include "utils/xdg_base_directory.h"
|
||||
#include "utils/xdg_icon_lookup.h"
|
||||
@@ -51,20 +50,19 @@ std::filesystem::path home()
|
||||
|
||||
std::pair<std::string, std::optional<std::filesystem::path>> find_steam()
|
||||
{
|
||||
auto h = home();
|
||||
// Flatpak Steam
|
||||
if (std::filesystem::exists(h / ".var/app/com.valvesoftware.Steam/.steam/steam"))
|
||||
return {"flatpak run com.valvesoftware.Steam", h / ".var/app/com.valvesoftware.Steam/.steam/steam"};
|
||||
|
||||
// system Steam
|
||||
if (std::filesystem::exists(xdg_data_home() / "Steam"))
|
||||
return {"steam", xdg_data_home() / "Steam"};
|
||||
|
||||
auto h = home();
|
||||
|
||||
// system Steam (accessed from flatpak)
|
||||
if (std::filesystem::exists(h / ".local/share/Steam"))
|
||||
return {"steam", h / ".local/share/Steam"};
|
||||
|
||||
// Flatpak Steam
|
||||
if (std::filesystem::exists(h / ".var/app/com.valvesoftware.Steam/.steam/steam"))
|
||||
return {"flatpak run com.valvesoftware.Steam", h / ".var/app/com.valvesoftware.Steam/.steam/steam"};
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -85,17 +83,17 @@ steam_app_info read_steam_app_info(const std::filesystem::path & root)
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<std::byte> load_steam_icon(const std::filesystem::path & root, int app_id, const steam_app_info & info)
|
||||
std::optional<std::filesystem::path> find_steam_icon(const std::filesystem::path & root, int app_id, const steam_app_info & info)
|
||||
{
|
||||
const auto & app_info = info.get(app_id);
|
||||
|
||||
try
|
||||
{
|
||||
std::string icon{std::get<std::string_view>(app_info.at("common.clienticon"))};
|
||||
auto icon_path = root / "steam/games" / (icon + ".ico");
|
||||
|
||||
auto image = load_icon(root / "steam/games" / (icon + ".ico"), 128);
|
||||
if (not image.empty())
|
||||
return image;
|
||||
if (std::filesystem::exists(icon_path))
|
||||
return icon_path;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -103,20 +101,21 @@ std::vector<std::byte> load_steam_icon(const std::filesystem::path & root, int a
|
||||
|
||||
try
|
||||
{
|
||||
std::string icon{std::get<std::string_view>(app_info.at("common.LinuxClientIcon"))};
|
||||
std::string icon{std::get<std::string_view>(app_info.at("common.linuxclienticon"))};
|
||||
|
||||
auto image = load_icon(root / "steam/games" / (icon + ".zip"), 128);
|
||||
if (not image.empty())
|
||||
return image;
|
||||
auto icon_path = root / "steam/games" / (icon + ".zip");
|
||||
|
||||
if (std::filesystem::exists(icon_path))
|
||||
return icon_path;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
|
||||
return {};
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void read_steam_vr_apps(std::unordered_map<std::string, application> & res, bool load_icons)
|
||||
void read_steam_vr_apps(std::unordered_map<std::string, application> & res)
|
||||
{
|
||||
auto [command, root] = find_steam();
|
||||
if (not root)
|
||||
@@ -166,21 +165,18 @@ void read_steam_vr_apps(std::unordered_map<std::string, application> & res, bool
|
||||
}
|
||||
}
|
||||
|
||||
if (load_icons)
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
const char prefix[] = "steam.app.";
|
||||
if (app_key.starts_with(prefix))
|
||||
{
|
||||
uint32_t app_id = stoll(app_key.substr(strlen(prefix)));
|
||||
app.image = load_steam_icon(*root, app_id, info);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
const char prefix[] = "steam.app.";
|
||||
if (app_key.starts_with(prefix))
|
||||
{
|
||||
uint32_t app_id = stoll(app_key.substr(strlen(prefix)));
|
||||
app.icon_path = find_steam_icon(*root, app_id, info);
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
|
||||
if (not app.exec.empty())
|
||||
res[app_key] = std::move(app);
|
||||
@@ -281,7 +277,7 @@ bool contains(std::string_view entries, std::string_view val, char sep = ';')
|
||||
return false;
|
||||
}
|
||||
|
||||
std::optional<application> do_desktop_entry(const std::filesystem::path & filename, bool load_icons)
|
||||
std::optional<application> do_desktop_entry(const std::filesystem::path & filename)
|
||||
{
|
||||
auto data = read_file(filename);
|
||||
std::optional<application> res;
|
||||
@@ -323,12 +319,11 @@ std::optional<application> do_desktop_entry(const std::filesystem::path & filena
|
||||
res->exec = unescape(item.value);
|
||||
if (item.key == "Path")
|
||||
res->path = unescape(item.value);
|
||||
if (item.key == "Icon" and load_icons)
|
||||
if (item.key == "Icon")
|
||||
{
|
||||
try
|
||||
{
|
||||
if (auto filename = xdg_icon_lookup(std::string{item.value}, 256))
|
||||
res->image = load_icon(*filename, 256);
|
||||
res->icon_path = xdg_icon_lookup(std::string{item.value}, 256);
|
||||
}
|
||||
catch (...)
|
||||
{}
|
||||
@@ -341,7 +336,7 @@ std::optional<application> do_desktop_entry(const std::filesystem::path & filena
|
||||
return res;
|
||||
}
|
||||
|
||||
void do_data_dir(std::filesystem::path dir, std::unordered_map<std::string, application> & res, bool load_icons)
|
||||
void do_data_dir(std::filesystem::path dir, std::unordered_map<std::string, application> & res)
|
||||
{
|
||||
dir = dir / "applications";
|
||||
if (not std::filesystem::is_directory(dir))
|
||||
@@ -364,29 +359,28 @@ void do_data_dir(std::filesystem::path dir, std::unordered_map<std::string, appl
|
||||
if (res.contains(file_id))
|
||||
continue;
|
||||
|
||||
auto app = do_desktop_entry(entry.path(), load_icons);
|
||||
auto app = do_desktop_entry(entry.path());
|
||||
if (app)
|
||||
res.emplace(std::move(file_id), std::move(*app));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::unordered_map<std::string, application> list_applications(bool include_steam, bool load_icons)
|
||||
std::unordered_map<std::string, application> list_applications()
|
||||
{
|
||||
std::unordered_map<std::string, application> res;
|
||||
|
||||
if (include_steam)
|
||||
read_steam_vr_apps(res, load_icons);
|
||||
read_steam_vr_apps(res);
|
||||
|
||||
do_data_dir(xdg_data_home(), res, load_icons);
|
||||
do_data_dir(xdg_data_home(), res);
|
||||
|
||||
for (auto && dir: xdg_data_dirs())
|
||||
do_data_dir(std::move(dir), res, load_icons);
|
||||
do_data_dir(std::move(dir), res);
|
||||
|
||||
if (wivrn::is_flatpak())
|
||||
{
|
||||
// Try to guess host data dirs
|
||||
do_data_dir("/run/host/usr/share", res, load_icons);
|
||||
do_data_dir("/run/host/usr/share", res);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
@@ -31,9 +31,9 @@ struct application
|
||||
// localised names, with empty locale for default
|
||||
std::unordered_map<std::string, std::string> name;
|
||||
std::string exec;
|
||||
std::vector<std::byte> image; // In PNG
|
||||
std::optional<std::filesystem::path> icon_path;
|
||||
std::optional<std::string> path;
|
||||
};
|
||||
|
||||
std::unordered_map<std::string, application> list_applications(bool include_steam = true, bool load_icons = true);
|
||||
std::unordered_map<std::string, application> list_applications();
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -23,5 +23,13 @@
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
const std::vector<std::byte> & load_icon(const std::filesystem::path & filename, int size);
|
||||
}
|
||||
struct icon
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int bpp;
|
||||
std::vector<std::byte> png_data;
|
||||
};
|
||||
|
||||
const std::vector<icon> & load_icon(const std::filesystem::path & filename);
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "steam_app_info.h"
|
||||
#include <bit>
|
||||
#include <cctype>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <span>
|
||||
@@ -89,6 +90,8 @@ void read_vdf(wivrn::steam_app_info::info & info, const std::string & prefix, st
|
||||
while (type != 8)
|
||||
{
|
||||
std::string name{string_table.at(read<uint32_t>(bindata))};
|
||||
for (char & c: name)
|
||||
c = std::tolower(c);
|
||||
|
||||
// https://github.com/ValveResourceFormat/ValveKeyValue/blob/master/ValveKeyValue/ValveKeyValue/KeyValues1/KV1BinaryNodeType.cs
|
||||
switch (type)
|
||||
|
||||
@@ -131,6 +131,12 @@ public:
|
||||
std::tie(resource, allocation) = traits::create(device, create_info, alloc_info);
|
||||
|
||||
vmaSetAllocationName(vk_allocator::instance(), allocation, name.c_str());
|
||||
if (vk_allocator::instance().has_debug_utils)
|
||||
device.setDebugUtilsObjectNameEXT(vk::DebugUtilsObjectNameInfoEXT{
|
||||
.objectType = T::objectType,
|
||||
.objectHandle = uint64_t(CType(*resource)),
|
||||
.pObjectName = name.c_str(),
|
||||
});
|
||||
}
|
||||
|
||||
basic_allocation(const basic_allocation &) = delete;
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* WiVRn VR streaming
|
||||
* Copyright (C) 2025 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 <array>
|
||||
#include <cstdint>
|
||||
#include <tuple>
|
||||
#include <vulkan/vulkan.hpp>
|
||||
|
||||
template <typename... Args>
|
||||
class specialization_constants
|
||||
{
|
||||
std::tuple<Args...> values;
|
||||
std::array<vk::SpecializationMapEntry, sizeof...(Args)> entries;
|
||||
vk::SpecializationInfo info_;
|
||||
|
||||
specialization_constants(specialization_constants &&) = delete;
|
||||
specialization_constants(const specialization_constants &) = delete;
|
||||
specialization_constants & operator=(const specialization_constants &) = delete;
|
||||
specialization_constants & operator=(specialization_constants &&) = delete;
|
||||
|
||||
template <uint32_t i = sizeof...(Args) - 1>
|
||||
void fill_entries()
|
||||
{
|
||||
entries[i] = vk::SpecializationMapEntry{
|
||||
.constantID = i,
|
||||
.offset = uint32_t(uintptr_t(std::addressof(std::get<i>(values))) - uintptr_t(std::addressof(values))),
|
||||
.size = sizeof(std::get<i>(values)),
|
||||
};
|
||||
if constexpr (i > 0)
|
||||
fill_entries<i - 1>();
|
||||
}
|
||||
|
||||
public:
|
||||
specialization_constants(Args &&... args) :
|
||||
values(std::forward<Args>(args)...),
|
||||
info_{
|
||||
.mapEntryCount = uint32_t(entries.size()),
|
||||
.pMapEntries = entries.data(),
|
||||
.dataSize = sizeof(values),
|
||||
.pData = &values,
|
||||
}
|
||||
{
|
||||
fill_entries();
|
||||
}
|
||||
|
||||
operator vk::SpecializationInfo *()
|
||||
{
|
||||
return &info_;
|
||||
}
|
||||
|
||||
vk::SpecializationInfo * info()
|
||||
{
|
||||
return &info_;
|
||||
}
|
||||
|
||||
template <uint32_t i>
|
||||
auto & data()
|
||||
{
|
||||
return std::get<i>(values);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
specialization_constants<Args...> make_specialization_constants(Args &&... args)
|
||||
{
|
||||
return specialization_constants<Args...>(std::forward<Args>(args)...);
|
||||
}
|
||||
@@ -20,7 +20,8 @@
|
||||
#include "vk_allocator.h"
|
||||
#include "vk/check.h"
|
||||
|
||||
vk_allocator::vk_allocator(const VmaAllocatorCreateInfo & info)
|
||||
vk_allocator::vk_allocator(const VmaAllocatorCreateInfo & info, bool has_debug_utils) :
|
||||
has_debug_utils(has_debug_utils)
|
||||
{
|
||||
CHECK_VK(vmaCreateAllocator(&info, &handle));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ class vk_allocator : public singleton<vk_allocator>
|
||||
VmaAllocator handle = nullptr;
|
||||
|
||||
public:
|
||||
vk_allocator(const VmaAllocatorCreateInfo &);
|
||||
const bool has_debug_utils;
|
||||
vk_allocator(const VmaAllocatorCreateInfo &, bool has_debug_utils);
|
||||
~vk_allocator();
|
||||
|
||||
operator VmaAllocator()
|
||||
|
||||
+14
-3
@@ -41,7 +41,7 @@ namespace wivrn
|
||||
// Default port for server to listen, both TCP and UDP
|
||||
static const int default_port = 9757;
|
||||
|
||||
static constexpr int protocol_revision = 2;
|
||||
static constexpr int protocol_revision = 1;
|
||||
|
||||
enum class device_id : uint8_t
|
||||
{
|
||||
@@ -239,6 +239,11 @@ struct headset_info_packet
|
||||
uint32_t num_generic_trackers;
|
||||
std::vector<video_codec> supported_codecs; // from preferred to least preferred
|
||||
std::string system_name;
|
||||
|
||||
// Used for the application list
|
||||
std::string language;
|
||||
std::string country;
|
||||
std::string variant;
|
||||
};
|
||||
|
||||
struct handshake
|
||||
@@ -675,11 +680,16 @@ struct application_list
|
||||
{
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::vector<std::byte> image; // In PNG
|
||||
};
|
||||
std::vector<application> applications;
|
||||
};
|
||||
|
||||
struct application_icon
|
||||
{
|
||||
std::string id;
|
||||
std::vector<std::byte> image; // In PNG
|
||||
};
|
||||
|
||||
using packets = std::variant<
|
||||
crypto_handshake,
|
||||
pin_check_2,
|
||||
@@ -693,6 +703,7 @@ using packets = std::variant<
|
||||
timesync_query,
|
||||
tracking_control,
|
||||
refresh_rate_change,
|
||||
application_list>;
|
||||
application_list,
|
||||
application_icon>;
|
||||
} // namespace to_headset
|
||||
} // namespace wivrn
|
||||
|
||||
@@ -69,10 +69,9 @@ wivrn::fd_base::~fd_base()
|
||||
wivrn::UDP::UDP()
|
||||
{
|
||||
fd = socket(AF_INET6, SOCK_DGRAM, 0);
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
|
||||
if (fd < 0)
|
||||
throw std::system_error{errno, std::generic_category()};
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
}
|
||||
|
||||
wivrn::UDP::UDP(int fd)
|
||||
@@ -177,10 +176,9 @@ wivrn::TCP::TCP(int fd)
|
||||
wivrn::TCP::TCP(in6_addr address, int port)
|
||||
{
|
||||
fd = socket(AF_INET6, SOCK_STREAM, 0);
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
|
||||
if (fd < 0)
|
||||
throw std::system_error{errno, std::generic_category()};
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
|
||||
sockaddr_in6 sa;
|
||||
sa.sin6_family = AF_INET6;
|
||||
@@ -199,10 +197,9 @@ wivrn::TCP::TCP(in6_addr address, int port)
|
||||
wivrn::TCP::TCP(in_addr address, int port)
|
||||
{
|
||||
fd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
|
||||
if (fd < 0)
|
||||
throw std::system_error{errno, std::generic_category()};
|
||||
fcntl(fd, F_SETFD, FD_CLOEXEC);
|
||||
|
||||
sockaddr_in sa;
|
||||
sa.sin_family = AF_INET;
|
||||
|
||||
Reference in New Issue
Block a user