diff --git a/sunshine/platform/common.h b/sunshine/platform/common.h index 4b702a9b..9d465749 100644 --- a/sunshine/platform/common.h +++ b/sunshine/platform/common.h @@ -286,8 +286,8 @@ std::unique_ptr audio_control(); */ std::shared_ptr display(mem_type_e hwdevice_type, const std::string &display_name, int framerate); -// A list of names of displays accepted as display_name -std::vector display_names(); +// A list of names of displays accepted as display_name with the mem_type_e +std::vector display_names(mem_type_e hwdevice_type); input_t input(); void move_mouse(input_t &input, int deltaX, int deltaY); diff --git a/sunshine/platform/linux/misc.cpp b/sunshine/platform/linux/misc.cpp index bf6201b3..dd114ec4 100644 --- a/sunshine/platform/linux/misc.cpp +++ b/sunshine/platform/linux/misc.cpp @@ -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 sources; #ifdef SUNSHINE_BUILD_CUDA std::vector nvfbc_display_names(); @@ -192,48 +196,48 @@ bool verify_x11() { } #endif -std::vector display_names() { - switch(source) { +std::vector 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(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 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 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; } diff --git a/sunshine/platform/windows/display_base.cpp b/sunshine/platform/windows/display_base.cpp index f816ad88..02b08c37 100644 --- a/sunshine/platform/windows/display_base.cpp +++ b/sunshine/platform/windows/display_base.cpp @@ -452,7 +452,7 @@ std::shared_ptr display(mem_type_e hwdevice_type, const std::string & return nullptr; } -std::vector display_names() { +std::vector display_names(mem_type_e) { std::vector display_names; HRESULT status; diff --git a/sunshine/video.cpp b/sunshine/video.cpp index 6faf82ee..f4a4c523 100644 --- a/sunshine/video.cpp +++ b/sunshine/video.cpp @@ -585,7 +585,7 @@ void captureThread( // Get all the monitor names now, rather than at boot, to // get the most up-to-date list available monitors - auto display_names = platf::display_names(); + auto display_names = platf::display_names(map_dev_type(encoder.dev_type)); int display_p = 0; if(display_names.empty()) { @@ -1105,17 +1105,30 @@ std::optional make_synced_session(platf::display_t *disp, const return std::nullopt; } - encode_session.session = std::move(*session); + encode_session.session = std::move(*session); return std::move(encode_session); } encode_e encode_run_sync( std::vector> &synced_session_ctxs, - encode_session_ctx_queue_t &encode_session_ctx_queue, - int &display_p, const std::vector &display_names) { + encode_session_ctx_queue_t &encode_session_ctx_queue) { const auto &encoder = encoders.front(); + auto display_names = platf::display_names(map_dev_type(encoder.dev_type)); + int display_p = 0; + + if(display_names.empty()) { + display_names.emplace_back(config::video.output_name); + } + + for(int x = 0; x < display_names.size(); ++x) { + if(display_names[x] == config::video.output_name) { + display_p = x; + + break; + } + } std::shared_ptr disp; @@ -1269,22 +1282,7 @@ void captureThreadSync() { } }); - auto display_names = platf::display_names(); - int display_p = 0; - - if(display_names.empty()) { - display_names.emplace_back(config::video.output_name); - } - - for(int x = 0; x < display_names.size(); ++x) { - if(display_names[x] == config::video.output_name) { - display_p = x; - - break; - } - } - - while(encode_run_sync(synced_session_ctxs, ctx, display_p, display_names) == encode_e::reinit) {} + while(encode_run_sync(synced_session_ctxs, ctx) == encode_e::reinit) {} } void capture_async(