Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
process.h File Reference

Declarations for the startup and shutdown of the apps started by a streaming Session. More...

#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
#include <boost/process/v1/child.hpp>
#include <boost/process/v1/group.hpp>
#include <boost/process/v1/environment.hpp>
#include <boost/process/v1/search_path.hpp>
#include <boost/property_tree/ptree.hpp>
#include <nlohmann/json.hpp>
#include "config.h"
#include "platform/common.h"
#include "rtsp.h"
#include "utility.h"
#include "platform/linux/virtual_display.h"
Include dependency graph for process.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  proc::ctx_t
struct  proc::virtual_display_decision_t
struct  proc::scale_factor_decision_t
class  proc::proc_t
struct  proc::proc_t::isolated_session_t
 One live isolated session, as the host needs to see it. More...

Macros

#define __kernel_entry
#define BOOST_PROCESS_VERSION   1
#define VIRTUAL_DISPLAY_UUID   "8902CB19-674A-403D-A587-41B092E900BA"
#define FALLBACK_DESKTOP_UUID   "EAAC6159-089A-46A9-9E24-6436885F6610"
#define REMOTE_INPUT_UUID   "8CB5C136-DA67-4F99-B4A1-F9CD35005CF4"
#define TERMINATE_APP_UUID   "E16CBE1B-295D-4632-9A76-EC4180C857D3"
#define DETACHED_DESKTOP_UUID   "5B1C7E0A-3D52-4F8E-9A61-2E7D0C4B9F13"
#define DETACHED_STEAM_UUID   "A4E2F6C8-1B37-4D95-8C0E-7F3A9D2B6E51"

Typedefs

using proc::file_t = util::safe_ptr_v2<FILE, int, fclose>
typedef config::prep_cmd_t proc::cmd_t

Enumerations

enum class  proc::session_route_e { shared , isolated_application , isolated_desktop }
enum class  proc::virtual_display_source_e { headless , app_forced , client , default_rule }
enum class  proc::scale_factor_source_e { app_forced , client , app , host_default }

Functions

bool proc::launch_requests_virtual_display (const ctx_t &app, const rtsp_stream::launch_session_t &launch_session, bool headless_mode)
virtual_display_decision_t proc::decide_virtual_display (const ctx_t &app, const rtsp_stream::launch_session_t &launch_session, bool headless_mode)
std::string_view proc::describe (virtual_display_source_e source)
scale_factor_decision_t proc::decide_scale_factor (const ctx_t &app, const rtsp_stream::launch_session_t &launch_session, int host_default)
std::string_view proc::describe (scale_factor_source_e source)
session_route_e proc::resolve_session_route (const ctx_t &app, bool isolated_sessions_enabled, bool virtual_display_requested, std::string_view global_method)
void proc::migration_v7 (nlohmann::json &fileTree)
boost::filesystem::path proc::find_working_directory (const std::string &cmd, const boost::process::v1::environment &env)
std::tuple< std::string, std::string > proc::calculate_app_id (const std::string &app_name, std::string app_image_path, int index)
 Calculate a stable id based on name and image data.
std::string proc::validate_app_image_path (std::string app_image_path)
void proc::refresh (const std::string &file_name, bool needs_terminate)
void proc::migrate_apps (nlohmann::json *fileTree_p, nlohmann::json *inputTree_p)
 Migrate the applications stored in the file tree by merging in a new app.
std::optional< proc::proc_t > proc::parse (const std::string &file_name, bool fallback_on_failure=true)
 Load the applications from apps.json.
std::unique_ptr< platf::deinit_t > proc::init ()
 Initialize proc functions.
void proc::initVDisplayDriver ()
 Initialize the virtual display driver. This should be called early in startup to enable virtual display support.
void proc::terminate_process_group (boost::process::v1::child &proc, boost::process::v1::group &group, std::chrono::seconds exit_timeout)
 Terminates all child processes in a process group.

Detailed Description

Declarations for the startup and shutdown of the apps started by a streaming Session.

Definition in file process.h.

Macro Definition Documentation

◆ __kernel_entry

#define __kernel_entry

Definition at line 8 of file process.h.

◆ BOOST_PROCESS_VERSION

#define BOOST_PROCESS_VERSION   1

Definition at line 12 of file process.h.

◆ DETACHED_DESKTOP_UUID

#define DETACHED_DESKTOP_UUID   "5B1C7E0A-3D52-4F8E-9A61-2E7D0C4B9F13"

Definition at line 42 of file process.h.

◆ DETACHED_STEAM_UUID

#define DETACHED_STEAM_UUID   "A4E2F6C8-1B37-4D95-8C0E-7F3A9D2B6E51"

Definition at line 43 of file process.h.

◆ FALLBACK_DESKTOP_UUID

#define FALLBACK_DESKTOP_UUID   "EAAC6159-089A-46A9-9E24-6436885F6610"

Definition at line 39 of file process.h.

◆ REMOTE_INPUT_UUID

#define REMOTE_INPUT_UUID   "8CB5C136-DA67-4F99-B4A1-F9CD35005CF4"

Definition at line 40 of file process.h.

◆ TERMINATE_APP_UUID

#define TERMINATE_APP_UUID   "E16CBE1B-295D-4632-9A76-EC4180C857D3"

Definition at line 41 of file process.h.

◆ VIRTUAL_DISPLAY_UUID

#define VIRTUAL_DISPLAY_UUID   "8902CB19-674A-403D-A587-41B092E900BA"

Definition at line 38 of file process.h.

Typedef Documentation

◆ cmd_t

typedef config::prep_cmd_t proc::cmd_t

Definition at line 50 of file process.h.

◆ file_t

using proc::file_t = util::safe_ptr_v2<FILE, int, fclose>

Definition at line 46 of file process.h.

Enumeration Type Documentation

◆ scale_factor_source_e

enum class proc::scale_factor_source_e
strong

Who decided a launch's resolution scale.

Enumerator
app_forced 

The app forces its scale on every client.

client 

The client sent a scale.

app 

The client sent none; the app's own scale.

host_default 

Neither did; the host's default_scale_factor.

Definition at line 198 of file process.h.

◆ session_route_e

enum class proc::session_route_e
strong

Where a launch belongs when independent Hermes-KMS sessions are available.

This is deliberately a per-launch decision. Enabling the capability must not move ordinary host-desktop applications into a private compositor.

Definition at line 58 of file process.h.

◆ virtual_display_source_e

enum class proc::virtual_display_source_e
strong

Who decided whether a launch uses a virtual display.

Enumerator
headless 

The host runs headless; there is nothing else to stream.

app_forced 

The app forces its setting on every client.

client 

The client chose (Hestia's session/prepare).

default_rule 

No explicit choice: client request, per-client or app setting.

Definition at line 168 of file process.h.

Function Documentation

◆ calculate_app_id()

std::tuple< std::string, std::string > proc::calculate_app_id ( const std::string & app_name,
std::string app_image_path,
int index )

Calculate a stable id based on name and image data.

Returns
Tuple of id calculated without index (for use if no collision) and one with.

Definition at line 4470 of file process.cpp.

◆ decide_scale_factor()

scale_factor_decision_t proc::decide_scale_factor ( const ctx_t & app,
const rtsp_stream::launch_session_t & launch_session,
int host_default )

Decide a launch's resolution scale: an app that forces its scale wins, then the client's, then the app's own when it is not 100, then the host default.

Definition at line 148 of file process.cpp.

◆ decide_virtual_display()

virtual_display_decision_t proc::decide_virtual_display ( const ctx_t & app,
const rtsp_stream::launch_session_t & launch_session,
bool headless_mode )

Decide whether a launch uses a virtual display.

Headless mode always does. An app that forces its setting wins next, on or off. Otherwise a client that stated a choice gets it. Without one, the launch uses a virtual display if the client asked for one or the app's setting is on, as before.

Definition at line 109 of file process.cpp.

◆ describe() [1/2]

std::string_view proc::describe ( scale_factor_source_e source)

Definition at line 165 of file process.cpp.

◆ describe() [2/2]

std::string_view proc::describe ( virtual_display_source_e source)

A phrase for the log: "forced by the app", "the client's choice", ...

Definition at line 126 of file process.cpp.

◆ find_working_directory()

boost::filesystem::path proc::find_working_directory ( const std::string & cmd,
const boost::process::v1::environment & env )

Definition at line 1685 of file process.cpp.

◆ init()

std::unique_ptr< platf::deinit_t > proc::init ( )

Initialize proc functions.

Returns
Unique pointer to deinit_t to manage cleanup

Definition at line 1601 of file process.cpp.

◆ initVDisplayDriver()

void proc::initVDisplayDriver ( )

Initialize the virtual display driver. This should be called early in startup to enable virtual display support.

Definition at line 1580 of file process.cpp.

◆ launch_requests_virtual_display()

bool proc::launch_requests_virtual_display ( const ctx_t & app,
const rtsp_stream::launch_session_t & launch_session,
bool headless_mode )

Return whether policy explicitly requests a virtual display for this launch.

This is intentionally narrower than the legacy execute() fallback that may create a display merely because no active display is available. Losing a monitor must not by itself change session ownership.

Definition at line 140 of file process.cpp.

◆ migrate_apps()

void proc::migrate_apps ( nlohmann::json * fileTree_p,
nlohmann::json * inputTree_p )

Migrate the applications stored in the file tree by merging in a new app.

This function updates the application entries in fileTree_p using the data in inputTree_p. If an app in the file tree does not have a UUID, one is generated and inserted. If an app with the same UUID as the new app is found, it is replaced. Additionally, empty keys (such as "prep-cmd" or "detached") and keys no longer needed ("launching", "index") are removed from the input.

Legacy versions of Sunshine/Apollo stored boolean and integer values as strings. The following keys are converted:

  • Boolean keys: "exclude-global-prep-cmd", "elevated", "auto-detach", "wait-all", "use-app-identity", "per-client-app-identity", "virtual-display"
  • Integer keys: "exit-timeout"

A migration version is stored in the file tree (under "version") so that future changes can be applied.

Parameters
fileTree_pPointer to the JSON object representing the file tree.
inputTree_pPointer to the JSON object representing the new app.

Definition at line 4521 of file process.cpp.

◆ migration_v7()

void proc::migration_v7 ( nlohmann::json & fileTree)

v7: session-type became isolation-method, named after what each value runs; "shared" never was a way to isolate, so it became the host-session flag. Hermes' own entries lose "Detached" from their names unless the user renamed them.

Rename session-type to isolation-method in a parsed apps.json.

Definition at line 4796 of file process.cpp.

◆ parse()

std::optional< proc::proc_t > proc::parse ( const std::string & file_name,
bool fallback_on_failure = true )

Load the applications from apps.json.

Parameters
file_nameThe apps file.
fallback_on_failureWhen the file can't be loaded, return the fallback Desktop and built-in entries (startup) instead of nothing (a reload, which keeps the current list).
Returns
The loaded applications, or std::nullopt when the file couldn't be loaded and no fallback was asked for.

Definition at line 4864 of file process.cpp.

◆ refresh()

void proc::refresh ( const std::string & file_name,
bool needs_terminate )

Definition at line 5251 of file process.cpp.

◆ resolve_session_route()

session_route_e proc::resolve_session_route ( const ctx_t & app,
bool isolated_sessions_enabled,
bool virtual_display_requested,
std::string_view global_method = "gamescope" )

Resolve a launch to the host session or an independent private session.

An app's own isolation method always applies. An app on the default follows global_method when a virtual display is requested, unless its layout places that display on the host desktop. host-session apps always stay on the host.

Definition at line 179 of file process.cpp.

◆ terminate_process_group()

void proc::terminate_process_group ( boost::process::v1::child & proc,
boost::process::v1::group & group,
std::chrono::seconds exit_timeout )

Terminates all child processes in a process group.

Parameters
procThe child process itself.
groupThe group of all children in the process tree.
exit_timeoutThe timeout to wait for the process group to gracefully exit.

Definition at line 1611 of file process.cpp.

◆ validate_app_image_path()

std::string proc::validate_app_image_path ( std::string app_image_path)

Definition at line 4393 of file process.cpp.