From 9f0a5825f063b16642caa32fdef76ddb7bafb27f Mon Sep 17 00:00:00 2001 From: loki Date: Fri, 24 Jan 2020 23:17:05 +0100 Subject: [PATCH] Select audio endpoint based on config option audio_sink on Windows --- assets/sunshine.conf | 6 +++++- sunshine/platform/windows_wasapi.cpp | 26 +++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/assets/sunshine.conf b/assets/sunshine.conf index 461b950d..29f2a12a 100644 --- a/assets/sunshine.conf +++ b/assets/sunshine.conf @@ -62,9 +62,13 @@ fec_percentage = 10 # If you do not specify this variable, pulseaudio will select the default monitor device. # # You can find the name of the audio sink using the following command: +# !! Linux only !! # pacmd list-sources | grep "name:" # audio_sink = alsa_output.pci-0000_09_00.3.analog-stereo.monitor - +# +# !! Windows only !! +# tools\audio-info.exe +# audio_sink = {0.0.0.00000000}.{FD47D9CC-4218-4135-9CE2-0C195C87405B} # !! Windows only !! # You can select the video card you want to stream: diff --git a/sunshine/platform/windows_wasapi.cpp b/sunshine/platform/windows_wasapi.cpp index ca105fd9..4c773a33 100644 --- a/sunshine/platform/windows_wasapi.cpp +++ b/sunshine/platform/windows_wasapi.cpp @@ -6,8 +6,11 @@ #include #include +#include + #include +#include "sunshine/config.h" #include "sunshine/main.h" #include "common.h" @@ -83,14 +86,23 @@ public: } device_t::pointer device_p{}; - status = device_enum->GetDefaultAudioEndpoint( - eRender, - eConsole, - &device_p); + + if(config::audio.sink.empty()) { + status = device_enum->GetDefaultAudioEndpoint( + eRender, + eConsole, + &device_p); + } + else { + std::wstring_convert, wchar_t> converter; + auto wstring_device_id = converter.from_bytes(config::audio.sink); + + status = device_enum->GetDevice(wstring_device_id.c_str(), &device_p); + } device.reset(device_p); if (FAILED(status)) { - BOOST_LOG(error) << "Couldn't create Device [0x"sv << util::hex(status).to_string_view() << ']'; + BOOST_LOG(error) << "Couldn't create audio Device [0x"sv << util::hex(status).to_string_view() << ']'; return -1; } @@ -104,7 +116,7 @@ public: audio_client.reset(audio_client_p); if (FAILED(status)) { - BOOST_LOG(error) << "Couldn't activate Device [0x"sv << util::hex(status).to_string_view() << ']'; + BOOST_LOG(error) << "Couldn't activate audio Device [0x"sv << util::hex(status).to_string_view() << ']'; return -1; } @@ -167,7 +179,7 @@ public: std::uint32_t frames; status = audio_client->GetBufferSize(&frames); if (FAILED(status)) { - BOOST_LOG(error) << "Couldn't acquire the number of frames [0x"sv << util::hex(status).to_string_view() << ']'; + BOOST_LOG(error) << "Couldn't acquire the number of audio frames [0x"sv << util::hex(status).to_string_view() << ']'; return -1; }