Handle acquiring display names based on encoder

This commit is contained in:
loki-47-6F-64
2021-09-25 14:44:38 +02:00
parent f78a9e2ccf
commit e287404992
4 changed files with 54 additions and 57 deletions

View File

@@ -140,7 +140,8 @@ std::string get_mac_address(const std::string_view &address) {
return "00:00:00:00:00:00"s;
}
enum class source_e {
namespace source {
enum source_e : std::size_t {
#ifdef SUNSHINE_BUILD_CUDA
NVFBC,
#endif
@@ -153,8 +154,11 @@ enum class source_e {
#ifdef SUNSHINE_BUILD_X11
X11,
#endif
MAX_FLAGS
};
static source_e source;
} // namespace source
static std::bitset<source::MAX_FLAGS> sources;
#ifdef SUNSHINE_BUILD_CUDA
std::vector<std::string> nvfbc_display_names();
@@ -192,48 +196,48 @@ bool verify_x11() {
}
#endif
std::vector<std::string> display_names() {
switch(source) {
std::vector<std::string> display_names(mem_type_e hwdevice_type) {
#ifdef SUNSHINE_BUILD_CUDA
case source_e::NVFBC:
return nvfbc_display_names();
// display using NvFBC only supports mem_type_e::cuda
if(sources[source::NVFBC] && hwdevice_type == mem_type_e::cuda) return nvfbc_display_names();
#endif
#ifdef SUNSHINE_BUILD_WAYLAND
case source_e::WAYLAND:
return wl_display_names();
if(sources[source::WAYLAND]) return wl_display_names();
#endif
#ifdef SUNSHINE_BUILD_DRM
case source_e::KMS:
return kms_display_names();
if(sources[source::KMS]) return kms_display_names();
#endif
#ifdef SUNSHINE_BUILD_X11
case source_e::X11:
return x11_display_names();
if(sources[source::X11]) return x11_display_names();
#endif
}
return {};
}
std::shared_ptr<display_t> display(mem_type_e hwdevice_type, const std::string &display_name, int framerate) {
switch(source) {
#ifdef SUNSHINE_BUILD_CUDA
case source_e::NVFBC:
if(sources[source::NVFBC] && hwdevice_type == mem_type_e::cuda) {
BOOST_LOG(info) << "Screencasting with NvFBC"sv;
return nvfbc_display(hwdevice_type, display_name, framerate);
}
#endif
#ifdef SUNSHINE_BUILD_WAYLAND
case source_e::WAYLAND:
if(sources[source::WAYLAND]) {
BOOST_LOG(info) << "Screencasting with Wayland's protocol"sv;
return wl_display(hwdevice_type, display_name, framerate);
}
#endif
#ifdef SUNSHINE_BUILD_DRM
case source_e::KMS:
if(sources[source::KMS]) {
BOOST_LOG(info) << "Screencasting with KMS"sv;
return kms_display(hwdevice_type, display_name, framerate);
}
#endif
#ifdef SUNSHINE_BUILD_X11
case source_e::X11:
if(sources[source::X11]) {
BOOST_LOG(info) << "Screencasting with X11"sv;
return x11_display(hwdevice_type, display_name, framerate);
#endif
}
#endif
return nullptr;
}
@@ -260,16 +264,14 @@ std::unique_ptr<deinit_t> init() {
#endif
#ifdef SUNSHINE_BUILD_CUDA
if(verify_nvfbc()) {
BOOST_LOG(info) << "Using nvFBC for screencasting"sv;
source = source_e::NVFBC;
goto found_source;
BOOST_LOG(info) << "Using NvFBC for screencasting"sv;
sources[source::NVFBC] = true;
}
#endif
#ifdef SUNSHINE_BUILD_WAYLAND
if(verify_wl()) {
BOOST_LOG(info) << "Using Wayland for screencasting"sv;
source = source_e::WAYLAND;
goto found_source;
sources[source::WAYLAND] = true;
}
#endif
#ifdef SUNSHINE_BUILD_DRM
@@ -281,23 +283,20 @@ std::unique_ptr<deinit_t> init() {
}
BOOST_LOG(info) << "Using KMS for screencasting"sv;
source = source_e::KMS;
goto found_source;
sources[source::KMS] = true;
}
#endif
#ifdef SUNSHINE_BUILD_X11
if(verify_x11()) {
BOOST_LOG(info) << "Using X11 for screencasting"sv;
source = source_e::X11;
goto found_source;
sources[source::X11] = true;
}
#endif
// Did not find a source
return nullptr;
// Normally, I would simply use if-else statements to achieve this result,
// but due to the macro's, (*spits on ground*), it would be too messy
found_source:
if(sources.none()) {
return nullptr;
}
if(!gladLoaderLoadEGL(EGL_NO_DISPLAY) || !eglGetPlatformDisplay) {
BOOST_LOG(warning) << "Couldn't load EGL library"sv;
}