Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
display_device.cpp
Go to the documentation of this file.
1
5// header include
6#include "display_device.h"
7
8// lib includes
9#include <boost/algorithm/string.hpp>
10#include <display_device/audio_context_interface.h>
11#include <display_device/file_settings_persistence.h>
12#include <display_device/json.h>
13#include <display_device/retry_scheduler.h>
14#include <display_device/settings_manager_interface.h>
15#include <mutex>
16#include <regex>
17
18// local includes
19#include "audio.h"
20#include "platform/common.h"
21#include "rtsp.h"
22
23// platform-specific includes
24
25namespace display_device {
26 namespace {
27 constexpr std::chrono::milliseconds DEFAULT_RETRY_INTERVAL {5000};
28
32 struct {
33 std::mutex mutex {};
34 std::chrono::milliseconds config_revert_delay {0};
35 std::unique_ptr<RetryScheduler<SettingsManagerInterface>> sm_instance {nullptr};
36 } DD_DATA;
37
45 class sunshine_audio_context_t: public AudioContextInterface {
46 public:
47 [[nodiscard]] bool capture() override {
48 return context_scheduler.execute([](auto &audio_context) {
49 // Explicitly releasing the context first in case it was not release yet so that it can be potentially cleaned up.
50 audio_context = boost::none;
51 audio_context = audio_context_t {};
52
53 // Always say that we have captured it successfully as otherwise the settings change procedure will be aborted.
54 return true;
55 });
56 }
57
58 [[nodiscard]] bool isCaptured() const override {
59 return context_scheduler.execute([](const auto &audio_context) {
60 if (audio_context) {
61 // In case we still have context we need to check whether it was released or not.
62 // If it was released we can pretend that we no longer have it as it will be immediately cleaned up in `capture` method before we acquire new context.
63 return !audio_context->released;
64 }
65
66 return false;
67 });
68 }
69
70 void release() override {
71 context_scheduler.schedule([](auto &audio_context, auto &stop_token) {
72 if (audio_context) {
73 audio_context->released = true;
74
75 const auto *audio_ctx_ptr = audio_context->audio_ctx_ref.get();
76 if (audio_ctx_ptr && !audio::is_audio_ctx_sink_available(*audio_ctx_ptr) && audio_context->retry_counter > 0) {
77 // It is possible that the audio sink is not immediately available after the display is turned on.
78 // Therefore, we will hold on to the audio context a little longer, until it is either available
79 // or we time out.
80 --audio_context->retry_counter;
81 return;
82 }
83 }
84
85 audio_context = boost::none;
86 stop_token.requestStop();
87 },
88 SchedulerOptions {.m_sleep_durations = {2s}});
89 }
90
91 private:
92 struct audio_context_t {
97 decltype(audio::get_audio_ctx_ref()) audio_ctx_ref {audio::get_audio_ctx_ref()};
98
102 bool released {false};
103
107 int retry_counter {15};
108 };
109
110 RetryScheduler<boost::optional<audio_context_t>> context_scheduler {std::make_unique<boost::optional<audio_context_t>>(boost::none)};
111 };
112
119 unsigned int stou(const std::string &value) {
120 unsigned long result {std::stoul(value)};
121 if (result > std::numeric_limits<unsigned int>::max()) {
122 throw std::out_of_range("stou");
123 }
124 return result;
125 }
126
145 bool parse_resolution_string(const std::string &input, std::optional<Resolution> &output) {
146 const std::string trimmed_input {boost::algorithm::trim_copy(input)};
147 const std::regex resolution_regex {R"(^(\d+)x(\d+)$)"};
148
149 if (std::smatch match; std::regex_match(trimmed_input, match, resolution_regex)) {
150 try {
151 output = Resolution {
152 stou(match[1].str()),
153 stou(match[2].str())
154 };
155 return true;
156 } catch (const std::out_of_range &) {
157 BOOST_LOG(error) << "Failed to parse resolution string " << trimmed_input << " (number out of range).";
158 } catch (const std::exception &err) {
159 BOOST_LOG(error) << "Failed to parse resolution string " << trimmed_input << ":\n"
160 << err.what();
161 }
162 } else {
163 if (trimmed_input.empty()) {
164 output = std::nullopt;
165 return true;
166 }
167
168 BOOST_LOG(error) << "Failed to parse resolution string " << trimmed_input << R"(. It must match a "1920x1080" pattern!)";
169 }
170
171 return false;
172 }
173
193 bool parse_refresh_rate_string(const std::string &input, std::optional<FloatingPoint> &output, const bool allow_decimal_point = true) {
194 static const auto is_zero {[](const auto &character) {
195 return character == '0';
196 }};
197 const std::string trimmed_input {boost::algorithm::trim_copy(input)};
198 const std::regex refresh_rate_regex {allow_decimal_point ? R"(^(\d+)(?:\.(\d+))?$)" : R"(^(\d+)$)"};
199
200 if (std::smatch match; std::regex_match(trimmed_input, match, refresh_rate_regex)) {
201 try {
202 // Here we are trimming zeros from the string to possibly reduce out of bounds case
203 std::string trimmed_match_1 {boost::algorithm::trim_left_copy_if(match[1].str(), is_zero)};
204 if (trimmed_match_1.empty()) {
205 trimmed_match_1 = "0"s; // Just in case ALL the string is full of zeros, we want to leave one
206 }
207
208 std::string trimmed_match_2;
209 if (allow_decimal_point && match[2].matched) {
210 trimmed_match_2 = boost::algorithm::trim_right_copy_if(match[2].str(), is_zero);
211 }
212
213 if (!trimmed_match_2.empty()) {
214 // We have a decimal point and will have to split it into numerator and denominator.
215 // For example:
216 // 59.995:
217 // numerator = 59995
218 // denominator = 1000
219
220 // We are essentially removing the decimal point here: 59.995 -> 59995
221 const std::string numerator_str {trimmed_match_1 + trimmed_match_2};
222 const auto numerator {stou(numerator_str)};
223
224 // Here we are counting decimal places and calculating denominator: 10^decimal_places
225 const auto denominator {static_cast<unsigned int>(std::pow(10, trimmed_match_2.size()))};
226
227 output = Rational {numerator, denominator};
228 } else {
229 // We do not have a decimal point, just a valid number.
230 // For example:
231 // 60:
232 // numerator = 60
233 // denominator = 1
234 output = Rational {stou(trimmed_match_1), 1};
235 }
236 return true;
237 } catch (const std::out_of_range &) {
238 BOOST_LOG(error) << "Failed to parse refresh rate string " << trimmed_input << " (number out of range).";
239 } catch (const std::exception &err) {
240 BOOST_LOG(error) << "Failed to parse refresh rate string " << trimmed_input << ":\n"
241 << err.what();
242 }
243 } else {
244 if (trimmed_input.empty()) {
245 output = std::nullopt;
246 return true;
247 }
248
249 BOOST_LOG(error) << "Failed to parse refresh rate string " << trimmed_input << ". Must have a pattern of " << (allow_decimal_point ? R"("123" or "123.456")" : R"("123")") << "!";
250 }
251
252 return false;
253 }
254
266 std::optional<SingleDisplayConfiguration::DevicePreparation> parse_device_prep_option(const config::video_t &video_config) {
268 using enum SingleDisplayConfiguration::DevicePreparation;
269
270 switch (video_config.dd.configuration_option) {
271 case verify_only:
272 return VerifyOnly;
273 case ensure_active:
274 return EnsureActive;
275 case ensure_primary:
276 return EnsurePrimary;
277 case ensure_only_display:
278 return EnsureOnlyDisplay;
279 case disabled:
280 break;
281 }
282
283 return std::nullopt;
284 }
285
301 bool parse_resolution_option(const config::video_t &video_config, const rtsp_stream::launch_session_t &session, SingleDisplayConfiguration &config) {
302 using resolution_option_e = config::video_t::dd_t::resolution_option_e;
303
304 switch (video_config.dd.resolution_option) {
305 case resolution_option_e::automatic:
306 {
307 if (!session.enable_sops) {
308 BOOST_LOG(warning) << R"(Hermes is configured to change resolution automatically, but the "Optimize game settings" is not set in the client! Resolution will not be changed.)";
309 } else if (session.width >= 0 && session.height >= 0) {
310 config.m_resolution = Resolution {
311 static_cast<unsigned int>(session.width),
312 static_cast<unsigned int>(session.height)
313 };
314 } else {
315 BOOST_LOG(error) << "Resolution provided by client session config is invalid: " << session.width << "x" << session.height;
316 return false;
317 }
318 break;
319 }
320 case resolution_option_e::manual:
321 {
322 if (!session.enable_sops) {
323 BOOST_LOG(warning) << R"(Hermes is configured to change resolution manually, but the "Optimize game settings" is not set in the client! Resolution will not be changed.)";
324 } else {
325 if (!parse_resolution_string(video_config.dd.manual_resolution, config.m_resolution)) {
326 BOOST_LOG(error) << "Failed to parse manual resolution string!";
327 return false;
328 }
329
330 if (!config.m_resolution) {
331 BOOST_LOG(error) << "Manual resolution must be specified!";
332 return false;
333 }
334 }
335 break;
336 }
337 case resolution_option_e::disabled:
338 break;
339 }
340
341 return true;
342 }
343
359 bool parse_refresh_rate_option(const config::video_t &video_config, const rtsp_stream::launch_session_t &session, SingleDisplayConfiguration &config) {
360 using refresh_rate_option_e = config::video_t::dd_t::refresh_rate_option_e;
361
362 switch (video_config.dd.refresh_rate_option) {
363 case refresh_rate_option_e::automatic:
364 {
365 if (session.fps >= 0) {
366 config.m_refresh_rate = Rational {static_cast<unsigned int>(session.fps), 1000};
367 } else {
368 BOOST_LOG(error) << "FPS value provided by client session config is invalid: " << session.fps;
369 return false;
370 }
371 break;
372 }
373 case refresh_rate_option_e::manual:
374 {
375 if (!parse_refresh_rate_string(video_config.dd.manual_refresh_rate, config.m_refresh_rate)) {
376 BOOST_LOG(error) << "Failed to parse manual refresh rate string!";
377 return false;
378 }
379
380 if (!config.m_refresh_rate) {
381 BOOST_LOG(error) << "Manual refresh rate must be specified!";
382 return false;
383 }
384 break;
385 }
386 case refresh_rate_option_e::disabled:
387 break;
388 }
389
390 return true;
391 }
392
406 std::optional<HdrState> parse_hdr_option(const config::video_t &video_config, const rtsp_stream::launch_session_t &session) {
407 using hdr_option_e = config::video_t::dd_t::hdr_option_e;
408
409 switch (video_config.dd.hdr_option) {
410 case hdr_option_e::automatic:
411 return session.enable_hdr ? HdrState::Enabled : HdrState::Disabled;
412 case hdr_option_e::disabled:
413 break;
414 }
415
416 return std::nullopt;
417 }
418
422 enum class remapping_type_e {
423 mixed,
424 resolution_only,
425 refresh_rate_only
426 };
427
433 std::optional<remapping_type_e> determine_remapping_type(const config::video_t &video_config) {
434 using dd_t = config::video_t::dd_t;
435 const bool auto_resolution {video_config.dd.resolution_option == dd_t::resolution_option_e::automatic};
436 const bool auto_refresh_rate {video_config.dd.refresh_rate_option == dd_t::refresh_rate_option_e::automatic};
437
438 if (auto_resolution && auto_refresh_rate) {
439 return remapping_type_e::mixed;
440 }
441
442 if (auto_resolution) {
443 return remapping_type_e::resolution_only;
444 }
445
446 if (auto_refresh_rate) {
447 return remapping_type_e::refresh_rate_only;
448 }
449
450 return std::nullopt;
451 }
452
456 struct parsed_remapping_entry_t {
457 std::optional<Resolution> requested_resolution;
458 std::optional<FloatingPoint> requested_fps;
459 std::optional<Resolution> final_resolution;
460 std::optional<FloatingPoint> final_refresh_rate;
461 };
462
468 bool is_resolution_mapped(const remapping_type_e type) {
469 return type == remapping_type_e::resolution_only || type == remapping_type_e::mixed;
470 }
471
477 bool is_fps_mapped(const remapping_type_e type) {
478 return type == remapping_type_e::refresh_rate_only || type == remapping_type_e::mixed;
479 }
480
487 std::optional<parsed_remapping_entry_t> parse_remapping_entry(const config::video_t::dd_t::mode_remapping_entry_t &entry, const remapping_type_e type) {
488 parsed_remapping_entry_t result {};
489
490 if (is_resolution_mapped(type) && (!parse_resolution_string(entry.requested_resolution, result.requested_resolution) ||
491 !parse_resolution_string(entry.final_resolution, result.final_resolution))) {
492 return std::nullopt;
493 }
494
495 if (is_fps_mapped(type) && (!parse_refresh_rate_string(entry.requested_fps, result.requested_fps, false) ||
496 !parse_refresh_rate_string(entry.final_refresh_rate, result.final_refresh_rate))) {
497 return std::nullopt;
498 }
499
500 return result;
501 }
502
518 bool remap_display_mode_if_needed(const config::video_t &video_config, const rtsp_stream::launch_session_t &session, SingleDisplayConfiguration &config) {
519 const auto remapping_type {determine_remapping_type(video_config)};
520 if (!remapping_type) {
521 return true;
522 }
523
524 const auto &remapping_list {[&]() {
525 using enum remapping_type_e;
526
527 switch (*remapping_type) {
528 case resolution_only:
529 return video_config.dd.mode_remapping.resolution_only;
530 case refresh_rate_only:
531 return video_config.dd.mode_remapping.refresh_rate_only;
532 case mixed:
533 default:
534 return video_config.dd.mode_remapping.mixed;
535 }
536 }()};
537
538 if (remapping_list.empty()) {
539 BOOST_LOG(debug) << "No values are available for display mode remapping.";
540 return true;
541 }
542 BOOST_LOG(debug) << "Trying to remap display modes...";
543
544 const auto entry_to_string {[type = *remapping_type](const config::video_t::dd_t::mode_remapping_entry_t &entry) {
545 const bool mapping_resolution {is_resolution_mapped(type)};
546 const bool mapping_fps {is_fps_mapped(type)};
547
548 // clang-format off
549 return (mapping_resolution ? " - requested resolution: "s + entry.requested_resolution + "\n" : "") +
550 (mapping_fps ? " - requested FPS: "s + entry.requested_fps + "\n" : "") +
551 (mapping_resolution ? " - final resolution: "s + entry.final_resolution + "\n" : "") +
552 (mapping_fps ? " - final refresh rate: "s + entry.final_refresh_rate : "");
553 // clang-format on
554 }};
555
556 for (const auto &entry : remapping_list) {
557 const auto parsed_entry {parse_remapping_entry(entry, *remapping_type)};
558 if (!parsed_entry) {
559 BOOST_LOG(error) << "Failed to parse remapping entry from:\n"
560 << entry_to_string(entry);
561 return false;
562 }
563
564 if (!parsed_entry->final_resolution && !parsed_entry->final_refresh_rate) {
565 BOOST_LOG(error) << "At least one final value must be set for remapping display modes! Entry:\n"
566 << entry_to_string(entry);
567 return false;
568 }
569
570 if (!session.enable_sops && (parsed_entry->requested_resolution || parsed_entry->final_resolution)) {
571 BOOST_LOG(warning) << R"(Skipping remapping entry, because the "Optimize game settings" is not set in the client! Entry:\n)"
572 << entry_to_string(entry);
573 continue;
574 }
575
576 // Note: at this point config should already have parsed resolution set.
577 if (parsed_entry->requested_resolution && parsed_entry->requested_resolution != config.m_resolution) {
578 BOOST_LOG(verbose) << "Skipping remapping because requested resolutions do not match! Entry:\n"
579 << entry_to_string(entry);
580 continue;
581 }
582
583 // Note: at this point config should already have parsed refresh rate set.
584 if (parsed_entry->requested_fps && parsed_entry->requested_fps != config.m_refresh_rate) {
585 BOOST_LOG(verbose) << "Skipping remapping because requested FPS do not match! Entry:\n"
586 << entry_to_string(entry);
587 continue;
588 }
589
590 BOOST_LOG(info) << "Remapping requested display mode. Entry:\n"
591 << entry_to_string(entry);
592 if (parsed_entry->final_resolution) {
593 config.m_resolution = parsed_entry->final_resolution;
594 }
595 if (parsed_entry->final_refresh_rate) {
596 config.m_refresh_rate = parsed_entry->final_refresh_rate;
597 }
598 break;
599 }
600
601 return true;
602 }
603
610 std::unique_ptr<SettingsManagerInterface> make_settings_manager([[maybe_unused]] const std::filesystem::path &persistence_filepath, [[maybe_unused]] const config::video_t &video_config) {
611 return nullptr;
612 }
613
617 enum class revert_option_e {
618 try_once,
619 try_indefinitely,
620 try_indefinitely_with_delay
621 };
622
627 void revert_configuration_unlocked(const revert_option_e option) {
628 if (!DD_DATA.sm_instance) {
629 // Platform is not supported, nothing to do.
630 return;
631 }
632
633 // Note: by default the executor function is immediately executed in the calling thread. With delay, we want to avoid that.
634 SchedulerOptions scheduler_option {.m_sleep_durations = {DEFAULT_RETRY_INTERVAL}};
635 if (option == revert_option_e::try_indefinitely_with_delay && DD_DATA.config_revert_delay > std::chrono::milliseconds::zero()) {
636 scheduler_option.m_sleep_durations = {DD_DATA.config_revert_delay, DEFAULT_RETRY_INTERVAL};
637 scheduler_option.m_execution = SchedulerOptions::Execution::ScheduledOnly;
638 }
639
640 DD_DATA.sm_instance->schedule([try_once = (option == revert_option_e::try_once), tried_out_devices = std::set<std::string> {}](auto &settings_iface, auto &stop_token) mutable {
641 if (try_once) {
642 std::ignore = settings_iface.revertSettings();
643 stop_token.requestStop();
644 return;
645 }
646
647 auto available_devices {[&settings_iface]() {
648 const auto devices {settings_iface.enumAvailableDevices()};
649 std::set<std::string> parsed_devices;
650
651 std::transform(
652 std::begin(devices),
653 std::end(devices),
654 std::inserter(parsed_devices, std::end(parsed_devices)),
655 [](const auto &device) {
656 return device.m_device_id + " - " + device.m_friendly_name;
657 }
658 );
659
660 return parsed_devices;
661 }()};
662 if (available_devices == tried_out_devices) {
663 BOOST_LOG(debug) << "Skipping reverting configuration, because no newly added/removed devices were detected since last check. Currently available devices:\n"
664 << toJson(available_devices);
665 return;
666 }
667
668 using enum SettingsManagerInterface::RevertResult;
669 if (const auto result {settings_iface.revertSettings()}; result == Ok) {
670 stop_token.requestStop();
671 return;
672 } else if (result == ApiTemporarilyUnavailable) {
673 // Do nothing and retry next time
674 return;
675 }
676
677 // If we have failed to revert settings then we will try to do it next time only if a device was added/removed
678 BOOST_LOG(warning) << "Failed to revert display device configuration (will retry once devices are added or removed). Enabling all of the available devices:\n"
679 << toJson(available_devices);
680 tried_out_devices.swap(available_devices);
681 },
682 scheduler_option);
683 }
684 } // namespace
685
686 std::unique_ptr<platf::deinit_t> init(const std::filesystem::path &persistence_filepath, const config::video_t &video_config) {
687 std::lock_guard lock {DD_DATA.mutex};
688 // We can support re-init without any issues, however we should make sure to clean up first!
689 if (video_config.dd.configuration_option == config::video_t::dd_t::config_option_e::disabled) {
690 if (!persistence_filepath.empty() && std::filesystem::exists(persistence_filepath)) {
691 std::filesystem::remove(persistence_filepath);
692 }
693 } else {
694 revert_configuration_unlocked(revert_option_e::try_once);
695 }
696 DD_DATA.config_revert_delay = video_config.dd.config_revert_delay;
697 DD_DATA.sm_instance = nullptr;
698
699 // If we fail to create settings manager, this means platform is not supported, and
700 // we will need to provided error-free pass-trough in other methods
701 if (auto settings_manager {make_settings_manager(persistence_filepath, video_config)}) {
702 DD_DATA.sm_instance = std::make_unique<RetryScheduler<SettingsManagerInterface>>(std::move(settings_manager));
703
704 const auto available_devices {DD_DATA.sm_instance->execute([](auto &settings_iface) {
705 return settings_iface.enumAvailableDevices();
706 })};
707 BOOST_LOG(info) << "Currently available display devices:\n"
708 << toJson(available_devices);
709
710 // In case we have failed to revert configuration before shutting down, we should
711 // do it now.
712 revert_configuration_unlocked(revert_option_e::try_indefinitely);
713 }
714
715 class deinit_t: public platf::deinit_t {
716 public:
717 ~deinit_t() override {
718 std::lock_guard lock {DD_DATA.mutex};
719 try {
720 // This may throw if used incorrectly. At the moment this will not happen, however
721 // in case some unforeseen changes are made that could raise an exception,
722 // we definitely don't want this to happen in destructor. Especially in the
723 // deinit_t where the outcome does not really matter.
724 revert_configuration_unlocked(revert_option_e::try_once);
725 } catch (std::exception &err) {
726 BOOST_LOG(fatal) << err.what();
727 }
728
729 DD_DATA.sm_instance = nullptr;
730 }
731 };
732
733 return std::make_unique<deinit_t>();
734 }
735
736 std::string map_output_name(const std::string &output_name) {
737 std::lock_guard lock {DD_DATA.mutex};
738 if (!DD_DATA.sm_instance) {
739 // Fallback to giving back the output name if the platform is not supported.
740 return output_name;
741 }
742
743 return DD_DATA.sm_instance->execute([&output_name](auto &settings_iface) {
744 return settings_iface.getDisplayName(output_name);
745 });
746 }
747
748 std::string map_display_name(const std::string &display_name) {
749 std::lock_guard lock { DD_DATA.mutex };
750 if (!DD_DATA.sm_instance) {
751 return {};
752 }
753
754 const auto available_devices { DD_DATA.sm_instance->execute([](auto &settings_iface) { return settings_iface.enumAvailableDevices(); }) };
755
756 for (auto &i : available_devices) {
757 if (i.m_display_name == display_name) {
758 return i.m_device_id;
759 }
760 }
761
762 return {};
763 }
764
765 void configure_display(const config::video_t &video_config, const rtsp_stream::launch_session_t &session) {
766 const auto result { parse_configuration(video_config, session) };
767 if (const auto *parsed_config { std::get_if<SingleDisplayConfiguration>(&result) }; parsed_config) {
768 configure_display(*parsed_config);
769 return;
770 }
771
772 if (const auto *disabled {std::get_if<configuration_disabled_tag_t>(&result)}; disabled) {
774 return;
775 }
776
777 // Error already logged for failed_to_parse_tag_t case, and we also don't
778 // want to revert active configuration in case we have any
779 }
780
781 void configure_display(const SingleDisplayConfiguration &config) {
782 std::lock_guard lock {DD_DATA.mutex};
783 if (!DD_DATA.sm_instance) {
784 // Platform is not supported, nothing to do.
785 return;
786 }
787
788 DD_DATA.sm_instance->schedule([config](auto &settings_iface, auto &stop_token) {
789 // We only want to keep retrying in case of a transient errors.
790 // In other cases, when we either fail or succeed we just want to stop...
791 if (settings_iface.applySettings(config) != SettingsManagerInterface::ApplyResult::ApiTemporarilyUnavailable) {
792 stop_token.requestStop();
793 }
794 },
795 {.m_sleep_durations = {DEFAULT_RETRY_INTERVAL}});
796 }
797
799 std::lock_guard lock {DD_DATA.mutex};
800 revert_configuration_unlocked(revert_option_e::try_indefinitely_with_delay);
801 }
802
804 std::lock_guard lock {DD_DATA.mutex};
805 if (!DD_DATA.sm_instance) {
806 // Platform is not supported, assume success.
807 return true;
808 }
809
810 return DD_DATA.sm_instance->execute([](auto &settings_iface, auto &stop_token) {
811 // Whatever the outcome is we want to stop interfering with the user,
812 // so any schedulers need to be stopped.
813 stop_token.requestStop();
814 return settings_iface.resetPersistence();
815 });
816 }
817
818 EnumeratedDeviceList enumerate_devices() {
819 std::lock_guard lock {DD_DATA.mutex};
820 if (!DD_DATA.sm_instance) {
821 // Platform is not supported.
822 return {};
823 }
824
825 return DD_DATA.sm_instance->execute([](auto &settings_iface) {
826 return settings_iface.enumAvailableDevices();
827 });
828 }
829
830 std::variant<failed_to_parse_tag_t, configuration_disabled_tag_t, SingleDisplayConfiguration> parse_configuration(const config::video_t &video_config, const rtsp_stream::launch_session_t &session) {
831 const auto device_prep {parse_device_prep_option(video_config)};
832 if (!device_prep) {
834 }
835
836 SingleDisplayConfiguration config;
837 config.m_device_id = video_config.output_name;
838 config.m_device_prep = *device_prep;
839 config.m_hdr_state = parse_hdr_option(video_config, session);
840
841 if (!parse_resolution_option(video_config, session, config)) {
842 // Error already logged
843 return failed_to_parse_tag_t {};
844 }
845
846 if (!parse_refresh_rate_option(video_config, session, config)) {
847 // Error already logged
848 return failed_to_parse_tag_t {};
849 }
850
851 if (!remap_display_mode_if_needed(video_config, session, config)) {
852 // Error already logged
853 return failed_to_parse_tag_t {};
854 }
855
856 return config;
857 }
858} // namespace display_device
audio_ctx_ref_t get_audio_ctx_ref()
Get the reference to the audio context.
Definition audio.cpp:315
Declarations for audio capture and encoding.
Declarations for common platform specific utilities.
std::variant< failed_to_parse_tag_t, configuration_disabled_tag_t, SingleDisplayConfiguration > parse_configuration(const config::video_t &video_config, const rtsp_stream::launch_session_t &session)
Parse the user configuration and the session information.
void revert_configuration()
Revert the display configuration and restore the previous state.
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).
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.
EnumeratedDeviceList enumerate_devices()
Enumerate the available devices.
bool reset_persistence()
Reset the persistence and currently held initial display state.
std::string map_output_name(const std::string &output_name)
Map the output name to a specific display.
Declarations for display device handling.
@ disabled
Single pass, the fastest and no extra vram.
Declarations for RTSP streaming.
std::vector< mode_remapping_entry_t > refresh_rate_only
To be use when only refresh_rate_option is set to automatic.
Definition config.h:109
std::vector< mode_remapping_entry_t > mixed
To be used when resolution_option and refresh_rate_option is set to automatic.
Definition config.h:107
std::vector< mode_remapping_entry_t > resolution_only
To be use when only resolution_option is set to automatic.
Definition config.h:108
std::string manual_resolution
Manual resolution in case resolution_option == resolution_option_e::manual.
Definition config.h:114
std::chrono::milliseconds config_revert_delay
Time to wait until settings are reverted (after stream ends/app exists).
Definition config.h:118
std::string manual_refresh_rate
Manual refresh rate in case refresh_rate_option == refresh_rate_option_e::manual.
Definition config.h:116
@ disabled
Disable the configuration for the device.
Definition config.h:75
A tag structure indicating that configuration is disabled.
A tag structure indicating that configuration parsing has failed.
void release(input_raw_t *raw, int index)
Free a gamepad whose stream ended; a detached desktop keeps it.