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

Definitions for display device handling. More...

#include "display_device.h"
#include <boost/algorithm/string.hpp>
#include <display_device/audio_context_interface.h>
#include <display_device/file_settings_persistence.h>
#include <display_device/json.h>
#include <display_device/retry_scheduler.h>
#include <display_device/settings_manager_interface.h>
#include <mutex>
#include <regex>
#include "audio.h"
#include "platform/common.h"
#include "rtsp.h"
#include <display_device/windows/settings_manager.h>
#include <display_device/windows/win_api_layer.h>
#include <display_device/windows/win_display_device.h>
Include dependency graph for display_device.cpp:

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.
 
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

Definitions 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:19

◆ 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);

◆ init()

std::unique_ptr< platf::deinit_t > display_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).

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)

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 )

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 ( )

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
Note
Whether the function succeeds or fails, the 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();

Variable Documentation

◆ audio_ctx_ref

decltype(audio::get_audio_ctx_ref()) audio_ctx_ref {audio::get_audio_ctx_ref()}

A reference to the audio context that will automatically extend the audio session.

Note
It is auto-initialized here for convenience.