Handle acquiring display names based on encoder

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

View file

@ -286,8 +286,8 @@ std::unique_ptr<audio_control_t> audio_control();
*/
std::shared_ptr<display_t> 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<std::string> display_names();
// A list of names of displays accepted as display_name with the mem_type_e
std::vector<std::string> display_names(mem_type_e hwdevice_type);
input_t input();
void move_mouse(input_t &input, int deltaX, int deltaY);

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;
}

View file

@ -452,7 +452,7 @@ std::shared_ptr<display_t> display(mem_type_e hwdevice_type, const std::string &
return nullptr;
}
std::vector<std::string> display_names() {
std::vector<std::string> display_names(mem_type_e) {
std::vector<std::string> display_names;
HRESULT status;

View file

@ -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<sync_session_t> 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<std::unique_ptr<sync_session_ctx_t>> &synced_session_ctxs,
encode_session_ctx_queue_t &encode_session_ctx_queue,
int &display_p, const std::vector<std::string> &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<platf::display_t> 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(