From c3af78caaa400b2f4aedb298886155cdac3e5f7f Mon Sep 17 00:00:00 2001 From: loki Date: Fri, 24 Jan 2020 01:05:43 +0100 Subject: [PATCH] Configure source for frame capturing on Windows --- assets/sunshine.conf | 9 +++++++++ sunshine/config.cpp | 6 +++++- sunshine/config.h | 3 +++ sunshine/platform/windows_dxgi.cpp | 22 +++++++++++++++++++++- 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/assets/sunshine.conf b/assets/sunshine.conf index 6b316a76..461b950d 100644 --- a/assets/sunshine.conf +++ b/assets/sunshine.conf @@ -57,6 +57,7 @@ fec_percentage = 10 # If back_button_timeout < 0, then the Home/Guide button will not be emulated # back_button_timeout = 2000 + # The name of the audio sink used for Audio Loopback # If you do not specify this variable, pulseaudio will select the default monitor device. # @@ -65,6 +66,14 @@ fec_percentage = 10 # audio_sink = alsa_output.pci-0000_09_00.3.analog-stereo.monitor +# !! Windows only !! +# You can select the video card you want to stream: +# The appropriate values can be found using the following command: +# tools\dxgi-info.exe +# adapter_name = Radeon RX 580 Series +# output_name = \\.\DISPLAY1 + + ############################################### # FFmpeg software encoding parameters # Honestly, I have no idea what the optimal values would be. diff --git a/sunshine/config.cpp b/sunshine/config.cpp index f16d33b3..ff9482fc 100644 --- a/sunshine/config.cpp +++ b/sunshine/config.cpp @@ -23,7 +23,9 @@ video_t video { 0, // hevc_mode "superfast"s, // preset - "zerolatency"s // tune + "zerolatency"s, // tune + {}, // adapter_name + {} // output_name }; audio_t audio {}; @@ -166,6 +168,8 @@ void parse_file(const char *file) { }); string_f(vars, "preset", video.preset); string_f(vars, "tune", video.tune); + string_f(vars, "adapter_name", video.adapter_name); + string_f(vars, "output_name", video.output_name); string_f(vars, "pkey", nvhttp.pkey); string_f(vars, "cert", nvhttp.cert); diff --git a/sunshine/config.h b/sunshine/config.h index 541d8727..b27d3e2a 100644 --- a/sunshine/config.h +++ b/sunshine/config.h @@ -15,6 +15,9 @@ struct video_t { int hevc_mode; std::string preset; std::string tune; + + std::string adapter_name; + std::string output_name; }; struct audio_t { diff --git a/sunshine/platform/windows_dxgi.cpp b/sunshine/platform/windows_dxgi.cpp index a755d407..9f8269a4 100644 --- a/sunshine/platform/windows_dxgi.cpp +++ b/sunshine/platform/windows_dxgi.cpp @@ -7,6 +7,9 @@ #include #include +#include +#include + #include "sunshine/main.h" #include "common.h" @@ -370,16 +373,31 @@ public: return -1; } + std::wstring_convert, wchar_t> converter; + + auto adapter_name = converter.from_bytes(config::video.adapter_name); + auto output_name = converter.from_bytes(config::video.output_name); for(int x = 0; factory_p->EnumAdapters1(x, &adapter_p) != DXGI_ERROR_NOT_FOUND; ++x) { dxgi::adapter_t adapter_tmp { adapter_p }; + DXGI_ADAPTER_DESC1 adapter_desc; + adapter_tmp->GetDesc1(&adapter_desc); + + if(!adapter_name.empty() && adapter_desc.Description != adapter_name) { + continue; + } + for(int y = 0; adapter_tmp->EnumOutputs(y, &output_p) != DXGI_ERROR_NOT_FOUND; ++y) { dxgi::output_t output_tmp {output_p }; DXGI_OUTPUT_DESC desc; output_tmp->GetDesc(&desc); + if(!output_name.empty() && desc.DeviceName != output_name) { + continue; + } + if(desc.AttachedToDesktop) { output = std::move(output_tmp); @@ -443,7 +461,9 @@ public: DXGI_ADAPTER_DESC adapter_desc; adapter->GetDesc(&adapter_desc); - BOOST_LOG(info) + auto description = converter.to_bytes(adapter_desc.Description); + BOOST_LOG(info) << std::endl + << "Device Description : " << description << std::endl << "Device Vendor ID : 0x"sv << util::hex(adapter_desc.VendorId).to_string_view() << std::endl << "Device Device ID : 0x"sv << util::hex(adapter_desc.DeviceId).to_string_view() << std::endl << "Device Video Mem : "sv << adapter_desc.DedicatedVideoMemory / 1048576 << " MiB"sv << std::endl