13#include <boost/core/noncopyable.hpp>
15 #include <boost/asio.hpp>
16 #include <boost/process.hpp>
26#include <moonlight-common-c/src/Limelight.h>
29using namespace std::literals;
34struct AVHWFramesContext;
47 namespace filesystem {
50 namespace process::inline v1 {
53 template <
typename Char>
68 constexpr auto MAX_GAMEPADS = 16;
70 constexpr std::uint32_t DPAD_UP = 0x0001;
71 constexpr std::uint32_t DPAD_DOWN = 0x0002;
72 constexpr std::uint32_t DPAD_LEFT = 0x0004;
73 constexpr std::uint32_t DPAD_RIGHT = 0x0008;
74 constexpr std::uint32_t START = 0x0010;
75 constexpr std::uint32_t BACK = 0x0020;
76 constexpr std::uint32_t LEFT_STICK = 0x0040;
77 constexpr std::uint32_t RIGHT_STICK = 0x0080;
78 constexpr std::uint32_t LEFT_BUTTON = 0x0100;
79 constexpr std::uint32_t RIGHT_BUTTON = 0x0200;
80 constexpr std::uint32_t HOME = 0x0400;
81 constexpr std::uint32_t A = 0x1000;
82 constexpr std::uint32_t B = 0x2000;
83 constexpr std::uint32_t X = 0x4000;
84 constexpr std::uint32_t Y = 0x8000;
85 constexpr std::uint32_t PADDLE1 = 0x010000;
86 constexpr std::uint32_t PADDLE2 = 0x020000;
87 constexpr std::uint32_t PADDLE3 = 0x040000;
88 constexpr std::uint32_t PADDLE4 = 0x080000;
89 constexpr std::uint32_t TOUCHPAD_BUTTON = 0x100000;
90 constexpr std::uint32_t MISC_BUTTON = 0x200000;
95 std::string reason_disabled;
107 make_rumble(std::uint16_t
id, std::uint16_t lowfreq, std::uint16_t highfreq) {
109 msg.type = gamepad_feedback_e::rumble;
111 msg.data.rumble = { lowfreq, highfreq };
116 make_rumble_triggers(std::uint16_t
id, std::uint16_t left, std::uint16_t right) {
118 msg.type = gamepad_feedback_e::rumble_triggers;
120 msg.data.rumble_triggers = { left, right };
125 make_motion_event_state(std::uint16_t
id, std::uint8_t motion_type, std::uint16_t report_rate) {
127 msg.type = gamepad_feedback_e::set_motion_event_state;
129 msg.data.motion_event_state.motion_type = motion_type;
130 msg.data.motion_event_state.report_rate = report_rate;
135 make_rgb_led(std::uint16_t
id, std::uint8_t r, std::uint8_t g, std::uint8_t b) {
137 msg.type = gamepad_feedback_e::set_rgb_led;
139 msg.data.rgb_led = { r, g, b };
147 std::uint16_t lowfreq;
148 std::uint16_t highfreq;
151 std::uint16_t left_trigger;
152 std::uint16_t right_trigger;
155 std::uint16_t report_rate;
156 std::uint8_t motion_type;
157 } motion_event_state;
166 using feedback_queue_t = safe::mail_raw_t::queue_t<gamepad_feedback_msg_t>;
181 constexpr std::uint8_t map_stereo[] {
182 FRONT_LEFT, FRONT_RIGHT
184 constexpr std::uint8_t map_surround51[] {
192 constexpr std::uint8_t map_surround71[] {
224 inline std::string_view
225 from_pix_fmt(pix_fmt_e pix_fmt) {
226 using namespace std::literals;
247 int offset_x, offset_y;
252 namespace platform_caps {
253 typedef uint32_t caps_t;
255 constexpr caps_t pen_touch = 0x01;
256 constexpr caps_t controller_touch = 0x02;
260 std::uint32_t buttonFlags;
277 std::uint8_t clientRelativeIndex;
282 std::uint16_t capabilities;
283 std::uint32_t supportedButtons;
288 std::uint8_t eventType;
289 std::uint32_t pointerId;
297 std::uint8_t motionType;
309 std::uint8_t percentage;
313 std::uint8_t eventType;
314 std::uint16_t rotation;
315 std::uint32_t pointerId;
318 float pressureOrDistance;
319 float contactAreaMajor;
320 float contactAreaMinor;
324 std::uint8_t eventType;
325 std::uint8_t toolType;
326 std::uint8_t penButtons;
328 std::uint16_t rotation;
331 float pressureOrDistance;
332 float contactAreaMajor;
333 float contactAreaMinor;
341 struct img_t: std::enable_shared_from_this<img_t> {
348 operator=(
img_t &&) =
delete;
350 operator=(
const img_t &) =
delete;
352 std::uint8_t *data {};
353 std::int32_t width {};
354 std::int32_t height {};
355 std::int32_t pixel_pitch {};
356 std::int32_t row_pitch {};
358 std::optional<std::chrono::steady_clock::time_point> frame_timestamp;
360 virtual ~img_t() =
default;
371 std::string surround51;
372 std::string surround71;
374 std::optional<null_t> null;
405 BOOST_LOG(error) <<
"Illegal call to hwdevice_t::set_frame(). Did you forget to override it?";
469 offset_x { 0 }, offset_y { 0 } {}
486 virtual std::shared_ptr<img_t>
490 dummy_img(
img_t *img) = 0;
492 virtual std::unique_ptr<avcodec_encode_device_t>
493 make_avcodec_encode_device(
pix_fmt_e pix_fmt) {
497 virtual std::unique_ptr<nvenc_encode_device_t>
498 make_nvenc_encode_device(
pix_fmt_e pix_fmt) {
508 get_hdr_metadata(SS_HDR_METADATA &metadata) {
509 std::memset(&metadata, 0,
sizeof(metadata));
527 int offset_x, offset_y;
528 int env_width, env_height;
540 sample(std::vector<float> &frame_buffer) = 0;
542 virtual ~mic_t() =
default;
548 set_sink(
const std::string &sink) = 0;
550 virtual std::unique_ptr<mic_t>
551 microphone(
const std::uint8_t *mapping,
int channels, std::uint32_t sample_rate, std::uint32_t frame_size) = 0;
561 virtual std::optional<sink_t>
572 std::filesystem::path
576 get_mac_address(
const std::string_view &address);
579 from_sockaddr(
const sockaddr *
const);
580 std::pair<std::uint16_t, std::string>
581 from_sockaddr_ex(
const sockaddr *
const);
583 std::unique_ptr<audio_control_t>
594 std::shared_ptr<display_t>
598 std::vector<std::string>
608 boost::process::v1::child
609 run_command(
bool elevated,
bool interactive,
const std::string &cmd, boost::filesystem::path &working_dir,
const boost::process::v1::environment &env, FILE *file, std::error_code &ec, boost::process::v1::group *group);
618 adjust_thread_priority(thread_priority_e priority);
622 streaming_will_start();
624 streaming_will_stop();
636 set_env(
const std::string &name,
const std::string &value);
644 unset_env(
const std::string &name);
652 buffer(buffer), size(size) {}
654 buffer(
nullptr), size(0) {}
665 std::vector<buffer_descriptor_t> &payload_buffers;
675 std::uintptr_t native_socket;
676 boost::asio::ip::address &target_address;
677 uint16_t target_port;
678 boost::asio::ip::address &source_address;
687 for (
const auto &desc : payload_buffers) {
688 if (offset < desc.size) {
690 desc.buffer + offset,
702 send_batch(batched_send_info_t &send_info);
710 std::uintptr_t native_socket;
711 boost::asio::ip::address &target_address;
712 uint16_t target_port;
713 boost::asio::ip::address &source_address;
731 std::unique_ptr<deinit_t>
732 enable_socket_qos(uintptr_t native_socket, boost::asio::ip::address &address, uint16_t port, qos_data_type_e data_type,
bool dscp_tagging);
739 open_url(
const std::string &url);
747 request_process_group_exit(std::uintptr_t native_handle);
755 process_group_running(std::uintptr_t native_handle);
768 get_mouse_loc(input_t &input);
770 move_mouse(input_t &input,
int deltaX,
int deltaY);
772 abs_mouse(input_t &input,
const touch_port_t &touch_port,
float x,
float y);
774 button_mouse(input_t &input,
int button,
bool release);
776 scroll(input_t &input,
int distance);
778 hscroll(input_t &input,
int distance);
780 keyboard_update(input_t &input, uint16_t modcode,
bool release, uint8_t flags);
782 gamepad_update(input_t &input,
int nr,
const gamepad_state_t &gamepad_state);
784 unicode(input_t &input,
char *utf8,
int size);
786 typedef deinit_t client_input_t;
793 std::unique_ptr<client_input_t>
794 allocate_client_input_context(input_t &input);
803 touch_update(client_input_t *input,
const touch_port_t &touch_port,
const touch_input_t &touch);
812 pen_update(client_input_t *input,
const touch_port_t &touch_port,
const pen_input_t &pen);
820 gamepad_touch(input_t &input,
const gamepad_touch_t &touch);
828 gamepad_motion(input_t &input,
const gamepad_motion_t &motion);
836 gamepad_battery(input_t &input,
const gamepad_battery_t &battery);
847 alloc_gamepad(input_t &input,
const gamepad_id_t &
id,
const gamepad_arrival_t &metadata, feedback_queue_t feedback_queue);
849 free_gamepad(input_t &input,
int nr);
855 platform_caps::caps_t
858#define SERVICE_NAME "Sunshine"
859#define SERVICE_TYPE "_nvstream._tcp"
862 [[nodiscard]] std::unique_ptr<deinit_t>
866 [[nodiscard]] std::unique_ptr<deinit_t>
882 std::vector<supported_gamepad_t> &
893 sleep_for(
const std::chrono::nanoseconds &duration) = 0;
907 std::unique_ptr<high_precision_timer>
A helper class for tracking and logging short time intervals across a period of time.
Definition logging.h:176
Abstract platform-agnostic base of standalone NVENC encoder. Derived classes perform platform-specifi...
Definition nvenc_base.h:25
virtual bool is_sink_available(const std::string &sink)=0
Check if the audio sink is available in the system.
virtual bool is_codec_supported(std::string_view name, const ::video::config_t &config)
Check that a given codec is supported by the display device.
Definition common.h:520
std::function< bool(std::shared_ptr< img_t > &&img, bool frame_captured)> push_captured_image_cb_t
Callback for when a new image is ready. When display has a new image ready or a timeout occurs,...
Definition common.h:457
std::function< bool(std::shared_ptr< img_t > &img_out)> pull_free_image_cb_t
Get free image from pool. Calls must be synchronized. Blocks until there is free image in the pool or...
Definition common.h:466
virtual capture_e capture(const push_captured_image_cb_t &push_captured_image_cb, const pull_free_image_cb_t &pull_free_image_cb, bool *cursor)=0
Capture a frame.
mem_type_e
Definition common.h:204
speaker_e
Definition common.h:169
@ BACK_LEFT
Back left.
Definition common.h:174
@ LOW_FREQUENCY
Low frequency.
Definition common.h:173
@ SIDE_RIGHT
Side right.
Definition common.h:177
@ MAX_SPEAKERS
Maximum number of speakers.
Definition common.h:178
@ FRONT_LEFT
Front left.
Definition common.h:170
@ SIDE_LEFT
Side left.
Definition common.h:176
@ FRONT_CENTER
Front center.
Definition common.h:172
@ BACK_RIGHT
Back right.
Definition common.h:175
@ FRONT_RIGHT
Front right.
Definition common.h:171
std::vector< supported_gamepad_t > & supported_gamepads(input_t *input)
Gets the supported gamepads for this platform backend.
Definition inputtino.cpp:150
std::shared_ptr< display_t > display(mem_type_e hwdevice_type, const std::string &display_name, const video::config_t &config)
Get the display_t instance for the given hwdevice_type. If display_name is empty, use the first monit...
Definition misc.cpp:909
pix_fmt_e
Definition common.h:213
@ yuv420p10
YUV 4:2:0 10-bit.
@ yuv444p16
Planar 10-bit (shifted to 16-bit) YUV 4:4:4.
std::filesystem::path appdata()
Performs migration if necessary, then returns the appdata directory.
Definition misc.cpp:109
qos_data_type_e
Definition common.h:718
std::unique_ptr< high_precision_timer > create_high_precision_timer()
Create platform-specific timer capable of high-precision sleep.
Definition misc.cpp:1019
bool needs_encoder_reenumeration()
Check if GPUs/drivers have changed since the last call to this function.
Definition misc.cpp:903
gamepad_feedback_e
Definition common.h:98
@ rumble_triggers
Rumble triggers.
@ set_motion_event_state
Set motion event state.
@ set_rgb_led
Set RGB LED.
thread_priority_e
Definition common.h:611
@ critical
Critical priority.
std::string get_host_name()
Returns the current computer name in UTF-8.
Definition misc.cpp:802
capture_e
Definition common.h:440
@ reinit
Need to reinitialize.
@ interrupted
Capture was interrupted.
Declarations for the configuration of Sunshine.
std::unique_ptr< platf::deinit_t > init(const std::filesystem::path &persistence_filepath, const config::video_t &video_config)
Initialize the implementation and perform the initial state recovery (if needed).
Definition display_device.cpp:721
Declarations for logging related functions.
Standalone NVENC encoder.
Definition nvenc_base.cpp:86
virtual int prepare_to_derive_context(int hw_device_type)
Prepare to derive a context.
Definition common.h:428
virtual void init_codec_options(AVCodecContext *ctx, AVDictionary **options)
Provides a hook for allow platform-specific code to adjust codec options.
Definition common.h:421
virtual int set_frame(AVFrame *frame, AVBufferRef *hw_frames_ctx)
Set the frame to be encoded.
Definition common.h:404
virtual void init_hwframes(AVHWFramesContext *frames)
Initialize the hwframes context.
Definition common.h:414
buffer_descriptor_t buffer_for_payload_offset(ptrdiff_t offset)
Returns a payload buffer descriptor for the given payload offset.
Definition common.h:686
virtual void sleep_for(const std::chrono::nanoseconds &duration)=0
Sleep for the duration.
Definition video_colorspace.h:20
Declarations for thread-safe data structures.
Declarations for utility functions.
Declarations for colorspace functions.