Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 8 #8

Merged
merged 32 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
4d4cfe9
Add new API to modify display devices for Windows
FrogTheFrog Jan 2, 2024
145bbd3
Separate device id from device path (prep)
FrogTheFrog Feb 6, 2024
f6f660f
Go back to the initial topology selection impl.
FrogTheFrog Feb 8, 2024
e39268d
Use more persistent device ids instead of just paths
FrogTheFrog Feb 8, 2024
847978f
Remove unused functions
FrogTheFrog Feb 8, 2024
2785bd1
Extend audio session if needed
FrogTheFrog Feb 10, 2024
634c744
Suppress the log
FrogTheFrog Feb 10, 2024
a7dfb25
Add mutex lock for main entry points
FrogTheFrog Feb 10, 2024
c05c94d
Add port related info to display ID
FrogTheFrog Feb 11, 2024
56982b7
Address some review points
FrogTheFrog Feb 11, 2024
8cb84f9
WIP doxygen
FrogTheFrog Feb 12, 2024
5ae8505
Remove @example usage
FrogTheFrog Feb 12, 2024
086321c
Remove the use of codecvt_utf8
FrogTheFrog Feb 13, 2024
beec757
Address setting reset question thingy
FrogTheFrog Feb 17, 2024
10499bc
Whoops, leftover
FrogTheFrog Feb 17, 2024
dbb21c7
Change log levels
FrogTheFrog Feb 17, 2024
ac9d0ef
Make non-Windows compile again
FrogTheFrog Feb 17, 2024
c6a20f2
Address review comments for display_device.h
FrogTheFrog Feb 18, 2024
02930ea
Document parsed_config
FrogTheFrog Feb 19, 2024
b6a406f
Document to_string
FrogTheFrog Feb 19, 2024
a241974
Document settings
FrogTheFrog Feb 19, 2024
ff6b509
Document session
FrogTheFrog Feb 20, 2024
2748ecf
Document windows utils
FrogTheFrog Feb 21, 2024
dc03fad
Simplify the error message functions
FrogTheFrog Feb 21, 2024
1b8bcc1
Docs and cleanup for settings_topology
FrogTheFrog Feb 21, 2024
5f2d9e0
Remove unnecessary header
FrogTheFrog Feb 21, 2024
2e7dce4
More documentation and cleanup
FrogTheFrog Feb 22, 2024
fb95da1
More documentation and cleanup
FrogTheFrog Feb 22, 2024
7e6b01a
More documentation and cleanup
FrogTheFrog Feb 22, 2024
c4a1776
More docs
FrogTheFrog Feb 22, 2024
e53b5aa
Complicate more stuff
FrogTheFrog Feb 23, 2024
fd0fe2f
Update README.rst
WesleyVanNeck Mar 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ LizardByte has the full documentation hosted on `Read the Docs <https://sunshine

About
-----
Sunshine is a self-hosted game stream host for Moonlight.
Sunshine is a self-hosted game stream host for Moonlight.
Offering low latency, cloud gaming server capabilities with support for AMD, Intel, and Nvidia GPUs for hardware
encoding. Software encoding is also available. You can connect to Sunshine from any Moonlight client on a variety of
devices. A web UI is provided to allow configuration, and client pairing, from your favorite web browser. Pair from
Expand Down
9 changes: 9 additions & 0 deletions cmake/compile_definitions/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ set(SUNSHINE_TARGET_FILES
"${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/src/RtspParser.c"
"${CMAKE_SOURCE_DIR}/third-party/moonlight-common-c/src/Video.h"
"${CMAKE_SOURCE_DIR}/third-party/tray/tray.h"
"${CMAKE_SOURCE_DIR}/src/display_device/display_device.h"
"${CMAKE_SOURCE_DIR}/src/display_device/parsed_config.cpp"
"${CMAKE_SOURCE_DIR}/src/display_device/parsed_config.h"
"${CMAKE_SOURCE_DIR}/src/display_device/session.cpp"
"${CMAKE_SOURCE_DIR}/src/display_device/session.h"
"${CMAKE_SOURCE_DIR}/src/display_device/settings.cpp"
"${CMAKE_SOURCE_DIR}/src/display_device/settings.h"
"${CMAKE_SOURCE_DIR}/src/display_device/to_string.cpp"
"${CMAKE_SOURCE_DIR}/src/display_device/to_string.h"
"${CMAKE_SOURCE_DIR}/src/upnp.cpp"
"${CMAKE_SOURCE_DIR}/src/upnp.h"
"${CMAKE_SOURCE_DIR}/src/cbs.cpp"
Expand Down
1 change: 1 addition & 0 deletions cmake/compile_definitions/linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ list(APPEND PLATFORM_TARGET_FILES
"${CMAKE_SOURCE_DIR}/src/platform/linux/misc.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/linux/audio.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/linux/input.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/linux/display_device.cpp"
"${CMAKE_SOURCE_DIR}/third-party/glad/src/egl.c"
"${CMAKE_SOURCE_DIR}/third-party/glad/src/gl.c"
"${CMAKE_SOURCE_DIR}/third-party/glad/include/EGL/eglplatform.h"
Expand Down
1 change: 1 addition & 0 deletions cmake/compile_definitions/macos.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ set(PLATFORM_TARGET_FILES
"${CMAKE_SOURCE_DIR}/src/platform/macos/av_video.h"
"${CMAKE_SOURCE_DIR}/src/platform/macos/av_video.m"
"${CMAKE_SOURCE_DIR}/src/platform/macos/display.mm"
"${CMAKE_SOURCE_DIR}/src/platform/macos/display_device.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/macos/input.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/macos/microphone.mm"
"${CMAKE_SOURCE_DIR}/src/platform/macos/misc.mm"
Expand Down
9 changes: 9 additions & 0 deletions cmake/compile_definitions/windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ set(PLATFORM_TARGET_FILES
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_vram.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_ram.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/audio.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_device/device_hdr_states.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_device/device_modes.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_device/device_topology.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_device/general_functions.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_device/settings_topology.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_device/settings_topology.h"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_device/settings.cpp"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_device/windows_utils.h"
"${CMAKE_SOURCE_DIR}/src/platform/windows/display_device/windows_utils.cpp"
"${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/src/ViGEmClient.cpp"
"${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/include/ViGEm/Client.h"
"${CMAKE_SOURCE_DIR}/third-party/ViGEmClient/include/ViGEm/Common.h"
Expand Down
34 changes: 30 additions & 4 deletions docs/source/about/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ keybindings
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

**Description**
Select the display number you want to stream.
Select the display you want to stream.

.. tip:: To find the name of the appropriate values follow these instructions.

Expand All @@ -556,9 +556,35 @@ keybindings
.. todo:: macOS

**Windows**
.. code-block:: batch
During Sunshine startup, you should see the list of detected display devices:

tools\dxgi-info.exe
.. code-block:: text

DEVICE ID: {de9bb7e2-186e-505b-9e93-f48793333810}
DISPLAY NAME: \\.\DISPLAY1
FRIENDLY NAME: ROG PG279Q
DEVICE STATE: PRIMARY
HDR STATE: UNKNOWN
-----------------------
DEVICE ID: {3bd008cd-0465-547c-8da5-c28749c041e6}
DISPLAY NAME: NOT AVAILABLE
FRIENDLY NAME: IDD HDR
DEVICE STATE: INACTIVE
HDR STATE: UNKNOWN
-----------------------
DEVICE ID: {77f67f3e-754f-5d31-af64-ee037e18100a}
DISPLAY NAME: NOT AVAILABLE
FRIENDLY NAME: SunshineHDR
DEVICE STATE: INACTIVE
HDR STATE: UNKNOWN
-----------------------
DEVICE ID: {bc172e6d-86eb-5851-aeca-56525ed716e9}
DISPLAY NAME: NOT AVAILABLE
FRIENDLY NAME: ROG PG279Q
DEVICE STATE: INACTIVE
HDR STATE: UNKNOWN

You need to use the ``DEVICE ID`` value.

**Default**
Sunshine will select the default display.
Expand All @@ -574,7 +600,7 @@ keybindings
**Windows**
.. code-block:: text

output_name = \\.\DISPLAY1
output_name = {de9bb7e2-186e-505b-9e93-f48793333810}

`resolutions <https://localhost:47990/config/#resolutions>`__
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
14 changes: 14 additions & 0 deletions docs/source/source_code/source_code.rst
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ Source

src/*

.. toctree::
:caption: src/display_device
:maxdepth: 1
:glob:

src/display_device/*

.. toctree::
:caption: src/platform
:maxdepth: 1
Expand Down Expand Up @@ -89,3 +96,10 @@ Source
:glob:

src/platform/windows/*

.. toctree::
:caption: src/platform/windows/display_device
:maxdepth: 1
:glob:

src/platform/windows/display_device/*
4 changes: 4 additions & 0 deletions docs/source/source_code/src/display_device/display_device.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
display_device
==============

.. todo:: Add display_device.h
4 changes: 4 additions & 0 deletions docs/source/source_code/src/display_device/parsed_config.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parsed_config
=============

.. todo:: Add parsed_config.h
4 changes: 4 additions & 0 deletions docs/source/source_code/src/display_device/session.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
session
=======

.. todo:: Add session.h
4 changes: 4 additions & 0 deletions docs/source/source_code/src/display_device/settings.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
settings
========

.. todo:: Add settings.h
4 changes: 4 additions & 0 deletions docs/source/source_code/src/display_device/to_string.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
to_string
=========

.. todo:: Add to_string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
settings_data
=============

.. todo:: Add settings_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
settings_topology
=================

.. todo:: Add settings_topology.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
windows_utils
=============

.. todo:: Add windows_utils.h
20 changes: 7 additions & 13 deletions src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@ namespace audio {
using opus_t = util::safe_ptr<OpusMSEncoder, opus_multistream_encoder_destroy>;
using sample_queue_t = std::shared_ptr<safe::queue_t<std::vector<std::int16_t>>>;

struct audio_ctx_t {
// We want to change the sink for the first stream only
std::unique_ptr<std::atomic_bool> sink_flag;

std::unique_ptr<platf::audio_control_t> control;

bool restore_sink;
platf::sink_t sink;
};

static int
start_audio_control(audio_ctx_t &ctx);
static void
Expand Down Expand Up @@ -93,8 +83,6 @@ namespace audio {
},
};

auto control_shared = safe::make_shared<audio_ctx_t>(start_audio_control, stop_audio_control);

void
encodeThread(sample_queue_t samples, config_t config, void *channel_data) {
auto packets = mail::man->queue<packet_t>(mail::audio_packets);
Expand Down Expand Up @@ -137,7 +125,7 @@ namespace audio {
auto shutdown_event = mail->event<bool>(mail::shutdown);
auto stream = &stream_configs[map_stream(config.channels, config.flags[config_t::HIGH_QUALITY])];

auto ref = control_shared.ref();
auto ref = get_audio_ctx_ref();
if (!ref) {
return;
}
Expand Down Expand Up @@ -243,6 +231,12 @@ namespace audio {
}
}

audio_ctx_ref_t
get_audio_ctx_ref() {
static auto control_shared { safe::make_shared<audio_ctx_t>(start_audio_control, stop_audio_control) };
return control_shared.ref();
}

int
map_stream(int channels, bool quality) {
int shift = quality ? 1 : 0;
Expand Down
33 changes: 29 additions & 4 deletions src/audio.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/**
* @file src/audio.h
* @brief todo
*/
#pragma once

// local includes
#include "platform/common.h"
#include "thread_safe.h"
#include "utility.h"

namespace audio {
enum stream_config_e : int {
STEREO,
Expand Down Expand Up @@ -42,8 +41,34 @@ namespace audio {
std::bitset<MAX_FLAGS> flags;
};

struct audio_ctx_t {
// We want to change the sink for the first stream only
std::unique_ptr<std::atomic_bool> sink_flag;

std::unique_ptr<platf::audio_control_t> control;

bool restore_sink;
platf::sink_t sink;
};

using buffer_t = util::buffer_t<std::uint8_t>;
using packet_t = std::pair<void *, buffer_t>;
using audio_ctx_ref_t = safe::shared_t<audio::audio_ctx_t>::ptr_t;

void
capture(safe::mail_t mail, config_t config, void *channel_data);

/**
* @brief Get the reference to the audio context.
* @returns A shared pointer reference to audio context.
* @note Aside from the configuration purposes, it can be used to extend the
* audio sink lifetime to capture sink earlier and restore it later.
*
* EXAMPLES:
* ```cpp
* audio_ctx_ref_t audio = get_audio_ctx_ref()
* ```
*/
audio_ctx_ref_t
get_audio_ctx_ref();
} // namespace audio
15 changes: 15 additions & 0 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "rtsp.h"
#include "utility.h"

#include "display_device/parsed_config.h"
#include "platform/common.h"

#ifdef _WIN32
Expand Down Expand Up @@ -367,7 +368,14 @@ namespace config {
{}, // capture
{}, // encoder
{}, // adapter_name

{}, // output_name
(int) display_device::parsed_config_t::device_prep_e::no_operation, // display_device_prep
(int) display_device::parsed_config_t::resolution_change_e::automatic, // resolution_change
{}, // manual_resolution
(int) display_device::parsed_config_t::refresh_rate_change_e::automatic, // refresh_rate_change
{}, // manual_refresh_rate
(int) display_device::parsed_config_t::hdr_prep_e::automatic // hdr_prep
};

audio_t audio {
Expand Down Expand Up @@ -1001,7 +1009,14 @@ namespace config {
string_f(vars, "capture", video.capture);
string_f(vars, "encoder", video.encoder);
string_f(vars, "adapter_name", video.adapter_name);

string_f(vars, "output_name", video.output_name);
int_f(vars, "display_device_prep", video.display_device_prep, display_device::parsed_config_t::device_prep_from_view);
int_f(vars, "resolution_change", video.resolution_change, display_device::parsed_config_t::resolution_change_from_view);
string_f(vars, "manual_resolution", video.manual_resolution);
int_f(vars, "refresh_rate_change", video.refresh_rate_change, display_device::parsed_config_t::refresh_rate_change_from_view);
string_f(vars, "manual_refresh_rate", video.manual_refresh_rate);
int_f(vars, "hdr_prep", video.hdr_prep, display_device::parsed_config_t::hdr_prep_from_view);

path_f(vars, "pkey", nvhttp.pkey);
path_f(vars, "cert", nvhttp.cert);
Expand Down
7 changes: 7 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ namespace config {
std::string capture;
std::string encoder;
std::string adapter_name;

std::string output_name;
int display_device_prep;
int resolution_change;
std::string manual_resolution;
int refresh_rate_change;
std::string manual_refresh_rate;
int hdr_prep;
};

struct audio_t {
Expand Down
19 changes: 19 additions & 0 deletions src/confighttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include "config.h"
#include "confighttp.h"
#include "crypto.h"
#include "display_device/session.h"
#include "file_handler.h"
#include "globals.h"
#include "httpcommon.h"
Expand Down Expand Up @@ -596,6 +597,23 @@ namespace confighttp {
platf::restart();
}

void
resetDisplayDevicePersistence(resp_https_t response, req_https_t request) {
if (!authenticate(response, request)) return;

print_req(request);

pt::ptree outputTree;
auto g = util::fail_guard([&]() {
std::ostringstream data;
pt::write_json(data, outputTree);
response->write(data.str());
});

display_device::session_t::get().reset_persistence();
outputTree.put("status", true);
}

void
savePassword(resp_https_t response, req_https_t request) {
if (!config::sunshine.username.empty() && !authenticate(response, request)) return;
Expand Down Expand Up @@ -744,6 +762,7 @@ namespace confighttp {
server.resource["^/api/config$"]["GET"] = getConfig;
server.resource["^/api/config$"]["POST"] = saveConfig;
server.resource["^/api/restart$"]["POST"] = restart;
server.resource["^/api/reset-display-device-persistence$"]["POST"] = resetDisplayDevicePersistence;
server.resource["^/api/password$"]["POST"] = savePassword;
server.resource["^/api/apps/([0-9]+)$"]["DELETE"] = deleteApp;
server.resource["^/api/clients/unpair$"]["POST"] = unpairAll;
Expand Down
Loading
Loading