-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add libdisplaydevice dependency and output name mapping
- Loading branch information
1 parent
f694137
commit c622bec
Showing
17 changed files
with
311 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* @file src/display_device.cpp | ||
* @brief Definitions for display device handling. | ||
*/ | ||
// header include | ||
#include "display_device.h" | ||
|
||
// lib includes | ||
#include <display_device/json.h> | ||
#include <display_device/retry_scheduler.h> | ||
#include <display_device/settings_manager_interface.h> | ||
|
||
// platform-specific includes | ||
#ifdef _WIN32 | ||
#include <display_device/windows/settings_manager.h> | ||
#include <display_device/windows/win_api_layer.h> | ||
#include <display_device/windows/win_display_device.h> | ||
#endif | ||
|
||
namespace display_device { | ||
namespace { | ||
std::unique_ptr<SettingsManagerInterface> | ||
make_settings_manager() { | ||
#ifdef _WIN32 | ||
// TODO: In the upcoming PR, add audio context capture and settings persistence | ||
return std::make_unique<SettingsManager>( | ||
std::make_shared<WinDisplayDevice>(std::make_shared<WinApiLayer>()), | ||
nullptr, | ||
std::make_unique<PersistentState>(nullptr)); | ||
#else | ||
return nullptr; | ||
#endif | ||
} | ||
} // namespace | ||
|
||
session_t & | ||
session_t::get() { | ||
static session_t session; | ||
return session; | ||
} | ||
|
||
std::unique_ptr<platf::deinit_t> | ||
session_t::init() { | ||
// We can support re-init without any issues, however we should make sure to cleanup first! | ||
get().impl = nullptr; | ||
|
||
// If we fail to create settings manager, this means platform is not supported and | ||
// we will need to provided error-free passtrough in other methods | ||
if (auto settings_manager { make_settings_manager() }) { | ||
get().impl = std::make_unique<RetryScheduler<SettingsManagerInterface>>(std::move(settings_manager)); | ||
|
||
const auto available_devices { get().impl->execute([](auto &settings_iface) { return settings_iface.enumAvailableDevices(); }) }; | ||
BOOST_LOG(info) << "Currently available display devices:\n" | ||
<< toJson(available_devices); | ||
|
||
// TODO: In the upcoming PR, schedule recovery here | ||
} | ||
|
||
class deinit_t: public platf::deinit_t { | ||
public: | ||
~deinit_t() override { | ||
// TODO: In the upcoming PR, execute recovery once here | ||
get().impl = nullptr; | ||
} | ||
}; | ||
return std::make_unique<deinit_t>(); | ||
} | ||
|
||
std::string | ||
session_t::map_output_name(const std::string &output_name) const { | ||
if (impl) { | ||
return impl->execute([&output_name](auto &settings_iface) { return settings_iface.getDisplayName(output_name); }); | ||
} | ||
|
||
// Fallback to giving back the output name if the platform is not supported. | ||
return output_name; | ||
} | ||
|
||
session_t::session_t() = default; | ||
} // namespace display_device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* @file src/display_device.h | ||
* @brief Declarations for display device handling. | ||
*/ | ||
#pragma once | ||
|
||
// local includes | ||
#include "platform/common.h" | ||
|
||
// forward declarations | ||
namespace display_device { | ||
template <class T> | ||
class RetryScheduler; | ||
class SettingsManagerInterface; | ||
} // namespace display_device | ||
|
||
namespace display_device { | ||
/** | ||
* @brief A singleton class for managing the display device configuration for the whole Sunshine session. | ||
* | ||
* This class is meant to be an entry point for applying the configuration and reverting it later | ||
* from within the various places in the Sunshine's source code. | ||
*/ | ||
class session_t { | ||
public: | ||
/** | ||
* @brief Get the singleton instance. | ||
* @returns Singleton instance for the class. | ||
* | ||
* EXAMPLES: | ||
* ```cpp | ||
* session_t& session { session_t::get() }; | ||
* ``` | ||
*/ | ||
[[nodiscard]] static session_t & | ||
get(); | ||
|
||
/** | ||
* @brief Initialize the singleton and perform the initial state recovery (if needed). | ||
* @returns A deinit_t instance that performs cleanup when destroyed. | ||
* | ||
* EXAMPLES: | ||
* ```cpp | ||
* const auto session_guard { session_t::init() }; | ||
* ``` | ||
*/ | ||
[[nodiscard]] static std::unique_ptr<platf::deinit_t> | ||
init(); | ||
|
||
/** | ||
* @brief Map the output name to a specific display. | ||
* @param output_name The user-configurable output name. | ||
* @returns Mapped display name or empty string if the output name could not be mapped. | ||
* | ||
* EXAMPLES: | ||
* ```cpp | ||
* session_t& session { session_t::get() }; | ||
* const auto mapped_name_config { session.get_display_name(config::video.output_name) }; | ||
* const auto mapped_name_custom { session.get_display_name("{some-device-id}") }; | ||
* ``` | ||
*/ | ||
[[nodiscard]] std::string | ||
map_output_name(const std::string &output_name) const; | ||
|
||
/** | ||
* @brief A deleted copy constructor for singleton pattern. | ||
* @note Public to ensure better error message. | ||
*/ | ||
session_t(session_t const &) = delete; | ||
|
||
/** | ||
* @brief A deleted assignment operator for singleton pattern. | ||
* @note Public to ensure better error message. | ||
*/ | ||
void | ||
operator=(session_t const &) = delete; | ||
|
||
private: | ||
/** | ||
* @brief A private constructor to ensure the singleton pattern. | ||
* @note Cannot be defaulted in declaration because of forward declared RetryScheduler. | ||
*/ | ||
explicit session_t(); | ||
|
||
std::unique_ptr<RetryScheduler<SettingsManagerInterface>> impl; /**< Platform specific interface for managing settings (with retry functionality). */ | ||
}; | ||
} // namespace display_device |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.