Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
Loading...
Searching...
No Matches
Go to the documentation of this file.
1
5#pragma once
6
7// standard includes
8#include <chrono>
9#include <fcntl.h>
10#include <filesystem>
11#include <thread>
12#include <unistd.h>
13#include <vector>
14
15// local includes
16#include "src/utility.h"
17
18#ifndef DOXYGEN
19KITTY_USING_MOVE_T(file_t, int, -1, {
20 if (el >= 0) {
21 close(el);
22 }
23});
24#else
28class file_t;
29#endif
30
34enum class window_system_e {
35 NONE,
37 WAYLAND,
38};
39
41
42namespace dyn {
46 struct library_t;
47
51 using apiproc = void (*)(void);
52
60 int load(library_t *handle, const std::vector<std::tuple<apiproc *, const char *>> &funcs, bool strict = true);
65 library_t *handle(const std::vector<const char *> &libs);
66
67} // namespace dyn
68
69#ifdef SUNSHINE_BUILD_PORTAL
70namespace portal {
76 bool has_saved_token();
77
81 void clear_saved_token();
82
88 std::filesystem::path get_saved_token_path();
89
90 #ifdef SUNSHINE_TESTS
98 std::filesystem::path get_saved_token_path_for_testing(const std::filesystem::path &directory, const std::string &desktop);
99 #endif
100
106 bool is_portal_service_reachable();
107
108 inline std::jthread xdg_worker;
109 inline std::once_flag xdg_worker_flag;
110} // namespace portal
111#endif
112
113namespace platf {
123
141 int open_drm_card_fd(const std::filesystem::path &path, int flags = O_RDWR);
142
152 inline void handle_pacing(std::chrono::steady_clock::time_point &next_frame, std::chrono::nanoseconds delay, auto &logger) {
153 auto now = std::chrono::steady_clock::now();
154
155 if (next_frame > now) {
156 std::this_thread::sleep_until(next_frame);
157 logger.first_point(next_frame);
158 logger.second_point_now_and_log();
159 }
160
161 next_frame += delay;
162 if (next_frame < now) { // some major slowdown happened; we couldn't keep up
163 next_frame = now + delay;
164 }
165 }
166
167#if defined(__linux__) && defined(SUNSHINE_BUILD_DRM)
168 namespace kms {
176 void ensure_privileged_drm_worker_started();
177
181 void drop_drm_worker_privileges();
182
189 int privileged_open_drm_card_fd(const char *path);
190 } // namespace kms
191#endif
192} // namespace platf
int close(int __fd)
Release the native resource held by the RAII wrapper.
bool sanitize_process_environment()
Remove environment variables that can load untrusted GUI modules.
Definition misc.cpp:192
int open_drm_card_fd(const std::filesystem::path &path, int flags)
Open a DRM card node, dropping implicit DRM master when possible.
Definition misc.cpp:212
int load(library_t *handle, const std::vector< std::tuple< apiproc *, const char * > > &funcs, bool strict)
Load named functions from an open shared library.
Definition misc.cpp:139
window_system_e window_system
Window system.
Definition misc.cpp:107
library_t * handle(const std::vector< const char * > &libs)
Open the first available shared library from a nonempty list.
Definition misc.cpp:113
void handle_pacing(std::chrono::steady_clock::time_point &next_frame, std::chrono::nanoseconds delay, auto &logger)
Generic frame pacing logic for Linux capture methods.
Definition misc.h:152
void(*)(void) apiproc
Generic GLX procedure pointer returned by the loader.
Definition misc.h:51
window_system_e
Enumerates supported window system options.
Definition misc.h:34
@ X11
X11.
Definition misc.h:36
util::safe_ptr_v2< FILE, int, &fclose > file_t
Boost.Process pipe stream used for child-process I/O.
Definition process.h:36
Declarations for utility functions.
#define KITTY_USING_MOVE_T(move_t, t, init_val, z)
Define a move-only RAII wrapper with caller-provided initial value and destructor body.
Definition utility.h:51