Sunshine latest
Self-hosted game stream host for Moonlight.
display_device.h File Reference

Declarations for display device handling. More...

#include <filesystem>
#include <memory>
#include <display_device/types.h>
Include dependency graph for display_device.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  display_device::configuration_disabled_tag_t
 A tag structure indicating that configuration is disabled. More...
 
struct  display_device::failed_to_parse_tag_t
 A tag structure indicating that configuration parsing has failed. More...
 

Functions

void display_device::configure_display (const config::video_t &video_config, const rtsp_stream::launch_session_t &session)
 Configure the display device based on the user configuration and the session information.
 
void display_device::configure_display (const SingleDisplayConfiguration &config)
 Configure the display device using the provided configuration.
 
EnumeratedDeviceList display_device::enumerate_devices ()
 Enumerate the available devices.
 
std::unique_ptr< platf::deinit_tdisplay_device::init (const std::filesystem::path &persistence_filepath, const config::video_t &video_config)
 Initialize the implementation and perform the initial state recovery (if needed).
 
std::string display_device::map_output_name (const std::string &output_name)
 Map the output name to a specific display.
 
std::variant< failed_to_parse_tag_t, configuration_disabled_tag_t, SingleDisplayConfiguration > display_device::parse_configuration (const config::video_t &video_config, const rtsp_stream::launch_session_t &session)
 Parse the user configuration and the session information.
 
bool display_device::reset_persistence ()
 Reset the persistence and currently held initial display state.
 
void display_device::revert_configuration ()
 Revert the display configuration and restore the previous state.
 

Detailed Description

Declarations for display device handling.

Function Documentation

◆ configure_display() [1/2]

void display_device::configure_display ( const config::video_t & video_config,
const rtsp_stream::launch_session_t & session )

Configure the display device based on the user configuration and the session information.

Note
This is a convenience method for calling similar method of a different signature.
Parameters
video_configUser's video related configuration.
sessionSession information.

*Examples**

const std::shared_ptr<rtsp_stream::launch_session_t> launch_session;
const config::video_t &video_config { config::video };
configure_display(video_config, *launch_session);
Definition config.h:22

◆ configure_display() [2/2]

void display_device::configure_display ( const SingleDisplayConfiguration & config)

Configure the display device using the provided configuration.

In some cases configuring display can fail due to transient issues and we will keep trying every 5 seconds, even if the stream has already started as there was no possibility to apply settings before the stream start.

Therefore, there is no return value as we still want to continue with the stream, so that the users can do something about it once they are connected. Otherwise, we might prevent users from logging in at all if we keep failing to apply configuration.

Parameters
configConfiguration for the display.

*Examples**

const SingleDisplayConfiguration valid_config { };
configure_display(valid_config);

◆ enumerate_devices()

EnumeratedDeviceList display_device::enumerate_devices ( )
nodiscard

Enumerate the available devices.

Returns
A list of devices.

*Examples**

const auto devices = enumerate_devices();

◆ init()

std::unique_ptr< platf::deinit_t > display_device::init ( const std::filesystem::path & persistence_filepath,
const config::video_t & video_config )
nodiscard

Initialize the implementation and perform the initial state recovery (if needed).

Parameters
persistence_filepathFile location for reading/saving persistent state.
video_configUser's video related configuration.
Returns
A deinit_t instance that performs cleanup when destroyed.

*Examples**

const config::video_t &video_config { config::video };
const auto init_guard { init("/my/persitence/file.state", video_config) };

◆ map_output_name()

std::string display_device::map_output_name ( const std::string & output_name)
nodiscard

Map the output name to a specific display.

Parameters
output_nameThe user-configurable output name.
Returns
Mapped display name or empty string if the output name could not be mapped.

*Examples**

const auto mapped_name_config { map_output_name(config::video.output_name) };
const auto mapped_name_custom { map_output_name("{some-device-id}") };

◆ parse_configuration()

std::variant< failed_to_parse_tag_t, configuration_disabled_tag_t, SingleDisplayConfiguration > display_device::parse_configuration ( const config::video_t & video_config,
const rtsp_stream::launch_session_t & session )
nodiscard

Parse the user configuration and the session information.

Parameters
video_configUser's video related configuration.
sessionSession information.
Returns
Parsed single display configuration or a tag indicating that the parsing has failed or a tag indicating that the user does not want to perform any configuration.

*Examples**

const std::shared_ptr<rtsp_stream::launch_session_t> launch_session;
const config::video_t &video_config { config::video };
const auto config { parse_configuration(video_config, *launch_session) };
if (const auto *parsed_config { std::get_if<SingleDisplayConfiguration>(&result) }; parsed_config) {
}
void configure_display(const config::video_t &video_config, const rtsp_stream::launch_session_t &session)
Configure the display device based on the user configuration and the session information.
Definition display_device.cpp:760

◆ reset_persistence()

bool display_device::reset_persistence ( )
nodiscard

Reset the persistence and currently held initial display state.

This is normally used to get out of the "broken" state where the algorithm wants to restore the initial display state, but it is no longer possible.

This could happen if the display is no longer available or the hardware was changed and the device ids no longer match.

The user then accepts that Sunshine is not able to restore the state and "agrees" to do it manually.

Returns
True if persistence was reset, false otherwise.
Note
Whether the function succeeds or fails, any of the scheduled "retries" from other methods will be stopped to not interfere with the user actions.

*Examples**

const auto result = reset_persistence();

◆ revert_configuration()

void display_device::revert_configuration ( )

Revert the display configuration and restore the previous state.

In case the state could not be restored, by default it will be retried again in 5 seconds (repeating indefinitely until success or until persistence is reset).

*Examples**

revert_configuration();